first
This commit is contained in:
157
apps/common/device/key/adkey.c
Normal file
157
apps/common/device/key/adkey.c
Normal file
@ -0,0 +1,157 @@
|
||||
#include "key_driver.h"
|
||||
#include "adkey.h"
|
||||
#include "gpio.h"
|
||||
#include "system/event.h"
|
||||
#include "app_config.h"
|
||||
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
|
||||
static const struct adkey_platform_data *__this = NULL;
|
||||
|
||||
u8 ad_get_key_value(void);
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para adkey_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 2, //按键消抖延时;
|
||||
.long_time = 75, //按键判定长按数量
|
||||
.hold_time = (75 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_AD,
|
||||
.get_value = ad_get_key_value,
|
||||
};
|
||||
u8 ad_get_key_value(void)
|
||||
{
|
||||
u8 i;
|
||||
u16 ad_data;
|
||||
|
||||
if (!__this->enable) {
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
/* ad_data = adc_get_voltage(__this->ad_channel); */
|
||||
ad_data = adc_get_value(__this->ad_channel);
|
||||
/* printf("ad_value = %d \n", ad_data); */
|
||||
for (i = 0; i < ADKEY_MAX_NUM; i++) {
|
||||
if ((ad_data <= __this->ad_value[i]) && (__this->ad_value[i] < 0x3ffL)) {
|
||||
return __this->key_value[i];
|
||||
}
|
||||
}
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
int adkey_init(const struct adkey_platform_data *adkey_data)
|
||||
{
|
||||
__this = adkey_data;
|
||||
if (!__this) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!__this->enable) {
|
||||
return KEY_NOT_SUPPORT;
|
||||
}
|
||||
adc_add_sample_ch(__this->ad_channel); //注意:初始化AD_KEY之前,先初始化ADC
|
||||
#if (TCFG_ADKEY_LED_IO_REUSE || TCFG_ADKEY_IR_IO_REUSE || TCFG_ADKEY_LED_SPI_IO_REUSE)
|
||||
#else
|
||||
gpio_set_die(__this->adkey_pin, 0);
|
||||
gpio_set_direction(__this->adkey_pin, 1);
|
||||
gpio_set_pull_down(__this->adkey_pin, 0);
|
||||
if (__this->extern_up_en) {
|
||||
gpio_set_pull_up(__this->adkey_pin, 0);
|
||||
} else {
|
||||
gpio_set_pull_up(__this->adkey_pin, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (TCFG_ADKEY_LED_IO_REUSE || TCFG_ADKEY_IR_IO_REUSE || TCFG_ADKEY_LED_SPI_IO_REUSE)
|
||||
|
||||
#if TCFG_ADKEY_IR_IO_REUSE
|
||||
static u8 ir_io_sus = 0;
|
||||
extern u8 ir_io_suspend(void);
|
||||
extern u8 ir_io_resume(void);
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_IO_REUSE
|
||||
static u8 led_io_sus = 0;
|
||||
extern u8 led_io_suspend(void);
|
||||
extern u8 led_io_resume(void);
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_SPI_IO_REUSE
|
||||
static u8 led_spi_sus = 0;
|
||||
extern u8 led_spi_suspend(void);
|
||||
extern u8 led_spi_resume(void);
|
||||
#endif
|
||||
u8 adc_io_reuse_enter(u32 ch)
|
||||
{
|
||||
if (ch == __this->ad_channel) {
|
||||
#if TCFG_ADKEY_IR_IO_REUSE
|
||||
if (ir_io_suspend()) {
|
||||
return 1;
|
||||
} else {
|
||||
ir_io_sus = 1;
|
||||
}
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_IO_REUSE
|
||||
if (led_io_suspend()) {
|
||||
return 1;
|
||||
} else {
|
||||
led_io_sus = 1;
|
||||
}
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_SPI_IO_REUSE
|
||||
if (led_spi_suspend()) {
|
||||
return 1;
|
||||
} else {
|
||||
led_spi_sus = 1;
|
||||
}
|
||||
#endif
|
||||
gpio_set_die(__this->adkey_pin, 0);
|
||||
gpio_set_direction(__this->adkey_pin, 1);
|
||||
gpio_set_pull_down(__this->adkey_pin, 0);
|
||||
if (__this->extern_up_en) {
|
||||
gpio_set_pull_up(__this->adkey_pin, 0);
|
||||
} else {
|
||||
gpio_set_pull_up(__this->adkey_pin, 1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 adc_io_reuse_exit(u32 ch)
|
||||
{
|
||||
if (ch == __this->ad_channel) {
|
||||
#if TCFG_ADKEY_IR_IO_REUSE
|
||||
if (ir_io_sus) {
|
||||
ir_io_sus = 0;
|
||||
ir_io_resume();
|
||||
}
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_IO_REUSE
|
||||
if (led_io_sus) {
|
||||
led_io_sus = 0;
|
||||
led_io_resume();
|
||||
}
|
||||
#endif
|
||||
#if TCFG_ADKEY_LED_SPI_IO_REUSE
|
||||
if (led_spi_sus) {
|
||||
led_spi_sus = 0;
|
||||
led_spi_resume();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #if TCFG_ADKEY_ENABLE */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
253
apps/common/device/key/adkey_rtcvdd.c
Normal file
253
apps/common/device/key/adkey_rtcvdd.c
Normal file
@ -0,0 +1,253 @@
|
||||
#include "includes.h"
|
||||
#include "key_driver.h"
|
||||
#include "adkey.h"
|
||||
#include "gpio.h"
|
||||
#include "system/event.h"
|
||||
#include "app_config.h"
|
||||
#include "asm/power/p33.h"
|
||||
|
||||
#if TCFG_ADKEY_RTCVDD_ENABLE
|
||||
|
||||
#define ADKEY_RTCVDD_DEBUG 1
|
||||
#if ADKEY_RTCVDD_DEBUG
|
||||
#define adkey_rtcvdd_debug(fmt, ...) printf("[ADKEY_RTCVDD] "fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define adkey_rtcvdd_debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define ADC_KEY_NUMBER 10
|
||||
|
||||
#define FULL_ADC 0x3ffL
|
||||
|
||||
#define ADC_FULL(x) (x)
|
||||
#define ADC_VOLTAGE(x,y,z) ((x*y) / (y + z)) //x当前满幅电压,y分压电阻,z上拉电阻
|
||||
#define ADC_ZERRO(x) (0)
|
||||
|
||||
u16 ad_rtcvdd_key_table[ADC_KEY_NUMBER + 1] = {0};
|
||||
|
||||
#define FULL_AD_VOLTAGE 0x3FFF
|
||||
|
||||
volatile u8 adkey_lock_cnt = 0;
|
||||
static u8 rtcvdd_cnt = 10;
|
||||
static u8 rtcvdd_full_cnt = 0xff;
|
||||
u16 rtcvdd_full_value = FULL_AD_VOLTAGE;
|
||||
u16 max_value = 0;
|
||||
u16 min_value = 0xffff;
|
||||
u32 total_value = 0;
|
||||
static u8 check_rtcvdd_cnt = 0;
|
||||
|
||||
static const struct adkey_rtcvdd_platform_data *__this = NULL;
|
||||
|
||||
|
||||
u8 adkey_rtcvdd_get_key_value(void);
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para adkey_rtcvdd_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 2, //按键消抖延时;
|
||||
.long_time = 75, //按键判定长按数量
|
||||
.hold_time = (75 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_RTCVDD_AD,
|
||||
.get_value = adkey_rtcvdd_get_key_value,
|
||||
};
|
||||
|
||||
static void set_rtcvdd_table(u16 adc_rtcvdd)
|
||||
{
|
||||
u8 i;
|
||||
u32 extern_up_res_value = __this->extern_up_res_value;
|
||||
|
||||
if (extern_up_res_value == 0) { //使用内部上拉
|
||||
extern_up_res_value = 100;
|
||||
}
|
||||
|
||||
for (i = 0; i < __this->adkey_num; i++) {
|
||||
if (i == (__this->adkey_num - 1)) {
|
||||
ad_rtcvdd_key_table[i] = (ADC_VOLTAGE(adc_rtcvdd, __this->res_value[i], extern_up_res_value) + ADC_FULL(adc_rtcvdd)) / 2;
|
||||
//adkey_rtcvdd_debug("recvdd = %d, res_value[%d] = %d", adc_rtcvdd, i, __this->res_value[i]);
|
||||
} else {
|
||||
ad_rtcvdd_key_table[i] = (ADC_VOLTAGE(adc_rtcvdd, __this->res_value[i], extern_up_res_value) + ADC_VOLTAGE(adc_rtcvdd, __this->res_value[i + 1], extern_up_res_value)) / 2;
|
||||
//adkey_rtcvdd_debug("res_value[%d] = %d, res_value[%d] = %d", i, __this->res_value[i], i + 1, __this->res_value[i+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SET_ADKEY_LOCK_CNT(u8 cnt)
|
||||
{
|
||||
CPU_SR_ALLOC();
|
||||
OS_ENTER_CRITICAL();
|
||||
|
||||
adkey_lock_cnt = cnt;
|
||||
|
||||
OS_EXIT_CRITICAL();
|
||||
}
|
||||
|
||||
static u8 GET_ADKEY_LOCK_CNT(void)
|
||||
{
|
||||
u8 val;
|
||||
CPU_SR_ALLOC();
|
||||
OS_ENTER_CRITICAL();
|
||||
|
||||
val = adkey_lock_cnt;
|
||||
|
||||
OS_EXIT_CRITICAL();
|
||||
return val;
|
||||
}
|
||||
|
||||
static void POST_ADKEY_LOCK_CNT(void)
|
||||
{
|
||||
CPU_SR_ALLOC();
|
||||
OS_ENTER_CRITICAL();
|
||||
|
||||
adkey_lock_cnt --;
|
||||
|
||||
OS_EXIT_CRITICAL();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief ad按键初始化
|
||||
@param void
|
||||
@param void
|
||||
@return void
|
||||
@note void ad_key0_init(void)
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int adkey_rtcvdd_init(const struct adkey_rtcvdd_platform_data *adkey_data)
|
||||
{
|
||||
adkey_rtcvdd_debug("ad key init\n");
|
||||
|
||||
__this = adkey_data;
|
||||
if (!__this) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (__this->extern_up_res_value == 0) { //使用内部上拉
|
||||
gpio_set_pull_up(__this->adkey_pin, 1);
|
||||
} else {
|
||||
gpio_set_pull_up(__this->adkey_pin, 0);
|
||||
}
|
||||
gpio_set_direction(__this->adkey_pin, 1);
|
||||
gpio_set_pull_down(__this->adkey_pin, 0);
|
||||
gpio_set_die(__this->adkey_pin, 0);
|
||||
|
||||
adc_add_sample_ch(__this->ad_channel); //注意:初始化AD_KEY之前,先初始化ADC
|
||||
adc_add_sample_ch(AD_CH_RTCVDD);
|
||||
|
||||
set_rtcvdd_table(FULL_ADC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*把cnt个值里的最大值和最小值去掉,求剩余cnt-2个数的平均值*/
|
||||
static u16 rtcvdd_full_vaule_update(u16 value)
|
||||
{
|
||||
u16 full_value = FULL_ADC;
|
||||
if (rtcvdd_full_cnt == 0xff) {
|
||||
rtcvdd_full_cnt = 0;
|
||||
SET_ADKEY_LOCK_CNT(50);
|
||||
return value; //first time
|
||||
} else {
|
||||
rtcvdd_full_cnt ++;
|
||||
if (value > max_value) {
|
||||
max_value = value;
|
||||
}
|
||||
if (value < min_value) {
|
||||
min_value = value;
|
||||
}
|
||||
total_value += value;
|
||||
|
||||
if (rtcvdd_full_cnt > 10 - 1) { //算10个数
|
||||
full_value = (total_value - max_value - min_value) / (rtcvdd_full_cnt - 2);
|
||||
rtcvdd_full_cnt = 0;
|
||||
max_value = 0;
|
||||
min_value = 0xffff;
|
||||
total_value = 0;
|
||||
} else {
|
||||
return rtcvdd_full_value;
|
||||
}
|
||||
}
|
||||
return full_value;
|
||||
}
|
||||
|
||||
u8 get_rtcvdd_level(void)
|
||||
{
|
||||
u8 level = GET_RTCVDD_VOL();
|
||||
return level;
|
||||
}
|
||||
|
||||
void set_rtcvdd_level(u8 level)
|
||||
{
|
||||
if (level > 7 || level < 0) {
|
||||
return;
|
||||
}
|
||||
RTCVDD_VOL_SEL(level);
|
||||
}
|
||||
/*检测到RTCVDD 比 VDDIO 高的时候自动把RTCVDD降一档*/
|
||||
static u8 rtcvdd_auto_match_vddio_lev(u32 rtcvdd_value)
|
||||
{
|
||||
u8 rtcvdd_lev = 0;
|
||||
if (rtcvdd_value >= FULL_ADC) { //trim rtcvdd < vddio
|
||||
if (rtcvdd_cnt > 10) {
|
||||
rtcvdd_cnt = 0;
|
||||
rtcvdd_lev = get_rtcvdd_level();
|
||||
if (rtcvdd_lev < 8) {
|
||||
rtcvdd_lev++; //降一档
|
||||
/* rtcvdd_lev--; //降一档 */
|
||||
set_rtcvdd_level(rtcvdd_lev);
|
||||
SET_ADKEY_LOCK_CNT(50);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
rtcvdd_cnt ++;
|
||||
}
|
||||
} else {
|
||||
rtcvdd_cnt = 0;
|
||||
rtcvdd_full_value = rtcvdd_full_vaule_update(rtcvdd_value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 获取ad按键值
|
||||
@param void
|
||||
@param void
|
||||
@return key_number
|
||||
@note tu8 adkey_rtcvdd_get_key_value(void)
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 adkey_rtcvdd_get_key_value(void)
|
||||
{
|
||||
u8 key_number, i;
|
||||
u32 ad_value;
|
||||
u16 rtcvdd_value = 0;
|
||||
|
||||
rtcvdd_value = 2 * adc_get_value(AD_CH_RTCVDD);
|
||||
ad_value = adc_get_value(__this->ad_channel);
|
||||
|
||||
/* printf("rtcvdd_value = %d, ad_value = %d", rtcvdd_value, ad_value); */
|
||||
if (rtcvdd_auto_match_vddio_lev(rtcvdd_value)) {
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
if (GET_ADKEY_LOCK_CNT()) {
|
||||
POST_ADKEY_LOCK_CNT();
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
set_rtcvdd_table(rtcvdd_full_value);
|
||||
|
||||
for (i = 0; i < __this->adkey_num; i++) {
|
||||
if (ad_value <= ad_rtcvdd_key_table[i] && (ad_rtcvdd_key_table[i] < 0x3FFL)) {
|
||||
return __this->key_value[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
|
||||
#endif /* #if TCFG_ADKEY_RTCVDD_ENABLE */
|
||||
|
||||
61
apps/common/device/key/ctmu_touch_key.c
Normal file
61
apps/common/device/key/ctmu_touch_key.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include "key_driver.h"
|
||||
#include "app_config.h"
|
||||
|
||||
|
||||
|
||||
#if TCFG_CTMU_TOUCH_KEY_ENABLE
|
||||
#include "asm/ctmu.h"
|
||||
|
||||
#define LOG_TAG_CONST CTMU
|
||||
#define LOG_TAG "[ctmu]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
/* =========== 触摸键使用说明 ============= */
|
||||
//1. 使用ctmu模块作计数;
|
||||
|
||||
static const struct ctmu_touch_key_platform_data *__this = NULL;
|
||||
|
||||
static u8 ctmu_touch_key_get_value(void);
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para ctmu_touch_key_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 2, //按键消抖延时;
|
||||
.long_time = 55, //按键判定长按数量
|
||||
.hold_time = (55 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 40, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_CTMU_TOUCH,
|
||||
.get_value = ctmu_touch_key_get_value,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static u8 ctmu_touch_key_get_value(void)
|
||||
{
|
||||
u8 key = get_ctmu_value();
|
||||
|
||||
if (key != NO_KEY) {
|
||||
log_debug("key = %d %x", key, __this->port_list[key].key_value);
|
||||
return __this->port_list[key].key_value;
|
||||
}
|
||||
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
|
||||
int ctmu_touch_key_init(const struct ctmu_touch_key_platform_data *ctmu_touch_key_data)
|
||||
{
|
||||
__this = ctmu_touch_key_data;
|
||||
log_info("ctmu touch_key_init >>>> ");
|
||||
|
||||
return ctmu_init((void *)ctmu_touch_key_data);
|
||||
}
|
||||
|
||||
|
||||
#endif /* #if TCFG_CTMU_TOUCH_KEY_ENABLE */
|
||||
|
||||
277
apps/common/device/key/iokey.c
Normal file
277
apps/common/device/key/iokey.c
Normal file
@ -0,0 +1,277 @@
|
||||
#include "key_driver.h"
|
||||
#include "iokey.h"
|
||||
#include "gpio.h"
|
||||
#include "system/event.h"
|
||||
#include "app_config.h"
|
||||
#include "asm/clock.h"
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
|
||||
static const struct iokey_platform_data *__this = NULL;
|
||||
|
||||
u8 io_get_key_value(void);
|
||||
|
||||
#if MOUSE_KEY_SCAN_MODE
|
||||
struct key_driver_para iokey_scan_para = {
|
||||
.scan_time = 5, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 2, //按键消抖延时;
|
||||
.long_time = 5, //按键判定长按数量
|
||||
.hold_time = (5 + 0), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_IO,
|
||||
.get_value = io_get_key_value,
|
||||
};
|
||||
#else
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para iokey_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 4, //按键消抖延时;
|
||||
.long_time = 75, //按键判定长按数量
|
||||
.hold_time = (75 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_IO,
|
||||
.get_value = io_get_key_value,
|
||||
};
|
||||
#endif
|
||||
|
||||
#define MARK_BIT_VALUE(b, v) do {if ((v & (~BIT(7))) < 7) b |= BIT(v & (~BIT(7)));} while(0)
|
||||
|
||||
static void key_io_pull_down_input(u8 key_io)
|
||||
{
|
||||
gpio_direction_input(key_io);
|
||||
gpio_set_pull_down(key_io, 1);
|
||||
gpio_set_pull_up(key_io, 0);
|
||||
gpio_set_die(key_io, 1);
|
||||
}
|
||||
|
||||
|
||||
static void key_io_pull_up_input(u8 key_io)
|
||||
{
|
||||
gpio_direction_input(key_io);
|
||||
gpio_set_pull_down(key_io, 0);
|
||||
gpio_set_pull_up(key_io, 1);
|
||||
gpio_set_die(key_io, 1);
|
||||
}
|
||||
|
||||
static void key_io_output_high(u8 key_io)
|
||||
{
|
||||
gpio_set_pull_down(key_io, 0);
|
||||
gpio_set_pull_up(key_io, 0);
|
||||
gpio_direction_output(key_io, 1);
|
||||
}
|
||||
|
||||
static void key_io_output_low(u8 key_io)
|
||||
{
|
||||
gpio_set_pull_down(key_io, 0);
|
||||
gpio_set_pull_up(key_io, 0);
|
||||
gpio_direction_output(key_io, 0);
|
||||
}
|
||||
|
||||
static int get_io_key_value(u8 key_io)
|
||||
{
|
||||
return gpio_read(key_io);
|
||||
}
|
||||
|
||||
|
||||
static void key_io_reset(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < __this->num; i++) {
|
||||
switch (__this->port[i].connect_way) {
|
||||
case ONE_PORT_TO_HIGH:
|
||||
key_io_pull_down_input(__this->port[i].key_type.one_io.port);
|
||||
break;
|
||||
|
||||
case ONE_PORT_TO_LOW:
|
||||
#if (TCFG_IO_MULTIPLEX_WITH_SD == ENABLE)
|
||||
if (TCFG_MULTIPLEX_PORT != __this->port[i].key_type.one_io.port) {
|
||||
key_io_pull_up_input(__this->port[i].key_type.one_io.port);
|
||||
}
|
||||
#else
|
||||
|
||||
key_io_pull_up_input(__this->port[i].key_type.one_io.port);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DOUBLE_PORT_TO_IO:
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(0, "IO KEY CONNECT ERR!!!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if MULT_KEY_ENABLE
|
||||
extern const struct key_remap_data iokey_remap_data;
|
||||
static u8 iokey_value_remap(u8 bit_mark)
|
||||
{
|
||||
for (int i = 0; i < iokey_remap_data.remap_num; i++) {
|
||||
if (iokey_remap_data.table[i].bit_value == bit_mark) {
|
||||
return iokey_remap_data.table[i].remap_value;
|
||||
}
|
||||
}
|
||||
|
||||
return NO_KEY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if TCFG_IO_MULTIPLEX_WITH_SD == ENABLE
|
||||
static u8 mult_key_value = 1;
|
||||
static void udelay(u32 usec)
|
||||
{
|
||||
JL_TIMER0->CON = BIT(14);
|
||||
JL_TIMER0->CNT = 0;
|
||||
JL_TIMER0->PRD = clk_get("lsb") / 1000000L * usec;
|
||||
JL_TIMER0->CON = BIT(0); //lsb clk
|
||||
while ((JL_TIMER0->CON & BIT(15)) == 0);
|
||||
JL_TIMER0->CON = BIT(14);
|
||||
}
|
||||
extern u8 sd_io_suspend(u8 sdx, u8 sd_io);
|
||||
extern u8 sd_io_resume(u8 sdx, u8 sd_io);
|
||||
void sd_mult_io_detect(void *arg)
|
||||
{
|
||||
static u32 cnt = 0;
|
||||
if (sd_io_suspend(1, 1) == 0) {
|
||||
gpio_set_direction(TCFG_MULTIPLEX_PORT, 0);
|
||||
gpio_write(TCFG_MULTIPLEX_PORT, 0);
|
||||
udelay(10);
|
||||
gpio_set_die(TCFG_MULTIPLEX_PORT, 1);
|
||||
gpio_set_pull_down(TCFG_MULTIPLEX_PORT, 0);
|
||||
gpio_set_pull_up(TCFG_MULTIPLEX_PORT, 1);
|
||||
gpio_set_direction(TCFG_MULTIPLEX_PORT, 1);
|
||||
udelay(10);
|
||||
mult_key_value = gpio_read(TCFG_MULTIPLEX_PORT);
|
||||
sd_io_resume(1, 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
__attribute__((weak)) u8 iokey_filter_hook(u8 io_state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 io_get_key_value(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
u8 press_value = 0;
|
||||
u8 read_value = 0;
|
||||
u8 read_io;
|
||||
u8 write_io;
|
||||
u8 connect_way;
|
||||
u8 ret_value = NO_KEY;
|
||||
u8 bit_mark = 0;
|
||||
|
||||
if (!__this->enable) {
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
//先扫描单IO接按键方式
|
||||
for (i = 0; i < __this->num; i++) {
|
||||
connect_way = __this->port[i].connect_way;
|
||||
|
||||
if (connect_way == ONE_PORT_TO_HIGH) {
|
||||
press_value = 1;
|
||||
} else if (connect_way == ONE_PORT_TO_LOW) {
|
||||
press_value = 0;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
read_io = __this->port[i].key_type.one_io.port;
|
||||
|
||||
#if (TCFG_IO_MULTIPLEX_WITH_SD == ENABLE)
|
||||
if (read_io == TCFG_MULTIPLEX_PORT) {
|
||||
read_value = mult_key_value;
|
||||
} else {
|
||||
read_value = get_io_key_value(read_io);
|
||||
}
|
||||
#else
|
||||
read_value = get_io_key_value(read_io);
|
||||
#endif
|
||||
if (iokey_filter_hook(read_value)) {
|
||||
#ifdef TCFG_IOKEY_TIME_REDEFINE
|
||||
extern struct key_driver_para iokey_scan_user_para;
|
||||
iokey_scan_user_para.filter_cnt = 0;
|
||||
iokey_scan_user_para.press_cnt = 0;
|
||||
iokey_scan_user_para.click_cnt = 0;
|
||||
iokey_scan_user_para.click_delay_cnt = 0;
|
||||
iokey_scan_user_para.last_key = NO_KEY;
|
||||
#else
|
||||
iokey_scan_para.filter_cnt = 0;
|
||||
iokey_scan_para.press_cnt = 0;
|
||||
iokey_scan_para.click_cnt = 0;
|
||||
iokey_scan_para.click_delay_cnt = 0;
|
||||
iokey_scan_para.last_key = NO_KEY;
|
||||
#endif
|
||||
return NO_KEY;
|
||||
}
|
||||
if (read_value == press_value) {
|
||||
ret_value = __this->port[i].key_value;
|
||||
#if MULT_KEY_ENABLE
|
||||
MARK_BIT_VALUE(bit_mark, ret_value); //标记被按下的按键
|
||||
#else
|
||||
goto _iokey_get_value_end;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//再扫描两个IO接按键方式, in_port: 上拉输入, out_port: 输出低
|
||||
for (i = 0; i < __this->num; i++) {
|
||||
connect_way = __this->port[i].connect_way;
|
||||
if (connect_way == DOUBLE_PORT_TO_IO) {//标准双io
|
||||
press_value = 0;
|
||||
read_io = __this->port[i].key_type.two_io.in_port;
|
||||
key_io_output_low(__this->port[i].key_type.two_io.out_port); //输出低
|
||||
key_io_pull_up_input(read_io); //上拉
|
||||
read_value = get_io_key_value(read_io);
|
||||
key_io_reset(); //按键初始化为单IO检测状态
|
||||
if (read_value == press_value) {
|
||||
ret_value = __this->port[i].key_value;
|
||||
#if MULT_KEY_ENABLE
|
||||
MARK_BIT_VALUE(bit_mark, ret_value); //标记被按下的按键
|
||||
#else
|
||||
goto _iokey_get_value_end;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if MULT_KEY_ENABLE
|
||||
bit_mark = iokey_value_remap(bit_mark); //组合按键重新映射按键值
|
||||
ret_value = (bit_mark != NO_KEY) ? bit_mark : ret_value;
|
||||
#endif
|
||||
|
||||
_iokey_get_value_end:
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iokey_init(const struct iokey_platform_data *iokey_data)
|
||||
{
|
||||
int i;
|
||||
|
||||
__this = iokey_data;
|
||||
if (__this == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!__this->enable) {
|
||||
return KEY_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
key_io_reset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* #if TCFG_IOKEY_ENABLE */
|
||||
|
||||
78
apps/common/device/key/irkey.c
Normal file
78
apps/common/device/key/irkey.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include "key_driver.h"
|
||||
#include "irkey.h"
|
||||
#include "gpio.h"
|
||||
#include "asm/irflt.h"
|
||||
#include "app_config.h"
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
|
||||
u8 ir_get_key_value(void);
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para irkey_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 2, //按键消抖延时;
|
||||
.long_time = 75, //按键判定长按数量
|
||||
.hold_time = (75 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_IR,
|
||||
.get_value = ir_get_key_value,
|
||||
};
|
||||
|
||||
|
||||
|
||||
const u8 IRTabFF00[] = {
|
||||
NKEY_00, NKEY_01, NKEY_02, NKEY_03, NKEY_04, NKEY_05, NKEY_06, IR_06, IR_15, IR_08, NKEY_0A, NKEY_0B, IR_12, IR_11, NKEY_0E, NKEY_0F,
|
||||
NKEY_10, NKEY_11, NKEY_12, NKEY_13, NKEY_14, IR_07, IR_09, NKEY_17, IR_13, IR_10, NKEY_1A, NKEY_1B, IR_16, NKEY_1D, NKEY_1E, NKEY_1F,
|
||||
NKEY_20, NKEY_21, NKEY_22, NKEY_23, NKEY_24, NKEY_25, NKEY_26, NKEY_27, NKEY_28, NKEY_29, NKEY_2A, NKEY_2B, NKEY_2C, NKEY_2D, NKEY_2E, NKEY_2F,
|
||||
NKEY_30, NKEY_31, NKEY_32, NKEY_33, NKEY_34, NKEY_35, NKEY_36, NKEY_37, NKEY_38, NKEY_39, NKEY_3A, NKEY_3B, NKEY_3C, NKEY_3D, NKEY_3E, NKEY_3F,
|
||||
IR_04, NKEY_41, IR_18, IR_05, IR_03, IR_00, IR_01, IR_02, NKEY_48, NKEY_49, IR_20, NKEY_4B, NKEY_4C, NKEY_4D, NKEY_4E, NKEY_4F,
|
||||
NKEY_50, NKEY_51, IR_19, NKEY_53, NKEY_54, NKEY_55, NKEY_56, NKEY_57, NKEY_58, NKEY_59, IR_17, NKEY_5B, NKEY_5C, NKEY_5D, IR_14, NKEY_5F,
|
||||
};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief 获取ir按键值
|
||||
@param void
|
||||
@param void
|
||||
@return void
|
||||
@note void get_irkey_value(void)
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u8 ir_get_key_value(void)
|
||||
{
|
||||
u8 tkey = 0xff;
|
||||
tkey = get_irflt_value();
|
||||
if (tkey == 0xff) {
|
||||
return tkey;
|
||||
}
|
||||
tkey = IRTabFF00[tkey];
|
||||
return tkey;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**@brief ir按键初始化
|
||||
@param void
|
||||
@param void
|
||||
@return void
|
||||
@note void ir_key_init(void)
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int irkey_init(const struct irkey_platform_data *irkey_data)
|
||||
{
|
||||
printf("irkey_init ");
|
||||
|
||||
ir_input_io_sel(irkey_data->port);
|
||||
|
||||
ir_output_timer_sel();
|
||||
|
||||
irflt_config();
|
||||
|
||||
ir_timeout_set();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
380
apps/common/device/key/key_driver.c
Normal file
380
apps/common/device/key/key_driver.c
Normal file
@ -0,0 +1,380 @@
|
||||
#include "device/key_driver.h"
|
||||
#include "system/event.h"
|
||||
#include "system/init.h"
|
||||
#include "iokey.h"
|
||||
#include "adkey.h"
|
||||
#include "slidekey.h"
|
||||
#include "irkey.h"
|
||||
#include "touch_key.h"
|
||||
#include "system/timer.h"
|
||||
#include "asm/power_interface.h"
|
||||
#include "app_config.h"
|
||||
#include "rdec_key.h"
|
||||
#include "tent600_key.h"
|
||||
#if TCFG_KEY_TONE_EN
|
||||
#include "tone_player.h"
|
||||
#endif
|
||||
|
||||
#if(TCFG_IRSENSOR_ENABLE == 1)
|
||||
#include "irSensor/ir_manage.h"
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST KEY
|
||||
#define LOG_TAG "[KEY]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
//#define LOG_DUMP_ENABLE
|
||||
//#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
#define KEY_EVENT_CLICK_ONLY_SUPPORT 1 //是否支持某些按键只响应单击事件
|
||||
|
||||
|
||||
#if TCFG_SPI_LCD_ENABLE
|
||||
#ifndef ALL_KEY_EVENT_CLICK_ONLY
|
||||
#define ALL_KEY_EVENT_CLICK_ONLY 1 //是否全部按键只响应单击事件
|
||||
#endif
|
||||
#else
|
||||
#ifndef ALL_KEY_EVENT_CLICK_ONLY
|
||||
#define ALL_KEY_EVENT_CLICK_ONLY 0 //是否全部按键只响应单击事件
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static volatile u8 is_key_active = 0;
|
||||
static volatile u8 key_poweron_flag = 0;
|
||||
|
||||
extern u32 timer_get_ms(void);
|
||||
|
||||
//=======================================================//
|
||||
// 按键值重新映射函数:
|
||||
// 用户可以实现该函数把一些按键值重新映射, 可用于组合键的键值重新映射
|
||||
//=======================================================//
|
||||
int __attribute__((weak)) key_event_remap(struct sys_event *e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
// 设置按键开机标志位
|
||||
//=======================================================//
|
||||
void set_key_poweron_flag(u8 flag)
|
||||
{
|
||||
key_poweron_flag = flag;
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
// 获取按键开机标志位
|
||||
//=======================================================//
|
||||
u8 get_key_poweron_flag(void)
|
||||
{
|
||||
return key_poweron_flag;
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
// 清除按键开机标志位
|
||||
//=======================================================//
|
||||
void clear_key_poweron_flag(void)
|
||||
{
|
||||
key_poweron_flag = 0;
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
// 按键扫描函数: 扫描所有注册的按键驱动
|
||||
//=======================================================//
|
||||
static void key_driver_scan(void *_scan_para)
|
||||
{
|
||||
struct key_driver_para *scan_para = (struct key_driver_para *)_scan_para;
|
||||
|
||||
u8 key_event = 0;
|
||||
u8 cur_key_value = NO_KEY;
|
||||
u8 key_value = 0;
|
||||
struct sys_event e;
|
||||
static u8 poweron_cnt = 0;
|
||||
|
||||
//为了滤掉adkey与mic连在一起时电容充放电导致的开机按键误判,一般用于type-c耳机
|
||||
/* if (poweron_cnt <= 250) { */
|
||||
/* poweron_cnt++; */
|
||||
/* return; */
|
||||
/* } */
|
||||
|
||||
cur_key_value = scan_para->get_value();
|
||||
/* if (cur_key_value != NO_KEY) { */
|
||||
/* printf(">>>cur_key_value: %d\n", cur_key_value); */
|
||||
/* } */
|
||||
|
||||
if (cur_key_value != NO_KEY) {
|
||||
is_key_active = 35; //35*10Ms
|
||||
} else if (is_key_active) {
|
||||
is_key_active --;
|
||||
}
|
||||
//===== 按键消抖处理
|
||||
if (cur_key_value != scan_para->filter_value && scan_para->filter_time) { //当前按键值与上一次按键值如果不相等, 重新消抖处理, 注意filter_time != 0;
|
||||
scan_para->filter_cnt = 0; //消抖次数清0, 重新开始消抖
|
||||
scan_para->filter_value = cur_key_value; //记录上一次的按键值
|
||||
return; //第一次检测, 返回不做处理
|
||||
} //当前按键值与上一次按键值相等, filter_cnt开始累加;
|
||||
if (scan_para->filter_cnt < scan_para->filter_time) {
|
||||
scan_para->filter_cnt++;
|
||||
return;
|
||||
}
|
||||
//为了滤掉adkey与mic连在一起时电容充放电导致的按键误判,一般用于type-c耳机
|
||||
/* if ((cur_key_value != scan_para->last_key) && (scan_para->last_key != NO_KEY) && (cur_key_value != NO_KEY)) { */
|
||||
/* return; */
|
||||
/* } */
|
||||
//===== 按键消抖结束, 开始判断按键类型(单击, 双击, 长按, 多击, HOLD, (长按/HOLD)抬起)
|
||||
if (cur_key_value != scan_para->last_key) {
|
||||
if (cur_key_value == NO_KEY) { //cur_key = NO_KEY; last_key = valid_key -> 按键被抬起
|
||||
|
||||
#if MOUSE_KEY_SCAN_MODE
|
||||
/* if (scan_para->press_cnt >= scan_para->long_time) { //长按/HOLD状态之后被按键抬起; */
|
||||
key_event = KEY_EVENT_UP;
|
||||
key_value = scan_para->last_key;
|
||||
goto _notify; //发送抬起消息
|
||||
/* } */
|
||||
#else
|
||||
if (scan_para->press_cnt >= scan_para->long_time) { //长按/HOLD状态之后被按键抬起;
|
||||
key_event = KEY_EVENT_UP;
|
||||
key_value = scan_para->last_key;
|
||||
goto _notify; //发送抬起消息
|
||||
}
|
||||
#endif
|
||||
|
||||
scan_para->click_delay_cnt = 1; //按键等待下次连击延时开始
|
||||
} else { //cur_key = valid_key, last_key = NO_KEY -> 按键被按下
|
||||
scan_para->press_cnt = 1; //用于判断long和hold事件的计数器重新开始计时;
|
||||
if (cur_key_value != scan_para->notify_value) { //第一次单击/连击时按下的是不同按键, 单击次数重新开始计数
|
||||
scan_para->click_cnt = 1;
|
||||
scan_para->notify_value = cur_key_value;
|
||||
} else {
|
||||
scan_para->click_cnt++; //单击次数累加
|
||||
}
|
||||
}
|
||||
goto _scan_end; //返回, 等待延时时间到
|
||||
} else { //cur_key = last_key -> 没有按键按下/按键长按(HOLD)
|
||||
if (cur_key_value == NO_KEY) { //last_key = NO_KEY; cur_key = NO_KEY -> 没有按键按下
|
||||
if (scan_para->click_cnt > 0) { //有按键需要消息需要处理
|
||||
|
||||
#if ALL_KEY_EVENT_CLICK_ONLY//彩屏方案支持单击
|
||||
key_event = KEY_EVENT_CLICK; //单击
|
||||
key_value = scan_para->notify_value;
|
||||
goto _notify;
|
||||
|
||||
#endif
|
||||
|
||||
#if KEY_EVENT_CLICK_ONLY_SUPPORT //是否支持某些按键只响应单击事件
|
||||
if (scan_para->notify_value & BIT(7)) { //BIT(7)按键特殊处理标志, 只发送单击事件, 也可以用于其它扩展
|
||||
key_event = KEY_EVENT_CLICK; //单击
|
||||
key_value = scan_para->notify_value;
|
||||
goto _notify;
|
||||
}
|
||||
#endif
|
||||
if (scan_para->click_delay_cnt > scan_para->click_delay_time) { //按键被抬起后延时到
|
||||
//TODO: 在此可以添加任意多击事件
|
||||
if (scan_para->click_cnt >= 5) {
|
||||
key_event = KEY_EVENT_FIRTH_CLICK; //五击
|
||||
} else if (scan_para->click_cnt >= 4) {
|
||||
key_event = KEY_EVENT_FOURTH_CLICK; //4击
|
||||
} else if (scan_para->click_cnt >= 3) {
|
||||
key_event = KEY_EVENT_TRIPLE_CLICK; //三击
|
||||
} else if (scan_para->click_cnt >= 2) {
|
||||
key_event = KEY_EVENT_DOUBLE_CLICK; //双击
|
||||
} else {
|
||||
key_event = KEY_EVENT_CLICK; //单击
|
||||
}
|
||||
key_value = scan_para->notify_value;
|
||||
goto _notify;
|
||||
} else { //按键抬起后等待下次延时时间未到
|
||||
scan_para->click_delay_cnt++;
|
||||
goto _scan_end; //按键抬起后延时时间未到, 返回
|
||||
}
|
||||
} else {
|
||||
goto _scan_end; //没有按键需要处理
|
||||
}
|
||||
} else { //last_key = valid_key; cur_key = valid_key, press_cnt累加用于判断long和hold
|
||||
scan_para->press_cnt++;
|
||||
if (scan_para->press_cnt == scan_para->long_time) {
|
||||
key_event = KEY_EVENT_LONG;
|
||||
} else if (scan_para->press_cnt == scan_para->hold_time) {
|
||||
key_event = KEY_EVENT_HOLD;
|
||||
scan_para->press_cnt = scan_para->long_time;
|
||||
} else {
|
||||
goto _scan_end; //press_cnt没到长按和HOLD次数, 返回
|
||||
}
|
||||
//press_cnt没到长按和HOLD次数, 发消息
|
||||
key_value = cur_key_value;
|
||||
goto _notify;
|
||||
}
|
||||
}
|
||||
|
||||
_notify:
|
||||
#if TCFG_IRSENSOR_ENABLE
|
||||
if (get_irSensor_event() == IR_SENSOR_EVENT_FAR) { //未佩戴的耳机不响应按键
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
key_value &= ~BIT(7); //BIT(7) 用作按键特殊处理的标志
|
||||
e.type = SYS_KEY_EVENT;
|
||||
e.u.key.init = 1;
|
||||
e.u.key.type = scan_para->key_type;//区分按键类型
|
||||
e.u.key.event = key_event;
|
||||
e.u.key.value = key_value;
|
||||
e.u.key.tmr = timer_get_ms();
|
||||
|
||||
|
||||
scan_para->click_cnt = 0; //单击次数清0
|
||||
scan_para->notify_value = NO_KEY;
|
||||
|
||||
e.arg = (void *)DEVICE_EVENT_FROM_KEY;
|
||||
/* printf("key_value: 0x%x, event: %d, key_poweron_flag: %d\n", key_value, key_event, key_poweron_flag); */
|
||||
if (key_poweron_flag) {
|
||||
if (key_event == KEY_EVENT_UP) {
|
||||
clear_key_poweron_flag();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (key_event_remap(&e)) {
|
||||
sys_event_notify(&e);
|
||||
#if TCFG_KEY_TONE_EN
|
||||
audio_key_tone_play();
|
||||
#endif
|
||||
}
|
||||
_scan_end:
|
||||
scan_para->last_key = cur_key_value;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//wakeup callback
|
||||
void key_active_set(u8 port)
|
||||
{
|
||||
is_key_active = 35; //35*10Ms
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
// 按键初始化函数: 初始化所有注册的按键驱动
|
||||
//=======================================================//
|
||||
int key_driver_init(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
#if TCFG_IOKEY_ENABLE
|
||||
extern const struct iokey_platform_data iokey_data;
|
||||
extern struct key_driver_para iokey_scan_para;
|
||||
err = iokey_init(&iokey_data);
|
||||
#ifdef TCFG_IOKEY_TIME_REDEFINE
|
||||
extern struct key_driver_para iokey_scan_user_para;
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&iokey_scan_user_para, key_driver_scan, iokey_scan_user_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#else
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&iokey_scan_para, key_driver_scan, iokey_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_ADKEY_ENABLE
|
||||
#ifdef CONFIG_ICRECORDER_CASE_ENABLE
|
||||
extern multi_adkey_init(const struct adkey_platform_data * multi_adkey_data);
|
||||
extern const struct adkey_platform_data multi_adkey_data[];
|
||||
extern struct key_driver_para multi_adkey_scan_para;
|
||||
err = multi_adkey_init(multi_adkey_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&multi_adkey_scan_para, key_driver_scan, multi_adkey_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#else
|
||||
extern const struct adkey_platform_data adkey_data;
|
||||
extern struct key_driver_para adkey_scan_para;
|
||||
err = adkey_init(&adkey_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&adkey_scan_para, key_driver_scan, adkey_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TCFG_IRKEY_ENABLE
|
||||
extern const struct irkey_platform_data irkey_data;
|
||||
extern struct key_driver_para irkey_scan_para;
|
||||
err = irkey_init(&irkey_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&irkey_scan_para, key_driver_scan, irkey_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_TOUCH_KEY_ENABLE
|
||||
extern const struct touch_key_platform_data touch_key_data;
|
||||
extern struct key_driver_para touch_key_scan_para;
|
||||
err = touch_key_init(&touch_key_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&touch_key_scan_para, key_driver_scan, touch_key_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_ADKEY_RTCVDD_ENABLE
|
||||
extern const struct adkey_rtcvdd_platform_data adkey_rtcvdd_data;
|
||||
extern struct key_driver_para adkey_rtcvdd_scan_para;
|
||||
err = adkey_rtcvdd_init(&adkey_rtcvdd_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&adkey_rtcvdd_scan_para, key_driver_scan, adkey_rtcvdd_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_RDEC_KEY_ENABLE
|
||||
extern const struct rdec_platform_data rdec_key_data;
|
||||
extern struct key_driver_para rdec_key_scan_para;
|
||||
err = rdec_key_init(&rdec_key_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&rdec_key_scan_para, key_driver_scan, rdec_key_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TCFG_CTMU_TOUCH_KEY_ENABLE
|
||||
#include "asm/ctmu.h"
|
||||
extern const struct ctmu_touch_key_platform_data ctmu_touch_key_data;
|
||||
extern struct key_driver_para ctmu_touch_key_scan_para;
|
||||
extern int ctmu_touch_key_init(const struct ctmu_touch_key_platform_data * ctmu_touch_key_data);
|
||||
err = ctmu_touch_key_init(&ctmu_touch_key_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&ctmu_touch_key_scan_para, key_driver_scan, ctmu_touch_key_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif /* #if TCFG_CTMU_TOUCH_KEY_ENABLE */
|
||||
|
||||
#if TCFG_SLIDE_KEY_ENABLE
|
||||
extern const struct slidekey_platform_data slidekey_data;
|
||||
extern int slidekey_init(const struct slidekey_platform_data * slidekey_data);
|
||||
err = slidekey_init(&slidekey_data);
|
||||
if (err == 0) {
|
||||
}
|
||||
#endif//TCFG_SLIDE_KEY_ENABLE
|
||||
|
||||
#if TCFG_6083_ADKEY_ENABLE
|
||||
extern int adkey_init_6083();
|
||||
err = adkey_init_6083();
|
||||
if (err == 0) {
|
||||
}
|
||||
#endif
|
||||
#if TCFG_TENT600_KEY_ENABLE
|
||||
extern const struct tent600_key_platform_data key_data ;
|
||||
extern struct key_driver_para tent600_key_scan_para;
|
||||
err = tent600_key_init(&key_data);
|
||||
if (err == 0) {
|
||||
sys_s_hi_timer_add((void *)&tent600_key_scan_para, key_driver_scan, tent600_key_scan_para.scan_time); //注册按键扫描定时器
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 key_idle_query(void)
|
||||
{
|
||||
return !is_key_active;
|
||||
}
|
||||
#if ((!TCFG_LP_TOUCH_KEY_ENABLE) && (TCFG_IOKEY_ENABLE || TCFG_ADKEY_ENABLE))
|
||||
REGISTER_LP_TARGET(key_lp_target) = {
|
||||
.name = "key",
|
||||
.is_idle = key_idle_query,
|
||||
};
|
||||
#endif /* #if !TCFG_LP_TOUCH_KEY_ENABLE */
|
||||
|
||||
62
apps/common/device/key/touch_key.c
Normal file
62
apps/common/device/key/touch_key.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include "touch_key.h"
|
||||
#include "key_driver.h"
|
||||
#include "app_config.h"
|
||||
|
||||
|
||||
#if TCFG_TOUCH_KEY_ENABLE
|
||||
|
||||
|
||||
/* =========== 触摸键使用说明 ============= */
|
||||
//1. 使用plcnt模块作计数;
|
||||
//2. 配置参数时, 在配置好时钟后, 需要调试no_touch_cnt和touch_cnt的值;
|
||||
|
||||
static const struct touch_key_platform_data *__this = NULL;
|
||||
|
||||
//按键驱动扫描参数列表
|
||||
struct key_driver_para touch_key_scan_para = {
|
||||
.scan_time = 10, //按键扫描频率, 单位: ms
|
||||
.last_key = NO_KEY, //上一次get_value按键值, 初始化为NO_KEY;
|
||||
.filter_time = 1, //按键消抖延时;
|
||||
.long_time = 75, //按键判定长按数量
|
||||
.hold_time = (75 + 15), //按键判定HOLD数量
|
||||
.click_delay_time = 20, //按键被抬起后等待连击延时数量
|
||||
.key_type = KEY_DRIVER_TYPE_TOUCH,
|
||||
.get_value = touch_key_get_value,
|
||||
};
|
||||
|
||||
#define TOUCH_KEY_DEBUG 0
|
||||
|
||||
#if TOUCH_KEY_DEBUG
|
||||
#define touch_key_debug(fmt, ...) printf("[TOUCH] "fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define touch_key_debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
u8 touch_key_get_value(void)
|
||||
{
|
||||
u8 key = get_plcnt_value();
|
||||
|
||||
if (key != NO_KEY) {
|
||||
touch_key_debug("key = %d", key);
|
||||
return __this->port_list[key].key_value;
|
||||
}
|
||||
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
|
||||
int touch_key_init(const struct touch_key_platform_data *touch_key_data)
|
||||
{
|
||||
__this = touch_key_data;
|
||||
printf("touch_key_init >>>> ");
|
||||
|
||||
return plcnt_init((void *)touch_key_data);
|
||||
}
|
||||
|
||||
|
||||
#endif /* #if TCFG_TOUCH_KEY_ENABLE */
|
||||
|
||||
|
||||
|
||||
|
||||
51
apps/common/device/key/uart_key.c
Normal file
51
apps/common/device/key/uart_key.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include "key_driver.h"
|
||||
#include "system/event.h"
|
||||
#include "asm/uart.h"
|
||||
#include "app_config.h"
|
||||
|
||||
extern int getbyte(char *c);
|
||||
|
||||
#if TCFG_UART_KEY_ENABLE
|
||||
|
||||
static int uart_key_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 uart_get_key_value(void)
|
||||
{
|
||||
char c;
|
||||
u8 key_value;
|
||||
|
||||
if (getbyte(&c) == 0) {
|
||||
return NO_KEY;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'm':
|
||||
key_value = KEY_MODE;
|
||||
break;
|
||||
case 'u':
|
||||
key_value = KEY_UP;
|
||||
break;
|
||||
case 'd':
|
||||
key_value = KEY_DOWN;
|
||||
break;
|
||||
case 'o':
|
||||
key_value = KEY_OK;
|
||||
break;
|
||||
case 'e':
|
||||
key_value = KEY_MENU;
|
||||
break;
|
||||
default:
|
||||
key_value = NO_KEY;
|
||||
break;
|
||||
}
|
||||
|
||||
return key_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* #if TCFG_UART_KEY_ENABLE */
|
||||
|
||||
Reference in New Issue
Block a user