address jepler's comments and further squeezes

This commit is contained in:
Dan Halbert 2022-05-20 10:10:55 -04:00
parent 3c20b5f95f
commit f63b26c534
30 changed files with 118 additions and 132 deletions

View File

@ -80,6 +80,10 @@ msgstr ""
msgid "%q and %q contain duplicate pins"
msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "%q and %q must be different"
msgstr ""
#: shared-bindings/microcontroller/Pin.c
msgid "%q contains duplicate pins"
msgstr ""
@ -179,9 +183,9 @@ msgstr ""
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
#: ports/cxd56/common-hal/pulseio/PulseIn.c
#: ports/nrf/common-hal/pulseio/PulseIn.c
#: ports/raspberrypi/common-hal/pulseio/PulseIn.c
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: ports/stm/common-hal/pulseio/PulseIn.c shared-bindings/canio/Match.c
#: ports/stm/common-hal/pulseio/PulseIn.c py/argcheck.c
#: shared-bindings/canio/Match.c
msgid "%q out of range"
msgstr ""
@ -646,6 +650,10 @@ msgstr ""
msgid "Call super().__init__() before accessing native object."
msgstr ""
#: ports/cxd56/common-hal/camera/Camera.c
msgid "Camera init"
msgstr ""
#: ports/espressif/common-hal/alarm/pin/PinAlarm.c
msgid "Can only alarm on RTC IO from deep sleep."
msgstr ""
@ -693,18 +701,10 @@ msgstr ""
msgid "Cannot have scan responses for extended, connectable advertisements."
msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "Cannot output both channels on the same pin"
msgstr ""
#: ports/espressif/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot pull on input-only pin."
msgstr ""
#: shared-module/bitbangio/SPI.c
msgid "Cannot read without MISO pin"
msgstr ""
#: shared-bindings/audiobusio/PDMIn.c
msgid "Cannot record to a file"
msgstr ""
@ -752,10 +752,6 @@ msgstr ""
msgid "Cannot wake on pin edge. Only level."
msgstr ""
#: shared-module/bitbangio/SPI.c
msgid "Cannot write without MOSI pin"
msgstr ""
#: shared-bindings/_bleio/CharacteristicBuffer.c
msgid "CharacteristicBuffer writing not provided"
msgstr ""
@ -786,28 +782,6 @@ msgstr ""
msgid "Corrupt .mpy file"
msgstr ""
#: ports/cxd56/common-hal/camera/Camera.c ports/cxd56/common-hal/gnss/GNSS.c
#: ports/cxd56/common-hal/sdioio/SDCard.c
msgid "Could not initialize %q"
msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
#: ports/espressif/common-hal/busio/UART.c
msgid "Could not initialize UART"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "Could not re-init channel"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "Could not re-init timer"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "Could not restart PWM"
msgstr ""
#: ports/espressif/common-hal/neopixel_write/__init__.c
msgid "Could not retrieve clock"
msgstr ""
@ -1038,6 +1012,10 @@ msgstr ""
msgid "Function requires lock"
msgstr ""
#: ports/cxd56/common-hal/gnss/GNSS.c
msgid "GNSS init"
msgstr ""
#: ports/espressif/bindings/espidf/__init__.c ports/espressif/esp_error.c
msgid "Generic Failure"
msgstr ""
@ -1182,12 +1160,7 @@ msgstr ""
msgid "Invalid %q"
msgstr ""
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c
#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c
#: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/busio/UART.c
#: ports/stm/common-hal/canio/CAN.c ports/stm/common-hal/sdioio/SDCard.c
#: shared-bindings/microcontroller/Pin.c
msgid "Invalid %q pin"
msgstr ""
@ -1208,8 +1181,7 @@ msgstr ""
msgid "Invalid MAC address"
msgstr ""
#: ports/espressif/bindings/espidf/__init__.c
#: ports/espressif/common-hal/busio/I2C.c ports/espressif/esp_error.c
#: ports/espressif/bindings/espidf/__init__.c ports/espressif/esp_error.c
#: py/moduerrno.c
msgid "Invalid argument"
msgstr ""
@ -1235,15 +1207,7 @@ msgstr ""
msgid "Invalid multicast MAC address"
msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "Invalid pin for left channel"
msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "Invalid pin for right channel"
msgstr ""
#: ports/espressif/common-hal/busio/UART.c shared-bindings/busio/UART.c
#: shared-bindings/busio/UART.c
msgid "Invalid pins"
msgstr ""
@ -1412,7 +1376,7 @@ msgstr ""
msgid "No MISO Pin"
msgstr ""
#: ports/stm/common-hal/busio/SPI.c
#: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c
msgid "No MISO pin"
msgstr ""
@ -1421,7 +1385,7 @@ msgstr ""
msgid "No MOSI Pin"
msgstr ""
#: ports/stm/common-hal/busio/SPI.c
#: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c
msgid "No MOSI pin"
msgstr ""
@ -1658,6 +1622,10 @@ msgid ""
"PWM frequency not writable when variable_frequency is False on construction."
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "PWM restart"
msgstr ""
#: ports/raspberrypi/common-hal/countio/Counter.c
msgid "PWM slice already in use"
msgstr ""
@ -1678,10 +1646,6 @@ msgstr ""
msgid "Pin cannot wake from Deep Sleep"
msgstr ""
#: ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c
msgid "Pin cannot wake from deep sleep"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Pin count too large"
msgstr ""
@ -1777,7 +1741,8 @@ msgstr ""
msgid "RNG Init Error"
msgstr ""
#: ports/nrf/common-hal/busio/UART.c
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
#: ports/nrf/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "RS485"
msgstr ""
@ -1790,11 +1755,6 @@ msgstr ""
msgid "RTC is not supported on this board"
msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
#: ports/stm/common-hal/busio/UART.c
msgid "RTS/CTS/RS485 Not yet supported on this device"
msgstr ""
#: ports/stm/common-hal/os/__init__.c
msgid "Random number generation error"
msgstr ""
@ -1844,6 +1804,10 @@ msgstr ""
msgid "SD card CSD format not supported"
msgstr ""
#: ports/cxd56/common-hal/sdioio/SDCard.c
msgid "SDCard init"
msgstr ""
#: ports/stm/common-hal/sdioio/SDCard.c
#, c-format
msgid "SDIO GetCardInfo Error %d"
@ -1867,7 +1831,7 @@ msgid "SPI peripheral in use"
msgstr ""
#: ports/stm/common-hal/busio/SPI.c
msgid "SPI re-initialization error"
msgid "SPI re-init"
msgstr ""
#: shared-bindings/is31fl3741/FrameBuffer.c
@ -2062,19 +2026,20 @@ msgid "Tuple or struct_time argument required"
msgstr ""
#: ports/stm/common-hal/busio/UART.c
msgid "UART de-init error"
msgid "UART de-init"
msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
#: ports/espressif/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "UART init"
msgstr ""
#: ports/stm/common-hal/busio/UART.c
msgid "UART init error"
msgid "UART re-init"
msgstr ""
#: ports/stm/common-hal/busio/UART.c
msgid "UART re-init error"
msgstr ""
#: ports/stm/common-hal/busio/UART.c
msgid "UART write error"
msgid "UART write"
msgstr ""
#: shared-module/usb_hid/Device.c
@ -2211,10 +2176,6 @@ msgid ""
"declined or ignored."
msgstr ""
#: ports/cxd56/common-hal/busio/I2C.c ports/espressif/common-hal/busio/UART.c
msgid "Unsupported baudrate"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c
msgid "Unsupported colorspace"
msgstr ""
@ -2227,10 +2188,6 @@ msgstr ""
msgid "Unsupported format"
msgstr ""
#: ports/atmel-samd/common-hal/busio/I2C.c ports/stm/common-hal/busio/I2C.c
msgid "Unsupported frequency"
msgstr ""
#: ports/espressif/common-hal/dualbank/__init__.c
msgid "Update Failed"
msgstr ""
@ -2671,6 +2628,10 @@ msgstr ""
msgid "casting"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "channel re-init"
msgstr ""
#: shared-bindings/_stage/Text.c
msgid "chars buffer too small"
msgstr ""
@ -3107,6 +3068,10 @@ msgstr ""
msgid "indices must be integers, slices, or Boolean lists"
msgstr ""
#: ports/espressif/common-hal/busio/I2C.c
msgid "init I2C"
msgstr ""
#: extmod/ulab/code/scipy/optimize/optimize.c
msgid "initial values must be iterable"
msgstr ""
@ -4025,6 +3990,10 @@ msgstr ""
msgid "timeout waiting for v2 card"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "timer re-init"
msgstr ""
#: shared-bindings/time/__init__.c
msgid "timestamp out of range for platform time_t"
msgstr ""

