src folder

This commit is contained in:
Malte Reents 2024-05-19 11:48:07 +02:00
parent c257f43edd
commit 4989bd3925
27 changed files with 8215 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
* Implementation of the LCD display routines for a TFT GLCD displays with external controller.
*/
#include "../../inc/MarlinConfig.h"
#if IS_TFTGLCD_PANEL
#include "../../libs/duration_t.h"
////////////////////////////////////
// Set up button and encode mappings for each panel (into 'buttons' variable)
//
// This is just to map common functions (across different panels) onto the same
// macro name. The mapping is independent of whether the button is directly connected or
// via a shift/i2c register.
////////////////////////////////////
// Create LCD class instance and chipset-specific information
class TFTGLCD {
private:
public:
TFTGLCD();
void clear_buffer();
void clr_screen();
void setCursor(uint8_t col, uint8_t row);
void write(char c);
void print(const char *line);
void print_line();
void print_screen();
void redraw_screen();
void setContrast(uint16_t contrast);
};
extern TFTGLCD lcd;
#include "../fontutils.h"
#include "../lcdprint.h"
// Use panel encoder - free old encoder pins
#undef BTN_EN1
#undef BTN_EN2
#undef BTN_ENC
#ifndef EN_C
#define EN_C 4 // for click
#endif
#endif // IS_TFTGLCD_PANEL

226
src/lcd/buttons.h Normal file
View File

@ -0,0 +1,226 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../inc/MarlinConfig.h"
#if ((!HAS_ADC_BUTTONS && IS_NEWPANEL) || BUTTONS_EXIST(EN1, EN2)) && !IS_TFTGLCD_PANEL
#define HAS_ENCODER_WHEEL 1
#endif
#if (HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)) && DISABLED(TOUCH_UI_FTDI_EVE)
#define HAS_DIGITAL_BUTTONS 1
#endif
#if !HAS_ADC_BUTTONS && (IS_RRW_KEYPAD || (HAS_WIRED_LCD && !IS_NEWPANEL))
#define HAS_SHIFT_ENCODER 1
#endif
// I2C buttons must be read in the main thread
#if ANY(LCD_I2C_VIKI, LCD_I2C_PANELOLU2, IS_TFTGLCD_PANEL)
#define HAS_SLOW_BUTTONS 1
#endif
#if HAS_ENCODER_WHEEL
#define ENCODER_PHASE_0 0
#define ENCODER_PHASE_1 2
#define ENCODER_PHASE_2 3
#define ENCODER_PHASE_3 1
#endif
#if EITHER(HAS_DIGITAL_BUTTONS, HAS_DWIN_E3V2)
// Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
#define BLEN_A 0
#define BLEN_B 1
#define EN_A _BV(BLEN_A)
#define EN_B _BV(BLEN_B)
#define _BUTTON_PRESSED(BN) !READ(BTN_##BN)
#if BUTTON_EXISTS(ENC) || HAS_TOUCH_BUTTONS
#define BLEN_C 2
#define EN_C _BV(BLEN_C)
#endif
#if ENABLED(LCD_I2C_VIKI)
#include <LiquidTWI2.h>
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
// button and encoder bit positions within 'buttons'
#define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
#define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
#define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
#define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
#define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
#if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
#define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
#define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
#else
#define BUTTON_CLICK() (buttons & (B_MI|B_RI))
#endif
// I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
#elif ENABLED(LCD_I2C_PANELOLU2)
#if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
#define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
#define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
#define BUTTON_CLICK() (buttons & B_MI)
#endif
#endif
#else
#undef BUTTON_EXISTS
#define BUTTON_EXISTS(...) false
// Dummy button, never pressed
#define _BUTTON_PRESSED(BN) false
// Shift register bits correspond to buttons:
#define BL_LE 7 // Left
#define BL_UP 6 // Up
#define BL_MI 5 // Middle
#define BL_DW 4 // Down
#define BL_RI 3 // Right
#define BL_ST 2 // Red Button
#define B_LE _BV(BL_LE)
#define B_UP _BV(BL_UP)
#define B_MI _BV(BL_MI)
#define B_DW _BV(BL_DW)
#define B_RI _BV(BL_RI)
#define B_ST _BV(BL_ST)
#ifndef BUTTON_CLICK
#if EN_C
#define BUTTON_CLICK() (buttons & (B_MI|B_ST))
#endif
#endif
#endif
#if IS_RRW_KEYPAD
#define BTN_OFFSET 0 // Bit offset into buttons for shift register values
#define BLEN_KEYPAD_F3 0
#define BLEN_KEYPAD_F2 1
#define BLEN_KEYPAD_F1 2
#define BLEN_KEYPAD_DOWN 3
#define BLEN_KEYPAD_RIGHT 4
#define BLEN_KEYPAD_MIDDLE 5
#define BLEN_KEYPAD_UP 6
#define BLEN_KEYPAD_LEFT 7
#define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
#define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
#define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
#define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
#define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
#define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
#define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
#define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
#define RRK(B) (keypad_buttons & (B))
#ifdef EN_C
#define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
#else
#define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
#endif
#endif
#ifndef EN_A
#define EN_A 0
#endif
#ifndef EN_B
#define EN_B 0
#endif
#ifndef EN_C
#define EN_C 0
#endif
#if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_BUTTONS, IS_TFTGLCD_PANEL)
#define BLEN_D 3
#define EN_D _BV(BLEN_D)
#else
#define EN_D 0
#endif
#define BUTTON_PRESSED(BN) (_BUTTON_PRESSED_##BN)
#if BUTTON_EXISTS(EN1)
#define _BUTTON_PRESSED_EN1 _BUTTON_PRESSED(EN1)
#else
#define _BUTTON_PRESSED_EN1 false
#endif
#if BUTTON_EXISTS(EN2)
#define _BUTTON_PRESSED_EN2 _BUTTON_PRESSED(EN2)
#else
#define _BUTTON_PRESSED_EN2 false
#endif
#if BUTTON_EXISTS(ENC_EN)
#define _BUTTON_PRESSED_ENC_EN _BUTTON_PRESSED(ENC_EN)
#else
#define _BUTTON_PRESSED_ENC_EN false
#endif
#if BUTTON_EXISTS(ENC)
#define _BUTTON_PRESSED_ENC _BUTTON_PRESSED(ENC)
#else
#define _BUTTON_PRESSED_ENC false
#endif
#if BUTTON_EXISTS(UP)
#define _BUTTON_PRESSED_UP _BUTTON_PRESSED(UP)
#else
#define _BUTTON_PRESSED_UP false
#endif
#if BUTTON_EXISTS(DWN)
#define _BUTTON_PRESSED_DWN _BUTTON_PRESSED(DWN)
#else
#define _BUTTON_PRESSED_DWN false
#endif
#if BUTTON_EXISTS(LFT)
#define _BUTTON_PRESSED_LFT _BUTTON_PRESSED(LFT)
#else
#define _BUTTON_PRESSED_LFT false
#endif
#if BUTTON_EXISTS(RT)
#define _BUTTON_PRESSED_RT _BUTTON_PRESSED(RT)
#else
#define _BUTTON_PRESSED_RT false
#endif
#if BUTTON_EXISTS(BACK)
#define _BUTTON_PRESSED_BACK _BUTTON_PRESSED(BACK)
#else
#define _BUTTON_PRESSED_BACK false
#endif
#ifndef BUTTON_CLICK
#if EN_C > 0
#define BUTTON_CLICK() (buttons & EN_C)
#else
#define BUTTON_CLICK() false
#endif
#endif
#if EN_D > 0
#define LCD_BACK_CLICKED() (buttons & EN_D)
#else
#define LCD_BACK_CLICKED() false
#endif

205
src/lcd/fontutils.cpp Normal file
View File

@ -0,0 +1,205 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* @file fontutils.cpp
* @brief help functions for font and char
* @author Yunhui Fu (yhfudev@gmail.com)
* @version 1.0
* @date 2016-08-19
* @copyright GPL/BSD
*/
#include "../inc/MarlinConfig.h"
#if HAS_WIRED_LCD
#include "marlinui.h"
#include "../MarlinCore.h"
#endif
#include "fontutils.h"
uint8_t read_byte_ram(const uint8_t *str) { return *str; }
uint8_t read_byte_rom(const uint8_t *str) { return pgm_read_byte(str); }
/**
* @brief Using binary search to find the position by data_pin
*
* @param userdata : User's data
* @param num_data : the item number of the sorted data
* @param cb_comp : the callback function to compare the user's data and pin
* @param data_pin : The reference data to be found
* @param ret_idx : the position of the required data; If failed, then it is the failed position, which is the insert position if possible.
*
* @return 0 on found, <0 on failed(fail position is saved by ret_idx)
*
* Using binary search to find the position by data_pin. The user's data should be sorted.
*/
int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp, void *data_pinpoint, size_t *ret_idx) {
int retcomp;
if (num_data < 1) {
*ret_idx = 0;
return -1;
}
size_t i = 0, ileft = 1, iright = num_data;
bool flg_found = false;
for (; ileft <= iright;) {
i = (ileft + iright) / 2 - 1;
/* cb_comp should return the *userdata[i] - *data_pinpoint */
retcomp = cb_comp (userdata, i, data_pinpoint);
if (retcomp > 0)
iright = i;
else if (retcomp < 0)
ileft = i + 2;
else {
/* found ! */
flg_found = true;
break;
}
}
if (flg_found) {
*ret_idx = i;
return 0;
}
if (iright <= i)
*ret_idx = i;
else if (ileft >= i + 2)
*ret_idx = i + 1;
return -1;
}
/* Returns true if passed byte is first byte of UTF-8 char sequence */
static inline bool utf8_is_start_byte_of_char(const uint8_t b) {
return 0x80 != (b & 0xC0);
}
/* This function gets the character at the pstart position, interpreting UTF8 multibyte sequences
and returns the pointer to the next character */
const uint8_t* get_utf8_value_cb(const uint8_t *pstart, read_byte_cb_t cb_read_byte, lchar_t &pval) {
uint32_t val = 0;
const uint8_t *p = pstart;
#define NEXT_6_BITS() do{ val <<= 6; p++; valcur = cb_read_byte(p); val |= (valcur & 0x3F); }while(0)
uint8_t valcur = cb_read_byte(p);
if (0 == (0x80 & valcur)) {
val = valcur;
p++;
}
else if (0xC0 == (0xE0 & valcur)) {
val = valcur & 0x1F;
NEXT_6_BITS();
p++;
}
#if MAX_UTF8_CHAR_SIZE >= 3
else if (0xE0 == (0xF0 & valcur)) {
val = valcur & 0x0F;
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 4
else if (0xF0 == (0xF8 & valcur)) {
val = valcur & 0x07;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 5
else if (0xF8 == (0xFC & valcur)) {
val = valcur & 0x03;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
#if MAX_UTF8_CHAR_SIZE >= 6
else if (0xFC == (0xFE & valcur)) {
val = valcur & 0x01;
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
NEXT_6_BITS();
p++;
}
#endif
else if (!utf8_is_start_byte_of_char(valcur))
for (; !utf8_is_start_byte_of_char(valcur); ) { p++; valcur = cb_read_byte(p); }
else
for (; 0xFC < (0xFE & valcur); ) { p++; valcur = cb_read_byte(p); }
pval = val;
return p;
}
static inline uint8_t utf8_strlen_cb(const char *pstart, read_byte_cb_t cb_read_byte) {
uint8_t cnt = 0;
uint8_t *p = (uint8_t *)pstart;
if (p) for (;;) {
const uint8_t b = cb_read_byte(p);
if (!b) break;
if (utf8_is_start_byte_of_char(b)) cnt++;
p++;
}
return cnt;
}
uint8_t utf8_strlen(const char *pstart) {
return utf8_strlen_cb(pstart, read_byte_ram);
}
uint8_t utf8_strlen_P(PGM_P pstart) {
return utf8_strlen_cb(pstart, read_byte_rom);
}
static inline uint8_t utf8_byte_pos_by_char_num_cb(const char *pstart, read_byte_cb_t cb_read_byte, const uint8_t charnum) {
uint8_t *p = (uint8_t *)pstart;
uint8_t char_idx = 0;
uint8_t byte_idx = 0;
for (;;) {
const uint8_t b = cb_read_byte(p + byte_idx);
if (!b) return byte_idx; // Termination byte of string
if (utf8_is_start_byte_of_char(b)) {
char_idx++;
if (char_idx == charnum + 1) return byte_idx;
}
byte_idx++;
}
}
uint8_t utf8_byte_pos_by_char_num(const char *pstart, const uint8_t charnum) {
return utf8_byte_pos_by_char_num_cb(pstart, read_byte_ram, charnum);
}
uint8_t utf8_byte_pos_by_char_num_P(PGM_P pstart, const uint8_t charnum) {
return utf8_byte_pos_by_char_num_cb(pstart, read_byte_rom, charnum);
}

79
src/lcd/fontutils.h Normal file
View File

@ -0,0 +1,79 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* @file fontutils.h
* @brief help functions for font and char
* @author Yunhui Fu (yhfudev@gmail.com)
* @version 1.0
* @date 2016-08-19
* @copyright GPL/BSD
*/
#pragma once
#include <stdlib.h>
#include <stdint.h> // uint32_t
#include "../HAL/shared/Marduino.h"
#include "../core/macros.h"
#define MAX_UTF8_CHAR_SIZE 4
// Use a longer character type (if needed) because wchar_t is only 16 bits wide
#ifdef MAX_UTF8_CHAR_SIZE
#if MAX_UTF8_CHAR_SIZE > 2
typedef uint32_t lchar_t;
#else
typedef wchar_t lchar_t;
#endif
#else
#define wchar_t uint32_t
#endif
// read a byte from ROM or RAM
typedef uint8_t (*read_byte_cb_t)(const uint8_t * str);
uint8_t read_byte_ram(const uint8_t *str);
uint8_t read_byte_rom(const uint8_t *str);
typedef uint16_t pixel_len_t;
#define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
/* Perform binary search */
typedef int (* pf_bsearch_cb_comp_t)(void *userdata, size_t idx, void * data_pin);
int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp, void *data_pinpoint, size_t *ret_idx);
/* Get the character, decoding multibyte UTF8 characters and returning a pointer to the start of the next UTF8 character */
const uint8_t* get_utf8_value_cb(const uint8_t *pstart, read_byte_cb_t cb_read_byte, lchar_t &pval);
inline const char* get_utf8_value_cb(const char *pstart, read_byte_cb_t cb_read_byte, lchar_t &pval) {
return (const char *)get_utf8_value_cb((const uint8_t *)pstart, cb_read_byte, pval);
}
/* Returns length of string in CHARACTERS, NOT BYTES */
uint8_t utf8_strlen(const char *pstart);
uint8_t utf8_strlen_P(PGM_P pstart);
inline uint8_t utf8_strlen(FSTR_P fstart) { return utf8_strlen_P(FTOP(fstart)); }
/* Returns start byte position of desired char number */
uint8_t utf8_byte_pos_by_char_num(const char *pstart, const uint8_t charnum);
uint8_t utf8_byte_pos_by_char_num_P(PGM_P pstart, const uint8_t charnum);

109
src/lcd/lcdprint.cpp Normal file
View File

@ -0,0 +1,109 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* lcdprint.cpp
*/
#include "../inc/MarlinConfigPre.h"
#if HAS_LCDPRINT
#include "marlinui.h"
#include "lcdprint.h"
/**
* lcd_put_u8str_P
*
* Print a string with optional substitutions:
*
* $ displays the clipped string given by fstr or cstr
* = displays '0'....'10' for indexes 0 - 10
* ~ displays '1'....'11' for indexes 0 - 10
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
* @ displays an axis name such as XYZUVW, or E for an extruder
*/
lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
const uint8_t *p = (uint8_t*)ptpl;
int8_t n = maxlen;
while (n > 0) {
lchar_t wc;
p = get_utf8_value_cb(p, read_byte_rom, wc);
if (!wc) break;
if (wc == '=' || wc == '~' || wc == '*') {
if (ind >= 0) {
if (wc == '*') { lcd_put_lchar('E'); n--; }
if (n) {
int8_t inum = ind + ((wc == '=') ? 0 : LCD_FIRST_TOOL);
if (inum >= 10) {
lcd_put_lchar('0' + (inum / 10)); n--;
inum %= 10;
}
if (n) { lcd_put_lchar('0' + inum); n--; }
}
}
else {
PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED);
n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
}
if (n) {
n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
break;
}
}
else if (wc == '$' && fstr) {
n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
}
else if (wc == '$' && cstr) {
n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
}
else if (wc == '@') {
lcd_put_lchar(AXIS_CHAR(ind));
n--;
}
else {
lcd_put_lchar(wc);
n -= wc > 255 ? prop : 1;
}
}
return n;
}
// Calculate UTF8 width with a simple check
int calculateWidth(PGM_P const pstr) {
if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH;
const uint8_t prop = 2;
const uint8_t *p = (uint8_t*)pstr;
int n = 0;
do {
lchar_t wc;
p = get_utf8_value_cb(p, read_byte_rom, wc);
if (!wc) break;
n += (wc > 255) ? prop : 1;
} while (1);
return n * MENU_FONT_WIDTH;
}
#endif // HAS_LCDPRINT

296
src/lcd/lcdprint.h Normal file
View File

