FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
atmega_xx4.h
1// Copyright 2016-2023 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
33
38namespace 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,
177 INTERNAL_2_56V
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__
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.
378extern "C" {
379 void ADC_vect(void) SIGNAL_HANDLER;
380 void ANALOG_COMP_vect(void) SIGNAL_HANDLER;
381 void INT0_vect(void) SIGNAL_HANDLER;
382 void INT1_vect(void) SIGNAL_HANDLER;
383 void INT2_vect(void) SIGNAL_HANDLER;
384 void PCINT0_vect(void) SIGNAL_HANDLER;
385 void PCINT1_vect(void) SIGNAL_HANDLER;
386 void PCINT2_vect(void) SIGNAL_HANDLER;
387 void PCINT3_vect(void) SIGNAL_HANDLER;
388 void SPI_STC_vect(void) SIGNAL_HANDLER;
389 void TIMER0_COMPA_vect(void) SIGNAL_HANDLER;
390 void TIMER0_COMPB_vect(void) SIGNAL_HANDLER;
391 void TIMER0_OVF_vect(void) SIGNAL_HANDLER;
392 void TIMER1_COMPA_vect(void) SIGNAL_HANDLER;
393 void TIMER1_COMPB_vect(void) SIGNAL_HANDLER;
394 void TIMER1_OVF_vect(void) SIGNAL_HANDLER;
395 void TIMER1_CAPT_vect(void) SIGNAL_HANDLER;
396 void TIMER2_COMPA_vect(void) SIGNAL_HANDLER;
397 void TIMER2_COMPB_vect(void) SIGNAL_HANDLER;
398 void TIMER2_OVF_vect(void) SIGNAL_HANDLER;
399 void TWI_vect(void) SIGNAL_HANDLER;
400 void WDT_vect(void) SIGNAL_HANDLER;
401 void USART0_UDRE_vect(void) SIGNAL_HANDLER;
402 void USART0_RX_vect(void) SIGNAL_HANDLER;
403 void USART0_TX_vect(void) SIGNAL_HANDLER;
404 void USART1_UDRE_vect(void) SIGNAL_HANDLER;
405 void USART1_RX_vect(void) SIGNAL_HANDLER;
406 void USART1_TX_vect(void) SIGNAL_HANDLER;
407 void EE_READY_vect(void) SIGNAL_HANDLER;
408}
410#endif /* BOARDS_ATMEGA_XX4_HH */
#define SIGNAL_HANDLER
Specific GCC attribute for AVR target, declaring a function as a signal handler (aka ISR,...
Definition: defines.h:73
@ NONE
No interrupt will be generated by the Anolog Comparator.
Defines all types and constants specific to support a specific MCU target.
Definition: empty.h:38
PWMPin
Defines all digital output pins of target MCU, capable of PWM output.
Definition: empty.h:84
Port
Defines all available ports of the target MCU.
Definition: empty.h:49
static void init()
Performs special initialization for the target MCU.
Definition: empty.h:43
DigitalPin
Defines all available digital input/output pins of the target MCU.
Definition: empty.h:56
AnalogClock
Defines available clocks of the target MCU, used for analog input.
Definition: empty.h:63
AnalogPin
Defines all available analog input pins of the target MCU.
Definition: empty.h:77
InterruptPin
Defines all digital output pins of target MCU, usable as pin change interrupt (PCI) pins.
Definition: empty.h:98
USART
Defines all USART modules of target MCU.
Definition: empty.h:105
Timer
Defines all timers available for target MCU.
Definition: empty.h:112
ExternalInterruptPin
Defines all digital output pins of target MCU, usable as direct external interrupt pins.
Definition: empty.h:91
SleepMode
Defines all available sleep modes for target MCU.
Definition: empty.h:119
AnalogReference
Defines available voltage references of the target MCU, used for analog input.
Definition: empty.h:70
@ PORT_A
The A port of MCP23017.
@ PORT_B
The B port of MCP23017.