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