@ -0,0 +1,296 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* @file lcdprint.h
* @brief LCD print api
* @author Yunhui Fu (yhfudev@gmail.com)
* @version 1.0
* @date 2016-08-19
* @copyright GPL/BSD
*/
#pragma once
#include "fontutils.h"
#include "../inc/MarlinConfig.h"
#if IS_DWIN_MARLINUI
#include "e3v2/marlinui/marlinui_dwin.h"
#define LCD_PIXEL_WIDTH DWIN_WIDTH
#define LCD_PIXEL_HEIGHT DWIN_HEIGHT
#define LCD_WIDTH ((LCD_PIXEL_WIDTH) / (MENU_FONT_WIDTH))
#define LCD_HEIGHT ((LCD_PIXEL_HEIGHT) / (MENU_LINE_HEIGHT))
// The DWIN lcd_moveto function uses row / column, not pixels
#define LCD_COL_X(col) (col)
#define LCD_ROW_Y(row) (row)
#define LCD_COL_X_RJ(len) (LCD_WIDTH - LCD_COL_X(len))
#elif HAS_MARLINUI_U8GLIB
#include "dogm/u8g_fontutf8.h"
typedef u8g_uint_t lcd_uint_t;
typedef u8g_int_t lcd_int_t;
// Only Western languages support big / small fonts
#if DISABLED(DISPLAY_CHARSET_ISO10646_1)
#undef USE_BIG_EDIT_FONT
#undef USE_SMALL_INFOFONT
#endif
#define MENU_FONT_NAME ISO10646_1_5x7
#define MENU_FONT_WIDTH 6
#define MENU_FONT_ASCENT 10
#define MENU_FONT_DESCENT 2
#define MENU_FONT_HEIGHT (MENU_FONT_ASCENT + MENU_FONT_DESCENT)
#if ENABLED(USE_BIG_EDIT_FONT)
#define EDIT_FONT_NAME u8g_font_9x18
#define EDIT_FONT_WIDTH 9
#define EDIT_FONT_ASCENT 10
#define EDIT_FONT_DESCENT 3
#else
#define EDIT_FONT_NAME MENU_FONT_NAME
#define EDIT_FONT_WIDTH MENU_FONT_WIDTH
#define EDIT_FONT_ASCENT MENU_FONT_ASCENT
#define EDIT_FONT_DESCENT MENU_FONT_DESCENT
#endif
#define EDIT_FONT_HEIGHT (EDIT_FONT_ASCENT + EDIT_FONT_DESCENT)
// Get the Ascent, Descent, and total Height for the Info Screen font
#if ENABLED(USE_SMALL_INFOFONT)
extern const u8g_fntpgm_uint8_t u8g_font_6x9[];
#define INFO_FONT_ASCENT 7
#else
#define INFO_FONT_ASCENT 8
#endif
#define INFO_FONT_DESCENT 2
#define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
#define INFO_FONT_WIDTH 6
// Graphical LCD uses the menu font size for cursor positioning
#define LCD_COL_X(col) (( (col)) * (MENU_FONT_WIDTH))
#define LCD_ROW_Y(row) ((1 + (row)) * (MENU_LINE_HEIGHT))
#else
#define _UxGT(a) a
typedef uint8_t lcd_uint_t;
typedef int8_t lcd_int_t;
#define MENU_FONT_WIDTH 1
#define MENU_FONT_HEIGHT 1
#define EDIT_FONT_WIDTH 1
#define EDIT_FONT_HEIGHT 1
#define INFO_FONT_WIDTH 1
#define INFO_FONT_HEIGHT 1
#define LCD_PIXEL_WIDTH LCD_WIDTH
#define LCD_PIXEL_HEIGHT LCD_HEIGHT
// Character LCD uses direct cursor positioning
#define LCD_COL_X(col) (col)
#define LCD_ROW_Y(row) (row)
#endif
#ifndef MENU_LINE_HEIGHT
#define MENU_LINE_HEIGHT MENU_FONT_HEIGHT
#endif
#ifndef LCD_COL_X_RJ
#define LCD_COL_X_RJ(len) (LCD_PIXEL_WIDTH - LCD_COL_X(len))
#endif
#define SETCURSOR(col, row) lcd_moveto(LCD_COL_X(col), LCD_ROW_Y(row))
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_COL_X_RJ(len), LCD_ROW_Y(row))
#define SETCURSOR_X(col) SETCURSOR(col, _lcdLineNr)
#define SETCURSOR_X_RJ(len) SETCURSOR_RJ(len, _lcdLineNr)
int lcd_glyph_height();
/**
* @brief Draw a UTF-8 character
*
* @param utf8_str : the UTF-8 character
* @param max_length : the output width limit (in pixels on GLCD)
*
* @return the output width (in pixels on GLCD)
*/
int lcd_put_lchar_max(const lchar_t &c, const pixel_len_t max_length);
/**
* @brief Draw a SRAM UTF-8 string
*
* @param utf8_str : the UTF-8 string
* @param max_length : the output width limit (in pixels on GLCD)
*
* @return the output width (in pixels on GLCD)
*/
int lcd_put_u8str_max(const char *utf8_str, const pixel_len_t max_length);
/**
* Change the print cursor position
*/
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row);
/**
* @brief Draw a ROM UTF-8 string
*
* @param pstr : the ROM UTF-8 string
* @param max_length : the output width limit (in pixels on GLCD)
*
* @return the output width (in pixels on GLCD)
*/
int lcd_put_u8str_max_P(PGM_P pstr, const pixel_len_t max_length);
inline int lcd_put_u8str_max_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P pstr, const pixel_len_t max_length) {
lcd_moveto(col, row);
return lcd_put_u8str_max_P(pstr, max_length);
}
inline int lcd_put_u8str_max(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr, const pixel_len_t max_length) {
return lcd_put_u8str_max_P(col, row, FTOP(fstr), max_length);
}
/**
* @brief Draw an integer, left-justified
*
* @param i : the integer
*/
void lcd_put_int(const int i);
inline void lcd_put_int(const lcd_uint_t col, const lcd_uint_t row, const int i) {
lcd_moveto(col, row);
lcd_put_int(i);
}
/**
* @brief Draw a ROM UTF-8 string
*
* @param i : the integer
*/
inline int lcd_put_u8str_P(PGM_P const pstr) { return lcd_put_u8str_max_P(pstr, PIXEL_LEN_NOLIMIT); }
inline int lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr) {
lcd_moveto(col, row);
return lcd_put_u8str_P(pstr);
}
/**
* @brief Draw a ROM UTF-8 F-string
*
* @param fstr The F-string pointer
* @return the output width (in pixels on GLCD)
*/
inline int lcd_put_u8str(FSTR_P const fstr) { return lcd_put_u8str_P(FTOP(fstr)); }
inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr) {
return lcd_put_u8str_P(col, row, FTOP(fstr));
}
/**
* @brief Draw a string with optional substitution
* @details Print a string with optional substitutions:
* $ displays the clipped string given by fstr or cstr
* = displays '0'....'10' for indexes 0 - 10
* ~ displays '1'....'11' for indexes 0 - 10
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
* @ displays an axis name such as XYZUVW, or E for an extruder
*
* @param ptpl A ROM string (template)
* @param ind An index value to use for = ~ * substitution
* @param cstr An SRAM C-string to use for $ substitution
* @param fstr A ROM F-string to use for $ substitution
* @param maxlen The maximum size of the string (in pixels on GLCD)
* @return the output width (in pixels on GLCD)
*/
lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH);
inline lcd_uint_t lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const ptpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
lcd_moveto(col, row);
return lcd_put_u8str_P(ptpl, ind, cstr, fstr, maxlen);
}
/**
* @brief Draw a ROM UTF-8 F-string with optional substitution
* @details (See above)
*
* @param ftpl A ROM F-string (template)
* @param ind An index value to use for = ~ * substitution
* @param cstr An SRAM C-string to use for $ substitution
* @param fstr A ROM F-string to use for $ substitution
* @param maxlen The maximum size of the string (in pixels on GLCD)
* @return the output width (in pixels on GLCD)
*/
inline lcd_uint_t lcd_put_u8str(FSTR_P const ftpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
return lcd_put_u8str_P(FTOP(ftpl), ind, cstr, fstr, maxlen);
}
/**
* @param col
* @param row
*/
inline lcd_uint_t lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const ftpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
return lcd_put_u8str_P(col, row, FTOP(ftpl), ind, cstr, fstr, maxlen);
}
/**
* @brief Draw a SRAM string with no width limit
*
* @param str The UTF-8 string
* @return the output width (in pixels on GLCD)
*/
inline int lcd_put_u8str(const char * const str) { return lcd_put_u8str_max(str, PIXEL_LEN_NOLIMIT); }
/**
* @param col
* @param row
*/
inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, const char * const str) {
lcd_moveto(col, row);
return lcd_put_u8str(str);
}
/**
* @brief Draw a UTF-8 character with no width limit
*
* @param c The lchar to draw
* @return the output width (in pixels on GLCD)
*/
inline int lcd_put_lchar(const lchar_t &c) { return lcd_put_lchar_max(c, PIXEL_LEN_NOLIMIT); }
/**
* @param col
* @param row
*/
inline int lcd_put_lchar(const lcd_uint_t col, const lcd_uint_t row, const lchar_t &c) {
lcd_moveto(col, row);
return lcd_put_lchar(c);
}
/**
* @brief Calculate the width of a ROM UTF-8 string (in pixels on GLCD)
*
* @param pstr The ROM-based UTF-8 string
* @return the string width (in pixels on GLCD)
*/
int calculateWidth(PGM_P const pstr);
/**
* @brief Calculate the width of a ROM UTF-8 string (in pixels on GLCD)
*
* @param pstr The ROM-based UTF-8 string
* @return the string width (in pixels on GLCD)
*/
inline int calculateWidth(FSTR_P const fstr) { return calculateWidth(FTOP(fstr)); }

1879
src/lcd/marlinui.cpp Normal file

File diff suppressed because it is too large Load Diff

791
src/lcd/marlinui.h Normal file
View File

