From da05b3ba94b9aa688dff2f6de5cef2d3c3c2211c Mon Sep 17 00:00:00 2001 From: Maik Stohn Date: Wed, 5 Jun 2013 16:27:44 +0200 Subject: [PATCH] faster GLCD (ST7920 SW-SPI) implementation / fixes - fixed long menu entries (>14 or >18 chars) caused overrun in dogm lcd implementation - fixed pin set problem when in interrupt - much faster ST7920 SW-SPI implementation - increased ST7920 framebuffer size for more speed --- Marlin/dogm_lcd_implementation.h | 9 +- Marlin/ultralcd_st7920_u8glib_rrd.h | 131 ++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 Marlin/ultralcd_st7920_u8glib_rrd.h diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h index 6b35b6aca..17a56adba 100644 --- a/Marlin/dogm_lcd_implementation.h +++ b/Marlin/dogm_lcd_implementation.h @@ -33,11 +33,11 @@ #define LCD_CLICKED (buttons&EN_C) #endif -// CHANGE_DE begin *** -#include // DE_U8glib +#include #include "DOGMbitmaps.h" #include "dogm_font_data_marlin.h" #include "ultralcd.h" +#include "ultralcd_st7920_u8glib_rrd.h" /* Russian language not supported yet, needs custom font @@ -74,11 +74,10 @@ #define FONT_STATUSMENU u8g_font_6x9 - // LCD selection #ifdef U8GLIB_ST7920 -// SPI Com: SCK = en = (D4), MOSI = rw = (RS), CS = di = (ENABLE) -U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); +//U8GLIB_ST7920_128X64_RRD u8g(0,0,0); +U8GLIB_ST7920_128X64_RRD u8g(0); #else U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 #endif diff --git a/Marlin/ultralcd_st7920_u8glib_rrd.h b/Marlin/ultralcd_st7920_u8glib_rrd.h new file mode 100644 index 000000000..e198a858a --- /dev/null +++ b/Marlin/ultralcd_st7920_u8glib_rrd.h @@ -0,0 +1,131 @@ +#ifndef ULCDST7920_H +#define ULCDST7920_H + +#include "Marlin.h" + +#ifdef U8GLIB_ST7920 + +//set optimization so ARDUINO optimizes this file +#pragma GCC optimize (3) + +#define ST7920_CLK_PIN LCD_PINS_D4 +#define ST7920_DAT_PIN LCD_PINS_ENABLE +#define ST7920_CS_PIN LCD_PINS_RS + +//#define PAGE_HEIGHT 8 //128 byte frambuffer +//#define PAGE_HEIGHT 16 //256 byte frambuffer +#define PAGE_HEIGHT 32 //512 byte framebuffer + +#define WIDTH 128 +#define HEIGHT 64 + +#include + +static void ST7920_SWSPI_SND_8BIT(uint8_t val) +{ + uint8_t i; + for( i=0; i<8; i++ ) + { + WRITE(ST7920_CLK_PIN,0); + WRITE(ST7920_DAT_PIN,val&0x80); + val<<=1; + WRITE(ST7920_CLK_PIN,1); + } +} + +#define ST7920_CS() {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();} +#define ST7920_NCS() {WRITE(ST7920_CS_PIN,0);} +#define ST7920_SET_CMD() {ST7920_SWSPI_SND_8BIT(0xf8);u8g_10MicroDelay();} +#define ST7920_SET_DAT() {ST7920_SWSPI_SND_8BIT(0xfa);u8g_10MicroDelay();} +#define ST7920_WRITE_BYTE(a) {ST7920_SWSPI_SND_8BIT((a)&0xf0);ST7920_SWSPI_SND_8BIT((a)<<4);u8g_10MicroDelay();} +#define ST7920_WRITE_BYTES(p,l) {uint8_t i;for(i=0;idev_mem); + y = pb->p.page_y0; + ptr = (uint8_t*)pb->buf; + + ST7920_CS(); + for( i = 0; i < PAGE_HEIGHT; i ++ ) + { + ST7920_SET_CMD(); + if ( y < 32 ) + { + ST7920_WRITE_BYTE(0x80 | y); //y + ST7920_WRITE_BYTE(0x80); //x=0 + } + else + { + ST7920_WRITE_BYTE(0x80 | (y-32)); //y + ST7920_WRITE_BYTE(0x80 | 8); //x=64 + } + + ST7920_SET_DAT(); + ST7920_WRITE_BYTES(ptr,WIDTH/8); //ptr is incremented inside of macro + y++; + } + ST7920_NCS(); + } + break; + } +#if PAGE_HEIGHT == 8 + return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); +#elif PAGE_HEIGHT == 16 + return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg); +#else + return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg); +#endif +} + +uint8_t u8g_dev_st7920_128x64_rrd_buf[WIDTH*(PAGE_HEIGHT/8)] U8G_NOCOMMON; +u8g_pb_t u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT,HEIGHT,0,0,0},WIDTH,u8g_dev_st7920_128x64_rrd_buf}; +u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = {u8g_dev_rrd_st7920_128x64_fn,&u8g_dev_st7920_128x64_rrd_pb,&u8g_com_null_fn}; + +class U8GLIB_ST7920_128X64_RRD : public U8GLIB +{ + public: + U8GLIB_ST7920_128X64_RRD(uint8_t dummy) : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi) {} +}; + + +#endif //U8GLIB_ST7920 +#endif //ULCDST7920_H