/********************************************************************************
*
*  File name:   FrntWiperCtrl.h
*
*********************************************************************************/
#ifndef __FRNTWIPERCTRL_H__
#define __FRNTWIPERCTRL_H__

/*********************************************************************************
*    Includes
*********************************************************************************/

/*********************************************************************************
*   Global Macros
*********************************************************************************/
/* Front Wiper Mode */
#define FWIPER_MODE_OFF			0x00
#define FWIPER_MODE_LOW			0x01
#define FWIPER_MODE_HIGH		0x02
#define FWIPER_MODE_MIST		0x03
#define FWIPER_MODE_INT			0x04
#define FWIPER_MODE_RESV1		0x05
#define FWIPER_MODE_RESV2		0x06
#define FWIPER_MODE_INVALID		0x07
#define FWIPER_MODE_RESET		0xFF

#define WIPER_SPEED_OFF			0x02
#define WIPER_SPEED_LOW			0x03
#define WIPER_SPEED_HIGH		0x04

#define WIPER_POS_HOME			0x00	/* WIPER position : home position */
#define WIPER_POS_AWAY			0x01	/* WIPER position : away from home position */

#define FWIPER_STS_OFF			0x00
#define FWIPER_STS_LOW			0x01
#define FWIPER_STS_HIGH			0x02
#define FWIPER_STS_MIST			0x03
#define FWIPER_STS_INT			0x04
#define FWIPER_STS_AUTO			0x05

/*********************************************************************************
*   Global Struct
*********************************************************************************/
/* Front Wiper State */
typedef union
{
	uint8_t Byte;
	struct
	{
		uint8_t Resv :5;
		uint8_t Blocked :1; /* Wiper blocked Flag */
		uint8_t Washer :1; /* Washer Working Flag */
		uint8_t WashSw :1; /* Washer Swtich Sts */
	} Bits;
} FWIPER_FLAG_UNION;

/* Input Output Control Flag */
typedef union
{
	uint8_t Byte;
	struct
	{
		uint8_t IOCtlFlg :1;
		uint8_t HighOn :1;
		uint8_t LowOn :1;
		uint8_t HighOff :1;
		uint8_t LowOff :1;
		uint8_t Resv2 :1;
		uint8_t Resv3 :1;
		uint8_t Resv4 :1;
	} Bits;
} FWIPER_IO_CTL_UNION;

typedef enum
{
	INT_STEP_START = 0x00,
	INT_STEP_CHK_AWAY,
	INT_STEP_CHK_BACK,
	INT_STEP_WAIT_MORE, /* Run More time while Arrived Home Position */
	INT_STEP_WAIT_DLY,
} FWIPER_INT_STEP_ENUM;

/* Fwiper Auto Control Step  */
typedef enum
{
	AUTO_STEP_START = 0x00,
	AUTO_STEP_CHK_AWAY,
	AUTO_STEP_CHK_BACK,
	AUTO_STEP_CHK_RLS, /* Delay and Check RainSensor */
	AUTO_STEP_AUTO_CHK,
	AUTO_STEP_AUTO_AWAY,
	AUTO_STEP_AUTO_BACK,
} FWIPER_AUTO_STEP_ENUM;

typedef enum
{
	OFF_STEP_START = 0x00,
	OFF_STEP_WAIT_AWAY,
	OFF_STEP_CHK_BACK,
	OFF_STEP_WAIT_MORE,
	OFF_STEP_IDLE,
} FWIPER_OFF_STEP_ENUM;

/* Washer Control Step */
typedef enum
{
	WASHER_STEP_START = 0x00,
	WASHER_STEP_CHK_AWAY,
	WASHER_STEP_CHK_BACK,
	WASHER_STEP_EXTRA_AWAY,
	WASHER_STEP_EXTRA_BACK,
	WASHER_STEP_WAIT_DLY,
	WASHER_STEP_LAST_AWAY,
	WASHER_STEP_LAST_BACK,
	WASHER_STEP_LAST_WAIT,
} FWASHER_STEP_ENUM;

typedef enum /*Maintain Mode Control Step */
{
	MTMD_STEP_START = 0x00,
	MTMD_STEP_WAIT_BACK,
	MTMD_STEP_CHK_AWAY,
	MTMD_STEP_CHK_DLY,
	MTMD_STEP_WAIT,
} FWIPER_MAINTAIN_STEP_ENUM;

/*********************************************************************************
*   Global Variables
*********************************************************************************/

/*********************************************************************************
*   Global Functions
*********************************************************************************/
extern void FrntWiper_Init(void);
extern void FrntWiper_MainFunction(void);
extern void Fwiper_DrvSet(uint8_t Speed);

#endif // __FRNTWIPERCTRL_H__