@ -0,0 +1,791 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../inc/MarlinConfig.h"
#include "../sd/cardreader.h"
#include "../module/motion.h"
#include "../libs/buzzer.h"
#include "buttons.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "tft_io/touch_calibration.h"
#endif
#if E_MANUAL > 1
#define MULTI_E_MANUAL 1
#endif
#if HAS_DISPLAY
#include "../module/printcounter.h"
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "../feature/pause.h"
#endif
#if ENABLED(DWIN_CREALITY_LCD)
#include "e3v2/creality/dwin.h"
#elif ENABLED(DWIN_LCD_PROUI)
#include "e3v2/proui/dwin.h"
#endif
#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)
typedef bool (*statusResetFunc_t)();
#if HAS_WIRED_LCD
enum LCDViewAction : uint8_t {
LCDVIEW_NONE,
LCDVIEW_REDRAW_NOW,
LCDVIEW_CALL_REDRAW_NEXT,
LCDVIEW_CLEAR_CALL_REDRAW,
LCDVIEW_CALL_NO_REDRAW
};
#if HAS_ADC_BUTTONS
uint8_t get_ADC_keyValue();
#endif
#if HAS_MARLINUI_MENU
#include "lcdprint.h"
#if !HAS_GRAPHICAL_TFT
void _wrap_string(uint8_t &col, uint8_t &row, const char * const string, read_byte_cb_t cb_read_byte, const bool wordwrap=false);
inline void wrap_string_P(uint8_t &col, uint8_t &row, PGM_P const pstr, const bool wordwrap=false) { _wrap_string(col, row, pstr, read_byte_rom, wordwrap); }
inline void wrap_string(uint8_t &col, uint8_t &row, const char * const string, const bool wordwrap=false) { _wrap_string(col, row, string, read_byte_ram, wordwrap); }
#endif
typedef void (*screenFunc_t)();
typedef void (*menuAction_t)();
#endif // HAS_MARLINUI_MENU
#endif // HAS_WIRED_LCD
#if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
#define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_BUTTONS, 50, 100)
#endif
#if HAS_MARLINUI_U8GLIB
enum MarlinFont : uint8_t {
FONT_STATUSMENU = 1,
FONT_EDIT,
FONT_MENU
};
#else
enum HD44780CharSet : uint8_t {
CHARSET_MENU,
CHARSET_INFO,
CHARSET_BOOT
};
#endif
#if HAS_PREHEAT
typedef struct {
#if HAS_HOTEND
celsius_t hotend_temp;
#endif
#if HAS_HEATED_BED
celsius_t bed_temp;
#endif
#if HAS_FAN
uint16_t fan_speed;
#endif
} preheat_t;
#endif
#if HAS_MARLINUI_MENU
// Manual Movement class
class ManualMove {
private:
static AxisEnum axis;
#if MULTI_E_MANUAL
static int8_t e_index;
#else
static int8_t constexpr e_index = 0;
#endif
static millis_t start_time;
#if IS_KINEMATIC
static xyze_pos_t all_axes_destination;
#endif
public:
static screenFunc_t screen_ptr;
static float menu_scale;
#if IS_KINEMATIC
static float offset;
#endif
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
static float e_origin;
#endif
template <typename T>
static void set_destination(const T& dest) {
#if IS_KINEMATIC
// Moves are segmented, so the entire move is not submitted at once.
// Using a separate variable prevents corrupting the in-progress move.
all_axes_destination = current_position;
all_axes_destination.set(dest);
#else
// Moves are submitted as single line to the planner using buffer_line.
current_position.set(dest);
#endif
}
static float axis_value(const AxisEnum axis) {
return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis);
}
static bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
#if IS_KINEMATIC
float &valref = offset;
const float rmin = min - current_position[axis], rmax = max - current_position[axis];
#else
float &valref = current_position[axis];
const float rmin = min, rmax = max;
#endif
valref += diff;
const float pre = valref;
if (min != max) { if (diff < 0) NOLESS(valref, rmin); else NOMORE(valref, rmax); }
return pre != valref;
}
#if IS_KINEMATIC
static bool processing;
#else
static bool constexpr processing = false;
#endif
static void task();
static void soon(const AxisEnum axis OPTARG(MULTI_E_MANUAL, const int8_t eindex=active_extruder));
};
void lcd_move_axis(const AxisEnum);
#endif
////////////////////////////////////////////
//////////// MarlinUI Singleton ////////////
////////////////////////////////////////////
class MarlinUI;
extern MarlinUI ui;
class MarlinUI {
public:
MarlinUI() {
TERN_(HAS_MARLINUI_MENU, currentScreen = status_screen);
}
static void init();
#if HAS_DISPLAY || HAS_DWIN_E3V2
static void init_lcd();
#else
static void init_lcd() {}
#endif
static void reinit_lcd() { TERN_(REINIT_NOISY_LCD, init_lcd()); }
#if HAS_WIRED_LCD
static bool detected();
#else
static bool detected() { return true; }
#endif
#if HAS_MULTI_LANGUAGE
static uint8_t language;
static void set_language(const uint8_t lang);
#endif
#if HAS_MARLINUI_U8GLIB
static void update_language_font();
#endif
#if ENABLED(SOUND_MENU_ITEM)
static bool sound_on; // Initialized by settings.load()
#else
static constexpr bool sound_on = true;
#endif
#if USE_MARLINUI_BUZZER
static void buzz(const long duration, const uint16_t freq);
#endif
static void chirp() {
TERN_(HAS_CHIRP, TERN(USE_MARLINUI_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
}
#if ENABLED(LCD_HAS_STATUS_INDICATORS)
static void update_indicators();
#endif
// LCD implementations
static void clear_lcd();
#if BOTH(HAS_MARLINUI_MENU, TOUCH_SCREEN_CALIBRATION)
static void check_touch_calibration() {
if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen;
}
#endif
#if ENABLED(SDSUPPORT)
#define MEDIA_MENU_GATEWAY TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media)
static void media_changed(const uint8_t old_stat, const uint8_t stat);
#endif
#if HAS_LCD_BRIGHTNESS
#ifndef LCD_BRIGHTNESS_MIN
#define LCD_BRIGHTNESS_MIN 1
#endif
#ifndef LCD_BRIGHTNESS_MAX
#define LCD_BRIGHTNESS_MAX 255
#endif
#ifndef LCD_BRIGHTNESS_DEFAULT
#define LCD_BRIGHTNESS_DEFAULT LCD_BRIGHTNESS_MAX
#endif
static uint8_t brightness;
static bool backlight;
static void _set_brightness(); // Implementation-specific
static void set_brightness(const uint8_t value);
FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
#endif
#if LCD_BACKLIGHT_TIMEOUT
#define LCD_BKL_TIMEOUT_MIN 1u
#define LCD_BKL_TIMEOUT_MAX UINT16_MAX // Slightly more than 18 hours
static uint16_t lcd_backlight_timeout;
static millis_t backlight_off_ms;
static void refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
#define SLEEP_TIMEOUT_MIN 0
#define SLEEP_TIMEOUT_MAX 99
static uint8_t sleep_timeout_minutes;
static millis_t screen_timeout_millis;
static void refresh_screen_timeout();
static void sleep_on();
static void sleep_off();
#endif
#if HAS_DWIN_E3V2_BASIC
static void refresh();
#else
FORCE_INLINE static void refresh() {
TERN_(HAS_WIRED_LCD, refresh(LCDVIEW_CLEAR_CALL_REDRAW));
}
#endif
#if HAS_PRINT_PROGRESS
#if HAS_PRINT_PROGRESS_PERMYRIAD
typedef uint16_t progress_t;
#define PROGRESS_SCALE 100U
#define PROGRESS_MASK 0x7FFF
#else
typedef uint8_t progress_t;
#define PROGRESS_SCALE 1U
#define PROGRESS_MASK 0x7F
#endif
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
static progress_t progress_override;
static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
#endif
#if ENABLED(SHOW_REMAINING_TIME)
static uint32_t _calculated_remaining_time() {
const duration_t elapsed = print_job_timer.duration();
const progress_t progress = _get_progress();
return progress ? elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress : 0;
}
#if ENABLED(USE_M73_REMAINING_TIME)
static uint32_t remaining_time;
FORCE_INLINE static void set_remaining_time(const uint32_t r) { remaining_time = r; }
FORCE_INLINE static uint32_t get_remaining_time() { return remaining_time ?: _calculated_remaining_time(); }
FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
#else
FORCE_INLINE static uint32_t get_remaining_time() { return _calculated_remaining_time(); }
#endif
#endif
static progress_t _get_progress();
#if HAS_PRINT_PROGRESS_PERMYRIAD
FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
#endif
static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
#else
static constexpr uint8_t get_progress_percent() { return 0; }
#endif
#if HAS_STATUS_MESSAGE
#if EITHER(HAS_WIRED_LCD, DWIN_LCD_PROUI)
#if ENABLED(STATUS_MESSAGE_SCROLLING)
#define MAX_MESSAGE_LENGTH _MAX(LONG_FILENAME_LENGTH, MAX_LANG_CHARSIZE * 2 * (LCD_WIDTH))
#else
#define MAX_MESSAGE_LENGTH (MAX_LANG_CHARSIZE * (LCD_WIDTH))
#endif
#else
#define MAX_MESSAGE_LENGTH 63
#endif
static char status_message[];
static uint8_t alert_level; // Higher levels block lower levels
#if HAS_STATUS_MESSAGE_TIMEOUT
static millis_t status_message_expire_ms; // Reset some status messages after a timeout
#endif
#if ENABLED(STATUS_MESSAGE_SCROLLING)
static uint8_t status_scroll_offset;
static void advance_status_scroll();
static char* status_and_len(uint8_t &len);
#endif
static bool has_status();
static void reset_status(const bool no_welcome=false);
static void set_alert_status(FSTR_P const fstr);
static void reset_alert_level() { alert_level = 0; }
static statusResetFunc_t status_reset_callback;
static void set_status_reset_fn(const statusResetFunc_t fn=nullptr) { status_reset_callback = fn; }
#else
static constexpr bool has_status() { return false; }
static void reset_status(const bool=false) {}
static void set_alert_status(FSTR_P const) {}
static void reset_alert_level() {}
static void set_status_reset_fn(const statusResetFunc_t=nullptr) {}
#endif
static void set_status(const char * const cstr, const bool persist=false);
static void set_status(FSTR_P const fstr, const int8_t level=0);
static void status_printf(int8_t level, FSTR_P const fmt, ...);
#if HAS_DISPLAY
static void update();
static void abort_print();
static void pause_print();
static void resume_print();
static void flow_fault();
#if BOTH(HAS_MARLINUI_MENU, PSU_CONTROL)
static void poweroff();
#endif
#if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
static bool get_blink();
#endif
#if HAS_WIRED_LCD
static millis_t next_button_update_ms;
static LCDViewAction lcdDrawUpdate;
FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
static void draw_custom_bootscreen(const uint8_t frame=0);
static void show_custom_bootscreen();
#endif
#if ENABLED(SHOW_BOOTSCREEN)
#ifndef BOOTSCREEN_TIMEOUT
#define BOOTSCREEN_TIMEOUT 2500
#endif
static void draw_marlin_bootscreen(const bool line2=false);
static void show_marlin_bootscreen();
static void show_bootscreen();
static void bootscreen_completion(const millis_t sofar);
#endif
#if HAS_MARLINUI_U8GLIB
static void set_font(const MarlinFont font_nr);
#elif IS_DWIN_MARLINUI
static void set_font(const uint8_t font_nr);
#endif
#if HAS_MARLINUI_HD44780
static void set_custom_characters(const HD44780CharSet screen_charset=CHARSET_INFO);
#endif
#if ENABLED(LCD_PROGRESS_BAR) && !HAS_MARLINUI_U8GLIB
static millis_t progress_bar_ms; // Start time for the current progress bar cycle
static void draw_progress_bar(const uint8_t percent);
#if PROGRESS_MSG_EXPIRE > 0
static millis_t expire_status_ms; // = 0
FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
#endif
#endif
static uint8_t lcd_status_update_delay;
#if HAS_LCD_CONTRAST
static uint8_t contrast;
static void _set_contrast(); // Implementation-specific
static void set_contrast(const uint8_t value);
FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
#endif
#if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
static millis_t next_filament_display;
#endif
#if HAS_TOUCH_SLEEP
static void wakeup_screen();
#endif
static void quick_feedback(const bool clear_buttons=true);
#if HAS_SOUND
static void completion_feedback(const bool good=true);
#else
static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
#endif
#if HAS_TOUCH_BUTTONS
static bool on_edit_screen;
static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
#endif
static void status_screen();
#endif
#if HAS_MARLINUI_U8GLIB
static bool drawing_screen, first_page;
#else
static constexpr bool drawing_screen = false, first_page = true;
#endif
#if IS_DWIN_MARLINUI
static bool did_first_redraw;
static bool old_is_printing;
#endif
#if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
static void zoffset_overlay(const int8_t dir);
static void zoffset_overlay(const_float_t zvalue);
#endif
static void draw_kill_screen();
static void kill_screen(FSTR_P const lcd_error, FSTR_P const lcd_component);
#if DISABLED(LIGHTWEIGHT_UI)
static void draw_status_message(const bool blink);
#endif
#else // No LCD
static void update() {}
static void kill_screen(FSTR_P const, FSTR_P const) {}
#endif
#if ENABLED(SDSUPPORT)
#if BOTH(SCROLL_LONG_FILENAMES, HAS_MARLINUI_MENU)
#define MARLINUI_SCROLL_NAME 1
#endif
#if MARLINUI_SCROLL_NAME
static uint8_t filename_scroll_pos, filename_scroll_max;
#endif
static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
#endif
#if HAS_PREHEAT
enum PreheatTarget : uint8_t { PT_HOTEND, PT_BED, PT_FAN, PT_CHAMBER, PT_ALL = 0xFF };
static preheat_t material_preset[PREHEAT_COUNT];
static FSTR_P get_preheat_label(const uint8_t m);
static void apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e=active_extruder);
static void preheat_set_fan(const uint8_t m) { TERN_(HAS_FAN, apply_preheat(m, _BV(PT_FAN))); }
static void preheat_hotend(const uint8_t m, const uint8_t e=active_extruder) { TERN_(HAS_HOTEND, apply_preheat(m, _BV(PT_HOTEND))); }
static void preheat_hotend_and_fan(const uint8_t m, const uint8_t e=active_extruder) { preheat_hotend(m, e); preheat_set_fan(m); }
static void preheat_bed(const uint8_t m) { TERN_(HAS_HEATED_BED, apply_preheat(m, _BV(PT_BED))); }
static void preheat_all(const uint8_t m) { apply_preheat(m, PT_ALL); }
#endif
static void reset_status_timeout(const millis_t ms) {
TERN(SCREENS_CAN_TIME_OUT, return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS, UNUSED(ms));
}
#if HAS_MARLINUI_MENU
#if HAS_TOUCH_BUTTONS
static uint8_t touch_buttons;
static uint8_t repeat_delay;
#else
static constexpr uint8_t touch_buttons = 0;
#endif
#if ENABLED(ENCODER_RATE_MULTIPLIER)
static bool encoderRateMultiplierEnabled;
static millis_t lastEncoderMovementMillis;
static void enable_encoder_multiplier(const bool onoff);
#define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
#else
#define ENCODER_RATE_MULTIPLY(F) NOOP
#endif
// Manual Movement
static ManualMove manual_move;
static bool can_show_slider() { return !external_control && currentScreen != manual_move.screen_ptr; }
// Select Screen (modal NO/YES style dialog)
static bool selection;
static void set_selection(const bool sel) { selection = sel; }
static bool update_selection();
static void synchronize(FSTR_P const msg=nullptr);
static screenFunc_t currentScreen;
static bool screen_changed;
static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
static void push_current_screen();
// goto_previous_screen and go_back may also be used as menu item callbacks
static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
static void goto_previous_screen() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, false)); }
static void go_back() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, true)); }
static void return_to_status();
static bool on_status_screen() { return currentScreen == status_screen; }
FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
#if ENABLED(LIGHTWEIGHT_UI)
static void lcd_in_status(const bool inStatus);
#endif
FORCE_INLINE static bool screen_is_sticky() {
return TERN1(SCREENS_CAN_TIME_OUT, defer_return_to_status);
}
FORCE_INLINE static void defer_status_screen(const bool defer=true) {
TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
}
static void goto_previous_screen_no_defer() {
defer_status_screen(false);
goto_previous_screen();
}
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
static void reselect_last_file();
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
static void ubl_plot(const uint8_t x_plot, const uint8_t y_plot);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
static void ubl_mesh_edit_start(const_float_t initial);
static float ubl_mesh_value();
#endif
static void draw_select_screen_prompt(FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr);
#else
static void return_to_status() {}
static constexpr bool on_status_screen() { return true; }
#if HAS_WIRED_LCD
FORCE_INLINE static void run_current_screen() { status_screen(); }
#endif
#endif
#if EITHER(HAS_MARLINUI_MENU, EXTENSIBLE_UI)
static bool lcd_clicked;
static bool use_click() {
const bool click = lcd_clicked;
lcd_clicked = false;
return click;
}
#else
static constexpr bool lcd_clicked = false;
static bool use_click() { return false; }
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_MARLINUI_MENU, EXTENSIBLE_UI, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder);
#else
static void _pause_show_message() {}
#define pause_show_message(...) _pause_show_message()
#endif
//
// EEPROM: Reset / Init / Load / Store
//
#if HAS_MARLINUI_MENU
static void reset_settings();
#endif
#if ENABLED(EEPROM_SETTINGS)
#if HAS_MARLINUI_MENU
static void init_eeprom();
static void load_settings();
static void store_settings();
#endif
#if DISABLED(EEPROM_AUTO_INIT)
static void eeprom_alert(const uint8_t msgid);
static void eeprom_alert_crc() { eeprom_alert(0); }
static void eeprom_alert_index() { eeprom_alert(1); }
static void eeprom_alert_version() { eeprom_alert(2); }
#endif
#endif
//
// Special handling if a move is underway
//
#if ANY(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
#define LCD_HAS_WAIT_FOR_MOVE 1
static bool wait_for_move;
#else
static constexpr bool wait_for_move = false;
#endif
//
// Block interaction while under external control
//
#if HAS_MARLINUI_MENU && EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
static bool external_control;
FORCE_INLINE static void capture() { external_control = true; }
FORCE_INLINE static void release() { external_control = false; }
#if ENABLED(AUTO_BED_LEVELING_UBL)
static void external_encoder();
#endif
#else
static constexpr bool external_control = false;
#endif
#if HAS_ENCODER_ACTION
static volatile uint8_t buttons;
#if IS_RRW_KEYPAD
static volatile uint8_t keypad_buttons;
static bool handle_keypad();
#endif
#if HAS_SLOW_BUTTONS
static volatile uint8_t slow_buttons;
static uint8_t read_slow_buttons();
#endif
static void update_buttons();
#if HAS_ENCODER_NOISE
#ifndef ENCODER_SAMPLES
#define ENCODER_SAMPLES 10
#endif
/**
* Some printers may have issues with EMI noise especially using a motherboard with 3.3V logic levels
* it may cause the logical LOW to float into the undefined region and register as a logical HIGH
* causing it to erroneously register as if someone clicked the button and in worst case make the
* printer unusable in practice.
*/
static bool hw_button_pressed() {
LOOP_L_N(s, ENCODER_SAMPLES) {
if (!BUTTON_CLICK()) return false;
safe_delay(1);
}
return true;
}
#else
static bool hw_button_pressed() { return BUTTON_CLICK(); }
#endif
#if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
static void wait_for_release();
#endif
static uint32_t encoderPosition;
#define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1))
#if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
static int8_t encoderDirection;
#else
static constexpr int8_t encoderDirection = ENCODERBASE;
#endif
FORCE_INLINE static void encoder_direction_normal() {
#if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
encoderDirection = ENCODERBASE;
#endif
}
FORCE_INLINE static void encoder_direction_menus() {
TERN_(REVERSE_MENU_DIRECTION, encoderDirection = -(ENCODERBASE));
}
FORCE_INLINE static void encoder_direction_select() {
TERN_(REVERSE_SELECT_DIRECTION, encoderDirection = -(ENCODERBASE));
}
#else
static void update_buttons() {}
static bool hw_button_pressed() { return false; }
#endif
static bool button_pressed() { return hw_button_pressed() || TERN0(TOUCH_SCREEN, touch_pressed()); }
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
static void touch_calibration_screen();
#endif
#if HAS_GRAPHICAL_TFT
static void move_axis_screen();
#endif
private:
#if SCREENS_CAN_TIME_OUT
static millis_t return_to_status_ms;
static bool defer_return_to_status;
#else
static constexpr bool defer_return_to_status = false;
#endif
#if HAS_STATUS_MESSAGE
static void finish_status(const bool persist);
#endif
#if HAS_WIRED_LCD
static void draw_status_screen();
#if HAS_GRAPHICAL_TFT
static void tft_idle();
#if ENABLED(TOUCH_SCREEN)
static bool touch_pressed();
#endif
#endif
#endif
};
#define LCD_MESSAGE_F(S) ui.set_status(F(S))
#define LCD_MESSAGE(M) ui.set_status(GET_TEXT_F(M))
#define LCD_ALERTMESSAGE_F(S) ui.set_alert_status(F(S))
#define LCD_ALERTMESSAGE(M) ui.set_alert_status(GET_TEXT_F(M))

55
src/lcd/scaled_tft.h Normal file
View File

@ -0,0 +1,55 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../inc/MarlinConfig.h"
#ifndef GRAPHICAL_TFT_UPSCALE
#define GRAPHICAL_TFT_UPSCALE 2
#endif
#ifndef TFT_WIDTH
#if GRAPHICAL_TFT_UPSCALE == 3
#define TFT_WIDTH 480
#else
#define TFT_WIDTH 320
#endif
#endif
#ifndef TFT_HEIGHT
#if GRAPHICAL_TFT_UPSCALE == 3
#define TFT_HEIGHT 320
#else
#define TFT_HEIGHT 240
#endif
#endif
#ifndef TFT_PIXEL_OFFSET_X
#if GRAPHICAL_TFT_UPSCALE == 2
#define TFT_PIXEL_OFFSET_X 32
#else
#define TFT_PIXEL_OFFSET_X 48
#endif
#endif
#ifndef TFT_PIXEL_OFFSET_Y
#define TFT_PIXEL_OFFSET_Y 32 // 32 is best for both 320x240 and 480x320
#endif

173
src/lcd/tft_io/ili9328.h Normal file
View File

@ -0,0 +1,173 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ILI9328_DRVCTL_SM 0x0400
#define ILI9328_DRVCTL_SS 0x0100 // Select the shift direction of outputs from the source driver. 0 - from S1 to S720 / 1 - from S720 to S1
#define ILI9328_GATE_SCANCTL_GS 0x8000 // Sets the direction of scan by the gate driver in the range determined by SCN[4:0] and NL[4:0].
#define ILI9328_ETMOD_TRI 0x8000
#define ILI9328_ETMOD_DFM 0x4000
#define ILI9328_ETMOD_BGR 0x1000 // RGB-BGR ORDER
#define ILI9328_ETMOD_RGB 0x0000
#define ILI9328_ETMOD_ORG 0x0080
#define ILI9328_ETMOD_ID1 0x0020 // 0 - Vertical Decrement / 1 - Vertical Increment
#define ILI9328_ETMOD_ID0 0x0010 // 0 - Horizontal Decrement / 1 - Horizontal Increment
#define ILI9328_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical
// MKS Robin TFT v1.1 - 320x240 ; Cable on the left side
#if TFT_ROTATION == TFT_ROTATE_180
#define ILI9328_DRVCTL_DATA 0x0000
#define ILI9328_GATE_SCANCTL1_DATA 0xA700
#else
#define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS
#define ILI9328_GATE_SCANCTL1_DATA 0x2700
#endif
/*
#define ILI9328_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9328_ETMOD_AM) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9328_ETMOD_ID1) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9328_ETMOD_ID0)
*/
#define ILI9328_ETMOD_ORIENTATION (ILI9328_ETMOD_AM | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
#define ILI9328_ETMOD_COLOR ILI9328_ETMOD_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define ILI9328_ETMOD_COLOR ILI9328_ETMOD_RGB
#endif
#define ILI9328_ETMOD_DATA (ILI9328_ETMOD_ORIENTATION) | (ILI9328_ETMOD_COLOR)
#define ILI9328_RDDID 0x00 // ID code - 0x9328
#define ILI9328_DRVCTL 0x01 // Driver Output Control
#define ILI9328_LCDCTL 0x02 // LCD Driving Wave Control
#define ILI9328_ETMOD 0x03 // Entry Mode - Control the GRAM update direction
#define ILI9328_RESIZECTL 0x04 // Resizing Control Register
#define ILI9328_DISCTRL1 0x07 // Display Control 1
#define ILI9328_DISCTRL2 0x08 // Display Control 2
#define ILI9328_DISCTRL3 0x09 // Display Control 3
#define ILI9328_DISCTRL4 0x0A // Display Control 4
#define ILI9328_RGBCTRL1 0x0C // RGB Display Interface Control 1
#define ILI9328_FMARKERPOS 0x0D // Frame Marker Position
#define ILI9328_RGBCTRL2 0x0F // RGB Display Interface Control 2
#define ILI9328_PWCTRL1 0x10 // Power Control 1
#define ILI9328_PWCTRL2 0x11 // Power Control 2
#define ILI9328_PWCTRL3 0x12 // Power Control 3
#define ILI9328_PWCTRL4 0x13 // Power Control 4
// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
#define ILI9328_HASET 0x20 // GRAM Horizontal Address Set (0-255)
#define ILI9328_VASET 0x21 // GRAM Vertical Address Set (0-511)
#define ILI9328_RAMWR 0x22 // Write data to GRAM
#define ILI9328_RAMRD 0x22 // Read Data from GRAM
#define ILI9328_PWCTRL7 0x29 // Power Control 7
#define ILI9328_FRMCTR 0x2B // Frame Rate and Color Control
#define ILI9328_GAMCTRL1 0x30 // Gamma Control
#define ILI9328_GAMCTRL2 0x31 // Gamma Control
#define ILI9328_GAMCTRL3 0x32 // Gamma Control
#define ILI9328_GAMCTRL4 0x35 // Gamma Control
#define ILI9328_GAMCTRL5 0x36 // Gamma Control
#define ILI9328_GAMCTRL6 0x37 // Gamma Control
#define ILI9328_GAMCTRL7 0x38 // Gamma Control
#define ILI9328_GAMCTRL8 0x39 // Gamma Control
#define ILI9328_GAMCTRL9 0x3C // Gamma Control
#define ILI9328_GAMCTRLA 0x3D // Gamma Control
// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
#define ILI9328_HASTART 0x50 // Horizontal Address Start Position (0-255)
#define ILI9328_HAEND 0x51 // Horizontal Address End Position (0-255)
#define ILI9328_VASTART 0x52 // Vertical Address Start Position (0-511)
#define ILI9328_VAEND 0x53 // Vertical Address End Position (0-511)
#define ILI9328_GATE_SCANCTL1 0x60 // Gate Scan Control
#define ILI9328_GATE_SCANCTL2 0x61 // Gate Scan Control
#define ILI9328_GATE_SCANCTL3 0x6A // Gate Scan Control
#define ILI9328_PLTPOS1 0x80 // Partial Image 1 Display Position
#define ILI9328_PLTSTART1 0x81 // Partial Image 1 RAM Start Address
#define ILI9328_PLTEND1 0x82 // Partial Image 1 RAM End Address
#define ILI9328_PLTPOS2 0x83 // Partial Image 2 Display Position
#define ILI9328_PLTSTART2 0x84 // Partial Image 2 RAM Start Address
#define ILI9328_PLTEND2 0x85 // Partial Image 2 RAM End Address
#define ILI9328_IFCTL1 0x90 // Panel Interface Control 1
#define ILI9328_IFCTL2 0x92 // Panel Interface Control 2
#define ILI9328_IFCTL4 0x95 // Panel Interface Control 4
#define ILI9328_IFCTL5 0x97 // Panel Interface Control 5
#define ILI9328_OTPWR 0xA1 // OTP VCM Programming Control
#define ILI9328_RDOTP 0xA2 // OTP VCM Status and Enable
#define ILI9328_OTPPKEY 0xA5 // OTP Programming ID Key
static const uint16_t ili9328_init[] = {
DATASIZE_16BIT,
ESC_REG(ILI9328_DRVCTL), ILI9328_DRVCTL_DATA,
ESC_REG(ILI9328_LCDCTL), 0x0400, // LCD Driving Wave Control
ESC_REG(ILI9328_ETMOD), ILI9328_ETMOD_DATA,
ESC_REG(ILI9328_RESIZECTL), 0x0000,
ESC_REG(ILI9328_DISCTRL2), 0x0202,
ESC_REG(ILI9328_DISCTRL3), 0x0000,
ESC_REG(ILI9328_DISCTRL4), 0x0000,
ESC_REG(ILI9328_RGBCTRL1), 0x0000,
ESC_REG(ILI9328_FMARKERPOS), 0x0000,
ESC_REG(ILI9328_RGBCTRL2), 0x0000,
ESC_REG(ILI9328_PWCTRL1), 0x0000,
ESC_REG(ILI9328_PWCTRL2), 0x0007,
ESC_REG(ILI9328_PWCTRL3), 0x0000,
ESC_REG(ILI9328_PWCTRL4), 0x0000,
ESC_REG(ILI9328_DISCTRL1), 0x0001,
ESC_DELAY(200),
ESC_REG(ILI9328_PWCTRL1), 0x1690,
ESC_REG(ILI9328_PWCTRL2), 0x0227,
ESC_DELAY(50),
ESC_REG(ILI9328_PWCTRL3), 0x008C,
ESC_DELAY(50),
ESC_REG(ILI9328_PWCTRL4), 0x1500,
ESC_REG(ILI9328_PWCTRL7), 0x0004,
ESC_REG(ILI9328_FRMCTR), 0x000D,
ESC_DELAY(50),
ESC_REG(ILI9328_GATE_SCANCTL1), ILI9328_GATE_SCANCTL1_DATA,
ESC_REG(ILI9328_GATE_SCANCTL2), 0x0001,
ESC_REG(ILI9328_GATE_SCANCTL3), 0x0000,
ESC_REG(ILI9328_PLTPOS1), 0x0000,
ESC_REG(ILI9328_PLTSTART1), 0x0000,
ESC_REG(ILI9328_PLTEND1), 0x0000,
ESC_REG(ILI9328_PLTPOS2), 0x0000,
ESC_REG(ILI9328_PLTSTART2), 0x0000,
ESC_REG(ILI9328_PLTEND2), 0x0000,
ESC_REG(ILI9328_IFCTL1), 0x0010,
ESC_REG(ILI9328_IFCTL2), 0x0600,
ESC_REG(ILI9328_DISCTRL1), 0x0133,
ESC_END
};

