LibDriver BMP390
Loading...
Searching...
No Matches
driver_bmp390_basic.c
Go to the documentation of this file.
1
36
37#include "driver_bmp390_basic.h"
38
39static bmp390_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link functions */
67
68 /* set interface */
69 res = bmp390_set_interface(&gs_handle, interface);
70 if (res != 0)
71 {
72 bmp390_interface_debug_print("bmp390: set interface failed.\n");
73
74 return 1;
75 }
76
77 /* set addr pin */
78 res = bmp390_set_addr_pin(&gs_handle, addr_pin);
79 if (res != 0)
80 {
81 bmp390_interface_debug_print("bmp390: set addr pin failed.\n");
82
83 return 1;
84 }
85
86 /* bmp390 init */
87 res = bmp390_init(&gs_handle);
88 if (res != 0)
89 {
90 bmp390_interface_debug_print("bmp390: init failed.\n");
91
92 return 1;
93 }
94
95 /* set default spi wire */
97 if (res != 0)
98 {
99 bmp390_interface_debug_print("bmp390: set spi wire failed.\n");
100 (void)bmp390_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 /* set default iic watchdog timer */
107 if (res != 0)
108 {
109 bmp390_interface_debug_print("bmp390: set iic watchdog timer failed.\n");
110 (void)bmp390_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set default iic watchdog period */
117 if (res != 0)
118 {
119 bmp390_interface_debug_print("bmp390: set iic watchdog period failed.\n");
120 (void)bmp390_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* disable fifo */
126 res = bmp390_set_fifo(&gs_handle, BMP390_BOOL_FALSE);
127 if (res != 0)
128 {
129 bmp390_interface_debug_print("bmp390: set fifo failed.\n");
130 (void)bmp390_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* disable interrupt fifo watermark */
137 if (res != 0)
138 {
139 bmp390_interface_debug_print("bmp390: set interrupt fifo watermark failed.\n");
140 (void)bmp390_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* disable interrupt fifo full */
147 if (res != 0)
148 {
149 bmp390_interface_debug_print("bmp390: set interrupt fifo full failed.\n");
150 (void)bmp390_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* disable interrupt data ready */
157 if (res != 0)
158 {
159 bmp390_interface_debug_print("bmp390: set interrupt data ready failed.\n");
160 (void)bmp390_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* set default pressure */
167 if (res != 0)
168 {
169 bmp390_interface_debug_print("bmp390: set pressure failed.\n");
170 (void)bmp390_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* set default temperature */
177 if (res != 0)
178 {
179 bmp390_interface_debug_print("bmp390: set temperature failed.\n");
180 (void)bmp390_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* set default pressure oversampling */
187 if (res != 0)
188 {
189 bmp390_interface_debug_print("bmp390: set pressure oversampling failed.\n");
190 (void)bmp390_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* set default temperature oversampling */
197 if (res != 0)
198 {
199 bmp390_interface_debug_print("bmp390: set temperature oversampling failed.\n");
200 (void)bmp390_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* set default odr */
206 res = bmp390_set_odr(&gs_handle, BMP390_BASIC_DEFAULT_ODR);
207 if (res != 0)
208 {
209 bmp390_interface_debug_print("bmp390: set odr failed.\n");
210 (void)bmp390_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* set default filter coefficient */
217 if (res != 0)
218 {
219 bmp390_interface_debug_print("bmp390: set filter coefficient failed.\n");
220 (void)bmp390_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* set default mode */
226 res = bmp390_set_mode(&gs_handle, BMP390_MODE_NORMAL_MODE);
227 if (res != 0)
228 {
229 bmp390_interface_debug_print("bmp390: set mode failed.\n");
230 (void)bmp390_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 return 0;
236}
237
247uint8_t bmp390_basic_read(float *temperature_c, float *pressure_pa)
248{
249 uint32_t temperature_raw;
250 uint32_t pressure_raw;
251
252 /* read temperature and pressure */
253 if (bmp390_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, temperature_c,
254 (uint32_t *)&pressure_raw, pressure_pa) != 0)
255 {
256 return 1;
257 }
258 else
259 {
260 return 0;
261 }
262}
263
272{
273 /* close bmp390 */
274 if (bmp390_deinit(&gs_handle) != 0)
275 {
276 return 1;
277 }
278 else
279 {
280 return 0;
281 }
282}
driver bmp390 basic 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
uint8_t bmp390_read_temperature_pressure(bmp390_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
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_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_FALSE
@ BMP390_MODE_NORMAL_MODE
uint8_t bmp390_basic_init(bmp390_interface_t interface, bmp390_address_t addr_pin)
basic example init
#define BMP390_BASIC_DEFAULT_FILTER_COEFFICIENT
#define BMP390_BASIC_DEFAULT_TEMPERATURE
#define BMP390_BASIC_DEFAULT_SPI_WIRE
bmp390 basic example default definition
#define BMP390_BASIC_DEFAULT_PRESSURE_OVERSAMPLING
#define BMP390_BASIC_DEFAULT_TEMPERATURE_OVERSAMPLING
#define BMP390_BASIC_DEFAULT_ODR
#define BMP390_BASIC_DEFAULT_IIC_WATCHDOG_PERIOD
#define BMP390_BASIC_DEFAULT_IIC_WATCHDOG_TIMER
uint8_t bmp390_basic_read(float *temperature_c, float *pressure_pa)
basic example read
#define BMP390_BASIC_DEFAULT_PRESSURE
uint8_t bmp390_basic_deinit(void)
basic example deinit
uint8_t bmp390_set_fifo(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo
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_receive_callback(uint8_t type)
interface receive callback
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_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo full interrupt