// 设备状态驱动，包括指示灯和其他外设
// 杭州秒寻科技有限公司
// 周涛
// 2023-11-21

#include "includes.h"

// 模块所用管脚初始化
void driver_led_gpio_init()
{
    GPIO_InitTypeDef stGpio = {0};

    stGpio.GPIO_Mode = GPIO_Mode_OUT;
    stGpio.GPIO_OType = GPIO_OType_PP;
    stGpio.GPIO_Speed = GPIO_Speed_50MHz;
    stGpio.GPIO_PuPd = GPIO_PuPd_NOPULL;

    RCC_AHB1PeriphClockCmd(DRIVER_LED_RED_CLK, ENABLE);
    stGpio.GPIO_Pin = DRIVER_LED_RED_PIN;
    GPIO_Init(DRIVER_LED_RED_PORT, &stGpio);

    RCC_AHB1PeriphClockCmd(DRIVER_LED_GREEN_CLK, ENABLE);
    stGpio.GPIO_Pin = DRIVER_LED_GREEN_PIN;
    GPIO_Init(DRIVER_LED_GREEN_PORT, &stGpio);

    RCC_AHB1PeriphClockCmd(DRIVER_LED_BLUE_CLK, ENABLE);
    stGpio.GPIO_Pin = DRIVER_LED_BLUE_PIN;
    GPIO_Init(DRIVER_LED_BLUE_PORT, &stGpio);

    GPIO_WriteBit(DRIVER_LED_RED_PORT, DRIVER_LED_RED_PIN, Bit_RESET);
    GPIO_WriteBit(DRIVER_LED_GREEN_PORT, DRIVER_LED_GREEN_PIN, Bit_RESET);
    GPIO_WriteBit(DRIVER_LED_BLUE_PORT, DRIVER_LED_BLUE_PIN, Bit_RESET);
}

// 切换红灯状态
// bySwitch:0：关闭，1：打开
void driver_led_switch_red(uint8 bySwitch)
{
    GPIO_WriteBit(DRIVER_LED_RED_PORT, DRIVER_LED_RED_PIN, (BitAction)bySwitch);
}

// 切换绿灯状态
// bySwitch:0：关闭，1：打开
void driver_led_switch_green(uint8 bySwitch)
{
    GPIO_WriteBit(DRIVER_LED_GREEN_PORT, DRIVER_LED_GREEN_PIN, (BitAction)bySwitch);
}

// 切换蓝灯状态
// bySwitch:0：关闭，1：打开
void driver_led_switch_blue(uint8 bySwitch)
{
    GPIO_WriteBit(DRIVER_LED_BLUE_PORT, DRIVER_LED_BLUE_PIN, (BitAction)bySwitch);
}
