59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
|
||
#include "stm32l4xx_ll_pwr.h"
|
||
#include "stm32l4xx_ll_bus.h"
|
||
#include "stm32l4xx_ll_exti.h"
|
||
#include "stm32l4xx_ll_system.h"
|
||
#include "bsp.h"
|
||
|
||
#define EXIT_LINE LL_EXTI_LINE_16
|
||
|
||
pvd_irq_handle_cb pvd_irq_handle_cb_func = NULL;
|
||
/**
|
||
* @brief 配置PVD(电源电压检测)
|
||
*
|
||
* 根据给定的电源电压等级配置PVD(电源电压检测)。
|
||
*
|
||
* @param pwr_level 电源电压等级
|
||
* @param call PVD中断处理回调函数
|
||
*/
|
||
void pvd_configuration(uint32_t pwr_level, pvd_irq_handle_cb call)
|
||
{
|
||
pvd_irq_handle_cb_func = call;
|
||
// 启用电源时钟
|
||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
||
|
||
// 设置PVD电平阈值,例如设置为2.2V LL_PWR_PVDLEVEL_1
|
||
LL_PWR_SetPVDLevel(pwr_level);
|
||
|
||
// 启用PVD
|
||
LL_PWR_EnablePVD();
|
||
|
||
// 配置PVD中断
|
||
LL_EXTI_EnableIT_0_31(EXIT_LINE); // PVD连接到EXTI Line
|
||
LL_EXTI_EnableRisingTrig_0_31(EXIT_LINE);
|
||
LL_EXTI_EnableFallingTrig_0_31(EXIT_LINE);
|
||
|
||
// 启用PVD中断向量
|
||
NVIC_EnableIRQ(PVD_PVM_IRQn);
|
||
NVIC_SetPriority(PVD_PVM_IRQn, 0);
|
||
}
|
||
|
||
/**
|
||
* @brief 处理PVD中断
|
||
*
|
||
* 当PVD中断触发时,该函数将被调用以处理中断事件。
|
||
*
|
||
* @note 无返回值
|
||
*/
|
||
void pvd_irq_handle(void)
|
||
{
|
||
if (LL_EXTI_IsActiveFlag_0_31(EXIT_LINE))
|
||
{
|
||
LL_EXTI_ClearFlag_0_31(EXIT_LINE);
|
||
if (pvd_irq_handle_cb_func != NULL)
|
||
{
|
||
pvd_irq_handle_cb_func();
|
||
}
|
||
}
|
||
}
|