File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 33
33
34
34
#include "shared/runtime/buffer_helper.h"
35
35
#include "shared/runtime/context_manager_helpers.h"
36
+ #include "py/mperrno.h"
36
37
#include "py/runtime.h"
38
+ #include "supervisor/port.h"
37
39
#include "supervisor/shared/translate.h"
38
40
39
41
//| class I2C:
@@ -138,9 +140,13 @@ STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
138
140
busio_i2c_obj_t * self = MP_OBJ_TO_PTR (self_in );
139
141
check_for_deinit (self );
140
142
check_lock (self );
143
+ uint64_t deadline = port_get_raw_ticks (NULL ) + 2048 ;
141
144
mp_obj_t list = mp_obj_new_list (0 , NULL );
142
145
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
143
146
for (int addr = 0x08 ; addr < 0x78 ; ++ addr ) {
147
+ if (port_get_raw_ticks (NULL ) > deadline ) {
148
+ mp_raise_OSError (MP_ETIMEDOUT );
149
+ }
144
150
bool success = common_hal_busio_i2c_probe (self , addr );
145
151
if (success ) {
146
152
mp_obj_list_append (list , MP_OBJ_NEW_SMALL_INT (addr ));
You can’t perform that action at this time.
0 commit comments