Skip to content

Commit f7e9716

Browse files
committed
[I2C] Add general call mode API
Adding true to the 3 Wire::begin() method will enable the general call mode else false per default. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent b545595 commit f7e9716

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

cores/arduino/stm32/twi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
192192
handle->Init.OwnAddress2 = 0xFF;
193193
handle->Init.AddressingMode = addressingMode;
194194
handle->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
195-
handle->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
195+
handle->Init.GeneralCallMode = (obj->generalCall == 0) ? I2C_GENERALCALL_DISABLE : I2C_GENERALCALL_ENABLE;
196196
handle->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
197197

198198
handle->State = HAL_I2C_STATE_RESET;

cores/arduino/stm32/twi.h

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct i2c_s {
107107
volatile uint8_t i2cTxRxBufferSize;
108108
volatile uint8_t slaveMode;
109109
uint8_t isMaster;
110+
uint8_t generalCall;
110111
};
111112

112113
///@brief I2C state

libraries/Wire/src/Wire.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ TwoWire::TwoWire(uint8_t sda, uint8_t scl)
5959

6060
// Public Methods //////////////////////////////////////////////////////////////
6161

62-
void TwoWire::begin(void)
62+
void TwoWire::begin(bool generalCall)
6363
{
64-
begin(MASTER_ADDRESS);
64+
begin(MASTER_ADDRESS, generalCall);
6565
}
6666

67-
void TwoWire::begin(uint8_t address)
67+
void TwoWire::begin(uint8_t address, bool generalCall)
6868
{
6969
rxBufferIndex = 0;
7070
rxBufferLength = 0;
@@ -80,6 +80,8 @@ void TwoWire::begin(uint8_t address)
8080

8181
_i2c.isMaster = (address == MASTER_ADDRESS) ? 1 : 0;
8282

83+
_i2c.generalCall = (generalCall == true) ? 1 : 0;
84+
8385
i2c_custom_init(&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress);
8486

8587
if (_i2c.isMaster == 0) {
@@ -91,9 +93,9 @@ void TwoWire::begin(uint8_t address)
9193
}
9294
}
9395

94-
void TwoWire::begin(int address)
96+
void TwoWire::begin(int address, bool generalCall)
9597
{
96-
begin((uint8_t)address);
98+
begin((uint8_t)address, generalCall);
9799
}
98100

99101
void TwoWire::end(void)

libraries/Wire/src/Wire.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class TwoWire : public Stream {
8282
{
8383
_i2c.sda = sda;
8484
};
85-
void begin();
86-
void begin(uint8_t);
87-
void begin(int);
85+
void begin(bool generalCall = false);
86+
void begin(uint8_t, bool generalCall = false);
87+
void begin(int, bool generalCall = false);
8888
void end();
8989
void setClock(uint32_t);
9090
void beginTransmission(uint8_t);

0 commit comments

Comments
 (0)