From d6bf5f18bba5350ba8c3799499696c7fc4478b2d Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Tue, 1 Oct 2024 13:26:40 +0300 Subject: [PATCH] [CH32] disable battery voltage ADC for a while --- .../source/SoftRF/src/platform/CH32.cpp | 67 ++++++++++++++++++- .../source/SoftRF/src/platform/CH32.h | 2 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/software/firmware/source/SoftRF/src/platform/CH32.cpp b/software/firmware/source/SoftRF/src/platform/CH32.cpp index 929eacd7d..9eebf0882 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.cpp +++ b/software/firmware/source/SoftRF/src/platform/CH32.cpp @@ -590,6 +590,67 @@ static void CH32_Button_fini() #endif /* SOC_GPIO_PIN_BUTTON != SOC_UNUSED_PIN */ } +#if defined(USE_TINYUSB) +static void CH32_USB_setup() { +#if !defined(USBCON) + USBSerial.begin(SERIAL_OUT_BR); +#endif /* USBCON */ +} + +static void CH32_USB_loop() { + +} + +static void CH32_USB_fini() { +#if !defined(USBCON) + USBSerial.end(); +#endif /* USBCON */ +} + +static int CH32_USB_available() +{ + int rval = 0; + + if (USBSerial) { + rval = USBSerial.available(); + } + + return rval; +} + +static int CH32_USB_read() +{ + int rval = -1; + + if (USBSerial) { + rval = USBSerial.read(); + } + + return rval; +} + +static size_t CH32_USB_write(const uint8_t *buffer, size_t size) +{ + size_t rval = size; + + if (USBSerial && (size < USBSerial.availableForWrite())) { + rval = USBSerial.write(buffer, size); + } + + return rval; +} + +IODev_ops_t CH32_USBSerial_ops = { + "CH32 USBSerial", + CH32_USB_setup, + CH32_USB_loop, + CH32_USB_fini, + CH32_USB_available, + CH32_USB_read, + CH32_USB_write +}; +#endif /* USE_TINYUSB */ + const SoC_ops_t CH32_ops = { SOC_CH32, "CH32", @@ -617,8 +678,12 @@ const SoC_ops_t CH32_ops = { CH32_SPI_begin, CH32_swSer_begin, CH32_swSer_enableRx, - NULL, /* TODO */ NULL, +#if defined(USE_TINYUSB) + &CH32_USBSerial_ops, +#else + NULL, +#endif /* USE_TINYUSB */ NULL, CH32_Display_setup, CH32_Display_loop, diff --git a/software/firmware/source/SoftRF/src/platform/CH32.h b/software/firmware/source/SoftRF/src/platform/CH32.h index af7f405f4..efd8f4f93 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.h +++ b/software/firmware/source/SoftRF/src/platform/CH32.h @@ -129,7 +129,7 @@ struct rst_info { #define SOC_GPIO_PIN_LED SOC_UNUSED_PIN #define SOC_GPIO_PIN_GNSS_PPS PA3 -#define SOC_GPIO_PIN_BATTERY PA0 +#define SOC_GPIO_PIN_BATTERY SOC_UNUSED_PIN /* PA0 TBD */ #define SOC_GPIO_PIN_BUTTON SOC_UNUSED_PIN /* PB3 */ #define SOC_GPIO_RADIO_LED_RX SOC_UNUSED_PIN