1 /* 2 * Copyright 2019 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _FSL_EKTF2K_H_ 9 #define _FSL_EKTF2K_H_ 10 11 #include "fsl_common.h" 12 13 /*! 14 * @addtogroup ektf2k 15 * @{ 16 */ 17 18 /******************************************************************************* 19 * Definitions 20 ******************************************************************************/ 21 /*! @brief EKTF2K maximum number of simultaneously detected touches. */ 22 #define EKTF2K_MAX_TOUCHES (2U) 23 24 /*! @brief EKTF2K raw touch data length. */ 25 #define EKTF2K_TOUCH_DATA_LEN (0x08) 26 27 typedef status_t (*ektf2k_i2c_send_func_t)( 28 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 29 typedef status_t (*ektf2k_i2c_receive_func_t)( 30 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 31 32 typedef struct _touch_point 33 { 34 bool valid; /*!< Whether the touch point coordinate value is valid. */ 35 uint8_t touchID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */ 36 uint16_t x; /*!< X coordinate of the touch point */ 37 uint16_t y; /*!< Y coordinate of the touch point */ 38 } touch_point_t; 39 40 /*! @brief ektf2k configure structure.*/ 41 typedef struct _ektf2k_config 42 { 43 ektf2k_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 44 ektf2k_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 45 void (*timeDelayMsFunc)(uint32_t delayMs); /*!< Function to delay some MS. */ 46 void (*pullResetPin)(bool pullUp); /*!< Function to pull reset pin high or low. */ 47 } ektf2k_config_t; 48 49 /*! @brief ektf2k driver structure.*/ 50 typedef struct _ektf2k_handle 51 { 52 ektf2k_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 53 ektf2k_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 54 void (*timeDelayMsFunc)(uint32_t delayMs); /*!< Function to delay some MS. */ 55 void (*pullResetPin)(bool pullUp); /*!< Function to pull reset pin high or low. */ 56 uint8_t receiveBuf[EKTF2K_TOUCH_DATA_LEN]; /*!< The I2C receive buffer. */ 57 uint16_t resolutionX; /*!< Resolution of the touch IC, it might be different with the display resolution. */ 58 uint16_t resolutionY; /*!< Resolution of the touch IC, it might be different with the display resolution. */ 59 } ektf2k_handle_t; 60 61 /******************************************************************************* 62 * API 63 ******************************************************************************/ 64 65 #if defined(__cplusplus) 66 extern "C" { 67 #endif 68 69 /*! 70 * @brief Initialize the driver. 71 * 72 * @param handle Pointer to the EKTF2K driver. 73 * @param config Pointer to the configuration. 74 * @return Returns @ref kStatus_Success if erase success, otherwise return error code. 75 */ 76 status_t EKTF2K_Init(ektf2k_handle_t *handle, const ektf2k_config_t *config); 77 78 /*! 79 * @brief De-initialize the driver. 80 * 81 * @param handle Pointer to the EKTF2K driver. 82 * @return Returns @ref kStatus_Success if erase success, otherwise return error code. 83 */ 84 status_t EKTF2K_Deinit(ektf2k_handle_t *handle); 85 86 /*! 87 * @brief Get touch IC resolution. 88 * 89 * Note the touch resolution might be different with display resolution. 90 * 91 * @param handle Pointer to the EKTF2K driver. 92 * @param touch_x X resolution. 93 * @param touch_y Y resolution. 94 * @return Returns @ref kStatus_Success if erase success, otherwise return error code. 95 */ 96 status_t EKTF2K_GetResolution(ektf2k_handle_t *handle, int *resolutionX, int *resolutionY); 97 98 /*! 99 * @brief Get single touch point coordinate. 100 * 101 * @param handle Pointer to the EKTF2K driver. 102 * @param touch_x X coordinate of the touch point. 103 * @param touch_y Y coordinate of the touch point. 104 * @return Returns @ref kStatus_Success if erase success, otherwise return error code. 105 */ 106 status_t EKTF2K_GetSingleTouch(ektf2k_handle_t *handle, int *touch_x, int *touch_y); 107 108 /*! 109 * @brief Get multiple touch points coordinate. 110 * 111 * @param handle Pointer to the EKTF2K driver. 112 * @param touch_array Array of touch points coordinate. 113 * @return Returns @ref kStatus_Success if erase success, otherwise return error code. 114 */ 115 status_t EKTF2K_GetMultiTouch(ektf2k_handle_t *handle, touch_point_t touch_array[EKTF2K_MAX_TOUCHES]); 116 117 #if defined(__cplusplus) 118 } 119 #endif 120 121 /*! @} */ 122 123 #endif /* _FSL_EKTF2K_H_ */ 124