Device driver for TI TLV320AIC1110 voice band codec

Work in Progress

Committer:
sam_grove
Date:
Fri May 10 21:14:19 2013 +0000
Revision:
0:ec233f3b49d8
Child:
1:4d559df5733e
Child:
2:e7c7c0177dd8
Initial commit. Basic functionality. Untested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:ec233f3b49d8 1 /**
sam_grove 0:ec233f3b49d8 2 * @file TLV320AIC1110.cpp
sam_grove 0:ec233f3b49d8 3 * @brief Device driver - TLV320AIC1110 CODEC
sam_grove 0:ec233f3b49d8 4 * @author sam grove
sam_grove 0:ec233f3b49d8 5 * @version 1.0
sam_grove 0:ec233f3b49d8 6 * @see http://www.ti.com/product/tlv320aic1110
sam_grove 0:ec233f3b49d8 7 *
sam_grove 0:ec233f3b49d8 8 * Copyright (c) 2013
sam_grove 0:ec233f3b49d8 9 *
sam_grove 0:ec233f3b49d8 10 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:ec233f3b49d8 11 * you may not use this file except in compliance with the License.
sam_grove 0:ec233f3b49d8 12 * You may obtain a copy of the License at
sam_grove 0:ec233f3b49d8 13 *
sam_grove 0:ec233f3b49d8 14 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:ec233f3b49d8 15 *
sam_grove 0:ec233f3b49d8 16 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:ec233f3b49d8 17 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:ec233f3b49d8 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:ec233f3b49d8 19 * See the License for the specific language governing permissions and
sam_grove 0:ec233f3b49d8 20 * limitations under the License.
sam_grove 0:ec233f3b49d8 21 */
sam_grove 0:ec233f3b49d8 22
sam_grove 0:ec233f3b49d8 23 #include "TLV320AIC1110.h"
sam_grove 0:ec233f3b49d8 24
sam_grove 0:ec233f3b49d8 25 TLV320AIC1110::TLV320AIC1110(I2C &i2c)
sam_grove 0:ec233f3b49d8 26 {
sam_grove 0:ec233f3b49d8 27 _i2c = &i2c;
sam_grove 0:ec233f3b49d8 28 _i2c->frequency(400000);
sam_grove 0:ec233f3b49d8 29
sam_grove 0:ec233f3b49d8 30 return;
sam_grove 0:ec233f3b49d8 31 }
sam_grove 0:ec233f3b49d8 32
sam_grove 0:ec233f3b49d8 33 TLV320AIC1110::~TLV320AIC1110()
sam_grove 0:ec233f3b49d8 34 {
sam_grove 0:ec233f3b49d8 35 return;
sam_grove 0:ec233f3b49d8 36 }
sam_grove 0:ec233f3b49d8 37
sam_grove 0:ec233f3b49d8 38 void TLV320AIC1110::init(void)
sam_grove 0:ec233f3b49d8 39 {
sam_grove 0:ec233f3b49d8 40 writeRegister(0x00, 0x9B);
sam_grove 0:ec233f3b49d8 41 writeRegister(0x01, 0x00);
sam_grove 0:ec233f3b49d8 42 writeRegister(0x06, 0x81);
sam_grove 0:ec233f3b49d8 43
sam_grove 0:ec233f3b49d8 44 return;
sam_grove 0:ec233f3b49d8 45 }
sam_grove 0:ec233f3b49d8 46
sam_grove 0:ec233f3b49d8 47 void TLV320AIC1110::writeRegister(const uint8_t reg, const uint8_t value)
sam_grove 0:ec233f3b49d8 48 {
sam_grove 0:ec233f3b49d8 49 const uint8_t w_address = 0xE2;
sam_grove 0:ec233f3b49d8 50 uint8_t data[2] = {reg, value};
sam_grove 0:ec233f3b49d8 51
sam_grove 0:ec233f3b49d8 52 if (0 != _i2c->write(w_address, (char *)data, 2))
sam_grove 0:ec233f3b49d8 53 {
sam_grove 0:ec233f3b49d8 54 // catch an error here
sam_grove 0:ec233f3b49d8 55 }
sam_grove 0:ec233f3b49d8 56
sam_grove 0:ec233f3b49d8 57 return;
sam_grove 0:ec233f3b49d8 58 }
sam_grove 0:ec233f3b49d8 59
sam_grove 0:ec233f3b49d8 60 uint8_t TLV320AIC1110::readRegister(const uint8_t reg)
sam_grove 0:ec233f3b49d8 61 {
sam_grove 0:ec233f3b49d8 62 const uint8_t w_address = 0xE2;
sam_grove 0:ec233f3b49d8 63 const uint8_t r_address = 0xE3;
sam_grove 0:ec233f3b49d8 64 uint8_t data[1] = {reg};
sam_grove 0:ec233f3b49d8 65
sam_grove 0:ec233f3b49d8 66 _i2c->write(w_address, (char *)data, 1);
sam_grove 0:ec233f3b49d8 67 _i2c->start();
sam_grove 0:ec233f3b49d8 68 _i2c->write(r_address);
sam_grove 0:ec233f3b49d8 69 data[0] = _i2c->read(0);
sam_grove 0:ec233f3b49d8 70 _i2c->stop();
sam_grove 0:ec233f3b49d8 71
sam_grove 0:ec233f3b49d8 72 return data[0];
sam_grove 0:ec233f3b49d8 73 }
sam_grove 0:ec233f3b49d8 74
sam_grove 0:ec233f3b49d8 75
sam_grove 0:ec233f3b49d8 76
sam_grove 0:ec233f3b49d8 77
sam_grove 0:ec233f3b49d8 78
sam_grove 0:ec233f3b49d8 79