Merge remote-tracking branch 'adafruit/main' into dotenv

This commit is contained in:
Scott Shawcroft 2022-05-23 11:23:20 -07:00
commit a6b60d2083
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
193 changed files with 7711 additions and 11129 deletions

3
.gitmodules vendored
View File

@ -289,3 +289,6 @@
[submodule "frozen/pew-pewpew-lcd"] [submodule "frozen/pew-pewpew-lcd"]
path = frozen/pew-pewpew-lcd path = frozen/pew-pewpew-lcd
url = https://github.com/pypewpew/pew-pewpew-lcd.git url = https://github.com/pypewpew/pew-pewpew-lcd.git
[submodule "ports/espressif/boards/mixgo_ce_udisk/cp_lib"]
path = ports/espressif/boards/mixgo_ce_udisk/cp_lib
url = https://github.com/dahanzimin/circuitpython_lib.git

View File

@ -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); self->value = mp_obj_new_bytes(initial_value_bufinfo->buf, initial_value_bufinfo->len);
const mp_int_t max_length_max = 512; 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->max_length = max_length;
self->fixed_length = fixed_length; self->fixed_length = fixed_length;

View File

@ -30,6 +30,11 @@
#define mp_obj_fat_vfs_t fs_user_mount_t #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) { STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) {
fs_user_mount_t *vfs = vfs_in; fs_user_mount_t *vfs = vfs_in;
FILINFO fno; 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 // don't error out if no filesystem, to let mkfs()/mount() create one if wanted
vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NO_FILESYSTEM; vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NO_FILESYSTEM;
} else if (res != FR_OK) { } else if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return MP_OBJ_FROM_PTR(vfs); 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)); res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
} }
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; 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; iter->is_str = is_str_type;
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path); FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return MP_OBJ_FROM_PTR(iter); 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); FRESULT res = f_stat(&self->fatfs, path, &fno);
if (res != FR_OK) { 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 // 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); res = f_unlink(&self->fatfs, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; return mp_const_none;
} else { } 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; FILINFO fno;
FRESULT res = f_stat(&self->fatfs, old_path, &fno); FRESULT res = f_stat(&self->fatfs, old_path, &fno);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
if ((fno.fattrib & AM_DIR) != 0 && if ((fno.fattrib & AM_DIR) != 0 &&
strlen(new_path) > strlen(old_path) && 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) { if (res == FR_OK) {
return mp_const_none; return mp_const_none;
} else { } 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) { if (res == FR_OK) {
return mp_const_none; return mp_const_none;
} else { } 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); 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); FRESULT res = f_chdir(&self->fatfs, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; 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]; char buf[MICROPY_ALLOC_PATH_MAX + 1];
FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf)); FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf));
if (res != FR_OK) { 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)); 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 { } else {
FRESULT res = f_stat(&self->fatfs, path, &fno); FRESULT res = f_stat(&self->fatfs, path, &fno);
if (res != FR_OK) { 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; FATFS *fatfs = &self->fatfs;
FRESULT res = f_getfree(fatfs, &nclst); FRESULT res = f_getfree(fatfs, &nclst);
if (FR_OK != res) { 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)); 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)); res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
} }
if (res != FR_OK) { 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; 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]; char working_buf[12];
FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL); FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL);
if (res != FR_OK) { 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)); 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) { if (res == FR_WRITE_PROTECTED) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem")); 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; return mp_const_none;
} }

View File

@ -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) { 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); assert(vfs != NULL);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -9,3 +9,5 @@ CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1 INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -7,5 +7,5 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ

View File

@ -7,5 +7,5 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ

View File

@ -7,7 +7,7 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_AESIO = 0 CIRCUITPY_AESIO = 0

View File

@ -234,7 +234,7 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
// raise ValueError here // raise ValueError here
MP_FALLTHROUGH MP_FALLTHROUGH
case PINALARM_ERR_NOEXTINT: case PINALARM_ERR_NOEXTINT:
mp_raise_RuntimeError(translate("No hardware support on pin")); raise_ValueError_invalid_pin();
case PINALARM_ERR_NOCHANNEL: case PINALARM_ERR_NOCHANNEL:
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use")); mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
default: default:
@ -261,7 +261,7 @@ static void pinalarm_set_alarms_deep(size_t n_alarms, const mp_obj_t *alarms) {
} }
} }
if (t->n < 0) { 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 // It is strange, but to my experiment, interrupt during sleep

View File

@ -100,7 +100,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_
continue; continue;
} }
if (timealarm_set) { 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 = MP_OBJ_TO_PTR(alarms[i]);
timealarm_set = true; timealarm_set = true;

View File

@ -36,6 +36,7 @@
#include "samd/adc.h" #include "samd/adc.h"
#include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/analogio/AnalogIn.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "atmel_start_pins.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) { if (adc_channel == 0xff) {
// No ADC function on that pin // No ADC function on that pin
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);

View File

@ -70,7 +70,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
#endif #endif
default: default:
mp_raise_ValueError(translate("AnalogOut not supported on given pin")); raise_ValueError_invalid_pin();
return; return;
} }

