8000 esp32s2: Add I2SAudioOut by jepler · Pull Request #3733 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

esp32s2: Add I2SAudioOut #3733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d024df6
esp32s2: Use better optimizer flags in debug builds
jepler Nov 12, 2020
05ba143
esp32s2: espidf: Add IDFError
jepler Nov 20, 2020
b40a579
esp32s2: espidf: Consistent error checking of esp-idf calls
jepler Oct 30, 2020
537a4da
mark script as executable
jepler Oct 28, 2020
2cd377f
audiobusio: Make PDMIn optional
jepler Oct 28, 2020
a754259
esp32s2: add I2SOut
jepler Oct 30, 2020
42cad23
make translate
jepler Dec 29, 2020
30c6dd3
Merge remote-tracking branch 'origin/main' into audioout-esp32
jepler Jan 7, 2021
7bb196b
esp32s2: 'make flash': Allow customizing the esptool flags
jepler Jan 7, 2021
010a4e7
esp32s2: port: Ensure JTAG pins are available for debugging
jepler Jan 7, 2021
3522264
esp32s2: i2s: fix accounting for "stretched" frames
jepler Jan 7, 2021
d3afda6
esp32s2: i2s: must reset buffer, otherwise wave samples don't start
jepler Jan 7, 2021
cfd8288
esp2s2: enlarge stack-buffer, use it instead of i2s_zero_dma_buffer
jepler Jan 7, 2021
873a300
i2s_fill_buffer: Need to fill with zeros when stopping
jepler Jan 8, 2021
0b7a4c4
i2s_fill_buffer: remove debug print
jepler Jan 8, 2021
12264cc
port_i2s_play: remove build error
jepler Jan 8, 2021
430bcdb
port_i2s_play: fill the initial buffer via background callback
jepler Jan 8, 2021
5f0e41a
I2SOut: Enable ticks during audio playback
jepler Jan 8, 2021
10861b4
esp32s2: Rename ESP_CALL_RAISE to CHECK_ESP_RESULT
jepler Jan 9, 2021
4735cf4
esp32s2: audiobusio: move i2s_common inside
jepler Jan 9, 2021
e20c65d
background tasks: Add, use port_wake_main_task
jepler Jan 9, 2021
1ca29ec
Merge remote-tracking branch 'origin/main' into audioout-esp32
jepler Jan 12, 2021
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
64 changes: 63 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"POT-Creation-Date: 2021-01-07 14:11-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -114,6 +114,11 @@ msgstr ""
msgid "%q() takes %d positional arguments but %d were given"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
#, c-format
msgid "%s error 0x%x"
msgstr ""

#: py/argcheck.c
msgid "'%q' argument required"
msgstr ""
Expand Down Expand Up @@ -536,6 +541,10 @@ msgstr ""
msgid "CBC blocks must be multiples of 16 bytes"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "CRC or checksum was invalid"
msgstr ""

#: py/objtype.c
msgid "Call super().__init__() before accessing native object."
msgstr ""
Expand Down Expand Up @@ -984,6 +993,10 @@ msgstr ""
msgid "Function requires lock"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Generic Failure"
msgstr ""

#: shared-bindings/displayio/Display.c
#: shared-bindings/displayio/EPaperDisplay.c
#: shared-bindings/framebufferio/FramebufferDisplay.c
Expand Down Expand Up @@ -1110,6 +1123,7 @@ msgstr ""
msgid "Invalid Pin"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
#: py/moduerrno.c shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid argument"
msgstr ""
Expand Down Expand Up @@ -1219,6 +1233,14 @@ msgstr ""
msgid "Invalid security_mode"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Invalid size"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Invalid state"
msgstr ""

#: shared-bindings/audiomixer/Mixer.c
msgid "Invalid voice"
msgstr ""
Expand Down Expand Up @@ -1259,6 +1281,10 @@ msgstr ""
msgid "Length must be non-negative"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "MAC address was invalid"
msgstr ""

#: shared-module/bitbangio/SPI.c
msgid "MISO pin init failed."
msgstr ""
Expand Down Expand Up @@ -1501,6 +1527,18 @@ msgstr ""
msgid "Only raw int supported for ip"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Operation or feature not supported"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Operation timed out"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Out of memory"
msgstr ""

#: ports/esp32s2/common-hal/socketpool/SocketPool.c
msgid "Out of sockets"
msgstr ""
Expand All @@ -1509,6 +1547,10 @@ msgstr ""
msgid "Oversample must be multiple of 8."
msgstr ""

#: shared-bindings/audiobusio/PDMIn.c
msgid "PDMIn not available"
msgstr ""

#: shared-bindings/pwmio/PWMOut.c
msgid ""
"PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)"
Expand All @@ -1525,6 +1567,10 @@ msgstr ""
msgid "ParallelBus not yet supported"
msgstr ""

#: ports/esp32s2/i2s_common.c
msgid "Peripheral in use"
msgstr ""

#: py/moduerrno.c
msgid "Permission denied"
msgstr ""
Expand Down Expand Up @@ -1642,6 +1688,10 @@ msgstr ""
msgid "Read-only object"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Received response was invalid"
msgstr ""

#: shared-bindings/displayio/EPaperDisplay.c
msgid "Refresh too soon"
msgstr ""
Expand All @@ -1654,6 +1704,10 @@ msgstr ""
msgid "Requested AES mode is unsupported"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Requested resource not found"
msgstr ""

#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "Right channel unsupported"
msgstr ""
Expand Down Expand Up @@ -2024,6 +2078,10 @@ msgstr ""
msgid "Value length > max_length"
msgstr ""

