Initial commit

This commit is contained in:
2024-05-06 23:34:13 -03:00
commit 453275b96f
16 changed files with 2688 additions and 0 deletions

109
src/bme280.h Normal file
View File

@@ -0,0 +1,109 @@
/**
* @file bme280.h
* @author marisa (marisa@fwmari.net)
* @brief BME280 helper
* @version 0.1
* @date 2024-05-06
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#include <driver/i2c_master.h>
#include <stdint.h>
enum BME280Regs {
// Start of first calibration data registers
REG_CALIB00 = 0x88,
// Temperature calibration data registers
REG_T1 = 0x88,
REG_T2 = 0x8A,
REG_T3 = 0x8C,
// Pressure calibration data registers
REG_P1 = 0x8E,
REG_P2 = 0x90,
REG_P3 = 0x92,
REG_P4 = 0x94,
REG_P5 = 0x96,
REG_P6 = 0x98,
REG_P7 = 0x9A,
REG_P8 = 0x9C,
REG_P9 = 0x9E,
// Humidity calibration data registers
REG_H1 = 0xA1,
REG_H2 = 0xE1,
REG_H3 = 0xE3,
REG_E4 = 0xE4,
REG_E5 = 0xE5,
REG_E6 = 0xE6,
REG_H6 = 0xE7,
// Start of second calibration data registers
REG_CALIB26 = 0xE1,
// System registers
REG_CHIP_ID = 0xD0,
REG_RESET = 0xE0,
REG_CTRL_HUM = 0xF2,
REG_STATUS = 0xF3,
REG_CTRL_MEAS = 0xF4,
REG_CONFIG = 0xF5,
// Start of raw data registers
REG_RAWDATA = 0xF7,
REG_P_MSB = 0xF7,
REG_P_LSB = 0xF8,
REG_P_XLSB = 0xF9,
REG_T_MSB = 0xFA,
REG_T_LSB = 0xFB,
REG_T_XLSB = 0xFC,
REG_H_MSB = 0xFD,
REG_H_LSB = 0xFE,
};
struct BME280CalibParams {
// Temperature trimming parameters
uint16_t t1;
int16_t t2, t3;
// Pressure trimming parameters
uint16_t p1;
int16_t p2, p3, p4, p5, p6, p7, p8, p9;
// Humidity trimming params
uint8_t h1;
int16_t h2;
int8_t h3, h4, h5, h6;
};
struct BME280Reading {
double tempC, humidity, pressurehPa;
};
enum BME280Oversampling {
OVSP_X1 = 1,
OVSP_X2,
OVSP_X4,
OVSP_X8,
OVSP_X16,
};
struct BME280 {
struct BME280CalibParams calibParams;
enum BME280Oversampling oversampling;
i2c_master_dev_handle_t i2cHandle;
};
/**
* @brief Initializes BME280 struct. Creates i2c handle, sets oversampling and calibParams
*
* @param bme
*/
void BME280Init(struct BME280 *bme, enum BME280Oversampling oversampling);
struct BME280Reading BME280Read(struct BME280 *bme);