#include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "driver/i2c.h" #include "mpr121.h" void i2c_setRegister(MPR121_t * dev, uint8_t reg, uint8_t value) { i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev->_address << 1) | I2C_MASTER_WRITE, true); i2c_master_write_byte(cmd, reg, true); i2c_master_write_byte(cmd, value, true); i2c_master_stop(cmd); esp_err_t espRc = i2c_master_cmd_begin(I2C_NUM, cmd, 10/portTICK_PERIOD_MS); if (espRc == ESP_OK) { ESP_LOGD(__FUNCTION__, "setRegister reg=0x%02x value=0x%02x successfully", reg, value); dev->error &= ~(1<error |= 1<_address << 1) | I2C_MASTER_WRITE, true); i2c_master_write_byte(cmd, reg, true); i2c_master_start(cmd); i2c_master_write_byte(cmd, (dev->_address << 1) | I2C_MASTER_READ, true); i2c_master_read(cmd, buf, 1, I2C_MASTER_NACK); i2c_master_stop(cmd); esp_err_t espRc = i2c_master_cmd_begin(I2C_NUM, cmd, 10/portTICK_PERIOD_MS); if (espRc == ESP_OK) { dev->error &= ~(1<error |= 1<