Skip to content

Commit 931f25d

Browse files
committed
Add audiobusio.I2SOut() support to Zephyr
Relies on added SDL audio emulation.
1 parent 99b1e14 commit 931f25d

40 files changed

Lines changed: 878 additions & 88 deletions

locale/circuitpython.pot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ msgstr ""
24192419
msgid "Use board.DISPLAY"
24202420
msgstr ""
24212421

2422+
#: ports/zephyr-cp/common-hal/audiobusio/I2SOut.c
24222423
#: ports/zephyr-cp/common-hal/busio/I2C.c
24232424
#: ports/zephyr-cp/common-hal/busio/SPI.c
24242425
#: ports/zephyr-cp/common-hal/busio/UART.c

ports/zephyr-cp/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ifeq ($(DEBUG),1)
2121
WEST_CMAKE_ARGS += -Dzephyr-cp_EXTRA_CONF_FILE=$(DEBUG_CONF_FILE)
2222
endif
2323

24-
.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash recover debug debug-jlink debugserver attach run run-sim clean menuconfig all clean-all test fetch-port-submodules
24+
.PHONY: $(BUILD)/zephyr-cp/zephyr/zephyr.elf flash recover debug attach debug-jlink debugserver attach run run-sim clean menuconfig all clean-all test fetch-port-submodules
2525

2626
$(BUILD)/zephyr-cp/zephyr/zephyr.elf:
2727
python cptools/pre_zephyr_build_prep.py $(BOARD)
@@ -68,7 +68,7 @@ run-sim:
6868
echo "Populating build-native_native_sim/flash.bin from ./CIRCUITPY"; \
6969
mcopy -s -i build-native_native_sim/flash.bin CIRCUITPY/* ::; \
7070
fi
71-
build-native_native_sim/firmware.exe --flash=build-native_native_sim/flash.bin --flash_rm -wait_uart -rt
71+
build-native_native_sim/firmware.exe --flash=build-native_native_sim/flash.bin --flash_rm -wait_uart -rt --i2s_capture=build-native_native_sim/i2s_capture.wav
7272

7373
menuconfig:
7474
west build $(WEST_SHIELD_ARGS) --sysbuild -d $(BUILD) -t menuconfig -- $(WEST_CMAKE_ARGS)

ports/zephyr-cp/background.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@
99
#include "py/runtime.h"
1010
#include "supervisor/port.h"
1111

12-
#if CIRCUITPY_DISPLAYIO
13-
#include "shared-module/displayio/__init__.h"
14-
#endif
15-
16-
#if CIRCUITPY_AUDIOBUSIO
17-
#include "common-hal/audiobusio/I2SOut.h"
18-
#endif
19-
20-
#if CIRCUITPY_AUDIOPWMIO
21-
#include "common-hal/audiopwmio/PWMAudioOut.h"
22-
#endif
12+
#include <zephyr/kernel.h>
2313

2414
void port_start_background_tick(void) {
2515
}
@@ -28,12 +18,7 @@ void port_finish_background_tick(void) {
2818
}
2919

3020
void port_background_tick(void) {
31-
#if CIRCUITPY_AUDIOPWMIO
32-
audiopwmout_background();
33-
#endif
34-
#if CIRCUITPY_AUDIOBUSIO
35-
i2s_background();
36-
#endif
21+
// No, ticks. We use Zephyr threads instead.
3722
}
3823

3924
void port_background_task(void) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DMA_TCD_QUEUE_SIZE=4
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
&w25q512jvfiq {
2+
partitions {
3+
/delete-node/ storage_partition;
4+
circuitpy_partition: partition@620000 {
5+
label = "circuitpy";
6+
reg = <0x00620000 (DT_SIZE_M(58) - DT_SIZE_K(128))>;
7+
};
8+
}
9+
10+
};
11+
12+
#include "../app.overlay"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_DMA_TCD_QUEUE_SIZE=4

ports/zephyr-cp/boards/mimxrt1170_evk_mimxrt1176_cm7.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
};
99
};
1010

11+
&sai1 {
12+
mclk-output;
13+
};
14+
1115
#include "../app.overlay"

ports/zephyr-cp/boards/native/native_sim/autogen_board_info.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ alarm = false
1515
analogbufio = false
1616
analogio = false
1717
atexit = false
18-
audiobusio = false
19-
audiocore = false
20-
audiodelays = false
21-
audiofilters = false
22-
audiofreeverb = false
18+
audiobusio = true # Zephyr board has audiobusio
19+
audiocore = true # Zephyr board has audiobusio
20+
audiodelays = true # Zephyr board has audiobusio
21+
audiofilters = true # Zephyr board has audiobusio
22+
audiofreeverb = true # Zephyr board has audiobusio
2323
audioio = false
24-
audiomixer = false
25-
audiomp3 = false
24+
audiomixer = true # Zephyr board has audiobusio
25+
audiomp3 = true # Zephyr board has audiobusio
2626
audiopwmio = false
2727
aurora_epaper = false
2828
bitbangio = false
@@ -62,7 +62,7 @@ keypad = false
6262
keypad_demux = false
6363
locale = false
6464
lvfontio = true # Zephyr board has busio
65-
math = false
65+
math = true
6666
max3421e = false
6767
mdns = false
6868
memorymap = false
@@ -94,7 +94,7 @@ ssl = false
9494
storage = true # Zephyr board has flash
9595
struct = true
9696
supervisor = true
97-
synthio = false
97+
synthio = true # Zephyr board has audiobusio
9898
terminalio = true # Zephyr board has busio
9999
tilepalettemapper = true # Zephyr board has busio
100100
time = true

ports/zephyr-cp/boards/native_sim.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ CONFIG_EEPROM=y
2323
CONFIG_EEPROM_AT24=y
2424
CONFIG_EEPROM_AT2X_EMUL=y
2525

26+
# I2S SDL emulation for audio testing
27+
CONFIG_I2S_SDL=y
28+
2629
CONFIG_NETWORKING=y
2730
CONFIG_NET_IPV4=y
2831
CONFIG_NET_TCP=y

ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ alarm = false
1515
analogbufio = false
1616
analogio = false
1717
atexit = false
18-
audiobusio = false
19-
audiocore = false
20-
audiodelays = false
21-
audiofilters = false
22-
audiofreeverb = false
18+
audiobusio = true # Zephyr board has audiobusio
19+
audiocore = true # Zephyr board has audiobusio
20+
audiodelays = true # Zephyr board has audiobusio
21+
audiofilters = true # Zephyr board has audiobusio
22+
audiofreeverb = true # Zephyr board has audiobusio
2323
audioio = false
24-
audiomixer = false
25-
audiomp3 = false
24+
audiomixer = true # Zephyr board has audiobusio
25+
audiomp3 = true # Zephyr board has audiobusio
2626
audiopwmio = false
2727
aurora_epaper = false
2828
bitbangio = false
@@ -62,7 +62,7 @@ keypad = false
6262
keypad_demux = false
6363
locale = false
6464
lvfontio = true # Zephyr board has busio
65-
math = false
65+
math = true
6666
max3421e = false
6767
mdns = false
6868
memorymap = false
@@ -94,7 +94,7 @@ ssl = false
9494
storage = true # Zephyr board has flash
9595
struct = true
9696
supervisor = true
97-
synthio = false
97+
synthio = true # Zephyr board has audiobusio
9898
terminalio = true # Zephyr board has busio
9999
tilepalettemapper = true # Zephyr board has busio
100100
time = true

0 commit comments

Comments
 (0)