input: move battery ADC call to timer call
This commit is contained in:
@@ -5,9 +5,13 @@
|
||||
#include "CH58x_sys.h"
|
||||
#include "CH58xBLE_LIB.h"
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
volatile int button_count[2] = {15, 0};
|
||||
volatile int button_pressed[2] = {1, 0};
|
||||
uint16_t last_battery_value[24] = {0};
|
||||
uint16_t last_battery_index = 0;
|
||||
|
||||
volatile int button_count[BUTTON_COUNT] = {15, 0};
|
||||
volatile int button_pressed[BUTTON_COUNT] = {1, 0};
|
||||
|
||||
static void handle_button(int i, int state) {
|
||||
if (state && button_count[i] < 16) button_count[i]++;
|
||||
@@ -20,10 +24,14 @@ static void handle_button(int i, int state) {
|
||||
__INTERRUPT
|
||||
__HIGH_CODE
|
||||
void TMR3_IRQHandler(void) {
|
||||
TMR3_ClearITFlag(TMR0_3_IT_CYC_END);
|
||||
|
||||
handle_button(0, !!GPIOA_ReadPortPin(GPIO_Pin_1));
|
||||
handle_button(1, !GPIOB_ReadPortPin(GPIO_Pin_22));
|
||||
|
||||
TMR3_ClearITFlag(TMR0_3_IT_CYC_END);
|
||||
ADC_ChannelCfg(1);
|
||||
last_battery_value[last_battery_index++] = ADC_ExcutSingleConver();
|
||||
if (last_battery_index >= 24) last_battery_index = 0;
|
||||
}
|
||||
|
||||
void button_init(void)
|
||||
@@ -52,7 +60,7 @@ int get_battery_percentage(void) {
|
||||
uint32_t adc = 0;
|
||||
|
||||
for (int i = 0; i < 24; i++) {
|
||||
adc += ADC_ExcutSingleConver();
|
||||
adc += last_battery_value[i];
|
||||
}
|
||||
|
||||
adc /= 24;
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
void button_init(void);
|
||||
extern volatile int button_pressed[2];
|
||||
extern volatile int button_pressed[BUTTON_COUNT];
|
||||
|
||||
int get_battery_percentage(void);
|
||||
int is_charging(void);
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "CH58xBLE_LIB.h"
|
||||
#include "usb/core.h"
|
||||
#include "led.h"
|
||||
#include "button.h"
|
||||
#include "input.h"
|
||||
#include "menu.h"
|
||||
#include "ble.h"
|
||||
#include "cdc.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "usb/core.h"
|
||||
#include "led.h"
|
||||
#include "ble.h"
|
||||
#include "button.h"
|
||||
#include "input.h"
|
||||
#include "wang.h"
|
||||
|
||||
#include "img/menu.xbm"
|
||||
|
||||
Reference in New Issue
Block a user