LibDriver BMP390
Loading...
Searching...
No Matches
driver_bmp390_fifo.c
Go to the documentation of this file.
1
36
37#include "driver_bmp390_fifo.h"
38
39static bmp390_handle_t gs_handle;
40
49{
50 /* run irq handler */
51 if (bmp390_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
72 void (*fifo_receive_callback)(uint8_t type))
73{
74 uint8_t res;
75
76 /* link functions */
88 DRIVER_BMP390_LINK_RECEIVE_CALLBACK(&gs_handle, fifo_receive_callback);
89
90 /* set interface */
91 res = bmp390_set_interface(&gs_handle, interface);
92 if (res != 0)
93 {
94 bmp390_interface_debug_print("bmp390: set interface failed.\n");
95
96 return 1;
97 }
98
99 /* set addr pin */
100 res = bmp390_set_addr_pin(&gs_handle, addr_pin);
101 if (res != 0)
102 {
103 bmp390_interface_debug_print("bmp390: set addr pin failed.\n");
104
105 return 1;
106 }
107
108 /* bmp390 init */
109 res = bmp390_init(&gs_handle);
110 if (res != 0)
111 {
112 bmp390_interface_debug_print("bmp390: init failed.\n");
113
114 return 1;
115 }
116
117 /* set spi wire 4 */
119 if (res != 0)
120 {
121 bmp390_interface_debug_print("bmp390: set spi wire failed.\n");
122 (void)bmp390_deinit(&gs_handle);
123
124 return 1;
125 }
126
127 /* set default iic watchdog timer */
129 if (res != 0)
130 {
131 bmp390_interface_debug_print("bmp390: set iic watchdog timer failed.\n");
132 (void)bmp390_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* set default iic watchdog period */
139 if (res != 0)
140 {
141 bmp390_interface_debug_print("bmp390: set iic watchdog period failed.\n");
142 (void)bmp390_deinit(&gs_handle);
143
144 return 1;
145 }
146
147 /* enable fifo */
148 res = bmp390_set_fifo(&gs_handle, BMP390_BOOL_TRUE);
149 if (res != 0)
150 {
151 bmp390_interface_debug_print("bmp390: set fifo failed.\n");
152 (void)bmp390_deinit(&gs_handle);
153
154 return 1;
155 }
156
157 /* set default fifo stop on full */
159 if (res != 0)
160 {
161 bmp390_interface_debug_print("bmp390: set fifo stop on full failed.\n");
162 (void)bmp390_deinit(&gs_handle);
163
164 return 1;
165 }
166
167 /* set default fifo watermark */
169 if (res != 0)
170 {
171 bmp390_interface_debug_print("bmp390: set fifo watermark failed.\n");
172 (void)bmp390_deinit(&gs_handle);
173
174 return 1;
175 }
176
177 /* set default fifo sensor time on */
179 if (res != 0)
180 {
181 bmp390_interface_debug_print("bmp390: set fifo sensor time on failed.\n");
182 (void)bmp390_deinit(&gs_handle);
183
184 return 1;
185 }
186
187 /* set default fifo pressure on */
189 if (res != 0)
190 {
191 bmp390_interface_debug_print("bmp390: set fifo sensor time on failed.\n");
192 (void)bmp390_deinit(&gs_handle);
193
194 return 1;
195 }
196
197 /* set default fifo temperature on */
199 if (res != 0)
200 {
201 bmp390_interface_debug_print("bmp390: set fifo temperature on failed.\n");
202 (void)bmp390_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* set default fifo subsampling */
209 if (res != 0)
210 {
211 bmp390_interface_debug_print("bmp390: set fifo subsampling failed.\n");
212 (void)bmp390_deinit(&gs_handle);
213
214 return 1;
215 }
216
217 /* set default fifo data source */
219 if (res != 0)
220 {
221 bmp390_interface_debug_print("bmp390: set fifo data source failed.\n");
222 (void)bmp390_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* set default interrupt pin type */
229 if (res != 0)
230 {
231 bmp390_interface_debug_print("bmp390: set interrupt pin type failed.\n");
232 (void)bmp390_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* set default interrupt active level */
239 if (res != 0)
240 {
241 bmp390_interface_debug_print("bmp390: set interrupt active level failed.\n");
242 (void)bmp390_deinit(&gs_handle);
243
244 return 1;
245 }
246
247 /* set default latch interrupt pin and interrupt status */
249 if (res != 0)
250 {
251 bmp390_interface_debug_print("bmp390: set latch interrupt pin and interrupt status failed.\n");
252 (void)bmp390_deinit(&gs_handle);
253
254 return 1;
255 }
256
257 /* set default interrupt fifo watermark */
259 if (res != 0)
260 {
261 bmp390_interface_debug_print("bmp390: set interrupt fifo watermark failed.\n");
262 (void)bmp390_deinit(&gs_handle);
263
264 return 1;
265 }
266
267 /* set default interrupt fifo full */
269 if (res != 0)
270 {
271 bmp390_interface_debug_print("bmp390: set interrupt fifo full failed.\n");
272 (void)bmp390_deinit(&gs_handle);
273
274 return 1;
275 }
276
277 /* set default interrupt data ready */
279 if (res != 0)
280 {
281 bmp390_interface_debug_print("bmp390: set interrupt data ready failed.\n");
282 (void)bmp390_deinit(&gs_handle);
283
284 return 1;
285 }
286
287 /* set default pressure */
289 if (res != 0)
290 {
291 bmp390_interface_debug_print("bmp390: set pressure failed.\n");
292 (void)bmp390_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* set default temperature */
299 if (res != 0)
300 {
301 bmp390_interface_debug_print("bmp390: set temperature failed.\n");
302 (void)bmp390_deinit(&gs_handle);
303
304 return 1;
305 }
306
307 /* set default pressure oversampling */
309 if (res != 0)
310 {
311 bmp390_interface_debug_print("bmp390: set pressure oversampling failed.\n");
312 (void)bmp390_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* set default temperature oversampling */
319 if (res != 0)
320 {
321 bmp390_interface_debug_print("bmp390: set temperature oversampling failed.\n");
322 (void)bmp390_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* set default odr */
328 res = bmp390_set_odr(&gs_handle, BMP390_FIFO_DEFAULT_ODR);
329 if (res != 0)
330 {
331 bmp390_interface_debug_print("bmp390: set odr failed.\n");
332 (void)bmp390_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* set default filter coefficient */
339 if (res != 0)
340 {
341 bmp390_interface_debug_print("bmp390: set filter coefficient failed.\n");
342 (void)bmp390_deinit(&gs_handle);
343
344 return 1;
345 }
346
347 /* set normal mode */
348 res = bmp390_set_mode(&gs_handle, BMP390_MODE_NORMAL_MODE);
349 if (res != 0)
350 {
351 bmp390_interface_debug_print("bmp390: set mode failed.\n");
352 (void)bmp390_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 return 0;
358}
359
371uint8_t bmp390_fifo_read(uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
372{
373 /* read fifo */
374 if (bmp390_read_fifo(&gs_handle, (uint8_t *)buf, (uint16_t *)&buf_len) != 0)
375 {
376 return 1;
377 }
378 /* parse fifo */
379 if (bmp390_fifo_parse(&gs_handle, (uint8_t *)buf, buf_len, (bmp390_frame_t *)frame, (uint16_t *)frame_len) != 0)
380 {
381 return 1;
382 }
383
384 return 0;
385}
386
395{
396 uint8_t res;
397
398 /* set sleep mode */
399 res = bmp390_set_mode(&gs_handle, BMP390_MODE_SLEEP_MODE);
400 if (res != 0)
401 {
402 return 1;
403 }
404
405 if (bmp390_deinit(&gs_handle) != 0)
406 {
407 return 1;
408 }
409 else
410 {
411 return 0;
412 }
413}
driver bmp390 fifo header file
uint8_t bmp390_set_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp390_set_pressure(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the pressure
uint8_t bmp390_set_mode(bmp390_handle_t *handle, bmp390_mode_t mode)
set the chip mode
bmp390_interface_t
bmp390 interface enumeration definition
uint8_t bmp390_set_temperature(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the temperature
uint8_t bmp390_set_addr_pin(bmp390_handle_t *handle, bmp390_address_t addr_pin)
set the iic address pin
struct bmp390_frame_s bmp390_frame_t
bmp390 frame structure definition
uint8_t bmp390_set_odr(bmp390_handle_t *handle, bmp390_odr_t odr)
set the output data rate
uint8_t bmp390_init(bmp390_handle_t *handle)
initialize the chip
uint8_t bmp390_set_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the iic watchdog timer
uint8_t bmp390_irq_handler(bmp390_handle_t *handle)
irq handler
uint8_t bmp390_set_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp390_set_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp390_deinit(bmp390_handle_t *handle)
close the chip
uint8_t bmp390_set_interface(bmp390_handle_t *handle, bmp390_interface_t interface)
set the interface
bmp390_address_t
bmp390 address enumeration definition
uint8_t bmp390_set_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t wire)
set the spi wire
uint8_t bmp390_set_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t coefficient)
set the filter coefficient
struct bmp390_handle_s bmp390_handle_t
bmp390 handle structure definition
@ BMP390_BOOL_TRUE
@ BMP390_MODE_NORMAL_MODE
@ BMP390_MODE_SLEEP_MODE
#define BMP390_FIFO_DEFAULT_TEMPERATURE
#define BMP390_FIFO_DEFAULT_IIC_WATCHDOG_TIMER
#define BMP390_FIFO_DEFAULT_FILTER_COEFFICIENT
#define BMP390_FIFO_DEFAULT_INTERRUPT_DATA_READY
#define BMP390_FIFO_DEFAULT_INTERRUPT_FIFO_FULL
#define BMP390_FIFO_DEFAULT_PRESSURE_OVERSAMPLING
#define BMP390_FIFO_DEFAULT_LATCH_INTERRUPT
#define BMP390_FIFO_DEFAULT_FIFO_PRESSURE_ON
#define BMP390_FIFO_DEFAULT_FIFO_SENSORTIME_ON
#define BMP390_FIFO_DEFAULT_TEMPERATURE_OVERSAMPLING
#define BMP390_FIFO_DEFAULT_PRESSURE
uint8_t bmp390_fifo_irq_handler(void)
fifo example irq handler
#define BMP390_FIFO_DEFAULT_FIFO_WATERMARK
uint8_t bmp390_fifo_deinit(void)
fifo example deinit
#define BMP390_FIFO_DEFAULT_FIFO_STOP_ON_FULL
#define BMP390_FIFO_DEFAULT_SPI_WIRE
bmp390 fifo example default definition
#define BMP390_FIFO_DEFAULT_FIFO_DATA_SOURCE
#define BMP390_FIFO_DEFAULT_INTERRUPT_ACTIVE_LEVEL
#define BMP390_FIFO_DEFAULT_IIC_WATCHDOG_PERIOD
#define BMP390_FIFO_DEFAULT_ODR
uint8_t bmp390_fifo_read(uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
fifo example read
uint8_t bmp390_fifo_init(bmp390_interface_t interface, bmp390_address_t addr_pin, void(*fifo_receive_callback)(uint8_t type))
fifo example init
#define BMP390_FIFO_DEFAULT_FIFO_TEMPERATURE_ON
#define BMP390_FIFO_DEFAULT_FIFO_SUBSAMPLING
#define BMP390_FIFO_DEFAULT_INTERRUPT_WATERMARK
#define BMP390_FIFO_DEFAULT_INTERRUPT_PIN_TYPE
uint8_t bmp390_fifo_parse(bmp390_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp390_set_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t source)
set the fifo data source
uint8_t bmp390_set_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp390_set_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp390_set_fifo(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo
uint8_t bmp390_read_fifo(bmp390_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp390_set_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp390_set_fifo_subsampling(bmp390_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp390_set_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp390_set_fifo_watermark(bmp390_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp390_interface_spi_init(void)
interface spi bus init
uint8_t bmp390_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void bmp390_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp390_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp390_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp390_interface_iic_init(void)
interface iic bus init
uint8_t bmp390_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp390_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp390_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp390_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp390_set_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp390_set_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp390_set_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp390_set_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp390_set_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp390_set_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t level)
set the interrupt active level