60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
/**
|
|
* @file bsp_led.c
|
|
* @brief LED GPIO driver (LED1=PB0, LED2=PA6)
|
|
*/
|
|
#include "bsp_led.h"
|
|
|
|
/**
|
|
* @brief Configure one LED pin as output push-pull.
|
|
*/
|
|
static void led_init(GPIO_Module* GPIOx, uint16_t pin)
|
|
{
|
|
GPIO_InitType GPIO_InitStructure;
|
|
|
|
/* Enable the GPIO clock */
|
|
if (GPIOx == GPIOA)
|
|
{
|
|
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
|
|
}
|
|
else if (GPIOx == GPIOB)
|
|
{
|
|
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
GPIO_InitStruct(&GPIO_InitStructure);
|
|
GPIO_InitStructure.Pin = pin;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize LED1 and LED2, both turned off.
|
|
*/
|
|
void bsp_led_init(void)
|
|
{
|
|
led_init(LED1_PORT, LED1_PIN);
|
|
led_init(LED2_PORT, LED2_PIN);
|
|
|
|
bsp_led_off(LED1_PORT, LED1_PIN);
|
|
bsp_led_off(LED2_PORT, LED2_PIN);
|
|
}
|
|
|
|
void bsp_led_on(GPIO_Module* GPIOx, uint16_t pin)
|
|
{
|
|
GPIO_SetBits(GPIOx, pin);
|
|
}
|
|
|
|
void bsp_led_off(GPIO_Module* GPIOx, uint16_t pin)
|
|
{
|
|
GPIO_ResetBits(GPIOx, pin);
|
|
}
|
|
|
|
void bsp_led_toggle(GPIO_Module* GPIOx, uint16_t pin)
|
|
{
|
|
GPIO_TogglePin(GPIOx, pin);
|
|
}
|