hw_power_off.c 871 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "board.h"
  2. #define POWER_OFF_PORT GPIOF
  3. #define POWER_OFF_PIN 2
  4. #define POWER_IS_OFF() (POWER_OFF_PORT->IDR & (1 << POWER_OFF_PIN)) == 0
  5. #define POWER_IS_ON() (POWER_OFF_PORT->IDR & (1 << POWER_OFF_PIN)) != 0
  6. /**
  7. * 掉电检测的硬件初始化
  8. *
  9. * @author lxz (2019/5/30/周四)
  10. *
  11. * @param void
  12. */
  13. void hw_power_off_init(void) {
  14. RCC->AHBENR |= 1 << (((uint32_t)(POWER_OFF_PORT)-GPIOA_BASE) / 0x400);
  15. GPIO_Set(POWER_OFF_PORT, 1 << POWER_OFF_PIN,
  16. GPIO_MODE_IPU,
  17. GPIO_SPEED_2M,
  18. GPIO_PUPD_NONE); //PB0,PB1设置
  19. }
  20. /**
  21. * 电源是否关闭
  22. *
  23. * @author lxz (2019/5/29/周三)
  24. *
  25. * @param void
  26. *
  27. * @return int
  28. */
  29. int hw_power_is_off(void) {
  30. return POWER_IS_OFF();
  31. }
  32. /**
  33. * 电源是否打开
  34. *
  35. * @author lxz (2019/5/29/周三)
  36. *
  37. * @param void
  38. *
  39. * @return int
  40. */
  41. int hw_power_is_on(void) {
  42. return POWER_IS_ON();
  43. }