File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ SDPSensor::SDPSensor(uint8_t i2c_addr, i2c_port_t i2c_port) {
6262}
6363
6464
65- void SDPSensor::initI2C (int pinSDA, int pinSCL) {
65+ esp_err_t SDPSensor::initI2C (int pinSDA, int pinSCL) {
6666 int intr_flag_disable = 0 ;
6767
6868 /* I2C master doesn't need buffer */
@@ -78,13 +78,23 @@ void SDPSensor::initI2C(int pinSDA, int pinSCL) {
7878 };
7979 conf.master .clk_speed = 400000 ; /* !< I2C master clock frequency */
8080
81- ESP_ERROR_CHECK (i2c_param_config (i2c_port, &conf));
82-
83- ESP_ERROR_CHECK (
84- i2c_driver_install (i2c_port, conf.mode ,
81+ esp_err_t err;
82+ err = i2c_param_config (i2c_port, &conf);
83+ if (err != ESP_OK) {
84+ ESP_LOGE (TAG_SDPSENSOR, " Could not configure the I2C: %s" , esp_err_to_name (err));
85+ return err;
86+ }
87+
88+ err = i2c_driver_install (i2c_port, conf.mode ,
8589 i2c_master_rx_buf_disable, i2c_master_tx_buf_disable,
86- intr_flag_disable));
90+ intr_flag_disable);
91+ if (err != ESP_OK) {
92+ ESP_LOGE (TAG_SDPSENSOR, " Could not initialize the I2C: %s" , esp_err_to_name (err));
93+ return err;
94+ }
8795 ESP_LOGI (TAG_SDPSENSOR, " I2C%d line initialized" , i2c_port);
96+
97+ return err;
8898}
8999
90100
Original file line number Diff line number Diff line change @@ -37,8 +37,10 @@ class SDPSensor {
3737 *
3838 * @param pinSDA - SDA GPIO
3939 * @param pinSCL - SCL GPIO
40+ *
41+ * @returns the error code (defined in esp_err.h)
4042 */
41- void initI2C (int pinSDA, int pinSCL);
43+ esp_err_t initI2C (int pinSDA, int pinSCL);
4244
4345
4446 /* *
You can’t perform that action at this time.
0 commit comments