mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 13:15:18 -05:00
Add generic touchscreen driver which allows calibration (apps/ layer will follow later).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20055 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1cb3ff0ab0
commit
44eba07516
5 changed files with 230 additions and 92 deletions
|
|
@ -57,6 +57,10 @@ void button_set_touch_available(void);
|
|||
|
||||
#define BUTTON_TOUCH 0x00002000
|
||||
|
||||
#define DEFAULT_TOUCHSCREEN_CALIBRATION {.A=0xFFF9FDA2, .B=0xFFFFE82A, \
|
||||
.C=0xA22AA2C, .D=0x23DC, .E=0x8E3E6, \
|
||||
.F=0x76CF88AA, .divider=0xFFAD4013}
|
||||
|
||||
#define BUTTON_MAIN 0x3FFF
|
||||
|
||||
/* No remote */
|
||||
|
|
|
|||
|
|
@ -68,14 +68,6 @@ static volatile bool pen_down = false;
|
|||
static volatile unsigned short bat_val;
|
||||
static struct mutex battery_mtx;
|
||||
|
||||
static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT;
|
||||
static const int touchscreen_buttons[3][3] =
|
||||
{
|
||||
{BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
|
||||
{BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
|
||||
{BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}
|
||||
};
|
||||
|
||||
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
|
||||
{
|
||||
/* TODO */
|
||||
|
|
@ -163,30 +155,6 @@ void button_init_device(void)
|
|||
mutex_init(&battery_mtx);
|
||||
}
|
||||
|
||||
static int touch_to_pixels(short x, short y)
|
||||
{
|
||||
/* X:300 -> 3800 Y:300->3900 */
|
||||
x -= 300;
|
||||
y -= 300;
|
||||
|
||||
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
||||
x /= 3200 / LCD_WIDTH;
|
||||
y /= 3600 / LCD_HEIGHT;
|
||||
|
||||
y = LCD_HEIGHT - y;
|
||||
|
||||
return (x << 16) | y;
|
||||
#else
|
||||
x /= 3200 / LCD_HEIGHT;
|
||||
y /= 3600 / LCD_WIDTH;
|
||||
|
||||
y = LCD_WIDTH - y;
|
||||
x = LCD_HEIGHT - x;
|
||||
|
||||
return (y << 16) | x;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool button_hold(void)
|
||||
{
|
||||
return (
|
||||
|
|
@ -218,38 +186,16 @@ int button_read_device(int *data)
|
|||
if(tmp & BTN_OFF)
|
||||
ret |= BUTTON_POWER;
|
||||
|
||||
if(cur_touch != 0)
|
||||
if(cur_touch != 0 && pen_down)
|
||||
{
|
||||
if(current_mode == TOUCHSCREEN_BUTTON)
|
||||
{
|
||||
int px_x = cur_touch >> 16;
|
||||
int px_y = cur_touch & 0xFFFF;
|
||||
ret |= touchscreen_buttons[px_y/(LCD_HEIGHT/3)]
|
||||
[px_x/(LCD_WIDTH/3)];
|
||||
}
|
||||
else if(pen_down)
|
||||
{
|
||||
ret |= BUTTON_TOUCHSCREEN;
|
||||
*data = cur_touch;
|
||||
}
|
||||
ret |= touchscreen_to_pixels(cur_touch >> 16, cur_touch & 0xFFFF, data);
|
||||
if( UNLIKELY(!is_backlight_on(true)) )
|
||||
*data = 0;
|
||||
}
|
||||
|
||||
if(ret & BUTTON_TOUCHSCREEN && !is_backlight_on(true))
|
||||
*data = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void touchscreen_set_mode(enum touchscreen_mode mode)
|
||||
{
|
||||
current_mode = mode;
|
||||
}
|
||||
|
||||
enum touchscreen_mode touchscreen_get_mode(void)
|
||||
{
|
||||
return current_mode;
|
||||
}
|
||||
|
||||
/* Interrupt handler */
|
||||
void SADC(void)
|
||||
{
|
||||
|
|
@ -314,7 +260,8 @@ void SADC(void)
|
|||
|
||||
if(datacount >= TS_AD_COUNT)
|
||||
{
|
||||
cur_touch = touch_to_pixels(x_pos/datacount, y_pos/datacount);
|
||||
cur_touch = ((x_pos / datacount) << 16) |
|
||||
((y_pos / datacount) & 0xFFFF);
|
||||
datacount = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue