11 #ifndef __digitalWriteFast_h_
12 #define __digitalWriteFast_h_ 1
17 #if !defined(BIT_READ)
18 # define BIT_READ(value, bit) ((value) & (1UL << (bit)))
21 # define BIT_SET(value, bit) ((value) |= (1UL << (bit)))
23 #if !defined(BIT_CLEAR)
24 # define BIT_CLEAR(value, bit) ((value) &= ~(1UL << (bit)))
26 #if !defined(BIT_WRITE)
27 # define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit))
33 #if (defined(ARDUINO_AVR_MEGA) || \
34 defined(ARDUINO_AVR_MEGA1280) || \
35 defined(ARDUINO_AVR_MEGA2560) || \
36 defined(__AVR_ATmega1280__) || \
37 defined(__AVR_ATmega1281__) || \
38 defined(__AVR_ATmega2560__) || \
39 defined(__AVR_ATmega2561__))
41 #define __digitalPinToPortReg(P) \
42 (((P) >= 22 && (P) <= 29) ? &PORTA : \
43 ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
44 (((P) >= 30 && (P) <= 37) ? &PORTC : \
45 ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
46 ((((P) <= 3) || (P) == 5) ? &PORTE : \
47 (((P) >= 54 && (P) <= 61) ? &PORTF : \
48 ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
49 ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
50 (((P) == 14 || (P) == 15) ? &PORTJ : \
51 (((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))
53 #define __digitalPinToDDRReg(P) \
54 (((P) >= 22 && (P) <= 29) ? &DDRA : \
55 ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
56 (((P) >= 30 && (P) <= 37) ? &DDRC : \
57 ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
58 ((((P) <= 3) || (P) == 5) ? &DDRE : \
59 (((P) >= 54 && (P) <= 61) ? &DDRF : \
60 ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
61 ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
62 (((P) == 14 || (P) == 15) ? &DDRJ : \
63 (((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))
65 #define __digitalPinToPINReg(P) \
66 (((P) >= 22 && (P) <= 29) ? &PINA : \
67 ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
68 (((P) >= 30 && (P) <= 37) ? &PINC : \
69 ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
70 ((((P) <= 3) || (P) == 5) ? &PINE : \
71 (((P) >= 54 && (P) <= 61) ? &PINF : \
72 ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
73 ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
74 (((P) == 14 || (P) == 15) ? &PINJ : \
75 (((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))
77 #define __digitalPinToBit(P) \
78 (((P) >= 7 && (P) <= 9) ? (P) - 3 : \
79 (((P) >= 10 && (P) <= 13) ? (P) - 6 : \
80 (((P) >= 22 && (P) <= 29) ? (P) - 22 : \
81 (((P) >= 30 && (P) <= 37) ? 37 - (P) : \
82 (((P) >= 39 && (P) <= 41) ? 41 - (P) : \
83 (((P) >= 42 && (P) <= 49) ? 49 - (P) : \
84 (((P) >= 50 && (P) <= 53) ? 53 - (P) : \
85 (((P) >= 54 && (P) <= 61) ? (P) - 54 : \
86 (((P) >= 62 && (P) <= 69) ? (P) - 62 : \
87 (((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
88 (((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
90 (((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
92 (((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))
96 #elif (defined(__AVR_ATmega1284P__) || \
97 defined(__AVR_ATmega1284__) || \
98 defined(__AVR_ATmega644P__) || \
99 defined(__AVR_ATmega644A__) || \
100 defined(__AVR_ATmega644__) || \
101 defined(__AVR_ATmega324PB__) || \
102 defined(__AVR_ATmega324PA__) || \
103 defined(__AVR_ATmega324P__) || \
104 defined(__AVR_ATmega324A__) || \
105 defined(__AVR_ATmega164P__) || \
106 defined(__AVR_ATmega164A__) || \
107 defined(__AVR_ATmega32__) || \
108 defined(__AVR_ATmega16__) || \
109 defined(__AVR_ATmega8535__)) && \
110 !defined(BOBUINO_PINOUT)
112 #if defined(__AVR_ATmega324PB__)
113 #define __digitalPinToPortReg(P) \
114 (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE))))
115 #define __digitalPinToDDRReg(P) \
116 (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE))))
117 #define __digitalPinToPINReg(P) \
118 (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE))))
119 # if defined(SANGUINO_PINOUT)
120 #define __digitalPinToBit(P) \
121 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32))))
122 # else //MightyCore Pinout
123 #define __digitalPinToBit(P) \
124 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32))))
127 #define __digitalPinToPortReg(P) \
128 (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA)))
129 #define __digitalPinToDDRReg(P) \
130 (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA)))
131 #define __digitalPinToPINReg(P) \
132 (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA)))
133 # if defined(SANGUINO_PINOUT)
134 #define __digitalPinToBit(P) \
135 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24)))))
136 # else //MightyCore Pinout
137 #define __digitalPinToBit(P) \
138 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24)))
141 #define __digitalPinToPortReg(P) \
142 (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : &PORTC))
143 #define __digitalPinToDDRReg(P) \
144 (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : &DDRC))
145 #define __digitalPinToPINReg(P) \
146 (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : &PINC))
147 # if defined(SANGUINO_PINOUT)
148 #define __digitalPinToBit(P) \
149 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24)))))
150 # else //MightyCore Pinout
151 #define __digitalPinToBit(P) \
152 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24)))
158 #elif (defined(ARDUINO_AVR_LEONARDO) || \
159 defined(__AVR_ATmega16U4__) || \
160 defined(__AVR_ATmega32U4__))
161 # if defined(TEENSYDUINO)
163 #define __digitalPinToPortReg(P) \
164 ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PORTB : (((P) == 9 || (P) == 10) ? &PORTC : (((P) >= 16 && (P) <= 21)) ? &PORTF : &PORTD))
165 #define __digitalPinToDDRReg(P) \
166 ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &DDRB : (((P) == 9 || (P) == 10) ? &DDRC : (((P) >= 16 && (P) <= 21)) ? &DDRF : &DDRD))
167 #define __digitalPinToPINReg(P) \
168 ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PINB : (((P) == 9 || (P) == 10) ? &PINC : (((P) >= 16 && (P) <= 21)) ? &PINF : &PIND))
169 #define __digitalPinToBit(P) \
170 (((P) <= 3) ? (P) : \
171 (((P) == 4 || (P) == 12) ? 7 : \
172 (((P) <= 8) ? (P) - 5 : \
173 (((P) <= 10) ? (P) - 3 : \
175 (((P) <= 15) ? (P) - 9 : \
176 (((P) <= 19) ? 23 - (P) : \
177 (((P) <= 21) ? 21 - (P) : (P) - 18))))))))
180 #define __digitalPinToPortReg(P) \
181 ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB)))
182 #define __digitalPinToDDRReg(P) \
183 ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB)))
184 #define __digitalPinToPINReg(P) \
185 ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB)))
186 #define __digitalPinToBit(P) \
187 (((P) >= 8 && (P) <= 11) ? (P) - 4 : \
188 (((P) >= 18 && (P) <= 21) ? 25 - (P) : \
189 (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : \
190 (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : \
191 (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 )))))))))))))))))))
195 #elif (defined(ARDUINO_AVR_UNO) || \
196 defined(ARDUINO_AVR_DUEMILANOVE) || \
197 defined(__AVR_ATmega8__) || \
198 defined(__AVR_ATmega48__) || \
199 defined(__AVR_ATmega48P__) || \
200 defined(__AVR_ATmega48PB__) || \
201 defined(__AVR_ATmega88P__) || \
202 defined(__AVR_ATmega88PB__) || \
203 defined(__AVR_ATmega168__) || \
204 defined(__AVR_ATmega168PA__) || \
205 defined(__AVR_ATmega168PB__) || \
206 defined(__AVR_ATmega328__) || \
207 defined(__AVR_ATmega328P__) || \
208 defined(__AVR_ATmega328PB__))
210 #if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__) || defined(__AVR_ATmega328PB__)
211 #define __digitalPinToPortReg(P) \
212 (((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE)))
213 #define __digitalPinToDDRReg(P) \
214 (((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE)))
215 #define __digitalPinToPINReg(P) \
216 (((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE)))
217 #define __digitalPinToBit(P) \
218 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22))))
220 #define __digitalPinToPortReg(P) \
221 (((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
222 #define __digitalPinToDDRReg(P) \
223 (((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
224 #define __digitalPinToPINReg(P) \
225 (((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
226 #define __digitalPinToBit(P) \
227 (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
231 #elif defined(__AVR_ATmega4809__)
233 #define __digitalPinToPortReg(P) \
234 (((P) == 2 || (P) == 7 ) ? &VPORTA.OUT : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.OUT : ((P) == 4) ? &VPORTC.OUT : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.OUT : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.OUT : &VPORTF.OUT)
235 #define __digitalPinToDDRReg(P) \
236 (((P) == 2 || (P) == 7 ) ? &VPORTA.DIR : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.DIR : ((P) == 4) ? &VPORTC.DIR : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.DIR : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.DIR : &VPORTF.DIR)
237 #define __digitalPinToPINReg(P) \
238 (((P) == 2 || (P) == 7 ) ? &VPORTA.IN : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.IN : ((P) == 4) ? &VPORTC.IN : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.IN : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.IN : &VPORTF.IN)
239 #define __digitalPinToBit(P) \
240 (((P) == 2 || (P) == 9 || (P) == 11 || (P) == 17) ? 0 : ((P) == 7 || (P) == 10 || (P) == 12 || (P) == 16) ? 1 : ((P) == 5 || (P) == 13 || (P) == 15 || (P) == 18) ? 2 : ((P) == 9 || (P) == 14 || (P) == 19) ? 3 : ((P) == 6 || (P) == 20) ? 4 : ((P) == 3 || (P) == 21) ? 5 : 6 )
246 #elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)
247 #define __digitalPinToPortReg(P) ((P) <= 5 ? &VPORTB.OUT : ((P) <= 9 ? &VPORTC.OUT : ((P) <= 16 ? &VPORTA.OUT : ((P) <= 18 ? &VPORTB.OUT : &VPORTC.OUT))))
248 #define __digitalPinToDDRReg(P) ((P) <= 5 ? &VPORTB.DIR : ((P) <= 9 ? &VPORTC.DIR : ((P) <= 16 ? &VPORTA.DIR : ((P) <= 18 ? &VPORTB.DIR : &VPORTC.DIR))))
249 #define __digitalPinToPINReg(P) ((P) <= 5 ? &VPORTB.IN : ((P) <= 9 ? &VPORTC.IN : ((P) <= 16 ? &VPORTA.IN : ((P) <= 18 ? &VPORTB.IN : &VPORTC.IN))))
250 #define __digitalPinToBit(P) ( (P) <= 3 ? (3 - P) : ((P) <= 5 ? (P) : ((P) <= 9 ? (P - 6) : ((P) <= 16 ? ((P) - 9) : ((P) <= 18 ? ((P) - 11) : ((P) - 15))))) )
252 #elif defined(__AVR_ATtiny1614__)
253 #define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 7 ? &VPORTB.OUT : &VPORTA.OUT))
254 #define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 7 ? &VPORTB.DIR : &VPORTA.DIR))
255 #define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 7 ? &VPORTB.IN : &VPORTA.IN))
256 #define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 7 ? (7 - P) : ((P) <= 10 ? (P - 7) : (P) - 11)) )
258 #elif defined(__AVR_ATtiny816__)
260 #define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 9 ? &VPORTB.OUT : ((P) <= 13 ? &VPORTC.OUT : ((P) <= 17 ? &VPORTA.OUT : &VPORTC.OUT))))
261 #define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 9 ? &VPORTB.DIR : ((P) <= 13 ? &VPORTC.DIR : ((P) <= 17 ? &VPORTA.DIR : &VPORTC.DIR))))
262 #define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 9 ? &VPORTB.IN : ((P) <= 13 ? &VPORTC.IN : ((P) <= 17 ? &VPORTA.IN : &VPORTC.IN))))
263 #define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 9 ? (9 - P) : ((P) <= 13 ? (P - 10) : ((P) <= 16 ? (P - 13) : ((P) - 17)))) )
266 #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
268 #define __digitalPinToPortReg(P) (&PORTB)
269 #define __digitalPinToDDRReg(P) (&DDRB)
270 #define __digitalPinToPINReg(P) (&PINB)
271 #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
275 #elif defined(__AVR_ATtiny88__)
276 # if defined(ARDUINO_AVR_DIGISPARKPRO)
277 #define __digitalPinToPortReg(P) ((P) <= 7 ? &PORTD : ((P) <= 14 ? &PORTB : ((P) <= 18 ? &PORTA : &PORTC)))
278 #define __digitalPinToDDRReg(P) ((P) <= 7 ? &DDRD : ((P) <= 14 ? &DDRB : ((P) <= 18 ? &DDRA : &DDRC)))
279 #define __digitalPinToPINReg(P) ((P) <= 7 ? &PIND : ((P) <= 14 ? &PINB : ((P) <= 18 ? &PINA : &PINC)))
280 #define __digitalPinToBit(P) ( (P) <= 7 ? (P) : ((P) <= 13 ? ((P) - 8) : ((P) == 14 ? 7 : ((P) <= 16 ? ((P) - 14) : ((P) <= 18 ? ((P) - 17) : ((P) == 25 ? 7 : ((P) - 19)))))) )
282 #define __digitalPinToPortReg(P) ((P) <= 7 ? &PORTD : ((P) <= 15 ? &PORTB : ((P) <= 22 ? &PORTC : ((P) <= 26 ? &PORTA : &PORTC))))
283 #define __digitalPinToDDRReg(P) ((P) <= 7 ? &DDRD : ((P) <= 15 ? &DDRB : ((P) <= 22 ? &DDRC : ((P) <= 26 ? &DDRA : &DDRC))))
284 #define __digitalPinToPINReg(P) ((P) <= 7 ? &PIND : ((P) <= 15 ? &PINB : ((P) <= 22 ? &PINC : ((P) <= 26 ? &PINA : &PINC))))
285 #define __digitalPinToBit(P) ((P) <= 15 ? ((P) & 0x7) : ((P) == 16 ? (7) : ((P) <= 22 ? ((P) - 17) : ((P) == 27 ? (6) : ((P) - 23)))))
290 #elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) \
291 || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
292 # if defined(ARDUINO_AVR_DIGISPARKPRO) || PIN_PA7 == 5
294 #define __digitalPinToPortReg(P) (((P) <= 4) ? &PORTB : &PORTA)
295 #define __digitalPinToDDRReg(P) (((P) <= 4) ? &DDRB : &DDRA)
296 #define __digitalPinToPINReg(P) (((P) <= 4) ? &PINB : &PINA)
297 #define __digitalPinToBit(P) (((P) <= 2) ? (P) : (((P) == 3) ? 6 : (((P) == 4) ? 3 : (((P) == 5) ? 7 : (P) - 6 ))))
301 #define __digitalPinToPortReg(P) (((P) <= 7) ? &PORTA : &PORTB)
302 #define __digitalPinToDDRReg(P) (((P) <= 7) ? &DDRA : &DDRB)
303 #define __digitalPinToPINReg(P) (((P) <= 7) ? &PINA : &PINB)
305 # if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__)
308 #define __digitalPinToBit(P) (((P) <= 7) ? (P) : ((P) == 11 ? (3) : 10 - (P)))
310 #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 )
321 #if !defined(digitalWriteFast)
322 # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg)
323 # if defined(THROW_ERROR_IF_NOT_FAST)
324 #define digitalWriteFast(P, V) \
325 if (__builtin_constant_p(P)) { \
326 BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \
328 NonConstantsUsedForDigitalWriteFast(); \
331 #define digitalWriteFast(P, V) \
332 if (__builtin_constant_p(P)) { \
333 BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \
335 digitalWrite((P), (V)); \
337 # endif // defined(THROW_ERROR_IF_NOT_FAST)
339 #define digitalWriteFast digitalWrite
343 #if !defined(pinModeFast)
344 # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg)
345 # if defined(THROW_ERROR_IF_NOT_FAST)
346 #define pinModeFast(P, V) \
347 if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
348 if (V == INPUT_PULLUP) {\
349 BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \
350 BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \
352 BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \
355 NonConstantsUsedForPinModeFast(); \
358 #define pinModeFast(P, V) \
359 if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
360 if (V == INPUT_PULLUP) {\
361 BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \
362 BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \
364 BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \
369 # endif // defined(THROW_ERROR_IF_NOT_FAST)
371 #define pinModeFast pinMode
373 #endif // !defined(pinModeFast)
375 #if !defined(digitalReadFast)
376 # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg)
377 # if defined(THROW_ERROR_IF_NOT_FAST)
378 #define digitalReadFast(P) ( (int) __digitalReadFast((P)) )
380 #define __digitalReadFast(P ) \
381 (__builtin_constant_p(P) ) ? \
382 (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \
383 NonConstantsUsedForDigitalReadFast()
385 #define digitalReadFast(P) ( (int) __digitalReadFast((P)) )
387 #define __digitalReadFast(P ) \
388 (__builtin_constant_p(P) ) ? \
389 (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \
391 # endif // defined(THROW_ERROR_IF_NOT_FAST)
393 #define digitalReadFast digitalRead
395 #endif // !defined(digitalReadFast)
397 #if !defined(digitalToggleFast)
398 # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg)
399 # if defined(THROW_ERROR_IF_NOT_FAST)
400 #define digitalToggleFast(P) \
401 if (__builtin_constant_p(P)) { \
402 BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \
404 NonConstantsUsedForDigitalToggleFast(); \
407 #define digitalToggleFast(P) \
408 if (__builtin_constant_p(P)) { \
409 BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \
411 digitalWrite(P, ! digitalRead(P)); \
413 # endif // defined(THROW_ERROR_IF_NOT_FAST)
415 #define digitalToggleFast(P) digitalWrite(P, ! digitalRead(P))
417 #endif // !defined(digitalToggleFast)
419 #endif //__digitalWriteFast_h_