Skip to content

Commit

Permalink
RA4M1: will drive sub-1GHz radio with 'Software SPI' for a while
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Mar 19, 2024
1 parent 69ae24c commit 5a9a8dd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions software/firmware/source/SoftRF/src/platform/RA4M1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.h>
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 */
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions software/firmware/source/SoftRF/src/platform/RA4M1.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ struct rst_info {
#define SOC_GPIO_PIN_SCK PIN_SPI_SCK
#define SOC_GPIO_PIN_SS PIN_SPI_CS

#include <SoftSPI.h>
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
Expand Down
7 changes: 4 additions & 3 deletions software/firmware/source/libraries/SoftSPI/SoftSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions software/firmware/source/libraries/SoftSPI/SoftSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include <cc13xx/cc13xx.h>
#endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */

#if defined(ARDUINO_ARCH_RENESAS)
#include <SoftSPI.h>
extern SoftSPI RadioSPI;
#undef SPI
#define SPI RadioSPI
#endif /* ARDUINO_ARCH_RENESAS */

#include "../lmic.h"
#include "hal.h"
#include <stdio.h>
Expand Down

1 comment on commit 5a9a8dd

@lyusupov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.