1 /*
2  * Copyright 2018-2021 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _BOARD_H_
10 #define _BOARD_H_
11 
12 #include "clock_config.h"
13 #include "fsl_common.h"
14 #include "fsl_reset.h"
15 #include "fsl_gpio.h"
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 /*! @brief The board name */
21 #define BOARD_NAME      "EVK-MIMXRT595"
22 #define BOARD_I3C_CODEC (1)
23 
24 /*! @brief The UART to use for debug messages. */
25 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
26 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) USART0
27 #define BOARD_DEBUG_UART_INSTANCE 0U
28 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFlexcommClkFreq(0)
29 #define BOARD_DEBUG_UART_FRG_CLK \
30     (&(const clock_frg_clk_config_t){0U, kCLOCK_FrgPllDiv, 255U, 0U}) /*!< Select FRG0 mux as frg_pll */
31 #define BOARD_DEBUG_UART_CLK_ATTACH kFRG_to_FLEXCOMM0
32 #define BOARD_UART_IRQ_HANDLER      FLEXCOMM0_IRQHandler
33 #define BOARD_UART_IRQ              FLEXCOMM0_IRQn
34 
35 #if BOARD_I3C_CODEC
36 #define BOARD_CODEC_I2C_BASEADDR   I3C0
37 #define BOARD_CODEC_I2C_INSTANCE   0
38 #define BOARD_CODEC_I2C_CLOCK_FREQ CLOCK_GetI3cClkFreq()
39 #else
40 #define BOARD_CODEC_I2C_BASEADDR   I2C4
41 #define BOARD_CODEC_I2C_INSTANCE   4
42 #define BOARD_CODEC_I2C_CLOCK_FREQ CLOCK_GetFlexcommClkFreq(4)
43 #endif
44 
45 #define BOARD_FLEXSPI_PSRAM FLEXSPI1
46 #ifndef BOARD_ENABLE_PSRAM_CACHE
47 #define BOARD_ENABLE_PSRAM_CACHE 1
48 #endif
49 
50 #ifndef BOARD_DEBUG_UART_BAUDRATE
51 #define BOARD_DEBUG_UART_BAUDRATE 115200
52 #endif /* BOARD_DEBUG_UART_BAUDRATE */
53 
54 /* PCA9420 */
55 #define BOARD_PMIC_I2C_BASEADDR   I2C15
56 #define BOARD_PMIC_I2C_CLOCK_FREQ CLOCK_GetFlexcommClkFreq(15)
57 
58 /* Accelerometer */
59 #define BOARD_ACCEL_I2C_BASEADDR   I2C4
60 #define BOARD_ACCEL_I2C_ADDR       0x1E
61 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFlexcommClkFreq(4)
62 
63 /* Board led color mapping */
64 #define LOGIC_LED_ON  1U
65 #define LOGIC_LED_OFF 0U
66 
67 #ifndef BOARD_LED_RED_GPIO
68 #define BOARD_LED_RED_GPIO GPIO
69 #endif
70 #define BOARD_LED_RED_GPIO_PORT 0U
71 #ifndef BOARD_LED_RED_GPIO_PIN
72 #define BOARD_LED_RED_GPIO_PIN 14U
73 #endif
74 
75 #ifndef BOARD_LED_GREEN_GPIO
76 #define BOARD_LED_GREEN_GPIO GPIO
77 #endif
78 #define BOARD_LED_GREEN_GPIO_PORT 1U
79 #ifndef BOARD_LED_GREEN_GPIO_PIN
80 #define BOARD_LED_GREEN_GPIO_PIN 0U
81 #endif
82 #ifndef BOARD_LED_BLUE_GPIO
83 #define BOARD_LED_BLUE_GPIO GPIO
84 #endif
85 #define BOARD_LED_BLUE_GPIO_PORT 3U
86 #ifndef BOARD_LED_BLUE_GPIO_PIN
87 #define BOARD_LED_BLUE_GPIO_PIN 17U
88 #endif
89 
90 #ifndef BOARD_FLASH_RESET_GPIO
91 #define BOARD_FLASH_RESET_GPIO GPIO
92 #endif
93 #ifndef BOARD_FLASH_RESET_GPIO_PORT
94 #define BOARD_FLASH_RESET_GPIO_PORT 4U
95 #endif
96 #ifndef BOARD_FLASH_RESET_GPIO_PIN
97 #define BOARD_FLASH_RESET_GPIO_PIN 5U
98 #endif
99 
100 /* Board microphone defines */
101 #ifndef BOARD_DMIC_NUM
102 #define BOARD_DMIC_NUM 2
103 #endif
104 
105 #define LED_RED_INIT(output)                                                          \
106     GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \
107                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */
108 #define LED_RED_ON()                                          \
109     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
110                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
111 #define LED_RED_OFF()                                           \
112     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
113                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
114 #define LED_RED_TOGGLE()                                         \
115     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
116                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
117 
118 #define LED_GREEN_INIT(output)                                                              \
119     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
120                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */
121 #define LED_GREEN_ON()                                            \
122     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
123                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
124 #define LED_GREEN_OFF()                                             \
125     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
126                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
127 #define LED_GREEN_TOGGLE()                                           \
128     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
129                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
130 
131 #define LED_BLUE_INIT(output)                                                            \
132     GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \
133                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */
134 #define LED_BLUE_ON()                                           \
135     GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
136                  1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
137 #define LED_BLUE_OFF()                                            \
138     GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
139                    1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
140 #define LED_BLUE_TOGGLE()                                          \
141     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
142                     1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
143 
144 /* Board SW PIN */
145 #ifndef BOARD_SW1_GPIO
146 #define BOARD_SW1_GPIO GPIO
147 #endif
148 #define BOARD_SW1_GPIO_PORT 0U
149 #ifndef BOARD_SW1_GPIO_PIN
150 #define BOARD_SW1_GPIO_PIN 25U
151 #endif
152 
153 #ifndef BOARD_SW2_GPIO
154 #define BOARD_SW2_GPIO GPIO
155 #endif
156 #define BOARD_SW2_GPIO_PORT 0U
157 #ifndef BOARD_SW2_GPIO_PIN
158 #define BOARD_SW2_GPIO_PIN 10U
159 #endif
160 
161 /* USB PHY condfiguration */
162 #define BOARD_USB_PHY_D_CAL     (0x0CU)
163 #define BOARD_USB_PHY_TXCAL45DP (0x06U)
164 #define BOARD_USB_PHY_TXCAL45DM (0x06U)
165 
166 #define BOARD_FLASH_SIZE (0x4000000U)
167 
168 /* SSD1963 (TFT_PROTO_5) panel. */
169 /* RST pin. */
170 #define BOARD_SSD1963_RST_PORT 5
171 #define BOARD_SSD1963_RST_PIN  0
172 /* CS pin. */
173 #define BOARD_SSD1963_CS_PORT 5
174 #define BOARD_SSD1963_CS_PIN  1
175 /* D/C pin, also named RS pin. */
176 #define BOARD_SSD1963_RS_PORT 4
177 #define BOARD_SSD1963_RS_PIN  31
178 /* Touch panel. */
179 #define BOARD_SSD1963_TOUCH_I2C_BASEADDR   I2C4
180 #define BOARD_SSD1963_TOUCH_I2C_CLOCK_FREQ CLOCK_GetFlexcommClkFreq(4)
181 
182 /* MIPI panel. */
183 /* RST pin. */
184 #define BOARD_MIPI_RST_PORT 3
185 #define BOARD_MIPI_RST_PIN  21
186 /* POWER pin .*/
187 #define BOARD_MIPI_POWER_PORT 3
188 #define BOARD_MIPI_POWER_PIN  15
189 /* Backlight pin. */
190 #define BOARD_MIPI_BL_PORT 0
191 #define BOARD_MIPI_BL_PIN  12
192 /* TE pin. */
193 #define BOARD_MIPI_TE_PORT 3
194 #define BOARD_MIPI_TE_PIN  18
195 
196 /* Touch panel. */
197 #define BOARD_MIPI_PANEL_TOUCH_I2C_BASEADDR   I2C4
198 #define BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_FREQ CLOCK_GetFlexcommClkFreq(4)
199 #define BOARD_MIPI_PANEL_TOUCH_RST_PORT       4
200 #define BOARD_MIPI_PANEL_TOUCH_RST_PIN        4
201 #define BOARD_MIPI_PANEL_TOUCH_INT_PORT       3
202 #define BOARD_MIPI_PANEL_TOUCH_INT_PIN        19
203 
204 #define BOARD_BT_UART_INSTANCE 0
205 #define BOARD_BT_UART_BAUDRATE 3000000
206 #define BOARD_BT_UART_CLK_FREQ CLOCK_GetFlexcommClkFreq(0U)
207 #define BOARD_BT_UART_FRG_CLK \
208     (&(const clock_frg_clk_config_t){0, kCLOCK_FrgMainClk, 255, 0}) /*!< Select FRG0 mux as frg_pll */
209 #define BOARD_BT_UART_CLK_ATTACH  kFRG_to_FLEXCOMM0
210 #define BOARD_BT_UART_RST         kFC0_RST_SHIFT_RSTn
211 #define BOARD_BT_UART_IRQ         FLEXCOMM0_IRQn
212 #define BOARD_BT_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler
213 #define BOARD_BT_UART_CLKSRC      kCLOCK_Flexcomm0
214 #if defined(__cplusplus)
215 extern "C" {
216 #endif /* __cplusplus */
217 
218 /*******************************************************************************
219  * API
220  ******************************************************************************/
221 
222 void BOARD_InitDebugConsole(void);
223 status_t BOARD_InitPsRam(void);
224 void BOARD_FlexspiClockSafeConfig(void);
225 AT_QUICKACCESS_SECTION_CODE(void BOARD_SetFlexspiClock(FLEXSPI_Type *base, uint32_t src, uint32_t divider));
226 AT_QUICKACCESS_SECTION_CODE(void BOARD_DeinitFlash(FLEXSPI_Type *base));
227 AT_QUICKACCESS_SECTION_CODE(void BOARD_InitFlash(FLEXSPI_Type *base));
228 AT_QUICKACCESS_SECTION_CODE(void BOARD_SetDeepSleepPinConfig(void));
229 AT_QUICKACCESS_SECTION_CODE(void BOARD_RestoreDeepSleepPinConfig(void));
230 AT_QUICKACCESS_SECTION_CODE(void BOARD_EnterDeepSleep(const uint32_t exclude_from_pd[4]));
231 AT_QUICKACCESS_SECTION_CODE(void BOARD_EnterDeepPowerDown(const uint32_t exclude_from_pd[4]));
232 
233 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
234 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
235 status_t BOARD_I2C_Send(I2C_Type *base,
236                         uint8_t deviceAddress,
237                         uint32_t subAddress,
238                         uint8_t subaddressSize,
239                         uint8_t *txBuff,
240                         uint8_t txBuffSize);
241 status_t BOARD_I2C_Receive(I2C_Type *base,
242                            uint8_t deviceAddress,
243                            uint32_t subAddress,
244                            uint8_t subaddressSize,
245                            uint8_t *rxBuff,
246                            uint8_t rxBuffSize);
247 
248 void BOARD_PMIC_I2C_Init(void);
249 status_t BOARD_PMIC_I2C_Send(
250     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
251 status_t BOARD_PMIC_I2C_Receive(
252     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
253 
254 void BOARD_MIPIPanelTouch_I2C_Init(void);
255 status_t BOARD_MIPIPanelTouch_I2C_Send(
256     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
257 status_t BOARD_MIPIPanelTouch_I2C_Receive(
258     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
259 
260 void BOARD_Accel_I2C_Init(void);
261 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint32_t txBuff);
262 status_t BOARD_Accel_I2C_Receive(
263     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
264 #endif /* SDK_I2C_BASED_COMPONENT_USED */
265 
266 #if defined BOARD_USE_CODEC
267 void BOARD_I3C_Init(I3C_Type *base, uint32_t clkSrc_Hz);
268 status_t BOARD_I3C_Send(I3C_Type *base,
269                         uint8_t deviceAddress,
270                         uint32_t subAddress,
271                         uint8_t subaddressSize,
272                         uint8_t *txBuff,
273                         uint8_t txBuffSize);
274 status_t BOARD_I3C_Receive(I3C_Type *base,
275                            uint8_t deviceAddress,
276                            uint32_t subAddress,
277                            uint8_t subaddressSize,
278                            uint8_t *rxBuff,
279                            uint8_t rxBuffSize);
280 void BOARD_Codec_I2C_Init(void);
281 status_t BOARD_Codec_I2C_Send(
282     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
283 status_t BOARD_Codec_I2C_Receive(
284     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
285 #endif
286 
287 #if defined(__cplusplus)
288 }
289 #endif /* __cplusplus */
290 
291 #endif /* _BOARD_H_ */
292