diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-24 15:13:07 +0100 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-24 15:13:07 +0100 |
| commit | 12fa5b3a66d6f0034113a56c7d647c7bac5be74c (patch) | |
| tree | cc4d5103421f930b7ebaa20eb7d6c8d59c6b6f0d /shared-bindings/bitbangio/SPI.c | |
| parent | efd429464ed82c78fd2e11244a803c7ec2cb2211 (diff) | |
Switch exception throwing to mp_raise helpers. It saves a little code space each time to share the call.
Diffstat (limited to 'shared-bindings/bitbangio/SPI.c')
| -rw-r--r-- | shared-bindings/bitbangio/SPI.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index a5d3f358f..83eb1b204 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -33,6 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "lib/utils/context_manager_helpers.h" +#include "py/mperrno.h" #include "py/runtime.h" //| .. currentmodule:: bitbangio @@ -113,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_obj___exit___obj, 4, 4, static void check_lock(bitbangio_spi_obj_t *self) { if (!shared_module_bitbangio_spi_has_lock(self)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Function requires SPI lock.")); + mp_raise_RuntimeError("Function requires lock"); } } @@ -136,15 +137,15 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args, uint8_t polarity = args[ARG_polarity].u_int; if (polarity != 0 && polarity != 1) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid polarity.")); + mp_raise_ValueError("Invalid polarity"); } uint8_t phase = args[ARG_phase].u_int; if (phase != 0 && phase != 1) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid phase.")); + mp_raise_ValueError("Invalid phase"); } uint8_t bits = args[ARG_bits].u_int; if (bits != 8 && bits != 9) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid number of bits.")); + mp_raise_ValueError("Invalid number of bits"); } shared_module_bitbangio_spi_configure(self, args[ARG_baudrate].u_int, polarity, phase, bits); @@ -183,7 +184,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) { check_lock(self); bool ok = shared_module_bitbangio_spi_write(self, src.buf, src.len); if (!ok) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error")); + mp_raise_OSError(MP_EIO); } return mp_const_none; } @@ -200,7 +201,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) { check_lock(args[0]); bool ok = shared_module_bitbangio_spi_read(args[0], bufinfo.buf, bufinfo.len); if (!ok) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "SPI bus error")); + mp_raise_OSError(MP_EIO); } return mp_const_none; } |
