25#define CURRENT_CLASS Due
27#define HAS_FLASH_READ 1
28#define HAS_HARDWARE_PWM 1
30#define HAS_INPUT_CAPTURE 0
32#define STRCPY_PF_CAST(x) static_cast<const char*>(x)
41#if defined(IR_USE_PWM0)
43#define IR_USE_PWM_PORT PIOC
44#define IR_USE_PWM_PERIPH PIO_PERIPH_B
45#define IR_USE_PWM_PINMASK PIO_PC2
46#define IR_USE_PWM_CH 0
47#elif defined(IR_USE_PWM1)
49#define IR_USE_PWM_PORT PIOC
50#define IR_USE_PWM_PERIPH PIO_PERIPH_B
51#define IR_USE_PWM_PINMASK PIO_PC4
52#define IR_USE_PWM_CH 1
53#elif defined(IR_USE_PWM2)
55#define IR_USE_PWM_PORT PIOC
56#define IR_USE_PWM_PERIPH PIO_PERIPH_B
57#define IR_USE_PWM_PINMASK PIO_PC6
58#define IR_USE_PWM_CH 2
59#elif defined(IR_USE_PWM3)
61#define IR_USE_PWM_PORT PIOC
62#define IR_USE_PWM_PERIPH PIO_PERIPH_B
63#define IR_USE_PWM_PINMASK PIO_PC8
64#define IR_USE_PWM_CH 3
65#elif defined(IR_USE_PWM4)
67#define IR_USE_PWM_PORT PIOC
68#define IR_USE_PWM_PERIPH PIO_PERIPH_B
69#define IR_USE_PWM_PINMASK PIO_PC21
70#define IR_USE_PWM_CH 4
71#elif defined(IR_USE_PWM5)
73#define IR_USE_PWM_PORT PIOC
74#define IR_USE_PWM_PERIPH PIO_PERIPH_B
75#define IR_USE_PWM_PINMASK PIO_PC22
76#define IR_USE_PWM_CH 5
77#elif defined(IR_USE_PWM6)
79#define IR_USE_PWM_PORT PIOC
80#define IR_USE_PWM_PERIPH PIO_PERIPH_B
81#define IR_USE_PWM_PINMASK PIO_PC23
82#define IR_USE_PWM_CH 6
83#elif defined(IR_USE_PWM7)
85#define IR_USE_PWM_PORT PIOC
86#define IR_USE_PWM_PERIPH PIO_PERIPH_B
87#define IR_USE_PWM_PINMASK PIO_PC24
88#define IR_USE_PWM_CH 7
91#if defined(IR_USE_TC3)
92#define IR_USE_TC_IRQ TC3_IRQn
95#define TIMER_INTR_NAME TC3_Handler
96#elif defined(IR_USE_TC4)
97#define IR_USE_TC_IRQ TC4_IRQn
100#define TIMER_INTR_NAME TC4_Handler
101#elif defined(IR_USE_TC5)
102#define IR_USE_TC_IRQ TC5_IRQn
105#define TIMER_INTR_NAME TC5_Handler
110 IR_USE_TC->TC_CHANNEL[IR_USE_CH].TC_SR;
113 void timerEnablePwm() {
114 PWMC_EnableChannel(PWM_INTERFACE, IR_USE_PWM_CH);
117 void timerDisablePwm() {
118 PWMC_DisableChannel(PWM_INTERFACE, IR_USE_PWM_CH);
122 void timerEnableIntr() {
123 NVIC_EnableIRQ(IR_USE_TC_IRQ);
126 void timerDisableIntr() {
127 NVIC_DisableIRQ(IR_USE_TC_IRQ);
130 static const unsigned multiplicator = 20U;
133 pmc_enable_periph_clk(PWM_INTERFACE_ID);
134 const uint32_t pwmval = frequency * multiplicator;
135 PWMC_ConfigureClocks(PWM_FREQUENCY * PWM_MAX_DUTY_CYCLE, pwmval, F_CPU);
136 PIO_Configure(IR_USE_PWM_PORT, IR_USE_PWM_PERIPH, IR_USE_PWM_PINMASK, PIO_DEFAULT);
137 PWMC_ConfigureChannel(PWM_INTERFACE, IR_USE_PWM_CH, PWM_CMR_CPRE_CLKB, 0U, 0U);
138 PWMC_SetPeriod(PWM_INTERFACE, IR_USE_PWM_CH, multiplicator);
139 PWMC_SetDutyCycle(PWM_INTERFACE, IR_USE_PWM_CH,
static_cast<uint16_t
>((multiplicator * dutyCycle + 50U) / 100U));
142 void timerConfigNormal() {
143 pmc_enable_periph_clk(
static_cast<uint32_t
>(IR_USE_TC_IRQ));
144 TC_Configure(IR_USE_TC, IR_USE_CH, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
146 TC_SetRA(IR_USE_TC, IR_USE_CH, rc / 2U);
147 TC_SetRC(IR_USE_TC, IR_USE_CH, rc);
148 TC_Start(IR_USE_TC, IR_USE_CH);
149 IR_USE_TC->TC_CHANNEL[IR_USE_CH].TC_IER = TC_IER_CPCS;
150 IR_USE_TC->TC_CHANNEL[IR_USE_CH].TC_IDR = ~TC_IER_CPCS;
int8_t dutycycle_t
Type for duty cycle in percent.
uint32_t frequency_t
Type for modulation frequency in Hz.
This class serves as an HAL (Hardware Abstraction Layer).
static const unsigned long microsPerTick