Merge remote-tracking branch 'adafruit/main' into add-os-utime-function

This commit is contained in:
Dan Halbert 2022-10-10 17:51:59 -04:00
commit 4cd370ecf8
23 changed files with 89 additions and 50 deletions

View File

@ -60,6 +60,11 @@ msgstr ""
msgid "%%c requires int or char"
msgstr ""
#: main.c
#, c-format
msgid "%02X"
msgstr ""
#: shared-bindings/rgbmatrix/RGBMatrix.c
#, c-format
msgid ""
@ -2077,6 +2082,10 @@ msgstr ""
msgid "UART write"
msgstr ""
#: main.c
msgid "UID:"
msgstr ""
#: shared-module/usb_hid/Device.c
msgid "USB busy"
msgstr ""

6
main.c
View File

@ -779,9 +779,9 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
common_hal_mcu_processor_get_uid(raw_id);
mp_printf(&mp_plat_print, "UID:");
for (uint8_t i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
mp_printf(&mp_plat_print, "%02X", raw_id[i]);
mp_cprintf(&mp_plat_print, translate("UID:"));
for (size_t i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
mp_cprintf(&mp_plat_print, translate("%02X"), raw_id[i]);
}
mp_printf(&mp_plat_print, "\n");
port_boot_info();

View File

@ -125,8 +125,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
// exact cutoff, but no frequency well under 100kHz is available)
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_arg_error_invalid(MP_QSTR_frequency);
}

View File

@ -165,7 +165,7 @@ void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint
esp_wifi_set_mac(ESP_IF_WIFI_AP, mac);
}
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, uint8_t start_channel, uint8_t stop_channel) {
if (self->current_scan != NULL) {
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
}
@ -177,9 +177,12 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
scan->base.type = &wifi_scannednetworks_type;
self->current_scan = scan;
scan->start_channel = 1;
scan->end_channel = 11;
scan->current_channel_index = 0;
scan->start_channel = start_channel;
scan->end_channel = stop_channel;
scan->radio_event_group = self->event_group_handle;
scan->done = false;
scan->channel_scan_in_progress = false;
wifi_scannednetworks_scan_next_channel(scan);
return scan;
}

View File

