Brett Wilson
/
Si4735
Si4735 Radio Library
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 #define ON true 00040 #define OFF false 00041 00042 #define address_write 34 00043 #define address_read 35 00044 00045 class Si4735 00046 { 00047 public: 00048 //This is just a constructor. 00049 Si4735(PinName sda, PinName scl, PinName RST_); 00050 /* 00051 * Description: 00052 * Initializes the Si4735, powers up the radio in the desired mode and limits the bandwidth appropriately. 00053 * This function must be called before any other radio command. 00054 * The bands are set as follows: 00055 * FM - 87.5 - 107.9 MHz 00056 * AM - 520 - 1710 kHz 00057 * SW - 2300 - 23000 khz 00058 * LW - 152 - 279 kHz 00059 * Parameters: 00060 * mode - The desired radio mode. Use AM(0), FM(1), SW(2) or LW(3). 00061 */ 00062 void begin(char mode); 00063 /* 00064 * Description: 00065 * Used to send an ascii command string to the radio. 00066 * Parameters: 00067 * myCommand - A null terminated ascii string limited to hexidecimal characters 00068 * to be sent to the radio module. Instructions for building commands can be found 00069 * in the Si4735 Programmers Guide. 00070 */ 00071 void sendCommand(char * myCommand); 00072 /* 00073 * Description: 00074 * Used to to tune the radio to a desired frequency. The library uses the mode indicated in the 00075 * begin() function to determine how to set the frequency. 00076 * Parameters: 00077 * frequency - The frequency to tune to, in kHz (or in 10kHz if using FM mode). 00078 * Returns: 00079 * True 00080 * TODO: 00081 * Make the function return true if the tune was successful, else return false. 00082 */ 00083 bool tuneFrequency(int frequency); 00084 /* 00085 * Description: 00086 * This function currently does not work! 00087 * TODO: 00088 * Make this function work. 00089 */ 00090 int getFrequency(void); 00091 /* 00092 * Description: 00093 * Commands the radio to seek up to the next valid channel. If the top of the band is reached, the seek 00094 * will continue from the bottom of the band. 00095 * Returns: 00096 * True 00097 * TODO: 00098 * Make the function return true if a valid channel was found, else return false. 00099 */ 00100 bool seekUp(void); 00101 /* 00102 * Description: 00103 * Commands the radio to seek down to the next valid channel. If the bottom of the band is reached, the seek 00104 * will continue from the top of the band. 00105 * Returns: 00106 * True 00107 * TODO: 00108 * Make the function return true if a valid channel was found, else return false. 00109 */ 00110 bool seekDown(void); 00111 /* 00112 * Description: 00113 * Increasese the volume by 1. If the maximum volume has been reached, no increase will take place. 00114 */ 00115 void volumeUp(void); 00116 /* 00117 * Description: 00118 * Decreases the volume by 1. If the minimum volume has been reached, no decrease will take place. 00119 */ 00120 void volumeDown(void); 00121 /* 00122 * Description: 00123 * Mutes the audio output 00124 */ 00125 void mute(void); 00126 /* 00127 * Description: 00128 * Disables the mute. 00129 */ 00130 void unmute(void); 00131 /* 00132 * Description: 00133 * Gets the current status of the radio. Learn more about the status in the Si4735 datasheet. 00134 * Returns: 00135 * The status of the radio. 00136 */ 00137 char getStatus(void); 00138 /* 00139 * Description: 00140 * Gets the long response (16 characters) from the radio. Learn more about the long response in the Si4735 datasheet. 00141 * Parameters: 00142 * response - A string for the response from the radio to be stored in. 00143 */ 00144 void getResponse(char * response); 00145 /* 00146 * Description: 00147 * Powers down the radio 00148 */ 00149 void end(void); 00150 00151 private: 00152 // Pointer for the SPI bus 00153 I2C* i2c_; 00154 // Declare digital out pins 00155 DigitalOut _RST_; 00156 /* 00157 * A variable that is assigned the current mode of the radio (AM, FM, SW or LW) 00158 */ 00159 char _mode; 00160 /* 00161 * A variable the keeps the current volume level. 00162 */ 00163 char _currentVolume; 00164 /* 00165 * Command string that holds the binary command string to be sent to the Si4735. 00166 */ 00167 char command[9]; 00168 /* 00169 * Description: 00170 * Sends a binary command string to the Si4735. 00171 * Parameters: 00172 * command - Binary command to be sent to the radio. 00173 * length - The number of characters in the command string (since it can't be null terminated!) 00174 * TODO: 00175 * Make the command wait for a valid CTS response from the radio before releasing control of the CPU. 00176 */ 00177 void sendCommand(char * command, int length); 00178 /* 00179 * Description: 00180 * Sends/Receives a character from the SPI bus. 00181 * Parameters: 00182 * value - The character to be sent to the SPI bus. 00183 * Returns: 00184 * The character read from the SPI bus during the transfer. 00185 */ 00186 char spiTransfer(char value); 00187 00188 }; 00189 00190 #endif
Generated on Tue Aug 2 2022 20:51:20 by 1.7.2