#ifndef __SN32F700B_CMP_H
#define __SN32F700B_CMP_H

/*_____ I N C L U D E S ____________________________________________________*/
#include <SN32F700B.h>
#include <SN32F700_Def.h>


/*_____ D E F I N I T I O N S ______________________________________________*/
//CM0PREF, CM1PREF
#define	CMP_VPREF_CMnP						1
#define	CMP_VPREF_VIREFn					0
#define	mskCMP_CM0PREF_CM0P				(CMP_VPREF_CMnP<<1)
#define	mskCMP_CM0PREF_VIREF0			(CMP_VPREF_VIREFn<<1)
#define	mskCMP_CM1PREF_CM1P				(CMP_VPREF_CMnP<<9)
#define	mskCMP_CM1PREF_VIREF1			(CMP_VPREF_VIREFn<<9)

//CM0RS
#define	mskCMP_CM0RS_VIREF				(0<<2)
#define	mskCMP_CM0RS_VIREF_M01D16	(1<<2)
#define	mskCMP_CM0RS_VIREF_M02D16	(2<<2)
#define	mskCMP_CM0RS_VIREF_M03D16	(3<<2)
#define	mskCMP_CM0RS_VIREF_M04D16	(4<<2)
#define	mskCMP_CM0RS_VIREF_M05D16	(5<<2)
#define	mskCMP_CM0RS_VIREF_M06D16	(6<<2)
#define	mskCMP_CM0RS_VIREF_M07D16	(7<<2)
#define	mskCMP_CM0RS_VIREF_M08D16	(8<<2)
#define	mskCMP_CM0RS_VIREF_M09D16	(9<<2)
#define	mskCMP_CM0RS_VIREF_M10D16	(10<<2)
#define	mskCMP_CM0RS_VIREF_M11D16	(11<<2)
#define	mskCMP_CM0RS_VIREF_M12D16	(12<<2)
#define	mskCMP_CM0RS_VIREF_M13D16	(13<<2)
#define	mskCMP_CM0RS_VIREF_M14D16	(14<<2)
#define	mskCMP_CM0RS_VIREF_M15D16	(15<<2)

//CM0OEN, CM1OEN
#define	CMP_CMnO_DISABLE					0
#define	CMP_CMnO_ENABLE						1
#define	mskCMP_CM0OEN_DISABLE			(CMP_CMnO_DISABLE<<6)
#define	mskCMP_CM0OEN_ENABLE			(CMP_CMnO_ENABLE<<6)
#define	mskCMP_CM1OEN_DISABLE			(CMP_CMnO_DISABLE<<14)
#define	mskCMP_CM1OEN_ENABLE			(CMP_CMnO_ENABLE<<14)

//CM0G, CM1G
#define	CMP_CMnG_FALLING					0
#define	CMP_CMnG_RISING						1
#define	mskCMP_CM0G_FALLING				(CMP_CMnG_FALLING<<7)
#define	mskCMP_CM0G_RISING				(CMP_CMnG_RISING<<7)
#define	mskCMP_CM1G_FALLING				(CMP_CMnG_FALLING<<15)
#define	mskCMP_CM1G_RISING				(CMP_CMnG_RISING<<15)


//CM1RS
#define	mskCMP_CM1RS_VIREF				(0<<10)
#define	mskCMP_CM1RS_VIREF_M01D16	(1<<10)
#define	mskCMP_CM1RS_VIREF_M02D16	(2<<10)
#define	mskCMP_CM1RS_VIREF_M03D16	(3<<10)
#define	mskCMP_CM1RS_VIREF_M04D16	(4<<10)
#define	mskCMP_CM1RS_VIREF_M05D16	(5<<10)
#define	mskCMP_CM1RS_VIREF_M06D16	(6<<10)
#define	mskCMP_CM1RS_VIREF_M07D16	(7<<10)
#define	mskCMP_CM1RS_VIREF_M08D16	(8<<10)
#define	mskCMP_CM1RS_VIREF_M09D16	(9<<10)
#define	mskCMP_CM1RS_VIREF_M10D16	(10<<10)
#define	mskCMP_CM1RS_VIREF_M11D16	(11<<10)
#define	mskCMP_CM1RS_VIREF_M12D16	(12<<10)
#define	mskCMP_CM1RS_VIREF_M13D16	(13<<10)
#define	mskCMP_CM1RS_VIREF_M14D16	(14<<10)
#define	mskCMP_CM1RS_VIREF_M15D16	(15<<10)

//CMPIREF
#define	CMP_IREF_VDD							0
#define	CMP_IREF_3V								1
#define	mskCMP_CMPIREF_VDD				(CMP_IREF_VDD<<1)
#define	mskCMP_CMPIREF_3V					(CMP_IREF_3V<<1)
#define	mskCMP_CMPIREFEN_DISABLE	(DISBALE<<0)
#define	mskCMP_CMPIREFEN_ENABLE		(ENABLE<<0)

//CM0IE, CM1IE
#define	mskCMP_CM0IE_DISABLE			(DISABLE<<0)
#define	mskCMP_CM0IE_ENABLE				(ENABLE<<0)
#define	mskCMP_CM1IE_DISABLE			(DISABLE<<1)
#define	mskCMP_CM1IE_ENABLE				(ENABLE<<1)

//CM0IC, CM1IC
#define	mskCMP_CM0IC_ENABLE				(ENABLE<<0)
#define	mskCMP_CM1IC_ENABLE				(ENABLE<<1)


/*_____ M A C R O S ________________________________________________________*/

//CMP HCLK Enable/Disable
#define	__CMP_ENABLE_CMPHCLK					SN_SYS1->AHBCLKEN_b.CMPCLKEN = 1;
#define	__CMP_DISABLE_CMPHCLK					SN_SYS1->AHBCLKEN_b.CMPCLKEN = 0;

//CMP0/1 Enable/Disable
#define	__CMP0_ENABLE									SN_CMP->CTRL_b.CM0EN = 1;
#define	__CMP0_DISABLE								SN_CMP->CTRL_b.CM0EN = 0;
#define	__CMP1_ENABLE									SN_CMP->CTRL_b.CM1EN = 1;
#define	__CMP1_DISABLE								SN_CMP->CTRL_b.CM1EN = 0;


/*_____ D E C L A R A T I O N S ____________________________________________*/

void CMP_init(void);
void CMP_VIREF_Enable(uint32_t VIREF);



#endif	/*__SN32F700B_CMP_H*/
