LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_hitex_eva_18504350.c
Go to the documentation of this file.
1 /*
2  * @brief Hitex EVA 1850/4350 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 other sources files specific to this board */
36 #include "lpc_phy_dp83848.c"
37 #include "retarget.c"
38 
43 /*****************************************************************************
44  * Private types/enumerations/variables
45  ****************************************************************************/
46 
47 /* Port and bit mapping for LEDs on GPIOs */
48 static const uint8_t ledports[] = {4, 7, 7, 7};
49 static const uint8_t ledbits[] = {1, 5, 6, 8};
50 
51 /* TSC2046 control byte definitions */
52 #define TSC_START (0x01 << 7)
53 #define TSC_CHANNEL_X (0x05 << 4) /* differential */
54 #define TSC_CHANNEL_Y (0x01 << 4) /* differential */
55 #define TSC_CHANNEL_Z1 (0x03 << 4) /* differential */
56 #define TSC_CHANNEL_Z2 (0x04 << 4) /* differential */
57 #define TSC_8BIT (0x01 << 3)
58 #define TSC_12BIT (0x00 << 3)
59 #define TSC_PD 0x00
60 #define TSC_ADC_ON 0x01
61 #define TSC_REF_ON 0x02
62 #if (TSC2046_CONVERSION_BITS == 12)
63 #define TSC_CONVERSION_MODE TSC_12BIT
64 #else
65 #define TSC_CONVERSION_MODE TSC_8BIT
66 #endif
67 
68 #define TSC_SER_MODE (0x01 << 2) /* Single-Ended Reference Mode */
69 #define TSC_DFR_MODE (0x00 << 2) /* Differential Reference Mode */
70 
71 #define X_MEASURE (TSC_START | TSC_CHANNEL_X | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
72 #define Y_MEASURE (TSC_START | TSC_CHANNEL_Y | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
73 #define Z1_MEASURE (TSC_START | TSC_CHANNEL_Z1 | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
74 #define Z2_MEASURE (TSC_START | TSC_CHANNEL_Z2 | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_ADC_ON)
75 #define PWRDOWN (TSC_START | TSC_CHANNEL_Y | TSC_CONVERSION_MODE | TSC_DFR_MODE | TSC_PD)
76 
77 typedef struct {
78  int16_t ad_left; /* left margin */
79  int16_t ad_right; /* right margin */
80  int16_t ad_top; /* top margin */
81  int16_t ad_bottom; /* bottom margin */
82  int16_t lcd_width; /* lcd horizontal size */
83  int16_t lcd_height; /* lcd vertical size */
84  uint8_t swap_xy; /* 1: swap x-y coords */
86 
87 #define DC_CMD (Chip_GPIO_WritePortBit(0x07, 8, false))
88 #define DC_DATA (Chip_GPIO_WritePortBit(0x07, 8, true))
89 
90 #define TSC2046_CONVERSION_BITS 12
91 
92 #if (TSC2046_CONVERSION_BITS == 12)
93 #define TSC2046_COORD_MAX (0xFFF)
94 #define TSC2046_DELTA_VARIANCE (0x50)
95 #else
96 #define TSC2046_COORD_MAX (0xFF)
97 #define TSC2046_DELTA_VARIANCE (0x03)
98 #endif
99 #define COORD_GET_NUM (10)
100 
103  3686, 205, 3842, 267, 240, 320, 1
104 };
105 
110  28, /* Horizontal back porch in clocks */
111  10, /* Horizontal front porch in clocks */
112  2, /* HSYNC pulse width in clocks */
113  240, /* Pixels per line */
114  2, /* Vertical back porch in clocks */
115  1, /* Vertical front porch in clocks */
116  2, /* VSYNC pulse width in clocks */
117  320, /* Lines per panel */
118  0, /* Invert output enable, 1 = invert */
119  1, /* Invert panel clock, 1 = invert */
120  1, /* Invert HSYNC, 1 = invert */
121  1, /* Invert VSYNC, 1 = invert */
122  1, /* AC bias frequency in clocks (not used) */
123  6, /* Maximum bits per pixel the display supports */
124  LCD_TFT, /* LCD panel type */
125  LCD_COLOR_FORMAT_BGR, /* BGR or RGB */
126  0 /* Dual panel, 1 = dual panel display */
127 };
128 
129 /* UDA1380 Register Address */
130 typedef enum {
146 } UDA1380_REG;
147 
148 #define UDA1380_REG_EVALCLK_DEFAULT_VALUE (0xF << 8 | 0x3 << 4 | 1 << 1)
149 #define UDA1380_REG_I2S_DEFAULT_VALUE 0x0000
150 
151 #define UDA1380_REG_PWRCTRL_DEFAULT_VALUE (1 << 15 | 1 << 13 | 1 << 10 | 1 << 8 | 1 << 6 | 1 << 4 | 0x0F)
152 #define UDA1380_REG_ANAMIX_DEFAULT_VALUE 0x0000
153 #define UDA1380_REG_HEADAMP_DEFAULT_VALUE ( 1 << 9 | 2)
154 
155 #define UDA1380_REG_MSTRVOL_DEFAULT_VALUE 0x0000
156 #define UDA1380_REG_MIXVOL_DEFAULT_VALUE 0x0000
157 #define UDA1380_REG_MODEBBT_DEFAULT_VALUE 0x0000
158 #define UDA1380_REG_MSTRMUTE_DEFAULT_VALUE (2 << 8 | 2)
159 #define UDA1380_REG_MIXSDO_DEFAULT_VALUE 0x0000
160 
161 #define UDA1380_REG_DECVOL_DEFAULT_VALUE 0xE4E4 /* Decrease Volume -28dB */
162 #define UDA1380_REG_PGA_DEFAULT_VALUE 0x0000
163 #define UDA1380_REG_ADC_DEFAULT_VALUE 0x0001 /* Apply 0bB VGA Gain, enable DC Filter */
164 #define UDA1380_REG_AGC_DEFAULT_VALUE 0x0000
165 
166 #define UDA1380_REG_L3_DEFAULT_VALUE 0x0000
167 
168 /* System Register Data Set */
169 static uint16_t UDA_sys_regs_dat[] = {
175 };
176 
177 /* System Register Data Set */
178 static uint16_t UDA_interfil_regs_dat[] = {
184 };
185 /* decimator Register Data Set */
186 static uint16_t UDA_decimator_regs_dat[] = {
191 };
192 
193 /*****************************************************************************
194  * Public types/enumerations/variables
195  ****************************************************************************/
196 
197 /*****************************************************************************
198  * Private functions
199  ****************************************************************************/
200 
201 /* Very simple (inaccurate) delay function */
202 static void DelayMs(uint32_t ms)
203 {
204  uint32_t i;
205  for (i = 0; i < 100 * ms; i++) {}
206 }
207 
208 /* Additional (SPI) pin configuration for LCD interface signals */
209 static void lcdPinConfig(void)
210 {
211  /* PC.11 connected to GPIO = SSEL_MUX_A, PC.12 connected to GPIO = SSEL_MUX_B */
212  Chip_SCU_PinMux(0xC, 11, MD_PLN, FUNC4);
213  Chip_SCU_PinMux(0xC, 12, MD_PLN, FUNC4);
214  Chip_GPIO_WriteDirBit(0x6, 10, true);
215  Chip_GPIO_WriteDirBit(0x6, 11, true);
216 
217  /* Configure SSP0 pins */
218  /* PF.0 connected to SCL/SCLK */
220  /* PF.1 connected to nCS */
222  /* PF.2 connected to SO */
224  /* PF.3 connected to nSI */
226 
227  /* DC PIN */
228  Chip_SCU_PinMux(0x0E, 8, MD_PUP, FUNC4);
229  Chip_GPIO_WriteDirBit(7, 8, true);
230 }
231 
232 /* Write to a LCD register using SPI */
233 static void writeToReg(uint16_t addr, uint16_t data)
234 {
235  uint8_t buf[2];
236 
237  Chip_GPIO_WritePortBit(0x06, 10, true);
238  Chip_GPIO_WritePortBit(0x06, 11, false);
239 
240  DC_CMD;
241 
242  buf[0] = 0;
243  buf[1] = (addr & 0xff);
244 
246 
247  DC_DATA;
248  buf[0] = (data >> 8);
249  buf[1] = (data & 0xff);
251 
252  DC_CMD;
253 
254  buf[0] = (0);
255  buf[1] = (0x22);
257 }
258 
259 /* Initialize SSD1289 LCD Controller */
260 static void ssd1289_init(void)
261 {
262  writeToReg(0x00, 0x0001);
263  DelayMs(15);
264  writeToReg(0x03, 0x6E3E); // 0xAEAC
265  writeToReg(0x0C, 0x0007);
266  writeToReg(0x0D, 0x000E); // 0x000F
267  writeToReg(0x0E, 0x2C00); // 0x2900
268  writeToReg(0x1E, 0x00AE); // 0x00B3
269  DelayMs(15);
270  writeToReg(0x07, 0x0021);
271  DelayMs(50);
272  writeToReg(0x07, 0x0023);
273  DelayMs(50);
274  writeToReg(0x07, 0x0033);
275  DelayMs(50);
276 
277  writeToReg(0x01, 0x2B3F);
278  writeToReg(0x02, 0x0600);
279  writeToReg(0x10, 0x0000);
280  DelayMs(15);
281  writeToReg(0x11, 0xC5B0); // 0x65b0
282  DelayMs(20);
283  writeToReg(0x05, 0x0000);
284  writeToReg(0x06, 0x0000);
285  writeToReg(0x16, 0xEF1C);
286  writeToReg(0x17, 0x0003);
287  writeToReg(0x07, 0x0233);
288  writeToReg(0x0B, 0x5312);
289  writeToReg(0x0F, 0x0000);
290  writeToReg(0x25, 0xE000);
291  DelayMs(20);
292  writeToReg(0x41, 0x0000);
293  writeToReg(0x42, 0x0000);
294  writeToReg(0x48, 0x0000);
295  writeToReg(0x49, 0x013F);
296  writeToReg(0x44, 0xEF00);
297  writeToReg(0x45, 0x0000);
298  writeToReg(0x46, 0x013F);
299  writeToReg(0x4A, 0x0000);
300  writeToReg(0x4B, 0x0000);
301  DelayMs(20);
302  writeToReg(0x30, 0x0707);
303  writeToReg(0x31, 0x0704);
304  writeToReg(0x32, 0x0005); // 0x0204
305  writeToReg(0x33, 0x0402); // 0x0201
306  writeToReg(0x34, 0x0203);
307  writeToReg(0x35, 0x0204);
308  writeToReg(0x36, 0x0204);
309  writeToReg(0x37, 0x0401); // 0x0502
310  writeToReg(0x3A, 0x0302);
311  writeToReg(0x3B, 0x0500);
312  DelayMs(20);
313  writeToReg(0x22, 0x0000);
314 }
315 
316 /* Send/Receive data to/from TSC2046. */
317 static void TSC2046_ReadWrite(uint8_t command, uint16_t *data)
318 {
319  uint32_t tmp;
320  uint8_t rx_data[2], tx_data[1] = {0x00};
321 
322  tx_data[0] = command;
323  Chip_GPIO_WritePortBit(6, 10, false);
324  Chip_GPIO_WritePortBit(6, 11, true);
325 
326  Chip_GPIO_WritePortBit(7, 16, false);
327 
328  for (tmp = 0x100; tmp; tmp--) {}
329 
332 
333  for (tmp = 0x100; tmp; tmp--) {}
334 
335 #if (TSC2046_CONVERSION_BITS == 8)
336  *data = (((rx_data[0] << 8) | (rx_data[1])) >> 7) & 0xFF;
337 #else
338  *data = (((rx_data[0] << 8) | rx_data[1]) >> 3) & 0xFFF;
339 #endif
340  Chip_GPIO_WritePortBit(7, 16, true);
341 }
342 
343 /* Evaluate the coordinates received from TSC. */
344 static Status EvalCoord(uint8_t command, uint16_t *coord)
345 {
346  uint32_t i;
347  uint16_t Tmp = 0, previousTmp;
348  int16_t diff = 0;
349  *coord = 0;
350  for (i = 0; i < COORD_GET_NUM; i++) {
351  previousTmp = Tmp;
352  TSC2046_ReadWrite(command, &Tmp);
353  if (Tmp > TSC2046_COORD_MAX) {
354  return ERROR;
355  }
356  if (i > 0) {
357  diff = Tmp - previousTmp;
358  }
359  if (diff < 0) {
360  diff = 0 - diff;
361  }
362  if (diff > TSC2046_DELTA_VARIANCE) {
363  return ERROR;
364  }
365  *coord += Tmp;
366  }
367  *coord /= COORD_GET_NUM;
368  return SUCCESS;
369 }
370 
371 /* Convert the coord received from TSC to a value on truly LCD */
372 static int16_t TSCCalibrate(int16_t Coord, int16_t MinVal, int16_t MaxVal, int16_t TrueSize)
373 {
374  int16_t tmp;
375  int16_t ret;
376  uint8_t convert = 0;
377 
378  /* Swap value? */
379  if (MinVal > MaxVal) {
380  tmp = MaxVal;
381  MaxVal = MinVal;
382  MinVal = tmp;
383  convert = 1;
384  }
385 
386  ret = (Coord - MinVal) * TrueSize / (MaxVal - MinVal);
387  if (convert) {
388  ret = TrueSize - ret;
389  }
390 
391  return ret;
392 }
393 
394 static void delay(uint32_t i) {
395  while (i--) {}
396 }
397 
398 /* Write value to a UDA1380 register */
399 static void UDA_Reg_write(UDA1380_REG reg, unsigned short value, I2C_M_SETUP_Type *I2C_Config) {
400 
401  I2C_Config->tx_data[0] = reg;
402  I2C_Config->tx_data[1] = value >> 8;
403  I2C_Config->tx_data[2] = value & 0xFF;
405  delay(10000);
406 }
407 
408 /* Read value from a UDA1380 register */
409 static uint16_t UDA_Reg_read(UDA1380_REG reg) {
410  uint8_t rx_data[2];
412  return rx_data[0] << 8 | rx_data[1];
413 }
414 
415 /* Initialize UDA1380 CODEC */
417 {
418  uint16_t temp;
419  uint8_t i;
420  /* Reset UDA1380 on board Hitex A4*/
421  /* PE_9: UDA_RST on Hitex A4 */
422  Chip_SCU_PinMux(0x0E, 9, MD_PUP, FUNC4);
423  Chip_GPIO_WriteDirBit(7, 9, true);
424  Chip_GPIO_WritePortBit(7, 9, true);
425  /* delay 1us */
426  delay(100000);
427  Chip_GPIO_WritePortBit(7, 9, false);
428  delay(100000);
429  for (i = 0; i < 5; i++) {
430  UDA_Reg_write((UDA1380_REG) (UDA_EVALM_CLK + i), UDA_sys_regs_dat[i], I2C_Config);
431  temp = UDA_Reg_read((UDA1380_REG) (UDA_EVALM_CLK + i));
432  if (temp != UDA_sys_regs_dat[i]) {
433  return ERROR;
434  }
435  }
436 
437  /* interfilter regs init */
438  for (i = 0; i < 5; i++) {
441  if (temp != UDA_interfil_regs_dat[i]) {
442  return ERROR;
443  }
444  }
445  /* decimator regs init */
446  for (i = 0; i < 4; i++) {
448  temp = UDA_Reg_read((UDA1380_REG) (UDA_DEC_VOL_CTRL + i));
449  if (temp != UDA_decimator_regs_dat[i]) {
450  return ERROR;
451  }
452  }
453 
454  if (audio_in_sel == MCB_18XX_AUDIO_MIC_SELECT) {
455  /* Disable Power On for ADCR, PGAR, PGAL to get mic sound more clearly */
459  return ERROR;
460  }
463  I2C_Config);
466  return ERROR;
467  }
468  }
469  return SUCCESS;
470 
471 }
472 
473 /*****************************************************************************
474  * Public functions
475  ****************************************************************************/
476 
477 /* Initialize pin muxing for a UART */
479 {
480  if (UARTx == LPC_USART0) {
481  Chip_SCU_PinMux(0xF, 10, MD_PDN, FUNC1); /* PF.10 : UART0_TXD */
482  Chip_SCU_PinMux(0xF, 11, MD_PLN | MD_EZI | MD_ZI, FUNC1); /* PF.11 : UART0_RXD */
483  }
484  else if (UARTx == LPC_UART1) {
485  Chip_SCU_PinMux(0xC, 13, MD_PDN, FUNC2); /* PC.13 : UART1_TXD - pin 1 of SV14 */
486  Chip_SCU_PinMux(0xC, 14, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* PC.14 : UART1_RX - pin 2 of SV14 */
487  }
488  else if (UARTx == LPC_USART2) {
489  /* P1.15 : UART2_TXD - pin 11 of SV6, P1.16 : UART2_RXD - pin 3 of SV6 */
490  Chip_SCU_PinMux(0x1, 15, MD_PDN, FUNC1);
491  Chip_SCU_PinMux(0x1, 16, MD_PLN | MD_EZI | MD_ZI, FUNC1);
492  }
493  else if (UARTx == LPC_USART3) {
494  /* P9.3 : UART3_TXD - pin 15 of SV6, P9.4 : UART3_RXD - pin 7 of SV3 */
495  Chip_SCU_PinMux(0x9, 3, MD_PDN, FUNC7);
496  Chip_SCU_PinMux(0x9, 4, MD_PLN | MD_EZI | MD_ZI, FUNC7);
497  }
498 }
499 
500 /* Initialize debug output via UART for board */
502 {
503 #if defined(DEBUG_UART)
505 
507  Chip_UART_SetBaud(DEBUG_UART, 115200);
509 
510  /* Enable UART Transmit */
512 #endif
513 }
514 
515 /* Sends a character on the UART */
516 void Board_UARTPutChar(char ch)
517 {
518 #if defined(DEBUG_UART)
519  while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {}
520 #endif
521 }
522 
523 /* Gets a character from the UART, returns EOF if no character is ready */
525 {
526 #if defined(DEBUG_UART)
527  uint8_t data;
528 
529  if (Chip_UART_ReceiveByte(DEBUG_UART, &data) == SUCCESS) {
530  return (int) data;
531  }
532 #endif
533  return EOF;
534 }
535 
536 /* Outputs a string on the debug UART */
537 void Board_UARTPutSTR(char *str)
538 {
539 #if defined(DEBUG_UART)
540  while (*str != '\0') {
541  Board_UARTPutChar(*str++);
542  }
543 #endif
544 }
545 
546 /* Initializes board LED(s) */
548 {
549  int i;
550 
551  /* Set ports as outputs with initial states off */
552  for (i = 0; i < (sizeof(ledports) / sizeof(ledports[0])); i++) {
553  Chip_GPIO_WriteDirBit(ledports[i], ledbits[i], true);
555  }
556  Chip_GPIO_WritePortBit(ledports[0], ledbits[0], false);
557 }
558 
559 /* Sets the state of a board LED to on or off */
560 void Board_LED_Set(uint8_t LEDNumber, bool On)
561 {
562  /* Must connect JP3 to see LED0 and JP4 to see LED1 */
563  if (LEDNumber == 0) {
564  On = !On;
565  }
566 
567  if (LEDNumber < 4) {
568  Chip_GPIO_WritePortBit(ledports[LEDNumber], ledbits[LEDNumber], !On);
569  }
570 }
571 
572 /* Returns the current state of a board LED */
573 bool Board_LED_Test(uint8_t LEDNumber)
574 {
575  bool On = false;
576 
577  if (LEDNumber < 4) {
578  On = (bool) !Chip_GPIO_ReadPortBit(ledports[LEDNumber], ledbits[LEDNumber]);
579 
580  if (LEDNumber == 0) {
581  On = ~On;
582  }
583  }
584 
585  return On;
586 }
587 
588 /* Initialize button(s) interface on board */
589 void Board_Buttons_Init(void) // FIXME not functional ATM
590 {
591  Chip_SCU_PinMux(0xD, 7, MD_PUP | MD_EZI, FUNC4); // GPIO6[21]
593 }
594 
595 /* Returns button(s) state on board */
597 {
598  uint8_t ret = NO_BUTTON_PRESSED;
600  ret |= BUTTONS_BUTTON1;
601  }
602  return ret;
603 }
604 
605 /* Initialize joystick interface on board */
607 {}
608 
609 /* Returns joystick states on board */
610 uint8_t Joystick_GetStatus(void)
611 {
612  return NO_BUTTON_PRESSED;
613 }
614 
619 
620 /* Update system core clock rate, should be called if the system has
621  a clock rate change */
623 {
624  /* CPU core speed */
626 }
627 
628 /* Returns the MAC address assigned to this board */
629 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
630 {
631  const uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
632 
633  memcpy(mcaddr, boardmac, 6);
634 }
635 
636 /* Set up and initialize all required blocks and functions related to the
637  board hardware */
638 void Board_Init(void)
639 {
640  /* Sets up DEBUG UART */
641  DEBUGINIT();
642 
643  /* Updates SystemCoreClock global var with current clock speed */
645 
646  /* Initializes GPIO */
647  Chip_GPIO_Init();
648 
649  /* Setup GPIOs for USB demos */
650 #if 0 /* FIXME: the following call removed on the Hitex board as it interferes with muxed MII state */
651  // Chip_SCU_PinMux(0x9, 5, (MD_PUP | MD_EZI), FUNC2); // P9_5 USB1_VBUS_EN, USB1 VBus function
652 #endif
653  Chip_SCU_PinMux(0x2, 5, (MD_PLN | MD_EZI | MD_ZI), FUNC2); // P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION
654  Chip_SCU_PinMux(0x6, 3, (MD_PUP | MD_EZI), FUNC1); // P6_3 USB0_PWR_EN, USB0 VBus function
655 }
656 
657 /* Sets up board specific ADC interface */
658 void Board_ADC_Init(void)
659 {
660  /* Analog function ADC1_2 selected on pin PF_9 */
662 }
663 
664 /* Sets up board specific I2C interface */
666 {
667  if (I2Cx == LPC_I2C1) {
668  /* Configure pin function for I2C1 on PE.13 (I2C1_SDA) and PE.15 (I2C1_SCL) */
669  Chip_SCU_PinMux(0xE, 13, MD_ZI | MD_EZI, FUNC2);
670  Chip_SCU_PinMux(0xE, 15, MD_ZI | MD_EZI, FUNC2);
671  }
672 }
673 
674 /* Initialize the LCD interface */
675 void Board_LCD_Init(void)
676 {
677  SSP_ConfigFormat ssp_format1;
678  /* Attach main PLL clock to divider A with a divider of 2 */
680 
681  /* Route divider A output to LCD base clock and enable base clock */
683 
684  /* Reset LCD and wait for reset to complete */
686  while (Chip_RGU_InReset(RGU_LCD_RST)) {}
687 
688  lcdPinConfig();
692  Chip_SSP_Set_BitRate(LPC_SSP0, 1000000);
693 
694  ssp_format1.frameFormat = SSP_FRAMEFORMAT_SPI;
695  ssp_format1.bits = SSP_BITS_8;
696  ssp_format1.clockFormat = SSP_CLOCK_MODE0;
697 
698  Chip_SSP_Set_Format(LPC_SSP0, &ssp_format1);
700 
701  DelayMs(200);
702 
703  /* initialize LCD controller */
704  ssd1289_init();
705 
708 }
709 
710 /* Initialize TSC2046 touchscreen controller */
712 {
713  uint16_t dummy_data;
714  SSP_ConfigFormat ssp_format1;
715 
716  /* Configure SSP0 pins*/
717  lcdPinConfig();
718  Chip_SCU_PinMux(0xF, 1, MD_PUP, FUNC4);
719 
720  Chip_GPIO_WriteDirBit(7, 16, true);
721 
722  Chip_GPIO_WritePortBit(6, 10, false);
723  Chip_GPIO_WritePortBit(6, 11, true);
724 
726 
729 
730  ssp_format1.frameFormat = SSP_FRAMEFORMAT_SPI;
731  ssp_format1.bits = SSP_BITS_8;
732  ssp_format1.clockFormat = SSP_CLOCK_MODE0;
733 
734  Chip_SSP_Set_Format(LPC_SSP0, &ssp_format1);
736 
737  /* Enable Touch Screen Controller */
738  TSC2046_ReadWrite(PWRDOWN, &dummy_data);
739 }
740 
741 /* Get Touch coordinates */
742 bool GetTouchPos(int16_t *pX, int16_t *pY)
743 {
744  uint16_t tmp;
745  uint16_t x, y, z1, z2, z = 0;
746  Status Sts = SUCCESS;
747 
752 
753  if (z1 != 0) {
754  z = x * ((z2 / z1) - 1);
755  }
756  if ((z <= 0) || (z > 35000)) {
757  return false;
758  }
759  /* Get X-Coordinate */
760  Sts = EvalCoord(X_MEASURE, &x);
761 
762  if (Sts == ERROR) {
763  return false;
764  }
765  /* Get Y-Coordinate */
766  Sts = EvalCoord(Y_MEASURE, &y);
767  if (Sts == ERROR) {
768  return false;
769  }
770  /* Get Z1-Value */
771  Sts = EvalCoord(Z1_MEASURE, &z1);
772  if (Sts == ERROR) {
773  return false;
774  }
775  /* Get Z2-Value */
776  Sts = EvalCoord(Z2_MEASURE, &z2);
777  if (Sts == ERROR) {
778  return false;
779  }
780 
781  z = x * ((z2 / z1) - 1);
782  if ((z <= 0) || (z > 35000)) {
783  return false;
784  }
785  else {
786  /* Swap, adjust to truly size of LCD */
787  if (TSC_Config.swap_xy) {
788  *pY = TSCCalibrate(x, TSC_Config.ad_top, TSC_Config.ad_bottom, TSC_Config.lcd_height);
789  *pX = TSCCalibrate(y, TSC_Config.ad_left, TSC_Config.ad_right, TSC_Config.lcd_width);
790  }
791  else {
792  *pX = TSCCalibrate(x, TSC_Config.ad_top, TSC_Config.ad_bottom, TSC_Config.lcd_width);
793  *pY = TSCCalibrate(y, TSC_Config.ad_left, TSC_Config.ad_right, TSC_Config.lcd_height);
794  }
795  }
796  TSC2046_ReadWrite(PWRDOWN, &tmp);
797 
798  return true;
799 }
800 
801 /* Turn on Board LCD Backlight */
802 void Board_LCD_Set_Backlight(uint8_t Intensity)
803 {
804  bool OnOff = (bool) (Intensity != 0);
805 
806  Chip_GPIO_WritePortBit(3, 8, OnOff);
807 }
808 
809 /* Initialize pin muxing for SDMMC interface */
811 {
812  Chip_SCU_PinMux(0xc, 9, MD_PLN, FUNC7); /* Pc.9 SDIO power */
813  Chip_SCU_PinMux(0xc, 2, MD_PLN, FUNC7); /* Pc.2 SDIO LED */
814  Chip_SCU_PinMux(0xf, 10, MD_PLN | MD_EZI, FUNC6); /* Pf.10 SDIO WP */
815  Chip_SCU_PinMux(0xc, 8, MD_PLN | MD_EZI, FUNC7); /* Pc.8 SDIO CD */
816  Chip_SCU_PinMux(0xc, 6, MD_PLN_FAST, FUNC7); /* Pc.6 SDIO D2 */
817  Chip_SCU_PinMux(0xc, 5, MD_PLN_FAST, FUNC7); /* Pc.5 SDIO D1 */
818  Chip_SCU_PinMux(0xc, 4, MD_PLN_FAST, FUNC7); /* Pc.4 SDIO D0 */
819  Chip_SCU_PinMux(0xc, 0, MD_PLN | MD_EHS, FUNC7); /* Pc.0 SDIO clock */
820  Chip_SCU_PinMux(0xc, 10, MD_PLN_FAST, FUNC7); /* Pc.10 SDIO command */
821  Chip_SCU_PinMux(0xc, 7, MD_PLN_FAST, FUNC7); /* Pc.7 SDIO D3 */
822 }
823 
824 /* Initialize pin muxing for SSP interface */
826 {
827  if (SSPx == LPC_SSP0) {
828  /* Set up clock and muxing for SSP0 interface */
829  // #if !defined(HITEX_LCD_TERM)
830  /* PC.11 connected to GPIO = SSEL_MUX_A, PC.12 connected to GPIO = SSEL_MUX_B */
831  Chip_SCU_PinMux(0xC, 11, MD_PLN, FUNC4);
832  Chip_SCU_PinMux(0xC, 12, MD_PLN, FUNC4);
833  Chip_GPIO_WriteDirBit(0x6, 10, true);
834  Chip_GPIO_WriteDirBit(0x6, 11, true);
835  // #endif
836  /* PF.0 connected to SCL/SCLK func2=SSP0 SCK0 */
838  /* PF.1 connected to nCS func2=SSP0 SSEL0 */
840  /* PF.2 connected to SO func2=SSP0 MISO0 */
841  Chip_SCU_PinMux(0xF, 2, MD_PLN | MD_EZI | MD_ZI, FUNC2);
842  /* PF.3 connected to nSI func2=SSP0 MOSI0 */
843  Chip_SCU_PinMux(0xF, 3, MD_PLN | MD_EZI | MD_ZI, FUNC2);
844 
846  }
847  else if (SSPx == LPC_SSP1) {
848  /* Set up clock and muxing for SSP1 interface */
849  /* P1.19 connected to SCL/SCLK func1=SSP1 SCK1 */
850  Chip_SCU_PinMux(0x1, 19, MD_PLN_FAST, FUNC1);
851  /* P1.20 connected to nCS func1=SSP1 SSEL1 */
852  Chip_SCU_PinMux(0x1, 20, MD_PLN_FAST, FUNC1);
853  /* P0.0 connected to SO func1=SSP1 MISO1 */
854  Chip_SCU_PinMux(0x0, 0, MD_PLN | MD_EZI | MD_ZI, FUNC1);
855  /* P0.1 connected to nSI func2=SSP1 MOSI1 */
856  Chip_SCU_PinMux(0x0, 1, MD_PLN | MD_EZI | MD_ZI, FUNC1);
857 
859  }
860 }
861 
862 /* Initialize I2S interface for the board and UDA1380 */
864 {
865  uint8_t uda1380_tx_data_buf[3];
866  Chip_I2S_Audio_Format_Type I2S_Config;
867  I2C_M_SETUP_Type I2C_Config;
868  I2C_Config.sl_addr7bit = I2CDEV_UDA1380_ADDR;
869  I2C_Config.retransmissions_max = 5;
870  I2C_Config.tx_length = 3;
871  I2C_Config.tx_data = uda1380_tx_data_buf;
872  I2C_Config.rx_length = 0;
873  I2C_Config.rx_data = NULL;
874 
875  /* Initialize I2C to the UDA1380 CODEC */
878 
879  I2S_Config.SampleRate = 48000;
880  I2S_Config.ChannelNumber = 2; // 1 is mono, 2 is stereo
881  I2S_Config.WordWidth = 16; // 8, 16 or 32 bits
883  Chip_I2S_Config(LPC_I2S0, I2S_TX_MODE, &I2S_Config);
884  /* Enable Slave I2C operation */
886  /* Init UDA1380 CODEC */
887  while (UDA1380_init(&I2C_Config, audio_in_sel) != SUCCESS) {}
888 }
889 
890 /* FIXME */
891 void Serial_CreateStream(void *Stream)
892 {
893  // implement later
894 }
895