PU2CLR BK108X Arduino Library  1.0.1
This is an Arduino Library to control the BK108X device
BK108X.h
Go to the documentation of this file.
1 
2 /**
3  * @mainpage PU2CLR BK108X Arduino Library
4  * @brief PU2CLR BK108X Arduino Library implementation. <br>
5  * @details This is an Arduino library for the BK1086 and BK1088 DSP BROADCAST RECEIVER.<br>
6  * @details It works with I2C protocol and can provide an easier interface for controlling the BK1086/88 devices.<br>
7  * @details This library is based on BEKEN - BK1086/88 - BROADCAST AM/FM/SW/LW RADIO RECEIVER manual.
8  *
9  * @see https://github.com/pu2clr/BK108X
10  *
11  * __THIS LIBRARY IS UNDER CONSTRUCTION.....___
12  *
13  *
14  * This library can be freely distributed using the MIT Free Software model.
15  * Copyright (c) 2020 Ricardo Lima Caratti.
16  * Contact: pu2clr@gmail.com
17  */
18 
19 #include <Arduino.h>
20 
21 #define MAX_DELAY_AFTER_OSCILLATOR 500 // Max delay after the crystal oscilator becomes active
22 
23 #define I2C_DEVICE_ADDR 0x80
24 
25 #define MAX_SEEK_TIME 3000 // Maximum time have to be a seeking process (in ms).
26 
27 #define OSCILLATOR_TYPE_CRYSTAL 1 // Crystal
28 #define OSCILLATOR_TYPE_REFCLK 0 // Reference clock
29 
30 #define RDS_STANDARD 0 //!< RDS Mode.
31 #define RDS_VERBOSE 1 //!< RDS Mode.
32 #define BK_SEEK_DOWN 0 //!< Seek Down Direction
33 #define BK_SEEK_UP 1 //!< Seek Up Direction
34 #define BK_SEEK_WRAP 0 //
35 #define BK_SEEK_STOP 1
36 
37 #define FM_FULL 0 //!< 64~108MHz
38 #define FM_BAND_JAPAN_WIDE 1 //!< 76–108 MHz (Japan wide band)
39 #define FM_BAND_JAPAN 2 //!< 76–90 MHz (Japan)
40 #define FM_BAND_USA_EU 3 //!< 87–108 MHz (US / Europe, Default)
41 
42 #define AM_LW 0 //!< 153~279KHz
43 #define AM_MW1 1 //!< 520~1710Khz
44 #define AM_SW 2 //!< 2.3~21.85KHz
45 #define AM_M22 3 //!< 522~1710
46 
47 #define MODE_FM 0
48 #define MODE_AM 1
49 
50 #define DE_EMPHASIS_75 0
51 #define DE_EMPHASIS_50 1
52 
53 #define REG00 0x00
54 #define REG01 0x01
55 #define REG02 0x02
56 #define REG03 0x03
57 #define REG04 0x04
58 #define REG05 0x05
59 #define REG06 0x06
60 #define REG07 0x07
61 #define REG08 0x08
62 #define REG09 0x09
63 #define REG0A 0x0A
64 #define REG0B 0x0B
65 #define REG0C 0x0C
66 #define REG0D 0x0D
67 #define REG0E 0x0E
68 #define REG0F 0x0F
69 #define REG10 0x10
70 #define REG11 0x11
71 #define REG12 0x12
72 #define REG13 0x13
73 #define REG14 0x14
74 #define REG15 0x15
75 #define REG16 0x16
76 #define REG17 0x17
77 #define REG18 0x18
78 #define REG19 0x19
79 #define REG1A 0x1A
80 #define REG1B 0x1B
81 #define REG1C 0x1C
82 #define REG1D 0x1D
83 #define REG1E 0x1E
84 #define REG1F 0x1F
85 
86 /**
87  * @defgroup GA01 Union, Structure and Defined Data Types
88  * @brief BK108X Defined Data Types
89  * @details Defined Data Types is a way to represent the BK108X registers information
90  * @details Some information appears to be inaccurate due to translation problems from Chinese to English.
91  * @details The information shown here was extracted from Datasheet:
92  * @details BK108X stereo FM digital tuning radio documentation.
93  * @details Other information seems incomplete even in the original Chinese Datasheet.
94  * @details For example: Reg 10 (0x0A). There is no information about it. The Reg11 and 12 seem wrong
95  */
96 
97 /**
98  * @ingroup GA01
99  * @brief Device ID
100  *
101  */
102 typedef union
103 {
104  struct
105  {
106  uint8_t lowByte;
107  uint8_t highByte;
108  } refined;
110 } bk_reg00;
111 
112 /**
113  * @ingroup GA01
114  * @brief Chip ID
115  *
116  */
117 typedef union
118 {
119  struct
120  {
121  uint8_t lowByte;
122  uint8_t highByte;
123  } refined;
125 } bk_reg01;
126 
127 /**
128  * @ingroup GA01
129  * @brief Power Configuratio
130  * @see BEKEN - BK1086/88 - BROADCAST AM/FM/SW/LW RADIO RECEIVER; pages 13 and 14
131  */
132 typedef union
133 {
134  struct
135  {
136  uint8_t ENABLE : 1; //!< Powerup Enable;
137  uint8_t SNR_REF : 5; //!< Output SNR adjustment. Read SNR = SNR (calculated)
138  uint8_t DISABLE : 1; //!< Powerup Disable;
139  uint8_t SKAFCRL : 1; //!< Seek with AFC Rail; 0 = During seeking, the channel is valid no matter whether AFCRL is high or low; 1 = During seeking, the channel is invalid if AFCRL is high.
140  uint8_t SEEK : 1; //!< 0 = Disable (default); 1 = Enable;
141  uint8_t SEEKUP : 1; //!< Seek Direction; 0 = Seek down (default); 1 = Seek up.
142  uint8_t SKMODE : 1; //!< Seek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit.
143  uint8_t STEREO : 1; //!< Stereo; 0 = Normal operation; 1 = Force stereo; MONO and STEREO cannot be set to 1 simultaneously.
144  uint8_t MONO : 1; //!< Mono; 0 = Normal operation; 1 = Force mono.
145  uint8_t MUTER : 1; //!< Mute R channel; 0 = R channel normal operation; 1 = R channel mute.
146  uint8_t MUTEL : 1; //!< Mute L channel; 0 = L channel normal operation; 1 = L channel mute.
147  uint8_t DSMUTE : 1; //!< Softmute Disable; 0 = Softmute enable (default); 1 = Softmute disable.
148  } refined;
150 } bk_reg02;
151 
152 /**
153  * @ingroup GA01
154  * @brief Channe
155  * @details The tuned Frequency = Band + CHAN * SPACE
156  * @see BEKEN - BK1086/88 - BROADCAST AM/FM/SW/LW RADIO RECEIVER; page 14
157  */
158 typedef union
159 {
160  struct
161  {
162  uint16_t CHAN : 15; //!< Channel Select; The tuned Frequency = Band + CHAN * SPACE.
163  uint16_t TUNE : 1; //!< Tune. 0 = Disable (default); 1 = Enable.
164  } refined;
166 } bk_reg03;
167 
168 /**
169  * @ingroup GA01
170  * @brief Register 04h. System Configuration1 (0x1180)
171  * @details When register GPIO2[1:0]=2’b01 and seek or tune finish, a 5ms low pulse will appear at GPIO2 .Both RDSIEN and STCIEN can be high;
172  * @details When register GPIO2[1:0]=2’b01 and new RDS come, a 5ms low pulse will appear at GPIO2.
173  *
174  */
175 typedef union
176 {
177  struct
178  {
179  uint8_t DUMMY : 2; //!< Not used / RESERVED General Purpose I/O 1; 00 = High impedance (default); 01 = CLK38MHz; 10 = Low; 11 = High.
180  uint8_t GPIO2 : 2; //!< General Purpose I/O 2. 00 = High impedance (default); 01 = STC/RDS interrupt; 10 = Low; 11 = High.
181  uint8_t GPIO3 : 2; //!< General Purpose I/O 2. 00 = High impedance (default); 01 = Mono/Stereo indicator (ST); 10 = Low; 11 = High.
182  uint8_t PILOTS : 3; //!< Stereo/Mono Blend Level Adjustment. Sets the RSSI range for stereo/mono blend. See table above.
183  uint8_t TCPILOT : 2; //!< The Time Used to Cal The Strength of Pilot
184  uint8_t DE : 1; //!< De-emphasis; 0 = 75 μs. Used in USA (default); 1 = 50 μs. Used in Europe, Australia, Japan.
185  uint8_t RDSEN : 1; //!< RDS Enable; 0 = Disable (default); 1 = Enable.
186  uint8_t AFCINV : 1; //!< AFC Invert; 0 = Normal AFC into mixer; 1 = Reverse AFC into mixer.
187  uint8_t STCIEN : 1; //!< Seek/Tune Complete Interrupt Enable; 0 = Disable Interrupt (default); 1 = Enable Interrupt. See details above.
188  uint8_t RDSIEN : 1; //!< RDS Interrupt Enable; 0 = Disable Interrupt (default); 1 = Enable Interrupt. See details above.
189  } refined;
191 } bk_reg04;
192 
193 /**
194  * @ingroup GA01
195  * @brief Register 05h. System Configuration2 (0x3ddf)
196  * @details LW and SW Band are only defined at BK1088
197  *
198  * AM and Fm Band table ()
199  * | BAND value | AM band KHz | FM band MHz |
200  * | ---------- | ----------------| ----------------- |
201  * | 0 | 00: LW 153~279 | FULL 64~108 |
202  * | 1 | 10: MW 520~1710 | East Europe 64~76 |
203  * | 2 | 10: SW 2.3~21.85| Japan 76~91 |
204  * | 3 | 11: MW 522~1710 | Europe 87~108 |
205  *
206  *
207  * AM and FM Channel Space
208  * | BAND value | AM Space KHz | FM Space KHz |
209  * | ---------- | ------------- | ------------- |
210  * | 0 | 1 | 10 |
211  * | 1 | 5 | 50 |
212  * | 2 | 9 | 100 |
213  * | 3 | 10 | 200 |
214  *
215  * @see bk_reg07
216  */
217 typedef union
218 {
219  struct
220  {
221  uint8_t VOLUME : 5; //!< 0x00 is the lowest and 0x1F is highest (0dBFS). 2dB each
222  uint8_t SPACE : 2; //!< Channel Spacing; See AM and FM Channel Space table above.
223  uint8_t BAND : 2; //!< Band Select. See AM and Fm Band table above.
224  uint8_t SEEKTH : 7; //!< RSSI Seek Threshold. 0x00 = min RSSI (default); 0x7F = max RSSI.
225  } refined;
227 } bk_reg05;
228 
229 /**
230  * @ingroup GA01
231  * @brief Register 06h. System Configuration3 (0x01ef)
232  * @details SKCNT - Seek Impulse Detection Threshold Allowable number of impulse for a valid seek channel while setting all zeros means not use Impulse number to judge the channel’s validity.
233  *
234  *
235  * SMUTEA table
236  *
237  * | Softmute Attenuation | Description |
238  * | ---------------------- | --------------- |
239  * | 0 | 16 dB (default) |
240  * | 1 | 14 dB |
241  * | 2 | 12 dB |
242  * | 3 | 10 dB |
243  *
244  * SMUTER table
245  *
246  * | Softmute Attack/Recover Rate | Description |
247  * | ------------------------------ | ----------------- |
248  * | 0 | fastest (default) |
249  * | 1 | fast |
250  * | 2 | slow |
251  * | 3 | slowest |
252  *
253  */
254 typedef union
255 {
256  struct
257  {
258  uint8_t SKCNT : 4; //!< See details above.
259  uint8_t SKSNR : 7; //!< Seek SNR Threshold. Required channel SNR for a valid seek channel
260  uint8_t CLKSEL : 1; //!< Clock Select. 0 = External clock input; 1= Internal oscillator input.
261  uint8_t SMUTEA : 2; //!< Softmute Attenuation; See table above.
262  uint8_t SMUTER : 2; //!< Softmute Attack/Recover Rate; See table above
263  } refined;
265 } bk_reg06;
266 
267 /**
268  * @ingroup GA01
269  * @brief Register 07h. Test1 (0x0900)
270  */
271 typedef union
272 {
273  struct
274  {
275  uint8_t FMGAIN : 3; //!< The gain of Frequency demodulated; 000 = 0dB ... 011= +18dB; 100= 0dB ... 111= -18dB
276  uint8_t RESERVED :3;
277  uint8_t STHYS_SEL : 1; //!< ST/MONO Transition Hysterisis Select. 0 = 6dB; 1=2dB
278  uint8_t DACCK_SEL : 1; //!< DAC Clock Select
279  uint8_t IMPTH : 2; //!< Threshold of Impulse Detect. 00 = toughest; 11 = loosest
280  uint8_t BPDE : 1; //!< De-emphasis Bypass; 0 = Normal operation; 1 = Bypass de-emphasis.
281  uint8_t IMPEN : 1; //!< Impulse Remove Enable; 0 = Disable; 1 = Enable.
282  uint8_t SIQ : 1; //!< IF I/Q Signal switch; 0 = Normal operation; 1 = Reversed I/Q signal.
283  uint8_t MODE : 1; //!< 0 = FM receiver; 1 = AM receiver
284  uint8_t LINEIN_EN : 1; //!< Audio Line in Enable; 0 = Disable (Receiver Mode)
285  uint8_t LINEIN_SEL : 1; //!< Audio Line in Channel Select; 0 = Channel 1; 1=Channel 2 ((QFN24 only support one line in channel))
286  } refined;
288 } bk_reg07;
289 
290 /**
291  * @ingroup GA01
292  * @brief Test 2
293  * @details RSSI Threshold for Instant AFC updating; AFC Average Range; Variation Threshold for average AFC calculation;
294  * @details AFC Average; AFCRL Threshold; AFC/RSSI/SNR Calculate Rate; AFC Enable
295  *
296  */
297 typedef union
298 {
299  struct
300  {
301  uint8_t AFCRSSIT : 7; //!< RSSI Threshold for Instant AFC updating
302  uint8_t RANGE : 2; //!< AFC Average Range; 00 = the toughest; 11 = the loosest
303  uint8_t VAR : 2; //!< Variation Threshold for average AFC calculation; 00 = Disable; 01 = the toughest; 11 = the loosest
304  uint8_t AVE : 1; //!< AFC Average
305  uint8_t SEL25K : 1; //!< AFCRL Threshold; 0 = Channel space/2; 1 = 25kHz
306  uint8_t TCSEL : 2; //!< AFC/RSSI/SNR Calculate Rate; 00 = fastest; 11 = slowest. 4X times each
307  uint8_t AFCEN : 1; //!< AFC Enable; 0 = Disable; 1 = Enable.
308  } refined;
310 } bk_reg08;
311 
312 /**
313  * @ingroup GA01
314  * @brief Register 09h. Status1 (0x0000)
315  */
316 typedef union
317 {
318  struct
319  {
320  uint16_t SNR:7; //!< The AFC value.
321  uint16_t AFC:9; //!< unit AM 0.15k Hz, FM 0.6k Hz
322  } refined;
324 } bk_reg09;
325 
326 /**
327  * @ingroup GA01
328  * @brief Register 0Ah. Status2 (0x0000)
329  */
330 typedef union
331 {
332  struct
333  {
334  uint8_t RSSI : 7; //!< RSSI (Received Signal Strength Indicator).
335  uint8_t ST : 1; //!< Stereo Indicator; 0 = Mono; 1 = Stereo.
336  uint8_t STEN : 1; //!< Impulse Number
337  uint8_t DUMMY: 3;
338  uint8_t AFCRL : 1; //!< AFC Rail; 0 = AFC not railed; 1 = AFC railed.
339  uint8_t SF_BL : 1; //!< Seek Fail/Band Limit; 0 = Seek successful; 1 = Seek failure/Band limit reached.
340  uint8_t STC : 1; //!< Seek/Tune Complete; 0 = Not complete (default); 1 = Complete.
341  uint8_t RDSR : 1; //!< RDS Ready; 0 = No RDS group ready (default); 1 = New RDS group ready. Keep high for 40ms after new RDS is received
342  } refined;
344 } bk_reg0a;
345 
346 /**
347  * @ingroup GA01
348  * @brief Register 0Bh. Read Channel (0x0000)
349  */
350 typedef union
351 {
352  struct
353  {
354  uint16_t READCHAN : 14; //!< Read Channel. Provides the current working channel
355  uint16_t RESERVED : 2;
356  } refined;
358 } bk_reg0b;
359 
360 /**
361  * @ingroup GA01
362  * @brief Register 0Ch. RDS1 (0x0000)
363  * @details RDS Block A - The First Register of RDS Received
364  */
365 typedef union
366 {
367  struct
368  {
369  uint8_t lowByte;
370  uint8_t highByte;
371  } refined;
373 } bk_reg0c;
374 
375 /**
376  * @ingroup GA01
377  * @brief Register 0Dh. RDS2 (0x0000)
378  * @details RDS Block B - The second register of RDS received
379  */
380 typedef union
381 {
382  struct
383  {
384  uint8_t lowByte;
385  uint8_t highByte;
386  } refined;
388 } bk_reg0d;
389 
390 /**
391  * @ingroup GA01
392  * @brief Register 0Eh. RDS2 (0x0000)
393  * @details RDS Block C - The third register of RDS received
394  */
395 typedef union
396 {
397  struct
398  {
399  uint8_t lowByte;
400  uint8_t highByte;
401  } refined;
403 } bk_reg0e;
404 
405 /**
406  * @ingroup GA01
407  * @brief Register 0Fh. RDS4 (0x0000)
408  * @details RDS Block D - The fourth register of RDS received when read
409  */
410 typedef union
411 {
412  struct
413  {
414  uint8_t lowByte;
415  uint8_t highByte;
416  } refined;
418 } bk_reg0f;
419 
420 /**
421  * @ingroup GA01
422  * @brief Register 10h. Boot Configuration1 (0x7b11)
423  */
424 typedef union
425 {
426  struct
427  {
428  uint8_t lowByte;
429  uint8_t highByte;
430  } refined;
432 } bk_reg10;
433 
434 /**
435  * @ingroup GA01
436  * @brief Register 11h. Boot Configuration2 (0x0080)
437  */
438 typedef union
439 {
440  struct
441  {
442  uint8_t lowByte;
443  uint8_t highByte;
444  } refined;
446 } bk_reg11;
447 
448 /**
449  * @ingroup GA01
450  * @brief Register 12h. Boot Configuration3 (0x4000)
451  */
452 typedef union
453 {
454  struct
455  {
456  uint8_t lowByte;
457  uint8_t highByte;
458  } refined;
460 } bk_reg12;
461 
462 /**
463  * @ingroup GA01
464  * @brief Register 13h. Boot Configuration4 (0x3e00)
465  */
466 typedef union
467 {
468  struct
469  {
470  uint8_t lowByte;
471  uint8_t highByte;
472  } refined;
474 } bk_reg13;
475 
476 /**
477  * @ingroup GA01
478  * @brief Register 14h. Boot Configuration5 (0x0000)
479  */
480 typedef union
481 {
482  struct
483  {
484  uint8_t RSSIMTH : 7; //!< The Mute Threshold Based on RSSI
485  uint8_t SNRMTH : 7; //!< The Mute Threshold Based on SNR
486  uint8_t AFCMUTE : 1; //!< 0: disable soft mute when AFCRL is high; 1: enable soft mute when AFCRL is high
487  uint8_t SKMUTE : 1; //!< 0: disable soft mute when seeking; 1: enable soft mute when seeking
488  } refined;
490 } bk_reg14;
491 
492 /**
493  * @ingroup GA01
494  * @brief 15h. Boot Configuration6 (0x0000)
495  */
496 typedef union
497 {
498  struct
499  {
500  uint8_t lowByte;
501  uint8_t highByte;
502  } refined;
504 } bk_reg15;
505 
506 /**
507  * @ingroup GA01
508  * @brief Register 16h. Boot Configuration7 (0x0400)
509  */
510 typedef union
511 {
512  struct
513  {
514  uint8_t lowByte;
515  uint8_t highByte;
516  } refined;
518 } bk_reg16;
519 
520 /**
521  * @ingroup GA01
522  * @brief Register 17h. Boot Configuration8 (0x0001)
523  */
524 typedef union
525 {
526  struct
527  {
528  uint8_t lowByte;
529  uint8_t highByte;
530  } refined;
532 } bk_reg17;
533 
534 /**
535  * @ingroup GA01
536  * @brief Register 18h. Boot Configuration9 (0x143c)
537  */
538 typedef union
539 {
540  struct
541  {
542  uint8_t lowByte;
543  uint8_t highByte;
544  } refined;
546 } bk_reg18;
547 
548 /**
549  * @ingroup GA01
550  * @brief Register 19h. Boot Configuration10 (0x4351)
551  */
552 typedef union
553 {
554  struct
555  {
556  uint8_t lowByte;
557  uint8_t highByte;
558  } refined;
560 } bk_reg19;
561 
562 /**
563  * @ingroup GA01
564  * @brief Register 1Ah. Boot Configuration11 (0x0000)
565  */
566 typedef union
567 {
568  struct
569  {
570  uint16_t RESERVED1 : 3;
571  uint16_t ANT_SEL : 5; //!< Antenna varactor tune
572  uint16_t RESERVED2 : 4;
573  } refined;
575 } bk_reg1A;
576 
577 /**
578  * @ingroup GA01
579  * @brief Register 1Bh. Analog Configuration1 (0x0000)
580  */
581 typedef union
582 {
583  struct {
584  uint16_t RESERVED;
585  } refined;
587 } bk_reg1B;
588 
589 /**
590  * @ingroup GA01
591  * @brief Register 1Ch. Analog Configuration2 (0x0000)
592  */
593 typedef union
594 {
595  struct
596  {
597  uint16_t RESERVED : 15;
598  uint16_t FREQ_SEL : 1; //!< Reference clock divider control ,Refer to Reg1D Default 0 for 32.768kHz reference input.
599  } refined;
601 } bk_reg1C;
602 
603 /**
604  * @ingroup GA01
605  * @brief Register 1Dh. Analog Configuration2 (0x0000)
606  */
607 typedef union
608 {
609  struct {
610  uint16_t FREQ_SEL;
611  } refined;
612  uint16_t raw; //!< //!< Reference clock divider control , FREQ_SEL[17:0] = HEX | Ref Frequency/512+0.5 | Default 16 for 32.768kHz reference.
613 } bk_reg1D;
614 
615 /**
616  * @brief The user does not have access to registsres 0x1E, 0x1F and 0x20.
617  * @details They are Internal test registers and can be provided separately by BEKEN.
618  * @details The author of this library did not have access to these register.
619  */
620 typedef uint16_t bk_reg1E; // Internal register
621 typedef uint16_t bk_reg1F; // Internal Register
622 typedef uint16_t bk_reg20; // Internal Register
623 
624 
625 /**
626  * @ingroup GA01
627  * @brief RDS Block B data type
628  *
629  * @details For GCC on System-V ABI on 386-compatible (32-bit processors), the following stands:
630  *
631  * 1) Bit-fields are allocated from right to left (least to most significant).
632  * 2) A bit-field must entirely reside in a storage unit appropriate for its declared type.
633  * Thus a bit-field never crosses its unit boundary.
634  * 3) Bit-fields may share a storage unit with other struct/union members, including members that are not bit-fields.
635  * Of course, struct members occupy different parts of the storage unit.
636  * 4) Unnamed bit-fields' types do not affect the alignment of a structure or union, although individual
637  * bit-fields' member offsets obey the alignment constraints.
638  *
639  * @see also https://en.wikipedia.org/wiki/Radio_Data_System
640  */
641 typedef union
642 {
643  struct
644  {
645  uint8_t address : 2; // Depends on Group Type and Version codes. If 0A or 0B it is the Text Segment Address.
646  uint8_t DI : 1; // Decoder Controll bit
647  uint8_t MS : 1; // Music/Speech
648  uint8_t TA : 1; // Traffic Announcement
649  uint8_t programType : 5; // PTY (Program Type) code
650  uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
651  uint8_t versionCode : 1; // (B0) => 0=A; 1=B
652  uint8_t groupType : 4; // Group Type code.
653  } group0;
654  struct
655  {
656  uint8_t address : 4; // Depends on Group Type and Version codes. If 2A or 2B it is the Text Segment Address.
657  uint8_t textABFlag : 1; // Do something if it chanhes from binary "0" to binary "1" or vice-versa
658  uint8_t programType : 5; // PTY (Program Type) code
659  uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
660  uint8_t versionCode : 1; // (B0) => 0=A; 1=B
661  uint8_t groupType : 4; // Group Type code.
662  } group2;
663  struct
664  {
665  uint8_t content : 4; // Depends on Group Type and Version codes.
666  uint8_t textABFlag : 1; // Do something if it chanhes from binary "0" to binary "1" or vice-versa
667  uint8_t programType : 5; // PTY (Program Type) code
668  uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
669  uint8_t versionCode : 1; // (B0) => 0=A; 1=B
670  uint8_t groupType : 4; // Group Type code.
671  } refined;
672  bk_reg0d blockB;
673 } bk_rds_blockb;
674 
675 /**
676  * @ingroup GA01
677  * Group RDS type 4A ( RDS Date and Time)
678  * When group type 4A is used by the station, it shall be transmitted every minute according to EN 50067.
679  * This Structure uses blocks 2,3 and 5 (B,C,D)
680  *
681  * ATTENTION:
682  * To make it compatible with 8, 16 and 32 bits platforms and avoid Crosses boundary, it was necessary to
683  * split minute and hour representation.
684  */
685 typedef union
686 {
687  struct
688  {
689  uint8_t offset : 5; // Local Time Offset
690  uint8_t offset_sense : 1; // Local Offset Sign ( 0 = + , 1 = - )
691  uint8_t minute1 : 2; // UTC Minutes - 2 bits less significant (void “Crosses boundary”).
692  uint8_t minute2 : 4; // UTC Minutes - 4 bits more significant (void “Crosses boundary”)
693  uint8_t hour1 : 4; // UTC Hours - 4 bits less significant (void “Crosses boundary”)
694  uint8_t hour2 : 1; // UTC Hours - 4 bits more significant (void “Crosses boundary”)
695  uint32_t mjd : 17; // Modified Julian Day Code
696  } refined;
698 } bk_rds_date_time;
699 
700 /**
701  * @ingroup GA01
702  * @brief Converts 16 bits word to two bytes
703  */
704 typedef union
705 {
706  struct
707  {
708  uint8_t lowByte;
709  uint8_t highByte;
710  } refined;
712 } word16_to_bytes;
713 
714 
715 
716 /**
717  * @ingroup GA01
718  * @brief KT0915 Class
719  * @details This class implements all functions that will help you to control the KT0915 devices.
720  *
721  * @author PU2CLR - Ricardo Lima Caratti
722  */
723 class BK108X
724 {
725 
726 private:
727 
728  uint8_t i2cBuffer[32];
729 
730  uint16_t shadowRegisters[32]; //!< shadow registers 0x00 to 0x1F (0 - 31)
731 
732  // Device registers map - References to the shadow registers
733  bk_reg00 *reg00 = (bk_reg00 *)&shadowRegisters[REG00]; // 0
734  bk_reg01 *reg01 = (bk_reg01 *)&shadowRegisters[REG01]; // 1
735  bk_reg02 *reg02 = (bk_reg02 *)&shadowRegisters[REG02]; // 2
736  bk_reg03 *reg03 = (bk_reg03 *)&shadowRegisters[REG03]; // 3
737  bk_reg04 *reg04 = (bk_reg04 *)&shadowRegisters[REG04]; // 4
738  bk_reg05 *reg05 = (bk_reg05 *)&shadowRegisters[REG05]; // 5
739  bk_reg06 *reg06 = (bk_reg06 *)&shadowRegisters[REG06]; // 6
740  bk_reg07 *reg07 = (bk_reg07 *)&shadowRegisters[REG07]; // 7
741  bk_reg08 *reg08 = (bk_reg08 *)&shadowRegisters[REG08]; // 8
742  bk_reg09 *reg09 = (bk_reg09 *)&shadowRegisters[REG09]; // 9
743  bk_reg0a *reg0a = (bk_reg0a *)&shadowRegisters[REG0A]; // 10
744  bk_reg0b *reg0b = (bk_reg0b *)&shadowRegisters[REG0B]; // 11
745  bk_reg0c *reg0c = (bk_reg0c *)&shadowRegisters[REG0C]; // 12
746  bk_reg0d *reg0d = (bk_reg0d *)&shadowRegisters[REG0D]; // 13
747  bk_reg0e *reg0e = (bk_reg0e *)&shadowRegisters[REG0E]; // 14
748  bk_reg0f *reg0f = (bk_reg0f *)&shadowRegisters[REG0F]; // 15
749  bk_reg10 *reg10 = (bk_reg10 *)&shadowRegisters[REG10]; // 16
750  bk_reg11 *reg11 = (bk_reg11 *)&shadowRegisters[REG11]; // 17
751  bk_reg12 *reg12 = (bk_reg12 *)&shadowRegisters[REG12]; // 18
752  bk_reg13 *reg13 = (bk_reg13 *)&shadowRegisters[REG13]; // 19
753  bk_reg14 *reg14 = (bk_reg14 *)&shadowRegisters[REG14]; // 20
754  bk_reg15 *reg15 = (bk_reg15 *)&shadowRegisters[REG15]; // 21
755  bk_reg16 *reg16 = (bk_reg16 *)&shadowRegisters[REG16]; // 22
756  bk_reg17 *reg17 = (bk_reg17 *)&shadowRegisters[REG17]; // 23
757  bk_reg18 *reg18 = (bk_reg18 *)&shadowRegisters[REG18]; // 24
758  bk_reg19 *reg19 = (bk_reg19 *)&shadowRegisters[REG19]; // 25
759  bk_reg1A *reg1A = (bk_reg1A *)&shadowRegisters[REG1A]; // 26
760  bk_reg1B *reg1b = (bk_reg1B *)&shadowRegisters[REG1B]; // 27
761  bk_reg1C *reg1c = (bk_reg1C *)&shadowRegisters[REG1C]; // 28
762  bk_reg1D *reg1d = (bk_reg1D *)&shadowRegisters[REG1D]; // 29
763  bk_reg1E *reg1e = (bk_reg1E *)&shadowRegisters[REG1E]; // 30
764  bk_reg1F *reg1f = (bk_reg1F *)&shadowRegisters[REG1F]; // 31
765 
766  uint16_t fmStartBand[4] = {6400, 7400, 7600, 8700}; //!< Start FM band limit
767  uint16_t fmEndBand[4] = {10800, 7600, 9100, 10800}; //!< End FM band limit
768  uint16_t fmSpace[4] = {1, 5, 10, 20}; //!< FM channel space
769 
770  uint16_t amStartBand[4] = {153, 520, 2300, 522}; //!< Start FM band limit
771  uint16_t amEndBand[4] = {279, 1710, 21850, 1710}; //!< End FM band limit
772  uint16_t amSpace[4] = {1, 5, 9, 10}; //!< AM channel space
773 
774  int pin_sdio, pin_sclk;
775 
776 protected:
777  char rds_buffer2A[65]; //!< RDS Radio Text buffer - Program Information
778  char rds_buffer2B[33]; //!< RDS Radio Text buffer - Station Informaation
779  char rds_buffer0A[9]; //!< RDS Basic tuning and switching information (Type 0 groups)
780  char rds_time[20]; //!< RDS date time received information
781 
783 
787 
795 
797  int rdsInterruptPin = -1;
801 
802 
803 public:
804  void setI2C(uint8_t i2c_addr = I2C_DEVICE_ADDR);
805  void i2cInit(int pin_sdio, int pin_sclk);
806  void i2cBeginTransaction();
807  void i2cEndTransaction();
808  void i2cAck();
809  void i2cNack();
811  void i2cWriteByte(uint8_t data);
813  void writeRegister(uint8_t reg,uint16_t vakue);
815 
816  void reset();
817  void powerUp();
818  void powerDown();
819  void waitAndFinishTune();
820 
821 
822 
823  /**
824  * @ingroup GA03
825  * @brief Sets the I2C bus address
826  * @details This function must to be called before setup function if your device are not using 0x10 (default)
827  * @param bus_addr I2C buss address
828  */
829  inline void setI2CAddress(int bus_addr) { this->deviceAddress = bus_addr; };
830 
831  /**
832  * @ingroup GA03
833  * @brief Set the Delay After Crystal On (default 500ms)
834  *
835  * @param ms_value Value in milliseconds
836  */
837  inline void setDelayAfterCrystalOn(uint8_t ms_value) { maxDelayAftarCrystalOn = ms_value; };
838 
840  void setRegister(uint8_t reg, uint16_t value);
841  bk_reg0a getStatus();
842 
843  /**
844  * @ingroup GA03
845  * @brief Get the Shadown Register object
846  * @details if you want to get the current value of the device register, call getAllRegisters() before calling this function.
847  * @details if you are dealing with the status register (0x0A), you can call getStatus() instead getAllRegisters().
848  * @see setAllRegisters, getAllRegisters, getShadownRegister, getStatus
849  * @param register_number
850  * @return 16 bits word with the Shadown registert
851  */
852  inline uint16_t getShadownRegister(uint8_t register_number) { return shadowRegisters[register_number]; };
853 
854  /**
855  * @ingroup GA03
856  * @brief Sets a given value to the Shadown Register
857  * @details You have to call setAllRegisters() after setting the Shadow Registers to store the value into the device.
858  * @see setAllRegisters, getAllRegisters, getShadownRegister, getStatus
859  * @param register_number register index (from 0x00 to 0x0F)
860  * @param value 16 bits word with the content of the register
861  */
862  void setShadownRegister(uint8_t register_number, uint16_t value)
863  {
864  if (register_number > 0x0F)
865  return;
866  shadowRegisters[register_number] = value;
867  };
868 
871 
872  void setup(int sda_pin, int sclk_pin, int rdsInterruptPin = -1, int seekInterruptPin = -1, uint8_t oscillator_type = OSCILLATOR_TYPE_CRYSTAL);
873 
874  void setFM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step);
875  void setAM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step, uint16_t am_space = 0);
876 
877  /**
878  * @ingroup GA03
879  * @brief Get the Current Mode (AM or FM)
880  *
881  * @return uint8_t 0 = FM; 1 = AM
882  */
883  inline uint8_t getCurrentMode() { return this->currentMode; };
884 
885  /**
886  * @ingroup GA03
887  * @brief Sets the Stereo Threshold of Pilotto Strength
888  *
889  * @param value 0 ~ 7
890  */
891  inline void setStereoThresholdPilotStrength(uint8_t value) {
892  reg04->refined.PILOTS = value;
893  setRegister(REG04,reg04->raw);
894  }
895 
896  /**
897  * @ingroup GA03
898  * @brief Sets De-emphasis.
899  * @details 75 μs. Used in USA (default); 50 μs. Used in Europe, Australia, Japan.
900  *
901  * @param de 0 = 75 μs; 1 = 50 μs
902  */
903  inline void setFmDeemphasis(uint8_t de)
904  {
905  reg04->refined.DE = de;
906  setRegister(REG04, reg04->raw);
907  }
908 
909  /**
910  * @ingroup GA03
911  * @brief Sets the time used to call the strength of pilot
912  *
913  * @param value 0 ~ 3
914  */
915  inline void setTimeCallStrengthPilot(uint8_t value)
916  {
917  reg04->refined.TCPILOT = value;
918  setRegister(REG04, reg04->raw);
919  }
920 
921  /**
922  * @brief Sets the Gpio2
923  * @details the General Purpose I/O 2. You can use this pin according to the table below.
924  *
925  * | value | description |
926  * | ----- | ----------- |
927  * | 0 | Low |
928  * | 1 | STC/RDS interrupt |
929  * | 2 | Low |
930  * | 3 | High |
931  *
932  * @param value See table above
933  */
934  inline void setGpio2( uint8_t value) {
935  reg04->refined.GPIO2 = value;
936  setRegister(REG04,reg04->raw);
937  }
938 
939  /**
940  * @brief Sets the Gpio3
941  * @details the General Purpose I/O 3. You can use this pin according to the table below.
942  *
943  * | value | description |
944  * | ----- | ----------- |
945  * | 0 | Low |
946  * | 1 | Mono/Stereo Indicator |
947  * | 2 | Low |
948  * | 3 | High |
949  *
950  * @param value See table above
951  */
952  inline void setGpio3(uint8_t value)
953  {
954  reg04->refined.GPIO3 = value;
955  setRegister(REG04, reg04->raw);
956  }
957 
958  /**
959  * @brief Enables or Disables AFC
960  *
961  * @param value if True, it enables AFC
962  */
963  inline void setAfc(bool value)
964  {
965  reg08->refined.AFCEN;
966  setRegister(REG08, reg08->raw);
967  }
968 
969  /**
970  * @brief Sets AFC/RSSI/SNR Calculate Rate
971  * @details 00 = fastest; 11 = slowest. 4X times each
972  * @param value 0˜3
973  */
974  inline void setAfcRssiSnrCalculateRate(uint8_t value)
975  {
976  reg08->refined.TCSEL;
977  setRegister(REG08, reg08->raw);
978  }
979 
980  /**
981  * @brief Sets AFCRL Threshold
982  * @details 0 = Channel space/2; 1 = 25kHz
983  * @param value 0=Channel space/2; 1 = 25kHz
984  */
985  inline void setAfcThreshold(uint8_t value)
986  {
987  reg08->refined.SEL25K;
988  setRegister(REG08, reg08->raw);
989  }
990 
991  /**
992  * @brief Sets AFC Average
993  * @details 0 = Use the instant AFC value; 1 = Use the average AFC value
994  * @param value 0 or 1
995  */
996  inline void setAfcAve(uint8_t value)
997  {
998  reg08->refined.AVE;
999  setRegister(REG08, reg08->raw);
1000  }
1001 
1002  /**
1003  * @brief Sets Variation Threshold for average AFC calculation
1004  * @details 0 = Disable; 1 = the most strict; 2= ?; 3 = the loosest
1005  * @param value 0, 1, 2 or 3
1006  */
1007  inline void setAfcVar(uint8_t value)
1008  {
1009  reg08->refined.VAR;
1010  setRegister(REG08, reg08->raw);
1011  }
1012 
1013  /**
1014  * @brief Sets AFC range
1015  * @details 0 = he most strict; 3 = the loosest
1016  * @param value 0,1,2 or 3
1017  */
1018  inline void setAfcRange(uint8_t value)
1019  {
1020  reg08->refined.RANGE;
1021  setRegister(REG08, reg08->raw);
1022  }
1023 
1024  /**
1025  * @brief Sets RSSI Threshold for Instant AFC updating
1026  * @details default value is 16 (0x10)
1027  * @param value
1028  */
1029  inline void setAfcRssiThreshold(uint8_t value)
1030  {
1031  reg08->refined.AFCRSSIT;
1032  setRegister(REG08, reg08->raw);
1033  }
1034 
1035 
1036 
1037  void setFrequency(uint16_t frequency);
1038  void setFrequencyUp();
1039  void setFrequencyDown();
1041  uint16_t getChannel();
1044  void setChannel(uint16_t channel);
1045  void seekHardware(uint8_t seek_mode, uint8_t direction);
1046  void seekSoftware(uint8_t seek_mode, uint8_t direction, void (*showFunc)() = NULL);
1047  void setSeekThreshold(uint8_t rssiValue, uint8_t snrValue);
1048 
1049  void setBand(uint8_t band = 1);
1050  void setSpace(uint8_t space = 0);
1051  int getRssi();
1052  int getSnr();
1053 
1054  void setSoftmute(bool value);
1055  void setSoftmuteAttack(uint8_t value);
1056  void setSoftmuteAttenuation(uint8_t value);
1057  void setMuteThreshold(uint8_t rssi, uint8_t snr);
1058  void setSeekMute(bool value);
1059  void setAfcMute(bool value);
1060  void setAgc(bool value);
1061 
1062  void setMono(bool value);
1063 
1064  bool isStereo();
1065 
1066  void setAudioMute(bool left, bool right);
1067  void setAudioMute(bool value);
1068  void setVolume(uint8_t value);
1069  uint8_t getVolume();
1070  void setVolumeUp();
1071  void setVolumeDown();
1072 
1073  void getRdsStatus();
1074  void setRdsMode(uint8_t rds_mode = 0);
1075  void setRds(bool value);
1076  inline void setRDS(bool value) { setRds(value); };
1077  bool getRdsReady();
1078 
1079  uint8_t getRdsFlagAB(void);
1080  uint8_t getRdsVersionCode(void);
1082  uint8_t getRdsProgramType(void);
1083  void getNext2Block(char *c);
1084  void getNext4Block(char *c);
1085  char *getRdsText(void);
1086  char *getRdsText0A(void);
1087  char *getRdsText2A(void);
1088  char *getRdsText2B(void);
1089  char *getRdsTime();
1090  bool getRdsSync();
1091 };
REG08
#define REG08
Definition: BK108X.h:61
BK108X::getRdsText
char * getRdsText(void)
Gets the RDS Text when the message is of the Group Type 2 version A.
Definition: BK108X.cpp:1181
REG14
#define REG14
Definition: BK108X.h:73
BK108X::rds_buffer0A
char rds_buffer0A[9]
RDS Basic tuning and switching information (Type 0 groups)
Definition: BK108X.h:779
BK108X::setFM
void setFM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step)
Sets the receiver to FM mode.
Definition: BK108X.cpp:467
bk_reg0a::raw
uint16_t raw
Definition: BK108X.h:343
REG18
#define REG18
Definition: BK108X.h:77
bk_reg11::raw
uint16_t raw
Definition: BK108X.h:445
bk_reg16::raw
uint16_t raw
Definition: BK108X.h:517
BK108X::i2cInit
void i2cInit(int pin_sdio, int pin_sclk)
Sets the MCU pins connected to the I2C bus.
Definition: BK108X.cpp:54
bk_reg1C::raw
uint16_t raw
Definition: BK108X.h:600
bk_reg10::raw
uint16_t raw
Definition: BK108X.h:431
BK108X::readRegister
uint16_t readRegister(uint8_t reg)
Gets an array of values from a BK108X given register.
Definition: BK108X.cpp:235
BK108X::setBand
void setBand(uint8_t band=1)
Sets the current band for AM or FM
Definition: BK108X.cpp:780
bk_reg1E
uint16_t bk_reg1E
The user does not have access to registsres 0x1E, 0x1F and 0x20.
Definition: BK108X.h:620
BK108X::isStereo
bool isStereo()
Checks stereo / mono status.
Definition: BK108X.cpp:986
BK108X::getChannel
uint16_t getChannel()
Gets the current channel.
Definition: BK108X.cpp:607
BK108X::setAfcThreshold
void setAfcThreshold(uint8_t value)
Sets AFCRL Threshold.
Definition: BK108X.h:985
BK108X::getRdsTime
char * getRdsTime()
Gets the RDS time and date when the Group type is 4.
Definition: BK108X.cpp:1226
BK108X::getRdsText2A
char * getRdsText2A(void)
Gets the Text processed for the 2A group.
Definition: BK108X.cpp:1206
BK108X::i2cReceiveAck
uint8_t i2cReceiveAck()
Gets Acknowledge (ACK)
Definition: BK108X.cpp:136
bk_reg0c::raw
uint16_t raw
Definition: BK108X.h:372
BK108X::setI2CAddress
void setI2CAddress(int bus_addr)
Sets the I2C bus address.
Definition: BK108X.h:829
bk_reg08::raw
uint16_t raw
Definition: BK108X.h:309
BK108X::currentMode
uint8_t currentMode
Definition: BK108X.h:794
BK108X::i2cAck
void i2cAck()
Sends Acknowledge (ACK)
Definition: BK108X.cpp:102
BK108X::currentVolume
uint8_t currentVolume
Definition: BK108X.h:796
BK108X::setAudioMute
void setAudioMute(bool value)
Sets the Mute true or false.
Definition: BK108X.cpp:961
REG03
#define REG03
Definition: BK108X.h:56
BK108X::setRDS
void setRDS(bool value)
Definition: BK108X.h:1076
BK108X::getDeviceId
uint16_t getDeviceId()
Returns the Device Indentifiction.
Definition: BK108X.cpp:302
bk_reg02::raw
uint16_t raw
Definition: BK108X.h:149
BK108X::getSnr
int getSnr()
Gets the current SNR.
Definition: BK108X.cpp:834
word16_to_bytes::raw
uint16_t raw
Definition: BK108X.h:711
BK108X::i2cBeginTransaction
void i2cBeginTransaction()
Starts the I2C bus transaction
Definition: BK108X.cpp:63
BK108X::oscillatorType
int oscillatorType
Definition: BK108X.h:799
bk_reg19::raw
uint16_t raw
Definition: BK108X.h:559
BK108X::powerDown
void powerDown()
Powers the receiver off.
Definition: BK108X.cpp:424
REG15
#define REG15
Definition: BK108X.h:74
bk_reg03::raw
uint16_t raw
Definition: BK108X.h:165
BK108X::getNext4Block
void getNext4Block(char *c)
Process data received from group 2A.
Definition: BK108X.cpp:1170
BK108X::setAfc
void setAfc(bool value)
Enables or Disables AFC.
Definition: BK108X.h:963
BK108X::setGpio2
void setGpio2(uint8_t value)
Sets the Gpio2.
Definition: BK108X.h:934
BK108X::seekHardware
void seekHardware(uint8_t seek_mode, uint8_t direction)
Seeks a station via hardware functionality.
Definition: BK108X.cpp:718
REG04
#define REG04
Definition: BK108X.h:57
BK108X::getRealFrequency
uint16_t getRealFrequency()
Gets the frequency based on READCHAN register (0x0B)
Definition: BK108X.cpp:631
bk_reg20
uint16_t bk_reg20
Definition: BK108X.h:622
REG1B
#define REG1B
Definition: BK108X.h:80
bk_reg0d::raw
uint16_t raw
Definition: BK108X.h:387
BK108X::rdsInterruptPin
int rdsInterruptPin
Definition: BK108X.h:797
BK108X::setFrequency
void setFrequency(uint16_t frequency)
Sets the FM frequency.
Definition: BK108X.cpp:548
BK108X::setDelayAfterCrystalOn
void setDelayAfterCrystalOn(uint8_t ms_value)
Set the Delay After Crystal On (default 500ms)
Definition: BK108X.h:837
bk_reg1A::raw
uint16_t raw
Definition: BK108X.h:574
REG10
#define REG10
Definition: BK108X.h:69
BK108X::setShadownRegister
void setShadownRegister(uint8_t register_number, uint16_t value)
Sets a given value to the Shadown Register.
Definition: BK108X.h:862
BK108X::getRssi
int getRssi()
Gets the current Rssi.
Definition: BK108X.cpp:822
REG0F
#define REG0F
Definition: BK108X.h:68
REG1F
#define REG1F
Definition: BK108X.h:84
BK108X::currentFrequency
uint32_t currentFrequency
Definition: BK108X.h:784
BK108X::rds_buffer2A
char rds_buffer2A[65]
RDS Radio Text buffer - Program Information.
Definition: BK108X.h:777
REG13
#define REG13
Definition: BK108X.h:72
BK108X::seekInterruptPin
int seekInterruptPin
Definition: BK108X.h:798
BK108X::getRdsVersionCode
uint8_t getRdsVersionCode(void)
Gets the version code (extracted from the Block B)
Definition: BK108X.cpp:1136
bk_reg0e::raw
uint16_t raw
Definition: BK108X.h:402
BK108X::setSeekThreshold
void setSeekThreshold(uint8_t rssiValue, uint8_t snrValue)
Sets RSSI and SNR Seek Threshold.
Definition: BK108X.cpp:755
bk_reg15::raw
uint16_t raw
Definition: BK108X.h:503
BK108X::getRdsText0A
char * getRdsText0A(void)
Gets the station name and other messages.
Definition: BK108X.cpp:1194
BK108X::i2cReadByte
uint8_t i2cReadByte()
Gets a Byte from the slave device.
Definition: BK108X.cpp:180
BK108X::setSpace
void setSpace(uint8_t space=0)
Sets the Space channel for AM or FM.
Definition: BK108X.cpp:805
BK108X::getRealChannel
uint16_t getRealChannel()
Gets the current channel stored in register 0x0B.
Definition: BK108X.cpp:618
BK108X::getRdsSync
bool getRdsSync()
Get the Rds Sync.
Definition: BK108X.cpp:1237
BK108X::currentChannel
uint16_t currentChannel
Definition: BK108X.h:788
BK108X::setSoftmuteAttenuation
void setSoftmuteAttenuation(uint8_t value)
Sets Softmute Attenuation.
Definition: BK108X.cpp:886
BK108X::getChipId
uint16_t getChipId()
Returns the Chip Indentifiction.
Definition: BK108X.cpp:312
bk_reg05::raw
uint16_t raw
Definition: BK108X.h:226
BK108X::getRegister
uint16_t getRegister(uint8_t reg)
Gets a givens current register content of the device.
Definition: BK108X.cpp:271
BK108X::setGpio3
void setGpio3(uint8_t value)
Sets the Gpio3.
Definition: BK108X.h:952
BK108X::setChannel
void setChannel(uint16_t channel)
Sets the channel.
Definition: BK108X.cpp:527
REG0C
#define REG0C
Definition: BK108X.h:65
BK108X::setMuteThreshold
void setMuteThreshold(uint8_t rssi, uint8_t snr)
Set the Mute Threshold based on RSSI and SNR.
Definition: BK108X.cpp:900
BK108X::setAfcMute
void setAfcMute(bool value)
Disable or Enable soft mute when AFCRL is high.
Definition: BK108X.cpp:924
BK108X::setAfcAve
void setAfcAve(uint8_t value)
Sets AFC Average.
Definition: BK108X.h:996
REG17
#define REG17
Definition: BK108X.h:76
BK108X::minimumFrequency
uint32_t minimumFrequency
Definition: BK108X.h:785
OSCILLATOR_TYPE_CRYSTAL
#define OSCILLATOR_TYPE_CRYSTAL
Definition: BK108X.h:27
BK108X::writeRegister
void writeRegister(uint8_t reg, uint16_t vakue)
Sends an array of values to a BK108X given register.
Definition: BK108X.cpp:207
REG19
#define REG19
Definition: BK108X.h:78
BK108X::setAudioMute
void setAudioMute(bool left, bool right)
Sets the Mute true or false.
Definition: BK108X.cpp:948
BK108X::setVolumeDown
void setVolumeDown()
Decrements the audio volume.
Definition: BK108X.cpp:1038
BK108X::seekSoftware
void seekSoftware(uint8_t seek_mode, uint8_t direction, void(*showFunc)()=NULL)
Seeks a station via Software.
Definition: BK108X.cpp:676
BK108X::waitAndFinishTune
void waitAndFinishTune()
Wait STC (Seek/Tune Complete) status becomes 0.
Definition: BK108X.cpp:351
BK108X::setAfcRange
void setAfcRange(uint8_t value)
Sets AFC range.
Definition: BK108X.h:1018
BK108X::currentFMBand
uint8_t currentFMBand
Definition: BK108X.h:790
BK108X::getNext2Block
void getNext2Block(char *c)
Process data received from group 2B.
Definition: BK108X.cpp:1158
BK108X::setSoftmute
void setSoftmute(bool value)
Sets the Softmute true or false.
Definition: BK108X.cpp:846
BK108X::setTimeCallStrengthPilot
void setTimeCallStrengthPilot(uint8_t value)
Sets the time used to call the strength of pilot.
Definition: BK108X.h:915
bk_reg09::raw
uint16_t raw
Definition: BK108X.h:323
bk_reg1D::raw
uint16_t raw
//!< Reference clock divider control , FREQ_SEL[17:0] = HEX | Ref Frequency/512+0....
Definition: BK108X.h:612
bk_reg13::raw
uint16_t raw
Definition: BK108X.h:473
bk_reg06::raw
uint16_t raw
Definition: BK108X.h:264
BK108X::currentFMSpace
uint8_t currentFMSpace
Definition: BK108X.h:792
BK108X::deviceAddress
int deviceAddress
Definition: BK108X.h:782
BK108X::getRdsStatus
void getRdsStatus()
Gets the RDS registers information.
Definition: BK108X.cpp:1061
BK108X::getFrequency
uint16_t getFrequency()
Gets the current frequency.
Definition: BK108X.cpp:597
BK108X::setFrequencyUp
void setFrequencyUp()
Increments the current frequency.
Definition: BK108X.cpp:567
BK108X::setSoftmuteAttack
void setSoftmuteAttack(uint8_t value)
Sets Softmute Attack/Recover Rate.
Definition: BK108X.cpp:867
bk_reg01::chipId
uint16_t chipId
Definition: BK108X.h:124
REG11
#define REG11
Definition: BK108X.h:70
BK108X::currentAMBand
uint8_t currentAMBand
Definition: BK108X.h:791
BK108X::reset
void reset()
Resets the device.
Definition: BK108X.cpp:367
BK108X::getRdsProgramType
uint8_t getRdsProgramType(void)
Returns the Program Type (extracted from the Block B)
Definition: BK108X.cpp:1147
bk_reg0b::raw
uint16_t raw
Definition: BK108X.h:357
BK108X::setAfcRssiSnrCalculateRate
void setAfcRssiSnrCalculateRate(uint8_t value)
Sets AFC/RSSI/SNR Calculate Rate.
Definition: BK108X.h:974
BK108X::setVolume
void setVolume(uint8_t value)
Sets the audio volume level.
Definition: BK108X.cpp:998
bk_reg12::raw
uint16_t raw
Definition: BK108X.h:459
REG1C
#define REG1C
Definition: BK108X.h:81
bk_reg07::raw
uint16_t raw
Definition: BK108X.h:287
REG1E
#define REG1E
Definition: BK108X.h:83
REG09
#define REG09
Definition: BK108X.h:62
BK108X::rds_time
char rds_time[20]
RDS date time received information.
Definition: BK108X.h:780
REG01
#define REG01
Definition: BK108X.h:54
BK108X::getRdsFlagAB
uint8_t getRdsFlagAB(void)
Returns the current Text Flag A/B
Definition: BK108X.cpp:1114
REG12
#define REG12
Definition: BK108X.h:71
BK108X::getCurrentMode
uint8_t getCurrentMode()
Get the Current Mode (AM or FM)
Definition: BK108X.h:883
REG0B
#define REG0B
Definition: BK108X.h:64
BK108X::setFmDeemphasis
void setFmDeemphasis(uint8_t de)
Sets De-emphasis.
Definition: BK108X.h:903
BK108X::currentAMSpace
uint8_t currentAMSpace
Definition: BK108X.h:793
BK108X::maximumFrequency
uint32_t maximumFrequency
Definition: BK108X.h:786
bk_reg18::raw
uint16_t raw
Definition: BK108X.h:545
BK108X::powerUp
void powerUp()
Powers the receiver on.
Definition: BK108X.cpp:383
BK108X::getShadownRegister
uint16_t getShadownRegister(uint8_t register_number)
Get the Shadown Register object.
Definition: BK108X.h:852
bk_reg17::raw
uint16_t raw
Definition: BK108X.h:531
REG0D
#define REG0D
Definition: BK108X.h:66
MAX_DELAY_AFTER_OSCILLATOR
#define MAX_DELAY_AFTER_OSCILLATOR
Definition: BK108X.h:21
bk_reg14::raw
uint16_t raw
Definition: BK108X.h:489
BK108X::getVolume
uint8_t getVolume()
Gets the current audio volume level.
Definition: BK108X.cpp:1014
BK108X::setup
void setup(int sda_pin, int sclk_pin, int rdsInterruptPin=-1, int seekInterruptPin=-1, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL)
Starts the device.
Definition: BK108X.cpp:441
bk_reg1B::raw
uint16_t raw
Definition: BK108X.h:586
REG0A
#define REG0A
Definition: BK108X.h:63
bk_rds_date_time::raw
uint8_t raw[6]
Definition: BK108X.h:697
BK108X::setStereoThresholdPilotStrength
void setStereoThresholdPilotStrength(uint8_t value)
Sets the Stereo Threshold of Pilotto Strength.
Definition: BK108X.h:891
MODE_FM
#define MODE_FM
Definition: BK108X.h:47
BK108X::maxDelayAftarCrystalOn
uint16_t maxDelayAftarCrystalOn
Definition: BK108X.h:800
bk_reg1F
uint16_t bk_reg1F
Definition: BK108X.h:621
REG00
#define REG00
Definition: BK108X.h:53
BK108X::setFrequencyDown
void setFrequencyDown()
Decrements the current frequency.
Definition: BK108X.cpp:582
BK108X::setSeekMute
void setSeekMute(bool value)
Disable or Enable soft mute when seeking.
Definition: BK108X.cpp:913
REG16
#define REG16
Definition: BK108X.h:75
BK108X::i2cNack
void i2cNack()
Sends Not Acknowledge (ACK)
Definition: BK108X.cpp:118
BK108X::setRdsMode
void setRdsMode(uint8_t rds_mode=0)
Sets the Rds Mode Standard or Verbose.
Definition: BK108X.cpp:1072
REG1A
#define REG1A
Definition: BK108X.h:79
I2C_DEVICE_ADDR
#define I2C_DEVICE_ADDR
Definition: BK108X.h:23
BK108X::getStatus
bk_reg0a getStatus()
Gets the current status (register 0x0A) content.
Definition: BK108X.cpp:336
BK108X::getRdsGroupType
uint16_t getRdsGroupType()
Return the group type.
Definition: BK108X.cpp:1125
bk_rds_blockb::blockB
bk_reg0d blockB
Definition: BK108X.h:672
bk_reg00::deviceId
uint16_t deviceId
Definition: BK108X.h:109
REG05
#define REG05
Definition: BK108X.h:58
BK108X::currentStep
uint16_t currentStep
Definition: BK108X.h:789
BK108X::getRdsText2B
char * getRdsText2B(void)
Gets the Text processed for the 2B group.
Definition: BK108X.cpp:1216
REG0E
#define REG0E
Definition: BK108X.h:67
REG07
#define REG07
Definition: BK108X.h:60
BK108X::setAM
void setAM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step, uint16_t am_space=0)
Sets the receiver to AM mode.
Definition: BK108X.cpp:495
bk_reg0f::raw
uint16_t raw
Definition: BK108X.h:417
BK108X::setMono
void setMono(bool value)
Sets the Mono true or false (stereo)
Definition: BK108X.cpp:972
BK108X::i2cEndTransaction
void i2cEndTransaction()
Finish the I2C bus transaction.
Definition: BK108X.cpp:82
BK108X::setI2C
void setI2C(uint8_t i2c_addr=I2C_DEVICE_ADDR)
Sets I2C bus address.
Definition: BK108X.cpp:42
REG06
#define REG06
Definition: BK108X.h:59
BK108X::setRds
void setRds(bool value)
Sets the RDS operation.
Definition: BK108X.cpp:1084
REG1D
#define REG1D
Definition: BK108X.h:82
BK108X::setVolumeUp
void setVolumeUp()
Increments the audio volume.
Definition: BK108X.cpp:1024
BK108X::setAfcRssiThreshold
void setAfcRssiThreshold(uint8_t value)
Sets RSSI Threshold for Instant AFC updating.
Definition: BK108X.h:1029
bk_reg04::raw
uint16_t raw
Definition: BK108X.h:190
REG02
#define REG02
Definition: BK108X.h:55
BK108X::setAgc
void setAgc(bool value)
Sets the AGC enable or disable.
Definition: BK108X.cpp:936
BK108X::setRegister
void setRegister(uint8_t reg, uint16_t value)
Sets a given value to the device registers.
Definition: BK108X.cpp:291
BK108X::setAfcVar
void setAfcVar(uint8_t value)
Sets Variation Threshold for average AFC calculation.
Definition: BK108X.h:1007
BK108X::i2cWriteByte
void i2cWriteByte(uint8_t data)
Sends a Byte to the slave device.
Definition: BK108X.cpp:158
BK108X::rds_buffer2B
char rds_buffer2B[33]
RDS Radio Text buffer - Station Informaation.
Definition: BK108X.h:778
BK108X::getRdsReady
bool getRdsReady()
Returns true if RDS Ready.
Definition: BK108X.cpp:1101