From b8b03370e4a3e1ec20324e9055065c77873e30f7 Mon Sep 17 00:00:00 2001 From: Rob Purchase Date: Sun, 23 Mar 2008 19:56:11 +0000 Subject: D2: Implement LCD driver framebuffer as per E200/Gigabeat F. Kill a few warnings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16763 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 5 +- firmware/export/config-cowond2.h | 4 +- firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c | 139 ++++++++++++++++++---- 3 files changed, 122 insertions(+), 26 deletions(-) diff --git a/firmware/SOURCES b/firmware/SOURCES index cf96d48e72..6ef129f4b9 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -893,10 +893,9 @@ target/arm/tcc77x/iaudio7/power-iaudio7.c #ifdef COWON_D2 #ifndef SIMULATOR +target/arm/lcd-as-memframe.S target/arm/tcc780x/adc-tcc780x.c target/arm/tcc780x/ata-nand-tcc780x.c -target/arm/tcc780x/kernel-tcc780x.c -target/arm/tcc780x/timer-tcc780x.c target/arm/tcc780x/system-tcc780x.c target/arm/tcc780x/cowond2/button-cowond2.c target/arm/tcc780x/cowond2/lcd-cowond2.c @@ -904,6 +903,8 @@ target/arm/tcc780x/cowond2/power-cowond2.c target/arm/tcc780x/cowond2/powermgmt-cowond2.c target/arm/tcc780x/cowond2/usb-cowond2.c #ifndef BOOTLOADER +target/arm/tcc780x/kernel-tcc780x.c +target/arm/tcc780x/timer-tcc780x.c target/arm/wmcodec-telechips.c target/arm/tcc780x/debug-tcc780x.c target/arm/tcc780x/cowond2/pcm-cowond2.c diff --git a/firmware/export/config-cowond2.h b/firmware/export/config-cowond2.h index 9363f67683..2574c51208 100644 --- a/firmware/export/config-cowond2.h +++ b/firmware/export/config-cowond2.h @@ -23,10 +23,10 @@ #define HAVE_LCD_COLOR /* define this if you can flip your LCD */ -#define HAVE_LCD_FLIP +/* #define HAVE_LCD_FLIP */ /* define this if you can invert the colours on your LCD */ -#define HAVE_LCD_INVERT +/* #define HAVE_LCD_INVERT */ /* define this if you want album art for this target */ #define HAVE_ALBUMART diff --git a/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c b/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c index 7514f93886..097dec31d3 100644 --- a/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c @@ -52,6 +52,10 @@ /* Power and display status */ static bool display_on = false; /* Is the display turned on? */ +static unsigned lcd_yuv_options = 0; + +/* Framebuffer copy as seen by the hardware */ +fb_data lcd_driver_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH]; int lcd_default_contrast(void) { @@ -60,8 +64,8 @@ int lcd_default_contrast(void) void lcd_set_contrast(int val) { - /* iirc there is an ltv250qv command to do this */ - #warning function not implemented + /* TODO: This won't be implemented until the S6F2002 controller + is better understood (nb: registers 16-23 control gamma). */ (void)val; } @@ -265,7 +269,7 @@ void lcd_init_device(void) LCDC_VTIME1 = LCDC_VTIME3 = (0<<16) | 239; LCDC_VTIME2 = LCDC_VTIME4 = (1<<16) | 3; - LCDC_I1BASE = (unsigned int)lcd_framebuffer; /* dirty, dirty hack */ + LCDC_I1BASE = (unsigned int)lcd_driver_framebuffer; LCDC_I1SIZE = (LCD_HEIGHT<<16) | LCD_WIDTH; /* image 1 size */ LCDC_I1POS = (0<<16) | 0; /* position */ LCDC_I1OFF = 0; /* address offset */ @@ -295,42 +299,81 @@ void lcd_init_device(void) /*** Update functions ***/ +/* Copies a rectangle from one framebuffer to another. Can be used in + single transfer mode with width = num pixels, and height = 1 which + allows a full-width rectangle to be copied more efficiently. */ +extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, + int width, int height); + /* Update the display. This must be called after all other LCD functions that change the display. */ void lcd_update(void) ICODE_ATTR; void lcd_update(void) { - #warning function not implemented - /* currently lcd_framebuffer is accessed directly by the hardware */ + if (!display_on) + return; + + lcd_copy_buffer_rect(&lcd_driver_framebuffer[0][0], + &lcd_framebuffer[0][0], LCD_WIDTH*LCD_HEIGHT, 1); } /* Update a fraction of the display. */ void lcd_update_rect(int, int, int, int) ICODE_ATTR; void lcd_update_rect(int x, int y, int width, int height) { - #warning function not implemented - (void)x; - (void)y; - (void)width; - (void)height; + fb_data *dst, *src; + + if (!display_on) + return; + + if (x + width > LCD_WIDTH) + width = LCD_WIDTH - x; /* Clip right */ + if (x < 0) + width += x, x = 0; /* Clip left */ + if (width <= 0) + return; /* nothing left to do */ + + if (y + height > LCD_HEIGHT) + height = LCD_HEIGHT - y; /* Clip bottom */ + if (y < 0) + height += y, y = 0; /* Clip top */ + if (height <= 0) + return; /* nothing left to do */ + + /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer + * and lcd_framebuffer */ + dst = &lcd_driver_framebuffer[y][x]; + src = &lcd_framebuffer[y][x]; + + /* Copy part of the Rockbox framebuffer to the second framebuffer */ + if (width < LCD_WIDTH) + { + /* Not full width - do line-by-line */ + lcd_copy_buffer_rect(dst, src, width, height); + } + else + { + /* Full width - copy as one line */ + lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); + } } void lcd_set_flip(bool yesno) { - #warning function not implemented + // TODO (void)yesno; } void lcd_set_invert_display(bool yesno) { - #warning function not implemented + // TODO (void)yesno; } void lcd_blit(const fb_data* data, int bx, int y, int bwidth, int height, int stride) { - #warning function not implemented + // TODO (void)data; (void)bx; (void)y; @@ -339,17 +382,69 @@ void lcd_blit(const fb_data* data, int bx, int y, int bwidth, (void)stride; } +void lcd_yuv_set_options(unsigned options) +{ + lcd_yuv_options = options; +} + +/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ +extern void lcd_write_yuv420_lines(fb_data *dst, + unsigned char const * const src[3], + int width, + int stride); +extern void lcd_write_yuv420_lines_odither(fb_data *dst, + unsigned char const * const src[3], + int width, + int stride, + int x_screen, /* To align dither pattern */ + int y_screen); + +/* Performance function to blit a YUV bitmap directly to the LCD */ void lcd_yuv_blit(unsigned char * const src[3], int src_x, int src_y, int stride, int x, int y, int width, int height) { - #warning function not implemented - (void)src; - (void)src_x; - (void)src_y; - (void)stride; - (void)x; - (void)y; - (void)width; - (void)height; + unsigned char const * yuv_src[3]; + off_t z; + + if (!display_on) + return; + + /* Sorry, but width and height must be >= 2 or else */ + width &= ~1; + height >>= 1; + + y = LCD_WIDTH - 1 - y; + fb_data *dst = &lcd_driver_framebuffer[x][y]; + + z = stride*src_y; + yuv_src[0] = src[0] + z + src_x; + yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); + yuv_src[2] = src[2] + (yuv_src[1] - src[1]); + + if (lcd_yuv_options & LCD_YUV_DITHER) + { + do + { + lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x); + yuv_src[0] += stride << 1; /* Skip down two luma lines */ + yuv_src[1] += stride >> 1; /* Skip down one chroma line */ + yuv_src[2] += stride >> 1; + dst -= 2; + y -= 2; + } + while (--height > 0); + } + else + { + do + { + lcd_write_yuv420_lines(dst, yuv_src, width, stride); + yuv_src[0] += stride << 1; /* Skip down two luma lines */ + yuv_src[1] += stride >> 1; /* Skip down one chroma line */ + yuv_src[2] += stride >> 1; + dst -= 2; + } + while (--height > 0); + } } -- cgit v1.2.3