Skip to content

Commit 8850246

Browse files
committed
Wire: fix for targets without slave support
1 parent 9a033dc commit 8850246

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

libraries/Wire/Wire.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ void arduino::MbedI2C::begin() {
77
}
88

99
void arduino::MbedI2C::begin(uint8_t slaveAddr) {
10+
#ifdef DEVICE_I2CSLAVE
1011
slave = new mbed::I2CSlave((PinName)_sda, (PinName)_scl);
1112
slave->address(slaveAddr);
13+
#endif
1214
}
1315

1416
void arduino::MbedI2C::end() {
1517
if (master != NULL) {
1618
delete master;
1719
}
20+
#ifdef DEVICE_I2CSLAVE
1821
if (slave != NULL) {
1922
delete slave;
2023
}
24+
#endif
2125
}
2226

2327
void arduino::MbedI2C::setClock(uint32_t freq) {
2428
if (master != NULL) {
2529
master->frequency(freq);
2630
}
31+
#ifdef DEVICE_I2CSLAVE
2732
if (slave != NULL) {
2833
slave->frequency(freq);
2934
}
35+
#endif
3036
}
3137

3238
void arduino::MbedI2C::beginTransmission(uint8_t address) {

libraries/Wire/Wire.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ class MbedI2C : public HardwareI2C
5252
virtual int available();
5353

5454
private:
55+
56+
#ifdef DEVICE_I2CSLAVE
5557
mbed::I2CSlave* slave;
58+
#endif
5659
mbed::I2C* master;
5760
int _sda;
5861
int _scl;
@@ -68,3 +71,5 @@ extern arduino::MbedI2C Wire;
6871
#elif DEVICE_I2C > 1
6972
extern arduino::MbedI2C Wire1;
7073
#endif
74+
75+
typedef arduino::MbedI2C TwoWire;

0 commit comments

Comments
 (0)