OSD working
authorlekernel <sebastien.bourdeauducq@lekernel.net>
Sat, 26 Jun 2010 11:40:39 +0000 (13:40 +0200)
committerlekernel <sebastien.bourdeauducq@lekernel.net>
Sat, 26 Jun 2010 11:40:39 +0000 (13:40 +0200)
software/demo/Makefile
software/demo/font.c
software/demo/font.h
software/demo/main.c
software/demo/osd.c
software/demo/osd.h
software/demo/rpipe.c

index e38fcc9..1e98e4d 100644 (file)
@@ -84,11 +84,20 @@ main.o: ../../software/include/hal/snd.h ../../software/include/hw/ac97.h
 main.o: ../../software/include/hw/common.h ../../software/include/hal/pfpu.h
 main.o: ../../software/include/hw/pfpu.h ../../software/include/hal/tmu.h
 main.o: ../../software/include/hw/tmu.h apipe.h rpipe.h renderer.h cpustats.h
-main.o: memstats.h shell.h
+main.o: memstats.h osd.h shell.h
 memstats.o: ../../software/include/base/board.h
 memstats.o: ../../software/include/hal/brd.h
 memstats.o: ../../software/include/hw/fmlmeter.h
 memstats.o: ../../software/include/hw/common.h
+osd.o: ../../software/include/hal/vga.h ../../software/include/hal/tmu.h
+osd.o: ../../software/include/hw/tmu.h ../../software/include/hw/common.h
+osd.o: ../../software/include/hw/sysctl.h ../../software/include/hw/gpio.h
+osd.o: ../../software/include/base/math.h
+osd.o: ../../software/include/base/system.h
+osd.o: ../../software/include/base/string.h
+osd.o: ../../software/include/base/stdlib.h
+osd.o: ../../software/include/base/fatfs.h
+osd.o: ../../software/include/base/blockdev.h font.h logo.h renderer.h osd.h
 renderer.o: ../../software/include/base/stdio.h
 renderer.o: ../../software/include/base/stdlib.h
 renderer.o: ../../software/include/base/string.h
@@ -107,7 +116,7 @@ rpipe.o: ../../software/include/base/math.h
 rpipe.o: ../../software/include/hw/interrupts.h
 rpipe.o: ../../software/include/hal/vga.h ../../software/include/hal/tmu.h
 rpipe.o: ../../software/include/hw/tmu.h ../../software/include/hw/common.h
-rpipe.o: renderer.h wave.h cpustats.h color.h line.h rpipe.h spam.h
+rpipe.o: renderer.h wave.h cpustats.h color.h line.h osd.h rpipe.h
 shell.o: ../../software/include/base/stdio.h
 shell.o: ../../software/include/base/stdlib.h
 shell.o: ../../software/include/base/string.h
index 067532e..07eefd6 100644 (file)
@@ -28,6 +28,16 @@ struct tff_file_hdr {
        unsigned int img_h;       /* height of font image */
 };
 