View File

@ -151,16 +151,16 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
} }
#endif #endif
if (bc_clock_unit == 0xff) { 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) { 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) { if (bc_clock_unit != ws_clock_unit) {
mp_raise_ValueError(translate("Bit clock and word select must share a clock unit")); mp_raise_ValueError(translate("Bit clock and word select must share a clock unit"));
} }
if (serializer == 0xff) { 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->clock_unit = ws_clock_unit;
self->serializer = serializer; 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); uint8_t channel_count = audiosample_channel_count(sample);
if (channel_count > 2) { if (channel_count > 2) {
mp_raise_ValueError(translate("Too many channels in sample.")); mp_raise_ValueError(translate("Too many channels in sample"));
} }
#ifdef SAMD21 #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; 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;

View File

@ -121,7 +121,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
self->clock_unit = 1; self->clock_unit = 1;
#endif #endif
} else { } 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 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; self->serializer = 1;
#endif #endif
} else { } 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) { if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != OVERSAMPLING) {

View File

@ -136,20 +136,21 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
mp_raise_ValueError(translate("Right channel unsupported")); mp_raise_ValueError(translate("Right channel unsupported"));
} }
if (left_channel != &pin_PA02) { if (left_channel != &pin_PA02) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
claim_pin(left_channel); claim_pin(left_channel);
#endif #endif
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
self->right_channel = NULL; self->right_channel = NULL;
if (left_channel != &pin_PA02 && left_channel != &pin_PA05) { 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) { 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) { 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); claim_pin(left_channel);
if (right_channel != NULL) { 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; audio_dma_result result = AUDIO_DMA_OK;
uint32_t sample_rate = audiosample_sample_rate(sample); uint32_t sample_rate = audiosample_sample_rate(sample);
#ifdef SAMD21 #ifdef SAMD21
uint32_t max_sample_rate = 350000; const uint32_t max_sample_rate = 350000;
#endif #endif
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
uint32_t max_sample_rate = 1000000; const uint32_t max_sample_rate = 1000000;
#endif #endif
if (sample_rate > max_sample_rate) { mp_arg_validate_int_max(sample_rate, max_sample_rate, MP_QSTR_sample_rate);
mp_raise_ValueError_varg(translate("Sample rate too high. It must be less than %d"), max_sample_rate);
}
#ifdef SAMD21 #ifdef SAMD21
result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0, result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0,
false /* output unsigned */, false /* output unsigned */,

View File

@ -34,6 +34,7 @@
#include "samd/sercom.h" #include "samd/sercom.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "common-hal/busio/__init__.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; self->sda_pin = NO_PIN;
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
if (sercom == NULL) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
#if CIRCUITPY_REQUIRE_I2C_PULLUPS #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 // 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 // but set_baudrate does not diagnose this problem. (This is not the
// exact cutoff, but no frequency well under 100kHz is available) // exact cutoff, but no frequency well under 100kHz is available)
if (frequency < 95000) { if (frequency < 95000 &&
mp_raise_ValueError(translate("Unsupported baudrate")); i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
}
if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
reset_pin_number(sda->number); reset_pin_number(sda->number);
reset_pin_number(scl->number); reset_pin_number(scl->number);
common_hal_busio_i2c_deinit(self); common_hal_busio_i2c_deinit(self);
mp_raise_ValueError(translate("Unsupported baudrate")); mp_arg_error_invalid(MP_QSTR_frequency);
} }
self->sda_pin = sda->number; self->sda_pin = sda->number;

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/SPI.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/runtime.h" #include "py/runtime.h"
@ -33,7 +34,6 @@
#include "supervisor/board.h" #include "supervisor/board.h"
#include "common-hal/busio/__init__.h" #include "common-hal/busio/__init__.h"
#include "common-hal/microcontroller/Pin.h"
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
#include "hal/include/hal_spi_m_sync.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) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
// Set up SPI clocks on SERCOM. // Set up SPI clocks on SERCOM.

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/UART.h" #include "shared-bindings/busio/UART.h"
#include "mpconfigport.h" #include "mpconfigport.h"
@ -76,12 +77,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->tx_pin = NO_PIN; self->tx_pin = NO_PIN;
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { 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_arg_validate_int_max(bits, 8, MP_QSTR_bits);
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
}
bool have_tx = tx != NULL; bool have_tx = tx != NULL;
bool have_rx = rx != NULL; bool have_rx = rx != NULL;
@ -145,7 +144,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
} }
} }
if (sercom == NULL) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
if (!have_tx) { if (!have_tx) {
tx_pad = 0; 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); self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
if (self->buffer == NULL) { if (self->buffer == NULL) {
common_hal_busio_uart_deinit(self); 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 { } 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) { 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 // usart_async_init() sets a number of defaults based on a prototypical SERCOM

View File

@ -45,6 +45,7 @@
#include "peripheral_clk_config.h" #include "peripheral_clk_config.h"
#include "hpl_gclk_config.h" #include "hpl_gclk_config.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/time/__init__.h" #include "shared-bindings/time/__init__.h"
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "supervisor/shared/translate.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) { 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) { if (!pin->has_extint) {
mp_raise_RuntimeError(translate("No hardware support on pin")); raise_ValueError_invalid_pin();
}
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, 0, 500, MP_QSTR_capture_period);
uint32_t mask = 1 << pin->extint_channel; uint32_t mask = 1 << pin->extint_channel;
if (eic_get_enable() == 1 && if (eic_get_enable() == 1 &&
#ifdef SAMD21 #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) { 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_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
}
self->capture_period = capture_period; self->capture_period = capture_period;

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "shared-bindings/i2cperipheral/I2CPeripheral.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "common-hal/busio/I2C.h" #include "common-hal/busio/I2C.h"
#include "shared/runtime/interrupt_char.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; uint32_t sda_pinmux, scl_pinmux;
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
if (sercom == NULL) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
self->sercom = sercom; self->sercom = sercom;

View File

@ -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 // The peripheral supports 8, 10, 12, or 14 data bits, but the code only supports 8 at present
if (data_count != 8) { 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) { 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) { 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) { 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 // technically, 0 was validated as free already but check again
for (int i = 0; i < data_count; i++) { for (int i = 0; i < data_count; i++) {

View File

@ -66,7 +66,7 @@ void common_hal_mcu_enable_interrupts(void) {
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
if (runmode == RUNMODE_BOOTLOADER) { if (runmode == RUNMODE_BOOTLOADER) {
if (!bootloader_available()) { 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 // Pretend to be the first of the two reset presses needed to enter the
// bootloader. That way one reset will end in the bootloader. // bootloader. That way one reset will end in the bootloader.

View File

@ -79,7 +79,7 @@ static void resume_interrupt(ps2io_ps2_obj_t *self) {
disable_interrupt(self); disable_interrupt(self);
self->state = STATE_IDLE; 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; uint32_t mask = 1 << self->channel;
EIC->INTFLAG.reg = mask << EIC_INTFLAG_EXTINT_Pos; EIC->INTFLAG.reg = mask << EIC_INTFLAG_EXTINT_Pos;
EIC->INTENSET.reg = mask << EIC_INTENSET_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) { static void clk_hi(ps2io_ps2_obj_t *self) {
// External pull-up // External pull-up
// Must set pull after setting direction. // Must set pull after setting direction.
gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_IN); gpio_set_pin_direction(self->clock_pin, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); gpio_set_pin_pull_mode(self->clock_pin, GPIO_PULL_OFF);
} }
static bool wait_clk_lo(ps2io_ps2_obj_t *self, uint32_t us) { static bool wait_clk_lo(ps2io_ps2_obj_t *self, uint32_t us) {
clk_hi(self); clk_hi(self);
common_hal_mcu_delay_us(1); 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; --us;
common_hal_mcu_delay_us(1); 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) { static bool wait_clk_hi(ps2io_ps2_obj_t *self, uint32_t us) {
clk_hi(self); clk_hi(self);
common_hal_mcu_delay_us(1); 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; --us;
common_hal_mcu_delay_us(1); 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) { static void clk_lo(ps2io_ps2_obj_t *self) {
gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); gpio_set_pin_pull_mode(self->clock_pin, GPIO_PULL_OFF);
gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_OUT); gpio_set_pin_direction(self->clock_pin, GPIO_DIRECTION_OUT);
gpio_set_pin_level(self->clk_pin, 0); gpio_set_pin_level(self->clock_pin, 0);
} }
static void data_hi(ps2io_ps2_obj_t *self) { 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, 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) { const mcu_pin_obj_t *data_pin, const mcu_pin_obj_t *clock_pin) {
if (!clk_pin->has_extint) { if (!clock_pin->has_extint) {
mp_raise_RuntimeError(translate("No hardware support on clk pin")); 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")); mp_raise_RuntimeError(translate("EXTINT channel already in use"));
} }
clk_hi(self); clk_hi(self);
data_hi(self); data_hi(self);
self->channel = clk_pin->extint_channel; self->channel = clock_pin->extint_channel;
self->clk_pin = clk_pin->number; self->clock_pin = clock_pin->number;
self->data_pin = data_pin->number; self->data_pin = data_pin->number;
self->state = STATE_IDLE; self->state = STATE_IDLE;
self->bufcount = 0; self->bufcount = 0;
@ -264,19 +264,19 @@ void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t *self,
self->bufposw = 0; self->bufposw = 0;
self->waiting_cmd_response = false; 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.' // Check to see if the EIC is enabled and start it up if its not.'
if (eic_get_enable() == 0) { if (eic_get_enable() == 0) {
turn_on_external_interrupt_controller(); 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); gpio_set_pin_function(data_pin->number, GPIO_PIN_FUNCTION_A);
turn_on_cpu_interrupt(self->channel); turn_on_cpu_interrupt(self->channel);
claim_pin(clk_pin); claim_pin(clock_pin);
claim_pin(data_pin); claim_pin(data_pin);
// Set config will enable the EIC. // 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) { 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) { 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); set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
turn_off_eic_channel(self->channel); turn_off_eic_channel(self->channel);
reset_pin_number(self->clk_pin); reset_pin_number(self->clock_pin);
reset_pin_number(self->data_pin); reset_pin_number(self->data_pin);
self->clk_pin = NO_PIN; self->clock_pin = NO_PIN;
self->data_pin = NO_PIN; self->data_pin = NO_PIN;
} }

View File

@ -35,7 +35,7 @@
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
uint8_t channel; uint8_t channel;
uint8_t clk_pin; uint8_t clock_pin;
uint8_t data_pin; uint8_t data_pin;
uint8_t state; uint8_t state;

View File

@ -41,6 +41,7 @@
#include "samd/pins.h" #include "samd/pins.h"
#include "samd/timers.h" #include "samd/timers.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/pulseio/PulseIn.h" #include "shared-bindings/pulseio/PulseIn.h"
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
@ -152,7 +153,7 @@ void pulsein_reset() {
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) { const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
if (!pin->has_extint) { 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)) { if (eic_get_enable() && !eic_channel_free(pin->extint_channel)) {
mp_raise_RuntimeError(translate("EXTINT channel already in use")); 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); self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
if (self->buffer == NULL) { 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->channel = pin->extint_channel;
self->pin = pin->number; 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; return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0;
} }
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) {
int16_t index) {
common_hal_mcu_disable_interrupts(); common_hal_mcu_disable_interrupts();
if (index < 0) { if (index < 0) {
index += self->len; index += self->len;
} }
if (index < 0 || index >= self->len) { if (index < 0 || index >= self->len) {
common_hal_mcu_enable_interrupts(); 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]; uint16_t value = self->buffer[(self->start + index) % self->maxlen];
common_hal_mcu_enable_interrupts(); common_hal_mcu_enable_interrupts();

View File

@ -377,7 +377,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self,
uint32_t frequency) { uint32_t frequency) {
uint32_t system_clock = common_hal_mcu_processor_get_frequency(); uint32_t system_clock = common_hal_mcu_processor_get_frequency();
if (frequency == 0 || frequency > system_clock / 2) { 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; const pin_timer_t *t = self->timer;
uint8_t resolution; uint8_t resolution;

View File

@ -68,13 +68,7 @@ int common_hal_rtc_get_calibration(void) {
} }
void common_hal_rtc_set_calibration(int calibration) { void common_hal_rtc_set_calibration(int calibration) {
if (calibration > 127 || calibration < -127) { mp_arg_validate_int_range(calibration, -127, 127, MP_QSTR_calibration);
#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
}
hri_rtcmode0_write_FREQCORR_SIGN_bit(RTC, calibration < 0 ? 0 : 1); hri_rtcmode0_write_FREQCORR_SIGN_bit(RTC, calibration < 0 ? 0 : 1);
hri_rtcmode0_write_FREQCORR_VALUE_bf(RTC, abs(calibration)); hri_rtcmode0_write_FREQCORR_VALUE_bf(RTC, abs(calibration));

View File

@ -31,6 +31,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/binary.h" #include "py/binary.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/touchio/TouchIn.h" #include "shared-bindings/touchio/TouchIn.h"
#include "supervisor/shared/translate.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, void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
if (!pin->has_touch) { if (!pin->has_touch) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);

View File

@ -90,7 +90,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
} }
} }
if (instance_index == NUM_I2C) { if (instance_index == NUM_I2C) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
i2c_in_use[instance_index] = true; i2c_in_use[instance_index] = true;
self->index = instance_index; self->index = instance_index;

View File

@ -104,7 +104,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
break; break;
} }
if (instance_index == NUM_SPI) { if (instance_index == NUM_SPI) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
self->clock = clock; self->clock = clock;

View File

@ -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, mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
bool sigint_enabled) { bool sigint_enabled) {
if (bits > 8) { mp_arg_validate_int_max(bits, 8, MP_QSTR_bits);
mp_raise_ValueError(translate("Invalid word/bit length")); mp_arg_validate_int_min(receiver_buffer_size, 1, MP_QSTR_receiver_buffer_size);
}
if (receiver_buffer_size == 0) {
mp_raise_ValueError(translate("Invalid buffer size"));
}
if ((rs485_dir != NULL) || (rs485_invert)) { if ((rs485_dir != NULL) || (rs485_invert)) {
mp_raise_NotImplementedError(translate("RS485 Not yet supported on this device")); 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; break;
} }
if (instance_index == NUM_UART) { if (instance_index == NUM_UART) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
self->rx_pin = rx; 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) // in the long-lived pool is not strictly necessary)
// (This is a macro.) // (This is a macro.)
if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) { 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);
} }
} }
} }

