diff --git a/software/firmware/source/SoftRF/src/driver/RF.cpp b/software/firmware/source/SoftRF/src/driver/RF.cpp index 3852a906a..53b851d10 100644 --- a/software/firmware/source/SoftRF/src/driver/RF.cpp +++ b/software/firmware/source/SoftRF/src/driver/RF.cpp @@ -2406,9 +2406,10 @@ extern NeoPixelBus TWR2_Pixel; void sa868_Tx_LED_state(bool val) { if (hw_info.model == SOFTRF_MODEL_HAM) { #if defined(USE_NEOPIXELBUS_LIBRARY) - TWR2_Pixel.SetPixelColor(0, val ? LED_COLOR_RED : + color_t inactive_color = hw_info.revision > 0 ? LED_COLOR_BLACK : settings->power_save & POWER_SAVE_NORECEIVE ? - LED_COLOR_BLACK : LED_COLOR_GREEN); + LED_COLOR_BLACK : LED_COLOR_GREEN; + TWR2_Pixel.SetPixelColor(0, val ? LED_COLOR_RED : inactive_color); TWR2_Pixel.Show(); #endif /* USE_NEOPIXELBUS_LIBRARY */ } @@ -2599,7 +2600,8 @@ static void sa8x8_setup() if (hw_info.model == SOFTRF_MODEL_HAM) { #if defined(USE_NEOPIXELBUS_LIBRARY) - TWR2_Pixel.SetPixelColor(0, rx ? LED_COLOR_GREEN: LED_COLOR_BLACK); + TWR2_Pixel.SetPixelColor(0, rx && hw_info.revision == 0 ? + LED_COLOR_GREEN : LED_COLOR_BLACK); TWR2_Pixel.Show(); #endif /* USE_NEOPIXELBUS_LIBRARY */ } diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index 018db72df..73ed53b03 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -629,6 +629,7 @@ static void ESP32_setup() #elif defined(CONFIG_IDF_TARGET_ESP32C2) switch (flash_id) { + case MakeFlashId(FMICRO_ID, FMICRO_ZB25Q16): /* WT018684-S5 */ default: esp32_board = ESP32_C2_DEVKIT; break; @@ -1286,12 +1287,6 @@ static void ESP32_setup() #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; @@ -1442,8 +1437,7 @@ static void ESP32_setup() #endif /* TBD */ #elif ARDUINO_USB_CDC_ON_BOOT && \ - (defined(CONFIG_IDF_TARGET_ESP32C2) || \ - defined(CONFIG_IDF_TARGET_ESP32C3) || \ + (defined(CONFIG_IDF_TARGET_ESP32C3) || \ defined(CONFIG_IDF_TARGET_ESP32C6)) Serial.begin(SERIAL_OUT_BR); @@ -2061,6 +2055,29 @@ static void ESP32_loop() } #endif /* !EXCLUDE_MAG */ + #if defined(USE_SA8X8) + if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision > 0) { + #if defined(USE_NEOPIXELBUS_LIBRARY) + color_t color = TWR2_Pixel.GetPixelColor(0); + + if (color != LED_COLOR_RED) { + bool sql = digitalRead(SOC_GPIO_PIN_TWR2_RADIO_SQL); + if (sql == LOW) { + if (color == LED_COLOR_BLACK) { + TWR2_Pixel.SetPixelColor(0, LED_COLOR_GREEN); + TWR2_Pixel.Show(); + } + } else { + if (color == LED_COLOR_GREEN) { + TWR2_Pixel.SetPixelColor(0, LED_COLOR_BLACK); + TWR2_Pixel.Show(); + } + } + } + #endif /* USE_NEOPIXELBUS_LIBRARY */ + } + #endif /* USE_SA8X8 */ + // if (esp32_board == ESP32_HELTEC_TRACKER) { // digitalWrite(SOC_GPIO_PIN_HELTRK_LED, // digitalRead(SOC_GPIO_PIN_HELTRK_GNSS_PPS)); @@ -2924,7 +2941,9 @@ static void ESP32_EEPROM_extension(int cmd) #endif /* CONFIG_IDF_TARGET_ESP32S3 */ if (cmd == EEPROM_EXT_LOAD) { -#if defined(CONFIG_IDF_TARGET_ESP32) || defined(USE_USB_HOST) +#if defined(CONFIG_IDF_TARGET_ESP32) || \ + defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(USE_USB_HOST) if (settings->nmea_out == NMEA_USB) { settings->nmea_out = NMEA_UART; } @@ -4759,8 +4778,7 @@ IODev_ops_t ESP32SX_USBSerial_ops = { #endif /* CONFIG_IDF_TARGET_ESP32S2 */ #if ARDUINO_USB_MODE && \ - (defined(CONFIG_IDF_TARGET_ESP32C2) || \ - defined(CONFIG_IDF_TARGET_ESP32C3) || \ + (defined(CONFIG_IDF_TARGET_ESP32C3) || \ defined(CONFIG_IDF_TARGET_ESP32C6)) #define USB_TX_FIFO_SIZE (MAX_TRACKING_OBJECTS * 65 + 75 + 75 + 42 + 20) @@ -5004,8 +5022,7 @@ 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_ESP32C2) || \ - defined(CONFIG_IDF_TARGET_ESP32C3) || \ + (defined(CONFIG_IDF_TARGET_ESP32C3) || \ defined(CONFIG_IDF_TARGET_ESP32C6)) &ESP32CX_USBSerial_ops, #else diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.h b/software/firmware/source/SoftRF/src/platform/ESP32.h index af9abbfe4..317425e2b 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.h +++ b/software/firmware/source/SoftRF/src/platform/ESP32.h @@ -305,6 +305,10 @@ struct rst_info { #define ZBIT_ID 0x5E #define ZBIT_ZB25VQ32B 0x4016 +/* Shanghai Fudan Microelectronics Group Co., Ltd. */ +#define FMICRO_ID 0xA1 +#define FMICRO_ZB25Q16 0x4015 + #define MakeFlashId(v,d) ((v << 16) | d) #define MPU6886_REG_PWR_MGMT_1 (0x6B) @@ -404,7 +408,7 @@ extern const USB_Device_List_t supported_USB_devices[]; defined(CONFIG_IDF_TARGET_ESP32C6) #undef USE_OLED #undef USE_TFT -#if defined(CONFIG_IDF_TARGET_ESP32C6) +#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) #define EXCLUDE_EGM96 #define EXCLUDE_TEST_MODE #define EXCLUDE_WATCHOUT_MODE diff --git a/software/firmware/source/SoftRF/src/ui/Web.cpp b/software/firmware/source/SoftRF/src/ui/Web.cpp index d1193338b..7d51f7d1e 100644 --- a/software/firmware/source/SoftRF/src/ui/Web.cpp +++ b/software/firmware/source/SoftRF/src/ui/Web.cpp @@ -1291,6 +1291,7 @@ void Web_setup() /* FLASH memory usage optimization */ #if !defined(ARDUINO_ARCH_RP2040) && \ + !defined(CONFIG_IDF_TARGET_ESP32C2) && \ !defined(CONFIG_IDF_TARGET_ESP32C6) && \ !defined(ARDUINO_ARCH_RENESAS) diff --git a/software/firmware/source/libraries/ADC/battery.cpp b/software/firmware/source/libraries/ADC/battery.cpp index ac81696b9..0729fdfa1 100644 --- a/software/firmware/source/libraries/ADC/battery.cpp +++ b/software/firmware/source/libraries/ADC/battery.cpp @@ -6,30 +6,7 @@ #include "battery.h" -#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) { - adc_pin = pin; - analogReadResolution(12); - analogSetPinAttenuation(adc_pin, atten); -} - -uint16_t read_voltage() { - // multisample ADC - uint32_t adc_reading = 0; - - for (int i = 0; i < NO_OF_SAMPLES; i++) { - adc_reading += analogReadMilliVolts(adc_pin); - yield(); - } - - adc_reading /= NO_OF_SAMPLES; - - return (uint16_t) adc_reading; -} - -#else +#if !defined(ESP_IDF_VERSION_MAJOR) || ESP_IDF_VERSION_MAJOR < 5 // Local logging tag static const char TAG[] = "ADC"; @@ -118,4 +95,29 @@ uint16_t read_voltage() { ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage); return voltage; } -#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */ + +#else + +static uint8_t adc_pin = 1; + +void calibrate_voltage(uint8_t pin, adc_attenuation_t atten) { + adc_pin = pin; + analogReadResolution(12); + analogSetPinAttenuation(adc_pin, atten); +} + +uint16_t read_voltage() { + // multisample ADC + uint32_t adc_reading = 0; + + for (int i = 0; i < NO_OF_SAMPLES; i++) { + adc_reading += analogReadMilliVolts(adc_pin); + yield(); + } + + adc_reading /= NO_OF_SAMPLES; + + return (uint16_t) adc_reading; +} + +#endif /* ESP_IDF_VERSION_MAJOR */ diff --git a/software/firmware/source/libraries/ADC/battery.h b/software/firmware/source/libraries/ADC/battery.h index 058e85299..25f6f8b7b 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_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6) -void calibrate_voltage(uint8_t, adc_attenuation_t atten = ADC_11db); -#else +#if !defined(ESP_IDF_VERSION_MAJOR) || ESP_IDF_VERSION_MAJOR < 5 #include #include void calibrate_voltage(adc1_channel_t, adc_atten_t atten = ADC_ATTEN_DB_11); -#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */ +#else +void calibrate_voltage(uint8_t, adc_attenuation_t atten = ADC_11db); +#endif /* ESP_IDF_VERSION_MAJOR */ #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