Si4735 Library with RDS/RBDS control functions
Embed:
(wiki syntax)
Show/hide line numbers
Si4735.h
00001 /* mbed Si4735 Library 00002 * Brett Wilson and Brett Berry 00003 * Georgia Tech ECE 4180 00004 * Ported from ... 00005 00006 * Arduino Si4735 Library 00007 * Written by Ryan Owens for SparkFun Electronics 00008 * 5/17/11 00009 * 00010 * This library is for use with the SparkFun Si4735 Shield 00011 * Released under the 'Buy Me a Beer' license 00012 * (If we ever meet, you buy me a beer) 00013 * 00014 * See the example sketches to learn how to use the library in your code. 00015 */ 00016 00017 #include "mbed.h" 00018 00019 #ifndef Si4735_h 00020 #define Si4735_h 00021 00022 //Assign the radio pin numbers 00023 #define POWER_PIN 8 00024 #define RADIO_RESET_PIN 9 00025 #define INT_PIN 2 00026 00027 //Define the SPI Pin Numbers 00028 #define DATAOUT 11 //MOSI 00029 #define DATAIN 12 //MISO 00030 #define SPICLOCK 13 //sck 00031 #define SS 10 //ss 00032 00033 //List of possible modes for the Si4735 Radio 00034 #define AM 0 00035 #define FM 1 00036 #define SW 2 00037 #define LW 3 00038 00039 00040 #define NA 0 00041 #define EU 1 00042 00043 #define ON true 00044 #define OFF false 00045 00046 #define address_write 34 00047 #define address_read 35 00048 00049 typedef struct _Station { 00050 char callSign[5]; 00051 char programType[17]; 00052 char programService[9]; 00053 char radioText[65]; 00054 bool newRadioText; 00055 //Metrics signalQuality; 00056 //int frequency 00057 } Station; 00058 00059 typedef struct _Today { 00060 char year; //The 2-digit year 00061 char month; 00062 char day; 00063 char hour; 00064 char minute; 00065 } Today; 00066 00067 00068 class Si4735 00069 { 00070 public: 00071 //This is just a constructor. 00072 Si4735(PinName sda, PinName scl, PinName RST_, Serial *pc); 00073 /* 00074 * Description: 00075 * Initializes the Si4735, powers up the radio in the desired mode and limits the bandwidth appropriately. 00076 * This function must be called before any other radio command. 00077 * The bands are set as follows: 00078 * FM - 87.5 - 107.9 MHz 00079 * AM - 520 - 1710 kHz 00080 * SW - 2300 - 23000 khz 00081 * LW - 152 - 279 kHz 00082 * Parameters: 00083 * mode - The desired radio mode. Use AM(0), FM(1), SW(2) or LW(3). 00084 */ 00085 void begin(char mode); 00086 /* 00087 * Description: 00088 * Used to send an ascii command string to the radio. 00089 * Parameters: 00090 * myCommand - A null terminated ascii string limited to hexidecimal characters 00091 * to be sent to the radio module. Instructions for building commands can be found 00092 * in the Si4735 Programmers Guide. 00093 */ 00094 void sendCommand(char * myCommand); 00095 /* 00096 * Description: 00097 * Used to to tune the radio to a desired frequency. The library uses the mode indicated in the 00098 * begin() function to determine how to set the frequency. 00099 * Parameters: 00100 * frequency - The frequency to tune to, in kHz (or in 10kHz if using FM mode). 00101 * Returns: 00102 * True 00103 * TODO: 00104 * Make the function return true if the tune was successful, else return false. 00105 */ 00106 bool tuneFrequency(int frequency); 00107 /* 00108 * Description: 00109 * This function currently does not work! 00110 * TODO: 00111 * Make this function work. 00112 */ 00113 int getFrequency(void); 00114 /* 00115 * Description: 00116 * Commands the radio to seek up to the next valid channel. If the top of the band is reached, the seek 00117 * will continue from the bottom of the band. 00118 * Returns: 00119 * True 00120 * TODO: 00121 * Make the function return true if a valid channel was found, else return false. 00122 */ 00123 bool seekUp(void); 00124 /* 00125 * Description: 00126 * Commands the radio to seek down to the next valid channel. If the bottom of the band is reached, the seek 00127 * will continue from the top of the band. 00128 * Returns: 00129 * True 00130 * TODO: 00131 * Make the function return true if a valid channel was found, else return false. 00132 */ 00133 bool seekDown(void); 00134 /* 00135 * Description: 00136 * Increasese the volume by 1. If the maximum volume has been reached, no increase will take place. 00137 */ 00138 void volumeUp(void); 00139 /* 00140 * Description: 00141 * Decreases the volume by 1. If the minimum volume has been reached, no decrease will take place. 00142 */ 00143 void volumeDown(void); 00144 /* 00145 * Description: 00146 * Mutes the audio output 00147 */ 00148 void mute(void); 00149 /* 00150 * Description: 00151 * Disables the mute. 00152 */ 00153 void unmute(void); 00154 /* 00155 * Description: 00156 * Gets the current status of the radio. Learn more about the status in the Si4735 datasheet. 00157 * Returns: 00158 * The status of the radio. 00159 */ 00160 char getStatus(void); 00161 /* 00162 * Description: 00163 * Gets the long response (16 characters) from the radio. Learn more about the long response in the Si4735 datasheet. 00164 * Parameters: 00165 * response - A string for the response from the radio to be stored in. 00166 */ 00167 void getResponse(char * response); 00168 /* 00169 *Description: 00170 * Gets RDS/RBDS information fromt the radio. Learn more about the RDS information in the Si4745 datasheet and programming guide. 00171 * Parameters: 00172 * response - A string for the response from the radio to be stored in. 00173 */ 00174 void getRDS(void); 00175 /* 00176 * Description: 00177 * Powers down the radio 00178 */ 00179 void end(void); 00180 00181 00182 //********** 00183 00184 void setProperty(int address, int value); 00185 bool readRDS(); 00186 bool getIntStatus(void); 00187 bool bitRead(char value, int index); 00188 void printable_str(char * str, int length); 00189 void clearRDS(void); 00190 void setLocale(char locale); 00191 char getLocale(void); 00192 void ptystr(char pty); 00193 void refreshDisplay(int next_stn); 00194 void getTime(void); 00195 00196 00197 00198 private: 00199 // Pointer for the SPI bus 00200 I2C* i2c_; 00201 00202 Serial *pc; 00203 // Declare digital out pins 00204 DigitalOut _RST_; 00205 /* 00206 * A variable that is assigned the current mode of the radio (AM, FM, SW or LW) 00207 */ 00208 char _mode; 00209 /* 00210 * A variable the keeps the current volume level. 00211 */ 00212 char _currentVolume; 00213 /* 00214 * Command string that holds the binary command string to be sent to the Si4735. 00215 */ 00216 char command[9]; 00217 /* 00218 * Description: 00219 * Sends a binary command string to the Si4735. 00220 * Parameters: 00221 * command - Binary command to be sent to the radio. 00222 * length - The number of characters in the command string (since it can't be null terminated!) 00223 * TODO: 00224 * Make the command wait for a valid CTS response from the radio before releasing control of the CPU. 00225 */ 00226 void sendCommand(char * command, int length); 00227 /* 00228 * Description: 00229 * Sends/Receives a character from the SPI bus. 00230 * Parameters: 00231 * value - The character to be sent to the SPI bus. 00232 * Returns: 00233 * The character read from the SPI bus during the transfer. 00234 */ 00235 char spiTransfer(char value); 00236 00237 00238 char _disp[65]; //Radio Text String 00239 char _ps[9]; //Program Service String 00240 char _csign[5]; //Call Sign 00241 bool _ab; //Indicates new radioText 00242 char _pty[17]; //Program Type String 00243 char _year; //Contains the month 00244 char _month; //Contains the year 00245 char _day; //Contains the day 00246 char _hour; //Contains the hour 00247 char _minute; //Contains the minute 00248 char _locale; //Contains the locale [NA, EU] 00249 bool _newRadioText; //Indicates that a new RadioText has been received 00250 Station tuned; 00251 Today date; 00252 bool ps_rdy; 00253 char RadioText[64]; 00254 char ps_prev[9]; //previous ps 00255 char pty_prev[17]; 00256 00257 00258 }; 00259 00260 #endif
Generated on Fri Jul 15 2022 01:59:08 by
![doxygen](doxygen.png)