View File

@ -34,6 +34,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/analogio/AnalogIn.h"
#include "shared-bindings/microcontroller/Pin.h"
typedef struct { typedef struct {
const char *devpath; 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) { void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) {
if (!pin->analog) { if (!pin->analog) {
mp_raise_ValueError(translate("AnalogIn not supported on given pin")); raise_ValueError_invalid_pin();
} }
self->number = -1; self->number = -1;
@ -65,13 +66,13 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
} }
if (self->number < 0) { 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) { if (analogin_dev[self->number].fd < 0) {
analogin_dev[self->number].fd = open(analogin_dev[self->number].devpath, O_RDONLY); analogin_dev[self->number].fd = open(analogin_dev[self->number].devpath, O_RDONLY);
if (analogin_dev[self->number].fd < 0) { if (analogin_dev[self->number].fd < 0) {
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); raise_ValueError_invalid_pin();
} }
} }

View File

@ -29,7 +29,7 @@
#include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/analogio/AnalogOut.h"
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { 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) { void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {

View File

@ -32,15 +32,16 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/busio/I2C.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, 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) { const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) { 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) { if (scl->number != PIN_I2C0_BCK || sda->number != PIN_I2C0_BDT) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
claim_pin(scl); claim_pin(scl);

View File

@ -33,6 +33,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/busio/SPI.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, 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) { 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) { if (port < 0) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
claim_pin(clock); claim_pin(clock);

View File

@ -40,6 +40,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/busio/UART.h" #include "shared-bindings/busio/UART.h"
#include "shared-bindings/microcontroller/Pin.h"
typedef struct { typedef struct {
const char *devpath; const char *devpath;
@ -65,20 +66,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
struct termios tio; struct termios tio;
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { 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_arg_validate_int(bits, 8, MP_QSTR_bits);
mp_raise_ValueError(translate("Could not initialize UART")); mp_arg_validate_int(parity, BUSIO_UART_PARITY_NONE, MP_QSTR_parity);
} mp_arg_validate_int(stop, 1, MP_QSTR_stop);
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"));
}
self->number = -1; self->number = -1;
@ -91,13 +84,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
} }
if (self->number < 0) { if (self->number < 0) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
if (busio_uart_dev[self->number].fd < 0) { if (busio_uart_dev[self->number].fd < 0) {
busio_uart_dev[self->number].fd = open(busio_uart_dev[self->number].devpath, O_RDWR); busio_uart_dev[self->number].fd = open(busio_uart_dev[self->number].devpath, O_RDWR);
if (busio_uart_dev[self->number].fd < 0) { 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 // Wait to make sure the UART is ready

View File

@ -121,11 +121,11 @@ static void camera_start_preview() {
void common_hal_camera_construct(camera_obj_t *self) { void common_hal_camera_construct(camera_obj_t *self) {
if (camera_dev.fd < 0) { if (camera_dev.fd < 0) {
if (video_initialize(camera_dev.devpath) < 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); camera_dev.fd = open(camera_dev.devpath, 0);
if (camera_dev.fd < 0) { if (camera_dev.fd < 0) {
mp_raise_ValueError(translate("Could not initialize Camera")); mp_raise_RuntimeError(translate("Camera init"));
} }
} }

View File

@ -29,10 +29,11 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/digitalio/DigitalInOut.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) { digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
if (pin->analog) { if (pin->analog) {
mp_raise_ValueError(translate("DigitalInOut not supported on given pin")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);

View File

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

View File

@ -72,7 +72,7 @@ void common_hal_mcu_enable_interrupts(void) {
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
if (runmode == RUNMODE_BOOTLOADER) { 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) { } else if (runmode == RUNMODE_SAFE_MODE) {
safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE); safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE);
} }

View File

@ -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) { const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false); self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
if (self->buffer == NULL) { 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->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) { if (index < 0 || index >= self->len) {
common_hal_mcu_enable_interrupts(); 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]; uint16_t value = self->buffer[(self->start + index) % self->maxlen];
common_hal_mcu_enable_interrupts(); common_hal_mcu_enable_interrupts();

View File

@ -74,7 +74,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
self->variable_frequency = variable_frequency; self->variable_frequency = variable_frequency;
if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) { 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); 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; self->info.frequency = frequency;
if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) { 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);
} }
} }

View File

@ -50,5 +50,5 @@ int common_hal_rtc_get_calibration(void) {
} }
void common_hal_rtc_set_calibration(int calibration) { 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);
} }

