-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradioM036.py
1710 lines (1385 loc) · 54.5 KB
/
radioM036.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3.8
#coding: utf-8
"""
================================================
A radio app for the AVerMedia AVerTV USB2.0 Plus
================================================
Version: 0.1
Author: Sinan Güngör
"""
import libusb_package
import usb.core
import usb.util
import usb.backend.libusb1
import os
import sys
import platform
#-----------------------
VENDOR_ID = 0x07ca
PRODUCT_ID = 0x0036
#-----------------------
# For non-root linux users, a udev rule is necessary to access the device.
# See tools/udev-rule-07ca-0036.sh
#
# To use libusb on Windows, a driver must be installed for the Interface 0
# See https://github.com/libusb/libusb/wiki/Windows#Driver_Installation
#
# the following packages are to be installed:
# pyusb
# libusb-package
# python-vlc
# pillow
#-----------------------
# Find device
#-----------------------
print("libusb path:\n\t{}".format(libusb_package.get_library_path()))
was_kernel_driver_active = False
dev = None
if platform.system() == 'Windows':
backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
dev= usb.core.find(backend=backend, idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
elif platform.system() == 'Linux':
dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
# if the OS kernel already claimed the device
if dev.is_kernel_driver_active(0) is True:
# tell the kernel to detach
dev.detach_kernel_driver(0)
was_kernel_driver_active = True
try:
dev.detach_kernel_driver(0)
except usb.core.USBError as e:
sys.exit("Could not detatch kernel driver from interface({0}): {1}".format(0, str(e)))
else:
dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
if dev is None:
raise ValueError('Device not found. Please ensure it is connected to the computer.')
sys.exit(1)
#--------------------------------------------------------------------
# Configuration (capture device for vlc)
# If needed, fix the capture device setting in the config.xml file.
#--------------------------------------------------------------------
import xml.etree.ElementTree as ET
def read_configuration(file):
tree=ET.parse(file)
root=tree.getroot()
global captureDevice
captureDevice=root.find('captureDevice').text
def write_configuration(file):
root = ET.Element("configuration")
CaptureDevice=ET.SubElement(root,"captureDevice").text="{}".format(captureDevice)
tree = ET.ElementTree(root)
tree.write(file,encoding="utf-8", xml_declaration=True)
if platform.system() == 'Linux':
from shutil import which
if which('xml') :
cmd="xml format {file} > {file}.1".format(file=fileConfiguration)
print(cmd)
os.system(cmd)
cmd="mv {file}.1 {file} ".format(file=fileConfiguration)
print(cmd)
os.system(cmd)
captureDevice=""
fileConfiguration="config.xml"
#
# to find out audio source in Linux:
# pactl list short sources
#
isFile = os.path.isfile(fileConfiguration)
if isFile:
read_configuration(fileConfiguration)
else:
if platform.system() == 'Linux':
captureDevice='pulse://alsa_input.usb-AVerMedia_AVerTV_USB_2.0_Plus-01.analog-stereo'
if platform.system() == 'Windows':
captureDevice= 'dshow:// :dshow-vdev=none :dshow-adev="Digital Audio Interface (AVerTV USB 2.0 Plus)" :live-caching=300'
write_configuration(fileConfiguration)
#-------------------------------
# VLC
#-------------------------------
import vlc
if platform.system() == 'Linux':
vlcOptions="-I 'dummy'"
vlcInstance = vlc.Instance(vlcOptions)
print("")
if platform.system() == 'Windows':
vlcOptions="--no-video"
vlcInstance = vlc.Instance(vlcOptions)
audioPlayer = vlcInstance.media_player_new()
capture_media = vlcInstance.media_new(captureDevice)
audioPlayer.set_media(capture_media)
audioPlayer.play()
#-------------------------------
# libusb control transfers
#-------------------------------
def ctrl_tx(index,value):
ret = dev.ctrl_transfer(0x40,1,value,index,0,timeout=1000)
def ctrl_rx(index):
ret = dev.ctrl_transfer(0xc0, 0, 0x0000, index,1,timeout=1000)
return ret[0]
def print_creg(index):
value=ctrl_rx(index)
#print("Index 0x{i:04x} : {v:04d} : 0x{v:02x} : {b}".format(i=index,v=value,b=byte2bits(value)))
return value
#-----------------------
# Radio playlist
#-----------------------
class radioStation():
def __init__(self):
self.frequency_MHz = None
self.name = None
def write_playlist(file):
root = ET.Element("playlist")
Playing=ET.SubElement(root,"playing").text="{}".format(station)
for i in range (nStation):
Station=ET.SubElement(root,"station")
ET.SubElement(Station,"name").text=stations[i].name
ET.SubElement(Station,"frequency_MHz").text="{freq:.2f}".format(freq=stations[i].frequency_MHz)
tree = ET.ElementTree(root)
tree.write(file,encoding="utf-8", xml_declaration=True)
from shutil import which
if which('xml') :
cmd="xml format {file} > {file}.1".format(file=filePlaylist)
print(cmd)
os.system(cmd)
cmd="mv {file}.1 {file} ".format(file=filePlaylist)
print(cmd)
os.system(cmd)
def read_playlist(file):
tree=ET.parse(file)
root=tree.getroot()
global station
global nStation
global stations
station=int(root[0].text)
stations = []
for s in root.findall('station'):
stations.append(radioStation())
nStation=len(stations)
stations[nStation-1].name=s[0].text
stations[nStation-1].frequency_MHz=float(s[1].text)
def print_playlist():
print('Station: {}'.format(station))
print('# of Station: {}'.format(nStation))
for i in range (nStation):
print("{} : {}".format(stations[i].frequency_MHz, stations[i].name))
#-----------------------
nStation = 0
station = 0
stations = []
filePlaylist="playlist.xml"
isFile = os.path.isfile(filePlaylist)
if isFile:
read_playlist(filePlaylist)
else:
newStation=radioStation()
newStation.frequency_MHz=87.50
newStation.name="Unknown Station"
stations.insert(station,newStation)
nStation+=1
#print_playlist()
#-----------------------
# Some bit operation
#-----------------------
def set_bit(value, bit):
return value | (1<<bit)
def clear_bit(value, bit):
return value & ~(1<<bit)
def get_bit(value,bit):
return ((value >> bit) & 1)
#-----------------------
# Utils
#-----------------------
def word2bits(x):
return "{:04b}".format(x>>12)+" "+"{:04b}".format((x>>8)&0x0F)+" "+"{:04b}".format((x>>4)&0x0F)+" "+"{:04b}".format(x&0x0F)
def byte2bits(x):
return "{:04b}".format(x>>4)+" "+"{:04b}".format(x&0x0F)
#===============================================================================
# I2C stuff
#===============================================================================
def i2c_start():
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0001,0x0003)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0003,0x0083)
def i2c_bit_tx(b):
if b :
ctrl_tx(0x0001,0x0003) # 1
else:
ctrl_tx(0x0001,0x0002) # 0
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0000,0x00ec)
def i2c_byte_tx(byte):
for x in range(7,-1,-1):
b=get_bit(byte,x)
i2c_bit_tx(b)
def i2c_ack_tx():
ctrl_tx(0x0003,0x0082)
ctrl_tx(0x0001,0x0003)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0003,0x0083)
def i2c_stop_tx():
ctrl_tx(0x0003,0x0082)
ctrl_tx(0x0001,0x0003)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0001,0x0003)
def i2c_bit_rx():
ctrl_tx(0x0000,0x00fc)
i1=ctrl_rx(0x0001)
ctrl_tx(0x0000,0x00ec)
if(i1 == 0x03):
b=1
else:
b=0
return b
def i2c_byte_rx():
byte=0x00
for x in range(7,-1,-1):
b=i2c_bit_rx()
if b == 1 :
byte=set_bit(byte,x)
return byte
def i2c_ack_rx():
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0001,0x0003)
ctrl_tx(0x0003,0x0082)
def i2c_stop_rx():
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0001,0x0003)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0000,0x00ec)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x0000,0x00fc)
ctrl_tx(0x0001,0x0003)
#===============================================================================
# TEA5767 stuff
#===============================================================================
#-------------------------------
# Write mode register values
#-------------------------------
# First register
TEA5767_MUTE = 0x80 # Mutes output
TEA5767_SM = 0x40 # Activates station search
# Third register
TEA5767_SUD = 0x80 # Station search from bottom to up
TEA5767_SL_MASK = 0x60
TEA5767_SL_H = 0x60 # Searches with ADC output = 10
TEA5767_SL_M = 0x40 # Searches with ADC output = 7
TEA5767_SL_L = 0x20 # Searches with ADC output = 5
TEA5767_HLSI = 0x10 # If on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq)
TEA5767_MS= 0x08 # Disable stereo
TEA5767_MR = 0x04 # Disable right channel and turns to mono
TEA5767_ML = 0x02 # Disable left channel and turns to mono
TEA5767_SWP1 = 0x01 #
# Fourth register
TEA5767_SWP2 = 0x80 #
TEA5767_STDBY = 0x40 # Chips stops working. Only I2C bus remains on
TEA5767_BL = 0x20 # Japan freq 76-108 MHz . If disabled, 87.5-108 MHz
TEA5767_XTAL = 0x10 # Selected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz
TEA5767_SMUTE = 0x08 # Cuts weak signals
TEA5767_HCC = 0x04 # Activates high cut control
TEA5767_SNC = 0x02 # Activates stereo noise control
TEA5767_SI = 0x01 # If activate PORT 1 indicates SEARCH or else it is used as PORT1 */
# Fifth register
TEA5767_PLLREF = 0x80 # By activating, it will use Xtal at 13 MHz as reference for divider
TEA5767_DTC = 0X40 # By activating, deemphasis=75us, or else, deemphasis of 50us
#-------------------------------
# Read mode register values
#-------------------------------
# First register
TEA5767_READY_FLAG_MASK = 0x80 # Tuning completed or BL reached / Busy
TEA5767_BAND_LIMIT_MASK = 0X40 # Band limit reached / not reached
TEA5767_PLL_H_MASK = 0X3F # Bits 0-5 for divider MSB after search or preset
# Second register
TEA5767_PLL_L_MASK = 0XFF # Bits 0-7 for divider LSB after search or preset
# Third register
TEA5767_STEREO_MASK = 0x80 # Stereo reception / Mono reception
TEA5767_IF_CNTR_MASK = 0x7f # IF counter result
# Fourth register
TEA5767_ADC_LEVEL_MASK = 0xf0 # Level ADC output
TEA5767_CHIP_ID_MASK = 0x0f # Should be 0
# Fifth register
TEA5767_RESERVED_MASK = 0xff # Reserved
#-------------------------------------------------------------------------------
tea5767_registers_r=[0,0,0,0,0]
tea5767_registers_w=[0,0,0,0,0]
#-------------------------------------------------------------------------------
def tea5767_read():
global tea5767_registers_r
i2c_start()
i2c_byte_tx(0xc1)
i2c_ack_rx()
tea5767_registers_r[0]=i2c_byte_rx()
i2c_ack_rx()
tea5767_registers_r[1]=i2c_byte_rx()
i2c_ack_rx()
tea5767_registers_r[2]=i2c_byte_rx()
i2c_ack_rx()
tea5767_registers_r[3]=i2c_byte_rx()
i2c_ack_rx()
tea5767_registers_r[4]=i2c_byte_rx()
i2c_stop_rx()
def tea5767_write():
i2c_start()
i2c_byte_tx(0xc0)
i2c_ack_tx()
i2c_byte_tx(tea5767_registers_w[0])
i2c_ack_tx()
i2c_byte_tx(tea5767_registers_w[1])
i2c_ack_tx()
i2c_byte_tx(tea5767_registers_w[2])
i2c_ack_tx()
i2c_byte_tx(tea5767_registers_w[3])
i2c_ack_tx()
i2c_byte_tx(tea5767_registers_w[4])
i2c_stop_tx()
def radio_status():
tea5767_read()
print_radio_status()
def print_radio_status():
TEA5767_Ready=(tea5767_registers_r[0]&TEA5767_READY_FLAG_MASK)>>7
TEA5767_Band_Limits=(tea5767_registers_r[0]&TEA5767_BAND_LIMIT_MASK)>>6
TEA5767_PLL=((tea5767_registers_r[0]&TEA5767_PLL_H_MASK)<<8)|tea5767_registers_r[1]&TEA5767_PLL_L_MASK
TEA5767_Stereo=(tea5767_registers_r[2]&TEA5767_STEREO_MASK)>>7
TEA5767_IF_Counter=tea5767_registers_r[2]&TEA5767_IF_CNTR_MASK
TEA5767_ADC_Level=(tea5767_registers_r[3]&TEA5767_ADC_LEVEL_MASK)>>4
print("\nReady flag: {rf}".format(rf=TEA5767_Ready))
print("Band limit flag: {blf}".format(blf=TEA5767_Band_Limits))
frequencyMHz = ((TEA5767_PLL*50.0)/4.0+225.0)/1000
print("Frequency: {f:.2f} MHz".format(f=frequencyMHz))
print("Stereo flag: {sf}".format(sf=TEA5767_Stereo))
print("ADC level: {adc}".format(adc=TEA5767_ADC_Level))
def print_radio_control():
TEA5767_Mute=(tea5767_registers_w[0]&TEA5767_MUTE)>>7
TEA5767_SearchMode=(tea5767_registers_w[0]&TEA5767_SM)>>6
TEA5767_PLL=((tea5767_registers_w[0]&TEA5767_PLL_H_MASK)<<8)|tea5767_registers_w[1]&TEA5767_PLL_L_MASK
ctrl_frequencyMHz = ((TEA5767_PLL*50.0)/4.0+225.0)/1000
TEA5767_Search_UpDown = (tea5767_registers_w[2]&TEA5767_SUD)>>7
TEA5767_Search_Level = (tea5767_registers_w[2]&TEA5767_SL_MASK)>>5
TEA5767_High_Low_Injection=(tea5767_registers_w[2]&TEA5767_HLSI)>>4
TEA5767_Mono_Stereo=(tea5767_registers_w[2]&TEA5767_MS)>>3
TEA5767_Mute_Right=(tea5767_registers_w[2]&TEA5767_MR)>>2
TEA5767_Mute_Left=(tea5767_registers_w[2]&TEA5767_ML)>>1
TEA5767_SoftwareProgrammable_P1=(tea5767_registers_w[2]&TEA5767_SWP1)
TEA5767_SoftwareProgrammable_P2=(tea5767_registers_w[3]&TEA5767_SWP2)>>7
TEA5767_Standby=(tea5767_registers_w[3]&TEA5767_STDBY)>>6
TEA5767_Band_Limits=(tea5767_registers_w[3]&TEA5767_BL)>>5
TEA5767_Clock_Frequency=(tea5767_registers_w[3]&TEA5767_XTAL)>>4
TEA5767_Soft_Mute=(tea5767_registers_w[3]&TEA5767_SMUTE)>>3
TEA5767_High_Cut_Control=(tea5767_registers_w[3]&TEA5767_HCC)>>2
TEA5767_Stereo_Noise_Cancelling=(tea5767_registers_w[3]&TEA5767_SNC)>>1
TEA5767_Search_Indicator=(tea5767_registers_w[3]&TEA5767_SI)
TEA5767_PLL_Reference=(tea5767_registers_w[4]&TEA5767_PLLREF)>>7
TEA5767_Deemphasis_Time_Constant=(tea5767_registers_w[4]&TEA5767_DTC)>>6
print("\n")
print("Mute: {m}".format(m=TEA5767_Mute))
print("Search Mode: {s}".format(s=TEA5767_SearchMode))
print("PLL: {pll} ({f:.2f} MHz)".format(pll=TEA5767_PLL, f=ctrl_frequencyMHz))
print("Search Up: {sud}".format(sud=TEA5767_Search_UpDown))
print("Search Level: {sl}".format(sl=TEA5767_Search_Level))
print("High/Low Side Injection: {hlsi}".format(hlsi=TEA5767_High_Low_Injection))
print("Mute Right: {mr}".format(mr=TEA5767_Mute_Right))
print("Mute Left: {ml}".format(ml=TEA5767_Mute_Left))
print("Software Programmable Port 1: {p1}".format(p1=TEA5767_SoftwareProgrammable_P1))
print("Software Programmable Port 2: {p2}".format(p2=TEA5767_SoftwareProgrammable_P2))
print("Standby: {stdby}".format(stdby=TEA5767_Standby))
print("Band Limits: {bl}".format(bl=TEA5767_Band_Limits))
print("Clock frenquency: {xtal}".format(xtal=TEA5767_Clock_Frequency))
print("Soft Mute: {sm}".format(sm=TEA5767_Soft_Mute))
print("High Cut Control: {hcc}".format(hcc=TEA5767_High_Cut_Control))
print("Stereo Noise Cancelling: {snc}".format(snc=TEA5767_Stereo_Noise_Cancelling))
print("Search Indicator: {si}".format(si=TEA5767_Search_Indicator))
print("PLL Reference: {pllref}".format(pllref=TEA5767_PLL_Reference))
print("Deemphasis Time Constant: {dtc}".format(dtc=TEA5767_Deemphasis_Time_Constant))
print("\n")
#===============================================================================
frequencyMHz_min=87.5
frequencyMHz_max=108
def radio_frequency_limits(bandLimits):
global requencyMHz_min
global requencyMHz_max
if bandLimits == 0 :
frequencyMHz_min=87.5
frequencyMHz_max=108
else:
frequencyMHz_min=76
frequencyMHz_max=91
def radio_signal_level():
tea5767_read()
TEA5767_ADC_Level=(tea5767_registers_r[3]&TEA5767_ADC_LEVEL_MASK)>>4
print("ADC level: {adc}".format(adc=TEA5767_ADC_Level))
return TEA5767_ADC_Level
def radio_set_frequency(frequencyMHz):
global tea5767_registers_w
# print("Frequency %.2f MHz" % frequencyMHz)
wPLL = round((frequencyMHz*1000.0-225.0)*4.0/50.0)
PLL_L = wPLL & 0x00FF
PLL_H = (wPLL >> 8) & 0x003F
tea5767_registers_w[0]=(tea5767_registers_w[0]&~TEA5767_PLL_H_MASK)|PLL_H
tea5767_registers_w[1]=PLL_L
tea5767_write()
def radio_play_station (station):
global frequencyMHz
frequencyMHz = stations[station].frequency_MHz
radio_set_frequency(frequencyMHz)
print( "\n%0.2f" % stations[station].frequency_MHz,"MHz (%s) is playing" % stations[station].name)
def radio_mute():
global tea5767_registers_w
tea5767_registers_w[0]=set_bit(tea5767_registers_w[0],7)
tea5767_write()
def radio_unmute():
global tea5767_registers_w
tea5767_registers_w[0]=clear_bit(tea5767_registers_w[0],7)
tea5767_write()
def radio_set_mono():
global tea5767_registers_w
tea5767_registers_w[2]=set_bit(tea5767_registers_w[2],3)
tea5767_write()
def radio_set_stereo():
global tea5767_registers_w
tea5767_registers_w[2]=clear_bit(tea5767_registers_w[2],3)
tea5767_write()
def radio_mute_left():
global tea5767_registers_w
tea5767_registers_w[2]=set_bit(tea5767_registers_w[2],1)
tea5767_write()
def radio_unmute_left():
global tea5767_registers_w
tea5767_registers_w[2]=clear_bit(tea5767_registers_w[2],1)
tea5767_write()
def radio_mute_right():
global tea5767_registers_w
tea5767_registers_w[2]=set_bit(tea5767_registers_w[2],2)
tea5767_write()
def radio_unmute_right():
global tea5767_registers_w
tea5767_registers_w[2]=clear_bit(tea5767_registers_w[2],2)
tea5767_write()
def radio_set_Band_Limits_Japan():
global tea5767_registers_w
tea5767_registers_w[3]=set_bit(tea5767_registers_w[3],5)
tea5767_write()
def radio_Band_Limits_EU_USA():
global tea5767_registers_w
tea5767_registers_w[3]=clear_bit(tea5767_registers_w[3],5)
tea5767_write()
def radio_set_search_mode():
global tea5767_registers_w
tea5767_registers_w[0]=set_bit(tea5767_registers_w[0],6)
tea5767_write()
def radio_clear_search_mode():
global tea5767_registers_w
tea5767_registers_w[0]=clear_bit(tea5767_registers_w[0],6)
tea5767_write()
def radio_search_up():
global tea5767_registers_w
tea5767_registers_w[2]=set_bit(tea5767_registers_w[2],7)
tea5767_write()
def radio_search_down():
global tea5767_registers_w
tea5767_registers_w[2]=clear_bit(tea5767_registers_w[2],7)
tea5767_write()
def radio_set_SSL(ssl):
global tea5767_registers_w
tea5767_registers_w[0]=(tea5767_registers_w[0]&~TEA5767_SL_MASK)|ssl
def radio_SNC_on():
global tea5767_registers_w
tea5767_registers_w[3]=set_bit(tea5767_registers_w[3],1)
tea5767_write()
def radio_SNC_off():
global tea5767_registers_w
tea5767_registers_w[3]=clear_bit(tea5767_registers_w[3],1)
tea5767_write()
def radio_HCC_on():
global tea5767_registers_w
tea5767_registers_w[3]=set_bit(tea5767_registers_w[3],2)
tea5767_write()
def radio_HCC_off():
global tea5767_registers_w
tea5767_registers_w[3]=clear_bit(tea5767_registers_w[3],2)
tea5767_write()
def radio_SoftMute_on():
global tea5767_registers_w
tea5767_registers_w[3]=set_bit(tea5767_registers_w[3],3)
tea5767_write()
def radio_SoftMute_off():
global tea5767_registers_w
tea5767_registers_w[3]=clear_bit(tea5767_registers_w[3],3)
tea5767_write()
#===============================================================================
# Realtek ACL655 Audio Codec stuff
#===============================================================================
vol=0
#-------------------------------
# Mixer registers
#-------------------------------
MASTER_VOL=0x02 # MX02 (Front) Master volume
MIC_VOL=0x0e # MX0E MIC Volume
LINE_IN_VOL=0x10 # MX10 LINE_IN Volume
CD_VOL=0x12 # MX12 CD Volume
AUX_VOL=0x16 # MX16 AUX Volume
RECORD_SELECT=0x1a # MX1A Record Select #
RECORD_GAIN=0x1c # MX1C Record Gain
def get_MX(mx):
ctrl_tx(0x0504,mx)
ctrl_tx(0x0500,0x008b)
MX_L=ctrl_rx(0x0502)
MX_H=ctrl_rx(0x0503)
MX=(MX_H<<8)|MX_L
return MX
def set_MX(mx,value):
ctrl_tx(0x0504,mx)
MX_L=value&0x00FF
MX_H=(value>>8)&0x00FF
ctrl_tx(0x0502,MX_L)
ctrl_tx(0x0503,MX_H)
ctrl_tx(0x0500,0x008c)
def set_volume(vol):
if vol > 15 :
vol=15
if vol < 0 :
vol=0
LRG=vol
RRG=vol
RG=(LRG<<8)|RRG
set_MX(RECORD_GAIN,RG)
print("Volume: {}".format(vol))
def set_volume_LR(volL,volR):
if volL > 15 :
volL=15
if volL < 0 :
volL=0
if volR > 15 :
volR=15
if volR < 0 :
volR=0
LRG=volL
RRG=volR
RG=(LRG<<8)|RRG
set_MX(RECORD_GAIN,RG)
print("Volume: {l} L {r} R".format(l=volL,r=volR))
def mute():
RG=get_MX(RECORD_GAIN)
RG=set_bit(RG,15)
set_MX(RECORD_GAIN,RG)
def unmute():
RG=get_MX(RECORD_GAIN)
RG=clear_bit(RG,15)
set_MX(RECORD_GAIN,RG)
#===============================================================================
# Others
#===============================================================================
def LED_on():
reg0x00=ctrl_rx(0x0000)
reg0x00=set_bit(reg0x00,6)
ctrl_tx(0x0000,reg0x00)
ctrl_tx(0x0002,0x00e8)
def LED_off():
reg0x00=ctrl_rx(0x0000)
reg0x00=clear_bit(reg0x00,6)
ctrl_tx(0x0000,reg0x00)
ctrl_tx(0x0002,0x00e8)
#===============================================================================
def init_driver():
if dev.get_active_configuration().bConfigurationValue != 1 :
dev.set_configuration(1)
dev.set_interface_altsetting(interface = 0, alternate_setting = 0)
ctrl_tx(0x0000,0x0060)
ctrl_tx(0x0002,0x00e8)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0002,0x00ef)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0066)
ctrl_tx(0x0000,0x0067)
ctrl_tx(0x0000,0x0066)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0064)
ctrl_tx(0x0000,0x0065)
ctrl_tx(0x0000,0x0061)
ctrl_tx(0x0002,0x00ef)
ctrl_tx(0x0000,0x0061)
ctrl_tx(0x0203,0x00ba)
ctrl_tx(0x0002,0x00e8)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0000,0x0060)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x000d,0x0000)
ctrl_tx(0x000f,0x0002)
ctrl_tx(0x0103,0x0000)
ctrl_tx(0x0300,0x0012)
ctrl_tx(0x0350,0x002d)
ctrl_tx(0x0351,0x0001)
ctrl_tx(0x0352,0x0000)
ctrl_tx(0x0353,0x0000)
ctrl_tx(0x0300,0x0080)
ctrl_tx(0x0018,0x0010)
ctrl_tx(0x0019,0x0000)
ctrl_tx(0x0202,0x001e)
ctrl_tx(0x0110,0x0050)
ctrl_tx(0x0111,0x0000)
ctrl_tx(0x0112,0x0019)
ctrl_tx(0x0113,0x0000)
ctrl_tx(0x0114,0x0050)
ctrl_tx(0x0115,0x0005)
ctrl_tx(0x0116,0x0009)
ctrl_tx(0x0117,0x0001)
ctrl_tx(0x0100,0x0033)
ctrl_tx(0x0203,0x00ba)
ctrl_tx(0x0204,0x007f)
ctrl_tx(0x0205,0x0000)
ctrl_tx(0x0200,0x0001)
ctrl_tx(0x0208,0x0080)
ctrl_tx(0x0200,0x0020)
ctrl_tx(0x0208,0x0081)
ctrl_tx(0x0200,0x0020)
ctrl_tx(0x0203,0x00a0)
ctrl_tx(0x0208,0x003c)
ctrl_tx(0x0200,0x0020)
ctrl_tx(0x0203,0x00ba)
ctrl_tx(0x0002,0x00e8)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0000,0x0060)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x000d,0x0000)
ctrl_tx(0x000f,0x0002)
ctrl_tx(0x0103,0x0000)
ctrl_tx(0x0300,0x0012)
ctrl_tx(0x0350,0x002d)
ctrl_tx(0x0351,0x0001)
ctrl_tx(0x0352,0x0000)
ctrl_tx(0x0353,0x0000)
ctrl_tx(0x0300,0x0080)
ctrl_tx(0x0018,0x0010)
ctrl_tx(0x0019,0x0000)
ctrl_tx(0x0202,0x001e)
ctrl_tx(0x0110,0x0050)
ctrl_tx(0x0111,0x0000)
ctrl_tx(0x0112,0x0019)
ctrl_tx(0x0113,0x0000)
ctrl_tx(0x0114,0x0050)
ctrl_tx(0x0115,0x0005)
ctrl_tx(0x0116,0x0009)
ctrl_tx(0x0117,0x0001)
ctrl_tx(0x0100,0x0033)
ctrl_tx(0x0204,0x0008)
ctrl_tx(0x0205,0x0008)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0028)
ctrl_tx(0x0205,0x000c)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0030)
ctrl_tx(0x0205,0x0000)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x000f)
ctrl_tx(0x0205,0x000a)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0500,0x0094)
ctrl_tx(0x0500,0x008c)
ctrl_tx(0x0506,0x0001)
ctrl_tx(0x0507,0x0000)
ctrl_tx(0x0100,0x0033)
ctrl_tx(0x0000,0x006c)
ctrl_tx(0x0204,0x0000)
ctrl_tx(0x0205,0x0002)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0003)
ctrl_tx(0x0205,0x006f)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0100,0x0033)
# mx10=get_MX(LINE_IN_VOL)
#
# set_MX(CD_VOL,0x8808)
#
# mx12=get_MX(CD_VOL)
# set_MX(CD_VOL,0x0808)
#
# mx0e=get_MX(MIC_VOL)
# set_MX(MIC_VOL,0x0008)
#
# mx16=get_MX(AUX_VOL)
# set_MX(AUX_VOL,0x0808)
#
# set_MX(RECORD_SELECT,0x0101)
# set_MX(RECORD_GAIN,0x0000)
####################################################################################
def init_radio():
dev.set_interface_altsetting(interface = 0, alternate_setting = 5)
ctrl_tx(0x0203,0x00ba)
ctrl_tx(0x0002,0x00e8)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0000,0x0060)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x000d,0x0000)
ctrl_tx(0x000f,0x0002)
ctrl_tx(0x0103,0x0000)
ctrl_tx(0x0300,0x0012)
ctrl_tx(0x0350,0x002d)
ctrl_tx(0x0351,0x0001)
ctrl_tx(0x0352,0x0000)
ctrl_tx(0x0353,0x0000)
ctrl_tx(0x0300,0x0080)
ctrl_tx(0x0018,0x0010)
ctrl_tx(0x0019,0x0000)
ctrl_tx(0x0202,0x001e)
ctrl_tx(0x0110,0x0050)
ctrl_tx(0x0111,0x0000)
ctrl_tx(0x0112,0x0019)
ctrl_tx(0x0113,0x0000)
ctrl_tx(0x0114,0x0050)
ctrl_tx(0x0115,0x0005)
ctrl_tx(0x0116,0x0009)
ctrl_tx(0x0117,0x0001)
ctrl_tx(0x0100,0x00b3)
ctrl_tx(0x0204,0x0008)
ctrl_tx(0x0205,0x0008)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0028)
ctrl_tx(0x0205,0x000c)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0030)
ctrl_tx(0x0205,0x0000)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x000f)
ctrl_tx(0x0205,0x000a)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0100,0x0033)
ctrl_tx(0x0103,0x0000)
ctrl_tx(0x0100,0x00b3)
ctrl_tx(0x0106,0x0000)
ctrl_tx(0x0100,0x0033)
ctrl_tx(0x0000,0x006c)
ctrl_tx(0x0204,0x0000)
ctrl_tx(0x0205,0x0002)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0003)
ctrl_tx(0x0205,0x006f)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0100,0x00b3)
ctrl_tx(0x0203,0x00ba)
ctrl_tx(0x0002,0x00e8)
ctrl_tx(0x0003,0x0083)
ctrl_tx(0x0000,0x0060)
ctrl_tx(0x0001,0x0002)
ctrl_tx(0x000d,0x0000)
ctrl_tx(0x000f,0x0002)
ctrl_tx(0x0103,0x0000)
ctrl_tx(0x0300,0x0012)
ctrl_tx(0x0350,0x002d)
ctrl_tx(0x0351,0x0001)
ctrl_tx(0x0352,0x0000)
ctrl_tx(0x0353,0x0000)
ctrl_tx(0x0300,0x0080)
ctrl_tx(0x0018,0x0010)
ctrl_tx(0x0019,0x0000)
ctrl_tx(0x0202,0x001e)
ctrl_tx(0x0110,0x0050)
ctrl_tx(0x0111,0x0000)
ctrl_tx(0x0112,0x0019)
ctrl_tx(0x0113,0x0000)
ctrl_tx(0x0114,0x0050)
ctrl_tx(0x0115,0x0005)
ctrl_tx(0x0116,0x0009)
ctrl_tx(0x0117,0x0001)
ctrl_tx(0x0100,0x00b3)
ctrl_tx(0x0204,0x0008)
ctrl_tx(0x0205,0x0008)
ctrl_tx(0x0200,0x0005)
ctrl_tx(0x0204,0x0028)
ctrl_tx(0x0205,0x000c)
ctrl_tx(0x0200,0x0005)