3636#include "common-hal/microcontroller/Pin.h"
3737
3838STATIC bool reserved_i2c [3 ];
39+ STATIC bool never_reset [3 ];
3940
4041void i2c_reset (void ) {
4142 //Note: I2Cs are also forcibly reset in construct, due to silicon error
@@ -48,11 +49,24 @@ void i2c_reset(void) {
4849 __HAL_RCC_I2C2_CLK_DISABLE ();
4950 #endif
5051 #ifdef I2C3
51- reserved_i2c [3 ] = false;
52+ reserved_i2c [2 ] = false;
5253 __HAL_RCC_I2C3_CLK_DISABLE ();
5354 #endif
5455}
5556
57+ void common_hal_busio_i2c_never_reset (busio_i2c_obj_t * self ) {
58+ for (size_t i = 0 ; i < MP_ARRAY_SIZE (mcu_i2c_banks ); i ++ ) {
59+ if (self -> handle .Instance == mcu_i2c_banks [i ]) {
60+ never_reset [i ] = true;
61+
62+ never_reset_pin_number (self -> scl -> pin -> port , self -> scl -> pin -> number );
63+ never_reset_pin_number (self -> sda -> pin -> port , self -> scl -> pin -> number );
64+ break ;
65+ }
66+ }
67+ }
68+
69+
5670void common_hal_busio_i2c_construct (busio_i2c_obj_t * self ,
5771 const mcu_pin_obj_t * scl , const mcu_pin_obj_t * sda , uint32_t frequency , uint32_t timeout ) {
5872
@@ -166,19 +180,22 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
166180 }
167181 #ifdef I2C1
168182 if (self -> handle .Instance == I2C1 ) {
169- reserved_i2c [0 ] = 0 ;
183+ never_reset [0 ] = false;
184+ reserved_i2c [0 ] = false;
170185 __HAL_RCC_I2C1_CLK_DISABLE ();
171186 }
172187 #endif
173188 #ifdef I2C2
174189 if (self -> handle .Instance == I2C2 ) {
175- reserved_i2c [1 ] = 0 ;
190+ never_reset [1 ] = false;
191+ reserved_i2c [1 ] = false;
176192 __HAL_RCC_I2C2_CLK_DISABLE ();
177193 }
178194 #endif
179195 #ifdef I2C3
180196 if (self -> handle .Instance == I2C3 ) {
181- reserved_i2c [3 ] = 0 ;
197+ never_reset [2 ] = false;
198+ reserved_i2c [2 ] = false;
182199 __HAL_RCC_I2C3_CLK_DISABLE ();
183200 }
184201 #endif
0 commit comments