View File

@ -31,6 +31,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/sdioio/SDCard.h" #include "shared-bindings/sdioio/SDCard.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
@ -42,7 +43,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
struct geometry geo; struct geometry geo;
if (clock->number != PIN_SDIO_CLK || command->number != PIN_SDIO_CMD) { 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; 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) { 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) { 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); self->inode->u.i_bops->geometry(self->inode, &geo);

View File

@ -0,0 +1,70 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "lib/oofatfs/ff.h"
#include "extmod/vfs_fat.h"
#include "py/mpstate.h"
void board_init(void) {
// Debug UART
#ifdef DEBUG
common_hal_never_reset_pin(&pin_GPIO43);
common_hal_never_reset_pin(&pin_GPIO44);
#endif /* DEBUG */
mp_import_stat_t stat_b = mp_import_stat("boot.py");
if (stat_b != MP_IMPORT_STAT_FILE) {
FATFS *fatfs = &((fs_user_mount_t *)MP_STATE_VM(vfs_mount_table)->obj)->fatfs;
FIL fs;
UINT char_written = 0;
const byte buffer[] = "#Serial port upload mode\nimport storage\nstorage.remount(\"/\", False)\nstorage.disable_usb_drive()\n";
// Create or modify existing boot.py file
f_open(fatfs, &fs, "/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
f_close(&fs);
// Delete code.Py, use main.py
mp_import_stat_t stat_c = mp_import_stat("code.py");
if (stat_c == MP_IMPORT_STAT_FILE) {
f_unlink(fatfs,"/code.py");
}
}
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}
void board_deinit(void) {
}

View File

@ -0,0 +1,32 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Micropython setup
#define MICROPY_HW_BOARD_NAME "MixGo CE"
#define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO45)

View File

@ -0,0 +1,23 @@
USB_VID = 0x303A
USB_PID = 0x80FD
USB_PRODUCT = "MixGo CE"
USB_MANUFACTURER = "Espressif"
IDF_TARGET = esp32s2
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
# The default queue depth of 16 overflows on release builds,
# so increase it to 32.
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=40m
CIRCUITPY_ESP_FLASH_SIZE=4MB
CIRCUITPY_MODULE=wroom
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
FROZEN_MPY_DIRS += boards/mixgo_ce_udisk/cp_lib/mixgoce_lib

View File

@ -0,0 +1,50 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) },
{ MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) },
{ MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) },
{ MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
{ MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
{ MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) },
{ MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) },
{ MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO45) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -0,0 +1,6 @@
# CONFIG_ESP32S2_SPIRAM_SUPPORT is not set
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# end of LWIP

