Vybhav Kadaba
/
EV-PRO-MW1001_Development_MWARE2390
sensor result structure modified
Diff: src/mbed/admw_spi.cpp
- Revision:
- 13:97cb32670539
- Parent:
- 5:0728bde67bdb
- Child:
- 23:bb685f35b08b
--- a/src/mbed/admw_spi.cpp Wed Jul 24 08:51:31 2019 +0000 +++ b/src/mbed/admw_spi.cpp Thu Jul 25 06:38:45 2019 +0000 @@ -96,6 +96,45 @@ /* * Execute a bi-directional data transfer on the SPI interface */ + ADMW_RESULT +admw_SpiReceive( + ADMW_SPI_HANDLE hDevice, + void *pTxData, + void *pRxData, + unsigned nLength, + bool bCsHold) +{ + SpiContext_t *pCtx = (SpiContext_t*)hDevice; + + pCtx->_spi->format(ADMW_SPI_FRAME_SIZE, 1); + + int rc = 0; + + *(pCtx->_wakeup) = 0; + + wait_us(60); + + *(pCtx->_cs) = 0; + + rc = pCtx->_spi->write((char*)(pTxData), pTxData ? nLength : 0, + (char*)(pRxData), pRxData ? nLength : 0); + + if ((rc < 0) || !bCsHold) + *(pCtx->_cs) = 1; + + *(pCtx->_wakeup) = 1; + + 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( ADMW_SPI_HANDLE hDevice,