
#ifndef __FUNCS_H__
#define __FUNCS_H__

#include "config.h"

//------------------------------------------------------------

#define	ALM_LIT_STA_OFF		0	// 关闭状态
#define	ALM_LIT_STA_ON		1	// 打开状态

#define	ALM_LIT_OFF			0	// 关灯
#define	ALM_LIT_ON			1	// 开灯
#define	ALM_LIT_FLASH		2	// 闪烁
#define	ALM_LIT_FLASH_FAST	3	// 快速闪烁
#define	ALM_LIT_FLASH_SLOW	4	// 慢速闪烁

#define	FLASH_LIGHT(flag, sta, onfunc, offfunc)		do \
{\
	if (flag == ALM_LIT_OFF)\
	{\
		if (sta != ALM_LIT_STA_OFF)\
		{\
			sta = ALM_LIT_STA_OFF;\
			offfunc();\
		}\
	}\
	else if (flag == ALM_LIT_ON)\
	{\
		if (sta != ALM_LIT_STA_ON)\
		{\
			sta = ALM_LIT_STA_ON;\
			onfunc();\
		}\
	}\
	else if (flag == ALM_LIT_FLASH || flag == ALM_LIT_FLASH_FAST || flag == ALM_LIT_FLASH_SLOW)\
	{\
		if (sta == ALM_LIT_STA_ON)\
		{\
			sta = ALM_LIT_STA_OFF;\
			offfunc();\
		}\
		else if (sta == ALM_LIT_STA_OFF)\
		{\
			sta = ALM_LIT_STA_ON;\
			onfunc();\
		}\
		else \
		{\
			sta = ALM_LIT_STA_OFF;\
		}\
	}\
	else \
	{\
		flag = ALM_LIT_OFF;\
	}\
}while(0)


//------------------------------------------------------------

#define OUTPUT_FUNCS(Name, LABEL)	\
void Set##Name##On(void) \
{ \
	LL_GPIO_ResetOutputPin(LABEL##_GPIO_Port, LABEL##_Pin); \
} \
void Set##Name##Off(void)\
{ \
	LL_GPIO_SetOutputPin(LABEL##_GPIO_Port, LABEL##_Pin); \
} \
void Set##Name##Toggle(void) \
{ \
	LL_GPIO_TogglePin(LABEL##_GPIO_Port, LABEL##_Pin); \
} \
u8 Get##Name##Status(void) \
{ \
	return LL_GPIO_IsOutputPinSet(LABEL##_GPIO_Port, LABEL##_Pin); \
} \

//------------------------------------------------------------

#define INPUT_FUNCS(Name, LABEL)	\
u8 Get##Name##Status(void)\
{\
	return LL_GPIO_IsInputPinSet(LABEL##_GPIO_Port, LABEL##_Pin);\
}

//------------------------------------------------------------


//------------------------------------------------------------
#define OUTPUT_NULL_FUNCS(Name, LABEL)	\
void Set##Name##On(void) \
{ \
	SetOutputNull(); \
} \
void Set##Name##Off(void)\
{ \
	SetOutputNull(); \
} \
void Set##Name##Toggle(void) \
{ \
	SetOutputNull(); \
} \
u8 Get##Name##Status(void) \
{ \
	return GetInputNullOff(); \
} \

//------------------------------------------------------------
#define INPUT_NULL_FUNCS(Name, LABEL)	\
u8 Get##Name##Status(void)\
{\
	return GetInputNullOff(); \
}

//------------------------------------------------------------

#endif
