Skip to content

Commit

Permalink
I2S.write(sample) needs to block according to the reference implement…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
GrumpyOldPizza committed Feb 25, 2017
1 parent 169038d commit 5a49ad1
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions libraries/I2S/src/I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ int I2SClass::read(void* buffer, size_t size)
{
uint32_t xf_offset, xf_index, xf_count;

if (!((_state == I2S_STATE_READY) || (_state == I2S_STATE_RECEIVE))) {
return 0;
if (_state != I2S_STATE_RECEIVE) {
if (!((_state == I2S_STATE_READY) || (_state == I2S_STATE_RECEIVE))) {
return 0;
}

_state = I2S_STATE_RECEIVE;
}

_state = I2S_STATE_RECEIVE;

if (!_xf_active)
{
xf_offset = _xf_offset;
Expand Down Expand Up @@ -376,24 +378,38 @@ size_t I2SClass::write(const uint8_t *buffer, size_t size)

size_t I2SClass::write(int sample)
{
return write((const void*)&sample, (_width / 8));
return write((int32_t)sample);
}

size_t I2SClass::write(int32_t sample)
{
return write((const void*)&sample, (_width / 8));
if (_state != I2S_STATE_TRANSMIT) {
if (!((_state == I2S_STATE_READY) || (_state == I2S_STATE_TRANSMIT))) {
return 0;
}

_state = I2S_STATE_TRANSMIT;
}

while (!write((const void*)&sample, (_width / 8))) {
armv7m_core_yield();
}

return 1;
}

size_t I2SClass::write(const void *buffer, size_t size)
{
uint32_t xf_offset, xf_index, xf_count;

if (!((_state == I2S_STATE_READY) || (_state == I2S_STATE_TRANSMIT))) {
return 0;
if (_state != I2S_STATE_TRANSMIT) {
if (!((_state == I2S_STATE_READY) || (_state == I2S_STATE_TRANSMIT))) {
return 0;
}

_state = I2S_STATE_TRANSMIT;
}

_state = I2S_STATE_TRANSMIT;

if (_width == 32) { size &= ~3; }
else if (_width == 16) { size &= ~1; }

Expand Down

0 comments on commit 5a49ad1

Please sign in to comment.