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 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 void lcd_scroll_speed(int speed
)
87 lcd_scroll_info
.ticks
= scroll_tick_table
[speed
];
90 #if defined(HAVE_LCD_BITMAP)
91 void lcd_scroll_step(int step
)
93 lcd_scroll_info
.step
= step
;
97 void lcd_scroll_delay(int ms
)
99 lcd_scroll_info
.delay
= ms
/ (HZ
/ 10);
102 void lcd_bidir_scroll(int percent
)
104 lcd_scroll_info
.bidir_limit
= percent
;
107 #ifdef HAVE_LCD_CHARCELLS
108 void lcd_jump_scroll(int mode
) /* 0=off, 1=once, ..., JUMP_SCROLL_ALWAYS */
110 lcd_scroll_info
.jump_scroll
= mode
;
113 void lcd_jump_scroll_delay(int ms
)
115 lcd_scroll_info
.jump_scroll_delay
= ms
/ (HZ
/ 10);
119 #ifdef HAVE_REMOTE_LCD
120 void lcd_remote_stop_scroll(void)
122 lcd_remote_scroll_info
.lines
= 0;
125 void lcd_remote_scroll_speed(int speed
)
127 lcd_remote_scroll_info
.ticks
= scroll_tick_table
[speed
];
130 void lcd_remote_scroll_step(int step
)
132 lcd_remote_scroll_info
.step
= step
;
135 void lcd_remote_scroll_delay(int ms
)
137 lcd_remote_scroll_info
.delay
= ms
/ (HZ
/ 10);
140 void lcd_remote_bidir_scroll(int percent
)
142 lcd_remote_scroll_info
.bidir_limit
= percent
;
145 static void sync_display_ticks(void)
147 lcd_scroll_info
.last_scroll
=
148 lcd_remote_scroll_info
.last_scroll
= current_tick
;
151 static bool scroll_process_message(int delay
)
153 struct queue_event ev
;
157 long tick
= current_tick
;
158 queue_wait_w_tmo(&scroll_queue
, &ev
, delay
);
164 case SYS_USB_CONNECTED
:
165 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
166 usb_wait_for_disconnect(&scroll_queue
);
167 sync_display_ticks();
170 case SYS_REMOTE_PLUGGED
:
171 if (!remote_initialized
)
172 sync_display_ticks();
176 delay
-= current_tick
- tick
;
182 #endif /* HAVE_REMOTE_LCD */
184 static void scroll_thread(void) __attribute__((noreturn
));
185 #ifdef HAVE_REMOTE_LCD
187 static void scroll_thread(void)
192 SCROLL_LCD_REMOTE
= 0x2,
195 sync_display_ticks();
201 long tick_lcd
, tick_remote
;
203 tick_lcd
= lcd_scroll_info
.last_scroll
+ lcd_scroll_info
.ticks
;
204 delay
= current_tick
;
208 !remote_initialized
||
210 (tick_remote
= lcd_remote_scroll_info
.last_scroll
+
211 lcd_remote_scroll_info
.ticks
,
212 TIME_BEFORE(tick_lcd
, tick_remote
)))
215 delay
= tick_lcd
- delay
;
217 /* TIME_BEFORE(tick_remote, tick_lcd) */
218 else if (tick_lcd
!= tick_remote
)
220 scroll
= SCROLL_LCD_REMOTE
;
221 delay
= tick_remote
- delay
;
225 scroll
= SCROLL_LCD
| SCROLL_LCD_REMOTE
;
226 delay
= tick_lcd
- delay
;
229 if (scroll_process_message(delay
))
232 if (scroll
& SCROLL_LCD
)
234 #ifdef HAVE_LCD_ENABLE
238 lcd_scroll_info
.last_scroll
= current_tick
;
241 if (scroll
== (SCROLL_LCD
| SCROLL_LCD_REMOTE
))
244 if (scroll
& SCROLL_LCD_REMOTE
)
246 lcd_remote_scroll_fn();
247 lcd_remote_scroll_info
.last_scroll
= current_tick
;
252 static void scroll_thread(void)
256 sleep(lcd_scroll_info
.ticks
);
257 #ifdef HAVE_LCD_ENABLE
263 #endif /* HAVE_REMOTE_LCD */
265 void scroll_init(void)
267 #ifdef HAVE_REMOTE_LCD
268 queue_init(&scroll_queue
, true);
270 create_thread(scroll_thread
, scroll_stack
,
271 sizeof(scroll_stack
), 0, scroll_name
272 IF_PRIO(, PRIORITY_USER_INTERFACE
)