LPCOpen Platform for LPC112X microcontrollers  112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
board.c
Go to the documentation of this file.
1 /*
2  * @brief LPCXpresso 1125 board file
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2015
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 "retarget.h"
34 
35 
36 /*****************************************************************************
37  * Private types/enumerations/variables
38  ****************************************************************************/
39 
40 #define BUTTONS_BUTTON1_GPIO_PORT_NUM 1 /* WAKE button */
41 #define BUTTONS_BUTTON1_GPIO_BIT_NUM 4
42 #define BUTTONS_BUTTON2_GPIO_PORT_NUM 0 /* ISP button */
43 #define BUTTONS_BUTTON2_GPIO_BIT_NUM 1
44 
45 /* Be careful that these pins are set to output before Board_LED_Init()
46  is called. */
47 static const uint8_t ledPin[] = {1, 2, 4};
48 
49 /*****************************************************************************
50  * Public types/enumerations/variables
51  ****************************************************************************/
52 
53 /* System oscillator rate and clock rate on the CLKIN pin */
54 const uint32_t OscRateIn = 12000000;
55 const uint32_t ExtRateIn = 0;
56 
57 /*****************************************************************************
58  * Private functions
59  ****************************************************************************/
60 
61 /*****************************************************************************
62  * Public functions
63  ****************************************************************************/
64 
65 /* Sends a character on the UART */
66 void Board_UARTPutChar(char ch)
67 {
68 #if defined(DEBUG_UART)
70 #endif
71 }
72 
73 /* Gets a character from the UART, returns EOF if no character is ready */
75 {
76 #if defined(DEBUG_UART)
77  uint8_t data;
78 
79  if (Chip_UART_Read(DEBUG_UART, &data, 1) == 1) {
80  return (int) data;
81  }
82 #endif
83  return EOF;
84 }
85 
86 /* Outputs a string on the debug UART */
87 void Board_UARTPutSTR(const char *str)
88 {
89 #if defined(DEBUG_UART)
90  while (*str != '\0') {
91  Board_UARTPutChar(*str++);
92  }
93 #endif
94 }
95 
96 /* Initialize debug output via UART for board */
97 void Board_Debug_Init(void)
98 {
99 #if defined(DEBUG_UART)
102 
103  /* Setup UART for 115.2K8N1 */
105  Chip_UART_SetBaud(DEBUG_UART, 115200);
109 #endif
110 }
111 
112 /* Initializes board LED(s) */
113 static void Board_LED_Init(void)
114 {
115  uint32_t idx;
116  for (idx = 0; idx < (sizeof(ledPin)/sizeof(ledPin[0])); ++idx) {
117  /* Set the PIO_7 as output */
119  Board_LED_Set(idx, false);
120  }
121 }
122 
123 /* Sets the state of a board LED to on or off */
124 void Board_LED_Set(uint8_t LEDNumber, bool On)
125 {
126  if(LEDNumber < (sizeof(ledPin)/sizeof(ledPin[0]))) {
127  Chip_GPIO_SetPinState(LPC_GPIO, 1, ledPin[LEDNumber], !On);
128  }
129 }
130 
131 /* Returns the current state of a board LED */
132 bool Board_LED_Test(uint8_t LEDNumber)
133 {
134  bool state = false;
135 
136  if(LEDNumber < (sizeof(ledPin)/sizeof(ledPin[0]))) {
137  state = Chip_GPIO_GetPinState(LPC_GPIO, 1, ledPin[LEDNumber]);
138  }
139 
140  return state;
141 }
142 
143 void Board_LED_Toggle(uint8_t LEDNumber)
144 {
145  if(LEDNumber < (sizeof(ledPin)/sizeof(ledPin[0]))) {
146  Chip_GPIO_SetPinToggle(LPC_GPIO, 1, ledPin[LEDNumber]);
147  }
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  /* Initialize GPIO */
159 
160  /* Initialize LEDs */
161  Board_LED_Init();
162 }
163 
165 {
168 }
169 
170 uint32_t Buttons_GetStatus(void)
171 {
172  uint8_t ret = NO_BUTTON_PRESSED;
173 
175  ret |= BUTTONS_BUTTON1;
176  }
178  ret |= BUTTONS_BUTTON2;
179  }
180 
181  return ret;
182 }