Allow I2S constructor to set pins, like PWMAudio (#2702)

Pins are a physical connection, makes sense to define them at construction.
This commit is contained in:
Earle F. Philhower, III 2024-12-18 10:06:54 -08:00 committed by GitHub
parent 66af359578
commit f1b965f704
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

View file

@ -19,14 +19,14 @@
#include <I2S.h>
// Create the I2S port using a PIO state machine
I2S i2s(OUTPUT);
// GPIO pin numbers
#define pBCLK 20
#define pWS (pBCLK+1)
#define pDOUT 22
// Create the I2S port using a PIO state machine
I2S i2s(OUTPUT, pBCLK, pDOUT);
const int frequency = 440; // frequency of square wave in Hz
const int amplitude = 500; // amplitude of square wave
const int sampleRate = 16000; // minimum for UDA1334A
@ -43,8 +43,6 @@ void setup() {
Serial.begin(115200);
Serial.println("I2S simple tone");
i2s.setBCLK(pBCLK);
i2s.setDATA(pDOUT);
i2s.setBitsPerSample(16);
// start I2S at the sample rate with 16-bits per sample

View file

@ -24,14 +24,14 @@
#include <pico/stdlib.h>
I2S::I2S(PinMode direction) {
I2S::I2S(PinMode direction, pin_size_t bclk, pin_size_t data, pin_size_t mclk) {
_running = false;
_bps = 16;
_writtenHalf = false;
_isOutput = direction == OUTPUT;
_pinBCLK = 26;
_pinDOUT = 28;
_pinMCLK = 25;
_pinBCLK = bclk;
_pinDOUT = data;
_pinMCLK = mclk;
_MCLKenabled = false;
#ifdef PIN_I2S_BCLK
_pinBCLK = PIN_I2S_BCLK;

View file

@ -25,7 +25,7 @@
class I2S : public Stream {
public:
I2S(PinMode direction = OUTPUT);
I2S(PinMode direction = OUTPUT, pin_size_t bclk = 26, pin_size_t data = 28, pin_size_t mclk = 25);
virtual ~I2S();
bool setBCLK(pin_size_t pin);