#ifndef HC32L1XX_LL_BGR_H_
#define HC32L1XX_LL_BGR_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "hc32l1xx.h"
#include "hc32l1xx_ll_bus.h"
///
//===BGR使能控制
#define LL_BGR_EN_DISABLE 0x00UL
#define LL_BGR_EN_ENABLE BGR_CR_EN
//===内部温度传感器控制
#define LL_BGR_TS_DISABLE 0x00UL
#define LL_BGR_TS_ENABLE BGR_TS_EN
//===系统内核时钟
extern volatile uint32_t SystemCoreClock;
///
//函 数:
//功 能: 使能BGR
//输入参 数:
//输出参 数:
//说 明:
//
static inline void LL_BGR_Enable(BGR_TypeDef *BGRx)
{
//---计算延时的脉冲书
uint32_t cnt = (SystemCoreClock >> 15);// SystemCoreClock / 40000;
//---BGR时钟使能
LL_PER0_GRP1_EnableClock(LL_PER0_GRP1_PERIPH_BGR);
SET_BIT(BGRx->CR, BGR_CR_EN);
//---等待BGR稳定
while (cnt--);
}
///
//函 数:
//功 能: 不使能BGR
//输入参 数:
//输出参 数:
//说 明:
//
static inline void LL_BGR_Disable(BGR_TypeDef *BGRx)
{
LL_PER0_GRP1_EnableClock(LL_PER0_GRP1_PERIPH_BGR);
CLEAR_BIT(BGRx->CR, BGR_CR_EN);
}
///
//函 数:
//功 能:
//输入参 数:
//输出参 数:
//说 明:
//
static inline uint32_t LL_BGR_IsEnabled(BGR_TypeDef *BGRx)
{
return (uint32_t)(READ_BIT(BGRx->CR, BGR_CR_EN)== BGR_CR_EN);
}
///
//函 数:
//功 能: 使能内部温度传感器
//输入参 数:
//输出参 数:
//说 明:
//
static inline void LL_BGR_EnableTemperatureSensor(BGR_TypeDef *BGRx)
{
SET_BIT(BGRx->CR, BGR_TS_EN);
}
///
//函 数:
//功 能: 不使能内部温度传感器
//输入参 数:
//输出参 数:
//说 明:
//
static inline void LL_BGR_DisableTemperatureSensor(BGR_TypeDef *BGRx)
{
CLEAR_BIT(BGRx->CR, BGR_TS_EN);
}
///
//函 数:
//功 能:
//输入参 数:
//输出参 数:
//说 明:
//
static inline uint32_t LL_BGR_IsEnabled_TemperatureSensor(BGR_TypeDef* BGRx)
{
return (uint32_t)(READ_BIT(BGRx->CR, BGR_TS_EN) == BGR_TS_EN);
}
//===GPIO初始化结构体
typedef struct
{
uint32_t ts; //---内部温度传感器配置
uint32_t bgr; //---BGR配置
} LL_BGR_InitTypeDef;
//===函数定义
uint8_t LL_BGR_DeInit(BGR_TypeDef *BGRx);
uint8_t LL_BGR_Init(BGR_TypeDef* BGRx, LL_BGR_InitTypeDef* BGR_InitStruct);
///
#ifdef __cplusplus
}
#endif
#endif /* HC32L1XX_LL_BGR_H_ */
#include "hc32l1xx_ll_bgr.h"
///
//函 数:
//功 能:
//输入参 数:
//输出参 数:
//说 明:
//
uint8_t LL_BGR_DeInit(BGR_TypeDef *BGRx)
{
LL_PER0_GRP1_ForceReset(LL_PER0_GRP1_PERIPH_BGR);
LL_PER0_GRP1_ReleaseReset(LL_PER0_GRP1_PERIPH_BGR);
return 0;
}
///
//函 数:
//功 能:
//输入参 数:
//输出参 数:
//说 明:
//
uint8_t LL_BGR_Init(BGR_TypeDef* BGRx, LL_BGR_InitTypeDef* BGR_InitStruct)
{
BGRx->CR = BGR_InitStruct->ts | BGR_InitStruct->bgr;
return 0;
}