FastArduino - ATtinyX5 Support v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
attiny_x5.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_ATTINYX5_HH
23#define BOARDS_ATTINYX5_HH
24
25#include "io.h"
26#include "../defines.h"
27#include <avr/sleep.h>
28
30/* This board is based on ATtinyX5/ATtiny */
31#define BOARDS_ATTINYX5
32#define BOARD_ATTINY
34
38namespace board
39{
49 inline static void init() {}
50
54 enum class Port: uint8_t
55 {
57 PORT_B = 0,
58 // FastArduino internal: DO NOT USE
59 NONE = UINT8_MAX
60 };
61
69 enum class DigitalPin: uint8_t
70 {
72 D0_PB0 = 0,
74 D1_PB1,
76 D2_PB2,
78 D3_PB3,
80 D4_PB4,
82 LED = D0_PB0,
83 // FastArduino internal: DO NOT USE
84 NONE = UINT8_MAX
85 };
86
90 enum class AnalogClock: uint8_t
91 {
92 MAX_FREQ_50KHz = 0,
93 MAX_FREQ_100KHz,
94 MAX_FREQ_200KHz,
95 MAX_FREQ_500KHz,
96 MAX_FREQ_1MHz
97 };
98
102 enum class AnalogReference: uint8_t
103 {
105 AREF = 0,
107 AVCC,
123 };
124
131 enum class AnalogPin: uint8_t
132 {
134 A1 = 0,
136 A2,
138 A3,
140 BANDGAP,
142 GND,
144 TEMP,
145 // FastArduino internal: DO NOT USE
146 NONE = UINT8_MAX
147 };
148
157 enum class PWMPin : uint8_t
158 {
159 D0_PB0_OC0A = 0,
160 D1_PB1_OC0B,
161 //TODO Currently PWM for Timer1 is not supported (setup is too much
162 // different compared to other MCU, even ATtinyX4)
163 // constexpr const DigitalPin D4_PB4_OC1B = DigitalPin::D4_PB4;
164 // FastArduino internal: DO NOT USE
165 NONE = UINT8_MAX
166 };
167
176 enum class ExternalInterruptPin : uint8_t
177 {
178 D2_PB2_EXT0 = 0
179 };
180
189 enum class InterruptPin : uint8_t
190 {
191 D0_PB0_PCI0 = uint8_t(DigitalPin::D0_PB0),
192 D1_PB1_PCI0 = uint8_t(DigitalPin::D1_PB1),
193 D2_PB2_PCI0 = uint8_t(DigitalPin::D2_PB2),
194 D3_PB3_PCI0 = uint8_t(DigitalPin::D3_PB3),
195 D4_PB4_PCI0 = uint8_t(DigitalPin::D4_PB4)
196 };
197
201 enum class USART: uint8_t
202 {
203 };
204
208 enum class Timer: uint8_t
209 {
211 TIMER0 = 0,
213 TIMER1 = 1
214 };
215
219 enum class SleepMode: uint8_t
220 {
226 IDLE = SLEEP_MODE_IDLE,
231 ADC_NOISE_REDUCTION = SLEEP_MODE_ADC,
241 POWER_DOWN = SLEEP_MODE_PWR_DOWN,
245 POWER_SAVE = SLEEP_MODE_PWR_DOWN,
249 STANDBY = SLEEP_MODE_PWR_DOWN,
253 EXTENDED_STANDBY = SLEEP_MODE_PWR_DOWN
254 };
255};
256
258#define ANALOG_COMP_vect ANA_COMP_vect
259#define EE_READY_vect EE_RDY_vect
260
261// Forward declare interrupt service routines to allow them as friends.
262extern "C" {
263 void ADC_vect(void) SIGNAL_HANDLER;
264 void ANALOG_COMP_vect(void) SIGNAL_HANDLER;
265 void INT0_vect(void) SIGNAL_HANDLER;
266 void PCINT0_vect(void) SIGNAL_HANDLER;
267 void TIMER0_COMPA_vect(void) SIGNAL_HANDLER;
268 void TIMER0_COMPB_vect(void) SIGNAL_HANDLER;
269 void TIMER0_OVF_vect(void) SIGNAL_HANDLER;
270 void TIMER1_COMPA_vect(void) SIGNAL_HANDLER;
271 void TIMER1_COMPB_vect(void) SIGNAL_HANDLER;
272 void TIMER1_OVF_vect(void) SIGNAL_HANDLER;
273 void WDT_vect(void) SIGNAL_HANDLER;
274 void USI_START_vect(void) SIGNAL_HANDLER;
275 void USI_OVF_vect(void) SIGNAL_HANDLER;
276 void EE_READY_vect(void) SIGNAL_HANDLER;
277}
279
280#endif /* BOARDS_ATTINYX5_HH */
Defines all types and constants specific to support ATtinyX5 MCU targets.
Definition: attiny_x5.h:39
PWMPin
Defines all digital output pins of ATtinyX5, capable of PWM output.
Definition: attiny_x5.h:158
Port
Defines all available ports of ATtinyX5.
Definition: attiny_x5.h:55
@ PORT_B
Port B (5 IO)
static void init()
Performs special initialization for ATtinyX5, actually nothing at all.
Definition: attiny_x5.h:49
DigitalPin
Defines all available digital input/output pins of ATtinyX5, with additional pin imaginary numbering ...
Definition: attiny_x5.h:70
@ D1_PB1
Pin PB1 (D1)
@ D0_PB0
Pin PB0 (D0)
@ D4_PB4
Pin PB4 (D4)
@ LED
Shortcut for LED pin, arbitrarily chosen to be D0.
@ D3_PB3
Pin PB3 (D3)
@ D2_PB2
Pin PB2 (D2)
AnalogClock
Defines available clocks of ATtinyX5, used for analog input.
Definition: attiny_x5.h:91
AnalogPin
Defines all available analog input pins of ATtinyX5, with reference to ATtinyX5 pins.
Definition: attiny_x5.h:132
@ A1
Pin ADC1 (PB2)
@ A3
Pin ADC3 (PB3)
@ TEMP
Temperature sensor.
@ A2
Pin ADC2 (PB4)
@ BANDGAP
Bandgap reference.
@ GND
Ground reference.
InterruptPin
Defines all digital output pins of ATtinyX5, usable as pin change interrupt (PCI) pins.
Definition: attiny_x5.h:190
USART
Defines all USART modules of ATtinyX5, actually none at all.
Definition: attiny_x5.h:202
Timer
Defines all timers available for ATtinyX5.
Definition: attiny_x5.h:209
@ TIMER1
Timer1 (8 bits)
@ TIMER0
Timer0 (8 bits)
ExternalInterruptPin
Defines all digital output pins of ATtinyX5, usable as direct external interrupt pins.
Definition: attiny_x5.h:177
SleepMode
Defines all available sleep modes for ATmega328P.
Definition: attiny_x5.h:220
@ 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 exactly the same POWER_DOWN.
AnalogReference
Defines available voltage references of ATtinyX5, used for analog input.
Definition: attiny_x5.h:103
@ INTERNAL_2_56V
Voltage reference is internal 2.56V reference, without external bypass capacitor, disconnected from P...
@ INTERNAL_1_1V
Voltage reference is internal 1.1V reference, generated from the internal bandgap reference.
@ AREF
Voltage reference is given by the AREF (PB0) pin.
@ AVCC
Voltage reference is given by the Vcc pin.
@ INTERNAL_2_56V_BYPASS_CAP
Voltage reference is internal 2.56V reference, with external bypass capacitor at PB0 (AREF).