Skip to content

Commit fb3c834

Browse files
committed
disabled direct port access on MEGAAVR targets
1 parent ab781cb commit fb3c834

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=BitBang_I2C
2-
version=1.2.0
2+
version=1.3.0
33
author=Larry Bank <[email protected]>
44
maintainer=Larry Bank <[email protected]>
55
sentence=Bit-bang the I2C protocol on any 2 GPIO pins on any system.

src/BitBang_I2C.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
static int iSCL, iSDA; // keep requested pin numbers in private statics
2727
static int iDelay; // bit delay in ms for the requested clock rate
28-
#ifdef __AVR__
28+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
2929
volatile uint8_t *iDDR_SCL, *iPort_SCL_Out;
3030
volatile uint8_t *iDDR_SDA, *iPort_SDA_In, *iPort_SDA_Out;
3131
uint8_t iSDABit, iSCLBit;
@@ -37,7 +37,7 @@ volatile uint32_t *iDDR_SDA, *iPort_SDA_In, *iPort_SDA_Out;
3737
uint32_t iSDABit, iSCLBit;
3838
#endif
3939

40-
#ifdef __AVR__
40+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
4141
uint8_t getPinInfo(uint8_t pin, volatile uint8_t **iDDR, volatile uint8_t **iPort, int bInput)
4242
{
4343
uint8_t port, bit;
@@ -111,7 +111,7 @@ uint32_t getPinInfo(uint8_t pin, volatile uint32_t **iDDR, volatile uint32_t **i
111111

112112
inline uint8_t SDA_READ(void)
113113
{
114-
#ifdef __AVR__
114+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
115115
if (iSDA >= 0xa0) // direct pin numbering
116116
{
117117
if (*iPort_SDA_In & iSDABit)
@@ -129,7 +129,7 @@ inline uint8_t SDA_READ(void)
129129
}
130130
inline void SCL_HIGH(void)
131131
{
132-
#ifdef __AVR__
132+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
133133
if (iSCL >= 0xa0) // direct pin numbering
134134
{
135135
*iDDR_SCL &= ~iSCLBit;
@@ -145,7 +145,7 @@ inline void SCL_HIGH(void)
145145

146146
inline void SCL_LOW(void)
147147
{
148-
#ifdef __AVR__
148+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
149149
if (iSCL >= 0xa0) // direct pin numbering
150150
{
151151
*iDDR_SCL |= iSCLBit;
@@ -161,7 +161,7 @@ inline void SCL_LOW(void)
161161

162162
inline void SDA_HIGH(void)
163163
{
164-
#ifdef __AVR__
164+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
165165
if (iSDA >= 0xa0) // direct pin numbering
166166
{
167167
*iDDR_SDA &= ~iSDABit;
@@ -177,7 +177,7 @@ inline void SDA_HIGH(void)
177177

178178
inline void SDA_LOW(void)
179179
{
180-
#ifdef __AVR__
180+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
181181
if (iSDA >= 0xa0) // direct pin numbering
182182
{
183183
*iDDR_SDA |= iSDABit;
@@ -238,7 +238,7 @@ uint8_t i, ack;
238238
} /* i2cByteOut() */
239239
#endif
240240

241-
#ifdef __AVR__
241+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
242242
#define SDA_LOW_AVR *iDDR_sda |= sdabit;
243243
#define SDA_HIGH_AVR *iDDR_sda &= ~sdabit;
244244
#define SCL_LOW_AVR *iDDR_scl |= sclbit;
@@ -419,7 +419,7 @@ int rc, iOldLen = iLen;
419419
#ifdef __AVR_ATtiny85__
420420
rc = i2cByteOutAVRFast(b);
421421
#else
422-
#ifdef __AVR__
422+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
423423
if (iSDA >= 0xa0)
424424
{
425425
rc = i2cByteOutAVRFast(b);
@@ -474,7 +474,7 @@ void I2CInit(int iSDA_Pin, int iSCL_Pin, int32_t iClock)
474474
digitalWrite(iSCL, LOW);
475475
#endif
476476
}
477-
#ifdef __AVR__
477+
#if defined ( __AVR__ ) && !defined( ARDUINO_ARCH_MEGAAVR )
478478
else // direct pin mode, get port address and bit
479479
{
480480
// iSDABit = 1 << (iSDA & 0x7);

0 commit comments

Comments
 (0)