12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include "board.h"
- #define POWER_OFF_PORT GPIOF
- #define POWER_OFF_PIN 2
- #define POWER_IS_OFF() (POWER_OFF_PORT->IDR & (1 << POWER_OFF_PIN)) == 0
- #define POWER_IS_ON() (POWER_OFF_PORT->IDR & (1 << POWER_OFF_PIN)) != 0
- /**
- * 掉电检测的硬件初始化
- *
- * @author lxz (2019/5/30/周四)
- *
- * @param void
- */
- void hw_power_off_init(void) {
- RCC->AHBENR |= 1 << (((uint32_t)(POWER_OFF_PORT)-GPIOA_BASE) / 0x400);
- GPIO_Set(POWER_OFF_PORT, 1 << POWER_OFF_PIN,
- GPIO_MODE_IPU,
- GPIO_SPEED_2M,
- GPIO_PUPD_NONE); //PB0,PB1设置
- }
- /**
- * 电源是否关闭
- *
- * @author lxz (2019/5/29/周三)
- *
- * @param void
- *
- * @return int
- */
- int hw_power_is_off(void) {
- return POWER_IS_OFF();
- }
- /**
- * 电源是否打开
- *
- * @author lxz (2019/5/29/周三)
- *
- * @param void
- *
- * @return int
- */
- int hw_power_is_on(void) {
- return POWER_IS_ON();
- }
|