@@ -59,12 +59,12 @@ TwoWire::TwoWire(uint8_t sda, uint8_t scl)
59
59
60
60
// Public Methods //////////////////////////////////////////////////////////////
61
61
62
- void TwoWire::begin (void )
62
+ void TwoWire::begin (bool generalCall )
63
63
{
64
- begin (MASTER_ADDRESS);
64
+ begin (MASTER_ADDRESS, generalCall );
65
65
}
66
66
67
- void TwoWire::begin (uint8_t address)
67
+ void TwoWire::begin (uint8_t address, bool generalCall )
68
68
{
69
69
rxBufferIndex = 0 ;
70
70
rxBufferLength = 0 ;
@@ -78,15 +78,13 @@ void TwoWire::begin(uint8_t address)
78
78
79
79
ownAddress = address << 1 ;
80
80
81
- if (address == MASTER_ADDRESS) {
82
- master = true ;
83
- } else {
84
- master = false ;
85
- }
81
+ _i2c.isMaster = (address == MASTER_ADDRESS) ? 1 : 0 ;
82
+
83
+ _i2c.generalCall = (generalCall == true ) ? 1 : 0 ;
86
84
87
- i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress, master );
85
+ i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress);
88
86
89
- if (master == false ) {
87
+ if (_i2c. isMaster == 0 ) {
90
88
// i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
91
89
// i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*, uint8_t*, int)>(&TwoWire::onReceiveService));
92
90
@@ -95,9 +93,9 @@ void TwoWire::begin(uint8_t address)
95
93
}
96
94
}
97
95
98
- void TwoWire::begin (int address)
96
+ void TwoWire::begin (int address, bool generalCall )
99
97
{
100
- begin ((uint8_t )address);
98
+ begin ((uint8_t )address, generalCall );
101
99
}
102
100
103
101
void TwoWire::end (void )
@@ -119,7 +117,7 @@ void TwoWire::setClock(uint32_t frequency)
119
117
uint8_t TwoWire::requestFrom (uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
120
118
{
121
119
UNUSED (sendStop);
122
- if (master == true ) {
120
+ if (_i2c. isMaster == 1 ) {
123
121
allocateRxBuffer (quantity);
124
122
// error if no memory block available to allocate the buffer
125
123
if (rxBuffer == nullptr ) {
@@ -216,7 +214,7 @@ uint8_t TwoWire::endTransmission(uint8_t sendStop)
216
214
UNUSED (sendStop);
217
215
int8_t ret = 4 ;
218
216
219
- if (master == true ) {
217
+ if (_i2c. isMaster == 1 ) {
220
218
// transmit buffer (blocking)
221
219
switch (i2c_master_write (&_i2c, txAddress, txBuffer, txBufferLength)) {
222
220
case I2C_OK :
0 commit comments