Skip to content

Commit 3b8bd99

Browse files
committed
Prevent #define leak outside of Wire.h and Wire.cpp, provide public typedef
1 parent 887fe87 commit 3b8bd99

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

libraries/Wire/Wire.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929
}
3030

3131
#include "twi.h"
32+
#define TwoWire_h_IMPLEMENTATION
3233
#include "Wire.h"
3334

3435

@@ -41,16 +42,18 @@ extern "C" {
4142
// Private Methods /////////////////////////////////////////////////////////////
4243
// Constructors ////////////////////////////////////////////////////////////////
4344

44-
TwoWireBase::TwoWireBase(uint8_t rxBufferSize, uint8_t txBufferSize) :
45-
twiMaster{new TwiMaster},
46-
rxBufferSize{rxBufferSize},
47-
rxBuffer{new uint8_t[rxBufferSize]},
48-
txBufferSize{txBufferSize},
49-
txBuffer{new uint8_t[txBufferSize]}
45+
TwoWireBase::TwoWireBase(uint8_t rxBufferSize, uint8_t txBufferSize)
46+
:
47+
twiMaster(new TwiMaster),
48+
rxBufferSize(rxBufferSize),
49+
rxBuffer(new uint8_t[rxBufferSize]),
50+
txBufferSize(txBufferSize),
51+
txBuffer(new uint8_t[txBufferSize])
5052
{
5153
}
5254

53-
TwoWireBase::TwoWireBase(TwiMaster* twiPtr, uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t* rxBuffer, uint8_t* txBuffer) :
55+
TwoWireBase::TwoWireBase(TwiMaster* twiPtr, uint8_t rxBufferSize, uint8_t txBufferSize, uint8_t* rxBuffer, uint8_t* txBuffer)
56+
:
5457
twiMaster{twiPtr},
5558
rxBufferSize{rxBufferSize},
5659
rxBuffer{rxBuffer},

libraries/Wire/Wire.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,17 @@ class TwoWireMasterOrSlave : public TwoWireBase
157157
extern TwoWire Wire;
158158
#endif
159159

160+
#ifndef TwoWire_h_IMPLEMENTATION
161+
162+
#ifdef TWOWIRE_MASTER_ONLY
163+
#undef TwoWireMaster
164+
using TwoWireMaster = TwoWire;
165+
#else
166+
#undef TwoWireMasterOrSlave
167+
using TwoWireMasterOrSlave = TwoWire;
160168
#endif
161169

170+
#endif // TwoWire_h_IMPLEMENTATION
171+
172+
#endif // TwoWire_h
173+

0 commit comments

Comments
 (0)