36
36
#include "common-hal/microcontroller/Pin.h"
37
37
38
38
STATIC bool reserved_i2c [3 ];
39
+ STATIC bool never_reset [3 ];
39
40
40
41
void i2c_reset (void ) {
41
42
//Note: I2Cs are also forcibly reset in construct, due to silicon error
@@ -48,11 +49,24 @@ void i2c_reset(void) {
48
49
__HAL_RCC_I2C2_CLK_DISABLE ();
49
50
#endif
50
51
#ifdef I2C3
51
- reserved_i2c [3 ] = false;
52
+ reserved_i2c [2 ] = false;
52
53
__HAL_RCC_I2C3_CLK_DISABLE ();
53
54
#endif
54
55
}
55
56
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
+
56
70
void common_hal_busio_i2c_construct (busio_i2c_obj_t * self ,
57
71
const mcu_pin_obj_t * scl , const mcu_pin_obj_t * sda , uint32_t frequency , uint32_t timeout ) {
58
72
@@ -166,19 +180,22 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
166
180
}
167
181
#ifdef I2C1
168
182
if (self -> handle .Instance == I2C1 ) {
169
- reserved_i2c [0 ] = 0 ;
183
+ never_reset [0 ] = false;
184
+ reserved_i2c [0 ] = false;
170
185
__HAL_RCC_I2C1_CLK_DISABLE ();
171
186
}
172
187
#endif
173
188
#ifdef I2C2
174
189
if (self -> handle .Instance == I2C2 ) {
175
- reserved_i2c [1 ] = 0 ;
190
+ never_reset [1 ] = false;
191
+ reserved_i2c [1 ] = false;
176
192
__HAL_RCC_I2C2_CLK_DISABLE ();
177
193
}
178
194
#endif
179
195
#ifdef I2C3
180
196
if (self -> handle .Instance == I2C3 ) {
181
- reserved_i2c [3 ] = 0 ;
197
+ never_reset [2 ] = false;
198
+ reserved_i2c [2 ] = false;
182
199
__HAL_RCC_I2C3_CLK_DISABLE ();
183
200
}
184
201
#endif
0 commit comments