![]() |
PU2CLR BK108X Arduino Library 1.0.2
This is an Arduino Library to control the BK108X device
|
Functions | |
void | BK108X::setI2CAddress (int bus_addr) |
Sets the I2C bus address. | |
void | BK108X::setDelayAfterCrystalOn (uint8_t ms_value) |
Set the Delay After Crystal On (default 500ms) | |
uint16_t | BK108X::getShadownRegister (uint8_t register_number) |
Get the Shadown Register object. | |
void | BK108X::setShadownRegister (uint8_t register_number, uint16_t value) |
Sets a given value to the Shadown Register. | |
void | BK108X::setFMGain (uint8_t value=0) |
set the FM gain. | |
uint8_t | BK108X::getCurrentMode () |
Get the Current Mode (AM or FM) | |
void | BK108X::setStereoThresholdPilotStrength (uint8_t value) |
Sets the Stereo Threshold of Pilotto Strength. | |
void | BK108X::setFmDeemphasis (uint8_t de) |
Sets De-emphasis. | |
void | BK108X::setTimeCallStrengthPilot (uint8_t value) |
Sets the time used to call the strength of pilot. | |
uint16_t | BK108X::getRegister (uint8_t reg) |
Gets a givens current register content of the device. | |
void | BK108X::setRegister (uint8_t reg, uint16_t value) |
Sets a given value to the device registers. | |
bk_reg0a | BK108X::getStatus () |
Gets the current status (register 0x0A) content. | |
void | BK108X::waitAndFinishTune () |
Wait STC (Seek/Tune Complete) status becomes 0. | |
void | BK108X::reset () |
Resets the device. | |
void | BK108X::powerUp () |
Powers the receiver on. | |
void | BK108X::powerDown () |
Powers the receiver off. | |
void | BK108X::setup (int sda_pin, int sclk_pin, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL, uint32_t oscillator_frequency=32768) |
Starts the device. | |
void | BK108X::setFM (uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step) |
Sets the receiver to FM mode. | |
void | BK108X::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 | BK108X::setChannel (uint16_t channel) |
Sets the channel. | |
void | BK108X::setFrequency (uint16_t frequency) |
Sets the FM frequency. | |
void | BK108X::setFrequencyUp () |
Increments the current frequency. | |
void | BK108X::setFrequencyDown () |
Decrements the current frequency. | |
uint16_t | BK108X::getFrequency () |
Gets the current frequency. | |
uint16_t | BK108X::getChannel () |
Gets the current channel. | |
uint16_t | BK108X::getRealChannel () |
Gets the current channel stored in register 0x0B. | |
uint16_t | BK108X::getRealFrequency () |
Gets the frequency based on READCHAN register (0x0B) | |
void | BK108X::seekSoftware (uint8_t seek_mode, uint8_t direction, void(*showFunc)()=NULL) |
Seeks a station via Software. | |
void | BK108X::seekHardware (uint8_t seek_mode, uint8_t direction, void(*showFunc)()=NULL) |
Seeks a station via hardware functionality. | |
void | BK108X::setSeekThreshold (uint8_t rssiValue, uint8_t snrValue) |
Sets RSSI and SNR Seek Threshold. | |
void | BK108X::setBand (uint8_t band=1) |
Sets the current band for AM or FM. | |
void | BK108X::setSpace (uint8_t space=0) |
Sets the Space channel for AM or FM. | |
int | BK108X::getRssi () |
Gets the current Rssi. | |
int | BK108X::getSnr () |
Gets the current SNR. | |
void | BK108X::setSoftMute (bool value) |
Sets the Softmute true or false. | |
void | BK108X::setSoftMuteAttack (uint8_t value) |
Sets Softmute Attack/Recover Rate. | |
void | BK108X::setSoftMuteAttenuation (uint8_t value) |
Sets Softmute Attenuation. | |
void | BK108X::setMuteThreshold (uint8_t rssi, uint8_t snr) |
Set the Mute Threshold based on RSSI and SNR. | |
void | BK108X::setSeekMute (bool value) |
Disable or Enable soft mute when seeking. | |
void | BK108X::setAfcMute (bool value) |
Disable or Enable soft mute when AFCRL is high. | |
void | BK108X::setAudioMute (bool left, bool right) |
Sets the Mute true or false. | |
void | BK108X::setAudioMute (bool value) |
Sets the Mute true or false. | |
void | BK108X::setMono (bool value) |
Sets the Mono true or false (stereo) | |
bool | BK108X::isStereo () |
Checks stereo / mono status. | |
void | BK108X::setVolume (uint8_t value) |
Sets the audio volume level. | |
uint8_t | BK108X::getVolume () |
Gets the current audio volume level. | |
void | BK108X::setVolumeUp () |
Increments the audio volume. | |
void | BK108X::setVolumeDown () |
Decrements the audio volume. | |
|
inline |
Sets the I2C bus address.
This function must to be called before setup function if your device are not using 0x10 (default)
bus_addr | I2C buss address |
Definition at line 844 of file BK108X.h.
References BK108X::deviceAddress.
|
inline |
|
inline |
Get the Shadown Register object.
if you want to get the current value of the device register, call getAllRegisters() before calling this function.
if you are dealing with the status register (0x0A), you can call getStatus() instead getAllRegisters().
register_number |
|
inline |
Sets a given value to the Shadown Register.
You have to call setAllRegisters() after setting the Shadow Registers to store the value into the device.
register_number | register index (from 0x00 to 0x0F) |
value | 16 bits word with the content of the register |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
uint16_t BK108X::getRegister | ( | uint8_t | reg | ) |
Gets a givens current register content of the device.
device | register address |
Definition at line 276 of file BK108X.cpp.
void BK108X::setRegister | ( | uint8_t | reg, |
uint16_t | value | ||
) |
Sets a given value to the device registers.
For write operations, the device acknowledge is followed by an eight bit data word latched internally on rising edges of SCLK. The device acknowledges each byte of data written by driving SDIO low after the next falling SCLK edge, for 1 cycle.
An internal address counter automatically increments to allow continuous data byte writes, starting with the upper byte of register 02h, followed by the lower byte of register 02h, and onward until the lower byte of the last register is reached. The internal address counter then automatically wraps around to the upper byte of register 00h and proceeds from there until continuous writes end.
The registers from 0x2 to 0x07 are used to setup the device. This method writes the array shadowRegisters, elements 8 to 14 (corresponding the registers 0x2 to 0x7 respectively) into the device. See Device registers map in BK108X.h file.
To implement this, a register maping was created to deal with each register structure. For each type of register, there is a reference to the array element.
device | register address |
Definition at line 296 of file BK108X.cpp.
bk_reg0a BK108X::getStatus | ( | ) |
Gets the current status (register 0x0A) content.
You can use this function when you need to get more than one status attribute at once.
See example code below.
Definition at line 341 of file BK108X.cpp.
void BK108X::waitAndFinishTune | ( | ) |
Wait STC (Seek/Tune Complete) status becomes 0.
Should be used before processing Tune or Seek.
The STC bit being cleared indicates that the TUNE or SEEK bits may be set again to start another tune or seek operation. Do not set the TUNE or SEEK bits until the BK108X clears the STC bit.
Definition at line 354 of file BK108X.cpp.
Referenced by BK108X::setChannel().
void BK108X::reset | ( | ) |
Resets the device.
Definition at line 371 of file BK108X.cpp.
void BK108X::powerUp | ( | ) |
Powers the receiver on.
Starts the receiver and set default configurations suggested by the BELEN
Definition at line 388 of file BK108X.cpp.
Referenced by BK108X::setup().
void BK108X::powerDown | ( | ) |
Powers the receiver off.
Definition at line 457 of file BK108X.cpp.
void BK108X::setup | ( | int | sda_pin, |
int | sclk_pin, | ||
uint8_t | oscillator_type = OSCILLATOR_TYPE_CRYSTAL , |
||
uint32_t | oscillator_frequency = 32768 |
||
) |
Starts the device.
Initiates the divice (similar to the previous setup function)
This method allows different clock frequencies.
You have to inform at least two parameters: RESET pin and I2C SDA pin of your MCU
sda_pin | MCU SDA/SDIO pin (ATMEGA328 must be 4) |
sclk_pin | MCU SCLK/CLK pin (ATMEGA328 must be 5) |
oscillator_type | 0 = External clock input; 1= Internal oscillator input (default). |
oscillator_frequency | from 32768Hz (32.768 KHz) to 34400000Hz (34.4Mhz). Default (32.768 kHz). For frequency less than 4 MHz, it must be multiplier of 32.768KHz. |
Definition at line 477 of file BK108X.cpp.
References BK108X::i2cInit(), and BK108X::powerUp().
void BK108X::setFM | ( | uint16_t | minimum_frequency, |
uint16_t | maximum_frequency, | ||
uint16_t | default_frequency, | ||
uint16_t | step | ||
) |
Sets the receiver to FM mode.
Configures the receiver on FM mode; Also sets the band limits, defaul frequency and step.
minimum_frequency | minimum frequency for the band |
maximum_frequency | maximum frequency for the band |
default_frequency | default freuency |
step | increment and decrement frequency step in KHz (default 10 * 10KHz) |
Definition at line 496 of file BK108X.cpp.
void BK108X::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.
Configures the receiver on AM mode; Also sets the band limits, defaul frequency and step.
minimum_frequency | minimum frequency for the band |
maximum_frequency | maximum frequency for the band |
default_frequency | default freuency |
step | increment and decrement frequency step |
am_space | (default 0 = 1kHz). You can control the freqyuency step by using am_space = 0 and just set the step to 1, 5, 9 or 10 kHz. This way, you can keep the space always 0 |
Definition at line 526 of file BK108X.cpp.
void BK108X::setChannel | ( | uint16_t | channel | ) |
Sets the channel.
channel |
Definition at line 556 of file BK108X.cpp.
References BK108X::waitAndFinishTune().
void BK108X::setFrequency | ( | uint16_t | frequency | ) |
void BK108X::setFrequencyUp | ( | ) |
Increments the current frequency.
The increment uses the band space as step.
Definition at line 598 of file BK108X.cpp.
void BK108X::setFrequencyDown | ( | ) |
Decrements the current frequency.
The drecrement uses the band space as step.
Definition at line 613 of file BK108X.cpp.
uint16_t BK108X::getFrequency | ( | ) |
uint16_t BK108X::getChannel | ( | ) |
uint16_t BK108X::getRealChannel | ( | ) |
Gets the current channel stored in register 0x0B.
This method is useful to query the current channel during the seek operations.
Definition at line 649 of file BK108X.cpp.
uint16_t BK108X::getRealFrequency | ( | ) |
Gets the frequency based on READCHAN register (0x0B)
Unlike getFrequency method, this method queries the device.
Definition at line 662 of file BK108X.cpp.
void BK108X::seekSoftware | ( | uint8_t | seek_mode, |
uint8_t | direction, | ||
void(*)() | showFunc = NULL |
||
) |
Seeks a station via Software.
Seeks a station up or down.
Seek up or down a station and call a function defined by the user to show the frequency during the seek process.
Seek begins at the current channel, and goes in the direction specified with the SEEKUP bit. Seek operation stops when a channel is qualified as valid according to the seek parameters, the entire band has been searched (SKMODE = 0), or the upper or lower band limit has been reached (SKMODE = 1).
The STC bit is set high when the seek operation completes and/or the SF/BL bit is set high if the seek operation was unable to find a channel qualified as valid according to the seek parameters. The STC and SF/BL bits must be set low by setting the SEEK bit low before the next seek or tune may begin.
Seek performance for 50 kHz channel spacing varies according to RCLK tolerance. Silicon Laboratories recommends ±50 ppm RCLK crystal tolerance for 50 kHz seek performance.
A seek operation may be aborted by setting SEEK = 0.
It is important to say you have to implement a show frequency function. This function have to get the frequency via getFrequency function.
Example:
seek_mode | Seek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit. |
direction | Seek Direction; 0 = Seek down (default); 1 = Seek up. |
showFunc | function that you have to implement to show the frequency during the seeking process. Set NULL if you do not want to show the progress. |
Definition at line 708 of file BK108X.cpp.
void BK108X::seekHardware | ( | uint8_t | seek_mode, |
uint8_t | direction, | ||
void(*)() | showFunc = NULL |
||
) |
Seeks a station via hardware functionality.
seek_mode | Seek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit. |
direction | Seek Direction; 0 = Seek down (default); 1 = Seek up. |
Definition at line 746 of file BK108X.cpp.
void BK108X::setSeekThreshold | ( | uint8_t | rssiValue, |
uint8_t | snrValue | ||
) |
Sets RSSI and SNR Seek Threshold.
rssiValue | between 0 and 127 |
snrValue | between 0 and 127 |
Definition at line 792 of file BK108X.cpp.
void BK108X::setBand | ( | uint8_t | band = 1 | ) |
Sets the current band for AM or FM.
Configures the band by setting the Register 05h. System Configuration2
Band value | AM / KHz | FM / MHz |
---|---|---|
0 | LW - 153~279 | FULL - 64~108 |
1 | MW - 520~1710 | East Europe 64~76 |
2 | SW - 2.3~21.85 | Japan 76~91 |
3 | MW - 522~1710 | Europe 87~108 |
band | the valid values are 0, 1, 2 and 3. See table above. |
Definition at line 817 of file BK108X.cpp.
void BK108X::setSpace | ( | uint8_t | space = 0 | ) |
Sets the Space channel for AM or FM.
Band value | AM | FM |
---|---|---|
0 | 1 KHz | 10 KHz |
1 | 5 KKz | 50 KHz |
2 | 9 KHz | 100 KHz |
3 | 10 KHz | 200 KHz |
space | valid values 0,1,2 and 3. See table above. |
Definition at line 842 of file BK108X.cpp.
int BK108X::getRssi | ( | ) |
int BK108X::getSnr | ( | ) |
void BK108X::setSoftMute | ( | bool | value | ) |
Sets the Softmute true or false.
Enable or Disable Soft Mute resource.
value | TRUE or FALSE |
Definition at line 883 of file BK108X.cpp.
void BK108X::setSoftMuteAttack | ( | uint8_t | value | ) |
Sets Softmute Attack/Recover Rate.
Soft mute Attack/Recover
Value | Description |
---|---|
0 | fastest |
1 | fast |
2 | slow |
3 | slowest |
value | See table above. |
Definition at line 904 of file BK108X.cpp.
void BK108X::setSoftMuteAttenuation | ( | uint8_t | value | ) |
Sets Softmute Attenuation.
Soft mute Attenuation.
Value | Description |
---|---|
0 | fastest |
1 | fast |
2 | slow |
3 | slowest |
value | See table above |
Definition at line 923 of file BK108X.cpp.
void BK108X::setMuteThreshold | ( | uint8_t | rssi, |
uint8_t | snr | ||
) |
Set the Mute Threshold based on RSSI and SNR.
rssi | The Mute Threshold Based on RSSI (default 26) |
snr | The Mute Threshold Based on SNR (default 5) |
Definition at line 937 of file BK108X.cpp.
void BK108X::setSeekMute | ( | bool | value | ) |
Disable or Enable soft mute when seeking.
value | If true, enable mute during the seek; |
Definition at line 950 of file BK108X.cpp.
void BK108X::setAfcMute | ( | bool | value | ) |
Disable or Enable soft mute when AFCRL is high.
value | If true, enable soft mute when AFCRL is high |
Definition at line 962 of file BK108X.cpp.
void BK108X::setAudioMute | ( | bool | left, |
bool | right | ||
) |
Sets the Mute true or false.
left | left channel (TRUE = MUTE/ FALSE = UNMUTE) |
left | right channel (TRUE = MUTE / FALSE = UMUTE) |
Definition at line 975 of file BK108X.cpp.
Referenced by BK108X::setAudioMute().
void BK108X::setAudioMute | ( | bool | value | ) |
Sets the Mute true or false.
value | left and right channels (TRUE = MUTE/ FALSE = UNMUTE) |
Definition at line 988 of file BK108X.cpp.
References BK108X::setAudioMute().
void BK108X::setMono | ( | bool | value | ) |
Sets the Mono true or false (stereo)
if TRUE, force mono; else force stereo
value | TRUE or FALSE |
Definition at line 999 of file BK108X.cpp.
bool BK108X::isStereo | ( | ) |
Checks stereo / mono status.
value | TRUE if stereo |
Definition at line 1013 of file BK108X.cpp.
void BK108X::setVolume | ( | uint8_t | value | ) |
Sets the audio volume level.
value | 0 to 31 (if 0, mutes the audio) |
Definition at line 1025 of file BK108X.cpp.
uint8_t BK108X::getVolume | ( | ) |
Gets the current audio volume level.
Definition at line 1042 of file BK108X.cpp.
void BK108X::setVolumeUp | ( | ) |
Increments the audio volume.
Definition at line 1052 of file BK108X.cpp.
void BK108X::setVolumeDown | ( | ) |
Decrements the audio volume.
Definition at line 1066 of file BK108X.cpp.