Cope with HALs not defining SPIName

pull/9469/head
Kevin Bracey 2019-02-28 10:51:59 +02:00
parent c368021e37
commit df7e3367f7
3 changed files with 21 additions and 13 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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
*