Production Test Program (PTP) for the LPC4088 Experiment Base Board

Dependencies:   EALib I2S LM75B SDFileSystem mbed

WM8731.cpp

Committer:
embeddedartists
Date:
2014-08-25
Revision:
0:0d5190d379d3
Child:
3:7ef908e84ae1

File content as of revision 0:0d5190d379d3:

/*
 *  Copyright 2013 Embedded Artists AB
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/******************************************************************************
 * Includes
 *****************************************************************************/

#include "mbed.h"
#include "mbed_debug.h"

#include "WM8731.h"

/******************************************************************************
 * Defines and typedefs
 *****************************************************************************/

#define WM8731_I2C_ADDR (0x1A << 1)

#define WM8731_REG_R0_LEFT_LINE_IN                    0x00
#define WM8731_REG_R1_RIGHT_LINE_IN                   0x01
#define WM8731_REG_R2_LEFT_HP_OUT                     0x02
#define WM8731_REG_R3_RIGHT_HP_OUT                    0x03
#define WM8731_REG_R4_ANALOGUE_AUDIO_PATH_CONTROL     0x04
#define WM8731_REG_R5_DIGITAL_AUDIO_PATH_CONTROL      0x05
#define WM8731_REG_R6_POWER_DOWN_CONTROL              0x06
#define WM8731_REG_R7_DIGITAL_AUDIO_INTERFACE_FORMAT  0x07
#define WM8731_REG_R8_SAMPLING_CONTROL                0x08
#define WM8731_REG_R9_ACTIVE_CONTROL                  0x09
#define WM8731_REG_R15_RESET                          0x0f


WM8731::WM8731(PinName sda, PinName scl) : _i2c(sda, scl) {
}

bool WM8731::writeCmd(Register reg, uint16_t data) {
  char dataToTransfer[2];
  
  dataToTransfer[0] = (reg << 1) | ((data & 0x100) >> 8);
  dataToTransfer[1] = data & 0xff;
  
  if (_i2c.write(WM8731_I2C_ADDR, dataToTransfer, 2) == 0) {
    wait_us(40);
	return true;
  }
  return false;
}