LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 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 
38 {
39  if (pUART == LPC_USART0) {
40  Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC2)); /* P6.5 : UART0_TXD */
42  }
43  else if (pUART == LPC_UART1) {
44  Chip_SCU_PinMuxSet(0x1, 13, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC2)); /* P1.13 : UART1_TXD */
46  }
47 }
48 
49 /* Initialize debug output via UART for board */
50 void Board_Debug_Init(void)
51 {
52 #if defined(DEBUG_UART)
54 
58 
59  /* Enable UART Transmit */
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 */
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 static void Board_LED_Init()
96 {
97  /* P2.12 : LED D2 as output */
99 
100  /* P2.11 : LED D3 as output */
101  Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 1, 11, true);
102 
103  /* Set initial states to off (true to disable) */
104  Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 1, 12, (bool) true);
105  Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 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(LPC_GPIO_PORT, 1, 12, (bool) !On);
112  }
113  else if (LEDNumber == 1) {
114  Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 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(LPC_GPIO_PORT, 1, 12);
122  }
123  else if (LEDNumber == 1) {
124  return (bool) !Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 1, 11);
125  }
126 
127  return false;
128 }
129 
130 void Board_Buttons_Init(void) // FIXME not functional ATM
131 {
134 }
135 
137 {
138  uint8_t ret = NO_BUTTON_PRESSED;
140  ret |= BUTTONS_BUTTON1;
141  }
142  return ret;
143 }
144 
146 {}
147 
148 uint8_t Joystick_GetStatus(void)
149 {
150  return NO_BUTTON_PRESSED;
151 }
152 
155 
156 /* Update system core clock rate, should be called if the system has
157  a clock rate change */
159 {
160  /* CPU core speed */
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 */
181 
182  /* Initializes GPIO */
184 
185  /* Setup GPIOs for USB demos */
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 */
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 */
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 */
189  Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 5, 6, true); /* GPIO5[6] = USB1_PWR_EN */
190  Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 5, 6, true); /* GPIO5[6] output high */
191 
192  /* Initialize LEDs */
193  Board_LED_Init();
194 }
195 
197 {
198  if (id == I2C1) {
199  /* Configure pin function for I2C1*/
200  Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.3 : I2C1_SDA */
201  Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.4 : I2C1_SCL */
202  }
203  else {
205  }
206 }
207 
208 #ifndef CORE_M0
209 /* PIN0 Interrupt not available in M0 core */
211 {
212  static bool On;
213 
216  On = (bool) !On;
217  Board_LED_Set(1, On);
218  }
219 }
220 
222 {
224  Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 7, 23, false); /* PF.9 -> GPIO7[23] : input */
225  Chip_SCU_GPIOIntPinSel(0, 7, 23);
226  Chip_GPIO_IntCmd(LPC_GPIO_PIN_INT, 0, 0, GPIOPININT_FALLING_EDGE); /* Configure GPIO0[7] to interrupt pin (SW2 switch) */
227 
228  NVIC_EnableIRQ(PIN_INT0_IRQn); /* enable GPIO interrupt 0 */
229 }
230 
231 #endif
232 
234 {
235  Chip_SCU_PinMuxSet(0x1, 9, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.9 connected to SDIO_D0 */
236  Chip_SCU_PinMuxSet(0x1, 10, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.10 connected to SDIO_D1 */
237  Chip_SCU_PinMuxSet(0x1, 11, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.11 connected to SDIO_D2 */
238  Chip_SCU_PinMuxSet(0x1, 12, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.12 connected to SDIO_D3 */
239 
240  Chip_SCU_ClockPinMuxSet(2, (SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* CLK2 connected to SDIO_CLK */
241  Chip_SCU_PinMuxSet(0x1, 6, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* P1.6 connected to SDIO_CMD */
242 }
243 
245 {
246  if (pSSP == LPC_SSP1) {
247  /* Set up clock and power for SSP1 module */
248  /* Configure SSP1 pins*/
249  /* SCLK comes out pin CLK0 */
250  Chip_SCU_ClockPinMuxSet(0, (SCU_PINIO_FAST | SCU_MODE_FUNC6)); /* CLK0 connected to CLK SCU_MODE_FUNC6=SSP1 CLK1 */
251  Chip_SCU_PinMuxSet(0x1, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC5)); /* P1.5 connected to nCS SCU_MODE_FUNC5=SSP1 SSEL1 */
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 */
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 */
254  }
255  else {
256  return;
257  }
258 }
259 
260 static void delay(uint32_t i) {
261  while (i--) {}
262 }
263 
264 /* Initialize Audio Codec */
265 static Status Board_Audio_CodecInit(int micIn)
266 {
267  /* Reset UDA1380 on board NGX Xplorer */
269  Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 0, 14, true);
271  // delay 1us
272  delay(100000);
273  Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 0, 14, false);
274  delay(100000);
275 
276  if (!UDA1380_Init(UDA1380_MIC_IN_LR & - (micIn != 0))) {
277  return ERROR;
278  }
279 
280  return SUCCESS;
281 }
282 
283 /* Board Audio initialization */
284 void Board_Audio_Init(LPC_I2S_T *pI2S, int micIn)
285 {
286  Chip_I2S_Audio_Format_T I2S_Config;
287 
288  I2S_Config.SampleRate = 48000;
289  I2S_Config.ChannelNumber = 2; /* 1 is mono, 2 is stereo */
290  I2S_Config.WordWidth = 16; /* 8, 16 or 32 bits */
291  Chip_I2S_Init(pI2S);
292  Chip_I2S_Config(pI2S, I2S_TX_MODE, &I2S_Config);
293 
294  /* Init UDA1380 CODEC */
295  while (Board_Audio_CodecInit(micIn) != SUCCESS) {}
296 }
297 
298 /* FIXME Should we remove this function? */
299 void Serial_CreateStream(void *Stream)
300 {}
301