Skip to content

Commit 36cdaf4

Browse files
authored
Add hwSPI to HAL (#1234)
1 parent 1ee64f2 commit 36cdaf4

File tree

15 files changed

+114
-103
lines changed

15 files changed

+114
-103
lines changed

MySensors.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,6 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
333333
#define MY_RAM_ROUTING_TABLE_ENABLED
334334
#endif
335335

336-
// SOFTSPI
337-
#ifdef MY_SOFTSPI
338-
#if defined(ARDUINO_ARCH_ESP8266)
339-
#error Soft SPI is not available on ESP8266
340-
#endif
341-
#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h"
342-
#endif
343-
344336
// SOFTSERIAL
345337
#if defined(MY_GSM_TX) != defined(MY_GSM_RX)
346338
#error Both, MY_GSM_TX and MY_GSM_RX need to be defined when using SoftSerial

hal/architecture/AVR/MyHwAVR.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919

2020
#include "MyHwAVR.h"
21-
#include "avr/boot.h"
22-
2321

2422
bool hwInit(void)
2523
{

hal/architecture/AVR/MyHwAVR.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
#include <avr/power.h>
2727
#include <avr/interrupt.h>
2828
#include <avr/wdt.h>
29+
#include <avr/boot.h>
2930
#include <util/atomic.h>
31+
#include <SPI.h>
3032

33+
// SOFTSPI
34+
#ifdef MY_SOFTSPI
35+
#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h"
36+
#endif
3137

3238
#ifdef __cplusplus
3339
#include <Arduino.h>
@@ -70,6 +76,12 @@ bool hwInit(void);
7076
inline void hwRandomNumberInit(void);
7177
void hwInternalSleep(uint32_t ms);
7278

79+
#if defined(MY_SOFTSPI)
80+
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, 0> hwSPI; //!< hwSPI
81+
#else
82+
#define hwSPI SPI //!< hwSPI
83+
#endif
84+
7385
#ifndef DOXYGEN
7486
#define MY_CRITICAL_SECTION ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
7587
#endif /* DOXYGEN */

hal/architecture/ESP32/MyHwESP32.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include <WiFi.h>
4242
#include "EEPROM.h"
43+
#include <SPI.h>
4344

4445
#ifdef __cplusplus
4546
#include <Arduino.h>
@@ -82,6 +83,12 @@ uint8_t hwReadConfig(const int addr);
8283
ssize_t hwGetentropy(void *__buffer, size_t __length);
8384
#define MY_HW_HAS_GETENTROPY
8485

86+
// SOFTSPI
87+
#ifdef MY_SOFTSPI
88+
#error Soft SPI is not available on this architecture!
89+
#endif
90+
#define hwSPI SPI //!< hwSPI
91+
8592
/**
8693
* Restore interrupt state.
8794
* Helper function for MY_CRITICAL_SECTION.

hal/architecture/ESP8266/MyHwESP8266.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef MyHwESP8266_h
2020
#define MyHwESP8266_h
2121

22+
#include <SPI.h>
23+
2224
#ifdef __cplusplus
2325
#include <Arduino.h>
2426
#endif
@@ -53,6 +55,13 @@ uint8_t hwReadConfig(const int addr);
5355
ssize_t hwGetentropy(void *__buffer, size_t __length);
5456
//#define MY_HW_HAS_GETENTROPY
5557

58+
// SOFTSPI
59+
#ifdef MY_SOFTSPI
60+
#error Soft SPI is not available on this architecture!
61+
#endif
62+
#define hwSPI SPI //!< hwSPI
63+
64+
5665
/**
5766
* Restore interrupt state.
5867
* Helper function for MY_CRITICAL_SECTION.

hal/architecture/Linux/MyHwLinuxGeneric.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <pthread.h>
2525
#include "SerialPort.h"
2626
#include "StdInOutStream.h"
27+
#include <SPI.h>
2728

2829
#define CRYPTO_LITTLE_ENDIAN
2930

@@ -59,6 +60,12 @@ ssize_t hwGetentropy(void *__buffer, size_t __length);
5960
#define MY_HW_HAS_GETENTROPY
6061
inline uint32_t hwMillis(void);
6162

63+
// SOFTSPI
64+
#ifdef MY_SOFTSPI
65+
#error Soft SPI is not available on this architecture!
66+
#endif
67+
#define hwSPI SPI //!< hwSPI
68+
6269
#ifdef MY_RF24_IRQ_PIN
6370
static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;
6471

hal/architecture/NRF5/MyHwNRF5.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "drivers/NVM/VirtualPage.h"
5656
#include <avr/dtostrf.h>
5757
#include <nrf.h>
58+
#include <SPI.h>
5859

5960
// mapping
6061
#ifndef strncpy_P
@@ -125,6 +126,13 @@ void hwRandomNumberInit(void);
125126
ssize_t hwGetentropy(void *__buffer, size_t __length);
126127
#define MY_HW_HAS_GETENTROPY
127128

129+
// SOFTSPI
130+
#ifdef MY_SOFTSPI
131+
#error Soft SPI is not available on this architecture!
132+
#endif
133+
#define hwSPI SPI //!< hwSPI
134+
135+
128136
/**
129137
* Disable all interrupts.
130138
* Helper function for MY_CRITICAL_SECTION.

hal/architecture/SAMD/MyHwSAMD.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef MyHwSAMD_h
2020
#define MyHwSAMD_h
2121

22+
#include <SPI.h>
23+
2224
#ifdef __cplusplus
2325
#include <Arduino.h>
2426
#endif
@@ -71,6 +73,13 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length);
7173
void hwWriteConfig(const int addr, uint8_t value);
7274
uint8_t hwReadConfig(const int addr);
7375

76+
// SOFTSPI
77+
#ifdef MY_SOFTSPI
78+
#error Soft SPI is not available on this architecture!
79+
#endif
80+
#define hwSPI SPI //!< hwSPI
81+
82+
7483
/**
7584
* Disable all interrupts.
7685
* Helper function for MY_CRITICAL_SECTION.

hal/architecture/STM32F1/MyHwSTM32F1.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <libmaple/iwdg.h>
2424
#include <itoa.h>
2525
#include <EEPROM.h>
26+
#include <SPI.h>
27+
2628
#ifdef __cplusplus
2729
#include <Arduino.h>
2830
#endif
@@ -76,6 +78,13 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length);
7678
void hwWriteConfig(const int addr, uint8_t value);
7779
uint8_t hwReadConfig(const int addr);
7880

81+
// SOFTSPI
82+
#ifdef MY_SOFTSPI
83+
#error Soft SPI is not available on this architecture!
84+
#endif
85+
#define hwSPI SPI //!< hwSPI
86+
87+
7988
#ifndef DOXYGEN
8089
#define MY_CRITICAL_SECTION
8190
#endif /* DOXYGEN */

hal/architecture/Teensy3/MyHwTeensy3.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#ifndef MyHwTeensy3_h
2929
#define MyHwTeensy3_h
3030

31+
#include <SPI.h>
32+
3133
#ifdef __cplusplus
3234
#include <Arduino.h>
3335
#endif
@@ -72,6 +74,13 @@ void hwReboot(void);
7274
#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void *)__buf, (const void *)__pos, (uint32_t)__length)
7375
#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((const void *)__buf, (void *)__pos, (uint32_t)__length)
7476

77+
// SOFTSPI
78+
#ifdef MY_SOFTSPI
79+
#error Soft SPI is not available on this architecture!
80+
#endif
81+
#define hwSPI SPI //!< hwSPI
82+
83+
7584
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
7685
#define MY_HW_HAS_GETENTROPY
7786
#endif

0 commit comments

Comments
 (0)