1 /* 2 * Copyright 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 "MIMXRT685-AUD-EVK" 22 23 /*! @brief The UART to use for debug messages. */ 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 CLOCK_GetFlexCommClkFreq(0U) 28 #define BOARD_DEBUG_UART_FRG_CLK \ 29 (&(const clock_frg_clk_config_t){0, kCLOCK_FrgPllDiv, 255, 0}) /*!< Select FRG0 mux as frg_pll */ 30 #define BOARD_DEBUG_UART_CLK_ATTACH kFRG_to_FLEXCOMM0 31 #define BOARD_DEBUG_UART_RST kFC0_RST_SHIFT_RSTn 32 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_Flexcomm0 33 #define BOARD_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler 34 #define BOARD_UART_IRQ FLEXCOMM0_IRQn 35 36 #ifndef BOARD_DEBUG_UART_BAUDRATE 37 #define BOARD_DEBUG_UART_BAUDRATE 115200 38 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 39 40 #define BOARD_FLEXSPI_PSRAM FLEXSPI 41 #ifndef BOARD_ENABLE_PSRAM_CACHE 42 #define BOARD_ENABLE_PSRAM_CACHE 1 43 #endif 44 45 #define BOARD_CODEC_I2C_BASEADDR I2C2 46 #define BOARD_CODEC_I2C_CLOCK_FREQ CLOCK_GetFlexCommClkFreq(2U) 47 #define BOARD_CODEC_I2C_INSTANCE 2 48 49 #define BOARD_PMIC_I2C_BASEADDR I2C15 50 #define BOARD_PMIC_I2C_CLOCK_FREQ CLOCK_GetFlexCommClkFreq(15U) 51 52 #define BOARD_ACCEL_I2C_BASEADDR I2C2 53 #define BOARD_ACCEL_I2C_ADDR 0x1E 54 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFlexCommClkFreq(2U) 55 56 /* Board led color mapping */ 57 #define LOGIC_LED_ON 1U 58 #define LOGIC_LED_OFF 0U 59 60 #ifndef BOARD_LED_RED_GPIO 61 #define BOARD_LED_RED_GPIO GPIO 62 #endif 63 #define BOARD_LED_RED_GPIO_PORT 0U 64 #ifndef BOARD_LED_RED_GPIO_PIN 65 #define BOARD_LED_RED_GPIO_PIN 31U 66 #endif 67 68 #ifndef BOARD_LED_GREEN_GPIO 69 #define BOARD_LED_GREEN_GPIO GPIO 70 #endif 71 #define BOARD_LED_GREEN_GPIO_PORT 0U 72 #ifndef BOARD_LED_GREEN_GPIO_PIN 73 #define BOARD_LED_GREEN_GPIO_PIN 14U 74 #endif 75 #ifndef BOARD_LED_BLUE_GPIO 76 #define BOARD_LED_BLUE_GPIO GPIO 77 #endif 78 #define BOARD_LED_BLUE_GPIO_PORT 0U 79 #ifndef BOARD_LED_BLUE_GPIO_PIN 80 #define BOARD_LED_BLUE_GPIO_PIN 26U 81 #endif 82 83 #ifndef BOARD_FLASH_RESET_GPIO 84 #define BOARD_FLASH_RESET_GPIO GPIO 85 #endif 86 #ifndef BOARD_FLASH_RESET_GPIO_PORT 87 #define BOARD_FLASH_RESET_GPIO_PORT 2U 88 #endif 89 #ifndef BOARD_FLASH_RESET_GPIO_PIN 90 #define BOARD_FLASH_RESET_GPIO_PIN 12U 91 #endif 92 93 /* Board microphone defines */ 94 #ifndef BOARD_DMIC_NUM 95 #define BOARD_DMIC_NUM 1 96 #endif 97 98 #define LED_RED_INIT(output) \ 99 GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \ 100 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */ 101 #define LED_RED_ON() \ 102 GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 103 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */ 104 #define LED_RED_OFF() \ 105 GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 106 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */ 107 #define LED_RED_TOGGLE() \ 108 GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 109 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ 110 111 #define LED_GREEN_INIT(output) \ 112 GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \ 113 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */ 114 #define LED_GREEN_ON() \ 115 GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 116 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */ 117 #define LED_GREEN_OFF() \ 118 GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 119 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */ 120 #define LED_GREEN_TOGGLE() \ 121 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 122 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ 123 124 #define LED_BLUE_INIT(output) \ 125 GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \ 126 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */ 127 #define LED_BLUE_ON() \ 128 GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 129 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */ 130 #define LED_BLUE_OFF() \ 131 GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 132 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */ 133 #define LED_BLUE_TOGGLE() \ 134 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 135 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 136 137 /* Board SW PIN */ 138 #ifndef BOARD_SW1_GPIO 139 #define BOARD_SW1_GPIO GPIO 140 #endif 141 #define BOARD_SW1_GPIO_PORT 1U 142 #ifndef BOARD_SW1_GPIO_PIN 143 #define BOARD_SW1_GPIO_PIN 1U 144 #endif 145 146 #ifndef BOARD_SW2_GPIO 147 #define BOARD_SW2_GPIO GPIO 148 #endif 149 #define BOARD_SW2_GPIO_PORT 0U 150 #ifndef BOARD_SW2_GPIO_PIN 151 #define BOARD_SW2_GPIO_PIN 10U 152 #endif 153 154 /* USDHC configuration */ 155 #define BOARD_SD_SUPPORT_180V (1) 156 #define BOARD_USDHC_CD_GPIO_BASE GPIO 157 #define BOARD_USDHC_CD_GPIO_PORT (2) 158 #define BOARD_USDHC_CD_GPIO_PIN (9) 159 #define BOARD_SD_POWER_RESET_GPIO (GPIO) 160 #define BOARD_SD_POWER_RESET_GPIO_PORT (2) 161 #define BOARD_SD_POWER_RESET_GPIO_PIN (10) 162 163 /* Card detect handled by uSDHC, no GPIO interrupt */ 164 #define BOARD_SD_DETECT_TYPE kSDMMCHOST_DetectCardByHostCD 165 #define BOARD_USDHC_CD_PORT_IRQ USDHC0_IRQn 166 #define BOARD_USDHC_CD_STATUS() 0 167 #define BOARD_USDHC_CD_INTERRUPT_STATUS() 0 168 #define BOARD_USDHC_CD_CLEAR_INTERRUPT(flag) 169 #define BOARD_USDHC_CD_GPIO_INIT() 170 171 #define BOARD_HAS_SDCARD (1U) 172 #define BOARD_USDHC_CARD_INSERT_CD_LEVEL (0U) 173 174 #define BOARD_USDHC_MMCCARD_POWER_CONTROL_INIT() 175 #define BOARD_USDHC_MMCCARD_POWER_CONTROL(state) 176 #define BOARD_USDHC_SDCARD_POWER_CONTROL_INIT() \ 177 { \ 178 GPIO_PortInit(BOARD_SD_POWER_RESET_GPIO, BOARD_SD_POWER_RESET_GPIO_PORT); \ 179 GPIO_PinInit(BOARD_SD_POWER_RESET_GPIO, BOARD_SD_POWER_RESET_GPIO_PORT, BOARD_SD_POWER_RESET_GPIO_PIN, \ 180 &(gpio_pin_config_t){kGPIO_DigitalOutput, 0}); \ 181 } 182 183 #define BOARD_MMC_SUPPORT_8BIT_BUS 0 184 185 #define BOARD_USDHC_SDCARD_POWER_CONTROL(state) \ 186 (state ? \ 187 GPIO_PortSet(BOARD_SD_POWER_RESET_GPIO, BOARD_SD_POWER_RESET_GPIO_PORT, 1 << BOARD_SD_POWER_RESET_GPIO_PIN) : \ 188 GPIO_PortClear(BOARD_SD_POWER_RESET_GPIO, BOARD_SD_POWER_RESET_GPIO_PORT, \ 189 1 << BOARD_SD_POWER_RESET_GPIO_PIN)) 190 191 #define BOARD_USDHC0_BASEADDR USDHC0 192 193 #define BOARD_USDHC0_CLK_FREQ CLOCK_GetSdioClkFreq(0) 194 195 #define BOARD_USDHC_SWITCH_VOLTAGE_FUNCTION 1U 196 197 #define BOARD_SD_HOST_BASEADDR BOARD_USDHC0_BASEADDR 198 #define BOARD_SD_HOST_CLK_FREQ BOARD_USDHC0_CLK_FREQ 199 #define BOARD_SD_HOST_IRQ USDHC0_IRQn 200 201 #define BOARD_SD_Pin_Config(speed, strength) 202 203 /* USB PHY condfiguration */ 204 #define BOARD_USB_PHY_D_CAL (0x0CU) 205 #define BOARD_USB_PHY_TXCAL45DP (0x06U) 206 #define BOARD_USB_PHY_TXCAL45DM (0x06U) 207 208 #define BOARD_FLASH_SIZE (0x4000000U) 209 210 /* Display. */ 211 #define BOARD_LCD_DC_GPIO GPIO 212 #define BOARD_LCD_DC_GPIO_PORT 1U 213 #define BOARD_LCD_DC_GPIO_PIN 7U 214 215 #if defined(__cplusplus) 216 extern "C" { 217 #endif /* __cplusplus */ 218 219 /******************************************************************************* 220 * API 221 ******************************************************************************/ 222 223 void BOARD_InitDebugConsole(void); 224 status_t BOARD_InitPsRam(void); 225 void BOARD_FlexspiClockSafeConfig(void); 226 AT_QUICKACCESS_SECTION_CODE(void BOARD_SetFlexspiClock(uint32_t src, uint32_t divider)); 227 AT_QUICKACCESS_SECTION_CODE(void BOARD_DeinitXip(FLEXSPI_Type *base)); 228 AT_QUICKACCESS_SECTION_CODE(void BOARD_InitXip(FLEXSPI_Type *base)); 229 AT_QUICKACCESS_SECTION_CODE(void BOARD_SetDeepSleepPinConfig(void)); 230 AT_QUICKACCESS_SECTION_CODE(void BOARD_RestoreDeepSleepPinConfig(void)); 231 AT_QUICKACCESS_SECTION_CODE(void BOARD_EnterDeepSleep(const uint32_t exclude_from_pd[4])); 232 AT_QUICKACCESS_SECTION_CODE(void BOARD_EnterDeepPowerDown(const uint32_t exclude_from_pd[4])); 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 #endif 248 #if defined BOARD_USE_CODEC 249 void BOARD_Codec_I2C_Init(void); 250 status_t BOARD_Codec_I2C_Send( 251 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 252 status_t BOARD_Codec_I2C_Receive( 253 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 254 #endif 255 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 256 void BOARD_PMIC_I2C_Init(void); 257 status_t BOARD_PMIC_I2C_Send( 258 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 259 status_t BOARD_PMIC_I2C_Receive( 260 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 261 262 void BOARD_Accel_I2C_Init(void); 263 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 264 status_t BOARD_Accel_I2C_Receive( 265 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 266 267 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 268 #if defined(__cplusplus) 269 } 270 #endif /* __cplusplus */ 271 272 #endif /* _BOARD_H_ */ 273