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 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
657 if (res != 0) /* check the result */
658 {
659 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
660
661 return 1; /* return error */
662 }
663 handle->delay_ms(5); /* delay 5ms */
664
665 return 0; /* success return 0 */
666}
667
680{
681 uint8_t res;
682 uint8_t prev;
683
684 if (handle == NULL) /* check handle */
685 {
686 return 2; /* return error */
687 }
688 if (handle->inited != 1) /* check handle initialization */
689 {
690 return 3; /* return error */
691 }
692
693 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
694 if (res != 0) /* check the result */
695 {
696 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
697
698 return 1; /* return error */
699 }
700 prev &= ~(1 << 0); /* clear settings */
701 prev |= enable << 0; /* set bool */
702 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
703 if (res != 0) /* check the result */
704 {
705 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
706
707 return 1; /* return error */
708 }
709 handle->delay_ms(5); /* delay 5ms */
710
711 return 0; /* success return 0 */
712}
713
726{
727 uint8_t res;
728 uint8_t prev;
729
730 if (handle == NULL) /* check handle */
731 {
732 return 2; /* return error */
733 }
734 if (handle->inited != 1) /* check handle initialization */
735 {
736 return 3; /* return error */
737 }
738
739 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
740 if (res != 0) /* check the result */
741 {
742 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
743
744 return 1; /* return error */
745 }
746 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
747
748 return 0; /* success return 0 */
749}
750
763{
764 uint8_t res;
765 uint8_t prev;
766
767 if (handle == NULL) /* check handle */
768 {
769 return 2; /* return error */
770 }
771 if (handle->inited != 1) /* check handle initialization */
772 {
773 return 3; /* return error */
774 }
775
776 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
777 if (res != 0) /* check the result */
778 {
779 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
780
781 return 1; /* return error */
782 }
783 prev &= ~(1 << 2); /* clear settings */
784 prev |= wire << 2; /* set wire */
785 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1); /* write config */
786 if (res != 0) /* check the result */
787 {
788 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
789
790 return 1; /* return error */
791 }
792
793 return 0; /* success return 0 */
794}
795
808{
809 uint8_t res;
810 uint8_t prev;
811
812 if (handle == NULL) /* check handle */
813 {
814 return 2; /* return error */
815 }
816 if (handle->inited != 1) /* check handle initialization */
817 {
818 return 3; /* return error */
819 }
820
821 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1); /* read config */
822 if (res != 0) /* check the result */
823 {
824 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
825
826 return 1; /* return error */
827 }
828 *wire = (bmm150_spi_wire_t)((prev >> 2) & 0x01); /* set wire */
829
830 return 0; /* success return 0 */
831}
832
845{
846 uint8_t res;
847 uint8_t prev;
848
849 if (handle == NULL) /* check handle */
850 {
851 return 2; /* return error */
852 }
853 if (handle->inited != 1) /* check handle initialization */
854 {
855 return 3; /* return error */
856 }
857
858 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
859 if (res != 0) /* check the result */
860 {
861 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
862
863 return 1; /* return error */
864 }
865 prev &= ~(3 << 6); /* clear settings */
866 prev |= test << 6; /* set test */
867 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
868 if (res != 0) /* check the result */
869 {
870 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
871
872 return 1; /* return error */
873 }
874
875 return 0; /* success return 0 */
876}
877
890{
891 uint8_t res;
892 uint8_t prev;
893
894 if (handle == NULL) /* check handle */
895 {
896 return 2; /* return error */
897 }
898 if (handle->inited != 1) /* check handle initialization */
899 {
900 return 3; /* return error */
901 }
902
903 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
904 if (res != 0) /* check the result */
905 {
906 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
907
908 return 1; /* return error */
909 }
910 *test = (bmm150_advanced_self_test_t)((prev >> 6) & 0x03); /* set test */
911
912 return 0; /* success return 0 */
913}
914
927{
928 uint8_t res;
929 uint8_t prev;
930
931 if (handle == NULL) /* check handle */
932 {
933 return 2; /* return error */
934 }
935 if (handle->inited != 1) /* check handle initialization */
936 {
937 return 3; /* return error */
938 }
939
940 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
941 if (res != 0) /* check the result */
942 {
943 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
944
945 return 1; /* return error */
946 }
947 prev &= ~(7 << 3); /* clear settings */
948 prev |= rate << 3; /* set rate */
949 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
950 if (res != 0) /* check the result */
951 {
952 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
953
954 return 1; /* return error */
955 }
956
957 return 0; /* success return 0 */
958}
959
972{
973 uint8_t res;
974 uint8_t prev;
975
976 if (handle == NULL) /* check handle */
977 {
978 return 2; /* return error */
979 }
980 if (handle->inited != 1) /* check handle initialization */
981 {
982 return 3; /* return error */
983 }
984
985 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
986 if (res != 0) /* check the result */
987 {
988 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
989
990 return 1; /* return error */
991 }
992 *rate = (bmm150_data_rate_t)((prev >> 3) & 0x07); /* set rate */
993
994 return 0; /* success return 0 */
995}
996
1009{
1010 uint8_t res;
1011 uint8_t prev;
1012
1013 if (handle == NULL) /* check handle */
1014 {
1015 return 2; /* return error */
1016 }
1017 if (handle->inited != 1) /* check handle initialization */
1018 {
1019 return 3; /* return error */
1020 }
1021
1022 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1023 if (res != 0) /* check the result */
1024 {
1025 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1026
1027 return 1; /* return error */
1028 }
1029 prev &= ~(3 << 1); /* clear settings */
1030 prev |= mode << 1; /* set mode */
1031 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
1032 if (res != 0) /* check the result */
1033 {
1034 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
1035
1036 return 1; /* return error */
1037 }
1038
1039 return 0; /* success return 0 */
1040}
1041
1054{
1055 uint8_t res;
1056 uint8_t prev;
1057
1058 if (handle == NULL) /* check handle */
1059 {
1060 return 2; /* return error */
1061 }
1062 if (handle->inited != 1) /* check handle initialization */
1063 {
1064 return 3; /* return error */
1065 }
1066
1067 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1068 if (res != 0) /* check the result */
1069 {
1070 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1071
1072 return 1; /* return error */
1073 }
1074 *mode = (bmm150_mode_t)((prev >> 1) & 0x03); /* set mode */
1075
1076 return 0; /* success return 0 */
1077}
1078
1091{
1092 uint8_t res;
1093 uint8_t prev;
1094
1095 if (handle == NULL) /* check handle */
1096 {
1097 return 2; /* return error */
1098 }
1099 if (handle->inited != 1) /* check handle initialization */
1100 {
1101 return 3; /* return error */
1102 }
1103
1104 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1105 if (res != 0) /* check the result */
1106 {
1107 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1108
1109 return 1; /* return error */
1110 }
1111 prev &= ~(1 << 0); /* clear settings */
1112 prev |= enable << 0; /* set bool */
1113 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
1114 if (res != 0) /* check the result */
1115 {
1116 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
1117
1118 return 1; /* return error */
1119 }
1120
1121 return 0; /* success return 0 */
1122}
1123
1136{
1137 uint8_t res;
1138 uint8_t prev;
1139
1140 if (handle == NULL) /* check handle */
1141 {
1142 return 2; /* return error */
1143 }
1144 if (handle->inited != 1) /* check handle initialization */
1145 {
1146 return 3; /* return error */
1147 }
1148
1149 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
1150 if (res != 0) /* check the result */
1151 {
1152 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
1153
1154 return 1; /* return error */
1155 }
1156 *enable = (bmm150_bool_t)((prev >> 0) & 0x01); /* set bool */
1157
1158 return 0; /* success return 0 */
1159}
1160
1174{
1175 uint8_t res;
1176 uint8_t prev;
1177
1178 if (handle == NULL) /* check handle */
1179 {
1180 return 2; /* return error */
1181 }
1182 if (handle->inited != 1) /* check handle initialization */
1183 {
1184 return 3; /* return error */
1185 }
1186
1187 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_2, &prev, 1); /* read config */
1188 if (res != 0) /* check the result */
1189 {
1190 handle->debug_print("bmm150: read config 2 failed.\n"); /* read config 2 failed */
1191
1192 return 1; /* return error */
1193 }
1194 prev &= ~(1 << (uint8_t)status); /* clear settings */
1195 if (status >= (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) /* index >= 6 */
1196 {
1197 prev |= enable << (uint8_t)status; /* set bool */
1198 }
1199 else /* index < 6 */
1200 {
1201 prev |= (uint8_t)(!enable) << (uint8_t)status; /* set bool */
1202 }
1203 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_2, &prev, 1); /* write config */
1204 if (res != 0) /* check the result */
1205 {
1206 handle->debug_print("bmm150: write config 2 failed.\n"); /* write config 2 failed */
1207
1208 return 1; /* return error */
1209 }
1210
1211 return 0; /* success return 0 */
1212}
1213
1227{
1228 uint8_t res;
1229 uint8_t prev;
1230
1231 if (handle == NULL) /* check handle */
1232 {
1233 return 2; /* return error */
1234 }
1235 if (handle->inited != 1) /* check handle initialization */
1236 {
1237 return 3; /* return error */
1238 }
1239
1240 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_2, &prev, 1); /* read config */
1241 if (res != 0) /* check the result */
1242 {
1243 handle->debug_print("bmm150: read config 2 failed.\n"); /* read config 2 failed */
1244
1245 return 1; /* return error */
1246 }
1247 if (status >= (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) /* index >= 6 */
1248 {
1249 *enable = (bmm150_bool_t)((prev >> (uint8_t)(status)) & 0x01); /* set bool */
1250 }
1251 else /* index < 6 */
1252 {
1253 *enable = (bmm150_bool_t)(!((prev >> (uint8_t)(status)) & 0x01)); /* set bool */
1254 }
1255
1256 return 0; /* success return 0 */
1257}
1258
1271{
1272 uint8_t res;
1273 uint8_t prev;
1274
1275 if (handle == NULL) /* check handle */
1276 {
1277 return 2; /* return error */
1278 }
1279 if (handle->inited != 1) /* check handle initialization */
1280 {
1281 return 3; /* return error */
1282 }
1283
1284 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1285 if (res != 0) /* check the result */
1286 {
1287 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1288
1289 return 1; /* return error */
1290 }
1291 prev &= ~(1 << 7); /* clear settings */
1292 prev |= enable << 7; /* set bool */
1293 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1294 if (res != 0) /* check the result */
1295 {
1296 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1297
1298 return 1; /* return error */
1299 }
1300
1301 return 0; /* success return 0 */
1302}
1303
1316{
1317 uint8_t res;
1318 uint8_t prev;
1319
1320 if (handle == NULL) /* check handle */
1321 {
1322 return 2; /* return error */
1323 }
1324 if (handle->inited != 1) /* check handle initialization */
1325 {
1326 return 3; /* return error */
1327 }
1328
1329 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1330 if (res != 0) /* check the result */
1331 {
1332 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1333
1334 return 1; /* return error */
1335 }
1336 *enable = (bmm150_bool_t)((prev >> 7) & 0x01); /* set bool */
1337
1338 return 0; /* success return 0 */
1339}
1340
1353{
1354 uint8_t res;
1355 uint8_t prev;
1356
1357 if (handle == NULL) /* check handle */
1358 {
1359 return 2; /* return error */
1360 }
1361 if (handle->inited != 1) /* check handle initialization */
1362 {
1363 return 3; /* return error */
1364 }
1365
1366 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1367 if (res != 0) /* check the result */
1368 {
1369 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1370
1371 return 1; /* return error */
1372 }
1373 prev &= ~(1 << 6); /* clear settings */
1374 prev |= enable << 6; /* set bool */
1375 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1376 if (res != 0) /* check the result */
1377 {
1378 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1379
1380 return 1; /* return error */
1381 }
1382
1383 return 0; /* success return 0 */
1384}
1385
1398{
1399 uint8_t res;
1400 uint8_t prev;
1401
1402 if (handle == NULL) /* check handle */
1403 {
1404 return 2; /* return error */
1405 }
1406 if (handle->inited != 1) /* check handle initialization */
1407 {
1408 return 3; /* return error */
1409 }
1410
1411 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1412 if (res != 0) /* check the result */
1413 {
1414 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1415
1416 return 1; /* return error */
1417 }
1418 *enable = (bmm150_bool_t)((prev >> 6) & 0x01); /* set bool */
1419
1420 return 0; /* success return 0 */
1421}
1422
1435{
1436 uint8_t res;
1437 uint8_t prev;
1438
1439 if (handle == NULL) /* check handle */
1440 {
1441 return 2; /* return error */
1442 }
1443 if (handle->inited != 1) /* check handle initialization */
1444 {
1445 return 3; /* return error */
1446 }
1447
1448 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1449 if (res != 0) /* check the result */
1450 {
1451 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1452
1453 return 1; /* return error */
1454 }
1455 prev &= ~(1 << 5); /* clear settings */
1456 prev |= (uint8_t)(!enable) << 5; /* set bool */
1457 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1458 if (res != 0) /* check the result */
1459 {
1460 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1461
1462 return 1; /* return error */
1463 }
1464
1465 return 0; /* success return 0 */
1466}
1467
1480{
1481 uint8_t res;
1482 uint8_t prev;
1483
1484 if (handle == NULL) /* check handle */
1485 {
1486 return 2; /* return error */
1487 }
1488 if (handle->inited != 1) /* check handle initialization */
1489 {
1490 return 3; /* return error */
1491 }
1492
1493 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1494 if (res != 0) /* check the result */
1495 {
1496 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1497
1498 return 1; /* return error */
1499 }
1500 *enable = (bmm150_bool_t)(!((prev >> 5) & 0x01)); /* set bool */
1501
1502 return 0; /* success return 0 */
1503}
1504
1517{
1518 uint8_t res;
1519 uint8_t prev;
1520
1521 if (handle == NULL) /* check handle */
1522 {
1523 return 2; /* return error */
1524 }
1525 if (handle->inited != 1) /* check handle initialization */
1526 {
1527 return 3; /* return error */
1528 }
1529
1530 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1531 if (res != 0) /* check the result */
1532 {
1533 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1534
1535 return 1; /* return error */
1536 }
1537 prev &= ~(1 << 4); /* clear settings */
1538 prev |= (uint8_t)(!enable) << 4; /* set bool */
1539 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1540 if (res != 0) /* check the result */
1541 {
1542 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1543
1544 return 1; /* return error */
1545 }
1546
1547 return 0; /* success return 0 */
1548}
1549
1562{
1563 uint8_t res;
1564 uint8_t prev;
1565
1566 if (handle == NULL) /* check handle */
1567 {
1568 return 2; /* return error */
1569 }
1570 if (handle->inited != 1) /* check handle initialization */
1571 {
1572 return 3; /* return error */
1573 }
1574
1575 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1576 if (res != 0) /* check the result */
1577 {
1578 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1579
1580 return 1; /* return error */
1581 }
1582 *enable = (bmm150_bool_t)(!((prev >> 4) & 0x01)); /* set bool */
1583
1584 return 0; /* success return 0 */
1585}
1586
1599{
1600 uint8_t res;
1601 uint8_t prev;
1602
1603 if (handle == NULL) /* check handle */
1604 {
1605 return 2; /* return error */
1606 }
1607 if (handle->inited != 1) /* check handle initialization */
1608 {
1609 return 3; /* return error */
1610 }
1611
1612 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1613 if (res != 0) /* check the result */
1614 {
1615 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1616
1617 return 1; /* return error */
1618 }
1619 prev &= ~(1 << 3); /* clear settings */
1620 prev |= (uint8_t)(!enable) << 3; /* set bool */
1621 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1622 if (res != 0) /* check the result */
1623 {
1624 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1625
1626 return 1; /* return error */
1627 }
1628
1629 return 0; /* success return 0 */
1630}
1631
1644{
1645 uint8_t res;
1646 uint8_t prev;
1647
1648 if (handle == NULL) /* check handle */
1649 {
1650 return 2; /* return error */
1651 }
1652 if (handle->inited != 1) /* check handle initialization */
1653 {
1654 return 3; /* return error */
1655 }
1656
1657 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1658 if (res != 0) /* check the result */
1659 {
1660 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1661
1662 return 1; /* return error */
1663 }
1664 *enable = (bmm150_bool_t)(!((prev >> 3) & 0x01)); /* set bool */
1665
1666 return 0; /* success return 0 */
1667}
1668
1681{
1682 uint8_t res;
1683 uint8_t prev;
1684
1685 if (handle == NULL) /* check handle */
1686 {
1687 return 2; /* return error */
1688 }
1689 if (handle->inited != 1) /* check handle initialization */
1690 {
1691 return 3; /* return error */
1692 }
1693
1694 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1695 if (res != 0) /* check the result */
1696 {
1697 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1698
1699 return 1; /* return error */
1700 }
1701 prev &= ~(1 << 2); /* clear settings */
1702 prev |= polarity << 2; /* set polarity */
1703 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1704 if (res != 0) /* check the result */
1705 {
1706 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1707
1708 return 1; /* return error */
1709 }
1710
1711 return 0; /* success return 0 */
1712}
1713
1726{
1727 uint8_t res;
1728 uint8_t prev;
1729
1730 if (handle == NULL) /* check handle */
1731 {
1732 return 2; /* return error */
1733 }
1734 if (handle->inited != 1) /* check handle initialization */
1735 {
1736 return 3; /* return error */
1737 }
1738
1739 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1740 if (res != 0) /* check the result */
1741 {
1742 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1743
1744 return 1; /* return error */
1745 }
1746 *polarity = (bmm150_data_ready_pin_polarity_t)((prev >> 2) & 0x01); /* set polarity */
1747
1748 return 0; /* success return 0 */
1749}
1750
1763{
1764 uint8_t res;
1765 uint8_t prev;
1766
1767 if (handle == NULL) /* check handle */
1768 {
1769 return 2; /* return error */
1770 }
1771 if (handle->inited != 1) /* check handle initialization */
1772 {
1773 return 3; /* return error */
1774 }
1775
1776 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1777 if (res != 0) /* check the result */
1778 {
1779 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1780
1781 return 1; /* return error */
1782 }
1783 prev &= ~(1 << 1); /* clear settings */
1784 prev |= enable << 1; /* set bool */
1785 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1786 if (res != 0) /* check the result */
1787 {
1788 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1789
1790 return 1; /* return error */
1791 }
1792
1793 return 0; /* success return 0 */
1794}
1795
1808{
1809 uint8_t res;
1810 uint8_t prev;
1811
1812 if (handle == NULL) /* check handle */
1813 {
1814 return 2; /* return error */
1815 }
1816 if (handle->inited != 1) /* check handle initialization */
1817 {
1818 return 3; /* return error */
1819 }
1820
1821 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1822 if (res != 0) /* check the result */
1823 {
1824 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1825
1826 return 1; /* return error */
1827 }
1828 *enable = (bmm150_bool_t)((prev >> 1) & 0x01); /* set bool */
1829
1830 return 0; /* success return 0 */
1831}
1832
1845{
1846 uint8_t res;
1847 uint8_t prev;
1848
1849 if (handle == NULL) /* check handle */
1850 {
1851 return 2; /* return error */
1852 }
1853 if (handle->inited != 1) /* check handle initialization */
1854 {
1855 return 3; /* return error */
1856 }
1857
1858 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1859 if (res != 0) /* check the result */
1860 {
1861 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1862
1863 return 1; /* return error */
1864 }
1865 prev &= ~(1 << 0); /* clear settings */
1866 prev |= polarity << 0; /* set polarity */
1867 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_3, &prev, 1); /* write config */
1868 if (res != 0) /* check the result */
1869 {
1870 handle->debug_print("bmm150: write config 3 failed.\n"); /* write config 3 failed */
1871
1872 return 1; /* return error */
1873 }
1874
1875 return 0; /* success return 0 */
1876}
1877
1890{
1891 uint8_t res;
1892 uint8_t prev;
1893
1894 if (handle == NULL) /* check handle */
1895 {
1896 return 2; /* return error */
1897 }
1898 if (handle->inited != 1) /* check handle initialization */
1899 {
1900 return 3; /* return error */
1901 }
1902
1903 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_3, &prev, 1); /* read config */
1904 if (res != 0) /* check the result */
1905 {
1906 handle->debug_print("bmm150: read config 3 failed.\n"); /* read config 3 failed */
1907
1908 return 1; /* return error */
1909 }
1910 *polarity = (bmm150_interrupt_pin_polarity_t)((prev >> 0) & 0x01); /* set polarity */
1911
1912 return 0; /* success return 0 */
1913}
1914
1926uint8_t bmm150_set_low_threshold(bmm150_handle_t *handle, int8_t threshold)
1927{
1928 uint8_t res;
1929 uint8_t prev;
1930
1931 if (handle == NULL) /* check handle */
1932 {
1933 return 2; /* return error */
1934 }
1935 if (handle->inited != 1) /* check handle initialization */
1936 {
1937 return 3; /* return error */
1938 }
1939
1940 prev = (uint8_t)threshold; /* set threshold */
1941 res = a_bmm150_iic_spi_write(handle, BMM150_REG_LOW_THRESHOLD, &prev, 1); /* write config */
1942 if (res != 0) /* check the result */
1943 {
1944 handle->debug_print("bmm150: write low threshold failed.\n"); /* write low threshold failed */
1945
1946 return 1; /* return error */
1947 }
1948
1949 return 0; /* success return 0 */
1950}
1951
1963uint8_t bmm150_get_low_threshold(bmm150_handle_t *handle, int8_t *threshold)
1964{
1965 uint8_t res;
1966 uint8_t prev;
1967
1968 if (handle == NULL) /* check handle */
1969 {
1970 return 2; /* return error */
1971 }
1972 if (handle->inited != 1) /* check handle initialization */
1973 {
1974 return 3; /* return error */
1975 }
1976
1977 res = a_bmm150_iic_spi_read(handle, BMM150_REG_LOW_THRESHOLD, &prev, 1); /* read config */
1978 if (res != 0) /* check the result */
1979 {
1980 handle->debug_print("bmm150: read low threshold failed.\n"); /* read low threshold failed */
1981
1982 return 1; /* return error */
1983 }
1984 *threshold = (int8_t)(prev); /* set threshold */
1985
1986 return 0; /* success return 0 */
1987}
1988
2000uint8_t bmm150_set_high_threshold(bmm150_handle_t *handle, int8_t threshold)
2001{
2002 uint8_t res;
2003 uint8_t prev;
2004
2005 if (handle == NULL) /* check handle */
2006 {
2007 return 2; /* return error */
2008 }
2009 if (handle->inited != 1) /* check handle initialization */
2010 {
2011 return 3; /* return error */
2012 }
2013
2014 prev = (uint8_t)threshold; /* set threshold */
2015 res = a_bmm150_iic_spi_write(handle, BMM150_REG_HIGH_THRESHOLD, &prev, 1); /* write config */
2016 if (res != 0) /* check the result */
2017 {
2018 handle->debug_print("bmm150: write high threshold failed.\n"); /* write high threshold failed */
2019
2020 return 1; /* return error */
2021 }
2022
2023 return 0; /* success return 0 */
2024}
2025
2037uint8_t bmm150_get_high_threshold(bmm150_handle_t *handle, int8_t *threshold)
2038{
2039 uint8_t res;
2040 uint8_t prev;
2041
2042 if (handle == NULL) /* check handle */
2043 {
2044 return 2; /* return error */
2045 }
2046 if (handle->inited != 1) /* check handle initialization */
2047 {
2048 return 3; /* return error */
2049 }
2050
2051 res = a_bmm150_iic_spi_read(handle, BMM150_REG_HIGH_THRESHOLD, &prev, 1); /* read config */
2052 if (res != 0) /* check the result */
2053 {
2054 handle->debug_print("bmm150: read high threshold failed.\n"); /* read high threshold failed */
2055
2056 return 1; /* return error */
2057 }
2058 *threshold = (int8_t)(prev); /* set threshold */
2059
2060 return 0; /* success return 0 */
2061}
2062
2078uint8_t bmm150_set_repxy_number(bmm150_handle_t *handle, uint8_t number)
2079{
2080 uint8_t res;
2081 uint8_t prev;
2082
2083 if (handle == NULL) /* check handle */
2084 {
2085 return 2; /* return error */
2086 }
2087 if (handle->inited != 1) /* check handle initialization */
2088 {
2089 return 3; /* return error */
2090 }
2091
2092 prev = number; /* set number */
2093 res = a_bmm150_iic_spi_write(handle, BMM150_REG_REPXY, &prev, 1); /* write config */
2094 if (res != 0) /* check the result */
2095 {
2096 handle->debug_print("bmm150: write repxy failed.\n"); /* write repxy failed */
2097
2098 return 1; /* return error */
2099 }
2100
2101 return 0; /* success return 0 */
2102}
2103
2115uint8_t bmm150_get_repxy_number(bmm150_handle_t *handle, uint8_t *number)
2116{
2117 uint8_t res;
2118
2119 if (handle == NULL) /* check handle */
2120 {
2121 return 2; /* return error */
2122 }
2123 if (handle->inited != 1) /* check handle initialization */
2124 {
2125 return 3; /* return error */
2126 }
2127
2128 res = a_bmm150_iic_spi_read(handle, BMM150_REG_REPXY, number, 1); /* read config */
2129 if (res != 0) /* check the result */
2130 {
2131 handle->debug_print("bmm150: read repxy failed.\n"); /* read repxy failed */
2132
2133 return 1; /* return error */
2134 }
2135
2136 return 0; /* success return 0 */
2137}
2138
2154uint8_t bmm150_set_repz_number(bmm150_handle_t *handle, uint8_t number)
2155{
2156 uint8_t res;
2157 uint8_t prev;
2158
2159 if (handle == NULL) /* check handle */
2160 {
2161 return 2; /* return error */
2162 }
2163 if (handle->inited != 1) /* check handle initialization */
2164 {
2165 return 3; /* return error */
2166 }
2167
2168 prev = number; /* set number */
2169 res = a_bmm150_iic_spi_write(handle, BMM150_REG_REPZ, &prev, 1); /* write config */
2170 if (res != 0) /* check the result */
2171 {
2172 handle->debug_print("bmm150: write repz failed.\n"); /* write repz failed */
2173
2174 return 1; /* return error */
2175 }
2176
2177 return 0; /* success return 0 */
2178}
2179
2191uint8_t bmm150_get_repz_number(bmm150_handle_t *handle, uint8_t *number)
2192{
2193 uint8_t res;
2194
2195 if (handle == NULL) /* check handle */
2196 {
2197 return 2; /* return error */
2198 }
2199 if (handle->inited != 1) /* check handle initialization */
2200 {
2201 return 3; /* return error */
2202 }
2203
2204 res = a_bmm150_iic_spi_read(handle, BMM150_REG_REPZ, number, 1); /* read config */
2205 if (res != 0) /* check the result */
2206 {
2207 handle->debug_print("bmm150: read repz failed.\n"); /* read repz failed */
2208
2209 return 1; /* return error */
2210 }
2211
2212 return 0; /* success return 0 */
2213}
2214
2228uint8_t bmm150_read(bmm150_handle_t *handle, int16_t raw[3], float ut[3])
2229{
2230 uint8_t res;
2231 uint8_t prev;
2232 uint8_t mode;
2233 uint8_t buf[8];
2234 uint16_t temp;
2235
2236 if (handle == NULL) /* check handle */
2237 {
2238 return 2; /* return error */
2239 }
2240 if (handle->inited != 1) /* check handle initialization */
2241 {
2242 return 3; /* return error */
2243 }
2244
2245 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
2246 if (res != 0) /* check the result */
2247 {
2248 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
2249
2250 return 1; /* return error */
2251 }
2252 mode = (prev >> 1) & 0x03; /* get mode config */
2253 if (mode == 0) /* normal mode */
2254 {
2255 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_X_LSB, buf, 8); /* read data */
2256 if (res != 0) /* check the result */
2257 {
2258 handle->debug_print("bmm150: read data failed.\n"); /* read data failed */
2259
2260 return 1; /* return error */
2261 }
2262 if (((buf[1] >> 7) & 0x01) != 0) /* check signed bit */
2263 {
2264 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3) | (0x7 << 13)); /* set data */
2265 raw[0] = temp; /* set x */
2266 }
2267 else
2268 {
2269 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3)); /* make data */
2270 raw[0] = temp; /* set x */
2271 }
2272 if (((buf[3] >> 7) & 0x01) != 0) /* check signed bit */
2273 {
2274 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3) | (0x7 << 13)); /* set data */
2275 raw[1] = temp; /* set y */
2276 }
2277 else
2278 {
2279 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3)); /* make data */
2280 raw[1] = temp; /* set y */
2281 }
2282 if (((buf[5] >> 7) & 0x01) != 0) /* check signed bit */
2283 {
2284 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1) | (0x1 << 15)); /* set data */
2285 raw[2] = temp; /* set z */
2286 }
2287 else
2288 {
2289 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1)); /* make data */
2290 raw[2] = temp; /* set z */
2291 }
2292 temp = (uint16_t)(((uint16_t)buf[7]) << 6 | (buf[6] >> 2)); /* make data */
2293 ut[0] = a_bmm150_compensate_x(handle, raw[0], temp); /* compensate x */
2294 ut[1] = a_bmm150_compensate_y(handle, raw[1], temp); /* compensate y */
2295 ut[2] = a_bmm150_compensate_z(handle, raw[2], temp); /* compensate z */
2296
2297 return 0; /* success return 0 */
2298 }
2299 else /* forced mode */
2300 {
2301 uint16_t timeout;
2302
2303 res = a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_1, &prev, 1); /* read config */
2304 if (res != 0) /* check the result */
2305 {
2306 handle->debug_print("bmm150: read config 1 failed.\n"); /* read config 1 failed */
2307
2308 return 1; /* return error */
2309 }
2310 prev &= ~(3 << 1); /* clear settings */
2311 prev |= 0x01 << 1; /* set forced mode */
2312 res = a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_1, &prev, 1); /* write config */
2313 if (res != 0) /* check the result */
2314 {
2315 handle->debug_print("bmm150: write config 1 failed.\n"); /* write config 1 failed */
2316
2317 return 1; /* return error */
2318 }
2319
2320 timeout = 1000; /* timeout 1s */
2321 while (timeout != 0) /* check timeout */
2322 {
2323 res = a_bmm150_iic_spi_read(handle, BMM150_REG_RHALL_LSB, &prev, 1); /* read rhall lsb */
2324 if (res != 0) /* check the result */
2325 {
2326 handle->debug_print("bmm150: read rhall lsb failed.\n"); /* read rhall lsb failed */
2327
2328 return 1; /* return error */
2329 }
2330 if ((prev & 0x01) != 0) /* check data ready bit */
2331 {
2332 break; /* break */
2333 }
2334 timeout--; /* timeout-- */
2335 handle->delay_ms(1); /* delay 1ms */
2336 }
2337 if (timeout == 0) /* check timeout */
2338 {
2339 handle->debug_print("bmm150: read timeout.\n"); /* read timeout */
2340
2341 return 4; /* return error */
2342 }
2343
2344 res = a_bmm150_iic_spi_read(handle, BMM150_REG_DATA_X_LSB, buf, 8); /* read data */
2345 if (res != 0) /* check the result */
2346 {
2347 handle->debug_print("bmm150: read data failed.\n"); /* read data failed */
2348
2349 return 1; /* return error */
2350 }
2351 if (((buf[1] >> 7) & 0x01) != 0) /* check signed bit */
2352 {
2353 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3) | (0x7 << 13)); /* set data */
2354 raw[0] = temp; /* set x */
2355 }
2356 else
2357 {
2358 temp = (int16_t)(((uint16_t)buf[1]) << 5 | (buf[0] >> 3)); /* make data */
2359 raw[0] = temp; /* set x */
2360 }
2361 if (((buf[3] >> 7) & 0x01) != 0) /* check signed bit */
2362 {
2363 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3) | (0x7 << 13)); /* set data */
2364 raw[1] = temp; /* set y */
2365 }
2366 else
2367 {
2368 temp = (int16_t)(((uint16_t)buf[3]) << 5 | (buf[2] >> 3)); /* make data */
2369 raw[1] = temp; /* set y */
2370 }
2371 if (((buf[5] >> 7) & 0x01) != 0) /* check signed bit */
2372 {
2373 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1) | (0x1 << 15)); /* set data */
2374 raw[2] = temp; /* set z */
2375 }
2376 else
2377 {
2378 temp = (int16_t)(((uint16_t)buf[5]) << 7 | (buf[4] >> 1)); /* make data */
2379 raw[2] = temp; /* set z */
2380 }
2381 temp = (uint16_t)(((uint16_t)buf[7]) << 6 | (buf[6] >> 2)); /* make data */
2382 ut[0] = a_bmm150_compensate_x(handle, raw[0], temp); /* compensate x */
2383 ut[1] = a_bmm150_compensate_y(handle, raw[1], temp); /* compensate y */
2384 ut[2] = a_bmm150_compensate_z(handle, raw[2], temp); /* compensate z */
2385
2386 return 0; /* success return 0 */
2387 }
2388}
2389
2401{
2402 uint8_t res;
2403 uint8_t prev;
2404
2405 if (handle == NULL) /* check handle */
2406 {
2407 return 2; /* return error */
2408 }
2409 if (handle->inited != 1) /* check handle initialization */
2410 {
2411 return 3; /* return error */
2412 }
2413
2414 res = a_bmm150_iic_spi_read(handle, BMM150_REG_INTERRUPT_STATUS, &prev, 1); /* read config */
2415 if (res != 0) /* check the result */
2416 {
2417 handle->debug_print("bmm150: read interrupt status failed.\n"); /* read interrupt status failed */
2418
2419 return 1; /* return error */
2420 }
2421
2422 if (prev != 0) /* check valid bits */
2423 {
2424 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_DATA_OVERRUN) & 0x01) != 0) /* check data overrun */
2425 {
2426 if (handle->receive_callback != NULL) /* not null */
2427 {
2428 handle->receive_callback(BMM150_INTERRUPT_STATUS_DATA_OVERRUN); /* run the callback */
2429 }
2430 }
2431 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_OVERFLOW) & 0x01) != 0) /* check overflow */
2432 {
2433 if (handle->receive_callback != NULL) /* not null */
2434 {
2435 handle->receive_callback(BMM150_INTERRUPT_STATUS_OVERFLOW); /* run the callback */
2436 }
2437 }
2438 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z) & 0x01) != 0) /* check high threshold z */
2439 {
2440 if (handle->receive_callback != NULL) /* not null */
2441 {
2442 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Z); /* run the callback */
2443 }
2444 }
2445 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y) & 0x01) != 0) /* check high threshold y */
2446 {
2447 if (handle->receive_callback != NULL) /* not null */
2448 {
2449 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_Y); /* run the callback */
2450 }
2451 }
2452 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X) & 0x01) != 0) /* check high threshold z */
2453 {
2454 if (handle->receive_callback != NULL) /* not null */
2455 {
2456 handle->receive_callback(BMM150_INTERRUPT_STATUS_HIGH_THRESHOLD_X); /* run the callback */
2457 }
2458 }
2459 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z) & 0x01) != 0) /* check low threshold z */
2460 {
2461 if (handle->receive_callback != NULL) /* not null */
2462 {
2463 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Z); /* run the callback */
2464 }
2465 }
2466 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y) & 0x01) != 0) /* check low threshold y */
2467 {
2468 if (handle->receive_callback != NULL) /* not null */
2469 {
2470 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_Y); /* run the callback */
2471 }
2472 }
2473 if (((prev >> (uint8_t)BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X) & 0x01) != 0) /* check low threshold x */
2474 {
2475 if (handle->receive_callback != NULL) /* not null */
2476 {
2477 handle->receive_callback(BMM150_INTERRUPT_STATUS_LOW_THRESHOLD_X); /* run the callback */
2478 }
2479 }
2480 }
2481
2482 return 0; /* success return 0 */
2483}
2484
2497{
2498 if (handle == NULL) /* check handle */
2499 {
2500 return 2; /* return error */
2501 }
2502 if (handle->inited != 1) /* check handle initialization */
2503 {
2504 return 3; /* return error */
2505 }
2506
2507 *reg = (int8_t)(ut / 6.0f); /* convert real data to register data */
2508
2509 return 0; /* success return 0 */
2510}
2511
2524{
2525 if (handle == NULL) /* check handle */
2526 {
2527 return 2; /* return error */
2528 }
2529 if (handle->inited != 1) /* check handle initialization */
2530 {
2531 return 3; /* return error */
2532 }
2533
2534 *ut = (float)(reg) * 6.0f; /* convert raw data to real data */
2535
2536 return 0; /* success return 0 */
2537}
2538
2554{
2555 uint8_t id;
2556 uint8_t prev;
2557
2558 if (handle == NULL) /* check handle */
2559 {
2560 return 2; /* return error */
2561 }
2562 if (handle->debug_print == NULL) /* check debug_print */
2563 {
2564 return 3; /* return error */
2565 }
2566 if (handle->iic_init == NULL) /* check iic_init */
2567 {
2568 handle->debug_print("bmm150: iic_init is null.\n"); /* iic_init is null */
2569
2570 return 3; /* return error */
2571 }
2572 if (handle->iic_deinit == NULL) /* check iic_deinit */
2573 {
2574 handle->debug_print("bmm150: iic_deinit is null.\n"); /* iic_deinit is null */
2575
2576 return 3; /* return error */
2577 }
2578 if (handle->iic_read == NULL) /* check iic_read */
2579 {
2580 handle->debug_print("bmm150: iic_read is null.\n"); /* iic_read is null */
2581
2582 return 3; /* return error */
2583 }
2584 if (handle->iic_write == NULL) /* check iic_write */
2585 {
2586 handle->debug_print("bmm150: iic_write is null.\n"); /* iic_write is null */
2587
2588 return 3; /* return error */
2589 }
2590 if (handle->spi_init == NULL) /* check spi_init */
2591 {
2592 handle->debug_print("bmm150: spi_init is null.\n"); /* spi_init is null */
2593
2594 return 3; /* return error */
2595 }
2596 if (handle->spi_deinit == NULL) /* check spi_deinit */
2597 {
2598 handle->debug_print("bmm150: spi_deinit is null.\n"); /* spi_deinit is null */
2599
2600 return 3; /* return error */
2601 }
2602 if (handle->spi_read == NULL) /* check spi_read */
2603 {
2604 handle->debug_print("bmm150: spi_read is null.\n"); /* spi_read is null */
2605
2606 return 3; /* return error */
2607 }
2608 if (handle->spi_write == NULL) /* check spi_write */
2609 {
2610 handle->debug_print("bmm150: spi_write is null.\n"); /* spi_write is null */
2611
2612 return 3; /* return error */
2613 }
2614 if (handle->delay_ms == NULL) /* check delay_ms */
2615 {
2616 handle->debug_print("bmm150: delay_ms is null.\n"); /* delay_ms is null */
2617
2618 return 3; /* return error */
2619 }
2620 if (handle->receive_callback == NULL) /* check receive_callback */
2621 {
2622 handle->debug_print("bmm150: receive_callback is null.\n"); /* receive_callback is null */
2623
2624 return 3; /* return error */
2625 }
2626
2627 if (handle->iic_spi == BMM150_INTERFACE_IIC) /* iic interface */
2628 {
2629 if (handle->iic_init() != 0) /* initialize iic bus */
2630 {
2631 handle->debug_print("bmm150: iic init failed.\n"); /* iic init failed */
2632
2633 return 1; /* return error */
2634 }
2635 }
2636 else /* spi interface */
2637 {
2638 if (handle->spi_init() != 0) /* initialize spi bus */
2639 {
2640 handle->debug_print("bmm150: spi init failed.\n"); /* spi init failed */
2641
2642 return 1; /* return error */
2643 }
2644 }
2645
2646 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* soft reset */
2647 {
2648 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
2649 (void)a_bmm150_close(handle); /* close */
2650
2651 return 4; /* return error */
2652 }
2653 prev &= ~(1 << 1); /* clear settings */
2654 prev |= 1 << 1; /* set bool */
2655 if (a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* soft reset */
2656 {
2657 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
2658 (void)a_bmm150_close(handle); /* close */
2659
2660 return 4; /* return error */
2661 }
2662 handle->delay_ms(5); /* delay 5ms */
2663
2664 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* read config */
2665 {
2666 handle->debug_print("bmm150: read config 0 failed.\n"); /* read config 0 failed */
2667
2668 return 5; /* return error */
2669 }
2670 prev &= ~(1 << 0); /* clear settings */
2671 prev |= 1 << 0; /* set bool */
2672 if (a_bmm150_iic_spi_write(handle, BMM150_REG_CONFIG_0, &prev, 1) != 0) /* write config */
2673 {
2674 handle->debug_print("bmm150: write config 0 failed.\n"); /* write config 0 failed */
2675
2676 return 5; /* return error */
2677 }
2678 handle->delay_ms(5); /* delay 5ms */
2679
2680 if (a_bmm150_iic_spi_read(handle, BMM150_REG_CHIP_ID, (uint8_t *)&id, 1) != 0) /* read id */
2681 {
2682 handle->debug_print("bmm150: read failed.\n"); /* read failed */
2683 (void)a_bmm150_close(handle); /* close */
2684
2685 return 6; /* return error */
2686 }
2687 if (id != 0x32) /* check id */
2688 {
2689 handle->debug_print("bmm150: id is invalid.\n"); /* id is invalid */
2690 (void)a_bmm150_close(handle); /* close */
2691
2692 return 6; /* return error */
2693 }
2694 if (a_bmm150_load_trim(handle) != 0) /* load trim */
2695 {
2696 handle->debug_print("bmm150: load trim failed.\n"); /* load trim failed */
2697 (void)a_bmm150_close(handle); /* close */
2698
2699 return 7; /* return error */
2700 }
2701 handle->inited = 1; /* flag finish initialization */
2702
2703 return 0; /* success return 0 */
2704}
2705
2717{
2718 uint8_t res;
2719
2720 if (handle == NULL) /* check handle */
2721 {
2722 return 2; /* return error */
2723 }
2724 if (handle->inited != 1) /* check handle initialization */
2725 {
2726 return 3; /* return error */
2727 }
2728
2729 res = a_bmm150_close(handle); /* close */
2730 if (res != 0) /* check result */
2731 {
2732 return 1; /* return error */
2733 }
2734 else
2735 {
2736 handle->inited = 0; /* flag close */
2737
2738 return 0; /* success return 0 */
2739 }
2740}
2741
2755uint8_t bmm150_set_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2756{
2757 uint8_t res;
2758
2759 if (handle == NULL) /* check handle */
2760 {
2761 return 2; /* return error */
2762 }
2763 if (handle->inited != 1) /* check handle initialization */
2764 {
2765 return 3; /* return error */
2766 }
2767
2768 res = a_bmm150_iic_spi_write(handle, reg, buf, len); /* write data */
2769 if (res != 0) /* check the result */
2770 {
2771 return 1; /* return error */
2772 }
2773
2774 return 0; /* success return 0 */
2775}
2776
2790uint8_t bmm150_get_reg(bmm150_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2791{
2792 uint8_t res;
2793
2794 if (handle == NULL) /* check handle */
2795 {
2796 return 2; /* return error */
2797 }
2798 if (handle->inited != 1) /* check handle initialization */
2799 {
2800 return 3; /* return error */
2801 }
2802
2803 res = a_bmm150_iic_spi_read(handle, reg, buf, len); /* read data */
2804 if (res != 0) /* check the result */
2805 {
2806 return 1; /* return error */
2807 }
2808
2809 return 0; /* success return 0 */
2810}
2811
2821{
2822 if (info == NULL) /* check handle */
2823 {
2824 return 2; /* return error */
2825 }
2826
2827 memset(info, 0, sizeof(bmm150_info_t)); /* initialize bmm150 info structure */
2828 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2829 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2830 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
2831 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2832 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2833 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2834 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2835 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2836 info->driver_version = DRIVER_VERSION; /* set driver version */
2837
2838 return 0; /* success return 0 */
2839}
#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]