Skip to content

Commit

Permalink
minor improvements of RadioLib driver
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jun 24, 2024
1 parent 88cbedc commit a68ab0d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 15 deletions.
57 changes: 51 additions & 6 deletions software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const rfchip_ops_t lr112x_ops = {
Module *mod;
RADIO_TYPE *radio;

const rf_proto_desc_t *rl_protocol = &ogntp_proto_desc;
const rf_proto_desc_t *rl_protocol = &ogntp_proto_desc;

static int8_t lr112x_channel_prev = (int8_t) -1;

Expand Down Expand Up @@ -388,7 +388,8 @@ static void lr112x_setup()
case RF_CHECKSUM_TYPE_CCITT_1D02:
case RF_CHECKSUM_TYPE_CRC8_107:
case RF_CHECKSUM_TYPE_RS:
/* TBD */
/* CRC is driven by software */
state = radio->setCRC(0, 0);
break;
case RF_CHECKSUM_TYPE_GALLAGER:
case RF_CHECKSUM_TYPE_CRC_MODES:
Expand All @@ -407,16 +408,29 @@ static void lr112x_setup()
pkt_size += pkt_size;
break;
case RF_WHITENING_PN9:
case RF_CHECKSUM_TYPE_CRC_MODES:
case RF_WHITENING_NONE:
case RF_WHITENING_NICERF:
default:
break;
}
state = radio->fixedPacketLengthMode(pkt_size);

state = radio->disableAddressFiltering();
state = radio->setSyncWord((uint8_t *) rl_protocol->syncword,
(size_t) rl_protocol->syncword_size);

/* Work around premature P3I syncword detection */
if (rl_protocol->syncword_size == 2) {
uint8_t preamble = rl_protocol->preamble_type == RF_PREAMBLE_TYPE_AA ?
0xAA : 0x55;
uint8_t sword[4] = { preamble,
preamble,
rl_protocol->syncword[0],
rl_protocol->syncword[1]
};
state = radio->setSyncWord(sword, 4);
} else {
state = radio->setSyncWord((uint8_t *) rl_protocol->syncword,
(size_t) rl_protocol->syncword_size);
}
break;
}

Expand Down Expand Up @@ -465,6 +479,25 @@ static void lr112x_setup()
radio->setPacketReceivedAction(lr112x_receive_handler);
}

static bool memeqzero(const uint8_t *data, size_t length)
{
const uint8_t *p = data;
size_t len;

/* Check first 16 bytes manually */
for (len = 0; len < 16; len++) {
if (!length)
return true;
if (*p)
return false;
p++;
length--;
}

/* Now we know that's zero, memcmp with self. */
return memcmp((void *) data, (void *) p, length) == 0;
}

