 |
PU2CLR BK108X Arduino Library
1.0.1
This is an Arduino Library to control the BK108X device
|
Go to the documentation of this file.
42 void BK108X::
setI2C(uint8_t i2c_addr) {
43 this->deviceAddress = i2c_addr;
54 void BK108X::
i2cInit(
int pin_sdio,
int pin_sclk){
55 this->pin_sdio = pin_sdio;
56 this->pin_sclk = pin_sclk;
65 pinMode(
this->pin_sdio, OUTPUT);
66 pinMode(
this->pin_sclk, OUTPUT);
67 digitalWrite(
this->pin_sdio, HIGH);
68 digitalWrite(
this->pin_sclk, HIGH);
71 digitalWrite(
this->pin_sdio, LOW);
73 digitalWrite(
this->pin_sclk, LOW);
75 digitalWrite(
this->pin_sdio, HIGH);
84 pinMode(pin_sdio, OUTPUT);
85 digitalWrite(
this->pin_sdio, LOW);
88 digitalWrite(
this->pin_sclk, HIGH);
91 digitalWrite(
this->pin_sdio, HIGH);
104 pinMode(pin_sdio, OUTPUT);
105 digitalWrite(
this->pin_sclk, LOW);
106 digitalWrite(
this->pin_sdio, LOW);
107 delayMicroseconds(1);
108 digitalWrite(
this->pin_sclk, HIGH);
109 delayMicroseconds(1);
110 digitalWrite(
this->pin_sclk, LOW);
120 pinMode(pin_sdio, OUTPUT);
122 digitalWrite(
this->pin_sclk, LOW);
123 digitalWrite(
this->pin_sdio, HIGH);
124 delayMicroseconds(1);
125 digitalWrite(
this->pin_sclk, HIGH);
126 delayMicroseconds(1);
127 digitalWrite(
this->pin_sclk, LOW);
139 pinMode(pin_sdio, INPUT);
140 delayMicroseconds(1);
142 digitalWrite(
this->pin_sclk, HIGH);
143 delayMicroseconds(1);
145 ack = digitalRead(
this->pin_sdio);
147 digitalWrite(
this->pin_sclk, LOW);
148 delayMicroseconds(1);
160 pinMode(pin_sdio, OUTPUT);
161 delayMicroseconds(1);
163 for (
int i = 0; i < 8; i++) {
165 digitalWrite(
this->pin_sdio, (
bool)(data &
this->deviceAddress) );
167 delayMicroseconds(1);
168 digitalWrite(
this->pin_sclk, HIGH);
169 delayMicroseconds(1);
170 digitalWrite(
this->pin_sclk, LOW);
184 pinMode(pin_sdio, INPUT);
185 delayMicroseconds(1);
187 for (
int i = 0; i < 8; i++)
189 digitalWrite(
this->pin_sclk, HIGH);
191 delayMicroseconds(1);
192 if ( digitalRead(
this->pin_sdio) )
194 digitalWrite(
this->pin_sclk, LOW);
195 delayMicroseconds(1);
209 word16_to_bytes data;
213 this->i2cWriteByte(
this->deviceAddress);
214 this->i2cReceiveAck();
218 this->i2cWriteByte(reg);
219 this->i2cReceiveAck();
221 this->i2cWriteByte(data.refined.highByte);
222 this->i2cReceiveAck();
223 this->i2cWriteByte(data.refined.lowByte);
224 this->i2cReceiveAck();
237 word16_to_bytes data;
240 this->i2cWriteByte(
this->deviceAddress);
241 this->i2cReceiveAck();
243 reg = (reg << 1) | 1;
245 this->i2cWriteByte(reg);
246 this->i2cReceiveAck();
248 data.refined.highByte =
this->i2cReadByte();
250 data.refined.lowByte =
this->i2cReadByte();
273 word16_to_bytes result;
274 result.raw =
this->readRegister(reg);
275 shadowRegisters[reg] = result.raw;
293 this->writeRegister(reg, value);
294 shadowRegisters[reg] = value;
295 delayMicroseconds(250);
304 return getRegister(
REG00);
314 return getRegister(
REG01);
334 while ( reg0a->refined.STC == 0) {
339 reg03->refined.TUNE = 0;
340 setRegister(
REG03, reg03->raw);
350 reg02->refined.DISABLE = 1;
351 reg02->refined.ENABLE = 0;
352 setRegister(
REG02, reg02->raw);
353 reg02->refined.DISABLE = 0;
354 reg02->refined.ENABLE = 1;
355 setRegister(
REG02, reg02->raw);
367 reg02->refined.DSMUTE = 1;
368 reg02->refined.STEREO = 1;
369 reg02->refined.ENABLE = 1;
370 setRegister(
REG02,reg02->raw);
372 setRegister(
REG03, 0x00);
373 setRegister(
REG04, 0x00);
376 this->currentVolume = reg05->refined.VOLUME = 15;
377 setRegister(
REG05, reg05->raw);
380 reg06->refined.CLKSEL = 1;
381 reg06->refined.SKSNR = 0x06;
382 reg06->refined.SKCNT = 0x0F;
383 setRegister(
REG06, reg06->raw);
394 reg02->refined.DISABLE = 1;
395 reg02->refined.ENABLE = 0;
396 setRegister(
REG02, reg02->raw);
409 void BK108X::
setup(
int sda_pin,
int sclk_pin,
int rdsInterruptPin,
int seekInterruptPin, uint8_t oscillator_type)
414 if (rdsInterruptPin >= 0)
416 if (seekInterruptPin >= 0)
419 this->oscillatorType = oscillator_type;
435 void BK108X::
setFM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step)
438 this->currentStep = step;
439 this->currentFrequency = default_frequency;
440 this->minimumFrequency = minimum_frequency;
441 this->maximumFrequency = maximum_frequency;
446 setRegister(
REG07, reg07->raw);
448 this->currentFMBand = reg05->refined.BAND = 0;
449 this->currentFMSpace = reg05->refined.SPACE = 2;
450 setRegister(
REG05, reg05->raw);
452 setFrequency(default_frequency);
465 void BK108X::
setAM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step, uint16_t am_space)
467 this->currentStep = step;
468 this->currentFrequency = default_frequency;
469 this->minimumFrequency = minimum_frequency;
470 this->maximumFrequency = maximum_frequency;
472 this->currentMode = reg07->refined.MODE =
MODE_AM;
473 setRegister(
REG07, reg07->raw);
476 if (minimum_frequency < 520 )
477 this->currentAMBand = reg05->refined.BAND = 0;
478 else if (minimum_frequency < 1800)
479 this->currentAMBand = reg05->refined.BAND = 1;
481 this->currentAMBand = reg05->refined.BAND = 2;
483 this->currentAMSpace = reg05->refined.SPACE = am_space;
485 setRegister(
REG05, reg05->raw);
487 this->setFrequency(default_frequency);
499 reg02->refined.SEEK = 0;
500 setRegister(
REG02,reg02->raw);
502 reg03->refined.TUNE = 1;
503 reg03->refined.CHAN = channel;
505 setRegister(
REG03,reg03->raw);
509 this->currentChannel = channel;
522 if (
this->currentMode ==
MODE_FM) {
523 channel = (frequency -
this->fmStartBand[
this->currentFMBand]) /
this->fmSpace[
this->currentFMSpace];
526 channel = (frequency -
this->amStartBand[
this->currentAMBand]) /
this->amSpace[
this->currentAMSpace];
529 this->setChannel(channel);
539 this->currentFrequency +=
this->currentStep;
541 if (
this->currentFrequency >
this->maximumFrequency )
542 this->currentFrequency =
this->minimumFrequency;
544 setFrequency(
this->currentFrequency);
554 this->currentFrequency -=
this->currentStep;
556 if (
this->currentFrequency <
this->minimumFrequency)
557 this->currentFrequency =
this->maximumFrequency;
559 setFrequency(
this->currentFrequency);
569 return this->currentFrequency;
579 return this->currentChannel;
591 return reg0b->refined.READCHAN;
604 return getRealChannel() *
this->amSpace[
this->currentAMSpace] +
this->amStartBand[
this->currentAMBand];
606 return getRealChannel() *
this->fmSpace[
this->currentFMSpace] +
this->fmStartBand[
this->currentFMBand];
621 void BK108X::
seek(uint8_t seek_mode, uint8_t direction)
659 void BK108X::
seek(uint8_t seek_mode, uint8_t direction,
void (*showFunc)())
789 if ( value > 31)
return;
790 this->currentVolume = value;
792 reg05->refined.VOLUME = value;
794 setRegister(
REG05,reg05->raw);
805 return this->currentVolume;
815 if (
this->currentVolume < 31)
817 this->currentVolume++;
818 setVolume(
this->currentVolume);
829 if (
this->currentVolume > 0)
831 this->currentVolume--;
832 setVolume(
this->currentVolume);
char * getRdsText(void)
Gets the RDS Text when the message is of the Group Type 2 version A.
void setFM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step)
Sets the receiver to FM mode.
void i2cInit(int pin_sdio, int pin_sclk)
Sets the MCU pins connected to the I2C bus.
uint16_t readRegister(uint8_t reg)
Gets an array of values from a BK108X given register.
void setBand(uint8_t band=1)
Sets the FM Band
bool isStereo()
Checks stereo / mono status.
uint16_t getChannel()
Gets the current channel.
char * getRdsTime()
Gets the RDS time and date when the Group type is 4.
char * getRdsText2A(void)
Gets the Text processed for the 2A group.
uint8_t i2cReceiveAck()
Gets Acknowledge (ACK)
void seek(uint8_t seek_mode, uint8_t direction)
Seek function.
void i2cAck()
Sends Acknowledge (ACK)
void setExtendedVolumeRange(bool value)
Sets Extended Volume Range.
uint16_t getDeviceId()
Returns the Device Indentifiction.
void i2cBeginTransaction()
Starts the I2C bus transaction
void powerDown()
Powers the receiver off.
void getNext4Block(char *c)
Process data received from group 2A.
uint16_t getRealFrequency()
Gets the frequency based on READCHAN register (0x0B)
void setFrequency(uint16_t frequency)
Sets the FM frequency.
int getRssi()
Gets the Rssi.
void seek(uint8_t seek_mode, uint8_t direction, void(*showFunc)())
Seek function.
void setMute(bool value)
Sets the Mute true or false.
uint8_t getRdsVersionCode(void)
Gets the version code (extracted from the Block B)
char * getRdsText0A(void)
Gets the station name and other messages.
uint8_t i2cReadByte()
Gets a Byte from the slave device.
void setSpace(uint8_t space=0)
Sets the FM Space
uint16_t getRealChannel()
Gets the current channel stored in register 0x0B.
bool getRdsSync()
Get the Rds Sync.
void setSoftmuteAttenuation(uint8_t value)
Sets Softmute Attenuation..
uint16_t getChipId()
Returns the Chip Indentifiction.
uint16_t getRegister(uint8_t reg)
Gets a givens current register content of the device.
void setChannel(uint16_t channel)
Sets the channel.
void writeRegister(uint8_t reg, uint16_t vakue)
Sends an array of values to a BK108X given register.
void setVolumeDown()
Decrements the audio volume.
void waitAndFinishTune()
Wait STC (Seek/Tune Complete) status becomes 0.
void getNext2Block(char *c)
Process data received from group 2B.
void setSoftmute(bool value)
Sets the Softmute true or false.
void getRdsStatus()
Gets the RDS registers information.
uint16_t getFrequency()
Gets the current frequency.
void setFrequencyUp()
Increments the current frequency.
void setSoftmuteAttack(uint8_t value)
Sets Softmute Attack/Recover Rate.
void reset()
Resets the device.
uint8_t getRdsProgramType(void)
Returns the Program Type (extracted from the Block B)
void setVolume(uint8_t value)
Sets the audio volume level.
uint8_t getRdsFlagAB(void)
Returns the current Text Flag A/B
void setFmDeemphasis(uint8_t de)
Sets De-emphasis.
void powerUp()
Powers the receiver on.
uint8_t getVolume()
Gets the current audio volume level.
void setup(int sda_pin, int sclk_pin, int rdsInterruptPin=-1, int seekInterruptPin=-1, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL)
Starts the device.
void setFrequencyDown()
Decrements the current frequency.
void i2cNack()
Sends Not Acknowledge (ACK)
void setRdsMode(uint8_t rds_mode=0)
Sets the Rds Mode Standard or Verbose.
uint16_t getRdsGroupType()
Return the group type.
char * getRdsText2B(void)
Gets the Text processed for the 2B group.
void setAM(uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step, uint16_t am_space=0)
Sets the receiver to AM mode.
void setMono(bool value)
Sets the Mono true or false (stereo)
void i2cEndTransaction()
Finish the I2C bus transaction.
void setI2C(uint8_t i2c_addr=I2C_DEVICE_ADDR)
Sets I2C bus address.
void setSeekThreshold(uint8_t value)
Sets RSSI Seek Threshold.
void setRds(bool value)
Sets the RDS operation.
void setVolumeUp()
Increments the audio volume.
void setAgc(bool value)
Sets the AGC enable or disable.
void setRegister(uint8_t reg, uint16_t value)
Sets a given value to the device registers.
void i2cWriteByte(uint8_t data)
Sends a Byte to the slave device.
bool getRdsReady()
Returns true if RDS Ready.