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