Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
146a223311
@ -57,9 +57,9 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
||||
self->value = mp_obj_new_bytes(initial_value_bufinfo->buf, initial_value_bufinfo->len);
|
||||
|
||||
const mp_int_t max_length_max = 512;
|
||||
if (max_length < 0 || max_length > max_length_max) {
|
||||
mp_raise_ValueError(translate("max_length must be <= 512"));
|
||||
}
|
||||
|
||||
mp_arg_validate_int_range(max_length, 0, max_length_max, MP_QSTR_max_length);
|
||||
|
||||
self->max_length = max_length;
|
||||
self->fixed_length = fixed_length;
|
||||
|
||||
|
@ -30,6 +30,11 @@
|
||||
|
||||
#define mp_obj_fat_vfs_t fs_user_mount_t
|
||||
|
||||
// Factoring this common call saves about 90 bytes.
|
||||
STATIC NORETURN void mp_raise_OSError_fresult(FRESULT res) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
|
||||
STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) {
|
||||
fs_user_mount_t *vfs = vfs_in;
|
||||
FILINFO fno;
|
||||
@ -64,7 +69,7 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
// don't error out if no filesystem, to let mkfs()/mount() create one if wanted
|
||||
vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NO_FILESYSTEM;
|
||||
} else if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(vfs);
|
||||
@ -97,7 +102,7 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) {
|
||||
res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
|
||||
}
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
@ -172,7 +177,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
|
||||
iter->is_str = is_str_type;
|
||||
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(iter);
|
||||
@ -188,7 +193,7 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in
|
||||
FRESULT res = f_stat(&self->fatfs, path, &fno);
|
||||
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
// check if path is a file or directory
|
||||
@ -196,7 +201,7 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in
|
||||
res = f_unlink(&self->fatfs, path);
|
||||
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
return mp_const_none;
|
||||
} else {
|
||||
@ -226,7 +231,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
|
||||
FILINFO fno;
|
||||
FRESULT res = f_stat(&self->fatfs, old_path, &fno);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
if ((fno.fattrib & AM_DIR) != 0 &&
|
||||
strlen(new_path) > strlen(old_path) &&
|
||||
@ -245,7 +250,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
|
||||
if (res == FR_OK) {
|
||||
return mp_const_none;
|
||||
} else {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
}
|
||||
@ -259,7 +264,7 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
|
||||
if (res == FR_OK) {
|
||||
return mp_const_none;
|
||||
} else {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir);
|
||||
@ -273,7 +278,7 @@ STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) {
|
||||
FRESULT res = f_chdir(&self->fatfs, path);
|
||||
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
@ -286,7 +291,7 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
|
||||
char buf[MICROPY_ALLOC_PATH_MAX + 1];
|
||||
FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf));
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
return mp_obj_new_str(buf, strlen(buf));
|
||||
}
|
||||
@ -307,7 +312,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
|
||||
} else {
|
||||
FRESULT res = f_stat(&self->fatfs, path, &fno);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,7 +362,7 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) {
|
||||
FATFS *fatfs = &self->fatfs;
|
||||
FRESULT res = f_getfree(fatfs, &nclst);
|
||||
if (FR_OK != res) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
|
||||
@ -395,7 +400,7 @@ STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs
|
||||
res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
|
||||
}
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
self->blockdev.flags &= ~MP_BLOCKDEV_FLAG_NO_FILESYSTEM;
|
||||
|
||||
@ -416,7 +421,7 @@ STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) {
|
||||
char working_buf[12];
|
||||
FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL);
|
||||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
return mp_obj_new_str(working_buf, strlen(working_buf));
|
||||
}
|
||||
@ -431,7 +436,7 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
|
||||
if (res == FR_WRITE_PROTECTED) {
|
||||
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem"));
|
||||
}
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
mp_raise_OSError_fresult(res);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
||||
}
|
||||
|
||||
if (rwxa_count != 1 || plus_count > 1 || bt_count > 1 || bad_mode) {
|
||||
mp_raise_ValueError(translate("Invalid mode"));
|
||||
mp_arg_error_invalid(MP_QSTR_mode);
|
||||
}
|
||||
|
||||
assert(vfs != NULL);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -234,7 +234,7 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
|
||||
// raise ValueError here
|
||||
MP_FALLTHROUGH
|
||||
case PINALARM_ERR_NOEXTINT:
|
||||
mp_raise_RuntimeError(translate("No hardware support on pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
case PINALARM_ERR_NOCHANNEL:
|
||||
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
|
||||
default:
|
||||
@ -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
|
||||
|
@ -100,7 +100,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_
|
||||
continue;
|
||||
}
|
||||
if (timealarm_set) {
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set."));
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set"));
|
||||
}
|
||||
timealarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
timealarm_set = true;
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "samd/adc.h"
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
@ -60,7 +61,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
|
||||
}
|
||||
if (adc_channel == 0xff) {
|
||||
// No ADC function on that pin
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
claim_pin(pin);
|
||||
|
||||
|
@ -70,7 +70,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
|
||||
#endif
|
||||
|
||||
default:
|
||||
mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -255,7 +255,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
|
||||
}
|
||||
uint8_t channel_count = audiosample_channel_count(sample);
|
||||
if (channel_count > 2) {
|
||||
mp_raise_ValueError(translate("Too many channels in sample."));
|
||||
mp_raise_ValueError(translate("Too many channels in sample"));
|
||||
}
|
||||
#ifdef SAMD21
|
||||
uint32_t serctrl = (self->clock_unit << I2S_SERCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_TX) | I2S_SERCTRL_TXSAME_SAME | I2S_SERCTRL_EXTEND_MSBIT | I2S_SERCTRL_TXDEFAULT_ONE | I2S_SERCTRL_SLOTADJ_LEFT;
|
||||
|
@ -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) {
|
||||
|
@ -136,20 +136,21 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
|
||||
mp_raise_ValueError(translate("Right channel unsupported"));
|
||||
}
|
||||
if (left_channel != &pin_PA02) {
|
||||
mp_raise_ValueError(translate("Invalid pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
claim_pin(left_channel);
|
||||
#endif
|
||||
#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) {
|
||||
@ -376,14 +377,13 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
|
||||
audio_dma_result result = AUDIO_DMA_OK;
|
||||
uint32_t sample_rate = audiosample_sample_rate(sample);
|
||||
#ifdef SAMD21
|
||||
uint32_t max_sample_rate = 350000;
|
||||
const uint32_t max_sample_rate = 350000;
|
||||
#endif
|
||||
#ifdef SAM_D5X_E5X
|
||||
uint32_t max_sample_rate = 1000000;
|
||||
const uint32_t max_sample_rate = 1000000;
|
||||
#endif
|
||||
if (sample_rate > max_sample_rate) {
|
||||
mp_raise_ValueError_varg(translate("Sample rate too high. It must be less than %d"), max_sample_rate);
|
||||
}
|
||||
mp_arg_validate_int_max(sample_rate, max_sample_rate, MP_QSTR_sample_rate);
|
||||
|
||||
#ifdef SAMD21
|
||||
result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0,
|
||||
false /* output unsigned */,
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include "samd/sercom.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
#include "common-hal/busio/__init__.h"
|
||||
@ -76,7 +77,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
self->sda_pin = NO_PIN;
|
||||
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
|
||||
if (sercom == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||
@ -122,15 +123,12 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
// The maximum frequency divisor gives a clock rate of around 48MHz/2/255
|
||||
// but set_baudrate does not diagnose this problem. (This is not the
|
||||
// exact cutoff, but no frequency well under 100kHz is available)
|
||||
if (frequency < 95000) {
|
||||
mp_raise_ValueError(translate("Unsupported baudrate"));
|
||||
}
|
||||
|
||||
if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
|
||||
if (frequency < 95000 &&
|
||||
i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
|
||||
reset_pin_number(sda->number);
|
||||
reset_pin_number(scl->number);
|
||||
common_hal_busio_i2c_deinit(self);
|
||||
mp_raise_ValueError(translate("Unsupported baudrate"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
|
||||
self->sda_pin = sda->number;
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
@ -33,7 +34,6 @@
|
||||
|
||||
#include "supervisor/board.h"
|
||||
#include "common-hal/busio/__init__.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "hal/include/hal_spi_m_sync.h"
|
||||
@ -133,7 +133,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
}
|
||||
}
|
||||
if (sercom == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
// Set up SPI clocks on SERCOM.
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/busio/UART.h"
|
||||
|
||||
#include "mpconfigport.h"
|
||||
@ -76,12 +77,10 @@ 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"));
|
||||
}
|
||||
|
||||
if (bits > 8) {
|
||||
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
|
||||
}
|
||||
mp_arg_validate_int_max(bits, 8, MP_QSTR_bits);
|
||||
|
||||
bool have_tx = tx != NULL;
|
||||
bool have_rx = rx != NULL;
|
||||
@ -145,7 +144,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
}
|
||||
}
|
||||
if (sercom == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
if (!have_tx) {
|
||||
tx_pad = 0;
|
||||
@ -175,7 +174,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
|
||||
if (self->buffer == NULL) {
|
||||
common_hal_busio_uart_deinit(self);
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), self->buffer_length * sizeof(uint8_t));
|
||||
m_malloc_fail(self->buffer_length * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -184,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
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "peripheral_clk_config.h"
|
||||
#include "hpl_gclk_config.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
@ -282,11 +283,11 @@ static void frequencyin_samd51_stop_dpll(void) {
|
||||
void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* self, const mcu_pin_obj_t* pin, const uint16_t capture_period) {
|
||||
|
||||
if (!pin->has_extint) {
|
||||
mp_raise_RuntimeError(translate("No hardware support on pin"));
|
||||
}
|
||||
if ((capture_period == 0) || (capture_period > 500)) {
|
||||
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
mp_arg_validate_int_range(capture_period, 0, 500, MP_QSTR_capture_period);
|
||||
|
||||
uint32_t mask = 1 << pin->extint_channel;
|
||||
if (eic_get_enable() == 1 &&
|
||||
#ifdef SAMD21
|
||||
@ -569,9 +570,7 @@ uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequ
|
||||
}
|
||||
|
||||
void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) {
|
||||
if ((capture_period == 0) || (capture_period > 500)) {
|
||||
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
|
||||
}
|
||||
mp_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
|
||||
|
||||
self->capture_period = capture_period;
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "shared-bindings/i2cperipheral/I2CPeripheral.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "common-hal/busio/I2C.h"
|
||||
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
@ -42,7 +43,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
|
||||
uint32_t sda_pinmux, scl_pinmux;
|
||||
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
|
||||
if (sercom == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
self->sercom = sercom;
|
||||
|
||||
|
@ -63,16 +63,16 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
|
||||
}
|
||||
// The peripheral supports 8, 10, 12, or 14 data bits, but the code only supports 8 at present
|
||||
if (data_count != 8) {
|
||||
mp_raise_ValueError_varg(translate("Invalid data_count %d"), data_count);
|
||||
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++) {
|
||||
|
@ -66,7 +66,7 @@ void common_hal_mcu_enable_interrupts(void) {
|
||||
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
|
||||
if (runmode == RUNMODE_BOOTLOADER) {
|
||||
if (!bootloader_available()) {
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present."));
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present"));
|
||||
}
|
||||
// Pretend to be the first of the two reset presses needed to enter the
|
||||
// bootloader. That way one reset will end in the bootloader.
|
||||
|
@ -79,7 +79,7 @@ static void resume_interrupt(ps2io_ps2_obj_t *self) {
|
||||
disable_interrupt(self);
|
||||
|
||||
self->state = STATE_IDLE;
|
||||
gpio_set_pin_function(self->clk_pin, GPIO_PIN_FUNCTION_A);
|
||||
gpio_set_pin_function(self->clock_pin, GPIO_PIN_FUNCTION_A);
|
||||
uint32_t mask = 1 << self->channel;
|
||||
EIC->INTFLAG.reg = mask << EIC_INTFLAG_EXTINT_Pos;
|
||||
EIC->INTENSET.reg = mask << EIC_INTENSET_EXTINT_Pos;
|
||||
@ -90,14 +90,14 @@ static void resume_interrupt(ps2io_ps2_obj_t *self) {
|
||||
static void clk_hi(ps2io_ps2_obj_t *self) {
|
||||
// External pull-up
|
||||
// Must set pull after setting direction.
|
||||
gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_IN);
|
||||
gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(self->clock_pin, GPIO_DIRECTION_IN);
|
||||
gpio_set_pin_pull_mode(self->clock_pin, GPIO_PULL_OFF);
|
||||
}
|
||||
|
||||
static bool wait_clk_lo(ps2io_ps2_obj_t *self, uint32_t us) {
|
||||
clk_hi(self);
|
||||
common_hal_mcu_delay_us(1);
|
||||
while (gpio_get_pin_level(self->clk_pin) && us) {
|
||||
while (gpio_get_pin_level(self->clock_pin) && us) {
|
||||
--us;
|
||||
common_hal_mcu_delay_us(1);
|
||||
}
|
||||
@ -107,7 +107,7 @@ static bool wait_clk_lo(ps2io_ps2_obj_t *self, uint32_t us) {
|
||||
static bool wait_clk_hi(ps2io_ps2_obj_t *self, uint32_t us) {
|
||||
clk_hi(self);
|
||||
common_hal_mcu_delay_us(1);
|
||||
while (!gpio_get_pin_level(self->clk_pin) && us) {
|
||||
while (!gpio_get_pin_level(self->clock_pin) && us) {
|
||||
--us;
|
||||
common_hal_mcu_delay_us(1);
|
||||
}
|
||||
@ -115,9 +115,9 @@ static bool wait_clk_hi(ps2io_ps2_obj_t *self, uint32_t us) {
|
||||
}
|
||||
|
||||
static void clk_lo(ps2io_ps2_obj_t *self) {
|
||||
gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(self->clk_pin, 0);
|
||||
gpio_set_pin_pull_mode(self->clock_pin, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(self->clock_pin, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(self->clock_pin, 0);
|
||||
}
|
||||
|
||||
static void data_hi(ps2io_ps2_obj_t *self) {
|
||||
@ -244,19 +244,19 @@ void ps2_interrupt_handler(uint8_t channel) {
|
||||
}
|
||||
|
||||
void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t *self,
|
||||
const mcu_pin_obj_t *data_pin, const mcu_pin_obj_t *clk_pin) {
|
||||
if (!clk_pin->has_extint) {
|
||||
mp_raise_RuntimeError(translate("No hardware support on clk pin"));
|
||||
const mcu_pin_obj_t *data_pin, const mcu_pin_obj_t *clock_pin) {
|
||||
if (!clock_pin->has_extint) {
|
||||
mp_arg_error_invalid(MP_QSTR_clock_pin);
|
||||
}
|
||||
if (eic_get_enable() && !eic_channel_free(clk_pin->extint_channel)) {
|
||||
if (eic_get_enable() && !eic_channel_free(clock_pin->extint_channel)) {
|
||||
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
|
||||
}
|
||||
|
||||
clk_hi(self);
|
||||
data_hi(self);
|
||||
|
||||
self->channel = clk_pin->extint_channel;
|
||||
self->clk_pin = clk_pin->number;
|
||||
self->channel = clock_pin->extint_channel;
|
||||
self->clock_pin = clock_pin->number;
|
||||
self->data_pin = data_pin->number;
|
||||
self->state = STATE_IDLE;
|
||||
self->bufcount = 0;
|
||||
@ -264,19 +264,19 @@ void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t *self,
|
||||
self->bufposw = 0;
|
||||
self->waiting_cmd_response = false;
|
||||
|
||||
set_eic_channel_data(clk_pin->extint_channel, (void *)self);
|
||||
set_eic_channel_data(clock_pin->extint_channel, (void *)self);
|
||||
|
||||
// Check to see if the EIC is enabled and start it up if its not.'
|
||||
if (eic_get_enable() == 0) {
|
||||
turn_on_external_interrupt_controller();
|
||||
}
|
||||
|
||||
gpio_set_pin_function(clk_pin->number, GPIO_PIN_FUNCTION_A);
|
||||
gpio_set_pin_function(clock_pin->number, GPIO_PIN_FUNCTION_A);
|
||||
gpio_set_pin_function(data_pin->number, GPIO_PIN_FUNCTION_A);
|
||||
|
||||
turn_on_cpu_interrupt(self->channel);
|
||||
|
||||
claim_pin(clk_pin);
|
||||
claim_pin(clock_pin);
|
||||
claim_pin(data_pin);
|
||||
|
||||
// Set config will enable the EIC.
|
||||
@ -284,7 +284,7 @@ void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t *self,
|
||||
}
|
||||
|
||||
bool common_hal_ps2io_ps2_deinited(ps2io_ps2_obj_t *self) {
|
||||
return self->clk_pin == NO_PIN;
|
||||
return self->clock_pin == NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t *self) {
|
||||
@ -293,9 +293,9 @@ void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t *self) {
|
||||
}
|
||||
set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
|
||||
turn_off_eic_channel(self->channel);
|
||||
reset_pin_number(self->clk_pin);
|
||||
reset_pin_number(self->clock_pin);
|
||||
reset_pin_number(self->data_pin);
|
||||
self->clk_pin = NO_PIN;
|
||||
self->clock_pin = NO_PIN;
|
||||
self->data_pin = NO_PIN;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint8_t channel;
|
||||
uint8_t clk_pin;
|
||||
uint8_t clock_pin;
|
||||
uint8_t data_pin;
|
||||
|
||||
uint8_t state;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "samd/pins.h"
|
||||
#include "samd/timers.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/pulseio/PulseIn.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
@ -152,7 +153,7 @@ void pulsein_reset() {
|
||||
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
||||
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
|
||||
if (!pin->has_extint) {
|
||||
mp_raise_RuntimeError(translate("No hardware support on pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
if (eic_get_enable() && !eic_channel_free(pin->extint_channel)) {
|
||||
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
|
||||
@ -160,7 +161,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
||||
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
self->channel = pin->extint_channel;
|
||||
self->pin = pin->number;
|
||||
@ -344,15 +345,15 @@ bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) {
|
||||
return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self,
|
||||
int16_t index) {
|
||||
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) {
|
||||
common_hal_mcu_disable_interrupts();
|
||||
if (index < 0) {
|
||||
index += self->len;
|
||||
}
|
||||
if (index < 0 || index >= self->len) {
|
||||
common_hal_mcu_enable_interrupts();
|
||||
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_PulseIn);
|
||||
// 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];
|
||||
common_hal_mcu_enable_interrupts();
|
||||
|
@ -377,7 +377,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self,
|
||||
uint32_t frequency) {
|
||||
uint32_t system_clock = common_hal_mcu_processor_get_frequency();
|
||||
if (frequency == 0 || frequency > system_clock / 2) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
const pin_timer_t *t = self->timer;
|
||||
uint8_t resolution;
|
||||
|
@ -68,13 +68,7 @@ int common_hal_rtc_get_calibration(void) {
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
if (calibration > 127 || calibration < -127) {
|
||||
#if CIRCUITPY_FULL_BUILD
|
||||
mp_raise_ValueError(translate("calibration value out of range +/-127"));
|
||||
#else
|
||||
mp_raise_ValueError(translate("calibration is out of range"));
|
||||
#endif
|
||||
}
|
||||
mp_arg_validate_int_range(calibration, -127, 127, MP_QSTR_calibration);
|
||||
|
||||
hri_rtcmode0_write_FREQCORR_SIGN_bit(RTC, calibration < 0 ? 0 : 1);
|
||||
hri_rtcmode0_write_FREQCORR_VALUE_bf(RTC, abs(calibration));
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "py/runtime.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/mphal.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/touchio/TouchIn.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
@ -60,7 +61,7 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
|
||||
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
|
||||
const mcu_pin_obj_t *pin) {
|
||||
if (!pin->has_touch) {
|
||||
mp_raise_ValueError(translate("Invalid pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
claim_pin(pin);
|
||||
|
||||
|
@ -90,7 +90,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
}
|
||||
}
|
||||
if (instance_index == NUM_I2C) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
i2c_in_use[instance_index] = true;
|
||||
self->index = instance_index;
|
||||
|
@ -104,7 +104,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
break;
|
||||
}
|
||||
if (instance_index == NUM_SPI) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
self->clock = clock;
|
||||
|
@ -162,13 +162,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
|
||||
bool sigint_enabled) {
|
||||
|
||||
if (bits > 8) {
|
||||
mp_raise_ValueError(translate("Invalid word/bit length"));
|
||||
}
|
||||
|
||||
if (receiver_buffer_size == 0) {
|
||||
mp_raise_ValueError(translate("Invalid buffer size"));
|
||||
}
|
||||
mp_arg_validate_int_max(bits, 8, MP_QSTR_bits);
|
||||
mp_arg_validate_int_min(receiver_buffer_size, 1, MP_QSTR_receiver_buffer_size);
|
||||
|
||||
if ((rs485_dir != NULL) || (rs485_invert)) {
|
||||
mp_raise_NotImplementedError(translate("RS485 Not yet supported on this device"));
|
||||
@ -203,7 +198,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
break;
|
||||
}
|
||||
if (instance_index == NUM_UART) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
self->rx_pin = rx;
|
||||
@ -224,7 +219,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
// in the long-lived pool is not strictly necessary)
|
||||
// (This is a macro.)
|
||||
if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) {
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer"));
|
||||
m_malloc_fail(receiver_buffer_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
const char *devpath;
|
||||
@ -52,7 +53,7 @@ STATIC analogin_dev_t analogin_dev[] = {
|
||||
|
||||
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
if (!pin->analog) {
|
||||
mp_raise_ValueError(translate("AnalogIn not supported on given pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
self->number = -1;
|
||||
@ -65,13 +66,13 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
|
||||
}
|
||||
|
||||
if (self->number < 0) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
if (analogin_dev[self->number].fd < 0) {
|
||||
analogin_dev[self->number].fd = open(analogin_dev[self->number].devpath, O_RDONLY);
|
||||
if (analogin_dev[self->number].fd < 0) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "shared-bindings/analogio/AnalogOut.h"
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
mp_raise_RuntimeError(translate("AnalogOut functionality not supported"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut);
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
|
@ -32,15 +32,16 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
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) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
claim_pin(scl);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock,
|
||||
const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) {
|
||||
@ -55,7 +56,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
|
||||
}
|
||||
|
||||
if (port < 0) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
claim_pin(clock);
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/busio/UART.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
const char *devpath;
|
||||
@ -65,20 +66,12 @@ 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"));
|
||||
}
|
||||
|
||||
if (bits != 8) {
|
||||
mp_raise_ValueError(translate("Could not initialize UART"));
|
||||
}
|
||||
|
||||
if (parity != BUSIO_UART_PARITY_NONE) {
|
||||
mp_raise_ValueError(translate("Could not initialize UART"));
|
||||
}
|
||||
|
||||
if (stop != 1) {
|
||||
mp_raise_ValueError(translate("Could not initialize UART"));
|
||||
}
|
||||
mp_arg_validate_int(bits, 8, MP_QSTR_bits);
|
||||
mp_arg_validate_int(parity, BUSIO_UART_PARITY_NONE, MP_QSTR_parity);
|
||||
mp_arg_validate_int(stop, 1, MP_QSTR_stop);
|
||||
|
||||
self->number = -1;
|
||||
|
||||
@ -91,13 +84,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
}
|
||||
|
||||
if (self->number < 0) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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(translate("Could not initialize Camera"));
|
||||
mp_raise_RuntimeError(translate("Camera init"));
|
||||
}
|
||||
camera_dev.fd = open(camera_dev.devpath, 0);
|
||||
if (camera_dev.fd < 0) {
|
||||
mp_raise_ValueError(translate("Could not initialize Camera"));
|
||||
mp_raise_RuntimeError(translate("Camera init"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,11 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
if (pin->analog) {
|
||||
mp_raise_ValueError(translate("DigitalInOut not supported on given pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
claim_pin(pin);
|
||||
|
@ -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(translate("Could not initialize GNSS"));
|
||||
mp_raise_RuntimeError(translate("GNSS init"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ void common_hal_mcu_enable_interrupts(void) {
|
||||
|
||||
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
|
||||
if (runmode == RUNMODE_BOOTLOADER) {
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present."));
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present"));
|
||||
} else if (runmode == RUNMODE_SAFE_MODE) {
|
||||
safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
||||
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
self->pin = pin;
|
||||
@ -190,7 +190,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();
|
||||
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_PulseIn);
|
||||
mp_raise_IndexError_varg(translate("%q out of range"), MP_QSTR_index);
|
||||
}
|
||||
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
|
||||
common_hal_mcu_enable_interrupts();
|
||||
|
@ -74,7 +74,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
|
||||
self->variable_frequency = variable_frequency;
|
||||
|
||||
if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
ioctl(pwmout_dev[self->number].fd, PWMIOC_START, 0);
|
||||
|
||||
@ -116,7 +116,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t fr
|
||||
self->info.frequency = frequency;
|
||||
|
||||
if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,5 +50,5 @@ int common_hal_rtc_get_calibration(void) {
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/sdioio/SDCard.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
@ -42,7 +43,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
|
||||
struct geometry geo;
|
||||
|
||||
if (clock->number != PIN_SDIO_CLK || command->number != PIN_SDIO_CMD) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
uint8_t data_pins_num = 0;
|
||||
@ -54,11 +55,11 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
|
||||
}
|
||||
|
||||
if (data_pins_num != DATA_PINS_NUM) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
if (open_blockdriver("/dev/mmcsd0", 0, &self->inode) < 0) {
|
||||
mp_raise_ValueError(translate("Could not initialize SDCard"));
|
||||
mp_raise_RuntimeError(translate("SDCard init"));
|
||||
}
|
||||
|
||||
self->inode->u.i_bops->geometry(self->inode, &geo);
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "shared-bindings/alarm/touch/TouchAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
#include "esp_sleep.h"
|
||||
#include "peripherals/touch.h"
|
||||
@ -36,7 +37,7 @@ static volatile bool woke_up = false;
|
||||
|
||||
void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
if (pin->touch_channel == TOUCH_PAD_MAX) {
|
||||
mp_raise_ValueError(translate("Invalid pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
claim_pin(pin);
|
||||
self->pin = pin;
|
||||
|
@ -51,7 +51,7 @@
|
||||
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
|
||||
const mcu_pin_obj_t *pin) {
|
||||
if (pin->adc_index == 0 || pin->adc_channel == ADC_CHANNEL_MAX) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
common_hal_mcu_pin_claim(pin);
|
||||
self->pin = pin;
|
||||
@ -80,7 +80,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||
} else if (self->pin->adc_index == ADC_UNIT_2) {
|
||||
adc2_config_channel_atten((adc2_channel_t)self->pin->adc_channel, ATTENUATION);
|
||||
} else {
|
||||
mp_raise_ValueError(translate("Invalid Pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
// Automatically select calibration process depending on status of efuse
|
||||
|
@ -49,7 +49,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
|
||||
} else if (pin == &pin_GPIO18) {
|
||||
self->channel = DAC_CHANNEL_2;
|
||||
} else {
|
||||
mp_raise_ValueError(translate("Invalid DAC pin supplied"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
dac_output_enable(self->channel);
|
||||
#else
|
||||
|
@ -42,7 +42,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
//
|
||||
// 46 is also input-only so it'll never work.
|
||||
if (scl->number == 45 || scl->number == 46 || sda->number == 45 || sda->number == 46) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
#include "driver/spi_common_internal.h"
|
||||
|
||||
@ -101,7 +102,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
if (result == ESP_ERR_NO_MEM) {
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed"));
|
||||
} else if (result == ESP_ERR_INVALID_ARG) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
set_spi_config(self, 250000, 0, 0, 8);
|
||||
|
@ -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"
|
||||
@ -101,9 +102,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
|
||||
bool sigint_enabled) {
|
||||
|
||||
if (bits > 8) {
|
||||
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
|
||||
}
|
||||
mp_arg_validate_int_max(bits, 8, MP_QSTR_bytes);
|
||||
|
||||
bool have_tx = tx != NULL;
|
||||
bool have_rx = rx != NULL;
|
||||
@ -158,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
|
||||
@ -265,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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, const mcu_pin_obj_t *
|
||||
if (result == ESP_ERR_NO_MEM) {
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed"));
|
||||
} else if (result == ESP_ERR_INVALID_ARG) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
} else if (result != ESP_OK) {
|
||||
mp_raise_OSError_msg_varg(translate("twai_driver_install returned esp-idf error #%d"), (int)result);
|
||||
}
|
||||
|
@ -130,9 +130,7 @@ static void init_timer(frequencyio_frequencyin_obj_t *self) {
|
||||
|
||||
void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t *self,
|
||||
const mcu_pin_obj_t *pin, const uint16_t capture_period) {
|
||||
if ((capture_period == 0) || (capture_period > 500)) {
|
||||
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
|
||||
}
|
||||
mp_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
|
||||
|
||||
self->pin = pin->number;
|
||||
self->handle = NULL;
|
||||
@ -188,9 +186,8 @@ uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequ
|
||||
}
|
||||
|
||||
void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) {
|
||||
if ((capture_period == 0) || (capture_period > 500)) {
|
||||
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
|
||||
}
|
||||
mp_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
|
||||
|
||||
self->capture_period = capture_period;
|
||||
common_hal_frequencyio_frequencyin_clear(self);
|
||||
timer_set_alarm_value(self->timer.group, self->timer.idx, capture_period * 1000000);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "common-hal/i2cperipheral/I2CPeripheral.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self,
|
||||
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
|
||||
@ -39,7 +40,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
|
||||
// support I2C on these pins.
|
||||
// Also 46 is input-only so it'll never work.
|
||||
if (scl->number == 45 || scl->number == 46 || sda->number == 45 || sda->number == 46) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
if (num_addresses > 1) {
|
||||
@ -72,7 +73,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
|
||||
if (err == ESP_FAIL) {
|
||||
mp_raise_OSError(MP_EIO);
|
||||
} else {
|
||||
mp_raise_ValueError(translate("Invalid argument"));
|
||||
mp_arg_error_invalid(MP_QSTR_I2CPeripheral);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
|
||||
const mcu_pin_obj_t *horizontal_reference) {
|
||||
|
||||
// only 8 bits is supported at present
|
||||
if (data_count < 8 || data_count > 16) {
|
||||
mp_raise_ValueError_varg(translate("%q must be between %d and %d"), MP_QSTR_data_count, 8, 16);
|
||||
}
|
||||
mp_arg_validate_int_range(data_count, 8, 16, MP_QSTR_data_count);
|
||||
|
||||
// This will throw if unsuccessful. Everything following is guaranteed to succeed.
|
||||
port_i2s_allocate_i2s0();
|
||||
|
@ -88,7 +88,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
|
||||
uint16_t maxlen, bool idle_state) {
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
self->pin = pin;
|
||||
self->maxlen = maxlen;
|
||||
|
@ -217,7 +217,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t fr
|
||||
// Calculate duty cycle
|
||||
uint32_t duty_bits = calculate_duty_cycle(frequency);
|
||||
if (duty_bits == 0) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
self->duty_resolution = duty_bits;
|
||||
ledc_set_freq(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num, frequency);
|
||||
|
@ -48,5 +48,5 @@ int common_hal_rtc_get_calibration(void) {
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "peripherals/touch.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
|
||||
uint32_t touch_value;
|
||||
@ -41,7 +42,7 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
|
||||
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
|
||||
const mcu_pin_obj_t *pin) {
|
||||
if (pin->touch_channel == TOUCH_PAD_MAX) {
|
||||
mp_raise_ValueError(translate("Invalid pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
claim_pin(pin);
|
||||
|
||||
|
@ -209,7 +209,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
|
||||
authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
||||
break;
|
||||
default:
|
||||
mp_raise_ValueError(translate("Invalid AuthMode"));
|
||||
mp_arg_error_invalid(MP_QSTR_authmode);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -221,9 +221,8 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
|
||||
config->ap.channel = channel;
|
||||
config->ap.authmode = authmode;
|
||||
|
||||
if (max_connections < 0 || max_connections > 10) {
|
||||
mp_raise_ValueError(translate("max_connections must be between 0 and 10"));
|
||||
}
|
||||
mp_arg_validate_int_range(max_connections, 0, 10, MP_QSTR_max_connections);
|
||||
|
||||
config->ap.max_connection = max_connections;
|
||||
|
||||
esp_wifi_set_config(WIFI_IF_AP, config);
|
||||
|
@ -42,7 +42,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
|
||||
adc_config_t config = {0};
|
||||
|
||||
if (pin->adc == NULL) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
ADC_GetDefaultConfig(&config);
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
mp_raise_NotImplementedError(translate("AnalogOut functionality not supported"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut);
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
|
@ -138,7 +138,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
}
|
||||
|
||||
if (self->sda == NULL || self->scl == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
} else {
|
||||
self->i2c = mcu_i2c_banks[self->sda->bank_idx - 1];
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
if (spi_taken) {
|
||||
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
|
||||
} else {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,12 +113,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
bool sigint_enabled) {
|
||||
|
||||
self->baudrate = baudrate;
|
||||
self->character_bits = bits;
|
||||
self->character_bits = (uint8_t)mp_arg_validate_int_range(self->character_bits, 7, 8, MP_QSTR_bits);
|
||||
self->timeout_ms = timeout * 1000;
|
||||
|
||||
if (self->character_bits != 7 && self->character_bits != 8) {
|
||||
mp_raise_ValueError(translate("Invalid word/bit length"));
|
||||
}
|
||||
|
||||
DBGPrintf(&mp_plat_print, "uart_construct: tx:%p rx:%p rts:%p cts:%p rs485:%p\n", tx, rx, rts, cts, rs485_dir);
|
||||
|
||||
@ -186,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) {
|
||||
@ -236,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +347,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
|
||||
if (!self->ringbuf) {
|
||||
LPUART_Deinit(self->uart);
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer"));
|
||||
m_malloc_fail(receiver_buffer_size);
|
||||
}
|
||||
|
||||
LPUART_TransferCreateHandle(self->uart, &self->handle, LPUART_UserCallback, self);
|
||||
|
@ -70,7 +70,7 @@ void common_hal_mcu_enable_interrupts(void) {
|
||||
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
|
||||
if (runmode == RUNMODE_BOOTLOADER) {
|
||||
if (!bootloader_available()) {
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present."));
|
||||
mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present"));
|
||||
}
|
||||
// Pretend to be the first of the two reset presses needed to enter the
|
||||
// bootloader. That way one reset will end in the bootloader.
|
||||
|
@ -301,7 +301,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self,
|
||||
|
||||
int pulse_count = calculate_pulse_count(frequency, &self->prescaler);
|
||||
if (pulse_count == 0) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
|
||||
self->pulse_count = pulse_count;
|
||||
|
@ -75,5 +75,5 @@ int common_hal_rtc_get_calibration(void) {
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
// SNVS has HPCALB_VAL bits for calibration.
|
||||
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
||||
|
@ -24,9 +24,8 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/usb_host/Port.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/usb_host/Port.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
@ -43,7 +42,7 @@ void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin
|
||||
supported_dm = &pin_USB_OTG2_DN;
|
||||
}
|
||||
if (dp != supported_dp || dm != supported_dm) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
self->init = true;
|
||||
usb_host_init = true;
|
||||
|
@ -49,10 +49,10 @@ extern uint32_t reset_reason_saved;
|
||||
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
|
||||
if (edge) {
|
||||
mp_raise_ValueError(translate("Cannot wake on pin edge. Only level."));
|
||||
mp_raise_ValueError(translate("Cannot wake on pin edge, only level"));
|
||||
}
|
||||
if (pin->number >= NUMBER_OF_PINS) {
|
||||
mp_raise_ValueError(translate("Invalid pin"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
self->pin = pin;
|
||||
self->value = value;
|
||||
|
@ -85,7 +85,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_
|
||||
continue;
|
||||
}
|
||||
if (timealarm_set) {
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set."));
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set"));
|
||||
}
|
||||
timealarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
timealarm_set = true;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "common-hal/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
@ -48,7 +49,7 @@ void analogin_init(void) {
|
||||
|
||||
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
if (pin->adc_channel == 0) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
nrf_gpio_cfg_default(pin->number);
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
mp_raise_RuntimeError(translate("AnalogOut functionality not supported"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut);
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
|
@ -263,9 +263,8 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self,
|
||||
&spacing);
|
||||
self->sample_channel_count = audiosample_channel_count(sample);
|
||||
|
||||
if (max_buffer_length > UINT16_MAX) {
|
||||
mp_raise_ValueError_varg(translate("Buffer length %d too big. It must be less than %d"), max_buffer_length, UINT16_MAX);
|
||||
}
|
||||
mp_arg_validate_length_max(max_buffer_length, UINT16_MAX, MP_QSTR_buffer);
|
||||
|
||||
uint16_t buffer_length = (uint16_t)max_buffer_length;
|
||||
self->buffers[0] = m_malloc(buffer_length * 2 * sizeof(uint16_t), false);
|
||||
if (!self->single_buffer) {
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
@ -96,7 +97,7 @@ static uint8_t twi_error_to_mp(const nrfx_err_t err) {
|
||||
|
||||
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 (scl->number == sda->number) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
// Find a free instance.
|
||||
|
@ -164,12 +164,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
|
||||
bool sigint_enabled) {
|
||||
|
||||
if (bits != 8) {
|
||||
mp_raise_ValueError(translate("Invalid word/bit length"));
|
||||
}
|
||||
mp_arg_validate_int(bits, 8, MP_QSTR_bits);
|
||||
|
||||
if ((rs485_dir != NULL) || (rs485_invert)) {
|
||||
mp_raise_ValueError(translate("RS485 Not yet supported on this device"));
|
||||
mp_raise_NotImplementedError(translate("RS485"));
|
||||
}
|
||||
|
||||
// Find a free UART peripheral.
|
||||
@ -189,9 +187,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
mp_raise_ValueError(translate("tx and rx cannot both be None"));
|
||||
}
|
||||
|
||||
if (receiver_buffer_size == 0) {
|
||||
mp_raise_ValueError(translate("Invalid buffer size"));
|
||||
}
|
||||
mp_arg_validate_int_min(receiver_buffer_size, 1, MP_QSTR_receiver_buffer_size);
|
||||
|
||||
if (parity == BUSIO_UART_PARITY_ODD) {
|
||||
mp_raise_ValueError(translate("Odd parity is not supported"));
|
||||
@ -234,7 +230,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
// (This is a macro.)
|
||||
} else if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) {
|
||||
nrfx_uarte_uninit(self->uarte);
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer"));
|
||||
m_malloc_fail(receiver_buffer_size);
|
||||
}
|
||||
|
||||
self->rx_pin_number = rx->number;
|
||||
|
@ -129,7 +129,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
|
||||
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
if (refcount == 0) {
|
||||
@ -271,7 +271,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_
|
||||
if (!self->paused) {
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_PulseIn);
|
||||
mp_raise_IndexError_varg(translate("%q out of range"), MP_QSTR_index);
|
||||
}
|
||||
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
|
||||
|
||||
|
@ -297,7 +297,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t fr
|
||||
uint16_t countertop;
|
||||
nrf_pwm_clk_t base_clock;
|
||||
if (frequency == 0 || !convert_frequency(frequency, &countertop, &base_clock)) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
self->frequency = frequency;
|
||||
|
||||
|
@ -80,5 +80,5 @@ int common_hal_rtc_get_calibration(void) {
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
||||
|
@ -223,50 +223,31 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
|
||||
|
||||
// We don't validate pin in use here because we may be ok sharing them within a PIO.
|
||||
const mcu_pin_obj_t *first_out_pin = validate_obj_is_pin_or_none(args[ARG_first_out_pin].u_obj);
|
||||
if (args[ARG_out_pin_count].u_int < 1) {
|
||||
mp_raise_ValueError(translate("Pin count must be at least 1"));
|
||||
}
|
||||
mp_int_t out_pin_count = mp_arg_validate_int_min(args[ARG_out_pin_count].u_int, 1, MP_QSTR_out_pin_count);
|
||||
|
||||
const mcu_pin_obj_t *first_in_pin = validate_obj_is_pin_or_none(args[ARG_first_in_pin].u_obj);
|
||||
if (args[ARG_in_pin_count].u_int < 1) {
|
||||
mp_raise_ValueError(translate("Pin count must be at least 1"));
|
||||
}
|
||||
mp_int_t in_pin_count = mp_arg_validate_int_min(args[ARG_in_pin_count].u_int, 1, MP_QSTR_in_pin_count);
|
||||
|
||||
const mcu_pin_obj_t *first_set_pin = validate_obj_is_pin_or_none(args[ARG_first_set_pin].u_obj);
|
||||
if (args[ARG_set_pin_count].u_int < 1) {
|
||||
mp_raise_ValueError(translate("Pin count must be at least 1"));
|
||||
}
|
||||
if (args[ARG_set_pin_count].u_int > 5) {
|
||||
mp_raise_ValueError(translate("Set pin count must be between 1 and 5"));
|
||||
}
|
||||
mp_int_t set_pin_count = mp_arg_validate_int_range(args[ARG_set_pin_count].u_int, 1, 5, MP_QSTR_set_pin_count);
|
||||
|
||||
const mcu_pin_obj_t *first_sideset_pin = validate_obj_is_pin_or_none(args[ARG_first_sideset_pin].u_obj);
|
||||
if (args[ARG_sideset_pin_count].u_int < 1) {
|
||||
mp_raise_ValueError(translate("Pin count must be at least 1"));
|
||||
}
|
||||
if (args[ARG_sideset_pin_count].u_int > 5) {
|
||||
mp_raise_ValueError(translate("Side set pin count must be between 1 and 5"));
|
||||
}
|
||||
mp_int_t sideset_pin_count = mp_arg_validate_int_range(args[ARG_sideset_pin_count].u_int, 1, 5, MP_QSTR_set_pin_count);
|
||||
|
||||
const mcu_pin_obj_t *jmp_pin = validate_obj_is_pin_or_none(args[ARG_jmp_pin].u_obj);
|
||||
digitalio_pull_t jmp_pin_pull = validate_pull(args[ARG_jmp_pin_pull].u_rom_obj, MP_QSTR_jmp_pull);
|
||||
|
||||
mp_int_t pull_threshold = args[ARG_pull_threshold].u_int;
|
||||
mp_int_t push_threshold = args[ARG_push_threshold].u_int;
|
||||
if (pull_threshold < 1 || pull_threshold > 32) {
|
||||
mp_raise_ValueError(translate("pull_threshold must be between 1 and 32"));
|
||||
}
|
||||
if (push_threshold < 1 || push_threshold > 32) {
|
||||
mp_raise_ValueError(translate("push_threshold must be between 1 and 32"));
|
||||
}
|
||||
mp_int_t pull_threshold =
|
||||
mp_arg_validate_int_range(args[ARG_pull_threshold].u_int, 1, 32, MP_QSTR_pull_threshold);
|
||||
mp_int_t push_threshold =
|
||||
mp_arg_validate_int_range(args[ARG_push_threshold].u_int, 1, 32, MP_QSTR_push_threshold);
|
||||
|
||||
if (bufinfo.len < 2) {
|
||||
mp_raise_ValueError(translate("Program must contain at least one 16-bit instruction."));
|
||||
}
|
||||
mp_arg_validate_length_range(bufinfo.len, 2, 64, MP_QSTR_program);
|
||||
if (bufinfo.len % 2 != 0) {
|
||||
mp_raise_ValueError(translate("Program size invalid"));
|
||||
}
|
||||
if (bufinfo.len > 64) {
|
||||
mp_raise_ValueError(translate("Program too large"));
|
||||
}
|
||||
|
||||
mp_arg_validate_length_range(init_bufinfo.len, 2, 64, MP_QSTR_init);
|
||||
if (init_bufinfo.len % 2 != 0) {
|
||||
mp_raise_ValueError(translate("Init program size invalid"));
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "common-hal/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
@ -36,7 +37,7 @@
|
||||
|
||||
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
if (pin->number < ADC_FIRST_PIN_NUMBER || pin->number > ADC_FIRST_PIN_NUMBER + ADC_PIN_COUNT) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
adc_init();
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
mp_raise_RuntimeError(translate("AnalogOut functionality not supported"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut);
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/bitbangio/I2C.h"
|
||||
|
||||
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
|
||||
@ -65,14 +66,14 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
self->peripheral = i2c[sda_instance];
|
||||
}
|
||||
if (self->peripheral == NULL) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
if ((i2c_get_hw(self->peripheral)->enable & I2C_IC_ENABLE_ENABLE_BITS) != 0) {
|
||||
mp_raise_ValueError(translate("I2C peripheral in use"));
|
||||
}
|
||||
if (frequency > 1000000) {
|
||||
mp_raise_ValueError(translate("Unsupported baudrate"));
|
||||
}
|
||||
|
||||
mp_arg_validate_int_max(frequency, 1000000, MP_QSTR_frequency);
|
||||
|
||||
|
||||
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
|
||||
|
@ -82,7 +82,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
// TODO: Check to see if we're sharing the SPI with a native APA102.
|
||||
|
||||
if (instance_index > 1) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
|
||||
if (instance_index == 0) {
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
|
||||
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
|
||||
@ -66,7 +67,7 @@ static uint8_t pin_init(const uint8_t uart, const mcu_pin_obj_t *pin, const uint
|
||||
return NO_PIN;
|
||||
}
|
||||
if (!(((pin->number % 4) == pin_type) && ((((pin->number + 4) / 8) % NUM_UARTS) == uart))) {
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
raise_ValueError_invalid_pins();
|
||||
}
|
||||
claim_pin(pin);
|
||||
gpio_set_function(pin->number, GPIO_FUNC_UART);
|
||||
@ -104,13 +105,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
|
||||
bool sigint_enabled) {
|
||||
|
||||
if (bits > 8) {
|
||||
mp_raise_ValueError(translate("Invalid word/bit length"));
|
||||
}
|
||||
|
||||
if (receiver_buffer_size == 0) {
|
||||
mp_raise_ValueError(translate("Invalid buffer size"));
|
||||
}
|
||||
mp_arg_validate_int_max(bits, 8, MP_QSTR_bits);
|
||||
mp_arg_validate_int_min(receiver_buffer_size, 1, MP_QSTR_receiver_buffer_size);
|
||||
|
||||
uint8_t uart_id = ((((tx != NULL) ? tx->number : rx->number) + 4) / 8) % NUM_UARTS;
|
||||
|
||||
@ -167,7 +163,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
// in the long-lived pool is not strictly necessary)
|
||||
// (This is a macro.)
|
||||
if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) {
|
||||
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer"));
|
||||
m_malloc_fail(receiver_buffer_size);
|
||||
}
|
||||
active_uarts[uart_id] = self;
|
||||
if (uart_id == 1) {
|
||||
|
@ -49,7 +49,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
||||
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
self->pin = pin->number;
|
||||
self->maxlen = maxlen;
|
||||
@ -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 index out of range"), MP_QSTR_PulseIn);
|
||||
mp_arg_validate_index_range(index, 0, self->len, MP_QSTR_index);
|
||||
}
|
||||
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
|
||||
return value;
|
||||
|
@ -259,7 +259,7 @@ void pwmio_pwmout_set_top(pwmio_pwmout_obj_t *self, uint16_t top) {
|
||||
|
||||
void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t frequency) {
|
||||
if (frequency == 0 || frequency > (common_hal_mcu_processor_get_frequency() / 2)) {
|
||||
mp_raise_ValueError(translate("Invalid PWM frequency"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
|
||||
target_slice_frequencies[self->slice] = frequency;
|
||||
|
@ -92,5 +92,5 @@ int common_hal_rtc_get_calibration(void) {
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_
|
||||
continue;
|
||||
}
|
||||
if (timealarm_set) {
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set."));
|
||||
mp_raise_ValueError(translate("Only one alarm.time alarm can be set"));
|
||||
}
|
||||
timealarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
timealarm_set = true;
|
||||
|
@ -51,7 +51,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
|
||||
|
||||
// No ADC function on pin
|
||||
if (pin->adc_unit == 0x00) {
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
// TODO: add ADC traits to structure?
|
||||
|
||||
@ -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);
|
||||
|
@ -65,7 +65,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
|
||||
self->channel = DAC_CHANNEL_2;
|
||||
self->dac_index = 1;
|
||||
} else {
|
||||
mp_raise_ValueError(translate("Invalid DAC pin supplied"));
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
|
||||
// Only init if the shared DAC is empty or reset
|
||||
|
@ -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 selection"), 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 baudrate"));
|
||||
mp_arg_error_invalid(MP_QSTR_frequency);
|
||||
}
|
||||
#else
|
||||
self->handle.Init.ClockSpeed = frequency;
|
||||
@ -171,7 +171,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
self->handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
self->handle.State = HAL_I2C_STATE_RESET;
|
||||
if (HAL_I2C_Init(&(self->handle)) != HAL_OK) {
|
||||
mp_raise_RuntimeError(translate("I2C Init Error"));
|
||||
mp_raise_RuntimeError(translate("I2C init error"));
|
||||
}
|
||||
common_hal_mcu_pin_claim(sda);
|
||||
common_hal_mcu_pin_claim(scl);
|
||||
|
@ -165,7 +165,7 @@ STATIC int check_pins(busio_spi_obj_t *self,
|
||||
if (spi_taken) {
|
||||
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
|
||||
} else {
|
||||
mp_raise_ValueError_varg(translate("Invalid %q pin selection"), MP_QSTR_SPI);
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
self->handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
self->handle.Init.CRCPolynomial = 10;
|
||||
if (HAL_SPI_Init(&self->handle) != HAL_OK) {
|
||||
mp_raise_ValueError(translate("SPI Init Error"));
|
||||
mp_raise_ValueError(translate("SPI init error"));
|
||||
}
|
||||
self->baudrate = (get_busclock(SPIx) / 16);
|
||||
self->prescaler = 16;
|
||||
@ -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;
|
||||
@ -346,7 +346,7 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
|
||||
bool common_hal_busio_spi_write(busio_spi_obj_t *self,
|
||||
const uint8_t *data, size_t len) {
|
||||
if (self->mosi == NULL) {
|
||||
mp_raise_ValueError(translate("No MOSI Pin"));
|
||||
mp_raise_ValueError(translate("No MOSI pin"));
|
||||
}
|
||||
HAL_StatusTypeDef result = HAL_SPI_Transmit(&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY);
|
||||
return result == HAL_OK;
|
||||
@ -355,9 +355,9 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
|
||||
bool common_hal_busio_spi_read(busio_spi_obj_t *self,
|
||||
uint8_t *data, size_t len, uint8_t write_value) {
|
||||
if (self->miso == NULL && !self->half_duplex) {
|
||||
mp_raise_ValueError(translate("No MISO Pin"));
|
||||
mp_raise_ValueError(translate("No MISO pin"));
|
||||
} else if (self->half_duplex && self->mosi == NULL) {
|
||||
mp_raise_ValueError(translate("No MOSI Pin"));
|
||||
mp_raise_ValueError(translate("No MOSI pin"));
|
||||
}
|
||||
HAL_StatusTypeDef result = HAL_OK;
|
||||
if ((!self->half_duplex && self->mosi == NULL) || (self->half_duplex && self->mosi != NULL && self->miso == NULL)) {
|
||||
@ -372,7 +372,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
|
||||
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
|
||||
const uint8_t *data_out, uint8_t *data_in, size_t len) {
|
||||
if (self->miso == NULL || self->mosi == NULL) {
|
||||
mp_raise_ValueError(translate("Missing MISO or MOSI Pin"));
|
||||
mp_raise_ValueError(translate("Missing MISO or MOSI pin"));
|
||||
}
|
||||
HAL_StatusTypeDef result = HAL_SPI_TransmitReceive(&self->handle,
|
||||
(uint8_t *)data_out, data_in, (uint16_t)len,HAL_MAX_DELAY);
|
||||
|
@ -58,7 +58,7 @@ STATIC USART_TypeDef *assign_uart_or_throw(busio_uart_obj_t *self, bool pin_eval
|
||||
if (uart_taken) {
|
||||
mp_raise_ValueError(translate("Hardware in use, try alternative pins"));
|
||||
} else {
|
||||
mp_raise_ValueError_varg(translate("Invalid %q pin selection"), MP_QSTR_UART);
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
@ -164,14 +164,11 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
}
|
||||
|
||||
// Other errors
|
||||
if (receiver_buffer_size == 0) {
|
||||
mp_raise_ValueError(translate("Invalid buffer size"));
|
||||
}
|
||||
if (bits != 8 && bits != 9) {
|
||||
mp_raise_ValueError(translate("Invalid word/bit length"));
|
||||
}
|
||||
mp_arg_validate_length_min(receiver_buffer_size, 1, MP_QSTR_receiver_buffer_size);
|
||||
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
|
||||
@ -211,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"));
|
||||
|
||||
}
|
||||
|
||||
@ -221,7 +218,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
self->ringbuf = (ringbuf_t) { receiver_buffer, receiver_buffer_size };
|
||||
} else {
|
||||
if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) {
|
||||
mp_raise_ValueError(translate("UART Buffer allocation error"));
|
||||
m_malloc_fail(receiver_buffer_size);
|
||||
}
|
||||
}
|
||||
common_hal_mcu_pin_claim(rx);
|
||||
@ -235,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
|
||||
@ -338,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;
|
||||
@ -408,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;
|
||||
|
@ -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 selection"), 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 selection"), MP_QSTR_rx);
|
||||
raise_ValueError_invalid_pin_name(MP_QSTR_rx);
|
||||
}
|
||||
|
||||
if (reserved_can[periph_index]) {
|
||||
|
@ -123,8 +123,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
|
||||
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
|
||||
if (self->buffer == NULL) {
|
||||
// TODO: free the EXTI here?
|
||||
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"),
|
||||
maxlen * sizeof(uint16_t));
|
||||
m_malloc_fail(maxlen * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
// Set internal variables
|
||||
@ -257,7 +256,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_
|
||||
}
|
||||
if (index < 0 || index >= self->len) {
|
||||
stm_peripherals_exti_enable(self->pin->number);
|
||||
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_PulseIn);
|
||||
mp_raise_IndexError_varg(translate("%q out of range"), MP_QSTR_index);
|
||||
}
|
||||
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
|
||||
stm_peripherals_exti_enable(self->pin->number);
|
||||
|
@ -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;
|
||||
|
@ -115,7 +115,7 @@ STATIC int check_pins(sdioio_sdcard_obj_t *self,
|
||||
if (sdio_taken) {
|
||||
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
|
||||
} else {
|
||||
mp_raise_ValueError_varg(translate("Invalid %q pin selection"), MP_QSTR_SDIO);
|
||||
raise_ValueError_invalid_pin();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,13 @@ NORETURN void mp_arg_error_unimpl_kw(void) {
|
||||
#endif
|
||||
|
||||
|
||||
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name) {
|
||||
if (i != required_i) {
|
||||
mp_raise_ValueError_varg(translate("%q must be %d"), arg_name, required_i);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
|
||||
if (i < min) {
|
||||
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, min);
|
||||
@ -194,6 +201,35 @@ mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_
|
||||
return length;
|
||||
}
|
||||
|
||||
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name) {
|
||||
if (length < min) {
|
||||
mp_raise_ValueError_varg(translate("%q length must be >= %d"), arg_name, min);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name) {
|
||||
if (length > max) {
|
||||
mp_raise_ValueError_varg(translate("%q length must be <= %d"), arg_name, max);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name) {
|
||||
if (length != required_length) {
|
||||
mp_raise_ValueError_varg(translate("%q length must be %d"), arg_name, required_length);
|
||||
}
|
||||
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);
|
||||
@ -201,9 +237,21 @@ mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_
|
||||
return obj;
|
||||
}
|
||||
|
||||
mp_obj_t mp_arg_validate_string(mp_obj_t obj, qstr arg_name) {
|
||||
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
|
||||
if (!mp_obj_is_str(obj)) {
|
||||
mp_raise_TypeError_varg(translate("%q must be a string"), arg_name);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
|
||||
mp_int_t an_int;
|
||||
if (!mp_obj_get_int_maybe(obj, &an_int)) {
|
||||
mp_raise_TypeError_varg(translate("%q must be an int"), arg_name);
|
||||
}
|
||||
return an_int;
|
||||
}
|
||||
|
||||
NORETURN void mp_arg_error_invalid(qstr arg_name) {
|
||||
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, s
|
||||
#endif
|
||||
|
||||
// If we have a __path__ in the globals dict, then we're a package.
|
||||
bool is_pkg = mp_map_lookup(&mp_globals_get()->map, MP_OBJ_NEW_QSTR(MP_QSTR___path__), MP_MAP_LOOKUP);
|
||||
bool is_pkg = mp_map_lookup(&mp_globals_get()->map, MP_OBJ_NEW_QSTR(MP_QSTR___path__), MP_MAP_LOOKUP) != NULL;
|
||||
|
||||
#if DEBUG_PRINT
|
||||
DEBUG_printf("Current module/package: ");
|
||||
|
@ -92,15 +92,22 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
|
||||
NORETURN void mp_arg_error_terse_mismatch(void);
|
||||
NORETURN void mp_arg_error_unimpl_kw(void);
|
||||
|
||||
NORETURN void mp_arg_error_invalid(qstr arg_name);
|
||||
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name);
|
||||
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name);
|
||||
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t j, qstr arg_name);
|
||||
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name);
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name);
|
||||
#endif
|
||||
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name);
|
||||
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_obj_t mp_arg_validate_string(mp_obj_t obj, 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);
|
||||
|
||||
static inline mp_obj_dict_t *PLACE_IN_ITCM(mp_locals_get)(void) {
|
||||
return MP_STATE_THREAD(dict_locals);
|
||||
|
@ -69,7 +69,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
|
||||
const mp_int_t address_type = args[ARG_address_type].u_int;
|
||||
if (address_type < BLEIO_ADDRESS_TYPE_MIN || address_type > BLEIO_ADDRESS_TYPE_MAX) {
|
||||
mp_raise_ValueError(translate("Address type out of range"));
|
||||
mp_arg_error_invalid(MP_QSTR_address_type);
|
||||
}
|
||||
|
||||
common_hal_bleio_address_construct(self, buf_info.buf, address_type);
|
||||
|
@ -100,7 +100,7 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
|
||||
|
||||
const bleio_characteristic_properties_t properties = args[ARG_properties].u_int;
|
||||
if (properties & ~CHAR_PROP_ALL) {
|
||||
mp_raise_ValueError(translate("Invalid properties"));
|
||||
mp_arg_error_invalid(MP_QSTR_properties);
|
||||
}
|
||||
|
||||
const bleio_attribute_security_mode_t read_perm = args[ARG_read_perm].u_int;
|
||||
@ -109,10 +109,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
|
||||
const bleio_attribute_security_mode_t write_perm = args[ARG_write_perm].u_int;
|
||||
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
|
||||
|
||||
const mp_int_t max_length_int = args[ARG_max_length].u_int;
|
||||
if (max_length_int < 0) {
|
||||
mp_raise_ValueError(translate("max_length must be >= 0"));
|
||||
}
|
||||
const mp_int_t max_length_int = mp_arg_validate_int_min(args[ARG_max_length].u_int, 0, MP_QSTR_max_length);
|
||||
|
||||
const size_t max_length = (size_t)max_length_int;
|
||||
const bool fixed_length = args[ARG_fixed_length].u_bool;
|
||||
mp_obj_t initial_value = args[ARG_initial_value].u_obj;
|
||||
|
@ -70,15 +70,9 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type,
|
||||
|
||||
bleio_characteristic_obj_t *characteristic = mp_arg_validate_type(args[ARG_characteristic].u_obj, &bleio_characteristic_type, MP_QSTR_characteristic);
|
||||
|
||||
mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
|
||||
if (timeout < 0.0f) {
|
||||
mp_raise_ValueError(translate("timeout must be >= 0.0"));
|
||||
}
|
||||
mp_float_t timeout = mp_arg_validate_obj_float_non_negative(args[ARG_timeout].u_obj, 1.0f, MP_QSTR_timeout);
|
||||
|
||||
const int buffer_size = args[ARG_buffer_size].u_int;
|
||||
if (buffer_size < 1) {
|
||||
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_buffer_size);
|
||||
}
|
||||
const mp_int_t buffer_size = mp_arg_validate_int_min(args[ARG_buffer_size].u_int, 1, MP_QSTR_buffer_size);
|
||||
|
||||
bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t);
|
||||
self->base.type = &bleio_characteristic_buffer_type;
|
||||
|
@ -94,10 +94,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
|
||||
const bleio_attribute_security_mode_t write_perm = args[ARG_write_perm].u_int;
|
||||
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
|
||||
|
||||
const mp_int_t max_length_int = args[ARG_max_length].u_int;
|
||||
if (max_length_int < 0) {
|
||||
mp_raise_ValueError(translate("max_length must be >= 0"));
|
||||
}
|
||||
const mp_int_t max_length_int = mp_arg_validate_int_min(args[ARG_max_length].u_int, 0, MP_QSTR_max_length);
|
||||
|
||||
const size_t max_length = (size_t)max_length_int;
|
||||
const bool fixed_length = args[ARG_fixed_length].u_bool;
|
||||
mp_obj_t initial_value = args[ARG_initial_value].u_obj;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user