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.
Dependents: DirectSPI-test wave_player_super_lite
Revision 2:1faa28f1a5bb, committed 2017-02-23
- Comitter:
- mimi3
- Date:
- Thu Feb 23 22:25:39 2017 +0900
- Parent:
- 1:576dbeb04958
- Child:
- 3:63cc20b0895b
- Commit message:
- update
Changed in this revision
| DirectSPI.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DirectSPI.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/DirectSPI.cpp Thu Feb 23 00:15:12 2017 +0900
+++ b/DirectSPI.cpp Thu Feb 23 22:25:39 2017 +0900
@@ -1,7 +1,12 @@
#include "DirectSPI.h"
-#define isTXE(spi) (spi->SR & SPI_SR_TXE)
-#define isRXNE(spi) (spi->SR & SPI_SR_RXNE)
+#if defined(SPI_SR_TXE) && defined(SPI_SR_RXNE)
+# define isTXE(spi) (spi->SR & SPI_SR_TXE)
+# define isRXNE(spi) (spi->SR & SPI_SR_RXNE)
+#else
+# error Unsupported MCU at this moment !
+#endif
+
#define SPIBUF8(spi) *(__IO uint8_t *)&spi->DR
#define SPIBUF16(spi) spi->DR
@@ -13,18 +18,14 @@
#endif
DirectSPI::DirectSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk) {
- spi = spi_get_id(mosi, miso, sclk, NC);
+ spi = _spi.spi.handle.Instance;
#if TODO
- struct spi_s *spiobj = SPI_S(spi);
- SPI_HandleTypeDef *handle = &(spiobj->handle);
- is16bit = (handle->Init.DataSize == SPI_DATASIZE_16BIT);
spiSend = is16bit ? &DirectSPI::spiSend16 : &DirectSPI::spiSend8;
#endif
}
-#if TODO
uint16_t DirectSPI::directWrite(uint16_t data) {
- if(is16bit){
+ if(_bits == 16){
while(!isTXE(spi));
SPIBUF16(spi) = data;
while(!isRXNE(spi));
@@ -36,7 +37,6 @@
return SPIBUF8(spi);
}
}
-#endif
uint16_t DirectSPI::directWrite8(uint16_t data) {
while(!isTXE(spi));
@@ -52,16 +52,3 @@
return SPIBUF16(spi);
}
-SPI_TypeDef *DirectSPI::spi_get_id( PinName mosi, PinName miso, PinName sclk, PinName ssel) {
- // Determine the SPI to use
- SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
- SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
- SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
- SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL);
-
- SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
- SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
-
- return (SPI_TypeDef *) ( (SPIName)pinmap_merge(spi_data, spi_cntl) );
-}
-
--- a/DirectSPI.h Thu Feb 23 00:15:12 2017 +0900
+++ b/DirectSPI.h Thu Feb 23 22:25:39 2017 +0900
@@ -8,17 +8,13 @@
DirectSPI(PinName mosi, PinName miso, PinName sclk);
uint16_t directWrite8(uint16_t data);
uint16_t directWrite16(uint16_t data);
- SPI_TypeDef *spi_get_id( PinName mosi, PinName miso, PinName sclk, PinName ssel);
+ uint16_t directWrite(uint16_t data);
+protected:
SPI_TypeDef *spi;
#if TODO
- uint16_t directWrite(uint16_t data);
- bool is16bit;
-#endif
-private:
-#if TODO
uint16_t (DirectSPI::*spiSend)(uint16_t data);
- uint16_t spiSend8(uint16_t data);
- uint16_t spiSend16(uint16_t data);
+ uint16_t spiSend8(uint16_t data){return 0;};
+ uint16_t spiSend16(uint16_t data){return 0;};
#endif
};