@@ -49,11 +49,11 @@ void never_reset_i2c(i2c_port_t num) {
49
49
void i2c_reset (void ) {
50
50
for (i2c_port_t num = 0 ; num < I2C_NUM_MAX ; num ++ ) {
51
51
if (i2c_status [num ] == STATUS_IN_USE ) {
52
- i2c_driver_delete (num );
53
52
i2c_status [num ] = STATUS_FREE ;
54
53
}
55
54
}
56
55
}
56
+ static bool i2c_inited [I2C_NUM_MAX ];
57
57
58
58
void common_hal_busio_i2c_construct (busio_i2c_obj_t * self ,
59
59
const mcu_pin_obj_t * scl , const mcu_pin_obj_t * sda , uint32_t frequency , uint32_t timeout ) {
@@ -121,13 +121,19 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
121
121
if (result != ESP_OK ) {
122
122
mp_raise_ValueError (translate ("Invalid pins" ));
123
123
}
124
- result = i2c_driver_install (self -> i2c_num ,
125
- I2C_MODE_MASTER ,
126
- 0 ,
127
- 0 ,
128
- 0 );
129
- if (result != ESP_OK ) {
130
- mp_raise_OSError (MP_EIO );
124
+
125
+
126
+ if (!i2c_inited [self -> i2c_num ]) {
127
+ result = i2c_driver_install (self -> i2c_num ,
128
+ I2C_MODE_MASTER ,
129
+ 0 ,
130
+ 0 ,
131
+ 0 );
132
+ if (result != ESP_OK ) {
133
+ mp_raise_OSError (MP_EIO );
134
+ }
135
+ i2c_inited [self -> i2c_num ] = true;
136
+
131
137
}
132
138
133
139
claim_pin (sda );
@@ -143,7 +149,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
143
149
return ;
144
150
}
145
151
146
- i2c_driver_delete (self -> i2c_num );
147
152
i2c_status [self -> i2c_num ] = STATUS_FREE ;
148
153
149
154
common_hal_reset_pin (self -> sda_pin );
0 commit comments