FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
atmega_xx4.h
1 // Copyright 2016-2021 Jean-Francois Poilpret
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
22 #ifndef BOARDS_ATMEGA_XX4_HH
23 #define BOARDS_ATMEGA_XX4_HH
24 
25 #include "io.h"
26 #include "../defines.h"
27 #include <avr/sleep.h>
28 
30 /* This board is based on ATmega644 or 1284 */
31 #define BOARDS_ATMEGAXX4
32 
38 namespace board
39 {
49  inline static void init() {}
50 
54  enum class Port: uint8_t
55  {
57  PORT_A = 0,
59  PORT_B,
61  PORT_C,
63  PORT_D,
64  // FastArduino internal: DO NOT USE
65  NONE = UINT8_MAX
66  };
67 
75  enum class DigitalPin: uint8_t
76  {
78  D0_PA0 = 0,
80  D1_PA1,
82  D2_PA2,
84  D3_PA3,
86  D4_PA4,
88  D5_PA5,
90  D6_PA6,
92  D7_PA7,
93 
95  D8_PB0,
97  D9_PB1,
99  D10_PB2,
101  D11_PB3,
103  D12_PB4,
105  D13_PB5,
107  D14_PB6,
109  D15_PB7,
110 
112  D16_PC0,
114  D17_PC1,
116  D18_PC2,
118  D19_PC3,
120  D20_PC4,
122  D21_PC5,
124  D22_PC6,
126  D23_PC7,
127 
129  D24_PD0,
131  D25_PD1,
133  D26_PD2,
135  D27_PD3,
137  D28_PD4,
139  D29_PD5,
141  D30_PD6,
143  D31_PD7,
144 
146  LED = D8_PB0,
147  // FastArduino internal: DO NOT USE
148  NONE = 0XFF
149  };
150 
154  enum class AnalogClock: uint8_t
155  {
156  MAX_FREQ_50KHz = 0,
157  MAX_FREQ_100KHz,
158  MAX_FREQ_200KHz,
159  MAX_FREQ_500KHz,
160  MAX_FREQ_1MHz
161  };
162 
166  enum class AnalogReference: uint8_t
167  {
169  AREF = 0,
171  AVCC,
174  INTERNAL_1_1V,
178  };
179 
186  enum class AnalogPin: uint8_t
187  {
189  A0 = 0,
191  A1,
193  A2,
195  A3,
197  A4,
199  A5,
201  A6,
203  A7,
205  BANDGAP,
206  // FastArduino internal: DO NOT USE
207  NONE = UINT8_MAX
208  };
209 
218  enum class PWMPin : uint8_t
219  {
220  D11_PB3_OC0A = 0,
221  D12_PB4_OC0B,
222  D28_PD4_OC1B,
223  D29_PD5_OC1A,
224  D30_PD6_OC2B,
225  D31_PD7_OC2A,
226 
227 #ifdef __AVR_ATmega1284P__
228  D14_PB6_OC3A,
229  D15_PB7_OC3B,
230 #endif
231  // FastArduino internal: DO NOT USE
232  NONE = UINT8_MAX
233  };
234 
243  enum class ExternalInterruptPin : uint8_t
244  {
245  D26_PD2_EXT0 = 0,
246  D27_PD3_EXT1,
247  D10_PB2_EXT2
248  };
249 
258  enum class InterruptPin : uint8_t
259  {
260  // PA0-7
261  D0_PA0_PCI0 = uint8_t(DigitalPin::D0_PA0),
262  D1_PA1_PCI0 = uint8_t(DigitalPin::D1_PA1),
263  D2_PA2_PCI0 = uint8_t(DigitalPin::D2_PA2),
264  D3_PA3_PCI0 = uint8_t(DigitalPin::D3_PA3),
265  D4_PA4_PCI0 = uint8_t(DigitalPin::D4_PA4),
266  D5_PA5_PCI0 = uint8_t(DigitalPin::D5_PA5),
267  D6_PA6_PCI0 = uint8_t(DigitalPin::D6_PA6),
268  D7_PA7_PCI0 = uint8_t(DigitalPin::D7_PA7),
269 
270  // PB0-7
271  D8_PB0_PCI1 = uint8_t(DigitalPin::D8_PB0),
272  D9_PB1_PCI1 = uint8_t(DigitalPin::D9_PB1),
273  D10_PB2_PCI1 = uint8_t(DigitalPin::D10_PB2),
274  D11_PB3_PCI1 = uint8_t(DigitalPin::D11_PB3),
275  D12_PB4_PCI1 = uint8_t(DigitalPin::D12_PB4),
276  D13_PB5_PCI1 = uint8_t(DigitalPin::D13_PB5),
277  D14_PB6_PCI1 = uint8_t(DigitalPin::D14_PB6),
278  D15_PB7_PCI1 = uint8_t(DigitalPin::D15_PB7),
279 
280  // PC0-7
281  D16_PC0_PCI2 = uint8_t(DigitalPin::D16_PC0),
282  D17_PC1_PCI2 = uint8_t(DigitalPin::D17_PC1),
283  D18_PC2_PCI2 = uint8_t(DigitalPin::D18_PC2),
284  D19_PC3_PCI2 = uint8_t(DigitalPin::D19_PC3),
285  D20_PC4_PCI2 = uint8_t(DigitalPin::D20_PC4),
286  D21_PC5_PCI2 = uint8_t(DigitalPin::D21_PC5),
287  D22_PC6_PCI2 = uint8_t(DigitalPin::D22_PC6),
288  D23_PC7_PCI2 = uint8_t(DigitalPin::D23_PC7),
289 
290  // PD0-7
291  D24_PD0_PCI3 = uint8_t(DigitalPin::D24_PD0),
292  D25_PD1_PCI3 = uint8_t(DigitalPin::D25_PD1),
293  D26_PD2_PCI3 = uint8_t(DigitalPin::D26_PD2),
294  D27_PD3_PCI3 = uint8_t(DigitalPin::D27_PD3),
295  D28_PD4_PCI3 = uint8_t(DigitalPin::D28_PD4),
296  D29_PD5_PCI3 = uint8_t(DigitalPin::D29_PD5),
297  D30_PD6_PCI3 = uint8_t(DigitalPin::D30_PD6),
298  D31_PD7_PCI3 = uint8_t(DigitalPin::D31_PD7),
299  };
300 
304  enum class USART: uint8_t
305  {
307  USART0 = 0,
309  USART1 = 1
310  };
311 
315  enum class Timer: uint8_t
316  {
318  TIMER0 = 0,
320  TIMER1 = 1,
322  TIMER2 = 2,
323 #ifdef __AVR_ATmega1284P__
324 
325  TIMER3 = 3
326 #endif
327  };
328 
332  enum class SleepMode: uint8_t
333  {
339  IDLE = SLEEP_MODE_IDLE,
344  ADC_NOISE_REDUCTION = SLEEP_MODE_ADC,
354  POWER_DOWN = SLEEP_MODE_PWR_DOWN,
362  POWER_SAVE = SLEEP_MODE_PWR_SAVE,
367  STANDBY = SLEEP_MODE_STANDBY,
372  EXTENDED_STANDBY = SLEEP_MODE_EXT_STANDBY
373  };
374 };
375 
377 // Forward declare interrupt service routines to allow them as friends.
378 extern "C" {
379  void ADC_vect(void) SIGNAL;
380  void ANALOG_COMP_vect(void) SIGNAL;
381  void INT0_vect(void) SIGNAL;
382  void INT1_vect(void) SIGNAL;
383  void INT2_vect(void) SIGNAL;
384  void PCINT0_vect(void) SIGNAL;
385  void PCINT1_vect(void) SIGNAL;
386  void PCINT2_vect(void) SIGNAL;
387  void PCINT3_vect(void) SIGNAL;
388  void SPI_STC_vect(void) SIGNAL;
389  void TIMER0_COMPA_vect(void) SIGNAL;
390  void TIMER0_COMPB_vect(void) SIGNAL;
391  void TIMER0_OVF_vect(void) SIGNAL;
392  void TIMER1_COMPA_vect(void) SIGNAL;
393  void TIMER1_COMPB_vect(void) SIGNAL;
394  void TIMER1_OVF_vect(void) SIGNAL;
395  void TIMER1_CAPT_vect(void) SIGNAL;
396  void TIMER2_COMPA_vect(void) SIGNAL;
397  void TIMER2_COMPB_vect(void) SIGNAL;
398  void TIMER2_OVF_vect(void) SIGNAL;
399  void TWI_vect(void) SIGNAL;
400  void WDT_vect(void) SIGNAL;
401  void USART0_UDRE_vect(void) SIGNAL;
402  void USART0_RX_vect(void) SIGNAL;
403  void USART0_TX_vect(void) SIGNAL;
404  void USART1_UDRE_vect(void) SIGNAL;
405  void USART1_RX_vect(void) SIGNAL;
406  void USART1_TX_vect(void) SIGNAL;
407  void EE_READY_vect(void) SIGNAL;
408 }
410 #endif /* BOARDS_ATMEGA_XX4_HH */
411 
board::Timer
Timer
Defines all timers available for ATmega644.
Definition: atmega_xx4.h:316
board::AnalogPin
AnalogPin
Defines all available analog input pins of ATmega644, with reference to Arduino MEGA pins.
Definition: atmega_xx4.h:187
board::AnalogReference
AnalogReference
Defines available voltage references of ATmega644, used for analog input.
Definition: atmega_xx4.h:167
board::ExternalInterruptPin
ExternalInterruptPin
Defines all digital output pins of ATmega644, usable as direct external interrupt pins.
Definition: atmega_xx4.h:244
board::Timer::TIMER0
@ TIMER0
Timer0 (8 bits)
board::USART
USART
Defines all USART modules of ATmega644.
Definition: atmega_xx4.h:305
board::init
static void init()
Performs special initialization for ATmega644, actually nothing at all.
Definition: atmega_xx4.h:49
board::USART::USART0
@ USART0
USART0 is connected to pins D24_PD0 (RX0) and D25_PD1 (TX0).
board::SleepMode::IDLE
@ IDLE
In this mode, CPU is stopped but all other peripherals and interrupts work normally.
board::PWMPin
PWMPin
Defines all digital output pins of ATmega644, capable of PWM output.
Definition: atmega_xx4.h:219
board
Defines all types and constants specific to support Arduino MEGA board (ATmega644 MCU target).
Definition: atmega_xx4.h:39
board::AnalogReference::AREF
@ AREF
Voltage reference is given by the AREF pin.
board::Port::PORT_A
@ PORT_A
Port A (8 IO)
board::SleepMode
SleepMode
Defines all available sleep modes for ATmega644.
Definition: atmega_xx4.h:333
board::InterruptPin
InterruptPin
Defines all digital output pins of ATmega644, usable as pin change interrupt (PCI) pins.
Definition: atmega_xx4.h:259
board::Port
Port
Defines all available ports of ATmega644.
Definition: atmega_xx4.h:55
SIGNAL
#define SIGNAL
Specific GCC attribute for AVR target, declaring a function as a signal handler (aka ISR,...
Definition: defines.h:78
board::SleepMode::POWER_DOWN
@ POWER_DOWN
In this mode, everything is stopped (including oscillator) but external interrupts,...
board::AnalogPin::BANDGAP
@ BANDGAP
Bandgap reference.
board::AnalogClock
AnalogClock
Defines available clocks of ATmega644, used for analog input.
Definition: atmega_xx4.h:155
board::DigitalPin
DigitalPin
Defines all available digital input/output pins of ATmega644, with reference to Arduino MEGA pins.
Definition: atmega_xx4.h:76