diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-07-31 19:09:10 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-31 19:09:10 -0400 |
| commit | 761f9a938e3b8f8ddadc5b16687126c92a68cdd4 (patch) | |
| tree | c1a43903e4b29fc537f4d373e4f826b469177f0d /shared-module | |
| parent | bf033123a7fa75394fd7a01d17ec99afd9abe645 (diff) | |
| parent | 0bf999f52a50590f4c660df41aa979f39da04c38 (diff) | |
Merge pull request #1075 from tannewt/more_mp_raise
Use more mp_raise_* to save 28 bytes code size.
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/bitbangio/SPI.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c index e572d4aab..b203fe1b4 100644 --- a/shared-module/bitbangio/SPI.c +++ b/shared-module/bitbangio/SPI.c @@ -26,8 +26,8 @@ #include "mpconfigport.h" -#include "py/nlr.h" #include "py/obj.h" +#include "py/runtime.h" #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" @@ -41,15 +41,13 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, const mcu_pin_obj_t * miso) { digitalinout_result_t result = common_hal_digitalio_digitalinout_construct(&self->clock, clock); if (result != DIGITALINOUT_OK) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "Clock pin init failed.")); + mp_raise_ValueError("Clock pin init failed."); } if (mosi != mp_const_none) { result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi); if (result != DIGITALINOUT_OK) { common_hal_digitalio_digitalinout_deinit(&self->clock); - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "MOSI pin init failed.")); + mp_raise_ValueError("MOSI pin init failed."); } self->has_mosi = true; } @@ -60,8 +58,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self, if (mosi != mp_const_none) { common_hal_digitalio_digitalinout_deinit(&self->mosi); } - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "MISO pin init failed.")); + mp_raise_ValueError("MISO pin init failed."); } self->has_miso = true; } @@ -121,8 +118,7 @@ void shared_module_bitbangio_spi_unlock(bitbangio_spi_obj_t *self) { // Writes out the given data. bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t *data, size_t len) { if (len > 0 && !self->has_mosi) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "Cannot write without MOSI pin.")); + mp_raise_ValueError("Cannot write without MOSI pin."); } uint32_t delay_half = self->delay_half; @@ -177,8 +173,7 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t // Reads in len bytes while outputting zeroes. bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data, size_t len) { if (len > 0 && !self->has_miso) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "Cannot read without MISO pin.")); + mp_raise_ValueError("Cannot read without MISO pin."); } uint32_t delay_half = self->delay_half; @@ -242,8 +237,7 @@ bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data, // transfer bool shared_module_bitbangio_spi_transfer(bitbangio_spi_obj_t *self, const uint8_t *dout, uint8_t *din, size_t len) { if (len > 0 && (!self->has_mosi || !self->has_miso) ) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "Cannot transfer without MOSI and MISO pins.")); + mp_raise_ValueError("Cannot transfer without MOSI and MISO pins."); } uint32_t delay_half = self->delay_half; |
