2
3
4
5
6
7
8
9
10
15
16
17
20
21
22
23
24
25
26
27
28
29
30
31
32
33
39 this->gpio1Control = mcuPin;
40 reg04->refined.GPIO1 = gpioSetup;
43 this->gpio2Control = mcuPin;
44 reg04->refined.GPIO2 = gpioSetup;
47 this->gpio3Control = mcuPin;
48 reg04->refined.GPIO3 = gpioSetup;
51 gpio1Control = gpio2Control = gpio3Control = -1;
54 setRegister(
REG04,reg04->raw);
58
59
60
61
62
63
69 Wire.requestFrom(
this->deviceAddressFullAccess, 12);
70 for (i = 0; i < 6; i++) {
71 aux.refined.highByte = Wire.read();
72 aux.refined.lowByte = Wire.read();
73 shadowStatusRegisters[i] = aux.raw;
75 Wire.endTransmission();
79
80
81
82
83
84
85
86word16_to_bytes
RDA5807::getDirectRegister(uint8_t reg)
90 Wire.beginTransmission(
this->deviceAddressDirectAccess);
92 Wire.endTransmission(
false);
93 Wire.requestFrom(
this->deviceAddressDirectAccess, 2);
94 aux.refined.highByte = Wire.read();
95 aux.refined.lowByte = Wire.read();
96 Wire.endTransmission();
102
103
104
105
106
107
112 if ( reg < 0x0A || reg > 0x0F )
return NULL;
114 Wire.beginTransmission(
this->deviceAddressDirectAccess);
116 Wire.endTransmission(
false);
117 Wire.requestFrom(
this->deviceAddressDirectAccess, 2);
118 delayMicroseconds(250);
119 aux.refined.highByte = Wire.read();
120 aux.refined.lowByte = Wire.read();
121 Wire.endTransmission(
true);
122 shadowStatusRegisters[reg - 0x0A] = aux.raw;
124 return &shadowStatusRegisters[reg - 0x0A];
129
130
131
132
133
134
135
136
137
142 Wire.beginTransmission(
this->deviceAddressDirectAccess);
145 Wire.write(aux.refined.highByte);
146 Wire.write(aux.refined.lowByte);
147 Wire.endTransmission();
148 shadowRegisters[reg] = aux.raw;
149 delayMicroseconds(3000);
153
154
155
160 }
while (reg0a->refined.STC == 0);
164
165
166
167
168
171 reg02->refined.SOFT_RESET = 1;
172 setRegister(
REG02,reg02->raw);
176
177
178
182 reg02->refined.NEW_METHOD = 0;
183 reg02->refined.RDS_EN = 0;
184 reg02->refined.CLK_MODE =
this->clockType;
185 reg02->refined.RCLK_DIRECT_IN =
this->oscillatorType;
186 reg02->refined.MONO = 1;
187 reg02->refined.DMUTE = 1;
188 reg02->refined.DHIZ = 1;
189 reg02->refined.ENABLE = 1;
190 reg02->refined.BASS = 1;
191 reg02->refined.SEEK = 0;
193 setRegister(
REG02,reg02->raw);
196 reg05->refined.INT_MODE = 0;
197 reg05->refined.LNA_PORT_SEL = 2;
198 reg05->refined.LNA_ICSEL_BIT = 0;
199 reg05->refined.SEEKTH = 8;
200 reg05->refined.VOLUME = 0;
202 setRegister(
REG05, reg05->raw);
206
207
208
209
210
212 reg02->refined.NEW_METHOD = value;
213 setRegister(
REG02,reg02->raw);
217
218
219
222 reg02->refined.SEEK = 0;
223 reg02->refined.ENABLE = 0;
224 setRegister(
REG02, reg02->raw);
229
230
231
232
233
234
235
236
239 this->oscillatorType = oscillator_type;
240 this->clockType = clock_type;
249
250
251
252
256 aux = getDirectRegister(0x0);
257 reg00->raw = aux.raw;
263
264
265
269
270
271
272
273
275 reg07->refined.SOFTBLEND_EN = value;
276 setRegister(
REG07,reg07->raw);
280
281
282
283
284
286 reg04->refined.AFCD = value;
287 setRegister(
REG04,reg04->raw);
292
293
294
295
296
297
298
299
300
301
302
305 reg03->refined.CHAN = channel;
306 reg03->refined.TUNE = 1;
307 reg03->refined.BAND =
this->currentFMBand;
308 reg03->refined.SPACE =
this->currentFMSpace;
309 reg03->refined.DIRECT_MODE = 0;
310 setRegister(
REG03, reg03->raw);
315
316
317
318
321 uint16_t channel = (frequency -
this->startBand[currentFMBand] ) / (
this->fmSpace[
this->currentFMSpace] );
323 this->currentFrequency = frequency;
327
328
329
330
333 if (
this->currentFrequency <
this->endBand[
this->currentFMBand])
334 this->currentFrequency += (
this->fmSpace[currentFMSpace] );
336 this->currentFrequency =
this->startBand[
this->currentFMBand];
338 setFrequency(
this->currentFrequency);
342
343
344
345
348 if (
this->currentFrequency >
this->startBand[
this->currentFMBand])
349 this->currentFrequency -= (
this->fmSpace[currentFMSpace] );
351 this->currentFrequency =
this->endBand[
this->currentFMBand];
353 setFrequency(
this->currentFrequency);
359
360
361
362
365 return this->currentFrequency;
369
370
371
372
373
374
375
376
380 return reg0a->refined.READCHAN;
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
400 return getRealChannel() * (
this->fmSpace[
this->currentFMSpace]) +
this->startBand[currentFMBand];
404
405
406
407
408
409
412 reg02->refined.SEEK = 1;
413 reg02->refined.SKMODE = seek_mode;
414 reg02->refined.SEEKUP = direction;
415 setRegister(
REG02,reg02->raw);
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450void RDA5807::
seek(uint8_t seek_mode, uint8_t direction,
void (*showFunc)())
455 reg02->refined.SEEK = 1;
456 reg02->refined.SKMODE = seek_mode;
457 reg02->refined.SEEKUP = direction;
458 setRegister(
REG02, reg02->raw);
459 this->currentFrequency = getRealFrequency();
460 if (showFunc != NULL)
466 }
while (reg0a->refined.STC == 0);
468 setFrequency(getRealFrequency());
474
475
476
477
480 reg05->refined.SEEKTH = value;
481 setRegister(
REG05,reg05->raw);
485
486
487
488
489
490
491
492
493
494
495
496
497
498
502 reg03->refined.BAND =
this->currentFMBand = band;
503 setRegister(
REG03,reg03->raw);
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
524 reg03->refined.SPACE = space;
525 this->currentFMSpace = space;
526 setRegister(
REG03, reg03->raw);
530
531
532
533
534
535
555 this->setSpace(space);
560
561
562
563
564
565
567 reg04->refined.DE = de;
568 setRegister(
REG04,reg04->raw);
572
573
574
575
578
579
580
581
582
583
586 reg02->refined.SEEK = 0;
587 reg02->refined.RDS_EN = value;
588 setRegister(
REG02, reg02->raw);
592
593
594
595
596
597
600 reg02->refined.SEEK = 0;
601 reg02->refined.RDS_EN = 1;
602 setRegister(
REG02, reg02->raw);
603 reg04->refined.RBDS = value;
604 setRegister(
REG04, reg04->raw);
609
610
611
612
613
614
615
620 return reg0a->refined.RDSR;
624
625
626
627
628
633 blkb.blockB = reg0d->RDSB;
634 return blkb.refined.textABFlag;
638
639
640
641
642
648 blkb.blockB = reg0d->RDSB;
649 return blkb.group0.groupType;
653
654
655
656
657
662 blkb.blockB = reg0d->RDSB;
663 return blkb.refined.versionCode;
667
668
669
670
671
676 blkb.blockB = reg0d->RDSB;
677 return blkb.refined.programType;
681
682
683
684
685
692 blk.raw = reg0f->RDSD;
694 raw[1] = blk.refined.lowByte;
695 raw[0] = blk.refined.highByte;
697 for (i = j = 0; i < 2; i++)
699 if (raw[i] == 0xD || raw[i] == 0xA)
717
718
719
720
721
722
727 word16_to_bytes blk_c, blk_d;
729 blk_c.raw = reg0e->RDSC;
730 blk_d.raw = reg0f->RDSD;
732 raw[0] = blk_c.refined.highByte;
733 raw[1] = blk_c.refined.lowByte;
734 raw[2] = blk_d.refined.highByte;
735 raw[3] = blk_d.refined.lowByte;
737 for (i = j = 0; i < 4; i++)
739 if (raw[i] == 0xD || raw[i] == 0xA)
757
758
759
760
761
764 static int rdsTextAdress2A;
769 blkb.blockB = reg0d->RDSB;
770 rdsTextAdress2A = blkb.group2.address;
772 if (rdsTextAdress2A >= 16)
776 rdsTextAdress2A += 4;
781
782
783
784
785
786
787
790 static int rdsTextAdress0A;
794 blkb.blockB = reg0d->RDSB;
796 if (blkb.group0.groupType == 0)
799 rdsTextAdress0A = blkb.group0.address;
800 if (rdsTextAdress0A >= 0 && rdsTextAdress0A < 4)
803 rds_buffer0A[8] =
'\0';
811
812
813
814
815
816
819 static int rdsTextAdress2A;
824 blkb.blockB = reg0d->RDSB;
825 rdsTextAdress2A = blkb.group2.address;
827 if (blkb.group2.groupType == 2)
831 if (rdsTextAdress2A >= 0 && rdsTextAdress2A < 16)
834 rds_buffer2A[63] =
'\0';
842
843
844
845
848 static int rdsTextAdress2B;
852 blkb.blockB = reg0d->RDSB;
853 if (blkb.group2.groupType == 2)
856 rdsTextAdress2B = blkb.group2.address;
857 if (rdsTextAdress2B >= 0 && rdsTextAdress2B < 16)
867
868
869
870
871
877 word16_to_bytes blk_b, blk_c, blk_d;
882 blk_b.raw = blkb.blockB = reg0d->RDSB;
883 blk_c.raw = reg0e->RDSC;
884 blk_d.raw = reg0f->RDSD;
889 if (blkb.group0.groupType == 4)
897 dt.raw[4] = blk_b.refined.lowByte;
898 dt.raw[5] = blk_b.refined.highByte;
900 dt.raw[2] = blk_c.refined.lowByte;
901 dt.raw[3] = blk_c.refined.highByte;
903 dt.raw[0] = blk_d.refined.lowByte;
904 dt.raw[1] = blk_d.refined.highByte;
909 minute = (dt.refined.minute2 << 2) | dt.refined.minute1;
910 hour = (dt.refined.hour2 << 4) | dt.refined.hour1;
912 offset_sign = (dt.refined.offset_sense == 1) ?
'+' :
'-';
913 offset_h = (dt.refined.offset * 30) / 60;
914 offset_m = (dt.refined.offset * 30) - (offset_h * 60);
916 sprintf(rds_time,
"%02u:%02u %c%02u:%02u", hour, minute, offset_sign, offset_h, offset_m);
925
926
927
928
929
933 return reg0a->refined.RDSS;
937
938
939
940
941
942
946 return reg0b->refined.ABCD_E;
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
968 return reg0b->refined.BLERB;
972
973
974
975
976
979 return (reg0a->refined.RDSS && reg0b->refined.ABCD_E == 0 && reg0b->refined.BLERB == 0 );
983
984
985
986
987
988
990 reg04->refined.RDS_FIFO_EN = value;
991 setRegister(
REG04,reg04->raw);
995
996
997
998
999
1000
1003 reg04->refined.RDS_FIFO_CLR = 1;
1004 setRegister(
REG04, reg04->raw);
1012
1013
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028void RDA5807::
convertToChar(uint16_t value,
char *strValue, uint8_t len, uint8_t dot, uint8_t separator,
bool remove_leading_zeros)
1031 for (
int i = (len - 1); i >= 0; i--)
1035 strValue[i] = d + 48;
1037 strValue[len] =
'\0';
1040 for (
int i = len; i >= dot; i--)
1042 strValue[i + 1] = strValue[i];
1044 strValue[dot] = separator;
1047 if (remove_leading_zeros) {
1048 if (strValue[0] ==
'0')
1051 if (strValue[1] ==
'0')
1059
1060
1061
1062
1063
1064
1069 for(address = 1; address < 127; address++ ) {
1070 Wire.beginTransmission(address);
1071 error = Wire.endTransmission();
1073 addressArray[idx] = address;
1086
1087
1088
1089
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114void RDA5807::
setI2SAllParameters(uint8_t R_DELY, uint8_t L_DELY, uint8_t SCLK_O_EDGE, uint8_t SW_O_EDGE, uint8_t I2S_SW_CNT, uint8_t WS_I_EDGE, uint8_t DATA_SIGNED, uint8_t SCLK_I_EDGE, uint8_t WS_LR, uint8_t SLAVE_MASTER, uint8_t OPEN_MODE ) {
1115 reg06->refined.R_DELY = R_DELY;
1116 reg06->refined.L_DELY = L_DELY;
1117 reg06->refined.SCLK_O_EDGE = SCLK_O_EDGE;
1118 reg06->refined.SW_O_EDGE = SW_O_EDGE;
1119 reg06->refined.I2S_SW_CNT = I2S_SW_CNT;
1120 reg06->refined.WS_I_EDGE = WS_I_EDGE;
1121 reg06->refined.DATA_SIGNED = DATA_SIGNED;
1122 reg06->refined.SCLK_I_EDGE = SCLK_I_EDGE;
1123 reg06->refined.WS_LR = WS_LR;
1124 reg06->refined.SLAVE_MASTER = SLAVE_MASTER;
1125 reg06->refined.OPEN_MODE = OPEN_MODE;
1127 setRegister(
REG06,reg06->raw);
1133
1134
1135
1136
1137
1138
1140 reg04->refined.I2S_ENABLE = value;
1141 setRegister(
REG04,reg04->raw);
1146
1147
1148
1149
1150
1152 reg06->refined.SLAVE_MASTER = !value;
1153 setRegister(
REG06,reg06->raw);
1159
1160
1161
1162
1163
1164
1166 reg06->refined.I2S_SW_CNT = value;
1167 setRegister(
REG06,reg06->raw);
1172
1173
1174
1175
1176
1178 reg06->refined.DATA_SIGNED = value;
1179 setRegister(
REG06,reg06->raw);
1186
1187
1188
1193
1194
1195
1196
1199 reg04->refined.SOFTMUTE_EN = value;
1200 setRegister(
REG04, reg04->raw);
1207
1208
1209
1210
1213 reg02->refined.SEEK = 0;
1214 reg02->refined.DMUTE = !value;
1215 setRegister(
REG02,reg02->raw);
1219
1220
1221
1222
1225 reg02->refined.SEEK = 0;
1226 reg02->refined.DHIZ = !value;
1227 setRegister(
REG02,reg02->raw);
1232
1233
1234
1235
1236
1239 reg02->refined.SEEK = 0;
1240 reg02->refined.MONO = value;
1241 setRegister(
REG02, reg02->raw);
1245
1246
1247
1248
1249
1252 reg02->refined.SEEK = 0;
1253 reg02->refined.BASS = value;
1254 setRegister(
REG02, reg02->raw);
1258
1259
1260
1261
1262
1266 return reg0a->refined.ST;
1272
1273
1274
1275
1276
1279 if ( value > 15 ) value = 15;
1281 reg05->refined.VOLUME =
this->currentVolume = value;
1282 setRegister(
REG05, reg05->raw);
1286
1287
1288
1289
1290
1293 return this->currentVolume;
1297
1298
1299
1300
1303 if (
this->currentVolume < 15)
1305 this->currentVolume++;
1306 setVolume(
this->currentVolume);
1311
1312
1313
1314
1317 if (
this->currentVolume > 0)
1319 this->currentVolume--;
1320 setVolume(
this->currentVolume);
1326
1327
1328
1331
1332
1333
1334
1335
1337 reg05->refined.LNA_ICSEL_BIT = value;
1338 setRegister(
REG05,reg05->raw);
1342
1343
1344
1345
1346
1348 reg05->refined.LNA_PORT_SEL = value;
1349 setRegister(
REG05,reg05->raw);
1354
1355
1356
1357
1358
1359
1363 return reg0b->refined.RSSI;
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.
int checkI2C(uint8_t *addressArray)
Check the I2C bus address.
void * getStatus(uint8_t reg)
Gets the register content of a given status register (from 0x0A to 0x0F)
void powerDown()
Power the receiver off.
void powerUp()
Powers the receiver on.
void setRegister(uint8_t reg, uint16_t value)
Sets a given value to a specific device register.
void softReset()
Resets the device.
void waitAndFinishTune()
Waits for Seek or Tune finish.
void setGpio(uint8_t gpioPin, uint8_t gpioSetup=0, int mcuPin=-1)
Sets the Device GPIO pins.
void setNewDemodulateMethod(bool value)
Sets new demodulate method. It can improve the receiver sensitivity about 1dB.
void getStatusRegisters()
Gets all current device status and RDS information registers (From 0x0A to 0x0F)
void setup(uint8_t clock_type=CLOCK_32K, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL)
Starts the device.
uint16_t getDeviceId()
Gets the Device identification.
uint16_t getRealFrequency()
Gets the current frequency bases on the current channel.
uint16_t getRealChannel()
Gets the current channel stored in 0x0A status register.
void setSeekThreshold(uint8_t value)
Sets RSSI Seek Threshold.
void setFrequencyUp()
Increments the current frequency.
void setFmDeemphasis(uint8_t de)
Sets De-emphasis.
uint16_t getFrequency()
Gets the current frequency.
void setSoftBlendEnable(bool value)
Sets Soft Blend.
void setSpace(uint8_t space=0)
Sets the FM channel space.
void seek(uint8_t seek_mode, uint8_t direction)
Seek function.
void setBand(uint8_t band=0)
Sets the FM band. See table below.
void setStep(uint8_t step=100)
Sets the FM Step;.
void setAFC(bool value)
Sets AFC true or false.
void setChannel(uint16_t channel)
Sets the channel.
void setFrequency(uint16_t frequency)
Sets the frequency.
void setFrequencyDown()
Decrements the current frequency.
void seek(uint8_t seek_mode, uint8_t direction, void(*showFunc)())
Seek function.
uint8_t getRdsFlagAB(void)
Returns the current Text Flag A/B
bool hasRdsInfo()
Returns true when the RDS system has valid information.
bool getRdsSync()
Gets the Rds Sync.
uint8_t getBlockId()
Gets the current Block ID.
uint16_t getRdsGroupType()
Return the group type.
void getNext4Block(char *c)
Process data received from group 2A.
char * getRdsText2A(void)
Gets the Text processed for the 2A group.
void setRDS(bool value)
Sets the RDS operation.
char * getRdsText0A(void)
Gets the station name and other messages.
void getNext2Block(char *c)
Process data received from group 2B.
char * getRdsText(void)
Gets the RDS Text when the message is of the Group Type 2 version A.
void clearRdsFifo()
Clear RDS fifo.
char * getRdsText2B(void)
Gets the Text processed for the 2B group.
bool getRdsReady()
Returns true if RDS Ready.
uint8_t getRdsVersionCode(void)
Gets the version code (extracted from the Block B)
uint8_t getErrorBlockB()
Gets the current Status of block B.
void setRdsFifo(bool value)
Sets RDS fifo mode enable.
uint8_t getRdsProgramType(void)
Returns the Program Type (extracted from the Block B)
void setRBDS(bool value)
Sets the RBDS operation.
char * getRdsTime()
Gets the RDS time and date when the Group type is 4.
void setI2SAllParameters(uint8_t R_DELY, uint8_t L_DELY, uint8_t SCLK_O_EDGE, uint8_t SW_O_EDGE, uint8_t I2S_SW_CNT, uint8_t WS_I_EDGE, uint8_t DATA_SIGNED, uint8_t SCLK_I_EDGE, uint8_t WS_LR, uint8_t SLAVE_MASTER, uint8_t OPEN_MODE)
Configures all parameters for I2S.
void setI2SSpeed(uint8_t value)
Sets the speed in kbps. You can use the predefined constantes: I2S_WS_STEP_48, I2S_WS_STEP_44_1,...
void setI2SMaster(bool value)
void setI2SDataSigned(bool value)
If 0, I2S output unsigned 16-bit audio data. If 1, I2S output signed 16-bit audio data.
void setI2SOn(bool value)
Enables I2S setup.
bool isStereo()
Gets the current Stereo status.
void setVolume(uint8_t value)
Sets the audio volume level.
uint8_t getVolume()
Gets the current audio volume level.
void setBass(bool value)
Sets Bass Boost.
void setVolumeUp()
Increments the audio volume.
void setVolumeDown()
Decrements the audio volume.
void setAudioOutputHighImpedance(bool value)
Sets audio output impedance high ow low.
void setMono(bool value)
Sets audio Mono or stereo.
void setSoftmute(bool value)
Sets Soft Mute Enable or disable.
void setMute(bool value)
Sets Audio mute or unmute.
void setLnaIcSel(uint8_t value)
Sets LNA_ICSEL_BIT.
int getRssi()
Gets the current Rssi.
void setLnaPortSel(uint8_t value)
Sets LNA input port selection bit.