File tree 4 files changed +36
-6
lines changed
4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change 1
1
#include " audio.hpp"
2
2
#include " config.h"
3
3
4
+ #include " hardware/dma.h"
5
+ #include " hardware/pio.h"
4
6
#include " pico/audio_i2s.h"
5
7
#define AUDIO_SAMPLE_FREQ 44100
6
8
7
9
#include " audio/audio.hpp"
8
10
11
+ #define audio_pio __CONCAT (pio, PICO_AUDIO_I2S_PIO)
12
+
9
13
static audio_buffer_pool *audio_pool = nullptr;
10
14
11
15
void init_audio () {
@@ -23,11 +27,18 @@ void init_audio() {
23
27
struct audio_buffer_pool *producer_pool = audio_new_producer_pool (&producer_format, 4 , 441 );
24
28
const struct audio_format *output_format;
25
29
30
+ uint8_t dma_channel = dma_claim_unused_channel (true );
31
+ uint8_t pio_sm = pio_claim_unused_sm (audio_pio, true );
32
+
33
+ // audio_i2s_setup claims
34
+ dma_channel_unclaim (dma_channel);
35
+ pio_sm_unclaim (audio_pio, pio_sm);
36
+
26
37
struct audio_i2s_config config = {
27
38
.data_pin = PICO_AUDIO_I2S_DATA_PIN,
28
39
.clock_pin_base = PICO_AUDIO_I2S_CLOCK_PIN_BASE,
29
- .dma_channel = 1 ,
30
- .pio_sm = 1 ,
40
+ .dma_channel = dma_channel ,
41
+ .pio_sm = pio_sm ,
31
42
};
32
43
33
44
output_format = audio_i2s_setup (&audio_format, &config);
Original file line number Diff line number Diff line change 3
3
4
4
#include " pico/audio_pwm.h"
5
5
#include " hardware/clocks.h"
6
+ #include " hardware/dma.h"
6
7
#include " hardware/pio.h"
7
8
8
9
#define AUDIO_SAMPLE_FREQ 22050
9
10
10
11
#include " audio/audio.hpp"
11
12
13
+ #define audio_pio __CONCAT (pio, PICO_AUDIO_I2S_PIO)
14
+
12
15
static audio_buffer_pool *audio_pool = nullptr;
13
16
14
17
void init_audio () {
@@ -26,11 +29,18 @@ void init_audio() {
26
29
struct audio_buffer_pool *producer_pool = audio_new_producer_pool (&producer_format, 4 , 441 );
27
30
const struct audio_format *output_format;
28
31
32
+ uint8_t dma_channel = dma_claim_unused_channel (true );
33
+ uint8_t pio_sm = pio_claim_unused_sm (audio_pio, true );
34
+
35
+ // audio_i2s_setup claims
36
+ dma_channel_unclaim (dma_channel);
37
+ pio_sm_unclaim (audio_pio, pio_sm);
38
+
29
39
struct audio_pwm_channel_config audio_pwm_config = {
30
40
.core = {
31
41
.base_pin = PICO_AUDIO_PWM_MONO_PIN,
32
- .dma_channel = 1 ,
33
- .pio_sm = 1 ,
42
+ .dma_channel = dma_channel ,
43
+ .pio_sm = pio_sm ,
34
44
},
35
45
.pattern = 3 ,
36
46
};
Original file line number Diff line number Diff line change 1
1
#include " display.hpp"
2
2
3
3
#include " hardware/clocks.h"
4
+ #include " hardware/dma.h"
4
5
#include " pico/time.h"
5
6
#include " pico/scanvideo.h"
6
7
#include " pico/scanvideo/composable_scanline.h"
@@ -43,7 +44,12 @@ static void fill_scanline_buffer(struct scanvideo_scanline_buffer *buffer) {
43
44
}
44
45
45
46
void init_display () {
47
+ // channel 0 get claimed later, channel 3 doesn't get claimed, but does get used
48
+ // reserve them so out claims don't conflict
49
+ dma_claim_mask (1 << 0 | 1 << 3 );
46
50
51
+ // PIO SMs that get claimed later
52
+ pio_claim_sm_mask (pio0, 1 << 0 | 1 << 3 );
47
53
}
48
54
49
55
void update_display (uint32_t time) {
@@ -56,6 +62,10 @@ void update_display(uint32_t time) {
56
62
}
57
63
58
64
void init_display_core1 () {
65
+ dma_unclaim_mask (1 << 0 | 1 << 3 );
66
+ pio_sm_unclaim (pio0, 0 );
67
+ pio_sm_unclaim (pio0, 3 );
68
+
59
69
// no mode switching yet
60
70
#if ALLOW_HIRES
61
71
#if DISPLAY_HEIGHT == 160 // extra middle mode
Original file line number Diff line number Diff line change @@ -182,6 +182,7 @@ int main() {
182
182
init_input ();
183
183
init_fs ();
184
184
init_usb ();
185
+ init_audio ();
185
186
186
187
#if defined(ENABLE_CORE1)
187
188
multicore_launch_core1 (core1_main);
@@ -192,8 +193,6 @@ int main() {
192
193
blit::render = ::render;
193
194
blit::update = ::update;
194
195
195
- init_audio ();
196
-
197
196
// user init
198
197
::init ();
199
198
You can’t perform that action at this time.
0 commit comments