Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions ports/atmel-samd/common-hal/audioio/AudioOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
76 changes: 35 additions & 41 deletions ports/espressif/common-hal/audioio/AudioOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -492,24 +517,15 @@ 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 &&
right_channel_pin == &pin_CHANNEL_0)) {
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;
Expand Down Expand Up @@ -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) {

Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ports/espressif/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ports/espressif/common-hal/pulseio/PulseOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions ports/raspberrypi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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/ \
Expand All @@ -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/ \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/audio_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/audio_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/bindings/cyw43/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/boardsource_blok/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/jpconstantineau_pykey18/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/jpconstantineau_pykey44/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/jpconstantineau_pykey60/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/jpconstantineau_pykey87/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/ugame22/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/wk-50/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/boards/zrichard_rp2.65-f/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions ports/raspberrypi/boot_stage2/RP2040.c.jinja
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions ports/raspberrypi/common-hal/analogbufio/BufferedIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading