Skip to content

Commit df7e336

Browse files
committed
Cope with HALs not defining SPIName
1 parent c368021 commit df7e336

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

drivers/SPI.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323

2424
#if DEVICE_SPI
2525

26-
/* Backwards compatibility with HALs that don't provide this */
27-
MBED_WEAK SPIName spi_get_peripheral_name(PinName /*mosi*/, PinName /*miso*/, PinName /*mclk*/)
28-
{
29-
return (SPIName)1;
30-
}
31-
3226
namespace mbed {
3327

3428
SPI::spi_peripheral_s SPI::_peripherals[SPI_PERIPHERALS_USED];
@@ -73,7 +67,12 @@ void SPI::_do_construct()
7367
_hz = 1000000;
7468
_write_fill = SPI_FILL_CHAR;
7569

70+
// Need backwards compatibility with HALs not providing API
71+
#ifdef SPI_COUNT
7672
SPIName name = spi_get_peripheral_name(_mosi, _miso, _sclk);
73+
#else
74+
SPIName name = GlobalSPI;
75+
#endif
7776

7877
core_util_critical_section_enter();
7978
// lookup in a critical section if we already have it else initialize it
@@ -98,7 +97,7 @@ SPI::~SPI()
9897
unlock();
9998
}
10099

101-
SPI::spi_peripheral_s *SPI::_lookup(SPIName name)
100+
SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name)
102101
{
103102
SPI::spi_peripheral_s *result = NULL;
104103
core_util_critical_section_enter();

drivers/SPI.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727
#include "platform/SingletonPtr.h"
2828
#include "platform/NonCopyable.h"
2929

30-
/* Backwards compatibility with HALs not providing this */
31-
#ifndef SPI_COUNT
32-
#define SPI_COUNT 1
33-
#endif
34-
3530
#if defined MBED_CONF_DRIVERS_SPI_COUNT_MAX && SPI_COUNT > MBED_CONF_DRIVERS_SPI_COUNT_MAX
3631
#define SPI_PERIPHERALS_USED MBED_CONF_DRIVERS_SPI_COUNT_MAX
37-
#else
32+
#elif defined SPI_COUNT
3833
#define SPI_PERIPHERALS_USED SPI_COUNT
34+
#else
35+
/* Backwards compatibility with HALs not providing SPI_COUNT */
36+
#define SPI_PERIPHERALS_USED 1
3937
#endif
4038

4139
#if DEVICE_SPI_ASYNCH
@@ -259,6 +257,7 @@ class SPI : private NonCopyable<SPI> {
259257

260258
#if !defined(DOXYGEN_ONLY)
261259
protected:
260+
262261
/** SPI interrupt handler.
263262
*/
264263
void irq_handler_asynch(void);
@@ -338,6 +337,14 @@ class SPI : private NonCopyable<SPI> {
338337

339338
#if !defined(DOXYGEN_ONLY)
340339
protected:
340+
#ifdef SPI_COUNT
341+
// HAL must have defined this as a global enum
342+
typedef ::SPIName SPIName;
343+
#else
344+
// HAL may or may not have defined it - use a local definition
345+
enum SPIName { GlobalSPI };
346+
#endif
347+
341348
struct spi_peripheral_s {
342349
/* Internal SPI name identifying the resources. */
343350
SPIName name;

hal/spi_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern "C" {
6262
* @{
6363
*/
6464

65+
#ifdef SPI_COUNT
6566
/**
6667
* Returns a variant of the SPIName enum uniquely identifying a SPI peripheral of the device.
6768
* @param[in] mosi The pin to use for MOSI
@@ -70,6 +71,7 @@ extern "C" {
7071
* @return An SPI peripheral identifier
7172
*/
7273
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName mclk);
74+
#endif
7375

7476
/** Initialize the SPI peripheral
7577
*

0 commit comments

Comments
 (0)