Skip to content

Commit

Permalink
[EFR32] misc. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Aug 26, 2024
1 parent 97c1abf commit 3ffea83
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 21 deletions.
3 changes: 2 additions & 1 deletion software/firmware/source/SoftRF/src/driver/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void EEPROM_defaults()
eeprom_block.field.magic = SOFTRF_EEPROM_MAGIC;
eeprom_block.field.version = SOFTRF_EEPROM_VERSION;
eeprom_block.field.settings.mode = SOFTRF_MODE_NORMAL;
eeprom_block.field.settings.rf_protocol = hw_info.model == SOFTRF_MODEL_BRACELET ?
eeprom_block.field.settings.rf_protocol = hw_info.model == SOFTRF_MODEL_BRACELET ||
hw_info.model == SOFTRF_MODEL_CARD ?
RF_PROTOCOL_FANET :
hw_info.model == SOFTRF_MODEL_ES ?
RF_PROTOCOL_ADSB_1090 :
Expand Down
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/src/driver/GNSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ byte GNSS_setup() {
hw_info.model == SOFTRF_MODEL_PRIME_MK3 ||
hw_info.model == SOFTRF_MODEL_UNI ||
hw_info.model == SOFTRF_MODEL_BADGE ||
hw_info.model == SOFTRF_MODEL_ACADEMY ||
hw_info.model == SOFTRF_MODEL_LEGO ||
hw_info.model == SOFTRF_MODEL_ES ||
hw_info.model == SOFTRF_MODEL_BALKAN ||
Expand Down
54 changes: 44 additions & 10 deletions software/firmware/source/SoftRF/src/platform/EFR32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#if defined(ARDUINO_ARCH_SILABS)

#include <SPI.h>
#include <Wire.h>

#include "../system/SoC.h"
#include "../driver/RF.h"
Expand All @@ -43,7 +42,7 @@ lmic_pinmap lmic_pins = {
.rxe = LMIC_UNUSED_PIN,
.rst = SOC_GPIO_PIN_RST,
.dio = {LMIC_UNUSED_PIN, LMIC_UNUSED_PIN, LMIC_UNUSED_PIN},
.busy = LMIC_UNUSED_PIN,
.busy = SOC_GPIO_PIN_BUSY,
.tcxo = LMIC_UNUSED_PIN,
};

Expand Down Expand Up @@ -112,6 +111,19 @@ eeprom_t eeprom_block;
settings_t *settings = &eeprom_block.field.settings;
#endif /* EXCLUDE_EEPROM */

#if defined(USE_SOFTSPI)
#include <SoftSPI.h>
SoftSPI RadioSPI(SOC_GPIO_PIN_MOSI,SOC_GPIO_PIN_MISO, SOC_GPIO_PIN_SCK);
#endif /* USE_SOFTSPI */

#if defined __has_include
#if __has_include(<FlexWire.h>)
#include <FlexWire.h>

FlexWire Wire = FlexWire(SOC_GPIO_PIN_SDA, SOC_GPIO_PIN_SCL, false);
#endif /* FlexWire.h */
#endif /* __has_include */

static void EFR32_setup()
{
uint32_t reset_cause = get_system_reset_cause();
Expand Down Expand Up @@ -183,6 +195,10 @@ static void EFR32_setup()
reset_info.reason = REASON_EXCEPTION_RST;
}

#if defined(USE_RADIOLIB)
lmic_pins.dio[0] = SOC_GPIO_PIN_DIO1;
#endif /* USE_RADIOLIB */

#if SOC_GPIO_RADIO_LED_TX != SOC_UNUSED_PIN
pinMode(SOC_GPIO_RADIO_LED_TX, OUTPUT);
digitalWrite(SOC_GPIO_RADIO_LED_TX, ! LED_STATE_ON);
Expand Down Expand Up @@ -302,7 +318,25 @@ static void EFR32_loop()

static void EFR32_fini(int reason)
{
LowPower.attachInterruptWakeup(SOC_GPIO_PIN_BUTTON, nullptr, RISING);
switch (reason)
{
#if SOC_GPIO_PIN_BUTTON != SOC_UNUSED_PIN
case SOFTRF_SHUTDOWN_BUTTON:
case SOFTRF_SHUTDOWN_LOWBAT:
/* the GPIO must have EM4 wake functionality */
pinMode(SOC_GPIO_PIN_BUTTON, INPUT_PULLUP);
LowPower.attachInterruptWakeup(SOC_GPIO_PIN_BUTTON, nullptr, FALLING);
break;
#endif /* SOC_GPIO_PIN_BUTTON != SOC_UNUSED_PIN */
case SOFTRF_SHUTDOWN_NMEA:
/* the GPIO must have EM4 wake functionality */
pinMode(SOC_GPIO_PIN_BUTTON, INPUT_PULLUP);
LowPower.attachInterruptWakeup(SOC_GPIO_PIN_CONS_RX, nullptr, FALLING);
break;
default:
break;
}

LowPower.deepSleep();
}

Expand Down Expand Up @@ -413,17 +447,15 @@ static void EFR32_EEPROM_extension(int cmd)
settings->mode = SOFTRF_MODE_NORMAL;
}

