File tree 1 file changed +7
-0
lines changed
1 file changed +7
-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,14 @@ 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
+ // 5 seconds
144
+ uint64_t deadline = port_get_raw_ticks (NULL ) + 5 * 1024 ;
141
145
mp_obj_t list = mp_obj_new_list (0 , NULL );
142
146
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
143
147
for (int addr = 0x08 ; addr < 0x78 ; ++ addr ) {
148
+ if (port_get_raw_ticks (NULL ) > deadline ) {
149
+ mp_raise_OSError (MP_ETIMEDOUT );
150
+ }
144
151
bool success = common_hal_busio_i2c_probe (self , addr );
145
152
if (success ) {
146
153
mp_obj_list_append (list , MP_OBJ_NEW_SMALL_INT (addr ));
You can’t perform that action at this time.
0 commit comments