LibDriver AS5600
Loading...
Searching...
No Matches
driver_as5600.c
Go to the documentation of this file.
1
36
37#include "driver_as5600.h"
38
42#define CHIP_NAME "AMS AS5600"
43#define MANUFACTURER_NAME "AMS"
44#define SUPPLY_VOLTAGE_MIN 4.5f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 100.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
50
54#define AS5600_ADDRESS 0x6C
55
59#define AS5600_REG_ZMCO 0x00
60#define AS5600_REG_ZPOS_H 0x01
61#define AS5600_REG_ZPOS_L 0x02
62#define AS5600_REG_MPOS_H 0x03
63#define AS5600_REG_MPOS_L 0x04
64#define AS5600_REG_MANG_H 0x05
65#define AS5600_REG_MANG_L 0x06
66#define AS5600_REG_CONF_H 0x07
67#define AS5600_REG_CONF_L 0x08
68#define AS5600_REG_RAW_ANGLE_H 0x0C
69#define AS5600_REG_RAW_ANGLE_L 0x0D
70#define AS5600_REG_ANGLE_H 0x0E
71#define AS5600_REG_ANGLE_L 0x0F
72#define AS5600_REG_STATUS 0x0B
73#define AS5600_REG_AGC 0x1A
74#define AS5600_REG_MAGNITUDE_H 0x1B
75#define AS5600_REG_MAGNITUDE_L 0x1C
76#define AS5600_REG_BURN 0xFF
77
89static uint8_t a_as5600_iic_read(as5600_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
90{
91 if (handle->iic_read(AS5600_ADDRESS, reg, data, len) != 0) /* read the register */
92 {
93 return 1; /* return error */
94 }
95 else
96 {
97 return 0; /* success return 0 */
98 }
99}
100
112static uint8_t a_as5600_iic_write(as5600_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
113{
114 if (handle->iic_write(AS5600_ADDRESS, reg, data, len) != 0) /* write the register */
115 {
116 return 1; /* return error */
117 }
118 else
119 {
120 return 0; /* success return 0 */
121 }
122}
123
135{
136 if (handle == NULL) /* check handle */
137 {
138 return 2; /* return error */
139 }
140 if (handle->debug_print == NULL) /* check debug_print */
141 {
142 return 3; /* return error */
143 }
144 if (handle->iic_init == NULL) /* check iic_init */
145 {
146 handle->debug_print("as5600: iic_init is null.\n"); /* iic_init is null */
147
148 return 3; /* return error */
149 }
150 if (handle->iic_deinit == NULL) /* check iic_init */
151 {
152 handle->debug_print("as5600: iic_deinit is null.\n"); /* iic_deinit is null */
153
154 return 3; /* return error */
155 }
156 if (handle->iic_read == NULL) /* check iic_read */
157 {
158 handle->debug_print("as5600: iic_read is null.\n"); /* iic_read is null */
159
160 return 3; /* return error */
161 }
162 if (handle->iic_write == NULL) /* check iic_write */
163 {
164 handle->debug_print("as5600: iic_write is null.\n"); /* iic_write is null */
165
166 return 3; /* return error */
167 }
168 if (handle->delay_ms == NULL) /* check delay_ms */
169 {
170 handle->debug_print("as5600: delay_ms is null.\n"); /* delay_ms is null */
171
172 return 3; /* return error */
173 }
174
175 if (handle->iic_init() != 0) /* iic init */
176 {
177 handle->debug_print("as5600: iic init failed.\n"); /* iic init failed */
178
179 return 1; /* return error */
180 }
181 handle->inited = 1; /* flag finish initialization */
182
183 return 0; /* success return 0 */
184}
185
197{
198 if (handle == NULL) /* check handle */
199 {
200 return 2; /* return error */
201 }
202 if (handle->inited != 1) /* check handle initialization */
203 {
204 return 3; /* return error */
205 }
206
207 if (handle->iic_deinit() != 0) /* iic deinit */
208 {
209 handle->debug_print("as5600: iic deinit failed.\n"); /* iic deinit failed */
210
211 return 1; /* return error */
212 }
213 handle->inited = 0; /* flag close */
214
215 return 0; /* success return 0 */
216}
217
230uint8_t as5600_read(as5600_handle_t *handle, uint16_t *angle_raw, float *deg)
231{
232 uint8_t buf[2];
233
234 if (handle == NULL) /* check handle */
235 {
236 return 2; /* return error */
237 }
238 if (handle->inited != 1) /* check handle initialization */
239 {
240 return 3; /* return error */
241 }
242
243 if (a_as5600_iic_read(handle, AS5600_REG_RAW_ANGLE_H, buf, 2) != 0) /* read conf */
244 {
245 handle->debug_print("as5600: get raw angle failed.\n"); /* get raw angle failed */
246
247 return 1; /* return error */
248 }
249 else
250 {
251 *angle_raw = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the raw angle */
252 *deg = (float)(*angle_raw ) * (360.0f / 4096.0f); /* convert the raw data to the real data */
253
254 return 0; /* success return 0 */
255 }
256}
257
269uint8_t as5600_angle_convert_to_register(as5600_handle_t *handle, float deg, uint16_t *reg)
270{
271 if (handle == NULL) /* check handle */
272 {
273 return 2; /* return error */
274 }
275 if (handle->inited != 1) /* check handle initialization */
276 {
277 return 3; /* return error */
278 }
279
280 *reg = (uint16_t)(deg / (360.0f / 4096.0f)); /* convert real data to register data */
281
282 return 0; /* success return 0 */
283}
284
296uint8_t as5600_angle_convert_to_data(as5600_handle_t *handle, uint16_t reg, float *deg)
297{
298 if (handle == NULL) /* check handle */
299 {
300 return 2; /* return error */
301 }
302 if (handle->inited != 1) /* check handle initialization */
303 {
304 return 3; /* return error */
305 }
306
307 *deg = (float)(reg) * (360.0f / 4096.0f); /* convert raw data to real data */
308
309 return 0; /* success return 0 */
310}
311
324uint8_t as5600_set_start_position(as5600_handle_t *handle, uint16_t pos)
325{
326 uint8_t buf[2];
327
328 if (handle == NULL) /* check handle */
329 {
330 return 2; /* return error */
331 }
332 if (handle->inited != 1) /* check handle initialization */
333 {
334 return 3; /* return error */
335 }
336 if (pos > 0xFFF) /* check the pos */
337 {
338 handle->debug_print("as5600: pos is over 0xFFF.\n"); /* pos is over 0xFFF */
339
340 return 4; /* return error */
341 }
342
343 buf[0] = (pos >> 8) & 0x0F; /* set high part */
344 buf[1] = (pos >> 0) & 0xFF; /* set low part */
345 if (a_as5600_iic_write(handle, AS5600_REG_ZPOS_H, buf, 2) != 0) /* write conf */
346 {
347 handle->debug_print("as5600: set start position failed.\n"); /* set start position failed */
348
349 return 1; /* return error */
350 }
351 else
352 {
353 return 0; /* success return 0 */
354 }
355}
356
368uint8_t as5600_get_start_position(as5600_handle_t *handle, uint16_t *pos)
369{
370 uint8_t buf[2];
371
372 if (handle == NULL) /* check handle */
373 {
374 return 2; /* return error */
375 }
376 if (handle->inited != 1) /* check handle initialization */
377 {
378 return 3; /* return error */
379 }
380
381 if (a_as5600_iic_read(handle, AS5600_REG_ZPOS_H, buf, 2) != 0) /* read conf */
382 {
383 handle->debug_print("as5600: get start position failed.\n"); /* get start position failed */
384
385 return 1; /* return error */
386 }
387 else
388 {
389 *pos = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the position */
390
391 return 0; /* success return 0 */
392 }
393}
394
407uint8_t as5600_set_stop_position(as5600_handle_t *handle, uint16_t pos)
408{
409 uint8_t buf[2];
410
411 if (handle == NULL) /* check handle */
412 {
413 return 2; /* return error */
414 }
415 if (handle->inited != 1) /* check handle initialization */
416 {
417 return 3; /* return error */
418 }
419 if (pos > 0xFFF) /* check the pos */
420 {
421 handle->debug_print("as5600: pos is over 0xFFF.\n"); /* pos is over 0xFFF */
422
423 return 4; /* return error */
424 }
425
426 buf[0] = (pos >> 8) & 0x0F; /* set high part */
427 buf[1] = (pos >> 0) & 0xFF; /* set low part */
428 if (a_as5600_iic_write(handle, AS5600_REG_MPOS_H, buf, 2) != 0) /* write conf */
429 {
430 handle->debug_print("as5600: set stop position failed.\n"); /* set stop position failed */
431
432 return 1; /* return error */
433 }
434 else
435 {
436 return 0; /* success return 0 */
437 }
438}
439
451uint8_t as5600_get_stop_position(as5600_handle_t *handle, uint16_t *pos)
452{
453 uint8_t buf[2];
454
455 if (handle == NULL) /* check handle */
456 {
457 return 2; /* return error */
458 }
459 if (handle->inited != 1) /* check handle initialization */
460 {
461 return 3; /* return error */
462 }
463
464 if (a_as5600_iic_read(handle, AS5600_REG_MPOS_H, buf, 2) != 0) /* read conf */
465 {
466 handle->debug_print("as5600: get stop position failed.\n"); /* get stop position failed */
467
468 return 1; /* return error */
469 }
470 else
471 {
472 *pos = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the position */
473
474 return 0; /* success return 0 */
475 }
476}
477
490uint8_t as5600_set_max_angle(as5600_handle_t *handle, uint16_t ang)
491{
492 uint8_t buf[2];
493
494 if (handle == NULL) /* check handle */
495 {
496 return 2; /* return error */
497 }
498 if (handle->inited != 1) /* check handle initialization */
499 {
500 return 3; /* return error */
501 }
502 if (ang > 0xFFF) /* check the ang */
503 {
504 handle->debug_print("as5600: ang is over 0xFFF.\n"); /* ang is over 0xFFF */
505
506 return 4; /* return error */
507 }
508
509 buf[0] = (ang >> 8) & 0x0F; /* set high part */
510 buf[1] = (ang >> 0) & 0xFF; /* set low part */
511 if (a_as5600_iic_write(handle, AS5600_REG_MANG_H, buf, 2) != 0) /* write conf */
512 {
513 handle->debug_print("as5600: set max angle failed.\n"); /* set max angle failed */
514
515 return 1; /* return error */
516 }
517 else
518 {
519 return 0; /* success return 0 */
520 }
521}
522
534uint8_t as5600_get_max_angle(as5600_handle_t *handle, uint16_t *ang)
535{
536 uint8_t buf[2];
537
538 if (handle == NULL) /* check handle */
539 {
540 return 2; /* return error */
541 }
542 if (handle->inited != 1) /* check handle initialization */
543 {
544 return 3; /* return error */
545 }
546
547 if (a_as5600_iic_read(handle, AS5600_REG_MANG_H, buf, 2) != 0) /* read conf */
548 {
549 handle->debug_print("as5600: get max angle failed.\n"); /* get max angle failed */
550
551 return 1; /* return error */
552 }
553 else
554 {
555 *ang = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the position */
556
557 return 0; /* success return 0 */
558 }
559}
560
573{
574 uint8_t prev;
575
576 if (handle == NULL) /* check handle */
577 {
578 return 2; /* return error */
579 }
580 if (handle->inited != 1) /* check handle initialization */
581 {
582 return 3; /* return error */
583 }
584
585 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
586 {
587 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
588
589 return 1; /* return error */
590 }
591 prev &= ~(1 << 5); /* clear the settings */
592 prev |= enable << 5; /* set the bool */
593 if (a_as5600_iic_write(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* write conf */
594 {
595 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
596
597 return 1; /* return error */
598 }
599
600 return 0; /* success return 0 */
601}
602
615{
616 uint8_t prev;
617
618 if (handle == NULL) /* check handle */
619 {
620 return 2; /* return error */
621 }
622 if (handle->inited != 1) /* check handle initialization */
623 {
624 return 3; /* return error */
625 }
626
627 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
628 {
629 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
630
631 return 1; /* return error */
632 }
633 *enable = (as5600_bool_t)((prev >> 5) & 0x1); /* get the bool */
634
635 return 0; /* success return 0 */
636}
637
650{
651 uint8_t prev;
652
653 if (handle == NULL) /* check handle */
654 {
655 return 2; /* return error */
656 }
657 if (handle->inited != 1) /* check handle initialization */
658 {
659 return 3; /* return error */
660 }
661
662 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
663 {
664 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
665
666 return 1; /* return error */
667 }
668 prev &= ~(7 << 2); /* clear the settings */
669 prev |= threshold << 2; /* set the threshold */
670 if (a_as5600_iic_write(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* write conf */
671 {
672 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
673
674 return 1; /* return error */
675 }
676
677 return 0; /* success return 0 */
678}
679
692{
693 uint8_t prev;
694
695 if (handle == NULL) /* check handle */
696 {
697 return 2; /* return error */
698 }
699 if (handle->inited != 1) /* check handle initialization */
700 {
701 return 3; /* return error */
702 }
703
704 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
705 {
706 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
707
708 return 1; /* return error */
709 }
710 *threshold = (as5600_fast_filter_threshold_t)((prev >> 2) & 0x7); /* set the threshold */
711
712 return 0; /* success return 0 */
713}
714
727{
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 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
740 {
741 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
742
743 return 1; /* return error */
744 }
745 prev &= ~(3 << 0); /* clear the settings */
746 prev |= filter << 0; /* set the filter */
747 if (a_as5600_iic_write(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* write conf */
748 {
749 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
750
751 return 1; /* return error */
752 }
753
754 return 0; /* success return 0 */
755}
756
769{
770 uint8_t prev;
771
772 if (handle == NULL) /* check handle */
773 {
774 return 2; /* return error */
775 }
776 if (handle->inited != 1) /* check handle initialization */
777 {
778 return 3; /* return error */
779 }
780
781 if (a_as5600_iic_read(handle, AS5600_REG_CONF_H, &prev, 1) != 0) /* read conf */
782 {
783 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
784
785 return 1; /* return error */
786 }
787 *filter = (as5600_slow_filter_t)(prev & 0x3); /* get the filter */
788
789 return 0; /* success return 0 */
790}
791
804{
805 uint8_t prev;
806
807 if (handle == NULL) /* check handle */
808 {
809 return 2; /* return error */
810 }
811 if (handle->inited != 1) /* check handle initialization */
812 {
813 return 3; /* return error */
814 }
815
816 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
817 {
818 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
819
820 return 1; /* return error */
821 }
822 prev &= ~(3 << 6); /* clear the settings */
823 prev |= freq << 6; /* set the freq */
824 if (a_as5600_iic_write(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* write conf */
825 {
826 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
827
828 return 1; /* return error */
829 }
830
831 return 0; /* success return 0 */
832}
833
846{
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 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
859 {
860 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
861
862 return 1; /* return error */
863 }
864 *freq = (as5600_pwm_frequency_t)((prev >> 6) & 0x3); /* set the frequency */
865
866 return 0; /* success return 0 */
867}
868
881{
882 uint8_t prev;
883
884 if (handle == NULL) /* check handle */
885 {
886 return 2; /* return error */
887 }
888 if (handle->inited != 1) /* check handle initialization */
889 {
890 return 3; /* return error */
891 }
892
893 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
894 {
895 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
896
897 return 1; /* return error */
898 }
899 prev &= ~(3 << 4); /* clear the settings */
900 prev |= stage << 4; /* set the stage */
901 if (a_as5600_iic_write(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* write conf */
902 {
903 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
904
905 return 1; /* return error */
906 }
907
908 return 0; /* success return 0 */
909}
910
923{
924 uint8_t prev;
925
926 if (handle == NULL) /* check handle */
927 {
928 return 2; /* return error */
929 }
930 if (handle->inited != 1) /* check handle initialization */
931 {
932 return 3; /* return error */
933 }
934
935 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
936 {
937 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
938
939 return 1; /* return error */
940 }
941 *stage = (as5600_output_stage_t)((prev >> 4) & 0x3); /* get the output stage */
942
943 return 0; /* success return 0 */
944}
945
958{
959 uint8_t prev;
960
961 if (handle == NULL) /* check handle */
962 {
963 return 2; /* return error */
964 }
965 if (handle->inited != 1) /* check handle initialization */
966 {
967 return 3; /* return error */
968 }
969
970 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
971 {
972 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
973
974 return 1; /* return error */
975 }
976 prev &= ~(3 << 2); /* clear the settings */
977 prev |= hysteresis << 2; /* set the hysteresis */
978 if (a_as5600_iic_write(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* write conf */
979 {
980 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
981
982 return 1; /* return error */
983 }
984
985 return 0; /* success return 0 */
986}
987
1000{
1001 uint8_t prev;
1002
1003 if (handle == NULL) /* check handle */
1004 {
1005 return 2; /* return error */
1006 }
1007 if (handle->inited != 1) /* check handle initialization */
1008 {
1009 return 3; /* return error */
1010 }
1011
1012 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
1013 {
1014 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
1015
1016 return 1; /* return error */
1017 }
1018 *hysteresis = (as5600_hysteresis_t)((prev >> 2) & 0x3); /* get the hysteresis */
1019
1020 return 0; /* success return 0 */
1021}
1022
1035{
1036 uint8_t prev;
1037
1038 if (handle == NULL) /* check handle */
1039 {
1040 return 2; /* return error */
1041 }
1042 if (handle->inited != 1) /* check handle initialization */
1043 {
1044 return 3; /* return error */
1045 }
1046
1047 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
1048 {
1049 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
1050
1051 return 1; /* return error */
1052 }
1053 prev &= ~(3 << 0); /* clear the settings */
1054 prev |= mode << 0; /* set the power mode */
1055 if (a_as5600_iic_write(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* write conf */
1056 {
1057 handle->debug_print("as5600: set conf failed.\n"); /* set conf failed */
1058
1059 return 1; /* return error */
1060 }
1061
1062 return 0; /* success return 0 */
1063}
1064
1077{
1078 uint8_t prev;
1079
1080 if (handle == NULL) /* check handle */
1081 {
1082 return 2; /* return error */
1083 }
1084 if (handle->inited != 1) /* check handle initialization */
1085 {
1086 return 3; /* return error */
1087 }
1088
1089 if (a_as5600_iic_read(handle, AS5600_REG_CONF_L, &prev, 1) != 0) /* read conf */
1090 {
1091 handle->debug_print("as5600: get conf failed.\n"); /* get conf failed */
1092
1093 return 1; /* return error */
1094 }
1095 *mode = (as5600_power_mode_t)((prev >> 0) & 0x3); /* get the power mode */
1096
1097 return 0; /* success return 0 */
1098}
1099
1111uint8_t as5600_get_raw_angle(as5600_handle_t *handle, uint16_t *ang)
1112{
1113 uint8_t buf[2];
1114
1115 if (handle == NULL) /* check handle */
1116 {
1117 return 2; /* return error */
1118 }
1119 if (handle->inited != 1) /* check handle initialization */
1120 {
1121 return 3; /* return error */
1122 }
1123
1124 if (a_as5600_iic_read(handle, AS5600_REG_RAW_ANGLE_H, buf, 2) != 0) /* read conf */
1125 {
1126 handle->debug_print("as5600: get raw angle failed.\n"); /* get raw angle failed */
1127
1128 return 1; /* return error */
1129 }
1130 else
1131 {
1132 *ang = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the angle */
1133
1134 return 0; /* success return 0 */
1135 }
1136}
1137
1149uint8_t as5600_get_angle(as5600_handle_t *handle, uint16_t *ang)
1150{
1151 uint8_t buf[2];
1152
1153 if (handle == NULL) /* check handle */
1154 {
1155 return 2; /* return error */
1156 }
1157 if (handle->inited != 1) /* check handle initialization */
1158 {
1159 return 3; /* return error */
1160 }
1161
1162 if (a_as5600_iic_read(handle, AS5600_REG_ANGLE_H, buf, 2) != 0) /* read conf */
1163 {
1164 handle->debug_print("as5600: get angle failed.\n"); /* get angle failed */
1165
1166 return 1; /* return error */
1167 }
1168 else
1169 {
1170 *ang = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the angle */
1171
1172 return 0; /* success return 0 */
1173 }
1174}
1175
1187uint8_t as5600_get_status(as5600_handle_t *handle, uint8_t *status)
1188{
1189 if (handle == NULL) /* check handle */
1190 {
1191 return 2; /* return error */
1192 }
1193 if (handle->inited != 1) /* check handle initialization */
1194 {
1195 return 3; /* return error */
1196 }
1197
1198 if (a_as5600_iic_read(handle, AS5600_REG_STATUS, status, 1) != 0) /* read conf */
1199 {
1200 handle->debug_print("as5600: get status failed.\n"); /* get status failed */
1201
1202 return 1; /* return error */
1203 }
1204 else
1205 {
1206 return 0; /* success return 0 */
1207 }
1208}
1209
1221uint8_t as5600_get_agc(as5600_handle_t *handle, uint8_t *agc)
1222{
1223 if (handle == NULL) /* check handle */
1224 {
1225 return 2; /* return error */
1226 }
1227 if (handle->inited != 1) /* check handle initialization */
1228 {
1229 return 3; /* return error */
1230 }
1231
1232 if (a_as5600_iic_read(handle, AS5600_REG_AGC, agc, 1) != 0) /* read conf */
1233 {
1234 handle->debug_print("as5600: get agc failed.\n"); /* get agc failed */
1235
1236 return 1; /* return error */
1237 }
1238 else
1239 {
1240 return 0; /* success return 0 */
1241 }
1242}
1243
1255uint8_t as5600_get_magnitude(as5600_handle_t *handle, uint16_t *magnitude)
1256{
1257 uint8_t buf[2];
1258
1259 if (handle == NULL) /* check handle */
1260 {
1261 return 2; /* return error */
1262 }
1263 if (handle->inited != 1) /* check handle initialization */
1264 {
1265 return 3; /* return error */
1266 }
1267
1268 if (a_as5600_iic_read(handle, AS5600_REG_MAGNITUDE_H, buf, 2) != 0) /* read conf */
1269 {
1270 handle->debug_print("as5600: get magnitude failed.\n"); /* get magnitude failed */
1271
1272 return 1; /* return error */
1273 }
1274 else
1275 {
1276 *magnitude = (uint16_t)(((buf[0] >> 0) & 0xF) << 8) | buf[1]; /* set the angle */
1277
1278 return 0; /* success return 0 */
1279 }
1280}
1281
1294{
1295 uint8_t prev;
1296
1297 if (handle == NULL) /* check handle */
1298 {
1299 return 2; /* return error */
1300 }
1301 if (handle->inited != 1) /* check handle initialization */
1302 {
1303 return 3; /* return error */
1304 }
1305
1306 prev = burn; /* set the burn */
1307 if (a_as5600_iic_write(handle, AS5600_REG_BURN, &prev, 1) != 0) /* write conf */
1308 {
1309 handle->debug_print("as5600: set burn failed.\n"); /* set burn failed */
1310
1311 return 1; /* return error */
1312 }
1313
1314 return 0; /* success return 0 */
1315}
1316
1330uint8_t as5600_set_reg(as5600_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1331{
1332 uint8_t res;
1333
1334 if (handle == NULL) /* check handle */
1335 {
1336 return 2; /* return error */
1337 }
1338 if (handle->inited != 1) /* check handle initialization */
1339 {
1340 return 3; /* return error */
1341 }
1342
1343 res = a_as5600_iic_write(handle, reg, buf, len); /* write data */
1344 if (res != 0) /* check result */
1345 {
1346 handle->debug_print("as5600: write register failed.\n"); /* write register failed */
1347
1348 return 1; /* return error */
1349 }
1350
1351 return 0; /* success return 0 */
1352}
1353
1367uint8_t as5600_get_reg(as5600_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
1368{
1369 uint8_t res;
1370
1371 if (handle == NULL) /* check handle */
1372 {
1373 return 2; /* return error */
1374 }
1375 if (handle->inited != 1) /* check handle initialization */
1376 {
1377 return 3; /* return error */
1378 }
1379
1380 res = a_as5600_iic_read(handle, reg, buf, len); /* read data */
1381 if (res != 0) /* check result */
1382 {
1383 handle->debug_print("as5600: read register failed.\n"); /* read register failed */
1384
1385 return 1; /* return error */
1386 }
1387
1388 return 0; /* success return 0 */
1389}
1390
1400{
1401 if (info == NULL) /* check handle */
1402 {
1403 return 2; /* return error */
1404 }
1405
1406 memset(info, 0, sizeof(as5600_info_t)); /* initialize as5600 info structure */
1407 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1408 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1409 strncpy(info->interface, "IIC", 8); /* copy interface name */
1410 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1411 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1412 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1413 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1414 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1415 info->driver_version = DRIVER_VERSION; /* set driver version */
1416
1417 return 0; /* success return 0 */
1418}
#define AS5600_REG_BURN
#define MAX_CURRENT
#define AS5600_REG_RAW_ANGLE_H
#define AS5600_REG_MAGNITUDE_H
#define AS5600_REG_MPOS_H
#define AS5600_REG_ZPOS_H
#define SUPPLY_VOLTAGE_MAX
#define AS5600_REG_STATUS
#define AS5600_ADDRESS
chip address definition
#define TEMPERATURE_MAX
#define AS5600_REG_CONF_L
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define AS5600_REG_CONF_H
#define AS5600_REG_AGC
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define AS5600_REG_ANGLE_H
#define AS5600_REG_MANG_H
driver as5600 header file
uint8_t as5600_set_burn(as5600_handle_t *handle, as5600_burn_t burn)
set the burn
uint8_t as5600_read(as5600_handle_t *handle, uint16_t *angle_raw, float *deg)
read the magnetic angle
as5600_bool_t
as5600 bool enumeration definition
uint8_t as5600_get_fast_filter_threshold(as5600_handle_t *handle, as5600_fast_filter_threshold_t *threshold)
get the fast filter threshold
uint8_t as5600_get_status(as5600_handle_t *handle, uint8_t *status)
get the status
as5600_output_stage_t
as5600 output stage enumeration definition
uint8_t as5600_info(as5600_info_t *info)
get chip's information
uint8_t as5600_get_watch_dog(as5600_handle_t *handle, as5600_bool_t *enable)
get the watch dog status
uint8_t as5600_get_start_position(as5600_handle_t *handle, uint16_t *pos)
get the start position
as5600_pwm_frequency_t
as5600 pwm frequency enumeration definition
struct as5600_handle_s as5600_handle_t
as5600 handle structure definition
uint8_t as5600_set_fast_filter_threshold(as5600_handle_t *handle, as5600_fast_filter_threshold_t threshold)
set the fast filter threshold
uint8_t as5600_angle_convert_to_register(as5600_handle_t *handle, float deg, uint16_t *reg)
convert the angle to the register raw data
struct as5600_info_s as5600_info_t
as5600 information structure definition
as5600_power_mode_t
as5600 power mode enumeration definition
uint8_t as5600_get_pwm_frequency(as5600_handle_t *handle, as5600_pwm_frequency_t *freq)
get the pwm frequency
as5600_burn_t
as5600 burn enumeration definition
uint8_t as5600_angle_convert_to_data(as5600_handle_t *handle, uint16_t reg, float *deg)
convert the register raw data to the angle
uint8_t as5600_set_slow_filter(as5600_handle_t *handle, as5600_slow_filter_t filter)
set the slow filter
uint8_t as5600_get_slow_filter(as5600_handle_t *handle, as5600_slow_filter_t *filter)
get the slow filter
uint8_t as5600_get_power_mode(as5600_handle_t *handle, as5600_power_mode_t *mode)
get the power mode
uint8_t as5600_get_magnitude(as5600_handle_t *handle, uint16_t *magnitude)
get the magnitude
uint8_t as5600_set_hysteresis(as5600_handle_t *handle, as5600_hysteresis_t hysteresis)
set the hysteresis
uint8_t as5600_set_power_mode(as5600_handle_t *handle, as5600_power_mode_t mode)
set the power mode
as5600_slow_filter_t
as5600 slow filter enumeration definition
uint8_t as5600_set_stop_position(as5600_handle_t *handle, uint16_t pos)
set the stop position
uint8_t as5600_get_agc(as5600_handle_t *handle, uint8_t *agc)
get the automatic gain control
uint8_t as5600_set_start_position(as5600_handle_t *handle, uint16_t pos)
set the start position
uint8_t as5600_set_pwm_frequency(as5600_handle_t *handle, as5600_pwm_frequency_t freq)
set the pwm frequency
uint8_t as5600_set_max_angle(as5600_handle_t *handle, uint16_t ang)
set the max angle
uint8_t as5600_init(as5600_handle_t *handle)
initialize the chip
uint8_t as5600_get_max_angle(as5600_handle_t *handle, uint16_t *ang)
get the max angle
uint8_t as5600_set_watch_dog(as5600_handle_t *handle, as5600_bool_t enable)
enable or disable the watch dog
uint8_t as5600_get_angle(as5600_handle_t *handle, uint16_t *ang)
get the angle
uint8_t as5600_get_stop_position(as5600_handle_t *handle, uint16_t *pos)
get the stop position
uint8_t as5600_get_raw_angle(as5600_handle_t *handle, uint16_t *ang)
get the raw angle
uint8_t as5600_deinit(as5600_handle_t *handle)
close the chip
as5600_fast_filter_threshold_t
as5600 fast filter threshold enumeration definition
uint8_t as5600_set_output_stage(as5600_handle_t *handle, as5600_output_stage_t stage)
set the output stage
uint8_t as5600_get_hysteresis(as5600_handle_t *handle, as5600_hysteresis_t *hysteresis)
get the hysteresis
uint8_t as5600_get_output_stage(as5600_handle_t *handle, as5600_output_stage_t *stage)
get the output stage
as5600_hysteresis_t
as5600 hysteresis enumeration definition
uint8_t as5600_get_reg(as5600_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t as5600_set_reg(as5600_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(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]