This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
/**
* We use the default Arduino SPI API to send/write the data as SPI Master.
* For a sample rate of 44100 with 2 channels and 16 bit data you need to be
* able to transmit faster then 44100 * 2 channels * 2 bytes = 176400 bytes per
* second. Using a SPI communication this gives 176400 * 8 =
* 1'411'200 bps!
*
* Untested DRAFT implementation!
*/
#include <SPI.h>
#include "AudioTools.h"
const size_t BUFFER_SIZE = 1024;
const int SPI_CLOCK = 2000000; // 2 MHz
AudioInfo info(44100, 2, 16); //
Vector<uint8_t> buffer(BUFFER_SIZE);
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
void setup() {
SPI.begin();
sineWave.begin(info, N_B4);
SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0));
}
void loop() {
// get data
size_t result = sound.readBytes(&buffer[0], buffer.size());
// transmit data
SPI.transfer(&buffer[0], result);
//SPI.endTransaction();
}

View File

@@ -0,0 +1,39 @@
/***
* We use the ESP32DMASPISlave library to implement the SPI slave on the ESP32
* which receives the data
*
* Untested DRAFT implementation!
*/
#include <ESP32DMASPISlave.h>
#include "AudioTools.h"
const size_t BUFFER_SIZE = 1024;
uint8_t *dma_rx_buf;
ESP32DMASPI::Slave spi_slave;
AudioInfo info(44100, 2, 16); //
I2SStream out; // or replace with another output
void setup() {
Serial.begin(115200);
// setup I2S
auto cfg = out.defaultConfig(TX_MODE);
cfg.copyFrom(info);
//cfg.pin_bck = 14;
//cfg.pin_ws = 15;
//cfg.pin_data = 22;
// to use DMA buffer, use these methods to allocate buffer
dma_rx_buf = spi_slave.allocDMABuffer(BUFFER_SIZE);
spi_slave.setDataMode(SPI_MODE0); // default: SPI_MODE0
spi_slave.setMaxTransferSize(BUFFER_SIZE); // default: 4092 bytes
// begin() after setting
spi_slave.begin(); // default: HSPI (please refer README for pin assignments)
}
void loop() {
// start and wait to complete one BIG transaction
size_t received_bytes = spi_slave.transfer(nullptr, dma_rx_buf, BUFFER_SIZE);
out.write(dma_rx_buf, received_bytes);
}

View File

@@ -0,0 +1,48 @@
/***
* We use the RP2040 SPISlave to implement the SPI slave
* which receives the data
*
* Untested DRAFT implementation!
*/
#include <SPISlave.h>
AudioInfo info(44100, 2, 16); //
I2SStream out; // or replace with another output
// Wiring:
// Master RX GP0 <-> GP11 Slave TX
// Master CS GP1 <-> GP9 Slave CS
// Master CK GP2 <-> GP10 Slave CK
// Master TX GP3 <-> GP8 Slave RX
SPISettings spisettings(2000000, MSBFIRST, SPI_MODE0);
// Core 1 will be SPI slave
void recvCallback(uint8_t *data, size_t len) { out.write(data, len); }
void setup() {
Serial.begin(115200);
// setup I2S
auto cfg = out.defaultConfig(TX_MODE);
cfg.copyFrom(info);
// cfg.pin_bck = 14;
// cfg.pin_ws = 15;
// cfg.pin_data = 22;
out.begin(cfg);
// setup SPI
SPISlave.setRX(8);
SPISlave.setCS(9);
SPISlave.setSCK(10);
SPISlave.setTX(11);
// Hook our callbacks into the slave
SPISlave.onDataRecv(recvCallback);
SPISlave.begin(spisettings);
delay(1000);
Serial.println("SPISlave started");
}
void loop() {}