3 * Atmel mxt probably mxt1188s-a or mxt1664s-a or mxt3432s or mxt143e
4 * I think its the mxt143e
6 * URL for original source material:
7 * http://www.atmel.com/products/touchsolutions/touchscreens/unlimited_touch.aspx
8 * GIT for original source material:
9 * git://github.com/atmel-maxtouch/obp-utils.git
11 * cc obp-utils.c test_atmel.c -o /tmp/test -I/usr/src/sys/
13 * kldload smb before running test program to get /dev/smb*
15 #include <sys/types.h>
23 #include <dev/smbus/smb/smb.h>
24 #include <bus/smbus/smbconf.h>
26 #include "obp-utils.h"
29 mxt_gettypestring(int type)
31 static const struct mxt_strinfo strinfo[] = { MXT_INIT_STRINGS };
34 for (i = 0; i < sizeof(strinfo) / sizeof(strinfo[0]); ++i) {
35 if (strinfo[i].type == type)
36 return(strinfo[i].id);
42 mxt_findobject(struct mxt_rollup *rup, int type)
46 for (i = 0; i < rup->nobjs; ++i) {
47 if (rup->objs[i].type == type)
48 return(&rup->objs[i]);
54 mxt_read_reg(int fd, uint16_t reg, void *rbuf, int bytes)
60 bzero(&cmd, sizeof(cmd));
68 cmd.op = SMB_TRANS_NOCNT | SMB_TRANS_NOCMD | SMB_TRANS_7BIT;
70 r = ioctl(fd, SMB_TRANS, &cmd);
74 printf("status r = %d slave 0x%02x\n", r, cmd.slave);
80 mxt_write_reg_buf(int fd, uint16_t reg, void *xbuf, int bytes)
86 assert(bytes < sizeof(wbuf) - 2);
89 bcopy(xbuf, wbuf + 2, bytes);
94 cmd.wcount = bytes + 2;
96 cmd.op = SMB_TRANS_NOCNT | SMB_TRANS_NOCMD | SMB_TRANS_7BIT;
98 r = ioctl(fd, SMB_TRANS, &cmd);
102 printf("status r = %d slave 0x%02x\n", r, cmd.slave);
108 mxt_write_reg(int fd, uint16_t reg, uint8_t val)
110 return mxt_write_reg_buf(fd, reg, &val, 1);
114 mxt_read_object(int fd, struct mxt_object *obj, void *rbuf, int rbytes)
116 uint16_t reg = obj->start_pos_lsb + (obj->start_pos_msb << 8);
117 int bytes = obj->size_minus_one + 1;
121 return mxt_read_reg(fd, reg, rbuf, bytes);
126 mxt_t6_command(int fd, uint16_t t6cmd, uint8_t t6val, int waitforme)
130 mxt_write_reg(fd, 6 + t6cmd, t6val);
133 if (mxt_read_reg(fd, 6 + t6cmd, &status, 1) != 1)
143 msgflagsstr(uint8_t flags)
147 buf[0] = (flags & MXT_MSGF_DETECT) ? 'D' : '.';
148 buf[1] = (flags & MXT_MSGF_PRESS) ? 'P' : '.';
149 buf[2] = (flags & MXT_MSGF_RELEASE) ? 'R' : '.';
150 buf[3] = (flags & MXT_MSGF_MOVE) ? 'M' : '.';
151 buf[4] = (flags & MXT_MSGF_VECTOR) ? 'V' : '.';
152 buf[5] = (flags & MXT_MSGF_AMP) ? 'A' : '.';
153 buf[6] = (flags & MXT_MSGF_SUPPRESS) ? 'S' : '.';
154 buf[7] = (flags & MXT_MSGF_UNGRIP) ? 'U' : '.';
160 main(int ac, char **av)
163 struct mxt_rollup rup;
164 struct mxt_object *obj;
173 fd = open("/dev/smb1-4a", O_RDWR);
174 printf("fd = %d\n", fd);
176 r = mxt_t6_command(fd, 0/*RESET*/, 0x01, 1);
177 printf("reset result %d\n", r);
179 n = mxt_read_reg(fd, 0, &rup.info, sizeof(rup.info));
180 for (i = 0; i < n; ++i)
181 printf(" %02x", ((uint8_t *)&rup.info)[i]);
183 rup.nobjs = rup.info.num_objects;
185 blksize = sizeof(rup.info) +
186 rup.nobjs * sizeof(struct mxt_object);
187 totsize = blksize + sizeof(struct mxt_raw_crc);
188 assert(totsize < sizeof(rbuf));
190 n = mxt_read_reg(fd, 0, rbuf, totsize);
192 printf("mxt_read_reg: config failed: %d/%d\n", n, totsize);
195 crc = obp_convert_crc((struct mxt_raw_crc *)(rbuf + blksize));
196 if (obp_crc24(rbuf, blksize) != crc) {
197 printf("info: crc failed %08x/%08x\n",
199 obp_crc24(rbuf, blksize));
202 rup.objs = (void *)(rbuf + sizeof(rup.info));
203 for (i = 0; i < rup.nobjs; ++i) {
205 printf("object %d (%s) {\n",
207 mxt_gettypestring(obj->type));
208 printf(" position = %d\n",
209 obj->start_pos_lsb + (obj->start_pos_msb << 8));
210 printf(" size = %d\n",
211 obj->size_minus_one + 1);
212 printf(" instances= %d\n",
213 obj->instances_minus_one + 1);
214 printf(" numids = %d\n",
215 obj->num_report_ids);
220 obj = mxt_findobject(&rup, MXT_GEN_MESSAGEPROCESSOR);
226 n = mxt_read_object(fd, obj, &msg, sizeof(msg));
227 if (msg.any.reportid == 255)
229 for (i = 0; i < n; ++i)
230 printf(" %02x", ((uint8_t *)&msg)[i]);
231 printf(" trk=%02x f=%s x=%-4d y=%-4d p=%d amp=%d\n",
233 msgflagsstr(msg.touch.flags),
234 (msg.touch.pos[0] << 4) |
235 ((msg.touch.pos[2] >> 4) & 0x0F),
236 (msg.touch.pos[1] << 4) |
237 ((msg.touch.pos[2]) & 0x0F),
239 msg.touch.amplitude);