WavPlayer.h changed to circuit board

Dependents:   WavPlayerSD WavPlayerUSB WavPlayerUSB WavPlayerSD_CB

Committer:
p07gbar
Date:
Wed Sep 19 11:05:12 2012 +0000
Revision:
1:3eb96771bbee
Working - Making it easier to publish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p07gbar 1:3eb96771bbee 1 /**
p07gbar 1:3eb96771bbee 2 * @author Giles Barton-Owen
p07gbar 1:3eb96771bbee 3 *
p07gbar 1:3eb96771bbee 4 * @section LICENSE
p07gbar 1:3eb96771bbee 5 *
p07gbar 1:3eb96771bbee 6 * Copyright (c) 2012 mbed
p07gbar 1:3eb96771bbee 7 *
p07gbar 1:3eb96771bbee 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
p07gbar 1:3eb96771bbee 9 * of this software and associated documentation files (the "Software"), to deal
p07gbar 1:3eb96771bbee 10 * in the Software without restriction, including without limitation the rights
p07gbar 1:3eb96771bbee 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
p07gbar 1:3eb96771bbee 12 * copies of the Software, and to permit persons to whom the Software is
p07gbar 1:3eb96771bbee 13 * furnished to do so, subject to the following conditions:
p07gbar 1:3eb96771bbee 14 *
p07gbar 1:3eb96771bbee 15 * The above copyright notice and this permission notice shall be included in
p07gbar 1:3eb96771bbee 16 * all copies or substantial portions of the Software.
p07gbar 1:3eb96771bbee 17 *
p07gbar 1:3eb96771bbee 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
p07gbar 1:3eb96771bbee 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
p07gbar 1:3eb96771bbee 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
p07gbar 1:3eb96771bbee 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
p07gbar 1:3eb96771bbee 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
p07gbar 1:3eb96771bbee 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
p07gbar 1:3eb96771bbee 24 * THE SOFTWARE.
p07gbar 1:3eb96771bbee 25 *
p07gbar 1:3eb96771bbee 26 * @section DESCRIPTION
p07gbar 1:3eb96771bbee 27 * A Driver set for the I2C half of the TLV320
p07gbar 1:3eb96771bbee 28 *
p07gbar 1:3eb96771bbee 29 */
p07gbar 1:3eb96771bbee 30
p07gbar 1:3eb96771bbee 31
p07gbar 1:3eb96771bbee 32 #ifndef TLV320_H
p07gbar 1:3eb96771bbee 33 #define TLV320_H
p07gbar 1:3eb96771bbee 34 #include "mbed.h"
p07gbar 1:3eb96771bbee 35
p07gbar 1:3eb96771bbee 36 #define TLV320_CS_HIGH true
p07gbar 1:3eb96771bbee 37 #define TLV320_CS_LOW false
p07gbar 1:3eb96771bbee 38
p07gbar 1:3eb96771bbee 39 #define TLV320_ON true
p07gbar 1:3eb96771bbee 40 #define TLV320_OFF false
p07gbar 1:3eb96771bbee 41
p07gbar 1:3eb96771bbee 42 #define TLV320_MUTE true
p07gbar 1:3eb96771bbee 43 #define TLV320_UNMUTE false
p07gbar 1:3eb96771bbee 44
p07gbar 1:3eb96771bbee 45 #define TLV320_MASTER true
p07gbar 1:3eb96771bbee 46 #define TLV320_SLAVE false
p07gbar 1:3eb96771bbee 47
p07gbar 1:3eb96771bbee 48 #define TLV320_LINE 0
p07gbar 1:3eb96771bbee 49 #define TLV320_MIC 1
p07gbar 1:3eb96771bbee 50 #define TLV320_NO_IN -1
p07gbar 1:3eb96771bbee 51
p07gbar 1:3eb96771bbee 52 #define TLV320_DE_EMPH_DISABLED 0
p07gbar 1:3eb96771bbee 53 #define TLV320_DE_EMPH_32KHZ 1
p07gbar 1:3eb96771bbee 54 #define TLV320_DE_EMPH_44KHZ 2
p07gbar 1:3eb96771bbee 55 #define TLV320_DE_EMPH_48KHZ 3
p07gbar 1:3eb96771bbee 56
p07gbar 1:3eb96771bbee 57 /** A class to control the I2C part of the TLV320
p07gbar 1:3eb96771bbee 58 *
p07gbar 1:3eb96771bbee 59 */
p07gbar 1:3eb96771bbee 60 class TLV320
p07gbar 1:3eb96771bbee 61 {
p07gbar 1:3eb96771bbee 62 public:
p07gbar 1:3eb96771bbee 63 /** Create an instance of the TLV320 class
p07gbar 1:3eb96771bbee 64 *
p07gbar 1:3eb96771bbee 65 * @param i2c_sda The SDA pin of the I2C
p07gbar 1:3eb96771bbee 66 * @param i2c_scl The SCL pin of the I2C
p07gbar 1:3eb96771bbee 67 */
p07gbar 1:3eb96771bbee 68 TLV320(PinName i2c_sda, PinName i2c_scl);
p07gbar 1:3eb96771bbee 69
p07gbar 1:3eb96771bbee 70 /** Create an instance of the TLV320 class
p07gbar 1:3eb96771bbee 71 *
p07gbar 1:3eb96771bbee 72 * @param i2c_sda The SDA pin of the I2C
p07gbar 1:3eb96771bbee 73 * @param i2c_scl The SCL pin of the I2C
p07gbar 1:3eb96771bbee 74 * @param cs_level The level of the CS pin on the TLV320
p07gbar 1:3eb96771bbee 75 */
p07gbar 1:3eb96771bbee 76 TLV320(PinName i2c_sda, PinName i2c_scl, bool cs_level);
p07gbar 1:3eb96771bbee 77
p07gbar 1:3eb96771bbee 78 /** Control the power of the device
p07gbar 1:3eb96771bbee 79 *
p07gbar 1:3eb96771bbee 80 * @param on_off The power state
p07gbar 1:3eb96771bbee 81 */
p07gbar 1:3eb96771bbee 82 void power(bool on_off);
p07gbar 1:3eb96771bbee 83
p07gbar 1:3eb96771bbee 84 /** Control the input source of the device
p07gbar 1:3eb96771bbee 85 *
p07gbar 1:3eb96771bbee 86 * @param input Select the source of the input of the device: TLV320_LINE, TLV320_MIC, TLV320_NO_IN
p07gbar 1:3eb96771bbee 87 */
p07gbar 1:3eb96771bbee 88 void input_select(int input);
p07gbar 1:3eb96771bbee 89
p07gbar 1:3eb96771bbee 90 /** Set the headphone volume
p07gbar 1:3eb96771bbee 91 *
p07gbar 1:3eb96771bbee 92 * @param h_volume The desired headphone volume: 0->1
p07gbar 1:3eb96771bbee 93 */
p07gbar 1:3eb96771bbee 94 void headphone_volume(float h_volume);
p07gbar 1:3eb96771bbee 95
p07gbar 1:3eb96771bbee 96 /** Set the line in pre-amp volume
p07gbar 1:3eb96771bbee 97 *
p07gbar 1:3eb96771bbee 98 * @param li_volume The desired line in volume: 0->1
p07gbar 1:3eb96771bbee 99 */
p07gbar 1:3eb96771bbee 100 void linein_volume(float li_volume);
p07gbar 1:3eb96771bbee 101
p07gbar 1:3eb96771bbee 102 /** Turn on/off the microphone pre-amp boost
p07gbar 1:3eb96771bbee 103 *
p07gbar 1:3eb96771bbee 104 * @param mic_boost Boost on or off
p07gbar 1:3eb96771bbee 105 */
p07gbar 1:3eb96771bbee 106 void microphone_boost(bool mic_boost);
p07gbar 1:3eb96771bbee 107
p07gbar 1:3eb96771bbee 108 /** Mute the input
p07gbar 1:3eb96771bbee 109 *
p07gbar 1:3eb96771bbee 110 * @param mute Mute on/off
p07gbar 1:3eb96771bbee 111 */
p07gbar 1:3eb96771bbee 112 void input_mute(bool mute);
p07gbar 1:3eb96771bbee 113
p07gbar 1:3eb96771bbee 114 /** Mute the output
p07gbar 1:3eb96771bbee 115 *
p07gbar 1:3eb96771bbee 116 * @param mute Mute on/off
p07gbar 1:3eb96771bbee 117 */
p07gbar 1:3eb96771bbee 118 void output_mute(bool mute);
p07gbar 1:3eb96771bbee 119
p07gbar 1:3eb96771bbee 120 /** Turn on/off the input stage
p07gbar 1:3eb96771bbee 121 *
p07gbar 1:3eb96771bbee 122 * @param on_off Input stage on(true)/off(false)
p07gbar 1:3eb96771bbee 123 */
p07gbar 1:3eb96771bbee 124 void input_power(bool on_off);
p07gbar 1:3eb96771bbee 125
p07gbar 1:3eb96771bbee 126 /** Turn on/off the output stage
p07gbar 1:3eb96771bbee 127 *
p07gbar 1:3eb96771bbee 128 * @param on_off Output stage on(true)/off(false)
p07gbar 1:3eb96771bbee 129 */
p07gbar 1:3eb96771bbee 130 void output_power(bool on_off);
p07gbar 1:3eb96771bbee 131
p07gbar 1:3eb96771bbee 132 /** Select the word size
p07gbar 1:3eb96771bbee 133 *
p07gbar 1:3eb96771bbee 134 * @param words 16/20/24/32 bits
p07gbar 1:3eb96771bbee 135 */
p07gbar 1:3eb96771bbee 136 void wordsize(int words);
p07gbar 1:3eb96771bbee 137
p07gbar 1:3eb96771bbee 138 /** Select interface mode: Master or Slave
p07gbar 1:3eb96771bbee 139 *
p07gbar 1:3eb96771bbee 140 * @param master Interface mode: master(true)/slave
p07gbar 1:3eb96771bbee 141 */
p07gbar 1:3eb96771bbee 142 void master(bool master);
p07gbar 1:3eb96771bbee 143
p07gbar 1:3eb96771bbee 144 /** Select the sample rate
p07gbar 1:3eb96771bbee 145 *
p07gbar 1:3eb96771bbee 146 * @param freq Frequency: 96/48/32/8 kHz
p07gbar 1:3eb96771bbee 147 */
p07gbar 1:3eb96771bbee 148 void frequency(int freq);
p07gbar 1:3eb96771bbee 149
p07gbar 1:3eb96771bbee 150 /** Enable the input highpass filter
p07gbar 1:3eb96771bbee 151 *
p07gbar 1:3eb96771bbee 152 * @param enabled Input highpass filter enabled
p07gbar 1:3eb96771bbee 153 */
p07gbar 1:3eb96771bbee 154 void input_highpass(bool enabled);
p07gbar 1:3eb96771bbee 155
p07gbar 1:3eb96771bbee 156 /** Enable the output soft mute
p07gbar 1:3eb96771bbee 157 *
p07gbar 1:3eb96771bbee 158 * @param enabled Output soft mute enabled
p07gbar 1:3eb96771bbee 159 */
p07gbar 1:3eb96771bbee 160 void output_softmute(bool enabled);
p07gbar 1:3eb96771bbee 161
p07gbar 1:3eb96771bbee 162 /** Turn on and off the I2S
p07gbar 1:3eb96771bbee 163 *
p07gbar 1:3eb96771bbee 164 * @param on_off Switch the I2S interface on(true)/off(false)
p07gbar 1:3eb96771bbee 165 */
p07gbar 1:3eb96771bbee 166 void interface_switch(bool on_off);
p07gbar 1:3eb96771bbee 167
p07gbar 1:3eb96771bbee 168 /** Reset the device and settings
p07gbar 1:3eb96771bbee 169 *
p07gbar 1:3eb96771bbee 170 */
p07gbar 1:3eb96771bbee 171 void reset();
p07gbar 1:3eb96771bbee 172
p07gbar 1:3eb96771bbee 173 /** Set the microphone sidetone volume
p07gbar 1:3eb96771bbee 174 *
p07gbar 1:3eb96771bbee 175 * @param sidetone_volume The volume of the sidetone: 0->1
p07gbar 1:3eb96771bbee 176 */
p07gbar 1:3eb96771bbee 177 void sidetone(float sidetone_vol);
p07gbar 1:3eb96771bbee 178
p07gbar 1:3eb96771bbee 179 /** Set the analog bypass
p07gbar 1:3eb96771bbee 180 *
p07gbar 1:3eb96771bbee 181 * @param bypass_en Enable the bypass: enabled(true)
p07gbar 1:3eb96771bbee 182 */
p07gbar 1:3eb96771bbee 183 void bypass(bool bypass_en);
p07gbar 1:3eb96771bbee 184
p07gbar 1:3eb96771bbee 185 /** Set the deemphasis frequency
p07gbar 1:3eb96771bbee 186 *
p07gbar 1:3eb96771bbee 187 * @param code The deemphasis code: TLV320_DE_EMPH_DISABLED, TLV320_DE_EMPH_32KHZ, TLV320_DE_EMPH_44KHZ, TLV320_DE_EMPH_48KHZ
p07gbar 1:3eb96771bbee 188 */
p07gbar 1:3eb96771bbee 189 void deemphasis(char code);
p07gbar 1:3eb96771bbee 190
p07gbar 1:3eb96771bbee 191 /** Enable the input highpass filter
p07gbar 1:3eb96771bbee 192 *
p07gbar 1:3eb96771bbee 193 * @param enable Enable the input highpass filter enabled(true)
p07gbar 1:3eb96771bbee 194 */
p07gbar 1:3eb96771bbee 195
p07gbar 1:3eb96771bbee 196 void adc_highpass(bool enable);
p07gbar 1:3eb96771bbee 197
p07gbar 1:3eb96771bbee 198 /** Start the device sending/recieving etc
p07gbar 1:3eb96771bbee 199 */
p07gbar 1:3eb96771bbee 200 void start();
p07gbar 1:3eb96771bbee 201
p07gbar 1:3eb96771bbee 202 /** Stop the device sending/recieving etc
p07gbar 1:3eb96771bbee 203 */
p07gbar 1:3eb96771bbee 204 void stop();
p07gbar 1:3eb96771bbee 205
p07gbar 1:3eb96771bbee 206 private:
p07gbar 1:3eb96771bbee 207
p07gbar 1:3eb96771bbee 208 enum reg_address {
p07gbar 1:3eb96771bbee 209 line_in_vol_left = 0x00,
p07gbar 1:3eb96771bbee 210 line_in_vol_right = 0x01,
p07gbar 1:3eb96771bbee 211 headphone_vol_left = 0x02,
p07gbar 1:3eb96771bbee 212 headphone_vol_right = 0x03,
p07gbar 1:3eb96771bbee 213 path_analog = 0x04,
p07gbar 1:3eb96771bbee 214 path_digital = 0x05,
p07gbar 1:3eb96771bbee 215 power_control = 0x06,
p07gbar 1:3eb96771bbee 216 interface_format = 0x07,
p07gbar 1:3eb96771bbee 217 sample_rate = 0x08,
p07gbar 1:3eb96771bbee 218 interface_activation = 0x09,
p07gbar 1:3eb96771bbee 219 reset_reg = 0x0A,
p07gbar 1:3eb96771bbee 220 all = 0xFF
p07gbar 1:3eb96771bbee 221 };
p07gbar 1:3eb96771bbee 222
p07gbar 1:3eb96771bbee 223 enum tlv320_defaults{
p07gbar 1:3eb96771bbee 224 df_bypass_ = 0,
p07gbar 1:3eb96771bbee 225 df_ADC_source = TLV320_LINE,
p07gbar 1:3eb96771bbee 226 df_mic_mute = TLV320_UNMUTE,
p07gbar 1:3eb96771bbee 227 df_li_mute_left = 0,
p07gbar 1:3eb96771bbee 228 df_li_mute_right = 0,
p07gbar 1:3eb96771bbee 229 df_mic_boost_ = 0,
p07gbar 1:3eb96771bbee 230 df_out_mute = TLV320_UNMUTE,
p07gbar 1:3eb96771bbee 231
p07gbar 1:3eb96771bbee 232 df_de_emph_code = 0x00,
p07gbar 1:3eb96771bbee 233 df_ADC_highpass_enable = 0,
p07gbar 1:3eb96771bbee 234
p07gbar 1:3eb96771bbee 235 df_device_all_pwr = 1,
p07gbar 1:3eb96771bbee 236 df_device_clk_pwr = 1,
p07gbar 1:3eb96771bbee 237 df_device_osc_pwr = 1,
p07gbar 1:3eb96771bbee 238 df_device_out_pwr = 1,
p07gbar 1:3eb96771bbee 239 df_device_dac_pwr = 1,
p07gbar 1:3eb96771bbee 240 df_device_adc_pwr = 1,
p07gbar 1:3eb96771bbee 241 df_device_mic_pwr = 0,
p07gbar 1:3eb96771bbee 242 df_device_lni_pwr = 1,
p07gbar 1:3eb96771bbee 243
p07gbar 1:3eb96771bbee 244 df_device_master = 0,
p07gbar 1:3eb96771bbee 245 df_device_lrswap = 0,
p07gbar 1:3eb96771bbee 246 df_device_lrws = 0,
p07gbar 1:3eb96771bbee 247 df_device_bitlength = 32,
p07gbar 1:3eb96771bbee 248
p07gbar 1:3eb96771bbee 249 df_ADC_rate = 32000,
p07gbar 1:3eb96771bbee 250 df_DAC_rate = 32000,
p07gbar 1:3eb96771bbee 251
p07gbar 1:3eb96771bbee 252 df_device_interface_active = 0
p07gbar 1:3eb96771bbee 253 };
p07gbar 1:3eb96771bbee 254
p07gbar 1:3eb96771bbee 255
p07gbar 1:3eb96771bbee 256 I2C i2c;
p07gbar 1:3eb96771bbee 257 uint8_t address;
p07gbar 1:3eb96771bbee 258 void command(reg_address add, uint16_t byte);
p07gbar 1:3eb96771bbee 259 void form_cmd(reg_address add);
p07gbar 1:3eb96771bbee 260 void defaulter();
p07gbar 1:3eb96771bbee 261
p07gbar 1:3eb96771bbee 262 char gen_samplerate();
p07gbar 1:3eb96771bbee 263
p07gbar 1:3eb96771bbee 264 //I2S i2s_tx(I2S_TRANSMIT, p5, p6 , p7);
p07gbar 1:3eb96771bbee 265 //I2S i2s_rx(I2S_RECIEVE , p8, p29, p30);
p07gbar 1:3eb96771bbee 266
p07gbar 1:3eb96771bbee 267 float hp_vol_left, hp_vol_right;
p07gbar 1:3eb96771bbee 268 float li_vol_left, li_vol_right;
p07gbar 1:3eb96771bbee 269 float sdt_vol;
p07gbar 1:3eb96771bbee 270 bool li_mute_left, li_mute_right;
p07gbar 1:3eb96771bbee 271 bool bypass_;
p07gbar 1:3eb96771bbee 272 bool ADC_source;
p07gbar 1:3eb96771bbee 273 bool ADC_source_old;
p07gbar 1:3eb96771bbee 274 bool mic_mute;
p07gbar 1:3eb96771bbee 275 bool mic_boost_;
p07gbar 1:3eb96771bbee 276 bool out_mute;
p07gbar 1:3eb96771bbee 277 char de_emph_code;
p07gbar 1:3eb96771bbee 278 bool ADC_highpass_enable;
p07gbar 1:3eb96771bbee 279
p07gbar 1:3eb96771bbee 280 bool device_all_pwr;
p07gbar 1:3eb96771bbee 281 bool device_clk_pwr;
p07gbar 1:3eb96771bbee 282 bool device_osc_pwr;
p07gbar 1:3eb96771bbee 283 bool device_out_pwr;
p07gbar 1:3eb96771bbee 284 bool device_dac_pwr;
p07gbar 1:3eb96771bbee 285 bool device_adc_pwr;
p07gbar 1:3eb96771bbee 286 bool device_mic_pwr;
p07gbar 1:3eb96771bbee 287 bool device_lni_pwr;
p07gbar 1:3eb96771bbee 288
p07gbar 1:3eb96771bbee 289 bool device_master;
p07gbar 1:3eb96771bbee 290 bool device_lrswap;
p07gbar 1:3eb96771bbee 291 bool device_lrws;
p07gbar 1:3eb96771bbee 292 char device_bitlength;
p07gbar 1:3eb96771bbee 293 static const char device_data_form = 0x02;
p07gbar 1:3eb96771bbee 294
p07gbar 1:3eb96771bbee 295 int ADC_rate;
p07gbar 1:3eb96771bbee 296 int DAC_rate;
p07gbar 1:3eb96771bbee 297 static const bool device_usb_mode = false;
p07gbar 1:3eb96771bbee 298 static const bool device_clk_in_div = false;
p07gbar 1:3eb96771bbee 299 static const bool device_clk_out_div = false;
p07gbar 1:3eb96771bbee 300 bool device_interface_active;
p07gbar 1:3eb96771bbee 301
p07gbar 1:3eb96771bbee 302 };
p07gbar 1:3eb96771bbee 303
p07gbar 1:3eb96771bbee 304
p07gbar 1:3eb96771bbee 305 #endif