Skip to content

Commit 721b62d

Browse files
committed
arduino examples
1 parent 636ec27 commit 721b62d

File tree

5 files changed

+4509
-0
lines changed

5 files changed

+4509
-0
lines changed

PCM510x_Examples/Arduino_Audio_Playback/.feather_rp2040.test.only

Whitespace-only changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-FileCopyrightText: 2023 Ladyada for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/*
6+
This example plays a 'raw' PCM file from memory to I2S
7+
*/
8+
9+
#include <I2S.h>
10+
11+
#include "startup.h" // audio file in flash
12+
13+
// Create the I2S port using a PIO state machine
14+
I2S i2s(OUTPUT);
15+
16+
// GPIO pin numbers on Feather RP2040
17+
#define pBCLK D9 // BITCLOCK
18+
#define pWS D10 // LRCLOCK
19+
#define pDOUT D11 // DATA
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
while (!Serial) delay(10);
24+
Serial.println("I2S playback demo");
25+
}
26+
27+
void loop() {
28+
}
29+
30+
void setup1() {
31+
i2s.setBCLK(pBCLK);
32+
i2s.setDATA(pDOUT);
33+
i2s.setBitsPerSample(16);
34+
}
35+
36+
void loop1() {
37+
// the main loop will tell us when it wants us to play!
38+
play_i2s(startupAudioData, sizeof(startupAudioData), startupSampleRate);
39+
delay(1000);
40+
}
41+
42+
void play_i2s(const uint8_t *data, uint32_t len, uint32_t rate) {
43+
// start I2S at the sample rate with 16-bits per sample
44+
if (!i2s.begin(rate)) {
45+
Serial.println("Failed to initialize I2S!");
46+
delay(500);
47+
i2s.end();
48+
return;
49+
}
50+
51+
for(uint32_t i=0; i<len; i++) {
52+
uint16_t sample = (uint16_t)data[i] << 6; // our data is 10 bit but we want 16 bit so we add some gain
53+
// write the same sample twice, once for left and once for the right channel
54+
i2s.write(sample);
55+
i2s.write(sample);
56+
}
57+
i2s.end();
58+
}

0 commit comments

Comments
 (0)