@@ -31,6 +31,15 @@ void pinMode(uint8_t pin, PinMode mode)
31
31
uint8_t bit_pos = digitalPinToBitPosition (pin );
32
32
33
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 ;
34
43
35
44
PORT_t * port = digitalPinToPortStruct (pin );
36
45
if (port == NULL ) return ;
@@ -137,6 +146,15 @@ void digitalWrite(uint8_t pin, PinStatus val)
137
146
/* Get bit mask for pin */
138
147
uint8_t bit_mask = digitalPinToBitMask (pin );
139
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 ;
140
158
141
159
/* Turn off PWM if applicable */
142
160
@@ -210,6 +228,15 @@ PinStatus digitalRead(uint8_t pin)
210
228
/* Get bit mask and check valid pin */
211
229
uint8_t bit_mask = digitalPinToBitMask (pin );
212
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 ;
213
240
214
241
// If the pin that support PWM output, we need to turn it off
215
242
// before getting a digital reading.
0 commit comments