From 02cca0bb9b0e43d4284c44e5d26e4a9400450317 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Wed, 19 Jun 2024 13:45:34 +0300 Subject: [PATCH] misc. CH32 and ESP32-S3 cleanup --- software/firmware/source/SoftRF/src/driver/GNSS.cpp | 5 +++++ .../firmware/source/SoftRF/src/platform/CH32.cpp | 8 ++++++++ software/firmware/source/SoftRF/src/platform/CH32.h | 12 ++++++------ .../firmware/source/SoftRF/src/platform/ESP32.cpp | 7 +++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/software/firmware/source/SoftRF/src/driver/GNSS.cpp b/software/firmware/source/SoftRF/src/driver/GNSS.cpp index 715d4d119..9b9aed1df 100644 --- a/software/firmware/source/SoftRF/src/driver/GNSS.cpp +++ b/software/firmware/source/SoftRF/src/driver/GNSS.cpp @@ -1246,7 +1246,12 @@ byte GNSS_setup() { #else int interrupt_num = digitalPinToInterrupt(SOC_GPIO_PIN_GNSS_PPS); if (interrupt_num != NOT_AN_INTERRUPT) { +#if defined(plat_attachInterrupt_func) + plat_attachInterrupt_func(SOC_GPIO_PIN_GNSS_PPS, SoC->GNSS_PPS_handler, + RISING); +#else attachInterrupt(interrupt_num, SoC->GNSS_PPS_handler, RISING); +#endif /* plat_attachInterrupt_func */ } #endif } diff --git a/software/firmware/source/SoftRF/src/platform/CH32.cpp b/software/firmware/source/SoftRF/src/platform/CH32.cpp index 089060984..d0202c7f7 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.cpp +++ b/software/firmware/source/SoftRF/src/platform/CH32.cpp @@ -72,6 +72,14 @@ eeprom_t eeprom_block; settings_t *settings = &eeprom_block.field.settings; #endif /* EXCLUDE_EEPROM */ +void CH32_attachInterrupt_func(uint32_t pin, void (*userFunc)(void), int mode) +{ + attachInterrupt(pin, GPIO_Mode_IN_FLOATING, userFunc, EXTI_Mode_Interrupt, + mode == RISING ? EXTI_Trigger_Rising : + mode == FALLING ? EXTI_Trigger_Falling : + EXTI_Trigger_Rising_Falling /* CHANGE */ ); +} + static void CH32_setup() { #if SOC_GPIO_RADIO_LED_TX != SOC_UNUSED_PIN diff --git a/software/firmware/source/SoftRF/src/platform/CH32.h b/software/firmware/source/SoftRF/src/platform/CH32.h index cc3144141..145202ab6 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.h +++ b/software/firmware/source/SoftRF/src/platform/CH32.h @@ -20,8 +20,6 @@ #ifndef PLATFORM_CH32_H #define PLATFORM_CH32_H -#include - /* Maximum of tracked flying objects is now SoC-specific constant */ #define MAX_TRACKING_OBJECTS 8 @@ -49,10 +47,6 @@ #define SOC_ADC_VOLTAGE_DIV 2 /* TBD */ -#ifndef strnlen -#define strnlen(x,y) strlen(x) /* TBD */ -#endif - enum rst_reason { REASON_DEFAULT_RST = 0, /* normal startup by power on */ REASON_WDT_RST = 1, /* hardware watch dog reset */ @@ -170,6 +164,12 @@ extern Adafruit_NeoPixel strip; #define U8X8_OLED_I2C_BUS_TYPE U8X8_SSD1306_128X64_NONAME_HW_I2C #endif /* USE_OLED */ +extern void CH32_attachInterrupt_func(uint32_t pin, void (*)(void), int mode); + +#define plat_attachInterrupt_func CH32_attachInterrupt_func + +#define DEBUG 0 /* https://github.com/openwch/arduino_core_ch32/issues/125 */ + #endif /* PLATFORM_CH32_H */ #endif /* ARDUINO_ARCH_CH32 */ diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index 813ee7331..306ae421c 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -1318,6 +1318,13 @@ static void ESP32_setup() } } else if (hw_info.model == SOFTRF_MODEL_MIDI) { +#if defined(ESP_IDF_VERSION_MAJOR) && ESP_IDF_VERSION_MAJOR >= 5 + #define BOARD_F_XTAL_MHZ 26 + + rtc_clk_xtal_freq_update((rtc_xtal_freq_t) BOARD_F_XTAL_MHZ); + rtc_clk_cpu_freq_set_xtal(); +#endif /* ESP_IDF_VERSION_MAJOR */ + #if ARDUINO_USB_CDC_ON_BOOT SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS, SOC_GPIO_PIN_S3_CONS_RX,