View File

@ -261,7 +261,7 @@ static void pinalarm_set_alarms_deep(size_t n_alarms, const mp_obj_t *alarms) {
}
}
if (t->n < 0) {
mp_raise_ValueError(translate("Pin cannot wake from deep sleep"));
raise_ValueError_invalid_pin();
}
// It is strange, but to my experiment, interrupt during sleep

View File

@ -151,16 +151,16 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
}
#endif
if (bc_clock_unit == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_bit_clock);
raise_ValueError_invalid_pin_name(MP_QSTR_clock);
}
if (ws_clock_unit == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_word_select);
raise_ValueError_invalid_pin_name(MP_QSTR_word_select);
}
if (bc_clock_unit != ws_clock_unit) {
mp_raise_ValueError(translate("Bit clock and word select must share a clock unit"));
}
if (serializer == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data);
raise_ValueError_invalid_pin_name(MP_QSTR_data);
}
self->clock_unit = ws_clock_unit;
self->serializer = serializer;

View File

@ -121,7 +121,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
self->clock_unit = 1;
#endif
} else {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_clock);
raise_ValueError_invalid_pin_name(MP_QSTR_clock);
}
self->data_pin = data_pin; // PA07, PA19 -> SD0, PA08, PB16 -> SD1
@ -152,7 +152,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
self->serializer = 1;
#endif
} else {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data);
raise_ValueError_invalid_pin_name(MP_QSTR_data);
}
if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != OVERSAMPLING) {

View File

@ -143,13 +143,14 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
#ifdef SAM_D5X_E5X
self->right_channel = NULL;
if (left_channel != &pin_PA02 && left_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for left channel"));
raise_ValueError_invalid_pin_name(MP_QSTR_left_channel);
}
if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for right channel"));
raise_ValueError_invalid_pin_name(MP_QSTR_right_channel);
}
if (right_channel == left_channel) {
mp_raise_ValueError(translate("Cannot output both channels on the same pin"));
mp_raise_ValueError_varg(translate("%q and %q must be different"),
MP_QSTR_left_channel, MP_QSTR_right_channel);
}
claim_pin(left_channel);
if (right_channel != NULL) {

View File

@ -128,7 +128,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
reset_pin_number(sda->number);
reset_pin_number(scl->number);
common_hal_busio_i2c_deinit(self);
mp_raise_ValueError(translate("Unsupported frequency"));
mp_arg_error_invalid(MP_QSTR_frequency);
}
self->sda_pin = sda->number;

