1 /*
2  * Copyright 2020 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_gpio.h"
14 #include "fsl_clock.h"
15 #if defined(CONFIG_BT_LOW_POWER_MODE) && (CONFIG_BT_LOW_POWER_MODE)
16 #if (defined(BUTTON_COUNT) && (BUTTON_COUNT > 0U))
17 #include "fsl_component_button.h"
18 #endif /* BUTTON_COUNT */
19 #endif /* CONFIG_BT_LOW_POWER_MODE */
20 
21 /*******************************************************************************
22  * Definitions
23  ******************************************************************************/
24 /*! @brief The board name */
25 #define BOARD_NAME "MIMXRT1170-EVK"
26 #ifndef DEBUG_CONSOLE_UART_INDEX
27 #define DEBUG_CONSOLE_UART_INDEX 1
28 #endif
29 
30 /* The UART to use for debug messages. */
31 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
32 #define BOARD_DEBUG_UART_CLK_FREQ 24000000
33 
34 #if DEBUG_CONSOLE_UART_INDEX == 1
35 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART1
36 #define BOARD_DEBUG_UART_INSTANCE 1U
37 #define BOARD_UART_IRQ            LPUART1_IRQn
38 #define BOARD_UART_IRQ_HANDLER    LPUART1_IRQHandler
39 #elif DEBUG_CONSOLE_UART_INDEX == 2
40 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART2
41 #define BOARD_DEBUG_UART_INSTANCE 2U
42 #define BOARD_UART_IRQ            LPUART2_IRQn
43 #define BOARD_UART_IRQ_HANDLER    LPUART2_IRQHandler
44 #elif DEBUG_CONSOLE_UART_INDEX == 12
45 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART12
46 #define BOARD_DEBUG_UART_INSTANCE 12U
47 #define BOARD_UART_IRQ            LPUART12_IRQn
48 #define BOARD_UART_IRQ_HANDLER    LPUART12_IRQHandler
49 #else
50 #error "Unsupported UART"
51 #endif
52 
53 #ifndef BOARD_DEBUG_UART_BAUDRATE
54 #define BOARD_DEBUG_UART_BAUDRATE (115200U)
55 #endif /* BOARD_DEBUG_UART_BAUDRATE */
56 
57 /* Definitions for eRPC MU transport layer */
58 #if defined(FSL_FEATURE_MU_SIDE_A)
59 #define MU_BASE        MUA
60 #define MU_IRQ         MUA_IRQn
61 #define MU_IRQ_HANDLER MUA_IRQHandler
62 #endif
63 #if defined(FSL_FEATURE_MU_SIDE_B)
64 #define MU_BASE        MUB
65 #define MU_IRQ         MUB_IRQn
66 #define MU_IRQ_HANDLER MUB_IRQHandler
67 #endif
68 #define MU_IRQ_PRIORITY (2)
69 
70 /*! @brief The USER_LED used for board */
71 #define LOGIC_LED_ON  (0U)
72 #define LOGIC_LED_OFF (1U)
73 #ifndef BOARD_USER_LED_GPIO
74 #define BOARD_USER_LED_GPIO GPIO9
75 #endif
76 #ifndef BOARD_USER_LED_GPIO_PIN
77 #define BOARD_USER_LED_GPIO_PIN (3U)
78 #endif
79 
80 #define USER_LED_INIT(output)                                            \
81     GPIO_PinWrite(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN, output); \
82     BOARD_USER_LED_GPIO->GDIR |= (1U << BOARD_USER_LED_GPIO_PIN) /*!< Enable target USER_LED */
83 #define USER_LED_OFF() \
84     GPIO_PortClear(BOARD_USER_LED_GPIO, 1U << BOARD_USER_LED_GPIO_PIN)                 /*!< Turn off target USER_LED */
85 #define USER_LED_ON() GPIO_PortSet(BOARD_USER_LED_GPIO, 1U << BOARD_USER_LED_GPIO_PIN) /*!<Turn on target USER_LED*/
86 #define USER_LED_TOGGLE()                                       \
87     GPIO_PinWrite(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN, \
88                   0x1 ^ GPIO_PinRead(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN)) /*!< Toggle target USER_LED */
89 
90 /*! @brief Define the port interrupt number for the board switches */
91 #ifndef BOARD_USER_BUTTON_GPIO
92 #define BOARD_USER_BUTTON_GPIO GPIO13
93 #endif
94 #ifndef BOARD_USER_BUTTON_GPIO_PIN
95 #define BOARD_USER_BUTTON_GPIO_PIN (0U)
96 #endif
97 #define BOARD_USER_BUTTON_IRQ         GPIO13_Combined_0_31_IRQn
98 #define BOARD_USER_BUTTON_IRQ_HANDLER GPIO13_Combined_0_31_IRQHandler
99 #define BOARD_USER_BUTTON_NAME        "SW7"
100 
101 #if defined(CONFIG_BT_LOW_POWER_MODE) && (CONFIG_BT_LOW_POWER_MODE)
102 #ifndef BUTTON_COUNT
103 #define BUTTON_COUNT 1
104 #endif
105 #if (defined(BUTTON_COUNT) && (BUTTON_COUNT > 0U))
106 #define APP_WAKEUP_BUTTON               BOARD_USER_BUTTON_GPIO
107 #define APP_WAKEUP_BUTTON_GPIO          13
108 #define APP_WAKEUP_BUTTON_GPIO_PIN      BOARD_USER_BUTTON_GPIO_PIN
109 #define APP_WAKEUP_BUTTON_DEFAULT_VALUE 1
110 #define APP_WAKEUP_BUTTON_IRQ           BOARD_USER_BUTTON_IRQ
111 #define APP_WAKEUP_BUTTON_IRQ_HANDLER   BOARD_USER_BUTTON_IRQ_HANDLER
112 #define APP_WAKEUP_BUTTON_NAME          BOARD_USER_BUTTON_NAME
113 
114 extern button_config_t g_buttonConfig[];
115 #endif /* BUTTON_COUNT */
116 #endif /* CONFIG_BT_LOW_POWER_MODE */
117 
118 /*! @brief The board flash size */
119 #define BOARD_FLASH_SIZE (0x1000000U)
120 
121 /* SKIP_SEMC_INIT can also be defined independently */
122 #ifdef USE_SDRAM
123 #define SKIP_SEMC_INIT
124 #endif
125 
126 /*! @brief The ENET0 PHY address. */
127 #define BOARD_ENET0_PHY_ADDRESS (0x02U) /* Phy address of enet port 0. */
128 
129 /*! @brief The ENET1 PHY address. */
130 #define BOARD_ENET1_PHY_ADDRESS (0x01U) /* Phy address of enet port 1. */
131 
132 /*! @brief The EMVSIM SMARTCARD PHY configuration. */
133 #define BOARD_SMARTCARD_MODULE                (EMVSIM1)      /*!< SMARTCARD communicational module instance */
134 #define BOARD_SMARTCARD_MODULE_IRQ            (EMVSIM1_IRQn) /*!< SMARTCARD communicational module IRQ handler */
135 #define BOARD_SMARTCARD_CLOCK_MODULE_CLK_FREQ (CLOCK_GetRootClockFreq(kCLOCK_Root_Emv1))
136 #define BOARD_SMARTCARD_CLOCK_VALUE           (4000000U) /*!< SMARTCARD clock frequency */
137 
138 /* USB PHY condfiguration */
139 #define BOARD_USB_PHY_D_CAL     (0x07U)
140 #define BOARD_USB_PHY_TXCAL45DP (0x06U)
141 #define BOARD_USB_PHY_TXCAL45DM (0x06U)
142 
143 #define BOARD_ARDUINO_INT_IRQ   (GPIO1_INT3_IRQn)
144 #define BOARD_ARDUINO_I2C_IRQ   (LPI2C1_IRQn)
145 #define BOARD_ARDUINO_I2C_INDEX (1)
146 
147 #define BOARD_HAS_SDCARD (1U)
148 
149 /* @Brief Board accelerator sensor configuration */
150 #define BOARD_ACCEL_I2C_BASEADDR LPI2C5
151 /* Clock divider for LPI2C clock source */
152 #define BOARD_ACCEL_I2C_CLOCK_FREQ (CLOCK_GetRootClockFreq(kCLOCK_Root_Lpi2c5))
153 
154 #define BOARD_CODEC_I2C_BASEADDR             LPI2C5
155 #define BOARD_CODEC_I2C_INSTANCE             5U
156 #define BOARD_CODEC_I2C_CLOCK_SOURCE_SELECT  (0U)
157 #define BOARD_CODEC_I2C_CLOCK_SOURCE_DIVIDER (6U)
158 #define BOARD_CODEC_I2C_CLOCK_FREQ           (24000000U)
159 
160 /* @Brief Board CAMERA configuration */
161 #define BOARD_CAMERA_I2C_BASEADDR      LPI2C6
162 #define BOARD_CAMERA_I2C_CLOCK_ROOT    kCLOCK_Root_Lpi2c6
163 #define BOARD_CAMERA_I2C_CLOCK_SOURCE  (1U)  /* OSC24M. */
164 #define BOARD_CAMERA_I2C_CLOCK_DIVIDER (12U) /* Divider = 12, LPI2C clock frequency 2M. */
165 
166 /*! @brief The MIPI panel pins. */
167 #define BOARD_MIPI_PANEL_RST_GPIO   GPIO9
168 #define BOARD_MIPI_PANEL_RST_PIN    1
169 #define BOARD_MIPI_PANEL_POWER_GPIO GPIO11
170 #define BOARD_MIPI_PANEL_POWER_PIN  16
171 /* Back light pin. */
172 #define BOARD_MIPI_PANEL_BL_GPIO GPIO9
173 #define BOARD_MIPI_PANEL_BL_PIN  29
174 
175 /* Touch panel. */
176 #define BOARD_MIPI_PANEL_TOUCH_I2C_BASEADDR      LPI2C5
177 #define BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_ROOT    kCLOCK_Root_Lpi2c5
178 #define BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_SOURCE  (1U)  /* OSC24M. */
179 #define BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_DIVIDER (12U) /* Divider = 12, LPI2C clock frequency 2M. */
180 #define BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_FREQ    CLOCK_GetRootClockFreq(BOARD_MIPI_PANEL_TOUCH_I2C_CLOCK_ROOT)
181 #define BOARD_MIPI_PANEL_TOUCH_RST_GPIO          GPIO9
182 #define BOARD_MIPI_PANEL_TOUCH_RST_PIN           0
183 #define BOARD_MIPI_PANEL_TOUCH_INT_GPIO          GPIO8
184 #define BOARD_MIPI_PANEL_TOUCH_INT_PIN           31
185 
186 /*! @brief The camera pins. */
187 #define BOARD_CAMERA_PWDN_GPIO GPIO9
188 #define BOARD_CAMERA_PWDN_PIN  25
189 #define BOARD_CAMERA_RST_GPIO  GPIO11
190 #define BOARD_CAMERA_RST_PIN   15
191 
192 /* SD card detection method when using wifi module. */
193 #define BOARD_WIFI_SD_DETECT_TYPE kSDMMCHOST_DetectCardByHostDATA3
194 
195 #define BOARD_BT_UART_INSTANCE    7
196 #define BOARD_BT_UART_BASEADDR    (uint32_t) LPUART7
197 #define BOARD_BT_UART_BAUDRATE    3000000
198 #define BOARD_BT_UART_CLK_FREQ    CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart7);
199 #define BOARD_BT_UART_IRQ         LPUART7_IRQn
200 #define BOARD_BT_UART_IRQ_HANDLER LPUART7_IRQHandler
201 
202 /*! @brief The Ethernet port used by network examples, default use 1G port. */
203 /* Below comment is for test script to easily define which port to be used, please don't delete. */
204 /* @TEST_ANCHOR */
205 #ifndef BOARD_NETWORK_USE_100M_ENET_PORT
206 #define BOARD_NETWORK_USE_100M_ENET_PORT (0U)
207 #endif
208 
209 /* Timer Manager definition. */
210 #define BOARD_TM_INSTANCE   1
211 #define BOARD_TM_CLOCK_ROOT kCLOCK_Root_Gpt1
212 
213 #if defined(__cplusplus)
214 extern "C" {
215 #endif /* __cplusplus */
216 
217 /*******************************************************************************
218  * API
219  ******************************************************************************/
220 uint32_t BOARD_DebugConsoleSrcFreq(void);
221 
222 void BOARD_InitDebugConsole(void);
223 
224 void BOARD_ConfigMPU(void);
225 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
226 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz);
227 status_t BOARD_LPI2C_Send(LPI2C_Type *base,
228                           uint8_t deviceAddress,
229                           uint32_t subAddress,
230                           uint8_t subaddressSize,
231                           uint8_t *txBuff,
232                           uint8_t txBuffSize);
233 status_t BOARD_LPI2C_Receive(LPI2C_Type *base,
234                              uint8_t deviceAddress,
235                              uint32_t subAddress,
236                              uint8_t subaddressSize,
237                              uint8_t *rxBuff,
238                              uint8_t rxBuffSize);
239 status_t BOARD_LPI2C_SendSCCB(LPI2C_Type *base,
240                               uint8_t deviceAddress,
241                               uint32_t subAddress,
242                               uint8_t subaddressSize,
243                               uint8_t *txBuff,
244                               uint8_t txBuffSize);
245 status_t BOARD_LPI2C_ReceiveSCCB(LPI2C_Type *base,
246                                  uint8_t deviceAddress,
247                                  uint32_t subAddress,
248                                  uint8_t subaddressSize,
249                                  uint8_t *rxBuff,
250                                  uint8_t rxBuffSize);
251 void BOARD_Accel_I2C_Init(void);
252 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
253 status_t BOARD_Accel_I2C_Receive(
254     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
255 void BOARD_Codec_I2C_Init(void);
256 status_t BOARD_Codec_I2C_Send(
257     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
258 status_t BOARD_Codec_I2C_Receive(
259     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
260 void BOARD_Camera_I2C_Init(void);
261 status_t BOARD_Camera_I2C_Send(
262     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
263 status_t BOARD_Camera_I2C_Receive(
264     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
265 
266 status_t BOARD_Camera_I2C_SendSCCB(
267     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
268 status_t BOARD_Camera_I2C_ReceiveSCCB(
269     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
270 
271 void BOARD_MIPIPanelTouch_I2C_Init(void);
272 status_t BOARD_MIPIPanelTouch_I2C_Send(
273     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
274 status_t BOARD_MIPIPanelTouch_I2C_Receive(
275     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
276 #endif /* SDK_I2C_BASED_COMPONENT_USED */
277 
278 void BOARD_SD_Pin_Config(uint32_t speed, uint32_t strength);
279 void BOARD_MMC_Pin_Config(uint32_t speed, uint32_t strength);
280 
281 #if defined(__cplusplus)
282 }
283 #endif /* __cplusplus */
284 
285 #endif /* _BOARD_H_ */
286