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