CommonPIC32

Changeset

123:6934a0847aed
2018-11-10 Paul Boddie raw files shortlog changelog graph Simplified display configuration initialisation.
examples/vga/main.c (file) include/display.h (file) include/vga_common.h (file) lib/display.c (file)
     1.1 --- a/examples/vga/main.c	Sat Nov 10 19:20:13 2018 +0100
     1.2 +++ b/examples/vga/main.c	Sat Nov 10 21:30:09 2018 +0100
     1.3 @@ -31,8 +31,8 @@
     1.4  /* Specific functionality. */
     1.5  
     1.6  #include "devconfig.h"
     1.7 -#include "display_config.h"
     1.8  #include "main.h"
     1.9 +#include "vga.h"
    1.10  
    1.11  
    1.12  
    1.13 @@ -87,13 +87,9 @@
    1.14  
    1.15  
    1.16  
    1.17 -/* Framebuffer memory. */
    1.18 -
    1.19 -static uint8_t framebuffer[FRAME_SIZE * FRAME_COUNT];
    1.20 +/* Initialise memory for a multi-frame display. */
    1.21  
    1.22 -/* Screen start values for each frame. */
    1.23 -
    1.24 -uint8_t *screen_starts[FRAME_COUNT];
    1.25 +static Display(display_config, LINE_LENGTH, LINE_COUNT, FRAME_COUNT);
    1.26  
    1.27  
    1.28  
    1.29 @@ -347,10 +343,9 @@
    1.30      uart_init(1, FPB, 115200);
    1.31      uart_on(1);
    1.32  
    1.33 -    /* Initialise memory for a double-buffered display. */
    1.34 +    /* Set the display to a well-defined state. */
    1.35  
    1.36 -    init_display(&display_config, framebuffer, LINE_LENGTH, LINE_COUNT,
    1.37 -                 FRAME_COUNT, screen_starts);
    1.38 +    init_display(&display_config);
    1.39  
    1.40      /* Initialise VGA output with one or two line channels, configuring a line
    1.41         timer and any transfer timer, with an initiating channel being introduced
     2.1 --- a/include/display.h	Sat Nov 10 19:20:13 2018 +0100
     2.2 +++ b/include/display.h	Sat Nov 10 21:30:09 2018 +0100
     2.3 @@ -94,11 +94,39 @@
     2.4  
     2.5  
     2.6  
     2.7 +/* Initialise a display. */
     2.8 +
     2.9 +#define Display(NAME, WIDTH, HEIGHT, FRAMES)                            \
    2.10 +    uint8_t __##NAME##_framebuffer[(WIDTH) * (HEIGHT + 1) * (FRAMES)];  \
    2.11 +    uint8_t *__##NAME##_screen_starts[FRAMES];                          \
    2.12 +    display_config_t NAME = {                                           \
    2.13 +        .framebuffer=__##NAME##_framebuffer,                            \
    2.14 +        .screen_starts=__##NAME##_screen_starts,                        \
    2.15 +                                                                        \
    2.16 +        .line_length=WIDTH,                                             \
    2.17 +        .line_count=HEIGHT,                                             \
    2.18 +        .screen_size=(WIDTH) * (HEIGHT),                                \
    2.19 +        .total_lines=(HEIGHT + 1) * (FRAMES),                           \
    2.20 +        .frame=0,                                                       \
    2.21 +        .frames=FRAMES,                                                 \
    2.22 +        .max_frames=FRAMES,                                             \
    2.23 +                                                                        \
    2.24 +        .scanlines = SCANLINES,                                         \
    2.25 +        .line_channels = LINE_CHANNELS,                                 \
    2.26 +        .cell_size = CELL_SIZE,                                         \
    2.27 +        .transfer_cell_size = TRANSFER_CELL_SIZE,                       \
    2.28 +                                                                        \
    2.29 +        .hfreq_limit = HFREQ_LIMIT,                                     \
    2.30 +        .hsync_start = HSYNC_START,                                     \
    2.31 +        .hsync_end = HSYNC_END,                                         \
    2.32 +        .visible_start = VISIBLE_START,                                 \
    2.33 +        .vfp_start = VFP_START,                                         \
    2.34 +        .vsync_start = VSYNC_START,                                     \
    2.35 +        .vsync_end = VSYNC_END};
    2.36 +
    2.37  /* Configuration functions. */
    2.38  
    2.39 -void init_display(display_config_t *cfg, uint8_t *framebuffer,
    2.40 -                  uint32_t line_length, uint32_t line_count,
    2.41 -                  int frames, uint8_t **screen_starts);
    2.42 +void init_display(display_config_t *cfg);
    2.43  
    2.44  void init_display_properties(display_config_t *cfg);
    2.45  
     3.1 --- a/include/vga_common.h	Sat Nov 10 19:20:13 2018 +0100
     3.2 +++ b/include/vga_common.h	Sat Nov 10 21:30:09 2018 +0100
     3.3 @@ -40,4 +40,21 @@
     3.4  
     3.5  #define VSYNC_END               622
     3.6  
     3.7 +/* Define DMA channels if not indicated in the build configuration. */
     3.8 +
     3.9 +/* CPU-based transfers: no channels. */
    3.10 +
    3.11 +#ifdef TRANSFER_CPU
    3.12 +#define LINE_CHANNELS   0
    3.13 +
    3.14 +/* DMA-based transfers: single channel by default. */
    3.15 +
    3.16 +#else
    3.17 +
    3.18 +#ifndef LINE_CHANNELS
    3.19 +#define LINE_CHANNELS   1
    3.20 +#endif
    3.21 +
    3.22 +#endif /* TRANSFER_CPU */
    3.23 +
    3.24  #endif /* __VGA_COMMON_H__ */
     4.1 --- a/lib/display.c	Sat Nov 10 19:20:13 2018 +0100
     4.2 +++ b/lib/display.c	Sat Nov 10 21:30:09 2018 +0100
     4.3 @@ -24,35 +24,8 @@
     4.4  
     4.5  /* Initialise a display configuration. */
     4.6  
     4.7 -void init_display(display_config_t *cfg, uint8_t *framebuffer,
     4.8 -                  uint32_t line_length, uint32_t line_count,
     4.9 -                  int frames, uint8_t **screen_starts)
    4.10 +void init_display(display_config_t *cfg)
    4.11  {
    4.12 -    /* Framebuffer address. */
    4.13 -
    4.14 -    cfg->framebuffer = framebuffer;
    4.15 -
    4.16 -    /* Frame allocation limits. */
    4.17 -
    4.18 -    cfg->total_lines = (line_count + 1) * frames;
    4.19 -    cfg->max_frames = frames;
    4.20 -
    4.21 -    /* Screen size and dimensions. */
    4.22 -
    4.23 -    cfg->screen_size = line_length * line_count;
    4.24 -    cfg->line_length = line_length;
    4.25 -    cfg->line_count = line_count;
    4.26 -
    4.27 -    /* Set the number of frames and the current frame. */
    4.28 -
    4.29 -    cfg->frames = frames;
    4.30 -    cfg->frame = 0;
    4.31 -
    4.32 -    /* Set the pointer to a collection of screen start pointers, one per
    4.33 -       frame. */
    4.34 -
    4.35 -    cfg->screen_starts = screen_starts;
    4.36 -
    4.37      init_frames(cfg);
    4.38      init_display_properties(cfg);
    4.39  }