HC32L17x的LL驱动库之BGR

#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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值