hw_power_off.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "board.h"
  2. #define POWER_OFF_PORT GPIOA
  3. #define POWER_OFF_PIN 0
  4. #define POWER_IS_OFF() (gpio_input_bit_get(POWER_OFF_PORT, (1<<POWER_OFF_PIN))==RESET)
  5. #define POWER_IS_ON() (gpio_input_bit_get(POWER_OFF_PORT, (1<<POWER_OFF_PIN))==SET)
  6. /**
  7. * 掉电检测的硬件初始化
  8. *
  9. * @author lxz (2019/5/30/周四)
  10. *
  11. * @param void
  12. */
  13. void hw_power_off_init(void)
  14. {
  15. unsigned long port;
  16. unsigned short pin;
  17. port = POWER_OFF_PORT;
  18. pin = 1 << POWER_OFF_PIN;
  19. if (port != 0) {
  20. //使能时钟
  21. rcu_periph_clock_enable(rcu_periph_clock_bit(port));
  22. //配置IO为输入
  23. gpio_mode_set(port, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
  24. gpio_output_options_set(port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
  25. }
  26. }
  27. /**
  28. * 电源是否关闭
  29. *
  30. * @author lxz (2019/5/29/周三)
  31. *
  32. * @param void
  33. *
  34. * @return int
  35. */
  36. int hw_power_is_off(void)
  37. {
  38. return POWER_IS_OFF();
  39. }
  40. /**
  41. * 电源是否打开
  42. *
  43. * @author lxz (2019/5/29/周三)
  44. *
  45. * @param void
  46. *
  47. * @return int
  48. */
  49. int hw_power_is_on(void)
  50. {
  51. return POWER_IS_ON();
  52. }