LPCOpen Platform for LPC112X microcontrollers
112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
Main Page
Modules
Data Structures
Files
File List
Globals
software
lpc_core
lpc_board
board_common
uda1380.c
Go to the documentation of this file.
1
/*
2
* @brief UDA1380 Audio codec interface file
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
board.h
"
33
34
/*****************************************************************************
35
* Private types/enumerations/variables
36
****************************************************************************/
37
/* Defalut UDA values */
38
/* System Register Data Set */
39
static
const
uint8_t
UDA_sys_regs_dat
[] = {
40
UDA_EVALM_CLK
,
/* Register to which following data be written */
41
UDA1380_U8
(
UDA1380_REG_EVALCLK_DEFAULT_VALUE
),
42
UDA1380_U8
(
UDA1380_REG_I2S_DEFAULT_VALUE
),
43
UDA1380_U8
(
UDA1380_REG_PWRCTRL_DEFAULT_VALUE
),
44
UDA1380_U8
(
UDA1380_REG_ANAMIX_DEFAULT_VALUE
),
45
UDA1380_U8
(
UDA1380_REG_HEADAMP_DEFAULT_VALUE
)
46
};
47
48
/* System Register Data Set */
49
static
const
uint8_t
UDA_interfil_regs_dat
[] = {
50
UDA_MASTER_VOL_CTRL
,
/* Register to which following data be written */
51
UDA1380_U8
(
UDA1380_REG_MSTRVOL_DEFAULT_VALUE
),
52
UDA1380_U8
(
UDA1380_REG_MIXVOL_DEFAULT_VALUE
),
53
UDA1380_U8
(
UDA1380_REG_MODEBBT_DEFAULT_VALUE
),
54
UDA1380_U8
(
UDA1380_REG_MSTRMUTE_DEFAULT_VALUE
),
55
UDA1380_U8
(
UDA1380_REG_MIXSDO_DEFAULT_VALUE
)
56
};
57
58
/* decimator Register Data Set */
59
static
const
uint8_t
UDA_decimator_regs_dat
[] = {
60
UDA_DEC_VOL_CTRL
,
/* Register to which following data be written */
61
UDA1380_U8
(
UDA1380_REG_DECVOL_DEFAULT_VALUE
),
62
UDA1380_U8
(
UDA1380_REG_PGA_DEFAULT_VALUE
),
63
UDA1380_U8
(
UDA1380_REG_ADC_DEFAULT_VALUE
),
64
UDA1380_U8
(
UDA1380_REG_AGC_DEFAULT_VALUE
)
65
};
66
67
/*****************************************************************************
68
* Public types/enumerations/variables
69
****************************************************************************/
70
71
/*****************************************************************************
72
* Private functions
73
****************************************************************************/
74
/* Set the default values to the codec registers */
75
static
int
Audio_Codec_SetDefaultValues
(
const
uint8_t *values,
int
sz)
76
{
77
int
ret;
78
uint8_t buff[10];
/* Verification buffer */
79
80
/* Set System register's default values */
81
ret =
UDA1380_REG_WriteMult
(values, sz);
82
if
(ret) {
83
ret =
UDA1380_REG_VerifyMult
(values[0], &values[1], buff, sz - 1);
84
}
85
return
ret;
86
}
87
88
/*****************************************************************************
89
* Public functions
90
****************************************************************************/
91
/* Write data to UDA register */
92
void
UDA1380_REG_Write
(uint8_t reg, uint16_t val)
93
{
94
uint8_t dat[3];
95
dat[0] = reg; dat[1] = val >> 8; dat[2] = val & 0xFF;
96
Chip_I2C_MasterSend
(UDA1380_I2C_BUS, I2CDEV_UDA1380_ADDR, dat,
sizeof
(dat));
97
}
98
99
/* Read data from UDA register */
100
uint16_t
UDA1380_REG_Read
(uint8_t reg) {
101
uint8_t rx_data[2];
102
if
(
Chip_I2C_MasterCmdRead
(UDA1380_I2C_BUS, I2CDEV_UDA1380_ADDR, reg, rx_data, 2) == 2) {
103
return
(rx_data[0] << 8) | rx_data[1];
104
}
105
return
0;
106
}
107
108
/* Write data to UDA register and verify the value by reading it back */
109
int
UDA1380_REG_WriteVerify
(uint8_t reg, uint16_t val)
110
{
111
uint16_t ret;
112
UDA1380_REG_Write
(reg, val);
113
ret =
UDA1380_REG_Read
(reg);
114
return
ret == val;
115
}
116
117
/* Multiple value verification function */
118
int
UDA1380_REG_VerifyMult
(uint8_t reg,
const
uint8_t *value, uint8_t *buff,
int
len)
119
{
120
int
i;
121
if
(
Chip_I2C_MasterCmdRead
(UDA1380_I2C_BUS, I2CDEV_UDA1380_ADDR, reg, buff, len) != len) {
122
return
0;
/* Partial read */
123
124
}
125
/* Compare the values */
126
for
(i = 0; i < len; i++) {
127
if
(value[i] != buff[i]) {
128
break
;
129
}
130
}
131
132
return
i == len;
133
}
134
135
/* UDA1380 initialize function */
136
int
UDA1380_Init
(
int
input)
137
{
138
I2C_EVENTHANDLER_T
old =
Chip_I2C_GetMasterEventHandler
(UDA1380_I2C_BUS);
139
int
ret;
140
141
/* Initialize I2C */
142
Board_I2C_Init(UDA1380_I2C_BUS);
143
Chip_I2C_Init
(UDA1380_I2C_BUS);
144
Chip_I2C_SetClockRate
(UDA1380_I2C_BUS, 100000);
145
Chip_I2C_SetMasterEventHandler
(UDA1380_I2C_BUS,
Chip_I2C_EventHandlerPolling
);
146
147
/* Initialize the default values */
148
ret =
Audio_Codec_SetDefaultValues
(
UDA_sys_regs_dat
,
sizeof
(
UDA_sys_regs_dat
));
149
150
if
(ret) {
151
ret =
Audio_Codec_SetDefaultValues
(
UDA_interfil_regs_dat
,
sizeof
(
UDA_interfil_regs_dat
));
152
}
153
154
if
(ret) {
155
ret =
Audio_Codec_SetDefaultValues
(
UDA_decimator_regs_dat
,
sizeof
(
UDA_decimator_regs_dat
));
156
}
157
158
if
(ret && input) {
159
/* Disable Power On for ADCR, PGAR, PGAL to get mic sound more clearly */
160
ret =
UDA1380_REG_WriteVerify
(
UDA_POWER_CTRL
,
161
UDA1380_REG_PWRCTRL_DEFAULT_VALUE
& (~(0x0B)));
162
163
if
(ret) {
164
ret =
UDA1380_REG_WriteVerify
(
UDA_ADC_CTRL
,
165
UDA1380_REG_ADC_DEFAULT_VALUE
| input);
166
}
167
}
168
Chip_I2C_SetMasterEventHandler
(UDA1380_I2C_BUS, old);
169
170
return
ret;
171
}
172
173
/* Write multiple registers in one go */
174
int
UDA1380_REG_WriteMult
(
const
uint8_t *buff,
int
len)
175
{
176
return
Chip_I2C_MasterSend
(UDA1380_I2C_BUS, I2CDEV_UDA1380_ADDR, buff, len) == len;
177
}
Generated on Fri Feb 20 2015 22:12:06 for LPCOpen Platform for LPC112X microcontrollers by
1.8.3.1