Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
ATmega4809.h
Go to the documentation of this file.
1/*
2Copyright (C) 2020 Bengt Martensson.
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 3 of the License, or (at
7your option) any later version.
8
9This program is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program. If not, see http://www.gnu.org/licenses/.
16 */
17
30#pragma once
31
32#define CURRENT_CLASS ATmega4809
33
34#define HAS_FLASH_READ 1
35#define HAS_HARDWARE_PWM 1
36#define HAS_SAMPLING 1
37#define HAS_INPUT_CAPTURE 0
38
39#define STRCPY_PF_CAST(x) (x)
40
41class ATmega4809 : public Board {
42public:
44 };
45
46private:
47
48#ifdef IR_USE_TIMER1
50#define TIMER_INTR_NAME TCB0_INT_vect
51
52 void timerReset() {
53 TCB0.INTFLAGS = TCB_CAPT_bm;
54 };
55 //#define TIMER_ENABLE_PWM (TCB0.CTRLB = TCB_CNTMODE_PWM8_gc)
56 //#define TIMER_DISABLE_PWM (TCB0.CTRLB &= ~(TCB_CNTMODE_PWM8_gc))
57
58 void timerEnablePwm() {
59 TCB0.CTRLB |= TCB_CCMPEN_bm;
60 };
61
62 void timerDisablePwm() {
63 TCB0.CTRLB &= ~(TCB_CCMPEN_bm);
64 };
65
66 void timerEnableIntr() {
67 TCB0.INTCTRL = TCB_CAPT_bm;
68 };
69
70 void timerDisableIntr() {
71 TCB0.INTCTRL &= ~TCB_CAPT_bm;
72 };
73
74 void timerConfigHz(frequency_t frequency, dutycycle_t dutyCycle) {
75 const uint8_t pwmval = F_CPU / 2U / frequency;
76 TCB0.CTRLB = TCB_CNTMODE_PWM8_gc;
77 TCB0.CCMPL = pwmval;
78 TCB0.CCMPH = pwmval * dutyCycle / 100UL;
79 TCB0.CTRLA = TCB_CLKSEL_CLKDIV2_gc | TCB_ENABLE_bm;
80 };
81
82 void timerConfigNormal() {
83 TCB0.CTRLB = TCB_CNTMODE_INT_gc;
84 TCB0.CCMP = F_CPU * microsPerTick / 1000000UL;
85 TCB0.INTCTRL = TCB_CAPT_bm;
86 TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm;
87 };
88
89#define PWM_PIN 6
90
92#elif defined(IR_USE_TIMER2) // ! defined(IR_USE_TIMER1)
93
94// TODO... ;-)
95#error IR_USE_TIMER2 for this architecture is not yet implemented, sorry.
96
97#else // ! defined(IR_USE_TIMER2)
98
99#error Config error, either IR_USE_TIMER1 or IR_USE_TIMER2 must be defined.
100
101#endif
102};
int8_t dutycycle_t
Type for duty cycle in percent.
Definition: InfraredTypes.h:36
uint32_t frequency_t
Type for modulation frequency in Hz.
Definition: InfraredTypes.h:31
This class serves as an HAL (Hardware Abstraction Layer).
Definition: Board.h:33
virtual void timerEnableIntr()=0
Start periodic sampling routine.
virtual void timerDisablePwm()=0
Turn off PWM output.
virtual void timerConfigHz(frequency_t hz, dutycycle_t dutyCycle=defaultDutyCycle)=0
Configure hardware PWM, but do not enable it.
static const unsigned long microsPerTick
Definition: Board.h:57
virtual void timerDisableIntr()=0
Turn off periodic interrupts.
virtual void timerEnablePwm()=0
Start PWM output.
virtual void timerConfigNormal()=0
Disables the PWM configuration.
virtual void timerReset()
TODO.
Definition: Board.h:115