2 * Copyright(C) NXP Semiconductors, 2012
\r
3 * All rights reserved.
\r
5 * Software that is described herein is for illustrative purposes only
\r
6 * which provides customers with programming information regarding the
\r
7 * LPC products. This software is supplied "AS IS" without any warranties of
\r
8 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
9 * all warranties, express or implied, including all implied warranties of
\r
10 * merchantability, fitness for a particular purpose and non-infringement of
\r
11 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
12 * or liability for the use of the software, conveys no license or rights under any
\r
13 * patent, copyright, mask work right, or any other intellectual property rights in
\r
14 * or to any products. NXP Semiconductors reserves the right to make changes
\r
15 * in the software without notification. NXP Semiconductors also makes no
\r
16 * representation or warranty that such application will be suitable for the
\r
17 * specified use without further testing or modification.
\r
19 * Permission to use, copy, modify, and distribute this software and its
\r
20 * documentation is hereby granted, under NXP Semiconductors' and its
\r
21 * licensor's relevant copyrights in the software, without fee, provided that it
\r
22 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
23 * copyright, permission, and disclaimer notice must appear in all copies of
\r
30 //#include "lpc_phy_smsc87x0.c"
\r
31 //#include "retarget.c"
\r
33 /** @ingroup BOARD_NGX_XPLORER_18304330
\r
37 void Board_UART_Init(LPC_USART_T *pUART)
\r
39 if (pUART == LPC_USART0) {
\r
40 Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC2)); /* P6.5 : UART0_TXD */
\r
41 Chip_SCU_PinMuxSet(0x6, 5, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2));/* P6.4 : UART0_RXD */
\r
43 else if (pUART == LPC_UART1) {
\r
44 Chip_SCU_PinMuxSet(0x1, 13, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC2)); /* P1.13 : UART1_TXD */
\r
45 Chip_SCU_PinMuxSet(0x1, 14, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P1.14 : UART1_RX */
\r
49 /* Initialize debug output via UART for board */
\r
50 void Board_Debug_Init(void)
\r
52 #if defined(DEBUG_UART)
\r
53 Board_UART_Init(DEBUG_UART);
\r
55 Chip_UART_Init(DEBUG_UART);
\r
56 Chip_UART_SetBaud(DEBUG_UART, 115200);
\r
57 Chip_UART_ConfigData(DEBUG_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);
\r
59 /* Enable UART Transmit */
\r
60 Chip_UART_TxCmd(DEBUG_UART, ENABLE);
\r
64 /* Sends a character on the UART */
\r
65 void Board_UARTPutChar(char ch)
\r
67 #if defined(DEBUG_UART)
\r
68 while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {}
\r
72 /* Gets a character from the UART, returns EOF if no character is ready */
\r
73 int Board_UARTGetChar(void)
\r
75 #if defined(DEBUG_UART)
\r
78 if (Chip_UART_ReceiveByte(DEBUG_UART, &data) == SUCCESS) {
\r
85 /* Outputs a string on the debug UART */
\r
86 void Board_UARTPutSTR(char *str)
\r
88 #if defined(DEBUG_UART)
\r
89 while (*str != '\0') {
\r
90 Board_UARTPutChar(*str++);
\r
95 static void Board_LED_Init()
\r
97 /* P2.12 : LED D2 as output */
\r
98 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 1, 12, true);
\r
100 /* P2.11 : LED D3 as output */
\r
101 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 1, 11, true);
\r
103 /* Set initial states to off (true to disable) */
\r
104 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 1, 12, (bool) true);
\r
105 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 1, 11, (bool) true);
\r
108 void Board_LED_Set(uint8_t LEDNumber, bool On)
\r
110 if (LEDNumber == 0) {
\r
111 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 1, 12, (bool) !On);
\r
113 else if (LEDNumber == 1) {
\r
114 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 1, 11, (bool) !On);
\r
118 bool Board_LED_Test(uint8_t LEDNumber)
\r
120 if (LEDNumber == 0) {
\r
121 return (bool) !Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 1, 12);
\r
123 else if (LEDNumber == 1) {
\r
124 return (bool) !Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 1, 11);
\r
130 void Board_Buttons_Init(void) // FIXME not functional ATM
\r
132 Chip_SCU_PinMuxSet(0x2, 7, (SCU_MODE_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0)); // P2_7 as GPIO0[7]
\r
133 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, (1 << BUTTONS_BUTTON1_GPIO_BIT_NUM), false); // input
\r
136 uint32_t Buttons_GetStatus(void)
\r
138 uint8_t ret = NO_BUTTON_PRESSED;
\r
139 if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM) == 0) {
\r
140 ret |= BUTTONS_BUTTON1;
\r
145 void Board_Joystick_Init(void)
\r
148 uint8_t Joystick_GetStatus(void)
\r
150 return NO_BUTTON_PRESSED;
\r
153 /*!< System Clock Frequency (Core Clock)*/
\r
154 uint32_t SystemCoreClock;
\r
156 /* Update system core clock rate, should be called if the system has
\r
157 a clock rate change */
\r
158 void SystemCoreClockUpdate(void)
\r
160 /* CPU core speed */
\r
161 SystemCoreClock = Chip_Clock_GetRate(CLK_MX_MXCORE);
\r
164 /* Returns the MAC address assigned to this board */
\r
165 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
\r
167 uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
\r
169 memcpy(mcaddr, boardmac, 6);
\r
172 /* Set up and initialize all required blocks and functions related to the
\r
174 void Board_Init(void)
\r
176 /* Sets up DEBUG UART */
\r
179 /* Updates SystemCoreClock global var with current clock speed */
\r
180 SystemCoreClockUpdate();
\r
182 /* Initializes GPIO */
\r
183 Chip_GPIO_Init(LPC_GPIO_PORT);
\r
185 /* Setup GPIOs for USB demos */
\r
186 Chip_SCU_PinMuxSet(0x2, 6, (SCU_MODE_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* P2_6 USB1_PWR_EN, USB1 VBus function */
\r
187 Chip_SCU_PinMuxSet(0x2, 5, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
\r
188 Chip_SCU_PinMuxSet(0x1, 7, (SCU_MODE_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* P1_7 USB0_PWR_EN, USB0 VBus function Xplorer */
\r
189 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 5, 6, true); /* GPIO5[6] = USB1_PWR_EN */
\r
190 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 5, 6, true); /* GPIO5[6] output high */
\r
192 /* Initialize LEDs */
\r
196 void Board_I2C_Init(I2C_ID_T id)
\r
199 /* Configure pin function for I2C1*/
\r
200 Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.3 : I2C1_SDA */
\r
201 Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.4 : I2C1_SCL */
\r
204 Chip_SCU_I2C0PinConfig(I2C0_STANDARD_FAST_MODE);
\r
209 /* PIN0 Interrupt not available in M0 core */
\r
210 void GPIO0_IRQHandler(void)
\r
214 if (Chip_GPIO_IntGetStatus(LPC_GPIO_PIN_INT, 0, 0, 0)) {
\r
215 Chip_GPIO_IntClear(LPC_GPIO_PIN_INT, 0, 0);
\r
217 Board_LED_Set(1, On);
\r
221 void Board_GPIO_Int_Init()
\r
223 Chip_SCU_PinMuxSet(0xF, 9, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0)); /* PF.9 : POTI button */
\r
224 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 7, 23, false); /* PF.9 -> GPIO7[23] : input */
\r
225 Chip_SCU_GPIOIntPinSel(0, 7, 23);
\r
226 Chip_GPIO_IntCmd(LPC_GPIO_PIN_INT, 0, 0, GPIOPININT_FALLING_EDGE); /* Configure GPIO0[7] to interrupt pin (SW2 switch) */
\r
228 NVIC_EnableIRQ(PIN_INT0_IRQn); /* enable GPIO interrupt 0 */
\r
233 void Board_SDMMC_Init(void)
\r
235 Chip_SCU_PinMuxSet(0x1, 9, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.9 connected to SDIO_D0 */
\r
236 Chip_SCU_PinMuxSet(0x1, 10, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.10 connected to SDIO_D1 */
\r
237 Chip_SCU_PinMuxSet(0x1, 11, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.11 connected to SDIO_D2 */
\r
238 Chip_SCU_PinMuxSet(0x1, 12, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.12 connected to SDIO_D3 */
\r
240 Chip_SCU_ClockPinMuxSet(2, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* CLK2 connected to SDIO_CLK */
\r
241 Chip_SCU_PinMuxSet(0x1, 6, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.6 connected to SDIO_CMD */
\r
244 void Board_SSP_Init(LPC_SSP_T *pSSP)
\r
246 if (pSSP == LPC_SSP1) {
\r
247 /* Set up clock and power for SSP1 module */
\r
248 /* Configure SSP1 pins*/
\r
249 /* SCLK comes out pin CLK0 */
\r
250 Chip_SCU_ClockPinMuxSet(0, (SCU_PINIO_FAST | SCU_MODE_FUNC6)); /* CLK0 connected to CLK SCU_MODE_FUNC6=SSP1 CLK1 */
\r
251 Chip_SCU_PinMuxSet(0x1, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC5)); /* P1.5 connected to nCS SCU_MODE_FUNC5=SSP1 SSEL1 */
\r
252 Chip_SCU_PinMuxSet(0x1, 3, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));/* P1.3 connected to SO SCU_MODE_FUNC5=SSP1 MISO1 */
\r
253 Chip_SCU_PinMuxSet(0x1, 4, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));/* P1.4 connected to nSI SCU_MODE_FUNC5=SSP1 MOSI1 */
\r
260 static void delay(uint32_t i) {
\r
264 /* Initialize Audio Codec */
\r
265 static Status Board_Audio_CodecInit(int micIn)
\r
267 /* Reset UDA1380 on board NGX Xplorer */
\r
268 Chip_SCU_PinMuxSet(0x2, 10, (SCU_MODE_MODE_INACT | SCU_MODE_FUNC0));
\r
269 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 0, 14, true);
\r
270 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 0, 14, true);
\r
273 Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 0, 14, false);
\r
276 if (!UDA1380_Init(UDA1380_MIC_IN_LR & - (micIn != 0))) {
\r
283 /* Board Audio initialization */
\r
284 void Board_Audio_Init(LPC_I2S_T *pI2S, int micIn)
\r
286 Chip_I2S_Audio_Format_T I2S_Config;
\r
288 I2S_Config.SampleRate = 48000;
\r
289 I2S_Config.ChannelNumber = 2; /* 1 is mono, 2 is stereo */
\r
290 I2S_Config.WordWidth = 16; /* 8, 16 or 32 bits */
\r
291 Chip_I2S_Init(pI2S);
\r
292 Chip_I2S_Config(pI2S, I2S_TX_MODE, &I2S_Config);
\r
294 /* Init UDA1380 CODEC */
\r
295 while (Board_Audio_CodecInit(micIn) != SUCCESS) {}
\r
298 /* FIXME Should we remove this function? */
\r
299 void Serial_CreateStream(void *Stream)
\r