LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
board_ngx_xplorer_18304330.c
Go to the documentation of this file.
1
/*
2
* Copyright(C) NXP Semiconductors, 2012
3
* All rights reserved.
4
*
5
* Software that is described herein is for illustrative purposes only
6
* which provides customers with programming information regarding the
7
* LPC products. This software is supplied "AS IS" without any warranties of
8
* any kind, and NXP Semiconductors and its licensor disclaim any and
9
* all warranties, express or implied, including all implied warranties of
10
* merchantability, fitness for a particular purpose and non-infringement of
11
* intellectual property rights. NXP Semiconductors assumes no responsibility
12
* or liability for the use of the software, conveys no license or rights under any
13
* patent, copyright, mask work right, or any other intellectual property rights in
14
* or to any products. NXP Semiconductors reserves the right to make changes
15
* in the software without notification. NXP Semiconductors also makes no
16
* representation or warranty that such application will be suitable for the
17
* specified use without further testing or modification.
18
*
19
* Permission to use, copy, modify, and distribute this software and its
20
* documentation is hereby granted, under NXP Semiconductors' and its
21
* licensor's relevant copyrights in the software, without fee, provided that it
22
* is used in conjunction with NXP Semiconductors microcontrollers. This
23
* copyright, permission, and disclaimer notice must appear in all copies of
24
* this code.
25
*/
26
27
#include "
board.h
"
28
#include "string.h"
29
30
#include "
lpc_phy_smsc87x0.c
"
31
#include "
retarget.c
"
32
37
void
Board_UART_Init
(
LPC_USART_Type
*UARTx)
38
{
39
if
(UARTx ==
LPC_USART0
) {
40
Chip_SCU_PinMux
(0x6, 4,
MD_PDN
,
FUNC2
);
/* P6.5 : UART0_TXD */
41
Chip_SCU_PinMux
(0x6, 5,
MD_PLN
|
MD_EZI
|
MD_ZI
,
FUNC2
);
/* P6.4 : UART0_RXD */
42
}
43
else
if
(UARTx ==
LPC_UART1
) {
44
Chip_SCU_PinMux
(0x1, 13,
MD_PDN
,
FUNC2
);
/* P1.13 : UART1_TXD */
45
Chip_SCU_PinMux
(0x1, 14,
MD_PLN
|
MD_EZI
|
MD_ZI
,
FUNC2
);
/* P1.14 : UART1_RX */
46
}
47
}
48
49
/* Initialize debug output via UART for board */
50
void
Board_Debug_Init
(
void
)
51
{
52
#if defined(DEBUG_UART)
53
Board_UART_Init
(
DEBUG_UART
);
54
55
Chip_UART_Init
(
DEBUG_UART
);
56
Chip_UART_SetBaud
(
DEBUG_UART
, 115200);
57
Chip_UART_ConfigData
(
DEBUG_UART
,
UART_DATABIT_8
,
UART_PARITY_NONE
,
UART_STOPBIT_1
);
58
59
/* Enable UART Transmit */
60
Chip_UART_TxCmd
(
DEBUG_UART
,
ENABLE
);
61
#endif
62
}
63
64
/* Sends a character on the UART */
65
void
Board_UARTPutChar
(
char
ch)
66
{
67
#if defined(DEBUG_UART)
68
while
(
Chip_UART_SendByte
(
DEBUG_UART
, (uint8_t) ch) ==
ERROR
) {}
69
#endif
70
}
71
72
/* Gets a character from the UART, returns EOF if no character is ready */
73
int
Board_UARTGetChar
(
void
)
74
{
75
#if defined(DEBUG_UART)
76
uint8_t data;
77
78
if
(
Chip_UART_ReceiveByte
(
DEBUG_UART
, &data) ==
SUCCESS
) {
79
return
(
int
) data;
80
}
81
#endif
82
return
EOF
;
83
}
84
85
/* Outputs a string on the debug UART */
86
void
Board_UARTPutSTR
(
char
*str)
87
{
88
#if defined(DEBUG_UART)
89
while
(*str !=
'\0'
) {
90
Board_UARTPutChar
(*str++);
91
}
92
#endif
93
}
94
95
void
Board_LED_Init
()
96
{
97
/* P2.12 : LED D2 as output */
98
Chip_GPIO_WriteDirBit
(1, 12,
true
);
99
100
/* P2.11 : LED D3 as output */
101
Chip_GPIO_WriteDirBit
(1, 11,
true
);
102
103
/* Set initial states to off (true to disable) */
104
Chip_GPIO_WritePortBit
(1, 12, (
bool
)
true
);
105
Chip_GPIO_WritePortBit
(1, 11, (
bool
)
true
);
106
}
107
108
void
Board_LED_Set
(uint8_t LEDNumber,
bool
On
)
109
{
110
if
(LEDNumber == 0) {
111
Chip_GPIO_WritePortBit
(1, 12, (
bool
) !On);
112
}
113
else
if
(LEDNumber == 1) {
114
Chip_GPIO_WritePortBit
(1, 11, (
bool
) !On);
115
}
116
}
117
118
bool
Board_LED_Test
(uint8_t LEDNumber)
119
{
120
if
(LEDNumber == 0) {
121
return
(
bool
) !
Chip_GPIO_ReadPortBit
(1, 12);
122
}
123
else
if
(LEDNumber == 1) {
124
return
(
bool
) !
Chip_GPIO_ReadPortBit
(1, 11);
125
}
126
127
return
false
;
128
}
129
130
void
Board_Buttons_Init
(
void
)
// FIXME not functional ATM
131
{
132
Chip_SCU_PinMux
(0x2, 7,
MD_PUP
|
MD_EZI
|
MD_ZI
,
FUNC0
);
// P2_7 as GPIO0[7]
133
Chip_GPIO_WriteDirBit
(
BUTTONS_BUTTON1_GPIO_PORT_NUM
, (1 <<
BUTTONS_BUTTON1_GPIO_BIT_NUM
),
false
);
// input
134
}
135
136
uint32_t
Buttons_GetStatus
(
void
)
137
{
138
uint8_t ret =
NO_BUTTON_PRESSED
;
139
if
(
Chip_GPIO_ReadPortBit
(
BUTTONS_BUTTON1_GPIO_PORT_NUM
,
BUTTONS_BUTTON1_GPIO_BIT_NUM
) == 0) {
140
ret |=
BUTTONS_BUTTON1
;
141
}
142
return
ret;
143
}
144
145
void
Board_Joystick_Init
(
void
)
146
{}
147
148
uint8_t
Joystick_GetStatus
(
void
)
149
{
150
return
NO_BUTTON_PRESSED
;
151
}
152
154
uint32_t
SystemCoreClock
;
155
156
/* Update system core clock rate, should be called if the system has
157
a clock rate change */
158
void
SystemCoreClockUpdate
(
void
)
159
{
160
/* CPU core speed */
161
SystemCoreClock
=
Chip_Clock_GetRate
(
CLK_MX_MXCORE
);
162
}
163
164
/* Returns the MAC address assigned to this board */
165
void
Board_ENET_GetMacADDR
(uint8_t *mcaddr)
166
{
167
uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
168
169
memcpy(mcaddr, boardmac, 6);
170
}
171
172
/* Set up and initialize all required blocks and functions related to the
173
board hardware */
174
void
Board_Init
(
void
)
175
{
176
/* Sets up DEBUG UART */
177
DEBUGINIT
();
178
179
/* Updates SystemCoreClock global var with current clock speed */
180
SystemCoreClockUpdate
();
181
182
/* Initializes GPIO */
183
Chip_GPIO_Init
();
184
185
/* Setup GPIOs for USB demos */
186
Chip_SCU_PinMux
(0x2, 6, (
MD_PUP
|
MD_EZI
),
FUNC4
);
/* P2_6 USB1_PWR_EN, USB1 VBus function */
187
Chip_SCU_PinMux
(0x2, 5, (
MD_PLN
|
MD_EZI
|
MD_ZI
),
FUNC2
);
/* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
188
Chip_SCU_PinMux
(0x1, 7, (
MD_PUP
|
MD_EZI
),
FUNC4
);
/* P1_7 USB0_PWR_EN, USB0 VBus function Xplorer */
189
Chip_GPIO_WriteDirBit
(5, 6,
true
);
/* GPIO5[6] = USB1_PWR_EN */
190
Chip_GPIO_WritePortBit
(5, 6,
true
);
/* GPIO5[6] output high */
191
}
192
193
void
Board_I2C_Init
(
LPC_I2C_Type
*I2Cx)
194
{
195
if
(I2Cx ==
LPC_I2C1
) {
196
/* Configure pin function for I2C1*/
197
Chip_SCU_PinMux
(0x2, 3,
MD_ZI
|
MD_EZI
,
FUNC1
);
/* P2.3 : I2C1_SDA */
198
Chip_SCU_PinMux
(0x2, 4,
MD_ZI
|
MD_EZI
,
FUNC1
);
/* P2.4 : I2C1_SCL */
199
}
200
}
201
202
void
GPIO0_IRQHandler
(
void
)
203
{
204
static
bool
On
;
205
206
if
(
Chip_GPIO_IntGetStatus
(0, 0, 0)) {
207
Chip_GPIO_IntClear
(0, 0);
208
On = (bool) !On;
209
Board_LED_Set
(1, On);
210
}
211
}
212
213
void
Board_GPIO_Int_Init
()
214
{
215
Chip_SCU_PinMux
(0xF, 9, (
MD_PLN
|
MD_EZI
|
MD_ZI
),
FUNC0
);
/* PF.9 : POTI button */
216
Chip_GPIO_WriteDirBit
(7, 23,
false
);
/* PF.9 -> GPIO7[23] : input */
217
Chip_SCU_GPIOIntPinSel
(0, 7, 23);
218
Chip_GPIO_IntCmd
(0, 0,
IP_GPIOPININT_FALLING_EDGE
);
/* Configure GPIO0[7] to interrupt pin (SW2 switch) */
219
220
NVIC_EnableIRQ(PIN_INT0_IRQn);
/* enable GPIO interrupt 0 */
221
}
222
223
void
Board_SDMMC_Init
(
void
)
224
{
225
Chip_SCU_PinMux
(0x1, 9,
MD_PLN_FAST
,
FUNC7
);
/* P1.9 connected to SDIO_D0 */
226
Chip_SCU_PinMux
(0x1, 10,
MD_PLN_FAST
,
FUNC7
);
/* P1.10 connected to SDIO_D1 */
227
Chip_SCU_PinMux
(0x1, 11,
MD_PLN_FAST
,
FUNC7
);
/* P1.11 connected to SDIO_D2 */
228
Chip_SCU_PinMux
(0x1, 12,
MD_PLN_FAST
,
FUNC7
);
/* P1.12 connected to SDIO_D3 */
229
230
Chip_SCU_PinMux
(
PINMUX_CLK
, 2,
MD_PLN
|
MD_EZI
,
FUNC4
);
/* CLK2 connected to SDIO_CLK */
231
Chip_SCU_PinMux
(0x1, 6,
MD_PLN_FAST
,
FUNC7
);
/* P1.6 connected to SDIO_CMD */
232
}
233
234
void
Board_SSP_Init
(
LPC_SSP_Type
*SSPx)
235
{
236
if
(SSPx ==
LPC_SSP1
) {
237
/* Set up clock and power for SSP1 module */
238
/* Configure SSP1 pins*/
239
/* SCLK comes out pin CLK0 */
240
Chip_SCU_PinMux
(
PINMUX_CLK
, 0,
MD_PLN_FAST
,
FUNC6
);
/* CLK0 connected to CLK func6=SSP1 CLK1 */
241
Chip_SCU_PinMux
(0x1, 5,
MD_PLN_FAST
,
FUNC5
);
/* P1.5 connected to nCS func5=SSP1 SSEL1 */
242
Chip_SCU_PinMux
(0x1, 3,
MD_PLN
|
MD_EZI
|
MD_ZI
,
FUNC5
);
/* P1.3 connected to SO func5=SSP1 MISO1 */
243
Chip_SCU_PinMux
(0x1, 4,
MD_PLN
|
MD_EZI
|
MD_ZI
,
FUNC5
);
/* P1.4 connected to nSI func5=SSP1 MOSI1 */
244
Chip_Clock_EnableOpts
(
CLK_MX_SSP1
,
true
,
true
, 1);
245
}
246
else
{
247
return
;
248
}
249
}
250
251
/* System Register Data Set */
252
uint16_t
UDA_sys_regs_dat
[] = {
253
UDA1380_REG_EVALCLK_DEFAULT_VALUE
,
254
UDA1380_REG_I2S_DEFAULT_VALUE
,
255
UDA1380_REG_PWRCTRL_DEFAULT_VALUE
,
256
UDA1380_REG_ANAMIX_DEFAULT_VALUE
,
257
UDA1380_REG_HEADAMP_DEFAULT_VALUE
258
};
259
260
/* System Register Data Set */
261
uint16_t
UDA_interfil_regs_dat
[] = {
262
UDA1380_REG_MSTRVOL_DEFAULT_VALUE
,
263
UDA1380_REG_MIXVOL_DEFAULT_VALUE
,
264
UDA1380_REG_MODEBBT_DEFAULT_VALUE
,
265
UDA1380_REG_MSTRMUTE_DEFAULT_VALUE
,
266
UDA1380_REG_MIXSDO_DEFAULT_VALUE
267
};
268
/* decimator Register Data Set */
269
uint16_t
UDA_decimator_regs_dat
[] = {
270
UDA1380_REG_DECVOL_DEFAULT_VALUE
,
271
UDA1380_REG_PGA_DEFAULT_VALUE
,
272
UDA1380_REG_ADC_DEFAULT_VALUE
,
273
UDA1380_REG_AGC_DEFAULT_VALUE
274
};
275
static
void
delay
(
uint32_t
i) {
276
while
(i--) {}
277
}
278
279
static
void
UDA_Reg_write
(
UDA1380_REG
reg,
unsigned
short
value,
I2C_M_SETUP_Type
*I2C_Config) {
280
281
I2C_Config->
tx_data
[0] = reg;
282
I2C_Config->
tx_data
[1] = value >> 8;
283
I2C_Config->
tx_data
[2] = value & 0xFF;
284
Chip_I2C_MasterTransmitData
(
LPC_I2C0
, I2C_Config,
I2C_TRANSFER_POLLING
);
285
delay
(10000);
286
}
287
288
static
uint16_t
UDA_Reg_read
(
UDA1380_REG
reg) {
289
uint8_t rx_data[2];
290
Chip_I2C_MasterReadReg
(
LPC_I2C0
,
I2CDEV_UDA1380_ADDR
, reg, rx_data, 2);
291
return
rx_data[0] << 8 | rx_data[1];
292
}
293
294
static
Status
UDA1380_init
(
I2C_M_SETUP_Type
*I2C_Config,
Board_Audio_Input_Sel_Type
audio_in_sel)
295
{
296
uint16_t temp;
297
uint8_t i;
298
/* Reset UDA1380 on board NGX Xplorer */
299
Chip_SCU_PinMux
(0x2, 10,
MD_PUP
,
FUNC0
);
300
Chip_GPIO_WriteDirBit
(0, 14,
true
);
301
Chip_GPIO_WritePortBit
(0, 14,
true
);
302
// delay 1us
303
delay
(100000);
304
Chip_GPIO_WritePortBit
(0, 14,
false
);
305
delay
(100000);
306
for
(i = 0; i < 5; i++) {
307
UDA_Reg_write
((
UDA1380_REG
) (
UDA_EVALM_CLK
+ i),
UDA_sys_regs_dat
[i], I2C_Config);
308
temp =
UDA_Reg_read
((
UDA1380_REG
) (
UDA_EVALM_CLK
+ i));
309
if
(temp !=
UDA_sys_regs_dat
[i]) {
310
return
ERROR
;
311
}
312
}
313
314
/* interfilter regs init */
315
for
(i = 0; i < 5; i++) {
316
UDA_Reg_write
((
UDA1380_REG
) (
UDA_MASTER_VOL_CTRL
+ i),
UDA_interfil_regs_dat
[i], I2C_Config);
317
temp =
UDA_Reg_read
((
UDA1380_REG
) (
UDA_MASTER_VOL_CTRL
+ i));
318
if
(temp !=
UDA_interfil_regs_dat
[i]) {
319
return
ERROR
;
320
}
321
}
322
/* decimator regs init */
323
for
(i = 0; i < 4; i++) {
324
UDA_Reg_write
((
UDA1380_REG
) (
UDA_DEC_VOL_CTRL
+ i),
UDA_decimator_regs_dat
[i], I2C_Config);
325
temp =
UDA_Reg_read
((
UDA1380_REG
) (
UDA_DEC_VOL_CTRL
+ i));
326
if
(temp !=
UDA_decimator_regs_dat
[i]) {
327
return
ERROR
;
328
}
329
}
330
331
if
(audio_in_sel ==
MCB_18XX_AUDIO_MIC_SELECT
) {
332
/* Disable Power On for ADCR, PGAR, PGAL to get mic sound more clearly */
333
UDA_Reg_write
((
UDA1380_REG
) (
UDA_POWER_CTRL
),
UDA1380_REG_PWRCTRL_DEFAULT_VALUE
& (~(0x0B)), I2C_Config);
334
temp =
UDA_Reg_read
((
UDA1380_REG
) (
UDA_ADC_CTRL
));
335
if
(temp != (
UDA1380_REG_ADC_DEFAULT_VALUE
|
MCB_18XX_AUDIO_MIC_SELECT
)) {
336
return
ERROR
;
337
}
338
UDA_Reg_write
((
UDA1380_REG
) (
UDA_ADC_CTRL
),
339
UDA1380_REG_ADC_DEFAULT_VALUE
|
MCB_18XX_AUDIO_MIC_SELECT
,
340
I2C_Config);
341
temp =
UDA_Reg_read
((
UDA1380_REG
) (
UDA_ADC_CTRL
));
342
if
(temp != (
UDA1380_REG_ADC_DEFAULT_VALUE
|
MCB_18XX_AUDIO_MIC_SELECT
)) {
343
return
ERROR
;
344
}
345
}
346
return
SUCCESS
;
347
348
}
349
350
void
Board_Audio_Init
(
LPC_I2S_Type
*I2Sx,
Board_Audio_Input_Sel_Type
audio_in_sel)
351
{
352
uint8_t uda1380_tx_data_buf[3];
353
Chip_I2S_Audio_Format_Type
I2S_Config;
354
I2C_M_SETUP_Type
I2C_Config;
355
I2C_Config.
sl_addr7bit
=
I2CDEV_UDA1380_ADDR
;
356
I2C_Config.
retransmissions_max
= 5;
357
I2C_Config.
tx_length
= 3;
358
I2C_Config.
tx_data
= uda1380_tx_data_buf;
359
I2C_Config.
rx_length
= 0;
360
I2C_Config.
rx_data
=
NULL
;
361
362
/* Initialize I2C peripheral ------------------------------------*/
363
/* Init I2C */
364
Chip_I2C_Init
(
LPC_I2C0
);
365
Chip_I2C_SetClockRate
(
LPC_I2C0
, 100000);
366
367
I2S_Config.
SampleRate
= 48000;
368
I2S_Config.
ChannelNumber
= 2;
/* 1 is mono, 2 is stereo */
369
I2S_Config.
WordWidth
= 16;
/* 8, 16 or 32 bits */
370
Chip_I2S_Init
(
LPC_I2S0
);
371
Chip_I2S_Config
(
LPC_I2S0
,
I2S_TX_MODE
, &I2S_Config);
372
/* Enable Slave I2C operation */
373
Chip_I2C_Cmd
(
LPC_I2C0
,
I2C_MASTER_MODE
,
ENABLE
);
374
/* Init UDA1380 CODEC */
375
while
(
UDA1380_init
(&I2C_Config, audio_in_sel) !=
SUCCESS
) {}
376
377
}
378
379
/* FIXME Should we remove this function? */
380
void
Serial_CreateStream
(
void
*Stream)
381
{}
382
software
lpc_core
lpc_board
boards_18xx_43xx
ngx_xplorer_18304330
board_ngx_xplorer_18304330.c
Generated on Fri Nov 16 2012 13:36:40 for LPCOpen Platform by
1.8.2