#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Version was invalid"
msgstr ""

#: py/emitnative.c
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
Expand Down Expand Up @@ -3846,6 +3904,10 @@ msgstr ""
msgid "x value out of bounds"
msgstr ""

#: ports/esp32s2/i2s_common.c
msgid "xTaskCreate failed"
msgstr ""

#: shared-bindings/displayio/Shape.c
msgid "y should be an int"
msgstr ""
Expand Down
6 changes: 4 additions & 2 deletions ports/esp32s2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld $(BUILD)/esp-id

FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE)

ESPTOOL_FLAGS ?= -b 460800 --before=default_reset --after=no_reset write_flash

all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2

.PHONY: esp-idf-stamp
Expand Down Expand Up @@ -337,10 +339,10 @@ $(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin
$(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^

flash: $(BUILD)/firmware.bin
esptool.py --chip esp32s2 -p $(PORT) -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x0000 $^
esptool.py --chip esp32s2 -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x0000 $^

flash-circuitpython-only: $(BUILD)/circuitpython-firmware.bin
esptool.py --chip esp32s2 -p $(PORT) -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x10000 $^
esptool.py --chip esp32s2 -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x10000 $^

include $(TOP)/py/mkrules.mk

Expand Down
88 changes: 84 additions & 4 deletions ports/esp32s2/bindings/espidf/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);

//| class MemoryError(MemoryError):
//| """Raised when an ESP IDF memory allocation fails."""
//| class IDFError(OSError):
//| """Raised for certain generic ESP IDF errors."""
//| ...
//|
NORETURN void mp_raise_espidf_MemoryError(void) {
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
NORETURN void mp_raise_espidf_IDFError(void) {
nlr_raise(mp_obj_new_exception(&mp_type_espidf_IDFError));
}

void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
Expand All @@ -83,6 +83,24 @@ void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin
mp_obj_exception_print(print, o_in, kind);
}

const mp_obj_type_t mp_type_espidf_IDFError = {
{ &mp_type_type },
.name = MP_QSTR_IDFError,
.print = espidf_exception_print,
.make_new = mp_obj_exception_make_new,
.attr = mp_obj_exception_attr,
.parent = &mp_type_OSError,
};


//| class MemoryError(MemoryError):
//| """Raised when an ESP IDF memory allocation fails."""
//| ...
//|
NORETURN void mp_raise_espidf_MemoryError(void) {
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
}

const mp_obj_type_t mp_type_espidf_MemoryError = {
{ &mp_type_type },
.name = MP_QSTR_MemoryError,
Expand All @@ -99,6 +117,7 @@ STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},

{ MP_ROM_QSTR(MP_QSTR_IDFError), MP_ROM_PTR(&mp_type_espidf_IDFError) },
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) },
};

Expand All @@ -108,3 +127,64 @@ const mp_obj_module_t espidf_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&espidf_module_globals,
};

void raise_esp_error(esp_err_t err) {
const compressed_string_t *msg = NULL;
const mp_obj_type_t * exception_type = &mp_type_espidf_IDFError;
switch(err) {
case ESP_FAIL:
msg = translate("Generic Failure");
break;
case ESP_ERR_NO_MEM:
exception_type = &mp_type_espidf_MemoryError;
msg = translate("Out of memory");
break;
case ESP_ERR_INVALID_ARG:
msg = translate("Invalid argument");
break;
case ESP_ERR_INVALID_STATE:
msg = translate("Invalid state");
break;
case ESP_ERR_INVALID_SIZE:
msg = translate("Invalid size");
break;
case ESP_ERR_NOT_FOUND:
msg = translate("Requested resource not found");
break;
case ESP_ERR_NOT_SUPPORTED:
msg = translate("Operation or feature not supported");
break;
case ESP_ERR_TIMEOUT:
msg = translate("Operation timed out");
break;
case ESP_ERR_INVALID_RESPONSE:
msg = translate("Received response was invalid");
break;
case ESP_ERR_INVALID_CRC:
msg = translate("CRC or checksum was invalid");
break;
case ESP_ERR_INVALID_VERSION:
msg = translate("Version was invalid");
break;
case ESP_ERR_INVALID_MAC:
msg = translate("MAC address was invalid");
break;
}
if (msg) {
mp_raise_msg(exception_type, msg);
}

const char *group = "ESP-IDF";

// tests must be in descending order
MP_STATIC_ASSERT( ESP_ERR_FLASH_BASE > ESP_ERR_MESH_BASE );
MP_STATIC_ASSERT( ESP_ERR_MESH_BASE > ESP_ERR_WIFI_BASE );
if(err >= ESP_ERR_FLASH_BASE) {
group = "Flash";
} else if (err >= ESP_ERR_MESH_BASE) {
group = "Mesh";
} else if (err >= ESP_ERR_WIFI_BASE) {
group = "WiFi";
}
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
}
8 changes: 8 additions & 0 deletions 91CA ports/esp32s2/bindings/espidf/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@
#ifndef MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
#define MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H

#include "esp_err.h"
#include "py/mpconfig.h"
#include "py/obj.h"

extern const mp_obj_type_t mp_type_espidf_IDFError;
extern const mp_obj_type_t mp_type_espidf_MemoryError;

NORETURN void mp_raise_espidf_MemoryError(void);

void raise_esp_error(esp_err_t err) NORETURN;
#define CHECK_ESP_RESULT(x) do { int res = (x); if(res != ESP_OK) raise_esp_error(res); } while(0)

#endif // MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
Loading
0