1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2018 NXP 4 * All rights reserved. 5 * 6 * 7 * SPDX-License-Identifier: BSD-3-Clause 8 */ 9 10 #ifndef _BOARD_H_ 11 #define _BOARD_H_ 12 13 #include "clock_config.h" 14 #include "fsl_common.h" 15 #include "fsl_gpio.h" 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 /*! @brief The board name */ 21 #define BOARD_NAME "LPCXPRESSO54S018" 22 23 #define BOARD_EXTCLKINRATE (0) 24 25 /*! @brief The UART to use for debug messages. */ 26 /* TODO: rename UART to USART */ 27 #define BOARD_DEBUG_UART_TYPE kSerialPort_Uart 28 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) USART0 29 #define BOARD_DEBUG_UART_INSTANCE 0U 30 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U) 31 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0 32 #define BOARD_DEBUG_UART_RST kFC0_RST_SHIFT_RSTn 33 #define BOARD_UART_IRQ_HANDLER FLEXCOMM0_IRQHandler 34 #define BOARD_UART_IRQ FLEXCOMM0_IRQn 35 /* TODO: obsolete */ 36 #define BOARD_DEBUG_SPI_CLK_FREQ 12000000 37 38 #define BOARD_ACCEL_I2C_BASEADDR I2C2 39 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000 40 41 #define BOARD_CODEC_I2C_BASEADDR I2C2 42 #define BOARD_CODEC_I2C_INSTANCE 2U 43 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000 44 45 #ifndef BOARD_DEBUG_UART_BAUDRATE 46 #define BOARD_DEBUG_UART_BAUDRATE 115200 47 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 48 49 /*! @brief The ENET PHY address. */ 50 #define BOARD_ENET0_PHY_ADDRESS (0x00U) /* Phy address of enet port 0. */ 51 52 /*! @brief Memory ranges not usable by the ENET DMA. */ 53 #ifndef BOARD_ENET_NON_DMA_MEMORY_ARRAY 54 #define BOARD_ENET_NON_DMA_MEMORY_ARRAY \ 55 { \ 56 {0x10000000U, 0x17FFFFFFU}, {0x80000000U, 0xDFFFFFFFU}, {0x00000000U, 0x00000000U}, \ 57 } 58 #endif /* BOARD_ENET_NON_DMA_MEMORY_ARRAY */ 59 60 #ifndef BOARD_LED1_GPIO 61 #define BOARD_LED1_GPIO GPIO 62 #endif 63 #define BOARD_LED1_GPIO_PORT 3U 64 #ifndef BOARD_LED1_GPIO_PIN 65 #define BOARD_LED1_GPIO_PIN 14U 66 #endif 67 #ifndef BOARD_LED2_GPIO 68 #define BOARD_LED2_GPIO GPIO 69 #endif 70 #define BOARD_LED2_GPIO_PORT 3U 71 #ifndef BOARD_LED2_GPIO_PIN 72 #define BOARD_LED2_GPIO_PIN 3U 73 #endif 74 #ifndef BOARD_LED3_GPIO 75 #define BOARD_LED3_GPIO GPIO 76 #endif 77 #define BOARD_LED3_GPIO_PORT 2U 78 #ifndef BOARD_LED3_GPIO_PIN 79 #define BOARD_LED3_GPIO_PIN 2U 80 #endif 81 82 #ifndef BOARD_SW1_GPIO 83 #define BOARD_SW1_GPIO GPIO 84 #endif 85 #define BOARD_SW1_GPIO_PORT 0U 86 #ifndef BOARD_SW1_GPIO_PIN 87 #define BOARD_SW1_GPIO_PIN 4U 88 #endif 89 #define BOARD_SW1_NAME "SW1" 90 #define BOARD_SW3_IRQ PIN_INT0_IRQn 91 #define BOARD_SW3_IRQ_HANDLER PIN_INT0_IRQHandler 92 93 #ifndef BOARD_SW2_GPIO 94 #define BOARD_SW2_GPIO GPIO 95 #endif 96 #define BOARD_SW2_GPIO_PORT 0U 97 #ifndef BOARD_SW2_GPIO_PIN 98 #define BOARD_SW2_GPIO_PIN 6U 99 #endif 100 #define BOARD_SW2_NAME "SW2" 101 #define BOARD_SW2_IRQ PIN_INT0_IRQn 102 #define BOARD_SW2_IRQ_HANDLER PIN_INT0_IRQHandler 103 104 #ifndef BOARD_SW3_GPIO 105 #define BOARD_SW3_GPIO GPIO 106 #endif 107 #define BOARD_SW3_GPIO_PORT 0U 108 #ifndef BOARD_SW3_GPIO_PIN 109 #define BOARD_SW3_GPIO_PIN 5U 110 #endif 111 #define BOARD_SW3_NAME "SW3" 112 #define BOARD_SW3_IRQ PIN_INT0_IRQn 113 #define BOARD_SW3_IRQ_HANDLER PIN_INT0_IRQHandler 114 #define BOARD_SW3_GPIO_PININT_INDEX 0 115 116 #ifndef BOARD_SW4_GPIO 117 #define BOARD_SW4_GPIO GPIO 118 #endif 119 #ifndef BOARD_SW4_GPIO_PORT 120 #define BOARD_SW4_GPIO_PORT 0U 121 #endif 122 #ifndef BOARD_SW4_GPIO_PIN 123 #define BOARD_SW4_GPIO_PIN 4U 124 #endif 125 #define BOARD_SW4_NAME "SW4" 126 #define BOARD_SW4_IRQ PIN_INT0_IRQn 127 #define BOARD_SW4_IRQ_HANDLER PIN_INT0_IRQHandler 128 #define BOARD_SW4_GPIO_PININT_INDEX 0 129 130 #ifndef BOARD_SW5_GPIO 131 #define BOARD_SW5_GPIO GPIO 132 #endif 133 #ifndef BOARD_SW5_GPIO_PORT 134 #define BOARD_SW5_GPIO_PORT 1U 135 #endif 136 #ifndef BOARD_SW5_GPIO_PIN 137 #define BOARD_SW5_GPIO_PIN 1U 138 #endif 139 #define BOARD_SW5_NAME "SW5" 140 #define BOARD_SW5_IRQ PIN_INT1_IRQn 141 #define BOARD_SW5_IRQ_HANDLER PIN_INT1_IRQHandler 142 #define BOARD_SW5_GPIO_PININT_INDEX 0 143 144 #define BOARD_ARDUINO_INT_IRQ (GINT0_IRQn) 145 #define BOARD_ARDUINO_I2C_IRQ (FLEXCOMM2_IRQn) 146 #define BOARD_ARDUINO_I2C_INDEX (2) 147 148 /* Board led color mapping */ 149 #define LOGIC_LED_ON 0U 150 #define LOGIC_LED_OFF 1U 151 152 #define LED1_INIT(output) \ 153 GPIO_PinInit(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, BOARD_LED1_GPIO_PIN, \ 154 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */ 155 #define LED1_ON() \ 156 GPIO_PortClear(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Turn on target LED1 */ 157 #define LED1_OFF() \ 158 GPIO_PortSet(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Turn off target LED1 */ 159 #define LED1_TOGGLE() \ 160 GPIO_PortToggle(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PORT, 1U << BOARD_LED1_GPIO_PIN) /*!< Toggle on target LED1 */ 161 #define LED2_INIT(output) \ 162 GPIO_PinInit(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, BOARD_LED2_GPIO_PIN, \ 163 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED2 */ 164 #define LED2_ON() \ 165 GPIO_PortClear(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Turn on target LED2 */ 166 #define LED2_OFF() \ 167 GPIO_PortSet(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Turn off target LED2 */ 168 #define LED2_TOGGLE() \ 169 GPIO_PortToggle(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PORT, 1U << BOARD_LED2_GPIO_PIN) /*!< Toggle on target LED2 */ 170 171 #define LED3_INIT(output) \ 172 GPIO_PinInit(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, BOARD_LED3_GPIO_PIN, \ 173 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED3 */ 174 #define LED3_ON() \ 175 GPIO_PortClear(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Turn on target LED3 */ 176 #define LED3_OFF() \ 177 GPIO_PortSet(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Turn off target LED3 */ 178 #define LED3_TOGGLE() \ 179 GPIO_PortToggle(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PORT, 1U << BOARD_LED3_GPIO_PIN) /*!< Toggle on target LED3 */ 180 181 /* LCD panel. */ 182 #define BOARD_LCD_BL_GPIO 3 183 #define BOARD_LCD_BL_PIN 31 184 #define BOARD_TOUCH_PANEL_RST_GPIO 2 185 #define BOARD_TOUCH_PANEL_RST_PIN 27 186 187 /* @Brief Board touch panel configuration */ 188 #define BOARD_TOUCH_I2C_BASEADDR I2C2 189 #define BOARD_TOUCH_RST_GPIO GPIO 190 #define BOARD_TOUCH_RST_PORT 2 191 #define BOARD_TOUCH_RST_PIN 27 192 #define BOARD_TOUCH_INT_GPIO GPIO 193 #define BOARD_TOUCH_INT_PORT 4 194 #define BOARD_TOUCH_INT_PIN 0 195 196 /* Serial MWM WIFI */ 197 #define BOARD_SERIAL_MWM_PORT_CLK_FREQ CLOCK_GetFlexCommClkFreq(4) 198 #define BOARD_SERIAL_MWM_PORT USART4 199 #define BOARD_SERIAL_MWM_PORT_IRQn FLEXCOMM4_IRQn 200 #define BOARD_SERIAL_MWM_RST_GPIO GPIO 201 #define BOARD_SERIAL_MWM_RST_PORT 1 202 #define BOARD_SERIAL_MWM_RST_PIN 22 203 #define BOARD_SERIAL_MWM_RST_WRITE(output) \ 204 GPIO_PinWrite(BOARD_SERIAL_MWM_RST_GPIO, BOARD_SERIAL_MWM_RST_PORT, BOARD_SERIAL_MWM_RST_PIN, output) 205 206 #if defined(__cplusplus) 207 extern "C" { 208 #endif /* __cplusplus */ 209 210 /******************************************************************************* 211 * API 212 ******************************************************************************/ 213 214 status_t BOARD_InitDebugConsole(void); 215 void BOARD_InitSDRAM(void); 216 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 217 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz); 218 status_t BOARD_I2C_Send(I2C_Type *base, 219 uint8_t deviceAddress, 220 uint32_t subAddress, 221 uint8_t subaddressSize, 222 uint8_t *txBuff, 223 uint8_t txBuffSize); 224 status_t BOARD_I2C_Receive(I2C_Type *base, 225 uint8_t deviceAddress, 226 uint32_t subAddress, 227 uint8_t subaddressSize, 228 uint8_t *rxBuff, 229 uint8_t rxBuffSize); 230 void BOARD_Accel_I2C_Init(void); 231 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 232 status_t BOARD_Accel_I2C_Receive( 233 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 234 void BOARD_Codec_I2C_Init(void); 235 status_t BOARD_Codec_I2C_Send( 236 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 237 status_t BOARD_Codec_I2C_Receive( 238 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 239 status_t BOARD_Touch_I2C_Send( 240 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 241 status_t BOARD_Touch_I2C_Receive( 242 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 243 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 244 245 #if defined(__cplusplus) 246 } 247 #endif /* __cplusplus */ 248 249 #endif /* _BOARD_H_ */ 250