mirror of
https://github.com/DualTachyon/uv-k5-firmware.git
synced 2025-02-17 17:50:43 +08:00
Added battery module.
This commit is contained in:
parent
a1d3857479
commit
1e027f8939
1
Makefile
1
Makefile
@ -33,6 +33,7 @@ OBJS += driver/systick.o
|
||||
OBJS += driver/uart.o
|
||||
|
||||
# Main
|
||||
OBJS += battery.o
|
||||
OBJS += board.o
|
||||
OBJS += dcs.o
|
||||
OBJS += dtmf.o
|
||||
|
77
battery.c
Normal file
77
battery.c
Normal file
@ -0,0 +1,77 @@
|
||||
#include "battery.h"
|
||||
#include "driver/backlight.h"
|
||||
#include "misc.h"
|
||||
|
||||
uint16_t gBatteryCalibration[6];
|
||||
uint16_t gBatteryBootVoltage;
|
||||
uint16_t gBatteryCurrent;
|
||||
uint16_t gBatteryVoltages[4];
|
||||
uint16_t gBatteryVoltageAverage;
|
||||
|
||||
uint8_t gBatteryDisplayLevel;
|
||||
|
||||
bool gChargingWithTypeC;
|
||||
bool gMaybeLowBatteryWarning;
|
||||
|
||||
void BATTERY_GetReadings(bool bDisplayBatteryLevel)
|
||||
{
|
||||
uint16_t Voltage;
|
||||
uint8_t PreviousBatteryLevel;
|
||||
|
||||
PreviousBatteryLevel = gBatteryDisplayLevel;
|
||||
|
||||
Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4;
|
||||
|
||||
if (gBatteryCalibration[5] < Voltage) {
|
||||
gBatteryDisplayLevel = 6;
|
||||
} else if (gBatteryCalibration[4] < Voltage) {
|
||||
gBatteryDisplayLevel = 5;
|
||||
} else if (gBatteryCalibration[3] < Voltage) {
|
||||
gBatteryDisplayLevel = 4;
|
||||
} else if (gBatteryCalibration[2] < Voltage) {
|
||||
gBatteryDisplayLevel = 3;
|
||||
} else if (gBatteryCalibration[1] < Voltage) {
|
||||
gBatteryDisplayLevel = 2;
|
||||
} else if (gBatteryCalibration[0] < Voltage) {
|
||||
gBatteryDisplayLevel = 1;
|
||||
} else {
|
||||
gBatteryDisplayLevel = 0;
|
||||
}
|
||||
|
||||
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
|
||||
|
||||
#if 0
|
||||
if ((gScreenToDisplay == MENU) && (gMenuCursor == MENU_VOL)) {
|
||||
DAT_20000370 = 1;
|
||||
}
|
||||
#endif
|
||||
if (gBatteryCurrent < 501) {
|
||||
if (gChargingWithTypeC) {
|
||||
g_2000036F = 1;
|
||||
}
|
||||
gChargingWithTypeC = 0;
|
||||
} else {
|
||||
if (gChargingWithTypeC == false) {
|
||||
g_2000036F = 1;
|
||||
BACKLIGHT_TurnOn();
|
||||
}
|
||||
gChargingWithTypeC = 1;
|
||||
}
|
||||
|
||||
if (PreviousBatteryLevel != gBatteryDisplayLevel) {
|
||||
if (gBatteryDisplayLevel < 2) {
|
||||
gMaybeLowBatteryWarning = 1;
|
||||
} else {
|
||||
gMaybeLowBatteryWarning = 0;
|
||||
if (bDisplayBatteryLevel) {
|
||||
#if 0
|
||||
GUI_DisplayBatteryLevel(gBatteryDisplayLevel);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
//DAT_20000400 = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
21
battery.h
Normal file
21
battery.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef BATTERY_H
|
||||
#define BATTERY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint16_t gBatteryCalibration[6];
|
||||
extern uint16_t gBatteryBootVoltage;
|
||||
extern uint16_t gBatteryCurrent;
|
||||
extern uint16_t gBatteryVoltages[4];
|
||||
extern uint16_t gBatteryVoltageAverage;
|
||||
|
||||
extern uint8_t gBatteryDisplayLevel;
|
||||
|
||||
extern bool gChargingWithTypeC;
|
||||
extern bool gMaybeLowBatteryWarning;
|
||||
|
||||
void BATTERY_GetReadings(bool bDisplayBatteryLevel);
|
||||
|
||||
#endif
|
||||
|
1
board.c
1
board.c
@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "battery.h"
|
||||
#include "board.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
#include "bsp/dp32g030/portcon.h"
|
||||
|
3
main.c
3
main.c
@ -17,6 +17,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "ARMCM0.h"
|
||||
|
||||
#include "battery.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
#include "bsp/dp32g030/portcon.h"
|
||||
#include "bsp/dp32g030/syscon.h"
|
||||
@ -128,7 +129,7 @@ void Main(void)
|
||||
// TODO: EEPROM Init
|
||||
|
||||
BK4819_Init();
|
||||
BOARD_ADC_GetBatteryInfo(&gADC_CH4_BootValue, &gADC_CH9);
|
||||
BOARD_ADC_GetBatteryInfo(&gBatteryBootVoltage, &gBatteryCurrent);
|
||||
BOARD_EEPROM_Init();
|
||||
BOARD_EEPROM_LoadMoreSettings();
|
||||
|
||||
|
5
misc.c
5
misc.c
@ -40,11 +40,6 @@ uint8_t gEEPROM_1EC8_0[8];
|
||||
uint8_t gEEPROM_1EC8_1[8];
|
||||
uint8_t gEEPROM_1EC8_2[8];
|
||||
|
||||
uint16_t gBatteryCalibration[6];
|
||||
uint16_t gADC_CH4_BootValue;
|
||||
uint16_t gADC_CH4[4];
|
||||
uint16_t gADC_CH9;
|
||||
|
||||
uint16_t gEEPROM_1F8A;
|
||||
uint16_t gEEPROM_1F8C;
|
||||
uint8_t gEEPROM_1F8E;
|
||||
|
5
misc.h
5
misc.h
@ -44,11 +44,6 @@ extern uint8_t gEEPROM_1EC8_0[8];
|
||||
extern uint8_t gEEPROM_1EC8_1[8];
|
||||
extern uint8_t gEEPROM_1EC8_2[8];
|
||||
|
||||
extern uint16_t gBatteryCalibration[6];
|
||||
extern uint16_t gADC_CH4_BootValue;
|
||||
extern uint16_t gADC_CH4[4];
|
||||
extern uint16_t gADC_CH9;
|
||||
|
||||
extern uint16_t gEEPROM_1F8A;
|
||||
extern uint16_t gEEPROM_1F8C;
|
||||
extern uint8_t gEEPROM_1F8E;
|
||||
|
Loading…
Reference in New Issue
Block a user