Browse Source

LCD menu optimalization - LiquidCrystal_Prusa removed

Robert Pelnar 5 years ago
parent
commit
19a72ef9eb

+ 0 - 1
Firmware/Firmware.ino

@@ -33,4 +33,3 @@
 #include "Configuration.h"
 #include "pins.h"
 
-#include "LiquidCrystal_Prusa.h" // library for character LCD

+ 0 - 543
Firmware/LiquidCrystal_Prusa.cpp

@@ -1,543 +0,0 @@
-#include "LiquidCrystal_Prusa.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
-#include "Arduino.h"
-
-// When the display powers up, it is configured as follows:
-//
-// 1. Display clear
-// 2. Function set: 
-//    DL = 1; 8-bit interface data 
-//    N = 0; 1-line display 
-//    F = 0; 5x8 dot character font 
-// 3. Display on/off control: 
-//    D = 0; Display off 
-//    C = 0; Cursor off 
-//    B = 0; Blinking off 
-// 4. Entry mode set: 
-//    I/D = 1; Increment by 1 
-//    S = 0; No shift 
-//
-// Note, however, that resetting the Arduino doesn't reset the LCD, so we
-// can't assume that it's in that state when a sketch starts (and the
-// LiquidCrystal_Prusa constructor is called).
-
-LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
-			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
-{
-  init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
-}
-
-LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
-			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
-{
-  init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
-}
-
-LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
-			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
-{
-  init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
-}
-
-LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs,  uint8_t enable,
-			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
-{
-  init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
-}
-
-void LiquidCrystal_Prusa::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
-			 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-			 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
-{
-  _rs_pin = rs;
-  _rw_pin = rw;
-  _enable_pin = enable;
-  
-  _data_pins[0] = d0;
-  _data_pins[1] = d1;
-  _data_pins[2] = d2;
-  _data_pins[3] = d3; 
-  _data_pins[4] = d4;
-  _data_pins[5] = d5;
-  _data_pins[6] = d6;
-  _data_pins[7] = d7; 
-
-  pinMode(_rs_pin, OUTPUT);
-  // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
-  if (_rw_pin != 255) { 
-    pinMode(_rw_pin, OUTPUT);
-  }
-  pinMode(_enable_pin, OUTPUT);
-  
-  if (fourbitmode)
-    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
-  else 
-    _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
-  
-  begin(16, 1);  
-}
-
-void LiquidCrystal_Prusa::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
-  if (lines > 1) {
-    _displayfunction |= LCD_2LINE;
-  }
-  _numlines = lines;
-  _currline = 0;
-
-  // for some 1 line displays you can select a 10 pixel high font
-  if ((dotsize != 0) && (lines == 1)) {
-    _displayfunction |= LCD_5x10DOTS;
-  }
-
-  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-  // according to datasheet, we need at least 40ms after power rises above 2.7V
-  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
-  delayMicroseconds(50000); 
-  // Now we pull both RS and R/W low to begin commands
-  digitalWrite(_rs_pin, LOW);
-  digitalWrite(_enable_pin, LOW);
-  if (_rw_pin != 255) { 
-    digitalWrite(_rw_pin, LOW);
-  }
-  
-  //put the LCD into 4 bit or 8 bit mode
-  if (! (_displayfunction & LCD_8BITMODE)) {
-    // this is according to the hitachi HD44780 datasheet
-    // figure 24, pg 46
-
-    // we start in 8bit mode, try to set 4 bit mode
-    write4bits(0x03);
-    delayMicroseconds(4500); // wait min 4.1ms
-
-    // second try
-    write4bits(0x03);
-    delayMicroseconds(4500); // wait min 4.1ms
-    
-    // third go!
-    write4bits(0x03); 
-    delayMicroseconds(150);
-
-    // finally, set to 4-bit interface
-    write4bits(0x02); 
-  } else {
-    // this is according to the hitachi HD44780 datasheet
-    // page 45 figure 23
-
-    // Send function set command sequence
-    command(LCD_FUNCTIONSET | _displayfunction);
-    delayMicroseconds(4500);  // wait more than 4.1ms
-
-    // second try
-    command(LCD_FUNCTIONSET | _displayfunction);
-    delayMicroseconds(150);
-
-    // third go
-    command(LCD_FUNCTIONSET | _displayfunction);
-  }
-
-  // finally, set # lines, font size, etc.
-  command(LCD_FUNCTIONSET | _displayfunction);  
-  delayMicroseconds(60);
-  // turn the display on with no cursor or blinking default
-  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
-  display();
-  delayMicroseconds(60);
-  // clear it off
-  clear();
-  delayMicroseconds(3000);
-  // Initialize to default text direction (for romance languages)
-  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-  // set the entry mode
-  command(LCD_ENTRYMODESET | _displaymode);
-  delayMicroseconds(60);
-
-  _escape[0] = 0;
-
-}
-
-
-
-void LiquidCrystal_Prusa::begin_noclear(uint8_t cols, uint8_t lines, uint8_t dotsize) {
-  if (lines > 1) {
-    _displayfunction |= LCD_2LINE;
-  }
-  _numlines = lines;
-  _currline = 0;
-
-  // for some 1 line displays you can select a 10 pixel high font
-  if ((dotsize != 0) && (lines == 1)) {
-    _displayfunction |= LCD_5x10DOTS;
-  }
-
-  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-  // according to datasheet, we need at least 40ms after power rises above 2.7V
-  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
-  delayMicroseconds(50000); 
-  // Now we pull both RS and R/W low to begin commands
-  digitalWrite(_rs_pin, LOW);
-  digitalWrite(_enable_pin, LOW);
-  if (_rw_pin != 255) { 
-    digitalWrite(_rw_pin, LOW);
-  }
-  
-  //put the LCD into 4 bit or 8 bit mode
-  if (! (_displayfunction & LCD_8BITMODE)) {
-    // this is according to the hitachi HD44780 datasheet
-    // figure 24, pg 46
-
-    // we start in 8bit mode, try to set 4 bit mode
-    write4bits(0x03);
-    delayMicroseconds(4500); // wait min 4.1ms
-
-    // second try
-    write4bits(0x03);
-    delayMicroseconds(4500); // wait min 4.1ms
-    
-    // third go!
-    write4bits(0x03); 
-    delayMicroseconds(150);
-
-    // finally, set to 4-bit interface
-    write4bits(0x02); 
-  } else {
-    // this is according to the hitachi HD44780 datasheet
-    // page 45 figure 23
-
-    // Send function set command sequence
-    command(LCD_FUNCTIONSET | _displayfunction);
-    delayMicroseconds(4500);  // wait more than 4.1ms
-
-    // second try
-    command(LCD_FUNCTIONSET | _displayfunction);
-    delayMicroseconds(150);
-
-    // third go
-    command(LCD_FUNCTIONSET | _displayfunction);
-  }
-
-  // finally, set # lines, font size, etc.
-  command(LCD_FUNCTIONSET | _displayfunction);  
-  delayMicroseconds(60);
-
-  // turn the display on with no cursor or blinking default
-  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
-  display();
-  delayMicroseconds(60);
-  // clear it off
-  //clear();
-
-  home();
-  delayMicroseconds(1600);
-  // Initialize to default text direction (for romance languages)
-  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-  // set the entry mode
-  command(LCD_ENTRYMODESET | _displaymode);
-  delayMicroseconds(60);
-/*
-  setCursor(8,0);
-  print("    ");
-  setCursor(8,1);
-  print("    ");
-  setCursor(6,2);
-  print("      ");
-*/
-
-}
-
-
-
-
-/********** high level commands, for the user! */
-void LiquidCrystal_Prusa::clear()
-{
-  command(LCD_CLEARDISPLAY);  // clear display, set cursor position to zero
-  delayMicroseconds(1600);  // this command takes a long time
-  
-}
-
-void LiquidCrystal_Prusa::home()
-{
-  command(LCD_RETURNHOME);  // set cursor position to zero
-  delayMicroseconds(1600);  // this command takes a long time!
-  
-}
-
-void LiquidCrystal_Prusa::setCursor(uint8_t col, uint8_t row)
-{
-  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
-  if ( row >= _numlines ) {
-    row = _numlines-1;    // we count rows starting w/0
-  }
-  _currline = row;  
-  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
-}
-
-// Turn the display on/off (quickly)
-void LiquidCrystal_Prusa::noDisplay() {
-  _displaycontrol &= ~LCD_DISPLAYON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-void LiquidCrystal_Prusa::display() {
-  _displaycontrol |= LCD_DISPLAYON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-
-// Turns the underline cursor on/off
-void LiquidCrystal_Prusa::noCursor() {
-  _displaycontrol &= ~LCD_CURSORON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-void LiquidCrystal_Prusa::cursor() {
-  _displaycontrol |= LCD_CURSORON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-
-// Turn on and off the blinking cursor
-void LiquidCrystal_Prusa::noBlink() {
-  _displaycontrol &= ~LCD_BLINKON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-void LiquidCrystal_Prusa::blink() {
-  _displaycontrol |= LCD_BLINKON;
-  command(LCD_DISPLAYCONTROL | _displaycontrol);
-}
-
-// These commands scroll the display without changing the RAM
-void LiquidCrystal_Prusa::scrollDisplayLeft(void) {
-  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
-}
-void LiquidCrystal_Prusa::scrollDisplayRight(void) {
-  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
-}
-
-// This is for text that flows Left to Right
-void LiquidCrystal_Prusa::leftToRight(void) {
-  _displaymode |= LCD_ENTRYLEFT;
-  command(LCD_ENTRYMODESET | _displaymode);
-}
-
-// This is for text that flows Right to Left
-void LiquidCrystal_Prusa::rightToLeft(void) {
-  _displaymode &= ~LCD_ENTRYLEFT;
-  command(LCD_ENTRYMODESET | _displaymode);
-}
-
-// This will 'right justify' text from the cursor
-void LiquidCrystal_Prusa::autoscroll(void) {
-  _displaymode |= LCD_ENTRYSHIFTINCREMENT;
-  command(LCD_ENTRYMODESET | _displaymode);
-}
-
-// This will 'left justify' text from the cursor
-void LiquidCrystal_Prusa::noAutoscroll(void) {
-  _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
-  command(LCD_ENTRYMODESET | _displaymode);
-}
-
-
-/*********** mid level commands, for sending data/cmds */
-
-void LiquidCrystal_Prusa::command(uint8_t value) {
-  send(value, LOW);
-}
-
-size_t LiquidCrystal_Prusa::write(uint8_t value) {
-  if (value == '\n')
-  {
-    if (_currline > 3) _currline = -1;
-	setCursor(0, _currline + 1); // LF
-	return 1;
-  }
-  if (_escape[0] || (value == 0x1b))
-    return escape_write(value);
-  send(value, HIGH);
-  return 1; // assume sucess
-}
-
-//Supported VT100 escape codes:
-//EraseScreen  "\x1b[2J"
-//CursorHome   "\x1b[%d;%dH"
-//CursorShow   "\x1b[?25h"
-//CursorHide   "\x1b[?25l"
-
-size_t LiquidCrystal_Prusa::escape_write(uint8_t chr)
-{
-#define escape_cnt (_escape[0])        //escape character counter
-#define is_num_msk (_escape[1])        //numeric character bit mask
-#define chr_is_num (is_num_msk & 0x01) //current character is numeric
-#define e_2_is_num (is_num_msk & 0x04) //escape char 2 is numeric
-#define e_3_is_num (is_num_msk & 0x08) //...
-#define e_4_is_num (is_num_msk & 0x10)
-#define e_5_is_num (is_num_msk & 0x20)
-#define e_6_is_num (is_num_msk & 0x40)
-#define e_7_is_num (is_num_msk & 0x80)
-#define e2_num (_escape[2] - '0')      //number from character 2
-#define e3_num (_escape[3] - '0')      //number from character 3
-#define e23_num (10*e2_num+e3_num)     //number from characters 2 and 3
-#define e4_num (_escape[4] - '0')      //number from character 4
-#define e5_num (_escape[5] - '0')      //number from character 5
-#define e45_num (10*e4_num+e5_num)     //number from characters 4 and 5
-#define e6_num (_escape[6] - '0')      //number from character 6
-#define e56_num (10*e5_num+e6_num)     //number from characters 5 and 6
-	if (escape_cnt > 1) // escape length > 1 = "\x1b["
-	{
-		_escape[escape_cnt] = chr; // store current char
-		if ((chr >= '0') && (chr <= '9')) // char is numeric
-			is_num_msk |= (1 | (1 << escape_cnt)); //set mask
-		else
-			is_num_msk &= ~1; //clear mask
-	}
-	switch (escape_cnt++)
-	{
-	case 0:
-		if (chr == 0x1b) return 1;  // escape = "\x1b"
-		break;
-	case 1:
-		is_num_msk = 0x00; // reset 'is number' bit mask
-		if (chr == '[') return 1; // escape = "\x1b["
-		break;
-	case 2:
-		switch (chr)
-		{
-		case '2': return 1; // escape = "\x1b[2"
-		case '?': return 1; // escape = "\x1b[?"
-		default:
-			if (chr_is_num) return 1; // escape = "\x1b[%1d"
-		}
-		break;
-	case 3:
-		switch (_escape[2])
-		{
-		case '?': // escape = "\x1b[?"
-			if (chr == '2') return 1; // escape = "\x1b[?2"
-			break;
-		case '2':
-			if (chr == 'J') // escape = "\x1b[2J"
-				{ clear(); _currline = 0; break; } // EraseScreen
-		default:
-			if (e_2_is_num && // escape = "\x1b[%1d"
-				((chr == ';') || // escape = "\x1b[%1d;"
-				chr_is_num)) // escape = "\x1b[%2d"
-				return 1;
-		}
-		break;
-	case 4:
-		switch (_escape[2])
-		{
-		case '?': // "\x1b[?"
-			if ((_escape[3] == '2') && (chr == '5')) return 1; // escape = "\x1b[?25"
-			break;
-		default:
-			if (e_2_is_num) // escape = "\x1b[%1d"
-			{
-				if ((_escape[3] == ';') && chr_is_num) return 1; // escape = "\x1b[%1d;%1d"
-				else if (e_3_is_num && (chr == ';')) return 1; // escape = "\x1b[%2d;"
-			}
-		}
-		break;
-	case 5:
-		switch (_escape[2])
-		{
-		case '?':
-			if ((_escape[3] == '2') && (_escape[4] == '5')) // escape = "\x1b[?25"
-				switch (chr)
-				{
-				case 'h': // escape = "\x1b[?25h"
-  					void cursor(); // CursorShow
-					break;
-				case 'l': // escape = "\x1b[?25l"
-					noCursor(); // CursorHide
-					break;
-				}
-			break;
-		default:
-			if (e_2_is_num) // escape = "\x1b[%1d"
-			{
-				if ((_escape[3] == ';') && e_4_is_num) // escape = "\x1b%1d;%1dH"
-				{
-					if (chr == 'H') // escape = "\x1b%1d;%1dH"
-						setCursor(e4_num, e2_num); // CursorHome
-					else if (chr_is_num)
-						return 1; // escape = "\x1b%1d;%2d"
-				}
-				else if (e_3_is_num && (_escape[4] == ';') && chr_is_num)
-					return 1; // escape = "\x1b%2d;%1d"
-			}
-		}
-		break;
-	case 6:
-		if (e_2_is_num) // escape = "\x1b[%1d"
-		{
-			if ((_escape[3] == ';') && e_4_is_num && e_5_is_num && (chr == 'H')) // escape = "\x1b%1d;%2dH"
-				setCursor(e45_num, e2_num); // CursorHome
-			else if (e_3_is_num && (_escape[4] == ';') && e_5_is_num) // escape = "\x1b%2d;%1d"
-			{
-				if (chr == 'H') // escape = "\x1b%2d;%1dH"
-					setCursor(e5_num, e23_num); // CursorHome
-				else if (chr_is_num) // "\x1b%2d;%2d"
-					return 1;
-			}
-		}
-		break;
-	case 7:
-		if (e_2_is_num && e_3_is_num && (_escape[4] == ';')) // "\x1b[%2d;"
-			if (e_5_is_num && e_6_is_num && (chr == 'H')) // "\x1b[%2d;%2dH"
-				setCursor(e56_num, e23_num); // CursorHome
-		break;
-	}
-	escape_cnt = 0; // reset escape
-end:
-	return 1; // assume sucess
-}
-
-
-/************ low level data pushing commands **********/
-
-// write either command or data, with automatic 4/8-bit selection
-void LiquidCrystal_Prusa::send(uint8_t value, uint8_t mode) {
-  digitalWrite(_rs_pin, mode);
-
-  // if there is a RW pin indicated, set it low to Write
-  if (_rw_pin != 255) { 
-    digitalWrite(_rw_pin, LOW);
-  }
-  
-  if (_displayfunction & LCD_8BITMODE) {
-    write8bits(value); 
-  } else {
-    write4bits(value>>4);
-    write4bits(value);
-  }
-}
-
-void LiquidCrystal_Prusa::pulseEnable(void) {
-  digitalWrite(_enable_pin, LOW);
-  delayMicroseconds(1);    
-  digitalWrite(_enable_pin, HIGH);
-  delayMicroseconds(1);    // enable pulse must be >450ns
-  digitalWrite(_enable_pin, LOW);
-  delayMicroseconds(100);   // commands need > 37us to settle
-}
-
-void LiquidCrystal_Prusa::write4bits(uint8_t value) {
-  for (int i = 0; i < 4; i++) {
-    pinMode(_data_pins[i], OUTPUT);
-    digitalWrite(_data_pins[i], (value >> i) & 0x01);
-  }
-
-  pulseEnable();
-}
-
-void LiquidCrystal_Prusa::write8bits(uint8_t value) {
-  for (int i = 0; i < 8; i++) {
-    pinMode(_data_pins[i], OUTPUT);
-    digitalWrite(_data_pins[i], (value >> i) & 0x01);
-  }
-  
-  pulseEnable();
-}

+ 0 - 114
Firmware/LiquidCrystal_Prusa.h

@@ -1,114 +0,0 @@
-#ifndef LiquidCrystal_Prusa_h
-#define LiquidCrystal_Prusa_h
-
-#include <inttypes.h>
-#include <stddef.h>
-
-// commands
-#define LCD_CLEARDISPLAY 0x01
-#define LCD_RETURNHOME 0x02
-#define LCD_ENTRYMODESET 0x04
-#define LCD_DISPLAYCONTROL 0x08
-#define LCD_CURSORSHIFT 0x10
-#define LCD_FUNCTIONSET 0x20
-#define LCD_SETCGRAMADDR 0x40
-#define LCD_SETDDRAMADDR 0x80
-
-// flags for display entry mode
-#define LCD_ENTRYRIGHT 0x00
-#define LCD_ENTRYLEFT 0x02
-#define LCD_ENTRYSHIFTINCREMENT 0x01
-#define LCD_ENTRYSHIFTDECREMENT 0x00
-
-// flags for display on/off control
-#define LCD_DISPLAYON 0x04
-#define LCD_DISPLAYOFF 0x00
-#define LCD_CURSORON 0x02
-#define LCD_CURSOROFF 0x00
-#define LCD_BLINKON 0x01
-#define LCD_BLINKOFF 0x00
-
-// flags for display/cursor shift
-#define LCD_DISPLAYMOVE 0x08
-#define LCD_CURSORMOVE 0x00
-#define LCD_MOVERIGHT 0x04
-#define LCD_MOVELEFT 0x00
-
-// flags for function set
-#define LCD_8BITMODE 0x10
-#define LCD_4BITMODE 0x00
-#define LCD_2LINE 0x08
-#define LCD_1LINE 0x00
-#define LCD_5x10DOTS 0x04
-#define LCD_5x8DOTS 0x00
-
-class LiquidCrystal_Prusa/* : public Print */{
-public:
-  LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
-		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
-  LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
-		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
-  LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
-		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
-  LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
-		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
-
-  void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
-	    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
-	    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
-    
-  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
-
-  void begin_noclear(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
-
-  void clear();
-  void home();
-
-  void noDisplay();
-  void display();
-  void noBlink();
-  void blink();
-  void noCursor();
-  void cursor();
-  void scrollDisplayLeft();
-  void scrollDisplayRight();
-  void leftToRight();
-  void rightToLeft();
-  void autoscroll();
-  void noAutoscroll();
-
-  void setCursor(uint8_t, uint8_t); 
-  size_t write(uint8_t);
-  void command(uint8_t);
-public:
-  void send(uint8_t, uint8_t);
-  void write4bits(uint8_t);
-  void write8bits(uint8_t);
-  void pulseEnable();
-
-  uint8_t _rs_pin; // LOW: command.  HIGH: character.
-  uint8_t _rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
-  uint8_t _enable_pin; // activated by a HIGH pulse.
-  uint8_t _data_pins[8];
-
-  uint8_t _displayfunction;
-  uint8_t _displaycontrol;
-  uint8_t _displaymode;
-
-  uint8_t _initialized;
-
-  uint8_t _numlines,_currline;
-
-  uint8_t _escape[8];
-  size_t escape_write(uint8_t value);
-  
-};
-
-#define ESC_2J     "\x1b[2J"
-#define ESC_25h    "\x1b[?25h"
-#define ESC_25l    "\x1b[?25l"
-#define ESC_H(c,r) "\x1b["#r";"#c"H"
-
-#endif

+ 6 - 7
Firmware/Marlin_main.cpp

@@ -907,8 +907,8 @@ void factory_reset(char level, bool quiet)
     
 
 }
-#include "LiquidCrystal_Prusa.h"
-extern LiquidCrystal_Prusa lcd;
+//#include "LiquidCrystal_Prusa.h"
+//extern LiquidCrystal_Prusa lcd;
 
 
 FILE _uartout = {0};
@@ -1148,8 +1148,7 @@ void list_sec_lang_from_external_flash()
 // are initialized by the main() routine provided by the Arduino framework.
 void setup()
 {
-    lcd_init();
-	fdev_setup_stream(lcdout, lcd_putchar, NULL, _FDEV_SETUP_WRITE); //setup lcdout stream
+    ultralcd_init();
 
 	spi_init();
 
@@ -1157,7 +1156,7 @@ void setup()
 
 #ifdef W25X20CL
   // Enter an STK500 compatible Optiboot boot loader waiting for flashing the languages to an external flash memory.
-  optiboot_w25x20cl_enter();
+ // optiboot_w25x20cl_enter();
 #endif
 
 #if (LANG_MODE != 0) //secondary language support
@@ -7603,9 +7602,9 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
                 {
                     lcd_update_enable(false);
                     lcd_clear();
-                    lcd.setCursor(0, 0);
+                    lcd_set_cursor(0, 0);
                     lcd_puts_P(_T(MSG_ERROR));
-                    lcd.setCursor(0, 2);
+                    lcd_set_cursor(0, 2);
                     lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
                     delay(2000);
                     lcd_clear();

+ 0 - 2
Firmware/fsensor.cpp

@@ -9,8 +9,6 @@
 #include "fastio.h"
 #include "cmdqueue.h"
 
-//#include "LiquidCrystal_Prusa.h"
-//extern LiquidCrystal_Prusa lcd;
 
 
 #define FSENSOR_ERR_MAX          5  //filament sensor max error count

+ 424 - 31
Firmware/lcd.cpp

@@ -7,7 +7,16 @@
 #include <avr/delay.h>
 #include "Timer.h"
 
-/*
+#include "Configuration.h"
+#include "pins.h"
+#include <binary.h>
+//#include <Arduino.h>
+#include "Marlin.h"
+#include "fastio.h"
+
+
+
+
 
 // commands
 #define LCD_CLEARDISPLAY 0x01
@@ -47,53 +56,317 @@
 #define LCD_5x10DOTS 0x04
 #define LCD_5x8DOTS 0x00
 
-*/
-
-LiquidCrystal_Prusa lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7
 
 
+//LiquidCrystal_Prusa lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7
+//LiquidCrystal_Prusa lcd;  //RS,Enable,D4,D5,D6,D7
 
 
 FILE _lcdout = {0};
 
-int lcd_putchar(char c, FILE *stream)
+
+uint8_t lcd_rs_pin; // LOW: command.  HIGH: character.
+uint8_t lcd_rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
+uint8_t lcd_enable_pin; // activated by a HIGH pulse.
+uint8_t lcd_data_pins[8];
+
+uint8_t lcd_displayfunction;
+uint8_t lcd_displaycontrol;
+uint8_t lcd_displaymode;
+
+uint8_t lcd_numlines;
+uint8_t lcd_currline;
+
+uint8_t lcd_escape[8];
+
+
+void lcd_pulseEnable(void)
 {
-	lcd_write(c);
-	return 0;
+	digitalWrite(lcd_enable_pin, LOW);
+	delayMicroseconds(1);    
+	digitalWrite(lcd_enable_pin, HIGH);
+	delayMicroseconds(1);    // enable pulse must be >450ns
+	digitalWrite(lcd_enable_pin, LOW);
+	delayMicroseconds(100);   // commands need > 37us to settle
+}
+
+void lcd_write4bits(uint8_t value)
+{
+	for (int i = 0; i < 4; i++)
+	{
+		pinMode(lcd_data_pins[i], OUTPUT);
+		digitalWrite(lcd_data_pins[i], (value >> i) & 0x01);
+	}
+	lcd_pulseEnable();
 }
 
+void lcd_write8bits(uint8_t value)
+{
+	for (int i = 0; i < 8; i++)
+	{
+		pinMode(lcd_data_pins[i], OUTPUT);
+		digitalWrite(lcd_data_pins[i], (value >> i) & 0x01);
+	}
+	lcd_pulseEnable();
+}
+
+// write either command or data, with automatic 4/8-bit selection
+void lcd_send(uint8_t value, uint8_t mode)
+{
+	digitalWrite(lcd_rs_pin, mode);
+	// if there is a RW pin indicated, set it low to Write
+	if (lcd_rw_pin != 255) digitalWrite(lcd_rw_pin, LOW);
+	if (lcd_displayfunction & LCD_8BITMODE)
+		lcd_write8bits(value); 
+	else
+	{
+		lcd_write4bits(value>>4);
+		lcd_write4bits(value);
+	}
+}
 
 void lcd_command(uint8_t value)
 {
-	lcd.send(value, LOW);
+	lcd_send(value, LOW);
 }
 
+void lcd_clear(void);
+void lcd_home(void);
+void lcd_no_display(void);
+void lcd_display(void);
+void lcd_no_cursor(void);
+void lcd_cursor(void);
+void lcd_no_blink(void);
+void lcd_blink(void);
+void lcd_scrollDisplayLeft(void);
+void lcd_scrollDisplayRight(void);
+void lcd_leftToRight(void);
+void lcd_rightToLeft(void);
+void lcd_autoscroll(void);
+void lcd_no_autoscroll(void);
+void lcd_set_cursor(uint8_t col, uint8_t row);
+void lcd_createChar_P(uint8_t location, const uint8_t* charmap);
+
+uint8_t lcd_escape_write(uint8_t chr);
+
 uint8_t lcd_write(uint8_t value)
 {
 	if (value == '\n')
 	{
-		if (lcd._currline > 3) lcd._currline = -1;
-		lcd_set_cursor(0, lcd._currline + 1); // LF
+		if (lcd_currline > 3) lcd_currline = -1;
+		lcd_set_cursor(0, lcd_currline + 1); // LF
 		return 1;
 	}
-	if (lcd._escape[0] || (value == 0x1b))
-		return lcd.escape_write(value);
-	lcd.send(value, HIGH);
+	if (lcd_escape[0] || (value == 0x1b))
+		return lcd_escape_write(value);
+	lcd_send(value, HIGH);
 	return 1; // assume sucess
 }
 
+void lcd_begin(uint8_t cols, uint8_t lines, uint8_t dotsize, uint8_t clear)
+{
+	if (lines > 1) lcd_displayfunction |= LCD_2LINE;
+	lcd_numlines = lines;
+	lcd_currline = 0;
+	// for some 1 line displays you can select a 10 pixel high font
+	if ((dotsize != 0) && (lines == 1)) lcd_displayfunction |= LCD_5x10DOTS;
+	// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
+	// according to datasheet, we need at least 40ms after power rises above 2.7V
+	// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
+	_delay_us(50000); 
+	// Now we pull both RS and R/W low to begin commands
+	digitalWrite(lcd_rs_pin, LOW);
+	digitalWrite(lcd_enable_pin, LOW);
+	if (lcd_rw_pin != 255)
+		digitalWrite(lcd_rw_pin, LOW);
+	//put the LCD into 4 bit or 8 bit mode
+	if (!(lcd_displayfunction & LCD_8BITMODE))
+	{
+		// this is according to the hitachi HD44780 datasheet
+		// figure 24, pg 46
+		// we start in 8bit mode, try to set 4 bit mode
+		lcd_write4bits(0x03);
+		_delay_us(4500); // wait min 4.1ms
+		// second try
+		lcd_write4bits(0x03);
+		_delay_us(4500); // wait min 4.1ms
+		// third go!
+		lcd_write4bits(0x03); 
+		_delay_us(150);
+		// finally, set to 4-bit interface
+		lcd_write4bits(0x02); 
+	}
+	else
+	{
+		// this is according to the hitachi HD44780 datasheet
+		// page 45 figure 23
+		// Send function set command sequence
+		lcd_command(LCD_FUNCTIONSET | lcd_displayfunction);
+		_delay_us(4500);  // wait more than 4.1ms
+		// second try
+		lcd_command(LCD_FUNCTIONSET | lcd_displayfunction);
+		_delay_us(150);
+		// third go
+		lcd_command(LCD_FUNCTIONSET | lcd_displayfunction);
+	}
+	// finally, set # lines, font size, etc.
+	lcd_command(LCD_FUNCTIONSET | lcd_displayfunction);  
+	_delay_us(60);
+	// turn the display on with no cursor or blinking default
+	lcd_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
+	lcd_display();
+	_delay_us(60);
+	// clear it off
+	if (clear) lcd_clear();
+	_delay_us(3000);
+	// Initialize to default text direction (for romance languages)
+	lcd_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
+	// set the entry mode
+	lcd_command(LCD_ENTRYMODESET | lcd_displaymode);
+	_delay_us(60);
+	lcd_escape[0] = 0;
+}
+
+int lcd_putchar(char c, FILE *stream)
+{
+	lcd_write(c);
+	return 0;
+}
+
+void lcd_init(void)
+{
+	uint8_t fourbitmode = 1;
+	lcd_rs_pin = LCD_PINS_RS;
+	lcd_rw_pin = 255;
+	lcd_enable_pin = LCD_PINS_ENABLE;
+	lcd_data_pins[0] = LCD_PINS_D4;
+	lcd_data_pins[1] = LCD_PINS_D5;
+	lcd_data_pins[2] = LCD_PINS_D6;
+	lcd_data_pins[3] = LCD_PINS_D7; 
+	lcd_data_pins[4] = 0;
+	lcd_data_pins[5] = 0;
+	lcd_data_pins[6] = 0;
+	lcd_data_pins[7] = 0;
+	pinMode(lcd_rs_pin, OUTPUT);
+	// we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
+	if (lcd_rw_pin != 255) pinMode(lcd_rw_pin, OUTPUT);
+	pinMode(lcd_enable_pin, OUTPUT);
+	if (fourbitmode) lcd_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
+	else lcd_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
+	lcd_begin(LCD_WIDTH, LCD_HEIGHT, LCD_5x8DOTS, 1);
+	fdev_setup_stream(lcdout, lcd_putchar, NULL, _FDEV_SETUP_WRITE); //setup lcdout stream
+}
+
+void lcd_refresh(void)
+{
+    lcd_begin(LCD_WIDTH, LCD_HEIGHT, LCD_5x8DOTS, 1);
+    lcd_set_custom_characters();
+}
+
+void lcd_refresh_noclear(void)
+{
+    lcd_begin(LCD_WIDTH, LCD_HEIGHT, LCD_5x8DOTS, 0);
+    lcd_set_custom_characters();
+}
+
+
+
 void lcd_clear(void)
 {
 	lcd_command(LCD_CLEARDISPLAY);  // clear display, set cursor position to zero
 	_delay_us(1600);  // this command takes a long time
 }
 
+void lcd_home(void)
+{
+	lcd_command(LCD_RETURNHOME);  // set cursor position to zero
+	_delay_us(1600);  // this command takes a long time!
+}
+
+// Turn the display on/off (quickly)
+void lcd_no_display(void)
+{
+	lcd_displaycontrol &= ~LCD_DISPLAYON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+void lcd_display(void)
+{
+	lcd_displaycontrol |= LCD_DISPLAYON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+// Turns the underline cursor on/off
+void lcd_no_cursor(void)
+{
+	lcd_displaycontrol &= ~LCD_CURSORON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+void lcd_cursor(void)
+{
+	lcd_displaycontrol |= LCD_CURSORON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+// Turn on and off the blinking cursor
+void lcd_no_blink(void)
+{
+	lcd_displaycontrol &= ~LCD_BLINKON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+void lcd_blink(void)
+{
+	lcd_displaycontrol |= LCD_BLINKON;
+	lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol);
+}
+
+// These commands scroll the display without changing the RAM
+void lcd_scrollDisplayLeft(void)
+{
+	lcd_command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
+}
+
+void lcd_scrollDisplayRight(void)
+{
+	lcd_command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
+}
+
+// This is for text that flows Left to Right
+void lcd_leftToRight(void)
+{
+	lcd_displaymode |= LCD_ENTRYLEFT;
+	lcd_command(LCD_ENTRYMODESET | lcd_displaymode);
+}
+
+// This is for text that flows Right to Left
+void lcd_rightToLeft(void)
+{
+	lcd_displaymode &= ~LCD_ENTRYLEFT;
+	lcd_command(LCD_ENTRYMODESET | lcd_displaymode);
+}
+
+// This will 'right justify' text from the cursor
+void lcd_autoscroll(void)
+{
+	lcd_displaymode |= LCD_ENTRYSHIFTINCREMENT;
+	lcd_command(LCD_ENTRYMODESET | lcd_displaymode);
+}
+
+// This will 'left justify' text from the cursor
+void lcd_no_autoscroll(void)
+{
+	lcd_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
+	lcd_command(LCD_ENTRYMODESET | lcd_displaymode);
+}
+
 void lcd_set_cursor(uint8_t col, uint8_t row)
 {
 	int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
-	if ( row >= lcd._numlines )
-		row = lcd._numlines-1;    // we count rows starting w/0
-	lcd._currline = row;  
+	if ( row >= lcd_numlines )
+		row = lcd_numlines-1;    // we count rows starting w/0
+	lcd_currline = row;  
 	lcd_command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
 }
 
@@ -104,9 +377,143 @@ void lcd_createChar_P(uint8_t location, const uint8_t* charmap)
   location &= 0x7; // we only have 8 locations 0-7
   lcd_command(LCD_SETCGRAMADDR | (location << 3));
   for (int i=0; i<8; i++)
-    lcd.send(pgm_read_byte(&charmap[i]), HIGH);
+    lcd_send(pgm_read_byte(&charmap[i]), HIGH);
 }
 
+//Supported VT100 escape codes:
+//EraseScreen  "\x1b[2J"
+//CursorHome   "\x1b[%d;%dH"
+//CursorShow   "\x1b[?25h"
+//CursorHide   "\x1b[?25l"
+uint8_t lcd_escape_write(uint8_t chr)
+{
+#define escape_cnt (lcd_escape[0])        //escape character counter
+#define is_num_msk (lcd_escape[1])        //numeric character bit mask
+#define chr_is_num (is_num_msk & 0x01) //current character is numeric
+#define e_2_is_num (is_num_msk & 0x04) //escape char 2 is numeric
+#define e_3_is_num (is_num_msk & 0x08) //...
+#define e_4_is_num (is_num_msk & 0x10)
+#define e_5_is_num (is_num_msk & 0x20)
+#define e_6_is_num (is_num_msk & 0x40)
+#define e_7_is_num (is_num_msk & 0x80)
+#define e2_num (lcd_escape[2] - '0')      //number from character 2
+#define e3_num (lcd_escape[3] - '0')      //number from character 3
+#define e23_num (10*e2_num+e3_num)     //number from characters 2 and 3
+#define e4_num (lcd_escape[4] - '0')      //number from character 4
+#define e5_num (lcd_escape[5] - '0')      //number from character 5
+#define e45_num (10*e4_num+e5_num)     //number from characters 4 and 5
+#define e6_num (lcd_escape[6] - '0')      //number from character 6
+#define e56_num (10*e5_num+e6_num)     //number from characters 5 and 6
+	if (escape_cnt > 1) // escape length > 1 = "\x1b["
+	{
+		lcd_escape[escape_cnt] = chr; // store current char
+		if ((chr >= '0') && (chr <= '9')) // char is numeric
+			is_num_msk |= (1 | (1 << escape_cnt)); //set mask
+		else
+			is_num_msk &= ~1; //clear mask
+	}
+	switch (escape_cnt++)
+	{
+	case 0:
+		if (chr == 0x1b) return 1;  // escape = "\x1b"
+		break;
+	case 1:
+		is_num_msk = 0x00; // reset 'is number' bit mask
+		if (chr == '[') return 1; // escape = "\x1b["
+		break;
+	case 2:
+		switch (chr)
+		{
+		case '2': return 1; // escape = "\x1b[2"
+		case '?': return 1; // escape = "\x1b[?"
+		default:
+			if (chr_is_num) return 1; // escape = "\x1b[%1d"
+		}
+		break;
+	case 3:
+		switch (lcd_escape[2])
+		{
+		case '?': // escape = "\x1b[?"
+			if (chr == '2') return 1; // escape = "\x1b[?2"
+			break;
+		case '2':
+			if (chr == 'J') // escape = "\x1b[2J"
+				{ lcd_clear(); lcd_currline = 0; break; } // EraseScreen
+		default:
+			if (e_2_is_num && // escape = "\x1b[%1d"
+				((chr == ';') || // escape = "\x1b[%1d;"
+				chr_is_num)) // escape = "\x1b[%2d"
+				return 1;
+		}
+		break;
+	case 4:
+		switch (lcd_escape[2])
+		{
+		case '?': // "\x1b[?"
+			if ((lcd_escape[3] == '2') && (chr == '5')) return 1; // escape = "\x1b[?25"
+			break;
+		default:
+			if (e_2_is_num) // escape = "\x1b[%1d"
+			{
+				if ((lcd_escape[3] == ';') && chr_is_num) return 1; // escape = "\x1b[%1d;%1d"
+				else if (e_3_is_num && (chr == ';')) return 1; // escape = "\x1b[%2d;"
+			}
+		}
+		break;
+	case 5:
+		switch (lcd_escape[2])
+		{
+		case '?':
+			if ((lcd_escape[3] == '2') && (lcd_escape[4] == '5')) // escape = "\x1b[?25"
+				switch (chr)
+				{
+				case 'h': // escape = "\x1b[?25h"
+  					lcd_cursor(); // CursorShow
+					break;
+				case 'l': // escape = "\x1b[?25l"
+					lcd_no_cursor(); // CursorHide
+					break;
+				}
+			break;
+		default:
+			if (e_2_is_num) // escape = "\x1b[%1d"
+			{
+				if ((lcd_escape[3] == ';') && e_4_is_num) // escape = "\x1b%1d;%1dH"
+				{
+					if (chr == 'H') // escape = "\x1b%1d;%1dH"
+						lcd_set_cursor(e4_num, e2_num); // CursorHome
+					else if (chr_is_num)
+						return 1; // escape = "\x1b%1d;%2d"
+				}
+				else if (e_3_is_num && (lcd_escape[4] == ';') && chr_is_num)
+					return 1; // escape = "\x1b%2d;%1d"
+			}
+		}
+		break;
+	case 6:
+		if (e_2_is_num) // escape = "\x1b[%1d"
+		{
+			if ((lcd_escape[3] == ';') && e_4_is_num && e_5_is_num && (chr == 'H')) // escape = "\x1b%1d;%2dH"
+				lcd_set_cursor(e45_num, e2_num); // CursorHome
+			else if (e_3_is_num && (lcd_escape[4] == ';') && e_5_is_num) // escape = "\x1b%2d;%1d"
+			{
+				if (chr == 'H') // escape = "\x1b%2d;%1dH"
+					lcd_set_cursor(e5_num, e23_num); // CursorHome
+				else if (chr_is_num) // "\x1b%2d;%2d"
+					return 1;
+			}
+		}
+		break;
+	case 7:
+		if (e_2_is_num && e_3_is_num && (lcd_escape[4] == ';')) // "\x1b[%2d;"
+			if (e_5_is_num && e_6_is_num && (chr == 'H')) // "\x1b[%2d;%2dH"
+				lcd_set_cursor(e56_num, e23_num); // CursorHome
+		break;
+	}
+	escape_cnt = 0; // reset escape
+end:
+	return 1; // assume sucess
+}
 
 
 
@@ -450,20 +857,6 @@ void lcd_buttons_update(void)
 
 
 
-void lcd_implementation_init(void)
-{
-    lcd.begin(LCD_WIDTH, LCD_HEIGHT);
-    lcd_set_custom_characters();
-    lcd_clear();
-}
-
-
-void lcd_implementation_init_noclear(void)
-{
-    lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
-    lcd_set_custom_characters();
-}
-
 
 
 

+ 29 - 21
Firmware/lcd.h

@@ -8,28 +8,48 @@
 
 ////////////////////////////////////
 // Create LCD class instance and chipset-specific information
-#include "LiquidCrystal_Prusa.h"
-extern LiquidCrystal_Prusa lcd;
+//#include "LiquidCrystal_Prusa.h"
+//extern LiquidCrystal_Prusa lcd;
 
 
 extern FILE _lcdout;
 
 #define lcdout (&_lcdout)
+extern int lcd_putchar(char c, FILE *stream);
 
 
-extern int lcd_putchar(char c, FILE *stream);
+extern void lcd_init(void);
+
+extern void lcd_refresh(void);
+
+extern void lcd_refresh_noclear(void);
 
-extern void lcd_command(uint8_t value);
 
-extern uint8_t lcd_write(uint8_t value);
 
 extern void lcd_clear(void);
 
+extern void lcd_home(void);
+
+
+/*extern void lcd_no_display(void);
+extern void lcd_display(void);
+extern void lcd_no_blink(void);
+extern void lcd_blink(void);
+extern void lcd_no_cursor(void);
+extern void lcd_cursor(void);
+extern void lcd_scrollDisplayLeft(void);
+extern void lcd_scrollDisplayRight(void);
+extern void lcd_leftToRight(void);
+extern void lcd_rightToLeft(void);
+extern void lcd_autoscroll(void);
+extern void lcd_no_autoscroll(void);*/
+
 extern void lcd_set_cursor(uint8_t col, uint8_t row);
 
 extern void lcd_createChar_P(uint8_t, const uint8_t*);
 
 
+
 extern int lcd_putc(int c);
 extern int lcd_puts_P(const char* str);
 extern int lcd_puts_at_P(uint8_t c, uint8_t r, const char* str);
@@ -47,6 +67,10 @@ extern void lcd_print(long, int = 10);
 extern void lcd_print(unsigned long, int = 10);
 extern void lcd_print(double, int = 2);
 
+#define ESC_2J     "\x1b[2J"
+#define ESC_25h    "\x1b[?25h"
+#define ESC_25l    "\x1b[?25l"
+#define ESC_H(c,r) "\x1b["#r";"#c"H"
 
 
 
@@ -145,19 +169,6 @@ extern void lcd_buttons_update(void);
 
 
 
-
-
-
-
-
-
-
-
-#include "Configuration_prusa.h"
-#include "Marlin.h"
-
-
-
 /**
 * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
 * When selecting the Russian language, a slightly different LCD implementation is used to handle UTF8 characters.
@@ -211,9 +222,6 @@ extern void lcd_set_custom_characters_progress(void);
 extern void lcd_set_custom_characters_nextpage(void);
 extern void lcd_set_custom_characters_degree(void);
 
-extern void lcd_implementation_init(void);
-extern void lcd_implementation_init_noclear(void);
-
 extern void lcd_drawedit(const char* pstr, char* value);
 extern void lcd_drawedit_2(const char* pstr, char* value);
 

+ 2 - 0
Firmware/menu.cpp

@@ -6,6 +6,8 @@
 #include <stdarg.h>
 #include <avr/pgmspace.h>
 #include "lcd.h"
+#include "Configuration.h"
+#include "Marlin.h"
 
 
 

+ 2 - 2
Firmware/tmc2130.cpp

@@ -3,13 +3,13 @@
 #ifdef TMC2130
 
 #include "tmc2130.h"
-#include "LiquidCrystal_Prusa.h"
+//#include "LiquidCrystal_Prusa.h"
 #include "ultralcd.h"
 #include "language.h"
 #include "spi.h"
 
 
-extern LiquidCrystal_Prusa lcd;
+//extern LiquidCrystal_Prusa lcd;
 
 #define TMC2130_GCONF_NORMAL 0x00000000 // spreadCycle
 #define TMC2130_GCONF_SGSENS 0x00003180 // spreadCycle with stallguard (stall activates DIAG0 and DIAG1 [pushpull])

+ 11 - 10
Firmware/ultralcd.cpp

@@ -644,12 +644,12 @@ static void lcd_implementation_status_screen()
     {
       uint8_t queue = planner_queue_min();
       if (queue < (BLOCK_BUFFER_SIZE >> 1)) {
-        lcd.write('!');
+        lcd_putc('!');
       } else {
-        lcd.write((char)(queue / 10) + '0');
+        lcd_putc((char)(queue / 10) + '0');
         queue %= 10;
       }
-      lcd.write((char)queue + '0');
+      lcd_putc((char)queue + '0');
       planner_queue_min_reset();
     }
 #else /* PLANNER_DIAGNOSTICS */
@@ -963,7 +963,7 @@ static void lcd_status_screen()
 
     if (ReInitLCD == 30)
 	{
-      lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
+      lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
       ReInitLCD = 0 ;
     }
 	else
@@ -971,7 +971,7 @@ static void lcd_status_screen()
 
       if ((ReInitLCD % 10) == 0)
 	  {
-        lcd_implementation_init_noclear(); //to maybe revive the LCD if static electricity killed it.
+        lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
       }
 
     }
@@ -1037,7 +1037,7 @@ static void lcd_status_screen()
   {
 	menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
     menu_submenu(lcd_main_menu);
-    lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
+    lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
   }
 
 #ifdef ULTIPANEL_FEEDMULTIPLY
@@ -1875,7 +1875,7 @@ static float count_e(float layer_heigth, float extrusion_width, float extrusion_
 
 static void lcd_return_to_status()
 {
-	lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
+	lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
 	menu_goto(lcd_status_screen, 0, false, true);
 	menu_depth = 0;
 }
@@ -7225,9 +7225,10 @@ void menu_action_sddirectory(const char* filename, char* longFilename)
 
 /** LCD API **/
 
-void lcd_init()
+void ultralcd_init()
 {
-	lcd_implementation_init();
+	lcd_init();
+//	lcd_refresh();
 	lcd_longpress_func = menu_lcd_longpress_func;
 	lcd_charsetup_func = menu_lcd_charsetup_func;
 	lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
@@ -7399,7 +7400,7 @@ void menu_lcd_lcdupdate_func(void)
   {
 	  lcd_draw_update = 2;
 	  lcd_oldcardstatus = IS_SD_INSERTED;
-	  lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
+	  lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
 
 	  if (lcd_oldcardstatus)
 	  {

+ 1 - 1
Firmware/ultralcd.h

@@ -15,7 +15,7 @@ extern void menu_lcd_lcdupdate_func(void);
 	static void lcd_language_menu();
 
   // Call with a false parameter to suppress the LCD update from various places like the planner or the temp control.
-  void lcd_init();
+  void ultralcd_init();
   void lcd_setstatus(const char* message);
   void lcd_setstatuspgm(const char* message);
   void lcd_setalertstatuspgm(const char* message);