LPCOpen Platform for LPC18XX/43XX microcontrollers  18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
board.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 "retarget.h"
31 #include "wm8904.h"
32 
37 /* SDIO Data pin configuration bits */
38 #define SDIO_DAT_PINCFG (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_PULLUP | SCU_MODE_FUNC7)
39 
40 /*****************************************************************************
41  * Public types/enumerations/variables
42  ****************************************************************************/
43 
44 /* System configuration variables used by chip driver */
45 const uint32_t ExtRateIn = 0;
46 const uint32_t OscRateIn = 12000000;
47 
48 typedef struct {
49  uint8_t port;
50  uint8_t pin;
51 } io_port_t;
52 
53 static const io_port_t gpioLEDBits[] = {{3, 5}, {0, 7}, {3, 7}};
54 static uint32_t lcd_cfg_val;
55 
57 {
58  Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* P6,4 : UART0_TXD */
60 }
61 
62 /* Initialize debug output via UART for board */
63 void Board_Debug_Init(void)
64 {
65 #if defined(DEBUG_UART)
67 
71 
72  /* Enable UART Transmit */
74 #endif
75 }
76 
77 /* Sends a character on the UART */
78 void Board_UARTPutChar(char ch)
79 {
80 #if defined(DEBUG_UART)
81  /* Wait for space in FIFO */
83  Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch);
84 #endif
85 }
86 
87 /* Gets a character from the UART, returns EOF if no character is ready */
89 {
90 #if defined(DEBUG_UART)
92  return (int) Chip_UART_ReadByte(DEBUG_UART);
93  }
94 #endif
95  return EOF;
96 }
97 
98 /* Outputs a string on the debug UART */
99 void Board_UARTPutSTR(const char *str)
100 {
101 #if defined(DEBUG_UART)
102  while (*str != '\0') {
103  Board_UARTPutChar(*str++);
104  }
105 #endif
106 }
107 
108 static void Board_LED_Init()
109 {
110  uint32_t idx;
111 
112  for (idx = 0; idx < (sizeof(gpioLEDBits) / sizeof(io_port_t)); ++idx) {
113  /* Set pin direction and init to off */
114  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, gpioLEDBits[idx].port, gpioLEDBits[idx].pin);
115  Chip_GPIO_SetPinState(LPC_GPIO_PORT, gpioLEDBits[idx].port, gpioLEDBits[idx].pin, (bool) true);
116  }
117 }
118 
119 void Board_LED_Set(uint8_t LEDNumber, bool On)
120 {
121  if (LEDNumber < (sizeof(gpioLEDBits) / sizeof(io_port_t)))
122  Chip_GPIO_SetPinState(LPC_GPIO_PORT, gpioLEDBits[LEDNumber].port, gpioLEDBits[LEDNumber].pin, (bool) !On);
123 }
124 
125 bool Board_LED_Test(uint8_t LEDNumber)
126 {
127  if (LEDNumber < (sizeof(gpioLEDBits) / sizeof(io_port_t)))
128  return (bool) !Chip_GPIO_GetPinState(LPC_GPIO_PORT, gpioLEDBits[LEDNumber].port, gpioLEDBits[LEDNumber].pin);
129 
130  return false;
131 }
132 
133 void Board_LED_Toggle(uint8_t LEDNumber)
134 {
135  Board_LED_Set(LEDNumber, !Board_LED_Test(LEDNumber));
136 }
137 
139 {
142 }
143 
144 uint32_t Buttons_GetStatus(void)
145 {
146  uint8_t ret = NO_BUTTON_PRESSED;
148  ret |= BUTTONS_BUTTON1;
149  }
150  return ret;
151 }
152 
154 {}
155 
156 uint8_t Joystick_GetStatus(void)
157 {
158  return NO_BUTTON_PRESSED;
159 }
160 
161 /* Returns the MAC address assigned to this board */
162 void Board_ENET_GetMacADDR(uint8_t *mcaddr)
163 {
164  uint8_t boardmac[] = {0x00, 0x60, 0x37, 0x12, 0x34, 0x56};
165 
166  memcpy(mcaddr, boardmac, 6);
167 }
168 
169 /* Set up and initialize all required blocks and functions related to the
170  board hardware */
171 void Board_Init(void)
172 {
173  /* Sets up DEBUG UART */
174  DEBUGINIT();
175 
176  /* Initializes GPIO */
178 
179  /* Initialize LEDs */
180  Board_LED_Init();
182 }
183 
185 {
186  if (id == I2C1) {
187  /* Configure pin function for I2C1*/
188  Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.3 : I2C1_SDA */
189  Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_ZIF_DIS | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* P2.4 : I2C1_SCL */
190  }
191  else {
193  }
194 }
195 
197 {
198  Chip_SCU_PinMuxSet(0x1, 9, SDIO_DAT_PINCFG); /* P1.9 connected to SDIO_D0 */
199  Chip_SCU_PinMuxSet(0x1, 10, SDIO_DAT_PINCFG); /* P1.10 connected to SDIO_D1 */
200  Chip_SCU_PinMuxSet(0x1, 11, SDIO_DAT_PINCFG); /* P1.11 connected to SDIO_D2 */
201  Chip_SCU_PinMuxSet(0x1, 12, SDIO_DAT_PINCFG); /* P1.12 connected to SDIO_D3 */
202 
203  Chip_SCU_ClockPinMuxSet(2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC4)); /* CLK2 connected to SDIO_CLK */
204  Chip_SCU_PinMuxSet(0x1, 6, SDIO_DAT_PINCFG); /* P1.6 connected to SDIO_CMD */
205  Chip_SCU_PinMuxSet(0x1, 13, (SCU_MODE_INBUFF_EN | SCU_MODE_FUNC7)); /* P1.13 connected to SDIO_CD */
206 }
207 
209 {
210  if (pSSP == LPC_SSP1) {
211  Chip_SCU_PinMuxSet(0x1, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC5)); /* P1.5 => SSEL1 */
212  Chip_SCU_PinMuxSet(0xF, 4, (SCU_PINIO_FAST | SCU_MODE_FUNC0)); /* PF.4 => SCK1 */
213 
216  }
217  else {
218  return;
219  }
220 }
221 
222 /* Initialize DAC interface for the board */
224 {
226 }
227 
228 /* Initialize Audio Codec */
229 static Status Board_Audio_CodecInit(int micIn)
230 {
231 
232  if (!WM8904_Init(micIn)){
233  return ERROR;
234  }
235 
236  return SUCCESS;
237 }
238 
239 /* Board Audio initialization */
240 void Board_Audio_Init(LPC_I2S_T *pI2S, int micIn)
241 {
242 
243  if (pI2S == LPC_I2S0) {
244  /* TODO :Add pin mux for I2S0 later */
245  } else if (pI2S == LPC_I2S1) {
246  Chip_SCU_PinMuxSet (0x1, 19, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* I2S1_TX_SCK */
247  Chip_SCU_PinMuxSet (0x0, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* I2S1_TX_SDA */
248  Chip_SCU_PinMuxSet (0x3, 4, (SCU_PINIO_FAST | SCU_MODE_FUNC6)); /* I2S1_RX_SDA */
249  Chip_SCU_PinMuxSet (0x0, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC7)); /* I2S1_TX_WS */
250 
252  /* Setup base clock for CLKOUT */
254  } else {
255  /* It is a BUG catch it */
256  while(1);
257  }
258  /* Init WM8904 CODEC */
259  while (Board_Audio_CodecInit(micIn) != SUCCESS) {}
260 }
261 
262 /* Initialize Pin Muxing for LCD */
263 void Board_LCD_Init(void)
264 {
265  uint32_t val;
266 
268  val = LCD_SSP->CR0 & 0xFFFF;
272 
273  /* Enable the SSP interface */
279 
280  lcd_cfg_val = LCD_SSP->CR0 & 0xFFFF;
281  LCD_SSP->CR0 = val;
282 }
283 
284 /* Write data to LCD module */
285 void Board_LCD_WriteData(const uint8_t *data, uint16_t size)
286 {
287  uint32_t val = LCD_SSP->CR0 & 0xFFFF;
288  LCD_SSP->CR0 = lcd_cfg_val;
290  LCD_SSP->CR0 = val;
291 }
292