#ifndef __MUX_H
#define __MUX_H

#include <stdbool.h>

//

#define LINE_0_SET      GPIOE->scr = GPIO_PINS_3
#define LINE_0_RESET    GPIOE->clr = GPIO_PINS_3

#define LINE_1_SET      GPIOE->scr = GPIO_PINS_2
#define LINE_1_RESET    GPIOE->clr = GPIO_PINS_2

#define LINE_2_SET      GPIOB->scr = GPIO_PINS_9
#define LINE_2_RESET    GPIOB->clr = GPIO_PINS_9

#define COL_1_SET      GPIOD->scr = GPIO_PINS_6
#define COL_1_RESET    GPIOD->clr = GPIO_PINS_6

#define COL_2_SET      GPIOD->scr = GPIO_PINS_7
#define COL_2_RESET    GPIOD->clr = GPIO_PINS_7

#define COL_3_SET      GPIOB->scr = GPIO_PINS_6
#define COL_3_RESET    GPIOB->clr = GPIO_PINS_6

#define COL_4_SET      GPIOB->scr = GPIO_PINS_7
#define COL_4_RESET    GPIOB->clr = GPIO_PINS_7

/* -------------------------------------------------------------------------- */
#if defined(MDIO_88)

#define LED_NUMBER      28

typedef enum
{
    INP_1 = 0, 
    INP_2, 
    INP_3, 
    INP_4,
    
    INP_5, 
    INP_6, 
    INP_7, 
    INP_8,
    
    OUT_1_G,
    OUT_2_G,
    OUT_3_G,
    OUT_4_G,
    
    OUT_1_R,
    OUT_2_R,
    OUT_3_R,
    OUT_4_R,
    
    STATUS_G,
    STATUS_R,
    RX_G,
    TX_R,
    
    OUT_5_R,
    OUT_6_R,
    OUT_7_R,
    OUT_8_R,
    
    OUT_5_G,
    OUT_6_G,
    OUT_7_G,
    OUT_8_G,
      
} led_t;
#endif

#if defined(MAI_12)

#define LED_NUMBER      28

typedef enum
{
    IO_1_G = 0, 
    IO_1_R, 
    IO_2_G,
    IO_2_R,
    
    IO_3_G,
    IO_3_R,
    IO_4_G,
    IO_4_R,
    
    IO_5_G,
    IO_5_R,
    IO_6_G,
    IO_6_R,
    
    STATUS_G,
    STATUS_R,
    RX_G,
    TX_R,
    
    IO_7_G,
    IO_7_R,
    IO_8_G,
    IO_8_R,
    
    IO_9_G,
    IO_9_R,
    IO_10_G,
    IO_10_R,
    
    IO_11_G,
    IO_11_R,
    IO_12_G,
    IO_12_R,
    
} led_t;
#endif

#if defined (MAO_4)

#define LED_NUMBER      12

typedef enum
{
    OUT_1_G = 0, 
    OUT_1_R,
    OUT_2_G,
    OUT_2_R,
    
    OUT_3_G, 
    OUT_3_R,
    OUT_4_G,
    OUT_4_R,
    
    STATUS_G,
    STATUS_R,
    RX_G,
    TX_R,
    
} led_t;
#endif

/* -------------------------------------------------------------------------- */

typedef enum
{
    LED_OFF = 0, 
    LED_ON,
    LED_BLINK,
    
} led_state_t;


typedef struct 
{
    led_t           name;
    uint8_t         line[3];    // [line_0, line_1, line_2]
    led_state_t     state;
    uint32_t        cnt;
    
} mux_channel_t;


//
void mux_led_init(mux_channel_t *ch);

//
void mux_gpio_init(void);

//
void mux_led_proc(void);

//
void mux_led_blink(void);

//
void mux_led_test_init(void);

//
void mux_led_test_toggle(void);

//
void mux_led_status(bool state);

//
void mux_task(void *argument);


extern mux_channel_t leds[];

#endif  // __MUX_H

