Remove the calls to backlight_lcd_sleep_countdown from target specific code and move...
[kugel-rb.git] / firmware / target / arm / tms320dm320 / mrobe-500 / button-mr500.c
blob2daae7e5d565db2f1d8504a7b56f4351b5100451
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007, 2009 by Karl Kurbjun
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* this file also handles the touch screen driver interface */
24 #include "config.h"
25 #include "cpu.h"
26 #include "system.h"
27 #include "button.h"
28 #include "kernel.h"
29 #include "backlight.h"
30 #include "backlight-target.h"
31 #include "lcd-remote-target.h"
32 #include "uart-target.h"
33 #include "tsc2100.h"
34 #include "string.h"
35 #include "touchscreen.h"
37 static bool touch_available = false;
38 static bool hold_button = false;
40 static struct touch_calibration_point topleft, bottomright;
42 /* Jd's tests.. These will hopefully work for everyone so we dont have to
43 * create a calibration screen.
44 * Portait:
45 * (0,0) = 200, 3900
46 * (480,640) = 3880, 270
47 * Landscape:
48 * (0,0) = 200, 270
49 * (640,480) = 3880, 3900
52 static int touch_to_pixels(short val_x, short val_y)
54 short x,y;
56 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
57 x=val_x;
58 y=val_y;
59 #else
60 x=val_y;
61 y=val_x;
62 #endif
64 x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x;
65 y = (y-topleft.val_y)*(bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y;
67 if (x < 0)
68 x = 0;
69 else if (x>=LCD_WIDTH)
70 x=LCD_WIDTH-1;
72 if (y < 0)
73 y = 0;
74 else if (y>=LCD_HEIGHT)
75 y=LCD_HEIGHT-1;
78 return (x<<16)|y;
81 void button_init_device(void)
83 touch_available = false;
84 /* GIO is the power button, set as input */
85 IO_GIO_DIR0 |= 0x01;
87 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
88 topleft.val_x = 200;
89 topleft.val_y = 3900;
91 bottomright.val_x = 3880;
92 bottomright.val_y = 270;
93 #else
94 topleft.val_x = 270;
95 topleft.val_y = 200;
97 bottomright.val_x = 3900;
98 bottomright.val_y = 3880;
99 #endif
101 topleft.px_x = 0;
102 topleft.px_y = 0;
104 bottomright.px_x = LCD_WIDTH;
105 bottomright.px_y = LCD_HEIGHT;
107 /* Enable the touchscreen interrupt */
108 IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
109 #if 0
110 tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS,
111 TSADC_PSTCM|
112 (0x2<<TSADC_ADSCM_SHIFT)| /* scan x,y,z1,z2 */
113 (0x1<<TSADC_RESOL_SHIFT) /* 8 bit resolution */
115 /* doesnt work for some reason...
116 setting to 8bit would probably be better than the 12bit currently */
117 #endif
120 inline bool button_hold(void)
122 return hold_button;
125 int button_read_device(int *data)
127 int button_read = BUTTON_NONE;
128 static int button_old = BUTTON_NONE;
129 static bool hold_button_old = false;
130 static long last_touch = 0;
132 *data = 0;
134 /* Handle touchscreen */
135 if (touch_available)
137 short x,y;
138 short last_z1, last_z2;
140 tsc2100_read_values(&x, &y, &last_z1, &last_z2);
142 *data = touch_to_pixels(x, y);
143 button_read |= touchscreen_to_pixels((*data&0xffff0000)>>16,
144 *data&0x0000ffff, data);
145 button_old = button_read;
147 touch_available = false;
148 last_touch=current_tick;
150 else
152 /* Touch hasn't happened in a while, clear the bits */
153 if(last_touch+3>current_tick)
154 button_old&=(0xFF);
157 /* Handle power button */
158 if ((IO_GIO_BITSET0&0x01) == 0)
160 button_read |= BUTTON_POWER;
161 button_old = button_read;
163 else
164 button_old&=~BUTTON_POWER;
166 /* Read data from the remote */
167 button_read |= remote_read_device();
168 hold_button=remote_button_hold();
170 /* Take care of hold notifications */
171 #ifndef BOOTLOADER
172 /* give BL notice if HB state chaged */
173 if (hold_button != hold_button_old)
175 backlight_hold_changed(hold_button);
176 hold_button_old=hold_button;
178 #endif
180 if (hold_button)
182 button_read = BUTTON_NONE;
183 button_old = button_read;
186 return button_read;
189 /* Touchscreen data available interupt */
190 void read_battery_inputs(void);
191 void GIO14(void)
193 short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
194 short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
195 switch (adscm)
197 case 1:
198 case 2:
199 touch_available = true;
200 break;
201 case 0xb:
202 read_battery_inputs();
203 break;
205 IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */