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/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/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..a20b16473174c 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); 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/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..6862f2799f28f 100644 --- a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c +++ b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c @@ -11,9 +11,9 @@ #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" +#include "hardware/adc.h" +#include "hardware/dma.h" +#include "pico/stdlib.h" #define ADC_FIRST_PIN_NUMBER 26 #define ADC_PIN_COUNT 4 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..9d107c8d14b91 100644 --- a/ports/raspberrypi/common-hal/analogio/AnalogIn.c +++ b/ports/raspberrypi/common-hal/analogio/AnalogIn.c @@ -10,7 +10,7 @@ #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) 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/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/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-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/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