39 lines
1006 B
C
39 lines
1006 B
C
//
|
|
// Created by Wind on 2025/11/2.
|
|
//
|
|
|
|
#include "led.h"
|
|
|
|
|
|
void led_init(const led_t *led) {
|
|
const GPIO_TypeDef *port_ = led->port;
|
|
if (port_ == GPIOA)
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
else if (port_ == GPIOB)
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
else if (port_ == GPIOC)
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
else if (port_ == GPIOD)
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
else if (port_ == GPIOE)
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
GPIO_InitStruct.Pin = led->pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(led->port, &GPIO_InitStruct);
|
|
}
|
|
|
|
void led_on(const led_t *led) {
|
|
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
void led_off(const led_t *led) {
|
|
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
|
|
}
|
|
|
|
void led_toggle(const led_t *led) {
|
|
HAL_GPIO_TogglePin(led->port, led->pin);
|
|
}
|