PU2CLR QN8066 Arduino Library 1.3.0
Arduino Library for QN8066Devices - By Ricardo Lima Caratti
Loading...
Searching...
No Matches
QN8066.h
Go to the documentation of this file.
1/**
2 * @brief QN8066 ARDUINO LIBRARY
3 *
4 * @details This is an Arduino library for the QN8066 FM RX/TX device (Digital FM Transceiver for Portable Devices).
5 * @details The communication used by this library is I2C.
6 * @details This file contains: const (#define), Defined Data type and Methods declarations
7 * @details You can see a complete documentation on <https://github.com/pu2clr/QN8066>
8 * @details There are examples that can help you in your project on <https://github.com/pu2clr/QN8066/tree/master/examples>
9 * @see [General Documentation](https://pu2clr.github.io/QN8066/)
10 *
11 * @author PU2CLR - Ricardo Lima Caratti
12 * @date 2024
13 */
14
15#ifndef _QN8066_H // Prevent this file from being compiled more than once
16#define _QN8066_H
17
18#include <Arduino.h>
19#include <Wire.h>
20
21#define QN8066_I2C_ADDRESS 0x21 // See Datasheet pag. 16.
22#define QN8066_RESET_DELAY 1000 // Delay after reset in us
23#define QN8066_DELAY_COMMAND 2500 // Delay after command
24
25/**
26 * @brief QN8066 Register addresses
27 *
28 */
29#define QN_SYSTEM1 0x00 //<! Sets device modes.
30#define QN_SYSTEM2 0x01 //<! Sets external clock type and CCA parameters.
31#define QN_CCA 0x02 //<! Sets CCA parameters.
32#define QN_SNR 0x03 //<! Estimate RF input CNR value
33#define QN_RSSISIG 0x04 //<! In-band signal RSSI dBµ V value.
34#define QN_CID1 0x05 //<! Device ID numbers.
35#define QN_CID2 0x06 //<! Device ID numbers.
36#define QN_XTAL_DIV0 0x07 //<! Frequency select of reference clock source.
37#define QN_XTAL_DIV1 0x08 //<! Frequency select of reference clock source.
38#define QN_XTAL_DIV2 0x09 //<! Frequency select of reference clock source.
39#define QN_STATUS1 0x0A //<! System status.
40#define QN_RX_CH 0x0B //<! Lower 8 bit of 10-bit receiver channel index.
41#define QN_CH_START 0x0C //<! Lower 8 bits of 10-bit channel scan start channel index.
42#define QN_CH_STOP 0x0D //<! Lower 8 bits of 10-bit channel scan stop channel index.
43#define QN_CH_STEP 0x0E //<! Channel scan frequency step. Highest 2 bits of receiver channel indexes.
44#define QN_RX_RDSD0 0x0F //<! RDS data byte 0.
45#define QN_RX_RDSD1 0x10 //<! RDS data byte 1.
46#define QN_RX_RDSD2 0x11 //<! RDS data byte 2.
47#define QN_RX_RDSD3 0x12 //<! RDS data byte 3.
48#define QN_RX_RDSD4 0x13 //<! RDS data byte 4.
49#define QN_RX_RDSD5 0x14 //<! RDS data byte 5.
50#define QN_RX_RDSD6 0x15 //<! RDS data byte 6.
51#define QN_RX_RDSD7 0x16 //<! RDS data byte 7.
52#define QN_STATUS2 0x17 //<! Receiver RDS status indicators.
53#define QN_VOL_CTL 0x18 //<! Audio volume control.
54#define QN_INT_CTRL 0x19 //<! Receiver RDS control
55#define QN_STATUS3 0x1A //<! Receiver audio peak level and AGC status.
56#define QN_TXCH 0x1B //<! Lower 8 bit of 10-bit transmitter channel index.
57#define QN_TX_RDSD0 0x1C //<! Transmit RDS data byte0.
58#define QN_TX_RDSD1 0x1D //<! Transmit RDS data byte1.
59#define QN_TX_RDSD2 0x1E //<! Transmit RDS data byte2.
60#define QN_TX_RDSD3 0x1F //<! Transmit RDS data byte3.
61#define QN_TX_RDSD4 0x20 //<! Transmit RDS data byte4
62#define QN_TX_RDSD5 0x21 //<! Transmit RDS data byte5
63#define QN_TX_RDSD6 0x22 //<! Transmit RDS data byte6
64#define QN_TX_RDSD7 0x23 //<! Transmit RDS data byte7
65#define QN_PAC 0x24 //<! PA output power target control.
66#define QN_FDEV 0x25 //<! Specify total TX frequency deviation.
67#define QN_RDS 0x26 //<! Specify transmit RDS frequency deviation.
68#define QN_GPLT 0x27 //<! Transmitter soft chip threshold, gain of TX pilot.
69#define QN_REG_VGA 0x28 //<! TX AGC gain.
70#define QN_REGISTER_6E 0x6E //<! This register is not documented in the Data Sheet. However, according to tests and observations, it seems to affect the quality and stability of the audio.
71#define QN_REGISTER_49 0x49 //<! This register is not documented in the Data Sheet. However, according to observations, it makes the system more stable (not sure)
72
73/** @defgroup group00 Union, Struct and Defined Data Types
74 * @section group01 Data Types
75 *
76 * @brief QN8066 data representation
77 *
78 * @details
79 *
80 */
81
82/**
83 * @ingroup group00
84 *
85 * @brief System1 - Sets device modes (Address: 00h)
86 *
87 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
88 * Devices, pag. 19
89 */
90
91typedef union {
92 struct {
93 uint8_t cca_ch_dis : 1; //!< 0 = RX_CH is decided by internal CCA; 1 = RX_CH is decided writing in RX_CH[9:0]
94 uint8_t ccs_ch_dis : 1; //!< 0 = TX_CH is decided by internal CCS; 1 = TX_CH is decided writing in TX_CH[9:0]
95 uint8_t chsc : 1; //!< Channel Scan mode enable - 0 = Normal operation; 1 = Channel Scan mode operation
96 uint8_t txreq : 1; //!< Transmission request - 0 = Non TX mode; 1 = Enter transmit mode
97 uint8_t rxreq : 1; //!< Receiving request - 0 = Non RX mode; 1 = Enter Receiving mode
98 uint8_t stnby : 1; //!< Request Immediately enter Standby mode whatever state chip is in - 0 = Non standby mode; 1 = Enter standby mode
99 uint8_t recal : 1; //!< Reset the state to initial states and recalibrate all blocks - 0 = No action. FSM runs normally; 1 = Reset the FSM. After this bit is de-asserted, FSM will go through all the power up and calibration sequence.
100 uint8_t swrst : 1; //!< Reset all registers to default values; 0 = Keep the current value; 1 = Reset to default values
101 } arg;
103} qn8066_system1;
104
105/**
106 * @ingroup group00
107 *
108 * @brief System2 - Sets device modes (Address: 01h)
109 *
110 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
111 * Devices, pag. 20
112 */
113
114typedef union {
115 struct {
116 uint8_t tc : 1; //!< Pre-emphasis and de-emphasis time constant; 0 = 50; 1 = 75
117 uint8_t rdsrdy : 1; //!< RDS transmitting ready; - If user want the chip transmitting all the 8 bytes in RDS0~RDS7, user should toggle this bit.
118 uint8_t tx_mute : 1; //!< TX audio mute enabel - 0 = Mute Disabled; 1 = Mute Enabled;
119 uint8_t rx_mute : 1; //!< RX audio Mute enable - 0 = Mute Disabled; 1 = Mute Enabled
120 uint8_t tx_mono : 1; //!< TX stereo and mono mode selection; 0 = Stereo; 1 = Mono
121 uint8_t force_mo : 1; //!< Force receiver in MONO mode; 0 = Not forced. ST/MONO auto selected; Forced in MONO mode
122 uint8_t tx_rdsen : 1; //!< Transmitter RDS enable; 0 = RDS Disable; 1 = RDS Enable
123 uint8_t rx_rdsen : 1; //!< Receiver RDS enable; 0 = RDS Disable; 1 = RDS Enable
124 } arg;
126} qn8066_system2;
127
128/**
129 * @ingroup group00
130 *
131 * @brief CCA - Sets CCA parameters ( Address: 02h)
132 *
133 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
134 * Devices, pag. 21
135 */
136
137typedef union {
138 struct {
139 uint8_t SNR_CCA_TH : 6; //!< The threshold for determination of whether current channel is valid by check its SNR.
140 uint8_t imr : 1; //!< Image Rejection. 0 = LO<RF, image is in lower side; 1 = LO>RF, image is in upper side
141 uint8_t xtal_inj : 1; //!< Select the reference clock source. 0 = Inject sine-wave clock; 1 = Inject digital clock
142 } arg;
144} qn8066_cca;
145
146/**
147 * @ingroup group00
148 *
149 * @brief SRN - Estimate RF input CNR value( Address: 03h - Read Only)
150 * @details Estimated RF input SNR.
151 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
152 * Devices, pag. 21
153 */
154
155typedef union {
158} qn8066_snr;
159
160/**
161 * @ingroup group00
162 *
163 * @brief RSSISIG - In-band signal RSSI (Received signal strength indicator)
164 * dBuV value. dBuV=RSSI-49( Address: 04h - Read Only)
165 *
166 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
167 * Devices, pag. 22
168 */
169
170typedef union {
173} qn8066_rssisig;
174
175/**
176 * @ingroup group00
177 *
178 * @brief CID1 - Device ID numbers ( Address: 05h - Read Only)
179 *
180 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
181 * Devices, pag. 22
182 */
183
184typedef union {
185 struct {
186 uint8_t CID2 : 2; //!< Chip ID for minor revision: 1~4
187 uint8_t CID1 : 3; //!< Chip ID for product family: 000 = FM; others Reserved
188 uint8_t RSVD : 3; //!< Reserved
189 } arg;
191} qn8066_cid1;
192
193/**
194 * @ingroup group00
195 *
196 * @brief CID2 - Device ID numbers ( Address: 06h - Read Only)
197 *
198 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
199 * Devices, pag. 22
200 */
201
202typedef union {
203 struct {
204 uint8_t CID4 : 2; //!< Sequency integer values from 0 to 4.
205 uint8_t CID3 : 6; //!< Chip ID for product ID. 001101 = Transceiver – QN8066; Others = Reserved unkown
206 } arg;
208} qn8066_cid2;
209
210/**
211 * @ingroup group00
212 *
213 * @brief XTAL_DIV0 - Frequency select of reference clock source (Lower bits -
214 * Address: 07h - Write Only)
215 *
216 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
217 * Devices, pag. 23
218 */
219
220typedef union {
221 uint8_t xtal_div; // !< Lower 8 bits of xtal_div[10:0]. Xtal_div[10:0] = round(freq of xtal/32.768KHz).
223} qn8066_xtal_div0;
224
225/**
226 * @ingroup group00
227 *
228 * @brief XTAL_DIV1 - Frequency select of reference clock source (Lower bits -
229 * Address: 08h - Write Only)
230 *
231 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
232 * Devices, pag. 23
233 */
234
235typedef union {
236 struct {
237 uint8_t xtal_div : 3; //!< Higher 3 bits of xtal_div[10:0]. Xtal_div[10:0] = round(freq of xtal/32.768KHz)
238 uint8_t pll_dlt : 5; //!< Lower 5 bits of pll_dlt[12:0].
239 } arg;
241} qn8066_xtal_div1;
242
243/**
244 * @ingroup group00
245 *
246 * @brief XTAL_DIV2 - Frequency select of reference clock source (Lower bits -
247 * Address: 09h - Write Only)
248 *
249 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
250 * Devices, pag. 23
251 */
252
253typedef union {
256} qn8066_xtal_div2;
257
258/**
259 * @ingroup group00
260 *
261 * @brief STATUS1 - System status ( Address: 0Ah - Read Only)
262 *
263 * | FSM Status | Description |
264 * | ---------- | ------------ |
265 * | 0 - 0000 | STBY |
266 * | 1 - 0001 | RESET |
267 * | 2 - 0010 | CALI |
268 * | 3 - 0011 | IDLE |
269 * | 4 - 0100 | CALIPLL |
270 * | 5 - 0101 | Reserved |
271 * | 6 - 0110 | Reserved |
272 * | 7 - 0111 | TXPLLC |
273 * | 8 - 1000 | TX_RSTB |
274 * | 9 - 1001 | PACAL |
275 * | 10 - 1010 | TRANSMIT |
276 * | 11 - 1011 | TXCCA |
277 * | Others | Reserved |
278 *
279 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
280 * Devices, pag. 24
281 */
282
283typedef union {
284 struct {
285 uint8_t ST_MO_RX : 1; //!<< Stereo receiving status. 0 = Stereo; 1 = Mono
286 uint8_t RXSTATUS : 1; //!<< RX Status. 0 = No receiving; 1 = Receiving
287 uint8_t RXAGCSET : 1; //!<< RX AGC Settling status. 0 = Not settled; 1 = Settled
288 uint8_t rxcca_fail : 1; //!<< RXCCA status flag. To indicate whether a valid channel is found during RX CCA. 0 = RX CCA success to find a valid channel; 1 = RX CCA fail to find a valid channel
289 uint8_t FSM : 4; //!<< Top FSM state code
290 } arg;
292} qn8066_status1;
293
294/**
295 * @ingroup group00
296 *
297 * @brief RX_CH - Lower 8 bit of 10-bit receiver channel index (Address: 0Bh -
298 * Write Only)
299 * @details Channel used for RX have two origins, one is from RXCH register
300 * (REG0EH[1:0]+REG0BH)
301 * @details which can be written by the user, another is from CCA. CCA selected
302 * channel is stored in an internal register, which is
303 * @details physically a different register with CH register, but it can be read
304 * out through register CH and be used for RX when
305 * @details CCA_CH_DIS(REG0[0])=0.
306 * @details FM channel: (60+RXCH*0.05)MHz
307 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
308 * Devices, pag. 25
309 */
310
311typedef union {
314} qn8066_rx_ch;
315
316/**
317 * @ingroup group00
318 *
319 * @brief CH_START - Lower 8 bits of 10-bit CCA(channel scan) start channel
320 * index (Address: 0Ch - Write Only)
321 *
322 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
323 * Devices, pag. 25
324 */
325
326typedef union {
329} qn8066_ch_start;
330
331/**
332 * @ingroup group00
333 *
334 * @brief CH_STOP - Lower 8 bits of 10-bit channel scan stop channel index
335 * (Address: 0Dh - Write Only)
336 *
337 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
338 * Devices, pag. 25
339 */
340
341typedef union {
344} qn8066_ch_stop;
345
346/**
347 * @ingroup group00
348 *
349 * @brief CH_STEP - Channel scan frequency step (Address: 0Eh - Write Only)
350 *
351 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
352 * Devices, pag. 26
353 */
354
355typedef union {
356 struct {
357 uint8_t RXCH : 2; //!< Highest 2 bits of 10-bit channel index. Channel freq is (60+RXCH*0.05)MHz
358 uint8_t CH_STA : 2; //!< Highest 2 bits of 10-bit CCA(channel scan) start channel index. Start freq is (60+RXCH_STA*0.05)MHz
359 uint8_t CH_STP : 2; //!< Highest 2 bits of 10-bit CCA(channel scan) stop channel index. Stop freq is (60+RXCH_STP*0.05)MHz
360 uint8_t CH_FSTEP : 2; //!< CCA (channel scan) frequency step. 00=50kHz; 01=100kHz; 10 = 200kHz; 11=Reserved
361 } arg;
363} qn8066_ch_step;
364
365/**
366 * @ingroup group00
367 *
368 * @brief RDS - RDS data byte 0 to byte 7 (Address: 0Fh to 16h - Read Only)
369 *
370 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
371 * Devices, pag. 26-28
372 */
373
374typedef union {
375 struct {
376 uint8_t RX_RDSD0; //!< RDS data byte 0 - 0Fh
377 uint8_t RX_RDSD1; //!< RDS data byte 1 - 10h
378 uint8_t RX_RDSD2; //!< RDS data byte 2 - 11h
379 uint8_t RX_RDSD3; //!< RDS data byte 3 - 12h
380 uint8_t RX_RDSD4; //!< RDS data byte 4 - 13h
381 uint8_t RX_RDSD5; //!< RDS data byte 5 - 14h
382 uint8_t RX_RDSD6; //!< RDS data byte 6 - 15h
383 uint8_t RX_RDSD7; //!< RDS data byte 7 - 16h
384 } arg;
386} qn8066_rx_rds;
387
388/**
389 * @ingroup group00
390 *
391 * @brief STATUS2 - Receiver RDS status indicators (Address: 17h - Read Only)
392 *
393 * @details RDS_RXUPD - RDS RX: RDS received group updated. Each time a new
394 * group is received, this bit will be toggled.
395 * @details If RDS_INT_EN=1, then at the same time this bit is
396 * toggled, interrupt output will out put a 4.5 ms low pulse
397 * @details 0->1 or 1->0 -> A new set (8 Byte) of data is received
398 * @details 0->0 or 1->1 -> New data is in receiving
399 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
400 * Devices, pag. 28-29
401 */
402
403typedef union {
404 struct {
405 uint8_t RDS3ERR : 1; //!< 0 = No Error
406 uint8_t RDS2ERR : 1; //!< 0 = No Error
407 uint8_t RDS1ERR : 1; //!< 0 = No Error
408 uint8_t RDS0ERR : 1; //!< 0 = No Error
409 uint8_t RDSSYNC : 1; //!< RDS block synchronous indicator. 0 = Non-synchronous; 1 = Synchronous
410 uint8_t RDSC0C1 : 1; //!< Type indicator of the RDS third block in one group. 0 = C0; 1 = C1
411 uint8_t E_DET : 1; //!< ‘E’ block (MMBS block) detected. 0 = Not detected; 1 = Detected
412 uint8_t RDS_RXUPD : 1; //!< RDS received group updated. Each time a new group is received, this bit will be toggled. See comment above.
413 } arg;
415} qn8066_status2;
416
417/**
418 * @ingroup group00
419 *
420 * @brief VOL_CT - Audio volume control (Address: 18h - Write Only)
421 *
422 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
423 * Devices, pag. 29
424 */
425
426typedef union {
427 struct {
428 uint8_t GAIN_ANA : 3; //!< set volume control gain of analog portion. From 0 to 7
429 uint8_t GAIN_DIG : 3; //!< set digital volume gain. From 0 to 5
430 uint8_t DAC_HOLD : 1; //!< DAC output control. 0 = Normal operation; 1 = Hold DAC output to a fixed voltage.
431 uint8_t TX_DIFF : 1; //!< Tx audio input mode selection. 0 = Single ended; 1 = Differential.
432 } arg;
434} qn8066_vol_ctl;
435
436/**
437 * @ingroup group00
438 *
439 * @brief INT_CTRL - Receiver RDS control (Address: 19h - Write Only)
440 *
441 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
442 * Devices, pag. 30
443 */
444
445typedef union {
446 struct {
447 uint8_t TXCH : 2; //!< Highest 2 bits of 10-bit channel index. hannel freq
448 //!< is (60+TXCH*0.05)MHz
449 uint8_t priv_mode : 1; //!< Private mode for RX/TX
450 uint8_t
451 rds_4k_mode : 1; //!< Enable RDS RX/TX 4k Mode: with or without the
452 //!< privacy mode (audio scramble and RDS encryption)
453 uint8_t s1k_en : 1; //!< Internal 1K tone selection. It will be used as DAC
454 //!< output when RXREQ. 0 = Disabled; 1 = Enabled
455 uint8_t rds_only : 1; //!< RDS Mode Selection. 0 = Received bit-stream have
456 //!< both RDS and MMBS blocks (‘E’ block); 1 =
457 //!< Received bit-stream has RDS block only, no MMBS
458 //!< block (‘E’ block)
459 uint8_t cca_int_en : 1; //!< RX CCA interrupt enable. When CCA_INT_EN=1,
460 //!< a 4.5ms low pulse will be output from pad din
461 //!< (RX mode) when a RXCCA (RX mode) is finished. 0
462 //!< = Disabled; 1 = Enabled
463 uint8_t
464 rds_int_en : 1; //!< RDS RX interrupt enable. When RDS_INT_EN=1, a 4.5ms
465 //!< low pulse will be output from pad din (RX mode)
466 //!< when a new group data is received and stored into
467 //!< RDS0~RDS7 (RX mode). 0 = Disabled; 1 = Enabled
468 } arg;
470} qn8066_int_ctrl;
471
472/**
473 * @ingroup group00
474 *
475 * @brief STATUS3 - Receiver audio peak level and AGC status (Address: 1Ah -
476 * Read Only)
477 *
478 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
479 * Devices, pag. 30-31
480 */
481
482typedef union {
483 struct {
484 uint8_t rsvd : 1; //!< Reserved
485 uint8_t rxagcerr : 1; //!< RXAGC Error Flag. 0 = No Error; 1 = Error
486 uint8_t
487 RDS_TXUPD : 1; //!< RDS TX: To transmit the 8 bytes in RDS0~RDS7, user
488 //!< should toggle the register bit RDSRDY. Then the chip
489 //!< internally fetches these bytes after completing
490 //!< transmitting of current group. Once the chip
491 //!< internally fetched these bytes, it will toggle this
492 //!< bit, and user can write in another group.
493 uint8_t aud_pk : 4; //!< Audio peak value at ADC input is aud_pk * 45mV
494 uint8_t CAP_SH : 1; //!< Large CAP short detection flag. 1 indicates a
495 //!< short. This bit is the OR-ed result of Poly phase
496 //!< filter I path and Poly phase filter Q path.
497 } arg;
499} qn8066_status3;
500
501/**
502 * @ingroup group00
503 *
504 * @brief TXCH - Lower 8 bit of 10-bit transmitter channel index (Address: 1Bh -
505 * Read and Write)
506 * @details Lower 8 bits of 10-bit Channel index. Channel used for TX have two
507 * origins, one is from TXCH register (REG19H[1:0]+REG1BH) which can be written
508 * by the user,
509 * @details another is from CCS. CCS selected channel is stored in an internal
510 * register, which is physically a different register with TXCH register, but it
511 * can be read out through
512 * @details register TXCH and be used for TX when CCS_CH_DIS(REG0[0])=0. FM
513 * channel: (60+TXCH*0.05)MHz
514 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
515 * Devices, pag. 31
516 */
517
518typedef union {
521} qn8066_txch;
522
523/**
524 * @ingroup group00
525 *
526 * @brief RDS - RDS tx data from byte 0 to byte 7 (Address: 1Ch to 23h - Write
527 * Only)
528 *
529 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
530 * Devices, pag. 31-33
531 */
532
533typedef union {
534 struct {
535 uint8_t TX_RDSD0; //!< RDS data byte 0 - 0Fh
536 uint8_t TX_RDSD1; //!< RDS data byte 1 - 10h
537 uint8_t TX_RDSD2; //!< RDS data byte 2 - 11h
538 uint8_t TX_RDSD3; //!< RDS data byte 3 - 12h
539 uint8_t TX_RDSD4; //!< RDS data byte 4 - 13h
540 uint8_t TX_RDSD5; //!< RDS data byte 5 - 14h
541 uint8_t TX_RDSD6; //!< RDS data byte 6 - 15h
542 uint8_t TX_RDSD7; //!< RDS data byte 7 - 16h
543 } arg;
545} qn8066_tx_rds;
546
547/**
548 * @ingroup group00
549 *
550 * @brief PAC - PA output power target control (Address: 24h - Write Only)
551 * @details PA_TRGT - PA output power target is 0.91*PA_TRGT+70.2dBu. Valid
552 * values are 24-56.
553 * @details TXPD_CLR - TX aud_pk clear signal. Audio peak value is max-hold
554 * and stored in aud_pk[3:0]. Once TXPD_CLR is toggled, the aud_pk value is
555 * cleared and restarted again.
556 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
557 * Devices, pag. 33
558 */
559
560typedef union {
561 struct {
562 uint8_t PA_TRGT : 7; //!< PA output power target is 0.91*PA_TRGT+70.2dBu.
563 //!< Valid values are 24-56.
564 uint8_t
565 TXPD_CLR : 1; //!< TX aud_pk clear signal. Audio peak value is max-hold
566 //!< and stored in aud_pk[3:0]. Once TXPD_CLR is toggled,
567 //!< the aud_pk value is cleared and restarted again.
568 } arg;
570} qn8066_pac;
571
572/**
573 * @ingroup group00
574 *
575 * @brief FDEV - Specify total TX frequency deviation (Address: 25h - Write
576 * Only)
577 * @details Specify total TX frequency deviation. TX frequency deviation =
578 * 0.69KHz*TX_FEDV. From 0 to 255
579 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
580 * Devices, pag. 33
581 */
582
583typedef union {
584 uint8_t TX_FDEV; //!< Specify total TX frequency deviation. TX frequency
585 //!< deviation = 0.69KHz*TX_FEDV. From 0 to 255
587} qn8066_fdev;
588
589/**
590 * @ingroup group00
591 *
592 * @brief RDS - Specify transmit RDS frequency deviation (Address: 26h - Write
593 * Only)
594 * @details RDSFDEV - RDS frequency deviation = 0.35KHz*RDSFDEV in normal mode.
595 * RDS frequency deviation = 0.207KHz*RDSFDEV in 4k mode and private mode.
596 * Values = from 0 to 127
597 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
598 * Devices, pag. 34
599 */
600
601typedef union {
602 struct {
603 uint8_t RDSFDEV : 7; //!< RDS frequency deviation = 0.35KHz*RDSFDEV in normal mode. RDS frequency deviation = 0.207KHz*RDSFDEV in 4k mode and private mode. Values = from 0 to 127
604 uint8_t line_in_en : 1; //!< Audio Line-in enable control. 0 = Disable; 1 = Enable
605 } arg;
607} qn8066_rds;
608
609/**
610 * @ingroup group00
611 *
612 * @brief GPLT - Transmitter soft chip threshold, gain of TX pilot (Address: 27h
613 * - Write Only)
614 *
615 * | GAIN_TXPLT | value |
616 * | ---------- | ----- |
617 * | 7 - 0111 | 7% * 75KHz |
618 * | 8 - 1000 | 8% * 75KHz |
619 * | 9 - 1001 | 9% * 75KHz |
620 * | 10 - 1010 | 10% * 75KHz |
621 *
622 * | t1m_sel | value |
623 * | ---------- | ----- |
624 * | 0 - 00 | 57s |
625 * | 1 - 01 | 58s |
626 * | 2 - 10 | 59s |
627 * | 3 - 11 | Infinity (Never) |
628 *
629 * | tx_sftclpth | value |
630 * | ---------- | ----- |
631 * | 0 - 00 | 12’d2051 (3db back off from 0.5v) |
632 * | 1 - 01 | 12’d1725 (4.5db back off from 0.5v) |
633 * | 2 - 10 | 12’d1452 (6db back off from 0.5v) |
634 * | 3 - 11 | 12’d1028 (9db back off from 0.5v) |
635 *
636 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
637 * Devices, pag. 34
638 */
639
640typedef union {
641 struct {
642 uint8_t GAIN_TXPLT : 4; //!< Gain of TX pilot to adjust pilot frequency deviation. Refer to peak frequency deviation of MPX signal when audio input is full scale.
643 uint8_t t1m_sel : 2; //!< Selection of 1 minute time for PA off when no audio.
644 uint8_t tx_sftclpth : 2; //!< TX soft clip threshold
645 } arg;
647} qn8066_gplt;
648
649/**
650 * @ingroup group00
651 *
652 * @brief REG_VGA - X AGC gain (Address: 28h - Read and Write)
653 * @details Attenuation/Gain depending on RIN - 0, 1, 2 AND 3 RESPECTIVELY. See tables below.
654 * | RIN | Input impedance (K Ohoms) |
655 * | ---------- | ------------------------- |
656 * | 0 - 00 | 10 |
657 * | 1 - 01 | 20 |
658 * | 2 - 10 | 40 |
659 * | 3 - 11 | 80 |
660 *
661 * | TXAGC_GDB | TX digital gain |
662 * | ---------- | ----- |
663 * | 0 - 00 | 0 dB |
664 * | 1 - 01 | 1 dB |
665 * | 2 - 10 | 2 dB |
666 * | 3 - 11 | Reserved |
667 *
668 * | TXAGC_GVGA | Attenuation/Gain depending on RIN - 0, 1, 2 AND 3 RESPECTIVELY |
669 * | ---------- | ---------------------------------------------------------- |
670 * | 0 - 000 | 3; -3; -9; -15 |
671 * | 1 - 001 | 6; 0; -6; -12 |
672 * | 2 - 010 | 9; 3; -3; -9 |
673 * | 3 - 011 | 12; 6; 0; -6 |
674 * | 4 - 100 | 15; 9; 3; -3 |
675 * | 5 - 101 | 18; 12; 6; 0 |
676 * | Others | Reserved |
677 *
678 *
679 * @see Data Sheet - Quintic - QN8066 - Digital FM Transceiver for Portable
680 * Devices, pag. 35
681 *
682 */
683
684typedef union {
685 struct {
686 uint8_t RIN : 2; //!< TX mode input impedance for both L/R channels. See
687 //!< table above
688 uint8_t TXAGC_GDB : 2; //!< TX digital gain. See table above.
689 uint8_t TXAGC_GVGA : 3; //!< TX input buffer gain. See table above
690 uint8_t tx_sftclpen : 1; //!< TX soft clipping enable
691 } arg;
693} qn8066_reg_vga;
694
695
696/**
697 * @ingroup group00 RDS
698 * @brief RDS - First block (RDS_BLOCK1 datatype)
699 * @details PI Code Function: Identifies the radio station. This code is essential
700 * @details for allowing receivers to identify the source of the radio signal.
701 */
702typedef union {
703 struct {
704 uint8_t reference : 7 ;
705 uint8_t programId : 4 ;
706 uint8_t countryId : 4 ;
707 } field;
708 unsigned char byteContent[2];
709 uint16_t pi; // pi Code
710} RDS_BLOCK1;
711
712
713
714/**
715 * @ingroup group00 RDS
716 *
717 * @brief Block 2 (RDS_BLOCK2 data type)
718 * @details Specifies the type of data being transmitted and includes information such as
719 * @details program type (e.g., news, music) and whether the station transmits traffic information.
720 * @details The table below show some program types you can use to check your transmitter.
721 * | PTY Code | Program Type |
722 * | ----------| ------------ |
723 * | 0 | No PTY (undefined) |
724 * | 1 | News |
725 * | 3 | Information |
726 * | 4 | Sport |
727 * | 5 | Education |
728 * | 7 | Culture |
729 * | 8 | Science |
730 * | 10 | Pop Music |
731 * | 11 | Rock Music |
732 * | 15 | Other Music |
733 * | 16 | Weather |
734 * | 17 | Finance |
735 * | 18 | Children's Programs |
736 * | 20 | Religion |
737 * | 24 | Jazz Music |
738 * | 25 | Country Music |
739 * | 26 | National Music |
740 * | 27 | Oldies Music |
741 * | 28 | Folk Music |
742 * | 29 | Documentary |
743 * | 31 | Alarm |
744 *
745 * @details For GCC on System-V ABI on 386-compatible (32-bit processors), the following stands:
746 * 1) Bit-fields are allocated from right to left (least to most significant).
747 * 2) A bit-field must entirely reside in a storage unit appropriate for its declared type.
748 * Thus a bit-field never crosses its unit boundary.
749 * 3) Bit-fields may share a storage unit with other struct/union members, including members that are not bit-fields.
750 * Of course, struct members occupy different parts of the storage unit.
751 * 4) Unnamed bit-fields' types do not affect the alignment of a structure or union, although individual
752 * bit-fields' member offsets obey the alignment constraints.
753 * @see also https://en.wikipedia.org/wiki/Radio_Data_System
754 *
755 */
756
757typedef union
758{
759 struct
760 {
761 uint16_t additionalData : 4; //!< Additional data bits, depending on the group.
762 uint16_t textABFlag : 1; //!< Do something if it chanhes from binary "0" to binary "1" or vice-versa
763 uint16_t programType : 5; //!< PTY (Program Type) code
764 uint16_t trafficProgramCode : 1; //!< (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
765 uint16_t versionCode : 1; //!< (B0) => 0=A; 1=B
766 uint16_t groupType : 4; //!< Group Type code.
767 } commonFields;
768
769 struct
770 {
771 uint16_t address : 2; //!< Depends on Group Type and Version codes. If 0A or 0B it is the Text Segment Address.
772 uint16_t DI : 1; //!< Decoder Control bit
773 uint16_t MS : 1; //!< Music/Speech
774 uint16_t TA : 1; //!< Traffic Announcement
775 uint16_t programType : 5; //!< PTY (Program Type) code
776 uint16_t trafficProgramCode : 1; //!< (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
777 uint16_t versionCode : 1; //!< (B0) => 0=A; 1=B
778 uint16_t groupType : 4; //!< Group Type code.
779 } group0Field;
780
781 struct
782 {
783 uint16_t address : 4; //!< Depends on Group Type and Version codes. If 2A or 2B it is the Text Segment Address.
784 uint16_t textABFlag : 1; //!< Do something if it changes from binary "0" to binary "1" or vice-versa
785 uint16_t programType : 5; //!< PTY (Program Type) code
786 uint16_t trafficProgramCode : 1; //!< (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
787 uint16_t versionCode : 1; //!< (B0) => 0=A; 1=B
788 uint16_t groupType : 4; //!< Group Type code.
789 } group2Field;
790 unsigned char byteContent[2];
791 uint16_t raw; //!< Raw 16-bit representation
792} RDS_BLOCK2;
793
794/**
795 * @ingroup group00 RDS
796 * @brief Block 3 (RDS_BLOCK3 data type)
797 */
798typedef union {
799 unsigned char byteContent[2];
801} RDS_BLOCK3;
802
803/**
804 * @ingroup group00 RDS
805 * @brief Block 4 (RDS_BLOCK4 data type)
806 */
807typedef union {
808 unsigned char byteContent[2];
809 struct {
810 uint16_t offset: 5; //!< Local Time Offset
811 uint16_t offset_sign: 1; //!< Offset sign (+/-)
812 uint16_t min: 6; //!< UTC Minutes (0–59)
813 uint16_t hour: 4; //!< Four least significant bits of the hour - UTC Hours (0–23)
814 } utc;
816} RDS_BLOCK4;
817
818typedef union
819{
820 struct
821 {
822 uint32_t offset : 5; //!< Local Time Offset
823 uint32_t offset_sense : 1; //!< Local Offset Sign ( 0 = + , 1 = - )
824 uint32_t minute : 6; //!< UTC Minutes
825 uint32_t hour : 5; //!< UTC Hours
826 uint32_t mjd : 17; //!< Modified Julian Day Code
827 } arg;
829} RDS_DATE_TIME;
830
831
832typedef union {
835} WORD16;
836
837
838/**
839 * @ingroup CLASSDEF
840 * @brief QN8066 Class
841 * @details This class implements all functions that will help you to control
842 * the QN8066 devices.
843 *
844 * @author PU2CLR - Ricardo Lima Caratti
845 */
846class QN8066 {
847private:
848 uint16_t resetDelay = 1000; //!<< Delay after reset (default 1s)
849 uint16_t xtal_div = 1000;
850
851 qn8066_system1 system1;
852 qn8066_system2 system2;
853 qn8066_gplt gplt;
854 qn8066_cca cca;
855 qn8066_fdev fdev;
856 qn8066_int_ctrl int_ctrl;
857 qn8066_txch txch;
858 qn8066_xtal_div0 xtal_div0;
859 qn8066_xtal_div1 xtal_div1;
860 qn8066_xtal_div2 xtal_div2;
861 qn8066_reg_vga reg_vga;
862 qn8066_rds rds;
863 qn8066_pac pac;
864 qn8066_vol_ctl vol_ctl;
865
866
867 uint8_t rdsSyncTime = 60; //!< Wait time in milliseconds before sending the next group - Default is 60 ms.
868 uint8_t rdsRepeatGroup = 5; //!< Number of times an RDS group will be transmitted consecutively.
869
870 char rdsStationName[9] = " QN8066\r"; //!< Default Program Station (PS)
871 uint16_t rdsPI = 33179; //!< Default value for piCode (0x819B)
872 uint8_t rdsPTY = 0; //!< The default program type (PTY) is 5, which is "Education" for RDS and "Rock" for RDBS.
873 uint8_t rdsTP = 0; //!< Traffic Program (TP)
874 uint8_t rdsSendError = 0;
875
876 char strRxCurrentFrequency[8]; // Stores formated current frequency
877 uint16_t rxCurrentFrequency;
878 uint8_t rxCurrentStep = 1; //!< current frequency step. Default is 100kHz
879
880 uint16_t minimalFrequency = 639;
881 uint16_t maximalFrequency = 1081;
882
883
884
885protected:
886public:
887 bool detectDevice();
889
891 void setRegister(uint8_t registerNumber, uint8_t value);
892
893 inline qn8066_cid1 getDeviceProductID() {
894 qn8066_cid1 value;
895 value.raw = this->getRegister(QN_CID1);
896 return value;
897 };
898
899 inline qn8066_cid2 getDeviceProductFamily() {
900 qn8066_cid2 value;
901 value.raw = this->getRegister(QN_CID2);
902 return value;
903 }
904
905 qn8066_status1 getStatus1();
906 qn8066_status2 getStatus2();
907 qn8066_status3 getStatus3();
908
909
910 /**
911 * @brief SYSTEM1 SETUP
912 *
913 */
914 void setRX(uint16_t frequency);
915 void setRxFrequency(uint16_t frequency);
916 void setRxFrequencyUp();
917 void setRxFrequencyDown();
918 void setRxFrequencyStep(uint8_t value);
919 inline uint16_t getRxCurrentFrequency(){ return this->rxCurrentFrequency;};
920 void rdsEnableRX(bool value);
921 void setAudioMuteRX(bool value);
924 void setRxFrequencyRange(uint16_t min = 640, uint16_t max = 1080);
925
926 bool isValidRxChannel();
927 bool isRxReceiving();
928 bool isRxAgcStable();
929 bool isRxStereo();
930 void scanRxStation(uint16_t startFrequency, uint16_t stopFrequyency, uint8_t frequencyStep );
931
932 // RX RDS
933 void rdsRxEnable(bool value);
934 char *rdsRxGetPS(char *ps);
935 char *rdsRxGetRT(char *rt);
936 char *rdsRxGetTime(char *time);
937
938
939
940 void setTX(uint16_t frequency); // RESET the system and set to TX mode at a given frequency
941
942 void setTxStereo(bool value = true);
943 void setTxMono(uint8_t value = 0); // Default stereo
945 void setTxPreEmphasis( uint8_t value = 75);
946 void setPreEmphasis(uint8_t value = 1);
947
948 void setTxOffAfterOneMinuteNoAudio(bool value);
949 void setTxOffAfterOneMinute(uint8_t value);
950 void setTxPilotGain(uint8_t value);
951 void setAudioAnalogGain(uint8_t value);
952 void setAudioDigitalGain(uint8_t value);
953 void setAudioDacHold(bool value);
954 void setAudioTxDiff(bool value);
955 void setTxInputImpedance(uint8_t value);
956 void setTxDigitalGain(uint8_t value);
957 void setTxInputBufferGain(uint8_t value);
958 void setTxSoftClippingEnable( bool value);
959 void setTxSoftClipThreshold(uint8_t value);
960 void setTxFrequencyDerivation(uint8_t value);
961
962 void setResetDelay(uint16_t delayAfterReset) {
963 this->resetDelay = delayAfterReset;
964 };
965
966 void begin();
967
968 void setup(uint16_t xtalDiv = 1000,
969 bool mono = false, bool rds = false, uint8_t PreEmphasis = 0,
970 uint8_t xtalInj = 0, uint8_t imageRejection = 1,
971 uint8_t txSoftClipThreshold = 0, uint8_t oneMinutOff = 3, uint8_t gainTxPLT =9,
972 uint8_t txFreqDev = 125, uint8_t rdsLineIn = 0, uint8_t rdsFreqDev = 60,
973 uint8_t inImpedance = 1, uint8_t txAgcDig = 0, uint8_t txAgcBuffer = 1 , uint8_t txSoftClip = 0 );
974
975
976 void updateTxSetup();
977
978
979 void setTxMode(uint8_t value);
980 void stopTransmitting();
981 void startTransmitting();
982
983
984 void setXtal(uint16_t divider, uint8_t xtalInj, uint8_t imageRejection);
985
986 void setPAC(uint8_t PA_TRGT);
987
988 void setToggleTxPdClear();
989
990 /**
991 * @ingroup group04 PA Control
992 * @brief TX Audio peak clear signal.
993 * @details Same setToggleTxPdClear (synonym)
994 * @details Audio peak value is max-hold and stored in aud_pk (see STATUS register). Once TXPD_CLR is toggled, the aud_pk value is cleared and restarted again
995 * @details Example
996 * @code
997 * #include <QN8066.h>
998 * QN8066 tx;
999 * void setup() {
1000 * tx.setup();
1001 * tx.setTX(1069); // Set the transmitter to 106.9 MHz
1002 * ...
1003 * tx.resetAudioPeak();
1004 * }
1005 * void loop() {
1006 * }
1007 * @endcode
1008 */
1010 int getAudioPeakValue();
1011
1012
1013 void setStnby(bool value);
1014
1015
1016 // RDS TX
1017
1018 void rdsSetMode(uint8_t mode);
1019 void rdsSet4KMode(uint8_t value);
1020 void rdsInitTx(uint8_t countryId = 0, uint8_t programId = 0, uint8_t reference = 0, uint8_t pty = 1, uint8_t rdsSyncTime = 60, uint8_t rdsRepeatGroup = 5 );
1021 void rdsSetInterrupt(uint8_t value);
1022
1023 void rdsTxEnable(bool value);
1025 bool rdsGetTxUpdated();
1026 void rdsSetFrequencyDerivation(uint8_t freq = 6);
1027 void rdsSetTxLineIn(bool value = 0);
1028
1029 void rdsSendGroup(RDS_BLOCK1 blockA, RDS_BLOCK2 blockB, RDS_BLOCK3 blockC, RDS_BLOCK4 blockD);
1030 void rdsSendPS(char* ps = NULL);
1031
1032
1033 void rdsSetStationName(char *stationName);
1034 void rdsSendRTMessage(char *rt);
1035 /**
1036 * @ingroup group05 TX RDS
1037 * @brief Sends RDS Radio Text Message (group 2A)
1038 * @details It is a synonym to rdsSendRTMessage. This function repeats sending a group this->rdsRepeatGroup times.
1039 * @param rt - Radio Text (string of 32 character)
1040 * @details Example
1041 * @code
1042 * #include <QN8066.h>
1043 * QN8066 tx;
1044 * void setup() {
1045 * tx.setup();
1046 * tx.setTX(1069); // Set the transmitter to 106.9 MHz
1047 * tx.rdsTxEnable(true);
1048 * delay(100);
1049 * tx.rdsSendRT("IT IS AN EXAMPLE..."); // transmits the message "IT IS AN EXAMPLE..." this->rdsRepeatGroup times
1050 * }
1051 *
1052 * void loop() {
1053 * }
1054 * @endcode
1055 */
1056 inline void rdsSendRT(char *rt) {this->rdsSendRTMessage(rt); };
1057
1059 void rdsSendDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, int8_t offset);
1060
1061
1062
1063 /**
1064 * @ingroup group05 TX RDS
1065 * @brief Sets the Program Identification (PI)
1066 * @details The Program Identification (PI) code is a critical component of the RDS (Radio Data System) protocol.
1067 * @details It is used to uniquely identify the radio station transmitting the RDS data. The PI code is a 16-bit
1068 * @details value (4 hexadecimal digits) assigned to each station.
1069 * @details PI Code Structure
1070 * @details The PI code is a 16-bit binary value (4 hexadecimal digits), and its structure is as follows:
1071 * @details a) Country Identifier (First 4 Bits) - The first 4 bits of the PI code represent the country identifier.
1072 * @details This helps to differentiate stations in different countries. For example, the code 0x1 might represent
1073 * @details one country, while 0x2 represents another.
1074 * @details b) Program Type (Next 4 Bits) - The next 4 bits indicate the program type. This categorizes the type of content
1075 * @details being broadcast, such as music, news, sports, etc.
1076 * @details c) Program Reference Number (Last 8 Bits) - The last 8 bits provide a unique reference number for the specific
1077 * @details station or program.
1078 * @details You can set the PI code using the rdsSetPI. The are three ways of setting PI code:
1079 * @details rdsInitTx(countryId, programId, reference); rdsSetPI(countryId, programId, reference);
1080 * @details rdsSetPI(piCode);
1081 * @see rdsInitTx
1082 * @details Example
1083 * @code
1084 * #include <QN8066.h>
1085 * QN8066 tx;
1086 *
1087 * uint8_t countryId = 0x1;
1088 * uint8_t programId = 0x2;
1089 * uint8_t reference = 0x34;
1090 *
1091 * void setup() {
1092 * tx.setup();
1093 * tx.setTX(1069); // Set the transmitter to 106.9 MHz
1094 * ...
1095 * tx.rdsInitTx(countryId, programId, reference); // You can use this
1096 * ...
1097 * tx.rdsSetPI(countryId, programId, reference); // Or this
1098 * ...
1099 * tx.rdsSetPI(0x1234); // Or this
1100 * }
1101 *
1102 * void loop() {
1103 * }
1104 * @endcode
1105 * @param pi - PI Code
1106 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1107 */
1108 void rdsSetPI(uint16_t pi) {this->rdsPI = pi;};
1109
1110 void rdsSetPI(uint8_t countryId, uint8_t programId, uint8_t reference = 0) ;
1111
1112
1113 /**
1114 * @ingroup group05 TX RDS
1115 * @brief Gets the Program Identification (PI)
1116 * @param pi - PI Code
1117 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1118 */
1119 uint8_t rdsGetPI() {return this->rdsPI;};
1120
1121 /**
1122 * @ingroup group05 TX RDS
1123 * @brief Sets the Program Type (PTY)
1124 * @param pty - Program type
1125 * @see The table of PTY Program Type for RDS and RDBS can be checkd here: https://en.wikipedia.org/wiki/Radio_Data_System
1126 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1127 */
1128 void rdsSetPTY(uint16_t pty) {this->rdsPTY = pty;};
1129
1130 /**
1131 * @ingroup group05 TX RDS
1132 * @brief Gets the Program Type (PTY)
1133 * @param pty - Program type
1134 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1135 */
1136 uint8_t rdsGetPTY() {return this->rdsPTY;};
1137
1138
1139 /**
1140 * @ingroup group05 TX RDS
1141 * @brief Sets the Traffic Program.
1142 * @param tp - tp Code
1143 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1144 */
1145 void rdsSetTP(uint16_t tp) {this->rdsTP = tp;};
1146
1147 /**
1148 * @ingroup group05 TX RDS
1149 * @brief Sets the Traffic Program.
1150 * @param tp - tp Code
1151 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1152 */
1153 uint8_t rdsGetTP() {return this->rdsTP;};
1154
1155
1156 /**
1157 * @ingroup group05 TX RDS
1158 * @brief Gets the Program Station (Station Name).
1159 */
1160 char* rdsGetPS() {return this->rdsStationName;};
1161
1162
1163 /**
1164 * @ingroup group05 TX RDS
1165 * @brief Gets TX RDS error setup
1166 */
1167 uint8_t rdsGetError() {return this->rdsSendError;};
1168
1169 /**
1170 * @ingroup group05 TX RDS
1171 * @brief Clear RDS register (Buffer)
1172 */
1173 void rdsClearBuffer();
1174
1175
1176 /**
1177 * @ingroup group05 TX RDS
1178 * @brief Sets the wait time for the QN8066 to be available to send the next RDS block.
1179 * @details The default time is 60ms, but depending on the microcontroller you are using, it may be necessary to reduce this time.
1180 * @param syncTime - time in ms
1181 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1182 */
1183 inline void rdsSetSyncTime(uint8_t syncTime) {this->rdsSyncTime = syncTime; };
1184
1185 /**
1186 * @ingroup group05 TX RDS
1187 * @brief Sets the number of time that a group will be sent at once
1188 * @details The default value is 5.
1189 * @param count - number of times
1190 * @see rdsSetPI, rdsInitTx, rdsTxEnable, rdsGetPI, rdsSetPTY, rdsGetPTY, rdsSetTP, rdsGetTP rdsSetSyncTime, rdsSetRepeatSendGroup
1191 */
1192 inline void rdsSetRepeatSendGroup (uint8_t count) {this->rdsRepeatGroup = count;};
1193
1194 void resetFsm();
1196
1197 void convertToChar(uint16_t value, char *strValue, uint8_t len, uint8_t dot, uint8_t separator = '.', bool remove_leading_zeros = true);
1198 char* formatCurrentFrequency(char decimalSeparator = ',');
1199
1200/*******************************************************************************
1201 * The functions below modify the clock frequency for I2C communication.
1202 * 100kHz is usually the baseline.
1203 * Use one of these funcition if you have a problem on the default configuration.
1204 *******************************************************************************/
1205
1206 /**
1207 * @ingroup group99 MCU I2C Speed
1208 * @brief Sets I2C bus to 10kHz
1209 */
1210 inline void setI2CLowSpeedMode(void)
1211 {
1212 Wire.setClock(10000);
1213 };
1214
1215 /**
1216 * @ingroup group99 MCU I2C Speed
1217 *
1218 * @brief Sets I2C bus to 100kHz
1219 */
1220 inline void setI2CStandardMode(void) { Wire.setClock(100000); };
1221
1222 /**
1223 * @ingroup group99 MCU I2C Speed
1224 *
1225 * @brief Sets I2C bus to 400kHz
1226 */
1227 inline void setI2CFastMode(void)
1228 {
1229 Wire.setClock(400000);
1230 };
1231
1232 /**
1233 * @ingroup group99 MCU I2C Speed
1234 *
1235 * @brief Sets the I2C bus to a given value.
1236 * ATTENTION: use this function with caution
1237 *
1238 * @param value in Hz. For example: The values 500000 sets the bus to 500kHz.
1239 */
1240 inline void setI2CFastModeCustom(long value = 500000) { Wire.setClock(value); };
1241
1242
1243
1244};
1245#endif // _QN8066_H
#define QN_TX_RDSD1
Definition: QN8066.h:58
#define QN_INT_CTRL
Definition: QN8066.h:54
#define QN_SYSTEM2
Definition: QN8066.h:30
#define QN_STATUS2
Definition: QN8066.h:52
#define QN_XTAL_DIV0
Definition: QN8066.h:36
#define QN_TX_RDSD2
Definition: QN8066.h:59
#define QN_SNR
Definition: QN8066.h:32
#define QN_STATUS1
Definition: QN8066.h:39
#define QN8066_DELAY_COMMAND
Definition: QN8066.h:23
#define QN_CH_START
Definition: QN8066.h:41
#define QN_CID2
Definition: QN8066.h:35
#define QN_REG_VGA
Definition: QN8066.h:69
#define QN_PAC
Definition: QN8066.h:65
#define QN_TX_RDSD7
Definition: QN8066.h:64
#define QN_TX_RDSD0
Definition: QN8066.h:57
#define QN_SYSTEM1
QN8066 Register addresses.
Definition: QN8066.h:29
#define QN_TXCH
Definition: QN8066.h:56
#define QN_XTAL_DIV2
Definition: QN8066.h:38
#define QN_STATUS3
Definition: QN8066.h:55
#define QN_CID1
Definition: QN8066.h:34
#define QN_XTAL_DIV1
Definition: QN8066.h:37
#define QN_CH_STEP
Definition: QN8066.h:43
#define QN_VOL_CTL
Definition: QN8066.h:53
#define QN_FDEV
Definition: QN8066.h:66
uint16_t value
Definition: QN8066.h:833
uint8_t raw[6]
Definition: QN8066.h:828
#define QN_TX_RDSD5
Definition: QN8066.h:62
#define QN_TX_RDSD4
Definition: QN8066.h:61
#define QN_RSSISIG
Definition: QN8066.h:33
#define QN_RX_CH
Definition: QN8066.h:40
#define QN_TX_RDSD6
Definition: QN8066.h:63
#define QN_CH_STOP
Definition: QN8066.h:42
#define QN_RDS
Definition: QN8066.h:67
#define QN_TX_RDSD3
Definition: QN8066.h:60
#define QN_GPLT
Definition: QN8066.h:68
uint8_t raw[2]
Definition: QN8066.h:834
#define QN_CCA
Definition: QN8066.h:31
#define QN8066_I2C_ADDRESS
QN8066 ARDUINO LIBRARY.
Definition: QN8066.h:21
QN8066 Class.
Definition: QN8066.h:846
void setResetDelay(uint16_t delayAfterReset)
Definition: QN8066.h:962
char * rdsRxGetRT(char *rt)
Definition: QN8066.cpp:614
char * rdsRxGetPS(char *ps)
Definition: QN8066.cpp:604
qn8066_cid2 getDeviceProductFamily()
Definition: QN8066.h:899
char * rdsRxGetTime(char *time)
Definition: QN8066.cpp:624
qn8066_cid1 getDeviceProductID()
Definition: QN8066.h:893
void rdsRxEnable(bool value)
Definition: QN8066.cpp:594
uint16_t getRxCurrentFrequency()
Definition: QN8066.h:919
uint16_t pi
Definition: QN8066.h:709
uint8_t raw
Definition: QN8066.h:313
uint8_t raw
Definition: QN8066.h:646
uint16_t raw
Definition: QN8066.h:815
uint8_t CH_START
Definition: QN8066.h:327
uint8_t raw
Definition: QN8066.h:520
uint8_t raw
Definition: QN8066.h:414
unsigned char byteContent[2]
Definition: QN8066.h:808
uint8_t raw
Definition: QN8066.h:240
uint8_t raw
Definition: QN8066.h:469
uint8_t raw
Definition: QN8066.h:433
uint8_t CH_STOP
Definition: QN8066.h:342
uint8_t raw
Definition: QN8066.h:102
uint8_t TXCH
Definition: QN8066.h:519
uint8_t data[8]
Definition: QN8066.h:385
unsigned char byteContent[2]
Definition: QN8066.h:708
uint8_t RSSISIG
Definition: QN8066.h:171
uint8_t raw
Definition: QN8066.h:569
uint16_t raw
Raw 16-bit representation.
Definition: QN8066.h:791
uint8_t RXCH
Definition: QN8066.h:312
uint8_t raw
Definition: QN8066.h:291
uint8_t raw
Definition: QN8066.h:606
uint8_t raw
Definition: QN8066.h:498
uint8_t SNRDB
Definition: QN8066.h:156
uint8_t raw
Definition: QN8066.h:222
uint8_t TX_FDEV
Definition: QN8066.h:584
uint8_t raw
Definition: QN8066.h:328
uint8_t raw
Definition: QN8066.h:125
uint8_t raw
Definition: QN8066.h:190
uint8_t raw
Definition: QN8066.h:172
uint8_t raw
Definition: QN8066.h:343
uint8_t data[8]
Definition: QN8066.h:544
unsigned char byteContent[2]
Definition: QN8066.h:790
uint16_t raw
Definition: QN8066.h:800
unsigned char byteContent[2]
Definition: QN8066.h:799
uint8_t raw
Definition: QN8066.h:143
uint8_t raw
Definition: QN8066.h:362
uint8_t raw
Definition: QN8066.h:692
uint8_t xtal_div
Definition: QN8066.h:221
uint8_t pll_dlt
Definition: QN8066.h:254
uint8_t raw
Definition: QN8066.h:255
uint8_t raw
Definition: QN8066.h:207
uint8_t raw
Definition: QN8066.h:586
uint8_t raw
Definition: QN8066.h:157
bool detectDevice()
Checks communication with QN8066 via I2C.
Definition: QN8066.cpp:26
uint8_t scanI2CBus(uint8_t *device)
Scans the I2C bus and returns the addresses of the devices found.
Definition: QN8066.cpp:41
void setTxMode(uint8_t value)
Set transmission request.
Definition: QN8066.cpp:236
void begin()
Device initial configuration.
Definition: QN8066.cpp:212
qn8066_status1 getStatus1()
Gets the current device Status stored in STATUS1 register.
Definition: QN8066.cpp:122
uint8_t getRegister(uint8_t registerNumber)
Gets register information.
Definition: QN8066.cpp:71
void stopTransmitting()
Stops transmitting.
Definition: QN8066.cpp:245
void setXtal(uint16_t divider, uint8_t xtalInj, uint8_t imageRejection)
QN8066 initial configuration of the of reference clock source.
Definition: QN8066.cpp:726
void setRegister(uint8_t registerNumber, uint8_t value)
Stores a velue to a given register.
Definition: QN8066.cpp:89
void startTransmitting()
Starts transmitting.
Definition: QN8066.cpp:253
qn8066_status2 getStatus2()
Gets the current device Status stored in STATUS2 register.
Definition: QN8066.cpp:151
void setup(uint16_t xtalDiv=1000, bool mono=false, bool rds=false, uint8_t PreEmphasis=0, uint8_t xtalInj=0, uint8_t imageRejection=1, uint8_t txSoftClipThreshold=0, uint8_t oneMinutOff=3, uint8_t gainTxPLT=9, uint8_t txFreqDev=125, uint8_t rdsLineIn=0, uint8_t rdsFreqDev=60, uint8_t inImpedance=1, uint8_t txAgcDig=0, uint8_t txAgcBuffer=1, uint8_t txSoftClip=0)
QN8066 initial configuration.
Definition: QN8066.cpp:291
qn8066_status3 getStatus3()
Gets the current device Status stored in STATUS3 register.
Definition: QN8066.cpp:181
void rdsEnableRX(bool value)
Enables RDS for RX.
Definition: QN8066.cpp:466
void setAudioMuteRX(bool value)
Mute or unmute the audio in receiver mode.
Definition: QN8066.cpp:477
uint8_t getRxSNR()
Gets the current SNR (Estimated RF input)
Definition: QN8066.cpp:487
bool isRxAgcStable()
RX AGC Status.
Definition: QN8066.cpp:535
void scanRxStation(uint16_t startFrequency, uint16_t stopFrequyency, uint8_t frequencyStep)
Scans a station.
Definition: QN8066.cpp:560
void setRxFrequencyStep(uint8_t value)
Sets the current Step frequency.
Definition: QN8066.cpp:453
void setRxFrequencyUp()
Increments the current receiver frequency.
Definition: QN8066.cpp:423
void setRX(uint16_t frequency)
SYSTEM1 SETUP.
Definition: QN8066.cpp:351
void setRxFrequencyDown()
Decrements the current receiver frequency.
Definition: QN8066.cpp:437
bool isValidRxChannel()
Gets a valid or no valid rx channel.
Definition: QN8066.cpp:511
bool isRxStereo()
Stereo receiving status.
Definition: QN8066.cpp:546
void setRxFrequency(uint16_t frequency)
sets the receiver frequency
Definition: QN8066.cpp:394
void setRxFrequencyRange(uint16_t min=640, uint16_t max=1080)
Sets the frequency range of the receiver.
Definition: QN8066.cpp:413
uint8_t getRxRSSI()
Gets the current RSSI.
Definition: QN8066.cpp:498
bool isRxReceiving()
Receiver status.
Definition: QN8066.cpp:522
void setTxInputBufferGain(uint8_t value)
TX input buffer gain.
Definition: QN8066.cpp:1210
void updateTxSetup()
Reset the system kepping the TX current STATUS.
Definition: QN8066.cpp:1307
void setAudioDigitalGain(uint8_t value)
Sets set digital volume gain.
Definition: QN8066.cpp:1036
void setTxMono(uint8_t value=0)
Set TX Stereo or Mono (Same setTxStereo )
Definition: QN8066.cpp:781
void setTxOffAfterOneMinuteNoAudio(bool value)
Set of 1 minute time for PA off when no audio.
Definition: QN8066.cpp:952
void setPreEmphasis(uint8_t value=1)
Pre-emphasis and de-emphasis time constant - Same setTxPreEmphasis.
Definition: QN8066.cpp:861
void setTxInputImpedance(uint8_t value)
TX mode input impedance for both L/R channels.
Definition: QN8066.cpp:1132
void resetAudioPeak()
TX Audio peak clear signal.
Definition: QN8066.h:1009
void setTxSoftClipThreshold(uint8_t value)
TX soft clip threshold.
Definition: QN8066.cpp:926
void setTxStereo(bool value=true)
Set TX Stereo or Mono.
Definition: QN8066.cpp:754
void setAudioAnalogGain(uint8_t value)
Sets volume control gain of analog portion.
Definition: QN8066.cpp:1006
uint8_t getTxMono()
Gets TX Stereo or Mono setup.
Definition: QN8066.cpp:809
void setTxFrequencyDerivation(uint8_t value)
Specify total TX frequency deviation.
Definition: QN8066.cpp:1266
void setTX(uint16_t frequency)
Sets the TX mode.
Definition: QN8066.cpp:659
void setTxDigitalGain(uint8_t value)
TX digital gain.
Definition: QN8066.cpp:1170
void setPAC(uint8_t PA_TRGT)
PA output power target control.
Definition: QN8066.cpp:1290
void setTxPreEmphasis(uint8_t value=75)
Pre-emphasis and de-emphasis time constant.
Definition: QN8066.cpp:833
void setTxSoftClippingEnable(bool value)
TX soft clipping enable.
Definition: QN8066.cpp:1238
void setTxOffAfterOneMinute(uint8_t value)
Sets PA Off after 1 minute time when no audio.
Definition: QN8066.cpp:979
void setTxPilotGain(uint8_t value)
Gain of TX pilot to adjust pilot frequency deviation.
Definition: QN8066.cpp:889
void setAudioTxDiff(bool value)
Tx audio input mode selection.
Definition: QN8066.cpp:1094
void setAudioDacHold(bool value)
DAC output control.
Definition: QN8066.cpp:1066
int getAudioPeakValue()
Audio peak value at ADC input.
Definition: QN8066.cpp:1403
void setToggleTxPdClear()
TX Audio peak clear signal.
Definition: QN8066.cpp:1374
void rdsSetInterrupt(uint8_t value)
Sets RDS interrupt.
Definition: QN8066.cpp:1483
void rdsSetMode(uint8_t mode)
Sets RDS Mode Selection.
Definition: QN8066.cpp:1430
void rdsSetTxLineIn(bool value=0)
Audio Line-in enable control.
Definition: QN8066.cpp:1679
void rdsSendPS(char *ps=NULL)
Sends the Program Service Message.
Definition: QN8066.cpp:1785
void rdsTxEnable(bool value)
Transmitter RDS enable.
Definition: QN8066.cpp:1566
uint8_t rdsGetPTY()
Gets the Program Type (PTY)
Definition: QN8066.h:1136
uint8_t rdsGetError()
Gets TX RDS error setup.
Definition: QN8066.h:1167
void rdsSetRepeatSendGroup(uint8_t count)
Sets the number of time that a group will be sent at once.
Definition: QN8066.h:1192
void rdsSendGroup(RDS_BLOCK1 blockA, RDS_BLOCK2 blockB, RDS_BLOCK3 blockC, RDS_BLOCK4 blockD)
Sends a RDS group (four blocks) to the QN8066.
Definition: QN8066.cpp:1720
void rdsSetFrequencyDerivation(uint8_t freq=6)
Sets RDS frequency deviation.
Definition: QN8066.cpp:1652
void rdsSendRT(char *rt)
Sends RDS Radio Text Message (group 2A)
Definition: QN8066.h:1056
void rdsSendRTMessage(char *rt)
Sends RDS Radio Text Message (group 2A)
Definition: QN8066.cpp:1844
void rdsSetStationName(char *stationName)
Sets the station name.
Definition: QN8066.cpp:1758
char * rdsGetPS()
Gets the Program Station (Station Name).
Definition: QN8066.h:1160
uint8_t rdsSetTxToggle()
RDS transmitting ready.
Definition: QN8066.cpp:1595
void rdsSetTP(uint16_t tp)
Sets the Traffic Program.
Definition: QN8066.h:1145
uint8_t rdsGetTP()
Sets the Traffic Program.
Definition: QN8066.h:1153
int32_t calculateMJD(uint16_t year, uint8_t month, uint8_t day)
Calculates the Modified Julian Date.
Definition: QN8066.cpp:1896
bool rdsGetTxUpdated()
RDS TX Updated.
Definition: QN8066.cpp:1626
void rdsSetPTY(uint16_t pty)
Sets the Program Type (PTY)
Definition: QN8066.h:1128
void rdsInitTx(uint8_t countryId=0, uint8_t programId=0, uint8_t reference=0, uint8_t pty=1, uint8_t rdsSyncTime=60, uint8_t rdsRepeatGroup=5)
Sets some RDS parameters.
Definition: QN8066.cpp:1520
void rdsSetPI(uint16_t pi)
Sets the Program Identification (PI)
Definition: QN8066.h:1108
void rdsSendDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, int8_t offset)
Sends the RDS Date Time information.
Definition: QN8066.cpp:1927
uint8_t rdsGetPI()
Gets the Program Identification (PI)
Definition: QN8066.h:1119
void rdsClearBuffer()
Clear RDS register (Buffer)
Definition: QN8066.cpp:1691
void rdsSetSyncTime(uint8_t syncTime)
Sets the wait time for the QN8066 to be available to send the next RDS block.
Definition: QN8066.h:1183
void rdsSetPI(uint8_t countryId, uint8_t programId, uint8_t reference=0)
Sets the Program Identification (PI)
Definition: QN8066.cpp:1537
void rdsSet4KMode(uint8_t value)
Sets RDS 4K Mode .
Definition: QN8066.cpp:1456
void resetFsm()
Resets the state to initial states and recalibrate all blocks.
Definition: QN8066.cpp:2013
uint8_t getFsmStateCode()
Get the FSM State Code.
Definition: QN8066.cpp:2002
void setStnby(bool value)
Request Immediately enter Standby mode whatever state chip is in.
Definition: QN8066.cpp:2026
void setI2CLowSpeedMode(void)
Sets I2C bus to 10kHz.
Definition: QN8066.h:1210
void setI2CStandardMode(void)
Sets I2C bus to 100kHz.
Definition: QN8066.h:1220
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: QN8066.cpp:2065
char * formatCurrentFrequency(char decimalSeparator=',')
Convert the current frequency to a formated string (char *) frequency.
Definition: QN8066.cpp:2103
void setI2CFastMode(void)
Sets I2C bus to 400kHz.
Definition: QN8066.h:1227
void setI2CFastModeCustom(long value=500000)
Sets the I2C bus to a given value. ATTENTION: use this function with caution.
Definition: QN8066.h:1240