#include #include "bk_arm_arch.h" #include #include #include //#include //#include "ntp.h" //#include "time.h" //#include "app_time.h" //#include "sys_time.h" #include #include "bk_gpio.h" #include #include #include "gpio_driver.h" #include "audio_player.h" #include "key_client.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 30 static beken_timer_t timer_handle; static int time_tick = 0; static int key_press = 0; static gpio_id_t key_ble_reset = GPIO_35; static key_cb_ops_t *event_cb; void key_client_set_cb(key_cb_ops_t *cb_ops){ event_cb = cb_ops; } #if 0 static void key_gpio_int_isr(gpio_id_t id) { bk_gpio_register_isr(id ,NULL); 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); rtos_start_timer(&timer_handle); } #endif 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); } } 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 bk_gpio_register_isr(key_ble_reset ,key_gpio_int_isr); bk_gpio_set_interrupt_type(key_ble_reset, GPIO_INT_TYPE_FALLING_EDGE); bk_gpio_enable_interrupt(key_ble_reset); #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)); rtos_init_timer(&timer_handle, 200, key_timer_handle, 0); rtos_start_timer(&timer_handle); }