static bool lr112x_receive()
{
bool success = false;
Expand Down Expand Up @@ -495,7 +528,8 @@ static bool lr112x_receive()
state = radio->readData(rxPacket.payload, rxPacket.len);
lr112x_receive_active = false;

if (state == RADIOLIB_ERR_NONE) {
if (state == RADIOLIB_ERR_NONE &&
!memeqzero(rxPacket.payload, rxPacket.len)) {
size_t size = 0;
uint8_t offset;

Expand Down Expand Up @@ -647,6 +681,10 @@ static bool lr112x_receive()
}

memset(rxPacket.payload, 0, sizeof(rxPacket.payload));
#if USE_SX1262 && (RADIOLIB_GODMODE || RADIOLIB_LOW_LEVEL)
radio->writeBuffer(rxPacket.payload, rxPacket.len);
radio->setBufferBaseAddress();
#endif
rxPacket.len = 0;
}

Expand Down Expand Up @@ -795,6 +833,13 @@ static bool lr112x_transmit()

success = true;

memset(txPacket.payload, 0, sizeof(txPacket.payload));
#if USE_SX1262 && (RADIOLIB_GODMODE || RADIOLIB_LOW_LEVEL)
radio->setBufferBaseAddress();
radio->writeBuffer(txPacket.payload, txPacket.len);
radio->setBufferBaseAddress();
#endif

#if 0
// the packet was successfully transmitted
Serial.println(F("success!"));
Expand Down
14 changes: 12 additions & 2 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ unsigned long TaskInfoTime;
#endif /* USE_EPD_TASK */

const char *Hardware_Rev[] = {
[0] = "TBD",
[0] = "2024-02-28",
[1] = "TBD",
[2] = "TBD",
[3] = "Unknown"
Expand Down Expand Up @@ -1340,7 +1340,8 @@ static void ESP32_setup()

} else if (esp32_board == ESP32_LILYGO_T3S3_EPD) {

hw_info.model = SOFTRF_MODEL_INK;
hw_info.model = SOFTRF_MODEL_INK;
hw_info.revision = 0; /* 2024-02-28 */

#if ARDUINO_USB_CDC_ON_BOOT
SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS,
Expand All @@ -1357,6 +1358,8 @@ static void ESP32_setup()
lmic_pins.dio[0] = SOC_GPIO_PIN_T3S3_DIO1;
#endif /* USE_RADIOLIB */

pinMode(SOC_GPIO_PIN_T3S3_3V3EN, INPUT_PULLUP);

int uSD_SS_pin = SOC_GPIO_PIN_T3S3_SD_SS;

/* uSD-SPI init */
Expand Down Expand Up @@ -2477,6 +2480,13 @@ static void ESP32_fini(int reason)
pinMode(SOC_GPIO_PIN_HELTRK_VEXT_EN, INPUT);
pinMode(SOC_GPIO_PIN_HELTRK_LED, INPUT);

#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
esp_sleep_enable_ext1_wakeup(1ULL << SOC_GPIO_PIN_S3_BUTTON,
ESP_EXT1_WAKEUP_ALL_LOW);
#endif /* CONFIG_IDF_TARGET_ESP32C2 || C3 */
} else if (esp32_board == ESP32_LILYGO_T3S3_EPD) {
pinMode(SOC_GPIO_PIN_T3S3_3V3EN, INPUT_PULLDOWN);

#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
esp_sleep_enable_ext1_wakeup(1ULL << SOC_GPIO_PIN_S3_BUTTON,
ESP_EXT1_WAKEUP_ALL_LOW);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

/* ESP32-S3-MINI-1U-N4 */
#define SOC_GPIO_PIN_T3S3_CONS_RX 44
#define SOC_GPIO_PIN_T3S3_CONS_TX 43
#define SOC_GPIO_PIN_T3S3_CONS_RX 39
#define SOC_GPIO_PIN_T3S3_CONS_TX 40

// GNSS module (ext.)
#define SOC_GPIO_PIN_T3S3_GNSS_RX 35 /* TBD */
#define SOC_GPIO_PIN_T3S3_GNSS_TX 38 /* TBD */
#define SOC_GPIO_PIN_T3S3_GNSS_PPS 36 /* TBD */
#define SOC_GPIO_PIN_T3S3_GNSS_RX 44
#define SOC_GPIO_PIN_T3S3_GNSS_TX 43
#define SOC_GPIO_PIN_T3S3_GNSS_PPS 38

// USB CDC/JTAG
#define SOC_GPIO_PIN_T3S3_USB_DP 20
Expand All @@ -26,9 +26,11 @@
#define SOC_GPIO_PIN_T3S3_ANT_RX 21
#define SOC_GPIO_PIN_T3S3_ANT_TX 10

#define SOC_GPIO_PIN_T3S3_3V3EN 35

// I2C (ext.)
#define SOC_GPIO_PIN_T3S3_SDA 45 /* TBD */
#define SOC_GPIO_PIN_T3S3_SCL 46 /* TBD */
#define SOC_GPIO_PIN_T3S3_SDA 41 /* 46 ? */
#define SOC_GPIO_PIN_T3S3_SCL 42

// status LED
#define SOC_GPIO_PIN_T3S3_LED 37
Expand Down

0 comments on commit a68ab0d

Please sign in to comment.