stmhal: Make error messages more consistent across peripherals.

This commit is contained in:
Damien George 2017-06-15 12:02:14 +10:00
parent 48d867b4a6
commit 2bf5a947b2
12 changed files with 21 additions and 21 deletions

View File

@ -321,7 +321,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const
// init CAN (if it fails, it's because the port doesn't exist)
if (!can_init(self)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN port %d does not exist", self->can_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) doesn't exist", self->can_id));
}
return mp_const_none;
@ -357,13 +357,13 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_
can_idx = PYB_CAN_2;
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%s) does not exist", port));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%s) doesn't exist", port));
}
} else {
can_idx = mp_obj_get_int(args[0]);
}
if (can_idx < 1 || can_idx > MP_ARRAY_SIZE(MP_STATE_PORT(pyb_can_obj_all))) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) does not exist", can_idx));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) doesn't exist", can_idx));
}
pyb_can_obj_t *self;

View File

@ -221,7 +221,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
} else if (pin == &pin_A5) {
dac_id = 2;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q does not have DAC capabilities", pin->name));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have DAC capabilities", pin->name));
}
}
@ -237,7 +237,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
dac->dac_channel = DAC_CHANNEL_2;
dac->tx_dma_descr = &dma_DAC_2_TX;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "DAC %d does not exist", dac_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "DAC(%d) doesn't exist", dac_id));
}
// configure the peripheral

View File

@ -626,14 +626,14 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"I2C(%s) does not exist", port));
"I2C(%s) doesn't exist", port));
}
} else {
i2c_id = mp_obj_get_int(args[0]);
if (i2c_id < 1 || i2c_id > MP_ARRAY_SIZE(pyb_i2c_obj)
|| pyb_i2c_obj[i2c_id - 1].i2c == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"I2C(%d) does not exist", i2c_id));
"I2C(%d) doesn't exist", i2c_id));
}
}

View File

@ -220,7 +220,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
lcd->pin_a0 = &pyb_pin_Y5;
lcd->pin_bl = &pyb_pin_Y12;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LCD bus '%s' does not exist", lcd_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LCD(%s) doesn't exist", lcd_id));
}
// init the SPI bus

View File

@ -299,7 +299,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));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED(%d) doesn't exist", led_id));
}
// return static led object

View File

@ -510,14 +510,14 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"I2C(%s) does not exist", port));
"I2C(%s) doesn't exist", port));
}
} else {
i2c_id = mp_obj_get_int(args[ARG_id].u_obj);
if (i2c_id < 1 || i2c_id > MP_ARRAY_SIZE(machine_hard_i2c_obj)
|| machine_hard_i2c_obj[i2c_id - 1].base.type == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"I2C(%d) does not exist", i2c_id));
"I2C(%d) doesn't exist", i2c_id));
}
}

View File

@ -176,7 +176,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)));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%s) doesn't exist", mp_obj_str_get_str(user_obj)));
}
/// \method __str__()

View File

@ -194,7 +194,7 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz
// check servo number
if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo(%d) doesn't exist", servo_id + 1));
}
// get and init servo object

View File

@ -182,7 +182,7 @@ STATIC int spi_find(mp_obj_t id) {
#endif
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"SPI(%s) does not exist", port));
"SPI(%s) doesn't exist", port));
} else {
// given an integer id
int spi_id = mp_obj_get_int(id);
@ -191,7 +191,7 @@ STATIC int spi_find(mp_obj_t id) {
return spi_id;
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"SPI(%d) does not exist", spi_id));
"SPI(%d) doesn't exist", spi_id));
}
}

View File

@ -702,7 +702,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz
#if defined(TIM17)
case 17: tim->tim.Instance = TIM17; tim->irqn = TIM1_TRG_COM_TIM17_IRQn; break;
#endif
default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id));
default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer(%d) doesn't exist", tim->tim_id));
}
// set the global variable for interrupt callbacks
@ -896,7 +896,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
const pin_obj_t *pin = pin_obj;
const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id);
if (af == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q doesn't have an af for TIM%d", pin->name, self->tim_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have an af for Timer(%d)", pin->name, self->tim_id));
}
// pin.init(mode=AF_PP, af=idx)
const mp_obj_t args2[6] = {

View File

@ -615,7 +615,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
// init UART (if it fails, it's because the port doesn't exist)
if (!uart_init2(self)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", self->uart_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) doesn't exist", self->uart_id));
}
// set timeout
@ -751,12 +751,12 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
uart_id = PYB_UART_6;
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) does not exist", port));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) doesn't exist", port));
}
} else {
uart_id = mp_obj_get_int(args[0]);
if (!uart_exists(uart_id)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) doesn't exist", uart_id));
}
}

View File

@ -49,7 +49,7 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_int_t id = args[ARG_id].u_int;
if (id != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "WDT(%d) does not exist", id));
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "WDT(%d) doesn't exist", id));
}
// timeout is in milliseconds