From aa9868b333a72921f492e4780efd02bd26db3ac6 Mon Sep 17 00:00:00 2001 From: Frederik 'playya' Sdun Date: Tue, 4 May 2010 13:18:22 +0200 Subject: [PATCH] cy8mrln-palmpre: New plugin for the Palm Pre's Touchscreen --- configure.ac | 1 + plugins/Makefile.am | 12 ++- plugins/cy8mrln-palmpre.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/plugins.h | 1 + src/ts_load_module.c | 3 + 5 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 plugins/cy8mrln-palmpre.c diff --git a/configure.ac b/configure.ac index 63f5af1..9ab9654 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,7 @@ TSLIB_CHECK_MODULE([pthres], [yes], [Enable building of pthres filter]) # hardware access modules TSLIB_CHECK_MODULE([ucb1x00], [yes], [Enable building of ucb1x00 raw module (UCB1x00 support)]) +TSLIB_CHECK_MODULE([cy8mrln-palmpre], [no], [Enable building of cy8mrln-palmpre raw module]) TSLIB_CHECK_MODULE([corgi], [yes], [Enable building of corgi raw module (Sharp Zaurus sl-c7x0 support)]) TSLIB_CHECK_MODULE([collie], [yes], [Enable building of collie raw module (Sharp Zaurus sl-5500/5000d support)]) TSLIB_CHECK_MODULE([h3600], [yes], [Enable building of h3600 raw module (HP iPaq H3600 support)]) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index a73971d..ca31993 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -97,6 +97,12 @@ else H2200_LINEAR_MODULE = endif +if ENABLE_CY8MRLN_PALMPRE_MODULE +CY8MRLN_PALMPRE_MODULE = cy8mrln_palmpre.la +else +CY8MRLN_PALMPRE_MODULE = +endif + pluginexec_LTLIBRARIES = \ $(LINEAR_MODULE) \ $(DEJITTER_MODULE) \ @@ -110,7 +116,8 @@ pluginexec_LTLIBRARIES = \ $(ARCTIC2_MODULE) \ $(TATUNG_MODULE) \ $(H2200_LINEAR_MODULE) \ - $(INPUT_MODULE) + $(INPUT_MODULE) \ + $(CY8MRLN_PALMPRE_MODULE) variance_la_SOURCES = variance.c variance_la_LDFLAGS = -module $(LTVSN) @@ -156,3 +163,6 @@ input_la_LIBADD = $(top_builddir)/src/libts.la linear_h2200_la_SOURCES = linear-h2200.c linear_h2200_la_LDFLAGS = -module $(LTVSN) + +cy8mrln_palmpre_la_SOURCES = cy8mrln-palmpre.c +cy8mrln_palmpre_la_LDFLAGS = -module $(LTVSN) diff --git a/plugins/cy8mrln-palmpre.c b/plugins/cy8mrln-palmpre.c new file mode 100644 index 0000000..b89965b --- /dev/null +++ b/plugins/cy8mrln-palmpre.c @@ -0,0 +1,242 @@ +/* + * tslib/plugins/cy8mrln-palmpre.c + * + * Copyright (C) 2010 Frederik Sdun + * Thomas Zimmermann + * + * + * This file is placed under the LGPL. Please see the file + * COPYING for more details. + * + * + * Pluging for the cy8mrln touchscreen with the Firmware used on the Palm Pre + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "tslib-private.h" +#include "tslib-filter.h" + +struct cy8mrln_palmpre_input +{ + uint16_t n_r; + uint16_t values[7][11]; + uint16_t ffff; //seperator? always ff + uint8_t seq_nr1; //incremented if seq_nr0 = scanrate + uint16_t seq_nr2; //incremeted if seq_nr1 = 255 + uint8_t unknown[4]; + uint8_t seq_nr0; //incremented. 0- scanrate + uint8_t null; //\0 +}__attribute__((packed)); + +struct tslib_cy8mrln_palmpre +{ + struct tslib_module_info module; + uint16_t nulls[7][11]; +}; + +static int scanrate = 60; +static int verbose = 1; +static int wot_threshold = 22; +static int sleepmode = CY8MRLN_ON_STATE; +static int wot_scanrate = WOT_SCANRATE_512HZ; +static int timestamp_mode = 1; + +static int +cy8mrln_palmpre_set_scanrate(struct tsdev* dev, int rate) +{ + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_SCANRATE,&rate) < 0) + return -1; + scanrate = rate; + return 0; +} + +static int +cy8mrln_palmpre_set_verbose(struct tsdev* dev, int v) +{ + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_VERBOSE_MODE,&v) < 0) + return -1; + verbose = v; + return 0; +} + +static int +cy8mrln_palmpre_set_sleepmode(struct tsdev* dev, int mode) +{ + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_SLEEPMODE,&mode) < 0) + return -1; + sleepmode = mode; + return 0; +} + +static int +cy8mrln_palmpre_set_wot_scanrate(struct tsdev* dev, int rate) +{ + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_WOT_SCANRATE,&rate) < 0) + return -1; + wot_scanrate = rate; + return 0; +} + +static int +cy8mrln_palmpre_set_wot_threshold(struct tsdev* dev, int v) +{ + if(v < WOT_THRESHOLD_MIN || v > WOT_THRESHOLD_MAX) + return -1; + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_WOT_THRESHOLD,&v) < 0) + return -1; + wot_threshold = v; + return 0; +} + +static int +cy8mrln_palmpre_set_timestamp_mode(struct tsdev* dev, int v) +{ + v = v ? 1 : 0; + if(ioctl(dev->fd,CY8MRLN_IOCTL_SET_TIMESTAMP_MODE,&v) < 0) + return -1; + timestamp_mode = v; + return 0; +} + +static int +parse_scanrate(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long rate = strtoul(str, NULL, 0); + + if(rate == ULONG_MAX && errno == ERANGE) + return -1; + + return cy8mrln_palmpre_set_scanrate(i->module.dev, scanrate); +} + +static int +parse_verbose(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long v = strtoul(str, NULL, 0); + + if(v == ULONG_MAX && errno == ERANGE) + return -1; + + return cy8mrln_palmpre_set_verbose(i->module.dev, scanrate); +} + +static int +parse_wot_scanrate(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long rate = strtoul(str, NULL, 0); + + return cy8mrln_palmpre_set_wot_scanrate(i->module.dev, rate); +} + +static int +parse_wot_threshold(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long threshold = strtoul(str, NULL, 0); + + return cy8mrln_palmpre_set_wot_threshold(i->module.dev, threshold); +} + +static int +parse_sleepmode(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long sleep = strtoul(str, NULL, 0); + + return cy8mrln_palmpre_set_sleepmode(i->module.dev, sleep); + return 0; +} + +static int +parse_timestamp_mode(struct tslib_module_info *info, char *str, void *data) +{ + (void)data; + struct tslib_cy8mrln_palmpre *i = (struct tslib_cy8mrln_palmpre*) info; + unsigned long sleep = strtoul(str, NULL, 0); + + return cy8mrln_palmpre_set_sleepmode(i->module.dev, sleep); + return 0; +} + +static const struct tslib_vars raw_vars[] = +{ + { "scanrate", NULL, parse_scanrate}, + { "verbose", NULL, parse_verbose}, + { "wot_scanrate", NULL, parse_wot_scanrate}, + { "wot_threshold", NULL, parse_wot_threshold}, + { "sleepmode", NULL, parse_sleepmode}, + { "timestamp_mode", NULL, parse_timestamp_mode} +}; + +#define NR_VARS (sizeof(raw_vars) / sizeof(raw_vars[0])) + +static int +cy8mrln_palmpre_read(struct tslib_module_info *info, struct ts_sample *samp, int nr) +{ + return 0; +} + +static int +cy8mrln_palmpre_fini(struct tslib_module_info *inf) +{ + return 0; +} + + +static const struct tslib_ops cy8mrln_palmpre_ops = +{ + .read = cy8mrln_palmpre_read, + .fini = cy8mrln_palmpre_fini, +}; + +TSAPI struct tslib_module_info *cy8mrln_palmpre_mod_init(struct tsdev *dev, const char *params) +{ + struct tslib_cy8mrln_palmpre *info; + struct cy8mrln_palmpre_input input; + + info = malloc(sizeof(struct tslib_cy8mrln_palmpre)); + if(info == NULL) + return NULL; + info->module.ops = &cy8mrln_palmpre_ops; + + cy8mrln_palmpre_set_verbose(dev,verbose); + cy8mrln_palmpre_set_scanrate(dev,scanrate); + cy8mrln_palmpre_set_timestamp_mode(dev,timestamp_mode); + cy8mrln_palmpre_set_sleepmode(dev,sleepmode); + cy8mrln_palmpre_set_wot_scanrate(dev,wot_scanrate); + cy8mrln_palmpre_set_wot_threshold(dev,wot_threshold); + + if (tslib_parse_vars(&info->module, raw_vars, NR_VARS, params)) { + free(info); + return NULL; + } + + read(dev->fd, &input, sizeof(input)); + + memcpy(info->nulls, input.values, 7*11*sizeof(uint16_t)); + + return &(info->module); +} +#ifndef TSLIB_STATIC_CY8MRLN_MODULE + TSLIB_MODULE_INIT(cy8mrln_palmpre_mod_init); +#endif diff --git a/plugins/plugins.h b/plugins/plugins.h index 4bba49c..873aba5 100644 --- a/plugins/plugins.h +++ b/plugins/plugins.h @@ -15,3 +15,4 @@ TSLIB_DECLARE_MODULE(mk712); TSLIB_DECLARE_MODULE(arctic2); TSLIB_DECLARE_MODULE(tatung); TSLIB_DECLARE_MODULE(input); +TSLIB_DECLARE_MODULE(cy8mrln_palmpre); diff --git a/src/ts_load_module.c b/src/ts_load_module.c index fa75d9e..c0e9f71 100644 --- a/src/ts_load_module.c +++ b/src/ts_load_module.c @@ -38,6 +38,9 @@ static struct { #ifdef TSLIB_STATIC_CORGI_MODULE { "corgi", corgi_mod_init }, #endif +#ifdef TSLIB_CY8MRLN_PALMPRE_MODULE + { "cy8mrln_palmpre", cy8mrln_palmpre_mod_init }, +#endif #ifdef TSLIB_STATIC_DEJITTER_MODULE { "dejitter", dejitter_mod_init }, #endif -- 2.11.0