View File

@ -0,0 +1,48 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
void board_init(void) {
// Debug UART
#ifdef DEBUG
common_hal_never_reset_pin(&pin_GPIO43);
common_hal_never_reset_pin(&pin_GPIO44);
#endif /* DEBUG */
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}
void board_deinit(void) {
}

@ -0,0 +1 @@
Subproject commit 8b6cd888b264abaf8f9b1904b09b01313b273bb2

View File

@ -0,0 +1,32 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Micropython setup
#define MICROPY_HW_BOARD_NAME "MixGo CE"
#define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO45)

View File

@ -0,0 +1,23 @@
USB_VID = 0x303A
USB_PID = 0x80FC
USB_PRODUCT = "MixGo CE"
USB_MANUFACTURER = "Espressif"
IDF_TARGET = esp32s2
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
# The default queue depth of 16 overflows on release builds,
# so increase it to 32.
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=40m
CIRCUITPY_ESP_FLASH_SIZE=4MB
CIRCUITPY_MODULE=wroom
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
FROZEN_MPY_DIRS += boards/$(BOARD)/cp_lib/mixgoce_lib

View File

@ -0,0 +1,50 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) },
{ MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) },
{ MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) },
{ MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
{ MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
{ MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) },
{ MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) },
{ MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO45) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -0,0 +1,6 @@
# CONFIG_ESP32S2_SPIRAM_SUPPORT is not set
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# end of LWIP

