| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_nxp_xpresso_1769.c
Go to the documentation of this file.
1 /*
2 * @brief NXP LPC1769 Xpresso board 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 #include "string.h"
34
35 #include "lpc_phy_smsc87x0.c"
36 #include "retarget.c"
37
42 /*****************************************************************************
43 * Private types/enumerations/variables
44 ****************************************************************************/
45 #define BUTTONS_BUTTON1_GPIO_PORT_NUM 2
46 #define BUTTONS_BUTTON1_GPIO_BIT_NUM 10
47 #define JOYSTICK_UP_GPIO_PORT_NUM 2
48 #define JOYSTICK_UP_GPIO_BIT_NUM 3
49 #define JOYSTICK_DOWN_GPIO_PORT_NUM 0
50 #define JOYSTICK_DOWN_GPIO_BIT_NUM 15
51 #define JOYSTICK_LEFT_GPIO_PORT_NUM 2
52 #define JOYSTICK_LEFT_GPIO_BIT_NUM 4
53 #define JOYSTICK_RIGHT_GPIO_PORT_NUM 0
54 #define JOYSTICK_RIGHT_GPIO_BIT_NUM 16
55 #define JOYSTICK_PRESS_GPIO_PORT_NUM 0
56 #define JOYSTICK_PRESS_GPIO_BIT_NUM 17
57 #define LED0_GPIO_PORT_NUM 0
58 #define LED0_GPIO_BIT_NUM 22
59
60 /*****************************************************************************
61 * Public types/enumerations/variables
62 ****************************************************************************/
63
65 uint32_t SystemCoreClock;
66
67 /*****************************************************************************
68 * Private functions
69 ****************************************************************************/
70
71 /* Initializes board LED(s) */
72 static void Board_LED_Init(void)
73 {
74 /* Pin PIO0_22 is configured as GPIO pin during SystemInit */
75 /* Set the PIO_22 as output */
76 Chip_GPIO_WriteDirBit(LPC_GPIO, LED0_GPIO_PORT_NUM, LED0_GPIO_BIT_NUM, true);
77 }
78
79 /*****************************************************************************
80 * Public functions
81 ****************************************************************************/
82
83 /* Update system core clock rate, should be called if the system has
84 a clock rate change */
85 void SystemCoreClockUpdate(void)
86 {
87 /* CPU core speed */
88 SystemCoreClock = Chip_Clock_GetSystemClockRate();
89 }
90
91 /* Initialize UART pins */
92 void Board_UART_Init(LPC_USART_T *pUART)
93 {
94 /* Pin Muxing has already been done during SystemInit */
95 }
96
97 /* Initialize debug output via UART for board */
98 void Board_Debug_Init(void)
99 {
100 #if defined(DEBUG_ENABLE)
101 Board_UART_Init(DEBUG_UART);
102
103 /* Setup UART for 115.2K8N1 */
104 Chip_UART_Init(DEBUG_UART);
105 Chip_UART_SetBaud(DEBUG_UART, 115200);
106 Chip_UART_ConfigData(DEBUG_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);
107
108 /* Enable UART Transmit */
109 Chip_UART_TxCmd(DEBUG_UART, ENABLE);
110 #endif
111 }
112
113 /* Sends a character on the UART */
114 void Board_UARTPutChar(char ch)
115 {
116 #if defined(DEBUG_ENABLE)
117 while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {}
118 #endif
119 }
120
121 /* Gets a character from the UART, returns EOF if no character is ready */
122 int Board_UARTGetChar(void)
123 {
124 #if defined(DEBUG_ENABLE)
125 uint8_t data;
126
127 if (Chip_UART_ReceiveByte(DEBUG_UART, &data) == SUCCESS) {
128 return (int) data;
129 }
130 #endif
131 return EOF;
132 }
133
134 /* Outputs a string on the debug UART */
135 void Board_UARTPutSTR(char *str)
136 {
137 #if defined(DEBUG_ENABLE)
138 while (*str != '\0') {
139 Board_UARTPutChar(*str++);
140 }
141 #endif
142 }
143
144 /* Sets the state of a board LED to on or off */
145 void Board_LED_Set(uint8_t LEDNumber, bool On)
146 {
147 /* There is only one LED */
148 if (LEDNumber == 0) {
149 Chip_GPIO_WritePortBit(LPC_GPIO, LED0_GPIO_PORT_NUM, LED0_GPIO_BIT_NUM, On);
150 }
151 }
152
153 /* Returns the current state of a board LED */
154 bool Board_LED_Test(uint8_t LEDNumber)
155 {
156 return Chip_GPIO_ReadPortBit(LPC_GPIO, LED0_GPIO_PORT_NUM, LED0_GPIO_BIT_NUM);
157 }
158
159 /* Set up and initialize all required blocks and functions related to the
160 board hardware */
161 void Board_Init(void)
162 {
163 /* Sets up DEBUG UART */
164 DEBUGINIT();
165
166 /* Updates SystemCoreClock global var with current clock speed */
167 SystemCoreClockUpdate();
168
169 /* Initializes GPIO */
170 Chip_GPIO_Init(LPC_GPIO);
171 Chip_IOCON_Init(LPC_IOCON);
172
173 /* Initialize LEDs */
174 Board_LED_Init();
175 }
176
177 /* Returns the MAC address assigned to this board */
178 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
179 {
180 const uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
181
182 memcpy(mcaddr, boardmac, 6);
183 }
184
185 /* Initialize pin muxing for SSP interface */
186 void Board_SSP_Init(LPC_SSP_T *pSSP)
187 {
188 if (pSSP == LPC_SSP1) {
189 /* Set up clock and muxing for SSP1 interface */
190 /*
191 * Initialize SSP0 pins connect
192 * P0.7: SCK
193 * P0.6: SSEL
194 * P0.8: MISO
195 * P0.9: MOSI
196 */
197 Chip_IOCON_PinMux(LPC_IOCON, 0, 7, IOCON_MODE_INACT, IOCON_FUNC2);
198 Chip_IOCON_PinMux(LPC_IOCON, 0, 6, IOCON_MODE_INACT, IOCON_FUNC2);
199 Chip_IOCON_PinMux(LPC_IOCON, 0, 8, IOCON_MODE_INACT, IOCON_FUNC2);
200 Chip_IOCON_PinMux(LPC_IOCON, 0, 9, IOCON_MODE_INACT, IOCON_FUNC2);
201 }
202 else {
203 /* Set up clock and muxing for SSP0 interface */
204 /*
205 * Initialize SSP0 pins connect
206 * P0.15: SCK
207 * P0.16: SSEL
208 * P0.17: MISO
209 * P0.18: MOSI
210 */
211 Chip_IOCON_PinMux(LPC_IOCON, 0, 15, IOCON_MODE_INACT, IOCON_FUNC2);
212 Chip_IOCON_PinMux(LPC_IOCON, 0, 16, IOCON_MODE_INACT, IOCON_FUNC2);
213 Chip_IOCON_PinMux(LPC_IOCON, 0, 17, IOCON_MODE_INACT, IOCON_FUNC2);
214 Chip_IOCON_PinMux(LPC_IOCON, 0, 18, IOCON_MODE_INACT, IOCON_FUNC2);
215 }
216 }
217
218 /* Initialize pin muxing for SPI interface */
219 void Board_SPI_Init(bool isMaster)
220 {
221 /* Set up clock and muxing for SSP0 interface */
222 /*
223 * Initialize SSP0 pins connect
224 * P0.15: SCK
225 * P0.16: SSEL
226 * P0.17: MISO
227 * P0.18: MOSI
228 */
229 Chip_IOCON_PinMux(LPC_IOCON, 0, 15, IOCON_MODE_PULLDOWN, IOCON_FUNC3);
230 if (isMaster) {
231 Chip_IOCON_PinMux(LPC_IOCON, 0, 16, IOCON_MODE_PULLUP, IOCON_FUNC0);
232 Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 16, true);
233 Board_SPI_DeassertSSEL();
234
235 }
236 else {
237 Chip_IOCON_PinMux(LPC_IOCON, 0, 16, IOCON_MODE_PULLUP, IOCON_FUNC3);
238 }
239 Chip_IOCON_PinMux(LPC_IOCON, 0, 17, IOCON_MODE_INACT, IOCON_FUNC3);
240 Chip_IOCON_PinMux(LPC_IOCON, 0, 18, IOCON_MODE_INACT, IOCON_FUNC3);
241 }
242
243 /* Assert SSEL pin */
244 void Board_SPI_AssertSSEL(void)
245 {
246 Chip_GPIO_WritePortBit(LPC_GPIO, 0, 16, false);
247 }
248
249 /* De-Assert SSEL pin */
250 void Board_SPI_DeassertSSEL(void)
251 {
252 Chip_GPIO_WritePortBit(LPC_GPIO, 0, 16, true);
253 }
254
255 void Board_Audio_Init(uint8_t audio_in_sel)
256 {}
257
258 /* Sets up board specific I2C interface */
259 void Board_I2C_Init(I2C_ID_T id)
260 {
261 switch (id) {
262 case I2C0:
263 Chip_IOCON_PinMux(LPC_IOCON, 0, 27, IOCON_MODE_INACT, IOCON_FUNC1);
264 Chip_IOCON_PinMux(LPC_IOCON, 0, 28, IOCON_MODE_INACT, IOCON_FUNC1);
265 Chip_IOCON_SetI2CPad(LPC_IOCON, I2CPADCFG_STD_MODE);
266 break;
267
268 case I2C1:
269 Chip_IOCON_PinMux(LPC_IOCON, 0, 19, IOCON_MODE_INACT, IOCON_FUNC2);
270 Chip_IOCON_PinMux(LPC_IOCON, 0, 20, IOCON_MODE_INACT, IOCON_FUNC2);
271 Chip_IOCON_EnableOD(LPC_IOCON, 0, 19);
272 Chip_IOCON_EnableOD(LPC_IOCON, 0, 20);
273 break;
274
275 case I2C2:
276 Chip_IOCON_PinMux(LPC_IOCON, 0, 10, IOCON_MODE_INACT, IOCON_FUNC2);
277 Chip_IOCON_PinMux(LPC_IOCON, 0, 11, IOCON_MODE_INACT, IOCON_FUNC2);
278 Chip_IOCON_EnableOD(LPC_IOCON, 0, 10);
279 Chip_IOCON_EnableOD(LPC_IOCON, 0, 11);
280 break;
281 }
282 }
283
284 void Board_Buttons_Init(void)
285 {
286 Chip_GPIO_WriteDirBit(LPC_GPIO, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM, false);
287 }
288
289 uint32_t Buttons_GetStatus(void)
290 {
291 uint8_t ret = NO_BUTTON_PRESSED;
292 if (Chip_GPIO_ReadPortBit(LPC_GPIO, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM) == 0x00) {
293 ret |= BUTTONS_BUTTON1;
294 }
295 return ret;
296 }
297
298 void Board_Joystick_Init(void)
299 {
300 Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0);
301 Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0);
302 Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0);
303 Chip_IOCON_PinMux(LPC_IOCON,
304 JOYSTICK_RIGHT_GPIO_PORT_NUM,
305 JOYSTICK_RIGHT_GPIO_BIT_NUM,
306 IOCON_MODE_INACT,
307 IOCON_FUNC0);
308 Chip_IOCON_PinMux(LPC_IOCON,
309 JOYSTICK_PRESS_GPIO_PORT_NUM,
310 JOYSTICK_PRESS_GPIO_BIT_NUM,
311 IOCON_MODE_INACT,
312 IOCON_FUNC0);
313 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM, false); /* input */
314 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM, false); /* input */
315 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM, false); /* input */
316 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM, false); /* input */
317 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM, false); /* input */
318 }
319
320 uint8_t Joystick_GetStatus(void)
321 {
322 uint8_t ret = NO_BUTTON_PRESSED;
323 if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM)) == 0x00) {
324 ret |= JOY_UP;
325 }
326 else if (Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM) == 0x00) {
327 ret |= JOY_DOWN;
328 }
329 else if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM)) == 0x00) {
330 ret |= JOY_LEFT;
331 }
332 else if (Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM) == 0x00) {
333 ret |= JOY_RIGHT;
334 }
335 else if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM)) == 0x00) {
336 ret |= JOY_PRESS;
337 }
338 return ret;
339 }
340
341 void Serial_CreateStream(void *Stream)
342 {}