1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-07-05 02:19:49 +03:00

ubb-vga: express mode data in more common units and remove hard-coded constants

- ubb-vga.h (struct mode), ubb-vga.c (mode_db): replaced hsync_end with
  its constituends hsync_cycles and hback_cycles
- ubb-vga.h (struct mode), ubb-vga.c (mode_db): added vsync_lines,
  vfront_lines, and vback_lines
- ubb-vga.h (struct mode): changed "line_cycles" from "int" to
  "uint16_t"
- ubb-vga.c (line): don't hard-code horizontal back porch
- ubb-vga.c (line): don't hard-code sum of horizontal back porch and
  hsync
- ubb-vga.c (hdelay): don't hard-code hsync
- ubb-vga.c (frame): don't hard-code vsync and the vertical porches
- ubb-vga.c (frame): don't hard-code hsync and horizontal back porch
This commit is contained in:
Werner Almesberger 2011-05-01 20:59:38 -03:00
parent aa2fc7101d
commit 4b59dbf062
2 changed files with 35 additions and 20 deletions

View File

@ -49,15 +49,18 @@ static int bad;
static const struct mode mode_db[] = { static const struct mode mode_db[] = {
{ "640x480", 640, 480, 11, US(29.7), US(0.79+3.77-0.3) }, /* name xres yres clkdiv vfront hsync hback htotal */
{ "800x600", 800, 600, 8, US(28.7), US(2.0+3.3+0.3) }, /* vsync vback */
{ "640x480", 640, 480, 11, 2, 32, 14, US(3.47), US(0.79), US(29.7) },
{ "800x600", 800, 600, 8, 2, 32, 14, US(4.81), US(0.79), US(28.7) },
/* the next one may work after adjusting the timing in "frame" */ /* the next one may work after adjusting the timing in "frame" */
{ "800x600", 800, 600, 8, US(28.2), US(2.0+3.3+0.3-0.3) }, { "800x600", 800, 600, 8, 2, 32, 14, US(4.51), US(0.79), US(28.2) },
/* the 1024x768 below is not great but has good parameter tolerance */ /* the 1024x768 below is not great but has good parameter tolerance */
{ "1024x768", 1024, 768, 8, US(36.0), US(2.0+3.3) }, { "1024x768", 1024, 768, 8, 2, 32, 14, US(4.51), US(0.79), US(36.0) },
/* illustrate underruns */ /* illustrate underruns */
{ "1024x768ur", 1024, 768, 7, US(33.5), US(0.4+2.1+0.5) }, { "1024x768ur", 1024, 768, 7, 2, 32, 14, US(2.21), US(0.79), US(33.5) },
{ "1024x768/53", 1024, 768, 5, US(23.1), US(0.4+2.1-0.4) }, { "1024x768/53",1024, 768, 5, 2, 32, 14, US(1.31), US(0.79), US(23.1) },
{ NULL } { NULL }
}; };
@ -274,7 +277,7 @@ static void line(unsigned long line)
DTA(DMA) = REG_PADDR(MSC_TXFIFO); /* MUST set this each time */ DTA(DMA) = REG_PADDR(MSC_TXFIFO); /* MUST set this each time */
DTC(DMA) = mode->xres >> 6; DTC(DMA) = mode->xres >> 6;
until(US(0.79)); until(mode->hback_cycles);
/* HSYNC */ /* HSYNC */
@ -295,7 +298,7 @@ static void line(unsigned long line)
(1 << 31) | /* no descriptor */ (1 << 31) | /* no descriptor */
1; 1;
until(mode->hsync_end); until(mode->hback_cycles+mode->hsync_cycles);
// MSC_TXFIFO = 0xffffffff; // MSC_TXFIFO = 0xffffffff;
@ -316,7 +319,7 @@ static void hdelay(int cycles)
while (cycles--) { while (cycles--) {
TCNT(TIMER) = 0; TCNT(TIMER) = 0;
PDDATC = HSYNC; PDDATC = HSYNC;
until(US(3.77)); until(mode->hsync_cycles);
PDDATS = HSYNC; PDDATS = HSYNC;
until(mode->line_cycles); until(mode->line_cycles);
} }
@ -329,12 +332,12 @@ static void frame(const unsigned long *f)
/* VSYNC */ /* VSYNC */
PDDATC = VSYNC; PDDATC = VSYNC;
hdelay(2); hdelay(mode->vsync_lines);
PDDATS = VSYNC; PDDATS = VSYNC;
/* Front porch */ /* Front porch */
hdelay(31); hdelay(mode->vfront_lines-1);
/* /*
* The horizontal back porch of the previous line is handled inside * The horizontal back porch of the previous line is handled inside
@ -342,9 +345,9 @@ static void frame(const unsigned long *f)
*/ */
TCNT(TIMER) = 0; TCNT(TIMER) = 0;
PDDATC = HSYNC; PDDATC = HSYNC;
until(US(3.77)); until(mode->hsync_cycles);
PDDATS = HSYNC; PDDATS = HSYNC;
until(mode->line_cycles-US(0.79)); until(mode->line_cycles-mode->hback_cycles);
/* /*
* Note: resetting the timer just before calling "line" isn't enough. * Note: resetting the timer just before calling "line" isn't enough.
@ -358,7 +361,7 @@ static void frame(const unsigned long *f)
} }
/* Back porch */ /* Back porch */
hdelay(14); hdelay(mode->vback_lines);
} }
@ -448,6 +451,14 @@ int main(int argc, char *const *argv)
usage(*argv); usage(*argv);
} }
#if 0
#define CYCLES(cy) ((cy)/112.0+0.5)
printf("V: %d+%d+%d+%d\n", mode->vsync_lines, mode->vfront_lines,
mode->yres, mode->vback_lines);
printf("H: %4.1f+?+?+%4.1f (%4.1f)\n", CYCLES(mode->hsync_cycles),
CYCLES(mode->hback_cycles), CYCLES(mode->line_cycles));
#endif
setup(); setup();
session(gen, frames); session(gen, frames);
cleanup(); cleanup();

View File

@ -27,8 +27,12 @@ struct mode {
const char *name; /* NULL for end of table */ const char *name; /* NULL for end of table */
int xres, yres; int xres, yres;
int clkdiv; /* pixel clock = 336 MHz/(clkdiv+1) */ int clkdiv; /* pixel clock = 336 MHz/(clkdiv+1) */
int line_cycles; /* 31.77 us for official VGA */ int vsync_lines; /* 2 lines, for official VGA */
int hsync_end; /* 0.79+3.77 us for official VGA */ int vfront_lines; /* 32 lines */
int vback_lines; /* 14 lines */
uint16_t hsync_cycles; /* 3.77 us */
uint16_t hback_cycles; /* 0.79 us */
uint16_t line_cycles; /* 31.77 us */
}; };
extern const struct mode *mode; extern const struct mode *mode;