diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95bc80657212c..f7e7956498d68 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,19 +4,33 @@ # CIRCUITPY-CHANGE: CircuitPython-specific. +# Note that by default, pre-commit hooks do not look inside submodules. +# So you don't need to exclude submodules explicitly here. + repos: -- repo: https://github.com/pre-commit/pre-commit-hooks + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/mimxrt10xx/sdk|ports/raspberrypi/sdk|lib/tinyusb)' - - id: trailing-whitespace - exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|lib/mbedtls_errors/generate_errors.diff|ports/raspberrypi/sdk|ports/mimxrt10xx/sdk|lib/tinyusb)' -- repo: https://github.com/codespell-project/codespell + - id: check-yaml + - id: end-of-file-fixer + exclude: | + (?x)^( + tests/.*\.exp| + tests/cmdline/.*| + tests/.*/data/.* + ) + - id: trailing-whitespace + exclude: | + (?x)^( + tests/.*\.exp| + tests/cmdline/.*| + tests/.*/data/.*| + lib/mbedtls_errors/generate_errors.diff + ) + - repo: https://github.com/codespell-project/codespell rev: v2.2.4 hooks: - - id: codespell + - id: codespell args: [-w] exclude: | (?x)^( @@ -25,38 +39,30 @@ repos: tests/unicode/data/utf-8_invalid.txt| tests/extmod/data/qr.pgm| tests/basics/bytearray_byte_operations.py| - ports/raspberrypi/sdk| ports/zephyr-cp/cptools/compat2driver.py ) -- repo: local + - repo: local hooks: - - id: translations + - id: translations name: Translations entry: sh -c "if ! make check-translate; then make translate; fi" types: [c] pass_filenames: false language: system - - id: formatting + - id: formatting name: Formatting - entry: python3 tools/codeformat.py - types: [c] - language: system - exclude: | - (?x)^( - lib/tinyusb| - ports/raspberrypi/sdk - ) -- repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.9.4 - hooks: - # Run the linter. - - id: ruff - args: [ --fix ] - # Run the formatter. - - id: ruff-format -- repo: https://github.com/tox-dev/pyproject-fmt - rev: "v2.5.0" - hooks: - - id: pyproject-fmt - exclude: '^(ports/mimxrt10xx/sdk)' + entry: python3 tools/codeformat.py -v -c + language: python + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.9.4 + hooks: + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format + - repo: https://github.com/tox-dev/pyproject-fmt + rev: "v2.5.0" + hooks: + - id: pyproject-fmt diff --git a/main.c b/main.c index c9c7acb11f7ba..0ea389635f40f 100644 --- a/main.c +++ b/main.c @@ -131,9 +131,9 @@ static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, siz *final_size = default_size; #if CIRCUITPY_OS_GETENV if (safe_mode == SAFE_MODE_NONE) { - (void)common_hal_os_getenv_int(env_key, (mp_int_t *)final_size); - if (*final_size < 0) { - *final_size = default_size; + mp_int_t size; + if (common_hal_os_getenv_int(env_key, &size) == GETENV_OK && size > 0) { + *final_size = size; } } #endif diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 032ebe9f628a7..3ad2e162ecf3c 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -85,6 +85,7 @@ void board_init(void) { false, // chip_select (don't always toggle chip select) false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index d9078a7470902..f7af5e292a719 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -79,6 +79,9 @@ static void ramp_value(uint16_t start, uint16_t end) { // Caller validates that pins are free. void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) { + + // The case of left_channel == right_channel is already disallowed in shared-bindings. + #ifdef SAM_D5X_E5X bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK); #endif @@ -107,10 +110,6 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) { raise_ValueError_invalid_pin_name(MP_QSTR_right_channel); } - if (right_channel == left_channel) { - mp_raise_ValueError_varg(MP_ERROR_TEXT("%q and %q must be different"), - MP_QSTR_left_channel, MP_QSTR_right_channel); - } claim_pin(left_channel); if (right_channel != NULL) { claim_pin(right_channel); diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 321a5a1f2c7a0..430079a94dad2 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -141,6 +141,7 @@ void board_init(void) { false, // always_toggle_chip_select true, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index 4567e2c595627..88150dd401b97 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -96,6 +96,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/espressif/boards/heltec_vision_master_e290/board.c b/ports/espressif/boards/heltec_vision_master_e290/board.c index cc8afe226be95..e392f65a76432 100644 --- a/ports/espressif/boards/heltec_vision_master_e290/board.c +++ b/ports/espressif/boards/heltec_vision_master_e290/board.c @@ -94,6 +94,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length true); // address_little_endian } diff --git a/ports/espressif/boards/heltec_wireless_paper/board.c b/ports/espressif/boards/heltec_wireless_paper/board.c index 2807f2d1a2012..28fb6ae41b9a1 100644 --- a/ports/espressif/boards/heltec_wireless_paper/board.c +++ b/ports/espressif/boards/heltec_wireless_paper/board.c @@ -134,6 +134,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/espressif/boards/m5stack_m5paper/board.c b/ports/espressif/boards/m5stack_m5paper/board.c index fbf66fa5ccdf9..db68df79c4291 100644 --- a/ports/espressif/boards/m5stack_m5paper/board.c +++ b/ports/espressif/boards/m5stack_m5paper/board.c @@ -74,6 +74,7 @@ void board_init(void) { // false, // always_toggle_chip_select // false, // grayscale // true, // acep + // false, // spectra6 // false, // two_byte_sequence_length // false // address_little_endian // ); diff --git a/ports/espressif/boards/sqfmi_watchy/board.c b/ports/espressif/boards/sqfmi_watchy/board.c index 25a7be4613c6e..393b8b759028a 100644 --- a/ports/espressif/boards/sqfmi_watchy/board.c +++ b/ports/espressif/boards/sqfmi_watchy/board.c @@ -190,6 +190,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length true // address_little_endian ); diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h index 78a0d9b5221f1..322acaf84b8b3 100644 --- a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h @@ -12,6 +12,7 @@ #define MICROPY_HW_MCU_NAME "ESP32-C6FH4" #define MICROPY_HW_NEOPIXEL (&pin_GPIO8) +#define MICROPY_HW_NEOPIXEL_ORDER_GRB (1) // I2C #define CIRCUITPY_BOARD_I2C (1) diff --git a/ports/espressif/common-hal/audiobusio/__init__.c b/ports/espressif/common-hal/audiobusio/__init__.c index 226e371c5b0b0..d07a0b521ba9b 100644 --- a/ports/espressif/common-hal/audiobusio/__init__.c +++ b/ports/espressif/common-hal/audiobusio/__init__.c @@ -184,7 +184,7 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) { self->next_buffer_size = sizeof(starting_frame); i2s_fill_buffer(self); i2s_channel_preload_data(self->handle, &starting_frame, sizeof(uint32_t), &bytes_loaded); - preloaded += 1; + preloaded += bytes_loaded; } // enable the channel diff --git a/ports/espressif/common-hal/audioio/AudioOut.c b/ports/espressif/common-hal/audioio/AudioOut.c index 8322bc3799850..6d829228e1555 100644 --- a/ports/espressif/common-hal/audioio/AudioOut.c +++ b/ports/espressif/common-hal/audioio/AudioOut.c @@ -11,7 +11,6 @@ #include "driver/dac_continuous.h" - #if defined(CONFIG_IDF_TARGET_ESP32) #define pin_CHANNEL_0 pin_GPIO25 #define pin_CHANNEL_1 pin_GPIO26 @@ -304,6 +303,32 @@ static audioout_sample_convert_func_t audioout_get_samples_convert_func( } } +static void audioio_audioout_start(audioio_audioout_obj_t *self) { + esp_err_t ret; + + self->playing = true; + self->paused = false; + + ret = dac_continuous_start_async_writing(self->handle); + if (ret != ESP_OK) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio")); + } +} + +static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) { + dac_continuous_stop_async_writing(self->handle); + if (full_stop) { + self->get_buffer_index = 0; + self->put_buffer_index = 0; + self->sample_buffer = NULL; + self->sample = NULL; + self->playing = false; + self->paused = false; + } else { + self->paused = true; + } +} + static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { if (!self->playing) { return false; @@ -342,7 +367,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { &raw_sample_buf, &raw_sample_buf_size); if (get_buffer_result == GET_BUFFER_ERROR) { - common_hal_audioio_audioout_stop(self); + audioio_audioout_stop(self, true); return false; } @@ -390,7 +415,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { } else { // TODO: figure out if it is ok to call this here or do we need // to somehow wait for all of the samples to be flushed - common_hal_audioio_audioout_stop(self); + audioio_audioout_stop(self, true); return false; } } @@ -492,11 +517,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, self->paused = false; self->freq_hz = DEFAULT_SAMPLE_RATE; - /* espressif has two dac channels and it can support true stereo or - * outputting the same signal to both channels (dual mono). - * if different pins are supplied for left and right then use true stereo. - * if the same pin is supplied for left and right then use dual mono. - */ + // The case of left_channel == right_channel is already disallowed in shared-bindings. + if ((left_channel_pin == &pin_CHANNEL_0 && right_channel_pin == &pin_CHANNEL_1) || (left_channel_pin == &pin_CHANNEL_1 && @@ -504,12 +526,6 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, self->channel_mask = DAC_CHANNEL_MASK_ALL; self->num_channels = 2; self->channel_mode = DAC_CHANNEL_MODE_ALTER; - } else if ((left_channel_pin == &pin_CHANNEL_0 || - left_channel_pin == &pin_CHANNEL_1) && - right_channel_pin == left_channel_pin) { - self->channel_mask = DAC_CHANNEL_MASK_ALL; - self->num_channels = 1; - self->channel_mode = DAC_CHANNEL_MODE_SIMUL; } else if (left_channel_pin == &pin_CHANNEL_0 && right_channel_pin == NULL) { self->channel_mask = DAC_CHANNEL_MASK_CH0; @@ -550,32 +566,6 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) { _active_handle = NULL; } -static void audioio_audioout_start(audioio_audioout_obj_t *self) { - esp_err_t ret; - - self->playing = true; - self->paused = false; - - ret = dac_continuous_start_async_writing(self->handle); - if (ret != ESP_OK) { - mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio")); - } -} - -static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) { - dac_continuous_stop_async_writing(self->handle); - if (full_stop) { - self->get_buffer_index = 0; - self->put_buffer_index = 0; - self->sample_buffer = NULL; - self->sample = NULL; - self->playing = false; - self->paused = false; - } else { - self->paused = true; - } -} - void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, mp_obj_t sample, bool loop) { @@ -597,7 +587,11 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, self->looping = loop; freq_hz = audiosample_get_sample_rate(self->sample); - if (freq_hz != self->freq_hz) { + // Workaround: always reset the DAC completely between plays, + // due to a bug that causes the left and right channels to be swapped randomly. + // See https://github.com/espressif/esp-idf/issues/11425 + // TODO: Remove the `true` when this issue is fixed. + if (true || freq_hz != self->freq_hz) { common_hal_audioio_audioout_deinit(self); self->freq_hz = freq_hz; audioout_init(self); diff --git a/ports/espressif/common-hal/pulseio/PulseIn.c b/ports/espressif/common-hal/pulseio/PulseIn.c index cf24b42a052f1..79d003a8a1e87 100644 --- a/ports/espressif/common-hal/pulseio/PulseIn.c +++ b/ports/espressif/common-hal/pulseio/PulseIn.c @@ -127,6 +127,9 @@ bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { } void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { + if (common_hal_pulseio_pulsein_deinited(self)) { + return; + } rmt_disable(self->channel); reset_pin_number(self->pin->number); rmt_del_channel(self->channel); diff --git a/ports/espressif/common-hal/pulseio/PulseOut.c b/ports/espressif/common-hal/pulseio/PulseOut.c index b76c84385596c..68cb64b5e60e1 100644 --- a/ports/espressif/common-hal/pulseio/PulseOut.c +++ b/ports/espressif/common-hal/pulseio/PulseOut.c @@ -54,6 +54,9 @@ bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) { } void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) { + if (common_hal_pulseio_pulseout_deinited(self)) { + return; + } rmt_disable(self->channel); rmt_del_encoder(self->encoder); rmt_del_channel(self->channel); diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index cb58e90352440..9b582fce83ced 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -12,6 +12,7 @@ HAL_DIR=hal/$(MCU_SERIES) ifeq ($(CIRCUITPY_CYW43),1) INC_CYW43 := \ + -isystem lib/cyw43-driver \ -isystem lib/cyw43-driver/firmware \ -isystem lib/cyw43-driver/src \ -isystem lib/lwip/src/include \ @@ -92,8 +93,6 @@ INC += \ -I../shared/timeutils \ -Iboards/$(BOARD) \ -Iboards/ \ - -isystem ./../../lib/cmsis/inc \ - -isystem sdk/ \ -isystem sdk/src/common/boot_picobin_headers/include/ \ -isystem sdk/src/common/boot_picoboot_headers/include/ \ -isystem sdk/src/common/hardware_claim/include/ \ @@ -107,6 +106,8 @@ INC += \ -isystem sdk/src/$(CHIP_VARIANT_LOWER)/hardware_structs/include/ \ -isystem sdk/src/$(CHIP_VARIANT_LOWER)/pico_platform/include/ \ -isystem sdk/src/rp2_common/boot_bootrom_headers/include/ \ + -isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Core/Include/ \ + -isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Device/${CHIP_VARIANT}/Include \ -isystem sdk/src/rp2_common/cmsis/ \ -isystem sdk/src/rp2_common/hardware_adc/include/ \ -isystem sdk/src/rp2_common/hardware_base/include/ \ @@ -153,7 +154,7 @@ INC += \ -isystem sdk/src/rp2_common/pico_platform_panic/include/ \ -isystem sdk/src/rp2_common/pico_time_adapter/include/ \ -isystem sdk/src/rp2_common/pico_unique_id/include/ \ -$(INC_CYW43) \ + $(INC_CYW43) \ -Isdk_config \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ @@ -222,7 +223,7 @@ endif DISABLE_WARNINGS = -Wno-cast-align -CFLAGS += $(INC) -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes +CFLAGS += $(INC) -Wtype-limits -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes PICO_LDFLAGS = --specs=nosys.specs --specs=nano.specs diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index e3aafbeef0543..c17ec102297b8 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -15,7 +15,7 @@ #include "py/mpstate.h" #include "py/runtime.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "hardware/irq.h" #include "hardware/regs/intctrl.h" // For isr_ macro. diff --git a/ports/raspberrypi/audio_dma.h b/ports/raspberrypi/audio_dma.h index b48456f5a83aa..48cc024fda98d 100644 --- a/ports/raspberrypi/audio_dma.h +++ b/ports/raspberrypi/audio_dma.h @@ -9,7 +9,7 @@ #include "py/obj.h" #include "supervisor/background_callback.h" -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "hardware/dma.h" typedef enum { AUDIO_DMA_OK, diff --git a/ports/raspberrypi/bindings/cyw43/__init__.c b/ports/raspberrypi/bindings/cyw43/__init__.c index c14f15212f5d0..36ac3ff7b6206 100644 --- a/ports/raspberrypi/bindings/cyw43/__init__.c +++ b/ports/raspberrypi/bindings/cyw43/__init__.c @@ -12,7 +12,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "bindings/cyw43/__init__.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "lib/cyw43-driver/src/cyw43.h" diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 60f3fc7317a85..673d9303d6b55 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -10,7 +10,7 @@ #include "shared-module/displayio/mipi_constants.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/board.h" #include "supervisor/shared/board.h" diff --git a/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c b/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c index 5a44f1167f0d9..ae948d089b51b 100644 --- a/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c +++ b/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c @@ -7,6 +7,6 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/boardsource_blok/board.c b/ports/raspberrypi/boards/boardsource_blok/board.c index 0c7574ea8a89d..5d714c242b5ee 100644 --- a/ports/raspberrypi/boards/boardsource_blok/board.c +++ b/ports/raspberrypi/boards/boardsource_blok/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void board_init(void) { diff --git a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c index 60efe1e282259..19e18bd544bee 100644 --- a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c +++ b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c @@ -26,9 +26,9 @@ #include "shared-module/displayio/__init__.h" #include "supervisor/shared/board.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" -#include "src/rp2_common/hardware_adc/include/hardware/adc.h" +#include "hardware/adc.h" #define ADC_FIRST_PIN_NUMBER 26 #define ADC_PIN_COUNT 4 extern void common_hal_mcu_delay_us(uint32_t); @@ -281,6 +281,7 @@ void board_init(void) { true, // always_toggle_chip_select false, // not grayscale false, // not acep + false, // not spectra6 false, // not two_byte_sequence_length true); // address_little_endian } else if (vid_setting == 2) { // Explorer SSD1608 BW @@ -314,6 +315,7 @@ void board_init(void) { true, // always_toggle_chip_select false, // not grayscale false, // not acep + false, // not spectra6 false, // not two_byte_sequence_length true); // address_little_endian } else { diff --git a/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c b/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c index 559800e34d962..d3c80c5cb87d9 100644 --- a/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" #include "supervisor/board.h" diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c index c123fd785c944..2bb2d06dcad4f 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c index f0a3953335557..743e9b14b52a2 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c index 360f18e382ed0..ab07a4aaaed27 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c index 751726a065da3..b9fa212c96d91 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index 457bff33b4433..5950d11da8a11 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -303,6 +303,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/board.c b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c index 30c05273b9478..7dc11af01eca3 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040w/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c @@ -303,6 +303,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/board.c b/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/board.c index 650d307711e8e..7969143ec6621 100644 --- a/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/board.c +++ b/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/board.c @@ -97,6 +97,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale true, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/mpconfigboard.h index d2547cc161568..a8c404c422501 100644 --- a/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/mpconfigboard.h +++ b/ports/raspberrypi/boards/pimoroni_inky_frame_5_7/mpconfigboard.h @@ -14,8 +14,8 @@ #define MICROPY_HW_LED_STATUS (&pin_GPIO6) -#define DEFAULT_I2C_BUS_SCL (&pin_GPIO4) -#define DEFAULT_I2C_BUS_SDA (&pin_GPIO5) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) #define DEFAULT_UART_BUS_TX (&pin_GPIO0) #define DEFAULT_UART_BUS_RX (&pin_GPIO1) diff --git a/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/board.c b/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/board.c index a24c91e546da9..7c71e03b4281d 100644 --- a/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/board.c +++ b/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/board.c @@ -156,6 +156,7 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale true, // acep + false, // spectra6 false, // two_byte_sequence_length false); // address_little_endian } diff --git a/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/mpconfigboard.h index 42cb1196a5475..32477b12c299f 100644 --- a/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/mpconfigboard.h +++ b/ports/raspberrypi/boards/pimoroni_inky_frame_7_3/mpconfigboard.h @@ -14,8 +14,8 @@ #define MICROPY_HW_LED_STATUS (&pin_GPIO6) -#define DEFAULT_I2C_BUS_SCL (&pin_GPIO4) -#define DEFAULT_I2C_BUS_SDA (&pin_GPIO5) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) #define DEFAULT_UART_BUS_TX (&pin_GPIO0) #define DEFAULT_UART_BUS_RX (&pin_GPIO1) diff --git a/ports/raspberrypi/boards/ugame22/board.c b/ports/raspberrypi/boards/ugame22/board.c index a208326a09439..6b8152b14eedf 100644 --- a/ports/raspberrypi/boards/ugame22/board.c +++ b/ports/raspberrypi/boards/ugame22/board.c @@ -7,7 +7,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/fourwire/FourWire.h" diff --git a/ports/raspberrypi/boards/wk-50/board.c b/ports/raspberrypi/boards/wk-50/board.c index 9ebde0a6f3363..2ea197d2b2e5b 100644 --- a/ports/raspberrypi/boards/wk-50/board.c +++ b/ports/raspberrypi/boards/wk-50/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c b/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c index 415a7b3b3e8ff..f8e9958433b08 100644 --- a/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c +++ b/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boot_stage2/RP2040.c.jinja b/ports/raspberrypi/boot_stage2/RP2040.c.jinja index 4c001525dcc2f..c00b35fa662c6 100644 --- a/ports/raspberrypi/boot_stage2/RP2040.c.jinja +++ b/ports/raspberrypi/boot_stage2/RP2040.c.jinja @@ -1,7 +1,7 @@ -#include "sdk/src/rp2040/hardware_structs/include/hardware/structs/ssi.h" -#include "sdk/src/rp2040/hardware_structs/include/hardware/structs/pads_qspi.h" -#include "sdk/src/rp2040/hardware_regs/include/hardware/regs/addressmap.h" -#include "sdk/src/rp2040/hardware_regs/include/hardware/regs/m0plus.h" +#include "hardware/structs/ssi.h" +#include "hardware/structs/pads_qspi.h" +#include "hardware/regs/addressmap.h" +#include "hardware/regs/m0plus.h" // "Mode bits" are 8 special bits sent immediately after // the address bits in a "Read Data Fast Quad I/O" command sequence. diff --git a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c index 7385b21ea95e3..fe74f3213927c 100644 --- a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c +++ b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c @@ -11,20 +11,25 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared/runtime/interrupt_char.h" #include "py/runtime.h" -#include "src/rp2_common/hardware_adc/include/hardware/adc.h" -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" -#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" - -#define ADC_FIRST_PIN_NUMBER 26 -#define ADC_PIN_COUNT 4 +#include "hardware/adc.h" +#include "hardware/dma.h" +#include "pico/stdlib.h" #define ADC_CLOCK_INPUT 48000000 #define ADC_MAX_CLOCK_DIV (1 << (ADC_DIV_INT_MSB - ADC_DIV_INT_LSB + 1)) void common_hal_analogbufio_bufferedin_construct(analogbufio_bufferedin_obj_t *self, const mcu_pin_obj_t *pin, uint32_t sample_rate) { // Make sure pin number is in range for ADC - if (pin->number < ADC_FIRST_PIN_NUMBER || pin->number >= (ADC_FIRST_PIN_NUMBER + ADC_PIN_COUNT)) { - raise_ValueError_invalid_pins(); + if ((pin->number < ADC_BASE_PIN) + || (pin->number > ADC_BASE_PIN + NUM_ADC_CHANNELS - 1) + // On many boards with a CYW43 radio co-processor, CYW43_DEFAULT_PIN_WL_CLOCK (usually GPIO29), + // is both a voltage monitor and also SPI SCK to the CYW43. + // Disallow its use for BufferedIn. + #if defined(CIRCUITPY_CYW43) && defined(CYW43_DEFAULT_PIN_WL_CLOCK) + || (pin->number == CYW43_DEFAULT_PIN_WL_CLOCK) + #endif + ) { + raise_ValueError_invalid_pin(); } // Validate sample rate here @@ -35,7 +40,7 @@ void common_hal_analogbufio_bufferedin_construct(analogbufio_bufferedin_obj_t *s claim_pin(pin); // TODO: find a way to accept ADC4 for temperature - self->chan = pin->number - ADC_FIRST_PIN_NUMBER; + self->chan = pin->number - ADC_BASE_PIN; // Init GPIO for analogue use: hi-Z, no pulls, disable digital input buffer. // TODO: Make sure we share the ADC well. Right now we just assume it is diff --git a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h index f0c536f392159..587668c1a7bf6 100644 --- a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h +++ b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h @@ -8,7 +8,7 @@ #pragma once #include "common-hal/microcontroller/Pin.h" -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "hardware/dma.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/analogio/AnalogIn.c b/ports/raspberrypi/common-hal/analogio/AnalogIn.c index 301b965c86c15..2a9c2d1d42d3c 100644 --- a/ports/raspberrypi/common-hal/analogio/AnalogIn.c +++ b/ports/raspberrypi/common-hal/analogio/AnalogIn.c @@ -10,22 +10,14 @@ #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "src/rp2_common/hardware_adc/include/hardware/adc.h" +#include "hardware/adc.h" -#define ADC_PIN_COUNT (NUM_ADC_CHANNELS - 1) - -#if ADC_PIN_COUNT == 4 -#define ADC_FIRST_PIN_NUMBER 26 -#else -#define ADC_FIRST_PIN_NUMBER 40 -#endif - -// Voltage monitor is special on Pico W, because this pin is shared between the -// voltage monitor function and the wifi function. Special handling is required -// to read the analog voltage. +// On many boards with a CYW43 radio co-processor, CYW43_DEFAULT_PIN_WL_CLOCK (usually GPIO29), +// is both a voltage monitor and also SPI SCK to the CYW43. +// Special handling is required to read the analog voltage. #if CIRCUITPY_CYW43 #include "bindings/cyw43/__init__.h" -#define SPECIAL_PIN(pin) (pin->number == 29) +#define SPECIAL_PIN(pin) (pin->number == CYW43_DEFAULT_PIN_WL_CLOCK) const mcu_pin_obj_t *common_hal_analogio_analogin_validate_pin(mp_obj_t obj) { return validate_obj_is_free_pin_or_gpio29(obj, MP_QSTR_pin); @@ -35,7 +27,7 @@ const mcu_pin_obj_t *common_hal_analogio_analogin_validate_pin(mp_obj_t obj) { #endif void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) { - if (pin->number < ADC_FIRST_PIN_NUMBER || pin->number > ADC_FIRST_PIN_NUMBER + ADC_PIN_COUNT) { + if (pin->number < ADC_BASE_PIN || pin->number > ADC_BASE_PIN + NUM_ADC_CHANNELS - 1) { raise_ValueError_invalid_pin(); } @@ -70,7 +62,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { uint32_t old_pad = pads_bank0_hw->io[self->pin->number]; uint32_t old_ctrl = io_bank0_hw->io[self->pin->number].ctrl; adc_gpio_init(self->pin->number); - adc_select_input(self->pin->number - ADC_FIRST_PIN_NUMBER); + adc_select_input(self->pin->number - ADC_BASE_PIN); common_hal_mcu_delay_us(100); value = adc_read(); gpio_init(self->pin->number); @@ -78,7 +70,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { io_bank0_hw->io[self->pin->number].ctrl = old_ctrl; common_hal_mcu_enable_interrupts(); } else { - adc_select_input(self->pin->number - ADC_FIRST_PIN_NUMBER); + adc_select_input(self->pin->number - ADC_BASE_PIN); value = adc_read(); } // Stretch 12-bit ADC reading to 16-bit range diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 0494e937f4b42..6fa5bf02c1486 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -20,8 +20,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" -#include "src/rp2040/hardware_structs/include/hardware/structs/dma.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "hardware/structs/dma.h" +#include "hardware/pwm.h" // The PWM clock frequency is base_clock_rate / PWM_TOP, typically 125_000_000 / PWM_TOP. // We pick BITS_PER_SAMPLE so we get a clock frequency that is above what would cause aliasing. diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index 3b7cf8662d90e..0f7e023f0e9c5 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -13,7 +13,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/bitbangio/I2C.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" // Synopsys DW_apb_i2c (v2.01) IP diff --git a/ports/raspberrypi/common-hal/busio/I2C.h b/ports/raspberrypi/common-hal/busio/I2C.h index b02c1c54a31c4..7a6fd1b9d1f37 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.h +++ b/ports/raspberrypi/common-hal/busio/I2C.h @@ -11,7 +11,7 @@ #include "py/obj.h" -#include "src/rp2_common/hardware_i2c/include/hardware/i2c.h" +#include "hardware/i2c.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index 7a033250f9142..d20bc4d7d10aa 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -14,8 +14,8 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/dma.h" +#include "hardware/gpio.h" #define NO_INSTANCE 0xff diff --git a/ports/raspberrypi/common-hal/busio/SPI.h b/ports/raspberrypi/common-hal/busio/SPI.h index 27d4cf6f3c72b..8510eb7693ae2 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.h +++ b/ports/raspberrypi/common-hal/busio/SPI.h @@ -10,7 +10,7 @@ #include "py/obj.h" -#include "src/rp2_common/hardware_spi/include/hardware/spi.h" +#include "hardware/spi.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/busio/UART.c b/ports/raspberrypi/common-hal/busio/UART.c index aeb0ff4bea289..17fcfa172293d 100644 --- a/ports/raspberrypi/common-hal/busio/UART.c +++ b/ports/raspberrypi/common-hal/busio/UART.c @@ -14,8 +14,8 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/irq.h" +#include "hardware/gpio.h" #define NO_PIN 0xff diff --git a/ports/raspberrypi/common-hal/busio/UART.h b/ports/raspberrypi/common-hal/busio/UART.h index ca75235ddf879..3709907633cb0 100644 --- a/ports/raspberrypi/common-hal/busio/UART.h +++ b/ports/raspberrypi/common-hal/busio/UART.h @@ -9,7 +9,7 @@ #include "py/obj.h" #include "py/ringbuf.h" -#include "src/rp2_common/hardware_uart/include/hardware/uart.h" +#include "hardware/uart.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c index 1a270bf882070..ba82ca8e7ab9d 100644 --- a/ports/raspberrypi/common-hal/countio/Counter.c +++ b/ports/raspberrypi/common-hal/countio/Counter.c @@ -13,9 +13,9 @@ #include "shared-bindings/digitalio/Pull.h" #include "common-hal/pwmio/PWMOut.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "hardware/gpio.h" +#include "hardware/pwm.h" +#include "hardware/irq.h" void common_hal_countio_counter_construct(countio_counter_obj_t *self, diff --git a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c index 60849eb120af8..f20facdad7dfc 100644 --- a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c +++ b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c @@ -14,7 +14,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #if CIRCUITPY_CYW43 #include "pico/cyw43_arch.h" diff --git a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c index 4f226fe56e957..d1c92eea9988f 100644 --- a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c +++ b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c @@ -14,7 +14,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" static i2c_inst_t *i2c[2] = {i2c0, i2c1}; diff --git a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h index 0b6c2875e3f40..5d4e0690cbffd 100644 --- a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h +++ b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h @@ -8,7 +8,7 @@ #include "py/obj.h" #include "common-hal/microcontroller/Pin.h" -#include "src/rp2_common/hardware_i2c/include/hardware/i2c.h" +#include "hardware/i2c.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c index 7be1d5581fcbd..d0a7a1d7b08a1 100644 --- a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c @@ -18,8 +18,8 @@ #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/__init__.h" -#include "src/rp2_common/hardware_pio/include/hardware/pio.h" -#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h" +#include "hardware/pio.h" +#include "hardware/pio_instructions.h" // Define this to (1), and you can scope the instruction-pointer of the state machine on D26..28 (note the weird encoding though!) #define DEBUG_STATE_MACHINE (0) diff --git a/ports/raspberrypi/common-hal/max3421e/Max3421E.c b/ports/raspberrypi/common-hal/max3421e/Max3421E.c index 20ce701b9f3cc..0077b460ed0a0 100644 --- a/ports/raspberrypi/common-hal/max3421e/Max3421E.c +++ b/ports/raspberrypi/common-hal/max3421e/Max3421E.c @@ -10,7 +10,7 @@ #include "shared-bindings/busio/SPI.h" #include "supervisor/usb.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" static max3421e_max3421e_obj_t *active_max = NULL; diff --git a/ports/raspberrypi/common-hal/microcontroller/Pin.c b/ports/raspberrypi/common-hal/microcontroller/Pin.c index 4ea7516d70915..3c5286d36c4e9 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Pin.c +++ b/ports/raspberrypi/common-hal/microcontroller/Pin.c @@ -9,7 +9,7 @@ #include "common-hal/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" static uint64_t gpio_bank0_pin_claimed; diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 139edc999d669..a3ea890d9aff3 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -15,26 +15,21 @@ #include "shared-bindings/time/__init__.h" #include "pico/stdlib.h" -#include "src/rp2_common/hardware_adc/include/hardware/adc.h" -#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" -#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" -#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h" +#include "hardware/adc.h" +#include "hardware/clocks.h" +#include "hardware/vreg.h" +#include "hardware/watchdog.h" #ifdef PICO_RP2040 -#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h" +#include "hardware/regs/vreg_and_chip_reset.h" +#include "hardware/structs/vreg_and_chip_reset.h" #endif #ifdef PICO_RP2350 -#include "src/rp2350/hardware_regs/include/hardware/regs/powman.h" +#include "hardware/regs/powman.h" +#include "hardware/structs/powman.h" #endif -#include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h" - -#ifdef PICO_RP2040 -#include "src/rp2040/hardware_structs/include/hardware/structs/vreg_and_chip_reset.h" -#endif -#ifdef PICO_RP2350 -#include "src/rp2350/hardware_structs/include/hardware/structs/powman.h" -#endif -#include "src/rp2040/hardware_structs/include/hardware/structs/watchdog.h" +#include "hardware/regs/watchdog.h" +#include "hardware/structs/watchdog.h" float common_hal_mcu_processor_get_temperature(void) { adc_init(); diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.h b/ports/raspberrypi/common-hal/microcontroller/Processor.h index 31f89f58fd308..df1e1cf2333b9 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.h +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.h @@ -6,7 +6,7 @@ #pragma once -#include "src/rp2_common/pico_unique_id/include/pico/unique_id.h" +#include "pico/unique_id.h" #define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH PICO_UNIQUE_BOARD_ID_SIZE_BYTES diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.c b/ports/raspberrypi/common-hal/microcontroller/__init__.c index 1d29b4a29f09d..e287e551710b6 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.c +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.c @@ -19,8 +19,8 @@ #include "supervisor/port.h" #include "supervisor/shared/safe_mode.h" -#include "src/rp2040/hardware_structs/include/hardware/structs/sio.h" -#include "src/rp2_common/hardware_sync/include/hardware/sync.h" +#include "hardware/structs/sio.h" +#include "hardware/sync.h" #include "hardware/watchdog.h" #include "hardware/irq.h" @@ -51,7 +51,7 @@ void common_hal_mcu_enable_interrupts(void) { asm volatile ("cpsie i" : : : "memory"); } #else -#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" +#include "RP2350.h" #define PICO_ELEVATED_IRQ_PRIORITY (0x60) // between PICO_DEFAULT and PIOCO_HIGHEST_IRQ_PRIORITY static uint32_t oldBasePri = 0; // 0 (default) masks nothing, other values mask equal-or-larger priority values void common_hal_mcu_disable_interrupts(void) { diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.h b/ports/raspberrypi/common-hal/microcontroller/__init__.h index e9a7602bc040c..8798c857404c5 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.h +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.h @@ -6,7 +6,7 @@ #pragma once -#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" +#include "hardware/platform_defs.h" #include "peripherals/pins.h" const mcu_pin_obj_t *mcu_get_pin_by_number(int); diff --git a/ports/raspberrypi/common-hal/nvm/ByteArray.c b/ports/raspberrypi/common-hal/nvm/ByteArray.c index c23ccfef4dad2..558f38240ce4f 100644 --- a/ports/raspberrypi/common-hal/nvm/ByteArray.c +++ b/ports/raspberrypi/common-hal/nvm/ByteArray.c @@ -10,7 +10,7 @@ #include #include "py/runtime.h" -#include "src/rp2_common/hardware_flash/include/hardware/flash.h" +#include "hardware/flash.h" #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/internal_flash.h" diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c index 0bfb86b4c8a1f..788f10d6df6ac 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c @@ -13,13 +13,13 @@ #include "common-hal/rp2pio/StateMachine.h" #include "supervisor/port.h" -#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" -#include "src/rp2040/hardware_structs/include/hardware/structs/mpu.h" -#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h" -#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" -#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" -#include "src/rp2_common/pico_multicore/include/pico/multicore.h" +#include "pico/stdlib.h" +#include "hardware/structs/mpu.h" +#include "RP2040.h" // (cmsis) +#include "hardware/clocks.h" +#include "hardware/pwm.h" +#include "hardware/vreg.h" +#include "pico/multicore.h" #include "lib/PicoDVI/software/libdvi/tmds_encode.h" diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c index c6fc593ce8644..79ec315d497e4 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c @@ -31,14 +31,14 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/port.h" -#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" +#include "pico/stdlib.h" // This is from: https://github.com/raspberrypi/pico-examples-rp2350/blob/a1/hstx/dvi_out_hstx_encoder/dvi_out_hstx_encoder.c -#include "sdk/src/rp2_common/hardware_dma/include/hardware/dma.h" -#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/bus_ctrl.h" -#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/hstx_ctrl.h" -#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/hstx_fifo.h" +#include "hardware/dma.h" +#include "hardware/structs/bus_ctrl.h" +#include "hardware/structs/hstx_ctrl.h" +#include "hardware/structs/hstx_fifo.h" // ---------------------------------------------------------------------------- // DVI constants diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index a1d281a247548..b56c90a9a53bb 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "hardware/gpio.h" #include diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index cca1dedfabca9..369d7b8f450fe 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -7,7 +7,7 @@ #pragma once #include "common-hal/microcontroller/Pin.h" -#include "src/rp2_common/hardware_pio/include/hardware/pio.h" +#include "hardware/pio.h" #include "common-hal/rp2pio/StateMachine.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c index 114bff13979f9..84d02e20cce15 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -14,9 +14,9 @@ #include "shared-bindings/microcontroller/__init__.h" #include "common-hal/pwmio/PWMOut.h" #include "hardware/structs/pwm.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" -#include "src/common/pico_time/include/pico/time.h" +#include "hardware/gpio.h" +#include "hardware/pwm.h" +#include "pico/time.h" volatile alarm_id_t cur_alarm = 0; diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.h b/ports/raspberrypi/common-hal/pulseio/PulseOut.h index fa264c36b7f68..cff82f2c28c72 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.h @@ -8,7 +8,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/pwmio/PWMOut.h" -#include "src/common/pico_time/include/pico/time.h" +#include "pico/time.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c index e0572eccd9e44..9ceb5a0185d92 100644 --- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c +++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c @@ -12,10 +12,10 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Processor.h" -#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" -#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "hardware/platform_defs.h" +#include "hardware/clocks.h" +#include "hardware/gpio.h" +#include "hardware/pwm.h" uint32_t target_slice_frequencies[NUM_PWM_SLICES]; uint32_t slice_variable_frequency; diff --git a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c index 029e2b2755ea0..875da3432510a 100644 --- a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c +++ b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c @@ -12,8 +12,8 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-module/rgbmatrix/RGBMatrix.h" -#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "hardware/pwm.h" +#include "hardware/irq.h" void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) { // Choose a PWM channel based on the first RGB pin diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 950fd3cab8ef0..3e4579fe49ddb 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -14,12 +14,12 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/memorymap/AddressRange.h" -#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" -#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" -#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h" -#include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "hardware/platform_defs.h" +#include "hardware/structs/iobank0.h" +#include "hardware/clocks.h" +#include "hardware/dma.h" +#include "hardware/pio_instructions.h" +#include "hardware/irq.h" #include "shared/runtime/interrupt_char.h" #include "py/obj.h" @@ -222,7 +222,7 @@ static bool is_gpio_compatible(PIO pio, uint32_t used_gpio_ranges) { #endif } -static bool use_existing_program(PIO *pio_out, uint *sm_out, int *offset_inout, uint32_t program_id, size_t program_len, uint gpio_base, uint gpio_count) { +static bool use_existing_program(PIO *pio_out, int *sm_out, int *offset_inout, uint32_t program_id, size_t program_len, uint gpio_base, uint gpio_count) { uint32_t required_gpio_ranges; if (gpio_count) { required_gpio_ranges = (1u << (gpio_base >> 4)) | @@ -307,12 +307,12 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, .origin = offset, }; PIO pio; - uint state_machine; + int state_machine; bool added = false; if (!use_existing_program(&pio, &state_machine, &offset, program_id, program_len, gpio_base, gpio_count)) { uint program_offset; - bool r = pio_claim_free_sm_and_add_program_for_gpio_range(&program_struct, &pio, &state_machine, &program_offset, gpio_base, gpio_count, true); + bool r = pio_claim_free_sm_and_add_program_for_gpio_range(&program_struct, &pio, (uint *)&state_machine, &program_offset, gpio_base, gpio_count, true); if (!r) { return false; } @@ -336,6 +336,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, } } + // Sanity check that state_machine number is valid. + assert(state_machine >= 0); self->pio = pio; self->state_machine = state_machine; self->offset = offset; @@ -739,6 +741,8 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, fifo_type, mov_status_type, mov_status_n); if (!ok) { + // indicate state machine never inited + self->state_machine = NUM_PIO_STATE_MACHINES; mp_raise_RuntimeError(MP_ERROR_TEXT("All state machines in use")); } } diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h index e163491825424..c7ef12e1b0177 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h @@ -10,7 +10,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/memorymap/AddressRange.h" -#include "src/rp2_common/hardware_pio/include/hardware/pio.h" +#include "hardware/pio.h" // pio_pinmask_t can hold ANY pin masks, so it is used before selection of gpiobase #if NUM_BANK0_GPIOS > 32 diff --git a/ports/raspberrypi/common-hal/rtc/RTC.c b/ports/raspberrypi/common-hal/rtc/RTC.c index 3bdf599d2701f..67935502ad322 100644 --- a/ports/raspberrypi/common-hal/rtc/RTC.c +++ b/ports/raspberrypi/common-hal/rtc/RTC.c @@ -11,8 +11,8 @@ #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "src/common/pico_util/include/pico/util/datetime.h" -#include "src/rp2_common/pico_aon_timer/include/pico/aon_timer.h" +#include "pico/util/datetime.h" +#include "pico/aon_timer.h" void common_hal_rtc_init(void) { // We start the RTC at 0 which mark as January 1, 2000. diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index fb1fdfb5f65bf..086fc4a13f78f 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -35,7 +35,7 @@ #include "lwip/timeouts.h" #include "lwip/udp.h" -#include "sdk/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h" +#include "pico/cyw43_arch.h" mp_obj_t socketpool_ip_addr_to_str(const ip_addr_t *addr) { char ip_str[IPADDR_STRLEN_MAX]; // big enough for any supported address type diff --git a/ports/raspberrypi/common-hal/usb_host/Port.c b/ports/raspberrypi/common-hal/usb_host/Port.c index e350c288f71a5..5439b39bf3aa3 100644 --- a/ports/raspberrypi/common-hal/usb_host/Port.c +++ b/ports/raspberrypi/common-hal/usb_host/Port.c @@ -11,17 +11,16 @@ #include "supervisor/shared/serial.h" #include "supervisor/usb.h" -#include "src/common/pico_time/include/pico/time.h" +#include "pico/time.h" +#include "hardware/structs/mpu.h" #ifdef PICO_RP2040 -#include "src/rp2040/hardware_structs/include/hardware/structs/mpu.h" -#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h" +#include "RP2040.h" // (cmsis) #endif #ifdef PICO_RP2350 -#include "src/rp2350/hardware_structs/include/hardware/structs/mpu.h" -#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" +#include "RP2350.h" // (cmsis) #endif -#include "src/rp2_common/hardware_dma/include/hardware/dma.h" -#include "src/rp2_common/pico_multicore/include/pico/multicore.h" +#include "hardware/dma.h" +#include "pico/multicore.h" #include "py/runtime.h" @@ -138,10 +137,11 @@ usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, } pio_cfg.pio_tx_num = get_usb_pio(); pio_cfg.pio_rx_num = pio_cfg.pio_tx_num; - pio_cfg.tx_ch = dma_claim_unused_channel(false); // DMA channel - if (pio_cfg.tx_ch < 0) { + int dma_ch = dma_claim_unused_channel(false); + if (dma_ch < 0) { mp_raise_RuntimeError(MP_ERROR_TEXT("All dma channels in use")); } + pio_cfg.tx_ch = dma_ch; self->base.type = &usb_host_port_type; self->dp = dp; diff --git a/ports/raspberrypi/cyw43_configport.h b/ports/raspberrypi/cyw43_configport.h index 62666bee42c23..c1769436ae497 100644 --- a/ports/raspberrypi/cyw43_configport.h +++ b/ports/raspberrypi/cyw43_configport.h @@ -12,7 +12,7 @@ #include "supervisor/port.h" -#include "sdk/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h" +#include_next "cyw43_configport.h" #define CYW43_NETUTILS (1) diff --git a/ports/raspberrypi/mphalport.c b/ports/raspberrypi/mphalport.c index 3258c4de4f3b6..3d322ba6bca45 100644 --- a/ports/raspberrypi/mphalport.c +++ b/ports/raspberrypi/mphalport.c @@ -19,7 +19,7 @@ #include "mphalport.h" #include "supervisor/shared/tick.h" -#include "src/rp2_common/hardware_timer/include/hardware/timer.h" +#include "hardware/timer.h" extern uint32_t common_hal_mcu_processor_get_frequency(void); diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index ce3bef6c564ce..9d5e13348aac2 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -24,11 +24,11 @@ #include "supervisor/usb.h" #ifdef PICO_RP2350 -#include "src/rp2350/hardware_structs/include/hardware/structs/qmi.h" +#include "hardware/structs/qmi.h" #endif -#include "src/rp2040/hardware_structs/include/hardware/structs/sio.h" -#include "src/rp2_common/hardware_flash/include/hardware/flash.h" -#include "src/common/pico_binary_info/include/pico/binary_info.h" +#include "hardware/structs/sio.h" +#include "hardware/flash.h" +#include "pico/binary_info.h" #if !defined(TOTAL_FLASH_MINIMUM) #define TOTAL_FLASH_MINIMUM (2 * 1024 * 1024) diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 026d9f629c57d..7514b4e6ad4aa 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -37,23 +37,23 @@ #include "supervisor/shared/stack.h" #include "supervisor/shared/tick.h" -#include "src/rp2040/hardware_structs/include/hardware/structs/watchdog.h" -#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -#include "src/rp2_common/hardware_uart/include/hardware/uart.h" -#include "src/rp2_common/hardware_sync/include/hardware/sync.h" -#include "src/rp2_common/hardware_timer/include/hardware/timer.h" +#include "hardware/structs/watchdog.h" +#include "hardware/gpio.h" +#include "hardware/uart.h" +#include "hardware/sync.h" +#include "hardware/timer.h" #if CIRCUITPY_CYW43 #include "py/mphal.h" #include "pico/cyw43_arch.h" #endif -#include "src/common/pico_time/include/pico/time.h" -#include "src/common/pico_binary_info/include/pico/binary_info.h" +#include "pico/time.h" +#include "pico/binary_info.h" #include "pico/bootrom.h" #include "hardware/watchdog.h" #ifdef PICO_RP2350 -#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" +#include "RP2350.h" // CMSIS #endif #include "supervisor/shared/serial.h" @@ -95,10 +95,10 @@ static size_t _psram_size = 0; #ifdef CIRCUITPY_PSRAM_CHIP_SELECT -#include "src/rp2350/hardware_regs/include/hardware/regs/qmi.h" -#include "src/rp2350/hardware_regs/include/hardware/regs/xip.h" -#include "src/rp2350/hardware_structs/include/hardware/structs/qmi.h" -#include "src/rp2350/hardware_structs/include/hardware/structs/xip_ctrl.h" +#include "hardware/regs/qmi.h" +#include "hardware/regs/xip.h" +#include "hardware/structs/qmi.h" +#include "hardware/structs/xip_ctrl.h" static void __no_inline_not_in_flash_func(setup_psram)(void) { gpio_set_function(CIRCUITPY_PSRAM_CHIP_SELECT->number, GPIO_FUNC_XIP_CS1); diff --git a/ports/raspberrypi/supervisor/usb.c b/ports/raspberrypi/supervisor/usb.c index 97933d5651ea5..398f3f448a1d5 100644 --- a/ports/raspberrypi/supervisor/usb.c +++ b/ports/raspberrypi/supervisor/usb.c @@ -7,9 +7,9 @@ #include "lib/tinyusb/src/device/usbd.h" #include "supervisor/background_callback.h" #include "supervisor/usb.h" -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "hardware/irq.h" #include "pico/platform.h" -#include "src/rp2040/hardware_regs/include/hardware/regs/intctrl.h" +#include "hardware/regs/intctrl.h" void init_usb_hardware(void) { } diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 513f7d2d64d97..2e7bba09d01b8 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -944,7 +944,7 @@ SRC_CIRCUITPY_COMMON = \ ifeq ($(CIRCUITPY_QRIO),1) SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c -$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h +$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-type-limits -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h endif ifdef LD_TEMPLATE_FILE diff --git a/shared-bindings/analogbufio/BufferedIn.c b/shared-bindings/analogbufio/BufferedIn.c index 9a8483220cda5..a25610207b49a 100644 --- a/shared-bindings/analogbufio/BufferedIn.c +++ b/shared-bindings/analogbufio/BufferedIn.c @@ -40,7 +40,12 @@ //| """Create a `BufferedIn` on the given pin and given sample rate. //| //| :param ~microcontroller.Pin pin: the pin to read from -//| :param ~int sample_rate: rate: sampling frequency, in samples per second""" +//| :param ~int sample_rate: rate: sampling frequency, in samples per second +//| +//| **Limitations**: On many boards with a CYW43 radio module, such as Pico W, +//| GPIO29 (often ``board.A3``) is also used to control the CYW43, +//| and is therefore not available to use as the `BufferedIn` pin. +//| """ //| ... //| static mp_obj_t analogbufio_bufferedin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 1bfc51cb9ab27..82aecefa370ba 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -28,11 +28,16 @@ //| """Create a AudioOut object associated with the given pin(s). This allows you to //| play audio signals out on the given pin(s). //| -//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to -//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to +//| :param ~microcontroller.Pin left_channel: Output left channel data to this pin +//| :param ~microcontroller.Pin right_channel: Output right channel data to this pin. May be ``None``. //| :param int quiescent_value: The output value when no signal is present. Samples should start //| and end with this value to prevent audible popping. //| +//| .. note:: On ESP32 and ESP32-S2, the DAC channels are usually designated +//| as ``DAC_1`` (right stereo channel) and DAC_2 (left stereo channel). +//| These pins are sometimes labelled as ``A0`` and ``A1``, but they may be assigned +//| in either order. Check your board's pinout to verify which pin is which channel. +//| //| Simple 8ksps 440 Hz sin wave:: //| //| import audiocore @@ -90,6 +95,12 @@ static mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj, MP_QSTR_right_channel); + // Can't use the same pin for both left and right channels. + if (left_channel_pin == right_channel_pin) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("%q and %q must be different"), + MP_QSTR_left_channel, MP_QSTR_right_channel); + } + // create AudioOut object from the given pin audioio_audioout_obj_t *self = mp_obj_malloc_with_finaliser(audioio_audioout_obj_t, &audioio_audioout_type); common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index a8757fbcc17f2..8a9b2e5e0d34e 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -316,7 +316,7 @@ MP_PROPERTY_GETSET(displayio_tilegrid_transpose_xy_obj, //| inside the tilegrid rectangle bounds.""" //| static mp_obj_t displayio_tilegrid_obj_contains(mp_obj_t self_in, mp_obj_t touch_tuple) { - displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); + displayio_tilegrid_t *self = native_tilegrid(self_in); mp_obj_t *touch_tuple_items; mp_obj_get_array_fixed_n(touch_tuple, 3, &touch_tuple_items); diff --git a/shared-bindings/epaperdisplay/EPaperDisplay.c b/shared-bindings/epaperdisplay/EPaperDisplay.c index 0d558a1319616..40a217a65bd1c 100644 --- a/shared-bindings/epaperdisplay/EPaperDisplay.c +++ b/shared-bindings/epaperdisplay/EPaperDisplay.c @@ -62,6 +62,7 @@ //| always_toggle_chip_select: bool = False, //| grayscale: bool = False, //| advanced_color_epaper: bool = False, +//| spectra6: bool = False, //| two_byte_sequence_length: bool = False, //| start_up_time: float = 0, //| address_little_endian: bool = False, @@ -104,6 +105,7 @@ //| :param bool always_toggle_chip_select: When True, chip select is toggled every byte //| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale //| :param bool advanced_color_epaper: When true, the display is a 7-color advanced color epaper (ACeP) +//| :param bool spectra6: When true, the display is a 6-color spectra6 epaper //| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length //| :param float start_up_time: Time to wait after reset before sending commands //| :param bool address_little_endian: Send the least significant byte (not bit) of multi-byte addresses first. Ignored when ram is addressed with one byte @@ -117,7 +119,7 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type, ARG_set_current_row_command, ARG_write_black_ram_command, ARG_black_bits_inverted, ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color, ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state, - ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_advanced_color_epaper, + ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_advanced_color_epaper, ARG_spectra6, ARG_two_byte_sequence_length, ARG_start_up_time, ARG_address_little_endian }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -147,6 +149,7 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type, { MP_QSTR_always_toggle_chip_select, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_advanced_color_epaper, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_spectra6, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_start_up_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(0)} }, { MP_QSTR_address_little_endian, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, @@ -215,7 +218,7 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type, args[ARG_write_black_ram_command].u_int, args[ARG_black_bits_inverted].u_bool, write_color_ram_command, args[ARG_color_bits_inverted].u_bool, highlight_color, refresh_buf, refresh_buf_len, refresh_time, busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame, - args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool, + args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool, args[ARG_spectra6].u_bool, two_byte_sequence_length, args[ARG_address_little_endian].u_bool ); diff --git a/shared-bindings/epaperdisplay/EPaperDisplay.h b/shared-bindings/epaperdisplay/EPaperDisplay.h index d4475e0a6aa43..016a07f1490c5 100644 --- a/shared-bindings/epaperdisplay/EPaperDisplay.h +++ b/shared-bindings/epaperdisplay/EPaperDisplay.h @@ -26,7 +26,7 @@ void common_hal_epaperdisplay_epaperdisplay_construct(epaperdisplay_epaperdispla uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time, const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, - bool always_toggle_chip_select, bool grayscale, bool acep, bool two_byte_sequence_length, + bool always_toggle_chip_select, bool grayscale, bool acep, bool spectra6, bool two_byte_sequence_length, bool address_little_endian); bool common_hal_epaperdisplay_epaperdisplay_refresh(epaperdisplay_epaperdisplay_obj_t *self); diff --git a/shared-bindings/keypad/EventQueue.c b/shared-bindings/keypad/EventQueue.c index 67d742c3dcd7a..a899c652bc546 100644 --- a/shared-bindings/keypad/EventQueue.c +++ b/shared-bindings/keypad/EventQueue.c @@ -23,7 +23,8 @@ //| //| def get(self) -> Optional[Event]: -//| """Return the next key transition event. Return ``None`` if no events are pending. +//| """Remove the next key transition event from the `EventQueue` and return it. +//| Return ``None`` if no events are pending. //| //| Note that the queue size is limited; see ``max_events`` in the constructor of //| a scanner such as `Keys` or `KeyMatrix`. @@ -43,7 +44,7 @@ static mp_obj_t keypad_eventqueue_get(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(keypad_eventqueue_get_obj, keypad_eventqueue_get); //| def get_into(self, event: Event) -> bool: -//| """Store the next key transition event in the supplied event, if available, +//| """Remove the next key transition event from the ``EventQueue`, store it in ``event``, //| and return ``True``. //| If there are no queued events, do not touch ``event`` and return ``False``. //| diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index e58b75ba92877..e139e3a077ab2 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -103,10 +103,6 @@ static mp_obj_t socketpool_socketpool_socket(size_t n_args, const mp_obj_t *pos_ socketpool_socketpool_sock_t type = args[ARG_type].u_int; socketpool_socketpool_ipproto_t proto = args[ARG_proto].u_int; - if (proto < 0) { - proto = 0; - } - return common_hal_socketpool_socket(self, family, type, proto); } MP_DEFINE_CONST_FUN_OBJ_KW(socketpool_socketpool_socket_obj, 1, socketpool_socketpool_socket); diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index 570449ad424a4..ccdd588578125 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -88,8 +88,7 @@ static mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n fontio_builtinfont_t *font = mp_arg_validate_type(args[ARG_font].u_obj, &fontio_builtinfont_type, MP_QSTR_font); - mp_arg_validate_int_min(scroll_area->width_in_tiles, 2, MP_QSTR_scroll_area_width); - mp_arg_validate_int_min(scroll_area->height_in_tiles, 2, MP_QSTR_scroll_area_height); + mp_arg_validate_int_min(scroll_area->width_in_tiles * scroll_area->height_in_tiles, 2, MP_QSTR_scroll_area_area); terminalio_terminal_obj_t *self = mp_obj_malloc(terminalio_terminal_obj_t, &terminalio_terminal_type); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 968c3bbddb693..35b3556db35b2 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -98,11 +98,10 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // read is where we read previous echo from delay_ms ago to play back now // write is where the store the latest playing sample to echo back later - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); - self->echo_buffer_write_pos = 0; + self->echo_buffer_left_pos = 0; - // where we read the previous echo from delay_ms ago to play back now (for freq shift) - self->echo_buffer_left_pos = self->echo_buffer_right_pos = 0; + // use a separate buffer position for the right channel + self->echo_buffer_right_pos = 0; } void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self) { @@ -128,30 +127,32 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { // Require that delay is at least 1 sample long f_delay_ms = MAX(f_delay_ms, self->sample_ms); + // Calculate the maximum buffer size per channel in bytes + uint32_t max_echo_buffer_len = self->max_echo_buffer_len >> (self->base.channel_count - 1); + if (self->freq_shift) { // Calculate the rate of iteration over the echo buffer with 8 sub-bits self->echo_buffer_rate = (uint32_t)MAX(self->max_delay_ms / f_delay_ms * MICROPY_FLOAT_CONST(256.0), MICROPY_FLOAT_CONST(1.0)); - self->echo_buffer_len = self->max_echo_buffer_len; + // Only use half of the buffer per channel if stereo + self->echo_buffer_len = max_echo_buffer_len; } else { // Calculate the current echo buffer length in bytes - uint32_t new_echo_buffer_len = (uint32_t)(self->base.sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->base.channel_count * sizeof(uint16_t)); - - // Check if our new echo is too long for our maximum buffer - if (new_echo_buffer_len > self->max_echo_buffer_len) { - return; - } else if (new_echo_buffer_len < 0.0) { // or too short! - return; - } - - // If the echo buffer is larger then our audio buffer weird things happen - if (new_echo_buffer_len < self->buffer_len) { - return; + uint32_t new_echo_buffer_len = (uint32_t)(self->base.sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * sizeof(uint16_t); + + // Limit to valid range + if (new_echo_buffer_len > max_echo_buffer_len) { + new_echo_buffer_len = max_echo_buffer_len; + } else if (new_echo_buffer_len < self->buffer_len) { + // If the echo buffer is smaller than our audio buffer, weird things happen + new_echo_buffer_len = self->buffer_len; } self->echo_buffer_len = new_echo_buffer_len; // Clear the now unused part of the buffer or some weird artifacts appear - memset(self->echo_buffer + self->echo_buffer_len, 0, self->max_echo_buffer_len - self->echo_buffer_len); + for (uint32_t i = 0; i < self->base.channel_count; i++) { + memset(self->echo_buffer + (i * max_echo_buffer_len) + self->echo_buffer_len, 0, max_echo_buffer_len - self->echo_buffer_len); + } } self->current_delay_ms = f_delay_ms; @@ -178,6 +179,12 @@ bool common_hal_audiodelays_echo_get_freq_shift(audiodelays_echo_obj_t *self) { } void common_hal_audiodelays_echo_set_freq_shift(audiodelays_echo_obj_t *self, bool freq_shift) { + // Clear the echo buffer and reset buffer position if changing freq_shift modes + if (self->freq_shift != freq_shift) { + memset(self->echo_buffer, 0, self->max_echo_buffer_len); + self->echo_buffer_left_pos = 0; + self->echo_buffer_right_pos = 0; + } self->freq_shift = freq_shift; uint32_t delay_ms = (uint32_t)synthio_block_slot_get(&self->delay_ms); recalculate_delay(self, delay_ms); @@ -277,15 +284,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); - - // Set our echo buffer position accounting for stereo - uint32_t echo_buffer_pos = 0; - if (self->freq_shift) { - echo_buffer_pos = self->echo_buffer_left_pos; - if (channel == 1) { - echo_buffer_pos = self->echo_buffer_right_pos; - } - } + uint32_t max_echo_buf_len = (self->max_echo_buffer_len >> (self->base.channel_count - 1)) / sizeof(uint16_t); // If we have no sample keep the echo echoing if (self->sample == NULL) { @@ -309,18 +308,22 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * int16_t echo, word = 0; uint32_t next_buffer_pos = 0; + // Get our echo buffer position and offset depending on current channel + uint32_t echo_buffer_offset = max_echo_buf_len * ((single_channel_output && channel == 1) || (!single_channel_output && (i % self->base.channel_count) == 1)); + uint32_t echo_buffer_pos = echo_buffer_offset ? self->echo_buffer_right_pos : self->echo_buffer_left_pos; + if (self->freq_shift) { - echo = echo_buffer[echo_buffer_pos >> 8]; + echo = echo_buffer[(echo_buffer_pos >> 8) + echo_buffer_offset]; next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - word = (int16_t)(echo_buffer[j % echo_buf_len] * decay); - echo_buffer[j % echo_buf_len] = word; + word = (int16_t)(echo_buffer[(j % echo_buf_len) + echo_buffer_offset] * decay); + echo_buffer[(j % echo_buf_len) + echo_buffer_offset] = word; } } else { - echo = echo_buffer[self->echo_buffer_read_pos++]; + echo = echo_buffer[echo_buffer_pos + echo_buffer_offset]; word = (int16_t)(echo * decay); - echo_buffer[self->echo_buffer_write_pos++] = word; + echo_buffer[echo_buffer_pos++ + echo_buffer_offset] = word; } word = (int16_t)(echo * mix); @@ -339,13 +342,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->freq_shift) { echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); + } else if (!self->freq_shift && echo_buffer_pos >= echo_buf_len) { + echo_buffer_pos = 0; + } + + // Update buffer position + if (echo_buffer_offset) { + self->echo_buffer_right_pos = echo_buffer_pos; } else { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + self->echo_buffer_left_pos = echo_buffer_pos; } } } @@ -380,37 +385,42 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * int32_t echo, word = 0; uint32_t next_buffer_pos = 0; + + // Get our echo buffer position and offset depending on current channel + uint32_t echo_buffer_offset = max_echo_buf_len * ((single_channel_output && channel == 1) || (!single_channel_output && (i % self->base.channel_count) == 1)); + uint32_t echo_buffer_pos = echo_buffer_offset ? self->echo_buffer_right_pos : self->echo_buffer_left_pos; + if (self->freq_shift) { - echo = echo_buffer[echo_buffer_pos >> 8]; + echo = echo_buffer[(echo_buffer_pos >> 8) + echo_buffer_offset]; next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; } else { - echo = echo_buffer[self->echo_buffer_read_pos++]; + echo = echo_buffer[echo_buffer_pos + echo_buffer_offset]; word = (int32_t)(echo * decay + sample_word); } if (MP_LIKELY(self->base.bits_per_sample == 16)) { if (self->freq_shift) { for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - word = (int32_t)(echo_buffer[j % echo_buf_len] * decay + sample_word); + word = (int32_t)(echo_buffer[(j % echo_buf_len) + echo_buffer_offset] * decay + sample_word); word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2)); - echo_buffer[j % echo_buf_len] = (int16_t)word; + echo_buffer[(j % echo_buf_len) + echo_buffer_offset] = (int16_t)word; } } else { word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2)); - echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; + echo_buffer[echo_buffer_pos++ + echo_buffer_offset] = (int16_t)word; } } else { if (self->freq_shift) { for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - word = (int32_t)(echo_buffer[j % echo_buf_len] * decay + sample_word); + word = (int32_t)(echo_buffer[(j % echo_buf_len) + echo_buffer_offset] * decay + sample_word); // Do not have mix_down for 8 bit so just hard cap samples into 1 byte word = MIN(MAX(word, -128), 127); - echo_buffer[j % echo_buf_len] = (int8_t)word; + echo_buffer[(j % echo_buf_len) + echo_buffer_offset] = (int8_t)word; } } else { // Do not have mix_down for 8 bit so just hard cap samples into 1 byte word = MIN(MAX(word, -128), 127); - echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word; + echo_buffer[echo_buffer_pos++ + echo_buffer_offset] = (int8_t)word; } } @@ -433,13 +443,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->freq_shift) { echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); + } else if (!self->freq_shift && echo_buffer_pos >= echo_buf_len) { + echo_buffer_pos = 0; + } + + // Update buffer position + if (echo_buffer_offset) { + self->echo_buffer_right_pos = echo_buffer_pos; } else { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + self->echo_buffer_left_pos = echo_buffer_pos; } } } @@ -451,14 +463,6 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * self->sample_remaining_buffer += (n * (self->base.bits_per_sample / 8)); self->sample_buffer_length -= n; } - - if (self->freq_shift) { - if (channel == 0) { - self->echo_buffer_left_pos = echo_buffer_pos; - } else if (channel == 1) { - self->echo_buffer_right_pos = echo_buffer_pos; - } - } } // Finally pass our buffer and length to the calling audio function diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index 7f5dbb69f090a..cc37f7030be0e 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -37,12 +37,9 @@ typedef struct { uint32_t echo_buffer_len; // bytes uint32_t max_echo_buffer_len; // bytes - uint32_t echo_buffer_read_pos; // words - uint32_t echo_buffer_write_pos; // words - + uint32_t echo_buffer_left_pos; // words (<< 8 when freq_shift=True) + uint32_t echo_buffer_right_pos; // words (<< 8 when freq_shift=True) uint32_t echo_buffer_rate; // words << 8 - uint32_t echo_buffer_left_pos; // words << 8 - uint32_t echo_buffer_right_pos; // words << 8 mp_obj_t sample; } audiodelays_echo_obj_t; diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c index 49bd4835e8855..3710b8252164d 100644 --- a/shared-module/audiomp3/MP3Decoder.c +++ b/shared-module/audiomp3/MP3Decoder.c @@ -385,7 +385,7 @@ void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, mp_obj_t self->base.channel_count = fi.nChans; self->base.single_buffer = false; self->base.bits_per_sample = 16; - self->base.samples_signed = false; + self->base.samples_signed = true; self->base.max_buffer_length = fi.outputSamps * sizeof(int16_t); self->len = 2 * self->base.max_buffer_length; self->samples_decoded = 0; diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index cf5136f4e6bb6..ae7d3f02d5127 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -91,6 +91,40 @@ uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888) { return hue; } +uint8_t displayio_colorconverter_compute_sixcolor(uint32_t color_rgb888) { + // This is DDX=1, the default for the displays. + uint8_t chroma = displayio_colorconverter_compute_chroma(color_rgb888); + if (chroma >= 64) { + uint8_t hue = displayio_colorconverter_compute_hue(color_rgb888); + // Red 0 + if (hue < 10) { + return 0x3; + } + // Yellow 42 + if (hue < 42 + 21) { + return 0x2; + } + // Green 85 + if (hue < 85 + 42) { + return 0x6; + } + // Blue 170 + if (hue < 170 + 42) { + return 0x5; + } + + // The rest is red to 255 + return 0x3; + } else { + uint8_t luma = displayio_colorconverter_compute_luma(color_rgb888); + if (luma >= 128) { + return 0x1; // White + } else { + return 0x0; // Black + } + } +} + uint8_t displayio_colorconverter_compute_sevencolor(uint32_t color_rgb888) { // This is DDX=1, the default for the displays. uint8_t chroma = displayio_colorconverter_compute_chroma(color_rgb888); @@ -309,7 +343,9 @@ void displayio_convert_color(const _displayio_colorspace_t *colorspace, bool dit return; } else if (colorspace->depth == 4) { uint8_t packed; - if (colorspace->sevencolor) { + if (colorspace->sixcolor) { + packed = displayio_colorconverter_compute_sixcolor(pixel); + } else if (colorspace->sevencolor) { packed = displayio_colorconverter_compute_sevencolor(pixel); } else { packed = displayio_colorconverter_compute_rgbd(pixel); diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index 60efc132f9ae5..d3dbedfe160ab 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -41,5 +41,6 @@ uint8_t displayio_colorconverter_compute_rgbd(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_chroma(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888); +uint8_t displayio_colorconverter_compute_sixcolor(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_sevencolor(uint32_t color_rgb888); void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t *colorspace, uint8_t pixel_hue, uint32_t *color); diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 092b934b66a24..bb87a93d98133 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -19,6 +19,7 @@ typedef struct { uint8_t grayscale_bit; // The lowest grayscale bit. Normally 8 - depth. bool grayscale; bool tricolor; + bool sixcolor; // Spectra6 e-ink screens. bool sevencolor; // Acep e-ink screens. bool pixels_in_byte_share_row; bool reverse_pixels_in_byte; diff --git a/shared-module/epaperdisplay/EPaperDisplay.c b/shared-module/epaperdisplay/EPaperDisplay.c index 14fbc3341b5ff..748297cc638de 100644 --- a/shared-module/epaperdisplay/EPaperDisplay.c +++ b/shared-module/epaperdisplay/EPaperDisplay.c @@ -36,7 +36,7 @@ void common_hal_epaperdisplay_epaperdisplay_construct(epaperdisplay_epaperdispla uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time, const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, - bool chip_select, bool grayscale, bool acep, bool two_byte_sequence_length, bool address_little_endian) { + bool chip_select, bool grayscale, bool acep, bool spectra6, bool two_byte_sequence_length, bool address_little_endian) { uint16_t color_depth = 1; bool core_grayscale = true; if (highlight_color != 0x000000) { @@ -46,9 +46,10 @@ void common_hal_epaperdisplay_epaperdisplay_construct(epaperdisplay_epaperdispla } else { self->core.colorspace.tricolor = false; } - self->acep = acep; + self->acep = acep || spectra6; + self->core.colorspace.sixcolor = spectra6; self->core.colorspace.sevencolor = acep; - if (acep) { + if (self->acep) { color_depth = 4; // bits. 7 colors + clean grayscale = false; core_grayscale = false; @@ -338,7 +339,7 @@ static bool epaperdisplay_epaperdisplay_refresh_area(epaperdisplay_epaperdisplay } else if (self->core.colorspace.tricolor) { self->core.colorspace.grayscale = false; displayio_display_core_fill_area(&self->core, &subrectangle, mask, buffer); - } else if (self->core.colorspace.sevencolor) { + } else if (self->core.colorspace.sixcolor || self->core.colorspace.sevencolor) { displayio_display_core_fill_area(&self->core, &subrectangle, mask, buffer); } } else { diff --git a/shared-module/keypad/EventQueue.c b/shared-module/keypad/EventQueue.c index ad1134417b858..e5b362a045ddf 100644 --- a/shared-module/keypad/EventQueue.c +++ b/shared-module/keypad/EventQueue.c @@ -13,9 +13,11 @@ #define EVENT_PRESSED (1 << 15) #define EVENT_KEY_NUM_MASK ((1 << 15) - 1) +#define EVENT_SIZE_BYTES (sizeof(uint16_t) + sizeof(mp_obj_t)) + void common_hal_keypad_eventqueue_construct(keypad_eventqueue_obj_t *self, size_t max_events) { // Event queue is 16-bit values. - ringbuf_alloc(&self->encoded_events, max_events * (sizeof(uint16_t) + sizeof(mp_obj_t))); + ringbuf_alloc(&self->encoded_events, max_events * EVENT_SIZE_BYTES); self->overflowed = false; self->event_handler = NULL; } @@ -63,7 +65,7 @@ void common_hal_keypad_eventqueue_clear(keypad_eventqueue_obj_t *self) { } size_t common_hal_keypad_eventqueue_get_length(keypad_eventqueue_obj_t *self) { - return ringbuf_num_filled(&self->encoded_events); + return ringbuf_num_filled(&self->encoded_events) / EVENT_SIZE_BYTES; } void common_hal_keypad_eventqueue_set_event_handler(keypad_eventqueue_obj_t *self, void (*event_handler)(keypad_eventqueue_obj_t *)) { diff --git a/shared-module/usb_cdc/Serial.c b/shared-module/usb_cdc/Serial.c index 3c67103afcee9..348729365c2fc 100644 --- a/shared-module/usb_cdc/Serial.c +++ b/shared-module/usb_cdc/Serial.c @@ -19,9 +19,7 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data, // Read up to len bytes immediately. // The number of bytes read will not be larger than what is already in the TinyUSB FIFO. uint32_t total_num_read = 0; - if (tud_cdc_n_connected(self->idx)) { - total_num_read = tud_cdc_n_read(self->idx, data, len); - } + total_num_read = tud_cdc_n_read(self->idx, data, len); if (wait_forever || wait_for_timeout) { // Continue filling the buffer past what we already read. @@ -48,9 +46,7 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data, data += num_read; // Try to read another batch of bytes. - if (tud_cdc_n_connected(self->idx)) { - num_read = tud_cdc_n_read(self->idx, data, len); - } + num_read = tud_cdc_n_read(self->idx, data, len); total_num_read += num_read; } } diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index bc57500ed7c3e..94b429b6ab650 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -298,7 +298,7 @@ char serial_read(void) { #if CIRCUITPY_WEB_WORKFLOW if (websocket_available()) { - char c = websocket_read_char(); + int c = websocket_read_char(); if (c != -1) { return c; } diff --git a/tests/circuitpython/issue9705.py b/tests/circuitpython/issue9705.py index 7a59ed46f2ccb..0c694cc1b9fb1 100644 --- a/tests/circuitpython/issue9705.py +++ b/tests/circuitpython/issue9705.py @@ -1,5 +1,4 @@ import audiomp3, audiocore -import ulab.numpy as np TEST_FILE = ( __file__.rsplit("/", 1)[0] @@ -7,19 +6,14 @@ ) -def normalized_rms_ulab(values): - values = np.frombuffer(values, dtype=np.int16) - # this function works with ndarrays only - minbuf = np.mean(values) - values = values - minbuf - samples_sum = np.sum(values * values) - return (samples_sum / len(values)) ** 0.5 +def loudness(values): + return sum(abs(a) for a in values) def print_frame_loudness(decoder, n): for i in range(n): result, buf = audiocore.get_buffer(decoder) - print(f"{i} {result} {normalized_rms_ulab(buf):5.0f}") + print(f"{i} {result} {loudness(buf):5.0f}") print() diff --git a/tests/circuitpython/issue9705.py.exp b/tests/circuitpython/issue9705.py.exp index 944fb65c8103f..b57f8e63395c6 100644 --- a/tests/circuitpython/issue9705.py.exp +++ b/tests/circuitpython/issue9705.py.exp @@ -1,16 +1,16 @@ 0 1 0 -1 1 4730 -2 1 27914 -3 1 28737 -4 1 29251 -5 1 29219 -6 1 28672 -7 1 28213 +1 1 25 +2 1 830 +3 1 880 +4 1 932 +5 1 892 +6 1 869 +7 1 839 0 1 0 -1 1 4730 +1 1 25 0 1 0 -1 1 4730 -2 1 27914 +1 1 25 +2 1 830