Skip to content

Commit

Permalink
build for an ESP32-C2 target
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Mar 8, 2024
1 parent 5aa90af commit 7d8e82f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/ ;
Expand Down
55 changes: 42 additions & 13 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions software/firmware/source/SoftRF/src/platform/iomap/WT0132C6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/src/system/SoC.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum
SOC_ESP32,
SOC_ESP32S2,
SOC_ESP32S3,
SOC_ESP32C2,
SOC_ESP32C3,
SOC_ESP32C6,
SOC_RPi,
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/source/libraries/ADC/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions software/firmware/source/libraries/ADC/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <driver/adc.h>
#include <esp_adc_cal.h>

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
Expand Down

0 comments on commit 7d8e82f

Please sign in to comment.