diff options
author | Lorenzo Miori <memoryS60@gmail.com> | 2013-09-10 22:48:34 +0200 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2014-02-05 09:56:21 +0100 |
commit | e876f4df6d240bd2e319b1e63be95a625f049a97 (patch) | |
tree | ce2fe1b24650e3be7a6cd2d346d29090a5422a8c /firmware/target/hosted/samsungypr/ypr1/button-ypr1.c | |
parent | b828b9d99bff2acc0e1f543f3176fd4b632cba68 (diff) | |
download | rockbox-e876f4df6d240bd2e319b1e63be95a625f049a97.tar.gz rockbox-e876f4df6d240bd2e319b1e63be95a625f049a97.zip |
Samsung YP-R1 target port
This is the basic port to the new target Samsung
YP-R1, which runs on a similar platform as YP-R0.
Port is usable, although there are still
some optimizations that have to be done.
Change-Id: If83a8e386369e413581753780c159026d9e41f04
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr1/button-ypr1.c')
-rw-r--r-- | firmware/target/hosted/samsungypr/ypr1/button-ypr1.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c b/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c new file mode 100644 index 0000000000..09891cfaf6 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $ | ||
9 | * | ||
10 | * Copyright (C) 2013 Lorenzo Miori | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "button.h" | ||
24 | #include "kernel.h" | ||
25 | #include "system.h" | ||
26 | #include "button-target.h" | ||
27 | |||
28 | #include <gpio-target.h> /* For headphones sense and buttons */ | ||
29 | #include "mcs5000.h" /* Touchscreen controller */ | ||
30 | #include "ioctl-ypr1.h" | ||
31 | |||
32 | enum { | ||
33 | STATE_UNKNOWN, | ||
34 | STATE_UP, | ||
35 | STATE_DOWN, | ||
36 | }; | ||
37 | |||
38 | static int last_x = 0; | ||
39 | static int last_y = 0; | ||
40 | static int last_touch_state = STATE_UNKNOWN; | ||
41 | |||
42 | int button_read_device(int *data) | ||
43 | { | ||
44 | int key = BUTTON_NONE; | ||
45 | int read_size; | ||
46 | struct mcs5000_raw_data touchpad_data; | ||
47 | |||
48 | /* Check for all the keys */ | ||
49 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_VOL_UP_KEY, 0, 0)) { | ||
50 | key |= BUTTON_VOL_UP; | ||
51 | } | ||
52 | if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_VOL_DOWN_KEY, 0, 0)) { | ||
53 | key |= BUTTON_VOL_DOWN; | ||
54 | } | ||
55 | if (gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_POWER_KEY, 0, 0)) { | ||
56 | key |= BUTTON_POWER; | ||
57 | } | ||
58 | |||
59 | read_size = mcs5000_read(&touchpad_data); | ||
60 | |||
61 | if (read_size == sizeof(struct mcs5000_raw_data)) { | ||
62 | /* Generate UP and DOWN events */ | ||
63 | if (touchpad_data.inputInfo & INPUT_TYPE_SINGLE) { | ||
64 | last_touch_state = STATE_DOWN; | ||
65 | } | ||
66 | else { | ||
67 | last_touch_state = STATE_UP; | ||
68 | } | ||
69 | /* Swap coordinates here */ | ||
70 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | ||
71 | last_x = (touchpad_data.yHigh << 8) | touchpad_data.yLow; | ||
72 | last_y = (touchpad_data.xHigh << 8) | touchpad_data.xLow; | ||
73 | #else | ||
74 | last_x = (touchpad_data.xHigh << 8) | touchpad_data.xLow; | ||
75 | last_y = (touchpad_data.yHigh << 8) | touchpad_data.yLow; | ||
76 | #endif | ||
77 | } | ||
78 | |||
79 | int tkey = touchscreen_to_pixels(last_x, last_y, data); | ||
80 | |||
81 | if (last_touch_state == STATE_DOWN) { | ||
82 | key |= tkey; | ||
83 | } | ||
84 | |||
85 | return key; | ||
86 | } | ||
87 | |||
88 | #ifndef HAS_BUTTON_HOLD | ||
89 | void touchscreen_enable_device(bool en) | ||
90 | { | ||
91 | if (en) { | ||
92 | mcs5000_power(); | ||
93 | } | ||
94 | else { | ||
95 | mcs5000_shutdown(); | ||
96 | } | ||
97 | } | ||
98 | #endif | ||
99 | |||
100 | bool headphones_inserted(void) | ||
101 | { | ||
102 | /* GPIO low - 0 - means headphones inserted */ | ||
103 | return !gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_HEADPHONE_SENSE, 0, 0); | ||
104 | } | ||
105 | |||
106 | void button_init_device(void) | ||
107 | { | ||
108 | /* Setup GPIO pin for headphone sense, copied from OF | ||
109 | * Pins for the other buttons are already set up by OF button module | ||
110 | */ | ||
111 | gpio_control(DEV_CTRL_GPIO_SET_MUX, GPIO_HEADPHONE_SENSE, 4, 0); | ||
112 | gpio_control(DEV_CTRL_GPIO_SET_INPUT, GPIO_HEADPHONE_SENSE, 4, 0); | ||
113 | |||
114 | /* Turn on touchscreen */ | ||
115 | mcs5000_init(); | ||
116 | mcs5000_power(); | ||
117 | mcs5000_set_hand(RIGHT_HAND); | ||
118 | } | ||
119 | |||
120 | #ifdef BUTTON_DRIVER_CLOSE | ||
121 | /* I'm not sure it's called at shutdown...give a check! */ | ||
122 | void button_close_device(void) | ||
123 | { | ||
124 | gpio_control(DEV_CTRL_GPIO_UNSET_MUX, GPIO_HEADPHONE_SENSE, 0, 0); | ||
125 | |||
126 | /* Turn off touchscreen device */ | ||
127 | mcs5000_shutdown(); | ||
128 | mcs5000_close(); | ||
129 | } | ||
130 | #endif /* BUTTON_DRIVER_CLOSE */ | ||