优化调试新增按键驱动
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include <stdint.h>
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_spi.h"
|
||||
|
||||
/**
|
||||
* @brief Board LED configuration structure
|
||||
@ -34,8 +35,17 @@ typedef struct {
|
||||
hal_gpio_mode_t mode;
|
||||
hal_gpio_speed_t speed;
|
||||
hal_gpio_pull_t pull;
|
||||
uint8_t active_high;
|
||||
} bsp_button_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board buttons configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t count;
|
||||
const bsp_button_config_t* buttons;
|
||||
} bsp_buttons_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART instance identifier definitions
|
||||
*/
|
||||
@ -64,6 +74,27 @@ typedef struct {
|
||||
hal_gpio_pin_t rx_pin;
|
||||
} bsp_uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board SPI configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_spi_instance_t instance;
|
||||
hal_spi_mode_t mode;
|
||||
uint32_t baudrate;
|
||||
hal_spi_polarity_t polarity;
|
||||
hal_spi_phase_t phase;
|
||||
hal_spi_databits_t databits;
|
||||
} bsp_spi_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board W25QXX configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t cs_port;
|
||||
hal_gpio_pin_t cs_pin;
|
||||
bsp_spi_config_t spi_config;
|
||||
} bsp_w25qxx_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral initialization function type
|
||||
*/
|
||||
@ -75,13 +106,15 @@ typedef void (*bsp_periph_init_func_t)(const void* config);
|
||||
typedef struct {
|
||||
const char* name;
|
||||
bsp_led_config_t led;
|
||||
bsp_button_config_t button;
|
||||
bsp_buttons_config_t buttons;
|
||||
bsp_uart_config_t uart;
|
||||
bsp_w25qxx_config_t w25qxx;
|
||||
|
||||
/* Initialization function pointers */
|
||||
bsp_periph_init_func_t led_init;
|
||||
bsp_periph_init_func_t button_init;
|
||||
bsp_periph_init_func_t uart_init;
|
||||
bsp_periph_init_func_t w25qxx_init;
|
||||
|
||||
/* Additional board-specific configuration */
|
||||
uint32_t clock_speed;
|
||||
|
||||
@ -25,10 +25,19 @@
|
||||
#define BSP_LED_PIN HAL_GPIO_PIN_6
|
||||
|
||||
/**
|
||||
* @brief Button hardware configuration (if available)
|
||||
* @brief Button hardware configuration
|
||||
*/
|
||||
/* #define BSP_BUTTON_PORT HAL_GPIO_PORT_X */
|
||||
/* #define BSP_BUTTON_PIN HAL_GPIO_PIN_X */
|
||||
/* KEY0 - PE4, active low */
|
||||
#define BSP_KEY0_PORT HAL_GPIO_PORT_E
|
||||
#define BSP_KEY0_PIN HAL_GPIO_PIN_4
|
||||
|
||||
/* KEY1 - PE3, active low */
|
||||
#define BSP_KEY1_PORT HAL_GPIO_PORT_E
|
||||
#define BSP_KEY1_PIN HAL_GPIO_PIN_3
|
||||
|
||||
/* WK_UP - PA0, active high */
|
||||
#define BSP_WKUP_PORT HAL_GPIO_PORT_A
|
||||
#define BSP_WKUP_PIN HAL_GPIO_PIN_0
|
||||
|
||||
/**
|
||||
* @brief UART hardware configuration
|
||||
|
||||
111
BSP/Inc/bsp_key.h
Normal file
111
BSP/Inc/bsp_key.h
Normal file
@ -0,0 +1,111 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_key.h
|
||||
* @brief : Board support package key driver header file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_KEY_H
|
||||
#define BSP_KEY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Key ID definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_ID_KEY0 = 0,
|
||||
BSP_KEY_ID_KEY1,
|
||||
BSP_KEY_ID_WKUP,
|
||||
BSP_KEY_ID_MAX
|
||||
} bsp_key_id_t;
|
||||
|
||||
/**
|
||||
* @brief Key state definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_STATE_RELEASED = 0,
|
||||
BSP_KEY_STATE_PRESSED
|
||||
} bsp_key_state_t;
|
||||
|
||||
/**
|
||||
* @brief Key event definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_KEY_EVENT_NONE = 0,
|
||||
BSP_KEY_EVENT_PRESSED, /* Key pressed event */
|
||||
BSP_KEY_EVENT_RELEASED, /* Key released event */
|
||||
BSP_KEY_EVENT_LONG_PRESSED, /* Key long pressed event */
|
||||
BSP_KEY_EVENT_REPEAT, /* Key repeat event */
|
||||
BSP_KEY_EVENT_SHORT_PRESSED /* Key short pressed event */
|
||||
} bsp_key_event_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize all keys
|
||||
*/
|
||||
void bsp_key_init(void);
|
||||
|
||||
/**
|
||||
* @brief Update key state (call this function periodically, e.g. every 10ms)
|
||||
*/
|
||||
void bsp_key_update(void);
|
||||
|
||||
/**
|
||||
* @brief Read debounced key state
|
||||
* @param key_id: Key ID
|
||||
* @retval Key state
|
||||
*/
|
||||
bsp_key_state_t bsp_key_read(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check if key is pressed
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if pressed, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_is_pressed(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check if key is released
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if released, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_is_released(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key press event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was pressed, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_get_press_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key release event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was released, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_get_release_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key long pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was long pressed, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_get_long_press_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key repeat event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key repeat event occurred, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_get_repeat_event(bsp_key_id_t key_id);
|
||||
|
||||
/**
|
||||
* @brief Check for key short pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was short pressed, 0 otherwise
|
||||
*/
|
||||
uint8_t bsp_key_get_short_press_event(bsp_key_id_t key_id);
|
||||
|
||||
#endif /* BSP_KEY_H */
|
||||
Reference in New Issue
Block a user