summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/lcd-player.c183
-rw-r--r--firmware/drivers/lcd-recorder.c195
-rw-r--r--firmware/drivers/lcd.h3
3 files changed, 303 insertions, 78 deletions
diff --git a/firmware/drivers/lcd-player.c b/firmware/drivers/lcd-player.c
index 64587b5319..54202a6f10 100644
--- a/firmware/drivers/lcd-player.c
+++ b/firmware/drivers/lcd-player.c
@@ -46,9 +46,16 @@
46#define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x)))) 46#define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x))))
47#define LCD_ICON(i) ((char)(lcd_iram+i)) 47#define LCD_ICON(i) ((char)(lcd_iram+i))
48 48
49#define SCROLLABLE_LINES 2
50
51#define SCROLL_MODE_OFF 0
52#define SCROLL_MODE_PAUSE 1
53#define SCROLL_MODE_RUN 2
54
49/*** generic code ***/ 55/*** generic code ***/
50 56
51struct scrollinfo { 57struct scrollinfo {
58 int mode;
52 char text[MAX_PATH]; 59 char text[MAX_PATH];
53 char line[32]; 60 char line[32];
54 int textlen; 61 int textlen;
@@ -63,10 +70,10 @@ static char scroll_stack[DEFAULT_STACK_SIZE];
63static char scroll_name[] = "scroll"; 70static char scroll_name[] = "scroll";
64static char scroll_speed = 8; /* updates per second */ 71static char scroll_speed = 8; /* updates per second */
65static char scroll_spacing = 3; /* spaces between end and start of text */ 72static char scroll_spacing = 3; /* spaces between end and start of text */
73static long scroll_start_tick;
66 74
67 75
68static struct scrollinfo scroll; /* only one scroll line at the moment */ 76static struct scrollinfo scroll[SCROLLABLE_LINES];
69static int scroll_count = 0;
70 77
71static const unsigned char new_lcd_ascii[] = { 78static const unsigned char new_lcd_ascii[] = {
72 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 79 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
@@ -272,13 +279,26 @@ void lcd_init (void)
272 279
273void lcd_puts_scroll(int x, int y, unsigned char* string ) 280void lcd_puts_scroll(int x, int y, unsigned char* string )
274{ 281{
275 struct scrollinfo* s = &scroll; 282 struct scrollinfo* s;
283 int index;
284
285 scroll_start_tick = current_tick + HZ/2;
286
287 /* search for the next free entry */
288 for (index = 0; index < SCROLLABLE_LINES; index++) {
289 s = &scroll[index];
290 if (s->mode == SCROLL_MODE_OFF) {
291 break;
292 }
293 }
294
276 s->space = 11 - x; 295 s->space = 11 - x;
277 296
278 lcd_puts(x,y,string); 297 lcd_puts(x,y,string);
279 s->textlen = strlen(string); 298 s->textlen = strlen(string);
280 299
281 if ( s->textlen > s->space ) { 300 if ( s->textlen > s->space ) {
301 s->mode = SCROLL_MODE_RUN;
282 s->offset=s->space; 302 s->offset=s->space;
283 s->startx=x; 303 s->startx=x;
284 s->starty=y; 304 s->starty=y;
@@ -289,31 +309,102 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
289 s->space > (int)sizeof s->line ? 309 s->space > (int)sizeof s->line ?
290 (int)sizeof s->line : s->space ); 310 (int)sizeof s->line : s->space );
291 s->line[sizeof s->line - 1] = 0; 311 s->line[sizeof s->line - 1] = 0;
292 scroll_count = 1;
293 } 312 }
294} 313}
295 314
296
297void lcd_stop_scroll(void) 315void lcd_stop_scroll(void)
298{ 316{
299 if ( scroll_count ) { 317 struct scrollinfo* s;
300 struct scrollinfo* s = &scroll; 318 int index;
301 scroll_count = 0; 319
320 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
321 s = &scroll[index];
322 if ( s->mode == SCROLL_MODE_RUN ||
323 s->mode == SCROLL_MODE_PAUSE ) {
324 /* restore scrolled row */
325 lcd_puts(s->startx, s->starty, s->text);
326 s->mode = SCROLL_MODE_OFF;
327 }
328 }
329
330 lcd_update();
331}
302 332
303 /* restore scrolled row */ 333void lcd_stop_scroll_line(int line)
304 lcd_puts(s->startx,s->starty,s->text); 334{
305 lcd_update(); 335 struct scrollinfo* s;
336 int index;
337
338 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
339 s = &scroll[index];
340 if ( s->startx == line &&
341 ( s->mode == SCROLL_MODE_RUN ||
342 s->mode == SCROLL_MODE_PAUSE )) {
343 /* restore scrolled row */
344 lcd_puts(s->startx, s->starty, s->text);
345 s->mode = SCROLL_MODE_OFF;
346 }
306 } 347 }
348
349 lcd_update();
307} 350}
308 351
309void lcd_scroll_pause(void) 352void lcd_scroll_pause(void)
310{ 353{
311 scroll_count = 0; 354 struct scrollinfo* s;
355 int index;
356
357 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
358 s = &scroll[index];
359 if ( s->mode == SCROLL_MODE_RUN ) {
360 s->mode = SCROLL_MODE_PAUSE;
361 }
362 }
363}
364
365void lcd_scroll_pause_line(int line)
366{
367 struct scrollinfo* s;
368 int index;
369
370 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
371 s = &scroll[index];
372 if ( s->startx == line &&
373 s->mode == SCROLL_MODE_RUN ) {
374 s->mode = SCROLL_MODE_PAUSE;
375 }
376 }
312} 377}
313 378
314void lcd_scroll_resume(void) 379void lcd_scroll_resume(void)
315{ 380{
316 scroll_count = 1; 381 struct scrollinfo* s;
382 int index;
383
384 scroll_start_tick = current_tick + HZ/2;
385
386 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
387 s = &scroll[index];
388 if ( s->mode == SCROLL_MODE_PAUSE ) {
389 s->mode = SCROLL_MODE_RUN;
390 }
391 }
392}
393
394void lcd_scroll_resume_line(int line)
395{
396 struct scrollinfo* s;
397 int index;
398
399 scroll_start_tick = current_tick + HZ/2;
400
401 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
402 s = &scroll[index];
403 if ( s->startx == line &&
404 s->mode == SCROLL_MODE_PAUSE ) {
405 s->mode = SCROLL_MODE_RUN;
406 }
407 }
317} 408}
318 409
319void lcd_scroll_speed(int speed) 410void lcd_scroll_speed(int speed)
@@ -323,36 +414,54 @@ void lcd_scroll_speed(int speed)
323 414
324static void scroll_thread(void) 415static void scroll_thread(void)
325{ 416{
326 struct scrollinfo* s = &scroll; 417 struct scrollinfo* s;
418 int index;
419 int i;
420 bool update;
421
422 /* initialize scroll struct array */
423 for (index = 0; index < SCROLLABLE_LINES; index++) {
424 scroll[index].mode = SCROLL_MODE_OFF;
425 }
426
427 scroll_start_tick = current_tick;
327 428
328 while ( 1 ) { 429 while ( 1 ) {
329 if ( !scroll_count ) { 430
330 yield(); 431 update = false;
331 continue; 432
332 }
333 /* wait 0.5s before starting scroll */ 433 /* wait 0.5s before starting scroll */
334 if ( scroll_count < scroll_speed/2 ) 434 if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
335 scroll_count++; 435
336 else { 436 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
337 int i; 437 s = &scroll[index];
338 for ( i=0; i<s->space-1; i++ ) 438 if ( s->mode == SCROLL_MODE_RUN ) {
339 s->line[i] = s->line[i+1]; 439 update = true;
340 440
341 if ( s->offset < s->textlen ) { 441 for ( i = 0; i < s->space - 1; i++ )
342 s->line[(int)s->space - 1] = s->text[(int)s->offset]; 442 s->line[i] = s->line[i+1];
343 s->offset++; 443
344 } 444 if ( s->offset < s->textlen ) {
345 else { 445 s->line[(int)s->space - 1] = s->text[(int)s->offset];
346 s->line[s->space - 1] = ' '; 446 s->offset++;
347 if ( s->offset < s->textlen + scroll_spacing - 1 ) 447 }
348 s->offset++; 448 else {
349 else 449 s->line[s->space - 1] = ' ';
350 s->offset = 0; 450 if ( s->offset < s->textlen + scroll_spacing - 1 )
451 s->offset++;
452 else
453 s->offset = 0;
454 }
455
456 lcd_puts(s->startx,s->starty,s->line);
457 }
351 } 458 }
352 459
353 lcd_puts(s->startx,s->starty,s->line); 460 if (update) {
354 lcd_update(); 461 lcd_update();
462 }
355 } 463 }
464
356 sleep(HZ/scroll_speed); 465 sleep(HZ/scroll_speed);
357 } 466 }
358} 467}
diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c
index 1c899307ed..10071dc3d7 100644
--- a/firmware/drivers/lcd-recorder.c
+++ b/firmware/drivers/lcd-recorder.c
@@ -70,7 +70,14 @@
70 70
71#define SCROLL_SPACING 3 71#define SCROLL_SPACING 3
72 72
73#define SCROLLABLE_LINES 10
74
75#define SCROLL_MODE_OFF 0
76#define SCROLL_MODE_PAUSE 1
77#define SCROLL_MODE_RUN 2
78
73struct scrollinfo { 79struct scrollinfo {
80 int mode;
74 char line[MAX_PATH + LCD_WIDTH/2 + SCROLL_SPACING + 2]; 81 char line[MAX_PATH + LCD_WIDTH/2 + SCROLL_SPACING + 2];
75 int len; /* length of line in chars */ 82 int len; /* length of line in chars */
76 int width; /* length of line in pixels */ 83 int width; /* length of line in pixels */
@@ -84,8 +91,8 @@ static char scroll_stack[DEFAULT_STACK_SIZE];
84static char scroll_name[] = "scroll"; 91static char scroll_name[] = "scroll";
85static char scroll_speed = 8; /* updates per second */ 92static char scroll_speed = 8; /* updates per second */
86static char scroll_step = 6; /* pixels per scroll step */ 93static char scroll_step = 6; /* pixels per scroll step */
87static struct scrollinfo scroll; /* only one scroll line at the moment */ 94static long scroll_start_tick;
88static int scroll_count = 0; 95static struct scrollinfo scroll[SCROLLABLE_LINES];
89static int xmargin = 0; 96static int xmargin = 0;
90static int ymargin = 0; 97static int ymargin = 0;
91static int curfont = FONT_SYSFIXED; 98static int curfont = FONT_SYSFIXED;
@@ -656,16 +663,26 @@ void lcd_invertpixel(int x, int y)
656 INVERT_PIXEL(x,y); 663 INVERT_PIXEL(x,y);
657} 664}
658 665
659void lcd_puts_scroll(int x, int y, unsigned char* string ) 666void lcd_puts_scroll(int x, int y, unsigned char* string)
660{ 667{
661 struct scrollinfo* s = &scroll; 668 struct scrollinfo* s;
662 int w, h; 669 int w, h;
670 int index;
671
672 scroll_start_tick = current_tick + HZ/2;
673
674 /* search for the next free entry */
675 for (index = 0; index < SCROLLABLE_LINES; index++) {
676 s = &scroll[index];
677 if (s->mode == SCROLL_MODE_OFF) {
678 break;
679 }
680 }
663 681
664 lcd_puts(x,y,string); 682 lcd_puts(x,y,string);
665 lcd_getstringsize(string, &w, &h); 683 lcd_getstringsize(string, &w, &h);
666 684
667 if (LCD_WIDTH - x*8 - xmargin < w) 685 if (LCD_WIDTH - x * 8 - xmargin < w) {
668 {
669 /* prepare scroll line */ 686 /* prepare scroll line */
670 char *end; 687 char *end;
671 688
@@ -678,42 +695,121 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
678 for (end = s->line; *end; end++); 695 for (end = s->line; *end; end++);
679 strncpy(end, string, LCD_WIDTH/2); 696 strncpy(end, string, LCD_WIDTH/2);
680 697
698 s->mode = SCROLL_MODE_RUN;
681 s->len = strlen(string); 699 s->len = strlen(string);
682 s->offset = 0; 700 s->offset = 0;
683 s->startx = x; 701 s->startx = x;
684 s->starty = y; 702 s->starty = y;
685 scroll_count = 1;
686 } 703 }
687} 704}
688 705
689
690void lcd_stop_scroll(void) 706void lcd_stop_scroll(void)
691{ 707{
692 if ( scroll_count ) { 708 struct scrollinfo* s;
693 int w,h; 709 int w,h;
694 struct scrollinfo* s = &scroll; 710 int index;
695 scroll_count = 0; 711
712 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
713 s = &scroll[index];
714 if ( s->mode == SCROLL_MODE_RUN ||
715 s->mode == SCROLL_MODE_PAUSE ) {
716 lcd_getstringsize(s->line, &w, &h);
717 lcd_clearrect(xmargin + s->startx * w / s->len,
718 ymargin + s->starty * h,
719 LCD_WIDTH - xmargin,
720 h);
721
722 /* restore scrolled row */
723 lcd_puts(s->startx, s->starty, s->line);
724 s->mode = SCROLL_MODE_OFF;
725 }
726 }
696 727
697 lcd_getstringsize(s->line, &w, &h); 728 lcd_update();
698 lcd_clearrect(xmargin + s->startx*w/s->len, 729}
699 ymargin + s->starty*h,
700 LCD_WIDTH - xmargin,
701 h);
702 730
703 /* restore scrolled row */ 731void lcd_stop_scroll_line(int line)
704 lcd_puts(s->startx,s->starty,s->line); 732{
705 lcd_update(); 733 struct scrollinfo* s;
734 int w,h;
735 int index;
736
737 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
738 s = &scroll[index];
739 if ( s->startx == line &&
740 ( s->mode == SCROLL_MODE_RUN ||
741 s->mode == SCROLL_MODE_PAUSE )) {
742 lcd_getstringsize(s->line, &w, &h);
743 lcd_clearrect(xmargin + s->startx * w / s->len,
744 ymargin + s->starty * h,
745 LCD_WIDTH - xmargin,
746 h);
747
748 /* restore scrolled row */
749 lcd_puts(s->startx, s->starty, s->line);
750 s->mode = SCROLL_MODE_OFF;
751 }
706 } 752 }
753
754 lcd_update();
707} 755}
708 756
709void lcd_scroll_pause(void) 757void lcd_scroll_pause(void)
710{ 758{
711 scroll_count = 0; 759 struct scrollinfo* s;
760 int index;
761
762 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
763 s = &scroll[index];
764 if ( s->mode == SCROLL_MODE_RUN ) {
765 s->mode = SCROLL_MODE_PAUSE;
766 }
767 }
768}
769
770void lcd_scroll_pause_line(int line)
771{
772 struct scrollinfo* s;
773 int index;
774
775 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
776 s = &scroll[index];
777 if ( s->startx == line &&
778 s->mode == SCROLL_MODE_RUN ) {
779 s->mode = SCROLL_MODE_PAUSE;
780 }
781 }
712} 782}
713 783
714void lcd_scroll_resume(void) 784void lcd_scroll_resume(void)
715{ 785{
716 scroll_count = 1; 786 struct scrollinfo* s;
787 int index;
788
789 scroll_start_tick = current_tick + HZ/2;
790
791 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
792 s = &scroll[index];
793 if ( s->mode == SCROLL_MODE_PAUSE ) {
794 s->mode = SCROLL_MODE_RUN;
795 }
796 }
797}
798
799void lcd_scroll_resume_line(int line)
800{
801 struct scrollinfo* s;
802 int index;
803
804 scroll_start_tick = current_tick + HZ/2;
805
806 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
807 s = &scroll[index];
808 if ( s->startx == line &&
809 s->mode == SCROLL_MODE_PAUSE ) {
810 s->mode = SCROLL_MODE_RUN;
811 }
812 }
717} 813}
718 814
719void lcd_scroll_speed(int speed) 815void lcd_scroll_speed(int speed)
@@ -723,33 +819,50 @@ void lcd_scroll_speed(int speed)
723 819
724static void scroll_thread(void) 820static void scroll_thread(void)
725{ 821{
726 struct scrollinfo* s = &scroll; 822 struct scrollinfo* s;
823 int index;
824 int w, h;
825 int xpos, ypos;
826 bool update;
827
828 /* initialize scroll struct array */
829 for (index = 0; index < SCROLLABLE_LINES; index++) {
830 scroll[index].mode = SCROLL_MODE_OFF;
831 }
832
833 scroll_start_tick = current_tick;
727 834
728 while ( 1 ) { 835 while ( 1 ) {
729 if ( !scroll_count ) { 836
730 yield(); 837 update = false;
731 continue; 838
732 }
733 /* wait 0.5s before starting scroll */ 839 /* wait 0.5s before starting scroll */
734 if ( scroll_count < scroll_speed/2 ) 840 if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
735 scroll_count++;
736 else {
737 int w, h;
738 int xpos, ypos;
739 841
740 s->offset += scroll_step; 842 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
843 s = &scroll[index];
844 if ( s->mode == SCROLL_MODE_RUN ) {
845 update = true;
741 846
742 if (s->offset >= s->width) 847 s->offset += scroll_step;
743 s->offset %= s->width;
744 848
745 lcd_getstringsize(s->line, &w, &h); 849 if (s->offset >= s->width)
746 xpos = xmargin + s->startx * w / s->len; 850 s->offset %= s->width;
747 ypos = ymargin + s->starty * h; 851
852 lcd_getstringsize(s->line, &w, &h);
853 xpos = xmargin + s->startx * w / s->len;
854 ypos = ymargin + s->starty * h;
855
856 lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h);
857 lcd_putsxyofs(xpos, ypos, s->offset, s->line);
858 }
859 }
748 860
749 lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h); 861 if (update) {
750 lcd_putsxyofs(xpos, ypos, s->offset, s->line); 862 lcd_update();
751 lcd_update(); 863 }
752 } 864 }
865
753 sleep(HZ/scroll_speed); 866 sleep(HZ/scroll_speed);
754 } 867 }
755} 868}
diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h
index e0cc8d9819..29f4362dcf 100644
--- a/firmware/drivers/lcd.h
+++ b/firmware/drivers/lcd.h
@@ -31,10 +31,13 @@ extern void lcd_backlight(bool on);
31extern void lcd_puts(int x, int y, unsigned char *string); 31extern void lcd_puts(int x, int y, unsigned char *string);
32extern void lcd_putc(int x, int y, unsigned char ch); 32extern void lcd_putc(int x, int y, unsigned char ch);
33extern void lcd_scroll_pause(void); 33extern void lcd_scroll_pause(void);
34extern void lcd_scroll_pause_line(int line);
34extern void lcd_scroll_resume(void); 35extern void lcd_scroll_resume(void);
36extern void lcd_scroll_resume_line(int line);
35extern void lcd_puts_scroll(int x, int y, unsigned char* string ); 37extern void lcd_puts_scroll(int x, int y, unsigned char* string );
36extern void lcd_icon(int icon, bool enable); 38extern void lcd_icon(int icon, bool enable);
37extern void lcd_stop_scroll(void); 39extern void lcd_stop_scroll(void);
40extern void lcd_stop_scroll_line(int line);
38extern void lcd_scroll_speed( int speed ); 41extern void lcd_scroll_speed( int speed );
39extern void lcd_set_contrast(int val); 42extern void lcd_set_contrast(int val);
40extern void lcd_write( bool command, int byte ); 43extern void lcd_write( bool command, int byte );