#ifndef _IKK_LED_H_
#define _IKK_LED_H_

#include "../general/ikk-module-def.h"


#define LED_OBJS_SUPPORT_MAXN	8
// the number of physical gpios that can be mapped for a single LED control instance!
#define LED_GPIO_MAPPING_MAXN	4

#define LED_UNUSED_ID			0
#define LED_ALLOPT_ID			255	// Valid[1,254], 255 for Operate all at the same time!

#define PWM_UNKNOW_ID					0	// Valid[1,254], 255 for Operate all at the same time!
#define PWM_ALLOPT_ID					255	// Valid[1,254], 255 for Operate all at the same time!

#define LED_UNKNOW_ID			0	// Valid[1,254], 255 for Operate all at the same time!
#define LED_ALLOPT_ID			255	// Valid[1,254], 255 for Operate all at the same time!

#define BLINK_DEAD				0xffffffff
#define BLINK_NONE				0x0

// LED STATUS
typedef enum { LED_OFF = 0,	LED_ON = 1,	LED_TOGGLE, LED_IGNORE = 2 }LedOptEnum;
typedef enum { ELP_LOW = 0/* low to on */, ELP_HIGH/* high to on */ }LedPolarityEnum;

typedef struct {
	uint32_t pin;
	uint8_t pwmId; //0 :not use pwm
}LedGpioListSt;

// led configuration struct
typedef struct tag_led_config_st {
	uint8_t u8LedId; 	// 0 ~ 254

	uint8_t u8GpioMappNum;
	LedGpioListSt gpios[LED_GPIO_MAPPING_MAXN];

	LedPolarityEnum eActionPolarity;
	//uint8_t pwmIds[LED_GPIO_MAPPING_MAXN]; //band pwm id
}LedConfSt;
typedef struct tag_led_controller_st {
	uint32_t onCounter;
	uint32_t onDuration;
	uint32_t offCounter;
	uint32_t offDuration;
	uint32_t blink_cnt;

	LedOptEnum start;
	LedOptEnum end;
}ST_LedCtrller;
typedef void (*pLedActionDoneCallback)(unsigned char id);

/*	DESP: Indicator lamp behavior control interface.
	Auth: dingmz_frc.20191108.
*/
void kLedOptTrigger(uint8_t id, uint32_t duration_on_ms, uint32_t duration_off_ms, uint32_t times, LedOptEnum start, LedOptEnum end );
/*	DESP: Toggle LED
	Auth: maozj.20200226.
*/
void kLedOptToggle(uint8_t id);

void Set_GPIO_OutPut(uint32_t pin,bool value);

// Turn ON
#define LED_OPT_ON(id)	do { \
	kLedOptTrigger(id, 0, 0, 0, LED_ON, LED_IGNORE); \
}while(0)

// Turn OFF
#define LED_OPT_OFF(id)	do { \
	kLedOptTrigger(id, 0, 0, 0, LED_OFF, LED_IGNORE); \
}while(0)

// Turn TOGGLE add by maozj 20200226
#define LED_OPT_TOGGLE(id)	do { \
		kLedOptToggle(id); \
}while(0)

#define GPIO_OUTPUT_SET(pin,value)  do{ \
										drv_gpio_func_set(pin); \
										drv_gpio_output_en(pin, 1); 	\
										drv_gpio_input_en(pin, 0);	\
										drv_gpio_write(pin, value); \
									}while(0);

#define GPIO_OUTPUT_TOGGLE(pin)  do{ \
										drv_gpio_func_set(pin); \
										drv_gpio_output_en(pin, 1); 	\
										drv_gpio_input_en(pin, 0);	\
										gpio_toggle(pin); \
									}while(0);
#define GPIO_INPUT_SET(pin,value)  do{ \
										drv_gpio_func_set(pin); \
										drv_gpio_output_en(pin, 0); 	\
										drv_gpio_input_en(pin, 1);	\
										drv_gpio_write(pin, value); \
									}while(0);


/*	DESP: Check if the specified led indicator is bliking.
 * 	Auth: dingmz_frc.20191108.
 * */
bool kLedIsBlinking(uint8_t led_id );
/*	DESP: single LED instance register interface.
 * 	Auth: dingmz_frc.20191108.
 * */
kk_err_t kLedRegister(uint8_t id, uint8_t gpio_num, LedGpioListSt gpio_list[], LedPolarityEnum ePolarity);
/*	DESP: led control module Initialize configuration interface.
 * 	Note: Led initialization interface supports one-time registration of multiple LEDs!
 * 	Auth: dingmz_frc.20191108.
 * */
kk_err_t kLedModuleInit(LedConfSt *ledlist, unsigned char led_number, pLedActionDoneCallback pCallback);
/*	DESP: led control module Initialize modify by led id.
 * 	Note: Led initialization interface
 * 	Auth: maozj.20191226.
 * */
kk_err_t kLedModuleInfoModifyGpioById(uint8_t id, LedConfSt ledconf);








void Key_test(void);
#endif /* _SAMPLE_LIGHT_H_ */