@ -72,7 +72,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
return mp_const_none;
}
// If we are scanning, wait and then load them.
if (self->scanning) {
if (self->channel_scan_in_progress) {
// We may have to scan more than one channel to get a result.
while (!self->done) {
if (!wifi_scannednetworks_wait_for_scan(self)) {
@ -81,7 +81,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
}
esp_wifi_scan_get_ap_num(&self->total_results);
self->scanning = false;
self->channel_scan_in_progress = false;
if (self->total_results > 0) {
break;
}
@ -112,7 +112,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
}
}
esp_wifi_scan_get_ap_records(&self->total_results, self->results);
self->scanning = false;
self->channel_scan_in_progress = false;
}
wifi_network_obj_t *entry = m_new_obj(wifi_network_obj_t);
@ -132,40 +132,49 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
}
// We don't do a linear scan so that we look at a variety of spectrum up front.
static uint8_t scan_pattern[] = {6, 1, 11, 3, 9, 13, 2, 4, 8, 12, 5, 7, 10, 14};
static uint8_t scan_pattern[] = {6, 1, 11, 3, 9, 13, 2, 4, 8, 12, 5, 7, 10, 14, 0};
void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) {
uint8_t next_channel = sizeof(scan_pattern);
// There is no channel 0, so use that as a flag to indicate we've run out of channels to scan.
uint8_t next_channel = 0;
while (self->current_channel_index < sizeof(scan_pattern)) {
next_channel = scan_pattern[self->current_channel_index];
self->current_channel_index++;
// Scan only channels that are in the specified range.
if (self->start_channel <= next_channel && next_channel <= self->end_channel) {
break;
}
}
wifi_scan_config_t config = { 0 };
config.channel = next_channel;
if (next_channel == sizeof(scan_pattern)) {
if (next_channel == 0) {
wifi_scannednetworks_done(self);
} else {
esp_err_t result = esp_wifi_scan_start(&config, false);
if (result != ESP_OK) {
wifi_scannednetworks_done(self);
} else {
self->scanning = true;
self->channel_scan_in_progress = true;
}
}
}
void wifi_scannednetworks_deinit(wifi_scannednetworks_obj_t *self) {
// if a scan is active, make sure and clean up the idf's buffer of results.
if (self->scanning) {
if (self->channel_scan_in_progress) {
esp_wifi_scan_stop();
if (wifi_scannednetworks_wait_for_scan(self)) {
// Ignore the number of records since we're throwing them away.
uint16_t number = 0;
esp_wifi_scan_get_ap_records(&number, NULL);
self->scanning = false;
// Discard the scanned records, one at a time, to avoid memory leaks.
uint16_t number;
do {
number = 1;
wifi_ap_record_t record;
esp_wifi_scan_get_ap_records(&number, &record);
} while (number > 0);
// TODO: available in ESP-IDF v5.0; do instead of the above.
// Discard scan results.
// esp_wifi_clear_ap_list();
self->channel_scan_in_progress = false;
}
}
wifi_scannednetworks_done(self);

View File

@ -53,7 +53,7 @@ typedef struct {
uint8_t end_channel; // Inclusive
bool done;
bool scanning;
bool channel_scan_in_progress;
} wifi_scannednetworks_obj_t;
void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self);

View File

@ -172,7 +172,7 @@ void common_hal_wifi_init(bool user_initiated) {
// Even though we just called esp_netif_create_default_wifi_sta,
// station mode isn't actually ready for use until esp_wifi_set_mode()
// is called and the configuration is loaded via esp_wifi_set_config().
// Set both convienence flags to false so it's not forgotten.
// Set both convenience flags to false so it's not forgotten.
self->sta_mode = 0;
self->ap_mode = 0;

@ -1 +1 @@
Subproject commit d51f7d882187afa4b39c2613fd0fe2ac2fea1145
Subproject commit 716d8531d71b122975e2966a24ec7613b87eb7b0

View File

@ -65,7 +65,7 @@ INC_CYW43 := \
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
-isystem sdk/src/rp2_common/pico_lwip/include/ \
CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DCYW43_LOGIC_DEBUG=0
CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DIGNORE_GPIO24 -DCYW43_LOGIC_DEBUG=0
SRC_SDK_CYW43 := \
src/common/pico_sync/sem.c \
src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \

View File

@ -28,13 +28,10 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_CYW1) },
{ MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_CYW1) },
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) },
{ MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) },
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) },
{ MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) },
@ -47,8 +44,5 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -176,7 +176,9 @@ const mp_rom_map_elem_t mcu_pin_global_dict_table[TOTAL_GPIO_COUNT] = {
#if !defined(IGNORE_GPIO23)
{ MP_ROM_QSTR(MP_QSTR_GPIO23), MP_ROM_PTR(&pin_GPIO23) },
#endif
#if !defined(IGNORE_GPIO24)
{ MP_ROM_QSTR(MP_QSTR_GPIO24), MP_ROM_PTR(&pin_GPIO24) },
#endif
#if !defined(IGNORE_GPIO25)
{ MP_ROM_QSTR(MP_QSTR_GPIO25), MP_ROM_PTR(&pin_GPIO25) },
#endif
@ -187,6 +189,7 @@ const mp_rom_map_elem_t mcu_pin_global_dict_table[TOTAL_GPIO_COUNT] = {
#if CIRCUITPY_CYW43
{ MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) },
{ MP_ROM_QSTR(MP_QSTR_CYW1), MP_ROM_PTR(&pin_CYW1) },
{ MP_ROM_QSTR(MP_QSTR_CYW2), MP_ROM_PTR(&pin_CYW2) },
#endif
};
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);

View File

@ -131,7 +131,8 @@ void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint
ro_attribute(MP_QSTR_mac_address_ap);
}
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, uint8_t start_channel, uint8_t stop_channel) {
// channel bounds are ignored; not implemented in driver
if (self->current_scan) {
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
}

View File

@ -64,8 +64,12 @@ PIN(19);
PIN(20);
PIN(21);
PIN(22);
#if !defined(IGNORE_GPIO23)
PIN(23);
#endif
#if !defined(IGNORE_GPIO24)
PIN(24);
#endif
#if !defined(IGNORE_GPIO25)
PIN(25);
#endif
@ -76,4 +80,5 @@ PIN(29);
#if CIRCUITPY_CYW43
CYW_PIN(0);
CYW_PIN(1);
CYW_PIN(2);
#endif

View File

@ -73,6 +73,7 @@ extern const mcu_pin_obj_t pin_GPIO29;
#if CIRCUITPY_CYW43
extern const mcu_pin_obj_t pin_CYW0;
extern const mcu_pin_obj_t pin_CYW1;
extern const mcu_pin_obj_t pin_CYW2;
#endif
#endif // MICROPY_INCLUDED_RASPBERRYPI_PERIPHERALS_PINS_H

View File

@ -759,7 +759,6 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_KeyError), MP_ROM_PTR(&mp_type_KeyError) },
{ MP_ROM_QSTR(MP_QSTR_LookupError), MP_ROM_PTR(&mp_type_LookupError) },
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_MemoryError) },
{ MP_ROM_QSTR(MP_QSTR_MpyError), MP_ROM_PTR(&mp_type_MpyError) },
{ MP_ROM_QSTR(MP_QSTR_NameError), MP_ROM_PTR(&mp_type_NameError) },
{ MP_ROM_QSTR(MP_QSTR_NotImplementedError), MP_ROM_PTR(&mp_type_NotImplementedError) },
{ MP_ROM_QSTR(MP_QSTR_OSError), MP_ROM_PTR(&mp_type_OSError) },

