mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-28 08:22:06 -07:00
refactor: remove button bsp lib
This commit is contained in:
parent
7b640ce615
commit
d7cbc1a53a
@ -1,64 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file py32f0xx_bsp_button.h
|
||||
* @author MCU Application Team
|
||||
* @brief
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef PY32F0XX_BSP_BUTTON_H
|
||||
#define PY32F0XX_BSP_BUTTON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "py32f0xx_hal.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_USER = 0,
|
||||
/* Alias */
|
||||
BUTTON_KEY = BUTTON_USER
|
||||
} Button_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_MODE_GPIO = 0,
|
||||
BUTTON_MODE_EXTI = 1
|
||||
} ButtonMode_TypeDef;
|
||||
|
||||
#define BUTTONn 1
|
||||
|
||||
/**
|
||||
* @brief User push-button
|
||||
*/
|
||||
#define USER_BUTTON_PIN GPIO_PIN_12
|
||||
#define USER_BUTTON_GPIO_PORT GPIOA
|
||||
#define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
|
||||
|
||||
/* Aliases */
|
||||
#define KEY_BUTTON_PIN USER_BUTTON_PIN
|
||||
#define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
|
||||
#define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
|
||||
#define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
|
||||
#define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
|
||||
|
||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
|
||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PY32F0XX_BSP_BUTTON_H */
|
||||
@ -1,76 +0,0 @@
|
||||
#include "py32f0xx_bsp_button.h"
|
||||
|
||||
|
||||
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT };
|
||||
const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN };
|
||||
const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configures Button GPIO and EXTI Line.
|
||||
* @param Button: Specifies the Button to be configured.
|
||||
* This parameter should be: BUTTON_USER
|
||||
* @param ButtonMode: Specifies Button mode.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
||||
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
||||
* generation capability
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
||||
{
|
||||
GPIO_InitTypeDef gpioinitstruct;
|
||||
|
||||
/* Enable the BUTTON Clock */
|
||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||
|
||||
gpioinitstruct.Pin = BUTTON_PIN[Button];
|
||||
gpioinitstruct.Pull = GPIO_NOPULL;
|
||||
gpioinitstruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_GPIO)
|
||||
{
|
||||
/* Configure Button pin as input */
|
||||
gpioinitstruct.Mode = GPIO_MODE_INPUT;
|
||||
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
||||
}
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_EXTI)
|
||||
{
|
||||
/* Configure Button pin as input with External interrupt */
|
||||
gpioinitstruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
||||
|
||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Push Button DeInit.
|
||||
* @param Button: Button to be configured
|
||||
* This parameter should be: BUTTON_USER
|
||||
* @note PB DeInit does not disable the GPIO clock
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_PB_DeInit(Button_TypeDef Button)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the selected Button state.
|
||||
* @param Button: Specifies the Button to be checked.
|
||||
* This parameter should be: BUTTON_USER
|
||||
* @retval Button state.
|
||||
*/
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||
{
|
||||
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user