View File

@ -77,7 +77,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->tx_pin = NO_PIN;
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
mp_raise_NotImplementedError(translate("RS485"));
}
mp_arg_validate_int_max(bits, 8, MP_QSTR_bits);
@ -183,7 +183,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
if (usart_async_init(usart_desc_p, sercom, self->buffer, self->buffer_length, NULL) != ERR_NONE) {
mp_raise_ValueError(translate("Could not initialize UART"));
mp_raise_RuntimeError(translate("UART init"));
}
// usart_async_init() sets a number of defaults based on a prototypical SERCOM

View File

@ -66,13 +66,13 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
mp_arg_error_invalid(MP_QSTR_datacount);
}
if (vertical_sync && vertical_sync->number != PIN_PCC_DEN1) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_vsync);
raise_ValueError_invalid_pin_name(MP_QSTR_vsync);
}
if (horizontal_reference && horizontal_reference->number != PIN_PCC_DEN2) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_href);
raise_ValueError_invalid_pin_name(MP_QSTR_href);
}
if (data_clock->number != PIN_PCC_CLK) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data_clock);
raise_ValueError_invalid_pin_name(MP_QSTR_data_clock);
}
// technically, 0 was validated as free already but check again
for (int i = 0; i < data_count; i++) {

View File

@ -352,6 +352,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_
}
if (index < 0 || index >= self->len) {
common_hal_mcu_enable_interrupts();
// Can't use mp_arg_validate_index_range() here due to the critical section.
mp_raise_IndexError_varg(translate("%q out of range"), MP_QSTR_index);
}
uint16_t value = self->buffer[(self->start + index) % self->maxlen];

