#ifndef __IKONKE_MODULE_PWM_H_______________________________
#define __IKONKE_MODULE_PWM_H_______________________________

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

#define PWM_OBJS_SUPPORT_MAXN			6

#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!
/**********************************************************************
 * LOCAL CONSTANTS
 */
#define PWM_FREQUENCY					1000	//1KHz
#define PWM_FULL_DUTYCYCLE				100
#define PMW_MAX_TICK		            (PWM_CLOCK_SOURCE / PWM_FREQUENCY)

#define PWM_TIMER_MAX_DUTY_CYCLE_NUM 	65535
#define PWM_TIMER_MID_DUTY_CYCLE_NUM 	500
#define PWM_TIMER_MIN_DUTY_CYCLE_NUM 	0

typedef enum {ELP_MIN = 0, ELP_MID,ELP_ANY, ELP_MAX, ELP_TO_BRIGHT/* min to max */, ELP_TO_DARKEN/* max to min */, ELP_OPT_DEFAULT=0xff }PwmGradientDirectionEnum;
typedef enum {KK_PWM_CC0=0, KK_PWM_CC1, KK_PWM_CC2,KK_PWM_CC3,KK_PWM_CC4,KK_PWM_CC5}PwmChannelEnum;
typedef enum {KTIMER0=0, KTIMER1}TIMER_ENUM;




#define PWM_TLSR8258_INFO_INIT      	{{KK_PWM_CC0, {{AS_PWM0,4,GPIO_PA2,GPIO_PC1,GPIO_PC2,GPIO_PD5},{AS_PWM0_N,4,GPIO_PA0,GPIO_PB3,GPIO_PC4,GPIO_PD5}}}, \
                                    	{KK_PWM_CC1, {{AS_PWM1,2,GPIO_PA3,GPIO_PC3,PIN_UNKNOW,PIN_UNKNOW},{AS_PWM1_N,2,GPIO_PC1,GPIO_PD3,PIN_UNKNOW,PIN_UNKNOW}}}, \
                                    	{KK_PWM_CC2, {{AS_PWM2,2,GPIO_PA4,GPIO_PC4,PIN_UNKNOW,PIN_UNKNOW},{AS_PWM2_N,1,GPIO_PD4,PIN_UNKNOW,PIN_UNKNOW,PIN_UNKNOW}}}, \
                                    	{KK_PWM_CC3, {{AS_PWM3,2,GPIO_PB0,GPIO_PD2,PIN_UNKNOW,PIN_UNKNOW},{AS_PWM3_N,1,GPIO_PC5,PIN_UNKNOW,PIN_UNKNOW,PIN_UNKNOW}}}, \
                                    	{KK_PWM_CC4, {{AS_PWM4,2,GPIO_PB1,GPIO_PB4,PIN_UNKNOW,PIN_UNKNOW},{AS_PWM4_N,2,GPIO_PC0,GPIO_PC6,PIN_UNKNOW,PIN_UNKNOW}}}, \
                                    	{KK_PWM_CC5, {{AS_PWM5,2,GPIO_PB2,GPIO_PB5,PIN_UNKNOW,PIN_UNKNOW},{AS_PWM5_N,1,GPIO_PC7,PIN_UNKNOW,PIN_UNKNOW,PIN_UNKNOW}}},\
										}


typedef struct {
	GPIO_FuncTypeDef 	Pin_Funs;
	uint8_t 			vaild_num;
	GPIO_PinTypeDef 	pin[4];
}PwmSupportGPIOList;

typedef struct {
	PwmChannelEnum pwmChannel;
	PwmSupportGPIOList gpioinfo[2];
}PwmGpioListSt;

typedef struct {
	uint32_t pin;
	PwmChannelEnum pwmChannel;
}PwmGpioSt;

// led configuration struct
typedef struct tag_pwm_config_st {
	unsigned char u8PwmId; 	// 0 ~ 254
	PwmGpioSt gpioInfo;
}PwmConfSt;

//funtion callback when pwm duty cycle is changed to max or min
typedef void (*pPwmActionDoneCallback)(unsigned char id, PwmGradientDirectionEnum opt);

/*	DESP: get the pwm index by led_id.
 * 	Auth: maozj.20200211.
 * */
uint8_t kPwmGetIndexByID(uint8_t pwm_id );
/*	DESP: Check whether all pwm have stopped action detection.
 * 	Auth: maozj.20200211.
 * */
bool kPwmGradientChangeIsGoing(void);

/*	DESP: Check if the specified pwm  is changing.
 * 	Auth: maozj.20200211.
 * */
bool kPwmIsChanging(uint8_t pwm_id );
/*	DESP: registration the system pwm driver processing function interface.
	Auth: maozj.20200211.
*/
void kPwmDriverhandler(uint8_t pwm_index, PwmGradientDirectionEnum st, uint16_t value);

/*	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 kPwmModuleInit(PwmConfSt pwmlist[], unsigned char pwm_number, pPwmActionDoneCallback pCallback);

/*	DESP: Indicator lamp behavior control interface.
	Auth: dingmz_frc.20191108.
*/
void kPwmOptTrigger(uint8_t id, uint32_t start_value, uint32_t end_value, uint32_t duration_time );

bool kPwmClearGradientCounterById(uint8_t pwm_id);

void PWM_Test(uint8_t data);





#endif

