Use more mp_raise_* to save 28 bytes code size.
This commit is contained in:
parent
4e7eee3553
commit
0bf999f52a
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| .. currentmodule:: microcontroller
|
||||
//|
|
||||
|
@ -74,7 +75,7 @@ const mp_obj_type_t mcu_pin_type = {
|
|||
|
||||
void assert_pin(mp_obj_t obj, bool none_ok) {
|
||||
if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", mcu_pin_type.name));
|
||||
mp_raise_TypeError_varg("Expected a %q", mcu_pin_type.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
//|
|
||||
STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) {
|
||||
if (!MP_OBJ_IS_TYPE(digitalinout_obj, &digitalio_digitalinout_type)) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", digitalio_digitalinout_type.name));
|
||||
mp_raise_TypeError_varg("Expected a %q", digitalio_digitalinout_type.name);
|
||||
}
|
||||
// Convert parameters into expected types.
|
||||
const digitalio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj);
|
||||
|
|
|
@ -71,7 +71,7 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
mp_obj_t carrier_obj = args[0];
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", pulseio_pwmout_type.name));
|
||||
mp_raise_TypeError_varg("Expected a %q", pulseio_pwmout_type.name);
|
||||
}
|
||||
|
||||
// create Pulse object from the given pin
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue