From df7e3367f73a9da4cce9dce055bee37a167c2715 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 28 Feb 2019 10:51:59 +0200 Subject: [PATCH] Cope with HALs not defining SPIName --- drivers/SPI.cpp | 13 ++++++------- drivers/SPI.h | 19 +++++++++++++------ hal/spi_api.h | 2 ++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/SPI.cpp b/drivers/SPI.cpp index daf2563d64..50980c4b99 100644 --- a/drivers/SPI.cpp +++ b/drivers/SPI.cpp @@ -23,12 +23,6 @@ #if DEVICE_SPI -/* Backwards compatibility with HALs that don't provide this */ -MBED_WEAK SPIName spi_get_peripheral_name(PinName /*mosi*/, PinName /*miso*/, PinName /*mclk*/) -{ - return (SPIName)1; -} - namespace mbed { SPI::spi_peripheral_s SPI::_peripherals[SPI_PERIPHERALS_USED]; @@ -73,7 +67,12 @@ void SPI::_do_construct() _hz = 1000000; _write_fill = SPI_FILL_CHAR; + // Need backwards compatibility with HALs not providing API +#ifdef SPI_COUNT SPIName name = spi_get_peripheral_name(_mosi, _miso, _sclk); +#else + SPIName name = GlobalSPI; +#endif core_util_critical_section_enter(); // lookup in a critical section if we already have it else initialize it @@ -98,7 +97,7 @@ SPI::~SPI() unlock(); } -SPI::spi_peripheral_s *SPI::_lookup(SPIName name) +SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name) { SPI::spi_peripheral_s *result = NULL; core_util_critical_section_enter(); diff --git a/drivers/SPI.h b/drivers/SPI.h index 592c55bec6..fa44654ce1 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -27,15 +27,13 @@ #include "platform/SingletonPtr.h" #include "platform/NonCopyable.h" -/* Backwards compatibility with HALs not providing this */ -#ifndef SPI_COUNT -#define SPI_COUNT 1 -#endif - #if defined MBED_CONF_DRIVERS_SPI_COUNT_MAX && SPI_COUNT > MBED_CONF_DRIVERS_SPI_COUNT_MAX #define SPI_PERIPHERALS_USED MBED_CONF_DRIVERS_SPI_COUNT_MAX -#else +#elif defined SPI_COUNT #define SPI_PERIPHERALS_USED SPI_COUNT +#else +/* Backwards compatibility with HALs not providing SPI_COUNT */ +#define SPI_PERIPHERALS_USED 1 #endif #if DEVICE_SPI_ASYNCH @@ -259,6 +257,7 @@ public: #if !defined(DOXYGEN_ONLY) protected: + /** SPI interrupt handler. */ void irq_handler_asynch(void); @@ -338,6 +337,14 @@ private: #if !defined(DOXYGEN_ONLY) protected: +#ifdef SPI_COUNT + // HAL must have defined this as a global enum + typedef ::SPIName SPIName; +#else + // HAL may or may not have defined it - use a local definition + enum SPIName { GlobalSPI }; +#endif + struct spi_peripheral_s { /* Internal SPI name identifying the resources. */ SPIName name; diff --git a/hal/spi_api.h b/hal/spi_api.h index ad80cf466e..369574609f 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -62,6 +62,7 @@ extern "C" { * @{ */ +#ifdef SPI_COUNT /** * Returns a variant of the SPIName enum uniquely identifying a SPI peripheral of the device. * @param[in] mosi The pin to use for MOSI @@ -70,6 +71,7 @@ extern "C" { * @return An SPI peripheral identifier */ SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName mclk); +#endif /** Initialize the SPI peripheral *