LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388_basic.c
Go to the documentation of this file.
1
37
38#include "driver_bmp388_basic.h"
39
40static bmp388_handle_t gs_handle;
41
52{
53 uint8_t res;
54
55 /* link functions */
68
69 /* set interface */
70 res = bmp388_set_interface(&gs_handle, interface);
71 if (res != 0)
72 {
73 bmp388_interface_debug_print("bmp388: set interface failed.\n");
74
75 return 1;
76 }
77
78 /* set addr pin */
79 res = bmp388_set_addr_pin(&gs_handle, addr_pin);
80 if (res != 0)
81 {
82 bmp388_interface_debug_print("bmp388: set addr pin failed.\n");
83
84 return 1;
85 }
86
87 /* bmp388 init */
88 res = bmp388_init(&gs_handle);
89 if (res != 0)
90 {
91 bmp388_interface_debug_print("bmp388: init failed.\n");
92
93 return 1;
94 }
95
96 /* set default spi wire */
98 if (res != 0)
99 {
100 bmp388_interface_debug_print("bmp388: set spi wire failed.\n");
101 (void)bmp388_deinit(&gs_handle);
102
103 return 1;
104 }
105
106 /* set default iic watchdog timer */
108 if (res != 0)
109 {
110 bmp388_interface_debug_print("bmp388: set iic watchdog timer failed.\n");
111 (void)bmp388_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* set default iic watchdog period */
118 if (res != 0)
119 {
120 bmp388_interface_debug_print("bmp388: set iic watchdog period failed.\n");
121 (void)bmp388_deinit(&gs_handle);
122
123 return 1;
124 }
125
126 /* disable fifo */
127 res = bmp388_set_fifo(&gs_handle, BMP388_BOOL_FALSE);
128 if (res != 0)
129 {
130 bmp388_interface_debug_print("bmp388: set fifo failed.\n");
131 (void)bmp388_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* disable interrupt fifo watermark */
138 if (res != 0)
139 {
140 bmp388_interface_debug_print("bmp388: set interrupt fifo watermark failed.\n");
141 (void)bmp388_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* disable interrupt fifo full */
148 if (res != 0)
149 {
150 bmp388_interface_debug_print("bmp388: set interrupt fifo full failed.\n");
151 (void)bmp388_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 /* disable interrupt data ready */
158 if (res != 0)
159 {
160 bmp388_interface_debug_print("bmp388: set interrupt data ready failed.\n");
161 (void)bmp388_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* set default pressure */
168 if (res != 0)
169 {
170 bmp388_interface_debug_print("bmp388: set pressure failed.\n");
171 (void)bmp388_deinit(&gs_handle);
172
173 return 1;
174 }
175
176 /* set default temperature */
178 if (res != 0)
179 {
180 bmp388_interface_debug_print("bmp388: set temperature failed.\n");
181 (void)bmp388_deinit(&gs_handle);
182
183 return 1;
184 }
185
186 /* set default pressure oversampling */
188 if (res != 0)
189 {
190 bmp388_interface_debug_print("bmp388: set pressure oversampling failed.\n");
191 (void)bmp388_deinit(&gs_handle);
192
193 return 1;
194 }
195
196 /* set default temperature oversampling */
198 if (res != 0)
199 {
200 bmp388_interface_debug_print("bmp388: set temperature oversampling failed.\n");
201 (void)bmp388_deinit(&gs_handle);
202
203 return 1;
204 }
205
206 /* set default odr */
207 res = bmp388_set_odr(&gs_handle, BMP388_BASIC_DEFAULT_ODR);
208 if (res != 0)
209 {
210 bmp388_interface_debug_print("bmp388: set odr failed.\n");
211 (void)bmp388_deinit(&gs_handle);
212
213 return 1;
214 }
215
216 /* set default filter coefficient */
218 if (res != 0)
219 {
220 bmp388_interface_debug_print("bmp388: set filter coefficient failed.\n");
221 (void)bmp388_deinit(&gs_handle);
222
223 return 1;
224 }
225
226 /* set default mode */
227 res = bmp388_set_mode(&gs_handle, BMP388_MODE_NORMAL_MODE);
228 if (res != 0)
229 {
230 bmp388_interface_debug_print("bmp388: set mode failed.\n");
231 (void)bmp388_deinit(&gs_handle);
232
233 return 1;
234 }
235
236 return 0;
237}
238
248uint8_t bmp388_basic_read(float *temperature_c, float *pressure_pa)
249{
250 uint32_t temperature_raw;
251 uint32_t pressure_raw;
252
253 /* read temperature and pressure */
254 if (bmp388_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, temperature_c,
255 (uint32_t *)&pressure_raw, pressure_pa) != 0)
256 {
257 return 1;
258 }
259 else
260 {
261 return 0;
262 }
263}
264
273{
274 /* close bmp388 */
275 if (bmp388_deinit(&gs_handle) != 0)
276 {
277 return 1;
278 }
279 else
280 {
281 return 0;
282 }
283}
driver bmp388 basic 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_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_FALSE
@ BMP388_MODE_NORMAL_MODE
#define BMP388_BASIC_DEFAULT_FILTER_COEFFICIENT
#define BMP388_BASIC_DEFAULT_PRESSURE
#define BMP388_BASIC_DEFAULT_ODR
uint8_t bmp388_basic_init(bmp388_interface_t interface, bmp388_address_t addr_pin)
basic example init
#define BMP388_BASIC_DEFAULT_IIC_WATCHDOG_PERIOD
#define BMP388_BASIC_DEFAULT_IIC_WATCHDOG_TIMER
#define BMP388_BASIC_DEFAULT_PRESSURE_OVERSAMPLING
uint8_t bmp388_basic_deinit(void)
basic example deinit
#define BMP388_BASIC_DEFAULT_SPI_WIRE
bmp388 basic example default definition
#define BMP388_BASIC_DEFAULT_TEMPERATURE
uint8_t bmp388_basic_read(float *temperature_c, float *pressure_pa)
basic example read
#define BMP388_BASIC_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
void bmp388_interface_receive_callback(uint8_t type)
interface receive callback
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