Skip to content

Commit f9c7622

Browse files
authored
Merge pull request #3733 from jepler/audioout-esp32
esp32s2: Add I2SAudioOut
2 parents 4be5e91 + 1ca29ec commit f9c7622

File tree

22 files changed

+853
-9
lines changed

22 files changed

+853
-9
lines changed

locale/circuitpython.pot

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ msgstr ""
113113
msgid "%q() takes %d positional arguments but %d were given"
114114
msgstr ""
115115

116+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
117+
#, c-format
118+
msgid "%s error 0x%x"
119+
msgstr ""
120+
116121
#: py/argcheck.c
117122
msgid "'%q' argument required"
118123
msgstr ""
@@ -539,6 +544,10 @@ msgstr ""
539544
msgid "CBC blocks must be multiples of 16 bytes"
540545
msgstr ""
541546

547+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
548+
msgid "CRC or checksum was invalid"
549+
msgstr ""
550+
542551
#: py/objtype.c
543552
msgid "Call super().__init__() before accessing native object."
544553
msgstr ""
@@ -987,6 +996,10 @@ msgstr ""
987996
msgid "Function requires lock"
988997
msgstr ""
989998

999+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1000+
msgid "Generic Failure"
1001+
msgstr ""
1002+
9901003
#: shared-bindings/displayio/Display.c
9911004
#: shared-bindings/displayio/EPaperDisplay.c
9921005
#: shared-bindings/framebufferio/FramebufferDisplay.c
@@ -1113,6 +1126,7 @@ msgstr ""
11131126
msgid "Invalid Pin"
11141127
msgstr ""
11151128

1129+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
11161130
#: py/moduerrno.c shared-module/rgbmatrix/RGBMatrix.c
11171131
msgid "Invalid argument"
11181132
msgstr ""
@@ -1222,6 +1236,14 @@ msgstr ""
12221236
msgid "Invalid security_mode"
12231237
msgstr ""
12241238

1239+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1240+
msgid "Invalid size"
1241+
msgstr ""
1242+
1243+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1244+
msgid "Invalid state"
1245+
msgstr ""
1246+
12251247
#: shared-bindings/audiomixer/Mixer.c
12261248
msgid "Invalid voice"
12271249
msgstr ""
@@ -1262,6 +1284,10 @@ msgstr ""
12621284
msgid "Length must be non-negative"
12631285
msgstr ""
12641286

1287+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1288+
msgid "MAC address was invalid"
1289+
msgstr ""
1290+
12651291
#: shared-module/bitbangio/SPI.c
12661292
msgid "MISO pin init failed."
12671293
msgstr ""
@@ -1504,6 +1530,18 @@ msgstr ""
15041530
msgid "Only raw int supported for ip"
15051531
msgstr ""
15061532

1533+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1534+
msgid "Operation or feature not supported"
1535+
msgstr ""
1536+
1537+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1538+
msgid "Operation timed out"
1539+
msgstr ""
1540+
1541+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1542+
msgid "Out of memory"
1543+
msgstr ""
1544+
15071545
#: ports/esp32s2/common-hal/socketpool/SocketPool.c
15081546
msgid "Out of sockets"
15091547
msgstr ""
@@ -1512,6 +1550,10 @@ msgstr ""
15121550
msgid "Oversample must be multiple of 8."
15131551
msgstr ""
15141552

1553+
#: shared-bindings/audiobusio/PDMIn.c
1554+
msgid "PDMIn not available"
1555+
msgstr ""
1556+
15151557
#: shared-bindings/pwmio/PWMOut.c
15161558
msgid ""
15171559
"PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)"
@@ -1528,6 +1570,10 @@ msgstr ""
15281570
msgid "ParallelBus not yet supported"
15291571
msgstr ""
15301572

1573+
#: ports/esp32s2/common-hal/audiobusio/__init__.c
1574+
msgid "Peripheral in use"
1575+
msgstr ""
1576+
15311577
#: py/moduerrno.c
15321578
msgid "Permission denied"
15331579
msgstr ""
@@ -1645,6 +1691,10 @@ msgstr ""
16451691
msgid "Read-only object"
16461692
msgstr ""
16471693

1694+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1695+
msgid "Received response was invalid"
1696+
msgstr ""
1697+
16481698
#: shared-bindings/displayio/EPaperDisplay.c
16491699
msgid "Refresh too soon"
16501700
msgstr ""
@@ -1657,6 +1707,10 @@ msgstr ""
16571707
msgid "Requested AES mode is unsupported"
16581708
msgstr ""
16591709

1710+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
1711+
msgid "Requested resource not found"
1712+
msgstr ""
1713+
16601714
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
16611715
msgid "Right channel unsupported"
16621716
msgstr ""
@@ -2027,6 +2081,10 @@ msgstr ""
20272081
msgid "Value length > max_length"
20282082
msgstr ""
20292083

2084+
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
2085+
msgid "Version was invalid"
2086+
msgstr ""
2087+
20302088
#: py/emitnative.c
20312089
msgid "Viper functions don't currently support more than 4 arguments"
20322090
msgstr ""
@@ -3869,6 +3927,10 @@ msgstr ""
38693927
msgid "x value out of bounds"
38703928
msgstr ""
38713929

3930+
#: ports/esp32s2/common-hal/audiobusio/__init__.c
3931+
msgid "xTaskCreate failed"
3932+
msgstr ""
3933+
38723934
#: shared-bindings/displayio/Shape.c
38733935
msgid "y should be an int"
38743936
msgstr ""

