File tree Expand file tree Collapse file tree 3 files changed +21
-13
lines changed Expand file tree Collapse file tree 3 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 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-
3226namespace mbed {
3327
3428SPI::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 ();
Original file line number Diff line number Diff line change 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)
261259protected:
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)
340339protected:
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;
Original file line number Diff line number Diff 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 */
7273SPIName spi_get_peripheral_name (PinName mosi , PinName miso , PinName mclk );
74+ #endif
7375
7476/** Initialize the SPI peripheral
7577 *
You can’t perform that action at this time.
0 commit comments