LibDriver TEA5767
Loading...
Searching...
No Matches
driver_tea5767_radio_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static tea5767_handle_t gs_handle;
41
51{
52 uint8_t res;
53 uint8_t output;
54 uint16_t pll;
55 float mhz;
56 tea5767_reception_t reception;
57 tea5767_info_t info;
58 tea5767_bool_t ready_flag;
59 tea5767_bool_t limit_flag;
60
61 /* link functions */
69
70 /* tea5767 info */
71 res = tea5767_info(&info);
72 if (res != 0)
73 {
74 tea5767_interface_debug_print("tea5767: get info failed.\n");
75
76 return 1;
77 }
78 else
79 {
80 /* print chip information */
81 tea5767_interface_debug_print("tea5767: chip is %s.\n", info.chip_name);
82 tea5767_interface_debug_print("tea5767: manufacturer is %s.\n", info.manufacturer_name);
83 tea5767_interface_debug_print("tea5767: interface is %s.\n", info.interface);
84 tea5767_interface_debug_print("tea5767: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
85 tea5767_interface_debug_print("tea5767: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
86 tea5767_interface_debug_print("tea5767: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
87 tea5767_interface_debug_print("tea5767: max current is %0.2fmA.\n", info.max_current_ma);
88 tea5767_interface_debug_print("tea5767: max temperature is %0.1fC.\n", info.temperature_max);
89 tea5767_interface_debug_print("tea5767: min temperature is %0.1fC.\n", info.temperature_min);
90 }
91
92 /* start radio test */
93 tea5767_interface_debug_print("tea5767: start radio test.\n");
94
95 /* tea5767 init */
96 res = tea5767_init(&gs_handle);
97 if (res != 0)
98 {
99 tea5767_interface_debug_print("tea5767: init failed.\n");
100
101 return 1;
102 }
103
104 /* disable mute */
105 res = tea5767_set_mute(&gs_handle, TEA5767_BOOL_FALSE);
106 if (res != 0)
107 {
108 tea5767_interface_debug_print("tea5767: set mute failed.\n");
109 (void)tea5767_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 /* search mode */
115 res = tea5767_set_mode(&gs_handle, TEA5767_MODE_SEARCH);
116 if (res != 0)
117 {
118 tea5767_interface_debug_print("tea5767: set mode failed.\n");
119 (void)tea5767_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set pll */
125 res = tea5767_set_pll(&gs_handle, 0x2A00);
126 if (res != 0)
127 {
128 tea5767_interface_debug_print("tea5767: set pll failed.\n");
129 (void)tea5767_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set search mode up */
136 if (res != 0)
137 {
138 tea5767_interface_debug_print("tea5767: set search mode failed.\n");
139 (void)tea5767_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set search stop level mid*/
146 if (res != 0)
147 {
148 tea5767_interface_debug_print("tea5767: set search stop level failed.\n");
149 (void)tea5767_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set side injection low */
156 if (res != 0)
157 {
158 tea5767_interface_debug_print("tea5767: set side injection failed.\n");
159 (void)tea5767_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* set channel stereo */
166 if (res != 0)
167 {
168 tea5767_interface_debug_print("tea5767: set channel failed.\n");
169 (void)tea5767_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 /* disable right mute */
176 if (res != 0)
177 {
178 tea5767_interface_debug_print("tea5767: set right mute failed.\n");
179 (void)tea5767_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* disable left mute */
186 if (res != 0)
187 {
188 tea5767_interface_debug_print("tea5767: set left mute failed.\n");
189 (void)tea5767_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* set port1 low */
195 res = tea5767_set_port1(&gs_handle, TEA5767_LEVEL_LOW);
196 if (res != 0)
197 {
198 tea5767_interface_debug_print("tea5767: set port1 failed.\n");
199 (void)tea5767_deinit(&gs_handle);
200
201 return 1;
202 }
203
204 /* set port2 low */
205 res = tea5767_set_port2(&gs_handle, TEA5767_LEVEL_LOW);
206 if (res != 0)
207 {
208 tea5767_interface_debug_print("tea5767: set port2 failed.\n");
209 (void)tea5767_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* disable standby */
215 res = tea5767_set_standby(&gs_handle, TEA5767_BOOL_FALSE);
216 if (res != 0)
217 {
218 tea5767_interface_debug_print("tea5767: set standby failed.\n");
219 (void)tea5767_deinit(&gs_handle);
220
221 return 1;
222 }
223
224 /* set band Japanese */
225 res = tea5767_set_band(&gs_handle, TEA5767_BAND_JAPANESE);
226 if (res != 0)
227 {
228 tea5767_interface_debug_print("tea5767: set band failed.\n");
229 (void)tea5767_deinit(&gs_handle);
230
231 return 1;
232 }
233
234 /* disable soft mute */
235 res = tea5767_set_soft_mute(&gs_handle, TEA5767_BOOL_FALSE);
236 if (res != 0)
237 {
238 tea5767_interface_debug_print("tea5767: set soft mute failed.\n");
239 (void)tea5767_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* enable high cut control */
246 if (res != 0)
247 {
248 tea5767_interface_debug_print("tea5767: set high cut control failed.\n");
249 (void)tea5767_deinit(&gs_handle);
250
251 return 1;
252 }
253
254 /* enable stereo noise cancelling */
256 if (res != 0)
257 {
258 tea5767_interface_debug_print("tea5767: set stereo noise cancelling failed.\n");
259 (void)tea5767_deinit(&gs_handle);
260
261 return 1;
262 }
263
264 /* enable port1 as search indicator */
266 if (res != 0)
267 {
268 tea5767_interface_debug_print("tea5767: set port1 as search indicator failed.\n");
269 (void)tea5767_deinit(&gs_handle);
270
271 return 1;
272 }
273
274 /* set de emphasis 50us */
276 if (res != 0)
277 {
278 tea5767_interface_debug_print("tea5767: set de emphasis failed.\n");
279 (void)tea5767_deinit(&gs_handle);
280
281 return 1;
282 }
283
284 /* set clock */
285 res = tea5767_set_clock(&gs_handle, clk);
286 if (res != 0)
287 {
288 tea5767_interface_debug_print("tea5767: set clock failed.\n");
289 (void)tea5767_deinit(&gs_handle);
290
291 return 1;
292 }
293
294 /* write conf */
295 res = tea5767_write_conf(&gs_handle);
296 if (res != 0)
297 {
298 tea5767_interface_debug_print("tea5767: write conf failed.\n");
299 (void)tea5767_deinit(&gs_handle);
300
301 return 1;
302 }
303
304 /* wait searched */
305 while (1)
306 {
307 /* read conf */
308 res = tea5767_read_conf(&gs_handle);
309 if (res != 0)
310 {
311 tea5767_interface_debug_print("tea5767: read conf failed.\n");
312 (void)tea5767_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* read ready flag */
318 res = tea5767_get_ready_flag(&gs_handle, &ready_flag);
319 if (res != 0)
320 {
321 tea5767_interface_debug_print("tea5767: get ready flag failed.\n");
322 (void)tea5767_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* get band limit flag */
328 res = tea5767_get_band_limit_flag(&gs_handle, &limit_flag);
329 if (res != 0)
330 {
331 tea5767_interface_debug_print("tea5767: get band limit flag failed.\n");
332 (void)tea5767_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* check teh ready flag */
338 if (ready_flag == TEA5767_BOOL_TRUE)
339 {
340 break;
341 }
342
343 /* delay 500ms */
345 }
346 if (limit_flag == TEA5767_BOOL_TRUE)
347 {
348 tea5767_interface_debug_print("tea5767: band limit.\n");
349 }
350 else
351 {
352 tea5767_interface_debug_print("tea5767: band found.\n");
353 }
354
355 /* get searched pll */
356 res = tea5767_get_searched_pll(&gs_handle, &pll);
357 if (res != 0)
358 {
359 tea5767_interface_debug_print("tea5767: get searched pll failed.\n");
360 (void)tea5767_deinit(&gs_handle);
361
362 return 1;
363 }
364
365 /* output */
366 tea5767_interface_debug_print("tea5767: searched pll is 0x%04X.\n", pll);
367
368 /* frequency convert to data */
369 res = tea5767_frequency_convert_to_data(&gs_handle, pll, &mhz);
370 if (res != 0)
371 {
372 tea5767_interface_debug_print("tea5767: frequency convert to data failed.\n");
373 (void)tea5767_deinit(&gs_handle);
374
375 return 1;
376 }
377
378 /* output */
379 tea5767_interface_debug_print("tea5767: searched frequency is %0.2fMHz.\n", mhz);
380
381 /* get if */
382 res = tea5767_get_if(&gs_handle, &output);
383 if (res != 0)
384 {
385 tea5767_interface_debug_print("tea5767: get if failed.\n");
386 (void)tea5767_deinit(&gs_handle);
387
388 return 1;
389 }
390
391 /* output */
392 tea5767_interface_debug_print("tea5767: if is 0x%02X.\n", output);
393
394 /* get reception */
395 res = tea5767_get_reception(&gs_handle, &reception);
396 if (res != 0)
397 {
398 tea5767_interface_debug_print("tea5767: get reception failed.\n");
399 (void)tea5767_deinit(&gs_handle);
400
401 return 1;
402 }
403
404 /* output */
405 tea5767_interface_debug_print("tea5767: reception is %s.\n", (reception == TEA5767_RECEPTION_MONO) ? "mono" : "stereo");
406
407 /* get level adc output */
408 res = tea5767_get_level_adc_output(&gs_handle, &output);
409 if (res != 0)
410 {
411 tea5767_interface_debug_print("tea5767: get level adc output failed.\n");
412 (void)tea5767_deinit(&gs_handle);
413
414 return 1;
415 }
416
417 /* output */
418 tea5767_interface_debug_print("tea5767: adc output level is 0x%02X.\n", output);
419
420 /* play 20s */
421 tea5767_interface_debug_print("tea5767: play 20s.\n");
423
424 /* finish radio test */
425 tea5767_interface_debug_print("tea5767: finish radio test.\n");
426 (void)tea5767_deinit(&gs_handle);
427
428 return 0;
429}
driver tea5767 radio test 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_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
tea5767_clock_t
tea5767 clock enumeration definition
tea5767_reception_t
tea5767 reception 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_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_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_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_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_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_CHANNEL_STEREO
@ TEA5767_DE_EMPHASIS_50US
@ TEA5767_RECEPTION_MONO
@ TEA5767_SIDE_INJECTION_LOW
@ TEA5767_SEARCH_STOP_LEVEL_MID
@ TEA5767_BOOL_TRUE
@ TEA5767_BOOL_FALSE
@ TEA5767_LEVEL_LOW
@ TEA5767_SEARCH_MODE_UP
@ TEA5767_BAND_JAPANESE
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
uint8_t tea5767_radio_test(tea5767_clock_t clk)
radio test
uint32_t driver_version
char manufacturer_name[32]