From 7d8e82f0572ab162b3730ba57ab64a5d9be54cfe Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Fri, 8 Mar 2024 11:50:31 +0300 Subject: [PATCH] build for an ESP32-C2 target --- .github/workflows/main.yml | 2 + .../source/SoftRF/src/platform/ESP32.cpp | 55 ++++++++++++++----- .../source/SoftRF/src/platform/ESP32.h | 11 +++- .../SoftRF/src/platform/iomap/WT0132C6.h | 38 +++++++++++++ .../firmware/source/SoftRF/src/system/SoC.h | 1 + .../firmware/source/libraries/ADC/battery.cpp | 4 +- .../firmware/source/libraries/ADC/battery.h | 4 +- 7 files changed, 96 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4088eb28a..9a2e64845 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,6 +50,7 @@ jobs: ARDUINO_BLE_VERSION: 1.3.6 ENERGIA_IDE_VERSION: 1.8.10E23 NIM_BLE_VERSION: 1.4.1 + # NIM_BLE_VERSION: esp32-c6-test BOARD: ${{ matrix.board }} # Steps represent a sequence of tasks that will be executed as part of the job @@ -216,6 +217,7 @@ jobs: cd $HOME/.arduino15/packages/esp32/hardware/esp32/3.0.0-alpha3 ; sed -i "s\echo '-DARDUINO_CORE_BUILD'\echo -DARDUINO_CORE_BUILD\g" platform.txt ; wget https://github.com/h2zero/NimBLE-Arduino/archive/refs/tags/${NIM_BLE_VERSION}.tar.gz ; + # wget https://github.com/h2zero/NimBLE-Arduino/archive/refs/heads/${NIM_BLE_VERSION}.tar.gz ; tar xzf ${NIM_BLE_VERSION}.tar.gz ; rm ${NIM_BLE_VERSION}.tar.gz ; mv NimBLE-Arduino-${NIM_BLE_VERSION} $HOME/Arduino/libraries/ ; diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index a79e68df3..10373aaef 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -577,6 +577,9 @@ static void ESP32_setup() case MakeFlashId(GIGADEVICE_ID, GIGADEVICE_GD25Q64): default: hw_info.model = SOFTRF_MODEL_PRIME_MK3; +#elif defined(CONFIG_IDF_TARGET_ESP32C2) + default: + esp32_board = ESP32_C2_DEVKIT; #elif defined(CONFIG_IDF_TARGET_ESP32C3) default: esp32_board = ESP32_C3_DEVKIT; @@ -623,6 +626,13 @@ static void ESP32_setup() esp32_board = ESP32_S3_DEVKIT; break; } +#elif defined(CONFIG_IDF_TARGET_ESP32C2) + switch (flash_id) + { + default: + esp32_board = ESP32_C2_DEVKIT; + break; + } #elif defined(CONFIG_IDF_TARGET_ESP32C3) switch (flash_id) { @@ -1273,6 +1283,21 @@ static void ESP32_setup() #endif /* CONFIG_IDF_TARGET_ESP32S3 */ +#if defined(CONFIG_IDF_TARGET_ESP32C2) + } else if (esp32_board == ESP32_C2_DEVKIT) { + +#if ARDUINO_USB_CDC_ON_BOOT + SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS, + SOC_GPIO_PIN_C2_CONS_RX, + SOC_GPIO_PIN_C2_CONS_TX); +#endif /* ARDUINO_USB_CDC_ON_BOOT */ + + lmic_pins.nss = SOC_GPIO_PIN_C2_SS; + lmic_pins.rst = LMIC_UNUSED_PIN; + lmic_pins.busy = SOC_GPIO_PIN_C2_TXE; + +#endif /* CONFIG_IDF_TARGET_ESP32C2 */ + #if defined(CONFIG_IDF_TARGET_ESP32C3) } else if (esp32_board == ESP32_C3_DEVKIT) { @@ -1417,7 +1442,9 @@ static void ESP32_setup() #endif /* TBD */ #elif ARDUINO_USB_CDC_ON_BOOT && \ - (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)) + (defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6)) Serial.begin(SERIAL_OUT_BR); @@ -1480,13 +1507,6 @@ static void ESP32_setup() delay(200); -#if 0 - calibrate_voltage((adc1_channel_t) ADC1_GPIO2_CHANNEL); - uint16_t gpio2_voltage = read_voltage(); // avg. of 32 samples - - if (gpio2_voltage > 1900) { -#else - bool probe_1 = false; bool probe_2 = false; @@ -1503,7 +1523,6 @@ static void ESP32_setup() probe_2 = digitalRead(SOC_GPIO_PIN_TWR2_RADIO_SQL); if (probe_1 == LOW && probe_2 == HIGH) { -#endif hw_info.revision = 1; axp_2xxx.setBLDO2Voltage(3300); // V2.1 - SA868 @@ -2911,7 +2930,8 @@ 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_ESP32C6) + defined(CONFIG_IDF_TARGET_ESP32C2) || 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) || \ defined(CONFIG_IDF_TARGET_ESP32C6) @@ -3800,6 +3820,8 @@ static void ESP32_Battery_setup() } else { calibrate_voltage((adc1_channel_t) ADC1_GPIO2_CHANNEL); } +#elif defined(CONFIG_IDF_TARGET_ESP32C2) + calibrate_voltage(SOC_GPIO_PIN_C2_BATTERY); #elif defined(CONFIG_IDF_TARGET_ESP32C3) calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL); #elif defined(CONFIG_IDF_TARGET_ESP32C6) @@ -4717,7 +4739,9 @@ IODev_ops_t ESP32SX_USBSerial_ops = { #endif /* CONFIG_IDF_TARGET_ESP32S2 */ #if ARDUINO_USB_MODE && \ - (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)) + (defined(CONFIG_IDF_TARGET_ESP32C2) || \ + 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) @@ -4793,7 +4817,7 @@ IODev_ops_t ESP32CX_USBSerial_ops = { ESP32CX_USB_read, ESP32CX_USB_write }; -#endif /* CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 */ +#endif /* CONFIG_IDF_TARGET_ESP32C2 || C3 || C6 */ #if defined(CONFIG_IDF_TARGET_ESP32S3) static bool ESP32_ADB_setup() @@ -4915,6 +4939,9 @@ const SoC_ops_t ESP32_ops = { #elif defined(CONFIG_IDF_TARGET_ESP32S3) SOC_ESP32S3, "ESP32-S3", +#elif defined(CONFIG_IDF_TARGET_ESP32C2) + SOC_ESP32C2, + "ESP32-C2", #elif defined(CONFIG_IDF_TARGET_ESP32C3) SOC_ESP32C3, "ESP32-C3", @@ -4957,7 +4984,9 @@ const SoC_ops_t ESP32_ops = { (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)) + (defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6)) &ESP32CX_USBSerial_ops, #else NULL, diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.h b/software/firmware/source/SoftRF/src/platform/ESP32.h index f36a07230..2f43982ed 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.h +++ b/software/firmware/source/SoftRF/src/platform/ESP32.h @@ -57,7 +57,9 @@ #undef SerialOutput #define SerialOutput Serial0 #endif /* ARDUINO_USB_CDC_ON_BOOT */ -#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) +#elif defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) #if ARDUINO_USB_CDC_ON_BOOT #define UATSerial Serial0 #undef SerialOutput @@ -135,6 +137,8 @@ extern Adafruit_NeoPixel strip; #define SOC_GPIO_PIN_LED 7 #elif defined(CONFIG_IDF_TARGET_ESP32S3) #define SOC_GPIO_PIN_LED SOC_UNUSED_PIN /* TBD 14? */ +#elif defined(CONFIG_IDF_TARGET_ESP32C2) +#define SOC_GPIO_PIN_LED SOC_UNUSED_PIN /* TBD */ #elif defined(CONFIG_IDF_TARGET_ESP32C3) #define SOC_GPIO_PIN_LED 19 /* D1 */ #elif defined(CONFIG_IDF_TARGET_ESP32C6) @@ -253,6 +257,7 @@ enum rst_reason { enum esp32_board_id { ESP32_DEVKIT, ESP32_S3_DEVKIT, + ESP32_C2_DEVKIT, ESP32_C3_DEVKIT, ESP32_C6_DEVKIT, ESP32_TTGO_V2_OLED, @@ -392,7 +397,9 @@ extern ESP32_USBSerial_device_t ESP32_USB_Serial; extern const USB_Device_List_t supported_USB_devices[]; #endif /* USE_USB_HOST */ -#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) +#elif defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) #undef USE_OLED #undef USE_TFT #if defined(CONFIG_IDF_TARGET_ESP32C6) diff --git a/software/firmware/source/SoftRF/src/platform/iomap/WT0132C6.h b/software/firmware/source/SoftRF/src/platform/iomap/WT0132C6.h index 0f6bda3d7..53750ffc0 100644 --- a/software/firmware/source/SoftRF/src/platform/iomap/WT0132C6.h +++ b/software/firmware/source/SoftRF/src/platform/iomap/WT0132C6.h @@ -35,3 +35,41 @@ // auxillary #define SOC_GPIO_PIN_C6_BUZZER 21 /* 10 */ #define SOC_GPIO_PIN_C6_STATUS SOC_UNUSED_PIN + + +/* WT018684-S5 (ESP32-C2) */ +#define SOC_GPIO_PIN_C2_CONS_RX 19 +#define SOC_GPIO_PIN_C2_CONS_TX 20 + +// GNSS module +#define SOC_GPIO_PIN_C2_GNSS_RX 9 /* D3 */ +#define SOC_GPIO_PIN_C2_GNSS_TX 18 +#define SOC_GPIO_PIN_C2_GNSS_PPS SOC_UNUSED_PIN // 0 + +// USB CDC/JTAG +#define SOC_GPIO_PIN_C2_USB_DP 13 /* NC */ +#define SOC_GPIO_PIN_C2_USB_DN 12 /* NC */ + +// SPI +#define SOC_GPIO_PIN_C2_MOSI 6 /* D7 */ +#define SOC_GPIO_PIN_C2_MISO 5 /* D6 */ +#define SOC_GPIO_PIN_C2_SCK 4 /* D5 */ +#define SOC_GPIO_PIN_C2_SS 7 /* D8 */ + +// NRF905 +#define SOC_GPIO_PIN_C2_TXE 2 /* D0 */ +#define SOC_GPIO_PIN_C2_CE 8 /* D4 */ +#define SOC_GPIO_PIN_C2_PWR 10 /* D2 */ + +// SX1276 +#define SOC_GPIO_PIN_C2_RST 10 /* D2 */ +#define SOC_GPIO_PIN_C2_DIO0 2 /* D0 */ +#define SOC_GPIO_PIN_C2_SDA 10 /* D2 */ +#define SOC_GPIO_PIN_C2_SCL 8 /* D4 */ + +// battery voltage (ADC) +#define SOC_GPIO_PIN_C2_BATTERY 1 /* A0 */ + +// auxillary +#define SOC_GPIO_PIN_C2_BUZZER SOC_UNUSED_PIN /* 10 */ +#define SOC_GPIO_PIN_C2_STATUS SOC_UNUSED_PIN diff --git a/software/firmware/source/SoftRF/src/system/SoC.h b/software/firmware/source/SoftRF/src/system/SoC.h index 757e32282..f9a0d7f71 100644 --- a/software/firmware/source/SoftRF/src/system/SoC.h +++ b/software/firmware/source/SoftRF/src/system/SoC.h @@ -95,6 +95,7 @@ enum SOC_ESP32, SOC_ESP32S2, SOC_ESP32S3, + SOC_ESP32C2, SOC_ESP32C3, SOC_ESP32C6, SOC_RPi, diff --git a/software/firmware/source/libraries/ADC/battery.cpp b/software/firmware/source/libraries/ADC/battery.cpp index a011b21ce..ac81696b9 100644 --- a/software/firmware/source/libraries/ADC/battery.cpp +++ b/software/firmware/source/libraries/ADC/battery.cpp @@ -6,7 +6,7 @@ #include "battery.h" -#if defined(CONFIG_IDF_TARGET_ESP32C6) +#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) static uint8_t adc_pin = 1; void calibrate_voltage(uint8_t pin, adc_attenuation_t atten) { @@ -118,4 +118,4 @@ uint16_t read_voltage() { ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage); return voltage; } -#endif /* CONFIG_IDF_TARGET_ESP32C6 */ +#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */ diff --git a/software/firmware/source/libraries/ADC/battery.h b/software/firmware/source/libraries/ADC/battery.h index ec8b60abd..058e85299 100644 --- a/software/firmware/source/libraries/ADC/battery.h +++ b/software/firmware/source/libraries/ADC/battery.h @@ -3,14 +3,14 @@ uint16_t read_voltage(void); -#if defined(CONFIG_IDF_TARGET_ESP32C6) +#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) void calibrate_voltage(uint8_t, adc_attenuation_t atten = ADC_11db); #else #include #include void calibrate_voltage(adc1_channel_t, adc_atten_t atten = ADC_ATTEN_DB_11); -#endif /* CONFIG_IDF_TARGET_ESP32C6 */ +#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */ #define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate #define NO_OF_SAMPLES 32 // we do some multisampling to get better values