| 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_ea_devkit_17884088.c
Go to the documentation of this file.
1 /*
2 * @brief Embedded Artists LPC1788 and LPC4088 Development Kit 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 /* EA1788 and EA4088 board uses 8720 PHY and retarget */
36 #include "lpc_phy_smsc87x0.c"
37 #include "lpc_norflash_sst39vf320.c"
38 #include "lpc_nandflash_k9f1g.c"
39 #include "retarget.c"
40
45 /*****************************************************************************
46 * Private types/enumerations/variables
47 ****************************************************************************/
48
49 #if defined(CHIP_LPC177X_8X)
50 #define LCD_SSP_CTRL LPC_SSP0
51 #elif defined(CHIP_LPC407X_8X)
52 #define LCD_SSP_CTRL LPC_SSP2
53 #endif
54
55 /* No. of TSC conversion bits */
56 #define TSC2046_CONVERSION_BITS 12
57
58 /* Touchscreen TSC2046 control byte definitions */
59 #define TSC_START (0x01 << 7)
60 #define TSC_CHANNEL_X (0x05 << 4) /* differential */
61 #define TSC_CHANNEL_Y (0x01 << 4) /* differential */
62 #define TSC_CHANNEL_Z1 (0x03 << 4) /* differential */
63 #define TSC_CHANNEL_Z2 (0x04 << 4) /* differential */
64 #define TSC_8BIT (0x01 << 3)
65 #define TSC_12BIT (0x00 << 3)
66 #define TSC_PD 0x00
67 #define TSC_ADC_ON 0x01
68 #define TSC_REF_ON 0x02
69 #if (TSC2046_CONVERSION_BITS == 12)
70 #define TSC_CONVERSION_MODE TSC_12BIT
71 #else
72 #define TSC_CONVERSION_MODE TSC_8BIT
73 #endif
74
75 #define TSC_SER_MODE (0x01 << 2) /* Single-Ended Reference Mode */
76 #define TSC_DFR_MODE (0x00 << 2) /* Differential Reference Mode */
77
78 #define X_MEASURE (TSC_START | TSC_CHANNEL_X | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
79 #define Y_MEASURE (TSC_START | TSC_CHANNEL_Y | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
80 #define Z1_MEASURE (TSC_START | TSC_CHANNEL_Z1 | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
81 #define Z2_MEASURE (TSC_START | TSC_CHANNEL_Z2 | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
82 #define PWRDOWN (TSC_START | TSC_CHANNEL_Y | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_PD)
83 #if (TSC2046_CONVERSION_BITS == 12)
84 #define TSC2046_COORD_MAX (0xFFF)
85 #define TSC2046_DELTA_VARIANCE (0x50)
86 #else
87 #define TSC2046_COORD_MAX (0xFF)
88 #define TSC2046_DELTA_VARIANCE (0x03)
89 #endif
90 #define COORD_GET_NUM (10)
91 #define TSC2046_CS_PORTNUM 0
92 #define TSC2046_CS_PINNUM 20
93 #define TSC2046_DC_PORTNUM 0
94 #define TSC2046_DC_PINNUM 19
95 #define LCD_DC_CMD (Chip_GPIO_WritePortBit(LPC_GPIO, TSC2046_DC_PORTNUM, TSC2046_DC_PINNUM, false))
96 #define LCD_DC_DATA (Chip_GPIO_WritePortBit(LPC_GPIO, TSC2046_DC_PORTNUM, TSC2046_DC_PINNUM, true))
97 #define TSC_CS_ON (Chip_GPIO_WritePortBit(LPC_GPIO, TSC2046_CS_PORTNUM, TSC2046_CS_PINNUM, false))
98 #define TSC_CS_OFF (Chip_GPIO_WritePortBit(LPC_GPIO, TSC2046_CS_PORTNUM, TSC2046_CS_PINNUM, true))
99
100 #define LCD_BACKLIGHT_PORTNUM 1
101 #define LCD_BACKLIGHT_PINNUM 18
102
103 #define BUTTONS_BUTTON1_GPIO_PORT_NUM 2
104 #define BUTTONS_BUTTON1_GPIO_BIT_NUM 10
105 #define JOYSTICK_UP_GPIO_PORT_NUM 2
106 #define JOYSTICK_UP_GPIO_BIT_NUM 26
107 #define JOYSTICK_DOWN_GPIO_PORT_NUM 2
108 #define JOYSTICK_DOWN_GPIO_BIT_NUM 23
109 #define JOYSTICK_LEFT_GPIO_PORT_NUM 2
110 #define JOYSTICK_LEFT_GPIO_BIT_NUM 25
111 #define JOYSTICK_RIGHT_GPIO_PORT_NUM 2
112 #define JOYSTICK_RIGHT_GPIO_BIT_NUM 27
113 #define JOYSTICK_PRESS_GPIO_PORT_NUM 2
114 #define JOYSTICK_PRESS_GPIO_BIT_NUM 22
115
116 #define NUM_LEDS 2
117
118 typedef struct {
119 int16_t ad_left; /* left margin */
120 int16_t ad_right; /* right margin */
121 int16_t ad_top; /* top margin */
122 int16_t ad_bottom; /* bottom margin */
123 int16_t lcd_width; /* lcd horizontal size */
124 int16_t lcd_height; /* lcd vertical size */
125 uint8_t swap_xy; /* 1: swap x-y coords */
126 } TSC2046_Init_T;
127
129 static TSC2046_Init_T TSC_Config = {
130 3758, 149, 3914, 163, 240, 320, 1
131 };
132
136 const LCD_Config_T EA320x240 = {
137 28, /* Horizontal back porch in clocks */
138 10, /* Horizontal front porch in clocks */
139 2, /* HSYNC pulse width in clocks */
140 240, /* Pixels per line */
141 2, /* Vertical back porch in clocks */
142 1, /* Vertical front porch in clocks */
143 2, /* VSYNC pulse width in clocks */
144 320, /* Lines per panel */
145 0, /* Invert output enable, 1 = invert */
146 1, /* Invert panel clock, 1 = invert */
147 1, /* Invert HSYNC, 1 = invert */
148 1, /* Invert VSYNC, 1 = invert */
149 1, /* AC bias frequency in clocks (not used) */
150 6, /* Maximum bits per pixel the display supports */
151 LCD_TFT, /* LCD panel type */
152 LCD_COLOR_FORMAT_BGR, /* BGR or RGB */
153 0 /* Dual panel, 1 = dual panel display */
154 };
155
156 /* LEDs on port 2 */
157 static const uint8_t ledBits[NUM_LEDS] = {26, 27};
158
159 /*****************************************************************************
160 * Public types/enumerations/variables
161 ****************************************************************************/
162
164 uint32_t SystemCoreClock;
165
166 /*****************************************************************************
167 * Private functions
168 ****************************************************************************/
169
170 /* Very simple (inaccurate) delay function */
171 static void delay(uint32_t i)
172 {
173 while (i--) {}
174 }
175
176 /* Delay in miliseconds (cclk = 120MHz) */
177 static void delayMs(uint32_t ms)
178 {
179 delay(ms * 40000);
180 }
181
182 /* Additional (SPI) pin configuration for LCD interface signals */
183 /* Write to a LCD register using SPI */
184 static void writeLCDReg(uint16_t addr, uint16_t data)
185 {
186 uint8_t buf[2];
187
188 LCD_DC_CMD;
189
190 buf[0] = 0;
191 buf[1] = (addr & 0xff);
192
193 Chip_SSP_WriteFrames_Blocking(LCD_SSP_CTRL, buf, 2);
194
195 LCD_DC_DATA;
196 buf[0] = (data >> 8);
197 buf[1] = (data & 0xff);
198 Chip_SSP_WriteFrames_Blocking(LCD_SSP_CTRL, buf, 2);
199
200 LCD_DC_CMD;
201
202 buf[0] = (0);
203 buf[1] = (0x22);
204 Chip_SSP_WriteFrames_Blocking(LCD_SSP_CTRL, buf, 2);
205 }
206
207 /* Initialize SSD1289 LCD Controller */
208 static void initSSD1289(void)
209 {
210 writeLCDReg(0x00, 0x0001);
211 delayMs(15);
212 writeLCDReg(0x03, 0x6E3E); /* 0xAEAC */
213 writeLCDReg(0x0C, 0x0007);
214 writeLCDReg(0x0D, 0x000E); /* 0x000F */
215 writeLCDReg(0x0E, 0x2C00); /* 0x2900 */
216 writeLCDReg(0x1E, 0x00AE); /* 0x00B3 */
217 delayMs(15);
218 writeLCDReg(0x07, 0x0021);
219 delayMs(50);
220 writeLCDReg(0x07, 0x0023);
221 delayMs(50);
222 writeLCDReg(0x07, 0x0033);
223 delayMs(50);
224
225 writeLCDReg(0x01, 0x2B3F);
226 writeLCDReg(0x02, 0x0600);
227 writeLCDReg(0x10, 0x0000);
228 delayMs(15);
229 writeLCDReg(0x11, 0xC5B0); /* 0x65b0 */
230 delayMs(20);
231 writeLCDReg(0x05, 0x0000);
232 writeLCDReg(0x06, 0x0000);
233 writeLCDReg(0x16, 0xEF1C);
234 writeLCDReg(0x17, 0x0003);
235 writeLCDReg(0x07, 0x0233);
236 writeLCDReg(0x0B, 0x5312);
237 writeLCDReg(0x0F, 0x0000);
238 writeLCDReg(0x25, 0xE000);
239 delayMs(20);
240 writeLCDReg(0x41, 0x0000);
241 writeLCDReg(0x42, 0x0000);
242 writeLCDReg(0x48, 0x0000);
243 writeLCDReg(0x49, 0x013F);
244 writeLCDReg(0x44, 0xEF00);
245 writeLCDReg(0x45, 0x0000);
246 writeLCDReg(0x46, 0x013F);
247 writeLCDReg(0x4A, 0x0000);
248 writeLCDReg(0x4B, 0x0000);
249 delayMs(20);
250 writeLCDReg(0x30, 0x0707);
251 writeLCDReg(0x31, 0x0704);
252 writeLCDReg(0x32, 0x0005); /* 0x0204 */
253 writeLCDReg(0x33, 0x0402); /* 0x0201 */
254 writeLCDReg(0x34, 0x0203);
255 writeLCDReg(0x35, 0x0204);
256 writeLCDReg(0x36, 0x0204);
257 writeLCDReg(0x37, 0x0401); /* 0x0502 */
258 writeLCDReg(0x3A, 0x0302);
259 writeLCDReg(0x3B, 0x0500);
260 delayMs(20);
261 writeLCDReg(0x22, 0x0000);
262 }
263
264 /* Configure TSC pins */
265 static void configTSC2046Pins(void)
266 {
267 #if defined(CHIP_LPC177X_8X)
268 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC2 | IOCON_MODE_INACT));
269 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_INACT));
270 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC2 | IOCON_MODE_INACT));
271 #elif defined(CHIP_LPC407X_8X)
272 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 2, (IOCON_FUNC2 | IOCON_MODE_INACT));
273 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 1, (IOCON_FUNC2 | IOCON_MODE_INACT));
274 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 0, (IOCON_FUNC2 | IOCON_MODE_INACT));
275 #endif
276
277 /* CS pin */
278 Chip_IOCON_PinMuxSet(LPC_IOCON, TSC2046_CS_PORTNUM, TSC2046_CS_PINNUM, (IOCON_FUNC0 | IOCON_MODE_INACT));
279 Chip_GPIO_WriteDirBit(LPC_GPIO, TSC2046_CS_PORTNUM, TSC2046_CS_PINNUM, true);
280 }
281
282 /* Send/Receive data to/from TSC2046. */
283 static void readWriteTSC2046(uint8_t command, uint16_t *data)
284 {
285 uint8_t rx_data[2], tx_data[1] = {0x00};
286
287 tx_data[0] = command;
288
289 TSC_CS_ON;
290
291 Chip_SSP_WriteFrames_Blocking(LCD_SSP_CTRL, tx_data, 1);
292 Chip_SSP_ReadFrames_Blocking(LCD_SSP_CTRL, rx_data, 2);
293
294 #if (TSC2046_CONVERSION_BITS == 8)
295 *data = (((rx_data[0] << 8) | (rx_data[1])) >> 7) & 0xFF;
296 #else
297 *data = (((rx_data[0] << 8) | rx_data[1]) >> 3) & 0xFFF;
298 #endif
299
300 TSC_CS_OFF;
301 }
302
303 /* Evaluate the coordinates received from TSC2046. */
304 static Status evalTSC2046Coord(uint8_t command, uint16_t *coord)
305 {
306 uint32_t i;
307 uint16_t Tmp = 0, previousTmp;
308 int16_t diff = 0;
309 *coord = 0;
310 for (i = 0; i < COORD_GET_NUM; i++) {
311 previousTmp = Tmp;
312 readWriteTSC2046(command, &Tmp);
313 if (Tmp > TSC2046_COORD_MAX) {
314 return ERROR;
315 }
316 if (i > 0) {
317 diff = Tmp - previousTmp;
318 }
319 if (diff < 0) {
320 diff = 0 - diff;
321 }
322 if (diff > TSC2046_DELTA_VARIANCE) {
323 return ERROR;
324 }
325 *coord += Tmp;
326 }
327 *coord /= COORD_GET_NUM;
328 return SUCCESS;
329 }
330
331 /* Convert the coord received from TSC to a value on truly LCD */
332 static int16_t calibrateTSC2046(int16_t Coord, int16_t MinVal, int16_t MaxVal, int16_t TrueSize)
333 {
334 int16_t tmp;
335 int16_t ret;
336 uint8_t convert = 0;
337
338 /* Swap value? */
339 if (MinVal > MaxVal) {
340 tmp = MaxVal;
341 MaxVal = MinVal;
342 MinVal = tmp;
343 convert = 1;
344 }
345
346 ret = (Coord - MinVal) * TrueSize / (MaxVal - MinVal);
347 if (convert) {
348 ret = TrueSize - ret;
349 }
350
351 return ret;
352 }
353
354 /* Initializes board LED(s) */
355 static void Board_LED_Init(void)
356 {
357 int i;
358
359 /* Setup port direction and initial output state */
360 for (i = 0; i < NUM_LEDS; i++) {
361 Chip_GPIO_WriteDirBit(LPC_GPIO, 2, ledBits[i], true);
362 Chip_GPIO_WritePortBit(LPC_GPIO, 2, ledBits[i], true);
363 }
364 }
365
366 /*****************************************************************************
367 * Public functions
368 ****************************************************************************/
369
370 /* Update system core clock rate, should be called if the system has
371 a clock rate change */
372 void SystemCoreClockUpdate(void)
373 {
374 /* CPU core speed */
375 SystemCoreClock = Chip_Clock_GetSystemClockRate();
376 }
377
378 /* Initialize UART pins */
379 void Board_UART_Init(LPC_USART_T *pUART)
380 {
381 if (pUART == LPC_UART0) {
382 /*
383 * Initialize UART0 pin connect
384 * P0.2: TXD
385 * P0.3: RXD
386 */
387 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 2, (IOCON_FUNC1 | IOCON_MODE_INACT));
388 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 3, (IOCON_FUNC1 | IOCON_MODE_INACT));
389 }
390 else if (pUART == LPC_UART2) {
391 /* Initialize UART2 pin connect */
392 #if defined(CHIP_LPC407X_8X)
393 Chip_IOCON_PinMuxSet(LPC_IOCON, 4, 22, (IOCON_FUNC2 | IOCON_MODE_INACT));
394 Chip_IOCON_PinMuxSet(LPC_IOCON, 4, 23, (IOCON_FUNC2 | IOCON_MODE_INACT));
395 #else
396 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 10, (IOCON_FUNC1 | IOCON_MODE_INACT));
397 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 11, (IOCON_FUNC1 | IOCON_MODE_INACT));
398 #endif
399 }
400 }
401
402 /* Initialize debug output via UART for board */
403 void Board_Debug_Init(void)
404 {
405 #if defined(DEBUG_UART)
406 Board_UART_Init(DEBUG_UART);
407
408 Chip_UART_Init(DEBUG_UART);
409 Chip_UART_SetBaud(DEBUG_UART, 115200);
410 Chip_UART_ConfigData(DEBUG_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);
411
412 /* Enable UART Transmit */
413 Chip_UART_TxCmd(DEBUG_UART, ENABLE);
414 #endif
415 }
416
417 /* Sends a character on the UART */
418 void Board_UARTPutChar(char ch)
419 {
420 #if defined(DEBUG_UART)
421 while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {}
422 #endif
423 }
424
425 /* Gets a character from the UART, returns EOF if no character is ready */
426 int Board_UARTGetChar(void)
427 {
428 #if defined(DEBUG_UART)
429 uint8_t data;
430
431 if (Chip_UART_ReceiveByte(DEBUG_UART, &data) == SUCCESS) {
432 return (int) data;
433 }
434 #endif
435 return EOF;
436 }
437
438 /* Outputs a string on the debug UART */
439 void Board_UARTPutSTR(char *str)
440 {
441 #if defined(DEBUG_UART)
442 while (*str != '\0') {
443 Board_UARTPutChar(*str++);
444 }
445 #endif
446 }
447
448 /* Sets the state of a board LED to on or off */
449 void Board_LED_Set(uint8_t LEDNumber, bool On)
450 {
451 Chip_GPIO_WritePortBit(LPC_GPIO, 2, ledBits[LEDNumber], (bool) !On);
452 }
453
454 /* Returns the current state of a board LED */
455 bool Board_LED_Test(uint8_t LEDNumber)
456 {
457 return Chip_GPIO_ReadPortBit(LPC_GPIO, 2, ledBits[LEDNumber]);
458 }
459
460 /* Returns the MAC address assigned to this board */
461 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
462 {
463 const uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
464
465 memcpy(mcaddr, boardmac, 6);
466 }
467
468 /* Initialize pin muxing for SSP interface */
469 void Board_SSP_Init(LPC_SSP_T *pSSP)
470 {
471 if (pSSP == LPC_SSP1) {
472 /* Set up clock and muxing for SSP1 interface */
473 #if defined(CHIP_LPC177X_8X) || defined(CHIP_LPC407X_8X)
474 /*
475 * Initialize SSP0 pins connect
476 * P0.7: SCK
477 * P0.6: SSEL
478 * P0.8: MISO
479 * P0.9: MOSI
480 */
481 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
482 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
483 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
484 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
485 #endif
486 }
487 #if !defined(CHIP_LPC175X_6X)
488 else if (pSSP == LPC_SSP2) {
489 #if defined(CHIP_LPC407X_8X)
490 /*
491 * Initialize SSP0 pins connect
492 * P5.2: SCK
493 * P5.3: SSEL
494 * P5.1: MISO
495 * P5.0: MOSI
496 */
497 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 2, (IOCON_FUNC2 | IOCON_MODE_INACT));
498 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 3, (IOCON_FUNC2 | IOCON_MODE_INACT));
499 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 1, (IOCON_FUNC2 | IOCON_MODE_INACT));
500 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 0, (IOCON_FUNC2 | IOCON_MODE_INACT));
501 #endif
502
503 }
504 #endif
505 else {
506 /* Set up clock and muxing for SSP0 interface */
507 #if defined(CHIP_LPC177X_8X)
508 /*
509 * Initialize SSP0 pins connect
510 * P0.15: SCK
511 * P0.16: SSEL
512 * P0.17: MISO
513 * P0.18: MOSI
514 */
515 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC2 | IOCON_MODE_INACT));
516 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_FUNC2 | IOCON_MODE_INACT));
517 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_INACT));
518 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC2 | IOCON_MODE_INACT));
519 #endif
520 }
521 }
522
523 /* Set up and initialize all required blocks and functions related to the
524 board hardware */
525 void Board_Init(void)
526 {
527 /* Sets up DEBUG UART */
528 DEBUGINIT();
529
530 /* Updates SystemCoreClock global var with current clock speed */
531 SystemCoreClockUpdate();
532
533 /* Initializes GPIO */
534 Chip_GPIO_Init(LPC_GPIO);
535 Chip_IOCON_Init(LPC_IOCON);
536
537 /* Initialize LEDs */
538 Board_LED_Init();
539 }
540
541 /* Initialize LCD Interface */
542 void Board_LCD_Init(void)
543 {
544 uint8_t i;
545
546 for (i = 4; i <= 9; i++) {
547 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, i, (IOCON_FUNC7 | IOCON_MODE_INACT));
548 }
549 for (i = 20; i <= 29; i++) {
550 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, i, (IOCON_FUNC7 | IOCON_MODE_INACT));
551 }
552 for (i = 0; i <= 6; i++) {
553 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, i, (IOCON_FUNC7 | IOCON_MODE_INACT));
554 }
555 #if defined(CHIP_LPC177X_8X)
556 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 7, (IOCON_FUNC7 | IOCON_MODE_INACT));
557 #elif defined(CHIP_LPC407X_8X)
558 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 10, (IOCON_FUNC7 | IOCON_MODE_INACT));
559 #endif
560 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 8, (IOCON_FUNC7 | IOCON_MODE_INACT));
561 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 9, (IOCON_FUNC7 | IOCON_MODE_INACT));
562
563 for (i = 11; i <= 13; i++) {
564 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, i, (IOCON_FUNC7 | IOCON_MODE_INACT));
565 }
566 Chip_IOCON_PinMuxSet(LPC_IOCON, 4, 28, (IOCON_FUNC7 | IOCON_MODE_INACT));
567 Chip_IOCON_PinMuxSet(LPC_IOCON, 4, 29, (IOCON_FUNC7 | IOCON_MODE_INACT));
568 Chip_IOCON_PinMuxSet(LPC_IOCON, LCD_BACKLIGHT_PORTNUM, LCD_BACKLIGHT_PINNUM, (IOCON_FUNC0 | IOCON_MODE_INACT));
569 Chip_GPIO_WriteDirBit(LPC_GPIO, LCD_BACKLIGHT_PORTNUM, LCD_BACKLIGHT_PINNUM, true);
570
571 Board_InitLCDController();
572 }
573
574 /* Initialize the LCD controller on the external QVGA (320x240) TFT LCD*/
575 void Board_InitLCDController(void)
576 {
577 SSP_ConfigFormat ssp_format;
578 /* SSP pin configuration */
579 #if defined(CHIP_LPC177X_8X)
580 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC2 | IOCON_MODE_INACT));
581 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_FUNC2 | IOCON_MODE_INACT));
582 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_INACT));
583 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC2 | IOCON_MODE_INACT));
584 #elif defined(CHIP_LPC407X_8X)
585 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 2, (IOCON_FUNC2 | IOCON_MODE_INACT));
586 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 3, (IOCON_FUNC2 | IOCON_MODE_INACT));
587 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 1, (IOCON_FUNC2 | IOCON_MODE_INACT));
588 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 0, (IOCON_FUNC2 | IOCON_MODE_INACT));
589 #endif
590 /* DC pin */
591 Chip_IOCON_PinMuxSet(LPC_IOCON, TSC2046_DC_PORTNUM, TSC2046_DC_PINNUM, (IOCON_FUNC0 | IOCON_MODE_INACT));
592 Chip_GPIO_WriteDirBit(LPC_GPIO, TSC2046_DC_PORTNUM, TSC2046_DC_PINNUM, true);
593
594 Chip_SSP_Init(LCD_SSP_CTRL);
595 Chip_SSP_SetMaster(LCD_SSP_CTRL, true);
596 Chip_SSP_SetBitRate(LCD_SSP_CTRL, 1000000);
597 ssp_format.frameFormat = SSP_FRAMEFORMAT_SPI;
598 ssp_format.bits = SSP_BITS_8;
599 ssp_format.clockMode = SSP_CLOCK_MODE0;
600
601 Chip_SSP_SetFormat(LCD_SSP_CTRL, &ssp_format);
602 Chip_SSP_Enable(LCD_SSP_CTRL);
603
604 delayMs(200);
605 /* initialize LCD controller */
606 initSSD1289();
607
608 /* Power of SSP inteface */
609 Chip_SSP_Disable(LCD_SSP_CTRL);
610 Chip_SSP_DeInit(LCD_SSP_CTRL);
611
612 #if defined(CHIP_LPC177X_8X)
613 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC0 | IOCON_MODE_INACT));
614 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_FUNC0 | IOCON_MODE_INACT));
615 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC0 | IOCON_MODE_INACT));
616 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT));
617 #elif defined(CHIP_LPC407X_8X)
618 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 2, (IOCON_FUNC0 | IOCON_MODE_INACT));
619 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 3, (IOCON_FUNC0 | IOCON_MODE_INACT));
620 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 1, (IOCON_FUNC0 | IOCON_MODE_INACT));
621 Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 0, (IOCON_FUNC0 | IOCON_MODE_INACT));
622 #endif
623 }
624
625 /* Initialize TSC2046 touchscreen controller */
626 void Board_InitTouchController(void)
627 {
628 uint16_t dummy_data;
629 SSP_ConfigFormat ssp_format;
630
631 configTSC2046Pins();
632
633 Chip_SSP_Init(LCD_SSP_CTRL);
634
635 Chip_SSP_SetMaster(LCD_SSP_CTRL, true);
636 Chip_SSP_SetBitRate(LCD_SSP_CTRL, 200000);
637
638 ssp_format.frameFormat = SSP_FRAMEFORMAT_SPI;
639 ssp_format.bits = SSP_BITS_8;
640 ssp_format.clockMode = SSP_CLOCK_MODE3;
641
642 Chip_SSP_SetFormat(LCD_SSP_CTRL, &ssp_format);
643 Chip_SSP_Enable(LCD_SSP_CTRL);
644
645 /* Enable Touch Screen Controller */
646 readWriteTSC2046(PWRDOWN, &dummy_data);
647 }
648
649 /* Get Touch coordinates */
650 bool Board_GetTouchPos(int16_t *pX, int16_t *pY)
651 {
652 uint16_t tmp;
653 uint16_t x, y, z1, z2, z = 0;
654 Status Sts = SUCCESS;
655
656 readWriteTSC2046(X_MEASURE, &x);
657 readWriteTSC2046(Y_MEASURE, &y);
658 readWriteTSC2046(Z1_MEASURE, &z1);
659 readWriteTSC2046(Z2_MEASURE, &z2);
660
661 if (z1 != 0) {
662 z = x * ((z2 / z1) - 1);
663 }
664 if ((z <= 0) || (z > 35000)) {
665 return false;
666 }
667 /* Get X-Coordinate */
668 Sts = evalTSC2046Coord(X_MEASURE, &x);
669
670 if (Sts == ERROR) {
671 return false;
672 }
673 /* Get Y-Coordinate */
674 Sts = evalTSC2046Coord(Y_MEASURE, &y);
675 if (Sts == ERROR) {
676 return false;
677 }
678 /* Get Z1-Value */
679 Sts = evalTSC2046Coord(Z1_MEASURE, &z1);
680 if (Sts == ERROR) {
681 return false;
682 }
683 /* Get Z2-Value */
684 Sts = evalTSC2046Coord(Z2_MEASURE, &z2);
685 if (Sts == ERROR) {
686 return false;
687 }
688
689 z = x * ((z2 / z1) - 1);
690 if ((z <= 0) || (z > 35000)) {
691 return false;
692 }
693 else {
694 /* Swap, adjust to truly size of LCD */
695 if (TSC_Config.swap_xy) {
696 *pY = calibrateTSC2046(x, TSC_Config.ad_top, TSC_Config.ad_bottom, TSC_Config.lcd_height);
697 *pX = calibrateTSC2046(y, TSC_Config.ad_left, TSC_Config.ad_right, TSC_Config.lcd_width);
698 }
699 else {
700 *pX = calibrateTSC2046(x, TSC_Config.ad_top, TSC_Config.ad_bottom, TSC_Config.lcd_width);
701 *pY = calibrateTSC2046(y, TSC_Config.ad_left, TSC_Config.ad_right, TSC_Config.lcd_height);
702 }
703 }
704 readWriteTSC2046(PWRDOWN, &tmp);
705
706 return true;
707 }
708
709 /* Turn on Board LCD Backlight */
710 void Board_SetLCDBacklight(uint8_t Intensity)
711 {
712 bool OnOff = (bool) (Intensity != 0);
713
714 Chip_GPIO_WritePortBit(LPC_GPIO, LCD_BACKLIGHT_PORTNUM, LCD_BACKLIGHT_PINNUM, OnOff);
715 }
716
717 void Board_Audio_Init(LPC_I2S_T *pI2S, int micIn)
718 {
719 Chip_I2S_Audio_Format_T I2S_Config;
720
721 /* Chip_Clock_EnablePeripheralClock(SYSCTL_CLOCK_I2S); */
722
723 I2S_Config.SampleRate = 48000;
724 I2S_Config.ChannelNumber = 2; /* 1 is mono, 2 is stereo */
725 I2S_Config.WordWidth = 16; /* 8, 16 or 32 bits */
726 Chip_I2S_Init(pI2S);
727 Chip_I2S_Config(pI2S, I2S_TX_MODE, &I2S_Config);
728
729 /* Init UDA1380 CODEC */
730 while (!UDA1380_Init(UDA1380_MIC_IN_LR & - (micIn != 0))) {}
731 }
732
733 /* Sets up board specific I2C interface */
734 void Board_I2C_Init(I2C_ID_T id)
735 {
736 switch (id) {
737 case I2C0:
738 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, IOCON_FUNC1);
739 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, IOCON_FUNC1);
740 break;
741
742 case I2C1:
743 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 14, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_OPENDRAIN_EN));
744 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 15, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_OPENDRAIN_EN));
745 break;
746
747 case I2C2:
748 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 30, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_OPENDRAIN_EN));
749 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 31, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_OPENDRAIN_EN));
750 break;
751
752 default:
753 return;
754 }
755 }
756
757 void Board_Buttons_Init(void)
758 {
759 Chip_GPIO_WriteDirBit(LPC_GPIO, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM, false);
760 }
761
762 uint32_t Buttons_GetStatus(void)
763 {
764 uint8_t ret = NO_BUTTON_PRESSED;
765 if (Chip_GPIO_ReadPortBit(LPC_GPIO, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM) == 0x00) {
766 ret |= BUTTONS_BUTTON1;
767 }
768 return ret;
769 }
770
771 void Board_Joystick_Init(void)
772 {
773 Chip_IOCON_PinMuxSet(LPC_IOCON, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM,
774 (IOCON_FUNC0 | IOCON_MODE_INACT));
775 Chip_IOCON_PinMuxSet(LPC_IOCON, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM,
776 (IOCON_FUNC0 | IOCON_MODE_INACT));
777 Chip_IOCON_PinMuxSet(LPC_IOCON, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM,
778 (IOCON_FUNC0 | IOCON_MODE_INACT));
779 Chip_IOCON_PinMuxSet(LPC_IOCON, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM,
780 (IOCON_FUNC0 | IOCON_MODE_INACT));
781 Chip_IOCON_PinMuxSet(LPC_IOCON, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM,
782 (IOCON_FUNC0 | IOCON_MODE_INACT));
783 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM, false); // input
784 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM, false); // input
785 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM, false); // input
786 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM, false); // input
787 Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM, false); // input
788 }
789
790 /* Sets up board specific CAN interface */
791 void Board_CAN_Init(LPC_CAN_T *pCAN)
792 {
793 if (pCAN == LPC_CAN1) {
794 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_FUNC1 | IOCON_MODE_INACT));
795 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 1, (IOCON_FUNC1 | IOCON_MODE_INACT));
796 }
797 else {
798 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 4, (IOCON_FUNC2 | IOCON_MODE_INACT));
799 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 5, (IOCON_FUNC2 | IOCON_MODE_INACT));
800 }
801 }
802
803 uint8_t Joystick_GetStatus(void)
804 {
805 uint8_t ret = NO_BUTTON_PRESSED;
806 if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM)) == 0x00) {
807 ret |= JOY_UP;
808 }
809 else if (Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM) == 0x00) {
810 ret |= JOY_DOWN;
811 }
812 else if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM)) == 0x00) {
813 ret |= JOY_LEFT;
814 }
815 else if (Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM) == 0x00) {
816 ret |= JOY_RIGHT;
817 }
818 else if ((Chip_GPIO_ReadPortBit(LPC_GPIO, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM)) == 0x00) {
819 ret |= JOY_PRESS;
820 }
821 return ret;
822 }
823
824 /* Pin mux for Event Monitor/Recorder */
825 void Board_RTC_EV_Init(void)
826 {
827 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7, (IOCON_FUNC4 | IOCON_MODE_INACT));
828 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, (IOCON_FUNC4 | IOCON_MODE_INACT));
829 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_FUNC4 | IOCON_MODE_INACT));
830 }
831
832 /* Create Serial Stream */
833 void Serial_CreateStream(void *Stream)
834 {
835 /* To be implemented */
836 }
837
838 /* Setup board for SDC interface */
839 void Board_SDC_Init(void)
840 {
841 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 2, (IOCON_FUNC2 | IOCON_MODE_INACT));
842 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 3, (IOCON_FUNC2 | IOCON_MODE_INACT));
843 #ifdef CHIP_LPC407X_8X
844 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 5, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
845 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 6, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
846 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 7, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
847 #else
848 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 5, (IOCON_FUNC2 | IOCON_MODE_INACT));
849 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 6, (IOCON_FUNC2 | IOCON_MODE_INACT));
850 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 7, (IOCON_FUNC2 | IOCON_MODE_INACT));
851 #endif
852 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 11, (IOCON_FUNC2 | IOCON_MODE_INACT));
853 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 12, (IOCON_FUNC2 | IOCON_MODE_INACT));
854 }
855
856 #ifdef CHIP_LPC407X_8X
857 /* Setup board for CMP interface */
858 void Board_CMP_Init(void)
859 {
860 /* CMP1_IN0 @ P1.7 */
861 Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 7, (IOCON_FUNC5 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
862 }
863
864 /* Setup board for SPIFI interface */
865 void Board_SPIFI_Init(void)
866 {
867 /* SPIFI_IO[2] */
868 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC5 | IOCON_MODE_INACT));
869 /* SPIFI_IO[3] */
870 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_FUNC5 | IOCON_MODE_INACT));
871 /* SPIFI_IO[1] */
872 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC5 | IOCON_MODE_INACT));
873 /* SPIFI_IO[0] */
874 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC5 | IOCON_MODE_INACT));
875 /* SPIFI_CLK */
876 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 22, (IOCON_FUNC5 | IOCON_MODE_INACT));
877 /* SPIFI_CS */
878 Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 7, (IOCON_FUNC5 | IOCON_MODE_INACT));
879 }
880
881 #endif
882
883 void Board_NANDFLash_Init(void)
884 {
885 /* NANDFLASH Ready pin */
886 Chip_IOCON_PinMuxSet(LPC_IOCON, NANDFLASH_READY_PORT, NANDFLASH_READY_PIN, (IOCON_FUNC0 | IOCON_MODE_INACT));
887 Chip_GPIO_WriteDirBit(LPC_GPIO, NANDFLASH_READY_PORT, NANDFLASH_READY_PIN, false);
888 #if defined(NAND_SUPPORTED_LOCKEDCS)
889 /* P4.31 is GPIO out for NAND CS, default is low */
890 Board_NANDFLash_CSLatch(false);
891 Chip_IOCON_PinMuxSet(LPC_IOCON, 4, 31, (IOCON_FUNC0 | IOCON_FASTSLEW_EN));
892 Chip_GPIO_WriteDirBit(LPC_GPIO, 4, 31, true);
893 #endif
894 }
895