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

Allow I2S constructor to set pins, like PWMAudio #2702

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
8 changes: 3 additions & 5 deletions libraries/I2S/examples/SimpleTone/SimpleTone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions libraries/I2S/src/I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libraries/I2S/src/I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading