26
26
#include "wiring_private.h"
27
27
#include "pins_arduino.h"
28
28
29
+ bool isDoubleBondedActive (uint8_t pin ) __attribute__((weak ));
30
+
29
31
void pinMode (uint8_t pin , PinMode mode )
30
32
{
31
33
uint8_t bit_pos = digitalPinToBitPosition (pin );
32
34
33
- if ((bit_pos == NOT_A_PIN )|| (mode > INPUT_PULLUP )) return ;
34
-
35
- /* Check if TWI is operating on double bonded pin (Master Enable is high
36
- in both Master and Slave mode for bus error detection, so this can
37
- indicate an active state for Wire) */
38
- if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return ;
39
-
40
- /* Special check for SPI_SS double bonded pin -- no action if SPI is active
41
- (Using SPI Enable bit as indicator of SPI activity) */
42
- if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
35
+ if ((bit_pos == NOT_A_PIN ) || (mode > INPUT_PULLUP ) || isDoubleBondedActive (pin )) return ;
43
36
44
37
PORT_t * port = digitalPinToPortStruct (pin );
45
38
if (port == NULL ) return ;
@@ -145,16 +138,7 @@ void digitalWrite(uint8_t pin, PinStatus val)
145
138
{
146
139
/* Get bit mask for pin */
147
140
uint8_t bit_mask = digitalPinToBitMask (pin );
148
- if (bit_mask == NOT_A_PIN ) return ;
149
-
150
- /* Check if TWI is operating on double bonded pin (Master Enable is high
151
- in both Master and Slave mode for bus error detection, so this can
152
- indicate an active state for Wire) */
153
- if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return ;
154
-
155
- /* Special check for SPI_SS double bonded pin -- no action if SPI is active
156
- (Using SPI Enable bit as indicator of SPI activity) */
157
- if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
141
+ if (bit_mask == NOT_A_PIN || isDoubleBondedActive (pin )) return ;
158
142
159
143
/* Turn off PWM if applicable */
160
144
@@ -189,7 +173,6 @@ void digitalWrite(uint8_t pin, PinStatus val)
189
173
/* Restore system status */
190
174
SREG = status ;
191
175
192
-
193
176
/* Input direction */
194
177
} else {
195
178
/* Old implementation has side effect when pin set as input -
@@ -218,7 +201,6 @@ void digitalWrite(uint8_t pin, PinStatus val)
218
201
219
202
/* Restore system status */
220
203
SREG = status ;
221
-
222
204
}
223
205
224
206
}
@@ -227,16 +209,7 @@ PinStatus digitalRead(uint8_t pin)
227
209
{
228
210
/* Get bit mask and check valid pin */
229
211
uint8_t bit_mask = digitalPinToBitMask (pin );
230
- if (bit_mask == NOT_A_PIN ) return LOW ;
231
-
232
- /* Check if TWI is operating on double bonded pin (Master Enable is high
233
- in both Master and Slave mode for bus error detection, so this can
234
- indicate an active state for Wire) */
235
- if (((pin == PIN_A4 ) || (pin == PIN_A5 )) && (TWI0 .MCTRLA & TWI_ENABLE_bm )) return LOW ;
236
-
237
- /* Special check for SPI_SS double bonded pin -- no action if SPI is active
238
- (Using SPI Enable bit as indicator of SPI activity) */
239
- if ((pin == 10 ) && (SPI0 .CTRLA & SPI_ENABLE_bm )) return ;
212
+ if (bit_mask == NOT_A_PIN || isDoubleBondedActive (pin )) return LOW ;
240
213
241
214
// If the pin that support PWM output, we need to turn it off
242
215
// before getting a digital reading.
0 commit comments