Support USB comms on Heltec

This commit is contained in:
Sassa NF
2024-12-24 11:59:54 +00:00
parent c6833ee3b0
commit de5f3c8e61
5 changed files with 28 additions and 15 deletions

View File

@@ -43,28 +43,38 @@ void _onReceive1()
Comms1->_onReceive();
}
#if ARDUINO_USB_MODE
#define IF_CDC_EVENT(e, data) \
arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data; \
if (event_base == ARDUINO_HW_CDC_EVENTS && event_id == ARDUINO_HW_CDC_##e)
#else
#define IF_CDC_EVENT(e, data) \
arduino_usb_cdc_event_data_t *data = (arduino_usb_cdc_event_data_t *)event_data; \
if (event_base == ARDUINO_USB_CDC_EVENTS && event_id == ARDUINO_USB_CDC_##e)
#endif
void _onUsbEvent0(void *arg, esp_event_base_t event_base, int32_t event_id,
void *event_data)
{
if (event_base == ARDUINO_HW_CDC_EVENTS)
{
arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data;
if (event_id == ARDUINO_HW_CDC_RX_EVENT)
{
_onReceiveUsb(data->rx.len);
}
}
IF_CDC_EVENT(RX_EVENT, data) { _onReceiveUsb(data->rx.len); }
}
bool Comms::initComms(Config &c)
{
bool fine = false;
#ifndef HELTEC
#ifdef ARDUINO_USB_CDC_ON_BOOT
if (c.listen_on_usb.equalsIgnoreCase("readline"))
{
// comms using readline plaintext protocol
HostComms = new ReadlineComms("Host", Serial);
#if ARDUINO_USB_MODE
// if Serial is HWCDC...
Serial.onEvent(ARDUINO_HW_CDC_RX_EVENT, _onUsbEvent0);
#else
// if Serial is USBCDC...
Serial.onEvent(ARDUINO_USB_CDC_RX_EVENT, _onUsbEvent0);
#endif
Serial.begin();
Serial.println("Initialized communications on Serial using readline protocol");

View File

@@ -7,7 +7,7 @@
#include <LiLyGo.h>
#include <config.h>
#ifdef HELTEC
#ifndef ARDUINO_USB_CDC_ON_BOOT
#define SERIAL0 Serial
#else
#define SERIAL0 Serial0

View File

@@ -384,21 +384,22 @@ LoRaConfig *configureLora(String cfg)
}
String k = param.substring(0, j);
param = param.substring(j + 1);
if (k.equalsIgnoreCase("sync_word"))
{
lora->sync_word = (uint8_t)fromHex(param.substring(j + 1));
lora->sync_word = (uint8_t)fromHex(param);
continue;
}
int v = param.substring(j + 1).toInt();
if (k.equalsIgnoreCase("freq"))
{
lora->freq = (uint16_t)v;
lora->freq = param.toFloat();
continue;
}
int v = param.toInt();
if (k.equalsIgnoreCase("bw"))
{
lora->bw = (uint16_t)v;

View File

@@ -12,7 +12,7 @@ struct ScanRange
struct LoRaConfig
{
uint16_t freq;
float freq;
uint16_t bw;
uint8_t sf;
uint8_t cr;

View File

@@ -34,6 +34,8 @@ lib_deps =
build_flags =
-DHELTEC_POWER_BUTTON
-DHELTEC
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1
[env:heltec_wifi_lora_32_V3-OSD]
platform = espressif32