From 765422094247570e043957c99633a9e8d71c2596 Mon Sep 17 00:00:00 2001 From: Richard Li Date: Wed, 7 Aug 2024 13:35:59 +0800 Subject: [PATCH] Fixed charging mechanism, EL18 and NB4P use the same chip have the same problem --- radio/src/targets/pl18/battery_driver.cpp | 4 +++- radio/src/targets/pl18/battery_driver.h | 17 --------------- radio/src/targets/pl18/board.cpp | 5 +---- radio/src/targets/pl18/board.h | 25 +++++++++++++++++++++++ radio/src/targets/pl18/hal.h | 21 ++++++++++--------- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/radio/src/targets/pl18/battery_driver.cpp b/radio/src/targets/pl18/battery_driver.cpp index c13ac7ca570..399f2c0eddb 100644 --- a/radio/src/targets/pl18/battery_driver.cpp +++ b/radio/src/targets/pl18/battery_driver.cpp @@ -26,7 +26,7 @@ #define __BATTERY_DRIVER_C__ #define BATTERY_W 140 -#define BATTERY_H 200 +#define BATTERY_H (LCD_H - 120) #define BATTERY_TOP ((LCD_H - BATTERY_H)/2) #define BATTERY_CONNECTOR_W 32 #define BATTERY_CONNECTOR_H 10 @@ -420,11 +420,13 @@ void handle_battery_charge(uint32_t last_press_time) sprintf(buffer, "%d,%d,%d,%d,%d,", uCharger.isChargingDetectionReady, uCharger.isChargeEnd, IS_UCHARGER_CHARGE_END_ACTIVE(), uCharger.chargingSamplingCount, uCharger.chargeEndSamplingCount); lcd->drawSizedText(100, 40, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2); +#if defined(WIRELESS_CHARGER) sprintf(buffer, "%d,%d,%d,%d,%d", wCharger.isChargerDetectionReady, wCharger.hasCharger, IS_WCHARGER_ACTIVE(), wCharger.chargerSamplingCount, wCharger.isHighCurrent); lcd->drawSizedText(100, 70, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2); sprintf(buffer, "%d,%d,%d,%d,%d,", wCharger.isChargingDetectionReady, wCharger.isChargeEnd, IS_WCHARGER_CHARGE_END_ACTIVE(), wCharger.chargingSamplingCount, wCharger.chargeEndSamplingCount); lcd->drawSizedText(100, 100, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2); +#endif sprintf(buffer, "%d", isChargerActive()); lcd->drawSizedText(100, 130, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2); diff --git a/radio/src/targets/pl18/battery_driver.h b/radio/src/targets/pl18/battery_driver.h index 14fce17bcda..a03ac70d6e6 100644 --- a/radio/src/targets/pl18/battery_driver.h +++ b/radio/src/targets/pl18/battery_driver.h @@ -42,23 +42,6 @@ enum ChargeState CHARGE_FINISHED }; -#if defined(UCHARGER_GPIO_PIN_INV) - #define IS_UCHARGER_ACTIVE() gpio_read(UCHARGER_GPIO) ? 0 : 1 -#else - #define IS_UCHARGER_ACTIVE() gpio_read(UCHARGER_GPIO) ? 1 : 0 -#endif -#if defined(UCHARGER_CHARGE_END_GPIO_PIN_INV) - #define IS_UCHARGER_CHARGE_END_ACTIVE() gpio_read(UCHARGER_CHARGE_END_GPIO) ? 0 : 1 -#else - #define IS_UCHARGER_CHARGE_END_ACTIVE() gpio_read(UCHARGER_CHARGE_END_GPIO) ? 1 : 0 -#endif -#if defined(UCHARGER_EN_GPIO) -#define ENABLE_UCHARGER() gpio_set(UCHARGER_EN_GPIO) -#define DISABLE_UCHARGER() gpio_clear(UCHARGER_EN_GPIO) -#else -#define ENABLE_UCHARGER() -#define DISABLE_UCHARGER() -#endif #define IS_WCHARGER_ACTIVE() gpio_read(WCHARGER_GPIO) ? 1 : 0 #define IS_WCHARGER_CHARGE_END_ACTIVE() gpio_read(WCHARGER_CHARGE_END_GPIO) ? 1 : 0 #define ENABLE_WCHARGER() gpio_set(WCHARGER_EN_GPIO) diff --git a/radio/src/targets/pl18/board.cpp b/radio/src/targets/pl18/board.cpp index 720552ef1a1..f4b9786b742 100644 --- a/radio/src/targets/pl18/board.cpp +++ b/radio/src/targets/pl18/board.cpp @@ -309,10 +309,7 @@ int usbPlugged() static uint8_t debouncedState = 0; static uint8_t lastState = 0; - uint8_t state = gpio_read(UCHARGER_GPIO) ? 1 : 0; -#if defined(UCHARGER_GPIO_PIN_INV) - state = !state; -#endif + uint8_t state = IS_UCHARGER_ACTIVE(); if (state == lastState) debouncedState = state; diff --git a/radio/src/targets/pl18/board.h b/radio/src/targets/pl18/board.h index 4f8ca522849..3e5e4c552b2 100644 --- a/radio/src/targets/pl18/board.h +++ b/radio/src/targets/pl18/board.h @@ -225,6 +225,31 @@ bool isBacklightEnabled(); } #endif +#if defined(RADIO_NB4P) || defined(RADIO_NV14_FAMILY) + #define IS_UCHARGER_ACTIVE() gpio_read(UCHARGER_GPIO) ? (gpio_read(UCHARGER_CHARGE_END_GPIO) ? 0 : 1) : 1 +#else + #define IS_UCHARGER_ACTIVE() gpio_read(UCHARGER_GPIO) ? 1 : 0 +#endif + +#if defined(RADIO_NB4P) || defined(RADIO_NV14_FAMILY) + #define IS_UCHARGER_CHARGE_END_ACTIVE() gpio_read(UCHARGER_CHARGE_END_GPIO) ? 0 : 1 +#else + #define IS_UCHARGER_CHARGE_END_ACTIVE() gpio_read(UCHARGER_CHARGE_END_GPIO) ? 1 : 0 +#endif + +#if defined(UCHARGER_EN_GPIO) + #if defined(RADIO_NV14_FAMILY) + #define ENABLE_UCHARGER() gpio_clear(UCHARGER_EN_GPIO) + #define DISABLE_UCHARGER() gpio_set(UCHARGER_EN_GPIO) + #else + #define ENABLE_UCHARGER() gpio_set(UCHARGER_EN_GPIO) + #define DISABLE_UCHARGER() gpio_clear(UCHARGER_EN_GPIO) + #endif +#else + #define ENABLE_UCHARGER() + #define DISABLE_UCHARGER() +#endif + // Audio driver void audioInit(); void audioConsumeCurrentBuffer(); diff --git a/radio/src/targets/pl18/hal.h b/radio/src/targets/pl18/hal.h index 2b7b936ba32..3142a922cf1 100644 --- a/radio/src/targets/pl18/hal.h +++ b/radio/src/targets/pl18/hal.h @@ -487,21 +487,22 @@ #endif // Power -#define PWR_SWITCH_GPIO GPIO_PIN(GPIOI, 11) // PI.11 -#define PWR_ON_GPIO GPIO_PIN(GPIOI, 14) // PI.14 +#define PWR_SWITCH_GPIO GPIO_PIN(GPIOI, 11) // PI.11 +#define PWR_ON_GPIO GPIO_PIN(GPIOI, 14) // PI.14 // Chargers (USB and wireless) -#define UCHARGER_GPIO GPIO_PIN(GPIOB, 14) // PB.14 input -#define UCHARGER_CHARGE_END_GPIO GPIO_PIN(GPIOB, 13) // PB.13 input -#if defined(RADIO_NB4P) || defined(RADIO_NV14_FAMILY) - #define UCHARGER_GPIO_PIN_INV - #define UCHARGER_CHARGE_END_GPIO_PIN_INV -#endif +#define UCHARGER_GPIO GPIO_PIN(GPIOB, 14) // PB.14 input +#define UCHARGER_CHARGE_END_GPIO GPIO_PIN(GPIOB, 13) // PB.13 input +//#if defined(RADIO_NB4P) || defined(RADIO_NV14_FAMILY) +// #define UCHARGER_GPIO_INV +// #define UCHARGER_CHARGE_END_GPIO_INV +//#endif #if defined(RADIO_PL18) || defined(RADIO_PL18EV) - #define UCHARGER_EN_GPIO GPIO_PIN(GPIOG, 3) // PG.03 output + #define UCHARGER_EN_GPIO GPIO_PIN(GPIOG, 3) // PG.03 output #elif defined(RADIO_NV14_FAMILY) - #define UCHARGER_EN_GPIO GPIO_PIN(GPIOH, 11) // PH.11 output + #define UCHARGER_EN_GPIO GPIO_PIN(GPIOH, 11) // PH.11 output +// #define UCHARGER_EN_GPIO_INV #endif #if defined (WIRELESS_CHARGER)