![]() |
PU2CLR BK108X Arduino Library
1.0.1
This is an Arduino Library to control the BK108X device
|
Functions | |
void | BK108X::setI2CAddress (int bus_addr) |
Sets the I2C bus address. More... | |
void | BK108X::setDelayAfterCrystalOn (uint8_t ms_value) |
Set the Delay After Crystal On (default 500ms) More... | |
uint16_t | BK108X::getShadownRegister (uint8_t register_number) |
Get the Shadown Register object. More... | |
void | BK108X::setShadownRegister (uint8_t register_number, uint16_t value) |
Sets a given value to the Shadown Register. More... | |
uint8_t | BK108X::getCurrentMode () |
Get the Current Mode (AM or FM) More... | |
uint16_t | BK108X::getRegister (uint8_t reg) |
Gets a givens current register content of the device. More... | |
void | BK108X::setRegister (uint8_t reg, uint16_t value) |
Sets a given value to the device registers. More... | |
bk_reg0a | BK108X::getStatus () |
void | BK108X::waitAndFinishTune () |
Wait STC (Seek/Tune Complete) status becomes 0. More... | |
void | BK108X::reset () |
Resets the device. More... | |
void | BK108X::powerUp () |
Powers the receiver on. More... | |
void | BK108X::powerDown () |
Powers the receiver off. More... | |
void | BK108X::setup (int sda_pin, int sclk_pin, int rdsInterruptPin=-1, int seekInterruptPin=-1, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL) |
Starts the device. More... | |
void | BK108X::setFM (uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step) |
Sets the receiver to FM mode. More... | |
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. More... | |
void | BK108X::setChannel (uint16_t channel) |
Sets the channel. More... | |
void | BK108X::setFrequency (uint16_t frequency) |
Sets the FM frequency. More... | |
void | BK108X::setFrequencyUp () |
Increments the current frequency. More... | |
void | BK108X::setFrequencyDown () |
Decrements the current frequency. More... | |
uint16_t | BK108X::getFrequency () |
Gets the current frequency. More... | |
uint16_t | BK108X::getChannel () |
Gets the current channel. More... | |
uint16_t | BK108X::getRealChannel () |
Gets the current channel stored in register 0x0B. More... | |
uint16_t | BK108X::getRealFrequency () |
Gets the frequency based on READCHAN register (0x0B) More... | |
void | BK108X::seek (uint8_t seek_mode, uint8_t direction) |
Seek function. More... | |
void | BK108X::seek (uint8_t seek_mode, uint8_t direction, void(*showFunc)()) |
Seek function. More... | |
void | BK108X::setSeekThreshold (uint8_t value) |
Sets RSSI Seek Threshold. More... | |
void | BK108X::setBand (uint8_t band=1) |
Sets the FM Band More... | |
void | BK108X::setSpace (uint8_t space=0) |
Sets the FM Space More... | |
int | BK108X::getRssi () |
Gets the Rssi. More... | |
void | BK108X::setSoftmute (bool value) |
Sets the Softmute true or false. More... | |
void | BK108X::setSoftmuteAttack (uint8_t value) |
Sets Softmute Attack/Recover Rate. More... | |
void | BK108X::setSoftmuteAttenuation (uint8_t value) |
Sets Softmute Attenuation.. More... | |
void | BK108X::setAgc (bool value) |
Sets the AGC enable or disable. More... | |
void | BK108X::setMute (bool value) |
Sets the Mute true or false. More... | |
void | BK108X::setMono (bool value) |
Sets the Mono true or false (stereo) More... | |
bool | BK108X::isStereo () |
Checks stereo / mono status. More... | |
void | BK108X::setVolume (uint8_t value) |
Sets the audio volume level. More... | |
uint8_t | BK108X::getVolume () |
Gets the current audio volume level. More... | |
void | BK108X::setVolumeUp () |
Increments the audio volume. More... | |
void | BK108X::setVolumeDown () |
Decrements the audio volume. More... | |
void | BK108X::setExtendedVolumeRange (bool value) |
Sets Extended Volume Range. More... | |
void | BK108X::setFmDeemphasis (uint8_t de) |
Sets De-emphasis. More... | |
|
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 830 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 |
uint16_t BK108X::getRegister | ( | uint8_t | reg | ) |
Gets a givens current register content of the device.
device | register address |
Definition at line 271 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 291 of file BK108X.cpp.
bk_reg0a BK108X::getStatus | ( | ) |
Definition at line 321 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 332 of file BK108X.cpp.
Referenced by BK108X::setChannel().
void BK108X::reset | ( | ) |
Resets the device.
Definition at line 348 of file BK108X.cpp.
void BK108X::powerUp | ( | ) |
Powers the receiver on.
Starts the receiver with some default configurations
Definition at line 363 of file BK108X.cpp.
Referenced by BK108X::setup().
void BK108X::powerDown | ( | ) |
Powers the receiver off.
Definition at line 392 of file BK108X.cpp.
void BK108X::setup | ( | int | sda_pin, |
int | sclk_pin, | ||
int | rdsInterruptPin = -1 , |
||
int | seekInterruptPin = -1 , |
||
uint8_t | oscillator_type = OSCILLATOR_TYPE_CRYSTAL |
||
) |
Starts the device.
sets the reset pin, interrupt pins and oscillator type you are using in your project.
You have to inform at least two parameters: RESET pin and I2C SDA pin of your MCU
rdsInterruptPin | // optional. Sets the Interrupt Arduino pin used to RDS function control. |
seekInterruptPin | // optional. Sets the Arduino pin used to Seek function control. |
oscillator_type | // optional. Sets the Oscillator type used Crystal (default) or Ref. Clock. |
Definition at line 409 of file BK108X.cpp.
References BK108X::i2cInit(), BK108X::powerUp(), BK108X::rdsInterruptPin, and BK108X::seekInterruptPin.
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 |
Definition at line 435 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 |
Definition at line 465 of file BK108X.cpp.
void BK108X::setChannel | ( | uint16_t | channel | ) |
Sets the channel.
channel |
Definition at line 497 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. See array: uint16_t fmSpace[4] = {20, 10, 5, 1};
Definition at line 537 of file BK108X.cpp.
void BK108X::setFrequencyDown | ( | ) |
Decrements the current frequency.
The drecrement uses the band space as step.
Definition at line 552 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 588 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 601 of file BK108X.cpp.
void BK108X::seek | ( | uint8_t | seek_mode, |
uint8_t | direction | ||
) |
Seek function.
Seeks a station up or down.
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.
A seek operation may be aborted by setting SEEK = 0.
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 621 of file BK108X.cpp.
void BK108X::seek | ( | uint8_t | seek_mode, |
uint8_t | direction, | ||
void(*)() | showFunc | ||
) |
Seek function.
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 659 of file BK108X.cpp.
void BK108X::setSeekThreshold | ( | uint8_t | value | ) |
Sets RSSI Seek Threshold.
value | between 0 and 127 |
Definition at line 669 of file BK108X.cpp.
void BK108X::setBand | ( | uint8_t | band = 1 | ) |
void BK108X::setSpace | ( | uint8_t | space = 0 | ) |
Sets the FM Space
Definition at line 690 of file BK108X.cpp.
int BK108X::getRssi | ( | ) |
void BK108X::setSoftmute | ( | bool | value | ) |
Sets the Softmute true or false.
value | TRUE or FALSE |
Definition at line 711 of file BK108X.cpp.
void BK108X::setSoftmuteAttack | ( | uint8_t | value | ) |
void BK108X::setSoftmuteAttenuation | ( | uint8_t | value | ) |
void BK108X::setAgc | ( | bool | value | ) |
Sets the AGC enable or disable.
value | true = enable; fale = disable |
Definition at line 743 of file BK108X.cpp.
void BK108X::setMute | ( | bool | value | ) |
Sets the Mute true or false.
value | TRUE or FALSE |
Definition at line 754 of file BK108X.cpp.
void BK108X::setMono | ( | bool | value | ) |
Sets the Mono true or false (stereo)
value | TRUE or FALSE |
Definition at line 765 of file BK108X.cpp.
bool BK108X::isStereo | ( | ) |
Checks stereo / mono status.
value | TRUE if stereo |
Definition at line 776 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 787 of file BK108X.cpp.
uint8_t BK108X::getVolume | ( | ) |
Gets the current audio volume level.
Definition at line 803 of file BK108X.cpp.
void BK108X::setVolumeUp | ( | ) |
Increments the audio volume.
Definition at line 813 of file BK108X.cpp.
void BK108X::setVolumeDown | ( | ) |
Decrements the audio volume.
Definition at line 827 of file BK108X.cpp.
void BK108X::setExtendedVolumeRange | ( | bool | value | ) |
Sets Extended Volume Range.
value | false = disabled (default); true = enabled. |
Definition at line 841 of file BK108X.cpp.
void BK108X::setFmDeemphasis | ( | uint8_t | de | ) |
Sets De-emphasis.
75 μs. Used in USA (default); 50 μs. Used in Europe, Australia, Japan.
de | 0 = 75 μs; 1 = 50 μs |
Definition at line 855 of file BK108X.cpp.