summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg White <gwhite@rockbox.org>2007-01-04 11:43:33 +0000
committerGreg White <gwhite@rockbox.org>2007-01-04 11:43:33 +0000
commit9d0faed29ce2293ce35ed8ba0dcba779b50f50a8 (patch)
treebcbb4cd78b863ded1d84bae94b7cccc81ddfe5be
parentdd7b75bd2c716f888b49ff50afc1f621157f394b (diff)
Use DMA for Blit to screen/clear
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11906 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/lcd-16bit.c68
-rw-r--r--firmware/export/lcd.h6
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c294
3 files changed, 217 insertions, 151 deletions
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
index 6e5c31c0a5..949f80ffbc 100644
--- a/firmware/drivers/lcd-16bit.c
+++ b/firmware/drivers/lcd-16bit.c
@@ -33,6 +33,11 @@
#include "font.h"
#include "rbunicode.h"
#include "bidi.h"
+#if defined(TOSHIBA_GIGABEAT_F)
+#define NON_GB_STATIC
+#else
+#define NON_GB_STATIC static
+#endif
#define SCROLLABLE_LINES ((LCD_HEIGHT+4)/5 < 32 ? (LCD_HEIGHT+4)/5 : 32)
@@ -45,11 +50,12 @@ enum fill_opt {
/*** globals ***/
fb_data lcd_framebuffer[LCD_HEIGHT][LCD_WIDTH] IRAM_LCDFRAMEBUFFER __attribute__ ((aligned (16)));
+
static fb_data* lcd_backdrop = NULL;
static long lcd_backdrop_offset IDATA_ATTR = 0;
-static unsigned fg_pattern IDATA_ATTR = LCD_DEFAULT_FG;
-static unsigned bg_pattern IDATA_ATTR = LCD_DEFAULT_BG;
+NON_GB_STATIC unsigned fg_pattern IDATA_ATTR = LCD_DEFAULT_FG;
+NON_GB_STATIC unsigned bg_pattern IDATA_ATTR = LCD_DEFAULT_BG;
static int drawmode = DRMODE_SOLID;
static int xmargin = 0;
static int ymargin = 0;
@@ -75,9 +81,12 @@ static const char scroll_tick_table[16] = {
/* LCD init */
void lcd_init(void)
{
- lcd_clear_display();
- /* Call device specific init */
- lcd_init_device();
+ lcd_clear_display();
+
+ /* Call device specific init */
+ lcd_init_device();
+
+
create_thread(scroll_thread, scroll_stack,
sizeof(scroll_stack), scroll_name
IF_PRIO(, PRIORITY_USER_INTERFACE));
@@ -95,20 +104,24 @@ int lcd_get_drawmode(void)
return drawmode;
}
+#if !defined(TOSHIBA_GIGABEAT_F)
void lcd_set_foreground(unsigned color)
{
fg_pattern = color;
}
+#endif
unsigned lcd_get_foreground(void)
{
return fg_pattern;
}
+#if !defined(TOSHIBA_GIGABEAT_F)
void lcd_set_background(unsigned color)
{
bg_pattern = color;
}
+#endif
unsigned lcd_get_background(void)
{
@@ -201,12 +214,13 @@ void lcd_set_backdrop(fb_data* backdrop)
{
lcd_backdrop_offset = (long)backdrop - (long)&lcd_framebuffer[0][0];
lcd_fastpixelfuncs = lcd_fastpixelfuncs_backdrop;
- }
- else
+ }
+ else
{
lcd_backdrop_offset = 0;
lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
}
+ lcd_device_prepare_backdrop(backdrop);
}
fb_data* lcd_get_backdrop(void)
@@ -217,10 +231,11 @@ fb_data* lcd_get_backdrop(void)
/*** drawing functions ***/
/* Clear the whole display */
+#if !defined(TOSHIBA_GIGABEAT_F)
void lcd_clear_display(void)
{
- fb_data *dst = LCDADDR(0, 0);
-
+ fb_data *dst = LCDADDR(0, 0);
+
if (drawmode & DRMODE_INVERSEVID)
{
memset16(dst, fg_pattern, LCD_WIDTH*LCD_HEIGHT);
@@ -234,6 +249,7 @@ void lcd_clear_display(void)
}
scrolling_lines = 0;
}
+#endif
/* Set a single pixel */
void lcd_drawpixel(int x, int y)
@@ -329,17 +345,17 @@ void lcd_hline(int x1, int x2, int y)
x1 = x2;
x2 = x;
}
-
+
/* nothing to draw? */
if (((unsigned)y >= LCD_HEIGHT) || (x1 >= LCD_WIDTH) || (x2 < 0))
- return;
-
+ return;
+
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= LCD_WIDTH)
x2 = LCD_WIDTH-1;
-
+
if (drawmode & DRMODE_INVERSEVID)
{
if (drawmode & DRMODE_BG)
@@ -363,7 +379,7 @@ void lcd_hline(int x1, int x2, int y)
}
dst = LCDADDR(x1, y);
width = x2 - x1 + 1;
-
+
switch (fillopt)
{
case OPT_SET:
@@ -401,14 +417,14 @@ void lcd_vline(int x, int y1, int y2)
/* nothing to draw? */
if (((unsigned)x >= LCD_WIDTH) || (y1 >= LCD_HEIGHT) || (y2 < 0))
- return;
-
+ return;
+
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCD_HEIGHT)
y2 = LCD_HEIGHT-1;
-
+
dst = LCDADDR(x, y1);
dst_end = dst + (y2 - y1) * LCD_WIDTH;
@@ -463,7 +479,7 @@ void lcd_fillrect(int x, int y, int width, int height)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
-
+
if (drawmode & DRMODE_INVERSEVID)
{
if (drawmode & DRMODE_BG)
@@ -544,7 +560,7 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
-
+
/* clipping */
if (x < 0)
{
@@ -577,7 +593,7 @@ void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
unsigned data = *src_col >> src_y;
fb_data *dst_col = dst++;
int numbits = 8 - src_y;
-
+
dst_end = dst_col + height * LCD_WIDTH;
do
{
@@ -620,7 +636,7 @@ void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
-
+
/* clipping */
if (x < 0)
{
@@ -672,7 +688,7 @@ void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
-
+
/* clipping */
if (x < 0)
{
@@ -742,7 +758,7 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str)
bits = font_get_bits(pf, ch);
lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs, pf->height);
-
+
x += width - ofs;
ofs = 0;
}
@@ -850,8 +866,8 @@ void lcd_puts_scroll_style(int x, int y, const unsigned char *string, int style)
void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, int offset)
{
lcd_puts_scroll_style_offset(x, y, string, STYLE_DEFAULT, offset);
-}
-
+}
+
void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
int style, int offset)
{
@@ -963,7 +979,7 @@ static void scroll_thread(void)
}
lastmode = drawmode;
- drawmode = s->invert ?
+ drawmode = s->invert ?
(DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
lcd_putsxyofs(xpos, ypos, s->offset, s->line);
drawmode = lastmode;
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 3e1ea4430b..fc0562419c 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -345,6 +345,12 @@ extern unsigned lcd_get_background(void);
extern void lcd_set_drawinfo(int mode, unsigned foreground,
unsigned background);
void lcd_set_backdrop(fb_data* backdrop);
+#if !defined(TOSHIBA_GIGABEAT_F)
+#define lcd_device_prepare_backdrop(x) ;
+#else
+void lcd_device_prepare_backdrop(fb_data* backdrop);
+#endif
+
fb_data* lcd_get_backdrop(void);
extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
diff --git a/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
index df5be43551..754ee6dec4 100644
--- a/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
@@ -4,19 +4,42 @@
#include "lcd.h"
#include "kernel.h"
#include "system.h"
-
-void lcd_init_device(void);
-void lcd_update_rec(int, int, int, int);
-void lcd_update(void);
-
-bool usedmablit = false;
+#include "mmu-meg-fx.h"
+#include <stdlib.h>
+#include "memory.h"
+#include "lcd-target.h"
+
+/*
+** We prepare foreground and background fills ahead of time - DMA fills in 16 byte groups
+*/
+unsigned long fg_pattern_blit[4];
+unsigned long bg_pattern_blit[4];
+
+volatile bool use_dma_blit = false;
+volatile bool lcd_on = true;
+volatile bool lcd_poweroff = true;
+/*
+** These are imported from lcd-16bit.c
+*/
+extern unsigned fg_pattern;
+extern unsigned bg_pattern;
+
+extern volatile bool lcd_on;
/* LCD init */
void lcd_init_device(void)
{
+ memset16(fg_pattern_blit, fg_pattern, sizeof(fg_pattern_blit)/2);
+ memset16(bg_pattern_blit, bg_pattern, sizeof(bg_pattern_blit)/2);
+ clean_dcache_range((void *)fg_pattern_blit, sizeof(fg_pattern_blit));
+ clean_dcache_range((void *)bg_pattern_blit, sizeof(bg_pattern_blit));
+
/* Switch from 555I mode to 565 mode */
LCDCON5 |= 1 << 11;
-
+
+#if !defined(BOOTLOADER)
+ use_dma_blit = true;
+#endif
}
/* Update a fraction of the display. */
@@ -24,35 +47,159 @@ void lcd_update_rect(int x, int y, int width, int height)
{
(void)x;
(void)width;
-
- if (usedmablit)
+ (void)y;
+ (void)height;
+
+ if(!lcd_on)
+ {
+ yield();
+ return;
+ }
+ if (use_dma_blit)
{
- /* Spin waiting for DMA to become available */
- //while (DSTAT0 & (1<<20)) ;
- if (DSTAT0 & (1<<20)) return;
-
+ /* Wait for this controller to stop pending transfer */
+ while((DSTAT1 & 0x000fffff))
+ yield();
+
+ /* Flush DCache */
+ invalidate_dcache_range((void *)(((int) &lcd_framebuffer)+(y * sizeof(fb_data) * LCD_WIDTH)), (height * sizeof(fb_data) * LCD_WIDTH));
+
/* set DMA dest */
- DIDST0 = (int) FRAME + y * sizeof(fb_data) * LCD_WIDTH;
+ DIDST1 = ((int) FRAME) + (y * sizeof(fb_data) * LCD_WIDTH);
/* FRAME on AHB buf, increment */
- DIDSTC0 = 0;
- DCON0 = (((1<<30) | (1<<28) | (1<<27) | (1<<22) | (2<<20)) | ((height * sizeof(fb_data) * LCD_WIDTH) >> 4));
+ DIDSTC1 = 0;
+ /* Handshake on AHB, Burst transfer, Whole service, Don't reload, transfer 32-bits */
+ DCON1 = ((1<<30) | (1<<28) | (1<<27) | (1<<22) | (2<<20)) | ((height * sizeof(fb_data) * LCD_WIDTH) >> 4);
- /* set DMA source and options */
- DISRC0 = (int) &lcd_framebuffer + (y * sizeof(fb_data) * LCD_WIDTH) + 0x30000000;
- DISRCC0 = 0x00; /* memory is on AHB bus, increment addresses */
+ /* set DMA source */
+ DISRC1 = ((int) &lcd_framebuffer) + (y * sizeof(fb_data) * LCD_WIDTH) + 0x30000000;
+ /* memory is on AHB bus, increment addresses */
+ DISRCC1 = 0x00;
/* Activate the channel */
- DMASKTRIG0 = 0x2;
+ DMASKTRIG1 = 0x2;
+
/* Start DMA */
- DMASKTRIG0 |= 0x1;
+ DMASKTRIG1 |= 0x1;
+
+ /* Wait for transfer to complete */
+ while((DSTAT1 & 0x000fffff))
+ yield();
+ }
+ else
+ memcpy(((char*)FRAME) + (y * sizeof(fb_data) * LCD_WIDTH), ((char *)&lcd_framebuffer) + (y * sizeof(fb_data) * LCD_WIDTH), ((height * sizeof(fb_data) * LCD_WIDTH)));
+}
+
+
+void lcd_enable(bool state)
+{
+ if(state) {
+ if(lcd_poweroff) {
+ if(!lcd_on)
+ memcpy(FRAME, lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT*2);
+ lcd_on = true;
+ LCDCON1 |= 1;
+ }
+ }
+ else {
+ if(lcd_poweroff) {
+ lcd_on = false;
+ LCDCON1 &= ~1;
+ }
+ }
+}
+
+void lcd_set_foreground(unsigned color)
+{
+ fg_pattern = color;
+
+ memset16(fg_pattern_blit, fg_pattern, sizeof(fg_pattern_blit)/2);
+ clean_dcache_range((void *)fg_pattern_blit, sizeof(fg_pattern_blit));
+}
+
+void lcd_set_background(unsigned color)
+{
+ bg_pattern = color;
+ memset16(bg_pattern_blit, bg_pattern, sizeof(bg_pattern_blit)/2);
+ clean_dcache_range((void *)bg_pattern_blit, sizeof(bg_pattern_blit));
+}
+
+void lcd_device_prepare_backdrop(fb_data* backdrop)
+{
+ clean_dcache_range((void *)backdrop, (LCD_HEIGHT * sizeof(fb_data) * LCD_WIDTH));
+}
+
+void lcd_clear_display_dma(void)
+{
+ void *src;
+ bool inc = false;
+
+ if (lcd_get_drawmode() & DRMODE_INVERSEVID)
+ src = fg_pattern_blit;
+ else
+ {
+ fb_data* lcd_backdrop = lcd_get_backdrop();
+
+ if (!lcd_backdrop)
+ src = bg_pattern_blit;
+ else
+ {
+ src = lcd_backdrop;
+ inc = true;
+ }
+ }
+ /* Wait for any pending transfer to complete */
+ while((DSTAT3 & 0x000fffff))
+ yield();
+ DMASKTRIG3 |= 0x4; /* Stop controller */
+ DIDST3 = ((int) lcd_framebuffer) + 0x30000000; /* set DMA dest, physical address */
+ DIDSTC3 = 0; /* Dest on AHB, increment */
+
+ DISRC3 = ((int) src) + 0x30000000; /* Set source, in physical space */
+ DISRCC3 = inc ? 0x00 : 0x01; /* memory is on AHB bus, increment addresses based on backdrop */
+
+ /* Handshake on AHB, Burst mode, whole service mode, no reload, move 32-bits */
+ DCON3 = ((1<<30) | (1<<28) | (1<<27) | (1<<22) | (2<<20)) | ((LCD_HEIGHT * sizeof(fb_data) * LCD_WIDTH) >> 4);
+
+ /* Dump DCache for dest, we are about to overwrite it with DMA */
+ dump_dcache_range((void *)lcd_framebuffer, (LCD_HEIGHT * sizeof(fb_data) * LCD_WIDTH));
+ /* Activate the channel */
+ DMASKTRIG3 = 2;
+ /* Start DMA */
+ DMASKTRIG3 |= 1;
+
+ /* Wait for transfer to complete */
+ while((DSTAT3 & 0x000fffff))
+ yield();
+}
+
+void lcd_clear_display(void)
+{
+ if(use_dma_blit)
+ {
+ lcd_clear_display_dma();
+ return;
+ }
+
+ fb_data *dst = &lcd_framebuffer[0][0];
+
+ if (lcd_get_drawmode() & DRMODE_INVERSEVID)
+ {
+ memset16(dst, fg_pattern, LCD_WIDTH*LCD_HEIGHT);
}
else
{
- memcpy((void*)FRAME, &lcd_framebuffer, sizeof(lcd_framebuffer));
+ fb_data* lcd_backdrop = lcd_get_backdrop();
+ if (!lcd_backdrop)
+ memset16(dst, bg_pattern, LCD_WIDTH*LCD_HEIGHT);
+ else
+ memcpy(dst, lcd_backdrop, sizeof(lcd_framebuffer));
}
+ lcd_stop_scroll();
}
+
/* Update the display.
This must be called after all other LCD functions that change the display. */
void lcd_update(void)
@@ -164,7 +311,6 @@ void lcd_yuv_blit(unsigned char * const src[3],
}
-
void lcd_set_contrast(int val) {
(void) val;
// TODO:
@@ -192,105 +338,3 @@ void lcd_set_flip(bool yesno) {
// TODO:
}
-
-
-
-
-
-
-
-
-
-
-
-
-#if 0
-/* 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)
-{
- fb_data *dst, *dst_end;
-
- width = (width + 1) & ~1;
-
- dst = (fb_data*)FRAME + LCD_WIDTH * y + x;
- dst_end = dst + LCD_WIDTH * height;
-
- do
- {
- fb_data *dst_row = dst;
- fb_data *row_end = dst_row + width;
- const unsigned char *ysrc = src[0] + stride * src_y + src_x;
- int y, u, v;
- int red, green, blue;
- unsigned rbits, gbits, bbits;
-
- /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
- const unsigned char *usrc = src[1] + (stride/CSUB_X) * (src_y/CSUB_Y)
- + (src_x/CSUB_X);
- const unsigned char *vsrc = src[2] + (stride/CSUB_X) * (src_y/CSUB_Y)
- + (src_x/CSUB_X);
- int xphase = src_x % CSUB_X;
- int rc, gc, bc;
-
- u = *usrc++ - 128;
- v = *vsrc++ - 128;
- rc = RVFAC * v + ROUNDOFFS;
- gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
- bc = BUFAC * u + ROUNDOFFS;
-
- do
- {
- y = *ysrc++;
- red = RYFAC * y + rc;
- green = GYFAC * y + gc;
- blue = BYFAC * y + bc;
-
- if ((unsigned)red > (RYFAC*255+ROUNDOFFS))
- {
- if (red < 0)
- red = 0;
- else
- red = (RYFAC*255+ROUNDOFFS);
- }
- if ((unsigned)green > (GYFAC*255+ROUNDOFFS))
- {
- if (green < 0)
- green = 0;
- else
- green = (GYFAC*255+ROUNDOFFS);
- }
- if ((unsigned)blue > (BYFAC*255+ROUNDOFFS))
- {
- if (blue < 0)
- blue = 0;
- else
- blue = (BYFAC*255+ROUNDOFFS);
- }
- rbits = ((unsigned)red) >> 16 ;
- gbits = ((unsigned)green) >> 16 ;
- bbits = ((unsigned)blue) >> 16 ;
- *dst_row++ = (rbits << 11) | (gbits << 5) | bbits;
-
- if (++xphase >= CSUB_X)
- {
- u = *usrc++ - 128;
- v = *vsrc++ - 128;
- rc = RVFAC * v + ROUNDOFFS;
- gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
- bc = BUFAC * u + ROUNDOFFS;
- xphase = 0;
- }
- }
- while (dst_row < row_end);
-
- src_y++;
- dst += LCD_WIDTH;
- }
- while (dst < dst_end);
-}
-#endif
-
-
-