170
src/lcd/tft_io/ili9341.h Normal file
View File

@ -0,0 +1,170 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ILI9341_MADCTL_MY 0x80 // Row Address Order
#define ILI9341_MADCTL_MX 0x40 // Column Address Order
#define ILI9341_MADCTL_MV 0x20 // Row/Column Exchange
#define ILI9341_MADCTL_ML 0x10 // Vertical Refresh Order
#define ILI9341_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define ILI9341_MADCTL_RGB 0x00
#define ILI9341_MADCTL_MH 0x04 // Horizontal Refresh Order
#define ILI9341_ORIENTATION_UP ILI9341_MADCTL_MY // 240x320 ; Cable on the upper side
#define ILI9341_ORIENTATION_RIGHT ILI9341_MADCTL_MV // 320x240 ; Cable on the right side
#define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; Cable on the left side
#define ILI9341_ORIENTATION_DOWN ILI9341_MADCTL_MX // 240x320 ; Cable on the upper side
#define ILI9341_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9341_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9341_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9341_MADCTL_MY)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
#define ILI9341_COLOR ILI9341_MADCTL_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define ILI9341_COLOR ILI9341_MADCTL_RGB
#endif
#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION) | (ILI9341_COLOR)
#define ILI9341_NOP 0x00 // No Operation
#define ILI9341_SWRESET 0x01 // Software Reset
#define ILI9341_RDDIDIF 0x04 // Read display identification information
#define ILI9341_RDDST 0x09 // Read Display Status
#define ILI9341_RDDPM 0x0A // Read Display Power Mode
#define ILI9341_RDDMADCTL 0x0B // Read Display MADCTL
#define ILI9341_RDDCOLMOD 0x0C // Read Display Pixel Format
#define ILI9341_RDDIM 0x0D // Read Display Image Format
#define ILI9341_RDDSM 0x0E // Read Display Signal Mode
#define ILI9341_RDDSDR 0x0F // Read Display Self-Diagnostic Result
#define ILI9341_SPLIN 0x10 // Enter Sleep Mode
#define ILI9341_SLPOUT 0x11 // Sleep Out
#define ILI9341_PTLON 0x12 // Partial Mode ON
#define ILI9341_NORON 0x13 // Normal Display Mode ON
#define ILI9341_DINVOFF 0x20 // Display Inversion OFF
#define ILI9341_DINVON 0x21 // Display Inversion ON
#define ILI9341_GAMSET 0x26 // Gamma Set
#define ILI9341_DISPOFF 0x28 // Display OFF
#define ILI9341_DISPON 0x29 // Display ON
#define ILI9341_CASET 0x2A // Column Address Set
#define ILI9341_PASET 0x2B // Page Address Set
#define ILI9341_RAMWR 0x2C // Memory Write
#define ILI9341_RGBSET 0x2D // Color Set
#define ILI9341_RAMRD 0x2E // Memory Read
#define ILI9341_PLTAR 0x30 // Partial Area
#define ILI9341_VSCRDEF 0x33 // Vertical Scrolling Definition
#define ILI9341_TEOFF 0x34 // Tearing Effect Line OFF
#define ILI9341_TEON 0x35 // Tearing Effect Line ON
#define ILI9341_MADCTL 0x36 // Memory Access Control
#define ILI9341_VSCRSADD 0x37 // Vertical Scrolling Start Address
#define ILI9341_IDMOFF 0x38 // Idle Mode OFF
#define ILI9341_IDMON 0x39 // Idle Mode ON
#define ILI9341_PIXSET 0x3A // COLMOD: Pixel Format Set
#define ILI9341_WRMEMC 0x3C // Write Memory Continue
#define ILI9341_RDMEMC 0x3E // Read Memory Continue
#define ILI9341_STE 0x44 // Set Tear Scanline
#define ILI9341_GSCAN 0x45 // Get Scanline
#define ILI9341_WRDISBV 0x51 // Write Display Brightness
#define ILI9341_RDDISBV 0x52 // Read Display Brightness
#define ILI9341_WRCTRLD 0x53 // Write CTRL Display
#define ILI9341_RDCTRLD 0x54 // Read CTRL Display
#define ILI9341_WRCABC 0x55 // Write Content Adaptive Brightness Control
#define ILI9341_RDCABC 0x56 // Read Content Adaptive Brightness Control
#define ILI9341_WRCABCMB 0x5E // Write CABC Minimum Brightness / Backlight Control 1
#define ILI9341_RDCABCMB 0x5F // Read CABC Minimum Brightness / Backlight Control 1
#define ILI9341_RDID1 0xDA // Read ID1
#define ILI9341_RDID2 0xDB // Read ID2
#define ILI9341_RDID3 0xDC // Read ID3
#define ILI9341_IFMODE 0xB0 // RGB Interface Signal Control
#define ILI9341_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors)
#define ILI9341_FRMCTR2 0xB2 // Frame Rate Control (In Idle Mode/8 colors)
#define ILI9341_FRMCTR3 0xB3 // Frame Rate control (In Partial Mode/Full Colors)
#define ILI9341_INVTR 0xB4 // Display Inversion Control
#define ILI9341_PRCTR 0xB5 // Blanking Porch Control
#define ILI9341_DISCTRL 0xB6 // Display Function Control
#define ILI9341_ETMOD 0xB7 // Entry Mode Set
#define ILI9341_BLCTL1 0xB8 // Backlight Control 1
#define ILI9341_BLCTL2 0xB9 // Backlight Control 2
#define ILI9341_BLCTL3 0xBA // Backlight Control 3
#define ILI9341_BLCTL4 0xBB // Backlight Control 4
#define ILI9341_BLCTL5 0xBC // Backlight Control 5
#define ILI9341_BLCTL7 0xBE // Backlight Control 7
#define ILI9341_BLCTL8 0xBF // Backlight Control 8
#define ILI9341_PWCTRL1 0xC0 // Power Control 1
#define ILI9341_PWCTRL2 0xC1 // Power Control 2
#define ILI9341_VMCTRL1 0xC5 // VCOM Control 1
#define ILI9341_VMCTRL2 0xC7 // VCOM Control 2
#define ILI9341_PWCTRLA 0xCB // Power control A
#define ILI9341_PWCTRLB 0xCF // Power control B
#define ILI9341_NVMWR 0xD0 // NV Memory Write
#define ILI9341_NVMPKEY 0xD1 // NV Memory Protection Key
#define ILI9341_RDNVM 0xD2 // NV Memory Status Read
#define ILI9341_RDID4 0xD3 // Read ID4 - 0x009341
#define ILI9341_PGAMCTRL 0xE0 // Positive Gamma Correction
#define ILI9341_NGAMCTRL 0xE1 // Negative Gamma Correction
#define ILI9341_DGAMCTRL1 0xE2 // Digital Gamma Control 1
#define ILI9341_DGAMCTRL2 0xE3 // Digital Gamma Control 2
#define ILI9341_DRVTCTLA1 0xE8 // Driver timing control A
#define ILI9341_DRVTCTLA2 0xE9 // Driver timing control A
#define ILI9341_DRVTCTLB 0xEA // Driver timing control B
#define ILI9341_PONSEQCTL 0xED // Power on sequence control
#define ILI9341_EN3G 0xF2 // Enable 3G - 3 gamma control
#define ILI9341_IFCTL 0xF6 // Interface Control
#define ILI9341_PUMPRCTL 0xF7 // Pump ratio control
static const uint16_t ili9341_init[] = {
DATASIZE_8BIT,
ESC_REG(ILI9341_SWRESET), ESC_DELAY(100),
ESC_REG(ILI9341_SLPOUT), ESC_DELAY(20),
/*
ESC_REG(ILI9341_PWCTRLA), 0x0039, 0x002C, 0x0000, 0x0034, 0x0002, // Power control A
ESC_REG(ILI9341_PWCTRLB), 0x0000, 0x00C1, 0x0030, // Power control B
ESC_REG(ILI9341_DRVTCTLA1), 0x0085, 0x0000, 0x0078, // Driver timing control A
ESC_REG(ILI9341_DRVTCTLB), 0x0000, 0x0000, // Driver timing control B
ESC_REG(ILI9341_PONSEQCTL), 0x0064, 0x0003, 0x0012, 0x0081, // Power on sequence control
ESC_REG(ILI9341_DISCTRL), 0x0008, 0x0082, 0x0027, // Display Function Control
ESC_REG(ILI9341_PUMPRCTL), 0x0020, // Pump ratio control
ESC_REG(ILI9341_VMCTRL1), 0x003E, 0x0028, // VCOM Control 1
ESC_REG(ILI9341_VMCTRL2), 0x0086, // VCOM Control 2
ESC_REG(ILI9341_FRMCTR1), 0x0000, 0x0018, // Frame Rate Control (In Normal Mode/Full Colors)
ESC_REG(ILI9341_PWCTRL1), 0x0023, // Power Control 1
ESC_REG(ILI9341_PWCTRL2), 0x0010, // Power Control 2
*/
ESC_REG(ILI9341_MADCTL), ILI9341_MADCTL_DATA,
ESC_REG(ILI9341_PIXSET), 0x0055,
/* Gamma Correction */
ESC_REG(ILI9341_EN3G), 0x0000, // 3Gamma Function Disable
ESC_REG(ILI9341_GAMSET), 0x0001, // Gamma curve selected
ESC_REG(ILI9341_PGAMCTRL), 0x000F, 0x0031, 0x002B, 0x000C, 0x000E, 0x0008, 0x004E, 0x00F1, 0x0037, 0x0007, 0x0010, 0x0003, 0x000E, 0x0009, 0x0000,
ESC_REG(ILI9341_NGAMCTRL), 0x0000, 0x000E, 0x0014, 0x0003, 0x0011, 0x0007, 0x0031, 0x00C1, 0x0048, 0x0008, 0x000F, 0x000C, 0x0031, 0x0036, 0x000F,
ESC_REG(ILI9341_NORON),
ESC_REG(ILI9341_DISPON),
ESC_END
};

164
src/lcd/tft_io/ili9488.h Normal file
View File

