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
89 if ( reg < 0x0A || reg > 0x0F )
return NULL;
91 Wire.beginTransmission(
this->deviceAddressDirectAccess);
93 Wire.endTransmission(
false);
94 Wire.requestFrom(
this->deviceAddressDirectAccess, 2);
95 delayMicroseconds(250);
96 aux.refined.highByte = Wire.read();
97 aux.refined.lowByte = Wire.read();
98 Wire.endTransmission(
true);
99 shadowStatusRegisters[reg - 0x0A] = aux.raw;
101 return &shadowStatusRegisters[reg - 0x0A];
106
107
108
109
110
111
112
113
114
119 Wire.beginTransmission(
this->deviceAddressDirectAccess);
122 Wire.write(aux.refined.highByte);
123 Wire.write(aux.refined.lowByte);
124 Wire.endTransmission();
125 shadowRegisters[reg] = aux.raw;
126 delayMicroseconds(3000);
130
131
132
137 }
while (reg0a->refined.STC == 0);
141
142
143
144
145
148 reg02->refined.SOFT_RESET = 1;
149 setRegister(
REG02,reg02->raw);
153
154
155
159 reg02->refined.NEW_METHOD = 0;
160 reg02->refined.RDS_EN = 0;
161 reg02->refined.CLK_MODE =
this->clockType;
162 reg02->refined.RCLK_DIRECT_IN =
this->oscillatorType;
163 reg02->refined.MONO = 1;
164 reg02->refined.DMUTE = 1;
165 reg02->refined.DHIZ = 1;
166 reg02->refined.ENABLE = 1;
167 reg02->refined.BASS = 1;
168 reg02->refined.SEEK = 0;
170 setRegister(
REG02,reg02->raw);
173 reg05->refined.INT_MODE = 0;
174 reg05->refined.LNA_PORT_SEL = 2;
175 reg05->refined.LNA_ICSEL_BIT = 0;
176 reg05->refined.SEEKTH = 8;
177 reg05->refined.VOLUME = 0;
179 setRegister(
REG05, reg05->raw);
183
184
185
186
187
189 reg02->refined.NEW_METHOD = value;
190 setRegister(
REG02,reg02->raw);
194
195
196
199 reg02->refined.SEEK = 0;
200 reg02->refined.ENABLE = 0;
201 setRegister(
REG02, reg02->raw);
206
207
208
209
210
211
212
213
216 this->oscillatorType = oscillator_type;
217 this->clockType = clock_type;
227
228
229
233
234
235
236
237
239 reg07->refined.SOFTBLEND_EN = value;
240 setRegister(
REG07,reg07->raw);
244
245
246
247
248
250 reg04->refined.AFCD = value;
251 setRegister(
REG04,reg04->raw);
257
258
259
260
261
262
263
264
265
266
267
270 reg03->refined.CHAN = channel;
271 reg03->refined.TUNE = 1;
272 reg03->refined.BAND =
this->currentFMBand;
273 reg03->refined.SPACE =
this->currentFMSpace;
274 reg03->refined.DIRECT_MODE = 0;
275 setRegister(
REG03, reg03->raw);
280
281
282
283
286 uint16_t channel = (frequency -
this->startBand[currentFMBand] ) / (
this->fmSpace[
this->currentFMSpace] );
288 this->currentFrequency = frequency;
292
293
294
295
298 if (
this->currentFrequency <
this->endBand[
this->currentFMBand])
299 this->currentFrequency += (
this->fmSpace[currentFMSpace] );
301 this->currentFrequency =
this->startBand[
this->currentFMBand];
303 setFrequency(
this->currentFrequency);
307
308
309
310
313 if (
this->currentFrequency >
this->startBand[
this->currentFMBand])
314 this->currentFrequency -= (
this->fmSpace[currentFMSpace] );
316 this->currentFrequency =
this->endBand[
this->currentFMBand];
318 setFrequency(
this->currentFrequency);
322
323
324
325
328 return this->currentFrequency;
332
333
334
335
336
337
338
339
343 return reg0a->refined.READCHAN;
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
363 return getRealChannel() * (
this->fmSpace[
this->currentFMSpace]) +
this->startBand[currentFMBand];
367
368
369
370
371
372
375 reg02->refined.SEEK = 1;
376 reg02->refined.SKMODE = seek_mode;
377 reg02->refined.SEEKUP = direction;
378 setRegister(
REG02,reg02->raw);
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413void RDA5807::
seek(uint8_t seek_mode, uint8_t direction,
void (*showFunc)())
418 reg02->refined.SEEK = 1;
419 reg02->refined.SKMODE = seek_mode;
420 reg02->refined.SEEKUP = direction;
421 setRegister(
REG02, reg02->raw);
422 this->currentFrequency = getRealFrequency();
423 if (showFunc != NULL)
429 }
while (reg0a->refined.STC == 0);
431 setFrequency(getRealFrequency());
437
438
439
440
443 reg05->refined.SEEKTH = value;
444 setRegister(
REG05,reg05->raw);
448
449
450
451
452
453
454
455
456
457
458
459
460
461
465 reg03->refined.BAND =
this->currentFMBand = band;
466 setRegister(
REG03,reg03->raw);
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
487 reg03->refined.SPACE = space;
488 this->currentFMSpace = space;
489 setRegister(
REG03, reg03->raw);
493
494
495
496
497
498
518 this->setSpace(space);
523
524
525
526
527
528
532 return reg0b->refined.RSSI;
537
538
539
540
541
548
549
550
551
552
553
555 reg04->refined.DE = de;
556 setRegister(
REG04,reg04->raw);
560
561
562
563
566
567
568
569
570
571
574 reg02->refined.SEEK = 0;
575 reg02->refined.RDS_EN = value;
576 setRegister(
REG02, reg02->raw);
580
581
582
583
584
585
588 reg02->refined.SEEK = 0;
589 reg02->refined.RDS_EN = 1;
590 setRegister(
REG02, reg02->raw);
591 reg04->refined.RBDS = value;
592 setRegister(
REG04, reg04->raw);
597
598
599
600
601
602
603
608 return reg0a->refined.RDSR;
612
613
614
615
616
621 blkb.blockB = reg0d->RDSB;
622 return blkb.refined.textABFlag;
626
627
628
629
630
636 blkb.blockB = reg0d->RDSB;
637 return blkb.group0.groupType;
641
642
643
644
645
650 blkb.blockB = reg0d->RDSB;
651 return blkb.refined.versionCode;
655
656
657
658
659
664 blkb.blockB = reg0d->RDSB;
665 return blkb.refined.programType;
669
670
671
672
673
680 blk.raw = reg0f->RDSD;
682 raw[1] = blk.refined.lowByte;
683 raw[0] = blk.refined.highByte;
685 for (i = j = 0; i < 2; i++)
687 if (raw[i] == 0xD || raw[i] == 0xA)
705
706
707
708
709
710
715 word16_to_bytes blk_c, blk_d;
717 blk_c.raw = reg0e->RDSC;
718 blk_d.raw = reg0f->RDSD;
720 raw[0] = blk_c.refined.highByte;
721 raw[1] = blk_c.refined.lowByte;
722 raw[2] = blk_d.refined.highByte;
723 raw[3] = blk_d.refined.lowByte;
725 for (i = j = 0; i < 4; i++)
727 if (raw[i] == 0xD || raw[i] == 0xA)
745
746
747
748
749
752 static int rdsTextAdress2A;
757 blkb.blockB = reg0d->RDSB;
758 rdsTextAdress2A = blkb.group2.address;
760 if (rdsTextAdress2A >= 16)
764 rdsTextAdress2A += 4;
769
770
771
772
773
774
775
778 static int rdsTextAdress0A;
782 blkb.blockB = reg0d->RDSB;
784 if (blkb.group0.groupType == 0)
787 rdsTextAdress0A = blkb.group0.address;
788 if (rdsTextAdress0A >= 0 && rdsTextAdress0A < 4)
791 rds_buffer0A[8] =
'\0';
799
800
801
802
803
804
807 static int rdsTextAdress2A;
812 blkb.blockB = reg0d->RDSB;
813 rdsTextAdress2A = blkb.group2.address;
815 if (blkb.group2.groupType == 2)
819 if (rdsTextAdress2A >= 0 && rdsTextAdress2A < 16)
822 rds_buffer2A[63] =
'\0';
830
831
832
833
836 static int rdsTextAdress2B;
840 blkb.blockB = reg0d->RDSB;
841 if (blkb.group2.groupType == 2)
844 rdsTextAdress2B = blkb.group2.address;
845 if (rdsTextAdress2B >= 0 && rdsTextAdress2B < 16)
855
856
857
858
859
865 word16_to_bytes blk_b, blk_c, blk_d;
870 blk_b.raw = blkb.blockB = reg0d->RDSB;
871 blk_c.raw = reg0e->RDSC;
872 blk_d.raw = reg0f->RDSD;
877 if (blkb.group0.groupType == 4)
885 dt.raw[4] = blk_b.refined.lowByte;
886 dt.raw[5] = blk_b.refined.highByte;
888 dt.raw[2] = blk_c.refined.lowByte;
889 dt.raw[3] = blk_c.refined.highByte;
891 dt.raw[0] = blk_d.refined.lowByte;
892 dt.raw[1] = blk_d.refined.highByte;
897 minute = (dt.refined.minute2 << 2) | dt.refined.minute1;
898 hour = (dt.refined.hour2 << 4) | dt.refined.hour1;
900 offset_sign = (dt.refined.offset_sense == 1) ?
'+' :
'-';
901 offset_h = (dt.refined.offset * 30) / 60;
902 offset_m = (dt.refined.offset * 30) - (offset_h * 60);
904 sprintf(rds_time,
"%02u:%02u %c%02u:%02u", hour, minute, offset_sign, offset_h, offset_m);
913
914
915
916
917
921 return reg0a->refined.RDSS;
925
926
927
928
929
930
934 return reg0b->refined.ABCD_E;
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
956 return reg0b->refined.BLERB;
960
961
962
963
964
967 return (reg0a->refined.RDSS && reg0b->refined.ABCD_E == 0 && reg0b->refined.BLERB == 0 );
971
972
973
974
975
976
978 reg04->refined.RDS_FIFO_EN = value;
979 setRegister(
REG04,reg04->raw);
983
984
985
986
987
988
991 reg04->refined.RDS_FIFO_CLR = 1;
992 setRegister(
REG04, reg04->raw);
1000
1001
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016void RDA5807::
convertToChar(uint16_t value,
char *strValue, uint8_t len, uint8_t dot, uint8_t separator,
bool remove_leading_zeros)
1019 for (
int i = (len - 1); i >= 0; i--)
1023 strValue[i] = d + 48;
1025 strValue[len] =
'\0';
1028 for (
int i = len; i >= dot; i--)
1030 strValue[i + 1] = strValue[i];
1032 strValue[dot] = separator;
1035 if (remove_leading_zeros) {
1036 if (strValue[0] ==
'0')
1039 if (strValue[1] ==
'0')
1047
1048
1049
1050
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075void 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 ) {
1076 reg06->refined.R_DELY = R_DELY;
1077 reg06->refined.L_DELY = L_DELY;
1078 reg06->refined.SCLK_O_EDGE = SCLK_O_EDGE;
1079 reg06->refined.SW_O_EDGE = SW_O_EDGE;
1080 reg06->refined.I2S_SW_CNT = I2S_SW_CNT;
1081 reg06->refined.WS_I_EDGE = WS_I_EDGE;
1082 reg06->refined.DATA_SIGNED = DATA_SIGNED;
1083 reg06->refined.SCLK_I_EDGE = SCLK_I_EDGE;
1084 reg06->refined.WS_LR = WS_LR;
1085 reg06->refined.SLAVE_MASTER = SLAVE_MASTER;
1086 reg06->refined.OPEN_MODE = OPEN_MODE;
1088 setRegister(
REG06,reg06->raw);
1094
1095
1096
1097
1098
1099
1101 reg04->refined.I2S_ENABLE = value;
1102 setRegister(
REG04,reg04->raw);
1107
1108
1109
1110
1111
1113 reg06->refined.SLAVE_MASTER = !value;
1114 setRegister(
REG06,reg06->raw);
1120
1121
1122
1123
1124
1125
1127 reg06->refined.I2S_SW_CNT = value;
1128 setRegister(
REG06,reg06->raw);
1133
1134
1135
1136
1137
1139 reg06->refined.DATA_SIGNED = value;
1140 setRegister(
REG06,reg06->raw);
1147
1148
1149
1154
1155
1156
1157
1160 reg04->refined.SOFTMUTE_EN = value;
1161 setRegister(
REG04, reg04->raw);
1168
1169
1170
1171
1174 reg02->refined.SEEK = 0;
1175 reg02->refined.DMUTE = !value;
1176 setRegister(
REG02,reg02->raw);
1180
1181
1182
1183
1186 reg02->refined.SEEK = 0;
1187 reg02->refined.DHIZ = !value;
1188 setRegister(
REG02,reg02->raw);
1193
1194
1195
1196
1197
1200 reg02->refined.SEEK = 0;
1201 reg02->refined.MONO = value;
1202 setRegister(
REG02, reg02->raw);
1206
1207
1208
1209
1210
1213 reg02->refined.SEEK = 0;
1214 reg02->refined.BASS = value;
1215 setRegister(
REG02, reg02->raw);
1219
1220
1221
1222
1223
1227 return reg0a->refined.ST;
1233
1234
1235
1236
1237
1240 if ( value > 15 ) value = 15;
1242 reg05->refined.VOLUME =
this->currentVolume = value;
1243 setRegister(
REG05, reg05->raw);
1247
1248
1249
1250
1251
1254 return this->currentVolume;
1258
1259
1260
1261
1264 if (
this->currentVolume < 15)
1266 this->currentVolume++;
1267 setVolume(
this->currentVolume);
1272
1273
1274
1275
1278 if (
this->currentVolume > 0)
1280 this->currentVolume--;
1281 setVolume(
this->currentVolume);
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.
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 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 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.
int getRssi()
Gets the current Rssi.
void setFrequencyUp()
Increments the current frequency.
void setFmDeemphasis(uint8_t de)
Sets De-emphasis.
uint8_t getDeviceId()
Gets the Device identification.
uint16_t getFrequency()
Gets the current frequency.
void setGpio(uint8_t gpioPin, uint8_t gpioSetup=0, int mcuPin=-1)
Set the Device GPIO pins.
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()
Get the Rds Sync.
uint8_t getBlockId()
Get 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()
Get 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)
Configure 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)
Enable 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.