ports/esp32s2/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld $(BUILD)/esp-id
299299

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

302+
ESPTOOL_FLAGS ?= -b 460800 --before=default_reset --after=no_reset write_flash
303+
302304
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
303305

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

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

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

345347
include $(TOP)/py/mkrules.mk
346348

ports/esp32s2/bindings/espidf/__init__.c

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
6565
}
6666
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
6767

68-
//| class MemoryError(MemoryError):
69-
//| """Raised when an ESP IDF memory allocation fails."""
68+
//| class IDFError(OSError):
69+
//| """Raised for certain generic ESP IDF errors."""
7070
//| ...
7171
//|
72-
NORETURN void mp_raise_espidf_MemoryError(void) {
73-
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
72+
NORETURN void mp_raise_espidf_IDFError(void) {
73+
nlr_raise(mp_obj_new_exception(&mp_type_espidf_IDFError));
7474
}
7575

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

86+
const mp_obj_type_t mp_type_espidf_IDFError = {
87+
{ &mp_type_type },
88+
.name = MP_QSTR_IDFError,
89+
.print = espidf_exception_print,
90+
.make_new = mp_obj_exception_make_new,
91+
.attr = mp_obj_exception_attr,
92+
.parent = &mp_type_OSError,
93+
};
94+
95+
96+
//| class MemoryError(MemoryError):
97+
//| """Raised when an ESP IDF memory allocation fails."""
98+
//| ...
99+
//|
100+
NORETURN void mp_raise_espidf_MemoryError(void) {
101+
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
102+
}
103+
86104
const mp_obj_type_t mp_type_espidf_MemoryError = {
87105
{ &mp_type_type },
88106
.name = MP_QSTR_MemoryError,
@@ -99,6 +117,7 @@ STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
99117
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
100118
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
101119

120+
{ MP_ROM_QSTR(MP_QSTR_IDFError), MP_ROM_PTR(&mp_type_espidf_IDFError) },
102121
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) },
103122
};
104123

@@ -108,3 +127,64 @@ const mp_obj_module_t espidf_module = {
108127
.base = { &mp_type_module },
109128
.globals = (mp_obj_dict_t*)&espidf_module_globals,
110129
};
130+
131+
void raise_esp_error(esp_err_t err) {
132+
const compressed_string_t *msg = NULL;
133+
const mp_obj_type_t * exception_type = &mp_type_espidf_IDFError;
134+
switch(err) {
135+
case ESP_FAIL:
136+
msg = translate("Generic Failure");
137+
break;
138+
case ESP_ERR_NO_MEM:
139+
exception_type = &mp_type_espidf_MemoryError;
140+
msg = translate("Out of memory");
141+
break;
142+
case ESP_ERR_INVALID_ARG:
143+
msg = translate("Invalid argument");
144+
break;
145+
case ESP_ERR_INVALID_STATE:
146+
msg = translate("Invalid state");
147+
break;
148+
case ESP_ERR_INVALID_SIZE:
149+
msg = translate("Invalid size");
150+
break;
151+
case ESP_ERR_NOT_FOUND:
152+
msg = translate("Requested resource not found");
153+
break;
154+
case ESP_ERR_NOT_SUPPORTED:
155+
msg = translate("Operation or feature not supported");
156+
break;
157+
case ESP_ERR_TIMEOUT:
158+
msg = translate("Operation timed out");
159+
break;
160+
case ESP_ERR_INVALID_RESPONSE:
161+
msg = translate("Received response was invalid");
162+
break;
163+
case ESP_ERR_INVALID_CRC:
164+
msg = translate("CRC or checksum was invalid");
165+
break;
166+
case ESP_ERR_INVALID_VERSION:
167+
msg = translate("Version was invalid");
168+
break;
169+
case ESP_ERR_INVALID_MAC:
170+
msg = translate("MAC address was invalid");
171+
break;
172+
}
173+
if (msg) {
174+
mp_raise_msg(exception_type, msg);
175+
}
176+
177+
const char *group = "ESP-IDF";
178+
179+
// tests must be in descending order
180+
MP_STATIC_ASSERT( ESP_ERR_FLASH_BASE > ESP_ERR_MESH_BASE );
181+
MP_STATIC_ASSERT( ESP_ERR_MESH_BASE > ESP_ERR_WIFI_BASE );
182+
if(err >= ESP_ERR_FLASH_BASE) {
183+
group = "Flash";
184+
} else if (err >= ESP_ERR_MESH_BASE) {
185+
group = "Mesh";
186+
} else if (err >= ESP_ERR_WIFI_BASE) {
187+
group = "WiFi";
188+
}
189+
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
190+
}

ports/esp32s2/bindings/espidf/__init__.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@
2727
#ifndef MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
2828
#define MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
2929

30+
#include "esp_err.h"
31+
#include "py/mpconfig.h"
32+
#include "py/obj.h"
33+
34+
extern const mp_obj_type_t mp_type_espidf_IDFError;
3035
extern const mp_obj_type_t mp_type_espidf_MemoryError;
3136

3237
NORETURN void mp_raise_espidf_MemoryError(void);
3338

39+
void raise_esp_error(esp_err_t err) NORETURN;
40+
#define CHECK_ESP_RESULT(x) do { int res = (x); if(res != ESP_OK) raise_esp_error(res); } while(0)
41+
3442
#endif // MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H

0 commit comments

Comments
 (0)