@ -0,0 +1,164 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ILI9488_MADCTL_MY 0x80 // Row Address Order
#define ILI9488_MADCTL_MX 0x40 // Column Address Order
#define ILI9488_MADCTL_MV 0x20 // Row/Column Exchange
#define ILI9488_MADCTL_ML 0x10 // Vertical Refresh Order
#define ILI9488_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define ILI9488_MADCTL_RGB 0x00
#define ILI9488_MADCTL_MH 0x04 // Horizontal Refresh Order
#define ILI9488_ORIENTATION_UP ILI9488_MADCTL_MY // 320x480 ; Cable on the upper side
#define ILI9488_ORIENTATION_RIGHT ILI9488_MADCTL_MV // 480x320 ; Cable on the right side
#define ILI9488_ORIENTATION_LEFT ILI9488_MADCTL_MY | ILI9488_MADCTL_MX | ILI9488_MADCTL_MV // 480x320 ; Cable on the left side
#define ILI9488_ORIENTATION_DOWN ILI9488_MADCTL_MX // 320x480 ; Cable on the upper side
#define ILI9488_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9488_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9488_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9488_MADCTL_MY)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
#define ILI9488_COLOR ILI9488_MADCTL_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define ILI9488_COLOR ILI9488_MADCTL_RGB
#endif
#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION) | (ILI9488_COLOR)
#define ILI9488_NOP 0x00 // No Operation
#define ILI9488_SWRESET 0x01 // Software Reset
#define ILI9488_RDDIDIF 0x04 // Read Display Identification Information
#define ILI9488_RDNUMED 0x05 // Read Number of the Errors on DSI
#define ILI9488_RDDST 0x09 // Read Display Status
#define ILI9488_RDDPM 0x0A // Read Display Power Mode
#define ILI9488_RDDMADCTL 0x0B // Read Display MADCTL
#define ILI9488_RDDCOLMOD 0x0C // Read Display COLMOD
#define ILI9488_RDDIM 0x0D // Read Display Image Mode
#define ILI9488_RDDSM 0x0E // Read Display Signal Mode
#define ILI9488_RDDSDR 0x0F // Read Display Self-Diagnostic Result
#define ILI9488_SLPIN 0x10 // Sleep IN
#define ILI9488_SLPOUT 0x11 // Sleep OUT
#define ILI9488_PTLON 0x12 // Partial Mode ON
#define ILI9488_NORON 0x13 // Normal Display Mode ON
#define ILI9488_INVOFF 0x20 // Display Inversion OFF
#define ILI9488_INVON 0x21 // Display Inversion ON
#define ILI9488_ALLPOFF 0x22 // All Pixels OFF
#define ILI9488_ALLPON 0x23 // All Pixels ON
#define ILI9488_DISOFF 0x28 // Display OFF
#define ILI9488_DISON 0x29 // Display ON
#define ILI9488_CASET 0x2A // Column Address Set
#define ILI9488_PASET 0x2B // Page Address Set
#define ILI9488_RAMWR 0x2C // Memory Write
#define ILI9488_RAMRD 0x2E // Memory Read
#define ILI9488_PLTAR 0x30 // Partial Area
#define ILI9488_VSCRDEF 0x33 // Vertical Scrolling Definition
#define ILI9488_TEOFF 0x34 // Tearing Effect Line OFF
#define ILI9488_TEON 0x35 // Tearing Effect Line ON
#define ILI9488_MADCTL 0x36 // Memory Access Control
#define ILI9488_VSCRSADD 0x37 // Vertical Scrolling Start Address
#define ILI9488_IDMOFF 0x38 // Idle Mode OFF
#define ILI9488_IDMON 0x39 // Idle Mode ON
#define ILI9488_COLMOD 0x3A // Interface Pixel Format
#define ILI9488_RAMWRC 0x3C // Memory Write Continue
#define ILI9488_RAMRDRC 0x3E // Memory Read Continue
#define ILI9488_TESLWR 0x44 // Write Tear Scan Line
#define ILI9488_TESLRD 0x45 // Read Scan Line
#define ILI9488_WRDISBV 0x51 // Write Display Brightness Value
#define ILI9488_RDDISBV 0x52 // Read Display Brightness Value
#define ILI9488_WRCTRLD 0x53 // Write Control Display Value
#define ILI9488_RDCTRLD 0x54 // Read Control Display Value
#define ILI9488_WRCABC 0x55 // Write Content Adaptive Brightness Control Value
#define ILI9488_RDCABC 0x56 // Read Content Adaptive Brightness Control Value
#define ILI9488_WRCABCMB 0x5E // Write CABC Minimum Brightness
#define ILI9488_RDCABCMB 0x5F // Read CABC Minimum Brightness
#define ILI9488_RDABCSDR 0x68 // Read Automatic Brightness Control Self-diagnostic Result
#define ILI9488_RDID1 0xDA // Read ID1
#define ILI9488_RDID2 0xDB // Read ID2
#define ILI9488_RDID3 0xDC // Read ID3
#define ILI9488_IFMODE 0xB0 // Interface Mode Control
#define ILI9488_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors)
#define ILI9488_FRMCTR2 0xB2 // Frame Rate Control (In Idle Mode/8 Colors)
#define ILI9488_FRMCTR3 0xB3 // Frame Rate Control (In Partial Mode/Full Colors)
#define ILI9488_INVTR 0xB4 // Display Inversion Control
#define ILI9488_PRCTR 0xB5 // Blanking Porch Control
#define ILI9488_DISCTRL 0xB6 // Display Function Control
#define ILI9488_ETMOD 0xB7 // Entry Mode Set
#define ILI9488_CECTRL1 0xB9 // Color Enhancement Control 1
#define ILI9488_CECTRL2 0xBA // Color Enhancement Control 2
#define ILI9488_HSLCTRL 0xBE // HS Lanes Control
#define ILI9488_PWCTRL1 0xC0 // Power Control 1
#define ILI9488_PWCTRL2 0xC1 // Power Control 2
#define ILI9488_PWCTRL3 0xC2 // Power Control 3 (For Normal Mode)
#define ILI9488_PWCTRL4 0xC3 // Power Control 4 (For Idle Mode)
#define ILI9488_PWCTRL5 0xC4 // Power Control 5 (For Partial Mode)
#define ILI9488_VMCTRL 0xC5 // VCOM Control
#define ILI9488_CABCCTRL1 0xC6 // CABC Control 1
#define ILI9488_CABCCTRL2 0xC8 // CABC Control 2
#define ILI9488_CABCCTRL3 0xC9 // CABC Control 3
#define ILI9488_CABCCTRL4 0xCA // CABC Control 4
#define ILI9488_CABCCTRL5 0xCB // CABC Control 5
#define ILI9488_CABCCTRL6 0xCC // CABC Control 6
#define ILI9488_CABCCTRL7 0xCD // CABC Control 7
#define ILI9488_CABCCTRL8 0xCE // CABC Control 8
#define ILI9488_CABCCTRL9 0xCF // CABC Control 9
#define ILI9488_NVMWR 0xD0 // NV Memory Write
#define ILI9488_NVMPKEY 0xD1 // NV Memory Protection Key
#define ILI9488_RDNVM 0xD2 // NV Memory Status Read
#define ILI9488_RDID4 0xD3 // Read ID4 - 0x009488
#define ILI9488_ADJCTL1 0xD7 // Adjust Control 1
#define ILI9488_RDIDV 0xD8 // Read ID Version
#define ILI9488_PGAMCTRL 0xE0 // Positive Gamma Control
#define ILI9488_NGAMCTRL 0xE1 // Negative Gamma Control
#define ILI9488_DGAMCTRL1 0xE2 // Ditigal Gamma Control 1
#define ILI9488_DGAMCTRL2 0xE3 // Ditigal Gamma Control 2
#define ILI9488_SETIMAGE 0xE9 // Set Image Function
#define ILI9488_ADJCTL2 0xF2 // Adjust Control 2
#define ILI9488_ADJCTL3 0xF7 // Adjust Control 3
#define ILI9488_ADJCTL4 0xF8 // Adjust Control 4
#define ILI9488_ADJCTL5 0xF9 // Adjust Control 5
#define ILI9488_RDEXTC 0xFB // Read EXTC command is SPI mode
#define ILI9488_ADJCTL6 0xFC // Adjust Control 6
#define ILI9488_ADJCTL7 0xFF // Adjust Control 7
static const uint16_t ili9488_init[] = {
DATASIZE_8BIT,
ESC_REG(ILI9488_SWRESET), ESC_DELAY(120),
ESC_REG(ILI9488_SLPOUT), ESC_DELAY(20),
ESC_REG(ILI9488_MADCTL), ILI9488_MADCTL_DATA,
ESC_REG(ILI9488_COLMOD), 0x0055,
/* Gamma Correction. */
ESC_REG(ILI9488_PGAMCTRL), 0x0000, 0x0003, 0x0009, 0x0008, 0x0016, 0x000A, 0x003F, 0x0078, 0x004C, 0x0009, 0x000A, 0x0008, 0x0016, 0x001A, 0x000F,
ESC_REG(ILI9488_NGAMCTRL), 0x0000, 0x0016, 0x0019, 0x0003, 0x000F, 0x0005, 0x0032, 0x0045, 0x0046, 0x0004, 0x000E, 0x000D, 0x0035, 0x0037, 0x000F,
ESC_REG(ILI9488_NORON),
ESC_REG(ILI9488_DISON),
ESC_END
};

176
src/lcd/tft_io/r65105.h Normal file
View File

@ -0,0 +1,176 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define R61505_DRVCTL_SM 0x0400
#define R61505_DRVCTL_SS 0x0100 // Select the shift direction of outputs from the source driver. 0 - from S1 to S720 / 1 - from S720 to S1
#define R61505_ETMOD_TRIGGER 0x8000 // 18-bit RAM when set; 16-bit RAM when not set
#define R61505_ETMOD_DFM 0x4000
#define R61505_ETMOD_BGR 0x1000 // RGB-BGR ORDER
#define R61505_ETMOD_RGB 0x0000
#define R61505_ETMOD_HWM 0x0020
#define R61505_ETMOD_ORG 0x0080
#define R61505_ETMOD_ID1 0x0020 // 0 - Vertical Decrement / 1 - Vertical Increment
#define R61505_ETMOD_ID0 0x0010 // 0 - Horizontal Decrement / 1 - Horizontal Increment
#define R61505_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical
#define R61505_DRVCTRL_GS 0x8000 // Gate Scan direction
// MKS Robin TFT v1.1 - 320x240 ; Cable on the left side
#if TFT_ROTATION == TFT_ROTATE_180
#define R61505_DRVCTL_DATA 0x0000
#define R61505_DRVCTRL_DATA (0x2700 | R61505_DRVCTRL_GS)
#else
#define R61505_DRVCTL_DATA R61505_DRVCTL_SS
#define R61505_DRVCTRL_DATA 0x2700
#endif
/*
#define R61505_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, R61505_ETMOD_AM) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, R61505_ETMOD_ID0) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, R61505_ETMOD_ID1)
*/
#define R61505_ETMOD_ORIENTATION (R61505_ETMOD_AM | R61505_ETMOD_ID0 | R61505_ETMOD_ID1)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
#define R61505_ETMOD_COLOR R61505_ETMOD_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define R61505_ETMOD_COLOR R61505_ETMOD_RGB
#endif
#define R61505_ETMOD_DATA (R61505_ETMOD_ORIENTATION) | (R61505_ETMOD_COLOR)
#define R61505_RDDID 0x00 // ID code - 0x1505
#define R61505_DRVCTL 0x01 // Driver Output Control
#define R61505_LCDCTL 0x02 // LCD Driving Wave Control
#define R61505_ETMOD 0x03 // Entry Mode - Control the GRAM update direction
#define R61505_RESIZECTL 0x04 // Resizing Control Register
#define R61505_DISCTRL1 0x07 // Display Control 1
#define R61505_DISCTRL2 0x08 // Display Control 2
#define R61505_DISCTRL3 0x09 // Display Control 3
#define R61505_DISCTRL4 0x0A // Display Control 4
#define R61505_RGBCTRL1 0x0C // RGB Display Interface Control 1
#define R61505_FMARKERPOS 0x0D // Frame Marker Position
#define R61505_RGBCTRL2 0x0F // RGB Display Interface Control 2
#define R61505_PWCTRL1 0x10 // Power Control 1
#define R61505_PWCTRL2 0x11 // Power Control 2
#define R61505_PWCTRL3 0x12 // Power Control 3
#define R61505_PWCTRL4 0x13 // Power Control 4
// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
#define R61505_HASET 0x20 // GRAM Horizontal Address Set (0-255)
#define R61505_VASET 0x21 // GRAM Vertical Address Set (0-511)
#define R61505_RAMWR 0x22 // Write data to GRAM
#define R61505_RAMRD 0x22 // Read Data from GRAM
#define R61505_PWCTRL7 0x29 // Power Control 7
#define R61505_GAMCTRL1 0x30 // Gamma Control
#define R61505_GAMCTRL2 0x31 // Gamma Control
#define R61505_GAMCTRL3 0x32 // Gamma Control
#define R61505_GAMCTRL4 0x35 // Gamma Control
#define R61505_GAMCTRL5 0x36 // Gamma Control
#define R61505_GAMCTRL6 0x37 // Gamma Control
#define R61505_GAMCTRL7 0x38 // Gamma Control
#define R61505_GAMCTRL8 0x39 // Gamma Control
#define R61505_GAMCTRL9 0x3C // Gamma Control
#define R61505_GAMCTRLA 0x3D // Gamma Control
// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
#define R61505_HASTART 0x50 // Horizontal Address Start Position (0-255)
#define R61505_HAEND 0x51 // Horizontal Address End Position (0-255)
#define R61505_VASTART 0x52 // Vertical Address Start Position (0-511)
#define R61505_VAEND 0x53 // Vertical Address End Position (0-511)
#define R61505_DRVCTRL 0x60 // Driver Output Control
#define R61505_BASE_IMAGE_CTRL 0x61 // Base Image Display Control
#define R61505_VSCROLL_CTRL 0x6A // Vertical Scroll Control
#define R61505_PLTPOS1 0x80 // Partial Image 1 Display Position
#define R61505_PLTSTART1 0x81 // Partial Image 1 RAM Start Address
#define R61505_PLTEND1 0x82 // Partial Image 1 RAM End Address
#define R61505_PLTPOS2 0x83 // Partial Image 2 Display Position
#define R61505_PLTSTART2 0x84 // Partial Image 2 RAM Start Address
#define R61505_PLTEND2 0x85 // Partial Image 2 RAM End Address
#define R61505_IFCTL1 0x90 // Panel Interface Control 1
#define R61505_IFCTL2 0x92 // Panel Interface Control 2
#define R61505_IFCTL3 0x93 // Panel Interface Control 3
#define R61505_IFCTL4 0x95 // Panel Interface Control 4
#define R61505_IFCTL5 0x97 // Panel Interface Control 5
#define R61505_IFCTL6 0x98 // Panel Interface Control 6
#define R61505_OSC_CTRL 0xA4 // Oscillation Control
static const uint16_t r61505_init[] = {
DATASIZE_16BIT,
ESC_REG(R61505_DRVCTL), R61505_DRVCTL_DATA,
ESC_REG(R61505_LCDCTL), 0x0700, // LCD Driving Wave Control
ESC_REG(R61505_ETMOD), R61505_ETMOD_DATA,
ESC_REG(R61505_RESIZECTL), 0x0000,
ESC_REG(R61505_DISCTRL1), 0x0173,
ESC_REG(R61505_DISCTRL2), 0x0202,
ESC_REG(R61505_DISCTRL3), 0x0000,
ESC_REG(R61505_DISCTRL4), 0x0000,
ESC_REG(R61505_RGBCTRL1), 0x0000,
ESC_REG(R61505_FMARKERPOS), 0x0000,
ESC_REG(R61505_RGBCTRL2), 0x0000,
ESC_REG(R61505_PWCTRL1), 0x17B0,
ESC_REG(R61505_PWCTRL2), 0x0037,
ESC_REG(R61505_PWCTRL3), 0x0138,
ESC_REG(R61505_PWCTRL4), 0x1700,
ESC_REG(R61505_PWCTRL7), 0x000D,
ESC_REG(R61505_GAMCTRL1), 0x0001,
ESC_REG(R61505_GAMCTRL2), 0x0606,
ESC_REG(R61505_GAMCTRL3), 0x0304,
ESC_REG(R61505_GAMCTRL4), 0x0103,
ESC_REG(R61505_GAMCTRL5), 0x011D,
ESC_REG(R61505_GAMCTRL6), 0x0404,
ESC_REG(R61505_GAMCTRL7), 0x0404,
ESC_REG(R61505_GAMCTRL8), 0x0404,
ESC_REG(R61505_GAMCTRL9), 0x0700,
ESC_REG(R61505_GAMCTRLA), 0x0A1F,
ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_DATA,
ESC_REG(R61505_BASE_IMAGE_CTRL), 0x0001,
ESC_REG(R61505_VSCROLL_CTRL), 0x0000,
ESC_REG(R61505_IFCTL1), 0x0010,
ESC_REG(R61505_IFCTL2), 0x0000,
ESC_REG(R61505_IFCTL3), 0x0003,
ESC_REG(R61505_IFCTL4), 0x0101,
ESC_REG(R61505_IFCTL5), 0x0000,
ESC_REG(R61505_IFCTL6), 0x0000,
ESC_END
};

131
src/lcd/tft_io/ssd1963.h Normal file
View File

@ -0,0 +1,131 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define SSD1963_MADCTL_MY 0x80 // Row Address Order
#define SSD1963_MADCTL_MX 0x40 // Column Address Order
#define SSD1963_MADCTL_MV 0x20 // Row/Column Exchange
#define SSD1963_MADCTL_MH 0x10 // Horizontal Refresh Order
#define SSD1963_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define SSD1963_MADCTL_RGB 0x00
#define SSD1963_MADCTL_ML 0x04 // Vertical Refresh Order
#define SSD1963_MADCTL_FH 0x02 // Flip Horizontal
#define SSD1963_MADCTL_FV 0x01 // Flip Vertical
#define SSD1963_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, SSD1963_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB
#define SSD1963_COLOR SSD1963_MADCTL_RGB
#elif TFT_COLOR == TFT_COLOR_BGR
#define SSD1963_COLOR SSD1963_MADCTL_BGR
#endif
#define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR)
#define SSD1963_NOP 0x00 // No Operation
#define SSD1963_SWRESET 0x01 // Software reset
#define SSD1963_RDDPM 0x0A // Read Display Power Mode
#define SSD1963_RDDMADCTL 0x0B // Read Display MADCTL
#define SSD1963_RDDCOLMOD 0x0C // Read Display Pixel Format
#define SSD1963_RDDIM 0x0D // Read Display Image Mode
#define SSD1963_RDDSM 0x0E // Read Display Signal Mode
#define SSD1963_SLPIN 0x10 // Sleep In
#define SSD1963_SLPOUT 0x11 // Sleep Out
#define SSD1963_PTLON 0x12 // Partial Display Mode On
#define SSD1963_NORON 0x13 // Normal Display Mode On
#define SSD1963_INVOFF 0x20 // Display Inversion Off
#define SSD1963_INVON 0x21 // Display Inversion On
#define SSD1963_GAMSET 0x26 // Gamma Set
#define SSD1963_DISPOFF 0x28 // Display Off
#define SSD1963_DISPON 0x29 // Display On
#define SSD1963_CASET 0x2A // Column Address Set
#define SSD1963_RASET 0x2B // Row Address Set
#define SSD1963_RAMWR 0x2C // Memory Write
#define SSD1963_RAMRD 0x2E // Memory Read
#define SSD1963_PTLAR 0x30 // Partial Area
#define SSD1963_VSCRDEF 0x33 // Vertical Scrolling Definition
#define SSD1963_TEOFF 0x34 // Tearing Effect Line OFF
#define SSD1963_TEON 0x35 // Tearing Effect Line ON
#define SSD1963_MADCTL 0x36 // Memory Data Access Control
#define SSD1963_VSCSAD 0x37 // Vertical Scroll Start Address of RAM
#define SSD1963_IDMOFF 0x38 // Idle Mode Off
#define SSD1963_IDMON 0x39 // Idle Mode On
#define SSD1963_WRMEMC 0x3C // Write Memory Continue
#define SSD1963_RDMEMC 0x3E // Read Memory Continue
#define SSD1963_STE 0x44 // Set Tear Scanline
#define SSD1963_GSCAN 0x45 // Get Scanline
#define SSD1963_WRDISBV 0x51 // Write Display Brightness
#define SSD1963_RDDISBV 0x52 // Read Display Brightness
#define SSD1963_WRCTRLD 0x53 // Write CTRL Display
#define SSD1963_RDCTRLD 0x54 // Read CTRL Value Display
#define SSD1963_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement
#define SSD1963_RDCABC 0x56 // Read Content Adaptive Brightness Control
#define SSD1963_WRCABCMB 0x5E // Write CABC Minimum Brightness
#define SSD1963_RDCABCMB 0x5F // Read CABC Minimum Brightness
#define SSD1963_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result
#define SSD1963_RDDDB 0xA1 // Read Device Descriptor Block
#define SSD1963_SLCDMODE 0xB0 // Set the LCD panel mode and resolution
#define SSD1963_SHSYNC 0xB4 // Set HSYNC
#define SSD1963_GHSYNC 0xB5 // Get HSYNC
#define SSD1963_SVSYNC 0xB6 // Set VSYNC
#define SSD1963_GVSYNC 0xB7 // Get VSYNC
#define SSD1963_SGPIOCFG 0xB8 // Set GPIO Conf
#define SSD1963_SGPIOV 0xBA // Set GPIO Value
#define SSD1963_SPWMCFG 0xBE // Set PWM Conf
#define SSD1963_GPWMCFG 0xBF // Get PWM Conf
#define SSD1963_SDBCCFG 0xD0 // Set Dynamic Back Light Config
#define SSD1963_GDBCCFG 0xD1 // Get Dynamic Back Light Config
#define SSD1963_PLLON 0xE0 // PLL Enable
#define SSD1963_PLLMN 0xE2 // Set PLL Multiplier
#define SSD1963_SLSHIFT 0xE6 // Set the LSHIFT (pixel clock) frequency
#define SSD1963_COLMOD 0xF0 // Interface Pixel Format
static const uint16_t ssd1963_init[] = {
DATASIZE_8BIT,
ESC_REG(SSD1963_PLLMN), 0x0023, 0x0002, 0x0054,
ESC_REG(SSD1963_PLLON), 0x0001, ESC_DELAY(10),
ESC_REG(SSD1963_PLLON), 0x0003, ESC_DELAY(10),
ESC_REG(SSD1963_SWRESET), ESC_DELAY(100),
ESC_REG(SSD1963_SLSHIFT), 0x0001, 0x001F, 0x00FF,
ESC_REG(SSD1963_SLCDMODE), 0x0020, 0x0000, 0x0001, 0x00DF, 0x0001, 0x000F, 0x0000,
ESC_REG(SSD1963_SHSYNC), 0x0002, 0x0013, 0x0000, 0x0008, 0x002B, 0x0000, 0x0002, 0x0000,
ESC_REG(SSD1963_SVSYNC), 0x0001, 0x0020, 0x0000, 0x0004, 0x000C, 0x0000, 0x0002,
ESC_REG(SSD1963_SGPIOV), 0x000F,
ESC_REG(SSD1963_SGPIOCFG), 0x0007, 0x0001,
ESC_REG(SSD1963_MADCTL), SSD1963_MADCTL_DATA,
ESC_REG(SSD1963_COLMOD), 0x0003, ESC_DELAY(1),//RBG 565
ESC_REG(SSD1963_NORON),
ESC_REG(SSD1963_DISPON),
ESC_REG(SSD1963_SPWMCFG), 0x0006, 0x00F0, 0x0001, 0x00F0, 0x0000, 0x0000,
ESC_REG(SSD1963_SDBCCFG), 0x000D,
ESC_END
};

