Skip to content

Commit

Permalink
Merge pull request #2493 from fpistm/7bits_only
Browse files Browse the repository at this point in the history
fix(wire): support only 7 bits addressing mode
  • Loading branch information
fpistm authored Aug 22, 2024
2 parents 8032cb5 + 1b227db commit 0935852
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void TwoWire::begin(uint8_t address, bool generalCall, bool NoStretchMode)

recoverBus(); // in case I2C bus (device) is stuck after a reset for example

i2c_custom_init(&_i2c, 100000, I2C_ADDRESSINGMODE_7BIT, ownAddress);
i2c_init(&_i2c, 100000, ownAddress);

if (_i2c.isMaster == 0) {
// i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
Expand Down
15 changes: 2 additions & 13 deletions libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,25 +637,14 @@ static uint32_t i2c_getTiming(i2c_t *obj, uint32_t frequency)
return ret;
}

/**
* @brief Default init and setup GPIO and I2C peripheral
* @param obj : pointer to i2c_t structure
* @retval none
*/
void i2c_init(i2c_t *obj)
{
i2c_custom_init(obj, 100000, I2C_ADDRESSINGMODE_7BIT, 0x33);
}

/**
* @brief Initialize and setup GPIO and I2C peripheral
* @param obj : pointer to i2c_t structure
* @param timing : one of the i2c_timing_e
* @param addressingMode : I2C_ADDRESSINGMODE_7BIT or I2C_ADDRESSINGMODE_10BIT
* @param ownAddress : device address
* @retval none
*/
void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint32_t ownAddress)
void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
{
if (obj != NULL) {

Expand Down Expand Up @@ -771,7 +760,7 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
#endif
handle->Init.OwnAddress1 = ownAddress;
handle->Init.OwnAddress2 = 0;
handle->Init.AddressingMode = addressingMode;
handle->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
handle->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
handle->Init.GeneralCallMode = (obj->generalCall == 0) ? I2C_GENERALCALL_DISABLE : I2C_GENERALCALL_ENABLE;
handle->Init.NoStretchMode = (obj->NoStretchMode == 0) ? I2C_NOSTRETCH_DISABLE : I2C_NOSTRETCH_ENABLE;
Expand Down
4 changes: 1 addition & 3 deletions libraries/Wire/src/utility/twi.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ typedef enum {
} i2c_status_e;

/* Exported functions ------------------------------------------------------- */
void i2c_init(i2c_t *obj);
void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode,
uint32_t ownAddress);
void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress);
void i2c_deinit(i2c_t *obj);
void i2c_setTiming(i2c_t *obj, uint32_t frequency);
i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address, uint8_t *data, uint16_t size);
Expand Down

0 comments on commit 0935852

Please sign in to comment.