nrf: Shrink "<peripheral> does not exist" error messages.

Code size reductions:
nrf51: -132
nrf52: -188
This commit is contained in:
Ayke van Laethem 2018-08-02 15:42:24 +02:00 committed by Damien George
parent 1ba962ff57
commit 4e1c2fc831
9 changed files with 13 additions and 24 deletions

View File

@ -105,7 +105,7 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
// check led number
if (!(1 <= led_id && led_id <= NUM_LEDS)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED(%d) does not exist", led_id));
mp_raise_ValueError("LED doesn't exist");
}
// return static led object

View File

@ -100,8 +100,7 @@ STATIC int adc_find(mp_obj_t id) {
&& machine_adc_obj[adc_idx].id != (uint8_t)-1) {
return adc_idx;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"ADC(%d) does not exist", adc_id));
mp_raise_ValueError("ADC doesn't exist");
}
/// \method __str__()

View File

@ -58,8 +58,7 @@ STATIC int i2c_find(mp_obj_t id) {
if (i2c_id >= 0 && i2c_id < MP_ARRAY_SIZE(machine_hard_i2c_obj)) {
return i2c_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"I2C(%d) does not exist", i2c_id));
mp_raise_ValueError("I2C doesn't exist");
}
STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

View File

@ -207,7 +207,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
return pin_obj;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", mp_obj_str_get_str(user_obj)));
mp_raise_ValueError("not a valid pin identifier");
}
/// \method __str__()

View File

@ -99,8 +99,7 @@ STATIC int hard_pwm_find(mp_obj_t id) {
if (pwm_id >= 0 && pwm_id < MP_ARRAY_SIZE(machine_hard_pwm_obj)) {
return pwm_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"PWM(%d) does not exist", pwm_id));
mp_raise_ValueError("PWM doesn't exist");
}
return -1;
}
@ -252,8 +251,7 @@ STATIC mp_obj_t machine_hard_pwm_make_new(mp_arg_val_t *args) {
if (args[ARG_period].u_obj != MP_OBJ_NULL) {
self->p_config->period = mp_obj_get_int(args[ARG_period].u_obj);
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"PWM period has to be within 16000 frequence cycles", self->p_config->period));
mp_raise_ValueError("PWM period must be within 16000 cycles");
}
if (args[ARG_duty].u_obj != MP_OBJ_NULL) {

View File

@ -116,8 +116,7 @@ STATIC int rtc_find(mp_obj_t id) {
if (rtc_id >= 0 && rtc_id < MP_ARRAY_SIZE(machine_rtc_obj)) {
return rtc_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"RTCounter(%d) does not exist", rtc_id));
mp_raise_ValueError("RTCounter doesn't exist");
}
STATIC void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

View File

@ -140,16 +140,14 @@ STATIC int spi_find(mp_obj_t id) {
return 1;
#endif
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"SPI(%s) does not exist", port));
mp_raise_ValueError("SPI doesn't exist");
} else {
// given an integer id
int spi_id = mp_obj_get_int(id);
if (spi_id >= 0 && spi_id < MP_ARRAY_SIZE(machine_hard_spi_obj)) {
return spi_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"SPI(%d) does not exist", spi_id));
mp_raise_ValueError("SPI doesn't exist");
}
}

View File

@ -75,8 +75,7 @@ STATIC int timer_find(mp_obj_t id) {
if (timer_id >= 0 && timer_id < MP_ARRAY_SIZE(machine_timer_obj)) {
return timer_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Timer(%d) does not exist", timer_id));
mp_raise_ValueError("Timer doesn't exist");
}
STATIC void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
@ -113,15 +112,13 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
#if BLUETOOTH_SD
if (timer_id == 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Timer(%d) reserved by Bluetooth LE stack.", timer_id));
mp_raise_ValueError("Timer reserved by Bluetooth LE stack");
}
#endif
#if MICROPY_PY_MACHINE_SOFT_PWM
if (timer_id == 1) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"Timer(%d) reserved by ticker driver.", timer_id));
mp_raise_ValueError("Timer reserved by ticker driver");
}
#endif

View File

@ -67,8 +67,7 @@ STATIC int uart_find(mp_obj_t id) {
if (uart_id >= 0 && uart_id < MP_ARRAY_SIZE(machine_hard_uart_obj)) {
return uart_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"UART(%d) does not exist", uart_id));
mp_raise_ValueError("UART doesn't exist");
}
void uart_irq_handler(mp_uint_t uart_id) {