summaryrefslogtreecommitdiff
path: root/src/tc1kpen.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tc1kpen.h')
-rw-r--r--src/tc1kpen.h268
1 files changed, 268 insertions, 0 deletions
diff --git a/src/tc1kpen.h b/src/tc1kpen.h
new file mode 100644
index 0000000..bf0bc28
--- /dev/null
+++ b/src/tc1kpen.h
@@ -0,0 +1,268 @@
+#ifndef TC1KPEN_H
+#define TC1KPEN_H
+
+/*
+ * Copyright 2007 Vaclav Krpec
+ */
+
+/*
+ * This file is part of tc1kpen X11 input driver.
+ *
+ * tc1kpen 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * tc1kpen 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 tc1kpen. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+
+/*
+ * MACROS
+ */
+
+/*
+ * Sanity checks
+ */
+
+#ifndef DRIVER_NAME
+#error "DRIVER_NAME not defined!"
+#endif
+
+#ifndef PACKAGE_VERSION_MAJOR
+#error "PACKAGE_VERSION_MAJOR not defined!"
+#endif
+#ifndef PACKAGE_VERSION_MINOR
+#error "PACKAGE_VERSION_MINOR not defined!"
+#endif
+#ifndef PACKAGE_VERSION_PATCHLEVEL
+#error "PACKAGE_VERSION_PATCHLEVEL not defined!"
+#endif
+
+
+/*
+ * Utility macros
+ */
+
+/* Absolute value */
+#define ABS(a) ((a) < 0 ? -(a) : (a))
+
+/*
+ * Logical XOR
+ *
+ * This is a little trick in C
+ * as it doesn't have logical XOR
+ * Note that a XOR b == a' XOR b'
+ * and we can use ! to make 0x00 or 0x01
+ * out of everything...
+ */
+#define XOR(a, b) (!(a) ^ !(b))
+
+/* Stringifization */
+#define STR0(a) #a
+#define STR(a) STR0(a)
+
+/* Concatenation */
+#define CONC0(a, b) a ## b
+#define CONC(a, b) CONC0(a, b)
+
+/* Bit mask */
+#define BIT(index) (0x1 << (index))
+
+/* Sign bit mask */
+#define SIGN(type) BIT(sizeof(type) * 8 - 1)
+
+/* Array length */
+#define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
+
+
+/*
+ * Driver ID version and full-text name
+ */
+
+#define DRIVER_ID STR(DRIVER_NAME)
+
+#define DRIVER_VERSION CONC(CONC(PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR), PACKAGE_VERSION_PATCHLEVEL)
+#define DRIVER_VERSION_STR STR(PACKAGE_VERSION_MAJOR) "." STR(PACKAGE_VERSION_MINOR) "." STR(PACKAGE_VERSION_PATCHLEVEL)
+
+#ifndef DRIVER_NAME_FULL
+#define DRIVER_NAME_FULL "TC1000 Pen"
+#endif
+
+
+/*
+ * Driver module data identifier
+ */
+
+#define DRIVER_MODULE_DATA0(id) id ## ModuleData
+#define DRIVER_MODULE_DATA1(id) DRIVER_MODULE_DATA0(id)
+#define DRIVER_MODULE_DATA DRIVER_MODULE_DATA1(DRIVER_NAME)
+
+
+/*
+ * Messages
+ */
+
+#define message(c, f, ...) xf86Msg(c, f "\n", ##__VA_ARGS__)
+
+#define messageVerb(c, f, ...) message(c, DRIVER_ID " v" DRIVER_VERSION_STR \
+ " in %s() at " __FILE__ ":%d " \
+ f, __func__, __LINE__, ##__VA_ARGS__)
+
+#define messageSmpl(c, f, ...) message(c, DRIVER_NAME_FULL ": " f, ##__VA_ARGS__)
+
+#define config(...) messageSmpl(X_CONFIG, __VA_ARGS__)
+#define info(...) messageSmpl(X_INFO, __VA_ARGS__)
+#define warning(...) messageSmpl(X_WARNING, __VA_ARGS__)
+#define error(...) messageSmpl(X_ERROR, __VA_ARGS__)
+
+
+/*
+ * Debug messages
+ */
+
+#ifdef DEBUG
+#ifndef DEBUG_LEVEL
+#define DEBUG_LEVEL 99
+#endif
+
+#define debug(lv, ...) if ((lv) <= DEBUG_LEVEL) \
+ messageVerb(X_ERROR, "DEBUG[" #lv "] " __VA_ARGS__)
+
+#define debugCond(cond, ...) if (cond) debug(__VA_ARGS__)
+#else
+#define debug(lv, ...)
+#define debugCond(cond, ...)
+#endif
+
+
+
+/*
+ * Error codes
+ */
+
+#define INTERNAL_ERROR FirstExtensionError
+#define INIT_FAILED (FirstExtensionError + 1)
+#define ON_FAILED (FirstExtensionError + 2)
+#define OFF_FAILED (FirstExtensionError + 3)
+#define CLOSE_FAILED (FirstExtensionError + 4)
+
+
+/*
+ * Protocol constants
+ */
+
+#define PHASING_BIT_INDEX 7
+#define STATUS_BIT_INDEX 6
+#define PROXIMITY_BIT_INDEX 5
+#define TIP_BIT_INDEX 0
+#define BUTTON_BIT_INDEX 1
+
+#define PHASING_BIT BIT(PHASING_BIT_INDEX)
+#define STATUS_BIT BIT(STATUS_BIT_INDEX)
+#define PROXIMITY_BIT BIT(PROXIMITY_BIT_INDEX)
+#define TIP_BIT BIT(TIP_BIT_INDEX)
+#define BUTTON_BIT BIT(BUTTON_BIT_INDEX)
+
+#define PACKET_SIZE 5
+#define BUFFER_SIZE (PACKET_SIZE * 20)
+
+
+/*
+ * Configuration constants
+ */
+
+#define IS_ABSOLUTE 1
+
+#define PHYS_BUTTONS_NUMBER 2
+#define BUTTONS_NUMBER PHYS_BUTTONS_NUMBER + 1
+#define SIDE_BTNS_NUMBER 3
+
+#define MAX_BUTTONS (BUTTONS_NUMBER + SIDE_BTNS_NUMBER * BUTTONS_NUMBER)
+
+
+
+/*
+ * Data types
+ */
+
+/* Side button X area */
+typedef struct
+{
+ int l; /* lower X coord */
+ int h; /* higher X coord */
+} tc1kpen_sideBtnXArea;
+
+/* Pen button change resolver */
+typedef int tc1kpen_btnMode_chFunc( InputInfoPtr info,
+ int status, int buttons,
+ int side_btn, unsigned prox_cnt);
+
+/* Pen button mode record */
+typedef struct _tc1kpen_btnMode
+{
+ char *id; /* pen button mode ID */
+ char *name; /* pen button mode name */
+ char *desc; /* pen button mode description */
+ tc1kpen_btnMode_chFunc *func; /* pen button change resolver */
+ struct _tc1kpen_btnMode *next; /* next in list */
+} tc1kpen_btnMode;
+
+/* Device private record */
+typedef struct
+{
+ /* Configuration */
+ int btn_no; /* number of pen-supported buttons */
+ CARD8 btn_map[MAX_BUTTONS + 1]; /* pen buttons map */
+ char *btn_map_str; /* pen buttons map option string */
+ char *btn_modes_str; /* pen button modes str. */
+ int btn_mode_switch; /* pen button mode switch button */
+ int btn3emu_timeout; /* 3-buttons emulation mode timeout */
+
+ /* On-screen area */
+ int min_x; /* min X on-screen coord. */
+ int min_y; /* min Y on-screen coord. */
+ int max_x; /* max X on-screen coord. */
+ int max_y; /* max Y on-screen coord. */
+ int x_scr_range; /* max X - min X */
+ int y_scr_range; /* max Y - min Y */
+
+ /* Side buttons area */
+ int side_btns_min_y; /* side buttons area lower Y border */
+ int side_btns_size; /* side button size */
+ int side_btns_y; /* side buttons center Y coord */
+ int side_btns_1_x; /* side button 1 center X coord */
+ int side_btns_2_x; /* side button 2 center X coord */
+ int side_btns_3_x; /* side button 3 center X coord */
+ int side_btns_yl; /* side buttons lower Y coord */
+ int side_btns_yh; /* side buttons higher Y coord */
+ tc1kpen_sideBtnXArea side_btns_x[SIDE_BTNS_NUMBER];
+ /* side buttons X areas */
+ /* Coordinates transformation */
+ int inv_x; /* invert X axis flag */
+ int inv_y; /* invert Y axis flag */
+ int swap_xy; /* swap X and Y values flag */
+ char *rotate; /* rotate tablet */
+
+ /* Screen info */
+ int screen_no; /* screen number */
+
+ /* State info */
+ int x; /* current pen X position */
+ int y; /* current pen Y position */
+ tc1kpen_btnMode *btn_mode; /* current pen button mode */
+} tc1kpen_deviceRec, *tc1kpen_devicePtr;
+
+
+#endif