summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/touchscreen.c31
-rw-r--r--firmware/export/config/cowond2.h1
-rw-r--r--firmware/export/config/mrobe500.h2
-rw-r--r--firmware/export/config/ondavx747.h1
-rw-r--r--firmware/export/config/ondavx767.h7
-rw-r--r--firmware/export/config/ondavx777.h1
-rw-r--r--firmware/export/config/sim.h1
-rw-r--r--firmware/export/lcd.h10
-rw-r--r--firmware/export/touchscreen.h1
-rw-r--r--firmware/target/hosted/android/lcd-android.c26
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c6
11 files changed, 85 insertions, 2 deletions
diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c
index 9660e0cb9d..823c2e7a92 100644
--- a/firmware/drivers/touchscreen.c
+++ b/firmware/drivers/touchscreen.c
@@ -25,6 +25,7 @@
25#include "touchscreen.h" 25#include "touchscreen.h"
26#include "string.h" 26#include "string.h"
27#include "logf.h" 27#include "logf.h"
28#include "lcd.h"
28 29
29/* Size of the 'dead zone' around each 3x3 button */ 30/* Size of the 'dead zone' around each 3x3 button */
30#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03) 31#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03)
@@ -167,3 +168,33 @@ enum touchscreen_mode touchscreen_get_mode(void)
167{ 168{
168 return current_mode; 169 return current_mode;
169} 170}
171
172
173#if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0)
174/* android has an API for this */
175
176#define TOUCH_SLOP 16u
177#define REFERENCE_DPI 160
178
179int touchscreen_get_scroll_threshold(void)
180{
181#ifdef LCD_DPI
182 const int dpi = LCD_DPI;
183#else
184 const int dpi = lcd_get_dpi();
185#endif
186
187 /* Inspired by Android calculation
188 *
189 * float density = real dpi / reference dpi (=160)
190 * int threshold = (int) (density * TOUCH_SLOP + 0.5f);(original calculation)
191 *
192 * + 0.5f is for rounding, we use fixed point math to achieve that
193 */
194
195 int result = dpi * (TOUCH_SLOP<<1) / REFERENCE_DPI;
196 result += result & 1; /* round up if needed */
197 return result>>1;
198}
199
200#endif
diff --git a/firmware/export/config/cowond2.h b/firmware/export/config/cowond2.h
index f9de2768bd..ebaa636ac7 100644
--- a/firmware/export/config/cowond2.h
+++ b/firmware/export/config/cowond2.h
@@ -75,6 +75,7 @@
75/* LCD dimensions */ 75/* LCD dimensions */
76#define LCD_WIDTH 320 76#define LCD_WIDTH 320
77#define LCD_HEIGHT 240 77#define LCD_HEIGHT 240
78#define LCD_DPI 160
78#define LCD_DEPTH 16 79#define LCD_DEPTH 16
79#define LCD_PIXELFORMAT 565 80#define LCD_PIXELFORMAT 565
80 81
diff --git a/firmware/export/config/mrobe500.h b/firmware/export/config/mrobe500.h
index 9a201951fc..776b0315f8 100644
--- a/firmware/export/config/mrobe500.h
+++ b/firmware/export/config/mrobe500.h
@@ -87,9 +87,11 @@
87#if _RESOLUTION == _LCD_RES_VGA 87#if _RESOLUTION == _LCD_RES_VGA
88#define LCD_NATIVE_WIDTH 480 88#define LCD_NATIVE_WIDTH 480
89#define LCD_NATIVE_HEIGHT 640 89#define LCD_NATIVE_HEIGHT 640
90#define LCD_DPI 216
90#else 91#else
91#define LCD_NATIVE_WIDTH 240 92#define LCD_NATIVE_WIDTH 240
92#define LCD_NATIVE_HEIGHT 320 93#define LCD_NATIVE_HEIGHT 320
94#define LCD_DPI 108
93#endif 95#endif
94 96
95/* choose the lcd orientation. CONFIG_ORIENTATION defined in config.h */ 97/* choose the lcd orientation. CONFIG_ORIENTATION defined in config.h */
diff --git a/firmware/export/config/ondavx747.h b/firmware/export/config/ondavx747.h
index ae80cac562..1cd9143965 100644
--- a/firmware/export/config/ondavx747.h
+++ b/firmware/export/config/ondavx747.h
@@ -79,6 +79,7 @@
79#define LCD_WIDTH 240 79#define LCD_WIDTH 240
80#define LCD_HEIGHT 400 80#define LCD_HEIGHT 400
81#endif 81#endif
82#define LCD_DPI 155
82 83
83#define LCD_DEPTH 16 /* 16bit colours */ 84#define LCD_DEPTH 16 /* 16bit colours */
84#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 85#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/ondavx767.h b/firmware/export/config/ondavx767.h
index 19bb7ed580..bf9aaed7c1 100644
--- a/firmware/export/config/ondavx767.h
+++ b/firmware/export/config/ondavx767.h
@@ -65,8 +65,11 @@
65/* LCD dimensions */ 65/* LCD dimensions */
66#define CONFIG_LCD LCD_ONDAVX767 66#define CONFIG_LCD LCD_ONDAVX767
67 67
68#define LCD_WIDTH 320 68/* this are not actually the correct dimensions (480x272 is correct)
69#define LCD_HEIGHT 240 69 * should be fixed once there's a working LCD driver */
70#define LCD_WIDTH 480
71#define LCD_HEIGHT 272
72#define LCD_DPI 128
70 73
71#define LCD_DEPTH 16 /* 16bit colours */ 74#define LCD_DEPTH 16 /* 16bit colours */
72#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 75#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/ondavx777.h b/firmware/export/config/ondavx777.h
index a2ad15533a..b6e7546590 100644
--- a/firmware/export/config/ondavx777.h
+++ b/firmware/export/config/ondavx777.h
@@ -73,6 +73,7 @@
73#define LCD_WIDTH 240 73#define LCD_WIDTH 240
74#define LCD_HEIGHT 400 74#define LCD_HEIGHT 400
75#endif 75#endif
76#define LCD_DPI 155
76 77
77#define LCD_DEPTH 16 /* 16bit colours */ 78#define LCD_DEPTH 16 /* 16bit colours */
78#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 79#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
index 066201ad08..fc7996e813 100644
--- a/firmware/export/config/sim.h
+++ b/firmware/export/config/sim.h
@@ -19,6 +19,7 @@
19#undef HAVE_ATA_POWER_OFF 19#undef HAVE_ATA_POWER_OFF
20 20
21#undef CONFIG_LCD 21#undef CONFIG_LCD
22#undef LCD_DPI /* likely to be too different on a PC */
22 23
23#undef CONFIG_LED 24#undef CONFIG_LED
24 25
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 79231d198e..e6e19b1597 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -549,4 +549,14 @@ extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
549 549
550#endif /* HAVE_LCD_BITMAP */ 550#endif /* HAVE_LCD_BITMAP */
551 551
552
553#ifdef HAVE_TOUCHSCREEN
554/* only needed for touchscreen for now, feel free to implement it for others
555 * once needed
556 */
557
558/* returns the pixel density of the display */
559extern int lcd_get_dpi(void);
560#endif
561
552#endif /* __LCD_H__ */ 562#endif /* __LCD_H__ */
diff --git a/firmware/export/touchscreen.h b/firmware/export/touchscreen.h
index 7d1eb4ac8a..a27e60c653 100644
--- a/firmware/export/touchscreen.h
+++ b/firmware/export/touchscreen.h
@@ -50,5 +50,6 @@ void touchscreen_set_mode(enum touchscreen_mode mode);
50enum touchscreen_mode touchscreen_get_mode(void); 50enum touchscreen_mode touchscreen_get_mode(void);
51void touchscreen_disable_mapping(void); 51void touchscreen_disable_mapping(void);
52void touchscreen_reset_mapping(void); 52void touchscreen_reset_mapping(void);
53int touchscreen_get_scroll_threshold(void);
53 54
54#endif /* __TOUCHSCREEN_INCLUDE_H_ */ 55#endif /* __TOUCHSCREEN_INCLUDE_H_ */
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index 78b1f12f7f..f4ef7b5e75 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -35,6 +35,8 @@ static jmethodID java_lcd_update;
35static jmethodID java_lcd_update_rect; 35static jmethodID java_lcd_update_rect;
36 36
37static bool display_on; 37static bool display_on;
38static int dpi;
39static int scroll_threshold;
38 40
39void lcd_init_device(void) 41void lcd_init_device(void)
40{ 42{
@@ -77,6 +79,20 @@ void lcd_init_device(void)
77 RockboxFramebuffer_class, 79 RockboxFramebuffer_class,
78 "java_lcd_update_rect", 80 "java_lcd_update_rect",
79 "(IIII)V"); 81 "(IIII)V");
82
83 jmethodID get_dpi = e->GetMethodID(env_ptr,
84 RockboxFramebuffer_class,
85 "getDpi", "()I");
86
87 jmethodID get_scroll_threshold
88 = e->GetMethodID(env_ptr,
89 RockboxFramebuffer_class,
90 "getScrollThreshold", "()I");
91
92 dpi = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance,
93 get_dpi);
94 scroll_threshold = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance,
95 get_scroll_threshold);
80 display_on = true; 96 display_on = true;
81} 97}
82 98
@@ -101,6 +117,16 @@ bool lcd_active(void)
101 return display_on; 117 return display_on;
102} 118}
103 119
120int lcd_get_dpi(void)
121{
122 return dpi;
123}
124
125int touchscreen_get_scroll_threshold(void)
126{
127 return scroll_threshold;
128}
129
104/* 130/*
105 * (un)block lcd updates. 131 * (un)block lcd updates.
106 * 132 *
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index 15e4ba95c3..96b1a04aa6 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -111,3 +111,9 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
111 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); 111 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
112} 112}
113 113
114int lcd_get_dpi(void)
115{
116 /* TODO: find a way to query it from the OS, SDL doesn't support it
117 * directly; for now assume the more or less standard 96 */
118 return 96;
119}