Vybhav Kadaba
/
EV-PRO-MW1001_Development_updateFW
Bumped Mbed FW version to 01.20.0080
Diff: src/mbed/admw_spi.cpp
- Revision:
- 23:bb685f35b08b
- Parent:
- 13:97cb32670539
- Child:
- 32:52445bef314d
--- a/src/mbed/admw_spi.cpp Thu Sep 26 05:56:58 2019 +0000 +++ b/src/mbed/admw_spi.cpp Thu Sep 26 06:15:39 2019 +0000 @@ -77,26 +77,26 @@ ADMW_LOG_ERROR("Failed to allocate memory for SPI device"); return ADMW_NO_MEM; } - + pCtx->_spi = new SPI((PinName)pConfig->mosiPin, - (PinName)pConfig->misoPin, - (PinName)pConfig->sckPin); + (PinName)pConfig->misoPin, + (PinName)pConfig->sckPin); pCtx->_cs = new DigitalOut((PinName)pConfig->csPin, 1); - + pCtx->_spi->format(ADMW_SPI_FRAME_SIZE, ADMW_SPI_MODE); pCtx->_spi->frequency(pConfig->maxSpeedHz); - + pCtx->_wakeup = new DigitalOut((PinName)pConfig->wakeupPin, 1); - + *phDevice = (ADMW_SPI_HANDLE)pCtx; - + return ADMW_SUCCESS; } /* * Execute a bi-directional data transfer on the SPI interface */ - ADMW_RESULT +ADMW_RESULT admw_SpiReceive( ADMW_SPI_HANDLE hDevice, void *pTxData, @@ -104,12 +104,12 @@ unsigned nLength, bool bCsHold) { - SpiContext_t *pCtx = (SpiContext_t*)hDevice; - - pCtx->_spi->format(ADMW_SPI_FRAME_SIZE, 1); - - int rc = 0; - + SpiContext_t *pCtx = (SpiContext_t*)hDevice; + + pCtx->_spi->format(ADMW_SPI_FRAME_SIZE, 1); + + int rc = 0; + *(pCtx->_wakeup) = 0; wait_us(60); @@ -117,23 +117,22 @@ *(pCtx->_cs) = 0; rc = pCtx->_spi->write((char*)(pTxData), pTxData ? nLength : 0, - (char*)(pRxData), pRxData ? nLength : 0); - + (char*)(pRxData), pRxData ? nLength : 0); + if ((rc < 0) || !bCsHold) *(pCtx->_cs) = 1; *(pCtx->_wakeup) = 1; - if (rc < 0) - { + if (rc < 0) { ADMW_LOG_ERROR("Failed to complete SPI transfer"); return ADMW_FAILURE; } pCtx->_spi->format(ADMW_SPI_FRAME_SIZE, ADMW_SPI_MODE); - + return ADMW_SUCCESS; - + } ADMW_RESULT admw_SpiTransfer( @@ -144,9 +143,9 @@ bool bCsHold) { int rc = 0; - + SpiContext_t *pCtx = (SpiContext_t*)hDevice; - + *(pCtx->_wakeup) = 0; wait_us(60); @@ -154,15 +153,14 @@ *(pCtx->_cs) = 0; rc = pCtx->_spi->write((char*)(pTxData), pTxData ? nLength : 0, - (char*)(pRxData), pRxData ? nLength : 0); - + (char*)(pRxData), pRxData ? nLength : 0); + if ((rc < 0) || !bCsHold) *(pCtx->_cs) = 1; *(pCtx->_wakeup) = 1; - if (rc < 0) - { + if (rc < 0) { ADMW_LOG_ERROR("Failed to complete SPI transfer"); return ADMW_FAILURE; } @@ -181,7 +179,7 @@ delete pCtx->_spi; delete pCtx->_cs; delete pCtx->_wakeup; - + free(pCtx); }