Library for Texas Instruments TLV320AIC23B hi-def audio chip note: requires I2SSlave abstraction library
Dependents: playback FTSESpeech i2s_audio_echo i2s_audio_sampler ... more
TLV320.cpp@0:bb2411673898, 2011-08-04 (annotated)
- Committer:
- d_worrall
- Date:
- Thu Aug 04 15:04:59 2011 +0000
- Revision:
- 0:bb2411673898
version 2.29
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
d_worrall | 0:bb2411673898 | 1 | /** |
d_worrall | 0:bb2411673898 | 2 | * @author Ioannis Kedros, Daniel Worrall |
d_worrall | 0:bb2411673898 | 3 | * |
d_worrall | 0:bb2411673898 | 4 | * @section LICENSE |
d_worrall | 0:bb2411673898 | 5 | * |
d_worrall | 0:bb2411673898 | 6 | * Copyright (c) 2011 mbed |
d_worrall | 0:bb2411673898 | 7 | * |
d_worrall | 0:bb2411673898 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
d_worrall | 0:bb2411673898 | 9 | * of this software and associated documentation files (the "Software"), to deal |
d_worrall | 0:bb2411673898 | 10 | * in the Software without restriction, including without limitation the rights |
d_worrall | 0:bb2411673898 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
d_worrall | 0:bb2411673898 | 12 | * copies of the Software, and to permit persons to whom the Software is |
d_worrall | 0:bb2411673898 | 13 | * furnished to do so, subject to the following conditions: |
d_worrall | 0:bb2411673898 | 14 | * |
d_worrall | 0:bb2411673898 | 15 | * The above copyright notice and this permission notice shall be included in |
d_worrall | 0:bb2411673898 | 16 | * all copies or substantial portions of the Software. |
d_worrall | 0:bb2411673898 | 17 | * |
d_worrall | 0:bb2411673898 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
d_worrall | 0:bb2411673898 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
d_worrall | 0:bb2411673898 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
d_worrall | 0:bb2411673898 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
d_worrall | 0:bb2411673898 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
d_worrall | 0:bb2411673898 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
d_worrall | 0:bb2411673898 | 24 | * THE SOFTWARE. |
d_worrall | 0:bb2411673898 | 25 | * |
d_worrall | 0:bb2411673898 | 26 | * @section DESCRIPTION |
d_worrall | 0:bb2411673898 | 27 | * Library for Texas instruments TLV320AIC23B library NXP LPC1768 |
d_worrall | 0:bb2411673898 | 28 | * |
d_worrall | 0:bb2411673898 | 29 | */ |
d_worrall | 0:bb2411673898 | 30 | |
d_worrall | 0:bb2411673898 | 31 | #include "mbed.h" |
d_worrall | 0:bb2411673898 | 32 | #include "TLV320.h" |
d_worrall | 0:bb2411673898 | 33 | |
d_worrall | 0:bb2411673898 | 34 | TLV320::TLV320(PinName sda, PinName scl, int addr, PinName tx_sda, PinName tx_ws, PinName clk, PinName rx_sda, PinName rx_ws) |
d_worrall | 0:bb2411673898 | 35 | : mAddr(addr), mI2c_(sda, scl), mI2s_(tx_sda, tx_ws, clk, rx_sda, rx_ws){ |
d_worrall | 0:bb2411673898 | 36 | mI2c_.frequency(150000); |
d_worrall | 0:bb2411673898 | 37 | reset(); //TLV resets |
d_worrall | 0:bb2411673898 | 38 | power(0x07); //Power Up the TLV320, but not the MIC, ADC and LINE |
d_worrall | 0:bb2411673898 | 39 | format(16, STEREO); //16Bit I2S protocol format, STEREO |
d_worrall | 0:bb2411673898 | 40 | frequency(44100); //Default sample frequency is 44.1kHz |
d_worrall | 0:bb2411673898 | 41 | bypass(false); //Do not bypass device |
d_worrall | 0:bb2411673898 | 42 | mute(false); //Not muted |
d_worrall | 0:bb2411673898 | 43 | activateDigitalInterface_(); //The digital part of the chip is active |
d_worrall | 0:bb2411673898 | 44 | outputVolume(0.7, 0.7); //Headphone volume to the default state |
d_worrall | 0:bb2411673898 | 45 | rxBuffer = &mI2s_.rxBuffer[0]; |
d_worrall | 0:bb2411673898 | 46 | } |
d_worrall | 0:bb2411673898 | 47 | //Public Functions |
d_worrall | 0:bb2411673898 | 48 | /****************************************************** |
d_worrall | 0:bb2411673898 | 49 | * Function name: inputVolume() |
d_worrall | 0:bb2411673898 | 50 | * |
d_worrall | 0:bb2411673898 | 51 | * Description: set line in volume for left and right channels |
d_worrall | 0:bb2411673898 | 52 | * |
d_worrall | 0:bb2411673898 | 53 | * Parameters: float leftVolumeIn, float rightVolumeIn |
d_worrall | 0:bb2411673898 | 54 | * Returns: int 0 (success), -1 (value out of range) |
d_worrall | 0:bb2411673898 | 55 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 56 | int TLV320::inputVolume(float leftVolumeIn, float rightVolumeIn){ |
d_worrall | 0:bb2411673898 | 57 | //check values are in range |
d_worrall | 0:bb2411673898 | 58 | if((leftVolumeIn < 0.0)||leftVolumeIn > 1.0) return -1; |
d_worrall | 0:bb2411673898 | 59 | if((rightVolumeIn < 0.0)||rightVolumeIn > 1.0) return -1; |
d_worrall | 0:bb2411673898 | 60 | //convert float to encoded char |
d_worrall | 0:bb2411673898 | 61 | char left = (char)31*leftVolumeIn; |
d_worrall | 0:bb2411673898 | 62 | char right = (char)31*rightVolumeIn; |
d_worrall | 0:bb2411673898 | 63 | //Left Channel |
d_worrall | 0:bb2411673898 | 64 | cmd[1] = left | (0 << 7); //set volume |
d_worrall | 0:bb2411673898 | 65 | cmd[0] = LEFT_LINE_INPUT_CHANNEL_VOLUME_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 66 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 67 | //Right Channel |
d_worrall | 0:bb2411673898 | 68 | cmd[1] = right | (0 << 7); //set volume |
d_worrall | 0:bb2411673898 | 69 | cmd[0] = RIGHT_LINE_INPUT_CHANNEL_VOLUME_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 70 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 71 | return 0; |
d_worrall | 0:bb2411673898 | 72 | } |
d_worrall | 0:bb2411673898 | 73 | /****************************************************** |
d_worrall | 0:bb2411673898 | 74 | * Function name: outputVolume() |
d_worrall | 0:bb2411673898 | 75 | * |
d_worrall | 0:bb2411673898 | 76 | * Description: Set headphone (line out) volume for left an right channels |
d_worrall | 0:bb2411673898 | 77 | * |
d_worrall | 0:bb2411673898 | 78 | * Parameters: float leftVolumeOut, float rightVolumeOut |
d_worrall | 0:bb2411673898 | 79 | * Returns: int 0 (success), -1 (value out of range) |
d_worrall | 0:bb2411673898 | 80 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 81 | int TLV320::outputVolume(float leftVolumeOut, float rightVolumeOut){ |
d_worrall | 0:bb2411673898 | 82 | //check values are in range |
d_worrall | 0:bb2411673898 | 83 | if((leftVolumeOut < 0.0)||leftVolumeOut > 1.0) return -1; |
d_worrall | 0:bb2411673898 | 84 | if((rightVolumeOut < 0.0)||rightVolumeOut > 1.0) return -1; |
d_worrall | 0:bb2411673898 | 85 | //convert float to encoded char |
d_worrall | 0:bb2411673898 | 86 | char left = (char)(79*leftVolumeOut)+0x30; |
d_worrall | 0:bb2411673898 | 87 | char right = (char)(79*rightVolumeOut)+0x30; |
d_worrall | 0:bb2411673898 | 88 | //Left Channel |
d_worrall | 0:bb2411673898 | 89 | cmd[1] = left | (1 << 7); //set volume |
d_worrall | 0:bb2411673898 | 90 | cmd[0] = LEFT_CHANNEL_HEADPHONE_VOLUME_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 91 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 92 | //Right Channel |
d_worrall | 0:bb2411673898 | 93 | cmd[1] = right | (1 << 7); //set volume |
d_worrall | 0:bb2411673898 | 94 | cmd[0] = RIGHT_CHANNEL_HEADPHONE_VOLUME_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 95 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 96 | return 0; |
d_worrall | 0:bb2411673898 | 97 | } |
d_worrall | 0:bb2411673898 | 98 | /****************************************************** |
d_worrall | 0:bb2411673898 | 99 | * Function name: bypass() |
d_worrall | 0:bb2411673898 | 100 | * |
d_worrall | 0:bb2411673898 | 101 | * Description: Send TLV320 into bypass mode, i.e. connect input to output |
d_worrall | 0:bb2411673898 | 102 | * |
d_worrall | 0:bb2411673898 | 103 | * Parameters: bool bypassVar |
d_worrall | 0:bb2411673898 | 104 | * Returns: none |
d_worrall | 0:bb2411673898 | 105 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 106 | void TLV320::bypass(bool bypassVar){ |
d_worrall | 0:bb2411673898 | 107 | if(bypassVar == true) |
d_worrall | 0:bb2411673898 | 108 | cmd[1] = (1 << 3) | (0 << 4) | (0 << 5);//bypass enabled, DAC disabled, sidetone insertion disabled |
d_worrall | 0:bb2411673898 | 109 | else |
d_worrall | 0:bb2411673898 | 110 | cmd[1] = (0 << 3) | (1 << 4); //bypass disabled, DAC enabled |
d_worrall | 0:bb2411673898 | 111 | cmd[1] |= (0 << 2); |
d_worrall | 0:bb2411673898 | 112 | cmd[0] = ANALOG_AUDIO_PATH_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 113 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 114 | } |
d_worrall | 0:bb2411673898 | 115 | /****************************************************** |
d_worrall | 0:bb2411673898 | 116 | * Function name: mute() |
d_worrall | 0:bb2411673898 | 117 | * |
d_worrall | 0:bb2411673898 | 118 | * Description: Send TLV320 into mute mode |
d_worrall | 0:bb2411673898 | 119 | * |
d_worrall | 0:bb2411673898 | 120 | * Parameters: bool softMute |
d_worrall | 0:bb2411673898 | 121 | * Returns: none |
d_worrall | 0:bb2411673898 | 122 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 123 | void TLV320::mute(bool softMute){ |
d_worrall | 0:bb2411673898 | 124 | if(softMute == true) cmd[1] = 0x08; //set instruction to mute |
d_worrall | 0:bb2411673898 | 125 | else cmd[1] = 0x00; //set instruction to NOT mute |
d_worrall | 0:bb2411673898 | 126 | |
d_worrall | 0:bb2411673898 | 127 | cmd[0] = DIGITAL_AUDIO_PATH_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 128 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 129 | } |
d_worrall | 0:bb2411673898 | 130 | /****************************************************** |
d_worrall | 0:bb2411673898 | 131 | * Function name: power() |
d_worrall | 0:bb2411673898 | 132 | * |
d_worrall | 0:bb2411673898 | 133 | * Description: Switch TLV320 on/off |
d_worrall | 0:bb2411673898 | 134 | * |
d_worrall | 0:bb2411673898 | 135 | * Parameters: bool powerUp |
d_worrall | 0:bb2411673898 | 136 | * Returns: none |
d_worrall | 0:bb2411673898 | 137 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 138 | void TLV320::power(bool powerUp){ |
d_worrall | 0:bb2411673898 | 139 | if(powerUp == true) cmd[1] = 0x00; //everything on |
d_worrall | 0:bb2411673898 | 140 | else cmd[1] = 0xFF; //everything off |
d_worrall | 0:bb2411673898 | 141 | |
d_worrall | 0:bb2411673898 | 142 | cmd[0] = POWER_DOWN_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 143 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 144 | } |
d_worrall | 0:bb2411673898 | 145 | /****************************************************** |
d_worrall | 0:bb2411673898 | 146 | * Function name: power() |
d_worrall | 0:bb2411673898 | 147 | * |
d_worrall | 0:bb2411673898 | 148 | * Description: Switch on individual devices on TLV320 |
d_worrall | 0:bb2411673898 | 149 | * |
d_worrall | 0:bb2411673898 | 150 | * Parameters: int device |
d_worrall | 0:bb2411673898 | 151 | * Returns: none |
d_worrall | 0:bb2411673898 | 152 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 153 | void TLV320::power(int device){ |
d_worrall | 0:bb2411673898 | 154 | cmd[1] = (char)device; //set user defined commands |
d_worrall | 0:bb2411673898 | 155 | cmd[0] = POWER_DOWN_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 156 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 157 | } |
d_worrall | 0:bb2411673898 | 158 | /****************************************************** |
d_worrall | 0:bb2411673898 | 159 | * Function name: format() |
d_worrall | 0:bb2411673898 | 160 | * |
d_worrall | 0:bb2411673898 | 161 | * Description: Set interface format |
d_worrall | 0:bb2411673898 | 162 | * |
d_worrall | 0:bb2411673898 | 163 | * Parameters: char length, bool mode |
d_worrall | 0:bb2411673898 | 164 | * Returns: none |
d_worrall | 0:bb2411673898 | 165 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 166 | void TLV320::format(char length, bool mode){ |
d_worrall | 0:bb2411673898 | 167 | char modeSet = (1 << 6); |
d_worrall | 0:bb2411673898 | 168 | modeSet |= (1 << 5); //swap left and right channels |
d_worrall | 0:bb2411673898 | 169 | |
d_worrall | 0:bb2411673898 | 170 | switch (length) //input data into instruction byte |
d_worrall | 0:bb2411673898 | 171 | { |
d_worrall | 0:bb2411673898 | 172 | case 16: |
d_worrall | 0:bb2411673898 | 173 | cmd[1] = modeSet | 0x02; |
d_worrall | 0:bb2411673898 | 174 | break; |
d_worrall | 0:bb2411673898 | 175 | case 20: |
d_worrall | 0:bb2411673898 | 176 | cmd[1] = modeSet | 0x06; |
d_worrall | 0:bb2411673898 | 177 | break; |
d_worrall | 0:bb2411673898 | 178 | case 24: |
d_worrall | 0:bb2411673898 | 179 | cmd[1] = modeSet | 0x0A; |
d_worrall | 0:bb2411673898 | 180 | break; |
d_worrall | 0:bb2411673898 | 181 | case 32: |
d_worrall | 0:bb2411673898 | 182 | cmd[1] = modeSet | 0x0E; |
d_worrall | 0:bb2411673898 | 183 | break; |
d_worrall | 0:bb2411673898 | 184 | default: |
d_worrall | 0:bb2411673898 | 185 | break; |
d_worrall | 0:bb2411673898 | 186 | } |
d_worrall | 0:bb2411673898 | 187 | mI2s_.format(length, mode); |
d_worrall | 0:bb2411673898 | 188 | cmd[0] = DIGITAL_AUDIO_INTERFACE_FORMAT; //set address |
d_worrall | 0:bb2411673898 | 189 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 190 | } |
d_worrall | 0:bb2411673898 | 191 | /****************************************************** |
d_worrall | 0:bb2411673898 | 192 | * Function name: frequency() |
d_worrall | 0:bb2411673898 | 193 | * |
d_worrall | 0:bb2411673898 | 194 | * Description: Set sample frequency |
d_worrall | 0:bb2411673898 | 195 | * |
d_worrall | 0:bb2411673898 | 196 | * Parameters: int hz |
d_worrall | 0:bb2411673898 | 197 | * Returns: int 0 (success), -1 (value not recognised) |
d_worrall | 0:bb2411673898 | 198 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 199 | int TLV320::frequency(int hz){ |
d_worrall | 0:bb2411673898 | 200 | char rate; |
d_worrall | 0:bb2411673898 | 201 | switch(hz){ |
d_worrall | 0:bb2411673898 | 202 | case 8000: |
d_worrall | 0:bb2411673898 | 203 | rate = 0x03; |
d_worrall | 0:bb2411673898 | 204 | break; |
d_worrall | 0:bb2411673898 | 205 | case 8021: |
d_worrall | 0:bb2411673898 | 206 | rate = 0x0B; |
d_worrall | 0:bb2411673898 | 207 | break; |
d_worrall | 0:bb2411673898 | 208 | case 32000: |
d_worrall | 0:bb2411673898 | 209 | rate = 0x06; |
d_worrall | 0:bb2411673898 | 210 | break; |
d_worrall | 0:bb2411673898 | 211 | case 44100: |
d_worrall | 0:bb2411673898 | 212 | rate = 0x08; |
d_worrall | 0:bb2411673898 | 213 | break; |
d_worrall | 0:bb2411673898 | 214 | case 48000: |
d_worrall | 0:bb2411673898 | 215 | rate = 0x00; |
d_worrall | 0:bb2411673898 | 216 | break; |
d_worrall | 0:bb2411673898 | 217 | case 88200: |
d_worrall | 0:bb2411673898 | 218 | rate = 0x0F; |
d_worrall | 0:bb2411673898 | 219 | break; |
d_worrall | 0:bb2411673898 | 220 | case 96000: |
d_worrall | 0:bb2411673898 | 221 | rate = 0x07; |
d_worrall | 0:bb2411673898 | 222 | break; |
d_worrall | 0:bb2411673898 | 223 | default: |
d_worrall | 0:bb2411673898 | 224 | return -1; |
d_worrall | 0:bb2411673898 | 225 | } |
d_worrall | 0:bb2411673898 | 226 | char clockInChar = (0 << 6); |
d_worrall | 0:bb2411673898 | 227 | char clockModeChar = (1 << 0); |
d_worrall | 0:bb2411673898 | 228 | |
d_worrall | 0:bb2411673898 | 229 | cmd[1] = (rate << 2) | clockInChar | clockModeChar; //input data into instruciton byte |
d_worrall | 0:bb2411673898 | 230 | cmd[0] = SAMPLE_RATE_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 231 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 232 | return 0; |
d_worrall | 0:bb2411673898 | 233 | } |
d_worrall | 0:bb2411673898 | 234 | /****************************************************** |
d_worrall | 0:bb2411673898 | 235 | * Function name: reset() |
d_worrall | 0:bb2411673898 | 236 | * |
d_worrall | 0:bb2411673898 | 237 | * Description: Reset TLV320 |
d_worrall | 0:bb2411673898 | 238 | * |
d_worrall | 0:bb2411673898 | 239 | * Parameters: none |
d_worrall | 0:bb2411673898 | 240 | * Returns: none |
d_worrall | 0:bb2411673898 | 241 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 242 | void TLV320::reset(void){ |
d_worrall | 0:bb2411673898 | 243 | cmd[0] = RESET_REGISTER; //set address |
d_worrall | 0:bb2411673898 | 244 | cmd[1] = 0x00; //this resets the entire device |
d_worrall | 0:bb2411673898 | 245 | mI2c_.write(mAddr, cmd, 2); |
d_worrall | 0:bb2411673898 | 246 | } |
d_worrall | 0:bb2411673898 | 247 | /****************************************************** |
d_worrall | 0:bb2411673898 | 248 | * Function name: start() |
d_worrall | 0:bb2411673898 | 249 | * |
d_worrall | 0:bb2411673898 | 250 | * Description: Enable interrupts on the I2S port |
d_worrall | 0:bb2411673898 | 251 | * |
d_worrall | 0:bb2411673898 | 252 | * Parameters: int mode |
d_worrall | 0:bb2411673898 | 253 | * Returns: none |
d_worrall | 0:bb2411673898 | 254 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 255 | void TLV320::start(int mode){ |
d_worrall | 0:bb2411673898 | 256 | mI2s_.start(mode); |
d_worrall | 0:bb2411673898 | 257 | } |
d_worrall | 0:bb2411673898 | 258 | /****************************************************** |
d_worrall | 0:bb2411673898 | 259 | * Function name: stop() |
d_worrall | 0:bb2411673898 | 260 | * |
d_worrall | 0:bb2411673898 | 261 | * Description: Disable interrupts on the I2S port |
d_worrall | 0:bb2411673898 | 262 | * |
d_worrall | 0:bb2411673898 | 263 | * Parameters: none |
d_worrall | 0:bb2411673898 | 264 | * Returns: none |
d_worrall | 0:bb2411673898 | 265 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 266 | void TLV320::stop(void){ |
d_worrall | 0:bb2411673898 | 267 | mI2s_.stop(); |
d_worrall | 0:bb2411673898 | 268 | } |
d_worrall | 0:bb2411673898 | 269 | /****************************************************** |
d_worrall | 0:bb2411673898 | 270 | * Function name: write() |
d_worrall | 0:bb2411673898 | 271 | * |
d_worrall | 0:bb2411673898 | 272 | * Description: Write (part of) a buffer to the I2S port |
d_worrall | 0:bb2411673898 | 273 | * |
d_worrall | 0:bb2411673898 | 274 | * Parameters: int *buffer, int from, int length |
d_worrall | 0:bb2411673898 | 275 | * Returns: none |
d_worrall | 0:bb2411673898 | 276 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 277 | void TLV320::write(int *buffer, int from, int length){ |
d_worrall | 0:bb2411673898 | 278 | mI2s_.write(buffer, from, length); |
d_worrall | 0:bb2411673898 | 279 | } |
d_worrall | 0:bb2411673898 | 280 | /****************************************************** |
d_worrall | 0:bb2411673898 | 281 | * Function name: read() |
d_worrall | 0:bb2411673898 | 282 | * |
d_worrall | 0:bb2411673898 | 283 | * Description: Place I2SRXFIFO in rxBuffer |
d_worrall | 0:bb2411673898 | 284 | * |
d_worrall | 0:bb2411673898 | 285 | * Parameters: none |
d_worrall | 0:bb2411673898 | 286 | * Returns: none |
d_worrall | 0:bb2411673898 | 287 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 288 | void TLV320::read(void){ |
d_worrall | 0:bb2411673898 | 289 | mI2s_.read(); |
d_worrall | 0:bb2411673898 | 290 | } |
d_worrall | 0:bb2411673898 | 291 | /****************************************************** |
d_worrall | 0:bb2411673898 | 292 | * Function name: attach() |
d_worrall | 0:bb2411673898 | 293 | * |
d_worrall | 0:bb2411673898 | 294 | * Description: Attach a void/void function or void/void static member function to IRQHandler |
d_worrall | 0:bb2411673898 | 295 | * |
d_worrall | 0:bb2411673898 | 296 | * Parameters: none |
d_worrall | 0:bb2411673898 | 297 | * Returns: none |
d_worrall | 0:bb2411673898 | 298 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 299 | void TLV320::attach(void(*fptr)(void)){ |
d_worrall | 0:bb2411673898 | 300 | mI2s_.attach(fptr); |
d_worrall | 0:bb2411673898 | 301 | } |
d_worrall | 0:bb2411673898 | 302 | //Private Functions |
d_worrall | 0:bb2411673898 | 303 | /****************************************************** |
d_worrall | 0:bb2411673898 | 304 | * Function name: setSampleRate_() |
d_worrall | 0:bb2411673898 | 305 | * |
d_worrall | 0:bb2411673898 | 306 | * Description: Clocking control |
d_worrall | 0:bb2411673898 | 307 | * |
d_worrall | 0:bb2411673898 | 308 | * Parameters: char rate, bool clockIn, bool clockMode, bool bOSR |
d_worrall | 0:bb2411673898 | 309 | * Returns: none |
d_worrall | 0:bb2411673898 | 310 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 311 | void TLV320::setSampleRate_(char rate, bool clockIn, bool clockMode, bool bOSR){ |
d_worrall | 0:bb2411673898 | 312 | char clockInChar; |
d_worrall | 0:bb2411673898 | 313 | char clockModeChar; |
d_worrall | 0:bb2411673898 | 314 | char baseOverSamplingRate; |
d_worrall | 0:bb2411673898 | 315 | if(bOSR){ |
d_worrall | 0:bb2411673898 | 316 | baseOverSamplingRate = (1 << 0); |
d_worrall | 0:bb2411673898 | 317 | } else { |
d_worrall | 0:bb2411673898 | 318 | baseOverSamplingRate = (0 << 0); |
d_worrall | 0:bb2411673898 | 319 | } |
d_worrall | 0:bb2411673898 | 320 | if(clockIn){ |
d_worrall | 0:bb2411673898 | 321 | clockInChar = (1 << 6); |
d_worrall | 0:bb2411673898 | 322 | } else { |
d_worrall | 0:bb2411673898 | 323 | clockInChar = (0 << 6); |
d_worrall | 0:bb2411673898 | 324 | } |
d_worrall | 0:bb2411673898 | 325 | if(clockMode){ |
d_worrall | 0:bb2411673898 | 326 | clockModeChar = 0x01; |
d_worrall | 0:bb2411673898 | 327 | } else { |
d_worrall | 0:bb2411673898 | 328 | clockModeChar = 0x00; |
d_worrall | 0:bb2411673898 | 329 | } |
d_worrall | 0:bb2411673898 | 330 | cmd[1] = (rate << 2) | clockInChar | clockModeChar | baseOverSamplingRate; //input data into instruciton byte |
d_worrall | 0:bb2411673898 | 331 | cmd[0] = SAMPLE_RATE_CONTROL; //set address |
d_worrall | 0:bb2411673898 | 332 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 333 | } |
d_worrall | 0:bb2411673898 | 334 | /****************************************************** |
d_worrall | 0:bb2411673898 | 335 | * Function name: activateDigitalInterface_() |
d_worrall | 0:bb2411673898 | 336 | * |
d_worrall | 0:bb2411673898 | 337 | * Description: Activate digital part of chip |
d_worrall | 0:bb2411673898 | 338 | * |
d_worrall | 0:bb2411673898 | 339 | * Parameters: none |
d_worrall | 0:bb2411673898 | 340 | * Returns: none |
d_worrall | 0:bb2411673898 | 341 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 342 | void TLV320::activateDigitalInterface_(void){ |
d_worrall | 0:bb2411673898 | 343 | cmd[1] = 0x01; //Activate |
d_worrall | 0:bb2411673898 | 344 | cmd[0] = DIGITAL_INTERFACE_ACTIVATION; //set address |
d_worrall | 0:bb2411673898 | 345 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 346 | } |
d_worrall | 0:bb2411673898 | 347 | /****************************************************** |
d_worrall | 0:bb2411673898 | 348 | * Function name: deactivateDigitalInterface_ |
d_worrall | 0:bb2411673898 | 349 | * |
d_worrall | 0:bb2411673898 | 350 | * Description: Deactivate digital part of chip |
d_worrall | 0:bb2411673898 | 351 | * |
d_worrall | 0:bb2411673898 | 352 | * Parameters: none |
d_worrall | 0:bb2411673898 | 353 | * Returns: none |
d_worrall | 0:bb2411673898 | 354 | ******************************************************/ |
d_worrall | 0:bb2411673898 | 355 | //Digital interface deactivation |
d_worrall | 0:bb2411673898 | 356 | void TLV320::deactivateDigitalInterface_(void){ |
d_worrall | 0:bb2411673898 | 357 | cmd[1] = 0x00; //Deactivate |
d_worrall | 0:bb2411673898 | 358 | cmd[0] = DIGITAL_INTERFACE_ACTIVATION; //set address |
d_worrall | 0:bb2411673898 | 359 | mI2c_.write(mAddr, cmd, 2); //send |
d_worrall | 0:bb2411673898 | 360 | } |
d_worrall | 0:bb2411673898 | 361 |