From b05a29f830008ab0e9a36d8384ed7cf4ea3fb18b Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 28 Oct 2013 11:03:39 +1000 Subject: [PATCH] Rename GDISP driver files to prevent problems when compiling for multiple controllers on platforms that put all generated object files into a single directory. --- drivers/gdisp/ED060SC4/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ED060SC4.c} | 0 drivers/gdisp/HX8347D/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_HX8347D.c} | 472 ++++++------ drivers/gdisp/ILI9320/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ILI9320.c} | 0 drivers/gdisp/ILI9325/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ILI9325.c} | 0 drivers/gdisp/ILI9341/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ILI9341.c} | 0 drivers/gdisp/ILI9481/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ILI9481.c} | 0 drivers/gdisp/Nokia6610GE12/gdisp_lld.mk | 2 +- ...{gdisp_lld.c => gdisp_lld_Nokia6610GE12.c} | 0 drivers/gdisp/Nokia6610GE8/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_Nokia6610GE8.c} | 0 drivers/gdisp/RA8875/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_RA8875.c} | 0 drivers/gdisp/S6D1121/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_S6D1121.c} | 2 +- drivers/gdisp/SSD1289/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_SSD1289.c} | 702 +++++++++--------- drivers/gdisp/SSD1306/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_SSD1306.c} | 560 +++++++------- drivers/gdisp/SSD1963/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_SSD1963.c} | 0 drivers/gdisp/SSD2119/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_SSD2119.c} | 0 drivers/gdisp/ST7565/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_ST7565.c} | 0 drivers/gdisp/TestStub/gdisp_lld.mk | 2 +- .../{gdisp_lld.c => gdisp_lld_TestStub.c} | 0 drivers/multiple/Win32/gdisp_lld.mk | 2 +- .../Win32/{gdisp_lld.c => gdisp_lld_Win32.c} | 0 drivers/multiple/X/gdisp_lld.mk | 2 +- .../multiple/X/{gdisp_lld.c => gdisp_lld_X.c} | 0 36 files changed, 886 insertions(+), 886 deletions(-) rename drivers/gdisp/ED060SC4/{gdisp_lld.c => gdisp_lld_ED060SC4.c} (100%) rename drivers/gdisp/HX8347D/{gdisp_lld.c => gdisp_lld_HX8347D.c} (97%) rename drivers/gdisp/ILI9320/{gdisp_lld.c => gdisp_lld_ILI9320.c} (100%) rename drivers/gdisp/ILI9325/{gdisp_lld.c => gdisp_lld_ILI9325.c} (100%) rename drivers/gdisp/ILI9341/{gdisp_lld.c => gdisp_lld_ILI9341.c} (100%) rename drivers/gdisp/ILI9481/{gdisp_lld.c => gdisp_lld_ILI9481.c} (100%) rename drivers/gdisp/Nokia6610GE12/{gdisp_lld.c => gdisp_lld_Nokia6610GE12.c} (100%) rename drivers/gdisp/Nokia6610GE8/{gdisp_lld.c => gdisp_lld_Nokia6610GE8.c} (100%) rename drivers/gdisp/RA8875/{gdisp_lld.c => gdisp_lld_RA8875.c} (100%) rename drivers/gdisp/S6D1121/{gdisp_lld.c => gdisp_lld_S6D1121.c} (99%) rename drivers/gdisp/SSD1289/{gdisp_lld.c => gdisp_lld_SSD1289.c} (96%) rename drivers/gdisp/SSD1306/{gdisp_lld.c => gdisp_lld_SSD1306.c} (96%) rename drivers/gdisp/SSD1963/{gdisp_lld.c => gdisp_lld_SSD1963.c} (100%) rename drivers/gdisp/SSD2119/{gdisp_lld.c => gdisp_lld_SSD2119.c} (100%) rename drivers/gdisp/ST7565/{gdisp_lld.c => gdisp_lld_ST7565.c} (100%) rename drivers/gdisp/TestStub/{gdisp_lld.c => gdisp_lld_TestStub.c} (100%) rename drivers/multiple/Win32/{gdisp_lld.c => gdisp_lld_Win32.c} (100%) rename drivers/multiple/X/{gdisp_lld.c => gdisp_lld_X.c} (100%) diff --git a/drivers/gdisp/ED060SC4/gdisp_lld.mk b/drivers/gdisp/ED060SC4/gdisp_lld.mk index fc62da03..0c78e1a7 100644 --- a/drivers/gdisp/ED060SC4/gdisp_lld.mk +++ b/drivers/gdisp/ED060SC4/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ED060SC4 -GFXSRC += $(GFXLIB)/drivers/gdisp/ED060SC4/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c diff --git a/drivers/gdisp/ED060SC4/gdisp_lld.c b/drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c similarity index 100% rename from drivers/gdisp/ED060SC4/gdisp_lld.c rename to drivers/gdisp/ED060SC4/gdisp_lld_ED060SC4.c diff --git a/drivers/gdisp/HX8347D/gdisp_lld.mk b/drivers/gdisp/HX8347D/gdisp_lld.mk index 72d9cf75..581e53e7 100644 --- a/drivers/gdisp/HX8347D/gdisp_lld.mk +++ b/drivers/gdisp/HX8347D/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/HX8347D -GFXSRC += $(GFXLIB)/drivers/gdisp/HX8347D/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c diff --git a/drivers/gdisp/HX8347D/gdisp_lld.c b/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c similarity index 97% rename from drivers/gdisp/HX8347D/gdisp_lld.c rename to drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c index ab976db0..fecf115c 100644 --- a/drivers/gdisp/HX8347D/gdisp_lld.c +++ b/drivers/gdisp/HX8347D/gdisp_lld_HX8347D.c @@ -1,236 +1,236 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/gdisp/HX8347D/gdisp_lld.c - * @brief GDISP Graphics Driver subsystem low level driver source for the HX8347D display. - */ - -#include "gfx.h" - -#if GFX_USE_GDISP - -#define GDISP_DRIVER_VMT GDISPVMT_HX8347D -#include "../drivers/gdisp/HX8347D/gdisp_lld_config.h" -#include "gdisp/lld/gdisp_lld.h" - -#include "board_HX8347D.h" - -/*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -#ifndef GDISP_SCREEN_HEIGHT - #define GDISP_SCREEN_HEIGHT 320 -#endif -#ifndef GDISP_SCREEN_WIDTH - #define GDISP_SCREEN_WIDTH 240 -#endif -#ifndef GDISP_INITIAL_CONTRAST - #define GDISP_INITIAL_CONTRAST 50 -#endif -#ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 -#endif - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -#include "../drivers/gdisp/HX8347D/HX8347D.h" - -#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); } - -static inline void set_viewport(GDisplay* g) { - write_reg(g, HX8347D_REG_SCL, g->p.x); - write_reg(g, HX8347D_REG_SCH, g->p.x >> 8); - write_reg(g, HX8347D_REG_ECL, g->p.x + g->p.cx -1); - write_reg(g, HX8347D_REG_ECH, (g->p.x + g->p.cx -1) >> 8); - write_reg(g, HX8347D_REG_SPL, g->p.y); - write_reg(g, HX8347D_REG_SPH, g->p.y >> 8); - write_reg(g, HX8347D_REG_EPL, g->p.y + g->p.cy -1); - write_reg(g, HX8347D_REG_EPH, (g->p.y + g->p.cy -1) >> 8); - write_index(g, HX8347D_REG_SRAMWC); -} - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - // No private area for this controller - g->priv = 0; - - // Initialise the board interface - init_board(g); - - // Hardware reset - setpin_reset(g, TRUE); - gfxSleepMilliseconds(1); - setpin_reset(g, FALSE); - gfxSleepMilliseconds(5); - - // Get the bus for the following initialisation commands - acquire_bus(g); - - /* Start Initial Sequence ----------------------------------------------------*/ - write_reg(g, HX8347D_REG_STBAH, 0x00); /* Reset Power Control 1 */ - write_reg(g, HX8347D_REG_STBAL, 0x20); /* Power Control 2 */ - write_reg(g, HX8347D_REG_PTBAH, 0x0C); /* Power Control 1 */ - write_reg(g, HX8347D_REG_PTBAL, 0xC4); /* Power Control 2 */ - write_reg(g, HX8347D_REG_OPONN, 0x40); /* Source OPON_N */ - write_reg(g, HX8347D_REG_OPONI, 0x38); /* Source OPON_I */ - write_reg(g, HX8347D_REG_DC2, 0xA3); /* Display Control 2 */ - - /* Power On sequence ---------------------------------------------------------*/ - write_reg(g, HX8347D_REG_PWC2, 0x1B); /* Power Control 2 */ - write_reg(g, HX8347D_REG_PWC1, 0x01); /* Power Control 1 */ - write_reg(g, HX8347D_REG_VMH, 0x2F); /* Vcom Control 2 */ - write_reg(g, HX8347D_REG_VML, 0x57); /* Vcom Control 3 */ - write_reg(g, HX8347D_REG_VMF, 0x8D); /* Vcom Control 1 */ - - /* Gamma settings -----------------------------------------------------------*/ - write_reg(g, HX8347D_REG_VRP0, 0x01); // default setup - write_reg(g, HX8347D_REG_VRP1, 0x0e); // - write_reg(g, HX8347D_REG_VRP2, 0x11); // - write_reg(g, HX8347D_REG_VRP3, 0x1a); // - write_reg(g, HX8347D_REG_VRP4, 0x18); // - write_reg(g, HX8347D_REG_VRP5, 0x24); // - write_reg(g, HX8347D_REG_PRP0, 0x15); // - write_reg(g, HX8347D_REG_PRP1, 0x65); // - write_reg(g, HX8347D_REG_PKP0, 0x0b); // - write_reg(g, HX8347D_REG_PKP1, 0x18); // - write_reg(g, HX8347D_REG_PKP2, 0x19); // - write_reg(g, HX8347D_REG_PKP3, 0x1a); // - write_reg(g, HX8347D_REG_PKP4, 0x18); // - write_reg(g, HX8347D_REG_VRN0, 0x1b); // - write_reg(g, HX8347D_REG_VRN1, 0x27); // - write_reg(g, HX8347D_REG_VRN2, 0x25); // - write_reg(g, HX8347D_REG_VRN3, 0x2e); // - write_reg(g, HX8347D_REG_VRN4, 0x31); // - write_reg(g, HX8347D_REG_VRN5, 0x3e); // - write_reg(g, HX8347D_REG_PRN0, 0x1a); // - write_reg(g, HX8347D_REG_PRN1, 0x6a); // - write_reg(g, HX8347D_REG_PKN0, 0x07); // - write_reg(g, HX8347D_REG_PKN1, 0x05); // - write_reg(g, HX8347D_REG_PKN2, 0x06); // - write_reg(g, HX8347D_REG_PKN3, 0x0b); // - write_reg(g, HX8347D_REG_PKN4, 0x14); // - write_reg(g, HX8347D_REG_CGM, 0xcc); // - - /* Power + Osc ---------------------------------------------------------------*/ - write_reg(g, HX8347D_REG_OSCCH, 0x36); /* OSC Control 1 */ - write_reg(g, HX8347D_REG_OSCCL, 0x01); /* OSC Control 2 */ - write_reg(g, HX8347D_REG_DMODE, 0x00); /* Display Mode Control */ - write_reg(g, HX8347D_REG_PWC6, 0x88); /* Power Control 6 */ - gfxSleepMilliseconds(5); /* Delay 5 ms */ - write_reg(g, HX8347D_REG_PWC6, 0x80); /* Power Control 6 */ - gfxSleepMilliseconds(5); /* Delay 5 ms */ - write_reg(g, HX8347D_REG_PWC6, 0x90); /* Power Control 6 */ - gfxSleepMilliseconds(5); /* Delay 5 ms */ - write_reg(g, HX8347D_REG_PWC6, 0xD0); /* Power Control 6 */ - gfxSleepMilliseconds(5); /* Delay 5 ms */ - write_reg(g, HX8347D_REG_COLMOD, 0x05); /* Colmod 16Bit/Pixel */ - write_reg(g, HX8347D_REG_PCH, 0x00); /* Panel Characteristic */ - write_reg(g, HX8347D_REG_DC3, 0x38); /* Display Control 3 */ - gfxSleepMilliseconds(40); /* Delay 40 ms */ - write_reg(g, HX8347D_REG_DC3, 0x3C); /* Display Control 3 */ - write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */ - - // Finish Init - post_init_board(g); - - // Release the bus - release_bus(g); - - /* Turn on the backlight */ - set_backlight(g, GDISP_INITIAL_BACKLIGHT); - - /* Initialise the GDISP structure */ - g->g.Width = GDISP_SCREEN_WIDTH; - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; - g->g.Backlight = GDISP_INITIAL_BACKLIGHT; - g->g.Contrast = GDISP_INITIAL_CONTRAST; - return TRUE; -} - -#if GDISP_HARDWARE_STREAM_WRITE - LLDSPEC void gdisp_lld_write_start(GDisplay *g) { - acquire_bus(g); - set_viewport(g); - busmode16(g); - } - LLDSPEC void gdisp_lld_write_color(GDisplay *g) { - write_ram16(g, g->p.color); - } - LLDSPEC void gdisp_lld_write_stop(GDisplay *g) { - busmode8(g); - release_bus(g); - } -#endif - -#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay *g) { - switch(g->p.x) { - case GDISP_CONTROL_ORIENTATION: - if (g->g.Orientation == (orientation_t)g->p.ptr) - return; - switch((orientation_t)g->p.ptr) { - case GDISP_ROTATE_0: - acquire_bus(g); - write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */ - release_bus(g); - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - - case GDISP_ROTATE_90: - acquire_bus(g); - write_reg(g, HX8347D_REG_MAC, 0x68); /* Memory access control */ - release_bus(g); - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - - case GDISP_ROTATE_180: - acquire_bus(g); - write_reg(g, HX8347D_REG_MAC, 0xc8); /* Memory access control */ - release_bus(g); - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - - case GDISP_ROTATE_270: - acquire_bus(g); - write_reg(g, HX8347D_REG_MAC, 0xa8); /* Memory access control */ - release_bus(g); - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - - default: - return; - } - g->g.Orientation = (orientation_t)g->p.ptr; - return; - - case GDISP_CONTROL_BACKLIGHT: - if ((unsigned)g->p.ptr > 100) - g->p.ptr = (void *)100; - set_backlight(g, (unsigned)g->p.ptr); - g->g.Backlight = (unsigned)g->p.ptr; - return; - - default: - return; - } - } -#endif - -#endif /* GFX_USE_GDISP */ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file drivers/gdisp/HX8347D/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the HX8347D display. + */ + +#include "gfx.h" + +#if GFX_USE_GDISP + +#define GDISP_DRIVER_VMT GDISPVMT_HX8347D +#include "../drivers/gdisp/HX8347D/gdisp_lld_config.h" +#include "gdisp/lld/gdisp_lld.h" + +#include "board_HX8347D.h" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#ifndef GDISP_SCREEN_HEIGHT + #define GDISP_SCREEN_HEIGHT 320 +#endif +#ifndef GDISP_SCREEN_WIDTH + #define GDISP_SCREEN_WIDTH 240 +#endif +#ifndef GDISP_INITIAL_CONTRAST + #define GDISP_INITIAL_CONTRAST 50 +#endif +#ifndef GDISP_INITIAL_BACKLIGHT + #define GDISP_INITIAL_BACKLIGHT 100 +#endif + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +#include "../drivers/gdisp/HX8347D/HX8347D.h" + +#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); } + +static inline void set_viewport(GDisplay* g) { + write_reg(g, HX8347D_REG_SCL, g->p.x); + write_reg(g, HX8347D_REG_SCH, g->p.x >> 8); + write_reg(g, HX8347D_REG_ECL, g->p.x + g->p.cx -1); + write_reg(g, HX8347D_REG_ECH, (g->p.x + g->p.cx -1) >> 8); + write_reg(g, HX8347D_REG_SPL, g->p.y); + write_reg(g, HX8347D_REG_SPH, g->p.y >> 8); + write_reg(g, HX8347D_REG_EPL, g->p.y + g->p.cy -1); + write_reg(g, HX8347D_REG_EPH, (g->p.y + g->p.cy -1) >> 8); + write_index(g, HX8347D_REG_SRAMWC); +} + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + // No private area for this controller + g->priv = 0; + + // Initialise the board interface + init_board(g); + + // Hardware reset + setpin_reset(g, TRUE); + gfxSleepMilliseconds(1); + setpin_reset(g, FALSE); + gfxSleepMilliseconds(5); + + // Get the bus for the following initialisation commands + acquire_bus(g); + + /* Start Initial Sequence ----------------------------------------------------*/ + write_reg(g, HX8347D_REG_STBAH, 0x00); /* Reset Power Control 1 */ + write_reg(g, HX8347D_REG_STBAL, 0x20); /* Power Control 2 */ + write_reg(g, HX8347D_REG_PTBAH, 0x0C); /* Power Control 1 */ + write_reg(g, HX8347D_REG_PTBAL, 0xC4); /* Power Control 2 */ + write_reg(g, HX8347D_REG_OPONN, 0x40); /* Source OPON_N */ + write_reg(g, HX8347D_REG_OPONI, 0x38); /* Source OPON_I */ + write_reg(g, HX8347D_REG_DC2, 0xA3); /* Display Control 2 */ + + /* Power On sequence ---------------------------------------------------------*/ + write_reg(g, HX8347D_REG_PWC2, 0x1B); /* Power Control 2 */ + write_reg(g, HX8347D_REG_PWC1, 0x01); /* Power Control 1 */ + write_reg(g, HX8347D_REG_VMH, 0x2F); /* Vcom Control 2 */ + write_reg(g, HX8347D_REG_VML, 0x57); /* Vcom Control 3 */ + write_reg(g, HX8347D_REG_VMF, 0x8D); /* Vcom Control 1 */ + + /* Gamma settings -----------------------------------------------------------*/ + write_reg(g, HX8347D_REG_VRP0, 0x01); // default setup + write_reg(g, HX8347D_REG_VRP1, 0x0e); // + write_reg(g, HX8347D_REG_VRP2, 0x11); // + write_reg(g, HX8347D_REG_VRP3, 0x1a); // + write_reg(g, HX8347D_REG_VRP4, 0x18); // + write_reg(g, HX8347D_REG_VRP5, 0x24); // + write_reg(g, HX8347D_REG_PRP0, 0x15); // + write_reg(g, HX8347D_REG_PRP1, 0x65); // + write_reg(g, HX8347D_REG_PKP0, 0x0b); // + write_reg(g, HX8347D_REG_PKP1, 0x18); // + write_reg(g, HX8347D_REG_PKP2, 0x19); // + write_reg(g, HX8347D_REG_PKP3, 0x1a); // + write_reg(g, HX8347D_REG_PKP4, 0x18); // + write_reg(g, HX8347D_REG_VRN0, 0x1b); // + write_reg(g, HX8347D_REG_VRN1, 0x27); // + write_reg(g, HX8347D_REG_VRN2, 0x25); // + write_reg(g, HX8347D_REG_VRN3, 0x2e); // + write_reg(g, HX8347D_REG_VRN4, 0x31); // + write_reg(g, HX8347D_REG_VRN5, 0x3e); // + write_reg(g, HX8347D_REG_PRN0, 0x1a); // + write_reg(g, HX8347D_REG_PRN1, 0x6a); // + write_reg(g, HX8347D_REG_PKN0, 0x07); // + write_reg(g, HX8347D_REG_PKN1, 0x05); // + write_reg(g, HX8347D_REG_PKN2, 0x06); // + write_reg(g, HX8347D_REG_PKN3, 0x0b); // + write_reg(g, HX8347D_REG_PKN4, 0x14); // + write_reg(g, HX8347D_REG_CGM, 0xcc); // + + /* Power + Osc ---------------------------------------------------------------*/ + write_reg(g, HX8347D_REG_OSCCH, 0x36); /* OSC Control 1 */ + write_reg(g, HX8347D_REG_OSCCL, 0x01); /* OSC Control 2 */ + write_reg(g, HX8347D_REG_DMODE, 0x00); /* Display Mode Control */ + write_reg(g, HX8347D_REG_PWC6, 0x88); /* Power Control 6 */ + gfxSleepMilliseconds(5); /* Delay 5 ms */ + write_reg(g, HX8347D_REG_PWC6, 0x80); /* Power Control 6 */ + gfxSleepMilliseconds(5); /* Delay 5 ms */ + write_reg(g, HX8347D_REG_PWC6, 0x90); /* Power Control 6 */ + gfxSleepMilliseconds(5); /* Delay 5 ms */ + write_reg(g, HX8347D_REG_PWC6, 0xD0); /* Power Control 6 */ + gfxSleepMilliseconds(5); /* Delay 5 ms */ + write_reg(g, HX8347D_REG_COLMOD, 0x05); /* Colmod 16Bit/Pixel */ + write_reg(g, HX8347D_REG_PCH, 0x00); /* Panel Characteristic */ + write_reg(g, HX8347D_REG_DC3, 0x38); /* Display Control 3 */ + gfxSleepMilliseconds(40); /* Delay 40 ms */ + write_reg(g, HX8347D_REG_DC3, 0x3C); /* Display Control 3 */ + write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */ + + // Finish Init + post_init_board(g); + + // Release the bus + release_bus(g); + + /* Turn on the backlight */ + set_backlight(g, GDISP_INITIAL_BACKLIGHT); + + /* Initialise the GDISP structure */ + g->g.Width = GDISP_SCREEN_WIDTH; + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->g.Backlight = GDISP_INITIAL_BACKLIGHT; + g->g.Contrast = GDISP_INITIAL_CONTRAST; + return TRUE; +} + +#if GDISP_HARDWARE_STREAM_WRITE + LLDSPEC void gdisp_lld_write_start(GDisplay *g) { + acquire_bus(g); + set_viewport(g); + busmode16(g); + } + LLDSPEC void gdisp_lld_write_color(GDisplay *g) { + write_ram16(g, g->p.color); + } + LLDSPEC void gdisp_lld_write_stop(GDisplay *g) { + busmode8(g); + release_bus(g); + } +#endif + +#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL + LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + case GDISP_ROTATE_0: + acquire_bus(g); + write_reg(g, HX8347D_REG_MAC, 0x08); /* Memory access control */ + release_bus(g); + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + + case GDISP_ROTATE_90: + acquire_bus(g); + write_reg(g, HX8347D_REG_MAC, 0x68); /* Memory access control */ + release_bus(g); + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + + case GDISP_ROTATE_180: + acquire_bus(g); + write_reg(g, HX8347D_REG_MAC, 0xc8); /* Memory access control */ + release_bus(g); + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + + case GDISP_ROTATE_270: + acquire_bus(g); + write_reg(g, HX8347D_REG_MAC, 0xa8); /* Memory access control */ + release_bus(g); + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_BACKLIGHT: + if ((unsigned)g->p.ptr > 100) + g->p.ptr = (void *)100; + set_backlight(g, (unsigned)g->p.ptr); + g->g.Backlight = (unsigned)g->p.ptr; + return; + + default: + return; + } + } +#endif + +#endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/ILI9320/gdisp_lld.mk b/drivers/gdisp/ILI9320/gdisp_lld.mk index 071e7c02..d61fbc33 100644 --- a/drivers/gdisp/ILI9320/gdisp_lld.mk +++ b/drivers/gdisp/ILI9320/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ILI9320 -GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9320/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c diff --git a/drivers/gdisp/ILI9320/gdisp_lld.c b/drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c similarity index 100% rename from drivers/gdisp/ILI9320/gdisp_lld.c rename to drivers/gdisp/ILI9320/gdisp_lld_ILI9320.c diff --git a/drivers/gdisp/ILI9325/gdisp_lld.mk b/drivers/gdisp/ILI9325/gdisp_lld.mk index 61565164..4dbda578 100644 --- a/drivers/gdisp/ILI9325/gdisp_lld.mk +++ b/drivers/gdisp/ILI9325/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ILI9325 -GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9325/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c diff --git a/drivers/gdisp/ILI9325/gdisp_lld.c b/drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c similarity index 100% rename from drivers/gdisp/ILI9325/gdisp_lld.c rename to drivers/gdisp/ILI9325/gdisp_lld_ILI9325.c diff --git a/drivers/gdisp/ILI9341/gdisp_lld.mk b/drivers/gdisp/ILI9341/gdisp_lld.mk index 8c44fc85..326b67ad 100644 --- a/drivers/gdisp/ILI9341/gdisp_lld.mk +++ b/drivers/gdisp/ILI9341/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ILI9341 -GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9341/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c diff --git a/drivers/gdisp/ILI9341/gdisp_lld.c b/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c similarity index 100% rename from drivers/gdisp/ILI9341/gdisp_lld.c rename to drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c diff --git a/drivers/gdisp/ILI9481/gdisp_lld.mk b/drivers/gdisp/ILI9481/gdisp_lld.mk index 6af4d1f8..8c971788 100644 --- a/drivers/gdisp/ILI9481/gdisp_lld.mk +++ b/drivers/gdisp/ILI9481/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ILI9481 -GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9481/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c diff --git a/drivers/gdisp/ILI9481/gdisp_lld.c b/drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c similarity index 100% rename from drivers/gdisp/ILI9481/gdisp_lld.c rename to drivers/gdisp/ILI9481/gdisp_lld_ILI9481.c diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk b/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk index 892665d5..65781667 100644 --- a/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk +++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12 -GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c b/drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c similarity index 100% rename from drivers/gdisp/Nokia6610GE12/gdisp_lld.c rename to drivers/gdisp/Nokia6610GE12/gdisp_lld_Nokia6610GE12.c diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk b/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk index 28c57fd6..a61948b3 100644 --- a/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk +++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8 -GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c b/drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c similarity index 100% rename from drivers/gdisp/Nokia6610GE8/gdisp_lld.c rename to drivers/gdisp/Nokia6610GE8/gdisp_lld_Nokia6610GE8.c diff --git a/drivers/gdisp/RA8875/gdisp_lld.mk b/drivers/gdisp/RA8875/gdisp_lld.mk index 7ac03624..146cf255 100644 --- a/drivers/gdisp/RA8875/gdisp_lld.mk +++ b/drivers/gdisp/RA8875/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/RA8875 -GFXSRC += $(GFXLIB)/drivers/gdisp/RA8875/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/RA8875/gdisp_lld_RA8875.c diff --git a/drivers/gdisp/RA8875/gdisp_lld.c b/drivers/gdisp/RA8875/gdisp_lld_RA8875.c similarity index 100% rename from drivers/gdisp/RA8875/gdisp_lld.c rename to drivers/gdisp/RA8875/gdisp_lld_RA8875.c diff --git a/drivers/gdisp/S6D1121/gdisp_lld.mk b/drivers/gdisp/S6D1121/gdisp_lld.mk index f5f067b7..583feb41 100644 --- a/drivers/gdisp/S6D1121/gdisp_lld.mk +++ b/drivers/gdisp/S6D1121/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/S6D1121 -GFXSRC += $(GFXLIB)/drivers/gdisp/S6D1121/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c diff --git a/drivers/gdisp/S6D1121/gdisp_lld.c b/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c similarity index 99% rename from drivers/gdisp/S6D1121/gdisp_lld.c rename to drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c index df9f01a7..cbaa7199 100644 --- a/drivers/gdisp/S6D1121/gdisp_lld.c +++ b/drivers/gdisp/S6D1121/gdisp_lld_S6D1121.c @@ -15,7 +15,7 @@ #include "gfx.h" -#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/ +#if GFX_USE_GDISP #if defined(GDISP_SCREEN_HEIGHT) #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored." diff --git a/drivers/gdisp/SSD1289/gdisp_lld.mk b/drivers/gdisp/SSD1289/gdisp_lld.mk index 564610eb..fd2713bc 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.mk +++ b/drivers/gdisp/SSD1289/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/SSD1289 -GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1289/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c similarity index 96% rename from drivers/gdisp/SSD1289/gdisp_lld.c rename to drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c index f600b305..6692e7d7 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.c +++ b/drivers/gdisp/SSD1289/gdisp_lld_SSD1289.c @@ -1,351 +1,351 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/gdisp/SSD1289/gdisp_lld.c - * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1289 display. - */ - -#include "gfx.h" - -#if GFX_USE_GDISP - -#define GDISP_DRIVER_VMT GDISPVMT_SSD1289 -#include "../drivers/gdisp/SSD1289/gdisp_lld_config.h" -#include "gdisp/lld/gdisp_lld.h" - -#include "board_SSD1289.h" - -/*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -#ifndef GDISP_SCREEN_HEIGHT - #define GDISP_SCREEN_HEIGHT 320 -#endif -#ifndef GDISP_SCREEN_WIDTH - #define GDISP_SCREEN_WIDTH 240 -#endif -#ifndef GDISP_INITIAL_CONTRAST - #define GDISP_INITIAL_CONTRAST 50 -#endif -#ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 -#endif - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -// Some common routines and macros -#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; } -#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); } - -static void set_cursor(GDisplay *g) { - /* - * Reg 0x004E is an 8 bit value - start x position - * Reg 0x004F is 9 bit - start y position - * Use a bit mask to make sure they are not set too high - */ - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - write_reg(g, 0x4e, g->p.x & 0x00FF); - write_reg(g, 0x4f, g->p.y & 0x01FF); - break; - case GDISP_ROTATE_90: - write_reg(g, 0x4e, g->p.y & 0x00FF); - write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF); - break; - case GDISP_ROTATE_180: - write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF); - write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF); - break; - case GDISP_ROTATE_270: - write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF); - write_reg(g, 0x4f, g->p.x & 0x01FF); - break; - } - write_index(g, 0x22); -} - -static void set_viewport(GDisplay* g) { - /* Reg 0x44 - Horizontal RAM address position - * Upper Byte - HEA - * Lower Byte - HSA - * 0 <= HSA <= HEA <= 0xEF - * Reg 0x45,0x46 - Vertical RAM address position - * Lower 9 bits gives 0-511 range in each value - * 0 <= Reg(0x45) <= Reg(0x46) <= 0x13F - * Use a bit mask to make sure they are not set too high - */ - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - write_reg(g, 0x44, (((g->p.x+g->p.cx-1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF)); - write_reg(g, 0x45, g->p.y & 0x01FF); - write_reg(g, 0x46, (g->p.y+g->p.cy-1) & 0x01FF); - break; - case GDISP_ROTATE_90: - write_reg(g, 0x44, (((g->p.y+g->p.cy-1) << 8) & 0xFF00 ) | (g->p.y & 0x00FF)); - write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.x+g->p.cx)) & 0x01FF); - write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF); - break; - case GDISP_ROTATE_180: - write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH - (g->p.x+g->p.cx)) & 0x00FF)); - write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.y+g->p.cy)) & 0x01FF); - write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF); - break; - case GDISP_ROTATE_270: - write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH-(g->p.y+g->p.cy)) & 0x00FF)); - write_reg(g, 0x45, g->p.x & 0x01FF); - write_reg(g, 0x46, (g->p.x+g->p.cx-1) & 0x01FF); - break; - } -} - -/*===========================================================================*/ -/* Driver interrupt handlers. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - // No private area for this controller - g->priv = 0; - - // Initialise the board interface - init_board(g); - - // Hardware reset - setpin_reset(g, TRUE); - gfxSleepMilliseconds(20); - setpin_reset(g, FALSE); - gfxSleepMilliseconds(20); - - // Get the bus for the following initialisation commands - acquire_bus(g); - - write_reg(g, 0x00, 0x0001); gfxSleepMicroseconds(5); - write_reg(g, 0x03, 0xA8A4); gfxSleepMicroseconds(5); - write_reg(g, 0x0C, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x0D, 0x080C); gfxSleepMicroseconds(5); - write_reg(g, 0x0E, 0x2B00); gfxSleepMicroseconds(5); - write_reg(g, 0x1E, 0x00B0); gfxSleepMicroseconds(5); - write_reg(g, 0x01, 0x2B3F); gfxSleepMicroseconds(5); - write_reg(g, 0x02, 0x0600); gfxSleepMicroseconds(5); - write_reg(g, 0x10, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x11, 0x6070); gfxSleepMicroseconds(5); - write_reg(g, 0x05, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x06, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x16, 0xEF1C); gfxSleepMicroseconds(5); - write_reg(g, 0x17, 0x0003); gfxSleepMicroseconds(5); - write_reg(g, 0x07, 0x0133); gfxSleepMicroseconds(5); - write_reg(g, 0x0B, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x0F, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x41, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x42, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x48, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x49, 0x013F); gfxSleepMicroseconds(5); - write_reg(g, 0x4A, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x4B, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x44, 0xEF00); gfxSleepMicroseconds(5); - write_reg(g, 0x45, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x46, 0x013F); gfxSleepMicroseconds(5); - write_reg(g, 0x30, 0x0707); gfxSleepMicroseconds(5); - write_reg(g, 0x31, 0x0204); gfxSleepMicroseconds(5); - write_reg(g, 0x32, 0x0204); gfxSleepMicroseconds(5); - write_reg(g, 0x33, 0x0502); gfxSleepMicroseconds(5); - write_reg(g, 0x34, 0x0507); gfxSleepMicroseconds(5); - write_reg(g, 0x35, 0x0204); gfxSleepMicroseconds(5); - write_reg(g, 0x36, 0x0204); gfxSleepMicroseconds(5); - write_reg(g, 0x37, 0x0502); gfxSleepMicroseconds(5); - write_reg(g, 0x3A, 0x0302); gfxSleepMicroseconds(5); - write_reg(g, 0x3B, 0x0302); gfxSleepMicroseconds(5); - write_reg(g, 0x23, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x24, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x25, 0x8000); gfxSleepMicroseconds(5); - write_reg(g, 0x4f, 0x0000); gfxSleepMicroseconds(5); - write_reg(g, 0x4e, 0x0000); gfxSleepMicroseconds(5); - - // Finish Init - post_init_board(g); - - // Release the bus - release_bus(g); - - /* Turn on the back-light */ - set_backlight(g, GDISP_INITIAL_BACKLIGHT); - - /* Initialise the GDISP structure */ - g->g.Width = GDISP_SCREEN_WIDTH; - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; - g->g.Backlight = GDISP_INITIAL_BACKLIGHT; - g->g.Contrast = GDISP_INITIAL_CONTRAST; - return TRUE; -} - -#if GDISP_HARDWARE_STREAM_WRITE - LLDSPEC void gdisp_lld_write_start(GDisplay *g) { - acquire_bus(g); - set_viewport(g); - #if !GDISP_HARDWARE_STREAM_POS - set_cursor(g); - #endif - } - LLDSPEC void gdisp_lld_write_color(GDisplay *g) { - write_data(g, g->p.color); - } - LLDSPEC void gdisp_lld_write_stop(GDisplay *g) { - release_bus(g); - } - #if GDISP_HARDWARE_STREAM_POS - LLDSPEC void gdisp_lld_write_pos(GDisplay *g) { - set_cursor(g); - } - #endif -#endif - -#if GDISP_HARDWARE_STREAM_READ - LLDSPEC void gdisp_lld_read_start(GDisplay *g) { - acquire_bus(g); - set_viewport(g); - set_cursor(g); - setreadmode(g); - dummy_read(g); - } - LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) { - return read_data(g); - } - LLDSPEC void gdisp_lld_read_stop(GDisplay *g) { - setwritemode(g); - release_bus(g); - } -#endif - -#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA) - LLDSPEC void gdisp_lld_fill_area(GDisplay *g) { - acquire_bus(g); - set_viewport(g); - set_cursor(g); - dma_with_noinc(g, &color, g->p.cx*g->p.cy) - release_bus(g); - } -#endif - -#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA) - LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { - pixel_t *buffer; - coord_t ycnt; - - buffer = (pixel_t *)g->p.ptr + g->p.x1 + g->p.y1 * g->p.x2; - - acquire_bus(g); - set_viewport(g); - set_cursor(g); - if (g->p.x2 == g->p.cx) { - dma_with_inc(g, buffer, g->p.cx*g->p.cy); - } else { - for (ycnt = g->p.cy; ycnt; ycnt--, buffer += g->p.x2) - dma_with_inc(g, buffer, g->p.cy); - } - release_bus(g); - } -#endif - -#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay *g) { - switch(g->p.x) { - case GDISP_CONTROL_POWER: - if (g->g.Powermode == (powermode_t)g->p.ptr) - return; - switch((powermode_t)g->p.ptr) { - case powerOff: - acquire_bus(g); - write_reg(g, 0x10, 0x0000); // leave sleep mode - write_reg(g, 0x07, 0x0000); // halt operation - write_reg(g, 0x00, 0x0000); // turn off oscillator - write_reg(g, 0x10, 0x0001); // enter sleep mode - release_bus(g); - break; - case powerOn: - acquire_bus(g); - write_reg(g, 0x10, 0x0000); // leave sleep mode - write_reg(g, 0x00, 0x0001); // turn on oscillator - gfxSleepMicroseconds(5); - release_bus(g); - break; - case powerSleep: - acquire_bus(g); - write_reg(g, 0x10, 0x0001); // enter sleep mode - release_bus(g); - break; - default: - return; - } - g->g.Powermode = (powermode_t)g->p.ptr; - return; - - case GDISP_CONTROL_ORIENTATION: - if (g->g.Orientation == (orientation_t)g->p.ptr) - return; - switch((orientation_t)g->p.ptr) { - case GDISP_ROTATE_0: - acquire_bus(g); - /* ID = 11 AM = 0 */ - write_reg(g, 0x11, 0x6070); - release_bus(g); - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - case GDISP_ROTATE_90: - acquire_bus(g); - /* ID = 01 AM = 1 */ - write_reg(g, 0x11, 0x6058); - release_bus(g); - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - case GDISP_ROTATE_180: - acquire_bus(g); - /* ID = 00 AM = 0 */ - write_reg(g, 0x11, 0x6040); - release_bus(g); - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - case GDISP_ROTATE_270: - acquire_bus(g); - /* ID = 10 AM = 1 */ - write_reg(g, 0x11, 0x6068); - release_bus(g); - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - default: - return; - } - g->g.Orientation = (orientation_t)g->p.ptr; - return; - - case GDISP_CONTROL_BACKLIGHT: - if ((unsigned)g->p.ptr > 100) - g->p.ptr = (void *)100; - set_backlight(g, (unsigned)g->p.ptr); - g->g.Backlight = (unsigned)g->p.ptr; - return; - - //case GDISP_CONTROL_CONTRAST: - default: - return; - } - } -#endif - -#endif /* GFX_USE_GDISP */ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file drivers/gdisp/SSD1289/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1289 display. + */ + +#include "gfx.h" + +#if GFX_USE_GDISP + +#define GDISP_DRIVER_VMT GDISPVMT_SSD1289 +#include "../drivers/gdisp/SSD1289/gdisp_lld_config.h" +#include "gdisp/lld/gdisp_lld.h" + +#include "board_SSD1289.h" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#ifndef GDISP_SCREEN_HEIGHT + #define GDISP_SCREEN_HEIGHT 320 +#endif +#ifndef GDISP_SCREEN_WIDTH + #define GDISP_SCREEN_WIDTH 240 +#endif +#ifndef GDISP_INITIAL_CONTRAST + #define GDISP_INITIAL_CONTRAST 50 +#endif +#ifndef GDISP_INITIAL_BACKLIGHT + #define GDISP_INITIAL_BACKLIGHT 100 +#endif + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +// Some common routines and macros +#define dummy_read(g) { volatile uint16_t dummy; dummy = read_data(g); (void) dummy; } +#define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); } + +static void set_cursor(GDisplay *g) { + /* + * Reg 0x004E is an 8 bit value - start x position + * Reg 0x004F is 9 bit - start y position + * Use a bit mask to make sure they are not set too high + */ + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + write_reg(g, 0x4e, g->p.x & 0x00FF); + write_reg(g, 0x4f, g->p.y & 0x01FF); + break; + case GDISP_ROTATE_90: + write_reg(g, 0x4e, g->p.y & 0x00FF); + write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF); + break; + case GDISP_ROTATE_180: + write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF); + write_reg(g, 0x4f, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF); + break; + case GDISP_ROTATE_270: + write_reg(g, 0x4e, (GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF); + write_reg(g, 0x4f, g->p.x & 0x01FF); + break; + } + write_index(g, 0x22); +} + +static void set_viewport(GDisplay* g) { + /* Reg 0x44 - Horizontal RAM address position + * Upper Byte - HEA + * Lower Byte - HSA + * 0 <= HSA <= HEA <= 0xEF + * Reg 0x45,0x46 - Vertical RAM address position + * Lower 9 bits gives 0-511 range in each value + * 0 <= Reg(0x45) <= Reg(0x46) <= 0x13F + * Use a bit mask to make sure they are not set too high + */ + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + write_reg(g, 0x44, (((g->p.x+g->p.cx-1) << 8) & 0xFF00 ) | (g->p.x & 0x00FF)); + write_reg(g, 0x45, g->p.y & 0x01FF); + write_reg(g, 0x46, (g->p.y+g->p.cy-1) & 0x01FF); + break; + case GDISP_ROTATE_90: + write_reg(g, 0x44, (((g->p.y+g->p.cy-1) << 8) & 0xFF00 ) | (g->p.y & 0x00FF)); + write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.x+g->p.cx)) & 0x01FF); + write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.x) & 0x01FF); + break; + case GDISP_ROTATE_180: + write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.x) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH - (g->p.x+g->p.cx)) & 0x00FF)); + write_reg(g, 0x45, (GDISP_SCREEN_HEIGHT-(g->p.y+g->p.cy)) & 0x01FF); + write_reg(g, 0x46, (GDISP_SCREEN_HEIGHT-1-g->p.y) & 0x01FF); + break; + case GDISP_ROTATE_270: + write_reg(g, 0x44, (((GDISP_SCREEN_WIDTH-1-g->p.y) & 0x00FF) << 8) | ((GDISP_SCREEN_WIDTH-(g->p.y+g->p.cy)) & 0x00FF)); + write_reg(g, 0x45, g->p.x & 0x01FF); + write_reg(g, 0x46, (g->p.x+g->p.cx-1) & 0x01FF); + break; + } +} + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + // No private area for this controller + g->priv = 0; + + // Initialise the board interface + init_board(g); + + // Hardware reset + setpin_reset(g, TRUE); + gfxSleepMilliseconds(20); + setpin_reset(g, FALSE); + gfxSleepMilliseconds(20); + + // Get the bus for the following initialisation commands + acquire_bus(g); + + write_reg(g, 0x00, 0x0001); gfxSleepMicroseconds(5); + write_reg(g, 0x03, 0xA8A4); gfxSleepMicroseconds(5); + write_reg(g, 0x0C, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x0D, 0x080C); gfxSleepMicroseconds(5); + write_reg(g, 0x0E, 0x2B00); gfxSleepMicroseconds(5); + write_reg(g, 0x1E, 0x00B0); gfxSleepMicroseconds(5); + write_reg(g, 0x01, 0x2B3F); gfxSleepMicroseconds(5); + write_reg(g, 0x02, 0x0600); gfxSleepMicroseconds(5); + write_reg(g, 0x10, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x11, 0x6070); gfxSleepMicroseconds(5); + write_reg(g, 0x05, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x06, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x16, 0xEF1C); gfxSleepMicroseconds(5); + write_reg(g, 0x17, 0x0003); gfxSleepMicroseconds(5); + write_reg(g, 0x07, 0x0133); gfxSleepMicroseconds(5); + write_reg(g, 0x0B, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x0F, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x41, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x42, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x48, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x49, 0x013F); gfxSleepMicroseconds(5); + write_reg(g, 0x4A, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x4B, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x44, 0xEF00); gfxSleepMicroseconds(5); + write_reg(g, 0x45, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x46, 0x013F); gfxSleepMicroseconds(5); + write_reg(g, 0x30, 0x0707); gfxSleepMicroseconds(5); + write_reg(g, 0x31, 0x0204); gfxSleepMicroseconds(5); + write_reg(g, 0x32, 0x0204); gfxSleepMicroseconds(5); + write_reg(g, 0x33, 0x0502); gfxSleepMicroseconds(5); + write_reg(g, 0x34, 0x0507); gfxSleepMicroseconds(5); + write_reg(g, 0x35, 0x0204); gfxSleepMicroseconds(5); + write_reg(g, 0x36, 0x0204); gfxSleepMicroseconds(5); + write_reg(g, 0x37, 0x0502); gfxSleepMicroseconds(5); + write_reg(g, 0x3A, 0x0302); gfxSleepMicroseconds(5); + write_reg(g, 0x3B, 0x0302); gfxSleepMicroseconds(5); + write_reg(g, 0x23, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x24, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x25, 0x8000); gfxSleepMicroseconds(5); + write_reg(g, 0x4f, 0x0000); gfxSleepMicroseconds(5); + write_reg(g, 0x4e, 0x0000); gfxSleepMicroseconds(5); + + // Finish Init + post_init_board(g); + + // Release the bus + release_bus(g); + + /* Turn on the back-light */ + set_backlight(g, GDISP_INITIAL_BACKLIGHT); + + /* Initialise the GDISP structure */ + g->g.Width = GDISP_SCREEN_WIDTH; + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->g.Backlight = GDISP_INITIAL_BACKLIGHT; + g->g.Contrast = GDISP_INITIAL_CONTRAST; + return TRUE; +} + +#if GDISP_HARDWARE_STREAM_WRITE + LLDSPEC void gdisp_lld_write_start(GDisplay *g) { + acquire_bus(g); + set_viewport(g); + #if !GDISP_HARDWARE_STREAM_POS + set_cursor(g); + #endif + } + LLDSPEC void gdisp_lld_write_color(GDisplay *g) { + write_data(g, g->p.color); + } + LLDSPEC void gdisp_lld_write_stop(GDisplay *g) { + release_bus(g); + } + #if GDISP_HARDWARE_STREAM_POS + LLDSPEC void gdisp_lld_write_pos(GDisplay *g) { + set_cursor(g); + } + #endif +#endif + +#if GDISP_HARDWARE_STREAM_READ + LLDSPEC void gdisp_lld_read_start(GDisplay *g) { + acquire_bus(g); + set_viewport(g); + set_cursor(g); + setreadmode(g); + dummy_read(g); + } + LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) { + return read_data(g); + } + LLDSPEC void gdisp_lld_read_stop(GDisplay *g) { + setwritemode(g); + release_bus(g); + } +#endif + +#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA) + LLDSPEC void gdisp_lld_fill_area(GDisplay *g) { + acquire_bus(g); + set_viewport(g); + set_cursor(g); + dma_with_noinc(g, &color, g->p.cx*g->p.cy) + release_bus(g); + } +#endif + +#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA) + LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { + pixel_t *buffer; + coord_t ycnt; + + buffer = (pixel_t *)g->p.ptr + g->p.x1 + g->p.y1 * g->p.x2; + + acquire_bus(g); + set_viewport(g); + set_cursor(g); + if (g->p.x2 == g->p.cx) { + dma_with_inc(g, buffer, g->p.cx*g->p.cy); + } else { + for (ycnt = g->p.cy; ycnt; ycnt--, buffer += g->p.x2) + dma_with_inc(g, buffer, g->p.cy); + } + release_bus(g); + } +#endif + +#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL + LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_POWER: + if (g->g.Powermode == (powermode_t)g->p.ptr) + return; + switch((powermode_t)g->p.ptr) { + case powerOff: + acquire_bus(g); + write_reg(g, 0x10, 0x0000); // leave sleep mode + write_reg(g, 0x07, 0x0000); // halt operation + write_reg(g, 0x00, 0x0000); // turn off oscillator + write_reg(g, 0x10, 0x0001); // enter sleep mode + release_bus(g); + break; + case powerOn: + acquire_bus(g); + write_reg(g, 0x10, 0x0000); // leave sleep mode + write_reg(g, 0x00, 0x0001); // turn on oscillator + gfxSleepMicroseconds(5); + release_bus(g); + break; + case powerSleep: + acquire_bus(g); + write_reg(g, 0x10, 0x0001); // enter sleep mode + release_bus(g); + break; + default: + return; + } + g->g.Powermode = (powermode_t)g->p.ptr; + return; + + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + case GDISP_ROTATE_0: + acquire_bus(g); + /* ID = 11 AM = 0 */ + write_reg(g, 0x11, 0x6070); + release_bus(g); + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + case GDISP_ROTATE_90: + acquire_bus(g); + /* ID = 01 AM = 1 */ + write_reg(g, 0x11, 0x6058); + release_bus(g); + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + case GDISP_ROTATE_180: + acquire_bus(g); + /* ID = 00 AM = 0 */ + write_reg(g, 0x11, 0x6040); + release_bus(g); + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + case GDISP_ROTATE_270: + acquire_bus(g); + /* ID = 10 AM = 1 */ + write_reg(g, 0x11, 0x6068); + release_bus(g); + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_BACKLIGHT: + if ((unsigned)g->p.ptr > 100) + g->p.ptr = (void *)100; + set_backlight(g, (unsigned)g->p.ptr); + g->g.Backlight = (unsigned)g->p.ptr; + return; + + //case GDISP_CONTROL_CONTRAST: + default: + return; + } + } +#endif + +#endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/SSD1306/gdisp_lld.mk b/drivers/gdisp/SSD1306/gdisp_lld.mk index ad320292..13df4230 100644 --- a/drivers/gdisp/SSD1306/gdisp_lld.mk +++ b/drivers/gdisp/SSD1306/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/SSD1306 -GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1306/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c diff --git a/drivers/gdisp/SSD1306/gdisp_lld.c b/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c similarity index 96% rename from drivers/gdisp/SSD1306/gdisp_lld.c rename to drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c index 390a9282..bd3e386d 100644 --- a/drivers/gdisp/SSD1306/gdisp_lld.c +++ b/drivers/gdisp/SSD1306/gdisp_lld_SSD1306.c @@ -1,280 +1,280 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/gdisp/SSD1306/gdisp_lld.c - * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1306 display. - */ - -#include "gfx.h" - -#if GFX_USE_GDISP - -#define GDISP_DRIVER_VMT GDISPVMT_SSD1306 -#include "../drivers/gdisp/SSD1306/gdisp_lld_config.h" -#include "gdisp/lld/gdisp_lld.h" - -#include "board_SSD1306.h" - -/*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -#ifndef GDISP_SCREEN_HEIGHT - #define GDISP_SCREEN_HEIGHT 64 // This controller should support 32 (untested) or 64 -#endif -#ifndef GDISP_SCREEN_WIDTH - #define GDISP_SCREEN_WIDTH 128 -#endif -#ifndef GDISP_INITIAL_CONTRAST - #define GDISP_INITIAL_CONTRAST 100 -#endif -#ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 -#endif -#ifdef SSD1306_PAGE_PREFIX - #define SSD1306_PAGE_WIDTH (GDISP_SCREEN_WIDTH+1) - #define SSD1306_PAGE_OFFSET 1 -#else - #define SSD1306_PAGE_WIDTH GDISP_SCREEN_WIDTH - #define SSD1306_PAGE_OFFSET 0 -#endif - -#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0) - -#include "SSD1306.h" - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -// Some common routines and macros -#define RAM(g) ((uint8_t *)g->priv) -#define write_cmd2(g, cmd1, cmd2) { write_cmd(g, cmd1); write_cmd(g, cmd2); } -#define write_cmd3(g, cmd1, cmd2, cmd3) { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); } - -// Some common routines and macros -#define delay(us) gfxSleepMicroseconds(us) -#define delayms(ms) gfxSleepMilliseconds(ms) - -#define xyaddr(x, y) (SSD1306_PAGE_OFFSET + (x) + ((y)>>3)*SSD1306_PAGE_WIDTH) -#define xybit(y) (1<<((y)&7)) - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * As this controller can't update on a pixel boundary we need to maintain the - * the entire display surface in memory so that we can do the necessary bit - * operations. Fortunately it is a small display in monochrome. - * 64 * 128 / 8 = 1024 bytes. - */ - -LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - // The private area is the display surface. - g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH); - - // Fill in the prefix command byte on each page line of the display buffer - // We can do it during initialisation as this byte is never overwritten. - #ifdef SSD1306_PAGE_PREFIX - { - unsigned i; - - for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH) - RAM(g)[i] = SSD1306_PAGE_PREFIX; - } - #endif - - // Initialise the board interface - init_board(g); - - // Hardware reset - setpin_reset(g, TRUE); - gfxSleepMilliseconds(20); - setpin_reset(g, FALSE); - gfxSleepMilliseconds(20); - - acquire_bus(g); - - write_cmd(g, SSD1306_DISPLAYOFF); - write_cmd2(g, SSD1306_SETDISPLAYCLOCKDIV, 0x80); - write_cmd2(g, SSD1306_SETMULTIPLEX, GDISP_SCREEN_HEIGHT-1); - write_cmd2(g, SSD1306_SETPRECHARGE, 0x1F); - write_cmd2(g, SSD1306_SETDISPLAYOFFSET, 0); - write_cmd(g, SSD1306_SETSTARTLINE | 0); - write_cmd2(g, SSD1306_ENABLE_CHARGE_PUMP, 0x14); - write_cmd2(g, SSD1306_MEMORYMODE, 0); - write_cmd(g, SSD1306_SEGREMAP+1); - write_cmd(g, SSD1306_COMSCANDEC); - #if GDISP_SCREEN_HEIGHT == 64 - write_cmd2(g, SSD1306_SETCOMPINS, 0x12); - #else - write_cmd2(g, SSD1306_SETCOMPINS, 0x22); - #endif - write_cmd2(g, SSD1306_SETCONTRAST, (uint8_t)(GDISP_INITIAL_CONTRAST*256/101)); // Set initial contrast. - write_cmd2(g, SSD1306_SETVCOMDETECT, 0x10); - write_cmd(g, SSD1306_DISPLAYON); - write_cmd(g, SSD1306_NORMALDISPLAY); - write_cmd3(g, SSD1306_HV_COLUMN_ADDRESS, 0, GDISP_SCREEN_WIDTH-1); - write_cmd3(g, SSD1306_HV_PAGE_ADDRESS, 0, GDISP_SCREEN_HEIGHT/8-1); - - // Finish Init - post_init_board(g); - - // Release the bus - release_bus(g); - - /* Initialise the GDISP structure */ - g->g.Width = GDISP_SCREEN_WIDTH; - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; - g->g.Backlight = GDISP_INITIAL_BACKLIGHT; - g->g.Contrast = GDISP_INITIAL_CONTRAST; - return TRUE; -} - -#if GDISP_HARDWARE_FLUSH - LLDSPEC void gdisp_lld_flush(GDisplay *g) { - unsigned i; - - // Don't flush if we don't need it. - if (!(g->flags & GDISP_FLG_NEEDFLUSH)) - return; - - write_cmd(g, SSD1306_SETSTARTLINE | 0); - - for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH) - write_data(g, RAM(g)+i, SSD1306_PAGE_WIDTH); - } -#endif - -#if GDISP_HARDWARE_DRAWPIXEL - LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { - coord_t x, y; - - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - x = g->p.x; - y = g->p.y; - break; - case GDISP_ROTATE_90: - x = g->p.y; - y = GDISP_SCREEN_HEIGHT-1 - g->p.x; - break; - case GDISP_ROTATE_180: - x = GDISP_SCREEN_WIDTH-1 - g->p.x; - y = GDISP_SCREEN_HEIGHT-1 - g->p.y; - break; - case GDISP_ROTATE_270: - x = GDISP_SCREEN_HEIGHT-1 - g->p.y; - x = g->p.x; - break; - } - if (g->p.color != Black) - RAM(g)[xyaddr(x, y)] |= xybit(y); - else - RAM(g)[xyaddr(x, y)] &= ~xybit(y); - g->flags |= GDISP_FLG_NEEDFLUSH; - } -#endif - -#if GDISP_HARDWARE_PIXELREAD - LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { - coord_t x, y; - - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - x = g->p.x; - y = g->p.y; - break; - case GDISP_ROTATE_90: - x = g->p.y; - y = GDISP_SCREEN_HEIGHT-1 - g->p.x; - break; - case GDISP_ROTATE_180: - x = GDISP_SCREEN_WIDTH-1 - g->p.x; - y = GDISP_SCREEN_HEIGHT-1 - g->p.y; - break; - case GDISP_ROTATE_270: - x = GDISP_SCREEN_HEIGHT-1 - g->p.y; - y = g->p.x; - break; - } - return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black; - } -#endif - -#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay *g) { - switch(g->p.x) { - case GDISP_CONTROL_POWER: - if (g->g.Powermode == (powermode_t)g->p.ptr) - return; - switch((powermode_t)g->p.ptr) { - case powerOff: - case powerSleep: - case powerDeepSleep: - acquire_bus(g); - write_cmd(g, SSD1306_DISPLAYOFF); - release_bus(g); - break; - case powerOn: - acquire_bus(g); - write_cmd(g, SSD1306_DISPLAYON); - release_bus(g); - break; - default: - return; - } - g->g.Powermode = (powermode_t)g->p.ptr; - return; - - case GDISP_CONTROL_ORIENTATION: - if (g->g.Orientation == (orientation_t)g->p.ptr) - return; - switch((orientation_t)g->p.ptr) { - /* Rotation is handled by the drawing routines */ - case GDISP_ROTATE_0: - case GDISP_ROTATE_180: - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - case GDISP_ROTATE_90: - case GDISP_ROTATE_270: - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - default: - return; - } - g->g.Orientation = (orientation_t)g->p.ptr; - return; - - case GDISP_CONTROL_CONTRAST: - if ((unsigned)g->p.ptr > 100) - g->p.ptr = (void *)100; - acquire_bus(g); - write_cmd2(g, SSD1306_SETCONTRAST, (((unsigned)g->p.ptr)<<8)/101); - release_bus(g); - g->g.Contrast = (unsigned)g->p.ptr; - return; - - // Our own special controller code to inverse the display - // 0 = normal, 1 = inverse - case GDISP_CONTROL_INVERSE: - acquire_bus(g); - write_cmd(g, g->p.ptr ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); - release_bus(g); - return; - } - } -#endif // GDISP_NEED_CONTROL - -#endif // GFX_USE_GDISP - +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file drivers/gdisp/SSD1306/gdisp_lld.c + * @brief GDISP Graphics Driver subsystem low level driver source for the SSD1306 display. + */ + +#include "gfx.h" + +#if GFX_USE_GDISP + +#define GDISP_DRIVER_VMT GDISPVMT_SSD1306 +#include "../drivers/gdisp/SSD1306/gdisp_lld_config.h" +#include "gdisp/lld/gdisp_lld.h" + +#include "board_SSD1306.h" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#ifndef GDISP_SCREEN_HEIGHT + #define GDISP_SCREEN_HEIGHT 64 // This controller should support 32 (untested) or 64 +#endif +#ifndef GDISP_SCREEN_WIDTH + #define GDISP_SCREEN_WIDTH 128 +#endif +#ifndef GDISP_INITIAL_CONTRAST + #define GDISP_INITIAL_CONTRAST 100 +#endif +#ifndef GDISP_INITIAL_BACKLIGHT + #define GDISP_INITIAL_BACKLIGHT 100 +#endif +#ifdef SSD1306_PAGE_PREFIX + #define SSD1306_PAGE_WIDTH (GDISP_SCREEN_WIDTH+1) + #define SSD1306_PAGE_OFFSET 1 +#else + #define SSD1306_PAGE_WIDTH GDISP_SCREEN_WIDTH + #define SSD1306_PAGE_OFFSET 0 +#endif + +#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0) + +#include "SSD1306.h" + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +// Some common routines and macros +#define RAM(g) ((uint8_t *)g->priv) +#define write_cmd2(g, cmd1, cmd2) { write_cmd(g, cmd1); write_cmd(g, cmd2); } +#define write_cmd3(g, cmd1, cmd2, cmd3) { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); } + +// Some common routines and macros +#define delay(us) gfxSleepMicroseconds(us) +#define delayms(ms) gfxSleepMilliseconds(ms) + +#define xyaddr(x, y) (SSD1306_PAGE_OFFSET + (x) + ((y)>>3)*SSD1306_PAGE_WIDTH) +#define xybit(y) (1<<((y)&7)) + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * As this controller can't update on a pixel boundary we need to maintain the + * the entire display surface in memory so that we can do the necessary bit + * operations. Fortunately it is a small display in monochrome. + * 64 * 128 / 8 = 1024 bytes. + */ + +LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + // The private area is the display surface. + g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH); + + // Fill in the prefix command byte on each page line of the display buffer + // We can do it during initialisation as this byte is never overwritten. + #ifdef SSD1306_PAGE_PREFIX + { + unsigned i; + + for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH) + RAM(g)[i] = SSD1306_PAGE_PREFIX; + } + #endif + + // Initialise the board interface + init_board(g); + + // Hardware reset + setpin_reset(g, TRUE); + gfxSleepMilliseconds(20); + setpin_reset(g, FALSE); + gfxSleepMilliseconds(20); + + acquire_bus(g); + + write_cmd(g, SSD1306_DISPLAYOFF); + write_cmd2(g, SSD1306_SETDISPLAYCLOCKDIV, 0x80); + write_cmd2(g, SSD1306_SETMULTIPLEX, GDISP_SCREEN_HEIGHT-1); + write_cmd2(g, SSD1306_SETPRECHARGE, 0x1F); + write_cmd2(g, SSD1306_SETDISPLAYOFFSET, 0); + write_cmd(g, SSD1306_SETSTARTLINE | 0); + write_cmd2(g, SSD1306_ENABLE_CHARGE_PUMP, 0x14); + write_cmd2(g, SSD1306_MEMORYMODE, 0); + write_cmd(g, SSD1306_SEGREMAP+1); + write_cmd(g, SSD1306_COMSCANDEC); + #if GDISP_SCREEN_HEIGHT == 64 + write_cmd2(g, SSD1306_SETCOMPINS, 0x12); + #else + write_cmd2(g, SSD1306_SETCOMPINS, 0x22); + #endif + write_cmd2(g, SSD1306_SETCONTRAST, (uint8_t)(GDISP_INITIAL_CONTRAST*256/101)); // Set initial contrast. + write_cmd2(g, SSD1306_SETVCOMDETECT, 0x10); + write_cmd(g, SSD1306_DISPLAYON); + write_cmd(g, SSD1306_NORMALDISPLAY); + write_cmd3(g, SSD1306_HV_COLUMN_ADDRESS, 0, GDISP_SCREEN_WIDTH-1); + write_cmd3(g, SSD1306_HV_PAGE_ADDRESS, 0, GDISP_SCREEN_HEIGHT/8-1); + + // Finish Init + post_init_board(g); + + // Release the bus + release_bus(g); + + /* Initialise the GDISP structure */ + g->g.Width = GDISP_SCREEN_WIDTH; + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->g.Backlight = GDISP_INITIAL_BACKLIGHT; + g->g.Contrast = GDISP_INITIAL_CONTRAST; + return TRUE; +} + +#if GDISP_HARDWARE_FLUSH + LLDSPEC void gdisp_lld_flush(GDisplay *g) { + unsigned i; + + // Don't flush if we don't need it. + if (!(g->flags & GDISP_FLG_NEEDFLUSH)) + return; + + write_cmd(g, SSD1306_SETSTARTLINE | 0); + + for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH) + write_data(g, RAM(g)+i, SSD1306_PAGE_WIDTH); + } +#endif + +#if GDISP_HARDWARE_DRAWPIXEL + LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { + coord_t x, y; + + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + x = g->p.x; + y = g->p.y; + break; + case GDISP_ROTATE_90: + x = g->p.y; + y = GDISP_SCREEN_HEIGHT-1 - g->p.x; + break; + case GDISP_ROTATE_180: + x = GDISP_SCREEN_WIDTH-1 - g->p.x; + y = GDISP_SCREEN_HEIGHT-1 - g->p.y; + break; + case GDISP_ROTATE_270: + x = GDISP_SCREEN_HEIGHT-1 - g->p.y; + x = g->p.x; + break; + } + if (g->p.color != Black) + RAM(g)[xyaddr(x, y)] |= xybit(y); + else + RAM(g)[xyaddr(x, y)] &= ~xybit(y); + g->flags |= GDISP_FLG_NEEDFLUSH; + } +#endif + +#if GDISP_HARDWARE_PIXELREAD + LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { + coord_t x, y; + + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + x = g->p.x; + y = g->p.y; + break; + case GDISP_ROTATE_90: + x = g->p.y; + y = GDISP_SCREEN_HEIGHT-1 - g->p.x; + break; + case GDISP_ROTATE_180: + x = GDISP_SCREEN_WIDTH-1 - g->p.x; + y = GDISP_SCREEN_HEIGHT-1 - g->p.y; + break; + case GDISP_ROTATE_270: + x = GDISP_SCREEN_HEIGHT-1 - g->p.y; + y = g->p.x; + break; + } + return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black; + } +#endif + +#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL + LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_POWER: + if (g->g.Powermode == (powermode_t)g->p.ptr) + return; + switch((powermode_t)g->p.ptr) { + case powerOff: + case powerSleep: + case powerDeepSleep: + acquire_bus(g); + write_cmd(g, SSD1306_DISPLAYOFF); + release_bus(g); + break; + case powerOn: + acquire_bus(g); + write_cmd(g, SSD1306_DISPLAYON); + release_bus(g); + break; + default: + return; + } + g->g.Powermode = (powermode_t)g->p.ptr; + return; + + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + /* Rotation is handled by the drawing routines */ + case GDISP_ROTATE_0: + case GDISP_ROTATE_180: + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + case GDISP_ROTATE_90: + case GDISP_ROTATE_270: + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_CONTRAST: + if ((unsigned)g->p.ptr > 100) + g->p.ptr = (void *)100; + acquire_bus(g); + write_cmd2(g, SSD1306_SETCONTRAST, (((unsigned)g->p.ptr)<<8)/101); + release_bus(g); + g->g.Contrast = (unsigned)g->p.ptr; + return; + + // Our own special controller code to inverse the display + // 0 = normal, 1 = inverse + case GDISP_CONTROL_INVERSE: + acquire_bus(g); + write_cmd(g, g->p.ptr ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); + release_bus(g); + return; + } + } +#endif // GDISP_NEED_CONTROL + +#endif // GFX_USE_GDISP + diff --git a/drivers/gdisp/SSD1963/gdisp_lld.mk b/drivers/gdisp/SSD1963/gdisp_lld.mk index ad406898..f56f11de 100644 --- a/drivers/gdisp/SSD1963/gdisp_lld.mk +++ b/drivers/gdisp/SSD1963/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/SSD1963 -GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1963/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c diff --git a/drivers/gdisp/SSD1963/gdisp_lld.c b/drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c similarity index 100% rename from drivers/gdisp/SSD1963/gdisp_lld.c rename to drivers/gdisp/SSD1963/gdisp_lld_SSD1963.c diff --git a/drivers/gdisp/SSD2119/gdisp_lld.mk b/drivers/gdisp/SSD2119/gdisp_lld.mk index 46807f62..921eaa2c 100644 --- a/drivers/gdisp/SSD2119/gdisp_lld.mk +++ b/drivers/gdisp/SSD2119/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/SSD2119 -GFXSRC += $(GFXLIB)/drivers/gdisp/SSD2119/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c similarity index 100% rename from drivers/gdisp/SSD2119/gdisp_lld.c rename to drivers/gdisp/SSD2119/gdisp_lld_SSD2119.c diff --git a/drivers/gdisp/ST7565/gdisp_lld.mk b/drivers/gdisp/ST7565/gdisp_lld.mk index cf0896e6..9f9c5408 100644 --- a/drivers/gdisp/ST7565/gdisp_lld.mk +++ b/drivers/gdisp/ST7565/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/ST7565 -GFXSRC += $(GFXLIB)/drivers/gdisp/ST7565/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/ST7565/gdisp_lld_ST7565.c diff --git a/drivers/gdisp/ST7565/gdisp_lld.c b/drivers/gdisp/ST7565/gdisp_lld_ST7565.c similarity index 100% rename from drivers/gdisp/ST7565/gdisp_lld.c rename to drivers/gdisp/ST7565/gdisp_lld_ST7565.c diff --git a/drivers/gdisp/TestStub/gdisp_lld.mk b/drivers/gdisp/TestStub/gdisp_lld.mk index 9394ee9d..d8faa3e9 100644 --- a/drivers/gdisp/TestStub/gdisp_lld.mk +++ b/drivers/gdisp/TestStub/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/gdisp/TestStub -GFXSRC += $(GFXLIB)/drivers/gdisp/TestStub/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/gdisp/TestStub/gdisp_lld_TestStub.c diff --git a/drivers/gdisp/TestStub/gdisp_lld.c b/drivers/gdisp/TestStub/gdisp_lld_TestStub.c similarity index 100% rename from drivers/gdisp/TestStub/gdisp_lld.c rename to drivers/gdisp/TestStub/gdisp_lld_TestStub.c diff --git a/drivers/multiple/Win32/gdisp_lld.mk b/drivers/multiple/Win32/gdisp_lld.mk index 081d8dda..f9242380 100644 --- a/drivers/multiple/Win32/gdisp_lld.mk +++ b/drivers/multiple/Win32/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/multiple/Win32 -GFXSRC += $(GFXLIB)/drivers/multiple/Win32/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/multiple/Win32/gdisp_lld_Win32.c diff --git a/drivers/multiple/Win32/gdisp_lld.c b/drivers/multiple/Win32/gdisp_lld_Win32.c similarity index 100% rename from drivers/multiple/Win32/gdisp_lld.c rename to drivers/multiple/Win32/gdisp_lld_Win32.c diff --git a/drivers/multiple/X/gdisp_lld.mk b/drivers/multiple/X/gdisp_lld.mk index e7b9daef..572a5b7d 100644 --- a/drivers/multiple/X/gdisp_lld.mk +++ b/drivers/multiple/X/gdisp_lld.mk @@ -1,2 +1,2 @@ GFXINC += $(GFXLIB)/drivers/multiple/X -GFXSRC += $(GFXLIB)/drivers/multiple/X/gdisp_lld.c +GFXSRC += $(GFXLIB)/drivers/multiple/X/gdisp_lld_X.c diff --git a/drivers/multiple/X/gdisp_lld.c b/drivers/multiple/X/gdisp_lld_X.c similarity index 100% rename from drivers/multiple/X/gdisp_lld.c rename to drivers/multiple/X/gdisp_lld_X.c