2013-09-14 22:32:57 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2013-09-14 22:32:57 +00:00
|
|
|
*/
|
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#include "gfx.h"
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#if GFX_USE_GDISP
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_ST7565
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "gdisp_lld_config.h"
|
|
|
|
#include "../../../src/gdisp/gdisp_driver.h"
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#include "board_ST7565.h"
|
2013-09-14 22:32:57 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef GDISP_SCREEN_HEIGHT
|
2013-10-22 09:53:39 +00:00
|
|
|
#define GDISP_SCREEN_HEIGHT 64
|
2013-09-14 22:32:57 +00:00
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SCREEN_WIDTH
|
2013-10-22 09:53:39 +00:00
|
|
|
#define GDISP_SCREEN_WIDTH 128
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_CONTRAST
|
|
|
|
#define GDISP_INITIAL_CONTRAST 51
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_BACKLIGHT
|
|
|
|
#define GDISP_INITIAL_BACKLIGHT 100
|
2013-09-14 22:32:57 +00:00
|
|
|
#endif
|
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
|
|
|
|
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "st7565.h"
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-12-14 11:11:48 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver config defaults for backward compatibility. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
#ifndef ST7565_LCD_BIAS
|
|
|
|
#define ST7565_LCD_BIAS ST7565_LCD_BIAS_7
|
|
|
|
#endif
|
|
|
|
#ifndef ST7565_ADC
|
|
|
|
#define ST7565_ADC ST7565_ADC_NORMAL
|
|
|
|
#endif
|
|
|
|
#ifndef ST7565_COM_SCAN
|
|
|
|
#define ST7565_COM_SCAN ST7565_COM_SCAN_INC
|
|
|
|
#endif
|
|
|
|
#ifndef ST7565_PAGE_ORDER
|
|
|
|
#define ST7565_PAGE_ORDER 0,1,2,3,4,5,6,7
|
|
|
|
#endif
|
|
|
|
|
2013-09-14 22:32:57 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
// Some common routines and macros
|
2013-10-22 09:53:39 +00:00
|
|
|
#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); }
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
// Some common routines and macros
|
|
|
|
#define delay(us) gfxSleepMicroseconds(us)
|
|
|
|
#define delay_ms(ms) gfxSleepMilliseconds(ms)
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#define xyaddr(x, y) ((x) + ((y)>>3)*GDISP_SCREEN_WIDTH)
|
|
|
|
#define xybit(y) (1<<((y)&7))
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2014-03-28 18:45:08 +00:00
|
|
|
/*
|
2013-10-22 09:53:39 +00:00
|
|
|
* 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.
|
2013-09-14 22:32:57 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
LLDSPEC gBool gdisp_lld_init(GDisplay *g) {
|
2013-10-22 09:53:39 +00:00
|
|
|
// The private area is the display surface.
|
|
|
|
g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8);
|
2016-08-26 19:45:41 +00:00
|
|
|
if (!g->priv) {
|
2018-06-23 03:02:07 +00:00
|
|
|
return gFalse;
|
2016-08-26 19:45:41 +00:00
|
|
|
}
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
// Initialise the board interface
|
|
|
|
init_board(g);
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
// Hardware reset
|
2018-06-23 03:02:07 +00:00
|
|
|
setpin_reset(g, gTrue);
|
2013-10-22 09:53:39 +00:00
|
|
|
gfxSleepMilliseconds(20);
|
2018-06-23 03:02:07 +00:00
|
|
|
setpin_reset(g, gFalse);
|
2013-10-22 09:53:39 +00:00
|
|
|
gfxSleepMilliseconds(20);
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
acquire_bus(g);
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-12-14 11:11:48 +00:00
|
|
|
write_cmd(g, ST7565_LCD_BIAS);
|
|
|
|
write_cmd(g, ST7565_ADC);
|
|
|
|
write_cmd(g, ST7565_COM_SCAN);
|
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
write_cmd(g, ST7565_START_LINE | 0);
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101);
|
|
|
|
write_cmd(g, ST7565_RESISTOR_RATIO | 0x3);
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
// turn on voltage converter (VC=1, VR=0, VF=0)
|
|
|
|
write_cmd(g, ST7565_POWER_CONTROL | 0x04);
|
|
|
|
delay_ms(50);
|
|
|
|
|
|
|
|
// turn on voltage regulator (VC=1, VR=1, VF=0)
|
|
|
|
write_cmd(g, ST7565_POWER_CONTROL | 0x06);
|
|
|
|
delay_ms(50);
|
|
|
|
|
|
|
|
// turn on voltage follower (VC=1, VR=1, VF=1)
|
|
|
|
write_cmd(g, ST7565_POWER_CONTROL | 0x07);
|
|
|
|
delay_ms(50);
|
|
|
|
|
|
|
|
write_cmd(g, ST7565_DISPLAY_ON);
|
|
|
|
write_cmd(g, ST7565_ALLON_NORMAL);
|
|
|
|
write_cmd(g, ST7565_POSITIVE_DISPLAY); // Disable Inversion of display.
|
|
|
|
|
|
|
|
write_cmd(g, ST7565_RMW);
|
|
|
|
|
|
|
|
// Finish Init
|
|
|
|
post_init_board(g);
|
|
|
|
|
|
|
|
// Release the bus
|
|
|
|
release_bus(g);
|
|
|
|
|
2016-08-26 19:45:41 +00:00
|
|
|
// Initialise the GDISP structure
|
2013-10-22 09:53:39 +00:00
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
2018-07-08 03:51:20 +00:00
|
|
|
g->g.Orientation = gOrientation0;
|
2018-07-08 01:47:36 +00:00
|
|
|
g->g.Powermode = gPowerOn;
|
2013-10-22 09:53:39 +00:00
|
|
|
g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
|
|
|
|
g->g.Contrast = GDISP_INITIAL_CONTRAST;
|
2016-08-26 19:45:41 +00:00
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
return gTrue;
|
2013-09-14 22:32:57 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#if GDISP_HARDWARE_FLUSH
|
|
|
|
LLDSPEC void gdisp_lld_flush(GDisplay *g) {
|
|
|
|
unsigned p;
|
|
|
|
|
|
|
|
// Don't flush if we don't need it.
|
|
|
|
if (!(g->flags & GDISP_FLG_NEEDFLUSH))
|
|
|
|
return;
|
|
|
|
|
|
|
|
acquire_bus(g);
|
2013-12-14 11:11:48 +00:00
|
|
|
uint8_t pagemap[8]={ST7565_PAGE_ORDER};
|
2013-10-22 09:53:39 +00:00
|
|
|
for (p = 0; p < 8; p++) {
|
2013-12-14 11:11:48 +00:00
|
|
|
write_cmd(g, ST7565_PAGE | pagemap[p]);
|
2013-10-22 09:53:39 +00:00
|
|
|
write_cmd(g, ST7565_COLUMN_MSB | 0);
|
|
|
|
write_cmd(g, ST7565_COLUMN_LSB | 0);
|
|
|
|
write_cmd(g, ST7565_RMW);
|
|
|
|
write_data(g, RAM(g) + (p*GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH);
|
|
|
|
}
|
|
|
|
release_bus(g);
|
2015-02-06 14:07:49 +00:00
|
|
|
|
|
|
|
g->flags &= ~GDISP_FLG_NEEDFLUSH;
|
2013-10-22 09:53:39 +00:00
|
|
|
}
|
2013-09-14 22:32:57 +00:00
|
|
|
#endif
|
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
|
|
|
LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord x, y;
|
2013-10-22 09:53:39 +00:00
|
|
|
|
|
|
|
switch(g->g.Orientation) {
|
2013-11-17 13:32:19 +00:00
|
|
|
default:
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation0:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = g->p.y;
|
|
|
|
y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation180:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation270:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
|
|
|
|
y = g->p.x;
|
|
|
|
break;
|
|
|
|
}
|
2018-03-10 10:36:12 +00:00
|
|
|
if (gdispColor2Native(g->p.color) != GFX_BLACK)
|
2013-10-22 09:53:39 +00:00
|
|
|
RAM(g)[xyaddr(x, y)] |= xybit(y);
|
|
|
|
else
|
|
|
|
RAM(g)[xyaddr(x, y)] &= ~xybit(y);
|
|
|
|
g->flags |= GDISP_FLG_NEEDFLUSH;
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#if GDISP_HARDWARE_PIXELREAD
|
2018-07-08 01:19:43 +00:00
|
|
|
LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay *g) {
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord x, y;
|
2013-10-22 09:53:39 +00:00
|
|
|
|
|
|
|
switch(g->g.Orientation) {
|
2013-11-17 13:32:19 +00:00
|
|
|
default:
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation0:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = g->p.y;
|
|
|
|
y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation180:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation270:
|
2013-10-22 09:53:39 +00:00
|
|
|
x = GDISP_SCREEN_HEIGHT-1 - g->p.y;
|
|
|
|
x = g->p.x;
|
|
|
|
break;
|
|
|
|
}
|
2018-03-10 10:36:12 +00:00
|
|
|
return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? GFX_WHITE : GFX_BLACK;
|
2013-10-22 09:53:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-09-14 22:32:57 +00:00
|
|
|
|
2013-10-22 09:53:39 +00:00
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
|
|
|
switch(g->p.x) {
|
|
|
|
case GDISP_CONTROL_POWER:
|
2018-07-08 01:47:36 +00:00
|
|
|
if (g->g.Powermode == (gPowermode)g->p.ptr)
|
2013-10-22 09:53:39 +00:00
|
|
|
return;
|
2018-07-08 01:47:36 +00:00
|
|
|
switch((gPowermode)g->p.ptr) {
|
|
|
|
case gPowerOff:
|
|
|
|
case gPowerSleep:
|
|
|
|
case gPowerDeepSleep:
|
2013-10-22 09:53:39 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_cmd(g, ST7565_DISPLAY_OFF);
|
|
|
|
release_bus(g);
|
|
|
|
break;
|
2018-07-08 01:47:36 +00:00
|
|
|
case gPowerOn:
|
2013-10-22 09:53:39 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_cmd(g, ST7565_DISPLAY_ON);
|
|
|
|
release_bus(g);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2018-07-08 01:47:36 +00:00
|
|
|
g->g.Powermode = (gPowermode)g->p.ptr;
|
2013-10-22 09:53:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
2018-07-08 03:51:20 +00:00
|
|
|
if (g->g.Orientation == (gOrientation)g->p.ptr)
|
2013-10-22 09:53:39 +00:00
|
|
|
return;
|
2018-07-08 03:51:20 +00:00
|
|
|
switch((gOrientation)g->p.ptr) {
|
2016-08-26 19:45:41 +00:00
|
|
|
// Rotation is handled by the drawing routines
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation0:
|
|
|
|
case gOrientation180:
|
2013-10-22 09:53:39 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
|
|
|
case gOrientation270:
|
2013-10-22 09:53:39 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2018-07-08 03:51:20 +00:00
|
|
|
g->g.Orientation = (gOrientation)g->p.ptr;
|
2013-10-22 09:53:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case GDISP_CONTROL_CONTRAST:
|
|
|
|
if ((unsigned)g->p.ptr > 100)
|
|
|
|
g->p.ptr = (void *)100;
|
|
|
|
acquire_bus(g);
|
|
|
|
write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F);
|
|
|
|
release_bus(g);
|
|
|
|
g->g.Contrast = (unsigned)g->p.ptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 22:32:57 +00:00
|
|
|
#endif // GDISP_NEED_CONTROL
|
|
|
|
|
|
|
|
#endif // GFX_USE_GDISP
|