View File

@ -26,6 +26,7 @@
#include "shared-bindings/alarm/touch/TouchAlarm.h" #include "shared-bindings/alarm/touch/TouchAlarm.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "esp_sleep.h" #include "esp_sleep.h"
#include "peripherals/touch.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) { 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) { if (pin->touch_channel == TOUCH_PAD_MAX) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);
self->pin = pin; self->pin = pin;

View File

@ -51,7 +51,7 @@
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
if (pin->adc_index == 0 || pin->adc_channel == ADC_CHANNEL_MAX) { 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); common_hal_mcu_pin_claim(pin);
self->pin = 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) { } else if (self->pin->adc_index == ADC_UNIT_2) {
adc2_config_channel_atten((adc2_channel_t)self->pin->adc_channel, ATTENUATION); adc2_config_channel_atten((adc2_channel_t)self->pin->adc_channel, ATTENUATION);
} else { } else {
mp_raise_ValueError(translate("Invalid Pin")); raise_ValueError_invalid_pin();
} }
// Automatically select calibration process depending on status of efuse // Automatically select calibration process depending on status of efuse

View File

@ -49,7 +49,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
} else if (pin == &pin_GPIO18) { } else if (pin == &pin_GPIO18) {
self->channel = DAC_CHANNEL_2; self->channel = DAC_CHANNEL_2;
} else { } else {
mp_raise_ValueError(translate("Invalid DAC pin supplied")); raise_ValueError_invalid_pin();
} }
dac_output_enable(self->channel); dac_output_enable(self->channel);
#else #else

View File

