From 4583da1ad81b59b2a8cd2ae51c32b1bc8d32f1c4 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 15 Jun 2010 19:40:34 +0200 Subject: refactor: Generate code for ABS_MT mapping Use the kernel-provided list MT_SLOT_ABS_EVENTS to generate code mappings between ABS_MT space and MT space. This patch adds the program mapgen that does the mapping, and adds two include files generated with it. Signed-off-by: Henrik Rydberg --- Makefile | 1 + include/abs2mt.h | 39 ++++++++++++++++++++++++++++++++ include/mtbit.h | 14 ++++++++++++ mtdev/mapgen.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 include/abs2mt.h create mode 100644 include/mtbit.h create mode 100644 mtdev/mapgen.c diff --git a/Makefile b/Makefile index f364845..1ed5758 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ o_src = hwstate mtstate memory mtouch gestures o_driver= multitouch TARGETS += match/test +TARGETS += mtdev/mapgen TARGETS += src/test OBJECTS = $(addsuffix .o,\ diff --git a/include/abs2mt.h b/include/abs2mt.h new file mode 100644 index 0000000..6021d8d --- /dev/null +++ b/include/abs2mt.h @@ -0,0 +1,39 @@ +/* generated by mapgen - do not edit */ + +#ifndef ABS2MT_H +#define ABS2MT_H + +#include "common.h" + +static const unsigned int map_abs2mt[ABS_CNT] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, + 0x0009, 0x000a, 0x000b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, +}; + +static const unsigned int map_mt2abs[MT_ABS_SIZE] = { + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, + 0x0038, 0x0039, 0x003a, +}; + +static inline int has_abs2mt(unsigned int code) +{ + return map_abs2mt[code]; +} + +static inline unsigned int abs2mt(unsigned int code) +{ + return map_abs2mt[code] - 1; +} + +static inline unsigned int mt2abs(unsigned int mtcode) +{ + return map_mt2abs[mtcode]; +} + +#endif diff --git a/include/mtbit.h b/include/mtbit.h new file mode 100644 index 0000000..2c4dacb --- /dev/null +++ b/include/mtbit.h @@ -0,0 +1,14 @@ +/* generated by mapgen - do not edit */ + +#ifndef MTBIT_H +#define MTBIT_H + +#define BIT_TRACKING_ID 9 +#define BIT_POSITION_X 5 +#define BIT_POSITION_Y 6 +#define BIT_TOUCH_MAJOR 0 +#define BIT_TOUCH_MINOR 1 +#define BIT_WIDTH_MAJOR 2 +#define BIT_WIDTH_MINOR 3 + +#endif diff --git a/mtdev/mapgen.c b/mtdev/mapgen.c new file mode 100644 index 0000000..efb3524 --- /dev/null +++ b/mtdev/mapgen.c @@ -0,0 +1,69 @@ +/*************************************************************************** + * + * Multitouch X driver + * Copyright (C) 2008 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + **************************************************************************/ + +#include +#include +#include + +#define BIT_DEF(name) \ + printf("#define BIT_"#name" %d\n", \ + cabs2mt[ABS_MT_##name] - 1) + +static unsigned int cabs2mt[ABS_CNT]; +static unsigned int cmt2abs[MT_ABS_SIZE]; + +void init_caps() +{ + static const int init_abs_map[MT_ABS_SIZE] = MT_SLOT_ABS_EVENTS; + int i; + for (i = 0; i < MT_ABS_SIZE; i++) { + cabs2mt[init_abs_map[i]] = i + 1; + cmt2abs[i] = init_abs_map[i]; + } +} + +static inline const char *newln(int i, int n) +{ + return i == n - 1 || i % 8 == 7 ? "\n" : ""; +} + +int main(int argc, char *argv[]) +{ + int i; + init_caps(); + printf("static const unsigned int map_abs2mt[ABS_CNT] = {\n"); + for (i = 0; i < ABS_CNT; i++) + printf(" 0x%04x,%s", cabs2mt[i], newln(i, ABS_CNT)); + printf("};\n\n"); + printf("static const unsigned int map_mt2abs[MT_ABS_SIZE] = {\n"); + for (i = 0; i < MT_ABS_SIZE; i++) + printf(" 0x%04x,%s", cmt2abs[i], newln(i, MT_ABS_SIZE)); + printf("};\n\n"); + BIT_DEF(TRACKING_ID); + BIT_DEF(POSITION_X); + BIT_DEF(POSITION_Y); + BIT_DEF(TOUCH_MAJOR); + BIT_DEF(TOUCH_MINOR); + BIT_DEF(WIDTH_MAJOR); + BIT_DEF(WIDTH_MINOR); + printf("\n"); + return 0; +} -- cgit v1.2.3