1 /* 2 * Copyright 2017-2018 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_reset.h" 14 #include "fsl_gpio.h" 15 #include "fsl_iocon.h" 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 /*! @brief The board name */ 21 #define BOARD_NAME "LPCXpresso55S16" 22 23 /*! @brief The UART to use for debug messages. */ 24 /* TODO: rename UART to USART */ 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 12000000U 29 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0 30 #define BOARD_DEBUG_UART_RST kFC0_RST_SHIFT_RSTn 31 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_Flexcomm0 32 #define BOARD_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler 33 #define BOARD_UART_IRQ FLEXCOMM0_IRQn 34 35 #define BOARD_ACCEL_I2C_BASEADDR I2C4 36 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000 37 38 #ifndef BOARD_DEBUG_UART_BAUDRATE 39 #define BOARD_DEBUG_UART_BAUDRATE 115200U 40 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 41 42 #define BOARD_CODEC_I2C_BASEADDR I2C4 43 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000 44 #define BOARD_CODEC_I2C_INSTANCE 4 45 #ifndef BOARD_LED_RED_GPIO 46 #define BOARD_LED_RED_GPIO GPIO 47 #endif 48 #define BOARD_LED_RED_GPIO_PORT 1U 49 #ifndef BOARD_LED_RED_GPIO_PIN 50 #define BOARD_LED_RED_GPIO_PIN 4U 51 #endif 52 53 #ifndef BOARD_LED_BLUE_GPIO 54 #define BOARD_LED_BLUE_GPIO GPIO 55 #endif 56 #define BOARD_LED_BLUE_GPIO_PORT 1U 57 #ifndef BOARD_LED_BLUE_GPIO_PIN 58 #define BOARD_LED_BLUE_GPIO_PIN 6U 59 #endif 60 61 #ifndef BOARD_LED_GREEN_GPIO 62 #define BOARD_LED_GREEN_GPIO GPIO 63 #endif 64 #define BOARD_LED_GREEN_GPIO_PORT 1U 65 #ifndef BOARD_LED_GREEN_GPIO_PIN 66 #define BOARD_LED_GREEN_GPIO_PIN 7U 67 #endif 68 69 #ifndef BOARD_SW1_GPIO 70 #define BOARD_SW1_GPIO GPIO 71 #endif 72 #define BOARD_SW1_GPIO_PORT 1U 73 #ifndef BOARD_SW1_GPIO_PIN 74 #define BOARD_SW1_GPIO_PIN 18U 75 #endif 76 #define BOARD_SW1_NAME "SW1" 77 #define BOARD_SW1_IRQ PIN_INT1_IRQn 78 #define BOARD_SW1_IRQ_HANDLER PIN_INT1_IRQHandler 79 80 #ifndef BOARD_SW3_GPIO 81 #define BOARD_SW3_GPIO GPIO 82 #endif 83 #define BOARD_SW3_GPIO_PORT 1U 84 #ifndef BOARD_SW3_GPIO_PIN 85 #define BOARD_SW3_GPIO_PIN 9U 86 #endif 87 #define BOARD_SW3_NAME "SW3" 88 #define BOARD_SW3_IRQ PIN_INT1_IRQn 89 #define BOARD_SW3_IRQ_HANDLER PIN_INT1_IRQHandler 90 #define BOARD_SW3_GPIO_PININT_INDEX 1 91 92 #ifndef BOARD_SW4_GPIO 93 #define BOARD_SW4_GPIO GPIO 94 #endif 95 #define BOARD_SW4_GPIO_PORT 0U 96 #ifndef BOARD_SW4_GPIO_PIN 97 #define BOARD_SW4_GPIO_PIN 5U 98 #endif 99 #define BOARD_SW4_NAME "SW4" 100 #define BOARD_SW4_IRQ PIN_INT0_IRQn 101 #define BOARD_SW4_IRQ_HANDLER PIN_INT0_IRQHandler 102 #define BOARD_SW4_GPIO_PININT_INDEX 1 103 104 /* USB PHY condfiguration */ 105 #define BOARD_USB_PHY_D_CAL (0x05U) 106 #define BOARD_USB_PHY_TXCAL45DP (0x0AU) 107 #define BOARD_USB_PHY_TXCAL45DM (0x0AU) 108 109 #define BOARD_SDIF_BASEADDR SDIF 110 #define BOARD_SDIF_CLKSRC kCLOCK_SDio 111 #define BOARD_SDIF_CLK_FREQ CLOCK_GetSdioClkFreq() 112 #define BOARD_SDIF_CLK_ATTACH kMAIN_CLK_to_SDIO_CLK 113 #define BOARD_SDIF_IRQ SDIO_IRQn 114 #define BOARD_MMC_VCC_SUPPLY kMMC_VoltageWindows270to360 115 #define BOARD_SD_CARD_DETECT_PIN 17 116 #define BOARD_SD_CARD_DETECT_PORT 0 117 #define BOARD_SD_CARD_DETECT_GPIO GPIO 118 #define BOARD_SD_DETECT_TYPE kSDMMCHOST_DetectCardByHostCD 119 120 #define BOARD_SDIF_CD_GPIO_INIT() \ 121 { \ 122 CLOCK_EnableClock(kCLOCK_Gpio2); \ 123 GPIO_PinInit(BOARD_SD_CARD_DETECT_GPIO, BOARD_SD_CARD_DETECT_PORT, BOARD_SD_CARD_DETECT_PIN, \ 124 &(gpio_pin_config_t){kGPIO_DigitalInput, 0U}); \ 125 } 126 #define BOARD_SDIF_CD_STATUS() \ 127 GPIO_PinRead(BOARD_SD_CARD_DETECT_GPIO, BOARD_SD_CARD_DETECT_PORT, BOARD_SD_CARD_DETECT_PIN) 128 129 /* Board led color mapping */ 130 #define LOGIC_LED_ON 1U 131 #define LOGIC_LED_OFF 0U 132 133 #define BOARD_SDIF_CLK_ATTACH kMAIN_CLK_to_SDIO_CLK 134 135 #define LED_RED_INIT(output) \ 136 { \ 137 IOCON_PinMuxSet(IOCON, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, IOCON_DIGITAL_EN); \ 138 GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \ 139 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \ 140 } 141 #define LED_RED_OFF() \ 142 GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 143 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED1 */ 144 #define LED_RED_ON() \ 145 GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 146 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED1 \ \ \ \ \ \ \ \ \ \ \ 147 */ 148 #define LED_RED_TOGGLE() \ 149 GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ 150 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED1 */ 151 152 #define LED_BLUE_INIT(output) \ 153 { \ 154 IOCON_PinMuxSet(IOCON, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, IOCON_DIGITAL_EN); \ 155 GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \ 156 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \ 157 } 158 #define LED_BLUE_OFF() \ 159 GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 160 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED1 */ 161 #define LED_BLUE_ON() \ 162 GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 163 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED1 */ 164 #define LED_BLUE_TOGGLE() \ 165 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ 166 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED1 */ 167 168 #define LED_GREEN_INIT(output) \ 169 GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \ 170 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */ 171 #define LED_GREEN_OFF() \ 172 GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 173 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED1 */ 174 #define LED_GREEN_ON() \ 175 GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 176 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED1 */ 177 #define LED_GREEN_TOGGLE() \ 178 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ 179 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED1 */ 180 181 /* Display. */ 182 #define BOARD_LCD_DC_GPIO GPIO 183 #define BOARD_LCD_DC_GPIO_PORT 1U 184 #define BOARD_LCD_DC_GPIO_PIN 5U 185 186 /* Serial MWM WIFI */ 187 #define BOARD_SERIAL_MWM_PORT_CLK_FREQ CLOCK_GetFlexCommClkFreq(2) 188 #define BOARD_SERIAL_MWM_PORT USART2 189 #define BOARD_SERIAL_MWM_PORT_IRQn FLEXCOMM2_IRQn 190 #define BOARD_SERIAL_MWM_RST_WRITE(output) 191 192 #if defined(__cplusplus) 193 extern "C" { 194 #endif /* __cplusplus */ 195 196 /******************************************************************************* 197 * API 198 ******************************************************************************/ 199 200 void BOARD_InitDebugConsole(void); 201 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 202 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz); 203 status_t BOARD_I2C_Send(I2C_Type *base, 204 uint8_t deviceAddress, 205 uint32_t subAddress, 206 uint8_t subaddressSize, 207 uint8_t *txBuff, 208 uint8_t txBuffSize); 209 status_t BOARD_I2C_Receive(I2C_Type *base, 210 uint8_t deviceAddress, 211 uint32_t subAddress, 212 uint8_t subaddressSize, 213 uint8_t *rxBuff, 214 uint8_t rxBuffSize); 215 void BOARD_Accel_I2C_Init(void); 216 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 217 status_t BOARD_Accel_I2C_Receive( 218 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 219 void BOARD_Codec_I2C_Init(void); 220 status_t BOARD_Codec_I2C_Send( 221 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 222 status_t BOARD_Codec_I2C_Receive( 223 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 224 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 225 226 #if defined(__cplusplus) 227 } 228 #endif /* __cplusplus */ 229 230 #endif /* _BOARD_H_ */ 231