Fixed byte order in bbSPIXfer

Got default endianess wrong and additionally the byte order has to be
changed according to bit order on the SPI-Line
This commit is contained in:
BjoernSch 2016-08-10 20:50:00 +02:00
parent 735c87342e
commit 09f56eb728
1 changed files with 23 additions and 5 deletions

View File

@ -9968,6 +9968,7 @@ static uint8_t bbSPIXferByte(wfRx_t *w, char txByte)
myGpioWrite(w->S.MOSI, txByte & 0x80); myGpioWrite(w->S.MOSI, txByte & 0x80);
txByte <<= 1; txByte <<= 1;
} }
set_SCLK(w); set_SCLK(w);
SPI_delay(w); SPI_delay(w);
@ -9997,6 +9998,7 @@ static uint8_t bbSPIXferByte(wfRx_t *w, char txByte)
myGpioWrite(w->S.MOSI, txByte & 0x80); myGpioWrite(w->S.MOSI, txByte & 0x80);
txByte <<= 1; txByte <<= 1;
} }
if (PI_SPI_FLAGS_GET_RX_LSB(w->S.spiFlags)) if (PI_SPI_FLAGS_GET_RX_LSB(w->S.spiFlags))
{ {
rxByte = (rxByte >> 1) | myGpioRead(w->S.MISO) << 7; rxByte = (rxByte >> 1) | myGpioRead(w->S.MISO) << 7;
@ -10204,9 +10206,10 @@ int bbSPIXfer(
unsigned len) unsigned len)
{ {
int pos, status; int pos, status;
char txByte, rxByte;
wfRx_t *w; wfRx_t *w;
DBG(DBG_USER, "gpio=%d inBuf=%s outBuf=%08X len=%d", DBG(DBG_USER, "CS=%d inBuf=%s outBuf=%08X len=%d",
CS, myBuf2Str(len, (char *)inBuf), (int)outBuf, len); CS, myBuf2Str(len, (char *)inBuf), (int)outBuf, len);
CHECK_INITED; CHECK_INITED;
@ -10228,12 +10231,27 @@ int bbSPIXfer(
status = 0; status = 0;
bbSPIStart(w); bbSPIStart(w);
for (pos=0; pos < len; pos++) for (pos=0; pos < len; pos++)
{ {
DBG(DBG_INTERNAL, "pos=%d len=%d sent=%d", if (PI_SPI_FLAGS_GET_TX_LSB(w->S.spiFlags))
pos, len, inBuf[pos]); {
outBuf[pos] = bbSPIXferByte(w, inBuf[pos]); txByte = inBuf[pos];
DBG(DBG_INTERNAL, "recvd=%d", outBuf[pos]); }
else
{
txByte = inBuf[len - pos - 1];
}
rxByte = bbSPIXferByte(w, txByte);
if (PI_SPI_FLAGS_GET_RX_LSB(w->S.spiFlags))
{
outBuf[pos] = rxByte;
}
else
{
outBuf[len - pos - 1] = rxByte;
}
DBG(DBG_INTERNAL, "pos=%d len=%d sent=%d recvd=%d", pos, len, txByte, rxByte);
} }
bbSPIStop(w); bbSPIStop(w);