@ -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. // 46 is also input-only so it'll never work.
if (scl->number == 45 || scl->number == 46 || sda->number == 45 || sda->number == 46) { 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 #if CIRCUITPY_REQUIRE_I2C_PULLUPS
@ -113,7 +113,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (err == ESP_FAIL) { if (err == ESP_FAIL) {
mp_raise_OSError(MP_EIO); mp_raise_OSError(MP_EIO);
} else { } else {
mp_raise_ValueError(translate("Invalid argument")); mp_raise_RuntimeError(translate("init I2C"));
} }
} }

View File

@ -28,6 +28,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/SPI.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "driver/spi_common_internal.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) { if (result == ESP_ERR_NO_MEM) {
mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed")); mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed"));
} else if (result == ESP_ERR_INVALID_ARG) { } 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); set_spi_config(self, 250000, 0, 0, 8);

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/UART.h" #include "shared-bindings/busio/UART.h"
#include "components/driver/include/driver/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, mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
bool sigint_enabled) { bool sigint_enabled) {
if (bits > 8) { mp_arg_validate_int_max(bits, 8, MP_QSTR_bytes);
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
}
bool have_tx = tx != NULL; bool have_tx = tx != NULL;
bool have_rx = rx != 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. // 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 || 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) { 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 // On the debug uart, enable pattern detection to look for CTRL+C
#ifdef CIRCUITPY_DEBUG_UART_RX #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; rts_num = rs485_dir->number;
} }
if (uart_set_pin(self->uart_num, tx_num, rx_num, rts_num, cts_num) != ESP_OK) { 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) { void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
if (baudrate > UART_BITRATE_MAX || if (baudrate > UART_BITRATE_MAX ||
uart_set_baudrate(self->uart_num, baudrate) != ESP_OK) { uart_set_baudrate(self->uart_num, baudrate) != ESP_OK) {
mp_raise_ValueError(translate("Unsupported baudrate")); mp_arg_error_invalid(MP_QSTR_baudrate);
} }
} }

View File

@ -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) { if (result == ESP_ERR_NO_MEM) {
mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed")); mp_raise_msg(&mp_type_MemoryError, translate("ESP-IDF memory allocation failed"));
} else if (result == ESP_ERR_INVALID_ARG) { } else if (result == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} else if (result != ESP_OK) { } else if (result != ESP_OK) {
mp_raise_OSError_msg_varg(translate("twai_driver_install returned esp-idf error #%d"), (int)result); mp_raise_OSError_msg_varg(translate("twai_driver_install returned esp-idf error #%d"), (int)result);
} }

View File

@ -130,9 +130,7 @@ static void init_timer(frequencyio_frequencyin_obj_t *self) {
void common_hal_frequencyio_frequencyin_construct(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) { const mcu_pin_obj_t *pin, const uint16_t capture_period) {
if ((capture_period == 0) || (capture_period > 500)) { mp_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
}
self->pin = pin->number; self->pin = pin->number;
self->handle = NULL; 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) { 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_arg_validate_int_range(capture_period, 1, 500, MP_QSTR_capture_period);
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
}
self->capture_period = capture_period; self->capture_period = capture_period;
common_hal_frequencyio_frequencyin_clear(self); common_hal_frequencyio_frequencyin_clear(self);
timer_set_alarm_value(self->timer.group, self->timer.idx, capture_period * 1000000); timer_set_alarm_value(self->timer.group, self->timer.idx, capture_period * 1000000);

View File

@ -30,6 +30,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "common-hal/i2cperipheral/I2CPeripheral.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, 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, 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. // support I2C on these pins.
// Also 46 is input-only so it'll never work. // Also 46 is input-only so it'll never work.
if (scl->number == 45 || scl->number == 46 || sda->number == 45 || sda->number == 46) { 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) { if (num_addresses > 1) {
@ -72,7 +73,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
if (err == ESP_FAIL) { if (err == ESP_FAIL) {
mp_raise_OSError(MP_EIO); mp_raise_OSError(MP_EIO);
} else { } else {
mp_raise_ValueError(translate("Invalid argument")); mp_arg_error_invalid(MP_QSTR_I2CPeripheral);
} }
} }

View File

@ -41,9 +41,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
const mcu_pin_obj_t *horizontal_reference) { const mcu_pin_obj_t *horizontal_reference) {
// only 8 bits is supported at present // only 8 bits is supported at present
if (data_count < 8 || data_count > 16) { mp_arg_validate_int_range(data_count, 8, 16, MP_QSTR_data_count);
mp_raise_ValueError_varg(translate("%q must be between %d and %d"), MP_QSTR_data_count, 8, 16);
}
// This will throw if unsuccessful. Everything following is guaranteed to succeed. // This will throw if unsuccessful. Everything following is guaranteed to succeed.
port_i2s_allocate_i2s0(); port_i2s_allocate_i2s0();

View File

@ -88,7 +88,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
uint16_t maxlen, bool idle_state) { uint16_t maxlen, bool idle_state) {
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false); self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
if (self->buffer == NULL) { 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->pin = pin;
self->maxlen = maxlen; self->maxlen = maxlen;

View File

@ -217,7 +217,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t fr
// Calculate duty cycle // Calculate duty cycle
uint32_t duty_bits = calculate_duty_cycle(frequency); uint32_t duty_bits = calculate_duty_cycle(frequency);
if (duty_bits == 0) { if (duty_bits == 0) {
mp_raise_ValueError(translate("Invalid PWM frequency")); mp_arg_error_invalid(MP_QSTR_frequency);
} }
self->duty_resolution = duty_bits; self->duty_resolution = duty_bits;
ledc_set_freq(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num, frequency); ledc_set_freq(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num, frequency);

View File

@ -48,5 +48,5 @@ int common_hal_rtc_get_calibration(void) {
} }
void common_hal_rtc_set_calibration(int calibration) { 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);
} }

