48 lines
980 B
C
48 lines
980 B
C
#include "led_if.h"
|
|
#include "bsp_led.h"
|
|
|
|
static int hal_led_init(int id)
|
|
{
|
|
bsp_led_t *led = bsp_led_get(id);
|
|
if (!led) return -1;
|
|
return 0;
|
|
}
|
|
|
|
static int hal_led_write(int id, int state)
|
|
{
|
|
bsp_led_t *led = bsp_led_get(id);
|
|
if (!led) return -1;
|
|
|
|
HAL_GPIO_WritePin(led->port, led->pin,
|
|
state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
|
return 0;
|
|
}
|
|
|
|
static int hal_led_read(int id)
|
|
{
|
|
bsp_led_t *led = bsp_led_get(id);
|
|
if (!led) return -1;
|
|
return HAL_GPIO_ReadPin(led->port, led->pin) == GPIO_PIN_SET ? 1 : 0;
|
|
}
|
|
|
|
static int hal_led_toggle(int id)
|
|
{
|
|
bsp_led_t *led = bsp_led_get(id);
|
|
if (!led) return -1;
|
|
|
|
HAL_GPIO_TogglePin(led->port, led->pin);
|
|
return 0;
|
|
}
|
|
|
|
// 注册接口
|
|
static const led_ops_t ops = {
|
|
.init = hal_led_init,
|
|
.write = hal_led_write,
|
|
.read = hal_led_read,
|
|
.toggle = hal_led_toggle
|
|
};
|
|
|
|
void hal_led_init_all(void)
|
|
{
|
|
led_register_ops(&ops);
|
|
} |