ARM: rockchip: rk3228: add grf definition
[firefly-linux-kernel-4.4.55.git] / include / linux / goodix_queue.h
1 /*---------------------------------------------------------------------------------------------------------
2  * kernel/include/linux/goodix_queue.h
3  *
4  * Copyright(c) 2010 Goodix Technology Corp. All rights reserved.      
5  * Author: Eltonny
6  * Date: 2010.11.11                                    
7  *                                                                                                         
8  *---------------------------------------------------------------------------------------------------------*/
9  
10 /* 用于管理手指序列的伪队列操作函数,
11  * 适用于Goodix的Guitar小屏驱动
12  * 调整手指上报顺序以避免出现手指ID交换现象
13  * 在大屏驱动中,该功能将被调整
14  */ 
15 #ifndef _LINUX_GOODIX_QUEUE_H
16 #define _LINUX_GOODIX_QUEUE_H
17 #include <linux/goodix_touch.h>
18
19 struct point_node
20 {
21         uint8_t num;
22         uint8_t state;
23         uint8_t pressure;
24         unsigned int x;
25         unsigned int y;
26 };
27
28 struct point_queue
29 {
30         int length;
31         struct point_node pointer[MAX_FINGER_NUM];
32 };
33
34
35 /*******************************************************        
36 功能:
37         删除手指队列中松键的手指
38 参数:
39         point_list
40 ********************************************************/
41 static void del_point(struct point_queue *point_list)
42 {
43         int count = point_list->length-1;
44         int position;
45         for(; count >= 0; count--)              //note: must search from tail to head
46         if(point_list->pointer[count].state == FLAG_UP)
47         {               
48                         if(point_list->length == 0 )
49                                 return ;
50                         position = count;
51                         for(; position < MAX_FINGER_NUM -1; position++)
52                                 point_list->pointer[position] = point_list->pointer[position+1];
53                         point_list->length--;
54         }
55 }
56
57 /*******************************************************        
58 功能:
59         在队列尾中加入新增的手指
60 参数:
61         point_list
62         num:手指标号
63 return:
64         是否成功增加手指
65 ********************************************************/
66 static int add_point(struct point_queue *point_list, int num)
67 {
68         if(point_list->length >= MAX_FINGER_NUM || num < 0 )
69                 return -1;
70         point_list->pointer[point_list->length].num = num;
71         point_list->pointer[point_list->length].state = FLAG_DOWN;
72         point_list->length++;
73         return 0;
74 }
75
76 /*******************************************************        
77 功能:
78         查找指定标号的手指位置
79 参数:
80         point_list
81         num:手指标号
82 return:
83         返回找到的手指在队列中的位置
84 ********************************************************/
85 static int search_point(struct point_queue *point_list, int num)
86 {
87         int count = 0;
88         if(point_list->length <= 0 || num < 0 || num > MAX_FINGER_NUM)
89                 return -1;      //no data
90         for(; count < point_list->length; count++)
91                 if(point_list->pointer[count].num == num)
92                         return count;
93                 else continue;
94         return -1;
95 }
96
97 /*******************************************************        
98 功能:
99         查找松键的手指并设置标志位为FLAG_UP
100 参数:
101         point_list
102         num:手指标号
103 return:
104         是否成功设置手指标志位
105 ********************************************************/
106 static int set_up_point(struct point_queue *point_list, int num)
107 {
108         int number = 0;
109         if(point_list->length <= 0 || num < 0 || num > MAX_FINGER_NUM)
110                 return -1;      //no data
111         number = search_point(point_list, num);
112         if(num >= 0)
113         {
114                 point_list->pointer[number].state = FLAG_UP;
115                 return 0;
116         }
117         return -1;
118 }
119
120 #endif /* _LINUX_GOODIX_QUEUE_H */