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. | |
void | BK108X::setGpio2 (uint8_t value) |
Sets the Gpio2. | |
void | BK108X::setGpio3 (uint8_t value) |
Sets the Gpio3. | |
void | BK108X::setAfc (bool value) |
Enables or Disables AFC. | |
void | BK108X::AfcRail (bool value) |
Sets AFC Rail. | |
void | BK108X::setAfcRssiSnrCalculateRate (uint8_t value) |
Sets AFC/RSSI/SNR Calculate Rate. | |
void | BK108X::setAfcThreshold (uint8_t value) |
Sets AFCRL Threshold. | |
void | BK108X::setAfcAve (uint8_t value) |
Sets AFC Average. | |
void | BK108X::setAfcVar (uint8_t value) |
Sets Variation Threshold for average AFC calculation. | |
void | BK108X::setAfcRssiThreshold (uint8_t value) |
Sets RSSI Threshold for Instant AFC updating. | |
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 |
Sets the time used to call the strength of pilot.
he Strength Pilot refers to a specific technique used in digital broadcasting systems to provide an indication of the signal strength or quality.
It is primarily used in FM (Frequency Modulation) broadcasting.
value | 0 ~ 3 |
|
inline |
|
inline |
|
inline |
Enables or Disables AFC.
In DSP receivers, AFC stands for Automatic Frequency Control.
It is a mechanism used to automatically adjust the frequency of the receiver's local oscillator to accurately track and lock onto the desired signal.
value | if True, it enables AFC |
|
inline |
Sets AFC Rail.
In the context of a DSP receiver, AFC (Automatic Frequency Control) rail refers to a control signal or voltage that is used to adjust the frequency of the receiver's local oscillator.
AFC rail helps maintain the receiver's frequency locked onto the desired signal by compensating for any variations or drifts in the received signal's frequency.
It is part of the automatic frequency control mechanism that ensures the receiver stays tuned accurately to the desired station or frequency.
value | True or false. If true, it enables AFC Rail |
|
inline |
|
inline |
|
inline |
Sets AFC Average.
0 = Use the instant AFC value; 1 = Use the average AFC value
AFC Average refers to the averaging of the Automatic Frequency Control (AFC) signal over a certain period of time.
AFC Average is used to mitigate short-term fluctuations or noise in the received signal's frequency.
value | 0 or 1 |
|
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 460 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 480 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 500 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 530 of file BK108X.cpp.
void BK108X::setChannel | ( | uint16_t | channel | ) |
Sets the channel.
channel |
Definition at line 560 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 602 of file BK108X.cpp.
void BK108X::setFrequencyDown | ( | ) |
Decrements the current frequency.
The drecrement uses the band space as step.
Definition at line 617 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 653 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 666 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 712 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 750 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 796 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 821 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 846 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 887 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 908 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 927 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 941 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 954 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 966 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 979 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 992 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 1003 of file BK108X.cpp.
bool BK108X::isStereo | ( | ) |
Checks stereo / mono status.
value | TRUE if stereo |
Definition at line 1017 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 1029 of file BK108X.cpp.
uint8_t BK108X::getVolume | ( | ) |
Gets the current audio volume level.
Definition at line 1046 of file BK108X.cpp.
void BK108X::setVolumeUp | ( | ) |
Increments the audio volume.
Definition at line 1056 of file BK108X.cpp.
void BK108X::setVolumeDown | ( | ) |
Decrements the audio volume.
Definition at line 1070 of file BK108X.cpp.