Skip to content
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

Bidirectional I2S #9909

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bfa7db1
Initial build of I2SIn.
relic-se Nov 13, 2024
0daaeb4
Enable I2SIn on RP2xxx
relic-se Nov 13, 2024
5feb12f
Merge branch 'adafruit:main' into i2sin
relic-se Dec 18, 2024
805a6b1
Remove `record` method.
relic-se Dec 18, 2024
e30e234
Update audio dma to support independent input dma.
relic-se Dec 18, 2024
f1e6f01
Fix pointer issue with dma setup.
relic-se Dec 18, 2024
9a0d1c2
Only reset buffer if output is enabled.
relic-se Dec 18, 2024
d0e2b01
Rename `last_record` to `last_index`.
relic-se Dec 18, 2024
76ac311
Handle dma input write destination.
relic-se Dec 18, 2024
55d3252
Send bit width to start PIO program on `reset_buffer`.
relic-se Dec 18, 2024
be48374
Fix errors within PIO program.
relic-se Dec 21, 2024
3c97fd8
Run background tasks while waiting for next buffer.
relic-se Dec 21, 2024
15384bc
Add bidirectional I2S class.
relic-se Dec 23, 2024
dc6e67e
Start input dma channel before output dma channel to allow blocks to …
relic-se Dec 23, 2024
ececb9c
Remove bug comment.
relic-se Dec 23, 2024
3d1a16d
Merge branch 'adafruit:main' into i2sin
relic-se Dec 23, 2024
1e9d455
Fix formatting errors.
relic-se Dec 23, 2024
c6bdd36
Fix input playback example.
relic-se Dec 23, 2024
05c719f
Add empty files within other port families to fix builds.
relic-se Dec 23, 2024
7c6f010
Add record method.
relic-se Dec 23, 2024
c04489c
Merge branch 'adafruit:main' into i2sin
relic-se Jan 18, 2025
c8499a5
Support 32-bit pio pin mask.
relic-se Jan 18, 2025
1aaf4f1
Return number of samples recorded.
relic-se Jan 22, 2025
851765e
Improve dma initialization.
relic-se Jan 22, 2025
4b82933
Double-buffering and improved buffer testing.
relic-se Jan 23, 2025
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
Prev Previous commit
Next Next commit
Fix errors within PIO program.
relic-se committed Dec 21, 2024
commit be48374086d2f4e07fcc7691cf08295314af0df5
78 changes: 39 additions & 39 deletions ports/raspberrypi/common-hal/audiobusio/I2SIn.c
Original file line number Diff line number Diff line change
@@ -19,27 +19,27 @@
#include "audio_dma.h"

