diff options
Diffstat (limited to 'firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c')
-rw-r--r-- | firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c new file mode 100644 index 0000000000..d6a4209292 --- /dev/null +++ b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
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 | #include "button-target.h" | ||
22 | #include "system.h" | ||
23 | #include "system-target.h" | ||
24 | #include "pinctrl-imx233.h" | ||
25 | #include "power-imx233.h" | ||
26 | #include "string.h" | ||
27 | #include "usb.h" | ||
28 | #include "touchscreen.h" | ||
29 | #include "touchscreen-imx233.h" | ||
30 | |||
31 | struct touch_calibration_point | ||
32 | { | ||
33 | short px_x; /* known pixel value */ | ||
34 | short px_y; | ||
35 | short val_x; /* touchscreen value at the known pixel */ | ||
36 | short val_y; | ||
37 | }; | ||
38 | |||
39 | static struct touch_calibration_point topleft, bottomright; | ||
40 | |||
41 | /* Amaury Pouly: values on my device | ||
42 | * Portait: (x and y are swapped) | ||
43 | * (0,0) = 200, 300 | ||
44 | * (240,400) = 3900, 3800 | ||
45 | * Landscape: | ||
46 | * (0,0) = 200, 3800 | ||
47 | * (400,240) = 3900, 300 | ||
48 | */ | ||
49 | void button_init_device(void) | ||
50 | { | ||
51 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | ||
52 | topleft.val_x = 300; | ||
53 | topleft.val_y = 200; | ||
54 | |||
55 | bottomright.val_x = 3800; | ||
56 | bottomright.val_y = 3900; | ||
57 | #else | ||
58 | topleft.val_x = 300; | ||
59 | topleft.val_y = 3900; | ||
60 | |||
61 | bottomright.val_x = 3800; | ||
62 | bottomright.val_y = 200; | ||
63 | #endif | ||
64 | topleft.px_x = 0; | ||
65 | topleft.px_y = 0; | ||
66 | |||
67 | bottomright.px_x = LCD_WIDTH; | ||
68 | bottomright.px_y = LCD_HEIGHT; | ||
69 | |||
70 | imx233_touchscreen_init(); | ||
71 | imx233_touchscreen_enable(true); | ||
72 | } | ||
73 | |||
74 | static int touch_to_pixels(int *val_x, int *val_y) | ||
75 | { | ||
76 | short x,y; | ||
77 | |||
78 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | ||
79 | x = *val_y; | ||
80 | y = *val_x; | ||
81 | #else | ||
82 | x = *val_x; | ||
83 | y = *val_y; | ||
84 | #endif | ||
85 | |||
86 | x = (x - topleft.val_x) * (bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x; | ||
87 | y = (y - topleft.val_y) * (bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y; | ||
88 | |||
89 | x = MAX(0, MIN(x, LCD_WIDTH - 1)); | ||
90 | y = MAX(0, MIN(y, LCD_HEIGHT - 1)); | ||
91 | |||
92 | *val_x = x; | ||
93 | *val_y = y; | ||
94 | |||
95 | return (x<<16)|y; | ||
96 | } | ||
97 | |||
98 | static int touchscreen_read_device(int *data) | ||
99 | { | ||
100 | int x, y; | ||
101 | if(!imx233_touchscreen_get_touch(&x, &y)) | ||
102 | return 0; | ||
103 | if(data) | ||
104 | *data = touch_to_pixels(&x, &y); | ||
105 | return touchscreen_to_pixels(x, y, data); | ||
106 | } | ||
107 | |||
108 | int button_read_device(int *data) | ||
109 | { | ||
110 | int res = 0; | ||
111 | /* B0P11: #power | ||
112 | * B0P14: #select */ | ||
113 | uint32_t mask = imx233_get_gpio_input_mask(0, 0x4800); | ||
114 | if(!(mask & 0x800)) | ||
115 | res |= BUTTON_POWER; | ||
116 | if(!(mask & 0x4000)) | ||
117 | res |= BUTTON_MENU; | ||
118 | return res | touchscreen_read_device(data); | ||
119 | } | ||