helloyifa 31f179cb76 init
2025-05-15 14:19:56 +08:00

158 lines
4.1 KiB
C
Executable File

#include <common/bk_include.h>
#include "bk_arm_arch.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <netdb.h>
//#include "ntp.h"
//#include "time.h"
//#include "app_time.h"
//#include "sys_time.h"
#include <driver/timer.h>
#include "bk_gpio.h"
#include <driver/gpio.h>
#include <driver/hal/hal_gpio_types.h>
#include "gpio_driver.h"
#include "audio_player.h"
#include "key_client.h"
#include "ilock_config.h"
#define TAG "KEY"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
#define TIME_TICK_SHORT 1
#define TIME_TICK_LONG 6
static beken_timer_t timer_handle;
static int time_tick = 0;
static int key_press = 0;
static gpio_id_t key_ble_reset = ILOCK_SETTINGS_KEY_GPIO;
static key_cb_ops_t *event_cb;
static void key_gpio_int_isr(gpio_id_t id);
void key_client_set_cb(key_cb_ops_t *cb_ops){
event_cb = cb_ops;
}
static void key_timer_handle( void *arg )
{
int io = bk_gpio_get_input(key_ble_reset);
BK_LOGE(TAG,"key_timer_handle : %d\r\n",io);
if(io == 0){
if(!key_press){
key_press = 1;
BK_LOGE(TAG,"key_down : %d\r\n",time_tick);
}
time_tick ++;
if(time_tick == TIME_TICK_SHORT){
if (event_cb != NULL)
event_cb->on_key_event(KEY_DOWN,KEY_BACK_REBOOT);
}
if(time_tick == TIME_TICK_LONG){
if (event_cb != NULL)
event_cb->on_key_event(KEY_DOWN,KEY_BACK_RESET_FACTORY);
}
}else{
if(key_press){
BK_LOGE(TAG,"key_up : %d\r\n",time_tick);
#if 1
if(time_tick > TIME_TICK_LONG){
if (event_cb != NULL)
event_cb->on_key_event(KEY_UP,KEY_BACK_RESET_FACTORY);
}else{
if (event_cb != NULL)
event_cb->on_key_event(KEY_UP,KEY_BACK_REBOOT);
}
#endif
time_tick = 0;
key_press = 0;
}
bk_gpio_register_isr(key_ble_reset ,key_gpio_int_isr);
//rtos_stop_timer(&timer_handle);
BK_LOGE(TAG,"stop key_timer_handle !!!!!!!!! \r\n");
rtos_stop_timer(&timer_handle);
rtos_deinit_timer(&timer_handle);
bk_gpio_clear_interrupt(key_ble_reset);
bk_gpio_enable_interrupt(key_ble_reset);
}
}
#if 1
static void key_gpio_int_isr(gpio_id_t id)
{
bk_gpio_register_isr(id ,NULL);
bk_gpio_clear_interrupt(id);
bk_gpio_disable_interrupt(id);
BK_LOGE(TAG,"key_gpio_int_isr : %d\r\n",id);
int io = bk_gpio_get_input(key_ble_reset);
BK_LOGE(TAG,"bk_gpio_get_input : %d\r\n",io);
if(rtos_is_timer_init(&timer_handle) == true){
rtos_stop_timer(&timer_handle);
rtos_deinit_timer(&timer_handle);
}
rtos_init_timer(&timer_handle, 1000, key_timer_handle, 0);
rtos_start_timer(&timer_handle);
//rtos_start_timer(&timer_handle);
}
#endif
void key_client_start(){
bk_gpio_driver_init();
gpio_config_t cfg;
cfg.io_mode =GPIO_INPUT_ENABLE;
cfg.pull_mode = GPIO_PULL_UP_EN;
gpio_dev_unmap(key_ble_reset);
bk_gpio_set_config(key_ble_reset, &cfg);
#if 0
rtos_init_timer(&timer_handle, 200, key_timer_handle, 0);
rtos_start_timer(&timer_handle);
#else
bk_gpio_enable_interrupt(key_ble_reset);
bk_gpio_set_interrupt_type(key_ble_reset, GPIO_INT_TYPE_LOW_LEVEL);
//bk_gpio_register_wakeup_source(key_ble_reset,GPIO_INT_TYPE_FALLING_EDGE);
bk_gpio_register_isr(key_ble_reset ,key_gpio_int_isr);
#endif
//BK_LOG_ON_ERR(bk_gpio_disable_output(key_ble_reset));
//BK_LOG_ON_ERR(bk_gpio_enable_input(key_ble_reset));
//pull up
//BK_LOG_ON_ERR(bk_gpio_enable_pull(key_ble_reset));
//BK_LOG_ON_ERR(bk_gpio_pull_up(key_ble_reset));
//pull down
//BK_LOG_ON_ERR(bk_gpio_enable_pull(id));
//BK_LOG_ON_ERR(bk_gpio_pull_down(id));
// disable pull
//BK_LOG_ON_ERR(bk_gpio_disable_pull(id));
}