1 /* 2 * Copyright (c) 2015, 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_gpio.h" 15 16 /******************************************************************************* 17 * Definitions 18 ******************************************************************************/ 19 /*! @brief The board name */ 20 #define BOARD_NAME "TWR-KV58F220M" 21 22 /*! @brief The UART to use for debug messages. */ 23 #define BOARD_USE_UART 24 #define BOARD_DEBUG_UART_TYPE kSerialPort_Uart 25 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0 26 #define BOARD_DEBUG_UART_INSTANCE 0U 27 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_FastPeriphClk 28 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFastPeriphClkFreq() 29 #define BOARD_UART_IRQ UART0_RX_TX_IRQn 30 #define BOARD_UART_IRQ_HANDLER UART0_RX_TX_IRQHandler 31 32 #ifndef BOARD_DEBUG_UART_BAUDRATE 33 #define BOARD_DEBUG_UART_BAUDRATE 115200 34 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 35 36 /*! @brief The i2c instance used for i2c connection by default */ 37 #define BOARD_I2C_BASEADDR I2C0 38 39 /*! @brief The ENET PHY address. */ 40 #define BOARD_ENET0_PHY_ADDRESS (0x00U) /* Phy address of enet port 0. */ 41 42 /*! @brief The bubble level demo information */ 43 #define BOARD_FXOS8700_ADDR 0x1D 44 #define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR 45 #define BOARD_ACCEL_BAUDRATE 100 46 #define BOARD_ACCEL_I2C_BASEADDR I2C1 47 #define BOARD_ACCEL_I2C_CLK_SRC I2C1_CLK_SRC 48 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFreq(I2C1_CLK_SRC) 49 50 /*! @brief The dspi instance used for board. */ 51 #define BOARD_DSPI_BASEADDR SPI0 52 53 /*! @brief Define the port interrupt number for the board switches */ 54 #ifndef BOARD_SW2_GPIO 55 #define BOARD_SW2_GPIO GPIOA 56 #endif 57 #ifndef BOARD_SW2_PORT 58 #define BOARD_SW2_PORT PORTA 59 #endif 60 #ifndef BOARD_SW2_GPIO_PIN 61 #define BOARD_SW2_GPIO_PIN 4U 62 #endif 63 #define BOARD_SW2_IRQ PORTA_IRQn 64 #define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler 65 #define BOARD_SW2_NAME "SW2" 66 67 #ifndef BOARD_SW3_GPIO 68 #define BOARD_SW3_GPIO GPIOE 69 #endif 70 #ifndef BOARD_SW3_PORT 71 #define BOARD_SW3_PORT PORTE 72 #endif 73 #ifndef BOARD_SW3_GPIO_PIN 74 #define BOARD_SW3_GPIO_PIN 4U 75 #endif 76 #define BOARD_SW3_IRQ PORTE_IRQn 77 #define BOARD_SW3_IRQ_HANDLER PORTE_IRQHandler 78 #define BOARD_SW3_NAME "SW3" 79 80 /* Board led color mapping */ 81 #define LOGIC_LED_ON 0U 82 #define LOGIC_LED_OFF 1U 83 #ifndef BOARD_LED_RED_GPIO 84 #define BOARD_LED_RED_GPIO GPIOE 85 #endif 86 #define BOARD_LED_RED_GPIO_PORT PORTE 87 #ifndef BOARD_LED_RED_GPIO_PIN 88 #define BOARD_LED_RED_GPIO_PIN 11U 89 #endif 90 #ifndef BOARD_LED_GREEN_GPIO 91 #define BOARD_LED_GREEN_GPIO GPIOE 92 #endif 93 #define BOARD_LED_GREEN_GPIO_PORT PORTE 94 #ifndef BOARD_LED_GREEN_GPIO_PIN 95 #define BOARD_LED_GREEN_GPIO_PIN 12U 96 #endif 97 #ifndef BOARD_LED_BLUE_GPIO 98 #define BOARD_LED_BLUE_GPIO GPIOE 99 #endif 100 #define BOARD_LED_BLUE_GPIO_PORT PORTE 101 #ifndef BOARD_LED_BLUE_GPIO_PIN 102 #define BOARD_LED_BLUE_GPIO_PIN 29U 103 #endif 104 #ifndef BOARD_LED_ORANGE_GPIO 105 #define BOARD_LED_ORANGE_GPIO GPIOE 106 #endif 107 #define BOARD_LED_ORANGE_GPIO_PORT PORTE 108 #ifndef BOARD_LED_ORANGE_GPIO_PIN 109 #define BOARD_LED_ORANGE_GPIO_PIN 30U 110 #endif 111 112 #define LED_RED_INIT(output) \ 113 GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \ 114 BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */ 115 #define LED_RED_ON() GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */ 116 #define LED_RED_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */ 117 #define LED_RED_TOGGLE() \ 118 GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ 119 120 #define LED_GREEN_INIT(output) \ 121 GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \ 122 BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */ 123 #define LED_GREEN_ON() \ 124 GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */ 125 #define LED_GREEN_OFF() \ 126 GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */ 127 #define LED_GREEN_TOGGLE() \ 128 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ 129 130 #define LED_BLUE_INIT(output) \ 131 GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \ 132 BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */ 133 #define LED_BLUE_ON() \ 134 GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ 135 */ 136 #define LED_BLUE_OFF() \ 137 GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ 138 */ 139 #define LED_BLUE_TOGGLE() \ 140 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 141 142 #define LED_ORANGE_INIT(output) \ 143 GPIO_PinWrite(BOARD_LED_ORANGE_GPIO, BOARD_LED_ORANGE_GPIO_PIN, output); \ 144 BOARD_LED_ORANGE_GPIO->PDDR |= (1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Enable target LED_ORANGE */ 145 #define LED_ORANGE_ON() \ 146 GPIO_PortClear(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn on target LED_ORANGE */ 147 #define LED_ORANGE_OFF() \ 148 GPIO_PortSet(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn off target LED_ORANGE */ 149 #define LED_ORANGE_TOGGLE() \ 150 GPIO_PortToggle(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Toggle on target LED_ORANGE */ 151 152 #if defined(__cplusplus) 153 extern "C" { 154 #endif /* __cplusplus */ 155 156 /******************************************************************************* 157 * API 158 ******************************************************************************/ 159 160 void BOARD_InitDebugConsole(void); 161 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 162 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz); 163 status_t BOARD_I2C_Send(I2C_Type *base, 164 uint8_t deviceAddress, 165 uint32_t subAddress, 166 uint8_t subaddressSize, 167 uint8_t *txBuff, 168 uint8_t txBuffSize); 169 status_t BOARD_I2C_Receive(I2C_Type *base, 170 uint8_t deviceAddress, 171 uint32_t subAddress, 172 uint8_t subaddressSize, 173 uint8_t *rxBuff, 174 uint8_t rxBuffSize); 175 void BOARD_Accel_I2C_Init(void); 176 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 177 status_t BOARD_Accel_I2C_Receive( 178 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 179 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 180 181 #if defined(__cplusplus) 182 } 183 #endif /* __cplusplus */ 184 185 #endif /* _BOARD_H_ */ 186