/*
 * ADBMS_CMD_MAKROS.h
 *
 *  Created on: 14.07.2022
 *      Author: max
 */

#ifndef INC_ADBMS_CMD_MAKROS_H_
#define INC_ADBMS_CMD_MAKROS_H_

#define WRCFGA 0x0001 //Write Configuration Register Group A
#define RDCFGA 0x0002 //Read Configuration Register Group A
#define WRCFGB 0x0024 //Write Configuration Register Group B
#define RDCFGB 0x0026 //Read Configuration Register Group B

#define RDCVA 0x0004 //Read Cell Voltage Register Group A
#define RDCVB 0x0006 //Read Cell Voltage Register Group B
#define RDCVC 0x0008 //Read Cell Voltage Register Group C
#define RDCVD 0x000A //Read Cell Voltage Register Group D
#define RDCVE 0x0009 //Read Cell Voltage Register Group E
#define RDCVF 0x000B //Read Cell Voltage Register Group F

#define RDAUXA 0x000C //Read Auxilliary Register Group A
#define RDAUXB 0x000E //Read Auxilliary Register Group B
#define RDAUXC 0x000D //Read Auxilliary Register Group C
#define RDAUXD 0x000F //Read Auxilliary Register Group D

#define RDSTATA 0x0010//Read Status Register Group A
#define RDSTATB 0x0012//Read Status Register Group B

#define WRSCTRL 0x0014 //Write S Control Register Group
#define WRPWM  0x0020//Write PWM Register Group
#define WRPSB 0x001A //Write PWM/S Control Register Group
#define RDSCTRL 0x0016 //Read S Control Register Group
#define RDPWM 0x0022//Read PWM Register Group
#define RDPSB 0x001E //Read PWM/S Control Register Group B
#define STSCTRL 0x0019 //Start S Control Pulsing and Poll Status
#define CLRSCTRL 0x0018 //Clear S Control Register Group

#define ADCV 0x0260 //Start Cell Voltage Conversion
#define ADOW 0x0228 //Start Open Wire ADC Conversion and Poll Status
#define CVST 0x0207//Start Self Test Cell Voltage Conversion and Poll Status
#define ADOL 0x201//Start Overlap Measurement of Cell 7 and 13 Voltages
#define ADAX 0x460 //Start GPIOs ADC Conversion and Poll Status
#define ADAXD 0x400 //Start GPIOs ADC Conversion with Digital Redundancy and Poll Status
#define AXOW 0x410 //Start GPIOs Open Wire ADC Conversion and Poll Status
#define AXST 0x407 //Start Self Test GPIOs Conversion and Poll Status
#define ADSTAT 0x468 //Start Status Group ADC Conversion and Poll Status
#define ADSTATD 0x408//Start Status Group ADC Conversion with Digital Redundany and Poll Status
#define STATST 0x40F //Start Self Test Status Group Conversion and Poll Status
#define ADCVAX 0x46F//Start Combiinden Cell Voltage and GPIO 1, GPIO2, Conversion and Poll Status
#define ADCVSC 0x467//Start Combined Cell Voltage and SC Conversion and Poll Status

#define CLRCELL 0x711//Clear Cell Voltage Register Groups
#define CLRAUX 0x712//Clear Auxiliary Register Groups
#define CLRSTAT 0x713//Clear Status Register Groups
#define PLADC 0x714//Poll ADC Conversion Status
#define DIAGN 0x715//Diagnos MUX and Poll Status
#define WRCOMM 0x721//Write COMM Register Group
#define RDCOMM 0x722//Read COMM Register Group
#define STCOMM 0x723//Start I2C/SPI Communication
#define MUTE 0x28//Mute Discharge
#define UNMUTE 0x29//Unmute Discharge


/*ADC Modes
 * ADCOPT(CFGAR0,Bit 0) = 0		ADCOPT(CFGAR0,Bit 0) = 1
 * 00 422Hz mode				1kHz mode
 * 01 27kHz mode (fast)			14kHz mode
 * 10 7kHz mode (normal)		3kHz mode
 * 11 26Hz mode (filtered)		2kHz mode
 */
