diff options
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr1/mcs5000-ypr1.c')
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr1/mcs5000-ypr1.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr1/mcs5000-ypr1.c b/firmware/target/hosted/samsungypr/ypr1/mcs5000-ypr1.c new file mode 100644 index 0000000000..bfd9922768 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr1/mcs5000-ypr1.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (c) 2013 Lorenzo Miori | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <unistd.h> | ||
22 | #include <fcntl.h> | ||
23 | #include "sys/ioctl.h" | ||
24 | |||
25 | #include "mcs5000.h" | ||
26 | #include "ioctl-ypr1.h" | ||
27 | |||
28 | /* TODO Settings like hand and sensitivity will be lost when shutting device off!! */ | ||
29 | |||
30 | static int mcs5000_dev = -1; | ||
31 | static int mcs5000_hand_setting = RIGHT_HAND; | ||
32 | |||
33 | void mcs5000_init(void) | ||
34 | { | ||
35 | mcs5000_dev = open("/dev/r1Touch", O_RDONLY); | ||
36 | } | ||
37 | |||
38 | void mcs5000_close(void) | ||
39 | { | ||
40 | if (mcs5000_dev > 0) | ||
41 | close(mcs5000_dev); | ||
42 | } | ||
43 | |||
44 | void mcs5000_power(void) | ||
45 | { | ||
46 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_ON); | ||
47 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_IDLE); | ||
48 | mcs5000_set_hand(mcs5000_hand_setting); | ||
49 | } | ||
50 | |||
51 | void mcs5000_shutdown(void) | ||
52 | { | ||
53 | /* save setting before shutting down the device */ | ||
54 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_FLUSH); | ||
55 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_RESET); | ||
56 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_OFF); | ||
57 | } | ||
58 | |||
59 | void mcs5000_set_hand(int hand) | ||
60 | { | ||
61 | switch (hand) | ||
62 | { | ||
63 | case RIGHT_HAND: | ||
64 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_RIGHTHAND); | ||
65 | break; | ||
66 | case LEFT_HAND: | ||
67 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_LEFTHAND); | ||
68 | break; | ||
69 | default: | ||
70 | break; | ||
71 | } | ||
72 | mcs5000_hand_setting = hand; | ||
73 | } | ||
74 | |||
75 | void mcs5000_set_sensitivity(int level) | ||
76 | { | ||
77 | ioctl(mcs5000_dev, DEV_CTRL_TOUCH_SET_SENSE, &level); | ||
78 | } | ||
79 | |||
80 | int mcs5000_read(struct mcs5000_raw_data *touchData) | ||
81 | { | ||
82 | /* work around GCC bug: aligned attribute is not applied to automatic | ||
83 | * variables, and apparently this structure has a large alignment requirement | ||
84 | * (if it's only automatic with implicit 8-byte alignment then the | ||
85 | * touchscreen misbehaves). The bug seems fixed in gcc 4.6.x | ||
86 | * See http://http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16660 | ||
87 | * Also: packet and aligned attributes don't really work together so | ||
88 | * the aligned attribute cannot be attached to the struct declaration */ | ||
89 | static struct mcs5000_raw_data touchpad_data __attribute__((aligned(256))); | ||
90 | ssize_t ret; | ||
91 | ret = read(mcs5000_dev, &touchpad_data, sizeof(struct mcs5000_raw_data)); | ||
92 | *touchData = touchpad_data; | ||
93 | return ret; | ||
94 | } | ||