LCD initialization sequence according to the docs

The LCD initialization show now be much better and faster with no
flickering at the startup.

Also fix the contrast control.
This commit is contained in:
Fred Sundvik 2017-04-07 10:55:29 +03:00
parent 3994fb1e79
commit 995002fa91
2 changed files with 13 additions and 29 deletions

View file

@ -26,7 +26,7 @@
#define GDISP_SCREEN_WIDTH 128 #define GDISP_SCREEN_WIDTH 128
#endif #endif
#ifndef GDISP_INITIAL_CONTRAST #ifndef GDISP_INITIAL_CONTRAST
#define GDISP_INITIAL_CONTRAST 0 #define GDISP_INITIAL_CONTRAST 35
#endif #endif
#ifndef GDISP_INITIAL_BACKLIGHT #ifndef GDISP_INITIAL_BACKLIGHT
#define GDISP_INITIAL_BACKLIGHT 100 #define GDISP_INITIAL_BACKLIGHT 100
@ -111,41 +111,25 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
gfxSleepMilliseconds(20); gfxSleepMilliseconds(20);
setpin_reset(g, FALSE); setpin_reset(g, FALSE);
gfxSleepMilliseconds(20); gfxSleepMilliseconds(20);
acquire_bus(g); acquire_bus(g);
enter_cmd_mode(g); enter_cmd_mode(g);
write_cmd(g, ST7565_DISPLAY_OFF);
write_cmd(g, ST7565_RESET);
write_cmd(g, ST7565_LCD_BIAS); write_cmd(g, ST7565_LCD_BIAS);
write_cmd(g, ST7565_ADC); write_cmd(g, ST7565_ADC);
write_cmd(g, ST7565_COM_SCAN); write_cmd(g, ST7565_COM_SCAN);
write_cmd(g, ST7565_START_LINE | 0); write_cmd(g, ST7565_RESISTOR_RATIO | 0x1);
write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST);
write_cmd(g, ST7565_RESISTOR_RATIO | 0x6); // turn on internal power supply (VC=1, VR=1, VF=1)
// turn on voltage converter (VC=1, VR=0, VF=0)
write_cmd(g, ST7565_POWER_CONTROL | 0x04);
flush_cmd(g);
delay_ms(50);
// turn on voltage regulator (VC=1, VR=1, VF=0)
write_cmd(g, ST7565_POWER_CONTROL | 0x06);
flush_cmd(g);
delay_ms(50);
// turn on voltage follower (VC=1, VR=1, VF=1)
write_cmd(g, ST7565_POWER_CONTROL | 0x07); write_cmd(g, ST7565_POWER_CONTROL | 0x07);
flush_cmd(g);
delay_ms(50);
write_cmd(g, 0xE2);
write_cmd(g, ST7565_COM_SCAN);
write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101);
//write_cmd2(g, ST7565_CONTRAST, 0);
write_cmd(g, ST7565_DISPLAY_ON);
write_cmd(g, ST7565_ALLON_NORMAL);
write_cmd(g, ST7565_INVERT_DISPLAY); write_cmd(g, ST7565_INVERT_DISPLAY);
write_cmd(g, ST7565_ALLON_NORMAL);
write_cmd(g, ST7565_DISPLAY_ON);
write_cmd(g, ST7565_START_LINE | 0);
write_cmd(g, ST7565_RMW); write_cmd(g, ST7565_RMW);
flush_cmd(g); flush_cmd(g);
@ -331,14 +315,12 @@ LLDSPEC void gdisp_lld_control(GDisplay *g) {
return; return;
case GDISP_CONTROL_CONTRAST: case GDISP_CONTROL_CONTRAST:
if ((unsigned)g->p.ptr > 100) g->g.Contrast = (unsigned)g->p.ptr & 63;
g->p.ptr = (void *)100;
acquire_bus(g); acquire_bus(g);
enter_cmd_mode(g); enter_cmd_mode(g);
write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F); write_cmd2(g, ST7565_CONTRAST, g->g.Contrast);
flush_cmd(g); flush_cmd(g);
release_bus(g); release_bus(g);
g->g.Contrast = (unsigned)g->p.ptr;
return; return;
} }
} }

View file

@ -34,4 +34,6 @@
#define ST7565_RESISTOR_RATIO 0x20 #define ST7565_RESISTOR_RATIO 0x20
#define ST7565_POWER_CONTROL 0x28 #define ST7565_POWER_CONTROL 0x28
#define ST7565_RESET 0xE2
#endif /* _ST7565_H */ #endif /* _ST7565_H */