Skip to content

Commit

Permalink
ESP32-Cx: basic USB I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jan 30, 2024
1 parent 73b788e commit 4e91c88
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 14 deletions.
8 changes: 4 additions & 4 deletions software/firmware/binaries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Model|Instructions|Firmware folder
---|:---:|:---:
[Standalone Edition](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition)|[NodeMCU](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#nodemcu)<br>[ESP32-C3](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32-c3)|[NodeMCU](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/NodeMCU/SoftRF)<br>[ESP32C3](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32C3/SoftRF)
[Standalone Edition](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition)|[NodeMCU](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#nodemcu)<br>[ESP32-C3](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32-c3)<br>[ESP32-C6](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32-c6)|[NodeMCU](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/NodeMCU/SoftRF)<br>[ESP32C3](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32C3/SoftRF)<br>ESP32C6
[Prime Edition Mk2](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkII)|[ESP32](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32)|[ESP32](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32/SoftRF)
[Prime Edition Mk3](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkIII)|[ESP32-S3](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32-s3)|[ESP32S3](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32S3/SoftRF/MassStorage)
[Ham Edition](https://github.com/lyusupov/SoftRF/wiki/Ham-Edition)|[ESP32-S3](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/binaries/README.md#esp32-s3)|[ESP32S3](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32S3/SoftRF/MassStorage)
Expand Down Expand Up @@ -71,7 +71,7 @@ Model|Instructions|Firmware folder

## ESP32

1. Take ESP32 flash download tool from this location: https://www.espressif.com/en/support/download/other-tools <br>
1. Take ESP32 flash download tool from this location: http://www.espressif.com/en/support/download/other-tools <br>
You might also need to install:
* a [driver for the CP210X USB to UART bridge from Silicon Labs](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) or
* [CH9102F driver](https://github.com/Xinyuan-LilyGO/CH9102_Driver)<br>
Expand Down Expand Up @@ -316,7 +316,7 @@ The Bootloader is capable to self-program an application firmware into the devic

## ESP32-C3

1. Take ESP32 flash download tool from this location: https://www.espressif.com/en/support/download/other-tools <br>
1. Take ESP32 flash download tool from this location: http://www.espressif.com/en/support/download/other-tools <br>

2. Download an appropriate version of SoftRF firmware from [this location](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32C3/SoftRF) and unzip the archive ; <br>

Expand All @@ -340,7 +340,7 @@ The Bootloader is capable to self-program an application firmware into the devic

## ESP32-C6

1. Take ESP32 flash download tool from this location: https://www.espressif.com/en/support/download/other-tools <br>
1. Take ESP32 flash download tool from this location: http://www.espressif.com/en/support/download/other-tools <br>

2. Download an appropriate version of SoftRF firmware from [this location](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/binaries/ESP32C6/SoftRF) and unzip the archive ; <br>

Expand Down
116 changes: 110 additions & 6 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,12 @@ static void ESP32_setup()
#if defined(CONFIG_IDF_TARGET_ESP32C3)
} else if (esp32_board == ESP32_C3_DEVKIT) {

#if ARDUINO_USB_CDC_ON_BOOT
SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS,
SOC_GPIO_PIN_C3_CONS_RX,
SOC_GPIO_PIN_C3_CONS_TX);
#endif /* ARDUINO_USB_CDC_ON_BOOT */

lmic_pins.nss = SOC_GPIO_PIN_C3_SS;
lmic_pins.rst = LMIC_UNUSED_PIN;
lmic_pins.busy = SOC_GPIO_PIN_C3_TXE;
Expand All @@ -1269,12 +1275,24 @@ static void ESP32_setup()
#if defined(CONFIG_IDF_TARGET_ESP32C6)
} else if (esp32_board == ESP32_C6_DEVKIT) {

#if ARDUINO_USB_CDC_ON_BOOT
SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS,
SOC_GPIO_PIN_C6_CONS_RX,
SOC_GPIO_PIN_C6_CONS_TX);
#endif /* ARDUINO_USB_CDC_ON_BOOT */

lmic_pins.nss = SOC_GPIO_PIN_C6_SS;
lmic_pins.rst = LMIC_UNUSED_PIN;
lmic_pins.busy = SOC_GPIO_PIN_C6_TXE;

} else if (esp32_board == ESP32_LILYGO_T3C6) {

#if ARDUINO_USB_CDC_ON_BOOT
SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS,
SOC_GPIO_PIN_T3C6_CONS_RX,
SOC_GPIO_PIN_T3C6_CONS_TX);
#endif /* ARDUINO_USB_CDC_ON_BOOT */

lmic_pins.nss = SOC_GPIO_PIN_T3C6_SS;
lmic_pins.rst = SOC_GPIO_PIN_T3C6_RST;
lmic_pins.busy = SOC_GPIO_PIN_T3C6_BUSY;
Expand Down Expand Up @@ -1382,9 +1400,16 @@ static void ESP32_setup()
}
#endif /* TBD */

