From 411776be3ffed7a59a971d031f88a52b5a4dbe91 Mon Sep 17 00:00:00 2001 From: jzlv Date: Tue, 13 Jul 2021 13:57:26 +0800 Subject: [PATCH] [fix][keyscan] fix keyscan default clk setting and array index warning --- bsp/board/bl706_avb/clock_config.h | 2 +- bsp/board/bl706_iot/clock_config.h | 2 +- drivers/bl702_driver/hal_drv/src/hal_keyscan.c | 14 ++++++++++---- examples/keyscan/keyscan_it/main.c | 2 +- examples/keyscan/keyscan_it/readme.md | 5 +++++ examples/keyscan/keyscan_poll/main.c | 2 +- examples/keyscan/keyscan_poll/readme.md | 5 +++++ 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bsp/board/bl706_avb/clock_config.h b/bsp/board/bl706_avb/clock_config.h index bcfc2380..cd82a85f 100644 --- a/bsp/board/bl706_avb/clock_config.h +++ b/bsp/board/bl706_avb/clock_config.h @@ -73,7 +73,7 @@ #define BSP_CAM_CLOCK_DIV 3 #endif #if defined(BSP_USING_QDEC) || defined(BSP_USING_KEYSCAN) -#define BSP_QDEC_KEYSCAN_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK +#define BSP_QDEC_KEYSCAN_CLOCK_SOURCE ROOT_CLOCK_SOURCE_32K_CLK #define BSP_QDEC_KEYSCAN_CLOCK_DIV 0 #endif diff --git a/bsp/board/bl706_iot/clock_config.h b/bsp/board/bl706_iot/clock_config.h index eef71a0a..4938ea65 100644 --- a/bsp/board/bl706_iot/clock_config.h +++ b/bsp/board/bl706_iot/clock_config.h @@ -64,7 +64,7 @@ #define BSP_CAM_CLOCK_DIV 3 #endif #if defined(BSP_USING_QDEC) || defined(BSP_USING_KEYSCAN) -#define BSP_QDEC_KEYSCAN_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK +#define BSP_QDEC_KEYSCAN_CLOCK_SOURCE ROOT_CLOCK_SOURCE_32K_CLK #define BSP_QDEC_KEYSCAN_CLOCK_DIV 0 #endif diff --git a/drivers/bl702_driver/hal_drv/src/hal_keyscan.c b/drivers/bl702_driver/hal_drv/src/hal_keyscan.c index e3500bae..9e8f18cc 100644 --- a/drivers/bl702_driver/hal_drv/src/hal_keyscan.c +++ b/drivers/bl702_driver/hal_drv/src/hal_keyscan.c @@ -24,14 +24,16 @@ #include "kys_reg.h" #include "bl702_glb.h" +#ifdef BSP_USING_KEYSCAN +static void KeyScan_IRQ(void); +#endif + static keyscan_device_t keyscan_device[KEYSCAN_MAX_INDEX] = { #ifdef BSP_USING_KEYSCAN KEYSCAN_CONFIG #endif }; -static void KeyScan_IRQ(void); - /** * @brief * @@ -79,7 +81,9 @@ int keyscan_control(struct device *dev, int cmd, void *args) { switch (cmd) { case DEVICE_CTRL_SET_INT /* constant-expression */: +#ifdef BSP_USING_KEYSCAN Interrupt_Handler_Register(KYS_IRQn, KeyScan_IRQ); +#endif BL_WR_REG(KYS_BASE, KYS_KS_INT_EN, 1); NVIC_EnableIRQ(KYS_IRQn); break; @@ -144,11 +148,13 @@ int keyscan_register(enum keyscan_index_type index, const char *name) return device_register(dev, name, 0); } +#if defined(BSP_USING_KEYSCAN) static void KeyScan_IRQ(void) { - if (keyscan_device[0].parent.callback) { - keyscan_device[0].parent.callback(&keyscan_device[0].parent, (void *)(BL_RD_REG(KYS_BASE, KYS_KEYCODE_VALUE)), 0, KEYSCAN_EVENT_TRIG); + if (keyscan_device[KEYSCAN_INDEX].parent.callback) { + keyscan_device[KEYSCAN_INDEX].parent.callback(&keyscan_device[KEYSCAN_INDEX].parent, (void *)(BL_RD_REG(KYS_BASE, KYS_KEYCODE_VALUE)), 0, KEYSCAN_EVENT_TRIG); } BL_WR_REG(KYS_BASE, KYS_KEYCODE_CLR, 0xf); } +#endif \ No newline at end of file diff --git a/examples/keyscan/keyscan_it/main.c b/examples/keyscan/keyscan_it/main.c index 08546ffe..47d5e94e 100644 --- a/examples/keyscan/keyscan_it/main.c +++ b/examples/keyscan/keyscan_it/main.c @@ -42,7 +42,7 @@ int main(void) if (keyscan) { KEYSCAN_DEV(keyscan)->col_num = COL_NUM_4; KEYSCAN_DEV(keyscan)->row_num = ROW_NUM_4; - device_open(keyscan, 0); //current scan latency is 32M/1/8 = 4Khz + device_open(keyscan, 0); //current scan latency is 32K/1/8 = 4Khz device_set_callback(keyscan, keyscan_irq_callback); device_control(keyscan, DEVICE_CTRL_SET_INT, NULL); device_control(keyscan, DEVICE_CTRL_RESUME, NULL); diff --git a/examples/keyscan/keyscan_it/readme.md b/examples/keyscan/keyscan_it/readme.md index 9c15edf7..d07ad704 100644 --- a/examples/keyscan/keyscan_it/readme.md +++ b/examples/keyscan/keyscan_it/readme.md @@ -1,3 +1,8 @@ +**board/bl706_iot/clock_config.h** 中, + +**BSP_QDEC_KEYSCAN_CLOCK_SOURCE** 设置成 **ROOT_CLOCK_SOURCE_32K_CLK** +**BSP_QDEC_KEYSCAN_CLOCK_DIV** 设置成 **0** + **board/bl706_iot/pinmux_config.h** 中, 以下宏设置成 **GPIO_FUN_KEY_SCAN_ROW** - **CONFIG_GPIO16_FUNC** diff --git a/examples/keyscan/keyscan_poll/main.c b/examples/keyscan/keyscan_poll/main.c index bcfd7ce8..10c83f39 100644 --- a/examples/keyscan/keyscan_poll/main.c +++ b/examples/keyscan/keyscan_poll/main.c @@ -33,7 +33,7 @@ int main(void) if (keyscan) { KEYSCAN_DEV(keyscan)->col_num = COL_NUM_4; KEYSCAN_DEV(keyscan)->row_num = ROW_NUM_4; - device_open(keyscan, 0); //current scan latency is 32M/1/8 = 4Khz + device_open(keyscan, 0); //current scan latency is 32K/1/8 = 4Khz device_control(keyscan, DEVICE_CTRL_RESUME, NULL); MSG("keyscan found\n"); } diff --git a/examples/keyscan/keyscan_poll/readme.md b/examples/keyscan/keyscan_poll/readme.md index 9c60f3d9..fb3677b9 100644 --- a/examples/keyscan/keyscan_poll/readme.md +++ b/examples/keyscan/keyscan_poll/readme.md @@ -1,3 +1,8 @@ +**board/bl706_iot/clock_config.h** 中, + +**BSP_QDEC_KEYSCAN_CLOCK_SOURCE** 设置成 **ROOT_CLOCK_SOURCE_32K_CLK** +**BSP_QDEC_KEYSCAN_CLOCK_DIV** 设置成 **0** + **board/bl706_iot/pinmux_config.h** 中, 以下宏设置成 **GPIO_FUN_KEY_SCAN_ROW** - **CONFIG_GPIO16_FUNC**