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_1347.c
Go to the documentation of this file.
1
/*
2
* @brief Xpresso 1347 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
/* Initialize pin muxing for UART interface */
72
void
Board_UART_Init
(
void
)
73
{
74
/* Pin Muxing has already been done during SystemInit */
75
}
76
77
/* Sends a character on the UART */
78
void
Board_UARTPutChar
(
char
ch)
79
{
80
#if defined(DEBUG_ENABLE)
81
/* Wait for space in FIFO */
82
while
((
IP_UART_ReadLineStatus
(
DEBUG_UART
) &
UART_LSR_THRE
) == 0) {}
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 */
88
int
Board_UARTGetChar
(
void
)
89
{
90
#if defined(DEBUG_ENABLE)
91
if
(
Chip_UART_ReadLineStatus
(
DEBUG_UART
) &
UART_LSR_RDR
) {
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
(
char
*str)
100
{
101
#if defined(DEBUG_ENABLE)
102
while
(*str !=
'\0'
) {
103
Board_UARTPutChar
(*str++);
104
}
105
#endif
106
}
107
108
/* Initialize debug output via UART for board */
109
void
Board_Debug_Init
(
void
)
110
{
111
#if defined(DEBUG_ENABLE)
112
Board_UART_Init
();
113
114
/* Setup UART for 115.2K8N1 */
115
Chip_UART_Init
(
LPC_USART
);
116
Chip_UART_SetBaud
(
LPC_USART
, 115200);
117
Chip_UART_ConfigData
(
LPC_USART
, (
UART_LCR_WLEN8
|
UART_LCR_SBS_1BIT
));
118
Chip_UART_SetupFIFOS
(
LPC_USART
, (
UART_FCR_FIFO_EN
|
UART_FCR_TRG_LEV2
));
119
Chip_UART_TXEnable
(
LPC_USART
);
120
#endif
121
}
122
123
/* Initializes board LED(s) */
124
static
void
Board_LED_Init
(
void
)
125
{
126
/* Set the PIO_7 as output */
127
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
, 0, 7,
true
);
128
}
129
130
/* Sets the state of a board LED to on or off */
131
void
Board_LED_Set
(uint8_t LEDNumber,
bool
On
)
132
{
133
if
(LEDNumber == 0)
134
Chip_GPIO_WritePortBit
(
LPC_GPIO_PORT
, 0, 7, On);
135
}
136
137
/* Returns the current state of a board LED */
138
bool
Board_LED_Test
(uint8_t LEDNumber)
139
{
140
return
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
, 0, 7);
141
}
142
143
/* Update system core clock rate, should be called if the system has
144
a clock rate change */
145
void
SystemCoreClockUpdate
(
void
)
146
{
147
/* CPU core speed */
148
SystemCoreClock
=
Chip_Clock_GetSystemClockRate
();
149
}
150
151
/* Set up and initialize all required blocks and functions related to the
152
board hardware */
153
void
Board_Init
(
void
)
154
{
155
/* Sets up DEBUG UART */
156
DEBUGINIT
();
157
158
/* Updates SystemCoreClock global var with current clock speed */
159
SystemCoreClockUpdate
();
160
161
/* Initialize GPIO */
162
Chip_GPIO_Init
(
LPC_GPIO_PORT
);
163
164
/* Initialize LEDs */
165
Board_LED_Init
();
166
}
167
168
/* Initialize pin muxing for SSP interface */
169
void
Board_SSP_Init
(
LPC_SSP_T
*pSSP)
170
{
171
if
(pSSP ==
LPC_SSP0
) {
172
}
173
else
{
174
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 1, 23, (
IOCON_FUNC2
|
IOCON_MODE_PULLUP
));
/* PIO1_23 connected to SSEL1 */
175
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 1, 20, (
IOCON_FUNC2
|
IOCON_MODE_PULLUP
));
/* PIO1_20 connected to SCK1 */
176
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 1, 21, (
IOCON_FUNC2
|
IOCON_MODE_PULLUP
));
/* PIO1_21 connected to MISO1 */
177
Chip_IOCON_PinMuxSet
(
LPC_IOCON
, 1, 22, (
IOCON_FUNC2
|
IOCON_MODE_PULLUP
));
/* PIO1_22 connected to MOSI1 */
178
}
179
}
180
181
/* Configure pin for ADC channel 0 */
182
void
Board_ADC_Init
(
void
)
183
{
184
/* Muxing already setup as part of SystemInit for AD0 */
185
}
186
187
/* Initialize buttons on the board */
188
void
Board_Buttons_Init
(
void
)
189
{
190
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
BUTTONS_BUTTON1_GPIO_PORT_NUM
,
BUTTONS_BUTTON1_GPIO_BIT_NUM
,
false
);
191
}
192
193
/* Get button status */
194
uint32_t
Buttons_GetStatus
(
void
)
195
{
196
uint8_t ret =
NO_BUTTON_PRESSED
;
197
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
BUTTONS_BUTTON1_GPIO_PORT_NUM
,
BUTTONS_BUTTON1_GPIO_BIT_NUM
) == 0x00) {
198
ret |=
BUTTONS_BUTTON1
;
199
}
200
return
ret;
201
}
202
203
/* Initialize Joystick */
204
void
Board_Joystick_Init
(
void
)
205
{
206
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
207
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
208
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
209
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
210
Chip_IOCON_PinMuxSet
(
LPC_IOCON
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
, (
IOCON_FUNC0
|
IOCON_MODE_PULLUP
));
211
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
,
false
);
212
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
,
false
);
213
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
,
false
);
214
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
,
false
);
215
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
,
false
);
216
}
217
218
/* Get Joystick status */
219
uint8_t
Joystick_GetStatus
(
void
)
220
{
221
uint8_t ret =
NO_BUTTON_PRESSED
;
222
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_UP_GPIO_PORT_NUM
,
JOYSTICK_UP_GPIO_BIT_NUM
)) == 0x00) {
223
ret |=
JOY_UP
;
224
}
225
else
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_DOWN_GPIO_PORT_NUM
,
JOYSTICK_DOWN_GPIO_BIT_NUM
) == 0x00) {
226
ret |=
JOY_DOWN
;
227
}
228
else
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_LEFT_GPIO_PORT_NUM
,
JOYSTICK_LEFT_GPIO_BIT_NUM
)) == 0x00) {
229
ret |=
JOY_LEFT
;
230
}
231
else
if
(
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_RIGHT_GPIO_PORT_NUM
,
JOYSTICK_RIGHT_GPIO_BIT_NUM
) == 0x00) {
232
ret |=
JOY_RIGHT
;
233
}
234
else
if
((
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
JOYSTICK_PRESS_GPIO_PORT_NUM
,
JOYSTICK_PRESS_GPIO_BIT_NUM
)) == 0x00) {
235
ret |=
JOY_PRESS
;
236
}
237
return
ret;
238
}
239
software
lpc_core
lpc_board
boards_13xx
nxp_xpresso_1347
board_nxp_xpresso_1347.c
Generated on Fri May 10 2013 10:42:11 for LPCOpen Platform by
1.8.2