#ifndef __forcesnsr_CFG_H__
#define __forcesnsr_CFG_H__

#include "forceSnsr.h"
#include "../config/mcal/peripheral/port/plib_port.h"
#include   "../config/mcal/peripheral/sercom/i2c_master/plib_sercom1_i2c_master.h"
/***************************************************************
copyright from private LiuXiao
if you have any question,you can contact me by email 461445092@qq.com
2022-10-05 17:56:24.020233
***************************************************************/


/***************************************************************
Macro Definition and enum define
***************************************************************/

typedef enum
{
	forcesnsr_REG_ID_MAIN_CFG_INDEX = 0x00,
	forcesnsr_REG_ID_CAL_BASELINE_INT_CFG_INDEX ,
	forcesnsr_REG_ID_FALLING_CFG_INDEX ,
	forcesnsr_REG_ID_AD_TEMP_INDEX ,
	forcesnsr_REG_ID_BASELINE_INDEX ,
}forcesnsr_Reg_Id_e_index_typ;





typedef enum
{
	forcesnsr_Tx_CMD = 0x00,
	forcesnsr_Rx_CMD = 0x01,
}forcesnsr_Direction_e_typ;

#define forcesnsr_Max_reg_num  26

/*forcesnsr register default initial value*/
#define forcesnsr_REG_FILL1_VAL  ((STATE_UINT8)0x00)
#define forcesnsr_REG_FILL2_VAL  forcesnsr_REG_FILL1_VAL,forcesnsr_REG_FILL1_VAL
#define forcesnsr_REG_FILL4_VAL  forcesnsr_REG_FILL2_VAL,forcesnsr_REG_FILL2_VAL
#define forcesnsr_REG_FILL6_VAL  forcesnsr_REG_FILL2_VAL,forcesnsr_REG_FILL2_VAL,forcesnsr_REG_FILL2_VAL
#define forcesnsr_REG_FILL8_VAL  forcesnsr_REG_FILL4_VAL,forcesnsr_REG_FILL4_VAL
#define forcesnsr_REG_FILL16_VAL  forcesnsr_REG_FILL8_VAL,forcesnsr_REG_FILL8_VAL

#define forcesnsr_BIT7_ADDR 0x46


/***************************************************************
extern function interface
***************************************************************/


#define forcesnsr_Get_INT_PORT()  PORT_PinRead(PORT_PIN_PB31)

/***************************************************************
struct type define
***************************************************************/



