#ifndef __HI_LED_H__
#define __HI_LED_H__
#define PWMI_ADRESS_BASE 0x12130000
#define HI_IO_PWMI_ADDRESS(x) (x)
#define PERI_CRG55 0x120100DC /* pwm clock && reset control register */
#define PWM4_MUXCTL_REG 0x12040000
#define PWM5_MUXCTL_REG 0x12040004
#define PWM7_MUXCTL_REG 0x120400A4
#define PWM_MUXCTL_GPIO 0
#define PWM_MUXCTL_PWM 3
//PWMI
#define PWM0_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0000)
#define PWM0_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0004)
#define PWM0_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0008)
#define PWM0_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x000C)
#define PWM0_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0010)
#define PWM0_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0014)
#define PWM0_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0018)
#define PWM1_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0020)
#define PWM1_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0024)
#define PWM1_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0028)
#define PWM1_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x002C)
#define PWM1_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0030)
#define PWM1_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0034)
#define PWM1_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0038)
#define PWM2_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0040)
#define PWM2_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0044)
#define PWM2_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0048)
#define PWM2_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x004C)
#define PWM2_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0050)
#define PWM2_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0054)
#define PWM2_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0058)
#define PWM3_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0060)
#define PWM3_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0064)
#define PWM3_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0068)
#define PWM3_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x006C)
#define PWM3_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0070)
#define PWM3_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0074)
#define PWM3_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0078)
#define PWM4_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0080)
#define PWM4_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0084)
#define PWM4_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0088)
#define PWM4_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x008C)
#define PWM4_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0090)
#define PWM4_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0094)
#define PWM4_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x0098)
#define PWM5_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00A0)
#define PWM5_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00A4)
#define PWM5_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00A8)
#define PWM5_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00AC)
#define PWM5_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00B0)
#define PWM5_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00B4)
#define PWM5_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00B8)
#define PWM6_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00C0)
#define PWM6_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00C4)
#define PWM6_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00C8)
#define PWM6_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00CC)
#define PWM6_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00D0)
#define PWM6_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00D4)
#define PWM6_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00D8)
#define PWM7_CFG_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00E0)
#define PWM7_CFG_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00E4)
#define PWM7_CFG_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00E8)
#define PWM7_CTRL_REG HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00EC)
#define PWM7_STATE_REG0 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00F0)
#define PWM7_STATE_REG1 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00F4)
#define PWM7_STATE_REG2 HI_IO_PWMI_ADDRESS(PWMI_ADRESS_BASE + 0x00F8)
#define PWM_WRITE_REG(Addr, Value) ((*(volatile unsigned int *)(Addr)) = (Value))
#define PWM_READ_REG(Addr) (*(volatile unsigned int *)(Addr))
//PWM
#define PWM_NUM_MAX 0x08
#define PWM_ENABLE 0x01
#define PWM_DISABLE 0x00
#define LED_Red 0
#define LED_Green 1
#define LED_Blue 2
#define LED_Purple 3
#define LED_Yellow 4
#define LED_White 5
#define HI_RED_GPIO_GROUP 1
#define HI_RED_GPIO_INDEX 0
#define HI_GREEN_GPIO_GROUP 1
#define HI_GREEN_GPIO_INDEX 2
#define HI_BLUE_GPIO_GROUP 1
#define HI_BLUE_GPIO_INDEX 3
#define HI_GPIO_BASE 0x12140000
#define HI_GPIO_DIR_OFFSET 0x400
#define HI_GPIO_DIR_IN 0
#define HI_GPIO_DIR_OUT 1
#define HI_GPIO_VAL_LOW 0
#define HI_GPIO_VAL_HIGH 1
#define HI_BIT_SET(addr, bit) ((*(volatile unsigned int *)(addr)) |= (1<<(bit)))
#define HI_BIT_CLR(addr, bit) ((*(volatile unsigned int *)(addr)) &= ~(1<<(bit)))
#define HI_GPIO_DIR(g, r, d) do { \
if ((d) == HI_GPIO_DIR_IN) \
HI_BIT_CLR(HI_GPIO_BASE+((g)<<12)+HI_GPIO_DIR_OFFSET, r); \
else \
HI_BIT_SET(HI_GPIO_BASE+((g)<<12)+HI_GPIO_DIR_OFFSET, r); \
} while(0)
#define HI_GPIO_VAL(g, r, v) do { \
if ((v) == HI_GPIO_VAL_LOW) \
HI_BIT_CLR(HI_GPIO_BASE+((g)<<12)+(1<<((r)+2)), r); \
else \
HI_BIT_SET(HI_GPIO_BASE+((g)<<12)+(1<<((r)+2)), r); \
} while(0)
typedef struct hiLED_RGB_S
{
int led_color; //0:red,1:green,2:blue,3:purple,4:yellow,5:white
} LED_COLOR_S;
typedef enum {
HI_LED_RED = 0,
HI_LED_GREEN = 1,
HI_LED_BLUE = 2,
HI_LED_PURPLE = 3,
HI_LED_YELLOW = 4,
HI_LED_WHITE = 5,
HI_LED_LIGHT_BLUE = 6,
}HI_LED_COLOR;
typedef enum {
LED_CONTROL_PWM = 0,
LED_CONTROL_GPIO = 1,
};
int rgbled_on(HI_LED_COLOR led);
//int rgbled_off(LED_COLOR_S *led);
#endif /* __HI_PWM_LED_H__ */