View File

@ -37,7 +37,7 @@
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl,
const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) {
mp_raise_ValueError(translate("Unsupported baudrate"));
mp_arg_error_invalid(MP_QSTR_frequency);
}
if (scl->number != PIN_I2C0_BCK || sda->number != PIN_I2C0_BDT) {

View File

@ -66,7 +66,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
struct termios tio;
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
mp_raise_NotImplementedError(translate("RS485"));
}
mp_arg_validate_int(bits, 8, MP_QSTR_bits);
@ -90,7 +90,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (busio_uart_dev[self->number].fd < 0) {
busio_uart_dev[self->number].fd = open(busio_uart_dev[self->number].devpath, O_RDWR);
if (busio_uart_dev[self->number].fd < 0) {
mp_raise_ValueError(translate("Could not initialize UART"));
mp_raise_RuntimeError(translate("UART init"));
}
// Wait to make sure the UART is ready

View File

@ -121,11 +121,11 @@ static void camera_start_preview() {
void common_hal_camera_construct(camera_obj_t *self) {
if (camera_dev.fd < 0) {
if (video_initialize(camera_dev.devpath) < 0) {
mp_raise_ValueError_varg(translate("Could not initialize %q"), MP_QSTR_Camera);
mp_raise_RuntimeError(translate("Camera init"));
}
camera_dev.fd = open(camera_dev.devpath, 0);
if (camera_dev.fd < 0) {
mp_raise_ValueError_varg(translate("Could not initialize %q"), MP_QSTR_Camera);
mp_raise_RuntimeError(translate("Camera init"));
}
}

View File

@ -56,7 +56,7 @@ void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection) {
if (gnss_dev.fd < 0) {
gnss_dev.fd = open(gnss_dev.devpath, O_RDONLY);
if (gnss_dev.fd < 0) {
mp_raise_ValueError_varg(translate("Could not initialize %q"), MP_QSTR_GNSS);
mp_raise_RuntimeError(translate("GNSS init"));
}
}

View File

@ -59,7 +59,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
}
if (open_blockdriver("/dev/mmcsd0", 0, &self->inode) < 0) {
mp_raise_ValueError_varg(translate("Could not initialize %q"), MP_QSTR_SDCard);
mp_raise_RuntimeError(translate("SDCard init"));
}
self->inode->u.i_bops->geometry(self->inode, &geo);

View File

@ -113,7 +113,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (err == ESP_FAIL) {
mp_raise_OSError(MP_EIO);
} else {
mp_raise_ValueError(translate("Invalid argument"));
mp_raise_RuntimeError(translate("init I2C"));
}
}

View File

@ -25,6 +25,7 @@
*/
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/UART.h"
#include "components/driver/include/driver/uart.h"
@ -156,7 +157,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// Install the driver before we change the settings.
if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 20, &self->event_queue, 0) != ESP_OK ||
uart_set_mode(self->uart_num, mode) != ESP_OK) {
mp_raise_ValueError(translate("Could not initialize UART"));
mp_raise_RuntimeError(translate("UART init"));
}
// On the debug uart, enable pattern detection to look for CTRL+C
#ifdef CIRCUITPY_DEBUG_UART_RX
@ -263,7 +264,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
rts_num = rs485_dir->number;
}
if (uart_set_pin(self->uart_num, tx_num, rx_num, rts_num, cts_num) != ESP_OK) {
mp_raise_ValueError(translate("Invalid pins"));
raise_ValueError_invalid_pins();
}
}
@ -374,7 +375,7 @@ uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) {
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
if (baudrate > UART_BITRATE_MAX ||
uart_set_baudrate(self->uart_num, baudrate) != ESP_OK) {
mp_raise_ValueError(translate("Unsupported baudrate"));
mp_arg_error_invalid(MP_QSTR_baudrate);
}
}

View File

