1 /*
2  * Copyright 2017-2018 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _BOARD_H_
9 #define _BOARD_H_
10 
11 #include "clock_config.h"
12 #include "fsl_common.h"
13 #include "fsl_reset.h"
14 #include "fsl_gpio.h"
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 /*! @brief The board name */
20 #define BOARD_NAME "LPCXpresso5500"
21 
22 /*! @brief The UART to use for debug messages. */
23 /* TODO: rename UART to USART */
24 #define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
25 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) USART0
26 #define BOARD_DEBUG_UART_INSTANCE 0U
27 #define BOARD_DEBUG_UART_CLK_FREQ 12000000U
28 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0
29 #define BOARD_DEBUG_UART_RST kFC0_RST_SHIFT_RSTn
30 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_Flexcomm0
31 #define BOARD_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler
32 #define BOARD_UART_IRQ FLEXCOMM0_IRQn
33 
34 #define BOARD_ACCEL_I2C_BASEADDR I2C4
35 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000
36 
37 #define BOARD_DEBUG_UART_TYPE_CORE1 kSerialPort_Uart
38 #define BOARD_DEBUG_UART_BASEADDR_CORE1 (uint32_t) USART1
39 #define BOARD_DEBUG_UART_INSTANCE_CORE1 1U
40 #define BOARD_DEBUG_UART_CLK_FREQ_CORE1 12000000U
41 #define BOARD_DEBUG_UART_CLK_ATTACH_CORE1 kFRO12M_to_FLEXCOMM1
42 #define BOARD_DEBUG_UART_RST_CORE1 kFC1_RST_SHIFT_RSTn
43 #define BOARD_DEBUG_UART_CLKSRC_CORE1 kCLOCK_Flexcomm1
44 #define BOARD_UART_IRQ_HANDLER_CORE1 FLEXCOMM1_IRQHandler
45 #define BOARD_UART_IRQ_CORE1 FLEXCOMM1_IRQn
46 
47 #ifndef BOARD_DEBUG_UART_BAUDRATE
48 #define BOARD_DEBUG_UART_BAUDRATE 115200U
49 #endif /* BOARD_DEBUG_UART_BAUDRATE */
50 
51 #ifndef BOARD_DEBUG_UART_BAUDRATE_CORE1
52 #define BOARD_DEBUG_UART_BAUDRATE_CORE1 115200U
53 #endif /* BOARD_DEBUG_UART_BAUDRATE_CORE1 */
54 
55 #define BOARD_CODEC_I2C_BASEADDR I2C4
56 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000
57 
58 #ifndef BOARD_LED_RED_GPIO
59 #define BOARD_LED_RED_GPIO GPIO
60 #endif
61 #define BOARD_LED_RED_GPIO_PORT 1U
62 #ifndef BOARD_LED_RED_GPIO_PIN
63 #define BOARD_LED_RED_GPIO_PIN 6U
64 #endif
65 
66 #ifndef BOARD_LED_BLUE_GPIO
67 #define BOARD_LED_BLUE_GPIO GPIO
68 #endif
69 #define BOARD_LED_BLUE_GPIO_PORT 1U
70 #ifndef BOARD_LED_BLUE_GPIO_PIN
71 #define BOARD_LED_BLUE_GPIO_PIN 4U
72 #endif
73 
74 #ifndef BOARD_LED_GREEN_GPIO
75 #define BOARD_LED_GREEN_GPIO GPIO
76 #endif
77 #define BOARD_LED_GREEN_GPIO_PORT 1U
78 #ifndef BOARD_LED_GREEN_GPIO_PIN
79 #define BOARD_LED_GREEN_GPIO_PIN 7U
80 #endif
81 
82 #ifndef BOARD_SW1_GPIO
83 #define BOARD_SW1_GPIO GPIO
84 #endif
85 #define BOARD_SW1_GPIO_PORT 0U
86 #ifndef BOARD_SW1_GPIO_PIN
87 #define BOARD_SW1_GPIO_PIN 5U
88 #endif
89 #define BOARD_SW1_NAME "SW1"
90 #define BOARD_SW1_IRQ PIN_INT0_IRQn
91 #define BOARD_SW1_IRQ_HANDLER PIN_INT0_IRQHandler
92 
93 #ifndef BOARD_SW2_GPIO
94 #define BOARD_SW2_GPIO GPIO
95 #endif
96 #define BOARD_SW2_GPIO_PORT 1U
97 #ifndef BOARD_SW2_GPIO_PIN
98 #define BOARD_SW2_GPIO_PIN 18U
99 #endif
100 #define BOARD_SW2_NAME "SW2"
101 #define BOARD_SW2_IRQ PIN_INT1_IRQn
102 #define BOARD_SW2_IRQ_HANDLER PIN_INT1_IRQHandler
103 #define BOARD_SW2_GPIO_PININT_INDEX 1
104 
105 #ifndef BOARD_SW3_GPIO
106 #define BOARD_SW3_GPIO GPIO
107 #endif
108 #define BOARD_SW3_GPIO_PORT 1U
109 #ifndef BOARD_SW3_GPIO_PIN
110 #define BOARD_SW3_GPIO_PIN 9U
111 #endif
112 #define BOARD_SW3_NAME "SW3"
113 #define BOARD_SW3_IRQ PIN_INT1_IRQn
114 #define BOARD_SW3_IRQ_HANDLER PIN_INT1_IRQHandler
115 #define BOARD_SW3_GPIO_PININT_INDEX 1
116 
117 #define BOARD_SDIF_BASEADDR SDIF
118 #define BOARD_SDIF_CLKSRC kCLOCK_SDio
119 #define BOARD_SDIF_CLK_FREQ CLOCK_GetFreq(kCLOCK_SDio)
120 #define BOARD_SDIF_CLK_ATTACH kMAIN_CLK_to_SDIO_CLK
121 #define BOARD_SDIF_IRQ SDIO_IRQn
122 #define BOARD_MMC_VCC_SUPPLY kMMC_VoltageWindows270to360
123 #define BOARD_SD_CARD_DETECT_PIN 17
124 #define BOARD_SD_CARD_DETECT_PORT 0
125 #define BOARD_SD_CARD_DETECT_GPIO GPIO
126 #define BOARD_SD_DETECT_TYPE kSDMMCHOST_DetectCardByHostCD
127 
128 #define BOARD_SDIF_CD_GPIO_INIT()                                                                    \
129     {                                                                                                \
130         CLOCK_EnableClock(kCLOCK_Gpio2);                                                             \
131         GPIO_PinInit(BOARD_SD_CARD_DETECT_GPIO, BOARD_SD_CARD_DETECT_PORT, BOARD_SD_CARD_DETECT_PIN, \
132                      &(gpio_pin_config_t){kGPIO_DigitalInput, 0U});                                  \
133     }
134 #define BOARD_SDIF_CD_STATUS() \
135     GPIO_PinRead(BOARD_SD_CARD_DETECT_GPIO, BOARD_SD_CARD_DETECT_PORT, BOARD_SD_CARD_DETECT_PIN)
136 
137 /* Board led color mapping */
138 #define LOGIC_LED_ON 0U
139 #define LOGIC_LED_OFF 1U
140 
141 #define BOARD_SDIF_CLK_ATTACH kMAIN_CLK_to_SDIO_CLK
142 
143 #define LED_RED_INIT(output)                                                          \
144     GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \
145                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
146 #define LED_RED_ON()                                            \
147     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
148                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED1 */
149 #define LED_RED_OFF()                                                                \
150     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT,                        \
151                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED1 \ \ \ \ \ \ \
152                                                         */
153 #define LED_RED_TOGGLE()                                         \
154     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
155                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED1 */
156 
157 #define LED_BLUE_INIT(output)                                                            \
158     GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \
159                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
160 #define LED_BLUE_ON()                                             \
161     GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
162                    1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED1 */
163 #define LED_BLUE_OFF()                                          \
164     GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
165                  1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED1 */
166 #define LED_BLUE_TOGGLE()                                          \
167     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
168                     1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED1 */
169 
170 #define LED_GREEN_INIT(output)                                                              \
171     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
172                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
173 #define LED_GREEN_ON()                                              \
174     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
175                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED1 */
176 #define LED_GREEN_OFF()                                           \
177     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
178                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED1 */
179 #define LED_GREEN_TOGGLE()                                           \
180     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
181                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED1 */
182 
183 /*! @brief The WIFI-QCA shield pin. */
184 #define BOARD_INITGT202SHIELD_PWRON_GPIO GPIO
185 #define BOARD_INITGT202SHIELD_PWRON_PORT 1U
186 #define BOARD_INITGT202SHIELD_PWRON_PIN 8U
187 
188 #define BOARD_INITGT202SHIELD_IRQ_GPIO GPIO
189 #define BOARD_INITGT202SHIELD_IRQ_PORT 1U
190 #define BOARD_INITGT202SHIELD_IRQ_PIN 9U
191 
192 
193 /*! @brief The WIFI-QCA shield pin. */
194 #define BOARD_INITSILEX2401SHIELD_PWRON_GPIO GPIO
195 #define BOARD_INITSILEX2401SHIELD_PWRON_PORT 1U
196 #define BOARD_INITSILEX2401SHIELD_PWRON_PIN 7U
197 
198 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO GPIO
199 #define BOARD_INITSILEX2401SHIELD_IRQ_PORT 0U
200 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO_PIN 15U
201 
202 #if defined(__cplusplus)
203 extern "C" {
204 #endif /* __cplusplus */
205 
206 /*******************************************************************************
207  * API
208  ******************************************************************************/
209 
210 void BOARD_InitDebugConsole(void);
211 void BOARD_InitDebugConsole_Core1(void);
212 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
213 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
214 status_t BOARD_I2C_Send(I2C_Type *base,
215                         uint8_t deviceAddress,
216                         uint32_t subAddress,
217                         uint8_t subaddressSize,
218                         uint8_t *txBuff,
219                         uint8_t txBuffSize);
220 status_t BOARD_I2C_Receive(I2C_Type *base,
221                            uint8_t deviceAddress,
222                            uint32_t subAddress,
223                            uint8_t subaddressSize,
224                            uint8_t *rxBuff,
225                            uint8_t rxBuffSize);
226 void BOARD_Accel_I2C_Init(void);
227 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
228 status_t BOARD_Accel_I2C_Receive(
229     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
230 void BOARD_Codec_I2C_Init(void);
231 status_t BOARD_Codec_I2C_Send(
232     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
233 status_t BOARD_Codec_I2C_Receive(
234     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
235 #endif /* SDK_I2C_BASED_COMPONENT_USED */
236 
237 #if defined(__cplusplus)
238 }
239 #endif /* __cplusplus */
240 
241 #endif /* _BOARD_H_ */
242