avr/timer/timer.h

57 lines
1.6 KiB
C

/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library.
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __TIMER_H__
#define __TIMER_H__
#include <avr/io.h>
// ATmega16U4/32U4 Datasheet, table 14.4, page 133
typedef enum {
normal,
pwm_phasecorrect_8bit,
pwm_phasecorrect_9bit,
pwm_phasecorrect_10bit,
ctc,
fast_pwm_8bit,
fast_pwm_9bit,
fast_pwm_10bit,
pwm_phase_and_frequency_correct_icrtop,
pwm_phase_and_frequency_correct_ocrtop,
pwm_phase_correct_icrtop,
pwm_phase_correct_ocrtop,
ctc_icr,
fast_pwm_icrtop,
fast_pwm_ocrtop,
} timer_mode_t;
// Clock prescaler selector, ATmega16U4/32U4 Datasheet, table 14.5, page 1354p
typedef enum {
none,
clk_1,
clk_8,
clk_64,
clk_256,
clk_1024,
external_falling_edge,
external_rising_edge,
} clock_select_t;
typedef struct {
volatile uint8_t count_msb;
volatile uint8_t count_lsb;
volatile uint8_t top_msb;
volatile uint8_t top_lsb;
} timer_16bit_t;
#endif