/* APP mssage ID 45B tx */
typedef struct {
	/* Byte0 */
	STATE_UINT8                      EN: 1;/*byte0 - bit0*/
	STATE_UINT8                      TEMPWAIT: 2;
	STATE_UINT8                      ADCRAW: 1;
	STATE_UINT8                      WAIT: 3;
	STATE_UINT8                      TOEN: 1;   /*byte0 - bit7*/
	
	/* Byte1 */
	STATE_UINT8                      PRECHARGE: 3;/*byte1- bit0*/
	STATE_UINT8                      RESERVED_BYTE1_BIT3: 1;
	STATE_UINT8                      INAGAIN: 3;
	STATE_UINT8                      RESERVED_BYTE1_BIT7: 1;
	
	/* Byte2 */
	STATE_UINT8                      INTR: 1;/*byte2- bit0*/
	STATE_UINT8                      SNSERR: 1;
	STATE_UINT8                      OVRACALTH: 1;
	STATE_UINT8                      OVRINTRTH: 1;
	STATE_UINT8                      RESERVED_BYTE2_BIT4_6:3;
	STATE_UINT8                      BUSY: 1;

	
	/* Byte3 */
	STATE_UINT8                      ADCOUT_H: 8;/*byte3- bit0*/

	/* Byte4 */
	STATE_UINT8                      SCOUNT :4;
	STATE_UINT8                      ADCOUT_L :4;/*byte4- bit0*/
	
	/* Byte5 */
	STATE_UINT8                      TEMP_H:  8;/*byte5- bit0*/

	/* Byte6 */
	STATE_UINT8                      RESERVED_BYTE6_BIT0_3:4;
	STATE_UINT8                      TEMP_L:  4;
	
	/* Byte7 */
	STATE_UINT8                      AUTOCAL_H:  8;

	/* Byte8 */
	STATE_UINT8                      RESERVED_BYTE7_BIT0:  1;
	STATE_UINT8                      AUTOPRELDAD:  1;
	STATE_UINT8                      RESERVED_BYTE7_BIT2_3:  2;
	STATE_UINT8                      AUTOCAL_L:  4;

	/* Byte9 */
	STATE_UINT8                      CALPERIOD:  3;
	STATE_UINT8                      INTRPOL:  1;
	STATE_UINT8                      CALRESET:  3;
	STATE_UINT8                      ENCALMODE:  1;

	/* ByteA */
	STATE_UINT8                      LIFTDELAY:  3;
	STATE_UINT8                      RESERVED_BYTEA_BIT3:  1;
	STATE_UINT8                      RISEBLWGT:  3;
	STATE_UINT8                      RESERVED_BYTEA_BIT7:  1;

	/* ByteB */
	STATE_UINT8                      FALLBLWGT:  3;
	STATE_UINT8                      PRELDADJ:  5;

	/* ByteC */
	STATE_UINT8                      INTRTHR_H:  8;

	/* ByteD */
	STATE_UINT8                      FALLTHRSEL:  3;
	STATE_UINT8                      RESERVED_BYTED_BIT3:  1;
	STATE_UINT8                      INTRTHR_L:  4;

	/* ByteE */
	STATE_UINT8                      INTRSAMPLE:  3;
	STATE_UINT8                      RESERVED_BYTEE_BIT3:  1;
	STATE_UINT8                      BTNMODE:  1;
	STATE_UINT8                      INTRPERSIST:  1;
	STATE_UINT8                      INTRMODE:  1;
	STATE_UINT8                      INTREN:  1;

	/* ByteF */
	STATE_UINT8                      FORCEBL:  1;
	STATE_UINT8                      RESERVED_BYTEF_BIT1_3:  3;
	STATE_UINT8                      PWRMODE:  4;

	/* Byte0x10 */
	STATE_UINT8                      ADCMAX_H:  8;

	/* Byte0x11 */
	STATE_UINT8                      RESERVED_BYTE11_BIT0_3:  4;
	STATE_UINT8                      ADCMAX_L:  4;

	/* Byte0x12 */
	STATE_UINT8                      BASELINE_H:  8;

	/* Byte0x13 */
	STATE_UINT8                      RESERVED_BYTE13_BIT0_3:  4;
	STATE_UINT8                      BASELINE_L:  4;


	/* Byte0x14 */
	STATE_UINT8                      ADCFIFO_H:  8;

	/* Byte0x15 */
	STATE_UINT8                      FCOUNT:  4;
	STATE_UINT8                      ADCFIFO_L:  4;
	
	/* Byte0x16 */
	STATE_UINT8                      FALLTHR_H:  8;

	/* Byte0x17 */
	STATE_UINT8                      RESERVED_BYTE17_BIT0_3:  4;
	STATE_UINT8                      FALLTHR_L:  4;

	/* Byte0x18 */
	STATE_UINT8                      VERSION:  8;

	/* Byte0x19 */
	STATE_UINT8                      TEMPSNSBL:  8;
	
}_forcesnsr_RxReg_Str_Type;

typedef union {
	STATE_UINT8   reg_grp[forcesnsr_Max_reg_num];
	_forcesnsr_RxReg_Str_Type	forcesnsr_RxReg;
}forcesnsr_RxReg_un_type;


typedef struct
{
	STATE_UINT8 cmd_direction;
	STATE_UINT8 cmd_id;
	STATE_UINT8 cmd_len;
	STATE_UINT8 * cmd_data;
	STATE_UINT8  default_state[16];
}forcesnsr_Reg_Cfg_Main_Str_typ;


/***************************************************************
extern  variable
***************************************************************/

extern forcesnsr_RxReg_un_type forcesnsr_reg_state_grp;
extern const forcesnsr_Reg_Cfg_Main_Str_typ  forcesnsr_Main_Cfg_Tbl[];



#endif
