LibDriver TEA5767
Loading...
Searching...
No Matches
driver_tea5767_basic.c
Go to the documentation of this file.
1
36
38
39static tea5767_handle_t gs_handle;
40
48uint8_t tea5767_basic_init(void)
49{
50 uint8_t res;
51 uint16_t pll;
52
53 /* link functions */
61
62 /* tea5767 init */
63 res = tea5767_init(&gs_handle);
64 if (res != 0)
65 {
66 tea5767_interface_debug_print("tea5767: init failed.\n");
67
68 return 1;
69 }
70
71 /* set default mute */
73 if (res != 0)
74 {
75 tea5767_interface_debug_print("tea5767: set mute failed.\n");
76 (void)tea5767_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default mode */
83 if (res != 0)
84 {
85 tea5767_interface_debug_print("tea5767: set mode failed.\n");
86 (void)tea5767_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* default frequency convert to register */
93 if (res != 0)
94 {
95 tea5767_interface_debug_print("tea5767: frequency convert to register failed.\n");
96 (void)tea5767_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set default pll */
102 res = tea5767_set_pll(&gs_handle, pll);
103 if (res != 0)
104 {
105 tea5767_interface_debug_print("tea5767: set pll failed.\n");
106 (void)tea5767_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default search mode */
113 if (res != 0)
114 {
115 tea5767_interface_debug_print("tea5767: set search mode failed.\n");
116 (void)tea5767_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* set default search stop level */
123 if (res != 0)
124 {
125 tea5767_interface_debug_print("tea5767: set search stop level failed.\n");
126 (void)tea5767_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* set default side injection */
133 if (res != 0)
134 {
135 tea5767_interface_debug_print("tea5767: set side injection failed.\n");
136 (void)tea5767_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set default channel */
143 if (res != 0)
144 {
145 tea5767_interface_debug_print("tea5767: set channel failed.\n");
146 (void)tea5767_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* set default right mute */
153 if (res != 0)
154 {
155 tea5767_interface_debug_print("tea5767: set right mute failed.\n");
156 (void)tea5767_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* set default left mute */
163 if (res != 0)
164 {
165 tea5767_interface_debug_print("tea5767: set left mute failed.\n");
166 (void)tea5767_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* set default port1 */
173 if (res != 0)
174 {
175 tea5767_interface_debug_print("tea5767: set port1 failed.\n");
176 (void)tea5767_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* set default port2 */
183 if (res != 0)
184 {
185 tea5767_interface_debug_print("tea5767: set port2 failed.\n");
186 (void)tea5767_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* disable standby */
192 res = tea5767_set_standby(&gs_handle, TEA5767_BOOL_FALSE);
193 if (res != 0)
194 {
195 tea5767_interface_debug_print("tea5767: set standby failed.\n");
196 (void)tea5767_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* set default band */
203 if (res != 0)
204 {
205 tea5767_interface_debug_print("tea5767: set band failed.\n");
206 (void)tea5767_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* set default soft mute */
213 if (res != 0)
214 {
215 tea5767_interface_debug_print("tea5767: set soft mute failed.\n");
216 (void)tea5767_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* set default high cut control */
223 if (res != 0)
224 {
225 tea5767_interface_debug_print("tea5767: set high cut control failed.\n");
226 (void)tea5767_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set default stereo noise cancelling */
233 if (res != 0)
234 {
235 tea5767_interface_debug_print("tea5767: set stereo noise cancelling failed.\n");
236 (void)tea5767_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set default port1 as search indicator */
243 if (res != 0)
244 {
245 tea5767_interface_debug_print("tea5767: set port1 as search indicator failed.\n");
246 (void)tea5767_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* set default de emphasis */
253 if (res != 0)
254 {
255 tea5767_interface_debug_print("tea5767: set de emphasis failed.\n");
256 (void)tea5767_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* set default clock */
263 if (res != 0)
264 {
265 tea5767_interface_debug_print("tea5767: set clock failed.\n");
266 (void)tea5767_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* write conf */
272 res = tea5767_write_conf(&gs_handle);
273 if (res != 0)
274 {
275 tea5767_interface_debug_print("tea5767: write conf failed.\n");
276 (void)tea5767_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 return 0;
282}
283
292{
293 /* close tea5767 */
294 if (tea5767_deinit(&gs_handle) != 0)
295 {
296 return 1;
297 }
298 else
299 {
300 return 0;
301 }
302}
303
313{
314 uint8_t res;
315 uint16_t pll;
316 tea5767_bool_t ready_flag;
317 tea5767_bool_t limit_flag;
318
319 /* set search mode up */
321 if (res != 0)
322 {
323 return 1;
324 }
325
326 /* search mode */
327 res = tea5767_set_mode(&gs_handle, TEA5767_MODE_SEARCH);
328 if (res != 0)
329 {
330 return 1;
331 }
332
333 /* write conf */
334 res = tea5767_write_conf(&gs_handle);
335 if (res != 0)
336 {
337 return 1;
338 }
339
340 /* wait searched */
341 while (1)
342 {
343 /* read conf */
344 res = tea5767_read_conf(&gs_handle);
345 if (res != 0)
346 {
347 return 1;
348 }
349
350 /* read ready flag */
351 res = tea5767_get_ready_flag(&gs_handle, &ready_flag);
352 if (res != 0)
353 {
354 return 1;
355 }
356
357 /* get band limit flag */
358 res = tea5767_get_band_limit_flag(&gs_handle, &limit_flag);
359 if (res != 0)
360 {
361 return 1;
362 }
363
364 /* check teh ready flag */
365 if (ready_flag == TEA5767_BOOL_TRUE)
366 {
367 break;
368 }
369
370 /* delay 200ms */
372 }
373
374 if (limit_flag == TEA5767_BOOL_TRUE)
375 {
376 return 2;
377 }
378 else
379 {
380 /* get the searched pll */
381 res = tea5767_get_searched_pll(&gs_handle, &pll);
382 if (res != 0)
383 {
384 return 1;
385 }
386
387 /* save the pll */
388 res = tea5767_set_pll(&gs_handle, pll);
389 if (res != 0)
390 {
391 return 1;
392 }
393
394 return 0;
395 }
396}
397
407{
408 uint8_t res;
409 uint16_t pll;
410 tea5767_bool_t ready_flag;
411 tea5767_bool_t limit_flag;
412
413 /* set search mode down */
415 if (res != 0)
416 {
417 return 1;
418 }
419
420 /* search mode */
421 res = tea5767_set_mode(&gs_handle, TEA5767_MODE_SEARCH);
422 if (res != 0)
423 {
424 return 1;
425 }
426
427 /* write conf */
428 res = tea5767_write_conf(&gs_handle);
429 if (res != 0)
430 {
431 return 1;
432 }
433
434 /* wait searched */
435 while (1)
436 {
437 /* read conf */
438 res = tea5767_read_conf(&gs_handle);
439 if (res != 0)
440 {
441 return 1;
442 }
443
444 /* read ready flag */
445 res = tea5767_get_ready_flag(&gs_handle, &ready_flag);
446 if (res != 0)
447 {
448 return 1;
449 }
450
451 /* get band limit flag */
452 res = tea5767_get_band_limit_flag(&gs_handle, &limit_flag);
453 if (res != 0)
454 {
455 return 1;
456 }
457
458 /* check teh ready flag */
459 if (ready_flag == TEA5767_BOOL_TRUE)
460 {
461 break;
462 }
463
464 /* delay 200ms */
466 }
467
468 if (limit_flag == TEA5767_BOOL_TRUE)
469 {
470 return 2;
471 }
472 else
473 {
474 /* get the searched pll */
475 res = tea5767_get_searched_pll(&gs_handle, &pll);
476 if (res != 0)
477 {
478 return 1;
479 }
480
481 /* save the pll */
482 res = tea5767_set_pll(&gs_handle, pll);
483 if (res != 0)
484 {
485 return 1;
486 }
487
488 return 0;
489 }
490}
491
501{
502 uint8_t res;
503 uint16_t pll;
504
505 /* convert to register */
506 res = tea5767_frequency_convert_to_register(&gs_handle, mhz, &pll);
507 if (res != 0)
508 {
509 return 1;
510 }
511
512 /* set pll */
513 res = tea5767_set_pll(&gs_handle, pll);
514 if (res != 0)
515 {
516 return 1;
517 }
518
519 /* write conf */
520 res = tea5767_write_conf(&gs_handle);
521 if (res != 0)
522 {
523 return 1;
524 }
525
526 return 0;
527}
528
538{
539 uint8_t res;
540 uint16_t pll;
541
542 /* read conf */
543 res = tea5767_read_conf(&gs_handle);
544 if (res != 0)
545 {
546 return 1;
547 }
548
549 /* get searched pll */
550 res = tea5767_get_searched_pll(&gs_handle, &pll);
551 if (res != 0)
552 {
553 return 1;
554 }
555
556 /* convert */
557 res = tea5767_frequency_convert_to_data(&gs_handle, pll, mhz);
558 if (res != 0)
559 {
560 return 1;
561 }
562
563 return 0;
564}
565
575{
576 uint8_t res;
577
578 /* set mute */
579 res = tea5767_set_mute(&gs_handle, enable);
580 if (res != 0)
581 {
582 return 1;
583 }
584
585 /* set right mute */
586 res = tea5767_set_right_mute(&gs_handle, enable);
587 if (res != 0)
588 {
589 return 1;
590 }
591
592 /* set left mute */
593 res = tea5767_set_left_mute(&gs_handle, enable);
594 if (res != 0)
595 {
596 return 1;
597 }
598
599 /* set soft mute */
600 res = tea5767_set_soft_mute(&gs_handle, enable);
601 if (res != 0)
602 {
603 return 1;
604 }
605
606 /* write conf */
607 res = tea5767_write_conf(&gs_handle);
608 if (res != 0)
609 {
610 return 1;
611 }
612
613 return 0;
614}
driver tea5767 basic include 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_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_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_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_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_set_mode(tea5767_handle_t *handle, tea5767_mode_t mode)
set the chip mode
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_set_port1(tea5767_handle_t *handle, tea5767_level_t level)
set the port1 level
tea5767_bool_t
tea5767 bool enumeration definition
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
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_frequency_convert_to_data(tea5767_handle_t *handle, uint16_t pll, float *mhz)
convert the register raw data to the frequency
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
@ TEA5767_MODE_SEARCH
@ TEA5767_BOOL_TRUE
@ TEA5767_BOOL_FALSE
@ TEA5767_SEARCH_MODE_UP
@ TEA5767_SEARCH_MODE_DOWN
uint8_t tea5767_basic_get_frequency(float *mhz)
basic example get frequency
uint8_t tea5767_basic_search_down(void)
basic example search down
#define TEA57671_BASIC_DEFAULT_SIDE_INJECTION
#define TEA57671_BASIC_DEFAULT_LEFT_MUTE
#define TEA57671_BASIC_DEFAULT_CHANNEL
#define TEA57671_BASIC_DEFAULT_MHZ
uint8_t tea5767_basic_init(void)
basic example init
#define TEA57671_BASIC_DEFAULT_PORT1_AS_SEARCH_INDICATOR
#define TEA57671_BASIC_DEFAULT_DE_EMPHASIS
#define TEA57671_BASIC_DEFAULT_SEARCH_MODE
uint8_t tea5767_basic_search_up(void)
basic example search up
#define TEA57671_BASIC_DEFAULT_BAND
#define TEA57671_BASIC_DEFAULT_CLOCK
#define TEA57671_BASIC_DEFAULT_PORT2
#define TEA57671_BASIC_DEFAULT_HIGH_CUT_CONTROL
#define TEA57671_BASIC_DEFAULT_MODE
#define TEA57671_BASIC_DEFAULT_STEREO_NOISE_CANCELING
uint8_t tea5767_basic_set_frequency(float mhz)
basic example set frequency
#define TEA57671_BASIC_DEFAULT_SOFT_MUTE
uint8_t tea5767_basic_deinit(void)
basic example deinit
#define TEA57671_BASIC_DEFAULT_PORT1
uint8_t tea5767_basic_set_mute(tea5767_bool_t enable)
basic example enable or disable mute
#define TEA57671_BASIC_DEFAULT_MUTE
tea5767 basic example default definition
#define TEA57671_BASIC_DEFAULT_SEARCH_STOP_LEVEL
#define TEA57671_BASIC_DEFAULT_RIGHT_MUTE
uint8_t tea5767_interface_iic_init(void)
interface iic bus init
void tea5767_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tea5767_interface_iic_deinit(void)
interface iic bus deinit
uint8_t tea5767_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t tea5767_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
void tea5767_interface_delay_ms(uint32_t ms)
interface delay ms