Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: src/mbed/admw_spi.cpp
- Revision:
- 32:52445bef314d
- Parent:
- 23:bb685f35b08b
- Child:
- 48:5731f1aa2c5a
--- a/src/mbed/admw_spi.cpp Wed Oct 23 16:18:50 2019 +0000
+++ b/src/mbed/admw_spi.cpp Fri Oct 25 05:08:19 2019 +0000
@@ -1,5 +1,5 @@
/******************************************************************************
-Copyright 2017 (c) Analog Devices, Inc.
+Copyright 2019 (c) Analog Devices, Inc.
All rights reserved.
@@ -77,25 +77,22 @@
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_SpiReceive(
ADMW_SPI_HANDLE hDevice,
@@ -105,35 +102,33 @@
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);
-
+ (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;
+}
- return ADMW_SUCCESS;
-
-}
+/*
+ * Execute a bi-directional data transfer on the SPI interface
+ */
ADMW_RESULT
admw_SpiTransfer(
ADMW_SPI_HANDLE hDevice,
@@ -143,28 +138,23 @@
bool bCsHold)
{
int rc = 0;
-
+
SpiContext_t *pCtx = (SpiContext_t*)hDevice;
-
- *(pCtx->_wakeup) = 0;
-
- wait_us(60);
-
+
*(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;
}
-
+
return ADMW_SUCCESS;
}
@@ -179,7 +169,7 @@
delete pCtx->_spi;
delete pCtx->_cs;
delete pCtx->_wakeup;
-
+
free(pCtx);
}