COSA
An Object-Oriented Platform for Arduino Programming
ATtinyX4.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_BOARD_ARDUINO_ATTINYX4_HH
22 #define COSA_BOARD_ARDUINO_ATTINYX4_HH
23 
24 /* This board is based on ATtinyX4/ATtiny */
25 #define BOARD_ATTINYX4
26 #define BOARD_ATTINY
27 
54 class Board {
55  friend class Pin;
56  friend class GPIO;
57 private:
61  Board() {}
62 
68  static volatile uint8_t* SFR(uint8_t pin)
69  __attribute__((always_inline))
70  {
71  return (pin < 8 ? &PINA : &PINB);
72  }
73 
80  static uint8_t BIT(uint8_t pin)
81  __attribute__((always_inline))
82  {
83  return (pin < 8 ? pin : pin - 8);
84  }
85 
91  static volatile uint8_t* PCIMR(uint8_t pin)
92  __attribute__((always_inline))
93  {
94  return (pin < 8 ? &PCMSK0 : &PCMSK1);
95  }
96 
101  static volatile uint8_t* USI()
102  __attribute__((always_inline))
103  {
104  return (&PINA);
105  }
106 
107 public:
111  static void init() {}
112 
116  enum DigitalPin {
117  D0 = 0, // PA0
118  D1, // PA1
119  D2, // PA2
120  D3, // PA3
121  D4, // PA4
122  D5, // PA5
123  D6, // PA6
124  D7, // PA7
125  D8, // PB0
126  D9, // PB1
127  D10, // PB2
128  LED = D7
129  } __attribute__((packed));
130 
134  enum AnalogPin {
135  A0 = 0, // PA0/D0
136  A1, // PA1/D1
137  A2, // PA2/D2
138  A3, // PA3/D3
139  A4, // PA4/D4
140  A5, // PA5/D5
141  A6, // PA6/D6
142  A7 // PA7/D7
143  } __attribute__((packed));
144 
148  enum Reference {
149  AVCC_REFERENCE = 0,
150  APIN_REFERENCE = _BV(REFS0),
151  A1V1_REFERENCE = _BV(REFS1)
152  } __attribute__((packed));
153 
158  enum PWMPin {
159  PWM0 = D10, // PB2 => OCR0A
160  PWM1 = D7, // PA7 => OCR0B
161  PWM2 = D6, // PA6 => OCR1A
162  PWM3 = D5 // PA5 => OCR1B
163  } __attribute__((packed));
164 
170  EXT0 = D10 // PB2
171  } __attribute__((packed));
172 
177  PCI0 = D0, // PA0
178  PCI1 = D1, // PA1
179  PCI2 = D2, // PA2
180  PCI3 = D3, // PA3
181  PCI4 = D4, // PA4
182  PCI5 = D5, // PA5
183  PCI6 = D6, // PA6
184  PCI7 = D7, // PA7
185  PCI8 = D8, // PB0
186  PCI9 = D9, // PB1
187  PCI10 = D10 // PB2
188  } __attribute__((packed));
189 
193  enum {
194  ANALOG_PIN_MAX = 8,
195  DIGITAL_PIN_MAX = 11,
196  EXT_PIN_MAX = 1,
197  PCI_PIN_MAX = 11,
198  PWM_PIN_MAX = 4
199  };
200 
204  enum TWIPin {
205  SDA = 6, // PA6/D6
206  SCL = 4 // PA4/D4
207  } __attribute__((packed));
208 
212  enum SPIPin {
213  SS = 3, // PA3/D3
214  SCK = 4, // PA4/D4
215  MOSI = 5, // PA5/D5
216  MISO = 6 // PA6/D6
217  } __attribute__((packed));
218 
222  enum {
223  VBG = (_BV(MUX5) | _BV(MUX0)),
224  EXT_MAX = 1,
225  PCMSK_MAX = 2,
226  PCINT_MAX = 11
227  } __attribute__((packed));
228 };
229 
233 #define ANALOG_COMP_vect ANA_COMP_vect
234 #define TIMER0_OVF_vect TIM0_OVF_vect
235 #define TIMER0_COMPA_vect TIM0_COMPA_vect
236 #define TIMER0_COMPB_vect TIM0_COMPB_vect
237 #define TIMER1_OVF_vect TIM1_OVF_vect
238 #define TIMER1_COMPA_vect TIM1_COMPA_vect
239 #define TIMER1_COMPB_vect TIM1_COMPB_vect
240 
244 extern "C" {
245  void ADC_vect(void) __attribute__ ((signal));
246  void ANALOG_COMP_vect(void) __attribute__ ((signal));
247  void INT0_vect(void) __attribute__ ((signal));
248  void PCINT0_vect(void) __attribute__ ((signal));
249  void PCINT1_vect(void) __attribute__ ((signal));
250  void TIMER0_COMPA_vect(void) __attribute__ ((signal));
251  void TIMER0_COMPB_vect(void) __attribute__ ((signal));
252  void TIMER0_OVF_vect(void) __attribute__ ((signal));
253  void TIMER1_COMPA_vect(void) __attribute__ ((signal));
254  void TIMER1_COMPB_vect(void) __attribute__ ((signal));
255  void TIMER1_OVF_vect(void) __attribute__ ((signal));
256  void TIMER1_CAPT_vect(void) __attribute__ ((signal));
257  void WDT_vect(void) __attribute__ ((signal));
258  void USI_START_vect(void) __attribute__ ((signal));
259  void USI_OVF_vect(void) __attribute__ ((signal));
260 }
261 #endif
void INT0_vect(void)
void USI_START_vect(void)
void TIMER1_CAPT_vect(void)
Definition: Pin.hh:35
void PCINT1_vect(void)
#define TIMER0_COMPB_vect
Definition: ATtinyX4.hh:236
void ADC_vect(void)
void WDT_vect(void)
Definition: LED.hh:32
#define TIMER1_COMPB_vect
Definition: ATtinyX4.hh:239
void PCINT0_vect(void)
void USI_OVF_vect(void)
ExternalInterruptPin
Definition: ATmega1284P.hh:190
#define PCMSK0
Definition: ATtinyX5.hh:227
Definition: PWMPin.hh:29
Definition: GPIO.hh:30
#define TIMER0_OVF_vect
Definition: ATtinyX4.hh:234
#define TIMER1_OVF_vect
Definition: ATtinyX4.hh:237
static void init()
Definition: ATtinyX4.hh:111
#define TIMER1_COMPA_vect
Definition: ATtinyX4.hh:238
#define ANALOG_COMP_vect
Definition: ATtinyX4.hh:233
#define TIMER0_COMPA_vect
Definition: ATtinyX4.hh:235