+static unsigned int i2u32(unsigned int *src)
+{
+       unsigned char *a = ((unsigned char *)src);
+       unsigned char *b = ((unsigned char *)src) + 1;
+       unsigned char *c = ((unsigned char *)src) + 2;
+       unsigned char *d = ((unsigned char *)src) + 3;
+       return ((unsigned int)(*a))      + (((unsigned int)(*b))<<8)
+           + (((unsigned int)(*c))<<16) + (((unsigned int)(*d))<<24);
+}
+
 void font_init_context(struct font_context *ctx, unsigned char *font, unsigned short *fb, int fb_w, int fb_h)
 {
        ctx->font = font;
@@ -36,26 +46,24 @@ void font_init_context(struct font_context *ctx, unsigned char *font, unsigned s
        ctx->fb_h = fb_h;
 }
 
-static void draw_pixel(struct font_context *ctx, int x, int y, unsigned char i)
+int font_get_height(struct font_context *ctx)
 {
-       if(x < 0) return;
-       if(x >= ctx->fb_w) return;
-       if(y < 0) return;
-       if(y >= ctx->fb_h) return;
-       ctx->fb[x+y*ctx->fb_w] = MAKERGB565(i >> 3, i >> 2, i >> 3);
+       struct tff_file_hdr *tff = (struct tff_file_hdr *)ctx->font;
+       return i2u32(&tff->img_h);
 }
 
-static unsigned int i2u32(unsigned int *src)
+static void draw_pixel(struct font_context *ctx, int x, int y, int r, unsigned char i)
 {
-       unsigned char *a = ((unsigned char *)src);
-       unsigned char *b = ((unsigned char *)src) + 1;
-       unsigned char *c = ((unsigned char *)src) + 2;
-       unsigned char *d = ((unsigned char *)src) + 3;
-       return ((unsigned int)(*a))      + (((unsigned int)(*b))<<8)
-           + (((unsigned int)(*c))<<16) + (((unsigned int)(*d))<<24);
+       /*if(x < 0) return;
+       if(x >= ctx->fb_w) return;
+       if(y < 0) return;
+       if(y >= ctx->fb_h) return;*/
+       if(r)
+               i = 255-i;
+       ctx->fb[x+y*ctx->fb_w] = MAKERGB565(i >> 3, i >> 2, i >> 3);
 }
 
-int font_draw_char(struct font_context *ctx, int x, int y, unsigned char c)
+int font_draw_char(struct font_context *ctx, int x, int y, int r, unsigned char c)
 {
        struct tff_file_hdr *tff = (struct tff_file_hdr *)ctx->font;
        unsigned char *font_img = ctx->font + sizeof(struct tff_file_hdr);
@@ -71,14 +79,14 @@ int font_draw_char(struct font_context *ctx, int x, int y, unsigned char c)
 
        for(dy=0;dy<h;dy++)
                for(dx=0;dx<w;dx++)
-                       draw_pixel(ctx, x+dx, y+dy, font_img[dx+dy*fw]);
+                       draw_pixel(ctx, x+dx, y+dy, r, font_img[dx+dy*fw]);
        return w;
 }
 
-void font_draw_string(struct font_context *ctx, int x, int y, char *str)
+void font_draw_string(struct font_context *ctx, int x, int y, int r, char *str)
 {
        while(*str) {
-               x += font_draw_char(ctx, x, y, (unsigned char)(*str));
+               x += font_draw_char(ctx, x, y, r, (unsigned char)(*str));
                str++;
        }
 }
index 8866637..cfa2acf 100644 (file)
@@ -27,8 +27,9 @@ struct font_context {
 };
 
 void font_init_context(struct font_context *ctx, unsigned char *font, unsigned short *fb, int fb_w, int fb_h);
-int font_draw_char(struct font_context *ctx, int x, int y, unsigned char c);
-void font_draw_string(struct font_context *ctx, int x, int y, char *str);
+int font_get_height(struct font_context *ctx);
+int font_draw_char(struct font_context *ctx, int x, int y, int r, unsigned char c);
+void font_draw_string(struct font_context *ctx, int x, int y, int r, char *str);
 
 #endif /* __FONT_H */
 
index f9f7b69..ee4a181 100644 (file)
@@ -74,6 +74,7 @@ int main()
                        shell_input(readchar());
                apipe_service();
                rpipe_service();
+               osd_service();
        }
        
        return 0;
index 581064d..c105a1a 100644 (file)
 
 #include <hal/vga.h>
 #include <hal/tmu.h>
-#include <math.h>
 #include <hw/sysctl.h>
 #include <hw/gpio.h>
+#include <math.h>
+#include <system.h>
+#include <string.h>
+#include <fatfs.h>
+#include <blockdev.h>
 
-#include "osd.h"
 #include "font.h"
 #include "logo.h"
+#include "renderer.h"
+#include "osd.h"
 
 int osd_x;
 int osd_y;
@@ -67,11 +72,7 @@ static void logo()
                        osd_fb[(x+OSD_W-LOGO_W-OSD_CORNER)+OSD_W*(y+OSD_CORNER)] = ((unsigned short *)logo_raw)[x+LOGO_W*y];
 }
 
