[Mod] 支持按键发送
1. 启用Timer中断(周期1ms),以支持按键状态获取;
This commit is contained in:
@ -30,6 +30,7 @@ target_link_libraries(bsp
|
||||
bsp_api
|
||||
os_api
|
||||
wifi_api
|
||||
cmt2310_api
|
||||
)
|
||||
|
||||
add_subdirectory(drivers)
|
||||
|
||||
@ -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--;
|
||||
|
||||
@ -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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
@ -94,3 +107,41 @@ uint8_t Ebyte_BTN_FIFO_Pop(BSP_BTN_FIFO_t *fifo, BSP_BTN_EVENT_t *event)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* !
|
||||
* @brief <20><>ʱ<EFBFBD><CAB1><EFBFBD>ж<EFBFBD> ״̬<D7B4><CCAC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void IT_Timer_ButtonCheck(void)
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (!Ebyte_BSP_ReadButton(BSP_BUTTON_1)) {
|
||||
Button1_TickCounter++;
|
||||
} else {
|
||||
if (Button1_TickCounter > 1000) // 1<><31> <20><><EFBFBD><EFBFBD>
|
||||
{
|
||||
Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_1_LONG);
|
||||
} else if (Button1_TickCounter > 50) // 50<35><30><EFBFBD><EFBFBD> <20>̰<EFBFBD>
|
||||
{
|
||||
Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_1_SHORT);
|
||||
} else {
|
||||
} // 50<35><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ϊ<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Button1_TickCounter = 0;
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (!Ebyte_BSP_ReadButton(BSP_BUTTON_2)) {
|
||||
Button2_TickCounter++;
|
||||
} else {
|
||||
if (Button2_TickCounter > 1000) // 1<><31> <20><><EFBFBD><EFBFBD>
|
||||
{
|
||||
Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_2_LONG);
|
||||
} else if (Button2_TickCounter > 50) // 50<35><30><EFBFBD><EFBFBD> <20>̰<EFBFBD>
|
||||
{
|
||||
Ebyte_BTN_FIFO_Push(&BSP_BTN_FIFO, BTN_2_SHORT);
|
||||
} else {
|
||||
} // 50<35><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ϊ<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Button2_TickCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1,6 @@
|
||||
#ifndef __BOARD_BUTTON_H__
|
||||
#define __BOARD_BUTTON_H__
|
||||
|
||||
void IT_Timer_ButtonCheck(void);
|
||||
|
||||
#endif // !__BOARD_BUTTON_H__
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user