if (settings->nmea_out == NMEA_BLUETOOTH ||
settings->nmea_out == NMEA_UDP ||
if (settings->nmea_out == NMEA_USB ||
settings->nmea_out == NMEA_UDP ||
settings->nmea_out == NMEA_TCP ) {
settings->nmea_out = NMEA_UART;
}
if (settings->gdl90 == GDL90_BLUETOOTH ||
settings->gdl90 == GDL90_UDP) {
if (settings->gdl90 == GDL90_USB || settings->gdl90 == GDL90_UDP) {
settings->gdl90 = GDL90_UART;
}
if (settings->d1090 == D1090_BLUETOOTH ||
settings->d1090 == D1090_UDP) {
if (settings->d1090 == D1090_USB || settings->d1090 == D1090_UDP) {
settings->d1090 = D1090_UART;
}

Expand All @@ -436,7 +468,9 @@ static void EFR32_EEPROM_extension(int cmd)

static void EFR32_SPI_begin()
{
#if !defined(EXCLUDE_NRF905) || defined(USE_OGN_RF_DRIVER)
SPI.begin();
#endif
}

static void EFR32_swSer_begin(unsigned long baud)
Expand Down Expand Up @@ -603,7 +637,7 @@ static void EFR32_Button_setup()
int button_pin = SOC_GPIO_PIN_BUTTON;

// Button(s) uses external pull up resistor.
pinMode(button_pin, INPUT);
pinMode(button_pin, INPUT_PULLUP);

button_1.init(button_pin);

Expand Down
8 changes: 7 additions & 1 deletion software/firmware/source/SoftRF/src/platform/EFR32.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ struct rst_info {
#define SOC_GPIO_PIN_SCK PIN_SPI_SCK
#define SOC_GPIO_PIN_SS PIN_SPI_SS

//#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
#define SOC_GPIO_PIN_PWR SOC_UNUSED_PIN

/* SX1276 */
#define SOC_GPIO_PIN_RST D0 /* PA0 */
#define SOC_GPIO_PIN_BUSY SOC_UNUSED_PIN
#define SOC_GPIO_PIN_BUSY LMIC_UNUSED_PIN
#define SOC_GPIO_PIN_DIO1 D5 /* PC6 */

/* I2C */
Expand Down
3 changes: 2 additions & 1 deletion software/firmware/source/libraries/OGN/manchester.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
defined(ENERGIA_ARCH_CC13XX) || defined(ENERGIA_ARCH_CC13X2) || \
(defined(ARDUINO_ARCH_RP2040) && defined(ARDUINO_ARCH_MBED)) || \
(defined(ARDUINO_ARCH_NRF52840) && defined(ARDUINO_ARCH_MBED)) || \
defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_SAMD)
defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_SAMD) || \
defined(ARDUINO_ARCH_SILABS)
#include <avr/pgmspace.h>
#endif

Expand Down
9 changes: 5 additions & 4 deletions software/firmware/source/libraries/SoftSPI/SoftSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#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) || \
defined(ARDUINO_ARCH_RENESAS)
defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_SILABS)
SoftSPI::SoftSPI(uint8_t mosi, uint8_t miso, uint8_t sck) : SPIClass()
#else
#error "This build architecture is not supported!"
#endif /* ARDUINO_ARCH_NRF52 || ARDUINO_ARCH_ESP32 || ARDUINO_ARCH_RP2040 */
#endif /* NRF52 || ESP32 || RP2040 || RENESAS || SILABS */
{
_mosi = mosi;
_miso = miso;
Expand Down Expand Up @@ -134,10 +134,11 @@ void SoftSPI::endTransaction(void)
{
}

#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS)
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS) || \
defined(ARDUINO_ARCH_SILABS)
/* 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 || ARDUINO_ARCH_RENESAS */
#endif /* RP2040 || RENESAS || SILABS */
5 changes: 3 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,14 @@ class SoftSPI : public SPIClass
// Transaction Functions
void beginTransaction(SPISettings settings);
void endTransaction(void);
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS)
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RENESAS) || \
defined(ARDUINO_ARCH_SILABS)
/* compatibility with Arduino RP2040 Core */
void usingInterrupt(int interruptNumber);
void notUsingInterrupt(int interruptNumber);
void attachInterrupt();
void detachInterrupt();
#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RENESAS */
#endif /* RP2040 || RENESAS || SILABS */
private:
uint8_t _miso;
uint8_t _mosi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#include <cc13xx/cc13xx.h>
#endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */

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

#include "../lmic.h"
#include "hal.h"
Expand Down

0 comments on commit 3ffea83

Please sign in to comment.