LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_keil_mcb_18574357.c
Go to the documentation of this file.
1 /*
2  * @brief Keil MCB 1857/4357 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 /* Keil board uses 83848 PHY and retarget */
36 #include "lpc_phy_dp83848.c"
37 #include "retarget.c"
38 
43 /*****************************************************************************
44  * Private types/enumerations/variables
45  ****************************************************************************/
46 /* Port and bit mapping for LEDs on GPIOs */
47 static const uint8_t ledports[] = {6, 6, 6, 6, 6, 4, 4, 4};
48 static const uint8_t ledbits[] = {24, 25, 26, 27, 28, 12, 13, 14};
49 
51 /* System Register Data Set */
52 uint16_t UDA_sys_regs_dat[] = {
58 };
59 
60 /* System Register Data Set */
61 uint16_t UDA_interfil_regs_dat[] = {
67 };
68 /* decimator Register Data Set */
69 uint16_t UDA_decimator_regs_dat[] = {
74 };
75 
77 #define LCD_CS(x) ((x) ? (Chip_GPIO_WritePortBit(7, 16, true)) : (Chip_GPIO_WritePortBit(7, 16, false)))
78 
82 const int32_t ad_left = 3813;
83 const int32_t ad_top = 3805;// 237;
84 const int32_t ad_right = 360;
85 const int32_t ad_bottom = 237; // 3805;
86 
88  8,
89  4,
90  4,
91  240,
92  4,
93  3,
94  4,
95  320,
96  0,
97  1,
98  1,
99  1,
100  1,
101  6,
102  LCD_TFT,
104  0
105 };
106 
107 /*****************************************************************************
108  * Public types/enumerations/variables
109  ****************************************************************************/
110 
113 
114 /*****************************************************************************
115  * Private functions
116  ****************************************************************************/
117 
118 /* Very simple (inaccurate) delay function */
119 static void delay(uint32_t i) {
120  while (i--) {}
121 }
122 
123 /* Write data to UDA register */
124 static void UDA_Reg_write(UDA1380_REG reg, unsigned short value, I2C_M_SETUP_Type *I2C_Config) {
125 
126  I2C_Config->tx_data[0] = reg;
127  I2C_Config->tx_data[1] = value >> 8;
128  I2C_Config->tx_data[2] = value & 0xFF;
130  delay(10000);
131 }
132 
133 /* Read data from UDA register */
134 static uint16_t UDA_Reg_read(UDA1380_REG reg) {
135  uint8_t rx_data[2];
137  return rx_data[0] << 8 | rx_data[1];
138 }
139 
140 /* Initializes default settings for UDA1380 */
142 {
143  uint16_t temp;
144  uint8_t i;
145  /* Reset UDA1380 on board Keil */
146  Chip_SCU_PinMux(0x8, 0, MD_PUP, FUNC0);
147  Chip_GPIO_WriteDirBit(4, 0, true);
148  Chip_GPIO_WritePortBit(4, 0, true);
149  /* delay 1us */
150  delay(100000);
151  Chip_GPIO_WritePortBit(4, 0, false);
152  delay(100000);
153  for (i = 0; i < 5; i++) {
154  UDA_Reg_write((UDA1380_REG) (UDA_EVALM_CLK + i), UDA_sys_regs_dat[i], I2C_Config);
155  temp = UDA_Reg_read((UDA1380_REG) (UDA_EVALM_CLK + i));
156  if (temp != UDA_sys_regs_dat[i]) {
157  return ERROR;
158  }
159  }
160 
161  /* interfilter regs init */
162  for (i = 0; i < 5; i++) {
165  if (temp != UDA_interfil_regs_dat[i]) {
166  return ERROR;
167  }
168  }
169  /* decimator regs init */
170  for (i = 0; i < 4; i++) {
172  temp = UDA_Reg_read((UDA1380_REG) (UDA_DEC_VOL_CTRL + i));
173  if (temp != UDA_decimator_regs_dat[i]) {
174  return ERROR;
175  }
176  }
177 
178  if (audio_in_sel == MCB_18XX_AUDIO_MIC_SELECT) {
179  /* Disable Power On for ADCR, PGAR, PGAL to get mic sound more clearly */
183  return ERROR;
184  }
187  I2C_Config);
190  return ERROR;
191  }
192  }
193  return SUCCESS;
194 
195 }
196 
198 /* Write to LCD controller, with A0 = 0 */
199 static void LCD_X_Write00_16(uint16_t c) {
200 
201  uint8_t buf[1];
202  LCD_CS(0);
203  buf[0] = 0x70;
204  Chip_SSP_WriteFrames_Blocking(SSP_ID, buf, 1); // Start + WR Register
205  buf[0] = (uint8_t) (c);
207  LCD_CS(1);
208 }
209 
210 /* Write to LCD controller, with A0 = 1 */
211 static void LCD_X_Write01_16(uint16_t c) {
212 
213  uint8_t buf[1];
214  LCD_CS(0);
215  buf[0] = 0x72;
216  Chip_SSP_WriteFrames_Blocking(SSP_ID, buf, 1); /* Start + WR Data */
217  buf[0] = (uint8_t) (c >> 8);
219  buf[0] = (uint8_t) (c);
221  LCD_CS(1);
222 }
223 
224 /* Write to LCD controller's register */
225 static void wr_reg(uint16_t reg, uint16_t dat) {
226  LCD_X_Write00_16(reg);
227  LCD_X_Write01_16(dat);
228 }
229 
230 /* Pin configuration to communicate with LCD Controller */
231 static void pinConfig(void)
232 {
233  /* (DC) */
234  Chip_GPIO_WriteDirBit(7, 16, true);
235  // Chip_Clock_EnableOpts(sspclk, true, true, 1);
236 }
237 
238 /* Writes a value to the STMPE811 register */
239 static uint32_t Board_TSC_WriteReg(IP_I2C_001_Type *I2Cx, uint8_t regAddr, uint8_t value)
240 {
241  return Chip_I2C_MasterWriteReg(I2Cx, TSC_I2C_ADDR, regAddr, &value, 1);
242 }
243 
244 /* Reads a value to the STMPE811 register */
245 static uint32_t Board_TSC_ReadReg(IP_I2C_001_Type *I2Cx, uint8_t regAddr, uint8_t *value)
246 {
247  return Chip_I2C_MasterReadReg(I2Cx, TSC_I2C_ADDR, regAddr, value, 1);
248 }
249 
250 /* Check if touch is detected or not */
252 {
253  uint8_t CtrRegVal = 0;
254 
255  if (Board_TSC_ReadReg(I2Cx, TSC_CTRL, &CtrRegVal) == 1) {
256  if (CtrRegVal & (1 << 7)) {
257  return true;
258  }
259  }
260  return false;
261 }
262 
263 /* Get the touch coordinates from STMPE811 registers */
264 static Status Board_TSC_GetTouchCoord(IP_I2C_001_Type *I2Cx, int16_t *x, int16_t *y)
265 {
266  uint8_t fifo_size, tscData[4], i;
267 
268  /* Read all samples except the last one */
269  Board_TSC_ReadReg(I2Cx, FIFO_SIZE, &fifo_size);
270  for (i = 0; i < fifo_size; ++i)
271  if (Chip_I2C_MasterReadReg(I2Cx, TSC_I2C_ADDR, DATA_XYZ, tscData, 4) == 0) {
272  return ERROR;
273  }
274 
275  /* Retrieve last taken sample */
276  Chip_I2C_MasterReadReg(I2Cx, TSC_I2C_ADDR, DATA_XYZ, tscData, 4);
277  *x = (tscData[0] << 4) | ((tscData[1] & 0xF0) >> 4);
278  *y = ((tscData[1] & 0x0F) << 8) | tscData[2];
279 
280  /* Clear interrupt flags */
281  Board_TSC_WriteReg(I2Cx, INT_STA, 0x1F);
282 
283  return SUCCESS;
284 }
285 
286 /*****************************************************************************
287  * Public functions
288  ****************************************************************************/
289 
290 /* Update system core clock rate, should be called if the system has
291  a clock rate change */
293 {
294  /* CPU core speed */
296 }
297 
298 /* Initialize UART pins */
300 {
301  if (UARTx == LPC_USART0) {
302  Chip_SCU_PinMux(0x2, 0, MD_PDN, FUNC1); /* P2.0 : UART0_TXD */
303  Chip_SCU_PinMux(0x2, 1, MD_PLN | MD_EZI | MD_ZI, FUNC1); /* P2.1 : UART0_RXD */
304  }
305  else if (UARTx == LPC_USART3) {
306  Chip_SCU_PinMux(0x2, 3, MD_PDN, FUNC2); /* P2.3 : UART3_TXD */
307  Chip_SCU_PinMux(0x2, 4, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P2.4 : UART3_RXD */
308  }
309 }
310 
311 /* Initialize debug output via UART for board */
313 {
314 #if defined(DEBUG_UART)
316 
318  Chip_UART_SetBaud(DEBUG_UART, 115200);
320 
321  /* Enable UART Transmit */
323 #endif
324 }
325 
326 /* Sends a character on the UART */
327 void Board_UARTPutChar(char ch)
328 {
329 #if defined(DEBUG_UART)
330  while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {}
331 #endif
332 }
333 
334 /* Gets a character from the UART, returns EOF if no character is ready */
336 {
337 #if defined(DEBUG_UART)
338  uint8_t data;
339 
340  if (Chip_UART_ReceiveByte(DEBUG_UART, &data) == SUCCESS) {
341  return (int) data;
342  }
343 #endif
344  return EOF;
345 }
346 
347 /* Outputs a string on the debug UART */
348 void Board_UARTPutSTR(char *str)
349 {
350 #if defined(DEBUG_UART)
351  while (*str != '\0') {
352  Board_UARTPutChar(*str++);
353  }
354 #endif
355 }
356 
357 /* Initializes board LED(s) */
359 {
360  int i;
361 
362  /* Must make sure J21 is installed to enabled LEDs */
363  /* PD.10 : LED 0 (leftmost) */
364  /* PD.11 : LED 1 */
365  /* PD.12 : LED 2 */
366  /* PD.13 : LED 3 */
367  /* PD.14 : LED 4 */
368  /* P9.0 : LED 5 */
369  /* P9.1 : LED 6 */
370  /* P9.2 : LED 7 (rightmost) */
371  for (i = 0; i < (sizeof(ledports) / sizeof(ledports[0])); i++) {
372  Chip_GPIO_WriteDirBit(ledports[i], ledbits[i], true);
373  }
374 }
375 
376 #ifndef BOARD_LED_TEST_FUNCTION_WORKS
377  /* FIXME: temporary code for toggle LED support only */
378  static uint8_t LEDStates; /* shadow variable for LED states */
379 #endif
380 
381 /* Sets the state of a board LED to on or off */
382 void Board_LED_Set(uint8_t LEDNumber, bool On)
383 {
384  if (LEDNumber <= 7) {
385  Chip_GPIO_WritePortBit(ledports[LEDNumber], ledbits[LEDNumber], On);
386 #ifndef BOARD_LED_TEST_FUNCTION_WORKS
387  if (On) {
388  LEDStates |= (1 << LEDNumber); /* set the state */
389  } else {
390  LEDStates &= ~(1 << LEDNumber); /* clear the state */
391  }
392 #endif
393  }
394 }
395 
396 /* Returns the current state of a board LED */
397 bool Board_LED_Test(uint8_t LEDNumber)
398 {
399  if (LEDNumber <= 7) {
400 #ifndef BOARD_LED_TEST_FUNCTION_WORKS
401  if (LEDStates & (1 << LEDNumber)) { /* LED is on */
402  return true;
403  } else { /* LED is off */
404  return false;
405  }
406 #else
407  return (bool)Chip_GPIO_ReadPortBit(ledports[LEDNumber], ledbits[LEDNumber]);
408 #endif
409  }
410  return false;
411 }
412 
413 /* Returns the MAC address assigned to this board */
414 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
415 {
416  const uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
417 
418  memcpy(mcaddr, boardmac, 6);
419 }
420 
421 /* Set up and initialize all required blocks and functions related to the
422  board hardware */
423 void Board_Init(void)
424 {
425  /* Sets up DEBUG UART */
426  DEBUGINIT();
427 
428  /* Updates SystemCoreClock global var with current clock speed */
430 
431  /* Initializes GPIO */
432  Chip_GPIO_Init();
433 
434  /* Setup GPIOs for USB demos */
435  Chip_SCU_PinMux(0x9, 5, (MD_PUP | MD_EZI), FUNC2); /* P9_5 USB1_VBUS_EN, USB1 VBus function */
436  Chip_SCU_PinMux(0x2, 5, (MD_PLN | MD_EZI | MD_ZI), FUNC2); /* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
437  Chip_SCU_PinMux(0x6, 3, (MD_PUP | MD_EZI), FUNC1); /* P6_3 USB0_PWR_EN, USB0 VBus function */
438 }
439 
440 /* Sets up board specific ADC interface */
441 void Board_ADC_Init(void)
442 {}
443 
444 /* Sets up board specific I2C interface */
446 {
447  if (I2Cx == LPC_I2C1) {
448  /* Configure pin function for I2C1 on PE.13 (I2C1_SDA) and PE.15 (I2C1_SCL) */
449  Chip_SCU_PinMux(0xE, 13, MD_ZI | MD_EZI, FUNC2);
450  Chip_SCU_PinMux(0xE, 15, MD_ZI | MD_EZI, FUNC2);
451  }
452 }
453 
454 /* Sets up board specific I2S interface and UDA1380 */
456 {
457  uint8_t uda1380_tx_data_buf[3];
458  Chip_I2S_Audio_Format_Type I2S_Config;
459  I2C_M_SETUP_Type I2C_Config;
460  I2C_Config.sl_addr7bit = I2CDEV_UDA1380_ADDR;
461  I2C_Config.retransmissions_max = 5;
462  I2C_Config.tx_length = 3;
463  I2C_Config.tx_data = uda1380_tx_data_buf;
464  I2C_Config.rx_length = 0;
465  I2C_Config.rx_data = NULL;
466 
467  /* Initialize I2C peripheral ------------------------------------*/
468  /* Init I2C */
471 
472  I2S_Config.SampleRate = 48000;
473  I2S_Config.ChannelNumber = 2; /* 1 is mono, 2 is stereo */
474  I2S_Config.WordWidth = 16; /* 8, 16 or 32 bits */
476  Chip_I2S_Config(LPC_I2S0, I2S_TX_MODE, &I2S_Config);
477  /* Enable Slave I2C operation */
479  /* Init UDA1380 CODEC */
480  while (UDA1380_init(&I2C_Config, audio_in_sel) != SUCCESS) {}
481 }
482 
483 /* Initialize the LCD interface */
484 void Board_LCD_Init(void)
485 {
486  /* LCD with HX8347-D LCD Controller */
487  SSP_ConfigFormat ssp_format1;
488  /* Attach main PLL clock to divider A with a divider of 2 */
490 
491  /* Route divider A output to LCD base clock and enable base clock */
493 
494  /* Reset LCD and wait for reset to complete */
496  while (Chip_RGU_InReset(RGU_LCD_RST)) {}
497 
498  /* Set backlight GPIO as an output */
499  Chip_GPIO_WriteDirBit(3, 8, true);
500 
501  delay(5);
502 
503  pinConfig();
504  // Chip_Clock_EnablePeripheralMax(SSP_ID);
505  /* TBD Externally */
507  // NVIC_EnableIRQ(SSP_ID);
509  Chip_SSP_Set_BitRate(SSP_ID, 1000000);
510 
511  ssp_format1.frameFormat = SSP_FRAMEFORMAT_SPI;
512  ssp_format1.bits = SSP_BITS_8;
513  ssp_format1.clockFormat = SSP_CLOCK_MODE0;
514 
515  Chip_SSP_Set_Format(SSP_ID, &ssp_format1);
517 
518  delay(200);
519 
520  /* Driving ability settings ------------------------------------------------*/
521  wr_reg(0xEA, 0x00); /* Power control internal used (1) */
522  wr_reg(0xEB, 0x20); /* Power control internal used (2) */
523  wr_reg(0xEC, 0x0C); /* Source control internal used (1) */
524  wr_reg(0xED, 0xC7); /* Source control internal used (2) */
525  wr_reg(0xE8, 0x38); /* Source output period Normal mode */
526  wr_reg(0xE9, 0x10); /* Source output period Idle mode */
527  wr_reg(0xF1, 0x01); /* RGB 18-bit interface ;0x0110 */
528  wr_reg(0xF2, 0x10);
529 
530  /* Adjust the Gamma Curve --------------------------------------------------*/
531  wr_reg(0x40, 0x01);
532  wr_reg(0x41, 0x00);
533  wr_reg(0x42, 0x00);
534  wr_reg(0x43, 0x10);
535  wr_reg(0x44, 0x0E);
536  wr_reg(0x45, 0x24);
537  wr_reg(0x46, 0x04);
538  wr_reg(0x47, 0x50);
539  wr_reg(0x48, 0x02);
540  wr_reg(0x49, 0x13);
541  wr_reg(0x4A, 0x19);
542  wr_reg(0x4B, 0x19);
543  wr_reg(0x4C, 0x16);
544 
545  wr_reg(0x50, 0x1B);
546  wr_reg(0x51, 0x31);
547  wr_reg(0x52, 0x2F);
548  wr_reg(0x53, 0x3F);
549  wr_reg(0x54, 0x3F);
550  wr_reg(0x55, 0x3E);
551  wr_reg(0x56, 0x2F);
552  wr_reg(0x57, 0x7B);
553  wr_reg(0x58, 0x09);
554  wr_reg(0x59, 0x06);
555  wr_reg(0x5A, 0x06);
556  wr_reg(0x5B, 0x0C);
557  wr_reg(0x5C, 0x1D);
558  wr_reg(0x5D, 0xCC);
559 
560  /* Power voltage setting ---------------------------------------------------*/
561  wr_reg(0x1B, 0x1B);
562  wr_reg(0x1A, 0x01);
563  wr_reg(0x24, 0x2F);
564  wr_reg(0x25, 0x57);
565  wr_reg(0x23, 0x88);
566 
567  /* Power on setting --------------------------------------------------------*/
568  wr_reg(0x18, 0x36); /* Internal oscillator frequency adj */
569  wr_reg(0x19, 0x01); /* Enable internal oscillator */
570  wr_reg(0x01, 0x00); /* Normal mode, no scrool */
571  wr_reg(0x1F, 0x88); /* Power control 6 - DDVDH Off */
572  delay(20);
573  wr_reg(0x1F, 0x82); /* Power control 6 - Step-up: 3 x VCI */
574  delay(5);
575  wr_reg(0x1F, 0x92); /* Power control 6 - Step-up: On */
576  delay(5);
577  wr_reg(0x1F, 0xD2); /* Power control 6 - VCOML active */
578  delay(5);
579 
580  /* Color selection ---------------------------------------------------------*/
581  wr_reg(0x17, 0x55); /* RGB, System interface: 16 Bit/Pixel*/
582  wr_reg(0x00, 0x00); /* Scrolling off, no standby */
583 
584  /* Interface config --------------------------------------------------------*/
585  wr_reg(0x2F, 0x11); /* LCD Drive: 1-line inversion */
586  wr_reg(0x31, 0x02); /* Value for SPI: 0x00, RBG: 0x02 */
587  wr_reg(0x32, 0x00); /* DPL=0, HSPL=0, VSPL=0, EPL=0 */
588 
589  /* Display on setting ------------------------------------------------------*/
590  wr_reg(0x28, 0x38); /* PT(0,0) active, VGL/VGL */
591  delay(20);
592  wr_reg(0x28, 0x3C); /* Display active, VGL/VGL */
593 
594  wr_reg(0x16, 0x00); /* Mem Access Control (MX/Y/V/L,BGR) */
595 
596  /* Display scrolling settings ----------------------------------------------*/
597  wr_reg(0x0E, 0x00); /* TFA MSB */
598  wr_reg(0x0F, 0x00); /* TFA LSB */
599  wr_reg(0x10, 320 >> 8); /* VSA MSB */
600  wr_reg(0x11, 320 & 0xFF); /* VSA LSB */
601  wr_reg(0x12, 0x00); /* BFA MSB */
602  wr_reg(0x13, 0x00); /* BFA LSB */
603 
604 }
605 
606 /* Initializes the STMPE811 touch screen controller */
608 {
609  volatile int32_t i;
610 
611  /* Init I2C */
614 
615  /* Enable Slave I2C operation */
617 
618  /* Reset Touch-screen controller */
620 
621  for (i = 0; i < 200000; i++) {}
622 
623  /* Enable TSC and ADC */
625  /* Enable Touch detect, FIFO */
627  /* Set sample time , 12-bit mode */
629 
630  for (i = 0; i < 40000; i++) {}
631 
632  /* ADC frequency 3.25 MHz */
634  /* Tracking index: 8, operation mode : XY only */
636  /* Detect delay 10us Settle time 500us*/
638  /* Threshold for FIFO */
640  /* FIFO reset */
642  /* FIFO not reset */
644  /* Drive 50 mA typical */
646  /* Pins are used for touchscreen */
648  /* Enable TSC */
650  /* Clear interrupt status */
652 }
653 
654 /* Get touch screen position */
655 bool GetTouchPos(int16_t *pX, int16_t *pY)
656 {
657  int16_t x, y, rng;
660  g_isPenDn = 1;
661  g_isNewPenDn = 1;
662 
663  /* calibrate X */
664  rng = ad_right - ad_left;
665  if (rng < 0) {
666  rng = -rng;
667  }
668  x -= (ad_right < ad_left) ? ad_right : ad_left;
669  *pX = (x * C_GLCD_H_SIZE) / rng;
670  if (ad_left > ad_right) {
671  *pX = C_GLCD_H_SIZE - *pX;
672  }
673 
674  /* calibrate Y */
675  rng = ad_bottom - ad_top;
676  if (rng < 0) {
677  rng = -rng;
678  }
679  y -= (ad_bottom < ad_top) ? ad_bottom : ad_top;
680  *pY = (y * C_GLCD_V_SIZE) / rng;
681  if (ad_top > ad_bottom) {
682  *pY = C_GLCD_V_SIZE - *pY;
683  }
684  }
685  else {
686  g_isPenDn = 0;
687  }
688 
689  if (g_isNewPenDn) {
690  g_isNewPenDn = 0;
691  if (*pX < 0) {
692  *pX = -*pX;
693  }
694  if (*pY < 0) {
695  *pY = -*pY;
696  }
697  return true;
698  }
699  return false;
700 }
701 
702 /* Turn on LCD backlight */
703 void Board_LCD_Set_Backlight(uint8_t Intensity)
704 {
705  bool OnOff = (bool) (Intensity != 0);
706 
707  Chip_GPIO_WritePortBit(3, 8, OnOff);
708 }
709 
710 /* Interrupt handler for GPIO0 */
712 {
713  static bool On;
714 
715  if (Chip_GPIO_IntGetStatus(0, 0, 0)) {
716  Chip_GPIO_IntClear(0, 0);
717  On = (bool) !On;
718  Board_LED_Set(1, On);
719  }
720 }
721 
722 /* Initializes board specific GPIO Interrupt */
724 {
725  Chip_SCU_PinMux(0xF, 9, (MD_PLN | MD_EZI | MD_ZI), FUNC0); /* PF.9 : POTI button */
726  Chip_GPIO_WriteDirBit(7, 23, false); /* PF.9 -> GPIO7[23] : input */
727  Chip_SCU_GPIOIntPinSel(0, 7, 23);
728  Chip_GPIO_IntCmd(0, 0, IP_GPIOPININT_FALLING_EDGE); /* Configure GPIO0[7] to interrupt pin (SW2 switch) */
729 
730  NVIC_EnableIRQ(PIN_INT0_IRQn); /* enable GPIO interrupt 0 */
731 }
732 
733 /* Initializes SDMMC interface */
735 {
736  Chip_SCU_PinMux(0xC, 4, MD_PLN_FAST, FUNC7); /* PC.4 connected to SDIO_D0 */
737  Chip_SCU_PinMux(0xC, 5, MD_PLN_FAST, FUNC7); /* PC.5 connected to SDIO_D1 */
738  Chip_SCU_PinMux(0xC, 6, MD_PLN_FAST, FUNC7); /* PC.6 connected to SDIO_D2 */
739  Chip_SCU_PinMux(0xC, 7, MD_PLN_FAST, FUNC7); /* PC.7 connected to SDIO_D3 */
740 
741  Chip_SCU_PinMux(0xC, 8, MD_PLN | MD_EZI, FUNC7);/* PC.4 connected to SDIO_CD */
742  Chip_SCU_PinMux(0xC, 10, MD_PLN_FAST, FUNC7); /* PC.10 connected to SDIO_CMD */
743  Chip_SCU_PinMux(0xC, 0, MD_PLN | MD_EHS, FUNC7);/* PC.0 connected to SDIO_CLK */
744 }
745 
746 /* Initializes SSP interface */
748 {
749  if (SSPx == LPC_SSP0) {
750  /* Set up clock and power for SSP0 module */
751  /* Configure SSP0 pins*/
752  Chip_SCU_PinMux(0x3, 3, MD_PLN_FAST, FUNC2); /* P3.3 connected to SCL/SCLK func2=SSP0 SCK0 */
753  Chip_SCU_PinMux(0x3, 6, MD_PLN_FAST, FUNC2); /* P3.6 connected to nCS func2=SSP0 SSEL0 */
754  Chip_SCU_PinMux(0x3, 7, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P3.7 connected to SO func2=SSP0 MISO0 */
755  Chip_SCU_PinMux(0x3, 8, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* P3.8 connected to nSI func2=SSP0 MOSI0 */
756 
757  Chip_Clock_EnableOpts(CLK_MX_SSP0, true, true, 1);
758  }
759  else if (SSPx == LPC_SSP1) {
760  /* Set up clock and power for SSP1 module */
761  /* Configure SSP1 pins*/
762  Chip_SCU_PinMux(0xF, 4, MD_PLN_FAST, FUNC0); /* PF.4 connected to SCL/SCLK func0 = SSP1 SCK1 */
763  Chip_SCU_PinMux(0xF, 5, MD_PLN_FAST, FUNC2); /* PF.5 connected to nCS func2 = SSP1 SSEL1 */
764  Chip_SCU_PinMux(0xF, 6, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* PF.6 connected to SO func2 = SSP1 MISO1 */
765  Chip_SCU_PinMux(0xF, 7, MD_PLN | MD_EZI | MD_ZI, FUNC2); /* PF.7 connected to nSI func2 = SSP1 MOSI1 */
766 
767  Chip_Clock_EnableOpts(CLK_MX_SSP1, true, true, 1);
768  }
769  else {
770  return;
771  }
772 }
773 
774 /* Initializes board specific buttons */
776 {
777  Chip_SCU_PinMux(0x4, 0, MD_PUP | MD_EZI | MD_ZI, FUNC0); /* P9.1 : LED 6 */
779 }
780 
781 /* Sets up default states for joystick */
783 {
784  Chip_SCU_PinMux(0xC, 9, MD_PUP | MD_EZI | MD_ZI, FUNC4); /* PC_9 as GPIO6[8] */
785  Chip_SCU_PinMux(0xC, 11, MD_PUP | MD_EZI | MD_ZI, FUNC4); /* PC_11 as GPIO6[10] */
786  Chip_SCU_PinMux(0xC, 12, MD_PUP | MD_EZI | MD_ZI, FUNC4); /* PC_12 as GPIO6[11] */
787  Chip_SCU_PinMux(0xC, 13, MD_PUP | MD_EZI | MD_ZI, FUNC4); /* PC_13 as GPIO6[12] */
788  Chip_SCU_PinMux(0xC, 14, MD_PUP | MD_EZI | MD_ZI, FUNC4); /* PC_14 as GPIO6[13] */
789 
795 }
796 
797 /* Gets joystick status */
798 uint8_t Joystick_GetStatus(void)
799 {
800 
801  uint8_t ret = NO_BUTTON_PRESSED;
802 
804  ret |= JOY_UP;
805  }
807  ret |= JOY_DOWN;
808  }
810  ret |= JOY_LEFT;
811  }
813  ret |= JOY_RIGHT;
814  }
816  ret |= JOY_PRESS;
817  }
818 
819  return ret;
820 }
821 
822 /* Gets buttons status */
824 {
825  uint8_t ret = NO_BUTTON_PRESSED;
826 
828  ret |= BUTTONS_BUTTON1;
829  }
830  return ret;
831 }
832 
833 /* FIXME Should we remove this function? */
834 void Serial_CreateStream(void *Stream)
835 {
836  // implement later
837 }
838