LibDriver BMM150
Loading...
Searching...
No Matches
driver_bmm150.c
Go to the documentation of this file.
1
36
37#include "driver_bmm150.h"
38
42#define CHIP_NAME "Bosch BMM150"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.62f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 20.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define BMM150_REG_CHIP_ID 0x40
55#define BMM150_REG_DATA_X_LSB 0x42
56#define BMM150_REG_DATA_X_MSB 0x43
57#define BMM150_REG_DATA_Y_LSB 0x44
58#define BMM150_REG_DATA_Y_MSB 0x45
59#define BMM150_REG_DATA_Z_LSB 0x46
60#define BMM150_REG_DATA_Z_MSB 0x47
61#define BMM150_REG_RHALL_LSB 0x48
62#define BMM150_REG_RHALL_MSB 0x49
63#define BMM150_REG_INTERRUPT_STATUS 0x4A
64#define BMM150_REG_CONFIG_0 0x4B
65#define BMM150_REG_CONFIG_1 0x4C
66#define BMM150_REG_CONFIG_2 0x4D
67#define BMM150_REG_CONFIG_3 0x4E
68#define BMM150_REG_LOW_THRESHOLD 0x4F
69#define BMM150_REG_HIGH_THRESHOLD 0x50
70#define BMM150_REG_REPXY 0x51
71#define BMM150_REG_REPZ 0x52
72
76#define BMM150_REG_DIG_X1 0x5D
77#define BMM150_REG_DIG_Y1 0x5E
78#define BMM150_REG_DIG_Z4_LSB 0x62
79#define BMM150_REG_DIG_Z4_MSB 0x63
80#define BMM150_REG_DIG_X2 0x64
81#define BMM150_REG_DIG_Y2 0x65
82#define BMM150_REG_DIG_Z2_LSB 0x68
83#define BMM150_REG_DIG_Z2_MSB 0x69
84#define BMM150_REG_DIG_Z1_LSB 0x6A
85#define BMM150_REG_DIG_Z1_MSB 0x6B
86#define BMM150_REG_DIG_XYZ1_LSB 0x6C
87#define BMM150_REG_DIG_XYZ1_MSB 0x6D
88#define BMM150_REG_DIG_Z3_LSB 0x6E
89#define BMM150_REG_DIG_Z3_MSB 0x6F
90#define BMM150_REG_DIG_XY2 0x70
91#define BMM150_REG_DIG_XY1 0x71
92
104static uint8_t a_bmm150_iic_spi_read(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
105{
106 if (handle->iic_spi == (uint8_t)BMM150_INTERFACE_IIC) /* iic interface */
107 {
108 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* read data */
109 {
110 return 1; /* return error */
111 }
112
113 return 0; /* success return 0 */
114 }
115 else /* spi interface */
116 {
117 reg |= 1 << 7; /* flag read */
118 if (handle->spi_read(reg, buf, len) != 0) /* read data */
119 {
120 return 1; /* return error */
121 }
122
123 return 0; /* success return 0 */
124 }
125}
126
138static uint8_t a_bmm150_iic_spi_write(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
139{
140 if (handle->iic_spi == (uint8_t)BMM150_INTERFACE_IIC) /* iic interface */
141 {
142 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* write data */
143 {
144 return 1; /* return error */
145 }
146
147 return 0; /* success return 0 */
148 }
149 else /* spi interface */
150 {
151 reg &= ~(1 << 7); /* flag write */
152 if (handle->spi_write(reg, buf, len) != 0) /* write data */
153 {
154 return 1; /* return error */
155 }
156
157 return 0; /* success return 0 */
158 }
159}
160
169static uint8_t a_bmm150_load_trim(bmm150_handle_t *handle)
170{
171 uint8_t res;
172 uint8_t trim_x1y1[2];
173 uint8_t trim_xyz_data[4];
174 uint8_t trim_xy1xy2[10];
175 uint16_t temp_msb = 0;
176
177 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DIG_X1, trim_x1y1, 2); /* read part 0 */
178 if (res != 0) /* check the result */
179 {
180 handle->debug_print("bmm150: read dig x1 failed.\n"); /* read dig x1 failed */
181
182 return 1; /* return error */
183 }
184 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DIG_Z4_LSB, trim_xyz_data, 4); /* read part 1 */
185 if (res != 0) /* check the result */
186 {
187 handle->debug_print("bmm150: read dig z4 failed.\n"); /* read dig z4 failed */
188
189 return 1; /* return error */
190 }
191 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DIG_Z2_LSB, trim_xy1xy2, 10); /* read part 2 */
192 if (res != 0) /* check the result */
193 {
194 handle->debug_print("bmm150: read dig z2 failed.\n"); /* read dig z2 failed */
195
196 return 1; /* return error */
197 }
198 handle->dig_x1 = (int8_t)trim_x1y1[0]; /* set x1 */
199 handle->dig_y1 = (int8_t)trim_x1y1[1]; /* set y1 */
200 handle->dig_x2 = (int8_t)trim_xyz_data[2]; /* set x2 */
201 handle->dig_y2 = (int8_t)trim_xyz_data[3]; /* set y2 */
202 temp_msb = ((uint16_t)trim_xy1xy2[3]) << 8; /* set msb */
203 handle->dig_z1 = (uint16_t)(temp_msb | trim_xy1xy2[2]); /* set z1 */
204 temp_msb = ((uint16_t)trim_xy1xy2[1]) << 8; /* set msb */
205 handle->dig_z2 = (int16_t)(temp_msb | trim_xy1xy2[0]); /* set z2 */
206 temp_msb = ((uint16_t)trim_xy1xy2[7]) << 8; /* set msb */
207 handle->dig_z3 = (int16_t)(temp_msb | trim_xy1xy2[6]); /* set z3 */
208 temp_msb = ((uint16_t)trim_xyz_data[1]) << 8; /* set msb */
209 handle->dig_z4 = (int16_t)(temp_msb | trim_xyz_data[0]); /* set z4 */
210 handle->dig_xy1 = trim_xy1xy2[9]; /* set xy1 */
211 handle->dig_xy2 = (int8_t)trim_xy1xy2[8]; /* set xy2 */
212 temp_msb = ((uint16_t)(trim_xy1xy2[5] & 0x7F)) << 8; /* set msb */
213 handle->dig_xyz1 = (uint16_t)(temp_msb | trim_xy1xy2[4]); /* set xyz1 */
214
215 return 0; /* success return 0 */
216}
217
226static float a_bmm150_compensate_x(bmm150_handle_t *handle, int16_t mag_data_x, uint16_t data_rhall)
227{
228 float retval;
229 float process_comp_x0;
230 float process_comp_x1;
231 float process_comp_x2;
232 float process_comp_x3;
233 float process_comp_x4;
234
235 process_comp_x0 = (((float)handle->dig_xyz1) * 16384.0f / (float)data_rhall); /* calculate process comp x0 */
236 retval = (process_comp_x0 - 16384.0f); /* calculate retval */
237 process_comp_x1 = ((float)handle->dig_xy2) * (retval * retval / 268435456.0f); /* calculate process comp x1 */
238 process_comp_x2 = process_comp_x1 + retval * ((float)handle->dig_xy1) / 16384.0f; /* calculate process comp x2 */
239 process_comp_x3 = ((float)handle->dig_x2) + 160.0f; /* calculate process comp x3 */
240 process_comp_x4 = (float)mag_data_x * ((process_comp_x2 + 256.0f) * process_comp_x3); /* calculate process comp x4 */
241 retval = ((process_comp_x4 / 8192.0f) + (((float)handle->dig_x1) * 8.0f)) / 16.0f; /* calculate the final result */
242
243 return retval; /* return the final result */
244}
245
254static float a_bmm150_compensate_y(bmm150_handle_t *handle, int16_t mag_data_y, uint16_t data_rhall)
255{
256 float retval;
257 float process_comp_y0;
258 float process_comp_y1;
259 float process_comp_y2;
260 float process_comp_y3;
261 float process_comp_y4;
262
263 process_comp_y0 = ((float)handle->dig_xyz1) * 16384.0f / (float)data_rhall; /* calculate process comp y0 */
264 retval = process_comp_y0 - 16384.0f; /* calculate retval */
265 process_comp_y1 = ((float)handle->dig_xy2) * (retval * retval / 268435456.0f); /* calculate process comp y1 */
266 process_comp_y2 = process_comp_y1 + retval * ((float)handle->dig_xy1) / 16384.0f; /* calculate process comp y2 */
267 process_comp_y3 = ((float)handle->dig_y2) + 160.0f; /* calculate process comp y3 */
268 process_comp_y4 = (float)mag_data_y * (((process_comp_y2) + 256.0f) * process_comp_y3); /* calculate process comp y4 */
269 retval = ((process_comp_y4 / 8192.0f) + (((float)handle->dig_y1) * 8.0f)) / 16.0f; /* calculate the final result */
270
271 return retval; /* return the final result */
272}
273
282static float a_bmm150_compensate_z(bmm150_handle_t *handle, int16_t mag_data_z, uint16_t data_rhall)
283{
284 float retval;
285 float process_comp_z0;
286 float process_comp_z1;
287 float process_comp_z2;
288 float process_comp_z3;
289 float process_comp_z4;
290 float process_comp_z5;
291
292 process_comp_z0 = ((float)mag_data_z) - ((float)handle->dig_z4); /* calculate process comp z0 */
293 process_comp_z1 = ((float)data_rhall) - ((float)handle->dig_xyz1); /* calculate process comp z1 */
294 process_comp_z2 = (((float)handle->dig_z3) * process_comp_z1); /* calculate process comp z2 */
295 process_comp_z3 = ((float)handle->dig_z1) * ((float)data_rhall) / 32768.0f; /* calculate process comp z3 */
296 process_comp_z4 = ((float)handle->dig_z2) + process_comp_z3; /* calculate process comp z4 */
297 process_comp_z5 = (process_comp_z0 * 131072.0f) - process_comp_z2; /* calculate process comp z5 */
298 retval = (process_comp_z5 / ((process_comp_z4) * 4.0f)) / 16.0f; /* calculate the final result */
299
300 return retval; /* return the final result */
301}
302
311static uint8_t a_bmm150_close(bmm150_handle_t *handle)
312{
313 uint8_t prev;
314
315 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* read config */
316 {
317 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
318
319 return 1; /* return error */
320 }
321 prev &= ~(1 << 0); /* clear settings */
322 if (a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* write config */
323 {
324 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
325
326 return 1; /* return error */
327 }
328
329 if (handle->iic_spi == BMM150_INTERFACE_IIC) /* iic interface */
330 {
331 if (handle->iic_deinit() != 0) /* iic deinit */
332 {
333 handle->debug_print("bmm150: iic deinit failed.\n"); /* iic deinit failed */
334
335 return 1; /* return error */
336 }
337
338 return 0; /* success return 0 */
339 }
340 else /* spi interface */
341 {
342 if (handle->spi_deinit() != 0) /* spi deinit */
343 {
344 handle->debug_print("bmm150: spi deinit failed.\n"); /* spi deinit failed */
345
346 return 1; /* return error */
347 }
348
349 return 0; /* success return 0 */
350 }
351}
352
363{
364 if (handle == NULL) /* check handle */
365 {
366 return 2; /* return error */
367 }
368
369 handle->iic_spi = (uint8_t)interface; /* set interface */
370
371 return 0; /* success return 0 */
372}
373
384{
385 if (handle == NULL) /* check handle */
386 {
387 return 2; /* return error */
388 }
389
390 *interface = (bmm150_interface_t)(handle->iic_spi); /* get interface */
391
392 return 0; /* success return 0 */
393}
394
405{
406 if (handle == NULL) /* check handle */
407 {
408 return 2; /* return error */
409 }
410
411 handle->iic_addr = (uint8_t)addr_pin; /* set pin */
412
413 return 0; /* success return 0 */
414}
415
426{
427 if (handle == NULL) /* check handle */
428 {
429 return 2; /* return error */
430 }
431
432 *addr_pin = (bmm150_address_t)(handle->iic_addr); /* get pin */
433
434 return 0; /* success return 0 */
435}
436
449{
450 uint8_t res;
451 uint8_t prev;
452
453 if (handle == NULL) /* check handle */
454 {
455 return 2; /* return error */
456 }
457 if (handle->inited != 1) /* check handle initialization */
458 {
459 return 3; /* return error */
460 }
461
462 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_X_LSB, &prev, 1); /* read config */
463 if (res != 0) /* check the result */
464 {
465 handle->debug_print("bmm150: read data x failed.\n"); /* read data x failed */
466
467 return 1; /* return error */
468 }
469 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
470
471 return 0; /* success return 0 */
472}
473
486{
487 uint8_t res;
488 uint8_t prev;
489
490 if (handle == NULL) /* check handle */
491 {
492 return 2; /* return error */
493 }
494 if (handle->inited != 1) /* check handle initialization */
495 {
496 return 3; /* return error */
497 }
498
499 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_Y_LSB, &prev, 1); /* read config */
500 if (res != 0) /* check the result */
501 {
502 handle->debug_print("bmm150: read data y failed.\n"); /* read data y failed */
503
504 return 1; /* return error */
505 }
506 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
507
508 return 0; /* success return 0 */
509}
510
523{
524 uint8_t res;
525 uint8_t prev;
526
527 if (handle == NULL) /* check handle */
528 {
529 return 2; /* return error */
530 }
531 if (handle->inited != 1) /* check handle initialization */
532 {
533 return 3; /* return error */
534 }
535
536 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_Z_LSB, &prev, 1); /* read config */
537 if (res != 0) /* check the result */
538 {
539 handle->debug_print("bmm150: read data z failed.\n"); /* read data z failed */
540
541 return 1; /* return error */
542 }
543 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
544
545 return 0; /* success return 0 */
546}
547
560{
561 uint8_t res;
562 uint8_t prev;
563
564 if (handle == NULL) /* check handle */
565 {
566 return 2; /* return error */
567 }
568 if (handle->inited != 1) /* check handle initialization */
569 {
570 return 3; /* return error */
571 }
572
573 res = a_bmm150_iic_spi_read(handle, BMM150_REG_RHALL_LSB, &prev, 1); /* read config */
574 if (res != 0) /* check the result */
575 {
576 handle->debug_print("bmm150: read rhall failed.\n"); /* read rhall failed */
577
578 return 1; /* return error */
579 }
580 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
581
582 return 0; /* success return 0 */
583}
584
598{
599 uint8_t res;
600 uint8_t prev;
601
602 if (handle == NULL) /* check handle */
603 {
604 return 2; /* return error */
605 }
606 if (handle->inited != 1) /* check handle initialization */
607 {
608 return 3; /* return error */
609 }
610
611 res = a_bmm150_iic_spi_read(handle, BMM150_REG_INTERRUPT_STATUS, &prev, 1); /* read config */
612 if (res != 0) /* check the result */
613 {
614 handle->debug_print("bmm150: read interrupt status failed.\n"); /* read interrupt status failed */
615
616 return 1; /* return error */
617 }
618 *enable = (bmm150_bool_t)((prev >> (uint8_t)status) & 0x01); /* set bool */
619
620 return 0; /* success return 0 */
621}
622
634{
635 uint8_t res;
636 uint8_t prev;
637
638 if (handle == NULL) /* check handle */
639 {
640 return 2; /* return error */
641 }
642 if (handle->inited != 1) /* check handle initialization */
643 {
644 return 3; /* return error */
645 }
646
647 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
648 if (res != 0) /* check the result */
649 {
650 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
651
652 return 1; /* return error */
653 }
654 prev &= ~(1 << 1); /* clear settings */
655 prev |= 1 << 1; /* set bool */
656 prev &= ~(1 << 7); /* clear settings */
657 prev |= 1 << 7; /* set bool */
658 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
659 if (res != 0) /* check the result */
660 {
661 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
662
663 return 1; /* return error */
664 }
665 handle->delay_ms(5); /* delay 5ms */
666
667 return 0; /* success return 0 */
668}
669
682{
683 uint8_t res;
684 uint8_t prev;
685
686 if (handle == NULL) /* check handle */
687 {
688 return 2; /* return error */
689 }
690 if (handle->inited != 1) /* check handle initialization */
691 {
692 return 3; /* return error */
693 }
694
695 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
696 if (res != 0) /* check the result */
697 {
698 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
699
700 return 1; /* return error */
701 }
702 prev &= ~(1 << 0); /* clear settings */
703 prev |= enable << 0; /* set bool */
704 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
705 if (res != 0) /* check the result */
706 {
707 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
708
709 return 1; /* return error */
710 }
711 handle->delay_ms(5); /* delay 5ms */
712
713 return 0; /* success return 0 */
714}
715
728{
729 uint8_t res;
730 uint8_t prev;
731
732 if (handle == NULL) /* check handle */
733 {
734 return 2; /* return error */
735 }
736 if (handle->inited != 1) /* check handle initialization */
737 {
738 return 3; /* return error */
739 }
740
741 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
742 if (res != 0) /* check the result */
743 {
744 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
745
746 return 1; /* return error */
747 }
748 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
749
750 return 0; /* success return 0 */
751}
752
765{
766 uint8_t res;
767 uint8_t prev;
768
769 if (handle == NULL) /* check handle */
770 {
771 return 2; /* return error */
772 }
773 if (handle->inited != 1) /* check handle initialization */
774 {
775 return 3; /* return error */
776 }
777
778 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
779 if (res != 0) /* check the result */
780 {
781 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
782
783 return 1; /* return error */
784 }
785 prev &= ~(1 << 2); /* clear settings */
786 prev |= wire << 2; /* set wire */
787 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
788 if (res != 0) /* check the result */
789 {
790 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
791
792 return 1; /* return error */
793 }
794
795 return 0; /* success return 0 */
796}
797
810{
811 uint8_t res;
812 uint8_t prev;
813
814 if (handle == NULL) /* check handle */
815 {
816 return 2; /* return error */
817 }
818 if (handle->inited != 1) /* check handle initialization */
819 {
820 return 3; /* return error */
821 }
822
823 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
824 if (res != 0) /* check the result */
825 {
826 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
827
828 return 1; /* return error */
829 }
830 *wire = (bmm150_spi_wire_t)((prev >> 2) & 0x01); /* set wire */
831
832 return 0; /* success return 0 */
833}
834
847{
848 uint8_t res;
849 uint8_t prev;
850
851 if (handle == NULL) /* check handle */
852 {
853 return 2; /* return error */
854 }
855 if (handle->inited != 1) /* check handle initialization */
856 {
857 return 3; /* return error */
858 }
859
860 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
861 if (res != 0) /* check the result */
862 {
863 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
864
865 return 1; /* return error */
866 }
867 prev &= ~(3 << 6); /* clear settings */
868 prev |= test << 6; /* set test */
869 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
870 if (res != 0) /* check the result */
871 {
872 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
873
874 return 1; /* return error */
875 }
876
877 return 0; /* success return 0 */
878}
879
892{
893 uint8_t res;
894 uint8_t prev;
895
896 if (handle == NULL) /* check handle */
897 {
898 return 2; /* return error */
899 }
900 if (handle->inited != 1) /* check handle initialization */
901 {
902 return 3; /* return error */
903 }
904
905 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
906 if (res != 0) /* check the result */
907 {
908 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
909
910 return 1; /* return error */
911 }
912 *test = (bmm150_advanced_self_test_t)((prev >> 6) & 0x03); /* set test */
913
914 return 0; /* success return 0 */
915}
916
929{
930 uint8_t res;
931 uint8_t prev;
932
933 if (handle == NULL) /* check handle */
934 {
935 return 2; /* return error */
936 }
937 if (handle->inited != 1) /* check handle initialization */
938 {
939 return 3; /* return error */
940 }
941
942 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
943 if (res != 0) /* check the result */
944 {
945 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
946
947 return 1; /* return error */
948 }
949 prev &= ~(7 << 3); /* clear settings */
950 prev |= rate << 3; /* set rate */
951 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
952 if (res != 0) /* check the result */
953 {
954 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
955
956 return 1; /* return error */
957 }
958
959 return 0; /* success return 0 */
960}
961
974{
975 uint8_t res;
976 uint8_t prev;
977
978 if (handle == NULL) /* check handle */
979 {
980 return 2; /* return error */
981 }
982 if (handle->inited != 1) /* check handle initialization */
983 {
984 return 3; /* return error */
985 }
986
987 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
988 if (res != 0) /* check the result */
989 {
990 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
991
992 return 1; /* return error */
993 }
994 *rate = (bmm150_data_rate_t)((prev >> 3) & 0x07); /* set rate */
995
996 return 0; /* success return 0 */
997}
998
1011{
1012 uint8_t res;
1013 uint8_t prev;
1014
1015 if (handle == NULL) /* check handle */
1016 {
1017 return 2; /* return error */
1018 }
1019 if (handle->inited != 1) /* check handle initialization */
1020 {
1021 return 3; /* return error */
1022 }
1023
1024 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1025 if (res != 0) /* check the result */
1026 {
1027 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1028
1029 return 1; /* return error */
1030 }
1031 prev &= ~(3 << 1); /* clear settings */
1032 prev |= mode << 1; /* set mode */
1033 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
1034 if (res != 0) /* check the result */
1035 {
1036 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
1037
1038 return 1; /* return error */
1039 }
1040
1041 return 0; /* success return 0 */
1042}
1043
1056{
1057 uint8_t res;
1058 uint8_t prev;
1059
1060 if (handle == NULL) /* check handle */
1061 {
1062 return 2; /* return error */
1063 }
1064 if (handle->inited != 1) /* check handle initialization */
1065 {
1066 return 3; /* return error */
1067 }
1068
1069 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1070 if (res != 0) /* check the result */
1071 {
1072 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1073
1074 return 1; /* return error */
1075 }
1076 *mode = (bmm150_mode_t)((prev >> 1) & 0x03); /* set mode */
1077
1078 return 0; /* success return 0 */
1079}
1080
1093{
1094 uint8_t res;
1095 uint8_t prev;
1096
1097 if (handle == NULL) /* check handle */
1098 {
1099 return 2; /* return error */
1100 }
1101 if (handle->inited != 1) /* check handle initialization */
1102 {
1103 return 3; /* return error */
1104 }
1105
1106 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1107 if (res != 0) /* check the result */
1108 {
1109 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1110
1111 return 1; /* return error */
1112 }
1113 prev &= ~(1 << 0); /* clear settings */
1114 prev |= enable << 0; /* set bool */
1115 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
1116 if (res != 0) /* check the result */
1117 {
1118 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
1119
1120 return 1; /* return error */
1121 }
1122
1123 return 0; /* success return 0 */
1124}
1125
1138{
1139 uint8_t res;
1140 uint8_t prev;
1141
1142 if (handle == NULL) /* check handle */
1143 {
1144 return 2; /* return error */
1145 }
1146 if (handle->inited != 1) /* check handle initialization */
1147 {
1148 return 3; /* return error */
1149 }
1150
1151 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1152 if (res != 0) /* check the result */
1153 {
1154 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1155
1156 return 1; /* return error */
1157 }
1158 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
1159
1160 return 0; /* success return 0 */
1161}
1162
1176{
1177 uint8_t res;
1178 uint8_t prev;
1179
1180 if (handle == NULL) /* check handle */
1181 {
1182 return 2; /* return error */
1183 }
1184 if (handle->inited != 1) /* check handle initialization */
1185 {
1186 return 3; /* return error */
1187 }
1188
1189 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_2, &prev, 1); /* read config */
1190 if (res != 0) /* check the result */
1191 {
1192 handle->debug_print("bmm150: read config 2 failed.\n"); /* read config 2 failed */
1193
1194 return 1; /* return error */
1195 }
1196 prev &= ~(1 << (uint8_t)status); /* clear settings */
1197 if (status >= (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) /* index >= 6 */
1198 {
1199 prev |= enable << (uint8_t)status; /* set bool */
1200 }
1201 else /* index < 6 */
1202 {
1203 prev |= (uint8_t)(!enable) << (uint8_t)status; /* set bool */
1204 }
1205 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_2, &prev, 1); /* write config */
1206 if (res != 0) /* check the result */
1207 {
1208 handle->debug_print("bmm150: write config 2 failed.\n"); /* write config 2 failed */
1209
1210 return 1; /* return error */
1211 }
1212
1213 return 0; /* success return 0 */
1214}
1215
1229{
1230 uint8_t res;
1231 uint8_t prev;
1232
1233 if (handle == NULL) /* check handle */
1234 {
1235 return 2; /* return error */
1236 }
1237 if (handle->inited != 1) /* check handle initialization */
1238 {
1239 return 3; /* return error */
1240 }
1241
1242 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_2, &prev, 1); /* read config */
1243 if (res != 0) /* check the result */
1244 {
1245 handle->debug_print("bmm150: read config 2 failed.\n"); /* read config 2 failed */
1246
1247 return 1; /* return error */
1248 }
1249 if (status >= (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) /* index >= 6 */
1250 {
1251 *enable = (bmm150_bool_t)((prev >> (uint8_t)(status)) & 0x01); /* set bool */
1252 }
1253 else /* index < 6 */
1254 {
1255 *enable = (bmm150_bool_t)(!((prev >> (uint8_t)(status)) & 0x01)); /* set bool */
1256 }
1257
1258 return 0; /* success return 0 */
1259}
1260
1273{
1274 uint8_t res;
1275 uint8_t prev;
1276
1277 if (handle == NULL) /* check handle */
1278 {
1279 return 2; /* return error */
1280 }
1281 if (handle->inited != 1) /* check handle initialization */
1282 {
1283 return 3; /* return error */
1284 }
1285
1286 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1287 if (res != 0) /* check the result */
1288 {
1289 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1290
1291 return 1; /* return error */
1292 }
1293 prev &= ~(1 << 7); /* clear settings */
1294 prev |= enable << 7; /* set bool */
1295 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1296 if (res != 0) /* check the result */
1297 {
1298 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1299
1300 return 1; /* return error */
1301 }
1302
1303 return 0; /* success return 0 */
1304}
1305
1318{
1319 uint8_t res;
1320 uint8_t prev;
1321
1322 if (handle == NULL) /* check handle */
1323 {
1324 return 2; /* return error */
1325 }
1326 if (handle->inited != 1) /* check handle initialization */
1327 {
1328 return 3; /* return error */
1329 }
1330
1331 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1332 if (res != 0) /* check the result */
1333 {
1334 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1335
1336 return 1; /* return error */
1337 }
1338 *enable = (bmm150_bool_t)((prev >> 7) & 0x01); /* set bool */
1339
1340 return 0; /* success return 0 */
1341}
1342
1355{
1356 uint8_t res;
1357 uint8_t prev;
1358
1359 if (handle == NULL) /* check handle */
1360 {
1361 return 2; /* return error */
1362 }
1363 if (handle->inited != 1) /* check handle initialization */
1364 {
1365 return 3; /* return error */
1366 }
1367
1368 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1369 if (res != 0) /* check the result */
1370 {
1371 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1372
1373 return 1; /* return error */
1374 }
1375 prev &= ~(1 << 6); /* clear settings */
1376 prev |= enable << 6; /* set bool */
1377 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1378 if (res != 0) /* check the result */
1379 {
1380 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1381
1382 return 1; /* return error */
1383 }
1384
1385 return 0; /* success return 0 */
1386}
1387
1400{
1401 uint8_t res;
1402 uint8_t prev;
1403
1404 if (handle == NULL) /* check handle */
1405 {
1406 return 2; /* return error */
1407 }
1408 if (handle->inited != 1) /* check handle initialization */
1409 {
1410 return 3; /* return error */
1411 }
1412
1413 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1414 if (res != 0) /* check the result */
1415 {
1416 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1417
1418 return 1; /* return error */
1419 }
1420 *enable = (bmm150_bool_t)((prev >> 6) & 0x01); /* set bool */
1421
1422 return 0; /* success return 0 */
1423}
1424
1437{
1438 uint8_t res;
1439 uint8_t prev;
1440
1441 if (handle == NULL) /* check handle */
1442 {
1443 return 2; /* return error */
1444 }
1445 if (handle->inited != 1) /* check handle initialization */
1446 {
1447 return 3; /* return error */
1448 }
1449
1450 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1451 if (res != 0) /* check the result */
1452 {
1453 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1454
1455 return 1; /* return error */
1456 }
1457 prev &= ~(1 << 5); /* clear settings */
1458 prev |= (uint8_t)(!enable) << 5; /* set bool */
1459 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1460 if (res != 0) /* check the result */
1461 {
1462 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1463
1464 return 1; /* return error */
1465 }
1466
1467 return 0; /* success return 0 */
1468}
1469
1482{
1483 uint8_t res;
1484 uint8_t prev;
1485
1486 if (handle == NULL) /* check handle */
1487 {
1488 return 2; /* return error */
1489 }
1490 if (handle->inited != 1) /* check handle initialization */
1491 {
1492 return 3; /* return error */
1493 }
1494
1495 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1496 if (res != 0) /* check the result */
1497 {
1498 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1499
1500 return 1; /* return error */
1501 }
1502 *enable = (bmm150_bool_t)(!((prev >> 5) & 0x01)); /* set bool */
1503
1504 return 0; /* success return 0 */
1505}
1506
1519{
1520 uint8_t res;
1521 uint8_t prev;
1522
1523 if (handle == NULL) /* check handle */
1524 {
1525 return 2; /* return error */
1526 }
1527 if (handle->inited != 1) /* check handle initialization */
1528 {
1529 return 3; /* return error */
1530 }
1531
1532 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1533 if (res != 0) /* check the result */
1534 {
1535 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1536
1537 return 1; /* return error */
1538 }
1539 prev &= ~(1 << 4); /* clear settings */
1540 prev |= (uint8_t)(!enable) << 4; /* set bool */
1541 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1542 if (res != 0) /* check the result */
1543 {
1544 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1545
1546 return 1; /* return error */
1547 }
1548
1549 return 0; /* success return 0 */
1550}
1551
1564{
1565 uint8_t res;
1566 uint8_t prev;
1567
1568 if (handle == NULL) /* check handle */
1569 {
1570 return 2; /* return error */
1571 }
1572 if (handle->inited != 1) /* check handle initialization */
1573 {
1574 return 3; /* return error */
1575 }
1576
1577 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1578 if (res != 0) /* check the result */
1579 {
1580 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1581
1582 return 1; /* return error */
1583 }
1584 *enable = (bmm150_bool_t)(!((prev >> 4) & 0x01)); /* set bool */
1585
1586 return 0; /* success return 0 */
1587}
1588
1601{
1602 uint8_t res;
1603 uint8_t prev;
1604
1605 if (handle == NULL) /* check handle */
1606 {
1607 return 2; /* return error */
1608 }
1609 if (handle->inited != 1) /* check handle initialization */
1610 {
1611 return 3; /* return error */
1612 }
1613
1614 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1615 if (res != 0) /* check the result */
1616 {
1617 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1618
1619 return 1; /* return error */
1620 }
1621 prev &= ~(1 << 3); /* clear settings */
1622 prev |= (uint8_t)(!enable) << 3; /* set bool */
1623 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1624 if (res != 0) /* check the result */
1625 {
1626 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1627
1628 return 1; /* return error */
1629 }
1630
1631 return 0; /* success return 0 */
1632}
1633
1646{
1647 uint8_t res;
1648 uint8_t prev;
1649
1650 if (handle == NULL) /* check handle */
1651 {
1652 return 2; /* return error */
1653 }
1654 if (handle->inited != 1) /* check handle initialization */
1655 {
1656 return 3; /* return error */
1657 }
1658
1659 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1660 if (res != 0) /* check the result */
1661 {
1662 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1663
1664 return 1; /* return error */
1665 }
1666 *enable = (bmm150_bool_t)(!((prev >> 3) & 0x01)); /* set bool */
1667
1668 return 0; /* success return 0 */
1669}
1670
1683{
1684 uint8_t res;
1685 uint8_t prev;
1686
1687 if (handle == NULL) /* check handle */
1688 {
1689 return 2; /* return error */
1690 }
1691 if (handle->inited != 1) /* check handle initialization */
1692 {
1693 return 3; /* return error */
1694 }
1695
1696 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1697 if (res != 0) /* check the result */
1698 {
1699 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1700
1701 return 1; /* return error */
1702 }
1703 prev &= ~(1 << 2); /* clear settings */
1704 prev |= polarity << 2; /* set polarity */
1705 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1706 if (res != 0) /* check the result */
1707 {
1708 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1709
1710 return 1; /* return error */
1711 }
1712
1713 return 0; /* success return 0 */
1714}
1715
1728{
1729 uint8_t res;
1730 uint8_t prev;
1731
1732 if (handle == NULL) /* check handle */
1733 {
1734 return 2; /* return error */
1735 }
1736 if (handle->inited != 1) /* check handle initialization */
1737 {
1738 return 3; /* return error */
1739 }
1740
1741 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1742 if (res != 0) /* check the result */
1743 {
1744 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1745
1746 return 1; /* return error */
1747 }
1748 *polarity = (bmm150_data_ready_pin_polarity_t)((prev >> 2) & 0x01); /* set polarity */
1749
1750 return 0; /* success return 0 */
1751}
1752
1765{
1766 uint8_t res;
1767 uint8_t prev;
1768
1769 if (handle == NULL) /* check handle */
1770 {
1771 return 2; /* return error */
1772 }
1773 if (handle->inited != 1) /* check handle initialization */
1774 {
1775 return 3; /* return error */
1776 }
1777
1778 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1779 if (res != 0) /* check the result */
1780 {
1781 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1782
1783 return 1; /* return error */
1784 }
1785 prev &= ~(1 << 1); /* clear settings */
1786 prev |= enable << 1; /* set bool */
1787 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1788 if (res != 0) /* check the result */
1789 {
1790 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1791
1792 return 1; /* return error */
1793 }
1794
1795 return 0; /* success return 0 */
1796}
1797
1810{
1811 uint8_t res;
1812 uint8_t prev;
1813
1814 if (handle == NULL) /* check handle */
1815 {
1816 return 2; /* return error */
1817 }
1818 if (handle->inited != 1) /* check handle initialization */
1819 {
1820 return 3; /* return error */
1821 }
1822
1823 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1824 if (res != 0) /* check the result */
1825 {
1826 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1827
1828 return 1; /* return error */
1829 }
1830 *enable = (bmm150_bool_t)((prev >> 1) & 0x01); /* set bool */
1831
1832 return 0; /* success return 0 */
1833}
1834
1847{
1848 uint8_t res;
1849 uint8_t prev;
1850
1851 if (handle == NULL) /* check handle */
1852 {
1853 return 2; /* return error */
1854 }
1855 if (handle->inited != 1) /* check handle initialization */
1856 {
1857 return 3; /* return error */
1858 }
1859
1860 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1861 if (res != 0) /* check the result */
1862 {
1863 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1864
1865 return 1; /* return error */
1866 }
1867 prev &= ~(1 << 0); /* clear settings */
1868 prev |= polarity << 0; /* set polarity */
1869 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1870 if (res != 0) /* check the result */
1871 {
1872 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1873
1874 return 1; /* return error */
1875 }
1876
1877 return 0; /* success return 0 */
1878}
1879
1892{
1893 uint8_t res;
1894 uint8_t prev;
1895
1896 if (handle == NULL) /* check handle */
1897 {
1898 return 2; /* return error */
1899 }
1900 if (handle->inited != 1) /* check handle initialization */
1901 {
1902 return 3; /* return error */
1903 }
1904
1905 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1906 if (res != 0) /* check the result */
1907 {
1908 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1909
1910 return 1; /* return error */
1911 }
1912 *polarity = (bmm150_interrupt_pin_polarity_t)((prev >> 0) & 0x01); /* set polarity */
1913
1914 return 0; /* success return 0 */
1915}
1916
1928uint8_t bmm150_set_low_threshold(bmm150_handle_t *handle, int8_t threshold)
1929{
1930 uint8_t res;
1931 uint8_t prev;
1932
1933 if (handle == NULL) /* check handle */
1934 {
1935 return 2; /* return error */
1936 }
1937 if (handle->inited != 1) /* check handle initialization */
1938 {
1939 return 3; /* return error */
1940 }
1941
1942 prev = (uint8_t)threshold; /* set threshold */
1943 res = a_bmm150_iic_spi_write(handle, BMM150_REG_LOW_THRESHOLD, &prev, 1); /* write config */
1944 if (res != 0) /* check the result */
1945 {
1946 handle->debug_print("bmm150: write low threshold failed.\n"); /* write low threshold failed */
1947
1948 return 1; /* return error */
1949 }
1950
1951 return 0; /* success return 0 */
1952}
1953
1965uint8_t bmm150_get_low_threshold(bmm150_handle_t *handle, int8_t *threshold)
1966{
1967 uint8_t res;
1968 uint8_t prev;
1969
1970 if (handle == NULL) /* check handle */
1971 {
1972 return 2; /* return error */
1973 }
1974 if (handle->inited != 1) /* check handle initialization */
1975 {
1976 return 3; /* return error */
1977 }
1978
1979 res = a_bmm150_iic_spi_read(handle, BMM150_REG_LOW_THRESHOLD, &prev, 1); /* read config */
1980 if (res != 0) /* check the result */
1981 {
1982 handle->debug_print("bmm150: read low threshold failed.\n"); /* read low threshold failed */
1983
1984 return 1; /* return error */
1985 }
1986 *threshold = (int8_t)(prev); /* set threshold */
1987
1988 return 0; /* success return 0 */
1989}
1990
2002uint8_t bmm150_set_high_threshold(bmm150_handle_t *handle, int8_t threshold)
2003{
2004 uint8_t res;
2005 uint8_t prev;
2006
2007 if (handle == NULL) /* check handle */
2008 {
2009 return 2; /* return error */
2010 }
2011 if (handle->inited != 1) /* check handle initialization */
2012 {
2013 return 3; /* return error */
2014 }
2015
2016 prev = (uint8_t)threshold; /* set threshold */
2017 res = a_bmm150_iic_spi_write(handle, BMM150_REG_HIGH_THRESHOLD, &prev, 1); /* write config */
2018 if (res != 0) /* check the result */
2019 {
2020 handle->debug_print("bmm150: write high threshold failed.\n"); /* write high threshold failed */
2021
2022 return 1; /* return error */
2023 }
2024
2025 return 0; /* success return 0 */
2026}
2027
2039uint8_t bmm150_get_high_threshold(bmm150_handle_t *handle, int8_t *threshold)
2040{
2041 uint8_t res;
2042 uint8_t prev;
2043
2044 if (handle == NULL) /* check handle */
2045 {
2046 return 2; /* return error */
2047 }
2048 if (handle->inited != 1) /* check handle initialization */
2049 {
2050 return 3; /* return error */
2051 }
2052
2053 res = a_bmm150_iic_spi_read(handle, BMM150_REG_HIGH_THRESHOLD, &prev, 1); /* read config */
2054 if (res != 0) /* check the result */
2055 {
2056 handle->debug_print("bmm150: read high threshold failed.\n"); /* read high threshold failed */
2057
2058 return 1; /* return error */
2059 }
2060 *threshold = (int8_t)(prev); /* set threshold */
2061
2062 return 0; /* success return 0 */
2063}
2064
2080uint8_t bmm150_set_repxy_number(bmm150_handle_t *handle, uint8_t number)
2081{
2082 uint8_t res;
2083 uint8_t prev;
2084
2085 if (handle == NULL) /* check handle */
2086 {
2087 return 2; /* return error */
2088 }
2089 if (handle->inited != 1) /* check handle initialization */
2090 {
2091 return 3; /* return error */
2092 }
2093
2094 prev = number; /* set number */
2095 res = a_bmm150_iic_spi_write(handle, BMM150_REG_REPXY, &prev, 1); /* write config */
2096 if (res != 0) /* check the result */
2097 {
2098 handle->debug_print("bmm150: write repxy failed.\n"); /* write repxy failed */
2099
2100 return 1; /* return error */
2101 }
2102
2103 return 0; /* success return 0 */
2104}
2105
2117uint8_t bmm150_get_repxy_number(bmm150_handle_t *handle, uint8_t *number)
2118{
2119 uint8_t res;
2120
2121 if (handle == NULL) /* check handle */
2122 {
2123 return 2; /* return error */
2124 }
2125 if (handle->inited != 1) /* check handle initialization */
2126 {
2127 return 3; /* return error */
2128 }
2129
2130 res = a_bmm150_iic_spi_read(handle, BMM150_REG_REPXY, number, 1); /* read config */
2131 if (res != 0) /* check the result */
2132 {
2133 handle->debug_print("bmm150: read repxy failed.\n"); /* read repxy failed */
2134
2135 return 1; /* return error */
2136 }
2137
2138 return 0; /* success return 0 */
2139}
2140
2156uint8_t bmm150_set_repz_number(bmm150_handle_t *handle, uint8_t number)
2157{
2158 uint8_t res;
2159 uint8_t prev;
2160
2161 if (handle == NULL) /* check handle */
2162 {
2163 return 2; /* return error */
2164 }
2165 if (handle->inited != 1) /* check handle initialization */
2166 {
2167 return 3; /* return error */
2168 }
2169
2170 prev = number; /* set number */
2171 res = a_bmm150_iic_spi_write(handle, BMM150_REG_REPZ, &prev, 1); /* write config */
2172 if (res != 0) /* check the result */
2173 {
2174 handle->debug_print("bmm150: write repz failed.\n"); /* write repz failed */
2175
2176 return 1; /* return error */
2177 }
2178
2179 return 0; /* success return 0 */
2180}
2181
2193uint8_t bmm150_get_repz_number(bmm150_handle_t *handle, uint8_t *number)
2194{
2195 uint8_t res;
2196
2197 if (handle == NULL) /* check handle */
2198 {
2199 return 2; /* return error */
2200 }
2201 if (handle->inited != 1) /* check handle initialization */
2202 {
2203 return 3; /* return error */
2204 }
2205
2206 res = a_bmm150_iic_spi_read(handle, BMM150_REG_REPZ, number, 1); /* read config */
2207 if (res != 0) /* check the result */
2208 {
2209 handle->debug_print("bmm150: read repz failed.\n"); /* read repz failed */
2210
2211 return 1; /* return error */
2212 }
2213
2214 return 0; /* success return 0 */
2215}
2216
2230uint8_t bmm150_read(bmm150_handle_t *handle, int16_t raw[3], float ut[3])
2231{
2232 uint8_t res;
2233 uint8_t prev;
2234 uint8_t mode;
2235 uint8_t buf[8];
2236 uint16_t temp;
2237
2238 if (handle == NULL) /* check handle */
2239 {
2240 return 2; /* return error */
2241 }
2242 if (handle->inited != 1) /* check handle initialization */
2243 {
2244 return 3; /* return error */
2245 }
2246
2247 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
2248 if (res != 0) /* check the result */
2249 {
2250 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
2251
2252 return 1; /* return error */
2253 }
2254 mode = (prev >> 1) & 0x03; /* get mode config */
2255 if (mode == 0) /* normal mode */
2256 {
2257 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_X_LSB, buf, 8); /* read data */
2258 if (res != 0) /* check the result */
2259 {
2260 handle->debug_print("bmm150: read data failed.\n"); /* read data failed */
2261
2262 return 1; /* return error */
2263 }
2264 if (((buf[1] >> 7) & 0x01) != 0) /* check signed bit */
2265 {
2266 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3) | (0x7 << 13)); /* set data */
2267 raw[0] = temp; /* set x */
2268 }
2269 else
2270 {
2271 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3)); /* make data */
2272 raw[0] = temp; /* set x */
2273 }
2274 if (((buf[3] >> 7) & 0x01) != 0) /* check signed bit */
2275 {
2276 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3) | (0x7 << 13)); /* set data */
2277 raw[1] = temp; /* set y */
2278 }
2279 else
2280 {
2281 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3)); /* make data */
2282 raw[1] = temp; /* set y */
2283 }
2284 if (((buf[5] >> 7) & 0x01) != 0) /* check signed bit */
2285 {
2286 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1) | (0x1 << 15)); /* set data */
2287 raw[2] = temp; /* set z */
2288 }
2289 else
2290 {
2291 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1)); /* make data */
2292 raw[2] = temp; /* set z */
2293 }
2294 temp = (uint16_t)(((uint16_t)buf[7]) << 6 | (buf[6] >> 2)); /* make data */
2295 ut[0] = a_bmm150_compensate_x(handle, raw[0], temp); /* compensate x */
2296 ut[1] = a_bmm150_compensate_y(handle, raw[1], temp); /* compensate y */
2297 ut[2] = a_bmm150_compensate_z(handle, raw[2], temp); /* compensate z */
2298
2299 return 0; /* success return 0 */
2300 }
2301 else /* forced mode */
2302 {
2303 uint16_t timeout;
2304
2305 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
2306 if (res != 0) /* check the result */
2307 {
2308 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
2309
2310 return 1; /* return error */
2311 }
2312 prev &= ~(3 << 1); /* clear settings */
2313 prev |= 0x01 << 1; /* set forced mode */
2314 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
2315 if (res != 0) /* check the result */
2316 {
2317 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
2318
2319 return 1; /* return error */
2320 }
2321
2322 timeout = 1000; /* timeout 1s */
2323 while (timeout != 0) /* check timeout */
2324 {
2325 res = a_bmm150_iic_spi_read(handle, BMM150_REG_RHALL_LSB, &prev, 1); /* read rhall lsb */
2326 if (res != 0) /* check the result */
2327 {
2328 handle->debug_print("bmm150: read rhall lsb failed.\n"); /* read rhall lsb failed */
2329
2330 return 1; /* return error */
2331 }
2332 if ((prev & 0x01) != 0) /* check data ready bit */
2333 {
2334 break; /* break */
2335 }
2336 timeout--; /* timeout-- */
2337 handle->delay_ms(1); /* delay 1ms */
2338 }
2339 if (timeout == 0) /* check timeout */
2340 {
2341 handle->debug_print("bmm150: read timeout.\n"); /* read timeout */
2342
2343 return 4; /* return error */
2344 }
2345
2346 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_X_LSB, buf, 8); /* read data */
2347 if (res != 0) /* check the result */
2348 {
2349 handle->debug_print("bmm150: read data failed.\n"); /* read data failed */
2350
2351 return 1; /* return error */
2352 }
2353 if (((buf[1] >> 7) & 0x01) != 0) /* check signed bit */
2354 {
2355 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3) | (0x7 << 13)); /* set data */
2356 raw[0] = temp; /* set x */
2357 }
2358 else
2359 {
2360 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3)); /* make data */
2361 raw[0] = temp; /* set x */
2362 }
2363 if (((buf[3] >> 7) & 0x01) != 0) /* check signed bit */
2364 {
2365 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3) | (0x7 << 13)); /* set data */
2366 raw[1] = temp; /* set y */
2367 }
2368 else
2369 {
2370 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3)); /* make data */
2371 raw[1] = temp; /* set y */
2372 }
2373 if (((buf[5] >> 7) & 0x01) != 0) /* check signed bit */
2374 {
2375 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1) | (0x1 << 15)); /* set data */
2376 raw[2] = temp; /* set z */
2377 }
2378 else
2379 {
2380 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1)); /* make data */
2381 raw[2] = temp; /* set z */
2382 }
2383 temp = (uint16_t)(((uint16_t)buf[7]) << 6 | (buf[6] >> 2)); /* make data */
2384 ut[0] = a_bmm150_compensate_x(handle, raw[0], temp); /* compensate x */
2385 ut[1] = a_bmm150_compensate_y(handle, raw[1], temp); /* compensate y */
2386 ut[2] = a_bmm150_compensate_z(handle, raw[2], temp); /* compensate z */
2387
2388 return 0; /* success return 0 */
2389 }
2390}
2391
2403{
2404 uint8_t res;
2405 uint8_t prev;
2406
2407 if (handle == NULL) /* check handle */
2408 {
2409 return 2; /* return error */
2410 }
2411 if (handle->inited != 1) /* check handle initialization */
2412 {
2413 return 3; /* return error */
2414 }
2415
2416 res = a_bmm150_iic_spi_read(handle, BMM150_REG_INTERRUPT_STATUS, &prev, 1); /* read config */
2417 if (res != 0) /* check the result */
2418 {
2419 handle->debug_print("bmm150: read interrupt status failed.\n"); /* read interrupt status failed */
2420
2421 return 1; /* return error */
2422 }
2423
2424 if (prev != 0) /* check valid bits */
2425 {
2426 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_DATA_OVERRUN) & 0x01) != 0) /* check data overrun */
2427 {
2428 if (handle->receive_callback != NULL) /* not null */
2429 {
2430 handle->receive_callback(BMM150_INTERRUPT_STATUS_DATA_OVERRUN); /* run the callback */
2431 }
2432 }
2433 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) & 0x01) != 0) /* check overflow */
2434 {
2435 if (handle->receive_callback != NULL) /* not null */
2436 {
2437 handle->receive_callback(BMM150_INTERRUPT_STATUS_OVERFLOW); /* run the callback */
2438 }
2439 }
2440 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z) & 0x01) != 0) /* check high threshold z */
2441 {
2442 if (handle->receive_callback != NULL) /* not null */
2443 {
2444 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z); /* run the callback */
2445 }
2446 }
2447 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y) & 0x01) != 0) /* check high threshold y */
2448 {
2449 if (handle->receive_callback != NULL) /* not null */
2450 {
2451 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y); /* run the callback */
2452 }
2453 }
2454 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X) & 0x01) != 0) /* check high threshold z */
2455 {
2456 if (handle->receive_callback != NULL) /* not null */
2457 {
2458 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X); /* run the callback */
2459 }
2460 }
2461 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z) & 0x01) != 0) /* check low threshold z */
2462 {
2463 if (handle->receive_callback != NULL) /* not null */
2464 {
2465 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z); /* run the callback */
2466 }
2467 }
2468 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y) & 0x01) != 0) /* check low threshold y */
2469 {
2470 if (handle->receive_callback != NULL) /* not null */
2471 {
2472 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y); /* run the callback */
2473 }
2474 }
2475 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X) & 0x01) != 0) /* check low threshold x */
2476 {
2477 if (handle->receive_callback != NULL) /* not null */
2478 {
2479 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X); /* run the callback */
2480 }
2481 }
2482 }
2483
2484 return 0; /* success return 0 */
2485}
2486
2499{
2500 if (handle == NULL) /* check handle */
2501 {
2502 return 2; /* return error */
2503 }
2504 if (handle->inited != 1) /* check handle initialization */
2505 {
2506 return 3; /* return error */
2507 }
2508
2509 *reg = (int8_t)(ut / 6.0f); /* convert real data to register data */
2510
2511 return 0; /* success return 0 */
2512}
2513
2526{
2527 if (handle == NULL) /* check handle */
2528 {
2529 return 2; /* return error */
2530 }
2531 if (handle->inited != 1) /* check handle initialization */
2532 {
2533 return 3; /* return error */
2534 }
2535
2536 *ut = (float)(reg) * 6.0f; /* convert raw data to real data */
2537
2538 return 0; /* success return 0 */
2539}
2540
2556{
2557 uint8_t id;
2558 uint8_t prev;
2559
2560 if (handle == NULL) /* check handle */
2561 {
2562 return 2; /* return error */
2563 }
2564 if (handle->debug_print == NULL) /* check debug_print */
2565 {
2566 return 3; /* return error */
2567 }
2568 if (handle->iic_init == NULL) /* check iic_init */
2569 {
2570 handle->debug_print("bmm150: iic_init is null.\n"); /* iic_init is null */
2571
2572 return 3; /* return error */
2573 }
2574 if (handle->iic_deinit == NULL) /* check iic_deinit */
2575 {
2576 handle->debug_print("bmm150: iic_deinit is null.\n"); /* iic_deinit is null */
2577
2578 return 3; /* return error */
2579 }
2580 if (handle->iic_read == NULL) /* check iic_read */
2581 {
2582 handle->debug_print("bmm150: iic_read is null.\n"); /* iic_read is null */
2583
2584 return 3; /* return error */
2585 }
2586 if (handle->iic_write == NULL) /* check iic_write */
2587 {
2588 handle->debug_print("bmm150: iic_write is null.\n"); /* iic_write is null */
2589
2590 return 3; /* return error */
2591 }
2592 if (handle->spi_init == NULL) /* check spi_init */
2593 {
2594 handle->debug_print("bmm150: spi_init is null.\n"); /* spi_init is null */
2595
2596 return 3; /* return error */
2597 }
2598 if (handle->spi_deinit == NULL) /* check spi_deinit */
2599 {
2600 handle->debug_print("bmm150: spi_deinit is null.\n"); /* spi_deinit is null */
2601
2602 return 3; /* return error */
2603 }
2604 if (handle->spi_read == NULL) /* check spi_read */
2605 {
2606 handle->debug_print("bmm150: spi_read is null.\n"); /* spi_read is null */
2607
2608 return 3; /* return error */
2609 }
2610 if (handle->spi_write == NULL) /* check spi_write */
2611 {
2612 handle->debug_print("bmm150: spi_write is null.\n"); /* spi_write is null */
2613
2614 return 3; /* return error */
2615 }
2616 if (handle->delay_ms == NULL) /* check delay_ms */
2617 {
2618 handle->debug_print("bmm150: delay_ms is null.\n"); /* delay_ms is null */
2619
2620 return 3; /* return error */
2621 }
2622 if (handle->receive_callback == NULL) /* check receive_callback */
2623 {
2624 handle->debug_print("bmm150: receive_callback is null.\n"); /* receive_callback is null */
2625
2626 return 3; /* return error */
2627 }
2628
2629 if (handle->iic_spi == BMM150_INTERFACE_IIC) /* iic interface */
2630 {
2631 if (handle->iic_init() != 0) /* initialize iic bus */
2632 {
2633 handle->debug_print("bmm150: iic init failed.\n"); /* iic init failed */
2634
2635 return 1; /* return error */
2636 }
2637 }
2638 else /* spi interface */
2639 {
2640 if (handle->spi_init() != 0) /* initialize spi bus */
2641 {
2642 handle->debug_print("bmm150: spi init failed.\n"); /* spi init failed */
2643
2644 return 1; /* return error */
2645 }
2646 }
2647
2648 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* soft reset */
2649 {
2650 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
2651 (void)a_bmm150_close(handle); /* close */
2652
2653 return 4; /* return error */
2654 }
2655 prev &= ~(1 << 1); /* clear settings */
2656 prev |= 1 << 1; /* set bool */
2657 prev &= ~(1 << 7); /* clear settings */
2658 prev |= 1 << 7; /* set bool */
2659 if (a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* soft reset */
2660 {
2661 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
2662 (void)a_bmm150_close(handle); /* close */
2663
2664 return 4; /* return error */
2665 }
2666 handle->delay_ms(5); /* delay 5ms */
2667
2668 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* read config */
2669 {
2670 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
2671
2672 return 5; /* return error */
2673 }
2674 prev &= ~(1 << 0); /* clear settings */
2675 prev |= 1 << 0; /* set bool */
2676 if (a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* write config */
2677 {
2678 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
2679
2680 return 5; /* return error */
2681 }
2682 handle->delay_ms(5); /* delay 5ms */
2683
2684 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CHIP_ID, (uint8_t *)&id, 1) != 0) /* read id */
2685 {
2686 handle->debug_print("bmm150: read failed.\n"); /* read failed */
2687 (void)a_bmm150_close(handle); /* close */
2688
2689 return 6; /* return error */
2690 }
2691 if (id != 0x32) /* check id */
2692 {
2693 handle->debug_print("bmm150: id is invalid.\n"); /* id is invalid */
2694 (void)a_bmm150_close(handle); /* close */
2695
2696 return 6; /* return error */
2697 }
2698 if (a_bmm150_load_trim(handle) != 0) /* load trim */
2699 {
2700 handle->debug_print("bmm150: load trim failed.\n"); /* load trim failed */
2701 (void)a_bmm150_close(handle); /* close */
2702
2703 return 7; /* return error */
2704 }
2705 handle->inited = 1; /* flag finish initialization */
2706
2707 return 0; /* success return 0 */
2708}
2709
2721{
2722 uint8_t res;
2723
2724 if (handle == NULL) /* check handle */
2725 {
2726 return 2; /* return error */
2727 }
2728 if (handle->inited != 1) /* check handle initialization */
2729 {
2730 return 3; /* return error */
2731 }
2732
2733 res = a_bmm150_close(handle); /* close */
2734 if (res != 0) /* check result */
2735 {
2736 return 1; /* return error */
2737 }
2738 else
2739 {
2740 handle->inited = 0; /* flag close */
2741
2742 return 0; /* success return 0 */
2743 }
2744}
2745
2759uint8_t bmm150_set_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2760{
2761 uint8_t res;
2762
2763 if (handle == NULL) /* check handle */
2764 {
2765 return 2; /* return error */
2766 }
2767 if (handle->inited != 1) /* check handle initialization */
2768 {
2769 return 3; /* return error */
2770 }
2771
2772 res = a_bmm150_iic_spi_write(handle, reg, buf, len); /* write data */
2773 if (res != 0) /* check the result */
2774 {
2775 return 1; /* return error */
2776 }
2777
2778 return 0; /* success return 0 */
2779}
2780
2794uint8_t bmm150_get_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2795{
2796 uint8_t res;
2797
2798 if (handle == NULL) /* check handle */
2799 {
2800 return 2; /* return error */
2801 }
2802 if (handle->inited != 1) /* check handle initialization */
2803 {
2804 return 3; /* return error */
2805 }
2806
2807 res = a_bmm150_iic_spi_read(handle, reg, buf, len); /* read data */
2808 if (res != 0) /* check the result */
2809 {
2810 return 1; /* return error */
2811 }
2812
2813 return 0; /* success return 0 */
2814}
2815
2825{
2826 if (info == NULL) /* check handle */
2827 {
2828 return 2; /* return error */
2829 }
2830
2831 memset(info, 0, sizeof(bmm150_info_t)); /* initialize bmm150 info structure */
2832 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2833 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2834 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
2835 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2836 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2837 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2838 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2839 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2840 info->driver_version = DRIVER_VERSION; /* set driver version */
2841
2842 return 0; /* success return 0 */
2843}
#define BMM150_REG_CHIP_ID
chip register definition
#define BMM150_REG_RHALL_LSB
#define BMM150_REG_CONFIG_0
#define BMM150_REG_DATA_Z_LSB
#define MAX_CURRENT
#define BMM150_REG_DIG_Z2_LSB
#define BMM150_REG_CONFIG_1
#define BMM150_REG_DATA_Y_LSB
#define SUPPLY_VOLTAGE_MAX
#define BMM150_REG_INTERRUPT_STATUS
#define BMM150_REG_CONFIG_2
#define BMM150_REG_DIG_X1
chip trim extended register definition
#define BMM150_REG_REPZ
#define TEMPERATURE_MAX
#define BMM150_REG_CONFIG_3
#define BMM150_REG_DIG_Z4_LSB
#define BMM150_REG_REPXY
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMM150_REG_LOW_THRESHOLD
#define CHIP_NAME
chip register definition
#define BMM150_REG_DATA_X_LSB
#define DRIVER_VERSION
#define BMM150_REG_HIGH_THRESHOLD
driver bmm150 header file
uint8_t bmm150_get_channel_x(bmm150_handle_t *handle, bmm150_bool_t *enable)
get channel x status
uint8_t bmm150_get_interrupt_pin_polarity(bmm150_handle_t *handle, bmm150_interrupt_pin_polarity_t *polarity)
get interrupt pin polarity
uint8_t bmm150_soft_reset(bmm150_handle_t *handle)
soft reset
uint8_t bmm150_get_channel_z(bmm150_handle_t *handle, bmm150_bool_t *enable)
get channel z status
uint8_t bmm150_get_mode(bmm150_handle_t *handle, bmm150_mode_t *mode)
get mode
uint8_t bmm150_deinit(bmm150_handle_t *handle)
close the chip
uint8_t bmm150_get_repxy_number(bmm150_handle_t *handle, uint8_t *number)
get repxy number
uint8_t bmm150_init(bmm150_handle_t *handle)
initialize the chip
bmm150_data_rate_t
bmm150 data rate enumeration definition
uint8_t bmm150_get_spi_wire(bmm150_handle_t *handle, bmm150_spi_wire_t *wire)
get spi wire
uint8_t bmm150_get_self_test(bmm150_handle_t *handle, bmm150_bool_t *enable)
get self test status
uint8_t bmm150_set_data_ready_pin(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable data ready pin
uint8_t bmm150_get_interface(bmm150_handle_t *handle, bmm150_interface_t *interface)
get the chip interface
uint8_t bmm150_get_data_ready_pin(bmm150_handle_t *handle, bmm150_bool_t *enable)
get data ready pin status
uint8_t bmm150_set_repz_number(bmm150_handle_t *handle, uint8_t number)
set repz number
uint8_t bmm150_get_low_threshold(bmm150_handle_t *handle, int8_t *threshold)
get low threshold
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_get_interrupt_latch(bmm150_handle_t *handle, bmm150_bool_t *enable)
get interrupt latch status
uint8_t bmm150_set_interrupt_pin_polarity(bmm150_handle_t *handle, bmm150_interrupt_pin_polarity_t polarity)
set interrupt pin polarity
bmm150_interrupt_status_t
bmm150 interrupt status enumeration definition
uint8_t bmm150_set_interface(bmm150_handle_t *handle, bmm150_interface_t interface)
set the chip interface
bmm150_spi_wire_t
bmm150 spi wire enumeration definition
uint8_t bmm150_set_spi_wire(bmm150_handle_t *handle, bmm150_spi_wire_t wire)
set spi wire
uint8_t bmm150_get_channel_y(bmm150_handle_t *handle, bmm150_bool_t *enable)
get channel y status
uint8_t bmm150_get_self_test_y(bmm150_handle_t *handle, bmm150_bool_t *enable)
get self test y result
bmm150_interface_t
bmm150 interface enumeration definition
uint8_t bmm150_get_data_ready_status(bmm150_handle_t *handle, bmm150_bool_t *enable)
get data ready status
uint8_t bmm150_interrupt_threshold_convert_to_data(bmm150_handle_t *handle, int8_t reg, float *ut)
convert the register raw data to the interrupt threshold
uint8_t bmm150_set_high_threshold(bmm150_handle_t *handle, int8_t threshold)
set high threshold
uint8_t bmm150_get_self_test_x(bmm150_handle_t *handle, bmm150_bool_t *enable)
get self test x result
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_info(bmm150_info_t *info)
get chip's information
uint8_t bmm150_set_mode(bmm150_handle_t *handle, bmm150_mode_t mode)
set mode
uint8_t bmm150_get_high_threshold(bmm150_handle_t *handle, int8_t *threshold)
get high threshold
uint8_t bmm150_set_power_on(bmm150_handle_t *handle, bmm150_bool_t enable)
set power on
bmm150_advanced_self_test_t
bmm150 advanced self test enumeration definition
uint8_t bmm150_set_low_threshold(bmm150_handle_t *handle, int8_t threshold)
set low threshold
bmm150_interrupt_pin_polarity_t
bmm150 interrupt pin polarity enumeration definition
uint8_t bmm150_get_data_rate(bmm150_handle_t *handle, bmm150_data_rate_t *rate)
get data rate
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
bmm150_mode_t
bmm150 mode enumeration definition
uint8_t bmm150_get_self_test_z(bmm150_handle_t *handle, bmm150_bool_t *enable)
get self test z result
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
bmm150_data_ready_pin_polarity_t
bmm150 data ready pin polarity enumeration definition
uint8_t bmm150_set_channel_z(bmm150_handle_t *handle, bmm150_bool_t enable)
enable or disable channel z
uint8_t bmm150_get_interrupt_pin(bmm150_handle_t *handle, bmm150_bool_t *enable)
get interrupt pin status
uint8_t bmm150_get_repz_number(bmm150_handle_t *handle, uint8_t *number)
get repz number
uint8_t bmm150_get_interrupt(bmm150_handle_t *handle, bmm150_interrupt_status_t status, bmm150_bool_t *enable)
get interrupt status
uint8_t bmm150_set_repxy_number(bmm150_handle_t *handle, uint8_t number)
set repxy number
uint8_t bmm150_get_power_on(bmm150_handle_t *handle, bmm150_bool_t *enable)
get power on
uint8_t bmm150_get_data_ready_pin_polarity(bmm150_handle_t *handle, bmm150_data_ready_pin_polarity_t *polarity)
get data ready pin polarity
struct bmm150_info_s bmm150_info_t
bmm150 information structure definition
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_get_advanced_self_test(bmm150_handle_t *handle, bmm150_advanced_self_test_t *test)
get advanced self test
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_get_addr_pin(bmm150_handle_t *handle, bmm150_address_t *addr_pin)
get the iic address pin
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_INTERFACE_IIC
uint8_t bmm150_set_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t bmm150_get_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]