8000 Use more mp_raise_* to save 28 bytes code size. · sparkfun/circuitpython@0bf999f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bf999f

Browse files
committed
Use more mp_raise_* to save 28 bytes code size.
1 parent 4e7eee3 commit 0bf999f

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

shared-bindings/microcontroller/Pin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "py/nlr.h"
3232
#include "py/obj.h"
33+
#include "py/runtime.h"
3334

3435
//| .. currentmodule:: microcontroller
3536
//|
@@ -74,7 +75,7 @@ const mp_obj_type_t mcu_pin_type = {
7475

7576
void assert_pin(mp_obj_t obj, bool none_ok) {
7677
if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) {
77-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", mcu_pin_type.name));
78+
mp_raise_TypeError_varg("Expected a %q", mcu_pin_type.name);
7879
}
7980
}
8081

shared-bindings/neopixel_write/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
//|
6565
STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) {
6666
if (!MP_OBJ_IS_TYPE(digitalinout_obj, &digitalio_digitalinout_type)) {
67-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", digitalio_digitalinout_type.name));
67+
mp_raise_TypeError_varg("Expected a %q", digitalio_digitalinout_type.name);
6868
}
6969
// Convert parameters into expected types.
7070
const digitalio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj);

shared-bindings/pulseio/PulseOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar
7171
mp_obj_t carrier_obj = args[0];
7272

7373
if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) {
74-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", pulseio_pwmout_type.name));
74+
mp_raise_TypeError_varg("Expected a %q", pulseio_pwmout_type.name);
7575
}
7676

7777
// create Pulse object from the given pin

shared-module/bitbangio/SPI.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
#include "mpconfigport.h"
2828

29-
#include "py/nlr.h"
3029
#include "py/obj.h"
30+
#include "py/runtime.h"
3131

3232
#include "common-hal/microcontroller/Pin.h"
3333
#include "shared-bindings/microcontroller/__init__.h"
@@ -41,15 +41,13 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
4141
const mcu_pin_obj_t * miso) {
4242
digitalinout_result_t result = common_hal_digitalio_digitalinout_construct(&self->clock, clock);
4343
if (result != DIGITALINOUT_OK) {
44-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
45-
"Clock pin init failed."));
44+
mp_raise_ValueError("Clock pin init failed.");
4645
}
4746
if (mosi != mp_const_none) {
4847
result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi);
4948
if (result != DIGITALINOUT_OK) {
5049
common_hal_digitalio_digitalinout_deinit(&self->clock);
51-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
52-
"MOSI pin init failed."));
50+
mp_raise_ValueError("MOSI pin init failed.");
5351
}
5452
self->has_mosi = true;
5553
}
@@ -60,8 +58,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
6058
if (mosi != mp_const_none) {
6159
common_hal_digitalio_digitalinout_deinit(&self->mosi);
6260
}
63-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
64-
"MISO pin init failed."));
61+
mp_raise_ValueError("MISO pin init failed.");
6562
}
6663
self->has_miso = true;
6764
}
@@ -121,8 +118,7 @@ void shared_module_bitbangio_spi_unlock(bitbangio_spi_obj_t *self) {
121118
// Writes out the given data.
122119
bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t *data, size_t len) {
123120
if (len > 0 && !self->has_mosi) {
124-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
125-
"Cannot write without MOSI pin."));
121+
mp_raise_ValueError("Cannot write without MOSI pin.");
126122
}
127123
uint32_t delay_half = self->delay_half;
128124

@@ -177,8 +173,7 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t
177173
// Reads in len bytes while outputting zeroes.
178174
bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data, size_t len) {
179175
if (len > 0 && !self->has_miso) {
180-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
181-
"Cannot read without MISO pin."));
176+
mp_raise_ValueError("Cannot read without MISO pin.");
182177
}
183178

184179
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,
242237
// transfer
243238
bool shared_module_bitbangio_spi_transfer(bitbangio_spi_obj_t *self, const uint8_t *dout, uint8_t *din, size_t len) {
244239
if (len > 0 && (!self->has_mosi || !self->has_miso) ) {
245-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
246-
"Cannot transfer without MOSI and MISO pins."));
240+
mp_raise_ValueError("Cannot transfer without MOSI and MISO pins.");
247241
}
248242
uint32_t delay_half = self->delay_half;
249243

0 commit comments

Comments
 (0)
0