From 8956b2ea461e0333b9c2251e6e72a826589d5cfd Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 17 Apr 2021 16:28:09 +0800 Subject: [PATCH 1/5] [stm32 pandora] implement drv_key and modify drv_sdcard --- bsp/stm32/stm32l475-atk-pandora/board/Kconfig | 7 + .../stm32l475-atk-pandora/board/SConscript | 5 +- .../board/ports/drv_key.c | 122 ++++++++++++++++++ .../ports/{sdcard_port.c => drv_sdcard.c} | 6 +- components/drivers/misc/pin.c | 2 +- 5 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c rename bsp/stm32/stm32l475-atk-pandora/board/ports/{sdcard_port.c => drv_sdcard.c} (93%) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index 5a11d21cc1..bb34e37366 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -15,6 +15,13 @@ menu "Onboard Peripheral Drivers" select BSP_USING_UART1 default y + config BSP_USING_KEY + bool "Enable onboard keys" + select RT_USING_PIN + select RT_USING_TIMER_SOFT + select PKG_USING_MULTIBUTTON + default n + config BSP_USING_QSPI_FLASH bool "Enable QSPI FLASH (W25Q128 qspi1)" select BSP_USING_QSPI diff --git a/bsp/stm32/stm32l475-atk-pandora/board/SConscript b/bsp/stm32/stm32l475-atk-pandora/board/SConscript index 1b069dffe8..086974334a 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/board/SConscript @@ -12,6 +12,9 @@ board.c CubeMX_Config/Src/stm32l4xx_hal_msp.c ''') +if GetDepend('BSP_USING_KEY'): + src = src + ['ports/drv_key.c'] + if GetDepend(['BSP_USING_QSPI_FLASH']): src += Glob('ports/drv_qspi_flash.c') @@ -19,7 +22,7 @@ if GetDepend('BSP_USING_SPI_LCD'): src = src + ['ports/drv_lcd.c'] if GetDepend(['BSP_USING_SDCARD']): - src += Glob('ports/sdcard_port.c') + src += Glob('ports/drv_sdcard.c') if GetDepend(['BSP_USING_ICM20608']) or GetDepend(['BSP_USING_AHT10']): src += Glob('ports/sensor_port.c') diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c new file mode 100644 index 0000000000..9c357cd5b0 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-04-17 Meco Man first version + */ +#include + +#ifdef BSP_USING_KEY +#define DBG_TAG "KEY" +#define DBG_LVL DBG_INFO +#include +#include +#include +#include + +#define KEY0_PIN GET_PIN(D, 10) +#define KEY1_PIN GET_PIN(D, 9) +#define KEY2_PIN GET_PIN(D, 8) +#define KEY_WKUP_PIN GET_PIN(C, 13) + +static struct rt_timer key_timer; + +static struct button key0; +static struct button key1; +static struct button key2; +static struct button key_wkup; + +/*---- user codes area begin ----*/ +/*ssers can modify according to needs*/ +static void key0_BtnCallback(void* state) +{ + rt_kprintf("key0!\n"); +} + +static void key1_BtnCallback(void* state) +{ + rt_kprintf("key1!\n"); +} + +static void key2_BtnCallback(void* state) +{ + rt_kprintf("key2!\n"); +} + +static void key_wkup_BtnCallback(void* state) +{ + rt_kprintf("key wkup!\n"); +} +/*---- user codes area end ----*/ + +static void _cb_key_timer(void *parameter) +{ + button_ticks(); +} + +static uint8_t _cb_key0_pin_level(void) +{ + return rt_pin_read(KEY0_PIN); +} + +static uint8_t _cb_key1_pin_level(void) +{ + return rt_pin_read(KEY1_PIN); +} + +static uint8_t _cb_key2_pin_level(void) +{ + return rt_pin_read(KEY2_PIN); +} + +static uint8_t _cb_key_wkup_pin_level(void) +{ + return rt_pin_read(KEY_WKUP_PIN); +} + +static int onboard_key_init(void) +{ + rt_timer_init(&key_timer, + "key timer", + _cb_key_timer, + RT_NULL, + rt_tick_from_millisecond(TICKS_INTERVAL), + RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); + + if(rt_timer_start(&key_timer) < 0) + { + LOG_E("drv_key timer initialization failed"); + return -1; + } + + rt_pin_mode(KEY0_PIN, PIN_MODE_INPUT); + rt_pin_mode(KEY1_PIN, PIN_MODE_INPUT); + rt_pin_mode(KEY2_PIN, PIN_MODE_INPUT); + rt_pin_mode(KEY_WKUP_PIN, PIN_MODE_INPUT); + + button_init(&key0, _cb_key0_pin_level, PIN_LOW); + button_init(&key1, _cb_key1_pin_level, PIN_LOW); + button_init(&key2, _cb_key2_pin_level, PIN_LOW); + button_init(&key_wkup, _cb_key_wkup_pin_level, PIN_HIGH); + + /*---- user codes area begin ----*/ + /*ssers can modify according to needs*/ + button_attach(&key0, PRESS_DOWN, key0_BtnCallback); + button_attach(&key1, PRESS_DOWN, key1_BtnCallback); + button_attach(&key2, PRESS_DOWN, key2_BtnCallback); + button_attach(&key_wkup, PRESS_UP, key_wkup_BtnCallback); + /*---- user codes area end ----*/ + + button_start(&key0); + button_start(&key1); + button_start(&key2); + button_start(&key_wkup); + + return 0; +} +INIT_APP_EXPORT(onboard_key_init); + +#endif diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/sdcard_port.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c similarity index 93% rename from bsp/stm32/stm32l475-atk-pandora/board/ports/sdcard_port.c rename to bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c index bf4babd15f..2bed0ef415 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/sdcard_port.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c @@ -23,7 +23,7 @@ #define DBG_LVL DBG_INFO #include -void sd_mount(void *parameter) +static void sd_mount(void *parameter) { while (1) { @@ -43,7 +43,7 @@ void sd_mount(void *parameter) } } -int stm32_sdcard_mount(void) +static int onboard_sdcard_mount(void) { rt_thread_t tid; @@ -67,7 +67,7 @@ int stm32_sdcard_mount(void) return RT_EOK; } -INIT_APP_EXPORT(stm32_sdcard_mount); +INIT_APP_EXPORT(onboard_sdcard_mount); static int rt_hw_spi1_tfcard(void) { diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index 91bf7058dc..3bf9a7b039 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -146,7 +146,7 @@ void rt_pin_write(rt_base_t pin, rt_base_t value) } FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_write, pinWrite, write value to hardware pin); -int rt_pin_read(rt_base_t pin) +int rt_pin_read(rt_base_t pin) { RT_ASSERT(_hw_pin.ops != RT_NULL); return _hw_pin.ops->pin_read(&_hw_pin.parent, pin); From 71988c967dbce2f819da4ab1758f143dc3d4f17d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 17 Apr 2021 16:31:08 +0800 Subject: [PATCH 2/5] format codes --- .../board/ports/drv_key.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c index 9c357cd5b0..28d78ec61a 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c @@ -78,11 +78,11 @@ static uint8_t _cb_key_wkup_pin_level(void) } static int onboard_key_init(void) -{ - rt_timer_init(&key_timer, - "key timer", - _cb_key_timer, - RT_NULL, +{ + rt_timer_init(&key_timer, + "key timer", + _cb_key_timer, + RT_NULL, rt_tick_from_millisecond(TICKS_INTERVAL), RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); @@ -91,17 +91,17 @@ static int onboard_key_init(void) LOG_E("drv_key timer initialization failed"); return -1; } - + rt_pin_mode(KEY0_PIN, PIN_MODE_INPUT); rt_pin_mode(KEY1_PIN, PIN_MODE_INPUT); rt_pin_mode(KEY2_PIN, PIN_MODE_INPUT); rt_pin_mode(KEY_WKUP_PIN, PIN_MODE_INPUT); - + button_init(&key0, _cb_key0_pin_level, PIN_LOW); button_init(&key1, _cb_key1_pin_level, PIN_LOW); button_init(&key2, _cb_key2_pin_level, PIN_LOW); button_init(&key_wkup, _cb_key_wkup_pin_level, PIN_HIGH); - + /*---- user codes area begin ----*/ /*ssers can modify according to needs*/ button_attach(&key0, PRESS_DOWN, key0_BtnCallback); @@ -109,12 +109,12 @@ static int onboard_key_init(void) button_attach(&key2, PRESS_DOWN, key2_BtnCallback); button_attach(&key_wkup, PRESS_UP, key_wkup_BtnCallback); /*---- user codes area end ----*/ - + button_start(&key0); button_start(&key1); button_start(&key2); button_start(&key_wkup); - + return 0; } INIT_APP_EXPORT(onboard_key_init); From a1d4a2586c9a33ef32c2feffbbc93a3f89ee4ed7 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 17 Apr 2021 16:32:33 +0800 Subject: [PATCH 3/5] miss typing --- bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c index 28d78ec61a..cdd1f2f222 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c @@ -103,7 +103,7 @@ static int onboard_key_init(void) button_init(&key_wkup, _cb_key_wkup_pin_level, PIN_HIGH); /*---- user codes area begin ----*/ - /*ssers can modify according to needs*/ + /*users can modify according to needs*/ button_attach(&key0, PRESS_DOWN, key0_BtnCallback); button_attach(&key1, PRESS_DOWN, key1_BtnCallback); button_attach(&key2, PRESS_DOWN, key2_BtnCallback); From 8ca492e9967e0872d65787ecf4d0d1106f3ce9bc Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 17 Apr 2021 18:01:20 +0800 Subject: [PATCH 4/5] format pin.c --- components/drivers/misc/pin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index 3bf9a7b039..666d221fa6 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -47,7 +47,7 @@ static rt_size_t _pin_write(rt_device_t dev, rt_off_t pos, const void *buffer, r return size; } -static rt_err_t _pin_control(rt_device_t dev, int cmd, void *args) +static rt_err_t _pin_control(rt_device_t dev, int cmd, void *args) { struct rt_device_pin_mode *mode; struct rt_device_pin *pin = (struct rt_device_pin *)dev; @@ -111,6 +111,7 @@ rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode, } return -RT_ENOSYS; } + rt_err_t rt_pin_detach_irq(rt_int32_t pin) { RT_ASSERT(_hw_pin.ops != RT_NULL); @@ -166,4 +167,3 @@ rt_base_t rt_pin_get(const char *name) return _hw_pin.ops->pin_get(name); } FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_get, pinGet, get pin number from hardware pin); - From b5a7a4365a49a1cafe4b77eadae1e54725f9a420 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 17 Apr 2021 20:43:44 +0800 Subject: [PATCH 5/5] miss typing --- bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c index cdd1f2f222..f9fbf9fa41 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_key.c @@ -30,7 +30,7 @@ static struct button key2; static struct button key_wkup; /*---- user codes area begin ----*/ -/*ssers can modify according to needs*/ +/*users can modify according to needs*/ static void key0_BtnCallback(void* state) { rt_kprintf("key0!\n");