Skip to content

Commit

Permalink
Fixed charging mechanism, EL18 and NB4P use the same chip have the sa…
Browse files Browse the repository at this point in the history
…me problem
  • Loading branch information
richardclli committed Aug 21, 2024
1 parent 493c4bf commit 8420286
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
4 changes: 3 additions & 1 deletion radio/src/targets/pl18/battery_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 0 additions & 17 deletions radio/src/targets/pl18/battery_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions radio/src/targets/pl18/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions radio/src/targets/pl18/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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();
Expand Down
21 changes: 11 additions & 10 deletions radio/src/targets/pl18/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8420286

Please sign in to comment.