1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2018 NXP 4 * All rights reserved. 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_gpio.h" 14 15 /******************************************************************************* 16 * Definitions 17 ******************************************************************************/ 18 /*! @brief FRDM-TOUCH board defines */ 19 /* Push buttons - mutual electrodes */ 20 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_TX_ELECTRODE_1 TF_TSI_MUTUAL_CAP_TX_CHANNEL_3 /* PTE11 */ 21 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_RX_ELECTRODE_1 TF_TSI_MUTUAL_CAP_RX_CHANNEL_6 /* PTD5 */ 22 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_TX_ELECTRODE_2 TF_TSI_MUTUAL_CAP_TX_CHANNEL_3 /* PTE11 */ 23 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_RX_ELECTRODE_2 TF_TSI_MUTUAL_CAP_RX_CHANNEL_7 /* PTD6 */ 24 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_TX_ELECTRODE_3 TF_TSI_MUTUAL_CAP_TX_CHANNEL_2 /* PTE10 */ 25 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_RX_ELECTRODE_3 TF_TSI_MUTUAL_CAP_RX_CHANNEL_6 /* PTD5 */ 26 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_TX_ELECTRODE_4 TF_TSI_MUTUAL_CAP_TX_CHANNEL_2 /* PTE10 */ 27 #define FRDM_TOUCH_BOARD_TSI_MUTUAL_RX_ELECTRODE_4 TF_TSI_MUTUAL_CAP_RX_CHANNEL_7 /* PTD6 */ 28 29 /* Slider - self electrodes */ 30 #define FRDM_TOUCH_BOARD_TSI_SLIDER_ELECTRODE_1 TF_TSI_SELF_CAP_CHANNEL_10 /* PTD1 */ 31 #define FRDM_TOUCH_BOARD_TSI_SLIDER_ELECTRODE_2 TF_TSI_SELF_CAP_CHANNEL_5 /* PTD7 */ 32 33 /* Rotary - self electrodes */ 34 #define FRDM_TOUCH_BOARD_TSI_ROTARY_ELECTRODE_1 TF_TSI_SELF_CAP_CHANNEL_0 /* PTE5 */ 35 #define FRDM_TOUCH_BOARD_TSI_ROTARY_ELECTRODE_2 TF_TSI_SELF_CAP_CHANNEL_1 /* PTE4 */ 36 #define FRDM_TOUCH_BOARD_TSI_ROTARY_ELECTRODE_3 TF_TSI_SELF_CAP_CHANNEL_9 /* PTB5 */ 37 #define FRDM_TOUCH_BOARD_TSI_ROTARY_ELECTRODE_4 TF_TSI_SELF_CAP_CHANNEL_8 /* PTB4 */ 38 39 /*! @brief The board name */ 40 #define BOARD_NAME "FRDM-KE15Z" 41 42 /*! @brief The UART to use for debug messages. */ 43 #define BOARD_USE_UART 44 #define BOARD_DEBUG_UART_TYPE kSerialPort_Uart 45 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART1 46 #define BOARD_DEBUG_UART_INSTANCE 1U 47 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_IpSrcSysOscAsync 48 #define BOARD_UART_IRQ LPUART1_IRQn 49 #define BOARD_UART_IRQ_HANDLER LPUART1_IRQHandler 50 51 /* @Brief Board accelerator sensor configuration */ 52 #define BOARD_ACCEL_I2C_BASEADDR LPI2C0 53 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetIpFreq(kCLOCK_Lpi2c0) 54 55 #ifndef BOARD_DEBUG_UART_BAUDRATE 56 #define BOARD_DEBUG_UART_BAUDRATE 115200 57 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 58 59 /*! @brief The i2c instance used for i2c connection by default */ 60 #define BOARD_I2C_BASEADDR I2C0 61 62 /*! @brief The CMP instance/channel used for board. */ 63 #define BOARD_CMP_BASEADDR CMP0 64 #define BOARD_CMP_CHANNEL 7U 65 66 /*! @brief The rtc instance used for board. */ 67 #define BOARD_RTC_FUNC_BASEADDR RTC 68 69 /*! @brief Indexes of the TSI channels for on-board electrodes */ 70 #ifndef BOARD_TSI_ELECTRODE_1 71 #define BOARD_TSI_ELECTRODE_1 22U 72 #endif 73 #ifndef BOARD_TSI_ELECTRODE_2 74 #define BOARD_TSI_ELECTRODE_2 23U 75 #endif 76 77 /*! @brief Indexes of the TSI mutual channels for FRDM-TOUCH board */ 78 #define BOARD_TSI_MUTUAL_TX_ELECTRODE_1 2U 79 #define BOARD_TSI_MUTUAL_RX_ELECTRODE_1 6U 80 81 /*! @brief Define the port interrupt number for the board switches */ 82 #ifndef BOARD_SW2_GPIO 83 #define BOARD_SW2_GPIO GPIOB 84 #endif 85 #ifndef BOARD_SW2_PORT 86 #define BOARD_SW2_PORT PORTB 87 #endif 88 #ifndef BOARD_SW2_GPIO_PIN 89 #define BOARD_SW2_GPIO_PIN 11U 90 #endif 91 #define BOARD_SW2_IRQ PORTBCD_IRQn 92 #define BOARD_SW2_IRQ_HANDLER PORTBCD_IRQHandler 93 #define BOARD_SW2_NAME "SW2" 94 95 /* Board RGB LED color mapping */ 96 #define LOGIC_LED_ON 0U 97 #define LOGIC_LED_OFF 1U 98 #ifndef BOARD_LED_RED_GPIO 99 #define BOARD_LED_RED_GPIO GPIOD 100 #endif 101 #define BOARD_LED_RED_GPIO_PORT PORTD 102 #ifndef BOARD_LED_RED_GPIO_PIN 103 #define BOARD_LED_RED_GPIO_PIN 0U 104 #endif 105 #ifndef BOARD_LED_GREEN_GPIO 106 #define BOARD_LED_GREEN_GPIO GPIOD 107 #endif 108 #define BOARD_LED_GREEN_GPIO_PORT PORTD 109 #ifndef BOARD_LED_GREEN_GPIO_PIN 110 #define BOARD_LED_GREEN_GPIO_PIN 16U 111 #endif 112 #ifndef BOARD_LED_BLUE_GPIO 113 #define BOARD_LED_BLUE_GPIO GPIOD 114 #endif 115 #define BOARD_LED_BLUE_GPIO_PORT PORTD 116 #ifndef BOARD_LED_BLUE_GPIO_PIN 117 #define BOARD_LED_BLUE_GPIO_PIN 15U 118 #endif 119 120 #define LED_RED1_INIT(output) \ 121 GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \ 122 BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED1 */ 123 #define LED_RED1_ON() GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED1 */ 124 #define LED_RED1_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED1 */ 125 #define LED_RED1_TOGGLE() \ 126 GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED1 */ 127 128 #define LED_GREEN1_INIT(output) \ 129 GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \ 130 BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN1 */ 131 #define LED_GREEN1_ON() \ 132 GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN1 */ 133 #define LED_GREEN1_OFF() \ 134 GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN1 */ 135 #define LED_GREEN1_TOGGLE() \ 136 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN1 */ 137 138 #define LED_BLUE_INIT(output) \ 139 GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \ 140 BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */ 141 #define LED_BLUE_ON() \ 142 GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ 143 */ 144 #define LED_BLUE_OFF() \ 145 GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ 146 */ 147 #define LED_BLUE_TOGGLE() \ 148 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 149 150 #if defined(__cplusplus) 151 extern "C" { 152 #endif /* __cplusplus */ 153 154 /******************************************************************************* 155 * API 156 ******************************************************************************/ 157 158 void BOARD_InitDebugConsole(void); 159 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 160 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz); 161 status_t BOARD_LPI2C_Send(LPI2C_Type *base, 162 uint8_t deviceAddress, 163 uint32_t subAddress, 164 uint8_t subaddressSize, 165 uint8_t *txBuff, 166 uint8_t txBuffSize); 167 status_t BOARD_LPI2C_Receive(LPI2C_Type *base, 168 uint8_t deviceAddress, 169 uint32_t subAddress, 170 uint8_t subaddressSize, 171 uint8_t *rxBuff, 172 uint8_t rxBuffSize); 173 void BOARD_Accel_I2C_Init(void); 174 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 175 status_t BOARD_Accel_I2C_Receive( 176 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 177 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 178 179 #if defined(__cplusplus) 180 } 181 #endif /* __cplusplus */ 182 183 #endif /* _BOARD_H_ */ 184