Device driver for TI TLV320AIC1110 voice band codec

Work in Progress

Committer:
sam_grove
Date:
Wed May 15 21:07:10 2013 +0000
Revision:
1:4d559df5733e
Parent:
0:ec233f3b49d8
Child:
3:4592d862ef88
Working up the driver....

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 1:4d559df5733e 24 #include "LogUtil.h"
sam_grove 0:ec233f3b49d8 25
sam_grove 0:ec233f3b49d8 26 TLV320AIC1110::TLV320AIC1110(I2C &i2c)
sam_grove 0:ec233f3b49d8 27 {
sam_grove 0:ec233f3b49d8 28 _i2c = &i2c;
sam_grove 1:4d559df5733e 29 _i2c->frequency(100000);
sam_grove 0:ec233f3b49d8 30
sam_grove 0:ec233f3b49d8 31 return;
sam_grove 0:ec233f3b49d8 32 }
sam_grove 0:ec233f3b49d8 33
sam_grove 0:ec233f3b49d8 34 TLV320AIC1110::~TLV320AIC1110()
sam_grove 0:ec233f3b49d8 35 {
sam_grove 0:ec233f3b49d8 36 return;
sam_grove 0:ec233f3b49d8 37 }
sam_grove 0:ec233f3b49d8 38
sam_grove 0:ec233f3b49d8 39 void TLV320AIC1110::init(void)
sam_grove 0:ec233f3b49d8 40 {
sam_grove 0:ec233f3b49d8 41 writeRegister(0x00, 0x9B);
sam_grove 0:ec233f3b49d8 42 writeRegister(0x01, 0x00);
sam_grove 0:ec233f3b49d8 43 writeRegister(0x06, 0x81);
sam_grove 0:ec233f3b49d8 44
sam_grove 0:ec233f3b49d8 45 return;
sam_grove 0:ec233f3b49d8 46 }
sam_grove 0:ec233f3b49d8 47
sam_grove 1:4d559df5733e 48 void TLV320AIC1110::regDump(void)
sam_grove 1:4d559df5733e 49 {
sam_grove 1:4d559df5733e 50 for(int i=0; i<7; i++)
sam_grove 1:4d559df5733e 51 {
sam_grove 1:4d559df5733e 52 LOG(" Register 0x%02x 0x%02x\n", i, readRegister(i));
sam_grove 1:4d559df5733e 53 }
sam_grove 1:4d559df5733e 54
sam_grove 1:4d559df5733e 55 return;
sam_grove 1:4d559df5733e 56 }
sam_grove 1:4d559df5733e 57
sam_grove 0:ec233f3b49d8 58 void TLV320AIC1110::writeRegister(const uint8_t reg, const uint8_t value)
sam_grove 0:ec233f3b49d8 59 {
sam_grove 0:ec233f3b49d8 60 const uint8_t w_address = 0xE2;
sam_grove 0:ec233f3b49d8 61 uint8_t data[2] = {reg, value};
sam_grove 0:ec233f3b49d8 62
sam_grove 1:4d559df5733e 63 __disable_irq();
sam_grove 0:ec233f3b49d8 64 if (0 != _i2c->write(w_address, (char *)data, 2))
sam_grove 0:ec233f3b49d8 65 {
sam_grove 1:4d559df5733e 66 ERROR("write failed\n");
sam_grove 0:ec233f3b49d8 67 }
sam_grove 1:4d559df5733e 68 __enable_irq();
sam_grove 1:4d559df5733e 69
sam_grove 1:4d559df5733e 70 // _i2c->start();
sam_grove 1:4d559df5733e 71 // _i2c->write(w_address);
sam_grove 1:4d559df5733e 72 // _i2c->write(reg);
sam_grove 1:4d559df5733e 73 // _i2c->write(value);
sam_grove 1:4d559df5733e 74 // _i2c->stop();
sam_grove 1:4d559df5733e 75
sam_grove 0:ec233f3b49d8 76 return;
sam_grove 0:ec233f3b49d8 77 }
sam_grove 0:ec233f3b49d8 78
sam_grove 0:ec233f3b49d8 79 uint8_t TLV320AIC1110::readRegister(const uint8_t reg)
sam_grove 0:ec233f3b49d8 80 {
sam_grove 0:ec233f3b49d8 81 const uint8_t w_address = 0xE2;
sam_grove 0:ec233f3b49d8 82 const uint8_t r_address = 0xE3;
sam_grove 0:ec233f3b49d8 83 uint8_t data[1] = {reg};
sam_grove 1:4d559df5733e 84 __disable_irq();
sam_grove 1:4d559df5733e 85 _i2c->start();
sam_grove 1:4d559df5733e 86 _i2c->write(w_address);
sam_grove 1:4d559df5733e 87 _i2c->write(reg);
sam_grove 1:4d559df5733e 88 _i2c->stop();
sam_grove 0:ec233f3b49d8 89 _i2c->start();
sam_grove 0:ec233f3b49d8 90 _i2c->write(r_address);
sam_grove 1:4d559df5733e 91 data[0] = _i2c->read(1);
sam_grove 0:ec233f3b49d8 92 _i2c->stop();
sam_grove 1:4d559df5733e 93 __enable_irq();
sam_grove 0:ec233f3b49d8 94 return data[0];
sam_grove 0:ec233f3b49d8 95 }
sam_grove 0:ec233f3b49d8 96
sam_grove 0:ec233f3b49d8 97
sam_grove 0:ec233f3b49d8 98
sam_grove 0:ec233f3b49d8 99
sam_grove 0:ec233f3b49d8 100
sam_grove 0:ec233f3b49d8 101