summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c')
-rw-r--r--firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c273
1 files changed, 0 insertions, 273 deletions
diff --git a/firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c b/firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c
deleted file mode 100644
index 91fe059c31..0000000000
--- a/firmware/target/arm/imx233/samsung-ypz5/button-ypz5.c
+++ /dev/null
@@ -1,273 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2013 by 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 "system.h"
22#include "lcd.h"
23#include "string.h"
24#include "kernel.h"
25#include "pinctrl-imx233.h"
26#include "power-imx233.h"
27#include "button-lradc-imx233.h"
28#include "button-target.h"
29#include "button-imx233.h"
30
31#ifndef BOOTLOADER
32#include "touchscreen.h"
33#include "touchscreen-imx233.h"
34#include "button.h"
35#include "font.h"
36#include "action.h"
37#endif
38
39#define CHAN 0 /* ADC channel for the buttons */
40#define I_VDDIO 0 /* Mock button to define the relative voltage to compute voltage from ADC steps */
41
42struct imx233_button_map_t imx233_button_map[] =
43{
44 [I_VDDIO] = IMX233_BUTTON_(VDDIO, VDDIO(3760), "vddio"), /* we need VDDIO for relative */
45 IMX233_BUTTON_(HOLD, GPIO(0, 13), "hold"),
46 IMX233_BUTTON(POWER, PSWITCH(1), "power"),
47 IMX233_BUTTON(SELECT, PSWITCH(3), "select"),
48 IMX233_BUTTON(VOL_UP, LRADC_REL(CHAN, 485, I_VDDIO), "vol up"),
49 IMX233_BUTTON(VOL_DOWN, LRADC_REL(CHAN, 975, I_VDDIO), "vol down"),
50 IMX233_BUTTON(BACK, LRADC_REL(CHAN, 1521, I_VDDIO), "back"),
51 IMX233_BUTTON(FF, LRADC_REL(CHAN, 2000, I_VDDIO), "ff"),
52 IMX233_BUTTON(REW, LRADC_REL(CHAN, 2480, I_VDDIO), "rew"),
53 IMX233_BUTTON_(END, END(), "")
54};
55
56#ifndef BOOTLOADER
57static int last_x = 0;
58static int last_y = 0;
59static bool touching = false;
60#endif /* BOOTLOADER */
61
62#ifndef BOOTLOADER
63
64/* Touchpad extra pin initialization
65 * Strange facts:
66 * 1. In the fully working sample I have, it seems that pins
67 * must be all set to low
68 * 2. In the other sample without LCD, it seems (by measurement) that
69 * not all the pins are set to low! Actually, I still need to see if
70 * touchpad works in this other sample.
71*/
72void touchpad_pin_setup(void)
73{
74 /* TX+ */
75 imx233_pinctrl_acquire(0, 25, "touchpad X+ power low");
76 imx233_pinctrl_set_function(0, 25, PINCTRL_FUNCTION_GPIO);
77 imx233_pinctrl_set_drive(0, 25, PINCTRL_DRIVE_4mA);
78 imx233_pinctrl_enable_gpio(0, 25, true);
79
80 /* TY+ */
81 imx233_pinctrl_acquire(0, 26, "touchpad Y+ power high");
82 imx233_pinctrl_set_function(0, 26, PINCTRL_FUNCTION_GPIO);
83 imx233_pinctrl_set_drive(0, 26, PINCTRL_DRIVE_4mA);
84 imx233_pinctrl_enable_gpio(0, 26, true);
85
86 /* TY- */
87 imx233_pinctrl_acquire(1, 21, "touchpad Y- power low");
88 imx233_pinctrl_set_function(1, 21, PINCTRL_FUNCTION_GPIO);
89 imx233_pinctrl_set_drive(1, 21, PINCTRL_DRIVE_4mA);
90 imx233_pinctrl_enable_gpio(1, 21, true);
91
92 /* TX- */
93 imx233_pinctrl_acquire(3, 15, "touchpad X- power high");
94 imx233_pinctrl_set_function(3, 15, PINCTRL_FUNCTION_GPIO);
95 imx233_pinctrl_set_drive(3, 15, PINCTRL_DRIVE_4mA);
96 imx233_pinctrl_enable_gpio(3, 15, true);
97
98}
99#endif /* BOOTLOADER */
100
101void button_init_device(void)
102{
103 /* init button subsystem */
104 imx233_button_init();
105#ifndef BOOTLOADER
106 touchpad_pin_setup();
107 /* Now that is powered up, proceed with touchpad initialization */
108 imx233_touchscreen_init();
109 imx233_touchscreen_enable(true);
110#endif /* BOOTLOADER */
111}
112
113/* X, Y, RadiusX, RadiusY */
114#define TOUCH_UP 2400, 1050, 650, 250
115#define TOUCH_DOWN 2057, 3320, 500, 350
116#define TOUCH_LEFT 3581, 2297, 300, 350
117#define TOUCH_RIGHT 1000, 2100, 400, 700
118#define TOUCH_CENTER 2682, 2167, 335, 276
119
120bool coord_in_radius(int x, int y, int cx, int cy, int rx, int ry)
121{
122 return ((x >= cx - rx && x <= cx + rx) && (y >= cy - ry && y <= cy + ry));
123}
124
125int button_read_device(void)
126{
127 int res = 0;
128
129#ifndef BOOTLOADER
130 /* handle the touchpad events */
131 touching = imx233_touchscreen_get_touch(&last_x, &last_y);
132 if(touching)
133 {
134 if (coord_in_radius(last_x, last_y, TOUCH_LEFT))
135 {
136 res |= BUTTON_LEFT;
137 }
138 else if (coord_in_radius(last_x, last_y, TOUCH_RIGHT))
139 {
140 res |= BUTTON_RIGHT;
141 }
142 else if (coord_in_radius(last_x, last_y, TOUCH_DOWN))
143 {
144 res |= BUTTON_DOWN;
145 }
146 else if (coord_in_radius(last_x, last_y, TOUCH_UP))
147 {
148 res |= BUTTON_UP;
149 }
150 }
151#endif /* BOOTLOADER */
152 /* handle the generic events */
153 return imx233_button_read(res);
154}
155
156#ifndef BOOTLOADER
157
158#define MAX_ENTRIES 100
159#define VIEWPORT_HEIGHT 100
160#define VIEWPORT_WIDTH 100
161#define MAX_X 3700
162#define MAX_Y 3700
163#define ADAPT_TO_VIEWPORT(cx, cy, rx, ry) ((float)(cx) / MAX_X) * VIEWPORT_WIDTH, \
164 ((float)(cy) / MAX_Y) * VIEWPORT_HEIGHT, \
165 ((float)(rx) / MAX_X) * VIEWPORT_WIDTH, \
166 ((float)(ry) / MAX_Y) * VIEWPORT_HEIGHT
167static void draw_calibration_rect(int cx, int cy, int rx, int ry)
168{
169 if (coord_in_radius(last_x, last_y, cx, cy, rx, ry))
170 lcd_set_drawinfo(DRMODE_SOLID, LCD_RGBPACK(0xff, 0xff, 0xff), LCD_BLACK);
171 else
172 lcd_set_drawinfo(DRMODE_SOLID, LCD_RGBPACK(0xff, 0, 0), LCD_BLACK);
173 lcd_drawrect(ADAPT_TO_VIEWPORT(cx - rx, cy - ry, 2 * rx, 2 * ry));
174}
175
176bool button_debug_screen(void)
177{
178 int last = 0;
179 struct point_t
180 {
181 int x;
182 int y;
183 };
184 struct point_t last_entries[MAX_ENTRIES];
185 struct viewport report_vp;
186
187 memset(&report_vp, 0, sizeof(report_vp));
188 report_vp.x = (LCD_WIDTH - VIEWPORT_WIDTH) / 2;
189 report_vp.y = (LCD_HEIGHT - VIEWPORT_HEIGHT) / 2;
190 report_vp.width = VIEWPORT_WIDTH;
191 report_vp.height = VIEWPORT_HEIGHT;
192
193 lcd_setfont(FONT_SYSFIXED);
194 lcd_clear_display();
195
196 while(1)
197 {
198 int button = get_action(CONTEXT_STD, HZ / 10);
199 switch(button)
200 {
201 case ACTION_STD_OK:
202 case ACTION_STD_MENU:
203 lcd_set_viewport(NULL);
204 lcd_setfont(FONT_UI);
205 lcd_clear_display();
206 return true;
207 case ACTION_STD_CANCEL:
208 lcd_set_viewport(NULL);
209 lcd_setfont(FONT_UI);
210 lcd_clear_display();
211 return false;
212 }
213
214 lcd_set_viewport(NULL);
215 lcd_putsf(0, 1, "(%d,%d) %s", last_x, last_y, touching ? "touching!" : "");
216 lcd_putsf(0, 0, "Type %s", imx233_pinctrl_get_gpio(0, 31) ? "CAP" : "REG");
217 lcd_set_viewport(&report_vp);
218 lcd_set_drawinfo(DRMODE_SOLID, LCD_RGBPACK(0, 0, 0xff), LCD_BLACK);
219 lcd_drawrect(0, 0, 100, 100);
220 float percent_x = ((float)(last_x) / MAX_X);
221 float percent_y = ((float)(last_y) / MAX_Y);
222 if (touching)
223 {
224 lcd_set_viewport(NULL);
225 if (last < MAX_ENTRIES)
226 {
227 last_entries[last].x = last_x;
228 last_entries[last].y = last_y;
229 last++;
230 lcd_putsf(0, 17, "Recording: %d captures left", MAX_ENTRIES - last);
231 }
232 else
233 {
234 int min_x = 9999;
235 int min_y = 9999;
236 int max_x = -1;
237 int max_y = -1;
238 int median_x = 0;
239 int median_y = 0;
240 for (int i = 0; i < MAX_ENTRIES; i++)
241 {
242 min_x = MIN(min_x, last_entries[i].x);
243 min_y = MIN(min_y, last_entries[i].y);
244 max_x = MAX(max_x, last_entries[i].x);
245 max_y = MAX(max_y, last_entries[i].y);
246 median_x += last_entries[i].x;
247 median_y += last_entries[i].y;
248 }
249 median_x /= MAX_ENTRIES;
250 median_y /= MAX_ENTRIES;
251 lcd_putsf(0, 17, "center(%d,%d)", median_x, median_y);
252 lcd_putsf(0, 18, "radius(%d,%d)", median_x / 2, median_y / 2);
253 }
254 lcd_set_viewport(&report_vp);
255 lcd_set_drawinfo(DRMODE_SOLID, LCD_RGBPACK(0xff, 0x8c, 0), LCD_BLACK);
256 lcd_fillrect(VIEWPORT_WIDTH * percent_x, VIEWPORT_HEIGHT * percent_y, 2, 2);
257 }
258
259 /* Draw current calibration settings */
260 lcd_set_viewport(&report_vp);
261 draw_calibration_rect(TOUCH_UP);
262 draw_calibration_rect(TOUCH_DOWN);
263 draw_calibration_rect(TOUCH_CENTER);
264 draw_calibration_rect(TOUCH_LEFT);
265 draw_calibration_rect(TOUCH_RIGHT);
266
267 lcd_update();
268 yield();
269 }
270
271 return true;
272}
273#endif