View File

@ -28,6 +28,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "peripherals/touch.h" #include "peripherals/touch.h"
#include "shared-bindings/microcontroller/Pin.h"
static uint16_t get_raw_reading(touchio_touchin_obj_t *self) { static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
uint32_t touch_value; 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, void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
if (pin->touch_channel == TOUCH_PAD_MAX) { if (pin->touch_channel == TOUCH_PAD_MAX) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);

View File

@ -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; authmode = WIFI_AUTH_WPA_WPA2_PSK;
break; break;
default: default:
mp_raise_ValueError(translate("Invalid AuthMode")); mp_arg_error_invalid(MP_QSTR_authmode);
break; 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.channel = channel;
config->ap.authmode = authmode; config->ap.authmode = authmode;
if (max_connections < 0 || max_connections > 10) { mp_arg_validate_int_range(max_connections, 0, 10, MP_QSTR_max_connections);
mp_raise_ValueError(translate("max_connections must be between 0 and 10"));
}
config->ap.max_connection = max_connections; config->ap.max_connection = max_connections;
esp_wifi_set_config(WIFI_IF_AP, config); esp_wifi_set_config(WIFI_IF_AP, config);

View File

@ -42,7 +42,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
adc_config_t config = {0}; adc_config_t config = {0};
if (pin->adc == NULL) { if (pin->adc == NULL) {
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); raise_ValueError_invalid_pin();
} }
ADC_GetDefaultConfig(&config); ADC_GetDefaultConfig(&config);

View File

@ -32,7 +32,7 @@
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { 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) { bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {

View File

@ -138,7 +138,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
} }
if (self->sda == NULL || self->scl == NULL) { if (self->sda == NULL || self->scl == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} else { } else {
self->i2c = mcu_i2c_banks[self->sda->bank_idx - 1]; self->i2c = mcu_i2c_banks[self->sda->bank_idx - 1];
} }

View File

@ -168,7 +168,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
if (spi_taken) { if (spi_taken) {
mp_raise_ValueError(translate("Hardware busy, try alternative pins")); mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
} else { } else {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
} }

View File

@ -113,12 +113,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
bool sigint_enabled) { bool sigint_enabled) {
self->baudrate = baudrate; 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; 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); 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) { 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) { 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) { if (uart_taken) {
@ -236,7 +233,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
} }
} }
if ((rts != NULL) && (rts_config == NULL)) { 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) { 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) { if (!self->ringbuf) {
LPUART_Deinit(self->uart); 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); LPUART_TransferCreateHandle(self->uart, &self->handle, LPUART_UserCallback, self);

View File

@ -70,7 +70,7 @@ void common_hal_mcu_enable_interrupts(void) {
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
if (runmode == RUNMODE_BOOTLOADER) { if (runmode == RUNMODE_BOOTLOADER) {
if (!bootloader_available()) { 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 // Pretend to be the first of the two reset presses needed to enter the
// bootloader. That way one reset will end in the bootloader. // bootloader. That way one reset will end in the bootloader.

View File

@ -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); int pulse_count = calculate_pulse_count(frequency, &self->prescaler);
if (pulse_count == 0) { if (pulse_count == 0) {
mp_raise_ValueError(translate("Invalid PWM frequency")); mp_arg_error_invalid(MP_QSTR_frequency);
} }
self->pulse_count = pulse_count; self->pulse_count = pulse_count;

View File

@ -75,5 +75,5 @@ int common_hal_rtc_get_calibration(void) {
void common_hal_rtc_set_calibration(int calibration) { void common_hal_rtc_set_calibration(int calibration) {
// SNVS has HPCALB_VAL bits for 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);
} }

View File

@ -24,9 +24,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "shared-bindings/usb_host/Port.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/usb_host/Port.h"
#include "py/runtime.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; supported_dm = &pin_USB_OTG2_DN;
} }
if (dp != supported_dp || dm != supported_dm) { if (dp != supported_dp || dm != supported_dm) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
self->init = true; self->init = true;
usb_host_init = true; usb_host_init = true;

View File

@ -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) { 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) { 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) { if (pin->number >= NUMBER_OF_PINS) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
self->pin = pin; self->pin = pin;
self->value = value; self->value = value;

Some files were not shown because too many files have changed in this diff Show More