More readable TLV320 Lib

Dependents:   TalkThrough

Committer:
hollegha
Date:
Wed Oct 22 09:23:47 2014 +0000
Revision:
0:808bb0b9cf45
More readable TLV320-Lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha 0:808bb0b9cf45 1
hollegha 0:808bb0b9cf45 2 #ifndef MBED_TLV320_H
hollegha 0:808bb0b9cf45 3 #define MBED_TLV320_H
hollegha 0:808bb0b9cf45 4
hollegha 0:808bb0b9cf45 5 #include "mbed.h"
hollegha 0:808bb0b9cf45 6 #include "I2SSlaveHL.h"
hollegha 0:808bb0b9cf45 7
hollegha 0:808bb0b9cf45 8 class TLV320 {
hollegha 0:808bb0b9cf45 9 public:
hollegha 0:808bb0b9cf45 10 // sda Serial data pin (p9 or p28)
hollegha 0:808bb0b9cf45 11 // scl Serial clock pin (p10 or p27)
hollegha 0:808bb0b9cf45 12 // addr Object address
hollegha 0:808bb0b9cf45 13 TLV320(PinName sda, PinName scl, int addr, I2SSlave* aI2S);
hollegha 0:808bb0b9cf45 14
hollegha 0:808bb0b9cf45 15 void Init(int aFrequ);
hollegha 0:808bb0b9cf45 16
hollegha 0:808bb0b9cf45 17 // 0 = power down, 1 = power up
hollegha 0:808bb0b9cf45 18 void power(bool powerUp);
hollegha 0:808bb0b9cf45 19
hollegha 0:808bb0b9cf45 20 /** Overloaded power() function default = 0x07, record requires 0x02
hollegha 0:808bb0b9cf45 21 * @param device Call individual devices to power up/down
hollegha 0:808bb0b9cf45 22 * Device power 0x00 = On 0x80 = Off
hollegha 0:808bb0b9cf45 23 * Clock 0x00 = On 0x40 = Off
hollegha 0:808bb0b9cf45 24 * Oscillator 0x00 = On 0x20 = Off
hollegha 0:808bb0b9cf45 25 * Outputs 0x00 = On 0x10 = Off
hollegha 0:808bb0b9cf45 26 * DAC 0x00 = On 0x08 = Off
hollegha 0:808bb0b9cf45 27 * ADC 0x00 = On 0x04 = Off
hollegha 0:808bb0b9cf45 28 * Microphone input 0x00 = On 0x02 = Off
hollegha 0:808bb0b9cf45 29 * Line input 0x00 = On 0x01 = Off */
hollegha 0:808bb0b9cf45 30 void power(int device);
hollegha 0:808bb0b9cf45 31
hollegha 0:808bb0b9cf45 32 /** Set I2S interface bit length and mode
hollegha 0:808bb0b9cf45 33 * @param length Set bit length to 16, 20, 24 or 32 bits
hollegha 0:808bb0b9cf45 34 * @param mode Set STEREO (0), MONO (1) */
hollegha 0:808bb0b9cf45 35 void format(char length, bool mode);
hollegha 0:808bb0b9cf45 36
hollegha 0:808bb0b9cf45 37 // Returns an integer 0 = success, -1 = unrecognnised frequency
hollegha 0:808bb0b9cf45 38 // The TLV320 supports the following frequencies: 8kHz, 8.021kHz, 32kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz
hollegha 0:808bb0b9cf45 39 // Default is 44.1kHz
hollegha 0:808bb0b9cf45 40 int frequency(int hz);
hollegha 0:808bb0b9cf45 41
hollegha 0:808bb0b9cf45 42 // Reset TLV320
hollegha 0:808bb0b9cf45 43 void reset(void);
hollegha 0:808bb0b9cf45 44
hollegha 0:808bb0b9cf45 45 /** Line in volume control i.e. record volume
hollegha 0:808bb0b9cf45 46 * @return Returns 0 for success, -1 if parameters are out of range
hollegha 0:808bb0b9cf45 47 * Parameters accept a value, where 0.0 < parameter < 1.0 and where 0.0 maps to -34.5dB
hollegha 0:808bb0b9cf45 48 * and 1.0 maps to +12dB (0.74 = 0 dB default). */
hollegha 0:808bb0b9cf45 49 int inputVolume(float leftVolumeIn, float rightVolumeIn);
hollegha 0:808bb0b9cf45 50
hollegha 0:808bb0b9cf45 51 /** Headphone out volume control
hollegha 0:808bb0b9cf45 52 * @return Returns 0 for success, -1 if parameters are out of range
hollegha 0:808bb0b9cf45 53 * Parameters accept a value, where 0.0 < parameter < 1.0 and where 0.0 maps to -73dB (mute)
hollegha 0:808bb0b9cf45 54 * and 1.0 maps to +6dB (0.5 = default) */
hollegha 0:808bb0b9cf45 55 int outputVolume(float leftVolumeOut, float rightVolumeOut);
hollegha 0:808bb0b9cf45 56
hollegha 0:808bb0b9cf45 57 // Analog audio path control
hollegha 0:808bb0b9cf45 58 // @param bypassVar Route analogue audio direct from line in to headphone out
hollegha 0:808bb0b9cf45 59 void bypass(bool bypassVar);
hollegha 0:808bb0b9cf45 60
hollegha 0:808bb0b9cf45 61 // Digital audio path control
hollegha 0:808bb0b9cf45 62 // @param softMute Mute output
hollegha 0:808bb0b9cf45 63 void mute(bool softMute);
hollegha 0:808bb0b9cf45 64
hollegha 0:808bb0b9cf45 65 protected:
hollegha 0:808bb0b9cf45 66 char cmd[2]; //the address and command for TLV320 internal registers
hollegha 0:808bb0b9cf45 67 int mAddr; //register write address
hollegha 0:808bb0b9cf45 68 private:
hollegha 0:808bb0b9cf45 69 I2C mI2c_;
hollegha 0:808bb0b9cf45 70 I2SSlave* mI2S;
hollegha 0:808bb0b9cf45 71
hollegha 0:808bb0b9cf45 72 /** Sample rate control
hollegha 0:808bb0b9cf45 73 * @param rate Set the sampling rate as per datasheet section 3.3.2
hollegha 0:808bb0b9cf45 74 * @param clockIn Set the clock in divider MCLK, MCLK_DIV2
hollegha 0:808bb0b9cf45 75 * @param clockMode Set clock mode CLOCK_NORMAL, CLOCK_USB */
hollegha 0:808bb0b9cf45 76 void setSampleRate_(char rate, bool clockIn, bool mode, bool bOSR);
hollegha 0:808bb0b9cf45 77
hollegha 0:808bb0b9cf45 78 // Digital interface activation
hollegha 0:808bb0b9cf45 79 void activateDigitalInterface_(void);
hollegha 0:808bb0b9cf45 80
hollegha 0:808bb0b9cf45 81 // Digital interface deactivation
hollegha 0:808bb0b9cf45 82 void deactivateDigitalInterface_(void);
hollegha 0:808bb0b9cf45 83
hollegha 0:808bb0b9cf45 84 //TLV320AIC23B register addresses as defined in the TLV320AIC23B datasheet
hollegha 0:808bb0b9cf45 85 #define LEFT_LINE_INPUT_CHANNEL_VOLUME_CONTROL (0x00 << 1)
hollegha 0:808bb0b9cf45 86 #define RIGHT_LINE_INPUT_CHANNEL_VOLUME_CONTROL (0x01 << 1)
hollegha 0:808bb0b9cf45 87 #define LEFT_CHANNEL_HEADPHONE_VOLUME_CONTROL (0x02 << 1)
hollegha 0:808bb0b9cf45 88 #define RIGHT_CHANNEL_HEADPHONE_VOLUME_CONTROL (0x03 << 1)
hollegha 0:808bb0b9cf45 89 #define ANALOG_AUDIO_PATH_CONTROL (0x04 << 1)
hollegha 0:808bb0b9cf45 90 #define DIGITAL_AUDIO_PATH_CONTROL (0x05 << 1)
hollegha 0:808bb0b9cf45 91 #define POWER_DOWN_CONTROL (0x06 << 1)
hollegha 0:808bb0b9cf45 92 #define DIGITAL_AUDIO_INTERFACE_FORMAT (0x07 << 1)
hollegha 0:808bb0b9cf45 93 #define SAMPLE_RATE_CONTROL (0x08 << 1)
hollegha 0:808bb0b9cf45 94 #define DIGITAL_INTERFACE_ACTIVATION (0x09 << 1)
hollegha 0:808bb0b9cf45 95 #define RESET_REGISTER (0x0F << 1)
hollegha 0:808bb0b9cf45 96
hollegha 0:808bb0b9cf45 97 #define CLOCK_NORMAL 0
hollegha 0:808bb0b9cf45 98 #define CLOCK_USB 1
hollegha 0:808bb0b9cf45 99 #define MCLK 0
hollegha 0:808bb0b9cf45 100 #define MCLK_DIV2 1
hollegha 0:808bb0b9cf45 101 };
hollegha 0:808bb0b9cf45 102
hollegha 0:808bb0b9cf45 103 #endif
hollegha 0:808bb0b9cf45 104
hollegha 0:808bb0b9cf45 105