#ifndef __ADS8688_H__
#define __ADS8688_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stdint.h"

//command register map
//only care about high 8 bits
#define NO_OP		0x0000 
#define STDBY		0x8200 
#define PWR_DN  	0x8300 
#define RST			0x8500 
#define AUTO_RST	0xA000 
#define MAN_Ch_0	0xC000 
#define MAN_CH_1	0xC400 
#define MAN_Ch_2	0xC800 
#define MAN_Ch_3	0xCC00 
#define MAN_Ch_4	0xD000 
#define MAN_Ch_5	0xD400 
#define MAN_Ch_6	0xD800 
#define MAN_Ch_7	0xDC00 
#define MAN_AUX		0xE000


//program register map
//format : 15~9     8       7~0
//         addr     W/R     DATA
//register bit15 ~ 9
#define AUTO_SEQ_EN				    0x01
#define Channel_Power_Down		    0x02 

#define Feature_Select			    0x03

#define Channel_0_Input_Range		0x05  
#define Channel_1_Input_Range		0x06 
#define Channel_2_Input_Range		0x07 
#define Channel_3_Input_Range		0x08 
#define Channel_4_Input_Range		0x09 
#define Channel_5_Input_Range		0x0A 
#define Channel_6_Input_Range		0x0B 
#define Channel_7_Input_Range		0x0C

#define Ch_0_Hysteresis				0x15 
#define Ch_0_High_Threshold_MSB		0x16 
#define Ch_0_High_Threshold_LSB		0x17 
#define Ch_0_Low_Threshold_MSB		0x18 
#define Ch_0_Low_Threshold_LSB		0x19 
 
#define Ch_7_Hysteresis				0x38 
#define Ch_7_High_Threshold_MSB		0x39 
#define Ch_7_High_Threshold_LSB		0x3A 
#define Ch_7_Low_Threshold_MSB		0x3B 
#define Ch_7_Low_Threshold_LSB		0x3C 
 
#define Command_Read_Back		    0x3F

//register bit8
#define WRITE		1
#define READ 		0

//register AUTO_SEQ_EN bit7 ~ 0
//default value is FFh(bit7~0 all selected)
#define CH7_EN      0x80
#define CH6_EN      0x40
#define CH5_EN      0x20
#define CH4_EN      0x10
#define CH3_EN      0x08
#define CH2_EN      0x04
#define CH1_EN      0x02
#define CH0_EN      0x01 

//register Channel_Power_Down bit7 ~ 0
//default value is 00h(bit7~0 all powered up)
#define CH7_PD      0x80
#define CH6_PD      0x40
#define CH5_PD      0x20
#define CH4_PD      0x10
#define CH3_PD      0x08
#define CH2_PD      0x04
#define CH1_PD      0x02
#define CH0_PD      0x01

//register Channel_x_Input_Range bit7 ~ 3 is 00000
//register Channel_x_Input_Range bit2 ~ 0
#define VREF_B_25           0x00	//channel range:±2.5×VREF = ±10.24V
#define VREF_B_125		    0x01	//channel range:±1.25×VREF = ±5.12V
#define VREF_B_0625  		0x02	//channel range:±0.625×VREF = ±2.56V
#define VREF_U_0_25			0x05	//channel range:0~2.5×VREF = 0~10.24V
#define VREF_U_0_125		0x06	//channel range:0~1.25×VREF = 0~5.12V

#endif /* __ADS8688_H__ */