LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388_interrupt.c
Go to the documentation of this file.
1
37
39
40static bmp388_handle_t gs_handle;
41
50{
51 /* run irq handler */
52 if (bmp388_irq_handler(&gs_handle) != 0)
53 {
54 return 1;
55 }
56 else
57 {
58 return 0;
59 }
60}
61
73 void (*interrupt_receive_callback)(uint8_t type))
74{
75 uint8_t res;
76
77 /* link functions */
89 DRIVER_BMP388_LINK_RECEIVE_CALLBACK(&gs_handle, interrupt_receive_callback);
90
91 /* set interface */
92 res = bmp388_set_interface(&gs_handle, interface);
93 if (res != 0)
94 {
95 bmp388_interface_debug_print("bmp388: set interface failed.\n");
96
97 return 1;
98 }
99
100 /* set addr pin */
101 res = bmp388_set_addr_pin(&gs_handle, addr_pin);
102 if (res != 0)
103 {
104 bmp388_interface_debug_print("bmp388: set addr pin failed.\n");
105
106 return 1;
107 }
108
109 /* bmp388 init */
110 res = bmp388_init(&gs_handle);
111 if (res != 0)
112 {
113 bmp388_interface_debug_print("bmp388: init failed.\n");
114
115 return 1;
116 }
117
118 /* set default spi wire */
120 if (res != 0)
121 {
122 bmp388_interface_debug_print("bmp388: set spi wire failed.\n");
123 (void)bmp388_deinit(&gs_handle);
124
125 return 1;
126 }
127
128 /* set default iic watchdog timer */
130 if (res != 0)
131 {
132 bmp388_interface_debug_print("bmp388: set iic watchdog timer failed.\n");
133 (void)bmp388_deinit(&gs_handle);
134
135 return 1;
136 }
137
138 /* set default iic watchdog period */
140 if (res != 0)
141 {
142 bmp388_interface_debug_print("bmp388: set iic watchdog period failed.\n");
143 (void)bmp388_deinit(&gs_handle);
144
145 return 1;
146 }
147
148 /* disable fifo */
149 res = bmp388_set_fifo(&gs_handle, BMP388_BOOL_FALSE);
150 if (res != 0)
151 {
152 bmp388_interface_debug_print("bmp388: set fifo failed.\n");
153 (void)bmp388_deinit(&gs_handle);
154
155 return 1;
156 }
157
158 /* set default interrupt pin type */
160 if (res != 0)
161 {
162 bmp388_interface_debug_print("bmp388: set interrupt pin type failed.\n");
163 (void)bmp388_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* set default interrupt active level */
170 if (res != 0)
171 {
172 bmp388_interface_debug_print("bmp388: set interrupt active level failed.\n");
173 (void)bmp388_deinit(&gs_handle);
174
175 return 1;
176 }
177
178 /* disable latch interrupt pin and interrupt status */
180 if (res != 0)
181 {
182 bmp388_interface_debug_print("bmp388: set latch interrupt pin and interrupt status failed.\n");
183 (void)bmp388_deinit(&gs_handle);
184
185 return 1;
186 }
187
188 /* disable interrupt fifo watermark */
190 if (res != 0)
191 {
192 bmp388_interface_debug_print("bmp388: set interrupt fifo watermark failed.\n");
193 (void)bmp388_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* disable interrupt fifo full */
200 if (res != 0)
201 {
202 bmp388_interface_debug_print("bmp388: set interrupt fifo full failed.\n");
203 (void)bmp388_deinit(&gs_handle);
204
205 return 1;
206 }
207
208 /* enable interrupt data ready */
210 if (res != 0)
211 {
212 bmp388_interface_debug_print("bmp388: set interrupt data ready failed.\n");
213 (void)bmp388_deinit(&gs_handle);
214
215 return 1;
216 }
217
218 /* set default pressure */
220 if (res != 0)
221 {
222 bmp388_interface_debug_print("bmp388: set pressure failed.\n");
223 (void)bmp388_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* set default temperature */
230 if (res != 0)
231 {
232 bmp388_interface_debug_print("bmp388: set temperature failed.\n");
233 (void)bmp388_deinit(&gs_handle);
234
235 return 1;
236 }
237
238 /* set default pressure oversampling */
240 if (res != 0)
241 {
242 bmp388_interface_debug_print("bmp388: set pressure oversampling failed.\n");
243 (void)bmp388_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* set default temperature oversampling */
250 if (res != 0)
251 {
252 bmp388_interface_debug_print("bmp388: set temperature oversampling failed.\n");
253 (void)bmp388_deinit(&gs_handle);
254
255 return 1;
256 }
257
258 /* set default odr */
260 if (res != 0)
261 {
262 bmp388_interface_debug_print("bmp388: set odr failed.\n");
263 (void)bmp388_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 /* set default filter coefficient */
270 if (res != 0)
271 {
272 bmp388_interface_debug_print("bmp388: set filter coefficient failed.\n");
273 (void)bmp388_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* set normal mode */
279 res = bmp388_set_mode(&gs_handle, BMP388_MODE_NORMAL_MODE);
280 if (res != 0)
281 {
282 bmp388_interface_debug_print("bmp388: set mode failed.\n");
283 (void)bmp388_deinit(&gs_handle);
284
285 return 1;
286 }
287
288 return 0;
289}
290
300uint8_t bmp388_interrupt_read(float *temperature_c, float *pressure_pa)
301{
302 uint32_t temperature_raw;
303 uint32_t pressure_raw;
304
305 /* read temperature and pressure */
306 if (bmp388_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, temperature_c,
307 (uint32_t *)&pressure_raw, pressure_pa) != 0)
308 {
309 return 1;
310 }
311 else
312 {
313 return 0;
314 }
315}
316
325{
326 uint8_t res;
327
328 /* set sleep mode */
329 res = bmp388_set_mode(&gs_handle, BMP388_MODE_SLEEP_MODE);
330 if (res != 0)
331 {
332 return 1;
333 }
334
335 if (bmp388_deinit(&gs_handle) != 0)
336 {
337 return 1;
338 }
339 else
340 {
341 return 0;
342 }
343}
driver bmp388 interrupt header file
uint8_t bmp388_set_odr(bmp388_handle_t *handle, bmp388_odr_t odr)
set the output data rate
uint8_t bmp388_set_pressure(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the pressure
bmp388_interface_t
bmp388 interface enumeration definition
uint8_t bmp388_init(bmp388_handle_t *handle)
initialize the chip
uint8_t bmp388_set_spi_wire(bmp388_handle_t *handle, bmp388_spi_wire_t wire)
set the spi wire
uint8_t bmp388_set_iic_watchdog_timer(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the iic watchdog timer
struct bmp388_handle_s bmp388_handle_t
bmp388 handle structure definition
uint8_t bmp388_set_pressure_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp388_set_temperature(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the temperature
uint8_t bmp388_set_filter_coefficient(bmp388_handle_t *handle, bmp388_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp388_irq_handler(bmp388_handle_t *handle)
irq handler
uint8_t bmp388_deinit(bmp388_handle_t *handle)
close the chip
uint8_t bmp388_set_interface(bmp388_handle_t *handle, bmp388_interface_t interface)
set the interface
uint8_t bmp388_set_iic_watchdog_period(bmp388_handle_t *handle, bmp388_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp388_read_temperature_pressure(bmp388_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
uint8_t bmp388_set_mode(bmp388_handle_t *handle, bmp388_mode_t mode)
set the chip mode
uint8_t bmp388_set_temperature_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp388_set_addr_pin(bmp388_handle_t *handle, bmp388_address_t addr_pin)
set the iic address pin
bmp388_address_t
bmp388 address enumeration definition
@ BMP388_BOOL_TRUE
@ BMP388_BOOL_FALSE
@ BMP388_MODE_SLEEP_MODE
@ BMP388_MODE_NORMAL_MODE
#define BMP388_INTERRUPT_DEFAULT_PRESSURE
#define BMP388_INTERRUPT_DEFAULT_TEMPERATURE
#define BMP388_INTERRUPT_DEFAULT_INTERRUPT_PIN_TYPE
#define BMP388_INTERRUPT_DEFAULT_IIC_WATCHDOG_TIMER
uint8_t bmp388_interrupt_irq_handler(void)
interrupt example irq handler
#define BMP388_INTERRUPT_DEFAULT_ODR
#define BMP388_INTERRUPT_DEFAULT_IIC_WATCHDOG_PERIOD
#define BMP388_INTERRUPT_DEFAULT_INTERRUPT_ACTIVE_LEVEL
#define BMP388_INTERRUPT_DEFAULT_SPI_WIRE
bmp388 interrupt example default definition
uint8_t bmp388_interrupt_init(bmp388_interface_t interface, bmp388_address_t addr_pin, void(*interrupt_receive_callback)(uint8_t type))
interrupt example init
uint8_t bmp388_interrupt_read(float *temperature_c, float *pressure_pa)
interrupt example read
uint8_t bmp388_interrupt_deinit(void)
interrupt example deinit
#define BMP388_INTERRUPT_DEFAULT_PRESSURE_OVERSAMPLING
#define BMP388_INTERRUPT_DEFAULT_FILTER_COEFFICIENT
#define BMP388_INTERRUPT_DEFAULT_TEMPERATURE_OVERSAMPLING
uint8_t bmp388_set_fifo(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo
uint8_t bmp388_interface_spi_init(void)
interface spi bus init
void bmp388_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp388_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp388_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp388_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmp388_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp388_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp388_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp388_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp388_interface_iic_init(void)
interface iic bus init
uint8_t bmp388_set_interrupt_fifo_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp388_set_interrupt_fifo_watermark(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp388_set_interrupt_data_ready(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp388_set_interrupt_active_level(bmp388_handle_t *handle, bmp388_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp388_set_interrupt_pin_type(bmp388_handle_t *handle, bmp388_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp388_set_latch_interrupt_pin_and_interrupt_status(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable latching interrupt pin and interrupt status