1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2018 NXP
4  * All rights reserved.
5  *
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  */
9 
10 #ifndef _BOARD_H_
11 #define _BOARD_H_
12 
13 #include "clock_config.h"
14 #include "fsl_common.h"
15 #include "fsl_gpio.h"
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 /*! @brief The board name */
21 #define BOARD_NAME "LPCXPRESSO54628"
22 
23 #define BOARD_EXTCLKINRATE (0)
24 
25 /*! @brief The UART to use for debug messages. */
26 /* TODO: rename UART to USART */
27 #define BOARD_DEBUG_UART_TYPE       kSerialPort_Uart
28 #define BOARD_DEBUG_UART_BASEADDR   (uint32_t) USART0
29 #define BOARD_DEBUG_UART_INSTANCE   0U
30 #define BOARD_DEBUG_UART_CLK_FREQ   CLOCK_GetFlexCommClkFreq(0)
31 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0
32 #define BOARD_DEBUG_UART_RST        kFC0_RST_SHIFT_RSTn
33 #define BOARD_DEBUG_UART_CLKSRC     kCLOCK_Flexcomm0
34 #define BOARD_UART_IRQ_HANDLER      FLEXCOMM0_IRQHandler
35 #define BOARD_UART_IRQ              FLEXCOMM0_IRQn
36 /* TODO: obsolete */
37 #define BOARD_DEBUG_SPI_CLK_FREQ 12000000
38 
39 #ifndef BOARD_DEBUG_UART_BAUDRATE
40 #define BOARD_DEBUG_UART_BAUDRATE 115200
41 #endif /* BOARD_DEBUG_UART_BAUDRATE */
42 
43 /*! @brief The ENET PHY address. */
44 #define BOARD_ENET0_PHY_ADDRESS (0x00U) /* Phy address of enet port 0. */
45 
46 /*! @brief Memory ranges not usable by the ENET DMA. */
47 #ifndef BOARD_ENET_NON_DMA_MEMORY_ARRAY
48 #define BOARD_ENET_NON_DMA_MEMORY_ARRAY                                                     \
49     {                                                                                       \
50         {0x00000000U, 0x0007FFFFU}, {0x10000000U, 0x17FFFFFFU}, {0x80000000U, 0xDFFFFFFFU}, \
51             {0x00000000U, 0x00000000U},                                                     \
52     }
53 #endif /* BOARD_ENET_NON_DMA_MEMORY_ARRAY */
54 
55 /* LPI2C */
56 #define BOARD_ACCEL_I2C_BASEADDR   I2C2
57 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000
58 
59 #define BOARD_CODEC_I2C_BASEADDR   I2C2
60 #define BOARD_CODEC_I2C_INSTANCE   2U
61 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000
62 
63 #ifndef BOARD_LED1_GPIO
64 #define BOARD_LED1_GPIO GPIO
65 #endif
66 #define BOARD_LED1_GPIO_PORT 3U
67 #ifndef BOARD_LED1_GPIO_PIN
68 #define BOARD_LED1_GPIO_PIN 14U
69 #endif
70 #ifndef BOARD_LED2_GPIO
71 #define BOARD_LED2_GPIO GPIO
72 #endif
73 #define BOARD_LED2_GPIO_PORT 3U
74 #ifndef BOARD_LED2_GPIO_PIN
75 #define BOARD_LED2_GPIO_PIN 3U
76 #endif
77 #ifndef BOARD_LED3_GPIO
78 #define BOARD_LED3_GPIO GPIO
79 #endif
80 #define BOARD_LED3_GPIO_PORT 2U
81 #ifndef BOARD_LED3_GPIO_PIN
82 #define BOARD_LED3_GPIO_PIN 2U
83 #endif
84 
85 #ifndef BOARD_SW1_GPIO
86 #define BOARD_SW1_GPIO GPIO
87 #endif
88 #define BOARD_SW1_GPIO_PORT 0U
89 #ifndef BOARD_SW1_GPIO_PIN
90 #define BOARD_SW1_GPIO_PIN 4U
91 #endif
92 #define BOARD_SW1_NAME        "SW1"
93 #define BOARD_SW3_IRQ         PIN_INT0_IRQn
94 #define BOARD_SW3_IRQ_HANDLER PIN_INT0_IRQHandler
95 
96 #ifndef BOARD_SW2_GPIO
97 #define BOARD_SW2_GPIO GPIO
98 #endif
99 #define BOARD_SW2_GPIO_PORT 0U
100 #ifndef BOARD_SW2_GPIO_PIN
101 #define BOARD_SW2_GPIO_PIN 6U
102 #endif
103 #define BOARD_SW2_NAME        "SW2"
104 #define BOARD_SW2_IRQ         PIN_INT0_IRQn
105 #define BOARD_SW2_IRQ_HANDLER PIN_INT0_IRQHandler
106 
107 #ifndef BOARD_SW3_GPIO
108 #define BOARD_SW3_GPIO GPIO
109 #endif
110 #define BOARD_SW3_GPIO_PORT 0U
111 #ifndef BOARD_SW3_GPIO_PIN
112 #define BOARD_SW3_GPIO_PIN 5U
113 #endif
114 #define BOARD_SW3_NAME              "SW3"
115 #define BOARD_SW3_IRQ               PIN_INT0_IRQn
116 #define BOARD_SW3_IRQ_HANDLER       PIN_INT0_IRQHandler
117 #define BOARD_SW3_GPIO_PININT_INDEX 0
118 
119 #ifndef BOARD_SW4_GPIO
120 #define BOARD_SW4_GPIO GPIO
121 #endif
122 #ifndef BOARD_SW4_GPIO_PORT
123 #define BOARD_SW4_GPIO_PORT 0U
124 #endif
125 #ifndef BOARD_SW4_GPIO_PIN
126 #define BOARD_SW4_GPIO_PIN 4U
127 #endif
128 #define BOARD_SW4_NAME              "SW4"
129 #define BOARD_SW4_IRQ               PIN_INT0_IRQn
130 #define BOARD_SW4_IRQ_HANDLER       PIN_INT0_IRQHandler
131 #define BOARD_SW4_GPIO_PININT_INDEX 0
132 
133 #ifndef BOARD_SW5_GPIO
134 #define BOARD_SW5_GPIO GPIO
135 #endif
136 #ifndef BOARD_SW5_GPIO_PORT
137 #define BOARD_SW5_GPIO_PORT 1U
138 #endif
139 #ifndef BOARD_SW5_GPIO_PIN
140 #define BOARD_SW5_GPIO_PIN 1U
141 #endif
142 #define BOARD_SW5_NAME              "SW5"
143 #define BOARD_SW5_IRQ               PIN_INT1_IRQn
144 #define BOARD_SW5_IRQ_HANDLER       PIN_INT1_IRQHandler
145 #define BOARD_SW5_GPIO_PININT_INDEX 0
146 
147 #define BOARD_ARDUINO_INT_IRQ   (GINT0_IRQn)
148 #define BOARD_ARDUINO_I2C_IRQ   (FLEXCOMM2_IRQn)
149 #define BOARD_ARDUINO_I2C_INDEX (2)
150 
151 /* Board led color mapping */
152 #define LOGIC_LED_ON  0U
153 #define LOGIC_LED_OFF 1U
154 
155 #define LED1_INIT(output)                                                    \
156     GPIO_PinInit(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, BOARD_LED1_GPIO_PIN, \
157                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
158 #define LED1_ON() \
159     GPIO_PortClear(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Turn on target LED1 */
160 #define LED1_OFF() \
161     GPIO_PortSet(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Turn off target LED1 */
162 #define LED1_TOGGLE() \
163     GPIO_PortToggle(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Toggle on target LED1 */
164 #define LED2_INIT(output)                                                    \
165     GPIO_PinInit(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, BOARD_LED2_GPIO_PIN, \
166                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED2 */
167 #define LED2_ON() \
168     GPIO_PortClear(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Turn on target LED2 */
169 #define LED2_OFF() \
170     GPIO_PortSet(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Turn off target LED2 */
171 #define LED2_TOGGLE() \
172     GPIO_PortToggle(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Toggle on target LED2 */
173 
174 #define LED3_INIT(output)                                                    \
175     GPIO_PinInit(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, BOARD_LED3_GPIO_PIN, \
176                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED3 */
177 #define LED3_ON() \
178     GPIO_PortClear(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Turn on target LED3 */
179 #define LED3_OFF() \
180     GPIO_PortSet(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Turn off target LED3 */
181 #define LED3_TOGGLE() \
182     GPIO_PortToggle(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Toggle on target LED3 */
183 
184 /* LCD panel. */
185 #define BOARD_LCD_BL_GPIO          3
186 #define BOARD_LCD_BL_PIN           31
187 #define BOARD_TOUCH_PANEL_RST_GPIO 2
188 #define BOARD_TOUCH_PANEL_RST_PIN  27
189 
190 /* @Brief Board touch panel configuration */
191 #define BOARD_TOUCH_I2C_BASEADDR I2C2
192 #define BOARD_TOUCH_RST_GPIO     GPIO
193 #define BOARD_TOUCH_RST_PORT     2
194 #define BOARD_TOUCH_RST_PIN      27
195 #define BOARD_TOUCH_INT_GPIO     GPIO
196 #define BOARD_TOUCH_INT_PORT     4
197 #define BOARD_TOUCH_INT_PIN      0
198 
199 /* Serial MWM WIFI */
200 #define BOARD_SERIAL_MWM_PORT_CLK_FREQ CLOCK_GetFlexCommClkFreq(4)
201 #define BOARD_SERIAL_MWM_PORT          USART4
202 #define BOARD_SERIAL_MWM_PORT_IRQn     FLEXCOMM4_IRQn
203 #define BOARD_SERIAL_MWM_RST_GPIO      GPIO
204 #define BOARD_SERIAL_MWM_RST_PORT      1
205 #define BOARD_SERIAL_MWM_RST_PIN       22
206 #define BOARD_SERIAL_MWM_RST_WRITE(output) \
207     GPIO_PinWrite(BOARD_SERIAL_MWM_RST_GPIO, BOARD_SERIAL_MWM_RST_PORT, BOARD_SERIAL_MWM_RST_PIN, output)
208 
209 #if defined(__cplusplus)
210 extern "C" {
211 #endif /* __cplusplus */
212 
213 /*******************************************************************************
214  * API
215  ******************************************************************************/
216 
217 status_t BOARD_InitDebugConsole(void);
218 void BOARD_InitSDRAM(void);
219 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
220 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
221 status_t BOARD_I2C_Send(I2C_Type *base,
222                         uint8_t deviceAddress,
223                         uint32_t subAddress,
224                         uint8_t subaddressSize,
225                         uint8_t *txBuff,
226                         uint8_t txBuffSize);
227 status_t BOARD_I2C_Receive(I2C_Type *base,
228                            uint8_t deviceAddress,
229                            uint32_t subAddress,
230                            uint8_t subaddressSize,
231                            uint8_t *rxBuff,
232                            uint8_t rxBuffSize);
233 void BOARD_Accel_I2C_Init(void);
234 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
235 status_t BOARD_Accel_I2C_Receive(
236     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
237 void BOARD_Codec_I2C_Init(void);
238 status_t BOARD_Codec_I2C_Send(
239     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
240 status_t BOARD_Codec_I2C_Receive(
241     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
242 status_t BOARD_Touch_I2C_Send(
243     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
244 status_t BOARD_Touch_I2C_Receive(
245     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
246 #endif /* SDK_I2C_BASED_COMPONENT_USED */
247 
248 #if defined(__cplusplus)
249 }
250 #endif /* __cplusplus */
251 
252 #endif /* _BOARD_H_ */
253