1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Michael Sevakis
12 * LCD scrolling driver and scheduler
14 * Much collected and combined from the various Rockbox LCD drivers.
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
30 #ifdef HAVE_REMOTE_LCD
31 #include "lcd-remote.h"
33 #include "scroll_engine.h"
35 static const char scroll_tick_table
[16] = {
37 1, 1.25, 1.55, 2, 2.5, 3.12, 4, 5, 6.25, 8.33, 10, 12.5, 16.7, 20, 25, 33 */
38 100, 80, 64, 50, 40, 32, 25, 20, 16, 12, 10, 8, 6, 5, 4, 3
41 static void scroll_thread(void);
42 static char scroll_stack
[DEFAULT_STACK_SIZE
*3];
43 static const char scroll_name
[] = "scroll";
45 static struct scrollinfo lcd_scroll
[LCD_SCROLLABLE_LINES
];
47 #ifdef HAVE_REMOTE_LCD
48 struct scrollinfo lcd_remote_scroll
[LCD_REMOTE_SCROLLABLE_LINES
];
49 struct event_queue scroll_queue
;
52 struct scroll_screen_info lcd_scroll_info
=
59 #ifdef HAVE_LCD_BITMAP
62 #ifdef HAVE_LCD_CHARCELLS
63 .jump_scroll_delay
= HZ
/4,
68 #ifdef HAVE_REMOTE_LCD
69 struct scroll_screen_info lcd_remote_scroll_info
=
71 .scroll
= lcd_remote_scroll
,
78 #endif /* HAVE_REMOTE_LCD */
80 void lcd_stop_scroll(void)
82 lcd_scroll_info
.lines
= 0;
85 /* Stop scrolling line y in the specified viewport, or all lines if y < 0 */
86 void lcd_scroll_stop_line(struct viewport
* current_vp
, int y
)
90 while (i
< lcd_scroll_info
.lines
)
92 if ((lcd_scroll_info
.scroll
[i
].vp
== current_vp
) &&
93 ((y
< 0) || (lcd_scroll_info
.scroll
[i
].y
== y
)))
95 /* If i is not the last active line in the array, then move
96 the last item to position i */
97 if ((i
+ 1) != lcd_scroll_info
.lines
)
99 lcd_scroll_info
.scroll
[i
] = lcd_scroll_info
.scroll
[lcd_scroll_info
.lines
-1];
101 lcd_scroll_info
.lines
--;
103 /* A line can only appear once, so we're done. */
113 /* Stop all scrolling lines in the specified viewport */
114 void lcd_scroll_stop(struct viewport
* vp
)
116 lcd_scroll_stop_line(vp
, -1);
119 void lcd_scroll_speed(int speed
)
121 lcd_scroll_info
.ticks
= scroll_tick_table
[speed
];
124 #if defined(HAVE_LCD_BITMAP)
125 void lcd_scroll_step(int step
)
127 lcd_scroll_info
.step
= step
;
131 void lcd_scroll_delay(int ms
)
133 lcd_scroll_info
.delay
= ms
/ (HZ
/ 10);
136 void lcd_bidir_scroll(int percent
)
138 lcd_scroll_info
.bidir_limit
= percent
;
141 #ifdef HAVE_LCD_CHARCELLS
142 void lcd_jump_scroll(int mode
) /* 0=off, 1=once, ..., JUMP_SCROLL_ALWAYS */
144 lcd_scroll_info
.jump_scroll
= mode
;
147 void lcd_jump_scroll_delay(int ms
)
149 lcd_scroll_info
.jump_scroll_delay
= ms
/ (HZ
/ 10);
153 #ifdef HAVE_REMOTE_LCD
154 void lcd_remote_stop_scroll(void)
156 lcd_remote_scroll_info
.lines
= 0;
159 /* Stop scrolling line y in the specified viewport, or all lines if y < 0 */
160 void lcd_remote_scroll_stop_line(struct viewport
* current_vp
, int y
)
164 while (i
< lcd_remote_scroll_info
.lines
)
166 if ((lcd_remote_scroll_info
.scroll
[i
].vp
== current_vp
) &&
167 ((y
< 0) || (lcd_remote_scroll_info
.scroll
[i
].y
== y
)))
169 /* If i is not the last active line in the array, then move
170 the last item to position i */
171 if ((i
+ 1) != lcd_remote_scroll_info
.lines
)
173 lcd_remote_scroll_info
.scroll
[i
] = lcd_remote_scroll_info
.scroll
[lcd_remote_scroll_info
.lines
-1];
175 lcd_remote_scroll_info
.lines
--;
177 /* A line can only appear once, so we're done. */
187 /* Stop all scrolling lines in the specified viewport */
188 void lcd_remote_scroll_stop(struct viewport
* vp
)
190 lcd_remote_scroll_stop_line(vp
, -1);
193 void lcd_remote_scroll_speed(int speed
)
195 lcd_remote_scroll_info
.ticks
= scroll_tick_table
[speed
];
198 void lcd_remote_scroll_step(int step
)
200 lcd_remote_scroll_info
.step
= step
;
203 void lcd_remote_scroll_delay(int ms
)
205 lcd_remote_scroll_info
.delay
= ms
/ (HZ
/ 10);
208 void lcd_remote_bidir_scroll(int percent
)
210 lcd_remote_scroll_info
.bidir_limit
= percent
;
213 static void sync_display_ticks(void)
215 lcd_scroll_info
.last_scroll
=
216 lcd_remote_scroll_info
.last_scroll
= current_tick
;
219 static bool scroll_process_message(int delay
)
221 struct queue_event ev
;
225 long tick
= current_tick
;
226 queue_wait_w_tmo(&scroll_queue
, &ev
, delay
);
232 case SYS_USB_CONNECTED
:
233 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
234 usb_wait_for_disconnect(&scroll_queue
);
235 sync_display_ticks();
238 case SYS_REMOTE_PLUGGED
:
239 if (!remote_initialized
)
240 sync_display_ticks();
244 delay
-= current_tick
- tick
;
250 #endif /* HAVE_REMOTE_LCD */
252 static void scroll_thread(void) __attribute__((noreturn
));
253 #ifdef HAVE_REMOTE_LCD
255 static void scroll_thread(void)
260 SCROLL_LCD_REMOTE
= 0x2,
263 sync_display_ticks();
269 long tick_lcd
, tick_remote
;
271 tick_lcd
= lcd_scroll_info
.last_scroll
+ lcd_scroll_info
.ticks
;
272 delay
= current_tick
;
276 !remote_initialized
||
278 (tick_remote
= lcd_remote_scroll_info
.last_scroll
+
279 lcd_remote_scroll_info
.ticks
,
280 TIME_BEFORE(tick_lcd
, tick_remote
)))
283 delay
= tick_lcd
- delay
;
285 /* TIME_BEFORE(tick_remote, tick_lcd) */
286 else if (tick_lcd
!= tick_remote
)
288 scroll
= SCROLL_LCD_REMOTE
;
289 delay
= tick_remote
- delay
;
293 scroll
= SCROLL_LCD
| SCROLL_LCD_REMOTE
;
294 delay
= tick_lcd
- delay
;
297 if (scroll_process_message(delay
))
300 if (scroll
& SCROLL_LCD
)
302 #ifdef HAVE_LCD_ENABLE
306 lcd_scroll_info
.last_scroll
= current_tick
;
309 if (scroll
== (SCROLL_LCD
| SCROLL_LCD_REMOTE
))
312 if (scroll
& SCROLL_LCD_REMOTE
)
314 lcd_remote_scroll_fn();
315 lcd_remote_scroll_info
.last_scroll
= current_tick
;
320 static void scroll_thread(void)
324 sleep(lcd_scroll_info
.ticks
);
325 #ifdef HAVE_LCD_ENABLE
331 #endif /* HAVE_REMOTE_LCD */
333 void scroll_init(void)
335 #ifdef HAVE_REMOTE_LCD
336 queue_init(&scroll_queue
, true);
338 create_thread(scroll_thread
, scroll_stack
,
339 sizeof(scroll_stack
), 0, scroll_name
340 IF_PRIO(, PRIORITY_USER_INTERFACE
)