1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017, 2024 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_FT6X06_H_ 10 #define _FSL_FT6X06_H_ 11 12 #include "fsl_common.h" 13 14 /*! 15 * @addtogroup ft6x06 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 #ifndef FT6X06_USE_CMSIS_DRIVER 24 #define FT6X06_USE_CMSIS_DRIVER 1 25 #endif 26 27 #if (FT6X06_USE_CMSIS_DRIVER) 28 #include "Driver_I2C.h" 29 #endif 30 31 /*! @brief FT6X06 I2C address. */ 32 #define FT6X06_I2C_ADDRESS (0x38) 33 34 /*! @brief FT6X06 maximum number of simultaneously detected touches. */ 35 #define FT6X06_MAX_TOUCHES (2U) 36 37 /*! @brief FT6X06 register address where touch data begin. */ 38 #define F6X06_TOUCH_DATA_SUBADDR (1) 39 40 /*! @brief FT6X06 raw touch data length. */ 41 #define FT6X06_TOUCH_DATA_LEN (2 + (FT6X06_MAX_TOUCHES) * 6) 42 43 #if (!FT6X06_USE_CMSIS_DRIVER) 44 typedef status_t (*ft6x06_i2c_send_func_t)( 45 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 46 typedef status_t (*ft6x06_i2c_receive_func_t)( 47 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 48 49 typedef struct _ft6x06_config 50 { 51 ft6x06_i2c_send_func_t I2C_SendFunc; 52 ft6x06_i2c_receive_func_t I2C_ReceiveFunc; 53 } ft6x06_config_t; 54 #endif 55 56 /*! @brief Touch event. */ 57 typedef enum _touch_event 58 { 59 kTouch_Down = 0, /*!< The state changed to touched. */ 60 kTouch_Up = 1, /*!< The state changed to not touched. */ 61 kTouch_Contact = 2, /*!< There is a continuous touch being detected. */ 62 kTouch_Reserved = 3 /*!< No touch information available. */ 63 } touch_event_t; 64 65 /*! @brief Touch point information. */ 66 typedef struct _touch_point 67 { 68 touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */ 69 uint8_t TOUCH_ID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */ 70 uint16_t TOUCH_X; /*!< X coordinate of the touch point */ 71 uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */ 72 } touch_point_t; 73 74 /*! @brief FT6X06 driver handle. */ 75 typedef struct _ft6x06_handle 76 { 77 #if FT6X06_USE_CMSIS_DRIVER 78 ARM_DRIVER_I2C *i2c_driver; 79 volatile uint32_t i2c_event; 80 volatile bool i2c_event_received; 81 #else 82 ft6x06_i2c_send_func_t I2C_SendFunc; 83 ft6x06_i2c_receive_func_t I2C_ReceiveFunc; 84 #endif 85 uint8_t touch_buf[FT6X06_TOUCH_DATA_LEN]; 86 } ft6x06_handle_t; 87 88 /******************************************************************************* 89 * API 90 ******************************************************************************/ 91 92 #if defined(__cplusplus) 93 extern "C" { 94 #endif 95 96 #if FT6X06_USE_CMSIS_DRIVER 97 /*! 98 * @brief Initialize the driver. 99 * 100 * This function power on the touch controller, releases the touch controller 101 * reset. After calling this function, the touch controller is ready to work. 102 * 103 * @param [in] handle Pointer to the driver. 104 * @param [in] i2c_driver Pointer to the CMSIS I2C driver used by FT6X06. 105 * @return Returns @ref kStatus_Success if initialize success, otherwise return error code. 106 */ 107 status_t FT6X06_Init(ft6x06_handle_t *handle, ARM_DRIVER_I2C *i2c_driver); 108 #else 109 status_t FT6X06_Init(ft6x06_handle_t *handle, const ft6x06_config_t *config); 110 #endif /* FT6X06_USE_CMSIS_DRIVER */ 111 112 /*! 113 * @brief De-initialize the driver. 114 * 115 * After this function, the touch controller is powered off. 116 * 117 * @param [in] handle Pointer to the driver. 118 * @return Returns @ref kStatus_Success if success, otherwise return error code. 119 */ 120 status_t FT6X06_Denit(ft6x06_handle_t *handle); 121 122 #if FT6X06_USE_CMSIS_DRIVER 123 /*! 124 * @brief Event Handler 125 * 126 * Called in CMSIS I2C event handler to notify the event. 127 * 128 * @param [in] handle Pointer to the driver. 129 * @param [in] i2c_event The event passed by CMSIS I2C signal function ARM_I2C_SignalEvent_t 130 */ 131 void FT6X06_EventHandler(ft6x06_handle_t *handle, uint32_t i2c_event); 132 #endif /* FT6X06_USE_CMSIS_DRIVER */ 133 134 /*! 135 * @brief Get single touch point coordinate. 136 * 137 * Get one touch point coordinate. 138 * 139 * @param [in] handle Pointer to the driver. 140 * @param [out] touch_event Touch Event. 141 * @param [out] touch_x X coordinate of the touch point. 142 * @param [out] touch_y Y coordinate of the touch point. 143 * @return Returns @ref kStatus_Success if success, otherwise return error code. 144 */ 145 status_t FT6X06_GetSingleTouch(ft6x06_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y); 146 147 /*! 148 * @brief Get multiple touch points coordinate. 149 * 150 * When this function returns successfully, the @p touch_count shows how 151 * many valid touch points there are in the @p touch_array. 152 * 153 * @param [in] handle Pointer to the driver. 154 * @param [out] touch_count The actual touch point number. 155 * @param [out] touch_array Array of touch points coordinate. 156 * @return Returns @ref kStatus_Success if success, otherwise return error code. 157 */ 158 status_t FT6X06_GetMultiTouch(ft6x06_handle_t *handle, int *touch_count, touch_point_t touch_array[FT6X06_MAX_TOUCHES]); 159 160 #if defined(__cplusplus) 161 } 162 #endif 163 164 /*! @} */ 165 166 #endif 167