FastArduino - ATtinyX4 Support v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
attiny_x4.h
Go to the documentation of this file.
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_ATTINYX4_HH
23#define BOARDS_ATTINYX4_HH
24
25#include "io.h"
26#include "../bits.h"
27#include "../defines.h"
28#include <avr/sleep.h>
29
31/* This board is based on ATtinyX4/ATtiny */
32#define BOARDS_ATTINYX4
33#define BOARD_ATTINY
35
39namespace board
40{
50 inline static void init() {}
51
55 enum class Port: uint8_t
56 {
58 PORT_A = 0,
60 PORT_B,
61 // FastArduino internal: DO NOT USE
62 NONE = UINT8_MAX
63 };
64
72 enum class DigitalPin: uint8_t
73 {
75 D0_PA0 = 0,
77 D1_PA1,
79 D2_PA2,
81 D3_PA3,
83 D4_PA4,
85 D5_PA5,
87 D6_PA6,
89 D7_PA7,
91 D8_PB0,
93 D9_PB1,
95 D10_PB2,
97 LED = D7_PA7,
98 // FastArduino internal: DO NOT USE
99 NONE = UINT8_MAX
100 };
101
105 enum class AnalogClock: uint8_t
106 {
107 MAX_FREQ_50KHz = 0,
108 MAX_FREQ_100KHz,
109 MAX_FREQ_200KHz,
110 MAX_FREQ_500KHz,
111 MAX_FREQ_1MHz
112 };
113
117 enum class AnalogReference: uint8_t
118 {
120 AREF = 0,
122 AVCC,
126 };
127
134 enum class AnalogPin: uint8_t
135 {
137 A0 = 0,
139 A1,
141 A2,
143 A3,
145 A4,
147 A5,
149 A6,
151 A7,
153 TEMP,
155 BANDGAP,
156 // FastArduino internal: DO NOT USE
157 NONE = UINT8_MAX
158 };
159
168 enum class PWMPin : uint8_t
169 {
170 D10_PB2_OC0A = 0,
171 D7_PA7_OC0B,
172 D6_PA6_OC1A,
173 D5_PA5_OC1B,
174 // FastArduino internal: DO NOT USE
175 NONE = UINT8_MAX
176 };
177
186 enum class ExternalInterruptPin : uint8_t
187 {
188 D10_PB2_EXT0 = 0
189 };
190
199 enum class InterruptPin : uint8_t
200 {
201 D0_PA0_PCI0 = uint8_t(DigitalPin::D0_PA0),
202 D1_PA1_PCI0 = uint8_t(DigitalPin::D1_PA1),
203 D2_PA2_PCI0 = uint8_t(DigitalPin::D2_PA2),
204 D3_PA3_PCI0 = uint8_t(DigitalPin::D3_PA3),
205 D4_PA4_PCI0 = uint8_t(DigitalPin::D4_PA4),
206 D5_PA5_PCI0 = uint8_t(DigitalPin::D5_PA5),
207 D6_PA6_PCI0 = uint8_t(DigitalPin::D6_PA6),
208 D7_PA7_PCI0 = uint8_t(DigitalPin::D7_PA7),
209
210 D8_PB0_PCI1 = uint8_t(DigitalPin::D8_PB0),
211 D9_PB1_PCI1 = uint8_t(DigitalPin::D9_PB1),
212 D10_PB2_PCI1 = uint8_t(DigitalPin::D10_PB2)
213 };
214
218 enum class USART: uint8_t
219 {
220 };
221
222 // IMPORTANT: on my setup, Timer runs faster than expected (9.5s for 10s)
223 //TODO check how we can calibrate clock?
227 enum class Timer: uint8_t
228 {
230 TIMER0 = 0,
232 TIMER1 = 1
233 };
234
236 #define SLEEP_MODE_PWR_SAVE (bits::BV8(SM0, SM1))
238
242 enum class SleepMode: uint8_t
243 {
249 IDLE = SLEEP_MODE_IDLE,
254 ADC_NOISE_REDUCTION = SLEEP_MODE_ADC,
264 POWER_DOWN = SLEEP_MODE_PWR_DOWN,
272 POWER_SAVE = SLEEP_MODE_PWR_SAVE,
276 STANDBY = SLEEP_MODE_PWR_SAVE,
280 EXTENDED_STANDBY = SLEEP_MODE_PWR_SAVE
281 };
282};
283
285#define ANALOG_COMP_vect ANA_COMP_vect
286#define TIMER0_OVF_vect TIM0_OVF_vect
287#define TIMER0_COMPA_vect TIM0_COMPA_vect
288#define TIMER0_COMPB_vect TIM0_COMPB_vect
289#define TIMER1_OVF_vect TIM1_OVF_vect
290#define TIMER1_COMPA_vect TIM1_COMPA_vect
291#define TIMER1_COMPB_vect TIM1_COMPB_vect
292#define EE_READY_vect EE_RDY_vect
293
294// Forward declare interrupt service routines to allow them as friends.
295extern "C" {
296 void ADC_vect(void) SIGNAL_HANDLER;
297 void ANALOG_COMP_vect(void) SIGNAL_HANDLER;
298 void INT0_vect(void) SIGNAL_HANDLER;
299 void PCINT0_vect(void) SIGNAL_HANDLER;
300 void PCINT1_vect(void) SIGNAL_HANDLER;
301 void TIMER0_COMPA_vect(void) SIGNAL_HANDLER;
302 void TIMER0_COMPB_vect(void) SIGNAL_HANDLER;
303 void TIMER0_OVF_vect(void) SIGNAL_HANDLER;
304 void TIMER1_COMPA_vect(void) SIGNAL_HANDLER;
305 void TIMER1_COMPB_vect(void) SIGNAL_HANDLER;
306 void TIMER1_OVF_vect(void) SIGNAL_HANDLER;
307 void TIMER1_CAPT_vect(void) SIGNAL_HANDLER;
308 void WDT_vect(void) SIGNAL_HANDLER;
309 void USI_START_vect(void) SIGNAL_HANDLER;
310 void USI_OVF_vect(void) SIGNAL_HANDLER;
311 void EE_READY_vect(void) SIGNAL_HANDLER;
312}
314
315#endif /* BOARDS_ATTINYX4_HH */
Defines all types and constants specific to support ATtinyX4 MCU targets.
Definition: attiny_x4.h:40
PWMPin
Defines all digital output pins of ATtinyX4, capable of PWM output.
Definition: attiny_x4.h:169
Port
Defines all available ports of ATtinyX4.
Definition: attiny_x4.h:56
@ PORT_A
Port A (8 IO)
@ PORT_B
Port B (3 IO)
static void init()
Performs special initialization for ATtinyX4, actually nothing at all.
Definition: attiny_x4.h:50
DigitalPin
Defines all available digital input/output pins of ATtinyX4, with additional pin imaginary numbering ...
Definition: attiny_x4.h:73
@ D0_PA0
Pin PA0 (D0)
@ D2_PA2
Pin PA2 (D2)
@ D3_PA3
Pin PA3 (D3)
@ D8_PB0
Pin PB0 (D8)
@ LED
Shortcut for LED pin, arbitrarily chosen to be D7.
@ D1_PA1
Pin PA1 (D1)
@ D7_PA7
Pin PA6 (D7)
@ D4_PA4
Pin PA4 (D4)
@ D9_PB1
Pin PB1 (D9)
@ D5_PA5
Pin PA5 (D5)
@ D10_PB2
Pin PB2 (D10)
@ D6_PA6
Pin PA6 (D6)
AnalogClock
Defines available clocks of ATtinyX4, used for analog input.
Definition: attiny_x4.h:106
AnalogPin
Defines all available analog input pins of ATtinyX4, with reference to AVR ATtinyX4 pins.
Definition: attiny_x4.h:135
@ A6
Pin ADC6 (PA6)
@ A4
Pin ADC4 (PA4)
@ A1
Pin ADC1 (PA1)
@ A3
Pin ADC3 (PA3)
@ TEMP
Temperature sensor.
@ A7
Pin ADC7 (PA7)
@ A2
Pin ADC2 (PA2)
@ A5
Pin ADC5 (PA5)
@ A0
Pin ADC0 (PA0)
@ BANDGAP
Bandgap reference.
InterruptPin
Defines all digital output pins of ATtinyX4, usable as pin change interrupt (PCI) pins.
Definition: attiny_x4.h:200
USART
Defines all USART modules of ATtinyX4, actually none at all.
Definition: attiny_x4.h:219
Timer
Defines all timers available for ATtinyX4.
Definition: attiny_x4.h:228
@ TIMER1
Timer1 (16 bits)
@ TIMER0
Timer0 (8 bits)
ExternalInterruptPin
Defines all digital output pins of ATtinyX4, usable as direct external interrupt pins.
Definition: attiny_x4.h:187
SleepMode
Defines all available sleep modes for ATmega328P.
Definition: attiny_x4.h:243
@ EXTENDED_STANDBY
This mode is exactly the same POWER_SAVE.
@ ADC_NOISE_REDUCTION
In this mode, CPU is stopped but other peripherals and interrupts work normally, except IO.
@ POWER_DOWN
In this mode, everything is stopped (including oscillator) but external interrupts,...
@ IDLE
In this mode, CPU is stopped but all other peripherals and interrupts work normally.
@ STANDBY
This mode is exactly the same POWER_DOWN.
@ POWER_SAVE
This mode is similar to POWER_DOWN, except Timer2 is still running if enabled.
AnalogReference
Defines available voltage references of ATtinyX4, used for analog input.
Definition: attiny_x4.h:118
@ INTERNAL_1_1V
Voltage reference is internal 1.1V reference, generated from the internal bandgap reference.
@ AREF
Voltage reference is given by the AREF (PA0) pin.
@ AVCC
Voltage reference is given by the Vcc pin.