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_FT6X06_H_
10 #define _FSL_FT6X06_H_
11 
12 #include "fsl_common.h"
13 #include "Driver_I2C.h"
14 
15 /*!
16  * @addtogroup ft6x06
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 
24 /*! @brief FT6X06 I2C address. */
25 #define FT6X06_I2C_ADDRESS (0x38)
26 
27 /*! @brief FT6X06 maximum number of simultaneously detected touches. */
28 #define FT6X06_MAX_TOUCHES (2U)
29 
30 /*! @brief FT6X06 register address where touch data begin. */
31 #define F6X06_TOUCH_DATA_SUBADDR (1)
32 
33 /*! @brief FT6X06 raw touch data length. */
34 #define FT6X06_TOUCH_DATA_LEN (2 + (FT6X06_MAX_TOUCHES)*6)
35 
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 typedef struct _touch_point
45 {
46     touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */
47     uint8_t TOUCH_ID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */
48     uint16_t TOUCH_X; /*!< X coordinate of the touch point */
49     uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */
50 } touch_point_t;
51 
52 typedef struct _ft6x06_handle
53 {
54     ARM_DRIVER_I2C *i2c_driver;
55     volatile uint32_t i2c_event;
56     volatile bool i2c_event_received;
57     uint8_t touch_buf[FT6X06_TOUCH_DATA_LEN];
58 } ft6x06_handle_t;
59 
60 status_t FT6X06_Init(ft6x06_handle_t *handle, ARM_DRIVER_I2C *i2c_driver);
61 
62 status_t FT6X06_Denit(ft6x06_handle_t *handle);
63 
64 void FT6X06_EventHandler(ft6x06_handle_t *handle, uint32_t i2c_event);
65 
66 status_t FT6X06_GetSingleTouch(ft6x06_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y);
67 
68 status_t FT6X06_GetMultiTouch(ft6x06_handle_t *handle, int *touch_count, touch_point_t touch_array[FT6X06_MAX_TOUCHES]);
69 
70 #endif
71