From ce1f140584cb5aa49562dc5e20019799b6583620 Mon Sep 17 00:00:00 2001 From: gaoyang3513 Date: Mon, 29 Jul 2024 23:56:12 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=20=E6=94=AF=E6=8C=81=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 启用Timer中断(周期1ms),以支持按键状态获取; --- NSPE/WIFI_IOT/bsp/CMakeLists.txt | 1 + .../2_Ebyte_Board_Support/E15-EVB02/board.c | 4 +- .../E15-EVB02/board_button.c | 51 +++++++++++++++++++ .../E15-EVB02/board_button.h | 5 ++ NSPE/WIFI_IOT/bsp/gd32_it.c | 47 +++++++++++++++++ 5 files changed, 106 insertions(+), 2 deletions(-) diff --git a/NSPE/WIFI_IOT/bsp/CMakeLists.txt b/NSPE/WIFI_IOT/bsp/CMakeLists.txt index b905938..5f26e52 100644 --- a/NSPE/WIFI_IOT/bsp/CMakeLists.txt +++ b/NSPE/WIFI_IOT/bsp/CMakeLists.txt @@ -30,6 +30,7 @@ target_link_libraries(bsp bsp_api os_api wifi_api + cmt2310_api ) add_subdirectory(drivers) diff --git a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board.c b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board.c index aa034b1..6670680 100755 --- a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board.c +++ b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board.c @@ -206,6 +206,8 @@ void Ebyte_BSP_TIMER_Init( void ) timer_interrupt_enable(BSP_RF_TIMER, TIMER_INT_UP); /* enable a TIMER */ timer_enable(BSP_RF_TIMER); + + nvic_irq_enable(TIMER2_IRQn, 0, 0); } /* ! @@ -292,8 +294,6 @@ void Ebyte_BSP_DelayMs( volatile uint32_t nTime ) */ void Ebyte_BSP_TimerDecrement(void) { - - if( Ebyte_TimerDelayCounter != 0 ) { Ebyte_TimerDelayCounter--; diff --git a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.c b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.c index f88371c..74df8b8 100755 --- a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.c +++ b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.c @@ -19,6 +19,19 @@ */ #include "board.h" +#include "ebyte_kfifo.h" +#include "ebyte_core.h" + +static uint16_t Button1_TickCounter = 0; +static uint16_t Button2_TickCounter = 0; + +extern Ebyte_FIFO_t hfifo; +extern uint8_t FIFO_isTimeCheckReady; +static uint32_t FIFO_TickCounter = 0; + +/* Private function prototypes -----------------------------------------------*/ +void IT_Timer_ButtonCheck(void); + /* ! * @brief гʼ @@ -94,3 +107,41 @@ uint8_t Ebyte_BTN_FIFO_Pop(BSP_BTN_FIFO_t *fifo, BSP_BTN_EVENT_t *event) return 0; } + +/* ! + * @brief ʱж ״̬ + */ +void IT_Timer_ButtonCheck(void) +{ + /* 1 */ + if (!Ebyte_BSP_ReadButton(BSP_BUTTON_1)) { + Button1_TickCounter++; + } else { + if (Button1_TickCounter > 1000) // 1 + { + Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_1_LONG); + } else if (Button1_TickCounter > 50) // 50 ̰ + { + Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_1_SHORT); + } else { + } // 50 ΪǶ + + Button1_TickCounter = 0; + } + + /* 2 */ + if (!Ebyte_BSP_ReadButton(BSP_BUTTON_2)) { + Button2_TickCounter++; + } else { + if (Button2_TickCounter > 1000) // 1 + { + Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_2_LONG); + } else if (Button2_TickCounter > 50) // 50 ̰ + { + Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_2_SHORT); + } else { + } // 50 ΪǶ + + Button2_TickCounter = 0; + } +} diff --git a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.h b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.h index d3f5a12..f046b3b 100755 --- a/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.h +++ b/NSPE/WIFI_IOT/bsp/drivers/2_Ebyte_Board_Support/E15-EVB02/board_button.h @@ -1 +1,6 @@ +#ifndef __BOARD_BUTTON_H__ +#define __BOARD_BUTTON_H__ +void IT_Timer_ButtonCheck(void); + +#endif // !__BOARD_BUTTON_H__ \ No newline at end of file diff --git a/NSPE/WIFI_IOT/bsp/gd32_it.c b/NSPE/WIFI_IOT/bsp/gd32_it.c index be3a136..de5a82b 100644 --- a/NSPE/WIFI_IOT/bsp/gd32_it.c +++ b/NSPE/WIFI_IOT/bsp/gd32_it.c @@ -33,6 +33,7 @@ OF SUCH DAMAGE. */ #include "bsp_inc.h" +#include "debug_print.h" #include "gd32_it.h" #include "uart.h" #include "dma.h" @@ -40,6 +41,29 @@ OF SUCH DAMAGE. #include "bsp_wlan.h" #include "wakelock.h" //#include "systick.h" +#include "board.h" +#include "ebyte_kfifo.h" +#include "ebyte_core.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uint8_t Uart_isInRecvState = 0; +static uint8_t Uart_isContinuousRecv = 0; +static uint32_t Uart_TickCounter = 0; +extern uint8_t Uart_isRecvReady; + +static uint16_t Button1_TickCounter = 0; +static uint16_t Button2_TickCounter = 0; + + +extern Ebyte_FIFO_t hfifo; +extern uint8_t FIFO_isTimeCheckReady; +static uint32_t FIFO_TickCounter = 0; +/* Private function prototypes -----------------------------------------------*/ +void IT_Timer_ButtonCheck(void); +void IT_Timer_UartCheck(void); +/* Private functions ---------------------------------------------------------*/ extern void wlan_interrupt_rx_handler(void); extern void wlan_interrupt_tx_handler(void); @@ -466,3 +490,26 @@ void WLAN_Cmn_IRQHandler(void) sys_int_exit(); /* Tell the OS that we are leaving the ISR */ } + +/*! + \brief This function handles TIMER2 interrupt request. + \param[in] none + \param[out] none + \retval none +*/ +void TIMER2_IRQHandler(void) +{ + if(SET == timer_interrupt_flag_get(TIMER2, TIMER_INT_UP)){ + /* clear channel 0 interrupt bit */ + timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP); + + /* 按键检测 */ + IT_Timer_ButtonCheck(); + + /* 串口状态检测 */ +// IT_Timer_UartCheck(); + + /* 定时器延时辅助计算 */ + Ebyte_BSP_TimerDecrement(); + } +} \ No newline at end of file