/*
 * hp206c.h
 *
 *  Created on: Oct 6, 2022
 *      Author: user
 */

#ifndef INC_HP206C_H_
#define INC_HP206C_H_

#define HP20X_I2C_PORT        hi2c1
//HP20X INCLUDED:HP203B,HP206C,HP209F
//HP20X REGISTER AND COMMAND
#define HP20X_I2C_DEV_ID       0xEC//CSB PIN is VDD level(address is 0x76)
#define HP20X_I2C_DEV_ID2      0XEE //CSB PIN is GND level(address is 0x77)
#define HP20X_SOFT_RST         0x06
#define HP20X_WR_CONVERT_CMD   0x40
#define HP20X_CONVERT_OSR4096  0<<2
#define HP20X_CONVERT_OSR2048  1<<2
#define HP20X_CONVERT_OSR1024  2<<2
#define HP20X_CONVERT_OSR512   3<<2
#define HP20X_CONVERT_OSR256   4<<2
#define HP20X_CONVERT_OSR128   5<<2

#define HP20X_READ_P           0x30  //read_p command
#define HP20X_READ_A           0x31  //read_a command
#define HP20X_READ_T           0x32  //read_t command
#define HP20X_READ_PT          0x10  //read_pt command
#define HP20X_READ_AT          0x11  //read_at command
#define HP20X_READ_CAL		0X28	//RE-CAL ANALOG

#define HP20X_WR_REG_MODE     0xC0
#define HP20X_RD_REG_MODE     0x80

#define ERR_WR_DEVID_NACK       0x01
#define ERR_RD_DEVID_NACK       0x02
#define ERR_WR_REGADD_NACK      0x04
#define ERR_WR_REGCMD_NACK      0x08
#define ERR_WR_DATA_NACK        0x10
#define ERR_RD_DATA_MISMATCH    0x20

#define I2C_DID_WR_MASK         0xFE
#define I2C_DID_RD_MASK         0x01

#define T_WIN_EN                0x01
#define PA_WIN_EN               0x02
#define T_TRAV_EN               0x04
#define PA_TRAV_EN              0x08
#define PA_RDY_EN               0x20
#define T_RDY_EN                0x10

#define T_WIN_CFG               0x01
#define PA_WIN_CFG              0x02
#define PA_MODE_P               0x00
#define PA_MODE_A               0x40

#define T_TRAV_CFG              0x04

#define OK_HP20X_DEV            0x80		//HP20x_dev successfully initialized
#define REG_PARA                0x0F    //This register has only one valid bit of CMPS_EN.

#define TEMPERATURE_H_THRESHOLD 0x08

#define SOME_RANDOM_NUMBER      0x2D  // xD

void HP20X_I2C_WriteCmd(uint8_t Cmd1);
uint32_t HP20X_I2C_ReadData(void);
uint32_t HP20X_I2C_ReadData3Bytes(void);
float HP20X_ReadTemperature(void);
float HP20X_ReadPressure(void);
float HP20X_ReadAltitude(void);
void HP20X_I2C_WriteReg(uint8_t Reg, uint8_t Data);
void HP20X_Compensate(void);
void HP20X_SoftReset(void);
uint8_t HP20X_I2C_ReadReg(uint8_t HpReg);


#endif /* INC_HP206C_H_ */
