diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 14:03:42 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 14:03:42 +0100 |
| commit | a773c79d6d767ddfe574ad513ab0276bdd13a717 (patch) | |
| tree | 8d879fe396dab810bf5632c9777c3931c08eb396 /src | |
| parent | 030a3c8a38a81ea882fa0a3b0bfce61ded50a20d (diff) | |
Driver stages in place - should one support multiple
device instances by moving the private alloc to init/close?
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/capabilities.c | 4 | ||||
| -rw-r--r-- | src/capabilities.h | 3 | ||||
| -rw-r--r-- | src/common.h | 1 | ||||
| -rw-r--r-- | src/hwdata.c | 90 | ||||
| -rw-r--r-- | src/hwdata.h | 34 | ||||
| -rw-r--r-- | src/mtouch.c | 22 | ||||
| -rw-r--r-- | src/mtouch.h | 21 | ||||
| -rw-r--r-- | src/multitouch.c | 123 |
8 files changed, 273 insertions, 25 deletions
diff --git a/src/capabilities.c b/src/capabilities.c index 513a254..d0a157b 100644 --- a/src/capabilities.c +++ b/src/capabilities.c | |||
| @@ -62,11 +62,13 @@ int read_capabilities(struct Capabilities *cap, int fd) | |||
| 62 | SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); | 62 | SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); |
| 63 | SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); | 63 | SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); |
| 64 | SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); | 64 | SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); |
| 65 | |||
| 66 | return 0; | ||
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | //////////////////////////////////////////////////////// | 69 | //////////////////////////////////////////////////////// |
| 68 | 70 | ||
| 69 | int output_capabilities(const struct Capabilities *cap) | 71 | void output_capabilities(const struct Capabilities *cap) |
| 70 | { | 72 | { |
| 71 | char line[1024]; | 73 | char line[1024]; |
| 72 | memset(line, 0, sizeof(line)); | 74 | memset(line, 0, sizeof(line)); |
diff --git a/src/capabilities.h b/src/capabilities.h index 5cde963..cd00353 100644 --- a/src/capabilities.h +++ b/src/capabilities.h | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #define CAPABILITIES_H | 2 | #define CAPABILITIES_H |
| 3 | 3 | ||
| 4 | #include "common.h" | 4 | #include "common.h" |
| 5 | #include <linux/input.h> | ||
| 6 | 5 | ||
| 7 | //////////////////////////////////////////////////////// | 6 | //////////////////////////////////////////////////////// |
| 8 | 7 | ||
| @@ -25,7 +24,7 @@ struct Capabilities { | |||
| 25 | //////////////////////////////////////////////////////// | 24 | //////////////////////////////////////////////////////// |
| 26 | 25 | ||
| 27 | int read_capabilities(struct Capabilities *cap, int fd); | 26 | int read_capabilities(struct Capabilities *cap, int fd); |
| 28 | int output_capabilities(const struct Capabilities *cap); | 27 | void output_capabilities(const struct Capabilities *cap); |
| 29 | 28 | ||
| 30 | //////////////////////////////////////////////////////// | 29 | //////////////////////////////////////////////////////// |
| 31 | 30 | ||
diff --git a/src/common.h b/src/common.h index 7aabd7e..22cd9e9 100644 --- a/src/common.h +++ b/src/common.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <xf86.h> | 5 | #include <xf86.h> |
| 6 | #include <xf86_OSproc.h> | 6 | #include <xf86_OSproc.h> |
| 7 | #include <xf86Xinput.h> | 7 | #include <xf86Xinput.h> |
| 8 | #include <linux/input.h> | ||
| 8 | //#include <exevents.h> | 9 | //#include <exevents.h> |
| 9 | 10 | ||
| 10 | //////////////////////////////////////////////////////// | 11 | //////////////////////////////////////////////////////// |
diff --git a/src/hwdata.c b/src/hwdata.c new file mode 100644 index 0000000..212e860 --- /dev/null +++ b/src/hwdata.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | #include "hwdata.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | /******************************************************/ | ||
| 5 | |||
| 6 | static int parse_event(struct HWData *hw) | ||
| 7 | { | ||
| 8 | const struct input_event *ev = hw->event + hw->at++; | ||
| 9 | bool on = ev->value != 0; | ||
| 10 | switch (ev->type) { | ||
| 11 | case EV_SYN: | ||
| 12 | switch (ev->code) { | ||
| 13 | case SYN_REPORT: | ||
| 14 | return 0; | ||
| 15 | } | ||
| 16 | break; | ||
| 17 | case EV_KEY: | ||
| 18 | switch (ev->code) { | ||
| 19 | case BTN_LEFT: | ||
| 20 | hw->left = on; | ||
| 21 | break; | ||
| 22 | case BTN_MIDDLE: | ||
| 23 | hw->middle = on; | ||
| 24 | break; | ||
| 25 | case BTN_RIGHT: | ||
| 26 | hw->right = on; | ||
| 27 | break; | ||
| 28 | case BTN_MT_REPORT_PACKET: | ||
| 29 | if (on) | ||
| 30 | hw->nfinger = 0; | ||
| 31 | break; | ||
| 32 | case BTN_MT_REPORT_FINGER: | ||
| 33 | if (!on && hw->nfinger < DIM_FINGER) | ||
| 34 | hw->nfinger++; | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | break; | ||
| 38 | case EV_ABS: | ||
| 39 | switch (ev->code) { | ||
| 40 | case ABS_MT_TOUCH_MAJOR: | ||
| 41 | hw->finger[hw->nfinger].touch_major = ev->value; | ||
| 42 | break; | ||
| 43 | case ABS_MT_TOUCH_MINOR: | ||
| 44 | hw->finger[hw->nfinger].touch_minor = ev->value; | ||
| 45 | break; | ||
| 46 | case ABS_MT_WIDTH_MAJOR: | ||
| 47 | hw->finger[hw->nfinger].width_major = ev->value; | ||
| 48 | break; | ||
| 49 | case ABS_MT_WIDTH_MINOR: | ||
| 50 | hw->finger[hw->nfinger].width_minor = ev->value; | ||
| 51 | break; | ||
| 52 | case ABS_MT_ORIENTATION: | ||
| 53 | hw->finger[hw->nfinger].orientation = ev->value; | ||
| 54 | break; | ||
| 55 | case ABS_MT_POSITION_X: | ||
| 56 | hw->finger[hw->nfinger].position_x = ev->value; | ||
| 57 | break; | ||
| 58 | case ABS_MT_POSITION_Y: | ||
| 59 | hw->finger[hw->nfinger].position_y = ev->value; | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | break; | ||
| 63 | } | ||
| 64 | return -EAGAIN; | ||
| 65 | } | ||
| 66 | |||
| 67 | /******************************************************/ | ||
| 68 | |||
| 69 | int read_hwdata(struct HWData *hw, int fd) | ||
| 70 | { | ||
| 71 | int n; | ||
| 72 | do { | ||
| 73 | while (hw->at < hw->nev) | ||
| 74 | if (!parse_event(hw)) | ||
| 75 | return 0; | ||
| 76 | n = read(fd, hw->event, sizeof(hw->event)); | ||
| 77 | hw->at = 0; | ||
| 78 | hw->nev = n / sizeof(struct input_event); | ||
| 79 | xf86Msg(X_INFO, "multitouch: read: %d %d\n", n, hw->nev); | ||
| 80 | } while (n > 0); | ||
| 81 | return -EIO; | ||
| 82 | }; | ||
| 83 | |||
| 84 | /******************************************************/ | ||
| 85 | |||
| 86 | void output_hwdata(const struct HWData *hw) | ||
| 87 | { | ||
| 88 | } | ||
| 89 | |||
| 90 | /******************************************************/ | ||
diff --git a/src/hwdata.h b/src/hwdata.h new file mode 100644 index 0000000..beb98b0 --- /dev/null +++ b/src/hwdata.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #ifndef HWDATA_H | ||
| 2 | #define HWDATA_H | ||
| 3 | |||
| 4 | #include "common.h" | ||
| 5 | |||
| 6 | #define DIM_EVENTS 64 | ||
| 7 | #define DIM_FINGER 16 | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////// | ||
| 10 | |||
| 11 | struct FingerData { | ||
| 12 | int touch_major, touch_minor; | ||
| 13 | int width_major, width_minor; | ||
| 14 | int orientation; | ||
| 15 | int position_x, position_y; | ||
| 16 | }; | ||
| 17 | |||
| 18 | //////////////////////////////////////////////////////// | ||
| 19 | |||
| 20 | struct HWData { | ||
| 21 | struct input_event event[DIM_EVENTS]; | ||
| 22 | struct FingerData finger[DIM_FINGER]; | ||
| 23 | int at, nev, nfinger; | ||
| 24 | bool left, middle, right; | ||
| 25 | }; | ||
| 26 | |||
| 27 | //////////////////////////////////////////////////////// | ||
| 28 | |||
| 29 | int read_hwdata(struct HWData *hw, int fd); | ||
| 30 | void output_hwdata(const struct HWData *hw); | ||
| 31 | |||
| 32 | //////////////////////////////////////////////////////// | ||
| 33 | |||
| 34 | #endif | ||
diff --git a/src/mtouch.c b/src/mtouch.c new file mode 100644 index 0000000..2d05921 --- /dev/null +++ b/src/mtouch.c | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #include "mtouch.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | /******************************************************/ | ||
| 5 | |||
| 6 | int configure_mtouch(struct MTouch *mt, int fd) | ||
| 7 | { | ||
| 8 | int rc = read_capabilities(&mt->caps, fd); | ||
| 9 | if (rc < 0) | ||
| 10 | return rc; | ||
| 11 | output_capabilities(&mt->caps); | ||
| 12 | return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | /******************************************************/ | ||
| 16 | |||
| 17 | int init_mtouch(struct MTouch *mt) | ||
| 18 | { | ||
| 19 | return 0; | ||
| 20 | } | ||
| 21 | |||
| 22 | /******************************************************/ | ||
diff --git a/src/mtouch.h b/src/mtouch.h new file mode 100644 index 0000000..a945162 --- /dev/null +++ b/src/mtouch.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #ifndef MTOUCH_H | ||
| 2 | #define MTOUCH_H | ||
| 3 | |||
| 4 | #include "capabilities.h" | ||
| 5 | #include "hwdata.h" | ||
| 6 | |||
| 7 | //////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | struct MTouch { | ||
| 10 | struct Capabilities caps; | ||
| 11 | struct HWData hw; | ||
| 12 | }; | ||
| 13 | |||
| 14 | //////////////////////////////////////////////////////// | ||
| 15 | |||
| 16 | int configure_mtouch(struct MTouch *mt, int fd); | ||
| 17 | int init_mtouch(struct MTouch *mt); | ||
| 18 | |||
| 19 | //////////////////////////////////////////////////////// | ||
| 20 | |||
| 21 | #endif | ||
diff --git a/src/multitouch.c b/src/multitouch.c index 6818e7c..9fb6d82 100644 --- a/src/multitouch.c +++ b/src/multitouch.c | |||
| @@ -21,47 +21,125 @@ | |||
| 21 | * | 21 | * |
| 22 | **************************************************************************/ | 22 | **************************************************************************/ |
| 23 | 23 | ||
| 24 | #include "capabilities.h" | 24 | #include "mtouch.h" |
| 25 | |||
| 26 | //////////////////////////////////////////////////////////////////////////// | ||
| 27 | |||
| 28 | static int device_init(LocalDevicePtr local) | ||
| 29 | { | ||
| 30 | struct MTouch *mt = local->private; | ||
| 31 | local->fd = xf86OpenSerial(local->options); | ||
| 32 | if (local->fd < 0) { | ||
| 33 | xf86Msg(X_ERROR, "multitouch: cannot configure device\n"); | ||
| 34 | return local->fd; | ||
| 35 | } | ||
| 36 | if (configure_mtouch(mt, local->fd)) | ||
| 37 | return -1; | ||
| 38 | xf86CloseSerial(local->fd); | ||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | //////////////////////////////////////////////////////////////////////////// | ||
| 43 | |||
| 44 | static int device_on(LocalDevicePtr local) | ||
| 45 | { | ||
| 46 | struct MTouch *mt = local->private; | ||
| 47 | local->fd = xf86OpenSerial(local->options); | ||
| 48 | if (local->fd < 0) { | ||
| 49 | xf86Msg(X_ERROR, "multitouch: cannot open device\n"); | ||
| 50 | return local->fd; | ||
| 51 | } | ||
| 52 | if (init_mtouch(mt)) | ||
| 53 | return -1; | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | //////////////////////////////////////////////////////////////////////////// | ||
| 58 | |||
| 59 | static void device_off(LocalDevicePtr local) | ||
| 60 | { | ||
| 61 | if(local->fd >= 0) | ||
| 62 | xf86CloseSerial(local->fd); | ||
| 63 | } | ||
| 64 | |||
| 65 | //////////////////////////////////////////////////////////////////////////// | ||
| 66 | |||
| 67 | static void device_close(LocalDevicePtr local) | ||
| 68 | { | ||
| 69 | } | ||
| 70 | |||
| 71 | //////////////////////////////////////////////////////////////////////////// | ||
| 72 | |||
| 73 | /* called for each full received packet from the touchpad */ | ||
| 74 | static void read_input(LocalDevicePtr local) | ||
| 75 | { | ||
| 76 | struct MTouch *mt = local->private; | ||
| 77 | |||
| 78 | xf86Msg(X_INFO, "read_input called\n"); | ||
| 79 | |||
| 80 | if (local->fd >= 0) { | ||
| 81 | while (!read_hwdata(&mt->hw, local->fd)) { | ||
| 82 | // do all the good stuff here | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | //////////////////////////////////////////////////////////////////////////// | ||
| 88 | |||
| 89 | static Bool device_control(DeviceIntPtr dev, int mode) | ||
| 90 | { | ||
| 91 | LocalDevicePtr local = dev->public.devicePrivate; | ||
| 92 | switch (mode) { | ||
| 93 | case DEVICE_INIT: | ||
| 94 | xf86Msg(X_INFO, "device control: init\n"); | ||
| 95 | if (device_init(local)) | ||
| 96 | return !Success; | ||
| 97 | return Success; | ||
| 98 | case DEVICE_ON: | ||
| 99 | xf86Msg(X_INFO, "device control: on\n"); | ||
| 100 | if (device_on(local)) | ||
| 101 | return !Success; | ||
| 102 | return Success; | ||
| 103 | case DEVICE_OFF: | ||
| 104 | xf86Msg(X_INFO, "device control: off\n"); | ||
| 105 | device_off(local); | ||
| 106 | return Success; | ||
| 107 | case DEVICE_CLOSE: | ||
| 108 | xf86Msg(X_INFO, "device control: close\n"); | ||
| 109 | device_close(local); | ||
| 110 | return Success; | ||
| 111 | default: | ||
| 112 | xf86Msg(X_INFO, "device control: default\n"); | ||
| 113 | return BadValue; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 25 | 117 | ||
| 26 | //////////////////////////////////////////////////////////////////////////// | 118 | //////////////////////////////////////////////////////////////////////////// |
| 27 | 119 | ||
| 28 | static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) | 120 | static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) |
| 29 | { | 121 | { |
| 122 | struct MTouch *mt; | ||
| 30 | InputInfoPtr local = xf86AllocateInput(drv, 0); | 123 | InputInfoPtr local = xf86AllocateInput(drv, 0); |
| 31 | if (!local) | 124 | if (!local) |
| 32 | goto error; | 125 | goto error; |
| 126 | mt = xcalloc(1, sizeof(struct MTouch)); | ||
| 127 | if (!mt) | ||
| 128 | goto error; | ||
| 33 | 129 | ||
| 34 | local->name = dev->identifier; | 130 | local->name = dev->identifier; |
| 35 | local->type_name = XI_TOUCHPAD; | 131 | local->type_name = XI_TOUCHPAD; |
| 36 | local->device_control = 0;//DeviceControl; | 132 | local->device_control = device_control; |
| 37 | local->read_input = 0;//ReadInput; | 133 | local->read_input = read_input; |
| 38 | local->control_proc = 0;//ControlProc; | 134 | local->private = mt; |
| 39 | local->close_proc = 0;//CloseProc; | ||
| 40 | local->switch_mode = 0;//SwitchMode; | ||
| 41 | local->conversion_proc = 0;//ConvertProc; | ||
| 42 | local->reverse_conversion_proc = NULL; | ||
| 43 | local->dev = NULL; | ||
| 44 | local->private = 0;//priv; | ||
| 45 | local->private_flags = 0; | 135 | local->private_flags = 0; |
| 46 | local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; | 136 | local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; |
| 47 | local->conf_idev = dev; | 137 | local->conf_idev = dev; |
| 48 | //local->motion_history_proc = xf86GetMotionEvents; | ||
| 49 | //local->history_size = 0; | ||
| 50 | local->always_core_feedback = 0; | 138 | local->always_core_feedback = 0; |
| 51 | 139 | ||
| 52 | xf86CollectInputOptions(local, NULL, NULL); | 140 | xf86CollectInputOptions(local, NULL, NULL); |
| 53 | xf86OptionListReport(local->options); | 141 | xf86OptionListReport(local->options); |
| 54 | 142 | ||
| 55 | local->fd = xf86OpenSerial(local->options); | ||
| 56 | if (local->fd < 0) { | ||
| 57 | xf86Msg(X_ERROR, "multitouch: cannot open device\n"); | ||
| 58 | goto error; | ||
| 59 | } | ||
| 60 | struct Capabilities cap; | ||
| 61 | read_capabilities(&cap, local->fd); | ||
| 62 | output_capabilities(&cap); | ||
| 63 | xf86CloseSerial(local->fd); | ||
| 64 | local->fd = -1; | ||
| 65 | local->flags |= XI86_CONFIGURED; | 143 | local->flags |= XI86_CONFIGURED; |
| 66 | error: | 144 | error: |
| 67 | return local; | 145 | return local; |
| @@ -69,6 +147,7 @@ static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) | |||
| 69 | 147 | ||
| 70 | static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags) | 148 | static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags) |
| 71 | { | 149 | { |
| 150 | xfree(local->private); | ||
| 72 | xf86DeleteInput(local, 0); | 151 | xf86DeleteInput(local, 0); |
| 73 | } | 152 | } |
| 74 | 153 | ||
