Code for measuring the signal with a specified length and sampling rate, and saving it on a SD card.

Dependencies:   EALib I2S mbed

Committer:
msamadani
Date:
Thu Jul 13 19:33:37 2017 +0000
Revision:
0:c05b00be2229
bpFilter function works.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
msamadani 0:c05b00be2229 1 /**
msamadani 0:c05b00be2229 2 *
msamadani 0:c05b00be2229 3 * @section LICENSE
msamadani 0:c05b00be2229 4 *
msamadani 0:c05b00be2229 5 * Copyright (c) 2012 mbed
msamadani 0:c05b00be2229 6 *
msamadani 0:c05b00be2229 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
msamadani 0:c05b00be2229 8 * of this software and associated documentation files (the "Software"), to deal
msamadani 0:c05b00be2229 9 * in the Software without restriction, including without limitation the rights
msamadani 0:c05b00be2229 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
msamadani 0:c05b00be2229 11 * copies of the Software, and to permit persons to whom the Software is
msamadani 0:c05b00be2229 12 * furnished to do so, subject to the following conditions:
msamadani 0:c05b00be2229 13 *
msamadani 0:c05b00be2229 14 * The above copyright notice and this permission notice shall be included in
msamadani 0:c05b00be2229 15 * all copies or substantial portions of the Software.
msamadani 0:c05b00be2229 16 *
msamadani 0:c05b00be2229 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
msamadani 0:c05b00be2229 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
msamadani 0:c05b00be2229 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
msamadani 0:c05b00be2229 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
msamadani 0:c05b00be2229 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
msamadani 0:c05b00be2229 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
msamadani 0:c05b00be2229 23 * THE SOFTWARE.
msamadani 0:c05b00be2229 24 *
msamadani 0:c05b00be2229 25 * @section DESCRIPTION
msamadani 0:c05b00be2229 26 * A Driver set for the I2C half of the WM8731. Based on the WM8731
msamadani 0:c05b00be2229 27 * code http://mbed.org/users/p07gbar/code/WM8731/
msamadani 0:c05b00be2229 28 *
msamadani 0:c05b00be2229 29 */
msamadani 0:c05b00be2229 30
msamadani 0:c05b00be2229 31 #include "WM8731.h"
msamadani 0:c05b00be2229 32
msamadani 0:c05b00be2229 33 #define WM8731_HP_VOL_DF_MASK 0x80
msamadani 0:c05b00be2229 34
msamadani 0:c05b00be2229 35
msamadani 0:c05b00be2229 36 #define WM8731_DF_hp_vol_left 0.5
msamadani 0:c05b00be2229 37 #define WM8731_DF_hp_vol_right 0.5
msamadani 0:c05b00be2229 38 #define WM8731_DF_li_vol_left 0.5
msamadani 0:c05b00be2229 39 #define WM8731_DF_li_vol_right 0.5
msamadani 0:c05b00be2229 40 #define WM8731_DF_sdt_vol 0
msamadani 0:c05b00be2229 41
msamadani 0:c05b00be2229 42 const uint8_t base_address = 0x1A;
msamadani 0:c05b00be2229 43
msamadani 0:c05b00be2229 44
msamadani 0:c05b00be2229 45 WM8731::WM8731(PinName i2c_sda, PinName i2c_scl): i2c(i2c_sda,i2c_scl) {
msamadani 0:c05b00be2229 46 address = base_address;
msamadani 0:c05b00be2229 47 defaulter();
msamadani 0:c05b00be2229 48 form_cmd(all);
msamadani 0:c05b00be2229 49 }
msamadani 0:c05b00be2229 50
msamadani 0:c05b00be2229 51 WM8731::WM8731(PinName i2c_sda, PinName i2c_scl, bool cs_level): i2c(i2c_sda,i2c_scl) {
msamadani 0:c05b00be2229 52 address = base_address + (1*cs_level);
msamadani 0:c05b00be2229 53 defaulter();
msamadani 0:c05b00be2229 54 form_cmd(all);
msamadani 0:c05b00be2229 55 }
msamadani 0:c05b00be2229 56
msamadani 0:c05b00be2229 57 void WM8731::power(bool on_off) {
msamadani 0:c05b00be2229 58 device_all_pwr = on_off;
msamadani 0:c05b00be2229 59 form_cmd(power_control);
msamadani 0:c05b00be2229 60 }
msamadani 0:c05b00be2229 61
msamadani 0:c05b00be2229 62 void WM8731::input_select(int input) {
msamadani 0:c05b00be2229 63
msamadani 0:c05b00be2229 64 switch(input)
msamadani 0:c05b00be2229 65 {
msamadani 0:c05b00be2229 66 case WM8731_NO_IN:
msamadani 0:c05b00be2229 67 device_adc_pwr = false;
msamadani 0:c05b00be2229 68 device_mic_pwr = false;
msamadani 0:c05b00be2229 69 device_lni_pwr = false;
msamadani 0:c05b00be2229 70 form_cmd(power_control);
msamadani 0:c05b00be2229 71 break;
msamadani 0:c05b00be2229 72 case WM8731_LINE:
msamadani 0:c05b00be2229 73 device_adc_pwr = true;
msamadani 0:c05b00be2229 74 device_lni_pwr = true;
msamadani 0:c05b00be2229 75 device_mic_pwr = false;
msamadani 0:c05b00be2229 76 ADC_source = WM8731_LINE;
msamadani 0:c05b00be2229 77 form_cmd(power_control);
msamadani 0:c05b00be2229 78 form_cmd(path_analog);
msamadani 0:c05b00be2229 79 break;
msamadani 0:c05b00be2229 80 case WM8731_MIC:
msamadani 0:c05b00be2229 81 device_adc_pwr = true;
msamadani 0:c05b00be2229 82 device_lni_pwr = true;
msamadani 0:c05b00be2229 83 device_mic_pwr = true;
msamadani 0:c05b00be2229 84 ADC_source = WM8731_MIC;
msamadani 0:c05b00be2229 85 form_cmd(power_control);
msamadani 0:c05b00be2229 86 form_cmd(path_analog);
msamadani 0:c05b00be2229 87 break;
msamadani 0:c05b00be2229 88 default:
msamadani 0:c05b00be2229 89 device_adc_pwr = df_device_adc_pwr;
msamadani 0:c05b00be2229 90 device_mic_pwr = df_device_mic_pwr;
msamadani 0:c05b00be2229 91 device_lni_pwr = df_device_lni_pwr;
msamadani 0:c05b00be2229 92 ADC_source = df_ADC_source;
msamadani 0:c05b00be2229 93 form_cmd(power_control);
msamadani 0:c05b00be2229 94 form_cmd(path_analog);
msamadani 0:c05b00be2229 95 break;
msamadani 0:c05b00be2229 96 }
msamadani 0:c05b00be2229 97 ADC_source_old = ADC_source;
msamadani 0:c05b00be2229 98 }
msamadani 0:c05b00be2229 99
msamadani 0:c05b00be2229 100 void WM8731::headphone_volume(float h_volume) {
msamadani 0:c05b00be2229 101 hp_vol_left = h_volume;
msamadani 0:c05b00be2229 102 hp_vol_right = h_volume;
msamadani 0:c05b00be2229 103 form_cmd(headphone_vol_left);
msamadani 0:c05b00be2229 104 form_cmd(headphone_vol_right);
msamadani 0:c05b00be2229 105 }
msamadani 0:c05b00be2229 106
msamadani 0:c05b00be2229 107 void WM8731::linein_volume(float li_volume) {
msamadani 0:c05b00be2229 108 li_vol_left = li_volume;
msamadani 0:c05b00be2229 109 li_vol_right = li_volume;
msamadani 0:c05b00be2229 110 form_cmd(line_in_vol_left);
msamadani 0:c05b00be2229 111 form_cmd(line_in_vol_right);
msamadani 0:c05b00be2229 112 }
msamadani 0:c05b00be2229 113
msamadani 0:c05b00be2229 114 void WM8731::microphone_boost(bool mic_boost) {
msamadani 0:c05b00be2229 115 mic_boost_ = mic_boost;
msamadani 0:c05b00be2229 116 }
msamadani 0:c05b00be2229 117
msamadani 0:c05b00be2229 118 void WM8731::input_mute(bool mute) {
msamadani 0:c05b00be2229 119 if(ADC_source == WM8731_MIC)
msamadani 0:c05b00be2229 120 {
msamadani 0:c05b00be2229 121 mic_mute = mute;
msamadani 0:c05b00be2229 122 form_cmd(path_analog);
msamadani 0:c05b00be2229 123 }
msamadani 0:c05b00be2229 124 else
msamadani 0:c05b00be2229 125 {
msamadani 0:c05b00be2229 126 li_mute_left = mute;
msamadani 0:c05b00be2229 127 li_mute_right = mute;
msamadani 0:c05b00be2229 128 form_cmd(line_in_vol_left);
msamadani 0:c05b00be2229 129 form_cmd(line_in_vol_right);
msamadani 0:c05b00be2229 130 }
msamadani 0:c05b00be2229 131 }
msamadani 0:c05b00be2229 132
msamadani 0:c05b00be2229 133 void WM8731::output_mute(bool mute) {
msamadani 0:c05b00be2229 134 out_mute = mute;
msamadani 0:c05b00be2229 135 form_cmd(path_digital);
msamadani 0:c05b00be2229 136 }
msamadani 0:c05b00be2229 137
msamadani 0:c05b00be2229 138 void WM8731::input_power(bool on_off) {
msamadani 0:c05b00be2229 139
msamadani 0:c05b00be2229 140 device_adc_pwr = on_off;
msamadani 0:c05b00be2229 141
msamadani 0:c05b00be2229 142 if(ADC_source == WM8731_MIC)
msamadani 0:c05b00be2229 143 {
msamadani 0:c05b00be2229 144 device_mic_pwr = on_off;
msamadani 0:c05b00be2229 145 device_lni_pwr = on_off;
msamadani 0:c05b00be2229 146 }
msamadani 0:c05b00be2229 147 else
msamadani 0:c05b00be2229 148 {
msamadani 0:c05b00be2229 149 device_mic_pwr = false;
msamadani 0:c05b00be2229 150 device_lni_pwr = on_off;
msamadani 0:c05b00be2229 151 }
msamadani 0:c05b00be2229 152
msamadani 0:c05b00be2229 153 form_cmd(power_control);
msamadani 0:c05b00be2229 154 }
msamadani 0:c05b00be2229 155
msamadani 0:c05b00be2229 156 void WM8731::output_power(bool on_off) {
msamadani 0:c05b00be2229 157 device_dac_pwr = on_off;
msamadani 0:c05b00be2229 158 device_out_pwr = on_off;
msamadani 0:c05b00be2229 159
msamadani 0:c05b00be2229 160 form_cmd(power_control);
msamadani 0:c05b00be2229 161 }
msamadani 0:c05b00be2229 162
msamadani 0:c05b00be2229 163 void WM8731::wordsize(int words) {
msamadani 0:c05b00be2229 164 device_bitlength = words;
msamadani 0:c05b00be2229 165 form_cmd(interface_format);
msamadani 0:c05b00be2229 166 }
msamadani 0:c05b00be2229 167
msamadani 0:c05b00be2229 168 void WM8731::master(bool master) {
msamadani 0:c05b00be2229 169 device_master = master;
msamadani 0:c05b00be2229 170 form_cmd(interface_format);
msamadani 0:c05b00be2229 171 }
msamadani 0:c05b00be2229 172
msamadani 0:c05b00be2229 173 void WM8731::frequency(int freq) {
msamadani 0:c05b00be2229 174 ADC_rate = freq;
msamadani 0:c05b00be2229 175 DAC_rate = freq;
msamadani 0:c05b00be2229 176 form_cmd(sample_rate);
msamadani 0:c05b00be2229 177 }
msamadani 0:c05b00be2229 178
msamadani 0:c05b00be2229 179 void WM8731::input_highpass(bool enabled) {
msamadani 0:c05b00be2229 180 ADC_highpass_enable = enabled;
msamadani 0:c05b00be2229 181 form_cmd(path_digital);
msamadani 0:c05b00be2229 182 }
msamadani 0:c05b00be2229 183
msamadani 0:c05b00be2229 184 void WM8731::output_softmute(bool enabled) {
msamadani 0:c05b00be2229 185 out_mute = enabled;
msamadani 0:c05b00be2229 186 form_cmd(path_digital);
msamadani 0:c05b00be2229 187 }
msamadani 0:c05b00be2229 188
msamadani 0:c05b00be2229 189 void WM8731::interface_switch(bool on_off) {
msamadani 0:c05b00be2229 190 device_interface_active = on_off;
msamadani 0:c05b00be2229 191 form_cmd(interface_activation);
msamadani 0:c05b00be2229 192 }
msamadani 0:c05b00be2229 193
msamadani 0:c05b00be2229 194 void WM8731::sidetone(float sidetone_vol) {
msamadani 0:c05b00be2229 195 sdt_vol = sidetone_vol;
msamadani 0:c05b00be2229 196 form_cmd(path_analog);
msamadani 0:c05b00be2229 197 }
msamadani 0:c05b00be2229 198
msamadani 0:c05b00be2229 199 void WM8731::deemphasis(char code) {
msamadani 0:c05b00be2229 200 de_emph_code = code & 0x03;
msamadani 0:c05b00be2229 201 form_cmd(path_digital);
msamadani 0:c05b00be2229 202 }
msamadani 0:c05b00be2229 203
msamadani 0:c05b00be2229 204 void WM8731::reset() {
msamadani 0:c05b00be2229 205 form_cmd(reset_reg);
msamadani 0:c05b00be2229 206 }
msamadani 0:c05b00be2229 207
msamadani 0:c05b00be2229 208 void WM8731::start() {
msamadani 0:c05b00be2229 209 interface_switch(true);
msamadani 0:c05b00be2229 210 }
msamadani 0:c05b00be2229 211
msamadani 0:c05b00be2229 212 void WM8731::bypass(bool enable) {
msamadani 0:c05b00be2229 213 bypass_ = enable;
msamadani 0:c05b00be2229 214 form_cmd(path_analog);
msamadani 0:c05b00be2229 215 }
msamadani 0:c05b00be2229 216
msamadani 0:c05b00be2229 217 void WM8731::stop() {
msamadani 0:c05b00be2229 218 interface_switch(false);
msamadani 0:c05b00be2229 219 }
msamadani 0:c05b00be2229 220
msamadani 0:c05b00be2229 221 void WM8731::command(reg_address add, uint16_t cmd) {
msamadani 0:c05b00be2229 222 char temp[2];
msamadani 0:c05b00be2229 223 temp[0] = (char(add)<<1) | ((cmd >> 6) & 0x01);
msamadani 0:c05b00be2229 224 temp[1] = (cmd & 0xFF);
msamadani 0:c05b00be2229 225 i2c.write((address<<1), temp, 2);
msamadani 0:c05b00be2229 226 }
msamadani 0:c05b00be2229 227
msamadani 0:c05b00be2229 228 void WM8731::form_cmd(reg_address add) {
msamadani 0:c05b00be2229 229 uint16_t cmd = 0;
msamadani 0:c05b00be2229 230 int temp = 0;
msamadani 0:c05b00be2229 231 bool mute;
msamadani 0:c05b00be2229 232 switch(add)
msamadani 0:c05b00be2229 233 {
msamadani 0:c05b00be2229 234 case line_in_vol_left:
msamadani 0:c05b00be2229 235 temp = int(li_vol_left * 32) - 1;
msamadani 0:c05b00be2229 236 mute = li_mute_left;
msamadani 0:c05b00be2229 237
msamadani 0:c05b00be2229 238 if(temp < 0)
msamadani 0:c05b00be2229 239 {
msamadani 0:c05b00be2229 240 temp = 0;
msamadani 0:c05b00be2229 241 mute = true;
msamadani 0:c05b00be2229 242 }
msamadani 0:c05b00be2229 243 cmd = temp & 0x1F;
msamadani 0:c05b00be2229 244 cmd |= mute << 7;
msamadani 0:c05b00be2229 245 break;
msamadani 0:c05b00be2229 246 case line_in_vol_right:
msamadani 0:c05b00be2229 247 temp = int(li_vol_right * 32) - 1;
msamadani 0:c05b00be2229 248 mute = li_mute_right;
msamadani 0:c05b00be2229 249 if(temp < 0)
msamadani 0:c05b00be2229 250 {
msamadani 0:c05b00be2229 251 temp = 0;
msamadani 0:c05b00be2229 252 mute = true;
msamadani 0:c05b00be2229 253 }
msamadani 0:c05b00be2229 254 cmd = temp & 0x1F;
msamadani 0:c05b00be2229 255 cmd |= mute << 7;
msamadani 0:c05b00be2229 256 break;
msamadani 0:c05b00be2229 257
msamadani 0:c05b00be2229 258 case headphone_vol_left:
msamadani 0:c05b00be2229 259 temp = int(hp_vol_left * 80) + 47;
msamadani 0:c05b00be2229 260 cmd = WM8731_HP_VOL_DF_MASK;
msamadani 0:c05b00be2229 261 cmd |= temp & 0x7F;
msamadani 0:c05b00be2229 262 break;
msamadani 0:c05b00be2229 263 case headphone_vol_right:
msamadani 0:c05b00be2229 264 temp = int(hp_vol_right * 80) + 47;
msamadani 0:c05b00be2229 265 cmd = WM8731_HP_VOL_DF_MASK;
msamadani 0:c05b00be2229 266 cmd |= temp & 0x7F;
msamadani 0:c05b00be2229 267 break;
msamadani 0:c05b00be2229 268
msamadani 0:c05b00be2229 269 case path_analog:
msamadani 0:c05b00be2229 270 temp = int(sdt_vol * 4);
msamadani 0:c05b00be2229 271 char vol_code = 0;
msamadani 0:c05b00be2229 272 switch(temp)
msamadani 0:c05b00be2229 273 {
msamadani 0:c05b00be2229 274 case 4:
msamadani 0:c05b00be2229 275 vol_code = 0x01;
msamadani 0:c05b00be2229 276 break;
msamadani 0:c05b00be2229 277 case 0:
msamadani 0:c05b00be2229 278 vol_code = 0x00;
msamadani 0:c05b00be2229 279 break;
msamadani 0:c05b00be2229 280 default:
msamadani 0:c05b00be2229 281 vol_code = (((0x04 - temp)&0x03) << 1) | 0x01;
msamadani 0:c05b00be2229 282 break;
msamadani 0:c05b00be2229 283 }
msamadani 0:c05b00be2229 284 cmd = vol_code << 5;
msamadani 0:c05b00be2229 285 cmd |= 1 << 4;
msamadani 0:c05b00be2229 286 cmd |= bypass_ << 3;
msamadani 0:c05b00be2229 287 cmd |= ADC_source << 2;
msamadani 0:c05b00be2229 288 cmd |= mic_mute << 1;
msamadani 0:c05b00be2229 289 cmd |= mic_boost_;
msamadani 0:c05b00be2229 290 break;
msamadani 0:c05b00be2229 291
msamadani 0:c05b00be2229 292 case path_digital:
msamadani 0:c05b00be2229 293 cmd |= out_mute << 3;
msamadani 0:c05b00be2229 294 cmd |= ((de_emph_code & 0x3) << 1);
msamadani 0:c05b00be2229 295 cmd |= ADC_highpass_enable;
msamadani 0:c05b00be2229 296 break;
msamadani 0:c05b00be2229 297
msamadani 0:c05b00be2229 298 case power_control:
msamadani 0:c05b00be2229 299 cmd |= !device_all_pwr << 7;
msamadani 0:c05b00be2229 300 cmd |= !device_clk_pwr << 6;
msamadani 0:c05b00be2229 301 cmd |= !device_osc_pwr << 5;
msamadani 0:c05b00be2229 302 cmd |= !device_out_pwr << 4;
msamadani 0:c05b00be2229 303 cmd |= !device_dac_pwr << 3;
msamadani 0:c05b00be2229 304 cmd |= !device_adc_pwr << 2;
msamadani 0:c05b00be2229 305 cmd |= !device_mic_pwr << 1;
msamadani 0:c05b00be2229 306 cmd |= !device_lni_pwr << 0;
msamadani 0:c05b00be2229 307 break;
msamadani 0:c05b00be2229 308
msamadani 0:c05b00be2229 309 case interface_format:
msamadani 0:c05b00be2229 310 cmd |= device_master << 6;
msamadani 0:c05b00be2229 311 cmd |= device_lrswap << 5;
msamadani 0:c05b00be2229 312 cmd |= device_lrws << 4;
msamadani 0:c05b00be2229 313 temp = 0;
msamadani 0:c05b00be2229 314 switch(device_bitlength)
msamadani 0:c05b00be2229 315 {
msamadani 0:c05b00be2229 316 case 16:
msamadani 0:c05b00be2229 317 temp = 0;
msamadani 0:c05b00be2229 318 break;
msamadani 0:c05b00be2229 319 case 20:
msamadani 0:c05b00be2229 320 temp = 1;
msamadani 0:c05b00be2229 321 break;
msamadani 0:c05b00be2229 322 case 24:
msamadani 0:c05b00be2229 323 temp = 2;
msamadani 0:c05b00be2229 324 break;
msamadani 0:c05b00be2229 325 case 32:
msamadani 0:c05b00be2229 326 temp = 3;
msamadani 0:c05b00be2229 327 break;
msamadani 0:c05b00be2229 328 }
msamadani 0:c05b00be2229 329 cmd |= (temp & 0x03) << 2;
msamadani 0:c05b00be2229 330 cmd |= (device_data_form & 0x03);
msamadani 0:c05b00be2229 331 break;
msamadani 0:c05b00be2229 332
msamadani 0:c05b00be2229 333 case sample_rate:
msamadani 0:c05b00be2229 334 temp = gen_samplerate();
msamadani 0:c05b00be2229 335 cmd = device_usb_mode;
msamadani 0:c05b00be2229 336 cmd |= (temp & 0x1f) << 1;
msamadani 0:c05b00be2229 337 cmd |= device_clk_in_div << 6;
msamadani 0:c05b00be2229 338 cmd |= device_clk_out_div << 7;
msamadani 0:c05b00be2229 339 break;
msamadani 0:c05b00be2229 340
msamadani 0:c05b00be2229 341 case interface_activation:
msamadani 0:c05b00be2229 342 cmd = device_interface_active;
msamadani 0:c05b00be2229 343 break;
msamadani 0:c05b00be2229 344
msamadani 0:c05b00be2229 345 case reset_reg:
msamadani 0:c05b00be2229 346 cmd = 0;
msamadani 0:c05b00be2229 347 break;
msamadani 0:c05b00be2229 348
msamadani 0:c05b00be2229 349 case all:
msamadani 0:c05b00be2229 350 for( int i = line_in_vol_left; i <= reset_reg; i++)
msamadani 0:c05b00be2229 351 {
msamadani 0:c05b00be2229 352 form_cmd((reg_address)i);
msamadani 0:c05b00be2229 353 }
msamadani 0:c05b00be2229 354 break;
msamadani 0:c05b00be2229 355 }
msamadani 0:c05b00be2229 356 if(add != all) command(add , cmd);
msamadani 0:c05b00be2229 357 }
msamadani 0:c05b00be2229 358
msamadani 0:c05b00be2229 359 void WM8731::defaulter() {
msamadani 0:c05b00be2229 360 hp_vol_left = WM8731_DF_hp_vol_left;
msamadani 0:c05b00be2229 361 hp_vol_right = WM8731_DF_hp_vol_right;
msamadani 0:c05b00be2229 362 li_vol_left = WM8731_DF_li_vol_left;
msamadani 0:c05b00be2229 363 li_vol_right = WM8731_DF_li_vol_right;
msamadani 0:c05b00be2229 364 sdt_vol = WM8731_DF_sdt_vol;
msamadani 0:c05b00be2229 365 bypass_ = df_bypass_;
msamadani 0:c05b00be2229 366
msamadani 0:c05b00be2229 367 ADC_source = df_ADC_source;
msamadani 0:c05b00be2229 368 ADC_source_old = df_ADC_source;
msamadani 0:c05b00be2229 369
msamadani 0:c05b00be2229 370 mic_mute = df_mic_mute;
msamadani 0:c05b00be2229 371 li_mute_left = df_li_mute_left;
msamadani 0:c05b00be2229 372 li_mute_right = df_li_mute_right;
msamadani 0:c05b00be2229 373
msamadani 0:c05b00be2229 374
msamadani 0:c05b00be2229 375 mic_boost_ = df_mic_boost_;
msamadani 0:c05b00be2229 376 out_mute = df_out_mute;
msamadani 0:c05b00be2229 377 de_emph_code = df_de_emph_code;
msamadani 0:c05b00be2229 378 ADC_highpass_enable = df_ADC_highpass_enable;
msamadani 0:c05b00be2229 379
msamadani 0:c05b00be2229 380 device_all_pwr = df_device_all_pwr;
msamadani 0:c05b00be2229 381 device_clk_pwr = df_device_clk_pwr;
msamadani 0:c05b00be2229 382 device_osc_pwr = df_device_osc_pwr;
msamadani 0:c05b00be2229 383 device_out_pwr = df_device_out_pwr;
msamadani 0:c05b00be2229 384 device_dac_pwr = df_device_dac_pwr;
msamadani 0:c05b00be2229 385 device_adc_pwr = df_device_dac_pwr;
msamadani 0:c05b00be2229 386 device_mic_pwr = df_device_mic_pwr;
msamadani 0:c05b00be2229 387 device_lni_pwr = df_device_lni_pwr;
msamadani 0:c05b00be2229 388
msamadani 0:c05b00be2229 389 device_master = df_device_master;
msamadani 0:c05b00be2229 390 device_lrswap = df_device_lrswap;
msamadani 0:c05b00be2229 391 device_lrws = df_device_lrws;
msamadani 0:c05b00be2229 392 device_bitlength = df_device_bitlength;
msamadani 0:c05b00be2229 393
msamadani 0:c05b00be2229 394
msamadani 0:c05b00be2229 395 ADC_rate = df_ADC_rate;
msamadani 0:c05b00be2229 396 DAC_rate = df_DAC_rate;
msamadani 0:c05b00be2229 397
msamadani 0:c05b00be2229 398 device_interface_active = df_device_interface_active;
msamadani 0:c05b00be2229 399 }
msamadani 0:c05b00be2229 400
msamadani 0:c05b00be2229 401 char WM8731::gen_samplerate() {
msamadani 0:c05b00be2229 402 char temp = 0;
msamadani 0:c05b00be2229 403 switch(ADC_rate)
msamadani 0:c05b00be2229 404 {
msamadani 0:c05b00be2229 405 case 96000:
msamadani 0:c05b00be2229 406 temp = 0x0E;
msamadani 0:c05b00be2229 407 break;
msamadani 0:c05b00be2229 408 case 48000:
msamadani 0:c05b00be2229 409 temp = 0x00;
msamadani 0:c05b00be2229 410 if(DAC_rate == 8000) temp = 0x02;
msamadani 0:c05b00be2229 411 break;
msamadani 0:c05b00be2229 412 case 32000:
msamadani 0:c05b00be2229 413 temp = 0x0C;
msamadani 0:c05b00be2229 414 break;
msamadani 0:c05b00be2229 415 case 8000:
msamadani 0:c05b00be2229 416 temp = 0x06;
msamadani 0:c05b00be2229 417 if(DAC_rate == 48000) temp = 0x04;
msamadani 0:c05b00be2229 418 break;
msamadani 0:c05b00be2229 419 default:
msamadani 0:c05b00be2229 420 temp = 0x00;
msamadani 0:c05b00be2229 421 break;
msamadani 0:c05b00be2229 422 }
msamadani 0:c05b00be2229 423 return temp;
msamadani 0:c05b00be2229 424 }