| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "bsp/gpio.h"
- #include "bsp/mcu_power_sleep.h"
- #include "libs/shark_task.h"
- #include "libs/logger.h"
- #include "app/sox/soc.h"
- static uint8_t led_on_mask = 0;
- static void gpio_key_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};
- void gpio_key_init(void){
- shark_timer_post(&_led_stop_timer, 2000);
- enable_gpio_key_irq(1);
- }
- void gpio_key_irq_handler(void){
- LED0_ON(1);
- LED1_ON(1);
- LED2_ON(1);
- LED3_ON(1);
- LED4_ON(1);
- 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 uint8_t _led_mask(uint8_t capacity){
- uint8_t mask = 0x1F;
- if (capacity >= 80) {
- mask = 0x1F;
- }else if (capacity >= 60) {
- mask = 0x1E;
- }else if (capacity >= 40) {
- mask = 0x1C;
- }else if (capacity >= 20) {
- mask = 0x18;
- }else {
- mask = 0x10;
- }
- return mask;
- }
- static void gpio_key_timer_handler(shark_timer_t *timer) {
- if (timer == &_led_stop_timer) {
- LED0_ON(0);
- LED1_ON(0);
- LED2_ON(0);
- LED3_ON(0);
- LED4_ON(0);
- return;
- }
-
- uint8_t want_mask = _led_mask(get_soc()->capacity);
- if (want_mask == led_on_mask) {
- shark_timer_post(&_led_stop_timer, 2000);
- }else {
- for (int m = 0; m < 5; m++){
- if (led_on_mask & (1 << m)){
- if (m == 0) {
- LED4_ON(0);
- }else if(m == 1) {
- LED3_ON(0);
- }else if (m == 2) {
- LED2_ON(0);
- }else if (m == 3) {
- LED1_ON(0);
- }else {
- LED0_ON(0);
- }
- led_on_mask &= ~(1 << m);
- break;
- }
- }
- shark_timer_post(&_led_timer, 500);
- }
- }
|