PU2CLR SI4844 Arduino Library 1.1.8
Arduino Library for Si4844 Devices - By Ricardo Lima Caratti
Loading...
Searching...
No Matches
BandList.h
Go to the documentation of this file.
1/**
2 * @mainpage SI48XX Custom Band implementation
3 * @brief SI4844 Custom Band for SI4844 ARDUINO LIBRARY
4 * @details This class implements the management of the custom band list in case the receiver developer wants to use
5 * @details frequency ranges different from those provided by the SI48XX.
6 * @details This list will start empty and can be referenced and maintained (with the addition and removal of bands)
7 * @details in the main program using the addCustomBand and removeCustomBand methods implemented in the Si4844 library.
8 * @details These methods are particularly useful for receivers with mechanical band selection switches, where it is
9 * @details impossible to determine in advance which band will be selected during use. It is crucial for the designer
10 * @details to correctly configure the custom bands so that when the band switch is positioned and the band index is
11 * @details detected, it matches an entry in the list. If the detected band index is not found in the list, the
12 * @details receiver will work with default settings.
13 * @details **Important** Currently, this structure only works for the band selection mode using a mechanical method (Slide Switch or Rotary Band Switch via a resistor network). For custom bands to function correctly, the LNA_EN pin (pin 1 of the Si4844) must be left floating (open). If this pin is pulled up, the custom parameters will be ignored, and the internally defined device parameters will be used.
14 * @todo Future Changes: Unify the band customization methods for both modes.
15*/
16
17#ifndef _BandList_H // Prevent this file from being compiled more than once
18#define _BandList_H
19
20struct BandNode {
21 int8_t bandIdx; // Band index
22 uint32_t bottomFrequency; // Lower frequency limit
23 uint32_t topFrequency; // Upper frequency limit
24 uint8_t space; // Band spacing
25 BandNode* next; // Pointer to the next node in the list
26};
27
28class BandList {
29 private:
30 BandNode* head; // Head of the linked list
31
32 public:
33 BandList() : head(nullptr) {}
34
35 // Add a new custom band to the list
36 void add(int8_t bandIdx, uint32_t bottomFrequency, uint32_t topFrequency, uint8_t space) {
37 BandNode* newBandNode = new BandNode{bandIdx, bottomFrequency, topFrequency, space, nullptr};
38 if (!head) {
39 head = newBandNode; // If the list is empty, set the new node as the head
40 } else {
41 BandNode* current = head;
42 while (current->next) {
43 current = current->next; // Traverse to the end of the list
44 }
45 current->next = newBandNode; // Add the new node at the end
46 }
47 }
48
49 // Remove a custom band identified by its bandIdx
50 void remove(int8_t bandIdx) {
51 if (!head) return; // If the list is empty, do nothing
52
53 // If the head node is the one to be removed
54 if (head->bandIdx == bandIdx) {
55 BandNode* temp = head;
56 head = head->next; // Move the head to the next node
57 delete temp; // Free the memory of the old head
58 return;
59 }
60
61 // Traverse the list to find the node to remove
62 BandNode* current = head;
63 while (current->next && current->next->bandIdx != bandIdx) {
64 current = current->next;
65 }
66
67 // If the node is found, remove it
68 if (current->next) {
69 BandNode* temp = current->next;
70 current->next = current->next->next; // Skip the node to be removed
71 delete temp; // Free the memory of the removed node
72 }
73 }
74
75 // Find a custom band by its bandIdx and return its pointer
76 BandNode* findBand(int8_t bandIdx) {
77 BandNode* current = head;
78 while (current) {
79 if (current->bandIdx == bandIdx) return current; // Return the pointer if found
80 current = current->next; // Move to the next node
81 }
82 return nullptr; // Return nullptr if not found
83 }
84};
85
86#endif // _BandList_H
uint32_t topFrequency
Definition: BandList.h:23
uint32_t bottomFrequency
Definition: BandList.h:22
int8_t bandIdx
Definition: BandList.h:21
uint8_t space
Definition: BandList.h:24
BandNode * next
Definition: BandList.h:25
Definition: BandList.h:20
void interrupt_hundler()
Library handle interrupt.
Definition: SI4844.cpp:39
#define FM_SOFT_MUTE_RATE
Definition: SI4844.h:51
#define AM_SOFT_MUTE_SLOPE
Definition: SI4844.h:61
uint16_t value
Definition: SI4844.h:270
#define DEVICE_LAST_VALID_INDEX_BAND
Definition: SI4844.h:65
#define AM_SOFT_MUTE_MAX_ATTENUATION
Definition: SI4844.h:49
#define FM_STEREO_IND_BLEND_THRESHOLD
Definition: SI4844.h:53
#define RX_HARD_MUTE
Definition: SI4844.h:44
#define REFCLK_PRESCALE
Definition: SI4844.h:58
#define RX_ACTUAL_VOLUME
Definition: SI4844.h:46
#define ATDD_GET_STATUS
Definition: SI4844.h:39
#define ATDD_POWER_DOWN
Definition: SI4844.h:33
si4844_firmware_info refined
Definition: SI4844.h:221
uint8_t raw[9]
Definition: SI4844.h:222
#define FM_SOFT_MUTE_MAX_ATTENUATION
Definition: SI4844.h:48
#define SET_PROPERTY
Definition: SI4844.h:41
#define GET_REV
Definition: SI4844.h:36
#define ATDD_POWER_UP
Definition: SI4844.h:34
#define FM_DEEMPHASIS
Definition: SI4844.h:50
#define AM_SOFT_MUTE_SNR_THRESHOLD
Definition: SI4844.h:62
#define AM_SOFT_MUTE_RATE
Definition: SI4844.h:60
uint16_t dummy
Definition: SI4844.h:183
#define SI4844_ADDRESS
SI4844 ARDUINO LIBRARY
Definition: SI4844.h:28
#define GET_PROPERTY
Definition: SI4844.h:42
#define REFCLK_FREQ
Definition: SI4844.h:57
#define RX_VOLUME
Definition: SI4844.h:43
#define RX_BASS_TREBLE
Definition: SI4844.h:45
uint16_t CHFREQ
Definition: SI4844.h:184
#define ATDD_AUDIO_MODE
Definition: SI4844.h:35
Definition: BandList.h:28
BandList()
Definition: BandList.h:33
void add(int8_t bandIdx, uint32_t bottomFrequency, uint32_t topFrequency, uint8_t space)
Definition: BandList.h:36
void remove(int8_t bandIdx)
Definition: BandList.h:50
BandNode * findBand(int8_t bandIdx)
Definition: BandList.h:76
SI4844 Class.
Definition: SI4844.h:289
uint16_t getFirmwareComponentMajorRevision()
Definition: SI4844.h:582
uint16_t getFirmwareCTS()
Definition: SI4844.h:578
uint16_t getStatusCTS()
Definition: SI4844.h:573
uint16_t getFirmwareChipRevision()
Definition: SI4844.h:584
uint16_t getFirmwareErr()
Definition: SI4844.h:577
uint16_t getFirmwareMinorRevision()
Definition: SI4844.h:581
uint16_t getFirmwareComponentMinorRevision()
Definition: SI4844.h:583
uint16_t getFirmwareMajorRevision()
Definition: SI4844.h:580
uint16_t getFirmwarePartNumber()
Definition: SI4844.h:579
void setDefaultBandIndx(uint8_t bandidx)
Definition: SI4844.cpp:395
uint8_t getBassTreble()
Definition: SI4844.h:392
uint16_t getFirmwareReserved()
Definition: SI4844.h:576
void setStatusInterruptFromDevice(bool value)
Set the Data Status From Device.
Definition: SI4844.h:358
bool getDataStatusInterruptFromDevice()
Get the Data Status From Device.
Definition: SI4844.h:366
void sendCommand(uint8_t cmd, int parameter_size, const uint8_t *parameter)
Sends a given command to the SI4844 device.
Definition: SI4844.cpp:126
void setResetPin(uint16_t resetPin)
Sets the MCU RESET pin.
Definition: SI4844.cpp:294
void setProperty(uint16_t propertyNumber, uint16_t parameter)
Sends (sets) property to the SI48XX.
Definition: SI4844.cpp:55
void getCommandResponse(int response_size, uint8_t *response)
Returns with the command response.
Definition: SI4844.cpp:148
void setInterruptPin(int interruptPin)
Sets the MCU Interrupt pin.
Definition: SI4844.cpp:306
uint16_t getProperty(uint16_t propertyNumber)
Gets a given property from the SI4844.
Definition: SI4844.cpp:84
uint8_t raw
Definition: SI4844.h:155
uint8_t raw
Definition: SI4844.h:239
uint8_t BCFG1
Definition: SI4844.h:167
uint8_t raw
Definition: SI4844.h:135
uint8_t CHIPREV
Definition: SI4844.h:213
uint8_t CMPMINOR
Definition: SI4844.h:212
uint8_t HOSTPWRUP
Definition: SI4844.h:171
uint8_t FWMAJOR
Definition: SI4844.h:209
uint8_t STEREO
Definition: SI4844.h:168
uint8_t PN
Definition: SI4844.h:208
uint8_t CMPMAJOR
Definition: SI4844.h:211
uint8_t raw[4]
Definition: SI4844.h:195
uint8_t d1
Definition: SI4844.h:177
uint8_t raw[7]
Definition: SI4844.h:116
uint8_t ERR
Definition: SI4844.h:206
uint8_t RESERVED
Definition: SI4844.h:205
uint8_t d3
Definition: SI4844.h:179
uint8_t HOSTRST
Definition: SI4844.h:172
uint8_t BANDMODE
Definition: SI4844.h:175
uint8_t d4
Definition: SI4844.h:178
si4844_get_status refined
Definition: SI4844.h:193
uint8_t raw
Definition: SI4844.h:256
uint8_t raw
Definition: SI4844.h:91
uint8_t STATION
Definition: SI4844.h:169
uint8_t BANDIDX
Definition: SI4844.h:174
uint8_t CTS
Definition: SI4844.h:207
uint8_t FWMINOR
Definition: SI4844.h:210
si4844_get_channel_frequency rawStatus
Definition: SI4844.h:194
uint8_t d2
Definition: SI4844.h:176
uint8_t INFORDY
Definition: SI4844.h:170
uint8_t CTS
Definition: SI4844.h:173
uint8_t BCFG0
Definition: SI4844.h:166
void setAmSoftMuteMaxAttenuation(uint8_t value)
Sets AM Soft Mute Max Attenuation..
Definition: SI4844.cpp:1227
float getFrequency(void)
Get the current frequency of the radio in KHz.
Definition: SI4844.cpp:1098
uint32_t getFrequencyInteger(void)
Get the current frequency of the radio in KHz in uint32_t (long integer) .
Definition: SI4844.cpp:1144
uint16_t getStatusBCFG0()
Gets Band CFG0 (Band Detection Configuration).
Definition: SI4844.h:482
void setup(uint16_t resetPin, int interruptPin, int8_t defaultBand=0, uint32_t hightClockSpeed=50000)
Initiates the SI4844 instance and connect the device (SI4844) to Arduino.
Definition: SI4844.cpp:255
void setBandSlideSwitch()
Sets a new band to the device configured as Slide Switch.
Definition: SI4844.cpp:625
void setFmDeemphasis(uint8_t value)
Sets de-emphasis time constant.
Definition: SI4844.cpp:1250
void changeVolume(char)
Up or down the sound volume level.
Definition: SI4844.cpp:772
bool hasBandChanged(void)
Checks whether the current band detected by the device changed.
Definition: SI4844.cpp:1204
si4844_firmware_response * getFirmware(void)
Get part number, chip revision, firmware, patch, and component revision numbers.
Definition: SI4844.cpp:1070
void setFmSoftMuteRate(uint8_t value)
Sets the attack and decay rates when entering and leaving soft mute.
Definition: SI4844.cpp:1263
void setAmSoftMuteSnrThreshold(uint8_t value)
Sets the SNR threshold to engage soft mute.
Definition: SI4844.cpp:1334
uint16_t getStatusBandMode()
Gets the current Band Mode.
Definition: SI4844.h:562
void setFmSoftMuteSlope(uint8_t value)
Configures attenuation slope during soft mute in dB attenuation per dB SNR below the soft mute SNR th...
Definition: SI4844.cpp:1278
void resetStatus(void)
set the interrupr status to false. It will turn true after next interrupr
Definition: SI4844.cpp:1213
bool needHostPowerUp()
Checks Host Power Up Status.
Definition: SI4844.h:530
uint16_t getStatusBandIndex()
Gets the current Band Index Detected.
Definition: SI4844.h:569
uint8_t getVolume()
Gets the current audio volume level.
Definition: SI4844.h:455
uint16_t getStatusStationIndicator()
Gets Station Indicator.
Definition: SI4844.h:509
void bassTrebleUp()
More treble, less bass.
Definition: SI4844.cpp:883
si4844_device_status * getStatus()
Gets current status of the device.
Definition: SI4844.cpp:980
void setBassTreble(uint8_t bass_treble)
Set the sound volume level, bass and treble.
Definition: SI4844.cpp:863
void setReferenceClockFrequency(uint16_t value)
Sets the frequency of the REFCLK from the output of the prescaler.
Definition: SI4844.cpp:1348
uint8_t getVolumeProperty()
Gets the current volume value stored in SI4844 device.
Definition: SI4844.cpp:839
bool needHostReset()
Checks HOST Reset Status
Definition: SI4844.h:539
void setBlendThresholdStereoIndicator(uint16_t value)
Sets the blend threshold for stereo indicator.
Definition: SI4844.cpp:1291
void setCustomBand(uint8_t bandIndex, uint16_t botton, uint16_t top, uint8_t bandSpace, uint8_t dfband=0, uint8_t uni_am=0, uint8_t tvreq=0)
This method allows you to customize the frequency range of a band.
Definition: SI4844.cpp:672
void addCustomBand(int8_t bandIdx, uint32_t bottomFrequency, uint32_t topFrequency, uint8_t space)
Add a custom band in the list of custom bands.
Definition: SI4844.cpp:471
void setVolume(byte)
Sets the volume level.
Definition: SI4844.cpp:822
void reset(void)
Resets the SI4844 device.
Definition: SI4844.cpp:363
bool isHostDetectionBandConfig()
Band CFG0 (Band Detection Configuration)
Definition: SI4844.cpp:1030
int8_t getValidBandIndex()
Retrieves the current valid BAND INDEX.
Definition: SI4844.cpp:1044
BandNode * findCustomBand(int8_t bandIdx)
Find a custom band in the list of custom bands.
Definition: SI4844.cpp:497
void setAmSoftMuteSlope(uint8_t value)
Configures attenuation slope during soft mute in dB attenuation per dB SNR below the soft mute SNR th...
Definition: SI4844.cpp:1321
uint16_t getStatusStereo()
Gets Stereo indicator.
Definition: SI4844.h:500
si4844_status_response * getAllReceiverInfo(void)
Gets all current information of the receiver (tune freq, band, and others information,...
Definition: SI4844.cpp:999
char * getStereoIndicator()
Get the Stereo Indicator.
Definition: SI4844.h:473
char * getBandMode()
Get the Band Mode.
Definition: SI4844.h:464
uint8_t getCurrentBand()
Gets the latest band set by the microcontroller.
Definition: SI4844.h:447
uint16_t getRawChannelFrequency()
Gets the Channel Frequency.
Definition: SI4844.h:553
void powerUp(void)
Power the device up.
Definition: SI4844.cpp:406
void volumeUp(void)
Increases the volume level.
Definition: SI4844.cpp:797
void setCrystalOscillatorStabilizationWaitTime(uint8_t XOWAIT)
Sets Crystal Oscillator Stabilization Wait Time After Reset.
Definition: SI4844.cpp:454
void volumeDown(void)
Decreases the volume level.
Definition: SI4844.cpp:808
void setCrystalOscillatorEnable(uint8_t XOSCEN)
Sets Crystal Oscillator Enable.
Definition: SI4844.cpp:440
uint16_t getStatusInformationReady()
Gets Information Ready.
Definition: SI4844.h:521
uint16_t getStatusBCFG1()
Gets Band CFG1 (Band Properties Priority)
Definition: SI4844.h:490
void debugDevice(uint16_t resetPin, uint16_t interruptPin, uint8_t defaultBand, void(*showFunc)(char *msg))
Used to debug
Definition: SI4844.cpp:320
void audioMute(uint8_t value)
Mutes the audio output.
Definition: SI4844.cpp:952
void bassTrebleDown()
Less treble, more bass.
Definition: SI4844.cpp:872
void setFmSoftMuteMaxAttenuation(uint8_t value)
FM Soft Mute Maximum Attenuation.
Definition: SI4844.cpp:1238
void setBand(uint8_t newBand=0)
Sets a new band to the device.
Definition: SI4844.cpp:593
si4844_audiomode_status_response setAudioMode(uint8_t audiomode, uint8_t fm_mono, uint8_t adjpt_attn, uint8_t adjpt_steo, uint8_t opcode)
Set audio mode.
Definition: SI4844.cpp:915
void setReferenceClockPrescaler(uint16_t value)
Sets the number used by the prescaler to divide the external reference clock frequency down to the in...
Definition: SI4844.cpp:1363
bool hasStatusChanged(void)
Checks whether the SI4844 has its status changed.
Definition: SI4844.cpp:1192
void removeCustomBand(int8_t bandIdx)
Remove a custom band in the list of custom bands.
Definition: SI4844.cpp:483
void setupSlideSwitch(uint16_t resetPin, int interruptPin, uint32_t hightClockSpeed=50000)
Initiates the SI48XX instance and connect the device (SI4844) to a microcontroller.
Definition: SI4844.cpp:189
void setAudioMute(bool on)
Mutes the audio output.
Definition: SI4844.cpp:963
void setAmSoftMuteRate(uint8_t value)
Sets the attack and decay rates when entering or leaving soft mute.
Definition: SI4844.cpp:1307
void powerDown(void)
Power the device down.
Definition: SI4844.cpp:384
char * getFormattedFrequency(uint8_t removeRightDigit=0, uint8_t thousandsSeparator=',')
Gets Formatted Frequency.
Definition: SI4844.cpp:1468
void convertToChar(uint32_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.
Definition: SI4844.cpp:1430
bool detectDevice()
Checks communication with SI4844 via I2C.
Definition: SI4844.cpp:1377
uint8_t scanI2CBus(uint8_t *device, uint8_t limit)
Scans the I2C bus and returns the addresses of the devices found.
Definition: SI4844.cpp:1393