-static int previous_keys;
-static int osd_alpha;
-static int osd_timer;
-
-#define OSD_MAX_ALPHA 40
+static void init_ui();
 
 void osd_init()
 {
@@ -90,19 +91,149 @@ void osd_init()
        round_corners();
        logo();
 
+       init_ui();
+}
+
+static int previous_keys;
+static int osd_alpha;
+static int osd_timer;
+
+#define OSD_DURATION 90
+#define OSD_MAX_ALPHA 40
+
+#define OSD_MAX_USER_X (OSD_W-OSD_CORNER-LOGO_W)
+
+#define MAX_PATCH_TITLE 45
+#define MAX_PATCHES 128
+static char current_patch[MAX_PATCH_TITLE+1];
+static char patchlist_filenames[MAX_PATCHES][13];
+static char patchlist_titles[MAX_PATCHES][MAX_PATCH_TITLE+1];
+static int patchlist_n;
+static int patchlist_sel;
+static int patchlist_page;
+
+static int patchlist_maxpage;
+static int patchlist_maxsel;
+
+static int patchlist_pending;
+
+static void clear_user_area()
+{
+       int x, y;
+       
+       for(y=OSD_CORNER;y<(OSD_H-OSD_CORNER);y++)
+               for(x=OSD_CORNER;x<OSD_MAX_USER_X;x++)
+                       osd_fb[x+y*OSD_W] = 0;
+}
+
+static void draw_user_area()
+{
+       int i;
+       int h;
+       int nel;
+       
+       clear_user_area();
+       h = font_get_height(&osd_font);
+       font_draw_string(&osd_font, OSD_CORNER, OSD_CORNER, 0, current_patch);
+       nel = patchlist_page < patchlist_maxpage ? 4 : patchlist_maxsel;
+       for(i=0;i<nel;i++)
+               font_draw_string(&osd_font, OSD_CORNER+20, OSD_CORNER+(i+1)*h, i == patchlist_sel, patchlist_titles[patchlist_page*4+i]);
+       flush_bridge_cache();
+}
+
+static void start_patch_from_list(int n)
+{
+       strcpy(current_patch, patchlist_titles[n]);
+       patchlist_pending = n;
+}
+
+static void process_keys(unsigned int keys)
+{
+       if(keys & GPIO_BTN1) {
+               if(patchlist_sel > 0)
+                       patchlist_sel--;
+               else if(patchlist_page > 0) {
+                       patchlist_page--;
+                       patchlist_sel = 3;
+               }
+       }
+       if(keys & GPIO_BTN3) {
+               if(patchlist_page < patchlist_maxpage) {
+                       if(patchlist_sel < 3)
+                               patchlist_sel++;
+                       else {
+                               patchlist_page++;
+                               patchlist_sel = 0;
+                       }
+               } else if(patchlist_sel < (patchlist_maxsel-1))
+                       patchlist_sel++;
+       }
+       if(keys & GPIO_BTN2)
+               start_patch_from_list(patchlist_page*4+patchlist_sel);
+
+       draw_user_area();
+}
+
+static int lscb(const char *filename, const char *longname, void *param)
+{
+       char *c;
+
+       if(strlen(longname) < 5) return 1;
+       c = (char *)longname + strlen(longname) - 5;
+       if(strcmp(c, ".milk") != 0) return 1;
+       strcpy(patchlist_filenames[patchlist_n], filename);
+       strncpy(patchlist_titles[patchlist_n], longname, MAX_PATCH_TITLE);
+       patchlist_titles[patchlist_n][MAX_PATCH_TITLE] = 0;
+       c = patchlist_titles[patchlist_n] + strlen(patchlist_titles[patchlist_n]) - 5;
+       if(strcmp(c, ".milk") == 0) *c = 0;
+       patchlist_n++;
+       return patchlist_n < MAX_PATCHES;
+}
+
+static void init_ui()
+{
        previous_keys = 0;
-       osd_alpha = OSD_MAX_ALPHA;
-       osd_timer = 125;
+       osd_alpha = 0;
+       osd_timer = OSD_DURATION;
+
+       patchlist_n = 0;
+       patchlist_sel = 0;
+       patchlist_page = 0;
+       patchlist_pending = -1;
+
+       if(!fatfs_init(BLOCKDEV_FLASH, 0)) return;
+       fatfs_list_files(lscb, NULL);
+       fatfs_done();
+
+       patchlist_maxpage = (patchlist_n+3)/4 - 1;
+       patchlist_maxsel = patchlist_n % 4;
+       
+       if(patchlist_n > 0)
+               start_patch_from_list(0);
 
        font_init_context(&osd_font, vera20_tff, osd_fb, OSD_W, OSD_H);
-       font_draw_string(&osd_font, OSD_CORNER, OSD_CORNER, "Rovastar - Touchdown on Mars");
+       draw_user_area();
 }
 
-static void process_keys(unsigned int keys)
+void osd_service()
 {
+       if(patchlist_pending != -1) {
+               char buffer[8192];
+               int size;
+               int n;
+
+               n = patchlist_pending;
+               patchlist_pending = -1;
+               if(!fatfs_init(BLOCKDEV_FLASH, 0)) return;
+               if(!fatfs_load(patchlist_filenames[n], buffer, sizeof(buffer), &size)) return;
+               fatfs_done();
+               buffer[size] = 0;
+
+               renderer_start(buffer);
+       }
 }
 
-static void osd_service()
+int osd_fill_blit_td(struct tmu_td *td, tmu_callback callback, void *user)
 {
        unsigned int keys;
        unsigned int new_keys;
@@ -112,7 +243,7 @@ static void osd_service()
        previous_keys = keys;
 
        if(new_keys) {
-               osd_timer = 125;
+               osd_timer = OSD_DURATION;
                if(osd_alpha != 0)
                        process_keys(new_keys);
        }
@@ -127,11 +258,6 @@ static void osd_service()
                if(osd_alpha < 0)
                        osd_alpha = 0;
        }
-}
-
-int osd_fill_blit_td(struct tmu_td *td, tmu_callback callback, void *user)
-{
-       osd_service();
 
        td->flags = TMU_CTL_CHROMAKEY;
        td->hmeshlast = 1;
@@ -157,3 +283,4 @@ int osd_fill_blit_td(struct tmu_td *td, tmu_callback callback, void *user)
 
        return osd_alpha != 0;
 }
+
index d534d96..6562c29 100644 (file)
@@ -22,5 +22,6 @@
 
 void osd_init();
 int osd_fill_blit_td(struct tmu_td *td, tmu_callback callback, void *user);
+void osd_service();
 
 #endif /* __OSD_H */
index 62711ee..34fe872 100644 (file)
@@ -29,6 +29,7 @@
 #include "cpustats.h"
 #include "color.h"
 #include "line.h"
+#include "osd.h"
 #include "rpipe.h"
 
 #define RPIPE_FRAMEQ_SIZE 4 /* < must be a power of 2 */