PU2CLR KT0915 Arduino Library  1.0.1
This is an Arduino Library to control the KT0915 device
KT0915.h
Go to the documentation of this file.
1 
2 /**
3  * @mainpage PU2CLR KT0915 Arduino Library
4  * @brief PU2CLR KT0915 Arduino Library implementation. <br>
5  * @details This is an Arduino library for the KT0915, BROADCAST RECEIVER.<br>
6  * @details It works with I2C protocol and can provide an easier interface for controlling the KT0915 device.<br>
7  * @details This library was built based on KT0915 Datasheet from KTMicro (Monolithic Digital FM/MW/SW/LW Receiver Radio-on-a-Chip TM).
8  * @details Others sources help the author to build this library. They are referenced in the documentation for this library on: https://github.com/pu2clr/KT0915
9  * @details This library uses the I2C protocols to read and write KT0915 registers. In this context, registers are memory position into the device.
10  * @details The KT0915 is a full band AM (LW, MW and SW) and FM DSP receiver that can provide you a easy way to build a high quality radio with low cost.
11  * @details This device, will surprise hobbyists and experimenters with its simplicity.
12  *
13  * This library can be freely distributed using the MIT Free Software model.
14  *
15  * Copyright (c) 2020 Ricardo Lima Caratti.
16  * Contact: pu2clr@gmail.com
17  */
18 
19 #include <Arduino.h>
20 #include <Wire.h>
21 
22 #define KT0915_I2C_ADDRESS 0x35 // It is needed to check it when the KT0915 device arrives.
23 
24 #define MODE_FM 0
25 #define MODE_AM 1
26 
27 
28 #define OSCILLATOR_32KHZ 0 // 32.768KHz
29 #define OSCILLATOR_6_5MHZ 1 // 6.5MHz
30 #define OSCILLATOR_7_6MHZ 2 // 7.6MHz
31 #define OSCILLATOR_12MHZ 3 // 12MHz
32 #define OSCILLATOR_13MHZ 4 // 13MHz
33 #define OSCILLATOR_15_2MHZ 5 // 15.2MHz
34 #define OSCILLATOR_19_2MHZ 6 // 19.2MHz
35 #define OSCILLATOR_24MHZ 7 // 24MHz
36 #define OSCILLATOR_26MHZ 8 // 26MHz
37 #define OSCILLATOR_38KHz 9 // 38KHz
38 
39 #define REF_CLOCK_ENABLE 1 // Reference Clock
40 #define REF_CLOCK_DISABLE 0 // Crystal Clock
41 
42 #define DIAL_MODE_ON 1 // Mechanical tuning (Via 100K resistor)
43 #define DIAL_MODE_OFF 0 // MCU (Arduino) tuning
44 
45 #define REG_CHIP_ID 0x01
46 #define REG_SEEK 0x02
47 #define REG_TUNE 0x03
48 #define REG_VOLUME 0x04
49 #define REG_DSPCFGA 0x05
50 #define REG_LOCFGA 0x0A
51 #define REG_LOCFGC 0x0C
52 #define REG_RXCFG 0x0F
53 #define REG_STATUSA 0x12
54 #define REG_STATUSB 0x13
55 #define REG_STATUSC 0x14
56 #define REG_AMSYSCFG 0x16
57 #define REG_AMCHAN 0x17
58 #define REG_AMCALI 0x18
59 #define REG_GPIOCFG 0x1D
60 #define REG_AMDSP 0x22
61 #define REG_AMSTATUSA 0x24
62 #define REG_AMSTATUSB 0x25
63 #define REG_SOFTMUTE 0x2E
64 #define REG_USERSTARTCH 0x2F
65 #define REG_USERGUARD 0x30
66 #define REG_USERCHANNUM 0x31
67 #define REG_AMCFG 0x33
68 #define REG_AMCFG2 0x34
69 #define REG_AFC 0x3C
70 
71 /**
72  * @defgroup GA01 Union, Structure and Defined Data Types
73  * @brief KT0915 Defined Data Types
74  * @details Defined Data Types is a way to represent the AKC695X registers information
75  * @details Some information appears to be inaccurate due to translation problems from Chinese to English.
76  * @details The information shown here was extracted from Datasheet:
77  * @details AKC6955 stereo FM / TV / MW / SW / LW digital tuning radio documentation.
78  * @details Other information seems incomplete even in the original Chinese Datasheet.
79  * @details For example: Reg 10 (0x0A). There is no information about it. The Reg11 and 12 seem wrong
80  */
81 
82 /**
83  * @ingroup GA01
84  * @brief 3.10.1. CHIP ID (Address 0x01)
85  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 15.
86  */
87 typedef union {
89  char chip_id_ascii[2];
90 } kt09xx_chip_id;
91 
92 /**
93  * @ingroup GA01
94  * @brief 3.10.2. SEEK (Address 0x02)
95  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 15.
96  */
97 typedef union {
98  struct
99  {
100  uint8_t DMUTEL : 1; //!< Left Channel Mute Control; 0 = Left channel mute enable; 1 = Left channel mute disable
101  uint8_t DMUTER : 1; //!< Right Channel Mute Control; 0 = Left channel mute enable; 1 = Left channel mute disable
102  uint8_t FMSPACE : 2; //!< FM Channel Spacing; 00 = 200KHz; 01 = 100KHz; 10 = 50KHz
103  uint16_t RESERVED : 11; //!< Reserved
104  } refinied;
106 } kt09xx_seek;
107 
108 /**
109  * @ingroup GA01
110  * @brief 3.10.3. TUNE (Address 0x03)
111  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 15.
112  */
113 typedef union {
114  struct
115  {
116  uint16_t FMCHAN : 12; //!< FM Channel Setting FMCHAN<11:0>=Frequency (KHz) / 50KHz. For example, if desired channel is 86MHz, then the FMCHAN<11:0> should be 0x06B8.
117  uint8_t RESERVED : 3; //!< Reserved
118  uint8_t FMTUNE : 1; //!< FM Tune Enable; 0 = Normal operation 1 = Start to tune to desired FM channel
119  } refined;
121 } kt09xx_tune;
122 
123 /**
124  * @ingroup GA01
125  * @brief 3.10.4. VOLUME (Address 0x04)
126  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 15/16.
127  */
128 typedef union {
129  struct
130  {
131  uint8_t RESERVED1 : 4; //!< Reserved
132  uint8_t POP : 2; //!< Audio DAC Anti - pop Configuration00 : 100uF AC - coupling capacitor 01 : 10 : 11 : Reserved 60uF AC - coupling capacitor 20uF AC - coupling capacitor 10uF AC - coupling capacitor.
133  uint8_t RESERVED2 : 2; //!< Reserved
134  uint8_t BASS : 2; //!< Bass Boost Effect Mode Selection; 00 = Disable; 01 = Low ; 10 = Med; 11 = High.
135  uint8_t RESERVED3 : 3; //!< Reserved
136  uint8_t DMUTE : 1; //!< Mute Disable; 0 = Mute enable; 1 = Mute disable.
137  uint8_t AMDSMUTE : 1; //!< AM Softmute Disable; 0 = AM softmute enable; 1 = AM softmute disable.
138  uint8_t FMDSMUTE : 1; //!< AM Softmute Disable; 0 = FM softmute enable; 1 = FM softmute disable.
139  } refined;
141 } kt09xx_volume;
142 
143 /**
144  * @ingroup GA01
145  * @brief 3.10.5. DSPCFGA (Address 0x05)
146  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 16/17.
147  */
148 typedef union {
149  struct
150  {
151  uint8_t RESERVED1 : 5; //!< Reserved
152  uint8_t DBLND : 1; //!< Blend disable; 0 = Blend enable; 1 = Blend disable
153  uint8_t RESERVED2 : 2; //!< Reserved
154  uint8_t BLNDADJ : 2; //! Stereo/Mono Blend; Level Adjustment 00 = High; 01 = Highest 10; = Lowest 11 = Low
155  uint8_t RESERVED3 : 1; //!< Reserved
156  uint8_t DE : 1; //!< De-emphasis Time Constant Selection. 0 = 75us; 1 = 50us.
157  uint8_t RESERVED4 : 3; //!< Reserved
158  uint8_t MONO : 1; //!< Mono Select; 0 = Stereo; 1 = Force mono
159  } refined;
161 } kt09xx_dspcfga;
162 
163 /**
164  * @ingroup GA01
165  * @brief 3.10.6. LOCFGA (Address 0x0A)
166  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 17.
167  */
168 typedef union {
169  struct
170  {
171  uint8_t RESERVED1 : 8; //!< Reserved
172  uint8_t FMAFCD : 1; //!< AFC Disable Control Bit; 0 = AFC enable; 1 = AFC disable.
173  uint8_t RESERVED2 : 7; //!< Reserved
174  } refined;
176 } kt09xx_locfga; // LOCFGA
177 
178 /**
179  * @ingroup GA01
180  * @brief 3.10.7. LOCFGC (Address 0x0C)
181  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 17.
182  */
183 typedef union {
184  struct
185  {
186  uint8_t RESERVED1 : 3; //!< Reserved
187  uint8_t CAMPUSBAND_EN : 1; //!< Campus FM Band Enable; 0 = User can only use 64MHz ~110MHz; 1 = User can extend the FM band down to 32MHz
188  uint16_t RESERVED2 : 12; //!< Reserved
189  } refined;
191 } kt09xx_locfgc; // LOCFGC
192 
193 /**
194  * @ingroup GA01
195  * @brief 3.10.8. RXCFG (Address 0x0F)
196  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 17.
197  */
198 typedef union {
199  struct
200  {
201  uint8_t VOLUME : 5; //!< Volume Control 11111 = 0dB 11110 = -2dB 11101 = -4dB .... 00010 = -58dB 00001 = -60dB 00000 = Mute
202  uint8_t RESERVED1 : 7; //!< Campus FM Band Enable; 0 = User can only use 64MHz ~110MHz; 1 = User can extend the FM band down to 32MHz
203  uint8_t STDBY : 1; //!< Standby Mode Enable. 0 = Disable; 1 = Enable
204  uint8_t RESERVED2 : 3; //!< Reserved
205  } refined;
207 } kt09xx_rxcfg; // RXCFG
208 
209 /**
210  * @ingroup GA01
211  * @brief 3.10.19. STATUSA (Address 0x12)
212  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 18.
213  */
214 typedef union {
215  struct
216  {
217  uint8_t RESERVED1 : 3; //!< Reserved
218  uint8_t FMRSSI : 5; //!< FM RSSI Value Indicator; RSSI starts from -100dBm and step is 3dB namely; RSSI(dBm) = -100 + FMRSSI<4:0> *3dB
219  uint8_t ST : 2; //!< Stereo Indicator; 11 = Stereo state; Other = Mono state
220  uint8_t LO_LOCK : 1; //!< LO Synthesizer Ready Indicator; 0 = Not ready; 1 = Ready
221  uint8_t PLL_LOCK : 1; //!< System PLL Ready Indicator; 0 = Not ready; 1 = System PLL ready
222  uint8_t RESERVED2 : 2; //!< Reserved
223  uint8_t STC : 1; //!< Seek/Tune Complete; 0 = Not Complete; 1 = Complete; Every time the Seek/tune process begins, the STC bit will clear to zero by hardware.
224  uint8_t XTAL_OK : 1; //!< Crystal ready indictor; 0 = Not ready; 1 = Crystal is ok
225  } refined;
227 } kt09xx_statusa; // STATUSA
228 
229 /**
230  * @ingroup GA01
231  * @brief 3.10.10. STATUSB (Address 0x13)
232  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 18.
233  */
234 typedef union {
235  struct
236  {
237  uint8_t RESERVED1 : 1; //!< Reserved
238  uint16_t RDCHAN : 15; //!< Current Channel Indicator
239  } refined;
241 } kt09xx_statusb; // STATUSB
242 
243 /**
244  * @ingroup GA01
245  * @brief 3.10.11. STATUSC (Address 0x14)
246  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 18/19.
247  */
248 typedef union {
249  struct
250  {
251  uint8_t RESERVED1 : 6; //!< Reserved
252  uint8_t FMSNR : 7; //!< Channel SNR value is FM mode.; 0000000 = Minimum SNR; 1111111 = Maximum SNR
253  uint8_t CHIPRDY : 1; //!< Chip Ready Indicator; 0 = Chip is not ready; 1 = Chip is ready, calibration done
254  uint8_t RESERVED2 : 1; //!< Reserved
255  uint8_t PWSTATUS : 1; //!< Power Status Indicator; 0 = Power not ready; 1 = Power ready
256  } refined;
258 } kt09xx_statusc; // STATUSC
259 
260 /**
261  * @ingroup GA01
262  * @brief 3.10.12. AMSYSCFG (Address 0x16)
263  * @details The table below shows REFCLK possibvle values
264  *
265  * Crystal type table
266  * | Dec | binary | Description | defined constant |
267  * | -- | ------ | ----------- | --------------- |
268  * | 0 | 0000 | 32.768KHz | OSCILLATOR_32KHZ |
269  * | 1 | 0001 | 6.5MHz | OSCILLATOR_6_5MHZ |
270  * | 2 | 0010 | 7.6MHz | OSCILLATOR_7_6MHZ |
271  * | 3 | 0011 | 12MHz | OSCILLATOR_12MHZ |
272  * | 4 | 0100 | 13MHz | OSCILLATOR_13MHZ |
273  * | 5 | 0101 | 15.2MHz | OSCILLATOR_15_2MHZ |
274  * | 6 | 0110 | 19.2MHz | OSCILLATOR_19_2MHZ |
275  * | 7 | 0111 | 24MHz | OSCILLATOR_24MHZ |
276  * | 8 | 1000 | 26MHz | OSCILLATOR_26MHZ |
277  * | 9 | 1001 | ?? 38KHz ?? | OSCILLATOR_38KHz |
278  *
279  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 19.
280  *
281  */
282 typedef union {
283  struct
284  {
285  uint8_t AMAFCD : 1; //!< AFC Disable Control in AM Mode; 0 = Enable; 1 = Disable
286  uint8_t RESERVED1 : 5; //!< Reserved
287  uint8_t AU_GAIN : 2; //!< Audio Gain Selection; 01 = 6dB; 00 = 3dB; 11 = 0dB; 10 = -3dB
288  uint8_t REFCLK : 4; //!< See Crystal type table
289  uint8_t RCLK_EN : 1; //!< Reference Clock Enable; 0 = Crystal; 1 = Reference clock
290  uint8_t RESERVED2 : 1; //!< Reserved
291  uint8_t USERBAND : 1; //!< User Definition Band Enable; 0 = Use internal defined band; 1 = Use user-defined band which is specified in USER_START_CHAN<14:0>, USER_GUARD<8:0> and USER_CHAN_NUM<11:0>
292  uint8_t AM_FM : 1; //!< AM/FM Mode Control; 0 = FM mode; 1 = AM mode
293  } refined;
295 } kt09xx_amsyscfg; // AMSYSCFG
296 
297 /**
298  * @ingroup GA01
299  * @brief 3.10.13. AMCHAN (Address 0x17)
300  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 20.
301  */
302 typedef union {
303  struct
304  {
305  uint16_t AMCHAN : 15; //!< AM Channel Setting; AMCHAN<14:0> = Frequency(in KHz)
306  uint8_t AMTUNE : 1; //!< AM Tune Enable
307  } refined;
309 } kt09xx_amchan; // AMCHAN
310 
311 /**
312  * @ingroup GA01
313  * @brief 3.10.14. AMCALI (Address 0x18)
314  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 20.
315  */
316 typedef union {
317  struct
318  {
319  uint16_t CAP_INDEX : 14; //!< On Chip Capacitor for AM Antenna Calibration; 0x0000 = Minimum capacitor; 0x3FFF = Maximum capacitor
320  uint8_t RESERVED1 : 2; //!< Reserved
321  } refined;
323 } kt09xx_amcali; // AMCALI
324 
325 /**
326  * @ingroup GA01
327  * @brief 3.10.15. GPIOCFG (Address 0x1D)
328  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 20.
329  */
330 typedef union {
331  struct
332  {
333  uint8_t GPIO1 : 2; //!< CH Pin Mode Selection; 00 = High Z; 01 = Key controlled channel increase / decrease; 10 = Dial controlled channel increase / decrease; 11 = Reserved
334  uint8_t GPIO2 : 2; //!< VOL Pin Mode Selection; 00 = High Z; 01 = Key controlled volume increase/decrease; 10 = Dial controlled volume increase/decrease; 11 = Reserved
335  uint16_t RESERVED : 12; //!< Reserved
336  } refined;
338 } kt09xx_gpiocfg; // GPIOCFG
339 
340 /**
341  * @ingroup GA01
342  * @brief 3.10.16. AMDSP (Address 0x22)
343  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); pages 20 and 21.
344  */
345 typedef union {
346  struct
347  {
348  uint8_t RESERVED1 : 3; //!< Reserved
349  uint8_t INV_LEFT_AUDIO : 1; //!< Left channel inverse control; 0 = Normal operation; 1 = Inversing the left channel audio signal
350  uint8_t RESERVED2 : 2; //!< Reserved
351  uint8_t AM_BW : 2; //!< AM Channel Bandwidth Selection; 00 = 2KHz; 01 = 2KHz; 10 = 4KHz; 11 = 6KHz
352  uint8_t RESERVED3 : 8; //!< Reserved
353  } refined;
355 } kt09xx_amdsp; // AMDSP
356 
357 /**
358  * @ingroup GA01
359  * @brief 3.10.17. AMSTATUSA (Address 0x24)
360  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 21.
361  */
362 typedef union {
363  struct
364  {
365  uint8_t RESERVED1 : 8; //!< Reserved
366  uint8_t AMRSSI : 5; //!< AM Channel RSSI; AM RSSI starts from -90dBm and step is 3dB, namely AMRSSI(dBm) = -90 + AMRSSI<4:0> *3dB
367  uint8_t RESERVED2 : 3; //!< Reserved
368 
369  } refined;
371 } kt09xx_amdstatusa; // AMSTATUSA
372 
373 /**
374  * @ingroup GA01
375  * @brief 3.10.18. AMSTATUSB (Address 0x25)
376  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 21.
377  */
378 typedef union {
379  struct
380  {
381  uint8_t AM_AFCDELTAF : 8; //!< Signed binary, max 16KHz , min -16KHz, step is 128Hz.
382  uint8_t RESERVED : 8; //!< Reserved
383  } refined;
385 } kt09xx_amdstatusb; // AMSTATUSB
386 
387 /**
388  * @ingroup GA01
389  * @brief 3.10.19. SOFTMUTE (Address 0x2Eh)
390  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 21.
391  */
392 typedef union {
393  struct
394  {
395  uint8_t FM_SMTH : 3; //!< FM Softmute Start Threshold; 000 = Lowest ... 111 = Highest
396  uint8_t SMMD : 1; //!< Softmute Mode Selection; 0 = RSSI mode; 1 = SNR mode (only effective in FM mode)
397  uint8_t VOLUMET : 5; //!< Softmute target Volume. 0 = RSSI; 1 = SNR mode (only effective in FM mode)
398  uint8_t AM_SMTH : 3; //!< AM Softmute Start Level. 000 = Lowest ... 111 = Highest
399  uint8_t SMUTER : 2; //!< Softmute Attack/Recover Rate; 00 = Slowest; 01 = Fastest (RSSI mode only); 10 = Fast; 11 = Slow
400  uint8_t SMUTEA : 2; //!< Softmute Attenuation; 00 = Strong; 01 = Strongest; 10 = Weak; 11 = Weakest
401  } refined;
403 } kt09xx_softmute; // SOFTMUTE
404 
405 /**
406  * @ingroup GA01
407  * @brief 3.10.20. USERSTARTCH (Address 0x2F)
408  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 22.
409  */
410 typedef union {
411  struct
412  {
413  uint16_t USER_START_CHAN : 15; //!< User band start channel, only effect when USERBAND=1. See section 3.7.3. of the Datasheet
414  uint8_t RESERVED : 1; //!< Reserved
415  } refined;
417 } kt09xx_userstartch; // USERSTARTCH
418 
419 /**
420  * @ingroup GA01
421  * @brief 3.10.21. USERGUARD (Address 0x30)
422  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio on a Chip(TM); page 22.
423  */
424 typedef union {
425  struct
426  {
427  uint16_t USER_GUARD : 9; //!< User band guard number, only effective when USERBAND=1. See section 3.7.2.
428  uint8_t RESERVED : 7; //!< Reserved
429  } refined;
431 } kt09xx_userguard; // USERGUARD
432 
433 /**
434  * @ingroup GA01
435  * @brief 3.10.22. USERCHANNUM (Address 0x31)
436  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio-on-a-Chip(TM); page 22.
437  */
438 typedef union {
439  struct
440  {
441  uint16_t USER_CHAN_NUM : 12; //!< User band channel number, only effective when USERBAND=1. See section 3.7.3.
442  uint8_t RESERVED : 4; //!< Reserved
443  } refined;
445 } kt09xx_userchannum; // USERCHANNUM
446 
447 /**
448  * @ingroup GA01
449  * @brief 3.10.23. AMCFG (Address 0x33)
450  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio-on-a-Chip(TM); page 23.
451  */
452 typedef union {
453  struct
454  {
455  uint8_t RESERVED1 : 5; //!< Reserved
456  uint8_t KEY_MODE : 2; //!< Working mode selection when key mode is selected. 00 = Working mode A; 01 = Working mode B Others = Reserved; For detailed information about working mode A and working mode B, please refer to section 3.7.1.
457  uint8_t RESERVED2 : 7; //!< Reserved
458  uint8_t AMSPACE : 2; //!< AM Channel Space Selection; 00 = 1KHz; 01 = 9KHz; 10 = 10KHz; 11 = 10KHz.
459  } refined;
461 } kt09xx_amcfg; // AMCFG
462 
463 /**
464  * @ingroup GA01
465  * @brief 3.10.24. AMCFG2 (Address 0x34h)
466  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio-on-a-Chip(TM); page 23.
467  */
468 typedef union {
469  struct
470  {
471  uint8_t RESERVED1 : 1; //!< Reserved
472  uint8_t TIME2 : 3; //!< 000 = Fastest...... 111 = Slowest
473  uint8_t TIME1 : 2; //!< 00 = Shortest...... 11 = Longest
474  uint16_t RESERVED2 : 10; //!< Reserved
475  } refined;
477 } kt09xx_amcfg2; // AMCFG2
478 
479 /**
480  * @ingroup GA01
481  * @brief 3.10.25. AFC (Address 0x3Ch)
482  * @see KT0915; Monolithic Digital FM/MW/SW/LW Receiver Radio-on-a-Chip(TM); page 23.
483  */
484 typedef union {
485  struct
486  {
487  uint8_t FM_AFC_DELTAF : 8; //!< Frequency difference between CHAN and received signal, calculated by AFC block in two’s complement format. Range is - 127 to +127. Unit is KHz. This register is valid when STC=1
488  uint8_t RESERVED1 : 8; //!< Reserved
489  } refined;
491 } kt09xx_afc; // AFC
492 
493 /**
494  * @ingroup GA01
495  * @brief Converts 16 bits word to two bytes
496  */
497 typedef union {
498  struct {
499  uint8_t lowByte;
500  uint8_t highByte;
501  } refined;
503 } word16_to_bytes;
504 
505 /**
506  * @ingroup GA01
507  * @brief KT0915 Class
508  * @details This class implements all functions that will help you to control the KT0915 devices.
509  *
510  * @author PU2CLR - Ricardo Lima Caratti
511  */
512 
513 class KT0915 {
514 
515 protected:
517  int enablePin = -1;
518 
519  uint8_t volume; //!< Stores the current volume
520  uint16_t currentStep; //!< Stores the current step
521  uint32_t currentFrequency; //!< Stores the current frequency
522  uint32_t minimumFrequency; //!< Stores the minimum frequency for the current band
523  uint32_t maximumFrequency; //!< Stores the maximum frequency for the current band
524  uint8_t currentMode; //!< Stores the current mode
525  uint8_t currentRefClockType = OSCILLATOR_32KHZ; //!< Stores the crystal type
526  uint8_t currentRefClockEnabled = REF_CLOCK_DISABLE; //!< Strores 0 = Crystal; 1 = Reference clock
527  uint8_t currentDialMode = DIAL_MODE_OFF; //!< Stores the default Dial Mode (OFF)
530 
531 public:
532  void setRegister(uint8_t reg, uint16_t parameter);
534 
536  void enable(uint8_t on_off);
537  void setI2CBusAddress(int deviceAddress);
538  void setReferenceClockType(uint8_t crystal, uint8_t ref_clock = 0);
539  bool isCrystalReady();
540  void setup(int enable_pin, uint8_t oscillator_type = OSCILLATOR_32KHZ, uint8_t ref_clock = REF_CLOCK_DISABLE);
541 
542  void setTuneDialModeOn(uint32_t minimu_frequency, uint32_t maximum_frequency);
543  void setTuneDialModeOff();
544  void setVolumeDialModeOn();
545  void setVolumeDialModeOff();
546 
547  void setVolume(uint8_t value);
548  void setVolumeUp();
549  void setVolumeDown();
550 
551  void setDeEmphasis(uint8_t value);
552  void setMono(bool on_off);
553 
554  void setFM(uint32_t minimum_frequency, uint32_t maximum_frequency, uint32_t default_frequency, uint16_t step);
555  void setAM(uint32_t minimum_frequency, uint32_t maximum_frequency, uint32_t default_frequency, uint16_t step);
556  void setFrequency(uint32_t frequency);
557  void setStep(uint16_t step);
558  void frequencyUp();
559  void frequencyDown();
561  void setAntennaTuneCapacitor(uint16_t capacitor);
562 
563  inline uint8_t getCurrentMode() { return this->currentMode; };
564 };
KT0915::enable
void enable(uint8_t on_off)
Sets the enable pin (9) of the KT0915 high or low.
Definition: KT0915.cpp:148
KT0915::setVolumeUp
void setVolumeUp()
Definition: KT0915.cpp:267
KT0915::setFM
void setFM(uint32_t minimum_frequency, uint32_t maximum_frequency, uint32_t default_frequency, uint16_t step)
Sets the receiver to FM mode.
Definition: KT0915.cpp:389
KT0915::setAntennaTuneCapacitor
void setAntennaTuneCapacitor(uint16_t capacitor)
Set AM the Antenna Tune Capacitor.
Definition: KT0915.cpp:344
kt09xx_amcali::raw
uint16_t raw
Definition: KT0915.h:322
KT0915::currentRefClockType
uint8_t currentRefClockType
Stores the crystal type.
Definition: KT0915.h:525
kt09xx_seek::raw
uint16_t raw
Definition: KT0915.h:105
KT0915_I2C_ADDRESS
#define KT0915_I2C_ADDRESS
Definition: KT0915.h:22
word16_to_bytes::raw
uint16_t raw
Definition: KT0915.h:502
kt09xx_softmute::raw
uint16_t raw
Definition: KT0915.h:402
kt09xx_amdsp::raw
uint16_t raw
Definition: KT0915.h:354
KT0915::currentVolume
uint8_t currentVolume
Definition: KT0915.h:529
DIAL_MODE_OFF
#define DIAL_MODE_OFF
Definition: KT0915.h:43
kt09xx_chip_id::chip_id
uint16_t chip_id
Definition: KT0915.h:88
kt09xx_statusa::raw
uint16_t raw
Definition: KT0915.h:226
kt09xx_afc::raw
uint16_t raw
Definition: KT0915.h:490
KT0915::deviceId
uint16_t deviceId
Definition: KT0915.h:528
KT0915::currentFrequency
uint32_t currentFrequency
Stores the current frequency.
Definition: KT0915.h:521
KT0915::currentDialMode
uint8_t currentDialMode
Stores the default Dial Mode (OFF)
Definition: KT0915.h:527
kt09xx_locfga::raw
uint16_t raw
Definition: KT0915.h:175
KT0915::isCrystalReady
bool isCrystalReady()
Gets the Crystal Status information.
Definition: KT0915.cpp:94
kt09xx_userchannum::raw
uint16_t raw
Definition: KT0915.h:444
KT0915
KT0915 Class.
Definition: KT0915.h:513
KT0915::setAM
void setAM(uint32_t minimum_frequency, uint32_t maximum_frequency, uint32_t default_frequency, uint16_t step)
Sets the receiver to AM mode.
Definition: KT0915.cpp:429
KT0915::setI2CBusAddress
void setI2CBusAddress(int deviceAddress)
Set I2C bus address.
Definition: KT0915.cpp:26
kt09xx_locfgc::raw
uint16_t raw
Definition: KT0915.h:190
REF_CLOCK_DISABLE
#define REF_CLOCK_DISABLE
Definition: KT0915.h:40
kt09xx_amcfg::raw
uint16_t raw
Definition: KT0915.h:460
KT0915::minimumFrequency
uint32_t minimumFrequency
Stores the minimum frequency for the current band.
Definition: KT0915.h:522
KT0915::volume
uint8_t volume
Stores the current volume.
Definition: KT0915.h:519
KT0915::currentMode
uint8_t currentMode
Stores the current mode.
Definition: KT0915.h:524
kt09xx_amsyscfg::raw
uint16_t raw
Definition: KT0915.h:294
KT0915::setMono
void setMono(bool on_off)
Sets the receiver Stereo or Mono.
Definition: KT0915.cpp:357
KT0915::currentStep
uint16_t currentStep
Stores the current step.
Definition: KT0915.h:520
KT0915::deviceAddress
int deviceAddress
Definition: KT0915.h:516
KT0915::maximumFrequency
uint32_t maximumFrequency
Stores the maximum frequency for the current band.
Definition: KT0915.h:523
KT0915::setStep
void setStep(uint16_t step)
Sets the frequency step.
Definition: KT0915.cpp:519
KT0915::getCurrentMode
uint8_t getCurrentMode()
Definition: KT0915.h:563
KT0915::getFrequency
uint32_t getFrequency()
Gets the current frequency.
Definition: KT0915.cpp:529
kt09xx_amcfg2::raw
uint16_t raw
Definition: KT0915.h:476
OSCILLATOR_32KHZ
#define OSCILLATOR_32KHZ
Definition: KT0915.h:28
KT0915::setTuneDialModeOn
void setTuneDialModeOn(uint32_t minimu_frequency, uint32_t maximum_frequency)
Sets Tune Dial Mode Interface On
Definition: KT0915.cpp:169
KT0915::setReferenceClockType
void setReferenceClockType(uint8_t crystal, uint8_t ref_clock=0)
Sets the Crystal Type.
Definition: KT0915.cpp:125
kt09xx_amdstatusb::raw
uint16_t raw
Definition: KT0915.h:384
kt09xx_statusb::raw
uint16_t raw
Definition: KT0915.h:240
kt09xx_userguard::raw
uint16_t raw
Definition: KT0915.h:430
kt09xx_gpiocfg::raw
uint16_t raw
Definition: KT0915.h:337
kt09xx_amchan::raw
uint16_t raw
Definition: KT0915.h:308
KT0915::getRegister
uint16_t getRegister(uint8_t reg)
Gets a given KT09XX register content.
Definition: KT0915.cpp:61
kt09xx_chip_id::chip_id_ascii
char chip_id_ascii[2]
Definition: KT0915.h:89
kt09xx_volume::raw
uint16_t raw
Definition: KT0915.h:140
KT0915::setRegister
void setRegister(uint8_t reg, uint16_t parameter)
Sets the a value to a given KT09XX register.
Definition: KT0915.cpp:38
KT0915::currentRefClockEnabled
uint8_t currentRefClockEnabled
Strores 0 = Crystal; 1 = Reference clock.
Definition: KT0915.h:526
KT0915::enablePin
int enablePin
Definition: KT0915.h:517
kt09xx_dspcfga::raw
uint16_t raw
Definition: KT0915.h:160
KT0915::setVolumeDown
void setVolumeDown()
Definition: KT0915.cpp:272
KT0915::getDeviceId
uint16_t getDeviceId()
Gets the Device Id.
Definition: KT0915.cpp:82
kt09xx_userstartch::raw
uint16_t raw
Definition: KT0915.h:416
KT0915::setVolumeDialModeOff
void setVolumeDialModeOff()
Turns the Volume Dial Mode interface Off.
Definition: KT0915.cpp:245
KT0915::frequencyUp
void frequencyUp()
Increments the frequency one step.
Definition: KT0915.cpp:489
KT0915::setVolumeDialModeOn
void setVolumeDialModeOn()
Sets Volume Dial Mode Interface On.
Definition: KT0915.cpp:231
KT0915::setFrequency
void setFrequency(uint32_t frequency)
Sets the current frequency.
Definition: KT0915.cpp:459
KT0915::setDeEmphasis
void setDeEmphasis(uint8_t value)
Sets the De-emphasis Time Constant Selection.
Definition: KT0915.cpp:370
KT0915::setTuneDialModeOff
void setTuneDialModeOff()
Turns the Tune Dial Mode interface Off.
Definition: KT0915.cpp:209
KT0915::frequencyDown
void frequencyDown()
Decrements the frequency one step.
Definition: KT0915.cpp:505
kt09xx_statusc::raw
uint16_t raw
Definition: KT0915.h:257
KT0915::setVolume
void setVolume(uint8_t value)
Sets the audio volume level.
Definition: KT0915.cpp:258
kt09xx_rxcfg::raw
uint16_t raw
Definition: KT0915.h:206
kt09xx_tune::raw
uint16_t raw
Definition: KT0915.h:120
kt09xx_amdstatusa::raw
uint16_t raw
Definition: KT0915.h:370
KT0915::setup
void setup(int enable_pin, uint8_t oscillator_type=OSCILLATOR_32KHZ, uint8_t ref_clock=REF_CLOCK_DISABLE)
Receiver startup.
Definition: KT0915.cpp:322