2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-03-24 19:01:20 +01:00
|
|
|
* Marlin 3D Printer Firmware
|
2017-12-05 09:18:25 +01:00
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2016-03-24 19:01:20 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-11-03 02:57:08 +01:00
|
|
|
// NOTE - the HAL version of the rrd device uses a generic ST7920 device. See the
|
|
|
|
// file u8g_dev_st7920_128x64_HAL.cpp for the HAL version.
|
2013-06-07 00:49:25 +02:00
|
|
|
|
2017-11-19 20:37:33 +01:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
2018-05-12 15:34:04 +02:00
|
|
|
#include "../../HAL/Delay.h"
|
2017-11-19 20:37:33 +01:00
|
|
|
|
2017-11-25 03:38:14 +01:00
|
|
|
#if ENABLED(U8GLIB_ST7920)
|
2017-11-19 20:37:33 +01:00
|
|
|
|
2017-12-21 19:05:25 +01:00
|
|
|
#if !(defined(U8G_HAL_LINKS) || defined(__SAM3X8E__))
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2013-06-07 00:49:25 +02:00
|
|
|
#define ST7920_CLK_PIN LCD_PINS_D4
|
|
|
|
#define ST7920_DAT_PIN LCD_PINS_ENABLE
|
|
|
|
#define ST7920_CS_PIN LCD_PINS_RS
|
|
|
|
|
2014-02-17 11:58:36 +01:00
|
|
|
//#define PAGE_HEIGHT 8 //128 byte framebuffer
|
Distribute GLCD screen updates in time
Currently we draw and send the screens for a graphical LCD all at once.
We draw in two or four parts but draw them directly behind each other.
For the tested status screen this takes 59-62ms in a single block.
During this time nothing else (except the interrupts) can be done.
When printing a sequence of very short moves the buffer drains - sometimes until it's empty.
This PR splits the screen update into parts.
Currently we have 10 time slots. During the first one the complete screen is drawn. (60,0,0,0,0,0,0,0,0,0,0)
Here i introduce pauses for doing other things. (30,30,0,0,0,0,0,0) or (15,15,15,15,0,0,0,0,0,0)
Drawing in consecutive time slots prevents from lagging too much. Even with a 4 stripe display all the drawing is done after 400ms.
Previous experiments with a even better distribution of the time slots like
(30,0,0,0,0,30,0,0,0,0) and (15,0,15,0,15,0,15,0,0,0) did not feel good when using the menu, because of too much lag.
Because of the previous PRs to speed up the display updates and especially reducing the difference between drawing 2 or 4 stripes,
it now makes sense for the REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER to go from 2 to 4 stripes. This costs about 1-2ms per complete
screen update, but is payed back by having partial updates lasting only the half time and two additional brakes. Also ~256 byte of
framebuffer are saved in RAM.
13:45:59.213 : echo: #:17 >:13 s:30; #:16 >:13 s:29; S#:33 S>:26 S:59
13:46:00.213 : echo: #:16 >:14 s:30; #:17 >:13 s:30; S#:33 S>:27 S:60
13:46:01.215 : echo: #:17 >:13 s:30; #:16 >:13 s:29; S#:33 S>:26 S:59
13:46:02.215 : echo: #:16 >:13 s:29; #:16 >:14 s:30; S#:32 S>:27 S:59
13:46:03.214 : echo: #:17 >:13 s:30; #:17 >:13 s:30; S#:34 S>:26 S:60
13:46:04.214 : echo: #:16 >:13 s:29; #:16 >:14 s:30; S#:32 S>:27 S:59
13:46:05.212 : echo: #:16 >:14 s:30; #:17 >:13 s:30; S#:33 S>:27 S:60
13:46:06.212 : echo: #:17 >:13 s:30; #:16 >:13 s:29; S#:33 S>:26 S:59
03:30:36.779 : echo: #:8 >:7 s:15; #:10 >:7 s:17; #:8 >:6 s:14; #:8 >:7 s:15; S#:34 S>:27 S:61
03:30:37.778 : echo: #:8 >:6 s:14; #:10 >:7 s:17; #:9 >:7 s:16; #:8 >:6 s:14; S#:35 S>:26 S:61
03:30:38.778 : echo: #:8 >:6 s:14; #:11 >:7 s:18; #:8 >:6 s:14; #:8 >:7 s:15; S#:35 S>:26 S:61
03:30:39.777 : echo: #:8 >:6 s:14; #:10 >:7 s:17; #:8 >:8 s:16; #:8 >:6 s:14; S#:34 S>:27 S:61
03:30:40.780 : echo: #:8 >:6 s:14; #:11 >:7 s:18; #:8 >:6 s:14; #:8 >:6 s:14; S#:35 S>:25 S:60
03:30:41.780 : echo: #:9 >:6 s:15; #:10 >:7 s:17; #:8 >:6 s:14; #:9 >:6 s:15; S#:36 S>:25 S:61
03:30:42.779 : echo: #:8 >:6 s:14; #:10 >:8 s:18; #:8 >:6 s:14; #:8 >:6 s:14; S#:34 S>:26 S:60
03:30:43.778 : echo: #:9 >:6 s:15; #:10 >:7 s:17; #:8 >:7 s:15; #:9 >:6 s:15; S#:36 S>:26 S:62
#: draw a stripe
>: transfer a stripe
s: sum of of draw and transfer for one stripe
S#: sum of draws for a complete screen
S>: sum of transfers for a complete screen
S: time to draw and transfer a complete screen
2016-11-24 21:17:25 +01:00
|
|
|
#define PAGE_HEIGHT 16 //256 byte framebuffer
|
|
|
|
//#define PAGE_HEIGHT 32 //512 byte framebuffer
|
2013-06-07 00:49:25 +02:00
|
|
|
|
2015-04-27 12:15:36 +02:00
|
|
|
#define LCD_PIXEL_WIDTH 128
|
|
|
|
#define LCD_PIXEL_HEIGHT 64
|
2013-06-07 00:49:25 +02:00
|
|
|
|
2018-02-20 00:39:40 +01:00
|
|
|
#include <U8glib.h>
|
|
|
|
|
2016-06-04 14:54:20 +02:00
|
|
|
//set optimization so ARDUINO optimizes this file
|
|
|
|
#pragma GCC optimize (3)
|
|
|
|
|
|
|
|
// If you want you can define your own set of delays in Configuration.h
|
2018-05-12 15:34:04 +02:00
|
|
|
//#define ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
//#define ST7920_DELAY_2 DELAY_NS(0)
|
|
|
|
//#define ST7920_DELAY_3 DELAY_NS(0)
|
2016-06-04 14:54:20 +02:00
|
|
|
|
|
|
|
#if F_CPU >= 20000000
|
2018-05-12 15:34:04 +02:00
|
|
|
#define CPU_ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_2 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_3 DELAY_NS(50)
|
2017-12-05 09:18:25 +01:00
|
|
|
#elif MB(3DRAG) || MB(K8200) || MB(K8400) || MB(SILVER_GATE)
|
2018-05-12 15:34:04 +02:00
|
|
|
#define CPU_ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_2 DELAY_NS(188)
|
|
|
|
#define CPU_ST7920_DELAY_3 DELAY_NS(0)
|
2017-12-05 09:18:25 +01:00
|
|
|
#elif MB(MINIRAMBO)
|
2018-05-12 15:34:04 +02:00
|
|
|
#define CPU_ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_2 DELAY_NS(250)
|
|
|
|
#define CPU_ST7920_DELAY_3 DELAY_NS(0)
|
2017-12-05 09:18:25 +01:00
|
|
|
#elif MB(RAMBO)
|
2018-05-12 15:34:04 +02:00
|
|
|
#define CPU_ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_2 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_3 DELAY_NS(0)
|
2016-06-04 14:54:20 +02:00
|
|
|
#elif F_CPU == 16000000
|
2018-05-12 15:34:04 +02:00
|
|
|
#define CPU_ST7920_DELAY_1 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_2 DELAY_NS(0)
|
|
|
|
#define CPU_ST7920_DELAY_3 DELAY_NS(63)
|
2016-06-04 14:54:20 +02:00
|
|
|
#else
|
|
|
|
#error "No valid condition for delays in 'ultralcd_st7920_u8glib_rrd.h'"
|
|
|
|
#endif
|
|
|
|
|
2016-06-26 03:32:13 +02:00
|
|
|
#ifndef ST7920_DELAY_1
|
|
|
|
#define ST7920_DELAY_1 CPU_ST7920_DELAY_1
|
|
|
|
#endif
|
|
|
|
#ifndef ST7920_DELAY_2
|
|
|
|
#define ST7920_DELAY_2 CPU_ST7920_DELAY_2
|
|
|
|
#endif
|
|
|
|
#ifndef ST7920_DELAY_3
|
|
|
|
#define ST7920_DELAY_3 CPU_ST7920_DELAY_3
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 04:59:18 +01:00
|
|
|
#define ST7920_SND_BIT \
|
|
|
|
WRITE(ST7920_CLK_PIN, LOW); ST7920_DELAY_1; \
|
|
|
|
WRITE(ST7920_DAT_PIN, val & 0x80); ST7920_DELAY_2; \
|
|
|
|
WRITE(ST7920_CLK_PIN, HIGH); ST7920_DELAY_3; \
|
|
|
|
val <<= 1
|
|
|
|
|
|
|
|
static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
|
|
|
|
ST7920_SND_BIT; // 1
|
|
|
|
ST7920_SND_BIT; // 2
|
|
|
|
ST7920_SND_BIT; // 3
|
|
|
|
ST7920_SND_BIT; // 4
|
|
|
|
ST7920_SND_BIT; // 5
|
|
|
|
ST7920_SND_BIT; // 6
|
|
|
|
ST7920_SND_BIT; // 7
|
|
|
|
ST7920_SND_BIT; // 8
|
|
|
|
}
|
|
|
|
|
2018-05-12 15:34:04 +02:00
|
|
|
#if DOGM_SPI_DELAY_US > 0
|
|
|
|
#define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
|
2016-11-25 04:49:55 +01:00
|
|
|
#else
|
2018-05-11 07:27:36 +02:00
|
|
|
#define U8G_DELAY() DELAY_US(10)
|
2016-11-25 04:49:55 +01:00
|
|
|
#endif
|
|
|
|
|
2017-08-03 00:45:42 +02:00
|
|
|
#define ST7920_CS() { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }
|
|
|
|
#define ST7920_NCS() { WRITE(ST7920_CS_PIN,0); }
|
2018-02-14 04:59:18 +01:00
|
|
|
#define ST7920_SET_CMD() { ST7920_SWSPI_SND_8BIT(0xF8); U8G_DELAY(); }
|
|
|
|
#define ST7920_SET_DAT() { ST7920_SWSPI_SND_8BIT(0xFA); U8G_DELAY(); }
|
|
|
|
#define ST7920_WRITE_BYTE(a) { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); U8G_DELAY(); }
|
|
|
|
#define ST7920_WRITE_BYTES(p,l) { for (uint8_t i = l + 1; --i;) { ST7920_SWSPI_SND_8BIT(*p&0xF0); ST7920_SWSPI_SND_8BIT(*p<<4); p++; } U8G_DELAY(); }
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2015-10-03 08:08:58 +02:00
|
|
|
uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
|
|
|
|
uint8_t i, y;
|
|
|
|
switch (msg) {
|
|
|
|
case U8G_DEV_MSG_INIT: {
|
2017-08-03 00:45:42 +02:00
|
|
|
OUT_WRITE(ST7920_CS_PIN, LOW);
|
2017-11-19 20:37:33 +01:00
|
|
|
OUT_WRITE(ST7920_DAT_PIN, LOW);
|
2018-02-14 04:59:18 +01:00
|
|
|
OUT_WRITE(ST7920_CLK_PIN, HIGH);
|
2017-08-03 00:45:42 +02:00
|
|
|
|
2015-10-03 08:08:58 +02:00
|
|
|
ST7920_CS();
|
|
|
|
u8g_Delay(120); //initial delay for boot up
|
|
|
|
ST7920_SET_CMD();
|
2018-02-14 22:43:54 +01:00
|
|
|
ST7920_WRITE_BYTE(0x20); //non-extended mode
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0x08); //display off, cursor+blink off
|
2018-02-14 22:43:54 +01:00
|
|
|
ST7920_WRITE_BYTE(0x01); //clear DDRAM ram
|
|
|
|
u8g_Delay(15); //delay for DDRAM clear
|
|
|
|
ST7920_WRITE_BYTE(0x24); //extended mode
|
|
|
|
ST7920_WRITE_BYTE(0x26); //extended mode + GDRAM active
|
2016-03-15 09:10:57 +01:00
|
|
|
for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0x80 | y); //set y
|
|
|
|
ST7920_WRITE_BYTE(0x80); //set x = 0
|
2015-10-03 08:08:58 +02:00
|
|
|
ST7920_SET_DAT();
|
2016-03-13 07:38:55 +01:00
|
|
|
for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0);
|
2013-06-07 00:49:25 +02:00
|
|
|
ST7920_SET_CMD();
|
|
|
|
}
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
|
2015-10-03 08:08:58 +02:00
|
|
|
ST7920_NCS();
|
|
|
|
}
|
|
|
|
break;
|
2017-11-03 02:57:08 +01:00
|
|
|
|
2017-12-05 09:18:25 +01:00
|
|
|
case U8G_DEV_MSG_STOP: break;
|
|
|
|
|
|
|
|
case U8G_DEV_MSG_PAGE_NEXT: {
|
2015-10-03 08:08:58 +02:00
|
|
|
uint8_t* ptr;
|
|
|
|
u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_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) {
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0x80 | y); //y
|
|
|
|
ST7920_WRITE_BYTE(0x80); //x=0
|
2015-10-03 08:08:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
|
|
|
|
ST7920_WRITE_BYTE(0x80 | 8); //x=64
|
2013-06-07 00:49:25 +02:00
|
|
|
}
|
2015-10-03 08:08:58 +02:00
|
|
|
ST7920_SET_DAT();
|
2018-02-14 04:59:18 +01:00
|
|
|
ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
|
2015-10-03 08:08:58 +02:00
|
|
|
y++;
|
2013-06-07 00:49:25 +02:00
|
|
|
}
|
2015-10-03 08:08:58 +02:00
|
|
|
ST7920_NCS();
|
|
|
|
}
|
|
|
|
break;
|
2013-06-07 00:49:25 +02:00
|
|
|
}
|
2016-11-25 04:49:55 +01:00
|
|
|
#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
|
2013-06-07 00:49:25 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 09:10:57 +01:00
|
|
|
uint8_t u8g_dev_st7920_128x64_rrd_buf[(LCD_PIXEL_WIDTH) * (PAGE_HEIGHT) / 8] U8G_NOCOMMON;
|
2015-10-03 08:08:58 +02:00
|
|
|
u8g_pb_t u8g_dev_st7920_128x64_rrd_pb = {{PAGE_HEIGHT, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_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};
|
2013-06-07 00:49:25 +02:00
|
|
|
|
2018-02-14 22:43:54 +01:00
|
|
|
#if ENABLED(LIGHTWEIGHT_UI)
|
|
|
|
// We have to include the code for the lightweight UI here
|
|
|
|
// as it relies on macros that are only defined in this file.
|
|
|
|
#include "status_screen_lite_ST7920_spi.h"
|
|
|
|
#endif
|
|
|
|
|
Decrease the needed nops to 1
by shitfing the left shift into the high phase.
```
2 cbi 0x2,1 ;set CLK //
1 in r18,__SREG__ //1
1-3 sbrc r24,7 //2-4
2 rjmp .L19 //4
1 cli .L19: //5
2 lds r25,258 lds r25,258 //7
1 andi r25,lo8(-2) ori r25,lo8(1) //8
2 sts 258,r25 sts 258,r25 //10
1 out __SREG__,r18 out __SREG__,r18 //11
2 .L3: rjmp .L3 //13 //2
2 sbi 0x2,1 ;reset CLK // //13-15 //2-4
1 lsl r24 ; val //1
1 nop //2
2 cbi 0x2,1 ;set CLK //4
...
```
2016-06-07 13:45:35 +02:00
|
|
|
#pragma GCC reset_options
|
2013-06-07 00:49:25 +02:00
|
|
|
|
2017-11-19 20:37:33 +01:00
|
|
|
#endif // U8G_HAL_LINKS
|
|
|
|
|
2017-11-25 03:38:14 +01:00
|
|
|
#endif // U8GLIB_ST7920
|