From 0535c67eab412e72223bc06a528c5bf7cd4aeb22 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 21 Oct 2013 15:13:10 +1000 Subject: [PATCH] Add support for a driver private area (as well as a board private area) --- .../HX8347D/board_HX8347D_stm32f4discovery.h | 4 +-- drivers/gdisp/HX8347D/gdisp_lld.c | 5 ++- .../board_ILI9320_olimex_pic32mx_lcd.h | 4 +-- .../ILI9320/board_ILI9320_olimex_stm32_lcd.h | 4 +-- drivers/gdisp/ILI9320/gdisp_lld.c | 5 ++- .../ILI9325/board_ILI9325_hy_stm32_100p.h | 4 +-- drivers/gdisp/ILI9325/gdisp_lld.c | 5 ++- .../ILI9481/board_ILI9481_firebullstm32f103.h | 4 +-- drivers/gdisp/ILI9481/gdisp_lld.c | 5 ++- .../board_Nokia6610GE12_olimexsam7ex256.h | 4 +-- drivers/gdisp/Nokia6610GE12/gdisp_lld.c | 17 +++++---- .../board_Nokia6610GE8_olimexsam7ex256.h | 4 +-- drivers/gdisp/Nokia6610GE8/gdisp_lld.c | 35 ++++++++++++------- drivers/gdisp/RA8875/board_RA8875_marlin.h | 4 +-- drivers/gdisp/RA8875/gdisp_lld.c | 5 ++- .../gdisp/S6D1121/board_S6D1121_olimex_e407.h | 4 +-- drivers/gdisp/S6D1121/gdisp_lld.c | 5 ++- .../SSD1289/board_SSD1289_firebullstm32f103.h | 4 +-- .../SSD1289/board_SSD1289_stm32f4discovery.h | 4 +-- drivers/gdisp/SSD1289/gdisp_lld.c | 5 ++- drivers/gdisp/TestStub/gdisp_lld.c | 3 ++ drivers/multiple/Win32/gdisp_lld.c | 1 + drivers/multiple/X/gdisp_lld.c | 1 + include/gdisp/gdisp.h | 2 +- include/gdisp/lld/gdisp_lld.h | 1 + 25 files changed, 90 insertions(+), 49 deletions(-) diff --git a/drivers/gdisp/HX8347D/board_HX8347D_stm32f4discovery.h b/drivers/gdisp/HX8347D/board_HX8347D_stm32f4discovery.h index daabe75d..708e1a06 100644 --- a/drivers/gdisp/HX8347D/board_HX8347D_stm32f4discovery.h +++ b/drivers/gdisp/HX8347D/board_HX8347D_stm32f4discovery.h @@ -66,8 +66,8 @@ static const SPIConfig spi1cfg_16bit = { static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/HX8347D/gdisp_lld.c b/drivers/gdisp/HX8347D/gdisp_lld.c index 8cdbb781..3851c8e1 100644 --- a/drivers/gdisp/HX8347D/gdisp_lld.c +++ b/drivers/gdisp/HX8347D/gdisp_lld.c @@ -62,7 +62,10 @@ static inline void set_viewport(GDisplay* g) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); // Hardware reset diff --git a/drivers/gdisp/ILI9320/board_ILI9320_olimex_pic32mx_lcd.h b/drivers/gdisp/ILI9320/board_ILI9320_olimex_pic32mx_lcd.h index cf101aaf..5315127b 100644 --- a/drivers/gdisp/ILI9320/board_ILI9320_olimex_pic32mx_lcd.h +++ b/drivers/gdisp/ILI9320/board_ILI9320_olimex_pic32mx_lcd.h @@ -19,8 +19,8 @@ static void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/ILI9320/board_ILI9320_olimex_stm32_lcd.h b/drivers/gdisp/ILI9320/board_ILI9320_olimex_stm32_lcd.h index 4738db61..8e79009a 100644 --- a/drivers/gdisp/ILI9320/board_ILI9320_olimex_stm32_lcd.h +++ b/drivers/gdisp/ILI9320/board_ILI9320_olimex_stm32_lcd.h @@ -20,8 +20,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/ILI9320/gdisp_lld.c b/drivers/gdisp/ILI9320/gdisp_lld.c index d4639617..bf82a88a 100644 --- a/drivers/gdisp/ILI9320/gdisp_lld.c +++ b/drivers/gdisp/ILI9320/gdisp_lld.c @@ -98,7 +98,10 @@ static void set_viewport(GDisplay *g) { LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { uint16_t cver; - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); /* Hardware reset */ diff --git a/drivers/gdisp/ILI9325/board_ILI9325_hy_stm32_100p.h b/drivers/gdisp/ILI9325/board_ILI9325_hy_stm32_100p.h index ae9e96fc..02949605 100644 --- a/drivers/gdisp/ILI9325/board_ILI9325_hy_stm32_100p.h +++ b/drivers/gdisp/ILI9325/board_ILI9325_hy_stm32_100p.h @@ -33,8 +33,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/ILI9325/gdisp_lld.c b/drivers/gdisp/ILI9325/gdisp_lld.c index 8a4b8603..6bb649b1 100644 --- a/drivers/gdisp/ILI9325/gdisp_lld.c +++ b/drivers/gdisp/ILI9325/gdisp_lld.c @@ -99,7 +99,10 @@ static void set_viewport(GDisplay* g) { LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { uint16_t cver; - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); /* Hardware reset */ diff --git a/drivers/gdisp/ILI9481/board_ILI9481_firebullstm32f103.h b/drivers/gdisp/ILI9481/board_ILI9481_firebullstm32f103.h index 9933d17b..52d8afda 100644 --- a/drivers/gdisp/ILI9481/board_ILI9481_firebullstm32f103.h +++ b/drivers/gdisp/ILI9481/board_ILI9481_firebullstm32f103.h @@ -27,8 +27,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/ILI9481/gdisp_lld.c b/drivers/gdisp/ILI9481/gdisp_lld.c index fc00be10..5af12986 100644 --- a/drivers/gdisp/ILI9481/gdisp_lld.c +++ b/drivers/gdisp/ILI9481/gdisp_lld.c @@ -71,7 +71,10 @@ static void set_viewport(GDisplay* g) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); /* Hardware reset */ diff --git a/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_olimexsam7ex256.h b/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_olimexsam7ex256.h index 7aad94d3..05a48e47 100644 --- a/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_olimexsam7ex256.h +++ b/drivers/gdisp/Nokia6610GE12/board_Nokia6610GE12_olimexsam7ex256.h @@ -59,8 +59,8 @@ static bool_t pwmRunning = FALSE; static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c b/drivers/gdisp/Nokia6610GE12/gdisp_lld.c index 9aa5ac53..25f26c69 100644 --- a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c +++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld.c @@ -69,7 +69,9 @@ /* Driver local variables. */ /*===========================================================================*/ -static color_t savecolor[GDISP_TOTAL_DISPLAYS]; +// Use the priv pointer itself to save our color. This save allocating ram for it +// and works provided sizeof(color_t) <= sizeof(void *) +#define savecolor(g) ((color_t)g->priv) #define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0) @@ -96,7 +98,10 @@ static inline void set_viewport(GDisplay* g) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); // Hardware reset @@ -140,18 +145,18 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { LLDSPEC void gdisp_lld_write_color(GDisplay *g) { if ((g->flags & GDISP_FLG_ODDBYTE)) { // Write the pair of pixels to the display - write_data3(g, ((savecolor[g->controllerdisplay] >> 4) & 0xFF), - (((savecolor[g->controllerdisplay] << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)), + write_data3(g, ((savecolor(g) >> 4) & 0xFF), + (((savecolor(g) << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)), (g->p.color & 0xFF)); g->flags &= ~GDISP_FLG_ODDBYTE; } else { - savecolor[g->controllerdisplay] = g->p.color; + savecolor(g) = g->p.color; g->flags |= GDISP_FLG_ODDBYTE; } } LLDSPEC void gdisp_lld_write_stop(GDisplay *g) { if ((g->flags & GDISP_FLG_ODDBYTE)) { - write_data2(g, ((savecolor[g->controllerdisplay] >> 4) & 0xFF), ((savecolor[g->controllerdisplay] << 4) & 0xF0)); + write_data2(g, ((savecolor(g) >> 4) & 0xFF), ((savecolor(g) << 4) & 0xF0)); write_index(g, NOP); } release_bus(g); diff --git a/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_olimexsam7ex256.h b/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_olimexsam7ex256.h index ebd038d5..6cbcc5ab 100644 --- a/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_olimexsam7ex256.h +++ b/drivers/gdisp/Nokia6610GE8/board_Nokia6610GE8_olimexsam7ex256.h @@ -71,8 +71,8 @@ static bool_t pwmRunning = FALSE; */ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c b/drivers/gdisp/Nokia6610GE8/gdisp_lld.c index 4906ee78..1bc7282a 100644 --- a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c +++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld.c @@ -110,10 +110,13 @@ /*===========================================================================*/ #if GDISP_HARDWARE_STREAM_WRITE - static color_t savecolor[GDISP_TOTAL_DISPLAYS]; - #if GDISP_GE8_BROKEN_CONTROLLER - static color_t firstcolor[GDISP_TOTAL_DISPLAYS]; - #endif + typedef struct dvrPriv { + color_t savecolor; + #if GDISP_GE8_BROKEN_CONTROLLER + color_t firstcolor; + #endif + } dvrPriv; + #define PRIV ((dvrPriv *)g->priv) #endif #define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0) @@ -164,7 +167,13 @@ static inline void set_viewport(GDisplay* g) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + #if GDISP_HARDWARE_STREAM_WRITE + g->priv = gfxAlloc(sizeof(dvrPriv)); + #else + g->priv = 0; + #endif + + // Initialise the board interface init_board(g); // Hardware reset @@ -224,18 +233,18 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { LLDSPEC void gdisp_lld_write_color(GDisplay *g) { #if GDISP_GE8_BROKEN_CONTROLLER if (!(g->flags & GDISP_FLG_RUNBYTE)) { - firstcolor[g->controllerdisplay] = g->p.color; + PRIV->firstcolor = g->p.color; g->flags |= GDISP_FLG_RUNBYTE; } #endif if ((g->flags & GDISP_FLG_ODDBYTE)) { // Write the pair of pixels to the display - write_data3(g, ((savecolor[g->controllerdisplay] >> 4) & 0xFF), - (((savecolor[g->controllerdisplay] << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)), + write_data3(g, ((PRIV->savecolor >> 4) & 0xFF), + (((PRIV->savecolor << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)), (g->p.color & 0xFF)); g->flags &= ~GDISP_FLG_ODDBYTE; } else { - savecolor[g->controllerdisplay] = g->p.color; + PRIV->savecolor = g->p.color; g->flags |= GDISP_FLG_ODDBYTE; } } @@ -260,11 +269,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { * user application uses the streaming calls and then terminates the stream early or after buffer wrap. * Since this is such an unlikely situation we just don't handle it. */ - write_data3(g, ((savecolor[g->controllerdisplay] >> 4) & 0xFF), - (((savecolor[g->controllerdisplay] << 4) & 0xF0)|((firstcolor[g->controllerdisplay] >> 8) & 0x0F)), - (firstcolor[g->controllerdisplay] & 0xFF)); + write_data3(g, ((PRIV->savecolor >> 4) & 0xFF), + (((PRIV->savecolor << 4) & 0xF0)|((PRIV->firstcolor >> 8) & 0x0F)), + (PRIV->firstcolor & 0xFF)); #else - write_data2(g, ((savecolor[g->controllerdisplay] >> 4) & 0xFF), ((savecolor[g->controllerdisplay] << 4) & 0xF0)); + write_data2(g, ((PRIV->savecolor >> 4) & 0xFF), ((PRIV->savecolor << 4) & 0xF0)); write_index(g, NOP); #endif } diff --git a/drivers/gdisp/RA8875/board_RA8875_marlin.h b/drivers/gdisp/RA8875/board_RA8875_marlin.h index 88523060..da90d8f3 100644 --- a/drivers/gdisp/RA8875/board_RA8875_marlin.h +++ b/drivers/gdisp/RA8875/board_RA8875_marlin.h @@ -22,8 +22,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/RA8875/gdisp_lld.c b/drivers/gdisp/RA8875/gdisp_lld.c index 6697d9fd..7916ef3b 100644 --- a/drivers/gdisp/RA8875/gdisp_lld.c +++ b/drivers/gdisp/RA8875/gdisp_lld.c @@ -107,7 +107,10 @@ static inline void set_backlight(GDisplay* g, uint8_t percent) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); // Hardware reset diff --git a/drivers/gdisp/S6D1121/board_S6D1121_olimex_e407.h b/drivers/gdisp/S6D1121/board_S6D1121_olimex_e407.h index ec367183..4f8d2f58 100644 --- a/drivers/gdisp/S6D1121/board_S6D1121_olimex_e407.h +++ b/drivers/gdisp/S6D1121/board_S6D1121_olimex_e407.h @@ -20,8 +20,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/S6D1121/gdisp_lld.c b/drivers/gdisp/S6D1121/gdisp_lld.c index 8b6a956c..f7e12591 100644 --- a/drivers/gdisp/S6D1121/gdisp_lld.c +++ b/drivers/gdisp/S6D1121/gdisp_lld.c @@ -117,7 +117,10 @@ static inline void set_viewport(GDisplay *g) { } LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* initialize the hardware */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); /* Hardware reset */ diff --git a/drivers/gdisp/SSD1289/board_SSD1289_firebullstm32f103.h b/drivers/gdisp/SSD1289/board_SSD1289_firebullstm32f103.h index 338d9799..3277a902 100644 --- a/drivers/gdisp/SSD1289/board_SSD1289_firebullstm32f103.h +++ b/drivers/gdisp/SSD1289/board_SSD1289_firebullstm32f103.h @@ -26,8 +26,8 @@ static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/SSD1289/board_SSD1289_stm32f4discovery.h b/drivers/gdisp/SSD1289/board_SSD1289_stm32f4discovery.h index d1e23c4a..81ce0512 100644 --- a/drivers/gdisp/SSD1289/board_SSD1289_stm32f4discovery.h +++ b/drivers/gdisp/SSD1289/board_SSD1289_stm32f4discovery.h @@ -36,8 +36,8 @@ static const PWMConfig pwmcfg = { static inline void init_board(GDisplay *g) { - // As we are not using multiple displays we set g->priv to NULL as we don't use it. - g->priv = 0; + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; switch(g->controllerdisplay) { case 0: // Set up for Display 0 diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld.c index 840a1753..698d3cfc 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.c +++ b/drivers/gdisp/SSD1289/gdisp_lld.c @@ -115,7 +115,10 @@ static void set_viewport(GDisplay* g) { /*===========================================================================*/ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - /* Initialise your display */ + // No private area for this controller + g->priv = 0; + + // Initialise the board interface init_board(g); // Hardware reset diff --git a/drivers/gdisp/TestStub/gdisp_lld.c b/drivers/gdisp/TestStub/gdisp_lld.c index f9c421f5..1a5ad81f 100644 --- a/drivers/gdisp/TestStub/gdisp_lld.c +++ b/drivers/gdisp/TestStub/gdisp_lld.c @@ -32,6 +32,9 @@ #endif LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + /* No board interface and no private driver area */ + g->priv = g->board = 0; + /* Initialise the GDISP structure */ g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; diff --git a/drivers/multiple/Win32/gdisp_lld.c b/drivers/multiple/Win32/gdisp_lld.c index 011f8e74..3ce50633 100644 --- a/drivers/multiple/Win32/gdisp_lld.c +++ b/drivers/multiple/Win32/gdisp_lld.c @@ -441,6 +441,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { assert(priv != NULL); memset(priv, 0, sizeof(winPriv)); g->priv = priv; + g->board = 0; // no board interface for this controller // Create the window in the message thread PostThreadMessage(winThreadId, WM_USER, (WPARAM)g->controllerdisplay, (LPARAM)g); diff --git a/drivers/multiple/X/gdisp_lld.c b/drivers/multiple/X/gdisp_lld.c index 188724ed..c9beb821 100644 --- a/drivers/multiple/X/gdisp_lld.c +++ b/drivers/multiple/X/gdisp_lld.c @@ -193,6 +193,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->priv = gfxAlloc(sizeof(xPriv)); priv = (xPriv *)g->priv; + g->board = 0; // No board interface for this driver xa.colormap = cmap; xa.border_pixel = 0xFFFFFF; diff --git a/include/gdisp/gdisp.h b/include/gdisp/gdisp.h index 006fa08b..1b17fabe 100644 --- a/include/gdisp/gdisp.h +++ b/include/gdisp/gdisp.h @@ -271,7 +271,7 @@ extern GDisplay *GDISP; #elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_MONO typedef uint8_t color_t; #define COLOR(c) ((color_t)(c)) - #define MASKCOLOR FALSE + #define MASKCOLOR TRUE #define RGB2COLOR(r,g,b) ((r|g|b) ? 1 : 0) #define HTML2COLOR(h) (h ? 1 : 0) #define RED_OF(c) (c ? 255 : 0) diff --git a/include/gdisp/lld/gdisp_lld.h b/include/gdisp/lld/gdisp_lld.h index b5d9c699..6f3a5e5f 100644 --- a/include/gdisp/lld/gdisp_lld.h +++ b/include/gdisp/lld/gdisp_lld.h @@ -191,6 +191,7 @@ struct GDisplay { #endif void * priv; // A private area just for the drivers use. + void * board; // A private area just for the board interfaces use. uint8_t systemdisplay; uint8_t controllerdisplay;