Device driver for TI TLV320AIC1110 voice band codec

Work in Progress

Committer:
sam_grove
Date:
Wed May 15 21:12:22 2013 +0000
Revision:
3:4592d862ef88
Parent:
1:4d559df5733e
Parent:
2:e7c7c0177dd8
Child:
4:470f89e786f9
Merged.

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 0:ec233f3b49d8 29 _i2c->frequency(400000);
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 2:e7c7c0177dd8 39 void TLV320AIC1110::init(void) const
sam_grove 0:ec233f3b49d8 40 {
sam_grove 2:e7c7c0177dd8 41 writeRegister(POWER_CONTROL, 0x9B);
sam_grove 2:e7c7c0177dd8 42 writeRegister(MODE_CONTROL, 0x00);
sam_grove 2:e7c7c0177dd8 43 writeRegister(AUX, 0x81);
sam_grove 0:ec233f3b49d8 44
sam_grove 0:ec233f3b49d8 45 return;
sam_grove 0:ec233f3b49d8 46 }
sam_grove 0:ec233f3b49d8 47
sam_grove 3:4592d862ef88 48 void TLV320AIC1110::regDump(void) const
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 2:e7c7c0177dd8 58 void TLV320AIC1110::writeRegister(const TLV320AIC1110_REGISTERS reg, const uint8_t value) const
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 0:ec233f3b49d8 70 return;
sam_grove 0:ec233f3b49d8 71 }
sam_grove 0:ec233f3b49d8 72
sam_grove 2:e7c7c0177dd8 73 uint8_t TLV320AIC1110::readRegister(const uint8_t reg) const
sam_grove 0:ec233f3b49d8 74 {
sam_grove 0:ec233f3b49d8 75 const uint8_t w_address = 0xE2;
sam_grove 0:ec233f3b49d8 76 const uint8_t r_address = 0xE3;
sam_grove 2:e7c7c0177dd8 77 char data[1] = {reg};
sam_grove 1:4d559df5733e 78 __disable_irq();
sam_grove 2:e7c7c0177dd8 79 _i2c->write(w_address, (char *)data, 1, 1);
sam_grove 2:e7c7c0177dd8 80 _i2c->read (r_address, data, 1);
sam_grove 1:4d559df5733e 81 __enable_irq();
sam_grove 3:4592d862ef88 82
sam_grove 3:4592d862ef88 83 // _i2c->start();
sam_grove 3:4592d862ef88 84 // _i2c->write(w_address);
sam_grove 3:4592d862ef88 85 // _i2c->write(reg);
sam_grove 3:4592d862ef88 86 // _i2c->stop();
sam_grove 2:e7c7c0177dd8 87 // _i2c->start();
sam_grove 2:e7c7c0177dd8 88 // _i2c->write(r_address);
sam_grove 3:4592d862ef88 89 // data[0] = _i2c->read(1);
sam_grove 2:e7c7c0177dd8 90 // _i2c->stop();
sam_grove 0:ec233f3b49d8 91
sam_grove 0:ec233f3b49d8 92 return data[0];
sam_grove 0:ec233f3b49d8 93 }
sam_grove 0:ec233f3b49d8 94
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