25 lines
422 B
C
25 lines
422 B
C
/**
|
|
* @file magnet.c
|
|
* @brief 单 GPIO 电磁铁控制实现
|
|
*/
|
|
|
|
#include "magnet.h"
|
|
|
|
static int s_gpio = -1; /* 未初始化 */
|
|
|
|
void magnet_init(int gpio)
|
|
{
|
|
s_gpio = gpio;
|
|
|
|
gpio_reset_pin(s_gpio);
|
|
gpio_set_direction(s_gpio, GPIO_MODE_OUTPUT);
|
|
gpio_set_level(s_gpio, 0); /* 默认关闭 */
|
|
}
|
|
|
|
void magnet_set(bool on)
|
|
{
|
|
if (s_gpio >= 0) {
|
|
gpio_set_level(s_gpio, on ? 1 : 0);
|
|
}
|
|
}
|