From 98610f901656d65221671e077438da89edecb7cd Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 23 Jul 2024 18:54:32 -0400 Subject: [PATCH 1/6] bleio_user_reset(): check if BLE running before doing any BLE ops --- ports/nordic/common-hal/_bleio/__init__.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ports/nordic/common-hal/_bleio/__init__.c b/ports/nordic/common-hal/_bleio/__init__.c index 705bc1453953..8c5a46d036e0 100644 --- a/ports/nordic/common-hal/_bleio/__init__.c +++ b/ports/nordic/common-hal/_bleio/__init__.c @@ -78,9 +78,11 @@ void common_hal_bleio_init(void) { } void bleio_user_reset() { - // Stop any user scanning or advertising. - common_hal_bleio_adapter_stop_scan(&common_hal_bleio_adapter_obj); - common_hal_bleio_adapter_stop_advertising(&common_hal_bleio_adapter_obj); + if (common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) { + // Stop any user scanning or advertising. + common_hal_bleio_adapter_stop_scan(&common_hal_bleio_adapter_obj); + common_hal_bleio_adapter_stop_advertising(&common_hal_bleio_adapter_obj); + } ble_drv_remove_heap_handlers(); From e398c1d7bc918956d0ab54e7b61b8505484b3aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brad=C3=A1n=20Lane?= Date: Wed, 24 Jul 2024 13:19:23 -0400 Subject: [PATCH 2/6] extend board driver support --- .../bradanlanestudio_explorer_rp2040/board.c | 64 +++++++++++++------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c index a886c949afce..a863c2b1228a 100644 --- a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c +++ b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c @@ -146,32 +146,33 @@ static int _set_vid(void) { vid_setting = value; /* Voltage Divider with 3.3V: (1241 * V) - 10K/ 15K = 1.98V = 2458 - 15K/ 10K = 1.32V = 1638 - 15K/4.7K = 0.79V = 980 - 15K/ 2K = 1.32V = 482 - 15K/ 1K = 1.32V = 256 + 10K/ 15K = 1.98V = 2458 GT 2000 = TBD + 15K/ 10K = 1.32V = 1638 GT 1200 = Explorer with SSD1681 BW + 15K/4.7K = 0.79V = 980 GT 600 = Explorer with SSD1681 BWR + 15K/ 2K = 0.39V = 482 GT 300 = Explorer with SSD1608 BW + 100K/ 10K = 0.30V = 372 ditto + 15K/ 1K = 0.21V = 256 GT 150 = DCNextGen with SSD1681 BWR Note: extreme values (using 100K or greater) will not create a strong enough current for the ADC to read accurately Note: we do not get a usable value when the voltage divider is missing */ // TODO change to min/max to tighten up the ranges (requires sampling of the initial boards) if (value > 2800) { - vid_setting = 9; + vid_setting = 9; // invalid } else if (value > 2000) { - vid_setting = 5; + vid_setting = 5; // future } else if (value > 1200) { - vid_setting = 4; + vid_setting = 4; // Explorer SSD1681 BW } else if (value > 600) { - vid_setting = 3; + vid_setting = 3; // Explorer SSD1681 BWR } else if (value > 300) { - vid_setting = 2; + vid_setting = 2; // Explorer SSD1608 BW } else if (value > 150) { - vid_setting = 1; + vid_setting = 1; // DCNextGen SSD1681 BWR } else { - vid_setting = 0; - } + vid_setting = 0; // invalid + } return vid_setting; } @@ -227,8 +228,29 @@ void board_init(void) { display = &allocate_display()->epaper_display; display->base.type = &epaperdisplay_epaperdisplay_type; - // VID codes: 1 = tricolor ePaper (BWR), 2 = monochrome ePaper (BW), other codes are TBD + // default to no rotation + int rotation = 0; if (vid_setting == 1) { + // DCNextGen SSD1681 BWR rotated 270 + rotation = 270; + } + + // default to BWR refresh rates + float refresh_time = 15.0; + float seconds_per_frame = 20.0; + if ((vid_setting == 2) || (vid_setting == 4)) { + // BW displays have faster refresh rates + refresh_time = 1.0; + seconds_per_frame = 5.0; + } + + // VID 1, 3, and 4 = SSD1681 display driver + // VID 2 = SSD1608 display driver + + // VID codes: see above + if ((vid_setting == 1) || // DCNextGen SSD1681 BWR rotated 270 + (vid_setting == 3) || // Explorer SSD1681 BW rotated 0 + (vid_setting == 4)) { // Explorer SSD1681 BWR rotated 0 common_hal_epaperdisplay_epaperdisplay_construct( display, bus, @@ -241,7 +263,7 @@ void board_init(void) { HEIGHT + 0x60, // ram_height RAM is actually only 200 bits high but we use 296 to match the 9 bits 0, // colstart 0, // rowstart - 270, // rotation + rotation, // rotation SSD_SET_RAMXPOS, // set_column_window_command SSD_SET_RAMYPOS, // set_row_window_command SSD_SET_RAMXCOUNT, // set_current_column_command @@ -252,16 +274,16 @@ void board_init(void) { false, // color_bits_inverted 0xFF0000, // highlight_color (RED for tri-color display) _refresh_sequence_ssd1681, sizeof(_refresh_sequence_ssd1681), // refresh_display_command - 15.0, // refresh_time + refresh_time, // refresh_time &pin_GPIO9, // DEFAULT_SPI_BUS_BUSY, // busy_pin true, // busy_state - 20.0, // seconds_per_frame (does not seem the user can change this) + seconds_per_frame, // seconds_per_frame (does not seem the user can change this) true, // always_toggle_chip_select false, // not grayscale false, // not acep false, // not two_byte_sequence_length true); // address_little_endian - } else if (vid_setting == 2) { + } else if (vid_setting == 2) { // Explorer SSD1608 BW common_hal_epaperdisplay_epaperdisplay_construct( display, bus, @@ -274,7 +296,7 @@ void board_init(void) { HEIGHT /* + 0x60 */, // ram_height RAM is actually only 200 bits high but we use 296 to match the 9 bits 0, // colstart 0, // rowstart - 0, // rotation + rotation, // rotation SSD_SET_RAMXPOS, // set_column_window_command SSD_SET_RAMYPOS, // set_row_window_command SSD_SET_RAMXCOUNT, // set_current_column_command @@ -285,10 +307,10 @@ void board_init(void) { false, // color_bits_inverted 0x000000, // highlight_color (RED for tri-color display) _refresh_sequence_ssd1608, sizeof(_refresh_sequence_ssd1608), // refresh_display_command - 1.0, // refresh_time + refresh_time, // refresh_time &pin_GPIO9, // DEFAULT_SPI_BUS_BUSY, // busy_pin true, // busy_state - 5.0, // seconds_per_frame (does not seem the user can change this) + seconds_per_frame, // seconds_per_frame (does not seem the user can change this) true, // always_toggle_chip_select false, // not grayscale false, // not acep From 5811f75a526891b6a15c0a8e33835d3e08f98169 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 23 Jul 2024 10:38:58 -0500 Subject: [PATCH 3/6] Warn on use of nonstandard sys.format_exception --- py/modsys.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/py/modsys.c b/py/modsys.c index f53e5e595a9d..3ea57ee9a5d8 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -39,6 +39,11 @@ #include "extmod/modplatform.h" #include "genhdr/mpversion.h" +// CIRCUITPY-CHANGE +#if CIRCUITPY_WARNINGS +#include "shared-module/warnings/__init__.h" +#endif + #if MICROPY_PY_SYS_SETTRACE #include "py/objmodule.h" #include "py/profile.h" @@ -134,6 +139,11 @@ STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { + // CIRCUITPY-CHANGE + #if CIRCUITPY_WARNINGS + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_print_exception, MP_QSTR_sys, MP_QSTR_traceback); + #endif + #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES void *stream_obj = &mp_sys_stdout_obj; if (n_args > 1) { From a60ad7b4650a577fbb6fb3017efdc7d029492f96 Mon Sep 17 00:00:00 2001 From: vickash Date: Thu, 25 Jul 2024 10:49:12 -0400 Subject: [PATCH 4/6] espressif: enable PCNT accumulator for Counter, FrequencyIn, IncrementalEncoder --- ports/espressif/common-hal/countio/Counter.c | 8 ++++++-- ports/espressif/common-hal/frequencyio/FrequencyIn.c | 8 ++++++-- ports/espressif/common-hal/rotaryio/IncrementalEncoder.c | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ports/espressif/common-hal/countio/Counter.c b/ports/espressif/common-hal/countio/Counter.c index 3297296e6a45..4c1857c4db6a 100644 --- a/ports/espressif/common-hal/countio/Counter.c +++ b/ports/espressif/common-hal/countio/Counter.c @@ -20,14 +20,18 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self, pcnt_unit_config_t unit_config = { // Set counter limit - .low_limit = -1, + .low_limit = INT16_MIN, .high_limit = INT16_MAX }; - // The pulse count driver automatically counts roll overs. + // Enable PCNT internal accumulator to count overflows. unit_config.flags.accum_count = true; // initialize PCNT CHECK_ESP_RESULT(pcnt_new_unit(&unit_config, &self->unit)); + + // Set watchpoints at limis, to auto-accumulate overflows. + pcnt_unit_add_watch_point(self->unit, INT16_MIN); + pcnt_unit_add_watch_point(self->unit, INT16_MAX); self->pin = pin->number; pcnt_chan_config_t channel_config = { diff --git a/ports/espressif/common-hal/frequencyio/FrequencyIn.c b/ports/espressif/common-hal/frequencyio/FrequencyIn.c index f65bfeee1daf..603ca5c9f9bc 100644 --- a/ports/espressif/common-hal/frequencyio/FrequencyIn.c +++ b/ports/espressif/common-hal/frequencyio/FrequencyIn.c @@ -30,10 +30,10 @@ static IRAM_ATTR bool timer_interrupt_handler(gptimer_handle_t timer, static esp_err_t init_pcnt(frequencyio_frequencyin_obj_t *self) { pcnt_unit_config_t unit_config = { // Set counter limit - .low_limit = -INT16_MAX + 1, + .low_limit = INT16_MIN, .high_limit = INT16_MAX }; - // The pulse count driver automatically counts roll overs. + // Enable PCNT internal accumulator to count overflows. unit_config.flags.accum_count = true; // initialize PCNT @@ -41,6 +41,10 @@ static esp_err_t init_pcnt(frequencyio_frequencyin_obj_t *self) { if (result != ESP_OK) { return result; } + + // Set watchpoints at limis, to auto-accumulate overflows. + pcnt_unit_add_watch_point(self->unit, INT16_MIN); + pcnt_unit_add_watch_point(self->unit, INT16_MAX); pcnt_chan_config_t channel_config = { .edge_gpio_num = self->pin, diff --git a/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c b/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c index c8d1556fc68b..ba8b70221b72 100644 --- a/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -23,15 +23,19 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode // in CircuitPython. pcnt_unit_config_t unit_config = { // Set counter limit - .low_limit = -INT16_MAX, + .low_limit = INT16_MIN, .high_limit = INT16_MAX }; - // The pulse count driver automatically counts roll overs. + // Enable PCNT internal accumulator to count overflows. unit_config.flags.accum_count = true; // initialize PCNT CHECK_ESP_RESULT(pcnt_new_unit(&unit_config, &self->unit)); + // Set watchpoints at limits, to auto-accumulate overflows. + pcnt_unit_add_watch_point(self->unit, INT16_MIN); + pcnt_unit_add_watch_point(self->unit, INT16_MAX); + pcnt_chan_config_t channel_a_config = { .edge_gpio_num = pin_a->number, .level_gpio_num = pin_b->number From 3e4495769d7e6b5421f56b8cb5792193f314a077 Mon Sep 17 00:00:00 2001 From: vickash Date: Thu, 25 Jul 2024 11:09:44 -0400 Subject: [PATCH 5/6] Fix whitespace and dereference error in espressif FrequencyIn --- ports/espressif/common-hal/countio/Counter.c | 2 +- ports/espressif/common-hal/frequencyio/FrequencyIn.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/espressif/common-hal/countio/Counter.c b/ports/espressif/common-hal/countio/Counter.c index 4c1857c4db6a..e754017ac3d9 100644 --- a/ports/espressif/common-hal/countio/Counter.c +++ b/ports/espressif/common-hal/countio/Counter.c @@ -28,7 +28,7 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self, // initialize PCNT CHECK_ESP_RESULT(pcnt_new_unit(&unit_config, &self->unit)); - + // Set watchpoints at limis, to auto-accumulate overflows. pcnt_unit_add_watch_point(self->unit, INT16_MIN); pcnt_unit_add_watch_point(self->unit, INT16_MAX); diff --git a/ports/espressif/common-hal/frequencyio/FrequencyIn.c b/ports/espressif/common-hal/frequencyio/FrequencyIn.c index 603ca5c9f9bc..966443485048 100644 --- a/ports/espressif/common-hal/frequencyio/FrequencyIn.c +++ b/ports/espressif/common-hal/frequencyio/FrequencyIn.c @@ -41,10 +41,10 @@ static esp_err_t init_pcnt(frequencyio_frequencyin_obj_t *self) { if (result != ESP_OK) { return result; } - + // Set watchpoints at limis, to auto-accumulate overflows. - pcnt_unit_add_watch_point(self->unit, INT16_MIN); - pcnt_unit_add_watch_point(self->unit, INT16_MAX); + pcnt_unit_add_watch_point(self->internal_data->unit, INT16_MIN); + pcnt_unit_add_watch_point(self->internal_data->unit, INT16_MAX); pcnt_chan_config_t channel_config = { .edge_gpio_num = self->pin, From a05584281e957bea7579785750d8c0cabdff5800 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 26 Jul 2024 10:14:17 -0500 Subject: [PATCH 6/6] Only use pyi files for autoapi doc generation Closes #9465 --- conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conf.py b/conf.py index 7a6701595044..7120fa3f00a3 100644 --- a/conf.py +++ b/conf.py @@ -110,6 +110,7 @@ autoapi_python_class_content = "both" autoapi_python_use_implicit_namespaces = True autoapi_root = "shared-bindings" +autoapi_file_patterns = ["*.pyi"] # Suppress cache warnings to prevent "unpickable" [sic] warning # about autoapi_prepare_jinja_env() from sphinx >= 7.3.0.