This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
forked from Dax89/chuwi-dev
-
Notifications
You must be signed in to change notification settings - Fork 3
/
chipone_regs.c
107 lines (81 loc) · 3.33 KB
/
chipone_regs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "chipone_regs.h"
#include "chipone.h"
static int chipone_ts_regs_i2c_rxdata(struct i2c_client* client, unsigned short addr, char* rxdata, int length){
struct device* dev = &client->dev;
int ret = -1, retries = 0;
unsigned char tmpbuf[2];
struct i2c_msg msgs[] = {
{
.addr = client->addr,
.flags = 0,
.len = 2,
.buf = tmpbuf,
},
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = length,
.buf = rxdata,
},
};
tmpbuf[0] = (unsigned char)(addr >> 8);
tmpbuf[1] = (unsigned char)(addr);
while(retries < CHIPONE_IIC_RETRY_NUM){
ret = i2c_transfer(client->adapter, msgs, 2);
if(ret == 2)
break;
retries++;
}
if(retries >= CHIPONE_IIC_RETRY_NUM)
dev_err(dev, "%s: i2c read error: %d\n", __func__, ret);
return ret;
}
static int chipone_ts_regs_i2c_txdata(struct i2c_client* client, unsigned short addr, char* txdata, int length){
struct device* dev = &client->dev;
int ret = -1, retries = 0;
unsigned char tmpbuf[128];
struct i2c_msg msg[] = {
{
.addr = client->addr,
.flags = 0,
.len = length + 2,
.buf = tmpbuf,
},
};
if (length > 125){
dev_err(dev, "%s: too big datalen = %d!\n", __func__, length);
return -1;
}
tmpbuf[0] = (unsigned char)(addr >> 8);
tmpbuf[1] = (unsigned char)(addr);
if(length != 0 && txdata != NULL)
memcpy(&tmpbuf[2], txdata, length);
while(retries < CHIPONE_IIC_RETRY_NUM){
ret = i2c_transfer(client->adapter, msg, 1);
if(ret == 1)
break;
retries++;
}
if(retries >= CHIPONE_IIC_RETRY_NUM)
dev_err(dev, "%s: i2c write error: %d\n", __func__, ret);
return ret;
}
bool chipone_ts_regs_is_finger_down(struct chipone_ts_coordinate_area_regs* coordinatearearegs, int idx){
return (coordinatearearegs->pointer[idx].event_id == POINTER_EVENT_DOWN) ||
(coordinatearearegs->pointer[idx].event_id == POINTER_EVENT_MOVE);
}
int chipone_ts_regs_get_header_area(struct i2c_client* client, struct chipone_ts_header_area_regs* headerarearegs){
return chipone_ts_regs_i2c_rxdata(client, HEADER_AREA_BASE, (char*)headerarearegs, sizeof(*headerarearegs));
}
int chipone_ts_regs_get_coordinate_area(struct i2c_client* client, struct chipone_ts_coordinate_area_regs* coordinatearearegs){
return chipone_ts_regs_i2c_rxdata(client, COORDINATE_AREA_BASE, (char*)coordinatearearegs, sizeof(*coordinatearearegs));
}
int chipone_ts_regs_get_configuration_area(struct i2c_client* client, struct chipone_ts_configuration_area_regs* configurationarea){
return chipone_ts_regs_i2c_rxdata(client, CONFIGURATION_AREA_BASE, (char*)configurationarea, sizeof(*configurationarea));
}
int chipone_ts_regs_set_resolution(struct i2c_client* client, u16 width, u16 height){
int res = chipone_ts_regs_i2c_txdata(client, CONFIGURATION_AREA_BASE + offsetof(struct chipone_ts_configuration_area_regs, res_x), (char*)&height, sizeof(u16));
if(res < 0)
return res;
return chipone_ts_regs_i2c_txdata(client, CONFIGURATION_AREA_BASE + offsetof(struct chipone_ts_configuration_area_regs, res_y), (char*)&width, sizeof(u16));
}