From 5a9a8dd1fa4d063cb04b004cf67f38122d3ab84d Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Tue, 19 Mar 2024 11:15:01 +0300 Subject: [PATCH] RA4M1: will drive sub-1GHz radio with 'Software SPI' for a while --- software/firmware/source/SoftRF/src/driver/RF.cpp | 5 +++++ .../firmware/source/SoftRF/src/platform/RA4M1.cpp | 11 +++++++++-- software/firmware/source/SoftRF/src/platform/RA4M1.h | 6 ++++++ .../firmware/source/libraries/SoftSPI/SoftSPI.cpp | 7 ++++--- software/firmware/source/libraries/SoftSPI/SoftSPI.h | 4 ++-- .../source/libraries/arduino-lmic/src/hal/hal.cpp | 7 +++++++ 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/software/firmware/source/SoftRF/src/driver/RF.cpp b/software/firmware/source/SoftRF/src/driver/RF.cpp index 53b851d10..92b6fcef2 100644 --- a/software/firmware/source/SoftRF/src/driver/RF.cpp +++ b/software/firmware/source/SoftRF/src/driver/RF.cpp @@ -1119,6 +1119,11 @@ static bool sx12xx_transmit() os_setCallback(&sx12xx_txjob, sx12xx_tx_func); unsigned long tx_timeout = LMIC.protocol ? (LMIC.protocol->air_time + 25) : 60; + +#if defined(USE_SOFTSPI) + tx_timeout += tx_timeout; +#endif + unsigned long tx_start = millis(); while (sx12xx_transmit_complete == false) { diff --git a/software/firmware/source/SoftRF/src/platform/RA4M1.cpp b/software/firmware/source/SoftRF/src/platform/RA4M1.cpp index 56fb28c3a..de3e61ff6 100644 --- a/software/firmware/source/SoftRF/src/platform/RA4M1.cpp +++ b/software/firmware/source/SoftRF/src/platform/RA4M1.cpp @@ -80,13 +80,18 @@ const char *RA4M1_Device_Manufacturer = SOFTRF_IDENT; const char *RA4M1_Device_Model = "Academy Edition"; const uint16_t RA4M1_Device_Version = SOFTRF_USB_FW_VERSION; -#if defined(ARDUINO_UNOR4_WIFI) +#if defined(ARDUINO_UNOR4_WIFI) && (__GNUC__ <= 7) #include "ArduinoGraphics.h" #include "Arduino_LED_Matrix.h" ArduinoLEDMatrix matrix; #endif /* ARDUINO_UNOR4_WIFI */ +#if defined(USE_SOFTSPI) +#include +SoftSPI RadioSPI(SOC_GPIO_PIN_MOSI,SOC_GPIO_PIN_MISO, SOC_GPIO_PIN_SCK); +#endif /* USE_SOFTSPI */ + static void RA4M1_setup() { if (1U == R_SYSTEM->RSTSR0_b.PORF) /* Power on Reset */ @@ -139,7 +144,7 @@ static void RA4M1_setup() for (int i=0; i < 20; i++) {if (Serial) break; else delay(100);} #endif -#if defined(ARDUINO_UNOR4_WIFI) +#if defined(ARDUINO_UNOR4_WIFI) && (__GNUC__ <= 7) matrix.begin(); matrix.beginDraw(); @@ -449,7 +454,9 @@ static void RA4M1_EEPROM_extension(int cmd) static void RA4M1_SPI_begin() { +#if !defined(EXCLUDE_NRF905) || defined(USE_OGN_RF_DRIVER) SPI.begin(); +#endif } static void RA4M1_swSer_begin(unsigned long baud) diff --git a/software/firmware/source/SoftRF/src/platform/RA4M1.h b/software/firmware/source/SoftRF/src/platform/RA4M1.h index 0fcf9f9e3..59107eab1 100644 --- a/software/firmware/source/SoftRF/src/platform/RA4M1.h +++ b/software/firmware/source/SoftRF/src/platform/RA4M1.h @@ -103,6 +103,12 @@ struct rst_info { #define SOC_GPIO_PIN_SCK PIN_SPI_SCK #define SOC_GPIO_PIN_SS PIN_SPI_CS +#include +extern SoftSPI RadioSPI; +#undef SPI +#define SPI RadioSPI +#define USE_SOFTSPI + /* NRF905 */ #define SOC_GPIO_PIN_TXE SOC_UNUSED_PIN #define SOC_GPIO_PIN_CE SOC_UNUSED_PIN diff --git a/software/firmware/source/libraries/SoftSPI/SoftSPI.cpp b/software/firmware/source/libraries/SoftSPI/SoftSPI.cpp index d2e7e5be7..9f89a8a91 100644 --- a/software/firmware/source/libraries/SoftSPI/SoftSPI.cpp +++ b/software/firmware/source/libraries/SoftSPI/SoftSPI.cpp @@ -2,7 +2,8 @@ #if defined(ARDUINO_ARCH_NRF52) SoftSPI::SoftSPI(uint8_t mosi, uint8_t miso, uint8_t sck) : SPIClass(NRF_SPIM0, 0, 0, 0) -#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) +#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) || \ + defined(ARDUINO_ARCH_RENESAS) SoftSPI::SoftSPI(uint8_t mosi, uint8_t miso, uint8_t sck) : SPIClass() #else #error "This build architecture is not supported!" @@ -133,10 +134,10 @@ void SoftSPI::endTransaction(void) { } -#if defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS) /* compatibility with Arduino RP2040 Core */ void SoftSPI::usingInterrupt(int interruptNumber) {} void SoftSPI::notUsingInterrupt(int interruptNumber) {} void SoftSPI::attachInterrupt() {} void SoftSPI::detachInterrupt() {} -#endif /* ARDUINO_ARCH_RP2040 */ +#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RENESAS */ diff --git a/software/firmware/source/libraries/SoftSPI/SoftSPI.h b/software/firmware/source/libraries/SoftSPI/SoftSPI.h index 19eebe412..5037371da 100644 --- a/software/firmware/source/libraries/SoftSPI/SoftSPI.h +++ b/software/firmware/source/libraries/SoftSPI/SoftSPI.h @@ -24,13 +24,13 @@ class SoftSPI : public SPIClass // Transaction Functions void beginTransaction(SPISettings settings); void endTransaction(void); -#if defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS) /* compatibility with Arduino RP2040 Core */ void usingInterrupt(int interruptNumber); void notUsingInterrupt(int interruptNumber); void attachInterrupt(); void detachInterrupt(); -#endif /* ARDUINO_ARCH_RP2040 */ +#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RENESAS */ private: uint8_t _miso; uint8_t _mosi; diff --git a/software/firmware/source/libraries/arduino-lmic/src/hal/hal.cpp b/software/firmware/source/libraries/arduino-lmic/src/hal/hal.cpp index 4fc4f8d3a..44ba66434 100644 --- a/software/firmware/source/libraries/arduino-lmic/src/hal/hal.cpp +++ b/software/firmware/source/libraries/arduino-lmic/src/hal/hal.cpp @@ -21,6 +21,13 @@ #include #endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */ +#if defined(ARDUINO_ARCH_RENESAS) +#include +extern SoftSPI RadioSPI; +#undef SPI +#define SPI RadioSPI +#endif /* ARDUINO_ARCH_RENESAS */ + #include "../lmic.h" #include "hal.h" #include