136
src/lcd/tft_io/st7735.h Normal file
View File

@ -0,0 +1,136 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ST7735_MADCTL_MY 0x80 // Row Address Order
#define ST7735_MADCTL_MX 0x40 // Column Address Order
#define ST7735_MADCTL_MV 0x20 // Row/Column Exchange
#define ST7735_MADCTL_ML 0x10 // Vertical Refresh Order
#define ST7735_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define ST7735_MADCTL_RGB 0x00
#define ST7735_MADCTL_MH 0x04 // Horizontal Refresh Order
#define ST7735_ORIENTATION_UP 0x00 // 128x160 ; Cable on the upper side
#define ST7735_ORIENTATION_RIGHT ST7735_MADCTL_MV | ST7735_MADCTL_MY // 160x128 ; Cable on the right side
#define ST7735_ORIENTATION_LEFT ST7735_MADCTL_MV | ST7735_MADCTL_MX // 160x128 ; Cable on the left side
#define ST7735_ORIENTATION_DOWN ST7735_MADCTL_MX | ST7735_MADCTL_MY // 128x160 ; Cable on the lower side
#define ST7735_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7735_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7735_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7735_MADCTL_MY)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB
#define ST7735_COLOR ST7735_MADCTL_RGB
#elif TFT_COLOR == TFT_COLOR_BGR
#define ST7735_COLOR ST7735_MADCTL_BGR
#endif
#define ST7735_MADCTL_DATA (ST7735_ORIENTATION) | (ST7735_COLOR)
#define ST7735_NOP 0x00 // No Operation
#define ST7735_SWRESET 0x01 // Software reset
#define ST7735_RDDID 0x04 // Read Display ID
#define ST7735_RDDST 0x09 // Read Display Status
#define ST7735_RDDPM 0x0A // Read Display Power Mode
#define ST7735_RDDMADCTL 0x0B // Read Display MADCTL
#define ST7735_RDDCOLMOD 0x0C // Read Display Pixel Format
#define ST7735_RDDIM 0x0D // Read Display Image Mode
#define ST7735_RDDSM 0x0E // Read Display Signal Mode
#define ST7735_SLPIN 0x10 // Sleep In
#define ST7735_SLPOUT 0x11 // Sleep Out
#define ST7735_PTLON 0x12 // Partial Display Mode On
#define ST7735_NORON 0x13 // Normal Display Mode On
#define ST7735_INVOFF 0x20 // Display Inversion Off
#define ST7735_INVON 0x21 // Display Inversion On
#define ST7735_GAMSET 0x26 // Gamma Set
#define ST7735_DISPOFF 0x28 // Display Off // The delay time between DISPON and DISPOFF needs 120ms at least.
#define ST7735_DISPON 0x29 // Display On
#define ST7735_CASET 0x2A // Column Address Set
#define ST7735_RASET 0x2B // Row Address Set
#define ST7735_RAMWR 0x2C // Memory Write
#define ST7735_RAMRD 0x2E // Memory Read
#define ST7735_PTLAR 0x30 // Partial Area
#define ST7735_TEOFF 0x34 // Tearing Effect Line OFF
#define ST7735_TEON 0x35 // Tearing Effect Line ON
#define ST7735_MADCTL 0x36 // Memory Data Access Control
#define ST7735_IDMOFF 0x38 // Idle Mode Off
#define ST7735_IDMON 0x39 // Idle Mode On
#define ST7735_COLMOD 0x3A // Interface Pixel Format
#define ST7735_RDID1 0xDA // Read ID1 Value
#define ST7735_RDID2 0xDB // Read ID2 Value
#define ST7735_RDID3 0xDC // Read ID3 Value
#define ST7735_FRMCTR1 0xB1 // Frame Rate Control (In normal mode/ Full colors)
#define ST7735_FRMCTR2 0xB2 // Frame Rate Control (In Idle mode/ 8-colors)
#define ST7735_FRMCTR3 0xB3 // Frame Rate Control (In Partial mode/ full colors)
#define ST7735_INVCTR 0xB4 // Display Inversion Control
#define ST7735_DISSET5 0xB6 // Display Function set 5
#define ST7735_PWCTR1 0xC0 // Power Control 1
#define ST7735_PWCTR2 0xC1 // Power Control 2
#define ST7735_PWCTR3 0xC2 // Power Control 3 (in Normal mode/ Full colors)
#define ST7735_PWCTR4 0xC3 // Power Control 4 (in Idle mode/ 8-colors)
#define ST7735_PWCTR5 0xC4 // Power Control 5 (in Partial mode/ full-colors)
#define ST7735_VMCTR1 0xC5 // VCOM Control 1
#define ST7735_VMOFCTR 0xC7 // VCOM Offset Control
#define ST7735_WRID2 0xD1 // Write ID2 Value
#define ST7735_WRID3 0xD2 // Write ID3 Value
#define ST7735_PWCTR6 0xFC // Power Control 5 (in Partial mode + Idle mode)
#define ST7735_NVFCTR1 0xD9 // EEPROM Control Status
#define ST7735_NVFCTR2 0xDE // EEPROM Read Command
#define ST7735_NVFCTR3 0xDF // EEPROM Write Command
#define ST7735_GMCTRP1 0xE0 // Gamma (+polarity) Correction Characteristics Setting
#define ST7735_GMCTRN1 0xE1 // GMCTRN1 (E1h): Gamma -polarity Correction Characteristics Setting
#define ST7735_EXTCTRL 0xF0 // Extension Command Control
#define ST7735_VCOM4L 0xFF // Vcom 4 Level Control
static const uint16_t st7735_init[] = {
DATASIZE_8BIT,
ESC_REG(ST7735_SWRESET), ESC_DELAY(100),
ESC_REG(ST7735_SLPOUT), ESC_DELAY(20),
/*
ESC_REG(ST7735_FRMCTR1), 0x0001, 0x002C, 0x002D,
ESC_REG(ST7735_FRMCTR2), 0x0001, 0x002C, 0x002D,
ESC_REG(ST7735_FRMCTR3), 0x0001, 0x002C, 0x002D, 0x0001, 0x002C, 0x002D,
ESC_REG(ST7735_INVCTR), 0x0007,
ESC_REG(ST7735_PWCTR1), 0x00A2, 0x0002, 0x0084,
ESC_REG(ST7735_PWCTR2), 0x00C5,
ESC_REG(ST7735_PWCTR3), 0x000A, 0x0000,
ESC_REG(ST7735_PWCTR4), 0x008A, 0x002A,
ESC_REG(ST7735_PWCTR5), 0x008A, 0x00EE,
ESC_REG(ST7735_VMCTR1), 0x000E,
ESC_REG(ST7735_INVOFF),
*/
ESC_REG(ST7735_MADCTL), ST7735_MADCTL_DATA,
ESC_REG(ST7735_COLMOD), 0x0005,
/* Gamma Correction. Colors with 'after-reset' settings are bleak */
ESC_REG(ST7735_GMCTRP1), 0x0002, 0x001C, 0x0007, 0x0012, 0x0037, 0x0032, 0x0029, 0x002D, 0x0029, 0x0025, 0x002B, 0x0039, 0x0000, 0x0001, 0x0003, 0x0010,
ESC_REG(ST7735_GMCTRN1), 0x0003, 0x001D, 0x0007, 0x0006, 0x002E, 0x002C, 0x0029, 0x002D, 0x002E, 0x002E, 0x0037, 0x003F, 0x0000, 0x0000, 0x0002, 0x0010,
ESC_REG(ST7735_NORON),
ESC_REG(ST7735_DISPON),
ESC_END
};

156
src/lcd/tft_io/st7789v.h Normal file
View File

@ -0,0 +1,156 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ST7789V_MADCTL_MY 0x80 // Row Address Order
#define ST7789V_MADCTL_MX 0x40 // Column Address Order
#define ST7789V_MADCTL_MV 0x20 // Row/Column Exchange
#define ST7789V_MADCTL_ML 0x10 // Vertical Refresh Order
#define ST7789V_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define ST7789V_MADCTL_RGB 0x00
#define ST7789V_MADCTL_MH 0x04 // Horizontal Refresh Order
#define ST7789V_ORIENTATION_UP ST7789V_MADCTL_MX | ST7789V_MADCTL_MY // 240x320 ; Cable on the upper side
#define ST7789V_ORIENTATION_RIGHT ST7789V_MADCTL_MX | ST7789V_MADCTL_MV // 320x240 ; Cable on the right side
#define ST7789V_ORIENTATION_LEFT ST7789V_MADCTL_MY | ST7789V_MADCTL_MV // 320x240 ; Cable on the left side
#define ST7789V_ORIENTATION_DOWN 0 // 240x320 ; Cable on the lower side
#define ST7789V_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7789V_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7789V_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7789V_MADCTL_MY)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB
#define ST7789V_COLOR ST7789V_MADCTL_RGB
#elif TFT_COLOR == TFT_COLOR_BGR
#define ST7789V_COLOR ST7789V_MADCTL_BGR
#endif
#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION) | (ST7789V_COLOR)
#define ST7789V_NOP 0x00 // No Operation
#define ST7789V_SWRESET 0x01 // Software reset
#define ST7789V_RDDID 0x04 // Read Display ID
#define ST7789V_RDDST 0x09 // Read Display Status
#define ST7789V_RDDPM 0x0A // Read Display Power Mode
#define ST7789V_RDDMADCTL 0x0B // Read Display MADCTL
#define ST7789V_RDDCOLMOD 0x0C // Read Display Pixel Format
#define ST7789V_RDDIM 0x0D // Read Display Image Mode
#define ST7789V_RDDSM 0x0E // Read Display Signal Mode
#define ST7789V_RDDSDR 0x0F // Read Display Self-Diagnostic Result
#define ST7789V_SLPIN 0x10 // Sleep In
#define ST7789V_SLPOUT 0x11 // Sleep Out
#define ST7789V_PTLON 0x12 // Partial Display Mode On
#define ST7789V_NORON 0x13 // Normal Display Mode On
#define ST7789V_INVOFF 0x20 // Display Inversion Off
#define ST7789V_INVON 0x21 // Display Inversion On
#define ST7789V_GAMSET 0x26 // Gamma Set
#define ST7789V_DISPOFF 0x28 // Display Off
#define ST7789V_DISPON 0x29 // Display On
#define ST7789V_CASET 0x2A // Column Address Set
#define ST7789V_RASET 0x2B // Row Address Set
#define ST7789V_RAMWR 0x2C // Memory Write
#define ST7789V_RAMRD 0x2E // Memory Read
#define ST7789V_PTLAR 0x30 // Partial Area
#define ST7789V_VSCRDEF 0x33 // Vertical Scrolling Definition
#define ST7789V_TEOFF 0x34 // Tearing Effect Line OFF
#define ST7789V_TEON 0x35 // Tearing Effect Line ON
#define ST7789V_MADCTL 0x36 // Memory Data Access Control
#define ST7789V_VSCSAD 0x37 // Vertical Scroll Start Address of RAM
#define ST7789V_IDMOFF 0x38 // Idle Mode Off
#define ST7789V_IDMON 0x39 // Idle Mode On
#define ST7789V_COLMOD 0x3A // Interface Pixel Format
#define ST7789V_WRMEMC 0x3C // Write Memory Continue
#define ST7789V_RDMEMC 0x3E // Read Memory Continue
#define ST7789V_STE 0x44 // Set Tear Scanline
#define ST7789V_GSCAN 0x45 // Get Scanline
#define ST7789V_WRDISBV 0x51 // Write Display Brightness
#define ST7789V_RDDISBV 0x52 // Read Display Brightness
#define ST7789V_WRCTRLD 0x53 // Write CTRL Display
#define ST7789V_RDCTRLD 0x54 // Read CTRL Value Display
#define ST7789V_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement
#define ST7789V_RDCABC 0x56 // Read Content Adaptive Brightness Control
#define ST7789V_WRCABCMB 0x5E // Write CABC Minimum Brightness
#define ST7789V_RDCABCMB 0x5F // Read CABC Minimum Brightness
#define ST7789V_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result
#define ST7789V_RDID1 0xDA // Read ID1 Value
#define ST7789V_RDID2 0xDB // Read ID2 Value
#define ST7789V_RDID3 0xDC // Read ID3 Value
#define ST7789V_RAMCTRL 0xB0 // RAM Control
#define ST7789V_RGBCTRL 0xB1 // RGB Interface Control
#define ST7789V_PORCTRL 0xB2 // Porch Setting
#define ST7789V_FRCTRL1 0xB3 // Frame Rate Control 1 (In partial mode/ idle colors)
#define ST7789V_GCTRL 0xB7 // Gate Control
#define ST7789V_DGMEN 0xBA // Digital Gamma Enable
#define ST7789V_VCOMS 0xBB // VCOM Setting
#define ST7789V_LCMCTRL 0xC0 // LCM Control
#define ST7789V_IDSET 0xC1 // ID Code Setting
#define ST7789V_VDVVRHEN 0xC2 // VDV and VRH Command Enable
#define ST7789V_VRHS 0xC3 // VRH Set
#define ST7789V_VDVS 0xC4 // VDV Set
#define ST7789V_VCMOFSET 0xC5 // VCOM Offset Set
#define ST7789V_FRCTRL2 0xC6 // Frame Rate Control in Normal Mode
#define ST7789V_CABCCTRL 0xC7 // CABC Control
#define ST7789V_REGSEL1 0xC8 // Register Value Selection 1
#define ST7789V_REGSEL2 0xCA // Register Value Selection 2
#define ST7789V_PWMFRSEL 0xCC // PWM Frequency Selection
#define ST7789V_PWCTRL1 0xD0 // Power Control 1
#define ST7789V_VAPVANEN 0xD2 // Enable VAP/VAN signal output
#define ST7789V_CMD2EN 0xDF // Command 2 Enable
#define ST7789V_PVGAMCTRL 0xE0 // Positive Voltage Gamma Control
#define ST7789V_NVGAMCTRL 0xE1 // Negative Voltage Gamma Control
#define ST7789V_DGMLUTR 0xE2 // Digital Gamma Look-up Table for Red
#define ST7789V_DGMLUTB 0xE3 // Digital Gamma Look-up Table for Blue
#define ST7789V_GATECTRL 0xE4 // Gate Control
#define ST7789V_SPI2EN 0xE7 // SPI2 Enable
#define ST7789V_PWCTRL2 0xE8 // Power Control 2
#define ST7789V_EQCTRL 0xE9 // Equalize time control
#define ST7789V_PROMCTRL 0xEC // Program Mode Control
#define ST7789V_PROMEN 0xFA // Program Mode Enable
#define ST7789V_NVMSET 0xFC // NVM Setting
#define ST7789V_PROMACT 0xFE // Program action
static const uint16_t st7789v_init[] = {
DATASIZE_8BIT,
ESC_REG(ST7789V_SWRESET), ESC_DELAY(100),
ESC_REG(ST7789V_SLPOUT), ESC_DELAY(20),
ESC_REG(ST7789V_PORCTRL), 0x000C, 0x000C, 0x0000, 0x0033, 0x0033,
ESC_REG(ST7789V_GCTRL), 0x0035,
ESC_REG(ST7789V_VCOMS), 0x001F,
ESC_REG(ST7789V_LCMCTRL), 0x002C,
ESC_REG(ST7789V_VDVVRHEN), 0x0001, 0x00C3,
ESC_REG(ST7789V_VDVS), 0x0020,
ESC_REG(ST7789V_FRCTRL2), 0x000F,
ESC_REG(ST7789V_PWCTRL1), 0x00A4, 0x00A1,
ESC_REG(ST7789V_MADCTL), ST7789V_MADCTL_DATA,
ESC_REG(ST7789V_COLMOD), 0x0055,
ESC_REG(ST7789V_NORON),
ESC_REG(ST7789V_DISPON),
ESC_END
};

157
src/lcd/tft_io/st7796s.h Normal file
View File

