Explorar o código

key 中断通过timer来处理,防止唤醒后立刻点灯导致电流不够

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=5) %!d(string=hai) anos
pai
achega
41f059376e
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      Application/app/key_leds.c

+ 12 - 2
Application/app/key_leds.c

@@ -9,16 +9,24 @@
 static uint8_t led_on_mask = 0;
 static void gpio_key_timer_handler(shark_timer_t *timer);
 static void led_charging_timer_handler(shark_timer_t *timer);
+static void led_irq_timer_handler(shark_timer_t *timer);
 void gpio_key_irq_handler(void);
 static shark_timer_t _led_timer = {.handler = gpio_key_timer_handler};
 static shark_timer_t _led_stop_timer = {.handler = gpio_key_timer_handler};
 static shark_timer_t _led_charging_timer = {.handler = led_charging_timer_handler};
+static shark_timer_t _led_irq_timer = {.handler = led_irq_timer_handler};
+
 void gpio_key_init(void){
 	shark_timer_post(&_led_stop_timer, 2000);
 	enable_gpio_key_irq(1);
 }
 
 void gpio_key_irq_handler(void){
+	mcu_sleep_set_wakeup_source(WAKEUP_SOURCE_KEY);
+	shark_timer_post(&_led_irq_timer, 0);
+}
+
+static void led_irq_timer_handler(shark_timer_t *timer) {
 	if (bms_state_get()->charging) {
 		return;
 	}
@@ -30,7 +38,6 @@ void gpio_key_irq_handler(void){
 	led_on_mask = 0x1F;
 	shark_timer_cancel(&_led_stop_timer);
 	shark_timer_post(&_led_timer, 500);
-	mcu_sleep_set_wakeup_source(WAKEUP_SOURCE_KEY);
 }
 
 static void led_show_by_mask(uint8_t mask) {
@@ -99,9 +106,12 @@ static void led_charging_timer_handler(shark_timer_t *timer) {
 void show_leds_for_charging(uint8_t charging){
 	if (charging){
 		show_next = 0;
+		shark_timer_cancel(&_led_stop_timer);
 		shark_timer_post(&_led_charging_timer, 300);
 	}else if (!charging){
+		led_show_by_mask(_led_mask(get_soc()->capacity));
 		shark_timer_cancel(&_led_charging_timer);
+		shark_timer_post(&_led_stop_timer, 2000);
 	}
 }
 
@@ -118,7 +128,7 @@ static void gpio_key_timer_handler(shark_timer_t *timer) {
 	uint8_t want_mask = _led_mask(get_soc()->capacity);
 	if (want_mask == led_on_mask) {
 		if (ml5238_is_discharging()) {
-			shark_timer_post(&_led_stop_timer, 30 * 000);
+			shark_timer_post(&_led_stop_timer, 30 * 1000);
 		}else {
 			shark_timer_post(&_led_stop_timer, 2000);
 		}