LibDriver BMP384
Loading...
Searching...
No Matches
driver_bmp384_fifo.c
Go to the documentation of this file.
1
36
37#include "driver_bmp384_fifo.h"
38
39static bmp384_handle_t gs_handle;
40
49{
50 /* run irq handler */
51 if (bmp384_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55
56 return 0;
57}
58
70 void (*fifo_receive_callback)(uint8_t type))
71{
72 uint8_t res;
73
74 /* link functions */
86 DRIVER_BMP384_LINK_RECEIVE_CALLBACK(&gs_handle, fifo_receive_callback);
87
88 /* set interface */
89 res = bmp384_set_interface(&gs_handle, interface);
90 if (res != 0)
91 {
92 bmp384_interface_debug_print("bmp384: set interface failed.\n");
93
94 return 1;
95 }
96
97 /* set addr pin */
98 res = bmp384_set_addr_pin(&gs_handle, addr_pin);
99 if (res != 0)
100 {
101 bmp384_interface_debug_print("bmp384: set addr pin failed.\n");
102
103 return 1;
104 }
105
106 /* bmp384 init */
107 res = bmp384_init(&gs_handle);
108 if (res != 0)
109 {
110 bmp384_interface_debug_print("bmp384: init failed.\n");
111
112 return 1;
113 }
114
115 /* set spi wire 4 */
117 if (res != 0)
118 {
119 bmp384_interface_debug_print("bmp384: set spi wire failed.\n");
120 (void)bmp384_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* set default iic watchdog timer */
127 if (res != 0)
128 {
129 bmp384_interface_debug_print("bmp384: set iic watchdog timer failed.\n");
130 (void)bmp384_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* set default iic watchdog period */
137 if (res != 0)
138 {
139 bmp384_interface_debug_print("bmp384: set iic watchdog period failed.\n");
140 (void)bmp384_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* enable fifo */
146 res = bmp384_set_fifo(&gs_handle, BMP384_BOOL_TRUE);
147 if (res != 0)
148 {
149 bmp384_interface_debug_print("bmp384: set fifo failed.\n");
150 (void)bmp384_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* set default fifo stop on full */
157 if (res != 0)
158 {
159 bmp384_interface_debug_print("bmp384: set fifo stop on full failed.\n");
160 (void)bmp384_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* set default fifo watermark */
167 if (res != 0)
168 {
169 bmp384_interface_debug_print("bmp384: set fifo watermark failed.\n");
170 (void)bmp384_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* set default fifo sensor time on */
177 if (res != 0)
178 {
179 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
180 (void)bmp384_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* set default fifo pressure on */
187 if (res != 0)
188 {
189 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
190 (void)bmp384_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* set default fifo temperature on */
197 if (res != 0)
198 {
199 bmp384_interface_debug_print("bmp384: set fifo temperature on failed.\n");
200 (void)bmp384_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* set default fifo subsampling */
207 if (res != 0)
208 {
209 bmp384_interface_debug_print("bmp384: set fifo subsampling failed.\n");
210 (void)bmp384_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* set default fifo data source */
217 if (res != 0)
218 {
219 bmp384_interface_debug_print("bmp384: set fifo data source failed.\n");
220 (void)bmp384_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* set default interrupt pin type */
227 if (res != 0)
228 {
229 bmp384_interface_debug_print("bmp384: set interrupt pin type failed.\n");
230 (void)bmp384_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* set default interrupt active level */
237 if (res != 0)
238 {
239 bmp384_interface_debug_print("bmp384: set interrupt active level failed.\n");
240 (void)bmp384_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* set default latch interrupt pin and interrupt status */
247 if (res != 0)
248 {
249 bmp384_interface_debug_print("bmp384: set latch interrupt pin and interrupt status failed.\n");
250 (void)bmp384_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* set default interrupt fifo watermark */
257 if (res != 0)
258 {
259 bmp384_interface_debug_print("bmp384: set interrupt fifo watermark failed.\n");
260 (void)bmp384_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* set default interrupt fifo full */
267 if (res != 0)
268 {
269 bmp384_interface_debug_print("bmp384: set interrupt fifo full failed.\n");
270 (void)bmp384_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* set default interrupt data ready */
277 if (res != 0)
278 {
279 bmp384_interface_debug_print("bmp384: set interrupt data ready failed.\n");
280 (void)bmp384_deinit(&gs_handle);
281
282 return 1;
283 }
284
285 /* set default pressure */
287 if (res != 0)
288 {
289 bmp384_interface_debug_print("bmp384: set pressure failed.\n");
290 (void)bmp384_deinit(&gs_handle);
291
292 return 1;
293 }
294
295 /* set default temperature */
297 if (res != 0)
298 {
299 bmp384_interface_debug_print("bmp384: set temperature failed.\n");
300 (void)bmp384_deinit(&gs_handle);
301
302 return 1;
303 }
304
305 /* set default pressure oversampling */
307 if (res != 0)
308 {
309 bmp384_interface_debug_print("bmp384: set pressure oversampling failed.\n");
310 (void)bmp384_deinit(&gs_handle);
311
312 return 1;
313 }
314
315 /* set default temperature oversampling */
317 if (res != 0)
318 {
319 bmp384_interface_debug_print("bmp384: set temperature oversampling failed.\n");
320 (void)bmp384_deinit(&gs_handle);
321
322 return 1;
323 }
324
325 /* set default odr */
326 res = bmp384_set_odr(&gs_handle, BMP384_FIFO_DEFAULT_ODR);
327 if (res != 0)
328 {
329 bmp384_interface_debug_print("bmp384: set odr failed.\n");
330 (void)bmp384_deinit(&gs_handle);
331
332 return 1;
333 }
334
335 /* set default filter coefficient */
337 if (res != 0)
338 {
339 bmp384_interface_debug_print("bmp384: set filter coefficient failed.\n");
340 (void)bmp384_deinit(&gs_handle);
341
342 return 1;
343 }
344
345 /* set normal mode */
346 res = bmp384_set_mode(&gs_handle, BMP384_MODE_NORMAL_MODE);
347 if (res != 0)
348 {
349 bmp384_interface_debug_print("bmp384: set mode failed.\n");
350 (void)bmp384_deinit(&gs_handle);
351
352 return 1;
353 }
354
355 return 0;
356}
357
369uint8_t bmp384_fifo_read(uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
370{
371 /* read fifo */
372 if (bmp384_read_fifo(&gs_handle, (uint8_t *)buf, (uint16_t *)&buf_len) != 0)
373 {
374 return 1;
375 }
376 /* parse fifo */
377 if (bmp384_fifo_parse(&gs_handle, (uint8_t *)buf, buf_len, (bmp384_frame_t *)frame, (uint16_t *)frame_len) != 0)
378 {
379 return 1;
380 }
381
382 return 0;
383}
384
393{
394 uint8_t res;
395
396 /* set sleep mode */
397 res = bmp384_set_mode(&gs_handle, BMP384_MODE_SLEEP_MODE);
398 if (res != 0)
399 {
400 return 1;
401 }
402
403 if (bmp384_deinit(&gs_handle) != 0)
404 {
405 return 1;
406 }
407
408 return 0;
409}
driver bmp384 fifo header file
uint8_t bmp384_deinit(bmp384_handle_t *handle)
close the chip
uint8_t bmp384_set_addr_pin(bmp384_handle_t *handle, bmp384_address_t addr_pin)
set the iic address pin
bmp384_interface_t
bmp384 interface enumeration definition
uint8_t bmp384_set_interface(bmp384_handle_t *handle, bmp384_interface_t interface)
set the interface
uint8_t bmp384_set_pressure(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the pressure
uint8_t bmp384_set_temperature(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the temperature
struct bmp384_frame_s bmp384_frame_t
bmp384 frame structure definition
uint8_t bmp384_set_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp384_set_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the iic watchdog timer
bmp384_address_t
bmp384 address enumeration definition
uint8_t bmp384_set_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp384_set_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t wire)
set the spi wire
uint8_t bmp384_set_mode(bmp384_handle_t *handle, bmp384_mode_t mode)
set the chip mode
uint8_t bmp384_init(bmp384_handle_t *handle)
initialize the chip
uint8_t bmp384_set_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp384_irq_handler(bmp384_handle_t *handle)
irq handler
uint8_t bmp384_set_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the temperature oversampling
struct bmp384_handle_s bmp384_handle_t
bmp384 handle structure definition
uint8_t bmp384_set_odr(bmp384_handle_t *handle, bmp384_odr_t odr)
set the output data rate
@ BMP384_MODE_NORMAL_MODE
@ BMP384_MODE_SLEEP_MODE
@ BMP384_BOOL_TRUE
uint8_t bmp384_fifo_read(uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
fifo example read
#define BMP384_FIFO_DEFAULT_INTERRUPT_WATERMARK
uint8_t bmp384_fifo_init(bmp384_interface_t interface, bmp384_address_t addr_pin, void(*fifo_receive_callback)(uint8_t type))
fifo example init
#define BMP384_FIFO_DEFAULT_INTERRUPT_DATA_READY
#define BMP384_FIFO_DEFAULT_FIFO_SUBSAMPLING
#define BMP384_FIFO_DEFAULT_FIFO_SENSORTIME_ON
#define BMP384_FIFO_DEFAULT_FIFO_WATERMARK
#define BMP384_FIFO_DEFAULT_PRESSURE_OVERSAMPLING
#define BMP384_FIFO_DEFAULT_FIFO_DATA_SOURCE
#define BMP384_FIFO_DEFAULT_FIFO_TEMPERATURE_ON
#define BMP384_FIFO_DEFAULT_IIC_WATCHDOG_PERIOD
uint8_t bmp384_fifo_irq_handler(void)
fifo example irq handler
uint8_t bmp384_fifo_deinit(void)
fifo example deinit
#define BMP384_FIFO_DEFAULT_ODR
#define BMP384_FIFO_DEFAULT_PRESSURE
#define BMP384_FIFO_DEFAULT_FIFO_STOP_ON_FULL
#define BMP384_FIFO_DEFAULT_INTERRUPT_ACTIVE_LEVEL
#define BMP384_FIFO_DEFAULT_IIC_WATCHDOG_TIMER
#define BMP384_FIFO_DEFAULT_TEMPERATURE_OVERSAMPLING
#define BMP384_FIFO_DEFAULT_INTERRUPT_PIN_TYPE
#define BMP384_FIFO_DEFAULT_SPI_WIRE
bmp384 fifo example default definition
#define BMP384_FIFO_DEFAULT_INTERRUPT_FIFO_FULL
#define BMP384_FIFO_DEFAULT_TEMPERATURE
#define BMP384_FIFO_DEFAULT_FILTER_COEFFICIENT
#define BMP384_FIFO_DEFAULT_LATCH_INTERRUPT
#define BMP384_FIFO_DEFAULT_FIFO_PRESSURE_ON
uint8_t bmp384_fifo_parse(bmp384_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp384_set_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp384_set_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t source)
set the fifo data source
uint8_t bmp384_set_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp384_set_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp384_read_fifo(bmp384_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp384_set_fifo(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo
uint8_t bmp384_set_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp384_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp384_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp384_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp384_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void bmp384_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp384_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp384_interface_iic_init(void)
interface iic bus init
uint8_t bmp384_interface_spi_init(void)
interface spi bus init
uint8_t bmp384_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp384_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp384_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp384_set_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp384_set_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp384_set_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp384_set_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp384_set_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp384_set_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable latching interrupt pin and interrupt status