@ -0,0 +1,157 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#define ST7796S_MADCTL_MY 0x80 // Row Address Order
#define ST7796S_MADCTL_MX 0x40 // Column Address Order
#define ST7796S_MADCTL_MV 0x20 // Row/Column Exchange
#define ST7796S_MADCTL_ML 0x10 // Vertical Refresh Order
#define ST7796S_MADCTL_BGR 0x08 // RGB-BGR ORDER
#define ST7796S_MADCTL_RGB 0x00
#define ST7796S_MADCTL_MH 0x04 // Horizontal Refresh Order
#define ST7796S_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7796S_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7796S_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7796S_MADCTL_MY)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
#define ST7796S_COLOR ST7796S_MADCTL_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define ST7796S_COLOR ST7796S_MADCTL_RGB
#endif
#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION) | (ST7796S_COLOR)
#define ST7796S_NOP 0x00 // No Operation
#define ST7796S_SWRESET 0x01 // Software reset
#define ST7796S_RDDID 0x04 // Read Display ID
#define ST7796S_RDNUMED 0x05 // Read Number of the Errors on DSI
#define ST7796S_RDDST 0x09 // Read Display Status
#define ST7796S_RDDPM 0x0A // Read Display Power Mode
#define ST7796S_RDDMADCTL 0x0B // Read Display MADCTL
#define ST7796S_RDDCOLMOD 0x0C // Read Display Pixel Format
#define ST7796S_RDDIM 0x0D // Read Display Image Mode
#define ST7796S_RDDSM 0x0E // Read Display Signal Status
#define ST7796S_RDDSDR 0x0F // Read Display Self-Diagnostic Result
#define ST7796S_SLPIN 0x10 // Sleep In
#define ST7796S_SLPOUT 0x11 // Sleep Out
#define ST7796S_PTLON 0x12 // Partial Display Mode On
#define ST7796S_NORON 0x13 // Normal Display Mode On
#define ST7796S_INVOFF 0x20 // Display Inversion Off
#define ST7796S_INVON 0x21 // Display Inversion On
#define ST7796S_DISPOFF 0x28 // Display Off
#define ST7796S_DISPON 0x29 // Display On
#define ST7796S_CASET 0x2A // Column Address Set
#define ST7796S_RASET 0x2B // Row Address Set
#define ST7796S_RAMWR 0x2C // Memory Write
#define ST7796S_RAMRD 0x2E // Memory Read
#define ST7796S_PTLAR 0x30 // Partial Area
#define ST7796S_VSCRDEF 0x33 // Vertical Scrolling Definition
#define ST7796S_TEOFF 0x34 // Tearing Effect Line OFF
#define ST7796S_TEON 0x35 // Tearing Effect Line On
#define ST7796S_MADCTL 0x36 // Memory Data Access Control
#define ST7796S_VSCSAD 0x37 // Vertical Scroll Start Address of RAM
#define ST7796S_IDMOFF 0x38 // Idle Mode Off
#define ST7796S_IDMON 0x39 // Idle Mode On
#define ST7796S_COLMOD 0x3A // Interface Pixel Format
#define ST7796S_WRMEMC 0x3C // Write Memory Continue
#define ST7796S_RDMEMC 0x3E // Read Memory Continue
#define ST7796S_STE 0x44 // Set Tear ScanLine
#define ST7796S_GSCAN 0x45 // Get ScanLine
#define ST7796S_WRDISBV 0x51 // Write Display Brightness
#define ST7796S_RDDISBV 0x52 // Read Display Brightness Value
#define ST7796S_WRCTRLD 0x53 // Write CTRL Display
#define ST7796S_RDCTRLD 0x54 // Read CTRL value Display
#define ST7796S_WRCABC 0x55 // Write Adaptive Brightness Control
#define ST7796S_RDCABC 0x56 // Read Content Adaptive Brightness Control
#define ST7796S_WRCABCMB 0x5E // Write CABC Minimum Brightness
#define ST7796S_RDCABCMB 0x5F // Read CABC Minimum Brightness
#define ST7796S_RDFCS 0xAA // Read First Checksum
#define ST7796S_RDCFCS 0xAF // Read Continue Checksum
#define ST7796S_RDID1 0xDA // Read ID1
#define ST7796S_RDID2 0xDB // Read ID2
#define ST7796S_RDID3 0xDC // Read ID3
#define ST7796S_IFMODE 0xB0 // Interface Mode Control
#define ST7796S_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors)
#define ST7796S_FRMCTR2 0xB2 // Frame Rate Control 2 (In Idle Mode/8 colors)
#define ST7796S_FRMCTR3 0xB3 // Frame Rate Control 3(In Partial Mode/Full Colors)
#define ST7796S_DIC 0xB4 // Display Inversion Control
#define ST7796S_BPC 0xB5 // Blanking Porch Control
#define ST7796S_DFC 0xB6 // Display Function Control
#define ST7796S_EM 0xB7 // Entry Mode Set
#define ST7796S_PWR1 0xC0 // Power Control 1
#define ST7796S_PWR2 0xC1 // Power Control 2
#define ST7796S_PWR3 0xC2 // Power Control 3
#define ST7796S_VCMPCTL 0xC5 // VCOM Control
#define ST7796S_VCMOST 0xC6 // VCOM Offset Register
#define ST7796S_NVMADW 0xD0 // NVM Address/Data Write
#define ST7796S_NVMBPROG 0xD1 // NVM Byte Program
#define ST7796S_NVMSTRD 0xD2 // NVM Status Read
#define ST7796S_RDID4 0xD3 // Read ID4
#define ST7796S_PGC 0xE0 // Positive Gamma Control
#define ST7796S_NGC 0xE1 // Negative Gamma Control
#define ST7796S_DGC1 0xE2 // Digital Gamma Control 1
#define ST7796S_DGC2 0xE3 // Digital Gamma Control 2
#define ST7796S_DOCA 0xE8 // Display Output Ctrl Adjust
#define ST7796S_CSCON 0xF0 // Command Set Control
#define ST7796S_SPIRC 0xFB // SPI Read Control
static const uint16_t st7796s_init[] = {
DATASIZE_8BIT,
ESC_REG(ST7796S_SWRESET), ESC_DELAY(100),
ESC_REG(ST7796S_SLPOUT), ESC_DELAY(20),
ESC_REG(ST7796S_CSCON), 0x00C3, // enable command 2 part I
ESC_REG(ST7796S_CSCON), 0x0096, // enable command 2 part II
ESC_REG(ST7796S_MADCTL), ST7796S_MADCTL_DATA,
ESC_REG(ST7796S_COLMOD), 0x0055,
ESC_REG(ST7796S_DIC), 0x0001, // 1-dot inversion
ESC_REG(ST7796S_EM), 0x00C6,
ESC_REG(ST7796S_PWR2), 0x0015,
ESC_REG(ST7796S_PWR3), 0x00AF,
ESC_REG(ST7796S_VCMPCTL), 0x0022,
ESC_REG(ST7796S_VCMOST), 0x0000,
ESC_REG(ST7796S_DOCA), 0x0040, 0x008A, 0x0000, 0x0000, 0x0029, 0x0019, 0x00A5, 0x0033,
/* Gamma Correction. */
ESC_REG(ST7796S_PGC), 0x00F0, 0x0004, 0x0008, 0x0009, 0x0008, 0x0015, 0x002F, 0x0042, 0x0046, 0x0028, 0x0015, 0x0016, 0x0029, 0x002D,
ESC_REG(ST7796S_NGC), 0x00F0, 0x0004, 0x0009, 0x0009, 0x0008, 0x0015, 0x002E, 0x0046, 0x0046, 0x0028, 0x0015, 0x0015, 0x0029, 0x002D,
#if ENABLED(ST7796S_INVERTED)
ESC_REG(ST7796S_INVON), // Display inversion ON
#else
ESC_REG(ST7796S_NORON),
#endif
ESC_REG(ST7796S_WRCTRLD), 0x0024,
ESC_REG(ST7796S_CSCON), 0x003C, // disable command 2 part I
ESC_REG(ST7796S_CSCON), 0x0069, // disable command 2 part II
ESC_REG(ST7796S_DISPON),
ESC_END
};

34
src/lcd/tft_io/tft_ids.h Normal file
View File

@ -0,0 +1,34 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#define LTDC_RGB 0xABAB
#define SSD1963 0x5761
#define ST7735 0x89F0
#define ST7789 0x8552
#define ST7796 0x7796
#define R61505 0x1505
#define ILI9328 0x9328
#define ILI9341 0x9341
#define ILI9488 0x9488
#define ILI9488_ID1 0x8066 // Some ILI9488 have 0x8066 in the 0x04
#define AUTO 0xFFFF

258
src/lcd/tft_io/tft_io.cpp Normal file
View File

@ -0,0 +1,258 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfigPre.h"
#if HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT
#include "tft_io.h"
#include "tft_ids.h"
#if TFT_DRIVER == ST7735 || TFT_DRIVER == AUTO
#include "st7735.h"
#endif
#if TFT_DRIVER == ST7789 || TFT_DRIVER == AUTO
#include "st7789v.h"
#endif
#if TFT_DRIVER == ST7796 || TFT_DRIVER == AUTO
#include "st7796s.h"
#endif
#if TFT_DRIVER == R61505 || TFT_DRIVER == AUTO
#include "r65105.h"
#endif
#if TFT_DRIVER == ILI9488 || TFT_DRIVER == ILI9488_ID1 || TFT_DRIVER == AUTO
#include "ili9488.h"
#endif
#if TFT_DRIVER == SSD1963 || TFT_DRIVER == AUTO
#include "ssd1963.h"
#endif
#include "ili9341.h"
#include "ili9328.h"
#if HAS_LCD_BRIGHTNESS
#include "../marlinui.h"
#endif
#define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
#include "../../core/debug_out.h"
TFT_IO_DRIVER TFT_IO::io;
uint32_t TFT_IO::lcd_id = 0xFFFFFFFF;
void TFT_IO::InitTFT() {
if (lcd_id != 0xFFFFFFFF) return;
#if PIN_EXISTS(TFT_BACKLIGHT)
OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
#endif
#if PIN_EXISTS(TFT_RESET)
OUT_WRITE(TFT_RESET_PIN, HIGH);
delay(10);
WRITE(TFT_RESET_PIN, LOW);
delay(10);
WRITE(TFT_RESET_PIN, HIGH);
#endif
#if PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
#if HAS_LCD_BRIGHTNESS && DISABLED(DELAYED_BACKLIGHT_INIT)
ui._set_brightness();
#endif
#endif
// io.Init();
delay(100);
#if TFT_DRIVER != AUTO
lcd_id = TFT_DRIVER;
#endif
#if TFT_DRIVER == ST7735
write_esc_sequence(st7735_init);
#elif TFT_DRIVER == SSD1963
write_esc_sequence(ssd1963_init);
#elif TFT_DRIVER == ST7789
write_esc_sequence(st7789v_init);
#elif TFT_DRIVER == ST7796
write_esc_sequence(st7796s_init);
#elif TFT_DRIVER == R61505
write_esc_sequence(r61505_init);
#elif TFT_DRIVER == ILI9328
write_esc_sequence(ili9328_init);
#elif TFT_DRIVER == ILI9341
write_esc_sequence(ili9341_init);
#elif TFT_DRIVER == ILI9488
write_esc_sequence(ili9488_init);
#elif TFT_DRIVER == AUTO // autodetect
lcd_id = io.GetID() & 0xFFFF;
switch (lcd_id) {
case LTDC_RGB:
break;
case ST7796: // ST7796S 480x320
DEBUG_ECHO_MSG(" ST7796S");
write_esc_sequence(st7796s_init);
break;
case ST7789: // ST7789V 320x240
DEBUG_ECHO_MSG(" ST7789V");
write_esc_sequence(st7789v_init);
break;
case SSD1963: // SSD1963
DEBUG_ECHO_MSG(" SSD1963");
write_esc_sequence(ssd1963_init);
break;
case ST7735: // ST7735 160x128
DEBUG_ECHO_MSG(" ST7735");
write_esc_sequence(st7735_init);
break;
case R61505: // R61505U 320x240
DEBUG_ECHO_MSG(" R61505U");
write_esc_sequence(r61505_init);
break;
case ILI9328: // ILI9328 320x240
DEBUG_ECHO_MSG(" ILI9328");
write_esc_sequence(ili9328_init);
break;
case ILI9341: // ILI9341 320x240
DEBUG_ECHO_MSG(" ILI9341");
write_esc_sequence(ili9341_init);
break;
case ILI9488: // ILI9488 480x320
case ILI9488_ID1: // 0x8066 ILI9488 480x320
DEBUG_ECHO_MSG(" ILI9488");
write_esc_sequence(ili9488_init);
break;
default:
lcd_id = 0;
}
#else
#error "Unsupported TFT driver"
#endif
#if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
TERN(HAS_LCD_BRIGHTNESS, ui._set_brightness(), WRITE(TFT_BACKLIGHT_PIN, HIGH));
#endif
}
void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
#ifdef OFFSET_X
Xmin += OFFSET_X; Xmax += OFFSET_X;
#endif
#ifdef OFFSET_Y
Ymin += OFFSET_Y; Ymax += OFFSET_Y;
#endif
switch (lcd_id) {
case LTDC_RGB:
io.WriteReg(0x01);
io.WriteData(Xmin);
io.WriteReg(0x02);
io.WriteData(Xmax);
io.WriteReg(0x03);
io.WriteData(Ymin);
io.WriteReg(0x04);
io.WriteData(Ymax);
io.WriteReg(0x00);
break;
case ST7735: // ST7735 160x128
case ST7789: // ST7789V 320x240
case ST7796: // ST7796 480x320
case ILI9341: // ILI9341 320x240
case ILI9488: // ILI9488 480x320
case SSD1963: // SSD1963
case ILI9488_ID1: // 0x8066 ILI9488 480x320
io.DataTransferBegin(DATASIZE_8BIT);
// CASET: Column Address Set
io.WriteReg(ILI9341_CASET);
io.WriteData((Xmin >> 8) & 0xFF);
io.WriteData(Xmin & 0xFF);
io.WriteData((Xmax >> 8) & 0xFF);
io.WriteData(Xmax & 0xFF);
// RASET: Row Address Set
io.WriteReg(ILI9341_PASET);
io.WriteData((Ymin >> 8) & 0xFF);
io.WriteData(Ymin & 0xFF);
io.WriteData((Ymax >> 8) & 0xFF);
io.WriteData(Ymax & 0xFF);
// RAMWR: Memory Write
io.WriteReg(ILI9341_RAMWR);
break;
case R61505: // R61505U 320x240
case ILI9328: // ILI9328 320x240
io.DataTransferBegin(DATASIZE_16BIT);
// Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
io.WriteReg(ILI9328_HASTART);
io.WriteData(Ymin);
io.WriteReg(ILI9328_HAEND);
io.WriteData(Ymax);
io.WriteReg(ILI9328_VASTART);
io.WriteData(Xmin);
io.WriteReg(ILI9328_VAEND);
io.WriteData(Xmax);
io.WriteReg(ILI9328_HASET);
io.WriteData(Ymin);
io.WriteReg(ILI9328_VASET);
io.WriteData(Xmin);
io.WriteReg(ILI9328_RAMWR);
break;
default:
break;
}
io.DataTransferEnd();
}
void TFT_IO::write_esc_sequence(const uint16_t *Sequence) {
uint16_t dataWidth, data;
dataWidth = *Sequence++;
io.DataTransferBegin(dataWidth);
for (;;) {
data = *Sequence++;
if (data != 0xFFFF) {
io.WriteData(data);
continue;
}
data = *Sequence++;
if (data == 0x7FFF) return;
if (data == 0xFFFF)
io.WriteData(0xFFFF);
else if (data & 0x8000)
delay(data & 0x7FFF);
else if ((data & 0xFF00) == 0)
io.WriteReg(data);
}
io.DataTransferEnd();
}
#endif // HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT

134
src/lcd/tft_io/tft_io.h Normal file
View File

@ -0,0 +1,134 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../../inc/MarlinConfig.h"
#if HAS_SPI_TFT
#include HAL_PATH(../../HAL, tft/tft_spi.h)
#elif HAS_FSMC_TFT
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
#elif HAS_LTDC_TFT
#include HAL_PATH(../../HAL, tft/tft_ltdc.h)
#else
#error "TFT IO only supports SPI, FSMC or LTDC interface"
#endif
#define TFT_EXCHANGE_XY _BV32(1)
#define TFT_INVERT_X _BV32(2)
#define TFT_INVERT_Y _BV32(3)
#define TFT_NO_ROTATION (0x00)
#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X)
#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_MIRROR_X (TFT_INVERT_Y)
#define TFT_MIRROR_Y (TFT_INVERT_X)
#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_INVERT_Y)
#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_INVERT_X)
#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_INVERT_Y)
#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_INVERT_X)
#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_INVERT_Y)
#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_INVERT_X)
// TFT_ROTATION is user configurable
#ifndef TFT_ROTATION
#define TFT_ROTATION TFT_NO_ROTATION
#endif
// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))
#define TFT_COLOR_RGB _BV32(3)
#define TFT_COLOR_BGR _BV32(4)
// Each TFT Driver is responsible for its default color mode.
// #ifndef TFT_COLOR
// #define TFT_COLOR TFT_COLOR_RGB
// #endif
#define TOUCH_ORIENTATION_NONE 0
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2
#ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 0
#endif
#ifndef TOUCH_CALIBRATION_Y
#define TOUCH_CALIBRATION_Y 0
#endif
#ifndef TOUCH_OFFSET_X
#define TOUCH_OFFSET_X 0
#endif
#ifndef TOUCH_OFFSET_Y
#define TOUCH_OFFSET_Y 0
#endif
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif
#ifndef TFT_DRIVER
#define TFT_DRIVER AUTO
#endif
#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x
#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF)
#define ESC_END 0xFFFF, 0x7FFF
#define ESC_FFFF 0xFFFF, 0xFFFF
class TFT_IO {
public:
static TFT_IO_DRIVER io;
static void InitTFT();
static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax);
static void write_esc_sequence(const uint16_t *Sequence);
// Deletaged methods
inline static void Init() { io.Init(); io.Abort(); };
inline static bool isBusy() { return io.isBusy(); };
inline static void Abort() { io.Abort(); };
inline static uint32_t GetID() { return io.GetID(); };
inline static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) { io.DataTransferBegin(DataWidth); }
inline static void DataTransferEnd() { io.DataTransferEnd(); };
// inline static void DataTransferAbort() { io.DataTransferAbort(); };
inline static void WriteData(uint16_t Data) { io.WriteData(Data); };
inline static void WriteReg(uint16_t Reg) { io.WriteReg(Reg); };
inline static void WriteSequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); };
#if ENABLED(USE_SPI_DMA_TC)
inline static void WriteSequenceIT(uint16_t *Data, uint16_t Count) { io.WriteSequenceIT(Data, Count); };
#endif
// static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
inline static void WriteMultiple(uint16_t Color, uint32_t Count) { io.WriteMultiple(Color, Count); };
protected:
static uint32_t lcd_id;
};