const uint16_t i2sin_program_mono[] = {
// pull block side 0b11 ; Load OSR with bits_per_sample
// pull block side 0b11 ; Load OSR with bits_per_sample-2
0x98a0,
// mov x osr side 0b11 ; Save the value in x
0xb827,
// out y 8 side 0b11 ; Save the value in y
0x7848,
// nop side 0b01
0xa842,
// mov y x side 0b01
0xa841,
// mov x y side 0b01
0xa822,
// lbit:
// nop side 0b00 [1]
0xa142,
// in pins 1 side 0b01
0x4801,
// jmp y-- lbit side 0b01
0x0884,
// jmp x-- lbit side 0b01
0x0844,
// nop side 0b10 [1]
0xb142,
// in pins 1 side 0b11
0x5801,
// mov y x side 0b11
0xb841,
// mov x y side 0b11
0xb822,
// rbit:
// nop side 0b10 [1]
0xb142,
@@ -54,27 +54,27 @@ const uint16_t i2sin_program_mono[] = {
};

const uint16_t i2sin_program_mono_swap[] = {
// pull block side 0b11 ; Load OSR with bits_per_sample
// pull block side 0b11 ; Load OSR with bits_per_sample-2
0x98a0,
// mov x osr side 0b11 ; Save the value in x
0xb827,
// out y 8 side 0b11 ; Save the value in y
0x7848,
// nop side 0b10
0xb042,
// mov y x side 0b10
0xb041,
// mov x y side 0b10
0xb022,
// lbit:
// nop side 0b00 [1]
0xa142,
// in pins 1 side 0b10
0x5001,
// jmp y-- lbit side 0b10
0x1084,
// jmp x-- lbit side 0b10
0x1044,
// nop side 0b01 [1]
0xa942,
// in pins 1 side 0b11
0x5801,
// mov y x side 0b11
0xb841,
// mov x y side 0b11
0xb822,
// rbit:
// nop side 0b01 [1]
0xa942,
@@ -92,27 +92,27 @@ const uint16_t i2sin_program_stereo[] = {
// ; /--- LRCLK
// ; |/-- BCLK
// ; ||
// pull block side 0b11 ; Load OSR with bits_per_sample
// pull block side 0b11 ; Load OSR with bits_per_sample-2
0x98a0,
// mov x osr side 0b11 ; Save the value in x
0xb827,
// out y 8 side 0b11 ; Save the value in y
0x7848,
// nop side 0b01
0xa842,
// mov y x side 0b01
0xa841,
// mov x y side 0b01
0xa822,
// lbit:
// nop side 0b00 [1]
0xa142,
// in pins 1 side 0b01
0x4801,
// jmp y-- lbit side 0b01
0x0884,
// jmp x-- lbit side 0b01
0x0844,
// nop side 0b10 [1]
0xb142,
// in pins 1 side 0b11
0x5801,
// mov y x side 0b11
0xb841,
// mov x y side 0b11
0xb822,
// rbit:
// nop side 0b10 [1]
0xb142,
@@ -130,27 +130,27 @@ const uint16_t i2sin_program_stereo_swap[] = {
// ; /--- LRCLK
// ; |/-- BCLK
// ; ||
// pull block side 0b11 ; Load OSR with bits_per_sample
// pull block side 0b11 ; Load OSR with bits_per_sample-2
0x98a0,
// mov x osr side 0b11 ; Save the value in x
0xb827,
// out y 8 side 0b11 ; Save the value in y
0x7848,
// nop side 0b10
0xb042,
// mov y x side 0b10
0xb041,
// mov x y side 0b10
0xb022,
// lbit:
// nop side 0b00 [1]
0xa142,
// in pins 1 side 0b10
0x5001,
// jmp y-- lbit side 0b10
0x1084,
// jmp x-- lbit side 0b10
0x1044,
// nop side 0b01 [1]
0xa942,
// in pins 1 side 0b11
0x5801,
// mov y x side 0b11
0xb841,
// mov x y side 0b11
0xb822,
// rbit:
// nop side 0b01 [1]
0xa942,
@@ -207,10 +207,10 @@ void common_hal_audiobusio_i2sin_construct(audiobusio_i2sin_obj_t *self,
sample_rate * bits_per_sample * 2 * 4, // Frequency based on sample rate and bit width
NULL, 0, // init
NULL, 0, // may_exec
NULL, 1, 0, 0xffffffff, // out pin
NULL, 1, 0, 0, // out pin
data, 1, // in pins
0, 0, // in pulls
NULL, 0, 0, 0x1f, // set pins
NULL, 1, 0, 0, // set pins
sideset_pin, 2, false, 0, 0x1f, // sideset pins
false, // No sideset enable
NULL, PULL_NONE, // jump pin
@@ -269,7 +269,7 @@ void audiobusio_i2sin_reset_buffer(audiobusio_i2sin_obj_t *self,
common_hal_rp2pio_statemachine_restart(&self->state_machine);

// Send bit width
const uint8_t bit_width_data[1] = { self->bits_per_sample };
const uint8_t bit_width_data[1] = { self->bits_per_sample - 2 };
common_hal_rp2pio_statemachine_write(&self->state_machine, bit_width_data, 1, 1, false);

audio_dma_result result = audio_dma_setup_record(