-
Notifications
You must be signed in to change notification settings - Fork 515
Use PIN_I2S_ defines if they exist in board pin definition. #991
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
Use PIN_I2S_ defines if they exist in board pin definition. #991
Conversation
earlephilhower
left a comment
There was a problem hiding this 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
|
@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;
} |
|
That looks good, yes! |
|
@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? |
|
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.) |
|
@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. |
libraries/I2S/src/I2S.cpp
Outdated
| #endif | ||
|
|
||
| #ifdef PIN_I2S_DOUT | ||
| if (_isOutput == OUTPUT) { |
There was a problem hiding this comment.
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...
libraries/I2S/src/I2S.cpp
Outdated
| #endif | ||
|
|
||
| #ifdef PIN_I2S_DIN | ||
| if (_isOutput == INPUT) { |
There was a problem hiding this comment.
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)...
|
Thx, but I think there's a couple minor things as noted. OTW looks good! |
earlephilhower
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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