@ -183,10 +183,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
if (rx && !rx_config) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RX);
raise_ValueError_invalid_pin_name(MP_QSTR_rx);
}
if (tx && !tx_config) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_TX);
raise_ValueError_invalid_pin_name(MP_QSTR_tx);
}
if (uart_taken) {
@ -233,7 +233,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
}
if ((rts != NULL) && (rts_config == NULL)) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_RTS);
raise_ValueError_invalid_pin_name(MP_QSTR_rts);
}
}
@ -247,7 +247,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
}
if (cts_config == NULL) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_CTS);
raise_ValueError_invalid_pin_name(MP_QSTR_cts);
}
}

View File

@ -237,7 +237,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self,
index += self->len;
}
if (index < 0 || index >= self->len) {
mp_raise_IndexError_varg(translate("%q out of range"), MP_QSTR_index);
mp_arg_validate_index_range(index, 0, self->len, MP_QSTR_index);
}
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
return value;

View File

@ -65,7 +65,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC3);
#endif
} else {
mp_raise_ValueError(translate("Invalid ADC Unit value"));
mp_raise_RuntimeError(translate("Invalid ADC Unit value"));
}
common_hal_mcu_pin_claim(pin);
self->pin = pin;
@ -147,7 +147,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
ADCx = ADC3;
#endif
} else {
mp_raise_ValueError(translate("Invalid ADC Unit value"));
mp_raise_RuntimeError(translate("Invalid ADC Unit value"));
}
LL_GPIO_SetPinMode(pin_port(self->pin->port), (uint32_t)pin_mask(self->pin->number), LL_GPIO_MODE_ANALOG);

View File

@ -120,7 +120,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (i2c_taken) {
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
} else {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_I2C);
raise_ValueError_invalid_pins();
}
}
@ -155,7 +155,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
} else if (frequency == 100000) {
self->handle.Init.Timing = CPY_I2CSTANDARD_TIMINGR;
} else {
mp_raise_ValueError(translate("Unsupported frequency"));
mp_arg_error_invalid(MP_QSTR_frequency);
}
#else
self->handle.Init.ClockSpeed = frequency;

View File

@ -306,7 +306,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
get_busclock(self->handle.Instance));
if (HAL_SPI_Init(&self->handle) != HAL_OK) {
mp_raise_ValueError(translate("SPI re-initialization error"));
mp_raise_RuntimeError(translate("SPI re-init"));
}
self->baudrate = baudrate;

View File

@ -93,7 +93,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint8_t periph_index = 0; // origin 0 corrected
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
mp_raise_NotImplementedError(translate("RS485"));
}
// Can have both pins, or either
@ -168,7 +168,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
mp_arg_validate_int_range(bits, 8, 9, MP_QSTR_bits);
if (USARTx == NULL) { // this can only be hit if the periph file is wrong
mp_raise_ValueError(translate("Internal define error"));
mp_raise_RuntimeError(translate("Internal define error"));
}
// GPIO Init
@ -208,7 +208,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
self->handle.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&self->handle) != HAL_OK) {
mp_raise_ValueError(translate("UART init error"));
mp_raise_RuntimeError(translate("UART init"));
}
@ -232,7 +232,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// start the interrupt series
if ((HAL_UART_GetState(&self->handle) & HAL_UART_STATE_BUSY_RX) == HAL_UART_STATE_BUSY_RX) {
mp_raise_ValueError(translate("Could not start interrupt, RX busy"));
mp_raise_RuntimeError(translate("Could not start interrupt, RX busy"));
}
// start the receive interrupt chain
@ -335,7 +335,7 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
Status = HAL_UART_GetState(&self->handle);
}
} else {
mp_raise_ValueError(translate("UART write error"));
mp_raise_RuntimeError(translate("UART write"));
}
return len;
@ -405,11 +405,11 @@ void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrat
// Otherwise de-init and set new rate
if (HAL_UART_DeInit(&self->handle) != HAL_OK) {
mp_raise_ValueError(translate("UART de-init error"));
mp_raise_RuntimeError(translate("UART de-init"));
}
self->handle.Init.BaudRate = baudrate;
if (HAL_UART_Init(&self->handle) != HAL_OK) {
mp_raise_ValueError(translate("UART re-init error"));
mp_raise_RuntimeError(translate("UART re-init"));
}
self->baudrate = baudrate;

