Skip to content

Commit 25216c8

Browse files
authored
Merge pull request #10195 from dhalbert/9.2.x
Merge 9.2.x to main
2 parents 14eb89a + f108587 commit 25216c8

File tree

70 files changed

+213
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+213
-213
lines changed

main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, siz
131131
*final_size = default_size;
132132
#if CIRCUITPY_OS_GETENV
133133
if (safe_mode == SAFE_MODE_NONE) {
134-
(void)common_hal_os_getenv_int(env_key, (mp_int_t *)final_size);
135-
if (*final_size < 0) {
136-
*final_size = default_size;
134+
mp_int_t size;
135+
if (common_hal_os_getenv_int(env_key, &size) == GETENV_OK && size > 0) {
136+
*final_size = size;
137137
}
138138
}
139139
#endif

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ static void ramp_value(uint16_t start, uint16_t end) {
7979
// Caller validates that pins are free.
8080
void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
8181
const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) {
82+
83+
// The case of left_channel == right_channel is already disallowed in shared-bindings.
84+
8285
#ifdef SAM_D5X_E5X
8386
bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK);
8487
#endif
@@ -107,10 +110,6 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
107110
if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) {
108111
raise_ValueError_invalid_pin_name(MP_QSTR_right_channel);
109112
}
110-
if (right_channel == left_channel) {
111-
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q and %q must be different"),
112-
MP_QSTR_left_channel, MP_QSTR_right_channel);
113-
}
114113
claim_pin(left_channel);
115114
if (right_channel != NULL) {
116115
claim_pin(right_channel);

ports/espressif/common-hal/audioio/AudioOut.c

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "driver/dac_continuous.h"
1313

14-
1514
#if defined(CONFIG_IDF_TARGET_ESP32)
1615
#define pin_CHANNEL_0 pin_GPIO25
1716
#define pin_CHANNEL_1 pin_GPIO26
@@ -304,6 +303,32 @@ static audioout_sample_convert_func_t audioout_get_samples_convert_func(
304303
}
305304
}
306305

306+
static void audioio_audioout_start(audioio_audioout_obj_t *self) {
307+
esp_err_t ret;
308+
309+
self->playing = true;
310+
self->paused = false;
311+
312+
ret = dac_continuous_start_async_writing(self->handle);
313+
if (ret != ESP_OK) {
314+
mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio"));
315+
}
316+
}
317+
318+
static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) {
319+
dac_continuous_stop_async_writing(self->handle);
320+
if (full_stop) {
321+
self->get_buffer_index = 0;
322+
self->put_buffer_index = 0;
323+
self->sample_buffer = NULL;
324+
self->sample = NULL;
325+
self->playing = false;
326+
self->paused = false;
327+
} else {
328+
self->paused = true;
329+
}
330+
}
331+
307332
static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
308333
if (!self->playing) {
309334
return false;
@@ -342,7 +367,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
342367
&raw_sample_buf, &raw_sample_buf_size);
343368

344369
if (get_buffer_result == GET_BUFFER_ERROR) {
345-
common_hal_audioio_audioout_stop(self);
370+
audioio_audioout_stop(self, true);
346371
return false;
347372
}
348373

@@ -390,7 +415,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
390415
} else {
391416
// TODO: figure out if it is ok to call this here or do we need
392417
// to somehow wait for all of the samples to be flushed
393-
common_hal_audioio_audioout_stop(self);
418+
audioio_audioout_stop(self, true);
394419
return false;
395420
}
396421
}
@@ -492,24 +517,15 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
492517
self->paused = false;
493518
self->freq_hz = DEFAULT_SAMPLE_RATE;
494519

495-
/* espressif has two dac channels and it can support true stereo or
496-
* outputting the same signal to both channels (dual mono).
497-
* if different pins are supplied for left and right then use true stereo.
498-
* if the same pin is supplied for left and right then use dual mono.
499-
*/
520+
// The case of left_channel == right_channel is already disallowed in shared-bindings.
521+
500522
if ((left_channel_pin == &pin_CHANNEL_0 &&
501523
right_channel_pin == &pin_CHANNEL_1) ||
502524
(left_channel_pin == &pin_CHANNEL_1 &&
503525
right_channel_pin == &pin_CHANNEL_0)) {
504526
self->channel_mask = DAC_CHANNEL_MASK_ALL;
505527
self->num_channels = 2;
506528
self->channel_mode = DAC_CHANNEL_MODE_ALTER;
507-
} else if ((left_channel_pin == &pin_CHANNEL_0 ||
508-
left_channel_pin == &pin_CHANNEL_1) &&
509-
right_channel_pin == left_channel_pin) {
510-
self->channel_mask = DAC_CHANNEL_MASK_ALL;
511-
self->num_channels = 1;
512-
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
513529
} else if (left_channel_pin == &pin_CHANNEL_0 &&
514530
right_channel_pin == NULL) {
515531
self->channel_mask = DAC_CHANNEL_MASK_CH0;
@@ -550,32 +566,6 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) {
550566
_active_handle = NULL;
551567
}
552568

