Compare commits
2 Commits
2098121ae0
...
ed930d1eae
Author | SHA1 | Date | |
---|---|---|---|
|
ed930d1eae | ||
|
e47498b8bd |
@ -117,6 +117,28 @@ static bool _BMP280_read_calibration_data(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float _BMP280_compute_temperature(uint8_t *data)
|
||||||
|
{
|
||||||
|
int32_t var1, var2;
|
||||||
|
int32_t adc_T = data[0] << 16 | data[1] << 8 | data[2];
|
||||||
|
adc_T >>= 4;
|
||||||
|
|
||||||
|
var1 = ((((adc_T >> 3) - ((int32_t)_calibration_data.dig_T1 << 1))) *
|
||||||
|
((int32_t)_calibration_data.dig_T2)) >>
|
||||||
|
11;
|
||||||
|
|
||||||
|
var2 = (((((adc_T >> 4) - ((int32_t)_calibration_data.dig_T1)) *
|
||||||
|
((adc_T >> 4) - ((int32_t)_calibration_data.dig_T1))) >>
|
||||||
|
12) *
|
||||||
|
((int32_t)_calibration_data.dig_T3)) >>
|
||||||
|
14;
|
||||||
|
|
||||||
|
t_fine = var1 + var2;
|
||||||
|
|
||||||
|
float T = (t_fine * 5 + 128) >> 8;
|
||||||
|
return T / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
bool BMP280_init(void)
|
bool BMP280_init(void)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
@ -162,40 +184,28 @@ bool BMP280_is_measuring(void)
|
|||||||
|
|
||||||
float BMP280_get_temperature(void)
|
float BMP280_get_temperature(void)
|
||||||
{
|
{
|
||||||
int32_t var1, var2;
|
|
||||||
uint8_t data[3];
|
uint8_t data[3];
|
||||||
|
|
||||||
if(!i2c_read(BMP280_I2C_ADDR, BMP280_TEMP_MSB, data, sizeof data)) return 0.0f;
|
if(!i2c_read(BMP280_I2C_ADDR, BMP280_TEMP_MSB, data, sizeof data)) return 0.0f;
|
||||||
|
|
||||||
int32_t adc_T = data[0] << 16 | data[1] << 8 | data[2];
|
return _BMP280_compute_temperature(data);
|
||||||
adc_T >>= 4;
|
|
||||||
|
|
||||||
var1 = ((((adc_T >> 3) - ((int32_t)_calibration_data.dig_T1 << 1))) *
|
|
||||||
((int32_t)_calibration_data.dig_T2)) >>
|
|
||||||
11;
|
|
||||||
|
|
||||||
var2 = (((((adc_T >> 4) - ((int32_t)_calibration_data.dig_T1)) *
|
|
||||||
((adc_T >> 4) - ((int32_t)_calibration_data.dig_T1))) >>
|
|
||||||
12) *
|
|
||||||
((int32_t)_calibration_data.dig_T3)) >>
|
|
||||||
14;
|
|
||||||
|
|
||||||
t_fine = var1 + var2;
|
|
||||||
|
|
||||||
float T = (t_fine * 5 + 128) >> 8;
|
|
||||||
return T / 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float BMP280_get_pressure(float * const temperature)
|
float BMP280_get_pressure(float * const temperature)
|
||||||
{
|
{
|
||||||
int64_t var1, var2, p;
|
int64_t var1, var2, p;
|
||||||
uint8_t data[3];
|
uint8_t data[6];
|
||||||
|
|
||||||
float temp = BMP280_get_temperature();
|
/* When reading the pressure, we also need to get the associated temperature, so let's read everything at once */
|
||||||
|
if(!i2c_read(BMP280_I2C_ADDR, BMP280_PRESS_MSB, data, sizeof data))
|
||||||
|
{
|
||||||
|
if(temperature) *temperature = 0.0f;
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float temp = _BMP280_compute_temperature(&data[3]);
|
||||||
if(temperature) *temperature = temp;
|
if(temperature) *temperature = temp;
|
||||||
|
|
||||||
if(!i2c_read(BMP280_I2C_ADDR, BMP280_PRESS_MSB, data, sizeof data)) return 0.0f;
|
|
||||||
|
|
||||||
int32_t adc_P = data[0] << 16 | data[1] << 8 | data[2];
|
int32_t adc_P = data[0] << 16 | data[1] << 8 | data[2];
|
||||||
adc_P >>= 4;
|
adc_P >>= 4;
|
||||||
|
|
||||||
|
@ -146,6 +146,7 @@ void tls_pmu_sdio_isr_register(tls_pmu_irq_callback callback, void *arg);
|
|||||||
*/
|
*/
|
||||||
void tls_pmu_clk_select(u8 bypass);
|
void tls_pmu_clk_select(u8 bypass);
|
||||||
|
|
||||||
|
/** NOT PART OF THE OFFICIAL SDK **/
|
||||||
/**
|
/**
|
||||||
* @brief Starts the internal 32K oscillator calibration cycle.
|
* @brief Starts the internal 32K oscillator calibration cycle.
|
||||||
*
|
*
|
||||||
@ -155,6 +156,7 @@ void tls_pmu_clk_select(u8 bypass);
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void tls_pmu_clk_calibrate(void);
|
void tls_pmu_clk_calibrate(void);
|
||||||
|
/**********************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +59,6 @@ void tls_set_rtc(struct tm *tblock);
|
|||||||
void tls_get_rtc(struct tm *tblock);
|
void tls_get_rtc(struct tm *tblock);
|
||||||
|
|
||||||
/** NOT PART OF THE OFFICIAL SDK **/
|
/** NOT PART OF THE OFFICIAL SDK **/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if the RTC peripheral is running or not
|
* @brief Checks if the RTC peripheral is running or not
|
||||||
*
|
*
|
||||||
@ -67,7 +66,6 @@ void tls_get_rtc(struct tm *tblock);
|
|||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
bool tls_is_rtc_running(void);
|
bool tls_is_rtc_running(void);
|
||||||
|
|
||||||
/**********************************/
|
/**********************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user