/**************************************************************************************/
/********************          Library BMP280 & AHT20              ********************/
/*          Author : Subeer Kumar Sarkar                                              */
/*          Website: iotthinghub.com                                                  */
/*                                                                                    */
/**************************************************************************************/
#include "stm32f0xx_hal.h"
#include "math.h"
/********************************    BMP280 Parameter                **************/
// Oversampling definitions 
#define OSRS_OFF    	0x00
#define OSRS_1      	0x01
#define OSRS_2      	0x02
#define OSRS_4      	0x03
#define OSRS_8      	0x04
#define OSRS_16     	0x05

// MODE Definitions
#define MODE_SLEEP      0x00
#define MODE_FORCED     0x01
#define MODE_NORMAL     0x03

// Standby Time
#define T_SB_0p5    	0x00
#define T_SB_62p5   	0x01
#define T_SB_125    	0x02
#define T_SB_250    	0x03
#define T_SB_500    	0x04
#define T_SB_1000   	0x05
#define T_SB_10     	0x06
#define T_SB_20     	0x07

// IIR Filter Coefficients
#define IIR_OFF     	0x00
#define IIR_2       	0x01
#define IIR_4       	0x02
#define IIR_8       	0x03
#define IIR_16      	0x04

// Temperature Oversampling
#define T_OVERx1      0x01
#define T_OVERx2      0x02
#define T_OVERx4      0x03
#define T_OVERx8      0x04
#define T_OVERx16     0x05

// Pressure Oversampling
#define P_OVERx1      0x01
#define P_OVERx2      0x02
#define P_OVERx4      0x03
#define P_OVERx8      0x04
#define P_OVERx16     0x05

// REGISTERS DEFINITIONS
#define ID_REG      	  0xD0
#define RESET_REG  		  0xE0
#define STATUS_REG      0xF3
#define CTRL_MEAS_REG   0xF4
#define CONFIG_REG      0xF5
#define TEMP_REG        0xF7
#define TRIMMING_PRA    0x88
/**********************************************************************************/

/********************************     AHT20 Parameter                **************/
#define AHT20_ADD    0x38
#define AHT20_INIT   0xBE
#define AHT20_RESET  0xBA
#define AHT20_TRIG   0xAC
/**********************************************************************************/

/**************************       Global Variable       ***************************/
extern float BMP280_Temperature, BMP280_Pressure, BMP280_Altitude;
extern float AHT20_Temperature, AHT20_Humidity;
/**********************************************************************************/


void BMP280_init(uint8_t t_sb,uint8_t filter, uint8_t osrs_t, uint8_t osrs_p,uint8_t mode);
void BMP280_calc_values(void);
void BMP280_get_calib_values(void);
void AHT20_init(void);
void AHT20_Read(void);
