|
31 | 31 | #include "shared-bindings/microcontroller/Pin.h" |
32 | 32 |
|
33 | 33 | #include "lib/utils/context_manager_helpers.h" |
| 34 | +#include "py/mperrno.h" |
34 | 35 | #include "py/runtime.h" |
35 | 36 | //| .. currentmodule:: bitbangio |
36 | 37 | //| |
@@ -129,8 +130,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan); |
129 | 130 | //| Attempts to grab the I2C lock. Returns True on success. |
130 | 131 | //| |
131 | 132 | STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) { |
132 | | - shared_module_bitbangio_i2c_try_lock(MP_OBJ_TO_PTR(self_in)); |
133 | | - return self_in; |
| 133 | + return mp_obj_new_bool(shared_module_bitbangio_i2c_try_lock(MP_OBJ_TO_PTR(self_in))); |
134 | 134 | } |
135 | 135 | MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock); |
136 | 136 |
|
@@ -183,7 +183,13 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a |
183 | 183 | } else if (len > bufinfo.len) { |
184 | 184 | len = bufinfo.len; |
185 | 185 | } |
186 | | - shared_module_bitbangio_i2c_read(self, args[ARG_address].u_int, ((uint8_t*)bufinfo.buf) + start, len); |
| 186 | + uint8_t status = shared_module_bitbangio_i2c_read(self, |
| 187 | + args[ARG_address].u_int, |
| 188 | + ((uint8_t*)bufinfo.buf) + start, |
| 189 | + len); |
| 190 | + if (status != 0) { |
| 191 | + mp_raise_OSError(status); |
| 192 | + } |
187 | 193 | return mp_const_none; |
188 | 194 | } |
189 | 195 | MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into); |
@@ -235,10 +241,10 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m |
235 | 241 | } |
236 | 242 |
|
237 | 243 | // do the transfer |
238 | | - bool ok = shared_module_bitbangio_i2c_write(self, args[ARG_address].u_int, |
| 244 | + uint8_t status = shared_module_bitbangio_i2c_write(self, args[ARG_address].u_int, |
239 | 245 | ((uint8_t*) bufinfo.buf) + start, len, args[ARG_stop].u_bool); |
240 | | - if (!ok) { |
241 | | - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "I2C bus error")); |
| 246 | + if (status != 0) { |
| 247 | + mp_raise_OSError(status); |
242 | 248 | } |
243 | 249 | return mp_const_none; |
244 | 250 | } |
|
0 commit comments