Skip to content

Commit dd9db27

Browse files
authored
Merge pull request #24 from coffee-and-telesense/add_bme68x_driver
Add delay function and update test code output
2 parents a0335fb + 68a7a95 commit dd9db27

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

libs/bme68x/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(bme68x STATIC
77
)
88

99
target_compile_definitions(bme68x PUBLIC
10+
BME68X_DO_NOT_USE_FPU
1011
$<$<CONFIG:Debug>:DEBUG>
1112
)
1213

libs/bme68x/Inc/bme68x_driver.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@
2323
* @todo: Alternatively, we could include an "i2c.h" file under the assumption that one will be created within the application code.
2424
*/
2525
#include "stm32l4xx_hal_i2c.h"
26-
27-
/* ========================== MACROS ========================== */
28-
29-
/**
30-
* @brief Used fixed point in the Bosch library
31-
* @todo: This can be removed when / if the Bosch library is reduced to only the necessary functionality
26+
/** @note: As currently written, the Bosch library needs BME68X_DO_NOT_USE_FPU
27+
* to be set in order to prevent floating point code from being used. This is currently
28+
* set in the CMakeLists.txt file for this driver.
3229
*/
33-
#define BME68X_DO_NOT_USE_FPU
34-
3530
#include "bme68x_defs.h"
3631
#include "bme68x.h"
3732

33+
/* ========================== MACROS ========================== */
34+
3835
/**
3936
* @brief Basic error macro
4037
* @todo: Consider using in conjunction with the common error types macros
@@ -72,6 +69,12 @@ typedef struct
7269

7370
/** Structure to store sensor measurement data. */
7471
/** @todo: May modify this to be an array in order to support parallel mode */
72+
/** @note: Since we're not using floating point, the data will be as follows:
73+
* - Temperature in degrees celsius x100
74+
* - Pressure in Pascal
75+
* - Humidity in % relative humidity x1000
76+
* - Gas resistance in Ohms
77+
*/
7578
struct bme68x_data sensor_data;
7679

7780
// /** Array to store multiple sensor data values (for parallel mode). */

libs/bme68x/Src/bme68x_driver.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ uint8_t bme_fetch_data(bme68x_sensor_t *bme)
137137
/** Get the measurement duration in microseconds*/
138138
uint32_t bme_get_meas_dur(bme68x_sensor_t *bme, uint8_t opmode)
139139
{
140-
if (opmode == NULL || opmode == BME68X_SLEEP_MODE)
140+
if (opmode == BME68X_SLEEP_MODE)
141141
opmode = bme->last_opmode;
142142

143143
return bme68x_get_meas_dur(opmode, &bme->conf, &bme->device);
@@ -150,6 +150,12 @@ void bme_delay_us(uint32_t period_us, void *intf_ptr)
150150
// so cast to void to avoid compiler warning
151151
(void)intf_ptr;
152152
/** @todo: Implement a microsecond delay here, possibly with a DWT cycle counter, or an actual hardware timer */
153+
// FIXME: Short-term implementation of a blocking delay
154+
volatile uint32_t cycles = period_us * 20;
155+
while (cycles--)
156+
{
157+
__NOP();
158+
}
153159
}
154160

155161
/** Implements the default microsecond delay callback */

tests/test_bme688/test_bme688.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ int main(void)
133133
// bme_read(0xD0, &sensor_id, 4, &hi2c1);
134134
// debug_print("Received sensor ID: 0x%X\r\n", sensor_id);
135135

136-
debug_print("Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status\r\n");
137136
/* USER CODE END 2 */
138137

139138
/* Infinite loop */
@@ -148,11 +147,17 @@ int main(void)
148147
int fetch_success = bme_fetch_data(&bme);
149148
if (fetch_success)
150149
{
151-
debug_print("%d, ", bme.sensor_data.temperature);
152-
debug_print("%d, ", bme.sensor_data.pressure);
153-
debug_print("%d, ", bme.sensor_data.humidity);
154-
debug_print("%d, ", bme.sensor_data.gas_resistance);
155-
debug_print("%X, \r\n", bme.sensor_data.status);
150+
debug_print("Temperature: %d.%02d°C, ",
151+
bme.sensor_data.temperature / 100,
152+
(bme.sensor_data.temperature % 100));
153+
debug_print("Pressure: %d Pa, ", bme.sensor_data.pressure);
154+
debug_print("Humidity: %d.%03d%%, ",
155+
bme.sensor_data.humidity / 1000,
156+
(bme.sensor_data.humidity % 1000));
157+
debug_print("Gas Resistance: %d.%03d kΩ, ",
158+
bme.sensor_data.gas_resistance / 1000,
159+
(bme.sensor_data.gas_resistance % 1000));
160+
debug_print("Status: 0x%X\r\n", bme.sensor_data.status);
156161
}
157162

158163
// The "blink" code is a simple verification of program execution,

0 commit comments

Comments
 (0)