mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-29 08:52:04 -07:00
refactor: split ll bsp into separate files
This commit is contained in:
parent
dafe61f45e
commit
4c758347e4
@ -22,7 +22,9 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "py32f003xx_ll_Start_Kit.h"
|
#include "py32f0xx_bsp_button.h"
|
||||||
|
#include "py32f0xx_bsp_led.h"
|
||||||
|
#include "py32f0xx_bsp_printf.h"
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|||||||
@ -52,10 +52,6 @@ typedef enum
|
|||||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
|
#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)
|
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
||||||
|
|
||||||
/** @defgroup Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
uint32_t BSP_GetVersion(void);
|
|
||||||
|
|
||||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
||||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||||
|
|||||||
@ -6,10 +6,6 @@ const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN };
|
|||||||
const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
|
const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup LED_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configures Button GPIO and EXTI Line.
|
* @brief Configures Button GPIO and EXTI Line.
|
||||||
* @param Button: Specifies the Button to be configured.
|
* @param Button: Specifies the Button to be configured.
|
||||||
|
|||||||
76
Libraries/BSP_LL/Inc/py32f003xx_ll_Start_Kit.h → Libraries/BSP_LL/Inc/py32f0xx_bsp_button.h
Executable file → Normal file
76
Libraries/BSP_LL/Inc/py32f003xx_ll_Start_Kit.h → Libraries/BSP_LL/Inc/py32f0xx_bsp_button.h
Executable file → Normal file
@ -1,35 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file py32f003xx_ll_Start_Kit.h
|
* @file py32f0xx_bsp_button.h
|
||||||
* @author MCU Application Team
|
* @author MCU Application Team
|
||||||
* @brief This file provides set of firmware functions to manage Leds,
|
* @brief
|
||||||
* push-button available on Start Kit.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
|
||||||
* the "License"; You may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at:
|
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
#ifndef PY32F0XX_LL_START_KIT_H
|
#ifndef PY32F003_BSP_BUTTON_H
|
||||||
#define PY32F0XX_LL_START_KIT_H
|
#define PY32F003_BSP_BUTTON_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "py32f0xx_ll_rcc.h"
|
#include "py32f0xx_ll_rcc.h"
|
||||||
#include "py32f0xx_ll_bus.h"
|
#include "py32f0xx_ll_bus.h"
|
||||||
@ -42,25 +28,6 @@ extern "C" {
|
|||||||
#include "py32f0xx_ll_gpio.h"
|
#include "py32f0xx_ll_gpio.h"
|
||||||
#include "py32f0xx_ll_usart.h"
|
#include "py32f0xx_ll_usart.h"
|
||||||
|
|
||||||
/** @addtogroup BSP
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup py32f0xx_Start_Kit
|
|
||||||
* @brief This section contains the exported types, contants and functions
|
|
||||||
* required to use the Nucleo 32 board.
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup py32f0xx_Start_Kit_Exported_Types Exported Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LED3 = 0,
|
|
||||||
LED_GREEN = LED3
|
|
||||||
} Led_TypeDef;
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BUTTON_USER = 0,
|
BUTTON_USER = 0,
|
||||||
@ -74,15 +41,7 @@ typedef enum
|
|||||||
BUTTON_MODE_EXTI = 1
|
BUTTON_MODE_EXTI = 1
|
||||||
} ButtonMode_TypeDef;
|
} ButtonMode_TypeDef;
|
||||||
|
|
||||||
#define LEDn 1
|
|
||||||
|
|
||||||
#define LED3_PIN LL_GPIO_PIN_5
|
|
||||||
#define LED3_GPIO_PORT GPIOB
|
|
||||||
#define LED3_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
|
|
||||||
#define LED3_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOB)
|
|
||||||
|
|
||||||
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
|
|
||||||
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE())
|
|
||||||
|
|
||||||
#define BUTTONn 1
|
#define BUTTONn 1
|
||||||
|
|
||||||
@ -110,35 +69,12 @@ typedef enum
|
|||||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
|
||||||
|
|
||||||
/** @defgroup Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
uint32_t BSP_GetVersion(void);
|
|
||||||
|
|
||||||
void BSP_LED_Init(Led_TypeDef Led);
|
|
||||||
void BSP_LED_DeInit(Led_TypeDef Led);
|
|
||||||
void BSP_LED_On(Led_TypeDef Led);
|
|
||||||
void BSP_LED_Off(Led_TypeDef Led);
|
|
||||||
void BSP_LED_Toggle(Led_TypeDef Led);
|
|
||||||
|
|
||||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
||||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* PY32F003XX_LL_START_KIT_H */
|
#endif /* PY32F003_BSP_BUTTON_H */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE****/
|
|
||||||
59
Libraries/BSP_LL/Inc/py32f0xx_bsp_led.h
Normal file
59
Libraries/BSP_LL/Inc/py32f0xx_bsp_led.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file py32f0xx_bsp_led.h
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @brief
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef PY32F003_BSP_LED_H
|
||||||
|
#define PY32F003_BSP_LED_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "py32f0xx_ll_rcc.h"
|
||||||
|
#include "py32f0xx_ll_bus.h"
|
||||||
|
#include "py32f0xx_ll_system.h"
|
||||||
|
#include "py32f0xx_ll_exti.h"
|
||||||
|
#include "py32f0xx_ll_cortex.h"
|
||||||
|
#include "py32f0xx_ll_utils.h"
|
||||||
|
#include "py32f0xx_ll_pwr.h"
|
||||||
|
#include "py32f0xx_ll_dma.h"
|
||||||
|
#include "py32f0xx_ll_gpio.h"
|
||||||
|
#include "py32f0xx_ll_usart.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LED3 = 0,
|
||||||
|
LED_GREEN = LED3
|
||||||
|
} Led_TypeDef;
|
||||||
|
|
||||||
|
#define LEDn 1
|
||||||
|
|
||||||
|
#define LED3_PIN LL_GPIO_PIN_5
|
||||||
|
#define LED3_GPIO_PORT GPIOB
|
||||||
|
#define LED3_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
|
||||||
|
#define LED3_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOB)
|
||||||
|
|
||||||
|
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
|
||||||
|
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE())
|
||||||
|
|
||||||
|
|
||||||
|
void BSP_LED_Init(Led_TypeDef Led);
|
||||||
|
void BSP_LED_DeInit(Led_TypeDef Led);
|
||||||
|
void BSP_LED_On(Led_TypeDef Led);
|
||||||
|
void BSP_LED_Off(Led_TypeDef Led);
|
||||||
|
void BSP_LED_Toggle(Led_TypeDef Led);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* PY32F003_BSP_LED_H */
|
||||||
@ -1,214 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file py32f003xx_ll_Start_Kit.c
|
|
||||||
* @author MCU Application Team
|
|
||||||
* @brief This file provides set of firmware functions to manage Leds,
|
|
||||||
* push-button available on Start Kit.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
|
||||||
* the "License"; You may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at:
|
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "py32f003xx_ll_Start_Kit.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PY32F003xx STK BSP Driver version number
|
|
||||||
*/
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_MAIN (0x01U) /*!< [31:24] main version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION ((__PY32F003xx_STK_BSP_VERSION_MAIN << 24) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_SUB1 << 16) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_SUB2 << 8 ) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_RC))
|
|
||||||
|
|
||||||
GPIO_TypeDef* LED_PORT[LEDn] = {LED3_GPIO_PORT};
|
|
||||||
const uint16_t LED_PIN[LEDn] = {LED3_PIN};
|
|
||||||
|
|
||||||
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 };
|
|
||||||
const uint32_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE };
|
|
||||||
|
|
||||||
/** @addtogroup PY32F003xx_STK_Exported_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This method returns the PY32F003 STK BSP Driver revision.
|
|
||||||
* @retval version : 0xXYZR (8bits for each decimal, R for RC)
|
|
||||||
*/
|
|
||||||
uint32_t BSP_GetVersion(void)
|
|
||||||
{
|
|
||||||
return __PY32F003xx_STK_BSP_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @addtogroup LED_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configures LED GPIO.
|
|
||||||
* @param Led Specifies the Led to be configured.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Init(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
/* Enable the GPIO_LED Clock */
|
|
||||||
LEDx_GPIO_CLK_ENABLE(Led);
|
|
||||||
|
|
||||||
/* Configure the GPIO_LED pin */
|
|
||||||
LL_GPIO_SetPinMode(LED_PORT[Led], LED_PIN[Led], LL_GPIO_MODE_OUTPUT);
|
|
||||||
/* LL_GPIO_SetPinOutputType(LED_PORT[Led], LED_PIN[Led], LL_GPIO_OUTPUT_PUSHPULL); */
|
|
||||||
/* LL_GPIO_SetPinSpeed(LED_PORT[Led], LED_PIN[Led], LL_GPIO_SPEED_FREQ_LOW); */
|
|
||||||
/* LL_GPIO_SetPinPull(LED_PORT[Led], LED_PIN[Led], LL_GPIO_PULL_NO); */
|
|
||||||
|
|
||||||
LL_GPIO_SetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DeInitialize LED GPIO.
|
|
||||||
* @param Led Specifies the Led to be deconfigured.
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED3
|
|
||||||
* @note BSP_LED_DeInit() does not disable the GPIO clock
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_DeInit(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
/* Turn off LED */
|
|
||||||
LL_GPIO_ResetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
/* DeInit the GPIO_LED pin */
|
|
||||||
LL_GPIO_SetPinMode(LED_PORT[Led], LED_PIN[Led], LL_GPIO_MODE_ANALOG);
|
|
||||||
/* LL_GPIO_SetPinOutputType(LED_PORT[Led], LED_PIN[Led], LL_GPIO_OUTPUT_PUSHPULL); */
|
|
||||||
/* LL_GPIO_SetPinSpeed(LED_PORT[Led], LED_PIN[Led], LL_GPIO_SPEED_FREQ_LOW); */
|
|
||||||
/* LL_GPIO_SetPinPull(LED_PORT[Led], LED_PIN[Led], LL_GPIO_PULL_NO); */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED On.
|
|
||||||
* @param Led Specifies the Led to be set on.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_On(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
LL_GPIO_ResetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED Off.
|
|
||||||
* @param Led Specifies the Led to be set off.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Off(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
LL_GPIO_SetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Toggles the selected LED.
|
|
||||||
* @param Led Specifies the Led to be toggled.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Toggle(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
LL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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)
|
|
||||||
{
|
|
||||||
/* Enable the BUTTON Clock */
|
|
||||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
|
||||||
|
|
||||||
/* Configure GPIO for BUTTON */
|
|
||||||
LL_GPIO_SetPinMode(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_MODE_INPUT);
|
|
||||||
LL_GPIO_SetPinPull(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_PULL_NO);
|
|
||||||
/* LL_GPIO_SetPinSpeed(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_SPEED_FREQ_HIGH); */
|
|
||||||
|
|
||||||
if(ButtonMode == BUTTON_MODE_EXTI)
|
|
||||||
{
|
|
||||||
/* Configure Button pin as input with External interrupt */
|
|
||||||
LL_EXTI_EnableIT(BUTTON_EXTI_LINE[Button]);
|
|
||||||
LL_EXTI_EnableFallingTrig(BUTTON_EXTI_LINE[Button]);
|
|
||||||
|
|
||||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
|
||||||
NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F);
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
|
||||||
LL_GPIO_SetPinMode(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_MODE_ANALOG);
|
|
||||||
/* LL_GPIO_SetPinSpeed(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_SPEED_FREQ_LOW); */
|
|
||||||
/* LL_GPIO_SetPinPull(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_PULL_NO); */
|
|
||||||
/* LL_GPIO_SetAFPin_8_15(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_AF_0); */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 LL_GPIO_IsInputPinSet(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//#endif
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE****/
|
|
||||||
69
Libraries/BSP_LL/Src/py32f0xx_bsp_button.c
Normal file
69
Libraries/BSP_LL/Src/py32f0xx_bsp_button.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#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 };
|
||||||
|
const uint32_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
/* Enable the BUTTON Clock */
|
||||||
|
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||||
|
|
||||||
|
/* Configure GPIO for BUTTON */
|
||||||
|
LL_GPIO_SetPinMode(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_MODE_INPUT);
|
||||||
|
LL_GPIO_SetPinPull(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_PULL_NO);
|
||||||
|
/* LL_GPIO_SetPinSpeed(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_SPEED_FREQ_HIGH); */
|
||||||
|
|
||||||
|
if(ButtonMode == BUTTON_MODE_EXTI)
|
||||||
|
{
|
||||||
|
/* Configure Button pin as input with External interrupt */
|
||||||
|
LL_EXTI_EnableIT(BUTTON_EXTI_LINE[Button]);
|
||||||
|
LL_EXTI_EnableFallingTrig(BUTTON_EXTI_LINE[Button]);
|
||||||
|
|
||||||
|
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||||
|
NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||||
|
LL_GPIO_SetPinMode(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_MODE_ANALOG);
|
||||||
|
/* LL_GPIO_SetPinSpeed(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_SPEED_FREQ_LOW); */
|
||||||
|
/* LL_GPIO_SetPinPull(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_PULL_NO); */
|
||||||
|
/* LL_GPIO_SetAFPin_8_15(BUTTON_PORT[Button], BUTTON_PIN[Button], LL_GPIO_AF_0); */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 LL_GPIO_IsInputPinSet(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||||
|
}
|
||||||
82
Libraries/BSP_LL/Src/py32f0xx_bsp_led.c
Normal file
82
Libraries/BSP_LL/Src/py32f0xx_bsp_led.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#include "py32f0xx_bsp_led.h"
|
||||||
|
|
||||||
|
|
||||||
|
GPIO_TypeDef* LED_PORT[LEDn] = {LED3_GPIO_PORT};
|
||||||
|
const uint16_t LED_PIN[LEDn] = {LED3_PIN};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures LED GPIO.
|
||||||
|
* @param Led Specifies the Led to be configured.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Init(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
/* Enable the GPIO_LED Clock */
|
||||||
|
LEDx_GPIO_CLK_ENABLE(Led);
|
||||||
|
|
||||||
|
/* Configure the GPIO_LED pin */
|
||||||
|
LL_GPIO_SetPinMode(LED_PORT[Led], LED_PIN[Led], LL_GPIO_MODE_OUTPUT);
|
||||||
|
/* LL_GPIO_SetPinOutputType(LED_PORT[Led], LED_PIN[Led], LL_GPIO_OUTPUT_PUSHPULL); */
|
||||||
|
/* LL_GPIO_SetPinSpeed(LED_PORT[Led], LED_PIN[Led], LL_GPIO_SPEED_FREQ_LOW); */
|
||||||
|
/* LL_GPIO_SetPinPull(LED_PORT[Led], LED_PIN[Led], LL_GPIO_PULL_NO); */
|
||||||
|
|
||||||
|
LL_GPIO_SetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DeInitialize LED GPIO.
|
||||||
|
* @param Led Specifies the Led to be deconfigured.
|
||||||
|
* This parameter can be one of the following values:
|
||||||
|
* @arg LED3
|
||||||
|
* @note BSP_LED_DeInit() does not disable the GPIO clock
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_DeInit(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
/* Turn off LED */
|
||||||
|
LL_GPIO_ResetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
/* DeInit the GPIO_LED pin */
|
||||||
|
LL_GPIO_SetPinMode(LED_PORT[Led], LED_PIN[Led], LL_GPIO_MODE_ANALOG);
|
||||||
|
/* LL_GPIO_SetPinOutputType(LED_PORT[Led], LED_PIN[Led], LL_GPIO_OUTPUT_PUSHPULL); */
|
||||||
|
/* LL_GPIO_SetPinSpeed(LED_PORT[Led], LED_PIN[Led], LL_GPIO_SPEED_FREQ_LOW); */
|
||||||
|
/* LL_GPIO_SetPinPull(LED_PORT[Led], LED_PIN[Led], LL_GPIO_PULL_NO); */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turns selected LED On.
|
||||||
|
* @param Led Specifies the Led to be set on.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_On(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
LL_GPIO_ResetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turns selected LED Off.
|
||||||
|
* @param Led Specifies the Led to be set off.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Off(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
LL_GPIO_SetOutputPin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Toggles the selected LED.
|
||||||
|
* @param Led Specifies the Led to be toggled.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Toggle(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
LL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user