LibDriver BMM150
Loading...
Searching...
No Matches
driver_bmm150_interrupt.c
Go to the documentation of this file.
1
36
38
39static bmm150_handle_t gs_handle;
40
49{
50 if (bmm150_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54
55 return 0;
56}
57
71 float low_threshold_ut, float high_threshold_ut, void (*callback)(uint8_t type))
72{
73 uint8_t res;
74 int8_t reg;
75 bmm150_bool_t enable;
76
77 /* link interface function */
89 DRIVER_BMM150_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
90
91 /* set the interface */
92 res = bmm150_set_interface(&gs_handle, interface);
93 if (res != 0)
94 {
95 bmm150_interface_debug_print("bmm150: set interface failed.\n");
96
97 return 1;
98 }
99
100 /* set addr pin */
101 res = bmm150_set_addr_pin(&gs_handle, addr_pin);
102 if (res != 0)
103 {
104 bmm150_interface_debug_print("bmm150: set addr pin failed.\n");
105
106 return 1;
107 }
108
109 /* bmm150 initialization */
110 res = bmm150_init(&gs_handle);
111 if (res != 0)
112 {
113 bmm150_interface_debug_print("bmm150: init failed.\n");
114
115 return 1;
116 }
117
118 /* power on */
119 res = bmm150_set_power_on(&gs_handle, BMM150_BOOL_TRUE);
120 if (res != 0)
121 {
122 bmm150_interface_debug_print("bmm150: set power on failed.\n");
123 (void)bmm150_deinit(&gs_handle);
124
125 return 1;
126 }
127
128 /* set advanced self test normal mode */
130 if (res != 0)
131 {
132 bmm150_interface_debug_print("bmm150: set advanced self test failed.\n");
133 (void)bmm150_deinit(&gs_handle);
134
135 return 1;
136 }
137
138 /* disable self test */
139 res = bmm150_set_self_test(&gs_handle, BMM150_BOOL_FALSE);
140 if (res != 0)
141 {
142 bmm150_interface_debug_print("bmm150: set self test failed.\n");
143 (void)bmm150_deinit(&gs_handle);
144
145 return 1;
146 }
147
148 /* set default data overrun */
150 if (res != 0)
151 {
152 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
153 (void)bmm150_deinit(&gs_handle);
154
155 return 1;
156 }
157
158 /* set default overflow */
160 if (res != 0)
161 {
162 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
163 (void)bmm150_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* set default high threshold z */
170 if (res != 0)
171 {
172 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
173 (void)bmm150_deinit(&gs_handle);
174
175 return 1;
176 }
177
178 /* set default high threshold y */
180 if (res != 0)
181 {
182 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
183 (void)bmm150_deinit(&gs_handle);
184
185 return 1;
186 }
187
188 /* set default high threshold x */
190 if (res != 0)
191 {
192 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
193 (void)bmm150_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* set default low threshold z */
200 if (res != 0)
201 {
202 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
203 (void)bmm150_deinit(&gs_handle);
204
205 return 1;
206 }
207
208 /* set default low threshold y */
210 if (res != 0)
211 {
212 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
213 (void)bmm150_deinit(&gs_handle);
214
215 return 1;
216 }
217
218 /* set default low threshold x */
220 if (res != 0)
221 {
222 bmm150_interface_debug_print("bmm150: set interrupt failed.\n");
223 (void)bmm150_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* set default data ready pin */
230 if (res != 0)
231 {
232 bmm150_interface_debug_print("bmm150: set data ready pin failed.\n");
233 (void)bmm150_deinit(&gs_handle);
234
235 return 1;
236 }
237
238 /* set default interrupt pin */
240 if (res != 0)
241 {
242 bmm150_interface_debug_print("bmm150: set interrupt pin failed.\n");
243 (void)bmm150_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* set default data ready pin polarity */
250 if (res != 0)
251 {
252 bmm150_interface_debug_print("bmm150: set data ready pin polarity failed.\n");
253 (void)bmm150_deinit(&gs_handle);
254
255 return 1;
256 }
257
258 /* set default interrupt latch */
260 if (res != 0)
261 {
262 bmm150_interface_debug_print("bmm150: set interrupt latch failed.\n");
263 (void)bmm150_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 /* set default interrupt pin polarity */
270 if (res != 0)
271 {
272 bmm150_interface_debug_print("bmm150: set interrupt pin polarity failed.\n");
273 (void)bmm150_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* convert low threshold */
279 res = bmm150_interrupt_threshold_convert_to_register(&gs_handle, low_threshold_ut, &reg);
280 if (res != 0)
281 {
282 bmm150_interface_debug_print("bmm150: interrupt threshold convert to register failed.\n");
283 (void)bmm150_deinit(&gs_handle);
284
285 return 1;
286 }
287
288 /* set low threshold */
289 res = bmm150_set_low_threshold(&gs_handle, reg);
290 if (res != 0)
291 {
292 bmm150_interface_debug_print("bmm150: set low threshold failed.\n");
293 (void)bmm150_deinit(&gs_handle);
294
295 return 1;
296 }
297
298 /* convert high threshold */
299 res = bmm150_interrupt_threshold_convert_to_register(&gs_handle, high_threshold_ut, &reg);
300 if (res != 0)
301 {
302 bmm150_interface_debug_print("bmm150: interrupt threshold convert to register failed.\n");
303 (void)bmm150_deinit(&gs_handle);
304
305 return 1;
306 }
307
308 /* set high threshold */
309 res = bmm150_set_high_threshold(&gs_handle, reg);
310 if (res != 0)
311 {
312 bmm150_interface_debug_print("bmm150: set high threshold failed.\n");
313 (void)bmm150_deinit(&gs_handle);
314
315 return 1;
316 }
317
318 /* enable channel z */
319 res = bmm150_set_channel_z(&gs_handle, BMM150_BOOL_TRUE);
320 if (res != 0)
321 {
322 bmm150_interface_debug_print("bmm150: set channel z failed.\n");
323 (void)bmm150_deinit(&gs_handle);
324
325 return 1;
326 }
327
328 /* enable channel y */
329 res = bmm150_set_channel_y(&gs_handle, BMM150_BOOL_TRUE);
330 if (res != 0)
331 {
332 bmm150_interface_debug_print("bmm150: set channel y failed.\n");
333 (void)bmm150_deinit(&gs_handle);
334
335 return 1;
336 }
337
338 /* enable channel x */
339 res = bmm150_set_channel_x(&gs_handle, BMM150_BOOL_TRUE);
340 if (res != 0)
341 {
342 bmm150_interface_debug_print("bmm150: set channel x failed.\n");
343 (void)bmm150_deinit(&gs_handle);
344
345 return 1;
346 }
347
348 /* set default repxy number */
350 if (res != 0)
351 {
352 bmm150_interface_debug_print("bmm150: set repxy number failed.\n");
353 (void)bmm150_deinit(&gs_handle);
354
355 return 1;
356 }
357
358 /* set default repz number */
360 if (res != 0)
361 {
362 bmm150_interface_debug_print("bmm150: set repz number failed.\n");
363 (void)bmm150_deinit(&gs_handle);
364
365 return 1;
366 }
367
368 /* set default data rate */
370 if (res != 0)
371 {
372 bmm150_interface_debug_print("bmm150: set data rate failed.\n");
373 (void)bmm150_deinit(&gs_handle);
374
375 return 1;
376 }
377
378 /* set normal mode */
379 res = bmm150_set_mode(&gs_handle, BMM150_MODE_NORMAL);
380 if (res != 0)
381 {
382 bmm150_interface_debug_print("bmm150: set mode failed.\n");
383 (void)bmm150_deinit(&gs_handle);
384
385 return 1;
386 }
387
388 /* clear interrupt status */
390 if (res != 0)
391 {
392 bmm150_interface_debug_print("bmm150: get interrupt status failed.\n");
393 (void)bmm150_deinit(&gs_handle);
394
395 return 1;
396 }
397
398 return 0;
399}
400
409uint8_t bmm150_interrupt_read(float ut[3])
410{
411 int16_t raw[3];
412
413 /* read data */
414 if (bmm150_read(&gs_handle, raw, ut) != 0)
415 {
416 return 1;
417 }
418
419 return 0;
420}
421
430{
431 /* set sleep mode */
432 if (bmm150_set_mode(&gs_handle, BMM150_MODE_SLEEP) != 0)
433 {
434 return 1;
435 }
436
437 /* deinit */
438 if (bmm150_deinit(&gs_handle) != 0)
439 {
440 return 1;
441 }
442
443 return 0;
444}
driver bmm150 interrupt header file
uint8_t bmm150_deinit(bmm150_handle_t *handle)
close the chip
uint8_t bmm150_init(bmm150_handle_t *handle)
initialize the chip
uint8_t bmm150_set_data_ready_pin(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable data ready pin
uint8_t bmm150_set_repz_number(bmm150_handle_t *handle, uint8_t number)
set repz number
uint8_t bmm150_set_interrupt_pin(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable interrupt pin
uint8_t bmm150_set_addr_pin(bmm150_handle_t *handle, bmm150_address_t addr_pin)
set the iic address pin
uint8_t bmm150_set_advanced_self_test(bmm150_handle_t *handle, bmm150_advanced_self_test_t test)
set advanced self test
uint8_t bmm150_set_data_ready_pin_polarity(bmm150_handle_t *handle, bmm150_data_ready_pin_polarity_t polarity)
set data ready pin polarity
uint8_t bmm150_set_interrupt_pin_polarity(bmm150_handle_t *handle, bmm150_interrupt_pin_polarity_t polarity)
set interrupt pin polarity
uint8_t bmm150_set_interface(bmm150_handle_t *handle, bmm150_interface_t interface)
set the chip interface
bmm150_interface_t
bmm150 interface enumeration definition
uint8_t bmm150_set_high_threshold(bmm150_handle_t *handle, int8_t threshold)
set high threshold
uint8_t bmm150_irq_handler(bmm150_handle_t *handle)
irq handler
uint8_t bmm150_set_channel_y(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel y
bmm150_bool_t
bmm150 bool enumeration definition
uint8_t bmm150_set_mode(bmm150_handle_t *handle, bmm150_mode_t mode)
set mode
uint8_t bmm150_set_power_on(bmm150_handle_t *handle, bmm150_bool_t enable)
set power on
uint8_t bmm150_set_low_threshold(bmm150_handle_t *handle, int8_t threshold)
set low threshold
uint8_t bmm150_get_interrupt_status(bmm150_handle_t *handle, bmm150_interrupt_status_t status, bmm150_bool_t *enable)
get interrupt status
struct bmm150_handle_s bmm150_handle_t
bmm150 handle structure definition
uint8_t bmm150_set_self_test(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable self test
uint8_t bmm150_set_interrupt_latch(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable interrupt latch
uint8_t bmm150_read(bmm150_handle_t *handle, int16_t raw[3], float ut[3])
read data
uint8_t bmm150_set_channel_z(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel z
uint8_t bmm150_set_repxy_number(bmm150_handle_t *handle, uint8_t number)
set repxy number
bmm150_address_t
bmm150 address enumeration definition
uint8_t bmm150_set_interrupt(bmm150_handle_t *handle, bmm150_interrupt_status_t status, bmm150_bool_t enable)
enable or disable interrupt
uint8_t bmm150_interrupt_threshold_convert_to_register(bmm150_handle_t *handle, float ut, int8_t *reg)
convert the interrupt threshold to the register raw data
uint8_t bmm150_set_data_rate(bmm150_handle_t *handle, bmm150_data_rate_t rate)
set data rate
uint8_t bmm150_set_channel_x(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel x
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y
@ BMM150_INTERRUPT_STATUS_OVERFLOW
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y
@ BMM150_INTERRUPT_STATUS_DATA_OVERRUN
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X
@ BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X
@ BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z
@ BMM150_BOOL_FALSE
@ BMM150_BOOL_TRUE
@ BMM150_ADVANCED_SELF_TEST_NORMAL
@ BMM150_MODE_SLEEP
@ BMM150_MODE_NORMAL
#define BMM150_INTERRUPT_DEFAULT_REPZ
#define BMM150_INTERRUPT_DEFAULT_DATA_READY_PIN_POLARITY
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_HIGH_THRESHOLD_Z
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_LOW_THRESHOLD_Y
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_PIN_POLARITY
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_OVERFLOW
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_DATA_OVERRUN
bmm150 interrupt example default definition
uint8_t bmm150_interrupt_irq_handler(void)
interrupt irq
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_LOW_THRESHOLD_Z
uint8_t bmm150_interrupt_init(bmm150_interface_t interface, bmm150_address_t addr_pin, float low_threshold_ut, float high_threshold_ut, void(*callback)(uint8_t type))
interrupt example init
uint8_t bmm150_interrupt_deinit(void)
interrupt example deinit
#define BMM150_INTERRUPT_DEFAULT_REPXY
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_HIGH_THRESHOLD_X
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_PIN
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_HIGH_THRESHOLD_Y
#define BMM150_INTERRUPT_DEFAULT_DATA_RATE
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_LATCH
#define BMM150_INTERRUPT_DEFAULT_INTERRUPT_LOW_THRESHOLD_X
#define BMM150_INTERRUPT_DEFAULT_DATA_READY_PIN
uint8_t bmm150_interrupt_read(float ut[3])
interrupt example read
uint8_t bmm150_interface_spi_init(void)
interface spi bus init
uint8_t bmm150_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmm150_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmm150_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmm150_interface_iic_init(void)
interface iic bus init
uint8_t bmm150_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmm150_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t bmm150_interface_iic_deinit(void)
interface iic bus deinit
void bmm150_interface_debug_print(const char *const fmt,...)
interface print format data
void bmm150_interface_delay_ms(uint32_t ms)
interface delay ms