1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_FT5406_RT_H_
10 #define _FSL_FT5406_RT_H_
11 
12 #include "fsl_common.h"
13 
14 /*!
15  * @addtogroup ft5406_rt
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /*! @brief FT5406_RT I2C address. */
24 #define FT5406_RT_I2C_ADDRESS (0x38)
25 
26 /*! @brief FT5406_RT maximum number of simultaneously detected touches. */
27 #define FT5406_RT_MAX_TOUCHES (5U)
28 
29 /*! @brief FT5406_RT register address where touch data begin. */
30 #define FT5406_RT_TOUCH_DATA_SUBADDR (1)
31 
32 /*! @brief FT5406_RT raw touch data length. */
33 #define FT5406_RT_TOUCH_DATA_LEN (0x20)
34 
35 /*! @brief Touch event. */
36 typedef enum _touch_event
37 {
38     kTouch_Down     = 0, /*!< The state changed to touched. */
39     kTouch_Up       = 1, /*!< The state changed to not touched. */
40     kTouch_Contact  = 2, /*!< There is a continuous touch being detected. */
41     kTouch_Reserved = 3  /*!< No touch information available. */
42 } touch_event_t;
43 
44 /*! @brief Touch point information. */
45 typedef struct _touch_point
46 {
47     touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */
48     uint8_t TOUCH_ID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */
49     uint16_t TOUCH_X; /*!< X coordinate of the touch point */
50     uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */
51 } touch_point_t;
52 
53 /*! @brief Driver handle. */
54 typedef struct _ft5406_rt_handle
55 {
56     LPI2C_Type *base;
57     lpi2c_master_transfer_t xfer;
58     uint8_t touch_buf[FT5406_RT_TOUCH_DATA_LEN];
59 } ft5406_rt_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 [in] handle Pointer to the driver.
73  * @param [in] base The I2C used by FT5406.
74  * @return Returns @ref kStatus_Success if initialize success, otherwise return error code.
75  */
76 status_t FT5406_RT_Init(ft5406_rt_handle_t *handle, LPI2C_Type *base);
77 
78 /*!
79  * @brief De-initialize the driver.
80  *
81  * @param [in] handle Pointer to the driver.
82  * @return Returns @ref kStatus_Success if success, otherwise return error code.
83  */
84 status_t FT5406_RT_Denit(ft5406_rt_handle_t *handle);
85 
86 /*!
87  * @brief Get single touch point coordinate.
88  *
89  * Get one touch point coordinate.
90  *
91  * @param [in] handle Pointer to the driver.
92  * @param [out] touch_event Touch event.
93  * @param [out] touch_x X coordinate of the touch point.
94  * @param [out] touch_y Y coordinate of the touch point.
95  * @return Returns @ref kStatus_Success if success, otherwise return error code.
96  */
97 status_t FT5406_RT_GetSingleTouch(ft5406_rt_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y);
98 
99 /*!
100  * @brief Get multiple touch points coordinate.
101  *
102  * When this function returns successfully, the @p touch_count shows how
103  * many valid touch points there are in the @p touch_array.
104  *
105  * @param [in] handle Pointer to the driver.
106  * @param [out] touch_count The actual touch point number.
107  * @param [out] touch_array Array of touch points coordinate.
108  * @return Returns @ref kStatus_Success if success, otherwise return error code.
109  */
110 status_t FT5406_RT_GetMultiTouch(ft5406_rt_handle_t *handle,
111                                  int *touch_count,
112                                  touch_point_t touch_array[FT5406_RT_MAX_TOUCHES]);
113 
114 #if defined(__cplusplus)
115 }
116 #endif
117 
118 /*! @} */
119 
120 #endif
121