1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "board.h"
- #define POWER_OFF_PORT GPIOA
- #define POWER_OFF_PIN 0
- #define POWER_IS_OFF() (gpio_input_bit_get(POWER_OFF_PORT, (1<<POWER_OFF_PIN))==RESET)
- #define POWER_IS_ON() (gpio_input_bit_get(POWER_OFF_PORT, (1<<POWER_OFF_PIN))==SET)
- /**
- * 掉电检测的硬件初始化
- *
- * @author lxz (2019/5/30/周四)
- *
- * @param void
- */
- void hw_power_off_init(void)
- {
- unsigned long port;
- unsigned short pin;
- port = POWER_OFF_PORT;
- pin = 1 << POWER_OFF_PIN;
- if (port != 0) {
- //使能时钟
- rcu_periph_clock_enable(rcu_periph_clock_bit(port));
- //配置IO为输入
- gpio_mode_set(port, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
- gpio_output_options_set(port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
- }
- }
- /**
- * 电源是否关闭
- *
- * @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();
- }
|