I found some very old code which seems to work but uses the API provided by driver/i2c.h. Since it is recommended to use the newer API driver/i2c_master.h I try to rewrite the code but having problems getting my head around it.
As per the BME-API one has to provide a write function for the used bus (which is I2C in my case). The signature is as follows:
Code: Select all
BME68X_INTF_RET_TYPE (*bme68x_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr);
My old code is this:
Code: Select all
int i2c_slave_write(uint8_t bus, uint8_t addr, const uint8_t *reg,
uint8_t *data, uint32_t len) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, addr << 1 | I2C_MASTER_WRITE, true);
if (reg)
i2c_master_write_byte(cmd, *reg, true);
if (data)
i2c_master_write(cmd, data, len, true);
i2c_master_stop(cmd);
esp_err_t err = i2c_master_cmd_begin(bus, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
return err;
}
How would I go about it with the new i2c_master.h API?
Currently I have something like this:
Code: Select all
BME68X_INTF_RET_TYPE BME680::write_i2c(uint8_t reg_addr,
const uint8_t *reg_data,
uint32_t length,
void *intf_ptr) {
assert(_instance->_device_handle);
error = i2c_master_transmit(_instance->_device_handle,
reg_data,
length,
-1);
if (error != ESP_OK) {
ESP_ERROR_CHECK_WITHOUT_ABORT(error);
return -1;
}
return 0;
}
Can anyone help?