View File

@ -0,0 +1,115 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "touch_calibration.h"
#define TOUCH_CALIBRATION_MAX_RETRIES 5
#define DEBUG_OUT ENABLED(DEBUG_TOUCH_CALIBRATION)
#include "../../core/debug_out.h"
#if ENABLED(TOUCH_CALIBRATION_AUTO_SAVE)
#include "../../module/settings.h"
#endif
TouchCalibration touch_calibration;
touch_calibration_t TouchCalibration::calibration;
calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
touch_calibration_point_t TouchCalibration::calibration_points[4];
uint8_t TouchCalibration::failed_count;
void TouchCalibration::validate_calibration() {
#define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B)
const bool landscape = VALIDATE_PRECISION(x, TOP_LEFT, BOTTOM_LEFT)
&& VALIDATE_PRECISION(x, TOP_RIGHT, BOTTOM_RIGHT)
&& VALIDATE_PRECISION(y, TOP_LEFT, TOP_RIGHT)
&& VALIDATE_PRECISION(y, BOTTOM_LEFT, BOTTOM_RIGHT);
const bool portrait = VALIDATE_PRECISION(y, TOP_LEFT, BOTTOM_LEFT)
&& VALIDATE_PRECISION(y, TOP_RIGHT, BOTTOM_RIGHT)
&& VALIDATE_PRECISION(x, TOP_LEFT, TOP_RIGHT)
&& VALIDATE_PRECISION(x, BOTTOM_LEFT, BOTTOM_RIGHT);
#undef VALIDATE_PRECISION
#define CAL_PTS(N) calibration_points[CALIBRATION_##N]
if (landscape) {
calibration_state = CALIBRATION_SUCCESS;
calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x + CAL_PTS(TOP_RIGHT).raw_x - CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x);
calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y - CAL_PTS(TOP_RIGHT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y);
calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x) * calibration.x) >> 17);
calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(TOP_RIGHT).raw_y) * calibration.y) >> 17);
calibration.orientation = TOUCH_LANDSCAPE;
}
else if (portrait) {
calibration_state = CALIBRATION_SUCCESS;
calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y + CAL_PTS(TOP_RIGHT).raw_y - CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y);
calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x - CAL_PTS(TOP_RIGHT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x);
calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y) * calibration.x) >> 17);
calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(TOP_RIGHT).raw_x) * calibration.y) >> 17);
calibration.orientation = TOUCH_PORTRAIT;
}
else {
calibration_state = CALIBRATION_FAIL;
calibration_reset();
if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_TOP_LEFT;
}
#undef CAL_PTS
if (calibration_state == CALIBRATION_SUCCESS) {
SERIAL_ECHOLNPGM("Touch screen calibration completed");
SERIAL_ECHOLNPGM("TOUCH_CALIBRATION_X ", calibration.x);
SERIAL_ECHOLNPGM("TOUCH_CALIBRATION_Y ", calibration.y);
SERIAL_ECHOLNPGM("TOUCH_OFFSET_X ", calibration.offset_x);
SERIAL_ECHOLNPGM("TOUCH_OFFSET_Y ", calibration.offset_y);
SERIAL_ECHO_TERNARY(calibration.orientation == TOUCH_LANDSCAPE, "TOUCH_ORIENTATION ", "TOUCH_LANDSCAPE", "TOUCH_PORTRAIT", "\n");
TERN_(TOUCH_CALIBRATION_AUTO_SAVE, settings.save());
}
}
bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) {
static millis_t next_button_update_ms = 0;
const millis_t now = millis();
if (PENDING(now, next_button_update_ms)) return false;
next_button_update_ms = now + BUTTON_DELAY_MENU;
if (calibration_state < CALIBRATION_SUCCESS) {
calibration_points[calibration_state].raw_x = x;
calibration_points[calibration_state].raw_y = y;
DEBUG_ECHOLNPGM("TouchCalibration - State: ", calibration_state, ", x: ", calibration_points[calibration_state].x, ", raw_x: ", x, ", y: ", calibration_points[calibration_state].y, ", raw_y: ", y);
}
switch (calibration_state) {
case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_BOTTOM_LEFT; break;
case CALIBRATION_BOTTOM_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break;
case CALIBRATION_TOP_RIGHT: calibration_state = CALIBRATION_BOTTOM_RIGHT; break;
case CALIBRATION_BOTTOM_RIGHT: validate_calibration(); break;
default: break;
}
return true;
}
#endif // TOUCH_SCREEN_CALIBRATION

View File

@ -0,0 +1,95 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#include "tft_io.h"
#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
#endif
#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS
#define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500
#endif
typedef struct __attribute__((__packed__)) {
int32_t x, y;
int16_t offset_x, offset_y;
uint8_t orientation;
} touch_calibration_t;
typedef struct __attribute__((__packed__)) {
uint16_t x, y;
int16_t raw_x, raw_y;
} touch_calibration_point_t;
enum calibrationState : uint8_t {
CALIBRATION_TOP_LEFT = 0x00,
CALIBRATION_BOTTOM_LEFT,
CALIBRATION_TOP_RIGHT,
CALIBRATION_BOTTOM_RIGHT,
CALIBRATION_SUCCESS,
CALIBRATION_FAIL,
CALIBRATION_NONE,
};
class TouchCalibration {
public:
static calibrationState calibration_state;
static touch_calibration_point_t calibration_points[4];
static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; }
static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); }
static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); }
static void validate_calibration();
static touch_calibration_t calibration;
static uint8_t failed_count;
static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
static calibrationState calibration_start() {
calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE };
calibration_state = CALIBRATION_TOP_LEFT;
calibration_points[CALIBRATION_TOP_LEFT].x = 30;
calibration_points[CALIBRATION_TOP_LEFT].y = 30;
calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30;
calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31;
calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 31;
calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
failed_count = 0;
return calibration_state;
}
static void calibration_end() { calibration_state = CALIBRATION_NONE; }
static calibrationState get_calibration_state() { return calibration_state; }
static bool calibration_loaded() {
if (need_calibration()) calibration_reset();
return !need_calibration();
}
static bool handleTouch(uint16_t x, uint16_t y);
};
extern TouchCalibration touch_calibration;

154
src/lcd/thermistornames.h Normal file
View File

@ -0,0 +1,154 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* thermistornames.h
*
* Used by LCD code to obtain a thermistor name
*
* Usage: Set THERMISTOR_ID then #include this file
* to set a new value for THERMISTOR_NAME.
*/
#undef THERMISTOR_NAME
// User-specified thermistor parameters
#if THERMISTOR_ID == 1000
#define THERMISTOR_NAME "User Parameters"
// Thermcouples
#elif THERMISTOR_ID == -5
#define THERMISTOR_NAME "MAX31865"
#elif THERMISTOR_ID == -4
#define THERMISTOR_NAME "AD8495"
#elif THERMISTOR_ID == -3
#define THERMISTOR_NAME "MAX31855"
#elif THERMISTOR_ID == -2
#define THERMISTOR_NAME "MAX6675"
#elif THERMISTOR_ID == -1
#define THERMISTOR_NAME "AD595"
// Standard thermistors
#elif THERMISTOR_ID == 1
#define THERMISTOR_NAME "EPCOS 100K"
#elif THERMISTOR_ID == 331
#define THERMISTOR_NAME "3.3V EPCOS 100K (MEGA)"
#elif THERMISTOR_ID == 332
#define THERMISTOR_NAME "3.3V EPCOS 100K (DUE)"
#elif THERMISTOR_ID == 2
#define THERMISTOR_NAME "ATC 204GT-2"
#elif THERMISTOR_ID == 202
#define THERMISTOR_NAME "200k Copymaster 3D"
#elif THERMISTOR_ID == 3
#define THERMISTOR_NAME "Mendel-parts"
#elif THERMISTOR_ID == 4
#define THERMISTOR_NAME "Generic 10K"
#elif THERMISTOR_ID == 5
#define THERMISTOR_NAME "ATC 104GT-2"
#elif THERMISTOR_ID == 501
#define THERMISTOR_NAME "Zonestar (Tronxy X3A)"
#elif THERMISTOR_ID == 502
#define THERMISTOR_NAME "Zonestar (P802M Hot Bed)"
#elif THERMISTOR_ID == 503
#define THERMISTOR_NAME "Zonestar (Z8XM2 Bed)"
#elif THERMISTOR_ID == 504
#define THERMISTOR_NAME "Zonestar (P802QR2 Hot End)"
#elif THERMISTOR_ID == 505
#define THERMISTOR_NAME "Zonestar (P802QR2 Bed)"
#elif THERMISTOR_ID == 512
#define THERMISTOR_NAME "RPW-Ultra"
#elif THERMISTOR_ID == 6
#define THERMISTOR_NAME "EPCOS (alt)"
#elif THERMISTOR_ID == 7
#define THERMISTOR_NAME "HW 104LAG"
#elif THERMISTOR_ID == 71
#define THERMISTOR_NAME "HW 104LAF"
#elif THERMISTOR_ID == 8
#define THERMISTOR_NAME "E3104FXT"
#elif THERMISTOR_ID == 9
#define THERMISTOR_NAME "GE AL03006"
#elif THERMISTOR_ID == 10
#define THERMISTOR_NAME "RS 198-961"
#elif THERMISTOR_ID == 11
#define THERMISTOR_NAME "1% beta 3950"
#elif THERMISTOR_ID == 12
#define THERMISTOR_NAME "E3104FXT (alt)"
#elif THERMISTOR_ID == 13
#define THERMISTOR_NAME "Hisens 3950"
#elif THERMISTOR_ID == 15
#define THERMISTOR_NAME "100k JGAurora A5"
#elif THERMISTOR_ID == 18
#define THERMISTOR_NAME "ATC Semitec 204GT-2"
#elif THERMISTOR_ID == 20
#define THERMISTOR_NAME "Pt100 UltiMB 5v"
#elif THERMISTOR_ID == 21
#define THERMISTOR_NAME "Pt100 UltiMB 3.3v"
#elif THERMISTOR_ID == 201
#define THERMISTOR_NAME "Pt100 OverLord"
#elif THERMISTOR_ID == 60
#define THERMISTOR_NAME "Makers Tool"
#elif THERMISTOR_ID == 70
#define THERMISTOR_NAME "Hephestos 2"
#elif THERMISTOR_ID == 75
#define THERMISTOR_NAME "MGB18"
#elif THERMISTOR_ID == 99
#define THERMISTOR_NAME "100k with 10k pull-up"
// Modified thermistors
#elif THERMISTOR_ID == 30
#define THERMISTOR_NAME "Kis3d EN AW NTC100K/3950"
#elif THERMISTOR_ID == 51
#define THERMISTOR_NAME "EPCOS 1K"
#elif THERMISTOR_ID == 52
#define THERMISTOR_NAME "ATC204GT-2 1K"
#elif THERMISTOR_ID == 55
#define THERMISTOR_NAME "ATC104GT-2 1K"
#elif THERMISTOR_ID == 1047
#define THERMISTOR_NAME "PT1000 4K7"
#elif THERMISTOR_ID == 1010
#define THERMISTOR_NAME "PT1000 1K"
#elif THERMISTOR_ID == 147
#define THERMISTOR_NAME "Pt100 4K7"
#elif THERMISTOR_ID == 110
#define THERMISTOR_NAME "Pt100 1K"
#elif THERMISTOR_ID == 666
#define THERMISTOR_NAME "Einstart S"
#elif THERMISTOR_ID == 2000
#define THERMISTOR_NAME "TDK NTCG104LH104JT1"
// High Temperature thermistors
#elif THERMISTOR_ID == 61
#define THERMISTOR_NAME "Formbot 350°C"
#elif THERMISTOR_ID == 66
#define THERMISTOR_NAME "Dyze 4.7M"
#elif THERMISTOR_ID == 67
#define THERMISTOR_NAME "SliceEng 450°C"
// Dummies for dev testing
#elif THERMISTOR_ID == 998
#define THERMISTOR_NAME "Dummy 1"
#elif THERMISTOR_ID == 999
#define THERMISTOR_NAME "Dummy 2"
#elif THERMISTOR_ID == 1000
#define THERMISTOR_NAME "Custom"
#endif // THERMISTOR_ID

View File

@ -0,0 +1,143 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if HAS_TOUCH_BUTTONS
#include "touch_buttons.h"
#include "../scaled_tft.h"
#if ENABLED(TFT_TOUCH_DEVICE_GT911)
#include HAL_PATH(../../HAL, tft/gt911.h)
GT911 touchIO;
#elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
#include HAL_PATH(../../HAL, tft/xpt2046.h)
XPT2046 touchIO;
#else
#error "Unknown Touch Screen Type."
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"
#endif
#if HAS_TOUCH_SLEEP
millis_t TouchButtons::next_sleep_ms;
#endif
#include "../buttons.h" // For EN_C bit mask
#include "../marlinui.h" // For ui.refresh
#include "../tft_io/tft_io.h"
#define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X
#define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y
#define DOGM_AREA_WIDTH (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH)
#define DOGM_AREA_HEIGHT (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT)
#define BUTTON_AREA_TOP BUTTON_Y_LO
#define BUTTON_AREA_BOT BUTTON_Y_HI
TouchButtons touchBt;
void TouchButtons::init() {
touchIO.Init();
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
}
uint8_t TouchButtons::read_buttons() {
#ifdef HAS_WIRED_LCD
int16_t x, y;
#if ENABLED(TFT_TOUCH_DEVICE_XPT2046)
const bool is_touched = (TERN(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration.orientation, TOUCH_ORIENTATION) == TOUCH_PORTRAIT ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y));
#if HAS_TOUCH_SLEEP
if (is_touched)
wakeUp();
else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
sleepTimeout();
#endif
if (!is_touched) return 0;
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
const calibrationState state = touch_calibration.get_calibration_state();
if (WITHIN(state, CALIBRATION_TOP_LEFT, CALIBRATION_BOTTOM_RIGHT)) {
if (touch_calibration.handleTouch(x, y)) ui.refresh();
return 0;
}
x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
#else
x = uint16_t((uint32_t(x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? touchIO.getPoint(&y, &x) : touchIO.getPoint(&x, &y));
if (!is_touched) return 0;
#endif
// Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D
: WITHIN(x, BUTTONA_X_LO, BUTTONA_X_HI) ? EN_A
: WITHIN(x, BUTTONB_X_LO, BUTTONB_X_HI) ? EN_B
: WITHIN(x, BUTTONC_X_LO, BUTTONC_X_HI) ? EN_C
: 0;
if ( !WITHIN(x, DOGM_AREA_LEFT, DOGM_AREA_LEFT + DOGM_AREA_WIDTH)
|| !WITHIN(y, DOGM_AREA_TOP, DOGM_AREA_TOP + DOGM_AREA_HEIGHT)
) return 0;
// Column and row above BUTTON_AREA_TOP
int8_t col = (x - (DOGM_AREA_LEFT)) * (LCD_WIDTH) / (DOGM_AREA_WIDTH),
row = (y - (DOGM_AREA_TOP)) * (LCD_HEIGHT) / (DOGM_AREA_HEIGHT);
// Send the touch to the UI (which will simulate the encoder wheel)
MarlinUI::screen_click(row, col, x, y);
#endif
return 0;
}
#if HAS_TOUCH_SLEEP
void TouchButtons::sleepTimeout() {
#if HAS_LCD_BRIGHTNESS
ui.set_brightness(0);
#elif PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, LOW);
#endif
next_sleep_ms = TSLP_SLEEPING;
}
void TouchButtons::wakeUp() {
if (isSleeping()) {
#if HAS_LCD_BRIGHTNESS
ui.set_brightness(ui.brightness);
#elif PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
}
#endif // HAS_TOUCH_SLEEP
#endif // HAS_TOUCH_BUTTONS

View File

@ -0,0 +1,71 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <stdint.h>
#include "../../inc/MarlinConfig.h"
#include "../scaled_tft.h"
#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
#define UPSCALE(A,M) (UPSCALE0(M) + (A))
#define BUTTON_DRAW_WIDTH 32
#define BUTTON_DRAW_HEIGHT 20
#define BUTTON_WIDTH UPSCALE0(BUTTON_DRAW_WIDTH)
#define BUTTON_HEIGHT UPSCALE0(BUTTON_DRAW_HEIGHT)
// calc the space between buttons
#define BUTTON_SPACING (((TFT_WIDTH) - (BUTTON_WIDTH * 4)) / 5)
#define BUTTOND_X_LO BUTTON_SPACING
#define BUTTOND_X_HI BUTTOND_X_LO + BUTTON_WIDTH - 1
#define BUTTONA_X_LO BUTTOND_X_HI + BUTTON_SPACING
#define BUTTONA_X_HI BUTTONA_X_LO + BUTTON_WIDTH - 1
#define BUTTONB_X_LO BUTTONA_X_HI + BUTTON_SPACING
#define BUTTONB_X_HI BUTTONB_X_LO + BUTTON_WIDTH - 1
#define BUTTONC_X_LO BUTTONB_X_HI + BUTTON_SPACING
#define BUTTONC_X_HI BUTTONC_X_LO + BUTTON_WIDTH - 1
#define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING
#define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
#define TSLP_PREINIT 0
#define TSLP_SLEEPING 1
class TouchButtons {
public:
static void init();
static uint8_t read_buttons();
#if HAS_TOUCH_SLEEP
static millis_t next_sleep_ms;
static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
static void sleepTimeout();
static void wakeUp();
#endif
};
extern TouchButtons touchBt;