EmbeddedArtists AB / Mbed 2 deprecated lpc4088_ebb_ptp

Dependencies:   EALib I2S LM75B SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WM8731.h Source File

WM8731.h

00001 /**
00002 *
00003 * @section LICENSE
00004 *
00005 * Copyright (c) 2012 mbed
00006 *
00007 * Permission is hereby granted, free of charge, to any person obtaining a copy
00008 * of this software and associated documentation files (the "Software"), to deal
00009 * in the Software without restriction, including without limitation the rights
00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 * copies of the Software, and to permit persons to whom the Software is
00012 * furnished to do so, subject to the following conditions:
00013 *
00014 * The above copyright notice and this permission notice shall be included in
00015 * all copies or substantial portions of the Software.
00016 *
00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 * THE SOFTWARE.
00024 *
00025 * @section DESCRIPTION
00026 *    A Driver set for the I2C half of the WM8731. Based on the WM8731
00027 *    code http://mbed.org/users/p07gbar/code/WM8731/
00028 *
00029 */ 
00030 
00031 #ifndef WM8731_H
00032 #define WM8731_H
00033 
00034 #include "mbed.h"
00035 
00036 #define WM8731_CS_HIGH              true
00037 #define WM8731_CS_LOW               false
00038 
00039 #define WM8731_ON                   true
00040 #define WM8731_OFF                  false
00041 
00042 #define WM8731_MUTE                 true
00043 #define WM8731_UNMUTE               false
00044 
00045 #define WM8731_MASTER               true
00046 #define WM8731_SLAVE                false
00047 
00048 #define WM8731_LINE                 0
00049 #define WM8731_MIC                  1
00050 #define WM8731_NO_IN               -1
00051 
00052 #define WM8731_DE_EMPH_DISABLED     0
00053 #define WM8731_DE_EMPH_32KHZ        1
00054 #define WM8731_DE_EMPH_44KHZ        2
00055 #define WM8731_DE_EMPH_48KHZ        3
00056 
00057 /** A class to control the I2C part of the WM8731
00058  * 
00059  */
00060 class WM8731 {
00061 public:
00062 
00063     /** Create an instance of the WM8731 class
00064      *
00065      * @param i2c_sda The SDA pin of the I2C
00066      * @param i2c_scl The SCL pin of the I2C
00067      */
00068     WM8731(PinName i2c_sda, PinName i2c_scl);
00069     
00070     /** Create an instance of the WM8731 class
00071      *
00072      * @param i2c_sda The SDA pin of the I2C
00073      * @param i2c_scl The SCL pin of the I2C
00074      * @param cs_level The level of the CS pin on the WM8731
00075      */
00076     WM8731(PinName i2c_sda, PinName i2c_scl, bool cs_level);
00077     
00078     /** Control the power of the device
00079      *
00080      * @param on_off The power state
00081      */
00082     void power(bool on_off);
00083     
00084     /** Control the input source of the device
00085      *
00086      * @param input Select the source of the input of the device: WM8731_LINE, WM8731_MIC, WM8731_NO_IN
00087      */
00088     void input_select(int input);
00089     
00090     /** Set the headphone volume
00091      *
00092      * @param h_volume The desired headphone volume: 0->1
00093      */
00094     void headphone_volume(float h_volume);
00095     
00096     /** Set the line in pre-amp volume
00097      *
00098      * @param li_volume The desired line in volume: 0->1
00099      */
00100     void linein_volume(float li_volume);
00101     
00102     /** Turn on/off the microphone pre-amp boost
00103      * 
00104      * @param mic_boost Boost on or off
00105      */
00106     void microphone_boost(bool mic_boost);
00107     
00108     /** Mute the input
00109      *
00110      * @param mute Mute on/off
00111      */
00112     void input_mute(bool mute);
00113     
00114     /** Mute the output
00115      *
00116      * @param mute Mute on/off
00117      */
00118     void output_mute(bool mute);
00119     
00120     /** Turn on/off the input stage
00121      *
00122      * @param on_off Input stage on(true)/off(false)
00123      */
00124     void input_power(bool on_off);
00125     
00126     /** Turn on/off the output stage
00127      *
00128      * @param on_off Output stage on(true)/off(false)
00129      */
00130     void output_power(bool on_off);
00131     
00132     /** Select the word size
00133      *
00134      * @param words 16/20/24/32 bits
00135      */
00136     void wordsize(int words);
00137     
00138     /** Select interface mode: Master or Slave
00139      *
00140      * @param master Interface mode: master(true)/slave
00141      */
00142     void master(bool master);
00143     
00144     /** Select the sample rate
00145      *
00146      * @param freq Frequency: 96/48/32/8 kHz
00147      */
00148     void frequency(int freq);
00149     
00150     /** Enable the input highpass filter
00151      *
00152      * @param enabled Input highpass filter enabled
00153      */
00154     void input_highpass(bool enabled);
00155     
00156     /** Enable the output soft mute
00157      *
00158      * @param enabled Output soft mute enabled
00159      */
00160     void output_softmute(bool enabled);
00161     
00162     /** Turn on and off the I2S
00163      * 
00164      * @param on_off Switch the I2S interface on(true)/off(false)
00165      */
00166     void interface_switch(bool on_off);
00167     
00168     /** Reset the device and settings
00169      *
00170      */
00171     void reset();
00172     
00173     /** Set the microphone sidetone volume
00174      *
00175      * @param sidetone_volume The volume of the sidetone: 0->1
00176      */
00177     void sidetone(float sidetone_vol);
00178     
00179     /** Set the analog bypass
00180      * 
00181      * @param bypass_en Enable the bypass: enabled(true)
00182      */
00183     void bypass(bool bypass_en);
00184     
00185     /** Set the deemphasis frequency
00186      *
00187      * @param code The deemphasis code: WM8731_DE_EMPH_DISABLED, WM8731_DE_EMPH_32KHZ, WM8731_DE_EMPH_44KHZ, WM8731_DE_EMPH_48KHZ
00188      */
00189     void deemphasis(char code);
00190     
00191     /** Enable the input highpass filter
00192      *
00193      * @param enable Enable the input highpass filter enabled(true)
00194      */
00195      
00196     void adc_highpass(bool enable);
00197     
00198     /** Start the device sending/recieving etc
00199     */
00200     void start();
00201     
00202     /** Stop the device sending/recieving etc
00203     */
00204     void stop();
00205     
00206 private:
00207     
00208     enum reg_address {
00209         line_in_vol_left        = 0x00,
00210         line_in_vol_right       = 0x01,
00211         headphone_vol_left      = 0x02,
00212         headphone_vol_right     = 0x03,
00213         path_analog             = 0x04,
00214         path_digital            = 0x05,
00215         power_control           = 0x06,
00216         interface_format        = 0x07,
00217         sample_rate             = 0x08,
00218         interface_activation    = 0x09,
00219         reset_reg               = 0x0F,
00220         all                     = 0xFF
00221     };
00222     
00223     enum tlv320_defaults{
00224         df_bypass_         = 0,
00225         df_ADC_source      = WM8731_LINE,
00226         df_mic_mute        = WM8731_UNMUTE,
00227         df_li_mute_left    = 0,
00228         df_li_mute_right   = 0,
00229         df_mic_boost_      = 0,
00230         df_out_mute        = WM8731_UNMUTE,
00231         
00232         df_de_emph_code         = 0x00,
00233         df_ADC_highpass_enable  = 0,
00234         
00235         df_device_all_pwr     = 1,
00236         df_device_clk_pwr     = 1,
00237         df_device_osc_pwr     = 1,
00238         df_device_out_pwr     = 1,
00239         df_device_dac_pwr     = 1,
00240         df_device_adc_pwr     = 1,
00241         df_device_mic_pwr     = 0,
00242         df_device_lni_pwr     = 1,
00243         
00244         df_device_master      = 0,
00245         df_device_lrswap      = 0,
00246         df_device_lrws        = 0,
00247         df_device_bitlength   = 32,
00248 
00249         df_ADC_rate           = 32000,
00250         df_DAC_rate           = 32000,
00251 
00252         df_device_interface_active = 0
00253     };
00254     
00255     
00256     I2C i2c;
00257     uint8_t address;
00258     void command(reg_address add, uint16_t byte);
00259     void form_cmd(reg_address add);
00260     void defaulter();
00261     
00262     char gen_samplerate();
00263     
00264     //I2S i2s_tx(I2S_TRANSMIT, p5, p6 , p7);
00265     //I2S i2s_rx(I2S_RECIEVE , p8, p29, p30);
00266     
00267     float hp_vol_left, hp_vol_right;
00268     float li_vol_left, li_vol_right;
00269     float sdt_vol;
00270     bool li_mute_left, li_mute_right;
00271     bool bypass_;
00272     bool ADC_source;
00273     bool ADC_source_old;
00274     bool mic_mute;
00275     bool mic_boost_;
00276     bool out_mute;
00277     char de_emph_code;
00278     bool ADC_highpass_enable;
00279     
00280     bool device_all_pwr;
00281     bool device_clk_pwr;
00282     bool device_osc_pwr;
00283     bool device_out_pwr;
00284     bool device_dac_pwr;
00285     bool device_adc_pwr;
00286     bool device_mic_pwr;
00287     bool device_lni_pwr;
00288     
00289     bool device_master;
00290     bool device_lrswap;
00291     bool device_lrws;
00292     char device_bitlength;
00293     static const char device_data_form = 0x02;
00294     
00295     int ADC_rate;
00296     int DAC_rate;
00297     static const bool device_usb_mode = false;
00298     static const bool device_clk_in_div = false;
00299     static const bool device_clk_out_div = false;
00300     bool device_interface_active;
00301 };
00302 
00303 #endif