1 /*
2  * Copyright 2018-2022 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 "MIMXRT1060-EVK"
21 
22 /* The UART to use for debug messages. */
23 #define BOARD_DEBUG_UART_CLK_FREQ BOARD_DebugConsoleSrcFreq()
24 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
25 #ifndef BOARD_DEBUG_UART_BASEADDR
26 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART1
27 #endif
28 #ifndef BOARD_DEBUG_UART_INSTANCE
29 #define BOARD_DEBUG_UART_INSTANCE 1U
30 #endif
31 #ifndef BOARD_UART_IRQ
32 #define BOARD_UART_IRQ LPUART1_IRQn
33 #endif
34 #ifndef BOARD_UART_IRQ_HANDLER
35 #define BOARD_UART_IRQ_HANDLER LPUART1_IRQHandler
36 #endif
37 #ifndef BOARD_DEBUG_UART_BAUDRATE
38 #define BOARD_DEBUG_UART_BAUDRATE (115200U)
39 #endif
40 
41 /*! @brief The USER_LED used for board */
42 #define LOGIC_LED_ON  (0U)
43 #define LOGIC_LED_OFF (1U)
44 #ifndef BOARD_USER_LED_GPIO
45 #define BOARD_USER_LED_GPIO GPIO1
46 #endif
47 #ifndef BOARD_USER_LED_GPIO_PIN
48 #define BOARD_USER_LED_GPIO_PIN (9U)
49 #endif
50 
51 #define USER_LED_INIT(output)                                            \
52     GPIO_PinWrite(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN, output); \
53     BOARD_USER_LED_GPIO->GDIR |= (1U << BOARD_USER_LED_GPIO_PIN) /*!< Enable target USER_LED */
54 #define USER_LED_ON() \
55     GPIO_PortClear(BOARD_USER_LED_GPIO, 1U << BOARD_USER_LED_GPIO_PIN)                  /*!< Turn off target USER_LED */
56 #define USER_LED_OFF() GPIO_PortSet(BOARD_USER_LED_GPIO, 1U << BOARD_USER_LED_GPIO_PIN) /*!<Turn on target USER_LED*/
57 #define USER_LED_TOGGLE()                                       \
58     GPIO_PinWrite(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN, \
59                   0x1 ^ GPIO_PinRead(BOARD_USER_LED_GPIO, BOARD_USER_LED_GPIO_PIN)) /*!< Toggle target USER_LED */
60 
61 /*! @brief Define the port interrupt number for the board switches */
62 #ifndef BOARD_USER_BUTTON_GPIO
63 #define BOARD_USER_BUTTON_GPIO GPIO5
64 #endif
65 #ifndef BOARD_USER_BUTTON_GPIO_PIN
66 #define BOARD_USER_BUTTON_GPIO_PIN (0U)
67 #endif
68 #define BOARD_USER_BUTTON_IRQ         GPIO5_Combined_0_15_IRQn
69 #define BOARD_USER_BUTTON_IRQ_HANDLER GPIO5_Combined_0_15_IRQHandler
70 #define BOARD_USER_BUTTON_NAME        "SW8"
71 
72 /*! @brief The board flash size */
73 #define BOARD_FLASH_SIZE (0x800000U)
74 
75 /*! @brief The ENET PHY address. */
76 #define BOARD_ENET0_PHY_ADDRESS (0x02U) /* Phy address of enet port 0. */
77 
78 /* USB PHY condfiguration */
79 #define BOARD_USB_PHY_D_CAL     (0x0CU)
80 #define BOARD_USB_PHY_TXCAL45DP (0x06U)
81 #define BOARD_USB_PHY_TXCAL45DM (0x06U)
82 
83 #define BOARD_ARDUINO_INT_IRQ   (GPIO1_INT3_IRQn)
84 #define BOARD_ARDUINO_I2C_IRQ   (LPI2C1_IRQn)
85 #define BOARD_ARDUINO_I2C_INDEX (1)
86 
87 /* @Brief Board accelerator sensor configuration */
88 #define BOARD_ACCEL_I2C_BASEADDR LPI2C1
89 /* Select USB1 PLL (480 MHz) as LPI2C's clock source */
90 #define BOARD_ACCEL_I2C_CLOCK_SOURCE_SELECT (0U)
91 /* Clock divider for LPI2C clock source */
92 #define BOARD_ACCEL_I2C_CLOCK_SOURCE_DIVIDER (5U)
93 #define BOARD_ACCEL_I2C_CLOCK_FREQ           (CLOCK_GetFreq(kCLOCK_Usb1PllClk) / 8 / (BOARD_ACCEL_I2C_CLOCK_SOURCE_DIVIDER + 1U))
94 
95 #define BOARD_CODEC_I2C_BASEADDR             LPI2C1
96 #define BOARD_CODEC_I2C_INSTANCE             1U
97 #define BOARD_CODEC_I2C_CLOCK_SOURCE_SELECT  (0U)
98 #define BOARD_CODEC_I2C_CLOCK_SOURCE_DIVIDER (5U)
99 #define BOARD_CODEC_I2C_CLOCK_FREQ           (10000000U)
100 
101 /* @Brief Board CAMERA configuration */
102 #define BOARD_CAMERA_I2C_BASEADDR             LPI2C1
103 #define BOARD_CAMERA_I2C_CLOCK_SOURCE_DIVIDER (5U)
104 #define BOARD_CAMERA_I2C_CLOCK_SOURCE_SELECT  (0U) /* Select USB1 PLL (480 MHz) as LPI2C's clock source */
105 #define BOARD_CAMERA_I2C_CLOCK_FREQ \
106     (CLOCK_GetFreq(kCLOCK_Usb1PllClk) / 8 / (BOARD_CAMERA_I2C_CLOCK_SOURCE_DIVIDER + 1U))
107 
108 #define BOARD_CAMERA_I2C_SCL_GPIO GPIO1
109 #define BOARD_CAMERA_I2C_SCL_PIN  16
110 #define BOARD_CAMERA_I2C_SDA_GPIO GPIO1
111 #define BOARD_CAMERA_I2C_SDA_PIN  17
112 #define BOARD_CAMERA_PWDN_GPIO    GPIO1
113 #define BOARD_CAMERA_PWDN_PIN     18
114 
115 /* @Brief Board touch panel configuration */
116 #define BOARD_TOUCH_I2C_BASEADDR LPI2C1
117 #define BOARD_TOUCH_RST_GPIO     GPIO1
118 #define BOARD_TOUCH_RST_PIN      2
119 #define BOARD_TOUCH_INT_GPIO     GPIO1
120 #define BOARD_TOUCH_INT_PIN      11
121 
122 /* @Brief Board Bluetooth HCI UART configuration */
123 #define BOARD_BT_UART_BASEADDR    LPUART3
124 #define BOARD_BT_UART_INSTANCE    3
125 #define BOARD_BT_UART_BAUDRATE    3000000
126 #define BOARD_BT_UART_CLK_FREQ    BOARD_DebugConsoleSrcFreq()
127 #define BOARD_BT_UART_IRQ         LPUART3_IRQn
128 #define BOARD_BT_UART_IRQ_HANDLER LPUART3_IRQHandler
129 
130 /*! @brief board has sdcard */
131 #define BOARD_HAS_SDCARD (1U)
132 
133 #if defined(__cplusplus)
134 extern "C" {
135 #endif /* __cplusplus */
136 
137 /*******************************************************************************
138  * API
139  ******************************************************************************/
140 uint32_t BOARD_DebugConsoleSrcFreq(void);
141 
142 void BOARD_InitDebugConsole(void);
143 
144 void BOARD_ConfigMPU(void);
145 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
146 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz);
147 status_t BOARD_LPI2C_Send(LPI2C_Type *base,
148                           uint8_t deviceAddress,
149                           uint32_t subAddress,
150                           uint8_t subaddressSize,
151                           uint8_t *txBuff,
152                           uint8_t txBuffSize);
153 status_t BOARD_LPI2C_Receive(LPI2C_Type *base,
154                              uint8_t deviceAddress,
155                              uint32_t subAddress,
156                              uint8_t subaddressSize,
157                              uint8_t *rxBuff,
158                              uint8_t rxBuffSize);
159 status_t BOARD_LPI2C_SendSCCB(LPI2C_Type *base,
160                               uint8_t deviceAddress,
161                               uint32_t subAddress,
162                               uint8_t subaddressSize,
163                               uint8_t *txBuff,
164                               uint8_t txBuffSize);
165 status_t BOARD_LPI2C_ReceiveSCCB(LPI2C_Type *base,
166                                  uint8_t deviceAddress,
167                                  uint32_t subAddress,
168                                  uint8_t subaddressSize,
169                                  uint8_t *rxBuff,
170                                  uint8_t rxBuffSize);
171 void BOARD_Accel_I2C_Init(void);
172 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
173 status_t BOARD_Accel_I2C_Receive(
174     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
175 void BOARD_Codec_I2C_Init(void);
176 status_t BOARD_Codec_I2C_Send(
177     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
178 status_t BOARD_Codec_I2C_Receive(
179     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
180 void BOARD_Camera_I2C_Init(void);
181 status_t BOARD_Camera_I2C_Send(
182     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
183 status_t BOARD_Camera_I2C_Receive(
184     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
185 
186 status_t BOARD_Camera_I2C_SendSCCB(
187     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
188 status_t BOARD_Camera_I2C_ReceiveSCCB(
189     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
190 status_t BOARD_Touch_I2C_Send(
191     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
192 status_t BOARD_Touch_I2C_Receive(
193     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
194 #endif /* SDK_I2C_BASED_COMPONENT_USED */
195 
196 void BOARD_SD_Pin_Config(uint32_t speed, uint32_t strength);
197 void BOARD_MMC_Pin_Config(uint32_t speed, uint32_t strength);
198 
199 #if defined(__cplusplus)
200 }
201 #endif /* __cplusplus */
202 
203 #endif /* _BOARD_H_ */
204