View File

@ -742,7 +742,6 @@ extern const mp_obj_type_t mp_type_ReloadException;
extern const mp_obj_type_t mp_type_KeyError;
extern const mp_obj_type_t mp_type_LookupError;
extern const mp_obj_type_t mp_type_MemoryError;
extern const mp_obj_type_t mp_type_MpyError;
extern const mp_obj_type_t mp_type_NameError;
extern const mp_obj_type_t mp_type_NotImplementedError;
extern const mp_obj_type_t mp_type_OSError;

View File

@ -347,7 +347,6 @@ MP_DEFINE_EXCEPTION(UnicodeError, ValueError)
#if CIRCUITPY_ALARM
MP_DEFINE_EXCEPTION(DeepSleepRequest, BaseException)
#endif
MP_DEFINE_EXCEPTION(MpyError, ValueError)
/*
MP_DEFINE_EXCEPTION(Warning, Exception)
MP_DEFINE_EXCEPTION(DeprecationWarning, Warning)

View File

@ -582,7 +582,7 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
|| MPY_FEATURE_DECODE_FLAGS(header[2]) != MPY_FEATURE_FLAGS
|| header[3] > mp_small_int_bits()
|| read_uint(reader, NULL) > QSTR_WINDOW_SIZE) {
mp_raise_MpyError(MP_ERROR_TEXT("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info."));
mp_raise_ValueError(MP_ERROR_TEXT("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info."));
}
if (MPY_FEATURE_DECODE_ARCH(header[2]) != MP_NATIVE_ARCH_NONE) {
byte arch = MPY_FEATURE_DECODE_ARCH(header[2]);

View File

@ -1742,10 +1742,6 @@ NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) {
va_end(argptr);
}
NORETURN void mp_raise_MpyError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_MpyError, msg);
}
NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg) {
nlr_raise(mp_obj_new_exception_arg1(exc_type, arg));
}

View File

@ -225,7 +225,6 @@ NORETURN void mp_raise_BrokenPipeError(void);
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_MpyError(const compressed_string_t *msg);
NORETURN void mp_raise_recursion_depth(void);
#endif

View File

@ -216,14 +216,38 @@ MP_PROPERTY_GETSET(wifi_radio_mac_address_ap_obj,
//| def start_scanning_networks(
//| self, *, start_channel: int = 1, stop_channel: int = 11
//| ) -> Iterable[Network]:
//| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country."""
//| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country.
//|
//| .. note::
//|
//| In the raspberrypi port (RP2040 CYW43), ``start_channel`` and ``stop_channel`` are ignored.
//| """
//| ...
STATIC mp_obj_t wifi_radio_start_scanning_networks(mp_obj_t self_in) {
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
STATIC mp_obj_t wifi_radio_start_scanning_networks(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_start_channel, ARG_stop_channel };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_start_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_stop_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 11} },
};
return common_hal_wifi_radio_start_scanning_networks(self);
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
uint8_t start_channel =
(uint8_t)mp_arg_validate_int_range(args[ARG_start_channel].u_int, 1, 14, MP_QSTR_start_channel);
uint8_t stop_channel =
(uint8_t)mp_arg_validate_int_range(args[ARG_stop_channel].u_int, 1, 14, MP_QSTR_stop_channel);
// Swap if in reverse order, without complaining.
if (start_channel > stop_channel) {
uint8_t temp = stop_channel;
stop_channel = start_channel;
start_channel = temp;
}
return common_hal_wifi_radio_start_scanning_networks(self, start_channel, stop_channel);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_scanning_networks_obj, wifi_radio_start_scanning_networks);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_scanning_networks_obj, 1, wifi_radio_start_scanning_networks);
//| def stop_scanning_networks(self) -> None:
//| """Stop scanning for Wifi networks and free any resources used to do it."""

View File

@ -85,7 +85,7 @@ extern void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, con
extern mp_float_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const mp_float_t power);
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, uint8_t start_channel, uint8_t stop_channel);
extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self);

View File

@ -1,4 +1,4 @@
mod0 RuntimeError Corrupt .mpy file
mod1 RuntimeError Corrupt .mpy file
mod2 MpyError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.
mod3 MpyError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.
mod2 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.
mod3 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.