#include "platform.h"
#include "hal_headfile.h"
#include "system.h"
#include "debug.h"
#include "config.h"
#include "led.h"
/**
 * This function is for Initializing LED indicator lights
 *
 * @param : none.
 * @return: none.
 */
void led_init(void)
{
    if (user_param.function_led_pin != 6) //上位机配置，6等于不启动该功能
    {
        hal_gpio_set_direction(user_param.function_led_pin, GPIO_DIRECTION_OUTPUT);
        hal_gpio_set_pull(user_param.function_led_pin, GPIO_PULL_DOWN_DISABLED);
        hal_gpio_pinmux_set_function(user_param.function_led_pin, GPIO_MUXSEL_GPIO);
        led_on(user_param.function_led_pin);
    }

    if (user_param.mute_led_pin != 6) //上位机配置，6等于不启动该功能
    {
        hal_gpio_set_direction(user_param.mute_led_pin, GPIO_DIRECTION_OUTPUT);
        hal_gpio_set_pull(user_param.mute_led_pin, GPIO_PULL_DOWN_DISABLED);
        hal_gpio_pinmux_set_function(user_param.mute_led_pin, GPIO_MUXSEL_GPIO);
        led_off(user_param.mute_led_pin);
    }
}
/**
 * This function is for setting LED on
 *
 * @param : none.
 * @return: none.
 */
void led_on(gpio_pin_t pin)
{
    hal_gpio_set_data(pin, GPIO_DATA_HIGH);
}

/**
 * This function is for setting LED off
 *
 * @param : none.
 * @return: none.
 */
void led_off(gpio_pin_t pin)
{
    hal_gpio_set_data(pin, GPIO_DATA_LOW);
}

/**
 * This function is for setting denoise LED status
 *
 * @param : none.
 * @return: none.
 */
void led_denoise_set(uint8_t enable)
{
    if (user_param.function_led_pin == 6)
    {
        return;
    }
    else if (enable)
    {
        led_on(user_param.function_led_pin);
    }
    else
    {
        led_off(user_param.function_led_pin);
    }
}

/**
 * This function is for setting mute LED status
 *
 * @param : none.
 * @return: none.
 */
void led_mute_set(uint8_t enable)
{
    if (user_param.mute_led_pin == 6)
    {
        return;
    }
    else if (enable)
    {
        led_on(user_param.mute_led_pin);
    }
    else
    {
        led_off(user_param.mute_led_pin);
    }
}