AberLED shield library
Library for the bicolor LED (and TFT screen) shield used in CS12020
TFT_FastPin.h
Go to the documentation of this file.
1 //
2 // This template library is from FastLED http://fastled.io
3 //
4 
5 /*
6 
7 The MIT License (MIT)
8 
9 Copyright (c) 2013 FastLED
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy of
12 this software and associated documentation files (the "Software"), to deal in
13 the Software without restriction, including without limitation the rights to
14 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15 the Software, and to permit persons to whom the Software is furnished to do so,
16 subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
23 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
24 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 
28 */
29 
30 #ifndef __INC_FASTPIN_H
31 #define __INC_FASTPIN_H
32 
33 #include<avr/io.h>
34 
35 // Arduino.h needed for convinience functions digitalPinToPort/BitMask/portOutputRegister and the pinMode methods.
36 #include<Arduino.h>
37 
38 #define NO_PIN 255
39 
40 // Class to ensure that a minimum amount of time has kicked since the last time run - and delay if not enough time has passed yet
41 // this should make sure that chipsets that have
42 template<int FASTPIN_WAIT> class CMinWait {
43  long mLastMicros;
44 public:
45  CMinWait() { mLastMicros = 0; }
46 
47  void wait() {
48  long diff = micros() - mLastMicros;
49  while(diff < FASTPIN_WAIT) {
50  diff = micros() - mLastMicros;
51  }
52  }
53 
54  void mark() { mLastMicros = micros(); }
55 };
56 
57 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 //
59 // Pin access class - needs to tune for various platforms (naive fallback solution?)
60 //
61 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 
63 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
64 #define _CYCLES(_PIN) (((_PIN >= 62 ) || (_PIN>=42 && _PIN<=49) || (_PIN>=14 && _PIN <=17) || (_PIN>=6 && _PIN <=9)) ? 2 : 1)
65 #else
66 #define _CYCLES(_PIN) ((_PIN >= 24) ? 2 : 1)
67 #endif
68 
69 class Selectable {
70 public:
71  virtual void select() = 0;
72  virtual void release() = 0;
73  virtual bool isSelected() = 0;
74 };
75 
76 class Pin : public Selectable {
77  uint8_t mPinMask;
78  uint8_t mPin;
79  volatile uint8_t *mPort;
80 
81  void _init() {
82  mPinMask = digitalPinToBitMask(mPin);
83  mPort = portOutputRegister(digitalPinToPort(mPin));
84  }
85 public:
86  Pin(int pin) : mPin(pin) { _init(); }
87 
88  typedef volatile uint8_t * port_ptr_t;
89  typedef uint8_t port_t;
90 
91  inline void setOutput() { pinMode(mPin, OUTPUT); }
92  inline void setInput() { pinMode(mPin, INPUT); }
93 
94  inline void hi() __attribute__ ((always_inline)) { *mPort |= mPinMask; }
95  inline void lo() __attribute__ ((always_inline)) { *mPort &= ~mPinMask; }
96 
97  inline void strobe() __attribute__ ((always_inline)) { hi(); lo(); }
98 
99  inline void hi(register port_ptr_t port) __attribute__ ((always_inline)) { *port |= mPinMask; }
100  inline void lo(register port_ptr_t port) __attribute__ ((always_inline)) { *port &= ~mPinMask; }
101  inline void set(register port_t val) __attribute__ ((always_inline)) { *mPort = val; }
102 
103  inline void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
104 
105  port_t hival() __attribute__ ((always_inline)) { return *mPort | mPinMask; }
106  port_t loval() __attribute__ ((always_inline)) { return *mPort & ~mPinMask; }
107  port_ptr_t port() __attribute__ ((always_inline)) { return mPort; }
108  port_t mask() __attribute__ ((always_inline)) { return mPinMask; }
109 
110  virtual void select() { hi(); }
111  virtual void release() { lo(); }
112  virtual bool isSelected() { return (*mPort & mPinMask) == mPinMask; }
113 };
114 
115 class OutputPin : public Pin {
116 public:
117  OutputPin(int pin) : Pin(pin) { setOutput(); }
118 };
119 
120 class InputPin : public Pin {
121 public:
122  InputPin(int pin) : Pin(pin) { setInput(); }
123 };
124 
125 /// The simplest level of Pin class. This relies on runtime functions durinig initialization to get the port/pin mask for the pin. Most
126 /// of the accesses involve references to these static globals that get set up. This won't be the fastest set of pin operations, but it
127 /// will provide pin level access on pretty much all arduino environments. In addition, it includes some methods to help optimize access in
128 /// various ways. Namely, the versions of hi, lo, and fastset that take the port register as a passed in register variable (saving a global
129 /// dereference), since these functions are aggressively inlined, that can help collapse out a lot of extraneous memory loads/dereferences.
130 ///
131 /// In addition, if, while writing a bunch of data to a pin, you know no other pins will be getting written to, you can get/cache a value of
132 /// the pin's port register and use that to do a full set to the register. This results in one being able to simply do a store to the register,
133 /// vs. the load, and/or, and store that would be done normally.
134 ///
135 /// There are platform specific instantiations of this class that provide direct i/o register access to pins for much higher speed pin twiddling.
136 ///
137 /// Note that these classes are all static functions. So the proper usage is Pin<13>::hi(); or such. Instantiating objects is not recommended,
138 /// as passing Pin objects around will likely -not- have the effect you're expecting.
139 template<uint8_t PIN> class FastPin {
140  static uint8_t sPinMask;
141  static volatile uint8_t *sPort;
142  static void _init() {
143  sPinMask = digitalPinToBitMask(PIN);
144  sPort = portOutputRegister(digitalPinToPort(PIN));
145  }
146 public:
147  typedef volatile uint8_t * port_ptr_t;
148  typedef uint8_t port_t;
149 
150  inline static void setOutput() { _init(); pinMode(PIN, OUTPUT); }
151  inline static void setInput() { _init(); pinMode(PIN, INPUT); }
152 
153  inline static void hi() __attribute__ ((always_inline)) { *sPort |= sPinMask; }
154  inline static void lo() __attribute__ ((always_inline)) { *sPort &= ~sPinMask; }
155 
156  inline static void strobe() __attribute__ ((always_inline)) { hi(); lo(); }
157 
158  inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { *port |= sPinMask; }
159  inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { *port &= ~sPinMask; }
160  inline static void set(register port_t val) __attribute__ ((always_inline)) { *sPort = val; }
161 
162  inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
163 
164  static port_t hival() __attribute__ ((always_inline)) { return *sPort | sPinMask; }
165  static port_t loval() __attribute__ ((always_inline)) { return *sPort & ~sPinMask; }
166  static port_ptr_t port() __attribute__ ((always_inline)) { return sPort; }
167  static port_t mask() __attribute__ ((always_inline)) { return sPinMask; }
168 };
169 
170 template<uint8_t PIN> uint8_t FastPin<PIN>::sPinMask;
171 template<uint8_t PIN> volatile uint8_t *FastPin<PIN>::sPort;
172 
173 /// Class definition for a Pin where we know the port registers at compile time for said pin. This allows us to make
174 /// a lot of optimizations, as the inlined hi/lo methods will devolve to a single io register write/bitset.
175 template<uint8_t PIN, uint8_t _MASK, typename _PORT, typename _DDR, typename _PIN> class _AVRPIN {
176 public:
177  typedef volatile uint8_t * port_ptr_t;
178  typedef uint8_t port_t;
179 
180  inline static void setOutput() { _DDR::r() |= _MASK; }
181  inline static void setInput() { _DDR::r() &= ~_MASK; }
182 
183  inline static void hi() __attribute__ ((always_inline)) { _PORT::r() |= _MASK; }
184  inline static void lo() __attribute__ ((always_inline)) { _PORT::r() &= ~_MASK; }
185  inline static void set(register uint8_t val) __attribute__ ((always_inline)) { _PORT::r() = val; }
186 
187  inline static void strobe() __attribute__ ((always_inline)) { hi(); lo(); }
188 
189  inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); }
190  inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); }
191  inline static void fastset(register port_ptr_t port, register uint8_t val) __attribute__ ((always_inline)) { set(val); }
192 
193  inline static port_t hival() __attribute__ ((always_inline)) { return _PORT::r() | _MASK; }
194  inline static port_t loval() __attribute__ ((always_inline)) { return _PORT::r() & ~_MASK; }
195  inline static port_ptr_t port() __attribute__ ((always_inline)) { return &_PORT::r(); }
196  inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; }
197 };
198 
199 /// Template definition for teensy 3.0 style ARM pins, providing direct access to the various GPIO registers. Note that this
200 /// uses the full port GPIO registers. In theory, in some way, bit-band register access -should- be faster, however I have found
201 /// that something about the way gcc does register allocation results in the bit-band code being slower. It will need more fine tuning.
202 template<uint8_t PIN, uint32_t _MASK, typename _PDOR, typename _PSOR, typename _PCOR, typename _PTOR, typename _PDIR, typename _PDDR> class _ARMPIN {
203 public:
204  typedef volatile uint32_t * port_ptr_t;
205  typedef uint32_t port_t;
206 
207  inline static void setOutput() { pinMode(PIN, OUTPUT); } // TODO: perform MUX config { _PDDR::r() |= _MASK; }
208  inline static void setInput() { pinMode(PIN, INPUT); } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; }
209 
210  inline static void hi() __attribute__ ((always_inline)) { _PSOR::r() = _MASK; }
211  inline static void lo() __attribute__ ((always_inline)) { _PCOR::r() = _MASK; }
212  inline static void set(register port_t val) __attribute__ ((always_inline)) { _PDOR::r() = val; }
213 
214  inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
215 
216  inline static void toggle() __attribute__ ((always_inline)) { _PTOR::r() = _MASK; }
217 
218  inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); }
219  inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); }
220  inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
221 
222  inline static port_t hival() __attribute__ ((always_inline)) { return _PDOR::r() | _MASK; }
223  inline static port_t loval() __attribute__ ((always_inline)) { return _PDOR::r() & ~_MASK; }
224  inline static port_ptr_t port() __attribute__ ((always_inline)) { return &_PDOR::r(); }
225  inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; }
226 };
227 
228 /// Template definition for teensy 3.0 style ARM pins using bit banding, providing direct access to the various GPIO registers. GCC
229 /// does a poor job of optimizing around these accesses so they are not being used just yet.
230 template<uint8_t PIN, int _BIT, typename _PDOR, typename _PSOR, typename _PCOR, typename _PTOR, typename _PDIR, typename _PDDR> class _ARMPIN_BITBAND {
231 public:
232  typedef volatile uint32_t * port_ptr_t;
233  typedef uint32_t port_t;
234 
235  inline static void setOutput() { pinMode(PIN, OUTPUT); } // TODO: perform MUX config { _PDDR::r() |= _MASK; }
236  inline static void setInput() { pinMode(PIN, INPUT); } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; }
237 
238  inline static void hi() __attribute__ ((always_inline)) { *_PDOR::template rx<_BIT>() = 1; }
239  inline static void lo() __attribute__ ((always_inline)) { *_PDOR::template rx<_BIT>() = 0; }
240  inline static void set(register port_t val) __attribute__ ((always_inline)) { *_PDOR::template rx<_BIT>() = val; }
241 
242  inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
243 
244  inline static void toggle() __attribute__ ((always_inline)) { *_PTOR::template rx<_BIT>() = 1; }
245 
246  inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { *port = 1; }
247  inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { *port = 0; }
248  inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
249 
250  inline static port_t hival() __attribute__ ((always_inline)) { return 1; }
251  inline static port_t loval() __attribute__ ((always_inline)) { return 0; }
252  inline static port_ptr_t port() __attribute__ ((always_inline)) { return _PDOR::template rx<_BIT>(); }
253  inline static port_t mask() __attribute__ ((always_inline)) { return 1; }
254 };
255 
256 /// AVR definitions for pins. Getting around the fact that I can't pass GPIO register addresses in as template arguments by instead creating
257 /// a custom type for each GPIO register with a single, static, aggressively inlined function that returns that specific GPIO register. A similar
258 /// trick is used a bit further below for the ARM GPIO registers (of which there are far more than on AVR!)
259 typedef volatile uint8_t & reg8_t;
260 #define _R(T) struct __gen_struct_ ## T
261 #define _RD8(T) struct __gen_struct_ ## T { static inline reg8_t r() { return T; }};
262 #define _IO(L) _RD8(DDR ## L); _RD8(PORT ## L); _RD8(PIN ## L);
263 #define _DEFPIN_AVR(PIN, MASK, L) template<> class FastPin<PIN> : public _AVRPIN<PIN, MASK, _R(PORT ## L), _R(DDR ## L), _R(PIN ## L)> {};
264 
265 // ARM definitions
266 #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
267 #define GPIO_BITBAND_PTR(reg, bit) ((uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
268 
269 typedef volatile uint32_t & reg32_t;
270 typedef volatile uint32_t * ptr_reg32_t;
271 
272 #define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline reg32_t r() { return T; } \
273  template<int BIT> static __attribute__((always_inline)) inline ptr_reg32_t rx() { return GPIO_BITBAND_PTR(T, BIT); } };
274 #define _IO32(L) _RD32(GPIO ## L ## _PDOR); _RD32(GPIO ## L ## _PSOR); _RD32(GPIO ## L ## _PCOR); _RD32(GPIO ## L ## _PTOR); _RD32(GPIO ## L ## _PDIR); _RD32(GPIO ## L ## _PDDR);
275 
276 #define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, 1 << BIT, _R(GPIO ## L ## _PDOR), _R(GPIO ## L ## _PSOR), _R(GPIO ## L ## _PCOR), \
277  _R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> {};
278 
279 // Don't use bit band'd pins for now, the compiler generates far less efficient code around them
280 // #define _DEFPIN_ARM(PIN, BIT, L) template<> class Pin<PIN> : public _ARMPIN_BITBAND<PIN, BIT, _R(GPIO ## L ## _PDOR), _R(GPIO ## L ## _PSOR), _R(GPIO ## L ## _PCOR),
281 // _R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> {};
282 
283 
284 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
285 //
286 // Pin definitions for AVR and ARM. If there are pin definitions supplied below for the platform being
287 // built on, then much higher speed access will be possible, namely with direct GPIO register accesses.
288 //
289 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
290 #if defined(FORCE_SOFTWARE_PINS)
291 #warning "Softwrae pin support forced pin access will be slightly slower. See fastpin.h for info."
292 #define NO_HARDWARE_PIN_SUPPORT
293 
294 #elif defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__)
295 _IO(B);
296 
297 _DEFPIN_AVR(0, 0x01, B); _DEFPIN_AVR(1, 0x02, B); _DEFPIN_AVR(2, 0x04, B); _DEFPIN_AVR(3, 0x08, B);
298 _DEFPIN_AVR(4, 0x10, B); _DEFPIN_AVR(5, 0x20, B);
299 
300 #elif(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__)
301 _IO(A); _IO(B);
302 
303 _DEFPIN_AVR(0, 0x01, A); _DEFPIN_AVR(1, 0x02, A); _DEFPIN_AVR(2, 0x04, A); _DEFPIN_AVR(3, 0x08, A);
304 _DEFPIN_AVR(4, 0x10, A); _DEFPIN_AVR(5, 0x20, A); _DEFPIN_AVR(6, 0x40, A); _DEFPIN_AVR(7, 0x80, A);
305 _DEFPIN_AVR(8, 0x04, B); _DEFPIN_AVR(9, 0x02, B); _DEFPIN_AVR(10, 0x01, B);
306 
307 #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
308 // Accelerated port definitions for arduino avrs
309 _IO(D); _IO(B); _IO(C);
310 _DEFPIN_AVR( 0, 0x01, D); _DEFPIN_AVR( 1, 0x02, D); _DEFPIN_AVR( 2, 0x04, D); _DEFPIN_AVR( 3, 0x08, D);
311 _DEFPIN_AVR( 4, 0x10, D); _DEFPIN_AVR( 5, 0x20, D); _DEFPIN_AVR( 6, 0x40, D); _DEFPIN_AVR( 7, 0x80, D);
312 _DEFPIN_AVR( 8, 0x01, B); _DEFPIN_AVR( 9, 0x02, B); _DEFPIN_AVR(10, 0x04, B); _DEFPIN_AVR(11, 0x08, B);
313 _DEFPIN_AVR(12, 0x10, B); _DEFPIN_AVR(13, 0x20, B); _DEFPIN_AVR(14, 0x01, C); _DEFPIN_AVR(15, 0x02, C);
314 _DEFPIN_AVR(16, 0x04, C); _DEFPIN_AVR(17, 0x08, C); _DEFPIN_AVR(18, 0x10, C); _DEFPIN_AVR(19, 0x20, C);
315 
316 #define SPI_DATA 11
317 #define SPI_CLOCK 13
318 #define SPI_SELECT 10
319 #define AVR_HARDWARE_SPI
320 
321 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
322 // megas
323 
324 _IO(A); _IO(B); _IO(C); _IO(D); _IO(E); _IO(F); _IO(G); _IO(H); _IO(J); _IO(K); _IO(L);
325 
326 _DEFPIN_AVR(0, 1, E); _DEFPIN_AVR(1, 2, E); _DEFPIN_AVR(2, 16, E); _DEFPIN_AVR(3, 32, E);
327 _DEFPIN_AVR(4, 32, G); _DEFPIN_AVR(5, 8, E); _DEFPIN_AVR(6, 8, H); _DEFPIN_AVR(7, 16, H);
328 _DEFPIN_AVR(8, 32, H); _DEFPIN_AVR(9, 64, H); _DEFPIN_AVR(10, 16, B); _DEFPIN_AVR(11, 32, B);
329 _DEFPIN_AVR(12, 64, B); _DEFPIN_AVR(13, 128, B); _DEFPIN_AVR(14, 2, J); _DEFPIN_AVR(15, 1, J);
330 _DEFPIN_AVR(16, 2, H); _DEFPIN_AVR(17, 1, H); _DEFPIN_AVR(18, 8, D); _DEFPIN_AVR(19, 4, D);
331 _DEFPIN_AVR(20, 2, D); _DEFPIN_AVR(21, 1, D); _DEFPIN_AVR(22, 1, A); _DEFPIN_AVR(23, 2, A);
332 _DEFPIN_AVR(24, 4, A); _DEFPIN_AVR(25, 8, A); _DEFPIN_AVR(26, 16, A); _DEFPIN_AVR(27, 32, A);
333 _DEFPIN_AVR(28, 64, A); _DEFPIN_AVR(29, 128, A); _DEFPIN_AVR(30, 128, C); _DEFPIN_AVR(31, 64, C);
334 _DEFPIN_AVR(32, 32, C); _DEFPIN_AVR(33, 16, C); _DEFPIN_AVR(34, 8, C); _DEFPIN_AVR(35, 4, C);
335 _DEFPIN_AVR(36, 2, C); _DEFPIN_AVR(37, 1, C); _DEFPIN_AVR(38, 128, D); _DEFPIN_AVR(39, 4, G);
336 _DEFPIN_AVR(40, 2, G); _DEFPIN_AVR(41, 1, G); _DEFPIN_AVR(42, 128, L); _DEFPIN_AVR(43, 64, L);
337 _DEFPIN_AVR(44, 32, L); _DEFPIN_AVR(45, 16, L); _DEFPIN_AVR(46, 8, L); _DEFPIN_AVR(47, 4, L);
338 _DEFPIN_AVR(48, 2, L); _DEFPIN_AVR(49, 1, L); _DEFPIN_AVR(50, 8, B); _DEFPIN_AVR(51, 4, B);
339 _DEFPIN_AVR(52, 2, B); _DEFPIN_AVR(53, 1, B); _DEFPIN_AVR(54, 1, F); _DEFPIN_AVR(55, 2, F);
340 _DEFPIN_AVR(56, 4, F); _DEFPIN_AVR(57, 8, F); _DEFPIN_AVR(58, 16, F); _DEFPIN_AVR(59, 32, F);
341 _DEFPIN_AVR(60, 64, F); _DEFPIN_AVR(61, 128, F); _DEFPIN_AVR(62, 1, K); _DEFPIN_AVR(63, 2, K);
342 _DEFPIN_AVR(64, 4, K); _DEFPIN_AVR(65, 8, K); _DEFPIN_AVR(66, 16, K); _DEFPIN_AVR(67, 32, K);
343 _DEFPIN_AVR(68, 64, K); _DEFPIN_AVR(69, 128, K);
344 
345 #define SPI_DATA 51
346 #define SPI_CLOCK 52
347 #define SPI_SELECT 53
348 #define AVR_HARDWARE_SPI
349 
350 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
351 // Xark: Add ATMega644,644P,1284 and 1284P (using pinout from http://maniacbug.wordpress.com/2011/11/27/arduino-on-atmega1284p-4/)
352 
353 _IO(A); _IO(B); _IO(C); _IO(D);
354 
355 _DEFPIN_AVR( 0, (1<<0), B); _DEFPIN_AVR( 1, (1<<1), B); _DEFPIN_AVR( 2, (1<<2), B); _DEFPIN_AVR( 3, (1<<3), B);
356 _DEFPIN_AVR( 4, (1<<4), B); _DEFPIN_AVR( 5, (1<<5), B); _DEFPIN_AVR( 6, (1<<6), B); _DEFPIN_AVR( 7, (1<<7), B);
357 
358 _DEFPIN_AVR( 8, (1<<0), D); _DEFPIN_AVR( 9, (1<<1), D); _DEFPIN_AVR(10, (1<<2), D); _DEFPIN_AVR(11, (1<<3), D);
359 _DEFPIN_AVR(12, (1<<4), D); _DEFPIN_AVR(13, (1<<5), D); _DEFPIN_AVR(14, (1<<6), D); _DEFPIN_AVR(15, (1<<7), D);
360 
361 _DEFPIN_AVR(16, (1<<0), C); _DEFPIN_AVR(17, (1<<1), C); _DEFPIN_AVR(18, (1<<2), C); _DEFPIN_AVR(19, (1<<3), C);
362 _DEFPIN_AVR(20, (1<<4), C); _DEFPIN_AVR(21, (1<<5), C); _DEFPIN_AVR(22, (1<<6), C); _DEFPIN_AVR(23, (1<<7), C);
363 
364 _DEFPIN_AVR(24, (1<<0), A); _DEFPIN_AVR(25, (1<<1), A); _DEFPIN_AVR(26, (1<<2), A); _DEFPIN_AVR(27, (1<<3), A);
365 _DEFPIN_AVR(28, (1<<4), A); _DEFPIN_AVR(29, (1<<5), A); _DEFPIN_AVR(30, (1<<6), A); _DEFPIN_AVR(31, (1<<7), A);
366 
367 #define SPI_DATA 5
368 #define SPI_CLOCK 7
369 #define SPI_SELECT 4
370 #define AVR_HARDWARE_SPI
371 
372 // Leonardo, teensy, blinkm
373 #elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)
374 // Leonardo, teensy, blinkm
375 #elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)
376 
377 // teensy defs
378 _IO(B); _IO(C); _IO(D); _IO(E); _IO(F);
379 
380 _DEFPIN_AVR(0, 1, B); _DEFPIN_AVR(1, 2, B); _DEFPIN_AVR(2, 4, B); _DEFPIN_AVR(3, 8, B);
381 _DEFPIN_AVR(4, 128, B); _DEFPIN_AVR(5, 1, D); _DEFPIN_AVR(6, 2, D); _DEFPIN_AVR(7, 4, D);
382 _DEFPIN_AVR(8, 8, D); _DEFPIN_AVR(9, 64, C); _DEFPIN_AVR(10, 128, C); _DEFPIN_AVR(11, 64, D);
383 _DEFPIN_AVR(12, 128, D); _DEFPIN_AVR(13, 16, B); _DEFPIN_AVR(14, 32, B); _DEFPIN_AVR(15, 64, B);
384 _DEFPIN_AVR(16, 128, F); _DEFPIN_AVR(17, 64, F); _DEFPIN_AVR(18, 32, F); _DEFPIN_AVR(19, 16, F);
385 _DEFPIN_AVR(20, 2, F); _DEFPIN_AVR(21, 1, F); _DEFPIN_AVR(22, 16, D); _DEFPIN_AVR(23, 32, D);
386 
387 #define SPI_DATA 2
388 #define SPI_CLOCK 1
389 #define SPI_SELECT 3
390 #define AVR_HARDWARE_SPI
391 
392 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
393 // teensy++ 2 defs
394 
395 _IO(A); _IO(B); _IO(C); _IO(D); _IO(E); _IO(F);
396 
397 _DEFPIN_AVR(0, 1, D); _DEFPIN_AVR(1, 2, D); _DEFPIN_AVR(2, 4, D); _DEFPIN_AVR(3, 8, D);
398 _DEFPIN_AVR(4, 16, D); _DEFPIN_AVR(5, 32, D); _DEFPIN_AVR(6, 64, D); _DEFPIN_AVR(7, 128, D);
399 _DEFPIN_AVR(8, 1, E); _DEFPIN_AVR(9, 2, E); _DEFPIN_AVR(10, 1, C); _DEFPIN_AVR(11, 2, C);
400 _DEFPIN_AVR(12, 4, C); _DEFPIN_AVR(13, 8, C); _DEFPIN_AVR(14, 16, C); _DEFPIN_AVR(15, 32, C);
401 _DEFPIN_AVR(16, 64, C); _DEFPIN_AVR(17, 128, C); _DEFPIN_AVR(18, 64, E); _DEFPIN_AVR(19, 128, E);
402 _DEFPIN_AVR(20, 1, B); _DEFPIN_AVR(21, 2, B); _DEFPIN_AVR(22, 4, B); _DEFPIN_AVR(23, 8, B);
403 _DEFPIN_AVR(24, 16, B); _DEFPIN_AVR(25, 32, B); _DEFPIN_AVR(26, 64, B); _DEFPIN_AVR(27, 128, B);
404 _DEFPIN_AVR(28, 1, A); _DEFPIN_AVR(29, 2, A); _DEFPIN_AVR(30, 4, A); _DEFPIN_AVR(31, 8, A);
405 _DEFPIN_AVR(32, 16, A); _DEFPIN_AVR(33, 32, A); _DEFPIN_AVR(34, 64, A); _DEFPIN_AVR(35, 128, A);
406 _DEFPIN_AVR(36, 16, E); _DEFPIN_AVR(37, 32, E); _DEFPIN_AVR(38, 1, F); _DEFPIN_AVR(39, 2, F);
407 _DEFPIN_AVR(40, 4, F); _DEFPIN_AVR(41, 8, F); _DEFPIN_AVR(42, 16, F); _DEFPIN_AVR(43, 32, F);
408 _DEFPIN_AVR(44, 64, F); _DEFPIN_AVR(45, 128, F);
409 
410 #define SPI_DATA 22
411 #define SPI_CLOCK 21
412 #define SPI_SELECT 20
413 #define AVR_HARDWARE_SPI
414 
415 #elif defined(__AVR_ATmega32U4__)
416 
417 // leonard defs
418 _IO(B); _IO(C); _IO(D); _IO(E); _IO(F);
419 
420 _DEFPIN_AVR(0, 4, D); _DEFPIN_AVR(1, 8, D); _DEFPIN_AVR(2, 2, D); _DEFPIN_AVR(3, 1, D);
421 _DEFPIN_AVR(4, 16, D); _DEFPIN_AVR(5, 64, C); _DEFPIN_AVR(6, 128, D); _DEFPIN_AVR(7, 64, E);
422 _DEFPIN_AVR(8, 16, B); _DEFPIN_AVR(9, 32, B); _DEFPIN_AVR(10, 64, B); _DEFPIN_AVR(11, 128, B);
423 _DEFPIN_AVR(12, 64, D); _DEFPIN_AVR(13, 128, C); _DEFPIN_AVR(14, 8, B); _DEFPIN_AVR(15, 2, B);
424 _DEFPIN_AVR(16, 4, B); _DEFPIN_AVR(17, 1, B); _DEFPIN_AVR(18, 128, F); _DEFPIN_AVR(19, 64, F);
425 _DEFPIN_AVR(20, 32, F); _DEFPIN_AVR(21, 16, F); _DEFPIN_AVR(22, 2, F); _DEFPIN_AVR(23, 0, F);
426 
427 #define SPI_DATA 16
428 #define SPI_CLOCK 15
429 #define AVR_HARDWARE_SPI
430 
431 #elif defined(__MK20DX128__) && defined(CORE_TEENSY)
432 
433 _IO32(A); _IO32(B); _IO32(C); _IO32(D); _IO32(E);
434 
435 _DEFPIN_ARM(0, 16, B); _DEFPIN_ARM(1, 17, B); _DEFPIN_ARM(2, 0, D); _DEFPIN_ARM(3, 12, A);
436 _DEFPIN_ARM(4, 13, A); _DEFPIN_ARM(5, 7, D); _DEFPIN_ARM(6, 4, D); _DEFPIN_ARM(7, 2, D);
437 _DEFPIN_ARM(8, 3, D); _DEFPIN_ARM(9, 3, C); _DEFPIN_ARM(10, 4, C); _DEFPIN_ARM(11, 6, C);
438 _DEFPIN_ARM(12, 7, C); _DEFPIN_ARM(13, 5, C); _DEFPIN_ARM(14, 1, D); _DEFPIN_ARM(15, 0, C);
439 _DEFPIN_ARM(16, 0, B); _DEFPIN_ARM(17, 1, B); _DEFPIN_ARM(18, 3, B); _DEFPIN_ARM(19, 2, B);
440 _DEFPIN_ARM(20, 5, D); _DEFPIN_ARM(21, 6, D); _DEFPIN_ARM(22, 1, C); _DEFPIN_ARM(23, 2, C);
441 _DEFPIN_ARM(24, 5, A); _DEFPIN_ARM(25, 19, B); _DEFPIN_ARM(26, 1, E); _DEFPIN_ARM(27, 9, C);
442 _DEFPIN_ARM(28, 8, C); _DEFPIN_ARM(29, 10, C); _DEFPIN_ARM(30, 11, C); _DEFPIN_ARM(31, 0, E);
443 _DEFPIN_ARM(32, 18, B); _DEFPIN_ARM(33, 4, A);
444 
445 #define SPI_DATA 11
446 #define SPI_CLOCK 13
447 #define ARM_HARDWARE_SPI
448 
449 #elif defined(__SAM3X8E__)
450 
451 DUE_IO32(A);
452 DUE_IO32(B);
453 DUE_IO32(C);
454 DUE_IO32(D);
455 
456 _DEFPIN_DUE(0, 8, A); _DEFPIN_DUE(1, 9, A); _DEFPIN_DUE(2, 25, B); _DEFPIN_DUE(3, 28, C);
457 _DEFPIN_DUE(4, 26, C); _DEFPIN_DUE(5, 25, C); _DEFPIN_DUE(6, 24, C); _DEFPIN_DUE(7, 23, C);
458 _DEFPIN_DUE(8, 22, C); _DEFPIN_DUE(9, 21, C); _DEFPIN_DUE(10, 29, C); _DEFPIN_DUE(11, 7, D);
459 _DEFPIN_DUE(12, 8, D); _DEFPIN_DUE(13, 27, B); _DEFPIN_DUE(14, 4, D); _DEFPIN_DUE(15, 5, D);
460 _DEFPIN_DUE(16, 13, A); _DEFPIN_DUE(17, 12, A); _DEFPIN_DUE(18, 11, A); _DEFPIN_DUE(19, 10, A);
461 _DEFPIN_DUE(20, 12, B); _DEFPIN_DUE(21, 13, B); _DEFPIN_DUE(22, 26, B); _DEFPIN_DUE(23, 14, A);
462 _DEFPIN_DUE(24, 15, A); _DEFPIN_DUE(25, 0, D); _DEFPIN_DUE(26, 1, D); _DEFPIN_DUE(27, 2, D);
463 _DEFPIN_DUE(28, 3, D); _DEFPIN_DUE(29, 6, D); _DEFPIN_DUE(30, 9, D); _DEFPIN_DUE(31, 7, A);
464 _DEFPIN_DUE(32, 10, D); _DEFPIN_DUE(33, 1, C); _DEFPIN_DUE(34, 2, C); _DEFPIN_DUE(35, 3, C);
465 _DEFPIN_DUE(36, 4, C); _DEFPIN_DUE(37, 5, C); _DEFPIN_DUE(38, 6, C); _DEFPIN_DUE(39, 7, C);
466 _DEFPIN_DUE(40, 8, C); _DEFPIN_DUE(41, 9, C); _DEFPIN_DUE(42, 19, A); _DEFPIN_DUE(43, 20, A);
467 _DEFPIN_DUE(44, 19, C); _DEFPIN_DUE(45, 18, C); _DEFPIN_DUE(46, 17, C); _DEFPIN_DUE(47, 16, C);
468 _DEFPIN_DUE(48, 15, C); _DEFPIN_DUE(49, 14, C); _DEFPIN_DUE(50, 13, C); _DEFPIN_DUE(51, 12, C);
469 _DEFPIN_DUE(52, 21, B); _DEFPIN_DUE(53, 14, B); _DEFPIN_DUE(54, 16, A); _DEFPIN_DUE(55, 24, A);
470 _DEFPIN_DUE(56, 23, A); _DEFPIN_DUE(57, 22, A); _DEFPIN_DUE(58, 6, A); _DEFPIN_DUE(59, 4, A);
471 _DEFPIN_DUE(60, 3, A); _DEFPIN_DUE(61, 2, A); _DEFPIN_DUE(62, 17, B); _DEFPIN_DUE(63, 18, B);
472 _DEFPIN_DUE(64, 19, B); _DEFPIN_DUE(65, 20, B); _DEFPIN_DUE(66, 15, B); _DEFPIN_DUE(67, 16, B);
473 _DEFPIN_DUE(68, 1, A); _DEFPIN_DUE(69, 0, A); _DEFPIN_DUE(70, 17, A); _DEFPIN_DUE(71, 18, A);
474 _DEFPIN_DUE(72, 30, C); _DEFPIN_DUE(73, 21, A); _DEFPIN_DUE(74, 25, A); _DEFPIN_DUE(75, 26, A);
475 _DEFPIN_DUE(76, 27, A); _DEFPIN_DUE(77, 28, A); _DEFPIN_DUE(78, 23, B);
476 
477 #else
478 
479 #warning "No pin/port mappings found, pin access will be slightly slower. See fastpin.h for info."
480 #define NO_HARDWARE_PIN_SUPPORT
481 
482 #endif
483 
484 #endif
static void lo() __attribute__((always_inline))
Definition: TFT_FastPin.h:154
volatile uint8_t * port_ptr_t
Definition: TFT_FastPin.h:88
uint8_t port_t
Definition: TFT_FastPin.h:178
uint32_t port_t
Definition: TFT_FastPin.h:205
port_t hival() __attribute__((always_inline))
Definition: TFT_FastPin.h:105
static void toggle() __attribute__((always_inline))
Definition: TFT_FastPin.h:216
port_t mask() __attribute__((always_inline))
Definition: TFT_FastPin.h:108
static void hi() __attribute__((always_inline))
Definition: TFT_FastPin.h:183
volatile uint8_t * port_ptr_t
Definition: TFT_FastPin.h:147
uint8_t port_t
Definition: TFT_FastPin.h:148
static void setInput()
Definition: TFT_FastPin.h:236
static void hi(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:218
static void hi() __attribute__((always_inline))
Definition: TFT_FastPin.h:238
static port_ptr_t port() __attribute__((always_inline))
Definition: TFT_FastPin.h:224
OutputPin(int pin)
Definition: TFT_FastPin.h:117
volatile uint32_t * port_ptr_t
Definition: TFT_FastPin.h:204
uint32_t port_t
Definition: TFT_FastPin.h:233
static void strobe() __attribute__((always_inline))
Definition: TFT_FastPin.h:242
static port_t hival() __attribute__((always_inline))
Definition: TFT_FastPin.h:164
void hi() __attribute__((always_inline))
Definition: TFT_FastPin.h:94
static port_t hival() __attribute__((always_inline))
Definition: TFT_FastPin.h:250
static void setOutput()
Definition: TFT_FastPin.h:150
volatile uint32_t & reg32_t
Definition: TFT_FastPin.h:269
void wait()
Definition: TFT_FastPin.h:47
static void lo() __attribute__((always_inline))
Definition: TFT_FastPin.h:211
static void fastset(register port_ptr_t port, register port_t val) __attribute__((always_inline))
Definition: TFT_FastPin.h:220
static void hi() __attribute__((always_inline))
Definition: TFT_FastPin.h:153
static void fastset(register port_ptr_t port, register port_t val) __attribute__((always_inline))
Definition: TFT_FastPin.h:248
static void setInput()
Definition: TFT_FastPin.h:151
static port_ptr_t port() __attribute__((always_inline))
Definition: TFT_FastPin.h:166
static port_t hival() __attribute__((always_inline))
Definition: TFT_FastPin.h:222
static void toggle() __attribute__((always_inline))
Definition: TFT_FastPin.h:244
void setInput()
Definition: TFT_FastPin.h:92
static void lo(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:190
virtual void select()
Definition: TFT_FastPin.h:110
void mark()
Definition: TFT_FastPin.h:54
virtual void release()
Definition: TFT_FastPin.h:111
volatile uint8_t & reg8_t
AVR definitions for pins. Getting around the fact that I can&#39;t pass GPIO register addresses in as tem...
Definition: TFT_FastPin.h:259
static port_t hival() __attribute__((always_inline))
Definition: TFT_FastPin.h:193
static void hi(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:189
static void setInput()
Definition: TFT_FastPin.h:181
static port_t mask() __attribute__((always_inline))
Definition: TFT_FastPin.h:225
static port_t mask() __attribute__((always_inline))
Definition: TFT_FastPin.h:196
#define _DEFPIN_AVR(PIN, MASK, L)
Definition: TFT_FastPin.h:263
static void hi() __attribute__((always_inline))
Definition: TFT_FastPin.h:210
static port_t loval() __attribute__((always_inline))
Definition: TFT_FastPin.h:194
Template definition for teensy 3.0 style ARM pins, providing direct access to the various GPIO regist...
Definition: TFT_FastPin.h:202
#define _IO(L)
Definition: TFT_FastPin.h:262
static void hi(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:246
static void strobe() __attribute__((always_inline))
Definition: TFT_FastPin.h:156
static port_ptr_t port() __attribute__((always_inline))
Definition: TFT_FastPin.h:195
Class definition for a Pin where we know the port registers at compile time for said pin...
Definition: TFT_FastPin.h:175
static void hi(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:158
static port_t mask() __attribute__((always_inline))
Definition: TFT_FastPin.h:167
volatile uint8_t * port_ptr_t
Definition: TFT_FastPin.h:177
static void strobe() __attribute__((always_inline))
Definition: TFT_FastPin.h:214
void setOutput()
Definition: TFT_FastPin.h:91
static port_t loval() __attribute__((always_inline))
Definition: TFT_FastPin.h:165
static port_t loval() __attribute__((always_inline))
Definition: TFT_FastPin.h:251
port_t loval() __attribute__((always_inline))
Definition: TFT_FastPin.h:106
static void fastset(register port_ptr_t port, register uint8_t val) __attribute__((always_inline))
Definition: TFT_FastPin.h:191
Template definition for teensy 3.0 style ARM pins using bit banding, providing direct access to the v...
Definition: TFT_FastPin.h:230
virtual bool isSelected()
Definition: TFT_FastPin.h:112
static port_t loval() __attribute__((always_inline))
Definition: TFT_FastPin.h:223
void lo(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:100
static void lo() __attribute__((always_inline))
Definition: TFT_FastPin.h:184
volatile uint32_t * port_ptr_t
Definition: TFT_FastPin.h:232
static void setOutput()
Definition: TFT_FastPin.h:180
void hi(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:99
InputPin(int pin)
Definition: TFT_FastPin.h:122
The simplest level of Pin class. This relies on runtime functions durinig initialization to get the p...
Definition: TFT_FastPin.h:139
static void setInput()
Definition: TFT_FastPin.h:208
volatile uint32_t * ptr_reg32_t
Definition: TFT_FastPin.h:270
port_ptr_t port() __attribute__((always_inline))
Definition: TFT_FastPin.h:107
static void lo(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:247
Pin(int pin)
Definition: TFT_FastPin.h:86
void strobe() __attribute__((always_inline))
Definition: TFT_FastPin.h:97
static void lo() __attribute__((always_inline))
Definition: TFT_FastPin.h:239
static void lo(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:159
void fastset(register port_ptr_t port, register port_t val) __attribute__((always_inline))
Definition: TFT_FastPin.h:103
#define _DEFPIN_ARM(PIN, BIT, L)
Definition: TFT_FastPin.h:276
void lo() __attribute__((always_inline))
Definition: TFT_FastPin.h:95
static void lo(register port_ptr_t port) __attribute__((always_inline))
Definition: TFT_FastPin.h:219
static port_ptr_t port() __attribute__((always_inline))
Definition: TFT_FastPin.h:252
static void setOutput()
Definition: TFT_FastPin.h:207
static port_t mask() __attribute__((always_inline))
Definition: TFT_FastPin.h:253
#define _IO32(L)
Definition: TFT_FastPin.h:274
static void fastset(register port_ptr_t port, register port_t val) __attribute__((always_inline))
Definition: TFT_FastPin.h:162
static void strobe() __attribute__((always_inline))
Definition: TFT_FastPin.h:187
uint8_t port_t
Definition: TFT_FastPin.h:89
static void setOutput()
Definition: TFT_FastPin.h:235