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.h@0:bb2411673898, 2011-08-04 (annotated)
- Committer:
- d_worrall
- Date:
- Thu Aug 04 15:04:59 2011 +0000
- Revision:
- 0:bb2411673898
- Child:
- 1:7e76c6f56169
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 | #ifndef MBED_TLV320_H |
d_worrall | 0:bb2411673898 | 32 | #define MBED_TLV320_H |
d_worrall | 0:bb2411673898 | 33 | |
d_worrall | 0:bb2411673898 | 34 | #include "mbed.h" |
d_worrall | 0:bb2411673898 | 35 | #include "I2SSlave.h" |
d_worrall | 0:bb2411673898 | 36 | |
d_worrall | 0:bb2411673898 | 37 | /** TLV320 class, defined on the I2C master bus |
d_worrall | 0:bb2411673898 | 38 | * |
d_worrall | 0:bb2411673898 | 39 | */ |
d_worrall | 0:bb2411673898 | 40 | |
d_worrall | 0:bb2411673898 | 41 | class TLV320 |
d_worrall | 0:bb2411673898 | 42 | { |
d_worrall | 0:bb2411673898 | 43 | public: |
d_worrall | 0:bb2411673898 | 44 | //constructor |
d_worrall | 0:bb2411673898 | 45 | /** Create a TLV320 object defined on the I2C port |
d_worrall | 0:bb2411673898 | 46 | * |
d_worrall | 0:bb2411673898 | 47 | * @param sda Serial data pin (p9 or p28) |
d_worrall | 0:bb2411673898 | 48 | * @param scl Serial clock pin (p10 or p27) |
d_worrall | 0:bb2411673898 | 49 | * @param addr Object address |
d_worrall | 0:bb2411673898 | 50 | */ |
d_worrall | 0:bb2411673898 | 51 | 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 | 52 | /** Power up/down |
d_worrall | 0:bb2411673898 | 53 | * |
d_worrall | 0:bb2411673898 | 54 | * @param powerUp 0 = power down, 1 = power up |
d_worrall | 0:bb2411673898 | 55 | */ |
d_worrall | 0:bb2411673898 | 56 | void power(bool powerUp); |
d_worrall | 0:bb2411673898 | 57 | /** Overloaded power() function default = 0x07, record requires 0x02 |
d_worrall | 0:bb2411673898 | 58 | * |
d_worrall | 0:bb2411673898 | 59 | * @param device Call individual devices to power up/down |
d_worrall | 0:bb2411673898 | 60 | * Device power 0x00 = On 0x80 = Off |
d_worrall | 0:bb2411673898 | 61 | * Clock 0x00 = On 0x40 = Off |
d_worrall | 0:bb2411673898 | 62 | * Oscillator 0x00 = On 0x20 = Off |
d_worrall | 0:bb2411673898 | 63 | * Outputs 0x00 = On 0x10 = Off |
d_worrall | 0:bb2411673898 | 64 | * DAC 0x00 = On 0x08 = Off |
d_worrall | 0:bb2411673898 | 65 | * ADC 0x00 = On 0x04 = Off |
d_worrall | 0:bb2411673898 | 66 | * Microphone input 0x00 = On 0x02 = Off |
d_worrall | 0:bb2411673898 | 67 | * Line input 0x00 = On 0x01 = Off |
d_worrall | 0:bb2411673898 | 68 | */ |
d_worrall | 0:bb2411673898 | 69 | void power(int device); |
d_worrall | 0:bb2411673898 | 70 | /** Set I2S interface bit length and mode |
d_worrall | 0:bb2411673898 | 71 | * |
d_worrall | 0:bb2411673898 | 72 | * @param length Set bit length to 16, 20, 24 or 32 bits |
d_worrall | 0:bb2411673898 | 73 | * @param mode Set STEREO (0), MONO (1) |
d_worrall | 0:bb2411673898 | 74 | */ |
d_worrall | 0:bb2411673898 | 75 | void format(char length, bool mode); |
d_worrall | 0:bb2411673898 | 76 | /** Set sample frequency |
d_worrall | 0:bb2411673898 | 77 | * |
d_worrall | 0:bb2411673898 | 78 | * @param frequency Sample frequency of data in Hz |
d_worrall | 0:bb2411673898 | 79 | * @return Returns an integer 0 = success, -1 = unrecognnised frequency |
d_worrall | 0:bb2411673898 | 80 | * |
d_worrall | 0:bb2411673898 | 81 | * The TLV320 supports the following frequencies: 8kHz, 8.021kHz, 32kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz |
d_worrall | 0:bb2411673898 | 82 | * Default is 44.1kHz |
d_worrall | 0:bb2411673898 | 83 | */ |
d_worrall | 0:bb2411673898 | 84 | int frequency(int hz); |
d_worrall | 0:bb2411673898 | 85 | /** Reset TLV320 |
d_worrall | 0:bb2411673898 | 86 | * |
d_worrall | 0:bb2411673898 | 87 | */ |
d_worrall | 0:bb2411673898 | 88 | void reset(void); |
d_worrall | 0:bb2411673898 | 89 | /** Start streaming i.e. enable interrupts |
d_worrall | 0:bb2411673898 | 90 | * |
d_worrall | 0:bb2411673898 | 91 | * @param mode Enable interrupts for NONE, TRANSMIT only, RECEIVE only, BOTH |
d_worrall | 0:bb2411673898 | 92 | */ |
d_worrall | 0:bb2411673898 | 93 | void start(int mode); |
d_worrall | 0:bb2411673898 | 94 | /** Stop streaming i.e. disable all interrupts |
d_worrall | 0:bb2411673898 | 95 | * |
d_worrall | 0:bb2411673898 | 96 | */ |
d_worrall | 0:bb2411673898 | 97 | void stop(void); |
d_worrall | 0:bb2411673898 | 98 | /** Write [length] 32 bit words in buffer to I2S port |
d_worrall | 0:bb2411673898 | 99 | * |
d_worrall | 0:bb2411673898 | 100 | * @param *buffer Address of buffer to be written |
d_worrall | 0:bb2411673898 | 101 | * @param from Start position in buffer to read from |
d_worrall | 0:bb2411673898 | 102 | * @param length Number of words to be written (MUST not exceed 4) |
d_worrall | 0:bb2411673898 | 103 | */ |
d_worrall | 0:bb2411673898 | 104 | void write(int *buffer, int from, int length); |
d_worrall | 0:bb2411673898 | 105 | /** Read 4 x (32bit) words into rxBuffer |
d_worrall | 0:bb2411673898 | 106 | * |
d_worrall | 0:bb2411673898 | 107 | */ |
d_worrall | 0:bb2411673898 | 108 | void read(void); |
d_worrall | 0:bb2411673898 | 109 | /** Attach a void/void function or void/void static member funciton to an interrupt generated by the I2SxxFIFOs |
d_worrall | 0:bb2411673898 | 110 | * |
d_worrall | 0:bb2411673898 | 111 | * @param function Function to attach |
d_worrall | 0:bb2411673898 | 112 | * |
d_worrall | 0:bb2411673898 | 113 | * e.g. myTlv320Object.attach(&myfunction); |
d_worrall | 0:bb2411673898 | 114 | * OR myTlv320Object.attach(&myClass::myStaticMemberFunction); |
d_worrall | 0:bb2411673898 | 115 | */ |
d_worrall | 0:bb2411673898 | 116 | void attach(void(*fptr)(void)); |
d_worrall | 0:bb2411673898 | 117 | /** Attach a nonstatic void/void member function to an interrupt generated by the I2SxxFIFOs |
d_worrall | 0:bb2411673898 | 118 | * |
d_worrall | 0:bb2411673898 | 119 | * @param tptr Object pointer |
d_worrall | 0:bb2411673898 | 120 | * @param mptr Member function pointer |
d_worrall | 0:bb2411673898 | 121 | * |
d_worrall | 0:bb2411673898 | 122 | * e.g. myTlv320Object.attach(&myObject, &myClass::myNonstaticMemberFunction); where myObject is an object of myClass |
d_worrall | 0:bb2411673898 | 123 | */ |
d_worrall | 0:bb2411673898 | 124 | template<typename T> |
d_worrall | 0:bb2411673898 | 125 | void attach(T *tptr, void(T::*mptr)(void)){ |
d_worrall | 0:bb2411673898 | 126 | mI2s_.attach(tptr, mptr); |
d_worrall | 0:bb2411673898 | 127 | } |
d_worrall | 0:bb2411673898 | 128 | /** Line in volume control i.e. record volume |
d_worrall | 0:bb2411673898 | 129 | * |
d_worrall | 0:bb2411673898 | 130 | * @param leftVolumeIn Left line-in volume |
d_worrall | 0:bb2411673898 | 131 | * @param rightVolumeIn Right line-in volume |
d_worrall | 0:bb2411673898 | 132 | * @return Returns 0 for success, -1 if parameters are out of range |
d_worrall | 0:bb2411673898 | 133 | * Parameters accept a value, where 0.0 < parameter < 1.0 and where 0.0 maps to -34.5dB |
d_worrall | 0:bb2411673898 | 134 | * and 1.0 maps to +12dB (0.74 = 0 dB default). |
d_worrall | 0:bb2411673898 | 135 | */ |
d_worrall | 0:bb2411673898 | 136 | int inputVolume(float leftVolumeIn, float rightVolumeIn); |
d_worrall | 0:bb2411673898 | 137 | /** Headphone out volume control |
d_worrall | 0:bb2411673898 | 138 | * |
d_worrall | 0:bb2411673898 | 139 | * @param leftVolumeOut Left line-out volume |
d_worrall | 0:bb2411673898 | 140 | * @param rightVolumeOut Right line-out volume |
d_worrall | 0:bb2411673898 | 141 | * @return Returns 0 for success, -1 if parameters are out of range |
d_worrall | 0:bb2411673898 | 142 | * Parameters accept a value, where 0.0 < parameter < 1.0 and where 0.0 maps to -73dB (mute) |
d_worrall | 0:bb2411673898 | 143 | * and 1.0 maps to +6dB (0.5 = default) |
d_worrall | 0:bb2411673898 | 144 | */ |
d_worrall | 0:bb2411673898 | 145 | int outputVolume(float leftVolumeOut, float rightVolumeOut); |
d_worrall | 0:bb2411673898 | 146 | /** Analog audio path control |
d_worrall | 0:bb2411673898 | 147 | * |
d_worrall | 0:bb2411673898 | 148 | * @param bypassVar Route analogue audio direct from line in to headphone out |
d_worrall | 0:bb2411673898 | 149 | */ |
d_worrall | 0:bb2411673898 | 150 | void bypass(bool bypassVar); |
d_worrall | 0:bb2411673898 | 151 | /**Digital audio path control |
d_worrall | 0:bb2411673898 | 152 | * |
d_worrall | 0:bb2411673898 | 153 | * @param softMute Mute output |
d_worrall | 0:bb2411673898 | 154 | */ |
d_worrall | 0:bb2411673898 | 155 | void mute(bool softMute); |
d_worrall | 0:bb2411673898 | 156 | //Receive buffer |
d_worrall | 0:bb2411673898 | 157 | |
d_worrall | 0:bb2411673898 | 158 | int *rxBuffer; |
d_worrall | 0:bb2411673898 | 159 | |
d_worrall | 0:bb2411673898 | 160 | protected: |
d_worrall | 0:bb2411673898 | 161 | char cmd[2]; //the address and command for TLV320 internal registers |
d_worrall | 0:bb2411673898 | 162 | int mAddr; //register write address |
d_worrall | 0:bb2411673898 | 163 | private: |
d_worrall | 0:bb2411673898 | 164 | I2C mI2c_; //MUST use the I2C port |
d_worrall | 0:bb2411673898 | 165 | I2SSlave mI2s_; |
d_worrall | 0:bb2411673898 | 166 | Ticker I2sTick; |
d_worrall | 0:bb2411673898 | 167 | void io(void); |
d_worrall | 0:bb2411673898 | 168 | /** Sample rate control |
d_worrall | 0:bb2411673898 | 169 | * |
d_worrall | 0:bb2411673898 | 170 | * @param rate Set the sampling rate as per datasheet section 3.3.2 |
d_worrall | 0:bb2411673898 | 171 | * @param clockIn Set the clock in divider MCLK, MCLK_DIV2 |
d_worrall | 0:bb2411673898 | 172 | * @param clockMode Set clock mode CLOCK_NORMAL, CLOCK_USB |
d_worrall | 0:bb2411673898 | 173 | */ |
d_worrall | 0:bb2411673898 | 174 | void setSampleRate_(char rate, bool clockIn, bool mode, bool bOSR); |
d_worrall | 0:bb2411673898 | 175 | /** Digital interface activation |
d_worrall | 0:bb2411673898 | 176 | * |
d_worrall | 0:bb2411673898 | 177 | */ |
d_worrall | 0:bb2411673898 | 178 | void activateDigitalInterface_(void); |
d_worrall | 0:bb2411673898 | 179 | /** Digital interface deactivation |
d_worrall | 0:bb2411673898 | 180 | * |
d_worrall | 0:bb2411673898 | 181 | */ |
d_worrall | 0:bb2411673898 | 182 | void deactivateDigitalInterface_(void); |
d_worrall | 0:bb2411673898 | 183 | |
d_worrall | 0:bb2411673898 | 184 | //TLV320AIC23B register addresses as defined in the TLV320AIC23B datasheet |
d_worrall | 0:bb2411673898 | 185 | #define LEFT_LINE_INPUT_CHANNEL_VOLUME_CONTROL (0x00 << 1) |
d_worrall | 0:bb2411673898 | 186 | #define RIGHT_LINE_INPUT_CHANNEL_VOLUME_CONTROL (0x01 << 1) |
d_worrall | 0:bb2411673898 | 187 | #define LEFT_CHANNEL_HEADPHONE_VOLUME_CONTROL (0x02 << 1) |
d_worrall | 0:bb2411673898 | 188 | #define RIGHT_CHANNEL_HEADPHONE_VOLUME_CONTROL (0x03 << 1) |
d_worrall | 0:bb2411673898 | 189 | #define ANALOG_AUDIO_PATH_CONTROL (0x04 << 1) |
d_worrall | 0:bb2411673898 | 190 | #define DIGITAL_AUDIO_PATH_CONTROL (0x05 << 1) |
d_worrall | 0:bb2411673898 | 191 | #define POWER_DOWN_CONTROL (0x06 << 1) |
d_worrall | 0:bb2411673898 | 192 | #define DIGITAL_AUDIO_INTERFACE_FORMAT (0x07 << 1) |
d_worrall | 0:bb2411673898 | 193 | #define SAMPLE_RATE_CONTROL (0x08 << 1) |
d_worrall | 0:bb2411673898 | 194 | #define DIGITAL_INTERFACE_ACTIVATION (0x09 << 1) |
d_worrall | 0:bb2411673898 | 195 | #define RESET_REGISTER (0x0F << 1) |
d_worrall | 0:bb2411673898 | 196 | |
d_worrall | 0:bb2411673898 | 197 | #define CLOCK_NORMAL 0 |
d_worrall | 0:bb2411673898 | 198 | #define CLOCK_USB 1 |
d_worrall | 0:bb2411673898 | 199 | #define MCLK 0 |
d_worrall | 0:bb2411673898 | 200 | #define MCLK_DIV2 1 |
d_worrall | 0:bb2411673898 | 201 | }; |
d_worrall | 0:bb2411673898 | 202 | |
d_worrall | 0:bb2411673898 | 203 | #endif |