/*
 * bsp_led.h
 *
 *  Created on: 2024Äê12ÔÂ16ÈÕ
 *      Author: 123
 */

#ifndef INC_BSP_LED_H_
#define INC_BSP_LED_H_

#include "CH58x_common.h"

#define LED_VALVE_R_PIN GPIO_Pin_7
#define LED_VALVE_G_PIN GPIO_Pin_8
#define LED_VALVE_Y_PIN GPIO_Pin_9
#define LED_ALARM_PIN   GPIO_Pin_9
#define LED_VBAT_PIN    GPIO_Pin_4

/***********************************************************************************************
#define LED_VALVE_OPEN  {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
                         GPIOA_SetBits(LED_VALVE_G_PIN);}

#define LED_VALVE_CLOSE  {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
                         GPIOA_SetBits(LED_VALVE_R_PIN);}

#define LED_ALARM_OPEN   GPIOB_SetBits(LED_ALARM_PIN)

#define LED_ALARM_CLOSE  GPIOB_ResetBits(LED_ALARM_PIN)

#define LED_VBAT_OPEN    GPIOB_SetBits(LED_VBAT_PIN)

#define LED_VBAT_CLOSE   GPIOB_ResetBits(LED_VBAT_PIN)

#define LED_ALL_OPEN     {GPIOA_SetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
                          GPIOB_SetBits(LED_ALARM_PIN | LED_VBAT_PIN);}

#define LED_ALL_CLOSE     {GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
                          GPIOA_ResetBits(LED_ALARM_PIN | LED_VBAT_PIN);}
****************************************************************************************************/

/**********LED_VALVE**************/
#define LED_VALVE_OPEN \
    do                 \
    {                  \
        GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
        GPIOA_SetBits(LED_VALVE_G_PIN); \
        GPIOA_ModeCfg(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

#define LED_VALVE_CLOSE \
    do                  \
    {                   \
        GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
        GPIOA_SetBits(LED_VALVE_R_PIN); \
        GPIOA_ModeCfg(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

/**********LED_ALARM**************/
#define LED_ALARM_OPEN \
    do                 \
    {                  \
        GPIOB_SetBits(LED_ALARM_PIN); \
        GPIOB_ModeCfg(LED_ALARM_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

#define LED_ALARM_CLOSE \
    do                  \
    {                   \
        GPIOB_ResetBits(LED_ALARM_PIN); \
        GPIOB_ModeCfg(LED_ALARM_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

/**********LED_VBAT**************/
#define LED_VBAT_OPEN \
    do                \
    {                 \
        GPIOB_SetBits(LED_VBAT_PIN); \
        GPIOB_ModeCfg(LED_VBAT_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

#define LED_VBAT_CLOSE \
    do                 \
    {                  \
        GPIOB_ResetBits(LED_VBAT_PIN); \
        GPIOB_ModeCfg(LED_VBAT_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

/**********LED_ALL**************/
#define LED_ALL_OPEN \
    do               \
    {                \
        GPIOA_SetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
        GPIOB_SetBits(LED_ALARM_PIN | LED_VBAT_PIN);\
        GPIOA_ModeCfg(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN, GPIO_ModeOut_PP_5mA); \
        GPIOB_ModeCfg(LED_ALARM_PIN | LED_VBAT_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

#define LED_ALL_CLOSE \
    do                \
    {                 \
        GPIOA_ResetBits(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN);\
        GPIOB_ResetBits(LED_ALARM_PIN | LED_VBAT_PIN); \
        GPIOA_ModeCfg(LED_VALVE_R_PIN | LED_VALVE_G_PIN | LED_VALVE_Y_PIN, GPIO_ModeOut_PP_5mA); \
        GPIOB_ModeCfg(LED_ALARM_PIN | LED_VBAT_PIN, GPIO_ModeOut_PP_5mA); \
    } while (0);

void BSP_LED_Init(void);

#endif /* INC_BSP_LED_H_ */
