Skip to content

Add hwSPI to HAL #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions MySensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,6 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#define MY_RAM_ROUTING_TABLE_ENABLED
#endif

// SOFTSPI
#ifdef MY_SOFTSPI
#if defined(ARDUINO_ARCH_ESP8266)
#error Soft SPI is not available on ESP8266
#endif
#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h"
#endif

// SOFTSERIAL
#if defined(MY_GSM_TX) != defined(MY_GSM_RX)
#error Both, MY_GSM_TX and MY_GSM_RX need to be defined when using SoftSerial
Expand Down
2 changes: 0 additions & 2 deletions hal/architecture/AVR/MyHwAVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/

#include "MyHwAVR.h"
#include "avr/boot.h"


bool hwInit(void)
{
Expand Down
12 changes: 12 additions & 0 deletions hal/architecture/AVR/MyHwAVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
#include <avr/power.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <util/atomic.h>
#include <SPI.h>

// SOFTSPI
#ifdef MY_SOFTSPI
#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h"
#endif

#ifdef __cplusplus
#include <Arduino.h>
Expand Down Expand Up @@ -70,6 +76,12 @@ bool hwInit(void);
inline void hwRandomNumberInit(void);
void hwInternalSleep(uint32_t ms);

#if defined(MY_SOFTSPI)
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, 0> hwSPI; //!< hwSPI
#else
#define hwSPI SPI //!< hwSPI
#endif

#ifndef DOXYGEN
#define MY_CRITICAL_SECTION ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
#endif /* DOXYGEN */
Expand Down
7 changes: 7 additions & 0 deletions hal/architecture/ESP32/MyHwESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include <WiFi.h>
#include "EEPROM.h"
#include <SPI.h>

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

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI

/**
* Restore interrupt state.
* Helper function for MY_CRITICAL_SECTION.
Expand Down
9 changes: 9 additions & 0 deletions hal/architecture/ESP8266/MyHwESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef MyHwESP8266_h
#define MyHwESP8266_h

#include <SPI.h>

#ifdef __cplusplus
#include <Arduino.h>
#endif
Expand Down Expand Up @@ -53,6 +55,13 @@ uint8_t hwReadConfig(const int addr);
ssize_t hwGetentropy(void *__buffer, size_t __length);
//#define MY_HW_HAS_GETENTROPY

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI


/**
* Restore interrupt state.
* Helper function for MY_CRITICAL_SECTION.
Expand Down
7 changes: 7 additions & 0 deletions hal/architecture/Linux/MyHwLinuxGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pthread.h>
#include "SerialPort.h"
#include "StdInOutStream.h"
#include <SPI.h>

#define CRYPTO_LITTLE_ENDIAN

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

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI

#ifdef MY_RF24_IRQ_PIN
static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down
8 changes: 8 additions & 0 deletions hal/architecture/NRF5/MyHwNRF5.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "drivers/NVM/VirtualPage.h"
#include <avr/dtostrf.h>
#include <nrf.h>
#include <SPI.h>

// mapping
#ifndef strncpy_P
Expand Down Expand Up @@ -125,6 +126,13 @@ void hwRandomNumberInit(void);
ssize_t hwGetentropy(void *__buffer, size_t __length);
#define MY_HW_HAS_GETENTROPY

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI


/**
* Disable all interrupts.
* Helper function for MY_CRITICAL_SECTION.
Expand Down
9 changes: 9 additions & 0 deletions hal/architecture/SAMD/MyHwSAMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef MyHwSAMD_h
#define MyHwSAMD_h

#include <SPI.h>

#ifdef __cplusplus
#include <Arduino.h>
#endif
Expand Down Expand Up @@ -71,6 +73,13 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length);
void hwWriteConfig(const int addr, uint8_t value);
uint8_t hwReadConfig(const int addr);

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI


/**
* Disable all interrupts.
* Helper function for MY_CRITICAL_SECTION.
Expand Down
9 changes: 9 additions & 0 deletions hal/architecture/STM32F1/MyHwSTM32F1.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <libmaple/iwdg.h>
#include <itoa.h>
#include <EEPROM.h>
#include <SPI.h>

#ifdef __cplusplus
#include <Arduino.h>
#endif
Expand Down Expand Up @@ -76,6 +78,13 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length);
void hwWriteConfig(const int addr, uint8_t value);
uint8_t hwReadConfig(const int addr);

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI


#ifndef DOXYGEN
#define MY_CRITICAL_SECTION
#endif /* DOXYGEN */
Expand Down
9 changes: 9 additions & 0 deletions hal/architecture/Teensy3/MyHwTeensy3.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef MyHwTeensy3_h
#define MyHwTeensy3_h

#include <SPI.h>

#ifdef __cplusplus
#include <Arduino.h>
#endif
Expand Down Expand Up @@ -72,6 +74,13 @@ void hwReboot(void);
#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void *)__buf, (const void *)__pos, (uint32_t)__length)
#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((const void *)__buf, (void *)__pos, (uint32_t)__length)

// SOFTSPI
#ifdef MY_SOFTSPI
#error Soft SPI is not available on this architecture!
#endif
#define hwSPI SPI //!< hwSPI


#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define MY_HW_HAS_GETENTROPY
#endif
Expand Down
28 changes: 4 additions & 24 deletions hal/transport/RF24/driver/RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

#include "RF24registers.h"

#if !defined(RF24_SPI)
#define RF24_SPI hwSPI //!< default SPI
#endif

#if defined(ARDUINO_ARCH_AVR)
#define DEFAULT_RF24_CE_PIN (9) //!< DEFAULT_RF24_CE_PIN
#elif defined(ARDUINO_ARCH_ESP8266)
Expand Down Expand Up @@ -92,30 +96,6 @@

#define RF24_BROADCAST_ADDRESS (255u) //!< RF24_BROADCAST_ADDRESS

#if defined(ARDUINO) && !defined(__arm__) && !defined(RF24_SPI)
#include <SPI.h>
#if defined(MY_SOFTSPI)
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RF24_SPI_DATA_MODE>
RF24_SPI;
#else
#define RF24_SPI SPI //!< SPI
#endif
#else
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#if defined(__arm__) || defined(__linux__)
#include <SPI.h>
#else
extern HardwareSPI SPI; //!< SPI
#endif

#if !defined(RF24_SPI)
#define RF24_SPI SPI //!< SPI
#endif
#endif

// verify RF24 IRQ defs
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
#if !defined(MY_RF24_IRQ_PIN)
Expand Down
24 changes: 4 additions & 20 deletions hal/transport/RFM69/driver/new/RFM69_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

#include "RFM69registers_new.h"

#if !defined(RFM69_SPI)
#define RFM69_SPI hwSPI //!< default SPI
#endif

#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_ATmega32U4__)
#define DEFAULT_RFM69_IRQ_PIN (3) //!< DEFAULT_RFM69_IRQ_PIN
Expand Down Expand Up @@ -100,26 +104,6 @@
#define RFM69_SPI_DATA_ORDER MSBFIRST //!< SPI data order
#define RFM69_SPI_DATA_MODE SPI_MODE0 //!< SPI mode

#if defined(ARDUINO) && !defined(__arm__) && !defined(RFM69_SPI)
#include <SPI.h>
#if defined(MY_SOFTSPI)
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, RFM69_SPI_DATA_MODE>RFM69_SPI;
#else
#define RFM69_SPI SPI
#endif
#else
#if defined(__arm__) || defined(__linux__)
#include <SPI.h>
#else
extern HardwareSPI SPI; //!< SPI
#endif

#if !defined(RFM69_SPI)
#define RFM69_SPI SPI //!< SPI
#endif
#endif


// Additional radio settings
#define RFM69_SYNCVALUE1 (0x2D) //!< Make this compatible with sync1 byte of RFM12B lib

Expand Down
Loading