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