Skip to content

Commit d955460

Browse files
committed
Hot-fix for making MasterOrSlave derivate of Master for easy downcasting
1 parent 57af720 commit d955460

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

libraries/Wire/Wire.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ TwoWireMaster::TwoWireMaster(uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t
263263
// Master-or-Slave Constructors ////////////////////////////////////////////////
264264

265265
TwoWireMasterOrSlave::TwoWireMasterOrSlave(uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t* rxBuffer, uint8_t* txBuffer)
266-
: TwoWireBase(&twiMasterSingleton, rxBufferSize, txBufferSize, rxBuffer, txBuffer)
266+
: TwoWireMaster(&twiMasterSingleton, rxBufferSize, txBufferSize, rxBuffer, txBuffer)
267267
{}
268268

269269
TwoWireMasterOrSlave::~TwoWireMasterOrSlave()
@@ -379,7 +379,7 @@ TwoWireMasterOrSlave::TwoWireMasterOrSlave()
379379
#else
380380

381381
TwoWireMasterOrSlave::TwoWireMasterOrSlave()
382-
: TwoWireBase(&twiMasterSingleton, I2C_BUFFER_LENGTH, I2C_BUFFER_LENGTH, new uint8_t[I2C_BUFFER_LENGTH], new uint8_t[I2C_BUFFER_LENGTH])
382+
: TwoWireMaster(&twiMasterSingleton, I2C_BUFFER_LENGTH, I2C_BUFFER_LENGTH, new uint8_t[I2C_BUFFER_LENGTH], new uint8_t[I2C_BUFFER_LENGTH])
383383
{}
384384

385385
#endif

libraries/Wire/Wire.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
You can use different configuration in separate compilation units, e.g., use
3636
TWOWIRE_MASTER_ONLY in most of the code, and don't use it only in the
3737
compilation unit where you need I2C slave capabilities.
38+
39+
You can also explicitely define TwoWireMaster instances and cast them to TwoWire
40+
when e.g. passing them to libarires using only master features.
3841
*/
3942

4043
#include <inttypes.h>
@@ -120,14 +123,18 @@ class TwoWireBase : public Stream
120123
// this is expected to be used with multiple instances for different pins
121124
class TwoWireMaster : public TwoWireBase
122125
{
126+
protected:
127+
// forwards to base
128+
// uses existing TwiMaster ptr (usefull for MasterOrSlave implementaion) and existing buffers
129+
TwoWireMaster(TwiMaster* twiPtr, uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t* rxBuffer, uint8_t* txBuffer);
123130
public:
124131
TwoWireMaster(uint8_t rxBufferSize = I2C_BUFFER_LENGTH, uint8_t txBufferSize = I2C_BUFFER_LENGTH);
125132
// singleton global instance constructor
126133
TwoWireMaster(uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t* rxBuffer, uint8_t* txBuffer);
127134
};
128135

129136
// this is expected to be used a singleton, it uses the singleton instance of TwiMaster, twiMasterSingleton, from twi.h
130-
class TwoWireMasterOrSlave : public TwoWireBase
137+
class TwoWireMasterOrSlave : public TwoWireMaster
131138
{
132139
private:
133140
void (*user_onRequest)(void);

0 commit comments

Comments
 (0)