Skip to content

Conversation

@DatanoiseTV
Copy link
Contributor

Make the usage more user friendly and use PIN_I2S_ pin definitions if they are defined in the board pins_arduino.h.

For example: https://github.com/DatanoiseTV/arduino-pico/blob/master/variants/datanoisetv_picoadk/pins_arduino.h#L43

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your idea, but this really isn't the way to do it with the way the class is architected now.

These defaults should be se set in the I2S::I2S constructor and not the ::begin. See https://github.com/earlephilhower/arduino-pico/blob/master/libraries/I2S/src/I2S.cpp#L26-L39

@DatanoiseTV
Copy link
Contributor Author

@earlephilhower Would this work for you?

I2S::I2S(PinMode direction) {
    _running = false;
    _bps = 16;
    _writtenHalf = false;
    _isOutput = direction == OUTPUT;
#ifdef PIN_I2S_BCLK
    _pinBCLK = PIN_I2S_BCLK;
#else
    _pinBCLK = 26;
#endif

#ifdef PIN_I2S_DOUT
    if (_isOutput == OUTPUT) {
        _pinDOUT = PIN_I2S_DOUT;
    }
#endif

#ifdef PIN_I2S_DIN
    if (_isOutput == INPUT) {
        _pinDOUT = PIN_I2S_DIN;
    }
#endif
    _freq = 48000;
    _arb = nullptr;
    _cb = nullptr;
    _buffers = 8;
    _bufferWords = 16;
    _silenceSample = 0;
}

@earlephilhower
Copy link
Owner

That looks good, yes!

@DatanoiseTV
Copy link
Contributor Author

@earlephilhower The weird thing is just the _pinDOUT confusion. It would be good to support both INPUT and OUTPUT and combined mode for I2S audio codec. Do you have an idea how to solve it?

@earlephilhower
Copy link
Owner

The way the state machine works it's not possible to do both shift directions in the same PIO SM. So you need 2 separate state machines if you want bidirectional. (They can, of course, be running completely different bit widths, frequencies, etc.)

@earlephilhower
Copy link
Owner

@DatanoiseTV can you update the PR with what we discussed above? That way it can be included in the next release this Friday or Saturday...

@DatanoiseTV
Copy link
Contributor Author

@DatanoiseTV can you update the PR with what we discussed above? That way it can be included in the next release this Friday or Saturday...

Sorry, done just now.

#endif

#ifdef PIN_I2S_DOUT
if (_isOutput == OUTPUT) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean "if (_isOutput) since this is a boolean...

#endif

#ifdef PIN_I2S_DIN
if (_isOutput == INPUT) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above...if (!_isOutput)...

@earlephilhower
Copy link
Owner

Thx, but I think there's a couple minor things as noted. OTW looks good!

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@earlephilhower earlephilhower merged commit 4e6e1d6 into earlephilhower:master Nov 23, 2022
@DatanoiseTV DatanoiseTV deleted the i2s-library-changes branch November 23, 2022 01:43
schkovich pushed a commit to schkovich/arduino-pico that referenced this pull request May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants