Ultra fast and direct SPI library for some STM32 micros.

Dependents:   DirectSPI-test wave_player_super_lite

Files at this revision

API Documentation at this revision

Comitter:
mimi3
Date:
Tue Feb 28 22:08:32 2017 +0900
Parent:
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
diff -r 63cc20b0895b -r f63f07d07d5a DirectSPI.cpp
--- a/DirectSPI.cpp	Tue Feb 28 22:00:46 2017 +0900
+++ b/DirectSPI.cpp	Tue Feb 28 22:08:32 2017 +0900
@@ -18,7 +18,7 @@
 #endif
 
 DirectSPI::DirectSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk) {
-    spi = _spi.spi.handle.Instance;
+    spi = spi_get_id(mosi, miso, sclk, NC);
 #if TODO
     spiSend = is16bit ? &DirectSPI::spiSend16 : &DirectSPI::spiSend8;
 #endif
@@ -52,3 +52,15 @@
     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) );
+}
diff -r 63cc20b0895b -r f63f07d07d5a DirectSPI.h
--- a/DirectSPI.h	Tue Feb 28 22:00:46 2017 +0900
+++ b/DirectSPI.h	Tue Feb 28 22:08:32 2017 +0900
@@ -12,6 +12,7 @@
     uint16_t directWrite8(uint16_t data);
     uint16_t directWrite16(uint16_t data);
     uint16_t directWrite(uint16_t data);
+    SPI_TypeDef *spi_get_id( PinName mosi, PinName miso, PinName sclk, PinName ssel);
     void operator = (uint8_t d8){
         volatile uint16_t res;
         res = directWrite8( d8 );