View File

@ -59,13 +59,13 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, const mcu_pin_obj_t *
const mcu_periph_obj_t *mcu_tx = find_pin_function(mcu_can_tx_list, can_tx_len, tx, -1);
if (!mcu_tx) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_tx);
raise_ValueError_invalid_pin_name(MP_QSTR_tx);
}
int periph_index = mcu_tx->periph_index;
const mcu_periph_obj_t *mcu_rx = find_pin_function(mcu_can_rx_list, can_rx_len, rx, periph_index);
if (!mcu_rx) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_rx);
raise_ValueError_invalid_pin_name(MP_QSTR_rx);
}
if (reserved_can[periph_index]) {

View File

@ -279,16 +279,16 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t fr
// restart everything, adjusting for new speed
if (HAL_TIM_PWM_Init(&self->handle) != HAL_OK) {
mp_raise_ValueError(translate("Could not re-init timer"));
mp_raise_RuntimeError(translate("timer re-init"));
}
self->chan_handle.Pulse = timer_get_internal_duty(self->duty_cycle, period);
if (HAL_TIM_PWM_ConfigChannel(&self->handle, &self->chan_handle, self->channel) != HAL_OK) {
mp_raise_ValueError(translate("Could not re-init channel"));
mp_raise_RuntimeError(translate("channel re-init"));
}
if (HAL_TIM_PWM_Start(&self->handle, self->channel) != HAL_OK) {
mp_raise_ValueError(translate("Could not restart PWM"));
mp_raise_RuntimeError(translate("PWM restart"));
}
tim_frequencies[self->tim->tim_index] = frequency;

View File

@ -222,6 +222,14 @@ mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qs
return length;
}
// int instead of uint because an index can be negative in some cases.
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name) {
if (index < min || index > max) {
mp_raise_IndexError_varg(translate("%q out of range"), arg_name, min, max);
}
return index;
}
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
if (!mp_obj_is_type(obj, type)) {
mp_raise_TypeError_varg(translate("%q must be of type %q"), arg_name, type->name);

View File

@ -104,6 +104,7 @@ mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_n
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name);
mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name);
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name);
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name);
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name);
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name);

View File

@ -202,3 +202,7 @@ NORETURN void raise_ValueError_invalid_pin(void) {
NORETURN void raise_ValueError_invalid_pins(void) {
mp_arg_error_invalid(MP_QSTR_pins);
}
NORETURN void raise_ValueError_invalid_pin_name(qstr pin_name) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), pin_name);
}

View File

@ -43,6 +43,7 @@ void validate_list_is_free_pins(qstr what, const mcu_pin_obj_t **pins_out, mp_in
void validate_pins(qstr what, uint8_t *pin_nos, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out);
NORETURN void raise_ValueError_invalid_pin(void);
NORETURN void raise_ValueError_invalid_pins(void);
NORETURN void raise_ValueError_invalid_pin_name(qstr pin_name);
void assert_pin_free(const mcu_pin_obj_t *pin);

View File

@ -129,7 +129,7 @@ STATIC mp_obj_t sdioio_sdcard_configure(size_t n_args, const mp_obj_t *pos_args,
MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS);
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_int_t frequency = mp_arg_validate_int_min(args[ARG_frequency].u_int, 0, MP_QSTR_frequency);
mp_int_t frequency = mp_arg_validate_int_min(args[ARG_frequency].u_int, 1, MP_QSTR_frequency);
uint8_t width = args[ARG_width].u_int;
if (width != 0 && width != 1 && width != 4) {
mp_arg_error_invalid(MP_QSTR_width);

View File

@ -123,7 +123,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) {
mp_raise_ValueError(translate("Cannot write without MOSI pin"));
mp_raise_ValueError(translate("No MOSI pin"));
}
uint32_t delay_half = self->delay_half;
@ -178,7 +178,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, uint8_t write_data) {
if (len > 0 && !self->has_miso) {
mp_raise_ValueError(translate("Cannot read without MISO pin"));
mp_raise_ValueError(translate("No MISO pin"));
}
uint32_t delay_half = self->delay_half;