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

Support claiming unused SM/channels for audio #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/rp2_common/pico_audio_i2s/audio_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,27 @@ const audio_format_t *audio_i2s_setup(const audio_format_t *intended_audio_forma
gpio_set_function(config->clock_pin_base, func);
gpio_set_function(config->clock_pin_base + 1, func);

uint8_t sm = shared_state.pio_sm = config->pio_sm;
pio_sm_claim(audio_pio, sm);
uint8_t sm = config->pio_sm;
if (sm == 0xFF) {
sm = pio_claim_unused_sm(audio_pio, true);
} else {
pio_sm_claim(audio_pio, sm);
}

shared_state.pio_sm = sm;

uint offset = pio_add_program(audio_pio, &audio_i2s_program);

audio_i2s_program_init(audio_pio, sm, offset, config->data_pin, config->clock_pin_base);

__mem_fence_release();

uint8_t dma_channel = config->dma_channel;
dma_channel_claim(dma_channel);
if(dma_channel == 0xFF) {
dma_channel = dma_claim_unused_channel(true);
} else {
dma_channel_claim(dma_channel);
}

shared_state.dma_channel = dma_channel;

Expand Down
16 changes: 13 additions & 3 deletions src/rp2_common/pico_audio_pwm/audio_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,14 @@ const audio_format_t *audio_pwm_setup(const audio_format_t *intended_audio_forma

gpio_set_function(config->core.base_pin, GPIO_FUNC_PIOx);

uint8_t sm = shared_state.pio_sm[ch] = config->core.pio_sm;
pio_sm_claim(audio_pio, sm);
uint8_t sm = config->core.pio_sm;
if (sm == 0xFF) {
sm = pio_claim_unused_sm(audio_pio, true);
} else {
pio_sm_claim(audio_pio, sm);
}

shared_state.pio_sm[ch] = sm;

pio_sm_config sm_config = audio_program_get_default_config(offset);
sm_config_set_out_pins(&sm_config, config->core.base_pin, 1);
Expand All @@ -241,7 +247,11 @@ const audio_format_t *audio_pwm_setup(const audio_format_t *intended_audio_forma
pio_sm_exec(audio_pio, sm, pio_encode_jmp(offset + audio_entry_point)); // jmp to ep

uint8_t dma_channel = config->core.dma_channel;
dma_channel_claim(dma_channel);
if(dma_channel == 0xFF) {
dma_channel = dma_claim_unused_channel(true);
} else {
dma_channel_claim(dma_channel);
}

shared_state.dma_channel[ch] = dma_channel;

Expand Down
17 changes: 14 additions & 3 deletions src/rp2_common/pico_audio_spdif/audio_spdif.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ const audio_format_t *audio_spdif_setup(const audio_format_t *intended_audio_for
uint func = GPIO_FUNC_PIOx;
gpio_set_function(config->pin, func);

uint8_t sm = shared_state.pio_sm = config->pio_sm;
pio_sm_claim(audio_pio, sm);
uint8_t sm = config->pio_sm;
if (sm == 0xFF) {
sm = pio_claim_unused_sm(audio_pio, true);
} else {
pio_sm_claim(audio_pio, sm);
}

shared_state.pio_sm = sm;

uint offset = pio_add_program(audio_pio, &audio_spdif_program);

Expand All @@ -144,8 +150,13 @@ const audio_format_t *audio_spdif_setup(const audio_format_t *intended_audio_for
}

__mem_fence_release();

uint8_t dma_channel = config->dma_channel;
dma_channel_claim(dma_channel);
if(dma_channel == 0xFF) {
dma_channel = dma_claim_unused_channel(true);
} else {
dma_channel_claim(dma_channel);
}

shared_state.dma_channel = dma_channel;

Expand Down