#define MD00 (0x00<<7)
#define MD01 (0x01<<7)
#define MD10 (0x02<<7)
#define MD11 (0x03<<7)

//Discharge Permitted if DCP = 1
#define DCP (0x01<<4)

/*Cell Selection for ADC Conversion
 * 000:	All Cells
 * 001: Cells 1,7,13
 * 010: Cells 2,8,14
 * 011: Cells 3,9,15
 * 100: Cells 4,10,16
 * 101: Cells 5,11,17
 * 110: Cells 6,12,18
 */
#define CH000 (0x00)
#define CH001 (0x01)
#define CH010 (0x02)
#define CH011 (0x03)
#define CH100 (0x04)
#define CH101 (0x05)
#define CH110 (0x06)


/* Pull-Up/Pull-Down Current for Open Wire Conversion
 * 0 Pull down current
 * 1 Pull up current
 */
#define PUP (0x01<<6)


/*Self Test Mode Selection
 * ST01 for Self Test 1
 * ST02 for Self Test 2
 * for value consultate Datasheet
 */
#define ST01 (0x01<<5)
#define ST10 (0x02<<5)

/* GPIO Selection for ADC Converion
 * 000: GPIO1 to 5, 2nd Reference, GPIO 6 to 9
 * 001: GPIO1 and GPIO6
 * 010 GPIO2 and GPIO7
 * 011 GPIO3 and GPIO8
 * 100 GPIO4 and GPIO9
 * 101 GPIO5
 * 110 2nd Reference
 */

#define CHG000 (0x00)
#define CHG001 (0x01)
#define CHG010 (0x02)
#define CHG011 (0x03)
#define CHG100 (0x04)
#define CHG101 (0x05)
#define CHG110 (0x06)

/* Status Group Selection
 * 000: SC,ITMP,VA,VD
 * 001: SC
 * 010: ITMP
 * 011: VA
 * 100: VD
 */

#define CHST000 (0x00)
#define CHST001 (0x01)
#define CHST010 (0x02)
#define CHST011 (0x03)
#define CHST100 (0x04)

#define PEC_FIELD_SIZE 2

#define CFG_GROUP_A_SIZE 6
#define CFG_GROUP_B_SIZE 6
#define CV_GROUP_A_SIZE 6
#define CV_GROUP_B_SIZE 6
#define CV_GROUP_C_SIZE 6
#define CV_GROUP_D_SIZE 6
#define CV_GROUP_E_SIZE 6
#define CV_GROUP_F_SIZE 6

#define AUX_GROUP_A_SIZE 6
#define AUX_GROUP_B_SIZE 6
#define AUX_GROUP_C_SIZE 6
#define AUX_GROUP_D_SIZE 6

#define STATUS_GROUP_A_SIZE 6
#define STATUS_GROUP_B_SIZE 6
#define COMM_GROUP_SIZE 6
#define S_CONTROL_GROUP_SIZE 6
#define PWM_GROUP_SIZE 6
#define PWM_S_CONTROL_GROUP_B_SIZE 6

#define CFG_GROUP_A_ID 1
#define CFG_GROUP_B_ID 2
#define CV_GROUP_A_ID 3
#define CV_GROUP_B_ID 4
#define CV_GROUP_C_ID 5
#define CV_GROUP_D_ID 6
#define CV_GROUP_E_ID 7
#define CV_GROUP_F_ID 8

#define AUX_GROUP_A_ID 9
#define AUX_GROUP_B_ID 10
#define AUX_GROUP_C_ID 11
#define AUX_GROUP_D_ID 12

#define STATUS_GROUP_A_ID 13
#define STATUS_GROUP_B_ID 14
#define COMM_GROUP_ID 15
#define S_CONTROL_GROUP_ID 16
#define PWM_GROUP_ID 17
#define PWM_S_CONTROL_GROUP_B_ID 18


#endif /* INC_ADBMS_CMD_MAKROS_H_ */
