Ultra fast and direct SPI library for some STM32 micros.

Dependents:   DirectSPI-test wave_player_super_lite

Revision:
4:f63f07d07d5a
Parent:
2:1faa28f1a5bb
--- 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) );
+}