1 /*
2  * Copyright 2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_FT3267_H_
9 #define _FSL_FT3267_H_
10 
11 #include "fsl_common.h"
12 
13 /*
14  * Change log:
15  *
16  *   1.0.1
17  *     - Fix MISRA 2012 issues.
18  *
19  *   1.0.0
20  *     - Initial version
21  */
22 
23 /*!
24  * @addtogroup ft3267
25  * @{
26  */
27 
28 /*******************************************************************************
29  * Definitions
30  ******************************************************************************/
31 
32 /*! @brief FT3267 I2C address. */
33 #define FT3267_I2C_ADDRESS (0x38U)
34 
35 /*! @brief FT3267 maximum number of simultaneously detected touches. */
36 #define FT3267_MAX_TOUCHES (5U)
37 
38 /*! @brief FT3267 register address where touch data begin. */
39 #define FT3267_TOUCH_DATA_SUBADDR (1)
40 
41 /*! @brief FT3267 raw touch data length. */
42 #define FT3267_TOUCH_DATA_LEN (0x20)
43 
44 /*! @brief FT3267 I2C receive function. */
45 typedef status_t (*ft3267_i2c_receive_func_t)(
46     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
47 
48 /*! @brief Function to pull reset pin up or down. */
49 typedef void (*ft3267_reset_pin_func_t)(bool pullUp);
50 
51 /*! @brief Function to pull power pin up or down. */
52 typedef void (*ft3267_power_pin_func_t)(bool pullUp);
53 
54 /*! @brief Touch event. */
55 typedef enum _touch_event
56 {
57     kTouch_Down     = 0, /*!< The state changed to touched. */
58     kTouch_Up       = 1, /*!< The state changed to not touched. */
59     kTouch_Contact  = 2, /*!< There is a continuous touch being detected. */
60     kTouch_Reserved = 3  /*!< No touch information available. */
61 } touch_event_t;
62 
63 /*! @brief Touch point information. */
64 typedef struct _touch_point
65 {
66     touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */
67     uint8_t TOUCH_ID; /*!< ID of the touch point. This numeric value stays constant between down and up event. */
68     uint16_t TOUCH_X; /*!< X coordinate of the touch point */
69     uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */
70 } touch_point_t;
71 
72 /*! @brief FT3267 configure structure.*/
73 typedef struct _ft3267_config
74 {
75     ft3267_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */
76     ft3267_reset_pin_func_t pullResetPinFunc;  /*!< Function to pull reset pin high or low. */
77     ft3267_power_pin_func_t pullPowerPinFunc;  /*!< Function to pull power pin high or low. */
78     void (*timeDelayMsFunc)(uint32_t delayMs); /*!< Function to delay some MS. */
79 } ft3267_config_t;
80 
81 /*! @brief FT3267 driver handle. */
82 typedef struct _ft3267_handle
83 {
84     ft3267_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */
85     ft3267_reset_pin_func_t pullResetPinFunc;  /*!< Function to pull reset pin high or low. */
86     ft3267_power_pin_func_t pullPowerPinFunc;  /*!< Function to pull power pin high or low. */
87     uint8_t touchBuf[FT3267_TOUCH_DATA_LEN];   /*!< Buffer to receive touch point raw data. */
88 } ft3267_handle_t;
89 
90 /*******************************************************************************
91  * API
92  ******************************************************************************/
93 
94 #if defined(__cplusplus)
95 extern "C" {
96 #endif
97 
98 /*!
99  * @brief Initialize the driver.
100  *
101  * This function power on the touch controller, releases the touch controller
102  * reset. After calling this function, the touch controller is ready to work.
103  *
104  * @param [in] handle Pointer to the driver.
105  * @param [in] config Pointer to the configuration.
106  * @return Returns @ref kStatus_Success if initialize success, otherwise return error code.
107  */
108 status_t FT3267_Init(ft3267_handle_t *handle, const ft3267_config_t *config);
109 
110 /*!
111  * @brief De-initialize the driver.
112  *
113  * After this function, the touch controller is powered off.
114  *
115  * @param [in] handle Pointer to the driver.
116  * @return Returns @ref kStatus_Success if success, otherwise return error code.
117  */
118 status_t FT3267_Deinit(ft3267_handle_t *handle);
119 
120 /*!
121  * @brief Get single touch point coordinate.
122  *
123  * Get one touch point coordinate.
124  *
125  * @param [in] handle Pointer to the driver.
126  * @param [out] touch_x X coordinate of the touch point.
127  * @param [out] touch_y Y coordinate of the touch point.
128  * @return Returns @ref kStatus_Success if success, otherwise return error code.
129  */
130 status_t FT3267_GetSingleTouch(ft3267_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y);
131 
132 /*!
133  * @brief Get multiple touch points coordinate.
134  *
135  * When this function returns successfully, the @p touch_count shows how
136  * many valid touch points there are in the @p touch_array.
137  *
138  * @param [in] handle Pointer to the driver.
139  * @param [out] touch_count The actual touch point number.
140  * @param [out] touch_array Array of touch points coordinate.
141  * @return Returns @ref kStatus_Success if success, otherwise return error code.
142  */
143 status_t FT3267_GetMultiTouch(ft3267_handle_t *handle, int *touch_count, touch_point_t touch_array[FT3267_MAX_TOUCHES]);
144 
145 #if defined(__cplusplus)
146 }
147 #endif
148 
149 /*! @} */
150 
151 #endif
152