LPCOpen Platform for LPC18XX/43XX microcontrollers: C:/w/lpcopen_docs/software/lpc_core/lpc_board/boards_18xx/ngx_xplorer_1830/board.c Source File

| LPCOpen Platform for LPC18XX/43XX microcontrollers 18XX43XX LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

board.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 "retarget.h"
31
36 /*****************************************************************************
37 * Public types/enumerations/variables
38 ****************************************************************************/
39
40 /* System configuration variables used by chip driver */
41 const uint32_t ExtRateIn = 0;
42 const uint32_t OscRateIn = 12000000;
43
44 void Board_UART_Init(LPC_USART_T *pUART)
45 {
46 if (pUART == LPC_USART0) {
47 Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC2)); /* P6.5 : UART0_TXD */
48 Chip_SCU_PinMuxSet(0x6, 5, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2));/* P6.4 : UART0_RXD */
49 }
50 else if (pUART == LPC_UART1) {
51 Chip_SCU_PinMuxSet(0x1, 13, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC2)); /* P1.13 : UART1_TXD */
52 Chip_SCU_PinMuxSet(0x1, 14, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P1.14 : UART1_RX */
53 }
54 }
55
56 /* Initialize debug output via UART for board */
57 void Board_Debug_Init(void)
58 {
59 #if defined(DEBUG_UART)
60 Board_UART_Init(DEBUG_UART);
61
62 Chip_UART_Init(DEBUG_UART);
63 Chip_UART_SetBaud(DEBUG_UART, 115200);
64 Chip_UART_ConfigData(DEBUG_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
65
66 /* Enable UART Transmit */
67 Chip_UART_TXEnable(DEBUG_UART);
68 #endif
69 }
70
71 /* Sends a character on the UART */
72 void Board_UARTPutChar(char ch)
73 {
74 #if defined(DEBUG_UART)
75 /* Wait for space in FIFO */
76 while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {}
77 Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch);
78 #endif
79 }
80
81 /* Gets a character from the UART, returns EOF if no character is ready */
82 int Board_UARTGetChar(void)
83 {
84 #if defined(DEBUG_UART)
85 if (Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_RDR) {
86 return (int) Chip_UART_ReadByte(DEBUG_UART);
87 }
88 #endif
89 return EOF;
90 }
91
92 /* Outputs a string on the debug UART */
93 void Board_UARTPutSTR(const char *str)
94 {
95 #if defined(DEBUG_UART)
96 while (*str != '\0') {
97 Board_UARTPutChar(*str++);
98 }
99 #endif
100 }
101
102 static void Board_LED_Init()
103 {
104 /* P2.12 : LED D2 as output */
105 Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 1, 12);
106
107 /* P2.11 : LED D3 as output */
108 Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 1, 11);
109
110 /* Set initial states to off (true to disable) */
111 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 1, 12, (bool) true);
112 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 1, 11, (bool) true);
113 }
114
115 void Board_LED_Set(uint8_t LEDNumber, bool On)
116 {
117 if (LEDNumber == 0) {
118 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 1, 12, (bool) !On);
119 }
120 else if (LEDNumber == 1) {
121 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 1, 11, (bool) !On);
122 }
123 }
124
125 bool Board_LED_Test(uint8_t LEDNumber)
126 {
127 if (LEDNumber == 0) {
128 return (bool) !Chip_GPIO_GetPinState(LPC_GPIO_PORT, 1, 12);
129 }
130 else if (LEDNumber == 1) {
131 return (bool) !Chip_GPIO_GetPinState(LPC_GPIO_PORT, 1, 11);
132 }
133
134 return false;
135 }
136
137 void Board_LED_Toggle(uint8_t LEDNumber)
138 {
139 Board_LED_Set(LEDNumber, !Board_LED_Test(LEDNumber));
140 }
141
142 void Board_Buttons_Init(void)
143 {
144 Chip_SCU_PinMuxSet(0x2, 7, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0)); // P2_7 as GPIO0[7]
145 Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, (1 << BUTTONS_BUTTON1_GPIO_BIT_NUM)); // input
146 }
147
148 uint32_t Buttons_GetStatus(void)
149 {
150 uint8_t ret = NO_BUTTON_PRESSED;
151 if (Chip_GPIO_GetPinState(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM) == 0) {
152 ret |= BUTTONS_BUTTON1;
153 }
154 return ret;
155 }
156
157 void Board_Joystick_Init(void)
158 {}
159
160 uint8_t Joystick_GetStatus(void)
161 {
162 return NO_BUTTON_PRESSED;
163 }
164
165 /* Returns the MAC address assigned to this board */
166 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
167 {
168 uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
169
170 memcpy(mcaddr, boardmac, 6);
171 }
172
173 /* Set up and initialize all required blocks and functions related to the
174 board hardware */
175 void Board_Init(void)
176 {
177 /* Sets up DEBUG UART */
178 DEBUGINIT();
179
180 /* Initializes GPIO */
181 Chip_GPIO_Init(LPC_GPIO_PORT);
182
183 /* Setup GPIOs for USB demos */
184 Chip_SCU_PinMuxSet(0x2, 6, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* P2_6 USB1_PWR_EN, USB1 VBus function */
185 Chip_SCU_PinMuxSet(0x2, 5, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
186 Chip_SCU_PinMuxSet(0x1, 7, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* P1_7 USB0_PWR_EN, USB0 VBus function Xplorer */
187 Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 5, 6); /* GPIO5[6] = USB1_PWR_EN */
188 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 5, 6, true); /* GPIO5[6] output high */
189
190 /* Initialize LEDs */
191 Board_LED_Init();
192 #if defined(USE_RMII)
193 Chip_ENET_RMIIEnable(LPC_ETHERNET);
194 #else
195 Chip_ENET_MIIEnable(LPC_ETHERNET);
196 #endif
197 }
198
199 void Board_I2C_Init(I2C_ID_T id)
200 {
201 if (id == I2C1) {
202 /* Configure pin function for I2C1*/
203 Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.3 : I2C1_SDA */
204 Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.4 : I2C1_SCL */
205 }
206 else {
207 Chip_SCU_I2C0PinConfig(I2C0_STANDARD_FAST_MODE);
208 }
209 }
210
211 void Board_SDMMC_Init(void)
212 {
213 Chip_SCU_PinMuxSet(0x1, 9, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.9 connected to SDIO_D0 */
214 Chip_SCU_PinMuxSet(0x1, 10, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.10 connected to SDIO_D1 */
215 Chip_SCU_PinMuxSet(0x1, 11, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.11 connected to SDIO_D2 */
216 Chip_SCU_PinMuxSet(0x1, 12, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.12 connected to SDIO_D3 */
217
218 Chip_SCU_ClockPinMuxSet(2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* CLK2 connected to SDIO_CLK */
219 Chip_SCU_PinMuxSet(0x1, 6, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.6 connected to SDIO_CMD */
220 }
221
222 void Board_SSP_Init(LPC_SSP_T *pSSP)
223 {
224 if (pSSP == LPC_SSP1) {
225 /* Set up clock and power for SSP1 module */
226 /* Configure SSP1 pins*/
227 /* SCLK comes out pin CLK0 */
228 Chip_SCU_ClockPinMuxSet(0, (SCU_PINIO_FAST | SCU_MODE_FUNC6)); /* CLK0 connected to CLK SCU_MODE_FUNC6=SSP1 CLK1 */
229 Chip_SCU_PinMuxSet(0x1, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC5)); /* P1.5 connected to nCS SCU_MODE_FUNC5=SSP1 SSEL1 */
230 Chip_SCU_PinMuxSet(0x1, 3, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));/* P1.3 connected to SO SCU_MODE_FUNC5=SSP1 MISO1 */
231 Chip_SCU_PinMuxSet(0x1, 4, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));/* P1.4 connected to nSI SCU_MODE_FUNC5=SSP1 MOSI1 */
232 }
233 else {
234 return;
235 }
236 }
237
238 static void delay(uint32_t i) {
239 while (i--) {}
240 }
241
242 /* Initialize Audio Codec */
243 static Status Board_Audio_CodecInit(int micIn)
244 {
245 /* Reset UDA1380 on board NGX Xplorer */
246 Chip_SCU_PinMuxSet(0x2, 10, (SCU_MODE_PULLUP | SCU_MODE_FUNC0));
247 Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 14);
248 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, true);
249 // delay 1us
250 delay(100000);
251 Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, false);
252 delay(100000);
253
254 if (!UDA1380_Init(UDA1380_MIC_IN_LR & - (micIn != 0))) {
255 return ERROR;
256 }
257
258 return SUCCESS;
259 }
260
261 /* Board Audio initialization */
262 void Board_Audio_Init(LPC_I2S_T *pI2S, int micIn)
263 {
264 I2S_AUDIO_FORMAT_T I2S_Config;
265
266 I2S_Config.SampleRate = 48000;
267 I2S_Config.ChannelNumber = 2; /* 1 is mono, 2 is stereo */
268 I2S_Config.WordWidth = 16; /* 8, 16 or 32 bits */
269 Chip_I2S_Init(pI2S);
270 Chip_I2S_TxConfig(pI2S, &I2S_Config);
271
272 /* Init UDA1380 CODEC */
273 while (Board_Audio_CodecInit(micIn) != SUCCESS) {}
274 }
275