LibDriver TEA5767
Loading...
Searching...
No Matches
driver_tea5767.c
Go to the documentation of this file.
1
36
37#include "driver_tea5767.h"
38
42#define CHIP_NAME "NXP TEA5767"
43#define MANUFACTURER_NAME "NXP"
44#define SUPPLY_VOLTAGE_MIN 2.5f
45#define SUPPLY_VOLTAGE_MAX 5.0f
46#define MAX_CURRENT 10.5f
47#define TEMPERATURE_MIN -10.0f
48#define TEMPERATURE_MAX 75.0f
49#define DRIVER_VERSION 1000
50
54#define TEA5767_ADDRESS 0xC0
55
66static uint8_t a_tea5767_iic_read(tea5767_handle_t *handle, uint8_t *data, uint16_t len)
67{
68 if (handle->iic_read_cmd(TEA5767_ADDRESS, data, len) != 0) /* read the register */
69 {
70 return 1; /* return error */
71 }
72 else
73 {
74 return 0; /* success return 0 */
75 }
76}
77
88static uint8_t a_tea5767_iic_write(tea5767_handle_t *handle, uint8_t *data, uint16_t len)
89{
90 if (handle->iic_write_cmd(TEA5767_ADDRESS, data, len) != 0) /* write the register */
91 {
92 return 1; /* return error */
93 }
94 else
95 {
96 return 0; /* success return 0 */
97 }
98}
99
111{
112 if (handle == NULL) /* check handle */
113 {
114 return 2; /* return error */
115 }
116 if (handle->debug_print == NULL) /* check debug_print */
117 {
118 return 3; /* return error */
119 }
120 if (handle->iic_init == NULL) /* check iic_init */
121 {
122 handle->debug_print("tea5767: iic_init is null.\n"); /* iic_init is null */
123
124 return 3; /* return error */
125 }
126 if (handle->iic_deinit == NULL) /* check iic_deinit */
127 {
128 handle->debug_print("tea5767: iic_deinit is null.\n"); /* iic_deinit is null */
129
130 return 3; /* return error */
131 }
132 if (handle->iic_read_cmd == NULL) /* check iic_read_cmd */
133 {
134 handle->debug_print("tea5767: iic_read_cmd is null.\n"); /* iic_read_cmd is null */
135
136 return 3; /* return error */
137 }
138 if (handle->iic_write_cmd == NULL) /* check iic_write_cmd */
139 {
140 handle->debug_print("tea5767: iic_write_cmd is null.\n"); /* iic_write_cmd is null */
141
142 return 3; /* return error */
143 }
144 if (handle->delay_ms == NULL) /* check delay_ms */
145 {
146 handle->debug_print("tea5767: delay_ms is null.\n"); /* delay_ms is null */
147
148 return 3; /* return error */
149 }
150
151 if (handle->iic_init() != 0) /* iic init */
152 {
153 handle->debug_print("tea5767: iic init failed.\n"); /* iic init failed */
154
155 return 1; /* return error */
156 }
157 handle->inited = 1; /* flag finish initialization */
158
159 return 0; /* success return 0 */
160}
161
174{
175 uint8_t res;
176
177 if (handle == NULL) /* check handle */
178 {
179 return 2; /* return error */
180 }
181 if (handle->inited != 1) /* check handle initialization */
182 {
183 return 3; /* return error */
184 }
185
186 handle->conf_up[3] |= 1 << 6; /* set power down */
187 res = a_tea5767_iic_write(handle, handle->conf_up, 5); /* write conf */
188 if (res != 0) /* check result */
189 {
190 handle->debug_print("tea5767: write conf failed.\n"); /* write conf failed */
191
192 return 4; /* return error */
193 }
194 res = handle->iic_deinit(); /* iic deinit */
195 if (res != 0) /* check error */
196 {
197 handle->debug_print("tea5767: iic deinit failed.\n"); /* iic deinit failed */
198
199 return 1; /* return error */
200 }
201 handle->inited = 0; /* flag closed */
202
203 return 0; /* success return 0 */
204}
205
217{
218 uint8_t res;
219
220 if (handle == NULL) /* check handle */
221 {
222 return 2; /* return error */
223 }
224 if (handle->inited != 1) /* check handle initialization */
225 {
226 return 3; /* return error */
227 }
228
229 res = a_tea5767_iic_write(handle, handle->conf_up, 5); /* write conf */
230 if (res != 0) /* check result */
231 {
232 handle->debug_print("tea5767: write conf failed.\n"); /* write conf failed */
233
234 return 1; /* return error */
235 }
236
237 return 0; /* success return 0 */
238}
239
251{
252 uint8_t res;
253
254 if (handle == NULL) /* check handle */
255 {
256 return 2; /* return error */
257 }
258 if (handle->inited != 1) /* check handle initialization */
259 {
260 return 3; /* return error */
261 }
262
263 res = a_tea5767_iic_read(handle, handle->conf_down, 5); /* read conf */
264 if (res != 0) /* check result */
265 {
266 handle->debug_print("tea5767: read conf failed.\n"); /* read conf failed */
267
268 return 1; /* return error */
269 }
270
271 return 0; /* success return 0 */
272}
273
284uint8_t tea5767_update_conf(tea5767_handle_t *handle, uint8_t conf[5])
285{
286 if (handle == NULL) /* check handle */
287 {
288 return 2; /* return error */
289 }
290 if (handle->inited != 1) /* check handle initialization */
291 {
292 return 3; /* return error */
293 }
294
295 memcpy(handle->conf_up, conf, 5); /* copy the conf */
296
297 return 0; /* success return 0 */
298}
299
311{
312 if (handle == NULL) /* check handle */
313 {
314 return 2; /* return error */
315 }
316 if (handle->inited != 1) /* check handle initialization */
317 {
318 return 3; /* return error */
319 }
320
321 handle->conf_up[0] &= ~(1 << 7); /* clear settings */
322 handle->conf_up[0] |= enable << 7; /* set settings */
323
324 return 0; /* success return 0 */
325}
326
338{
339 if (handle == NULL) /* check handle */
340 {
341 return 2; /* return error */
342 }
343 if (handle->inited != 1) /* check handle initialization */
344 {
345 return 3; /* return error */
346 }
347
348 *enable = (tea5767_bool_t)((handle->conf_up[0] >> 7) & 0x01); /* get the settings */
349
350 return 0; /* success return 0 */
351}
352
364{
365 if (handle == NULL) /* check handle */
366 {
367 return 2; /* return error */
368 }
369 if (handle->inited != 1) /* check handle initialization */
370 {
371 return 3; /* return error */
372 }
373
374 handle->conf_up[0] &= ~(1 << 6); /* clear settings */
375 handle->conf_up[0] |= mode << 6; /* set settings */
376
377 return 0; /* success return 0 */
378}
379
391{
392 if (handle == NULL) /* check handle */
393 {
394 return 2; /* return error */
395 }
396 if (handle->inited != 1) /* check handle initialization */
397 {
398 return 3; /* return error */
399 }
400
401 *mode = (tea5767_mode_t)((handle->conf_up[0] >> 6) & 0x01); /* get settings */
402
403 return 0; /* success return 0 */
404}
405
418uint8_t tea5767_set_pll(tea5767_handle_t *handle, uint16_t pll)
419{
420 uint8_t buf[2];
421
422 if (handle == NULL) /* check handle */
423 {
424 return 2; /* return error */
425 }
426 if (handle->inited != 1) /* check handle initialization */
427 {
428 return 3; /* return error */
429 }
430 if (pll > 0x3FFF) /* check the pll */
431 {
432 handle->debug_print("tea5767: pll > 0x3FFF.\n"); /* pll > 0x3FFF */
433
434 return 4; /* return error */
435 }
436
437 buf[0] = (pll >> 8) & 0x3F; /* get the pll */
438 buf[1] = pll & 0xFF; /* get the pll */
439 handle->conf_up[0] &= ~0x3F; /* clear settings */
440 handle->conf_up[0] |= buf[0]; /* set settings */
441 handle->conf_up[1] = buf[1]; /* set settings */
442
443 return 0; /* success return 0 */
444}
445
456uint8_t tea5767_get_pll(tea5767_handle_t *handle, uint16_t *pll)
457{
458 uint8_t buf[2];
459
460 if (handle == NULL) /* check handle */
461 {
462 return 2; /* return error */
463 }
464 if (handle->inited != 1) /* check handle initialization */
465 {
466 return 3; /* return error */
467 }
468
469 buf[0] = handle->conf_up[0]; /* get settings */
470 buf[1] = handle->conf_up[1]; /* get settings */
471 *pll = (((uint16_t)(buf[0] & 0x3F)) << 8) | buf[1]; /* get the pll */
472
473 return 0; /* success return 0 */
474}
475
487{
488 if (handle == NULL) /* check handle */
489 {
490 return 2; /* return error */
491 }
492 if (handle->inited != 1) /* check handle initialization */
493 {
494 return 3; /* return error */
495 }
496
497 handle->conf_up[2] &= ~(1 << 7); /* clear settings */
498 handle->conf_up[2] |= mode << 7; /* set settings */
499
500 return 0; /* success return 0 */
501}
502
514{
515 if (handle == NULL) /* check handle */
516 {
517 return 2; /* return error */
518 }
519 if (handle->inited != 1) /* check handle initialization */
520 {
521 return 3; /* return error */
522 }
523
524 *mode = (tea5767_search_mode_t)((handle->conf_up[2] >> 7) & 0x01); /* get the settings */
525
526 return 0; /* success return 0 */
527}
528
540{
541 if (handle == NULL) /* check handle */
542 {
543 return 2; /* return error */
544 }
545 if (handle->inited != 1) /* check handle initialization */
546 {
547 return 3; /* return error */
548 }
549
550 handle->conf_up[2] &= ~(3 << 5); /* clear settings */
551 handle->conf_up[2] |= level << 5; /* set settings */
552
553 return 0; /* success return 0 */
554}
555
567{
568 if (handle == NULL) /* check handle */
569 {
570 return 2; /* return error */
571 }
572 if (handle->inited != 1) /* check handle initialization */
573 {
574 return 3; /* return error */
575 }
576
577 *level = (tea5767_search_stop_level_t)((handle->conf_up[2] >> 5) & 0x03); /* get the settings */
578
579 return 0; /* success return 0 */
580}
581
593{
594 if (handle == NULL) /* check handle */
595 {
596 return 2; /* return error */
597 }
598 if (handle->inited != 1) /* check handle initialization */
599 {
600 return 3; /* return error */
601 }
602
603 handle->conf_up[2] &= ~(1 << 4); /* clear settings */
604 handle->conf_up[2] |= side << 4; /* set settings */
605
606 return 0; /* success return 0 */
607}
608
620{
621 if (handle == NULL) /* check handle */
622 {
623 return 2; /* return error */
624 }
625 if (handle->inited != 1) /* check handle initialization */
626 {
627 return 3; /* return error */
628 }
629
630 *side = (tea5767_side_injection_t)((handle->conf_up[2] >> 4) & 0x01); /* get the settings */
631
632 return 0; /* success return 0 */
633}
634
646{
647 if (handle == NULL) /* check handle */
648 {
649 return 2; /* return error */
650 }
651 if (handle->inited != 1) /* check handle initialization */
652 {
653 return 3; /* return error */
654 }
655
656 handle->conf_up[2] &= ~(1 << 3); /* clear settings */
657 handle->conf_up[2] |= channel << 3; /* set settings */
658
659 return 0; /* success return 0 */
660}
661
673{
674 if (handle == NULL) /* check handle */
675 {
676 return 2; /* return error */
677 }
678 if (handle->inited != 1) /* check handle initialization */
679 {
680 return 3; /* return error */
681 }
682
683 *channel = (tea5767_channel_t)((handle->conf_up[2] >> 3) & 0x01); /* get the settings */
684
685 return 0; /* success return 0 */
686}
687
699{
700 if (handle == NULL) /* check handle */
701 {
702 return 2; /* return error */
703 }
704 if (handle->inited != 1) /* check handle initialization */
705 {
706 return 3; /* return error */
707 }
708
709 handle->conf_up[2] &= ~(1 << 2); /* clear settings */
710 handle->conf_up[2] |= enable << 2; /* set settings */
711
712 return 0; /* success return 0 */
713}
714
726{
727 if (handle == NULL) /* check handle */
728 {
729 return 2; /* return error */
730 }
731 if (handle->inited != 1) /* check handle initialization */
732 {
733 return 3; /* return error */
734 }
735
736 *enable = (tea5767_bool_t)((handle->conf_up[2] >> 2) & 0x01); /* get the settings */
737
738 return 0; /* success return 0 */
739}
740
752{
753 if (handle == NULL) /* check handle */
754 {
755 return 2; /* return error */
756 }
757 if (handle->inited != 1) /* check handle initialization */
758 {
759 return 3; /* return error */
760 }
761
762 handle->conf_up[2] &= ~(1 << 1); /* clear settings */
763 handle->conf_up[2] |= enable << 1; /* set settings */
764
765 return 0; /* success return 0 */
766}
767
779{
780 if (handle == NULL) /* check handle */
781 {
782 return 2; /* return error */
783 }
784 if (handle->inited != 1) /* check handle initialization */
785 {
786 return 3; /* return error */
787 }
788
789 *enable = (tea5767_bool_t)((handle->conf_up[2] >> 1) & 0x01); /* get the settings */
790
791 return 0; /* success return 0 */
792}
793
805{
806 if (handle == NULL) /* check handle */
807 {
808 return 2; /* return error */
809 }
810 if (handle->inited != 1) /* check handle initialization */
811 {
812 return 3; /* return error */
813 }
814
815 handle->conf_up[2] &= ~(1 << 0); /* clear settings */
816 handle->conf_up[2] |= level << 0; /* set settings */
817
818 return 0; /* success return 0 */
819}
820
832{
833 if (handle == NULL) /* check handle */
834 {
835 return 2; /* return error */
836 }
837 if (handle->inited != 1) /* check handle initialization */
838 {
839 return 3; /* return error */
840 }
841
842 *level = (tea5767_level_t)((handle->conf_up[2] >> 0) & 0x01); /* get the settings */
843
844 return 0; /* success return 0 */
845}
846
858{
859 if (handle == NULL) /* check handle */
860 {
861 return 2; /* return error */
862 }
863 if (handle->inited != 1) /* check handle initialization */
864 {
865 return 3; /* return error */
866 }
867
868 handle->conf_up[3] &= ~(1 << 7); /* clear settings */
869 handle->conf_up[3] |= level << 7; /* set settings */
870
871 return 0; /* success return 0 */
872}
873
885{
886 if (handle == NULL) /* check handle */
887 {
888 return 2; /* return error */
889 }
890 if (handle->inited != 1) /* check handle initialization */
891 {
892 return 3; /* return error */
893 }
894
895 *level = (tea5767_level_t)((handle->conf_up[3] >> 7) & 0x01); /* get the settings */
896
897 return 0; /* success return 0 */
898}
899
911{
912 if (handle == NULL) /* check handle */
913 {
914 return 2; /* return error */
915 }
916 if (handle->inited != 1) /* check handle initialization */
917 {
918 return 3; /* return error */
919 }
920
921 handle->conf_up[3] &= ~(1 << 6); /* clear settings */
922 handle->conf_up[3] |= enable << 6; /* set settings */
923
924 return 0; /* success return 0 */
925}
926
938{
939 if (handle == NULL) /* check handle */
940 {
941 return 2; /* return error */
942 }
943 if (handle->inited != 1) /* check handle initialization */
944 {
945 return 3; /* return error */
946 }
947
948 *enable = (tea5767_bool_t)((handle->conf_up[3] >> 6) & 0x01); /* get the settings */
949
950 return 0; /* success return 0 */
951}
952
964{
965 if (handle == NULL) /* check handle */
966 {
967 return 2; /* return error */
968 }
969 if (handle->inited != 1) /* check handle initialization */
970 {
971 return 3; /* return error */
972 }
973
974 handle->conf_up[3] &= ~(1 << 5); /* clear settings */
975 handle->conf_up[3] |= band << 5; /* set settings */
976
977 return 0; /* success return 0 */
978}
979
991{
992 if (handle == NULL) /* check handle */
993 {
994 return 2; /* return error */
995 }
996 if (handle->inited != 1) /* check handle initialization */
997 {
998 return 3; /* return error */
999 }
1000
1001 *band = (tea5767_band_t)((handle->conf_up[3] >> 5) & 0x01); /* get the settings */
1002
1003 return 0; /* success return 0 */
1004}
1005
1017{
1018 if (handle == NULL) /* check handle */
1019 {
1020 return 2; /* return error */
1021 }
1022 if (handle->inited != 1) /* check handle initialization */
1023 {
1024 return 3; /* return error */
1025 }
1026
1027 handle->conf_up[3] &= ~(1 << 3); /* clear settings */
1028 handle->conf_up[3] |= enable << 3; /* set settings */
1029
1030 return 0; /* success return 0 */
1031}
1032
1044{
1045 if (handle == NULL) /* check handle */
1046 {
1047 return 2; /* return error */
1048 }
1049 if (handle->inited != 1) /* check handle initialization */
1050 {
1051 return 3; /* return error */
1052 }
1053
1054 *enable = (tea5767_bool_t)((handle->conf_up[3] >> 3) & 0x01); /* get the settings */
1055
1056 return 0; /* success return 0 */
1057}
1058
1070{
1071 if (handle == NULL) /* check handle */
1072 {
1073 return 2; /* return error */
1074 }
1075 if (handle->inited != 1) /* check handle initialization */
1076 {
1077 return 3; /* return error */
1078 }
1079
1080 handle->conf_up[3] &= ~(1 << 2); /* clear settings */
1081 handle->conf_up[3] |= enable << 2; /* set settings */
1082
1083 return 0; /* success return 0 */
1084}
1085
1097{
1098 if (handle == NULL) /* check handle */
1099 {
1100 return 2; /* return error */
1101 }
1102 if (handle->inited != 1) /* check handle initialization */
1103 {
1104 return 3; /* return error */
1105 }
1106
1107 *enable = (tea5767_bool_t)((handle->conf_up[3] >> 2) & 0x01); /* get the settings */
1108
1109 return 0; /* success return 0 */
1110}
1111
1123{
1124 if (handle == NULL) /* check handle */
1125 {
1126 return 2; /* return error */
1127 }
1128 if (handle->inited != 1) /* check handle initialization */
1129 {
1130 return 3; /* return error */
1131 }
1132
1133 handle->conf_up[3] &= ~(1 << 1); /* clear settings */
1134 handle->conf_up[3] |= enable << 1; /* set settings */
1135
1136 return 0; /* success return 0 */
1137}
1138
1150{
1151 if (handle == NULL) /* check handle */
1152 {
1153 return 2; /* return error */
1154 }
1155 if (handle->inited != 1) /* check handle initialization */
1156 {
1157 return 3; /* return error */
1158 }
1159
1160 *enable = (tea5767_bool_t)((handle->conf_up[3] >> 1) & 0x01); /* get the settings */
1161
1162 return 0; /* success return 0 */
1163}
1164
1176{
1177 if (handle == NULL) /* check handle */
1178 {
1179 return 2; /* return error */
1180 }
1181 if (handle->inited != 1) /* check handle initialization */
1182 {
1183 return 3; /* return error */
1184 }
1185
1186 handle->conf_up[3] &= ~(1 << 0); /* clear settings */
1187 handle->conf_up[3] |= enable << 0; /* set settings */
1188
1189 return 0; /* success return 0 */
1190}
1191
1203{
1204 if (handle == NULL) /* check handle */
1205 {
1206 return 2; /* return error */
1207 }
1208 if (handle->inited != 1) /* check handle initialization */
1209 {
1210 return 3; /* return error */
1211 }
1212
1213 *enable = (tea5767_bool_t)((handle->conf_up[3] >> 0) & 0x01); /* get the settings */
1214
1215 return 0; /* success return 0 */
1216}
1217
1229{
1230 if (handle == NULL) /* check handle */
1231 {
1232 return 2; /* return error */
1233 }
1234 if (handle->inited != 1) /* check handle initialization */
1235 {
1236 return 3; /* return error */
1237 }
1238
1239 handle->conf_up[4] &= ~(1 << 6); /* clear settings */
1240 handle->conf_up[4] |= emphasis << 6; /* set settings */
1241
1242 return 0; /* success return 0 */
1243}
1244
1256{
1257 if (handle == NULL) /* check handle */
1258 {
1259 return 2; /* return error */
1260 }
1261 if (handle->inited != 1) /* check handle initialization */
1262 {
1263 return 3; /* return error */
1264 }
1265
1266 *emphasis = (tea5767_de_emphasis_t)((handle->conf_up[4] >> 6) & 0x01); /* get the settings */
1267
1268 return 0; /* success return 0 */
1269}
1270
1282{
1283 if (handle == NULL) /* check handle */
1284 {
1285 return 2; /* return error */
1286 }
1287 if (handle->inited != 1) /* check handle initialization */
1288 {
1289 return 3; /* return error */
1290 }
1291
1292 handle->conf_up[3] &= ~(1 << 4); /* clear settings */
1293 handle->conf_up[4] &= ~(1 << 7); /* clear settings */
1294 handle->conf_up[3] |= ((clk >> 0)& 0x01) << 4; /* set settings */
1295 handle->conf_up[4] |= ((clk >> 1)& 0x01) << 7; /* set settings */
1296
1297 return 0; /* success return 0 */
1298}
1299
1311{
1312 if (handle == NULL) /* check handle */
1313 {
1314 return 2; /* return error */
1315 }
1316 if (handle->inited != 1) /* check handle initialization */
1317 {
1318 return 3; /* return error */
1319 }
1320
1321 *clk = (tea5767_clock_t)(((handle->conf_up[4] >> 7) & 0x01) << 1 | ((handle->conf_up[3] >> 4) & 0x01)); /* get the settings */
1322
1323 return 0; /* success return 0 */
1324}
1325
1337{
1338 if (handle == NULL) /* check handle */
1339 {
1340 return 2; /* return error */
1341 }
1342 if (handle->inited != 1) /* check handle initialization */
1343 {
1344 return 3; /* return error */
1345 }
1346
1347 *enable = (tea5767_bool_t)((handle->conf_down[0] >> 7) & 0x01); /* get the settings */
1348
1349 return 0; /* success return 0 */
1350}
1351
1363{
1364 if (handle == NULL) /* check handle */
1365 {
1366 return 2; /* return error */
1367 }
1368 if (handle->inited != 1) /* check handle initialization */
1369 {
1370 return 3; /* return error */
1371 }
1372
1373 *enable = (tea5767_bool_t)((handle->conf_down[0] >> 6) & 0x01); /* get the settings */
1374
1375 return 0; /* success return 0 */
1376}
1377
1388uint8_t tea5767_get_searched_pll(tea5767_handle_t *handle, uint16_t *pll)
1389{
1390 if (handle == NULL) /* check handle */
1391 {
1392 return 2; /* return error */
1393 }
1394 if (handle->inited != 1) /* check handle initialization */
1395 {
1396 return 3; /* return error */
1397 }
1398
1399 *pll = ((uint16_t)(handle->conf_down[0] & 0x3F) << 8) | handle->conf_down[1]; /* get the settings */
1400
1401 return 0; /* success return 0 */
1402}
1403
1414uint8_t tea5767_get_if(tea5767_handle_t *handle, uint8_t *if_out)
1415{
1416 if (handle == NULL) /* check handle */
1417 {
1418 return 2; /* return error */
1419 }
1420 if (handle->inited != 1) /* check handle initialization */
1421 {
1422 return 3; /* return error */
1423 }
1424
1425 *if_out = handle->conf_down[2] & 0x7F; /* get the settings */
1426
1427 return 0; /* success return 0 */
1428}
1429
1441{
1442 if (handle == NULL) /* check handle */
1443 {
1444 return 2; /* return error */
1445 }
1446 if (handle->inited != 1) /* check handle initialization */
1447 {
1448 return 3; /* return error */
1449 }
1450
1451 *reception = (tea5767_reception_t)((handle->conf_down[2] >> 7) & 0x01); /* get the settings */
1452
1453 return 0; /* success return 0 */
1454}
1455
1466uint8_t tea5767_get_level_adc_output(tea5767_handle_t *handle, uint8_t *output)
1467{
1468 if (handle == NULL) /* check handle */
1469 {
1470 return 2; /* return error */
1471 }
1472 if (handle->inited != 1) /* check handle initialization */
1473 {
1474 return 3; /* return error */
1475 }
1476
1477 *output = (handle->conf_down[3] >> 4) & 0xF; /* get the settings */
1478
1479 return 0; /* success return 0 */
1480}
1481
1494uint8_t tea5767_frequency_convert_to_register(tea5767_handle_t *handle, float mhz, uint16_t *pll)
1495{
1496 uint8_t hlsi;
1497 uint8_t clk;
1498 float f;
1499
1500 if (handle == NULL) /* check handle */
1501 {
1502 return 2; /* return error */
1503 }
1504 if (handle->inited != 1) /* check handle initialization */
1505 {
1506 return 3; /* return error */
1507 }
1508
1509 hlsi = (handle->conf_up[2] >> 4) & 0x01; /* get hte hlsi */
1510 clk = ((handle->conf_up[4] >> 7) & 0x01) << 1
1511 | ((handle->conf_up[3] >> 4) & 0x01); /* get the clock */
1512 if (clk == 0x00) /* 13MHz */
1513 {
1514 f = 13000.0f; /* 13MHz */
1515 }
1516 else if (clk == 0x01) /* 32.768KHz */
1517 {
1518 f = 32.768f; /* 32.768KHz */
1519 }
1520 else if (clk == 0x02) /* 6.5MHz */
1521 {
1522 f = 6500.0f; /* 6.5MHz */
1523 }
1524 else
1525 {
1526 handle->debug_print("tea5767: clock is invalid.\n"); /* clock is invalid */
1527
1528 return 4; /* return error */
1529 }
1530
1531 if (hlsi != 0) /* high side lo injection */
1532 {
1533 *pll = (uint16_t)((4.0f * (mhz * 1000.0f + 225.0f)) / f); /* convert real data to raw data */
1534 } /* low side lo injection */
1535 else
1536 {
1537 *pll = (uint16_t)((4.0f * (mhz * 1000.0f - 225.0f)) / f); /* convert real data to raw data */
1538 }
1539
1540 return 0; /* success return 0 */
1541}
1542
1555uint8_t tea5767_frequency_convert_to_data(tea5767_handle_t *handle, uint16_t pll, float *mhz)
1556{
1557 uint8_t hlsi;
1558 uint8_t clk;
1559 float f;
1560
1561 if (handle == NULL) /* check handle */
1562 {
1563 return 2; /* return error */
1564 }
1565 if (handle->inited != 1) /* check handle initialization */
1566 {
1567 return 3; /* return error */
1568 }
1569
1570 hlsi = (handle->conf_up[2] >> 4) & 0x01; /* get hte hlsi */
1571 clk = ((handle->conf_up[4] >> 7) & 0x01) << 1
1572 | ((handle->conf_up[3] >> 4) & 0x01); /* get the clock */
1573 if (clk == 0x00) /* 13MHz */
1574 {
1575 f = 13000.0f; /* 13MHz */
1576 }
1577 else if (clk == 0x01) /* 32.768KHz */
1578 {
1579 f = 32.768f; /* 32.768KHz */
1580 }
1581 else if (clk == 0x02) /* 6.5MHz */
1582 {
1583 f = 6500.0f; /* 6.5MHz */
1584 }
1585 else
1586 {
1587 handle->debug_print("tea5767: clock is invalid.\n"); /* clock is invalid */
1588
1589 return 4; /* return error */
1590 }
1591
1592 if (hlsi != 0) /* high side lo injection */
1593 {
1594 *mhz = (pll * f / 4.0f - 255.0f) / 1000.0f; /* convert raw data to real data */
1595 } /* low side lo injection */
1596 else
1597 {
1598 *mhz = (pll * f / 4.0f + 255.0f) / 1000.0f; /* convert raw data to real data */
1599 }
1600
1601 return 0; /* success return 0 */
1602}
1603
1616uint8_t tea5767_set_reg(tea5767_handle_t *handle, uint8_t *buf, uint16_t len)
1617{
1618 if (handle == NULL) /* check handle */
1619 {
1620 return 2; /* return error */
1621 }
1622 if (handle->inited != 1) /* check handle initialization */
1623 {
1624 return 3; /* return error */
1625 }
1626
1627 return a_tea5767_iic_write(handle, buf, len); /* write command */
1628}
1629
1642uint8_t tea5767_get_reg(tea5767_handle_t *handle, uint8_t *buf, uint16_t len)
1643{
1644 if (handle == NULL) /* check handle */
1645 {
1646 return 2; /* return error */
1647 }
1648 if (handle->inited != 1) /* check handle initialization */
1649 {
1650 return 3; /* return error */
1651 }
1652
1653 return a_tea5767_iic_read(handle, buf, len); /* read command */
1654}
1655
1665{
1666 if (info == NULL) /* check handle */
1667 {
1668 return 2; /* return error */
1669 }
1670
1671 memset(info, 0, sizeof(tea5767_info_t)); /* initialize tea5767 info structure */
1672 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1673 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1674 strncpy(info->interface, "IIC", 8); /* copy interface name */
1675 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1676 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1677 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1678 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1679 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1680 info->driver_version = DRIVER_VERSION; /* set driver version */
1681
1682 return 0; /* success return 0 */
1683}
#define MAX_CURRENT
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define TEA5767_ADDRESS
chip address definition
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver tea5767 header file
uint8_t tea5767_get_ready_flag(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the ready flag
uint8_t tea5767_deinit(tea5767_handle_t *handle)
close the chip
uint8_t tea5767_get_reception(tea5767_handle_t *handle, tea5767_reception_t *reception)
get the reception
uint8_t tea5767_set_right_mute(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable right mute
uint8_t tea5767_set_pll(tea5767_handle_t *handle, uint16_t pll)
set the pll
uint8_t tea5767_get_right_mute(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the right mute status
uint8_t tea5767_get_band(tea5767_handle_t *handle, tea5767_band_t *band)
get the band
tea5767_mode_t
tea5767 mode enumeration definition
uint8_t tea5767_set_search_stop_level(tea5767_handle_t *handle, tea5767_search_stop_level_t level)
set the search stop level
uint8_t tea5767_write_conf(tea5767_handle_t *handle)
write the conf
uint8_t tea5767_get_pll(tea5767_handle_t *handle, uint16_t *pll)
get the pll
uint8_t tea5767_get_port1(tea5767_handle_t *handle, tea5767_level_t *level)
get the port1 level
uint8_t tea5767_get_side_injection(tea5767_handle_t *handle, tea5767_side_injection_t *side)
get the side injection
uint8_t tea5767_set_high_cut_control(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable high cut control
uint8_t tea5767_get_searched_pll(tea5767_handle_t *handle, uint16_t *pll)
get the searched pll
uint8_t tea5767_get_search_mode(tea5767_handle_t *handle, tea5767_search_mode_t *mode)
get the search mode
tea5767_channel_t
tea5767 channel enumeration definition
uint8_t tea5767_set_search_mode(tea5767_handle_t *handle, tea5767_search_mode_t mode)
set the search mode
uint8_t tea5767_set_side_injection(tea5767_handle_t *handle, tea5767_side_injection_t side)
set the side injection
uint8_t tea5767_get_search_stop_level(tea5767_handle_t *handle, tea5767_search_stop_level_t *level)
get the search stop level
uint8_t tea5767_get_mode(tea5767_handle_t *handle, tea5767_mode_t *mode)
get the chip mode
uint8_t tea5767_set_mode(tea5767_handle_t *handle, tea5767_mode_t mode)
set the chip mode
tea5767_de_emphasis_t
tea5767 de-emphasis enumeration definition
tea5767_clock_t
tea5767 clock enumeration definition
tea5767_reception_t
tea5767 reception enumeration definition
uint8_t tea5767_get_clock(tea5767_handle_t *handle, tea5767_clock_t *clk)
get the clock
tea5767_side_injection_t
tea5767 side injection enumeration definition
uint8_t tea5767_get_port1_as_search_indicator(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the port1 as search indicator status
uint8_t tea5767_get_channel(tea5767_handle_t *handle, tea5767_channel_t *channel)
get the sound channel
tea5767_search_stop_level_t
tea5767 search stop level enumeration definition
uint8_t tea5767_set_port1_as_search_indicator(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable port1 as search indicator
uint8_t tea5767_get_de_emphasis(tea5767_handle_t *handle, tea5767_de_emphasis_t *emphasis)
get the de emphasis status
uint8_t tea5767_get_if(tea5767_handle_t *handle, uint8_t *if_out)
get the if
struct tea5767_info_s tea5767_info_t
tea5767 information structure definition
uint8_t tea5767_set_port1(tea5767_handle_t *handle, tea5767_level_t level)
set the port1 level
tea5767_bool_t
tea5767 bool enumeration definition
uint8_t tea5767_get_level_adc_output(tea5767_handle_t *handle, uint8_t *output)
get the level adc output
uint8_t tea5767_get_soft_mute(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the soft mute status
uint8_t tea5767_set_mute(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable the mute
uint8_t tea5767_set_de_emphasis(tea5767_handle_t *handle, tea5767_de_emphasis_t emphasis)
set the de emphasis
uint8_t tea5767_frequency_convert_to_register(tea5767_handle_t *handle, float mhz, uint16_t *pll)
convert the frequency to the register raw data
uint8_t tea5767_get_band_limit_flag(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the band limit flag
uint8_t tea5767_set_soft_mute(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable soft mute
struct tea5767_handle_s tea5767_handle_t
tea5767 handle structure definition
uint8_t tea5767_init(tea5767_handle_t *handle)
initialize the chip
uint8_t tea5767_set_channel(tea5767_handle_t *handle, tea5767_channel_t channel)
set the sound channel
uint8_t tea5767_set_clock(tea5767_handle_t *handle, tea5767_clock_t clk)
set the clock
tea5767_level_t
tea5767 level enumeration definition
uint8_t tea5767_get_left_mute(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the left mute status
uint8_t tea5767_get_high_cut_control(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the high cut control status
uint8_t tea5767_get_mute(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the mute status
uint8_t tea5767_get_stereo_noise_cancelling(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the stereo noise cancelling status
uint8_t tea5767_get_standby(tea5767_handle_t *handle, tea5767_bool_t *enable)
get the standby status
tea5767_search_mode_t
tea5767 search mode enumeration definition
uint8_t tea5767_set_stereo_noise_cancelling(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable stereo noise cancelling
uint8_t tea5767_read_conf(tea5767_handle_t *handle)
read the conf
uint8_t tea5767_get_port2(tea5767_handle_t *handle, tea5767_level_t *level)
get the port2 level
tea5767_band_t
tea5767 band enumeration definition
uint8_t tea5767_info(tea5767_info_t *info)
get chip's information
uint8_t tea5767_frequency_convert_to_data(tea5767_handle_t *handle, uint16_t pll, float *mhz)
convert the register raw data to the frequency
uint8_t tea5767_update_conf(tea5767_handle_t *handle, uint8_t conf[5])
update the conf
uint8_t tea5767_set_band(tea5767_handle_t *handle, tea5767_band_t band)
set the band
uint8_t tea5767_set_left_mute(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable left mute
uint8_t tea5767_set_port2(tea5767_handle_t *handle, tea5767_level_t level)
set the port2 level
uint8_t tea5767_set_standby(tea5767_handle_t *handle, tea5767_bool_t enable)
enable or disable standby
uint8_t tea5767_set_reg(tea5767_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
uint8_t tea5767_get_reg(tea5767_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint32_t driver_version
char manufacturer_name[32]