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);
205
206
207
208
209
212 this->oscillatorType = oscillator_type;
213 this->clockType = clock_type;
222
223
224
225
226
227
228
229
230
231
232
235 reg03->refined.CHAN = channel;
236 reg03->refined.TUNE = 1;
237 reg03->refined.BAND =
this->currentFMBand;
238 reg03->refined.SPACE =
this->currentFMSpace;
239 reg03->refined.DIRECT_MODE = 0;
240 setRegister(
REG03, reg03->raw);
245
246
247
248
251 uint16_t channel = (frequency -
this->startBand[currentFMBand] ) / (
this->fmSpace[
this->currentFMSpace] );
253 this->currentFrequency = frequency;
257
258
259
260
263 if (
this->currentFrequency <
this->endBand[
this->currentFMBand])
264 this->currentFrequency += (
this->fmSpace[currentFMSpace] );
266 this->currentFrequency =
this->startBand[
this->currentFMBand];
268 setFrequency(
this->currentFrequency);
272
273
274
275
278 if (
this->currentFrequency >
this->startBand[
this->currentFMBand])
279 this->currentFrequency -= (
this->fmSpace[currentFMSpace] );
281 this->currentFrequency =
this->endBand[
this->currentFMBand];
283 setFrequency(
this->currentFrequency);
287
288
289
290
293 return this->currentFrequency;
297
298
299
300
301
302
303
304
308 return reg0a->refined.READCHAN;
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
328 return getRealChannel() * (
this->fmSpace[
this->currentFMSpace]) +
this->startBand[currentFMBand];
332
333
334
335
336
337
340 reg02->refined.SEEK = 1;
341 reg02->refined.SKMODE = seek_mode;
342 reg02->refined.SEEKUP = direction;
343 setRegister(
REG02,reg02->raw);
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378void RDA5807::
seek(uint8_t seek_mode, uint8_t direction,
void (*showFunc)())
383 reg02->refined.SEEK = 1;
384 reg02->refined.SKMODE = seek_mode;
385 reg02->refined.SEEKUP = direction;
386 setRegister(
REG02, reg02->raw);
387 this->currentFrequency = getRealFrequency();
388 if (showFunc != NULL)
394 }
while (reg0a->refined.STC == 0);
396 setFrequency(getRealFrequency());
402
403
404
405
408 reg05->refined.SEEKTH = value;
409 setRegister(
REG05,reg05->raw);
413
414
415
416
417
418
419
420
421
422
423
424
425
426
430 reg03->refined.BAND =
this->currentFMBand = band;
431 setRegister(
REG03,reg03->raw);
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
452 reg03->refined.SPACE = space;
453 this->currentFMSpace = space;
454 setRegister(
REG03, reg03->raw);
458
459
460
461
462
463
483 this->setSpace(space);
488
489
490
491
492
493
497 return reg0b->refined.RSSI;
501
502
503
504
507 reg04->refined.SOFTMUTE_EN = value;
508 setRegister(
REG04, reg04->raw);
515
516
517
518
521 reg02->refined.SEEK = 0;
522 reg02->refined.DHIZ = !value;
523 setRegister(
REG02,reg02->raw);
527
528
529
530
531
534 reg02->refined.SEEK = 0;
535 reg02->refined.MONO = value;
536 setRegister(
REG02, reg02->raw);
540
541
542
543
544
547 reg02->refined.SEEK = 0;
548 reg02->refined.BASS = value;
549 setRegister(
REG02, reg02->raw);
553
554
555
556
557
561 return reg0a->refined.ST;
566
567
568
569
570
571
573 reg02->refined.DHIZ = !value;
574 setRegister(
REG02, reg02->raw);
579
580
581
582
583
586 if ( value > 15 ) value = 15;
588 reg05->refined.VOLUME =
this->currentVolume = value;
589 setRegister(
REG05, reg05->raw);
593
594
595
596
597
600 return this->currentVolume;
604
605
606
607
610 if (
this->currentVolume < 15)
612 this->currentVolume++;
613 setVolume(
this->currentVolume);
618
619
620
621
624 if (
this->currentVolume > 0)
626 this->currentVolume--;
627 setVolume(
this->currentVolume);
633
634
635
636
637
644
645
646
647
648
649
651 reg04->refined.DE = de;
652 setRegister(
REG04,reg04->raw);
656
657
658
659
662
663
664
665
666
667
670 reg02->refined.SEEK = 0;
671 reg02->refined.RDS_EN = value;
672 setRegister(
REG02, reg02->raw);
676
677
678
679
680
681
684 reg02->refined.SEEK = 0;
685 reg02->refined.RDS_EN = 1;
686 setRegister(
REG02, reg02->raw);
687 reg04->refined.RBDS = value;
688 setRegister(
REG04, reg04->raw);
693
694
695
696
697
698
699
704 return reg0a->refined.RDSR;
708
709
710
711
712
717 blkb.blockB = reg0d->RDSB;
718 return blkb.refined.textABFlag;
722
723
724
725
726
732 blkb.blockB = reg0d->RDSB;
733 return blkb.group0.groupType;
737
738
739
740
741
746 blkb.blockB = reg0d->RDSB;
747 return blkb.refined.versionCode;
751
752
753
754
755
760 blkb.blockB = reg0d->RDSB;
761 return blkb.refined.programType;
765
766
767
768
769
776 blk.raw = reg0f->RDSD;
778 raw[1] = blk.refined.lowByte;
779 raw[0] = blk.refined.highByte;
781 for (i = j = 0; i < 2; i++)
783 if (raw[i] == 0xD || raw[i] == 0xA)
801
802
803
804
805
806
811 word16_to_bytes blk_c, blk_d;
813 blk_c.raw = reg0e->RDSC;
814 blk_d.raw = reg0f->RDSD;
816 raw[0] = blk_c.refined.highByte;
817 raw[1] = blk_c.refined.lowByte;
818 raw[2] = blk_d.refined.highByte;
819 raw[3] = blk_d.refined.lowByte;
821 for (i = j = 0; i < 4; i++)
823 if (raw[i] == 0xD || raw[i] == 0xA)
841
842
843
844
845
848 static int rdsTextAdress2A;
853 blkb.blockB = reg0d->RDSB;
854 rdsTextAdress2A = blkb.group2.address;
856 if (rdsTextAdress2A >= 16)
860 rdsTextAdress2A += 4;
865
866
867
868
869
870
871
874 static int rdsTextAdress0A;
878 blkb.blockB = reg0d->RDSB;
880 if (blkb.group0.groupType == 0)
883 rdsTextAdress0A = blkb.group0.address;
884 if (rdsTextAdress0A >= 0 && rdsTextAdress0A < 4)
887 rds_buffer0A[8] =
'\0';
895
896
897
898
899
900
903 static int rdsTextAdress2A;
908 blkb.blockB = reg0d->RDSB;
909 rdsTextAdress2A = blkb.group2.address;
911 if (blkb.group2.groupType == 2)
915 if (rdsTextAdress2A >= 0 && rdsTextAdress2A < 16)
918 rds_buffer2A[63] =
'\0';
926
927
928
929
932 static int rdsTextAdress2B;
936 blkb.blockB = reg0d->RDSB;
937 if (blkb.group2.groupType == 2)
940 rdsTextAdress2B = blkb.group2.address;
941 if (rdsTextAdress2B >= 0 && rdsTextAdress2B < 16)
951
952
953
954
955
961 word16_to_bytes blk_b, blk_c, blk_d;
966 blk_b.raw = blkb.blockB = reg0d->RDSB;
967 blk_c.raw = reg0e->RDSC;
968 blk_d.raw = reg0f->RDSD;
973 if (blkb.group0.groupType == 4)
981 dt.raw[4] = blk_b.refined.lowByte;
982 dt.raw[5] = blk_b.refined.highByte;
984 dt.raw[2] = blk_c.refined.lowByte;
985 dt.raw[3] = blk_c.refined.highByte;
987 dt.raw[0] = blk_d.refined.lowByte;
988 dt.raw[1] = blk_d.refined.highByte;
993 minute = (dt.refined.minute2 << 2) | dt.refined.minute1;
994 hour = (dt.refined.hour2 << 4) | dt.refined.hour1;
996 offset_sign = (dt.refined.offset_sense == 1) ?
'+' :
'-';
997 offset_h = (dt.refined.offset * 30) / 60;
998 offset_m = (dt.refined.offset * 30) - (offset_h * 60);
1000 sprintf(rds_time,
"%02u:%02u %c%02u:%02u", hour, minute, offset_sign, offset_h, offset_m);
1009
1010
1011
1012
1013
1017 return reg0a->refined.RDSS;
1021
1022
1023
1024
1025
1026
1030 return reg0b->refined.ABCD_E;
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1052 return reg0b->refined.BLERB;
1056
1057
1058
1059
1060
1063 return (reg0a->refined.RDSS && reg0b->refined.ABCD_E == 0 && reg0b->refined.BLERB == 0 );
1067
1068
1069
1070
1071
1072
1074 reg04->refined.RDS_FIFO_EN = value;
1075 setRegister(
REG04,reg04->raw);
1079
1080
1081
1082
1083
1084
1087 reg04->refined.RDS_FIFO_CLR = 1;
1088 setRegister(
REG04, reg04->raw);
1096
1097
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112void RDA5807::
convertToChar(uint16_t value,
char *strValue, uint8_t len, uint8_t dot, uint8_t separator,
bool remove_leading_zeros)
1115 for (
int i = (len - 1); i >= 0; i--)
1119 strValue[i] = d + 48;
1121 strValue[len] =
'\0';
1124 for (
int i = len; i >= dot; i--)
1126 strValue[i + 1] = strValue[i];
1128 strValue[dot] = separator;
1131 if (remove_leading_zeros) {
1132 if (strValue[0] ==
'0')
1135 if (strValue[1] ==
'0')
1143
1144
1145
1146
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171void 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 ) {
1172 reg06->refined.R_DELY = R_DELY;
1173 reg06->refined.L_DELY = L_DELY;
1174 reg06->refined.SCLK_O_EDGE = SCLK_O_EDGE;
1175 reg06->refined.SW_O_EDGE = SW_O_EDGE;
1176 reg06->refined.I2S_SW_CNT = I2S_SW_CNT;
1177 reg06->refined.WS_I_EDGE = WS_I_EDGE;
1178 reg06->refined.DATA_SIGNED = DATA_SIGNED;
1179 reg06->refined.SCLK_I_EDGE = SCLK_I_EDGE;
1180 reg06->refined.WS_LR = WS_LR;
1181 reg06->refined.SLAVE_MASTER = SLAVE_MASTER;
1182 reg06->refined.OPEN_MODE = OPEN_MODE;
1184 setRegister(
REG06,reg06->raw);
1190
1191
1192
1193
1194
1195
1197 reg04->refined.I2S_ENABLE = value;
1198 setRegister(
REG04,reg04->raw);
1203
1204
1205
1206
1207
1209 reg06->refined.SLAVE_MASTER = !value;
1210 setRegister(
REG06,reg06->raw);
1216
1217
1218
1219
1220
1221
1223 reg06->refined.I2S_SW_CNT = value;
1224 setRegister(
REG06,reg06->raw);
1229
1230
1231
1232
1233
1235 reg06->refined.DATA_SIGNED = value;
1236 setRegister(
REG06,reg06->raw);
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.
uint16_t getRealFrequency()
Gets the current frequency bases on the current channel.
void * getStatus(uint8_t reg)
Gets the register content of a given status register (from 0x0A to 0x0F)
void powerDown()
Power the receiver off.
bool isStereo()
Gets the current Stereo status.
void powerUp()
Powers the receiver on.
uint16_t getRealChannel()
Gets the current channel stored in 0x0A status register.
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 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.
void setVolume(uint8_t value)
Sets the audio volume level.
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.
uint8_t getVolume()
Gets the current audio volume level.
void setSpace(uint8_t space=0)
Sets the FM channel space.
void setBass(bool value)
Sets Bass Boost.
void setVolumeUp()
Increments the audio volume.
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 setVolumeDown()
Decrements the audio volume.
void setChannel(uint16_t channel)
Sets the channel.
void setAudioOutputHighImpedance(bool value)
Sets the audio output hight or low impedance.
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.
void setFrequency(uint16_t frequency)
Sets the frequency.
void setMono(bool value)
Sets audio Mono or stereo.
void setFrequencyDown()
Decrements the current frequency.
void setSoftmute(bool value)
Sets Soft Mute Enable or disable.
void seek(uint8_t seek_mode, uint8_t direction, void(*showFunc)())
Seek function.
void setMute(bool value)
Sets Audio mute or unmute.
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.