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_11u14.c
Go to the documentation of this file.
1
/*
2
* @brief NXP XPRESSO 11U14 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
38
/*****************************************************************************
39
* Private types/enumerations/variables
40
****************************************************************************/
41
42
#define BUTTONS_BUTTON1_GPIO_PORT_NUM 0
43
#define BUTTONS_BUTTON1_GPIO_BIT_NUM 16
44
45
#define JOYSTICK_UP_GPIO_PORT_NUM 1
46
#define JOYSTICK_UP_GPIO_BIT_NUM 22
47
#define JOYSTICK_DOWN_GPIO_PORT_NUM 1
48
#define JOYSTICK_DOWN_GPIO_BIT_NUM 20
49
#define JOYSTICK_LEFT_GPIO_PORT_NUM 1
50
#define JOYSTICK_LEFT_GPIO_BIT_NUM 23
51
#define JOYSTICK_RIGHT_GPIO_PORT_NUM 1
52
#define JOYSTICK_RIGHT_GPIO_BIT_NUM 21
53
#define JOYSTICK_PRESS_GPIO_PORT_NUM 1
54
#define JOYSTICK_PRESS_GPIO_BIT_NUM 19
55
56
/*****************************************************************************
57
* Public types/enumerations/variables
58
****************************************************************************/
59
60
/* System Clock Frequency (Core Clock) */
61
uint32_t
SystemCoreClock
;
62
63
/*****************************************************************************
64
* Private functions
65
****************************************************************************/
66
67
/*****************************************************************************
68
* Public functions
69
****************************************************************************/
70
71
void
Board_UART_Init
(
void
)
72
{
73
/* Pin Muxing has already been done during the system init */
74
}
75
76
/* Sends a character on the UART */
77
void
Board_UARTPutChar
(
char
ch)
78
{
79
#if defined(DEBUG_ENABLE)
80
/* Wait for space in FIFO */
81
while
((
IP_UART_ReadLineStatus
(
DEBUG_UART
) &
UART_LSR_THRE
) == 0);
82
Chip_UART_SendByte
(
DEBUG_UART
, (uint8_t) ch);
83
#endif
84
}
85
86
/* Gets a character from the UART, returns EOF if no character is ready */
87
int
Board_UARTGetChar
(
void
)
88
{
89
#if defined(DEBUG_ENABLE)
90
if
(
Chip_UART_ReadLineStatus
(
DEBUG_UART
) &
UART_LSR_RDR
) {
91
return
(
int
)
Chip_UART_ReadByte
(
DEBUG_UART
);
92
}
93
#endif
94
return
EOF
;
95
}
96
97
/* Outputs a string on the debug UART */
98
void
Board_UARTPutSTR
(
char
*str)
99
{
100
#if defined(DEBUG_ENABLE)
101
while
(*str !=
'\0'
) {
102
Board_UARTPutChar
(*str++);
103
}
104
#endif
105
}
106
107
/* Initialize debug output via UART for board */
108
void
Board_Debug_Init
(
void
)
109
{
110
#if defined(DEBUG_ENABLE)
111
Board_UART_Init
();
112
113
/* Setup UART for 115.2K8N1 */
114
Chip_UART_Init
(
LPC_USART
);
115
Chip_UART_SetBaud
(
LPC_USART
, 115200);
116
Chip_UART_ConfigData
(
LPC_USART
, (
UART_LCR_WLEN8
|
UART_LCR_SBS_1BIT
));
117
Chip_UART_SetupFIFOS
(
LPC_USART
, (
UART_FCR_FIFO_EN
|
UART_FCR_TRG_LEV2
));
118
Chip_UART_TXEnable
(
LPC_USART
);
119
#endif
120
}
121
122
/* Initializes board LED(s) */
123
static
void
Board_LED_Init
(
void
)
124
{
125
/* Set the PIO_7 as output */
126
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
, 0, 7,
true
);
127
}
128
129
/* Sets the state of a board LED to on or off */
130
void
Board_LED_Set
(uint8_t LEDNumber,
bool
On
)
131
{
132
if
(LEDNumber == 0)
133
Chip_GPIO_WritePortBit
(
LPC_GPIO_PORT
, 0, 7, On);
134
}
135
136
/* Returns the current state of a board LED */
137
bool
Board_LED_Test
(uint8_t LEDNumber)
138
{
139
return
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
, 0, 7);
140
}
141
142
/* Update system core clock rate, should be called if the system has
143
a clock rate change */
144
void
SystemCoreClockUpdate
(
void
)
145
{
146
/* CPU core speed */
147
SystemCoreClock
=
Chip_Clock_GetSystemClockRate
();
148
}
149
150
/* Set up and initialize all required blocks and functions related to the
151
board hardware */
152
void
Board_Init
(
void
)
153
{
154
/* Sets up DEBUG UART */
155
DEBUGINIT
();
156
157
/* Updates SystemCoreClock global var with current clock speed */
158
SystemCoreClockUpdate
();
159
160
/* Initialize GPIO */
161
Chip_GPIO_Init
(
LPC_GPIO_PORT
);
162
163
/* Initialize LEDs */
164
Board_LED_Init
();
165
}
166
167
void
Board_SSP_Init
(
void
)
168
{
169
/* Only SSP0 is supported */
170
/* SSEL0 */
171
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 0, 2, (
IOCON_FUNC1
|
IOCON_MODE_PULLUP
));
172
/* SCK0 */
173
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 0, 6, (
IOCON_FUNC2
|
IOCON_MODE_PULLUP
));
174
/* MISO0 */
175
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 0, 8, (
IOCON_FUNC1
|
IOCON_MODE_PULLUP
));
176
/* MOSI0 */
177
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 0, 9, (
IOCON_FUNC1
|
IOCON_MODE_PULLUP
));
178
}
179
180
/* Configure pin for ADC channel 0 */
181
void
Board_ADC_Init
()
182
{
183
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 0, 11, 0x2);
184
}
185
186
void
Board_Buttons_Init
(
void
)
187
{
188
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
BUTTONS_BUTTON1_GPIO_PORT_NUM
,
BUTTONS_BUTTON1_GPIO_BIT_NUM
,
false
);
189
}
190
191
uint32_t
Buttons_GetStatus
(
void
)
192
{
193
uint8_t ret =
NO_BUTTON_PRESSED
;
194
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
BUTTONS_BUTTON1_GPIO_PORT_NUM
,
BUTTONS_BUTTON1_GPIO_BIT_NUM
) == 0x00) {
195
ret |=
BUTTONS_BUTTON1
;
196
}
197
return
ret;
198
}
199
200
void
Board_Joystick_Init
(
void
)
201
{
202
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
203
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
204
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
205
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
206
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
207
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
,
false
);
// input
208
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
,
false
);
// input
209
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
,
false
);
// input
210
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
,
false
);
// input
211
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
,
false
);
// input
212
}
213
214
uint8_t
Joystick_GetStatus
(
void
)
215
{
216
uint8_t ret =
NO_BUTTON_PRESSED
;
217
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
)) == 0x00) {
218
ret |=
JOY_UP
;
219
}
220
else
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
) == 0x00) {
221
ret |=
JOY_DOWN
;
222
}
223
else
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
)) == 0x00) {
224
ret |=
JOY_LEFT
;
225
}
226
else
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
) == 0x00) {
227
ret |=
JOY_RIGHT
;
228
}
229
else
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
)) == 0x00) {
230
ret |=
JOY_PRESS
;
231
}
232
return
ret;
233
}
234
software
lpc_core
lpc_board
boards_11xx
nxp_xpresso_11u14
board_nxp_xpresso_11u14.c
Generated on Fri May 10 2013 10:42:11 for LPCOpen Platform by
1.8.2