#elif ARDUINO_USB_CDC_ON_BOOT && \
(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6))

Serial.begin(SERIAL_OUT_BR);

for (int i=0; i < 20; i++) {if (Serial) break; else delay(100);}

#else
Serial.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS);
#endif /* ARDUINO_USB_CDC_ON_BOOT && (CONFIG_IDF_TARGET_ESP32S2 || S3) */
#endif /* ARDUINO_USB_CDC_ON_BOOT */

#if defined(CONFIG_IDF_TARGET_ESP32S3)
ui = &ui_settings;
Expand Down Expand Up @@ -2827,8 +2852,7 @@ static void ESP32_EEPROM_extension(int cmd)
#endif /* CONFIG_IDF_TARGET_ESP32S3 */

if (cmd == EEPROM_EXT_LOAD) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(USE_USB_HOST)
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(USE_USB_HOST)
if (settings->nmea_out == NMEA_USB) {
settings->nmea_out = NMEA_UART;
}
Expand All @@ -2840,9 +2864,10 @@ static void ESP32_EEPROM_extension(int cmd)
}
#endif /* CONFIG_IDF_TARGET_ESP32 */
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || \
defined(CONFIG_IDF_TARGET_ESP32C3)
defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
if (settings->bluetooth != BLUETOOTH_NONE) {
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(CONFIG_IDF_TARGET_ESP32C6)
settings->bluetooth = BLUETOOTH_LE_HM10_SERIAL;
#else
settings->bluetooth = BLUETOOTH_NONE;
Expand All @@ -2852,7 +2877,7 @@ static void ESP32_EEPROM_extension(int cmd)
// if (hw_info.model == SOFTRF_MODEL_HAM) {
// settings->power_save |= POWER_SAVE_NORECEIVE;
// }
#endif /* CONFIG_IDF_TARGET_ESP32S2 || S3 || C3 */
#endif /* CONFIG_IDF_TARGET_ESP32S2 || S3 || C3 || C6 */

/* AUTO and UK RF bands are deprecated since Release v1.3 */
if (settings->band == RF_BAND_AUTO || settings->band == RF_BAND_UK) {
Expand Down Expand Up @@ -4647,6 +4672,82 @@ IODev_ops_t ESP32SX_USBSerial_ops = {
#endif /* USE_USB_HOST || ARDUINO_USB_CDC_ON_BOOT */
#endif /* CONFIG_IDF_TARGET_ESP32S2 */

#if ARDUINO_USB_MODE && \
(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6))

#define USB_TX_FIFO_SIZE (MAX_TRACKING_OBJECTS * 65 + 75 + 75 + 42 + 20)
#define USB_RX_FIFO_SIZE (256)

#if ARDUINO_USB_CDC_ON_BOOT
#define USBSerial Serial
#else
#if defined(CONFIG_IDF_TARGET_ESP32C6)
#define USBSerial HWCDCSerial
#endif /* CONFIG_IDF_TARGET_ESP32C6 */
#endif /* ARDUINO_USB_CDC_ON_BOOT */

static void ESP32CX_USB_setup()
{
/* native CDC (HWCDC) */
USBSerial.setRxBufferSize(USB_RX_FIFO_SIZE);
USBSerial.setTxBufferSize(USB_TX_FIFO_SIZE);
}

static void ESP32CX_USB_loop()
{

}

static void ESP32CX_USB_fini()
{

}

static int ESP32CX_USB_available()
{
int rval = 0;

if (USBSerial) {
rval = USBSerial.available();
}

return rval;
}

static int ESP32CX_USB_read()
{
int rval = -1;

if (USBSerial) {
rval = USBSerial.read();
}

return rval;
}

static size_t ESP32CX_USB_write(const uint8_t *buffer, size_t size)
{
size_t rval = size;

/* Espressif native CDC (HWCDC) */
if (USBSerial && (size < USBSerial.availableForWrite())) {
rval = USBSerial.write(buffer, size);
}

return rval;
}

IODev_ops_t ESP32CX_USBSerial_ops = {
"ESP32CX USB",
ESP32CX_USB_setup,
ESP32CX_USB_loop,
ESP32CX_USB_fini,
ESP32CX_USB_available,
ESP32CX_USB_read,
ESP32CX_USB_write
};
#endif /* CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 */

#if defined(CONFIG_IDF_TARGET_ESP32S3)
static bool ESP32_ADB_setup()
{
Expand Down Expand Up @@ -4808,6 +4909,9 @@ const SoC_ops_t ESP32_ops = {
#if (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)) && \
(ARDUINO_USB_CDC_ON_BOOT || defined(USE_USB_HOST))
&ESP32SX_USBSerial_ops,
#elif ARDUINO_USB_MODE && \
(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6))
&ESP32CX_USBSerial_ops,
#else
NULL,
#endif /* USE_USB_HOST */
Expand Down
6 changes: 6 additions & 0 deletions software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
#define SerialOutput Serial0
#endif /* ARDUINO_USB_CDC_ON_BOOT */
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
#if ARDUINO_USB_CDC_ON_BOOT
#define UATSerial Serial0
#undef SerialOutput
#define SerialOutput Serial0
#else
#define UATSerial Serial
#endif /* ARDUINO_USB_CDC_ON_BOOT */
#else
#error "This ESP32 family build variant is not supported!"
#endif /* CONFIG_IDF_TARGET_ESP32 */
Expand Down
15 changes: 11 additions & 4 deletions software/firmware/source/SoftRF/src/ui/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ void handleSettings() {
offset += len;
size -= len;

} else if (SoC->id == SOC_ESP32S3 || SoC->id == SOC_ESP32C3) {
} else if (SoC->id == SOC_ESP32S3 || SoC->id == SOC_ESP32C3 ||
SoC->id == SOC_ESP32C6) {

snprintf_P ( offset, size,
PSTR("\
Expand Down Expand Up @@ -446,7 +447,8 @@ void handleSettings() {

/* SoC specific part 2 */
if (SoC->id == SOC_ESP32 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_RP2040) {
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("\
<option %s value='%d'>TCP</option>\
Expand All @@ -459,6 +461,7 @@ void handleSettings() {
size -= len;
}
if (SoC->id == SOC_ESP32S2 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("<option %s value='%d'>USB</option>"),
Expand Down Expand Up @@ -493,7 +496,8 @@ void handleSettings() {
#if !defined(EXCLUDE_BLUETOOTH)
/* SoC specific part 3 */
if (SoC->id == SOC_ESP32 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_RP2040) {
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("<option %s value='%d'>Bluetooth</option>"),
(settings->gdl90 == GDL90_BLUETOOTH ? "selected" : ""), GDL90_BLUETOOTH);
Expand All @@ -505,6 +509,7 @@ void handleSettings() {
#endif /* EXCLUDE_BLUETOOTH */

if (SoC->id == SOC_ESP32S2 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("<option %s value='%d'>USB</option>"),
Expand Down Expand Up @@ -537,7 +542,8 @@ void handleSettings() {
#if !defined(EXCLUDE_BLUETOOTH)
/* SoC specific part 4 */
if (SoC->id == SOC_ESP32 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_RP2040) {
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("<option %s value='%d'>Bluetooth</option>"),
(settings->d1090 == D1090_BLUETOOTH ? "selected" : ""), D1090_BLUETOOTH);
Expand All @@ -549,6 +555,7 @@ void handleSettings() {
#endif /* EXCLUDE_BLUETOOTH */

if (SoC->id == SOC_ESP32S2 || SoC->id == SOC_ESP32S3 ||
SoC->id == SOC_ESP32C3 || SoC->id == SOC_ESP32C6 ||
SoC->id == SOC_RP2040) {
snprintf_P ( offset, size,
PSTR("<option %s value='%d'>USB</option>"),
Expand Down

0 comments on commit 4e91c88

Please sign in to comment.