553-
static void audioio_audioout_start(audioio_audioout_obj_t *self) {
554-
esp_err_t ret;
555-
556-
self->playing = true;
557-
self->paused = false;
558-
559-
ret = dac_continuous_start_async_writing(self->handle);
560-
if (ret != ESP_OK) {
561-
mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio"));
562-
}
563-
}
564-
565-
static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) {
566-
dac_continuous_stop_async_writing(self->handle);
567-
if (full_stop) {
568-
self->get_buffer_index = 0;
569-
self->put_buffer_index = 0;
570-
self->sample_buffer = NULL;
571-
self->sample = NULL;
572-
self->playing = false;
573-
self->paused = false;
574-
} else {
575-
self->paused = true;
576-
}
577-
}
578-
579569
void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
580570
mp_obj_t sample, bool loop) {
581571

@@ -597,7 +587,11 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
597587
self->looping = loop;
598588
freq_hz = audiosample_get_sample_rate(self->sample);
599589

600-
if (freq_hz != self->freq_hz) {
590+
// Workaround: always reset the DAC completely between plays,
591+
// due to a bug that causes the left and right channels to be swapped randomly.
592+
// See https://github.com/espressif/esp-idf/issues/11425
593+
// TODO: Remove the `true` when this issue is fixed.
594+
if (true || freq_hz != self->freq_hz) {
601595
common_hal_audioio_audioout_deinit(self);
602596
self->freq_hz = freq_hz;
603597
audioout_init(self);

ports/espressif/common-hal/pulseio/PulseIn.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
127127
}
128128

129129
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
130+
if (common_hal_pulseio_pulsein_deinited(self)) {
131+
return;
132+
}
130133
rmt_disable(self->channel);
131134
reset_pin_number(self->pin->number);
132135
rmt_del_channel(self->channel);

ports/espressif/common-hal/pulseio/PulseOut.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) {
5454
}
5555

5656
void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) {
57+
if (common_hal_pulseio_pulseout_deinited(self)) {
58+
return;
59+
}
5760
rmt_disable(self->channel);
5861
rmt_del_encoder(self->encoder);
5962
rmt_del_channel(self->channel);

ports/raspberrypi/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ HAL_DIR=hal/$(MCU_SERIES)
1212

1313
ifeq ($(CIRCUITPY_CYW43),1)
1414
INC_CYW43 := \
15+
-isystem lib/cyw43-driver \
1516
-isystem lib/cyw43-driver/firmware \
1617
-isystem lib/cyw43-driver/src \
1718
-isystem lib/lwip/src/include \
@@ -92,8 +93,6 @@ INC += \
9293
-I../shared/timeutils \
9394
-Iboards/$(BOARD) \
9495
-Iboards/ \
95-
-isystem ./../../lib/cmsis/inc \
96-
-isystem sdk/ \
9796
-isystem sdk/src/common/boot_picobin_headers/include/ \
9897
-isystem sdk/src/common/boot_picoboot_headers/include/ \
9998
-isystem sdk/src/common/hardware_claim/include/ \
@@ -107,6 +106,8 @@ INC += \
107106
-isystem sdk/src/$(CHIP_VARIANT_LOWER)/hardware_structs/include/ \
108107
-isystem sdk/src/$(CHIP_VARIANT_LOWER)/pico_platform/include/ \
109108
-isystem sdk/src/rp2_common/boot_bootrom_headers/include/ \
109+
-isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Core/Include/ \
110+
-isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Device/${CHIP_VARIANT}/Include \
110111
-isystem sdk/src/rp2_common/cmsis/ \
111112
-isystem sdk/src/rp2_common/hardware_adc/include/ \
112113
-isystem sdk/src/rp2_common/hardware_base/include/ \
@@ -153,7 +154,7 @@ INC += \
153154
-isystem sdk/src/rp2_common/pico_platform_panic/include/ \
154155
-isystem sdk/src/rp2_common/pico_time_adapter/include/ \
155156
-isystem sdk/src/rp2_common/pico_unique_id/include/ \
156-
$(INC_CYW43) \
157+
$(INC_CYW43) \
157158
-Isdk_config \
158159
-I../../lib/tinyusb/src \
159160
-I../../supervisor/shared/usb \
@@ -222,7 +223,7 @@ endif
222223

223224
DISABLE_WARNINGS = -Wno-cast-align
224225

225-
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes
226+
CFLAGS += $(INC) -Wtype-limits -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes
226227

227228
PICO_LDFLAGS = --specs=nosys.specs --specs=nano.specs
228229

ports/raspberrypi/audio_dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "py/mpstate.h"
1616
#include "py/runtime.h"
1717

18-
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
18+
#include "hardware/irq.h"
1919
#include "hardware/regs/intctrl.h" // For isr_ macro.
2020

2121

ports/raspberrypi/audio_dma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "py/obj.h"
1010
#include "supervisor/background_callback.h"
1111

12-
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
12+
#include "hardware/dma.h"
1313

1414
typedef enum {
1515
AUDIO_DMA_OK,

ports/raspberrypi/bindings/cyw43/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "shared-bindings/microcontroller/Pin.h"
1313
#include "bindings/cyw43/__init__.h"
1414

15-
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
15+
#include "hardware/gpio.h"
1616

1717
#include "lib/cyw43-driver/src/cyw43.h"
1818

ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "shared-module/displayio/mipi_constants.h"
1111
#include "shared-bindings/busio/SPI.h"
1212
#include "shared-bindings/microcontroller/Pin.h"
13-
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
13+
#include "hardware/gpio.h"
1414
#include "supervisor/board.h"
1515
#include "supervisor/shared/board.h"
1616

0 commit comments

Comments
 (0)