# HG changeset patch # User Paul Boddie # Date 1541698327 -3600 # Node ID e83be2917e9a90f6a286cf2bbd1ccda54f5f137c # Parent 6423c19b840b7bcfee5ee88c45b6f3f2122447df Fixed pixel positioning for single-channel timed transfers, introducing the line channel count in the display configuration structure, moving the initialisation of a default into the appropriate header file. diff -r 6423c19b840b -r e83be2917e9a examples/vga/main.c --- a/examples/vga/main.c Wed Nov 07 00:12:44 2018 +0100 +++ b/examples/vga/main.c Thu Nov 08 18:32:07 2018 +0100 @@ -39,17 +39,11 @@ /* CPU-based transfers: no channels. */ #ifdef TRANSFER_CPU -#define LINE_CHANNELS 0 #define SCROLL_XSTEP 1 /* DMA-based transfers: single channel by default. */ #else - -#ifndef LINE_CHANNELS -#define LINE_CHANNELS 1 -#endif - #define SCROLL_XSTEP LINE_CHANNELS #endif diff -r 6423c19b840b -r e83be2917e9a include/display.h --- a/include/display.h Wed Nov 07 00:12:44 2018 +0100 +++ b/include/display.h Thu Nov 08 18:32:07 2018 +0100 @@ -66,6 +66,10 @@ int line_multiplier; /* = scanlines / line_count */ + /* Number of line channels used for pixel data transfers. */ + + int line_channels; + /* Number of consecutive pixels provided by a framebuffer region. */ uint32_t cell_size; diff -r 6423c19b840b -r e83be2917e9a include/display_config.h --- a/include/display_config.h Wed Nov 07 00:12:44 2018 +0100 +++ b/include/display_config.h Thu Nov 08 18:32:07 2018 +0100 @@ -24,6 +24,23 @@ #include "display.h" #include "vga.h" +/* Define DMA channels if not indicated in the build configuration. */ + +/* CPU-based transfers: no channels. */ + +#ifdef TRANSFER_CPU +#define LINE_CHANNELS 0 + +/* DMA-based transfers: single channel by default. */ + +#else + +#ifndef LINE_CHANNELS +#define LINE_CHANNELS 1 +#endif + +#endif + /* Define a structure containing the display parameters. */ display_config_t display_config = { @@ -31,6 +48,7 @@ /* Define display properties. */ .scanlines = SCANLINES, + .line_channels = LINE_CHANNELS, .cell_size = CELL_SIZE, .transfer_cell_size = TRANSFER_CELL_SIZE, diff -r 6423c19b840b -r e83be2917e9a lib/display.c --- a/lib/display.c Wed Nov 07 00:12:44 2018 +0100 +++ b/lib/display.c Thu Nov 08 18:32:07 2018 +0100 @@ -121,8 +121,24 @@ int get_position(display_config_t *cfg, int x) { - int cell = x / cfg->cell_size, offset = x % cfg->cell_size; - int pos = (cell / 2) * cfg->cell_size + offset; + int cell, offset, pos; + + if (cfg->line_channels < 2) + return x; + + /* Determine which cell is providing the position and the offset of the + pixel within the cell. */ + + cell = x / cfg->cell_size; + offset = x % cfg->cell_size; + + /* Determine the resulting position within the divided-up data. */ + + pos = (cell / 2) * cfg->cell_size + offset; + + /* Return the final position within the entire data. All cells in + odd-numbered positions occur in the first half, all even-numbered cells + in the second half. */ return cell % 2 ? pos + cfg->line_length / 2 : pos; }