diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 40b8ba5f22..6a3cad0b45 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -3003,7 +3003,9 @@ // https://github.com/mikeshub/SailfishLCD // Uses the code directly from Sailfish // -//#define FF_INTERFACEBOARD +// #define FF_INTERFACEBOARD + +// #define MIGHTYBOARD_LCD // // TFT GLCD Panel with Marlin UI diff --git a/Marlin/src/HAL/AVR/pinsDebug.h b/Marlin/src/HAL/AVR/pinsDebug.h index c833964a29..ce801333a2 100644 --- a/Marlin/src/HAL/AVR/pinsDebug.h +++ b/Marlin/src/HAL/AVR/pinsDebug.h @@ -45,7 +45,7 @@ #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS -#if MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14) +#if MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14, MIGHTYBOARD_REVG) #define AVR_ATmega2560_FAMILY_PLUS_70 1 #endif diff --git a/Marlin/src/HAL/AVR/pinsDebug_plus_70.h b/Marlin/src/HAL/AVR/pinsDebug_plus_70.h index 6565acd523..46fe45c1f8 100644 --- a/Marlin/src/HAL/AVR/pinsDebug_plus_70.h +++ b/Marlin/src/HAL/AVR/pinsDebug_plus_70.h @@ -25,7 +25,7 @@ * Structures for 2560 family boards that use more than 70 pins */ -#if MB(BQ_ZUM_MEGA_3D, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14) +#if MB(BQ_ZUM_MEGA_3D, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14, MIGHTYBOARD_REVG) #undef NUM_DIGITAL_PINS #define NUM_DIGITAL_PINS 85 #elif MB(MIGHTYBOARD_REVE) diff --git a/Marlin/src/inc/Conditionals-2-LCD.h b/Marlin/src/inc/Conditionals-2-LCD.h index 41d3805954..53daae462f 100644 --- a/Marlin/src/inc/Conditionals-2-LCD.h +++ b/Marlin/src/inc/Conditionals-2-LCD.h @@ -540,10 +540,55 @@ #define IS_ULTIPANEL 1 #endif -#if ANY(IS_ULTIPANEL, ULTRA_LCD) +#if ENABLED(MIGHTYBOARD_INTERFACE) + #define MIGHTYBOARD_LCD + // #define IS_ULTIPANEL 1 + // #define HAS_WIRED_LCD 1 + #define LCD_WIDTH 20 + #define LCD_HEIGHT 4 +#endif + +#if ANY(IS_ULTIPANEL, ULTRA_LCD, MIGHTYBOARD_LCD) #define HAS_WIRED_LCD 1 #endif + +// // Compile-time diagnostic warnings for MightyBoard builds +// #if ENABLED(MIGHTYBOARD_LCD) +// #warning "MightyBoard build: MIGHTYBOARD_LCD is ENABLED" +// #if ENABLED(IS_ULTIPANEL) +// #warning "MightyBoard build: IS_ULTIPANEL is defined" +// #else +// #warning "MightyBoard build: IS_ULTIPANEL is NOT defined" +// #endif +// #if ENABLED(HAS_WIRED_LCD) +// #warning "MightyBoard build: HAS_WIRED_LCD is defined" +// #else +// #warning "MightyBoard build: HAS_WIRED_LCD is NOT defined" +// #endif +// #if ENABLED(HAS_MARLINUI_HD44780) +// #warning "MightyBoard build: HAS_MARLINUI_HD44780 is defined" +// #else +// #warning "MightyBoard build: HAS_MARLINUI_HD44780 is NOT defined" +// #endif +// #if ENABLED(HAS_MARLINUI_MENU) +// #warning "MightyBoard build: HAS_MARLINUI_MENU is defined" +// #else +// #warning "MightyBoard build: HAS_MARLINUI_MENU is NOT defined" +// #endif +// #if ENABLED(HAS_SHIFT_ENCODER) +// #warning "MightyBoard build: HAS_SHIFT_ENCODER is defined" +// #else +// #warning "MightyBoard build: HAS_SHIFT_ENCODER is NOT defined" +// #endif +// #if ENABLED(HAS_DIGITAL_BUTTONS) +// #warning "HAS_DIGITAL_BUTTONS enabled" +// #else +// #warning "MightyBoard build: HAS_DIGITAL_BUTTONS is NOT defined" +// #endif +// #endif + + #if ANY(IS_ULTIPANEL, REPRAPWORLD_KEYPAD) #define IS_NEWPANEL 1 #endif diff --git a/Marlin/src/lcd/HD44780/MightyboardLCDSerial.cpp b/Marlin/src/lcd/HD44780/MightyboardLCDSerial.cpp new file mode 100644 index 0000000000..b8326de0fd --- /dev/null +++ b/Marlin/src/lcd/HD44780/MightyboardLCDSerial.cpp @@ -0,0 +1,342 @@ +/** + * 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 . + * + */ + +#include "MightyboardLCDSerial.h" + +#include "../../inc/MarlinConfigPre.h" +#include "../../core/serial.h" + +#if HAS_MARLINUI_HD44780 && ENABLED(MIGHTYBOARD_LCD) + +#include + +/** + * Constructor: store pin assignments + */ +MightyboardLCDSerial::MightyboardLCDSerial(uint8_t strobe, uint8_t data, uint8_t clk, uint8_t pwrPin) + : _strobe_pin(strobe), _data_pin(data), _clk_pin(clk), _pwr_pin(pwrPin), + _displayfunction(LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS), + _displaycontrol(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF), + _displaymode(LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT), + _xcursor(0), _ycursor(0) {} + +/** + * Initialize LCD display with 4-bit mode + * Follows HD44780 initialization sequence from datasheet + */ +void MightyboardLCDSerial::begin(uint8_t cols, uint8_t rows, uint8_t charsize) { + pinMode(_strobe_pin, OUTPUT); + pinMode(_data_pin, OUTPUT); + pinMode(_clk_pin, OUTPUT); + + // Power on LCD if power pin is defined + if (_pwr_pin != 255) { + pinMode(_pwr_pin, OUTPUT); + digitalWrite(_pwr_pin, LOW); // Power on (active low) + } + + _cols = cols; + _rows = rows; + + // Diagnostic output showing LCD configuration + #ifdef MIGHTYBOARD_RUNTIME_DEBUG + SERIAL_ECHOLN("MightyboardLCDSerial::begin() - LCD Configuration:"); + SERIAL_ECHO(" Dimensions: "); + SERIAL_ECHO(_cols); + SERIAL_ECHO(" x "); + SERIAL_ECHOLN(_rows); + #ifdef LCD_WIDTH + SERIAL_ECHO(" Expected from config: "); + SERIAL_ECHO(LCD_WIDTH); + SERIAL_ECHO(" x "); + SERIAL_ECHOLN(LCD_HEIGHT); + #endif + SERIAL_ECHO(" Charsize: "); + if (charsize == LCD_5x8DOTS) + SERIAL_ECHOLN("5x8 dots"); + else if (charsize == LCD_5x10DOTS) + SERIAL_ECHOLN("5x10 dots"); + else + SERIAL_ECHOLN("unknown"); + #endif + if (rows > 1) { + _displayfunction |= LCD_2LINE; + } + + if ((charsize != LCD_5x8DOTS) && (rows == 1)) { + _displayfunction |= LCD_5x10DOTS; + } + + // Power-up delay as per HD44780 datasheet (> 40ms required) + delay(50); + + // Initialization sequence for 4-bit mode + // This is a simplified sequence that works reliably + sendCommand(0x33); // Initialize, 8-bit mode attempt 1 + sendCommand(0x32); // Set 4-bit mode + sendCommand(0x28); // Function Set: 4-bit, 2-line, 5x8 dots + sendCommand(0x0C); // Display ON, cursor OFF, blink OFF + sendCommand(0x06); // Entry Mode Set: increment, no shift + sendCommand(0x01); // Clear display + delay(5); +} + +/** + * Clear the display and return cursor to home + */ +void MightyboardLCDSerial::clear() { + sendCommand(LCD_CLEARDISPLAY); + delay(2); // Clear takes ~1.52ms +} + +/** + * Return cursor to home (0, 0) + */ +void MightyboardLCDSerial::home() { + sendCommand(LCD_RETURNHOME); + delay(2); + _xcursor = 0; + _ycursor = 0; +} + +/** + * Turn display off (keeps data in DDRAM) + */ +void MightyboardLCDSerial::noDisplay() { + _displaycontrol &= ~LCD_DISPLAYON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Turn display on + */ +void MightyboardLCDSerial::display() { + _displaycontrol |= LCD_DISPLAYON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Turn off the blinking cursor + */ +void MightyboardLCDSerial::noBlink() { + _displaycontrol &= ~LCD_BLINKON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Turn on the blinking cursor + */ +void MightyboardLCDSerial::blink() { + _displaycontrol |= LCD_BLINKON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Turn off the underline cursor + */ +void MightyboardLCDSerial::noCursor() { + _displaycontrol &= ~LCD_CURSORON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Turn on the underline cursor + */ +void MightyboardLCDSerial::cursor() { + _displaycontrol |= LCD_CURSORON; + sendCommand(LCD_DISPLAYCONTROL | _displaycontrol); +} + +/** + * Scroll display contents left (cursor follows) + */ +void MightyboardLCDSerial::scrollDisplayLeft() { + sendCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); +} + +/** + * Scroll display contents right (cursor follows) + */ +void MightyboardLCDSerial::scrollDisplayRight() { + sendCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); +} + +/** + * Set text direction left-to-right + */ +void MightyboardLCDSerial::leftToRight() { + _displaymode |= LCD_ENTRYLEFT; + sendCommand(LCD_ENTRYMODESET | _displaymode); +} + +/** + * Set text direction right-to-left + */ +void MightyboardLCDSerial::rightToLeft() { + _displaymode &= ~LCD_ENTRYLEFT; + sendCommand(LCD_ENTRYMODESET | _displaymode); +} + +/** + * Enable autoscroll (characters printed shift display left) + */ +void MightyboardLCDSerial::autoscroll() { + _displaymode |= LCD_ENTRYSHIFTINCREMENT; + sendCommand(LCD_ENTRYMODESET | _displaymode); +} + +/** + * Disable autoscroll + */ +void MightyboardLCDSerial::noAutoscroll() { + _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + sendCommand(LCD_ENTRYMODESET | _displaymode); +} + +/** + * Load a custom character into CGRAM + * @param location CGRAM address (0-7) + * @param charmap 8-byte array defining the character + */ +void MightyboardLCDSerial::createChar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // Only 8 locations available + sendCommand(LCD_SETCGRAMADDR | (location << 3)); + for (int8_t i = 0; i < 8; i++) { + sendData(charmap[i]); + } +} + +/** + * Set cursor position + * @param col Column (0 to cols-1) + * @param row Row (0 to rows-1) + */ +void MightyboardLCDSerial::setCursor(uint8_t col, uint8_t row) { + static const uint8_t row_offsets[] = {0x00, 0x40, 0x14, 0x54}; + if (row >= _rows) row = _rows - 1; + _xcursor = col; + _ycursor = row; + sendCommand(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} + +/** + * Write a character to the LCD at current cursor position + * Automatically advances cursor and wraps to next line if needed + */ +size_t MightyboardLCDSerial::write(uint8_t value) { + sendData(value); + _xcursor++; + if (_xcursor >= _cols) { + _xcursor = 0; + _ycursor++; + if (_ycursor >= _rows) _ycursor = 0; + setCursor(_xcursor, _ycursor); + } + return 1; +} + +/** + * Send a raw command byte to LCD + */ +void MightyboardLCDSerial::command(uint8_t value) { + send(value, false); +} + +/** + * Low-level: send 8-bit value as two 4-bit nibbles + * @param value Byte to send + * @param mode false = command, true = data + */ +void MightyboardLCDSerial::send(uint8_t value, bool mode) { + write4bits(value >> 4, mode); + write4bits(value & 0x0F, mode); +} + +/** + * Send command (RS = 0) + */ +inline void MightyboardLCDSerial::sendCommand(uint8_t value) { + send(value, false); +} + +/** + * Send data (RS = 1) + */ +inline void MightyboardLCDSerial::sendData(uint8_t value) { + send(value, true); +} + +/** + * Write 4-bit nibble to display + * @param value Lower 4 bits are used + * @param dataMode false = command (RS=0), true = data (RS=1) + */ +void MightyboardLCDSerial::write4bits(uint8_t value, bool dataMode) { + // Shift data to upper 4 bits (D7-D4 in HD44780) + uint8_t bits = value << 4; + + // Set RS bit (bit 1) based on mode + // On Mightyboard: RS = 0b0010 + if (dataMode) + bits |= 0b0010; // RS = 1 for data + + // Pulse enable to latch the nibble + pulseEnable(bits); +} + +/** + * Pulse the Enable line to latch data + * On Mightyboard hardware: Enable = bit 3 (0b01000) + * @param value Pre-set data bits (D7-D0 in shift register) + */ +void MightyboardLCDSerial::pulseEnable(uint8_t value) { + _delay_us(1); + value |= 0b01000; // Set enable HIGH + writeSerial(value); + _delay_us(1); + value &= 0b11110111; // Set enable LOW + writeSerial(value); + _delay_us(50); // Wait for command execution +} + +/** + * Shift out 8 bits serially via shift register + * Sends MSB first (bit 7 down to bit 0) + * @param value Byte to shift out + */ +void MightyboardLCDSerial::writeSerial(uint8_t value) { + // Shift out each bit, MSB first + for (int8_t i = 7; i >= 0; i--) { + digitalWrite(_clk_pin, LOW); + bool data = (value >> i) & 0x01; + digitalWrite(_data_pin, data); + digitalWrite(_clk_pin, HIGH); + _delay_us(1); // Clock pulse width + } + + // Pulse strobe to latch data into display shift register + digitalWrite(_strobe_pin, HIGH); + _delay_us(1); + digitalWrite(_strobe_pin, LOW); +} + +#endif // HAS_MARLINUI_HD44780 && ENABLED(MIGHTYBOARD_LCD) diff --git a/Marlin/src/lcd/HD44780/MightyboardLCDSerial.h b/Marlin/src/lcd/HD44780/MightyboardLCDSerial.h new file mode 100644 index 0000000000..63ac91a06e --- /dev/null +++ b/Marlin/src/lcd/HD44780/MightyboardLCDSerial.h @@ -0,0 +1,142 @@ +/** + * 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 . + * + */ +#pragma once + +/** + * MightyboardLCDSerial + * Optimized 3-wire shift-register LCD driver for Mightyboard OEM displays + * Provides HD44780 compatible interface with minimal CPU overhead + */ + +#include + +class MightyboardLCDSerial : public Print { +public: + /** + * Constructor: initialize pin assignments + * @param strobe Strobe/latch pin (LATCH_PIN / SR_STROBE_PIN) + * @param data Data pin (MOSI_PIN / SR_DATA_PIN) + * @param clk Clock pin (SCLK_PIN / SR_CLK_PIN) + * @param pwrPin Power control pin (LCD_PWR_PIN) + */ + MightyboardLCDSerial(uint8_t strobe, uint8_t data, uint8_t clk, uint8_t pwrPin = 255); + + /** + * Initialize display with given dimensions + * @param cols Number of columns (typically 20) + * @param rows Number of rows (typically 4) + */ + void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); + + // Basic display control + void clear(); + void home(); + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + + // Cursor movement + void setCursor(uint8_t col, uint8_t row); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + // Custom characters + void createChar(uint8_t location, uint8_t charmap[]); + + // Text output + virtual size_t write(uint8_t value); + using Print::write; + + // Low-level command + void command(uint8_t value); + +private: + uint8_t _strobe_pin; + uint8_t _data_pin; + uint8_t _clk_pin; + uint8_t _pwr_pin; + + uint8_t _cols; + uint8_t _rows; + uint8_t _displayfunction; + uint8_t _displaycontrol; + uint8_t _displaymode; + + uint8_t _xcursor; + uint8_t _ycursor; + + // Low-level communication + void send(uint8_t value, bool mode); + void sendCommand(uint8_t value); + void sendData(uint8_t value); + void write4bits(uint8_t value, bool dataMode); + void pulseEnable(uint8_t value); + void writeSerial(uint8_t value); + + // HD44780 command constants + static const uint8_t LCD_CLEARDISPLAY = 0x01; + static const uint8_t LCD_RETURNHOME = 0x02; + static const uint8_t LCD_ENTRYMODESET = 0x04; + static const uint8_t LCD_DISPLAYCONTROL = 0x08; + static const uint8_t LCD_CURSORSHIFT = 0x10; + static const uint8_t LCD_FUNCTIONSET = 0x20; + static const uint8_t LCD_SETCGRAMADDR = 0x40; + static const uint8_t LCD_SETDDRAMADDR = 0x80; + + // Entry mode flags + static const uint8_t LCD_ENTRYRIGHT = 0x00; + static const uint8_t LCD_ENTRYLEFT = 0x02; + static const uint8_t LCD_ENTRYSHIFTINCREMENT = 0x01; + static const uint8_t LCD_ENTRYSHIFTDECREMENT = 0x00; + + // Display control flags + static const uint8_t LCD_DISPLAYON = 0x04; + static const uint8_t LCD_DISPLAYOFF = 0x00; + static const uint8_t LCD_CURSORON = 0x02; + static const uint8_t LCD_CURSOROFF = 0x00; + static const uint8_t LCD_BLINKON = 0x01; + static const uint8_t LCD_BLINKOFF = 0x00; + + // Display shift flags + static const uint8_t LCD_DISPLAYMOVE = 0x08; + static const uint8_t LCD_CURSORMOVE = 0x00; + static const uint8_t LCD_MOVERIGHT = 0x04; + static const uint8_t LCD_MOVELEFT = 0x00; + + // Function set flags + static const uint8_t LCD_8BITMODE = 0x10; + static const uint8_t LCD_4BITMODE = 0x00; + static const uint8_t LCD_2LINE = 0x08; + static const uint8_t LCD_1LINE = 0x00; + static const uint8_t LCD_5x10DOTS = 0x04; + static const uint8_t LCD_5x8DOTS = 0x00; +}; + +// Alias for compatibility with Marlin's LCD_CLASS macro +using MightyboardLCD = MightyboardLCDSerial; diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index a7507bd1e8..5362a3d056 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -67,19 +67,19 @@ // #if ENABLED(LCD_I2C_TYPE_PCF8575) - + #warning "LCD_CLASS: LiquidCrystal_I2C (PCF8575)" LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_I2C_PIN_EN, LCD_I2C_PIN_RW, LCD_I2C_PIN_RS, LCD_I2C_PIN_D4, LCD_I2C_PIN_D5, LCD_I2C_PIN_D6, LCD_I2C_PIN_D7); #elif ANY(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) - + #warning "LCD_CLASS: LiquidTWI2 (MCP23017/MCP23008)" LCD_CLASS lcd(LCD_I2C_ADDRESS OPTARG(DETECT_I2C_LCD_DEVICE, 1)); #elif ENABLED(LCD_I2C_TYPE_PCA8574) - + #warning "LCD_CLASS: LiquidCrystal_I2C (PCA8574)" LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); #elif ENABLED(SR_LCD_2W_NL) - + #warning "LCD_CLASS: LiquidCrystal_SR (2-Wire)" // 2 wire Non-latching LCD SR from: // https://github.com/fmalpartida/New-LiquidCrystal/wiki/schematics#user-content-ShiftRegister_connection @@ -89,8 +89,20 @@ #endif ); -#elif ENABLED(SR_LCD_3W_NL) +#elif ENABLED(MIGHTYBOARD_LCD) + #warning "LCD_CLASS: MightyboardLCDSerial (MIGHTYBOARD_LCD)" + // 3-wire shift-register LCD for Mightyboard + // Optimized in-tree implementation + #if PIN_EXISTS(LCD_PWR) + #warning "MIGHTYBOARD: LCD_PWR_PIN defined - power control enabled" + LCD_CLASS lcd(SR_STROBE_PIN, SR_DATA_PIN, SR_CLK_PIN, LCD_PWR_PIN); + #else + #warning "MIGHTYBOARD: LCD_PWR_PIN not defined - power control disabled" + LCD_CLASS lcd(SR_STROBE_PIN, SR_DATA_PIN, SR_CLK_PIN); + #endif +#elif ENABLED(SR_LCD_3W_NL) + #warning "LCD_CLASS: LiquidCrystalSerial (Sailfish SR_LCD_3W_NL)" // NewLiquidCrystal was not working // https://github.com/mikeshub/SailfishLCD // uses the code directly from Sailfish @@ -98,7 +110,7 @@ LCD_CLASS lcd(SR_STROBE_PIN, SR_DATA_PIN, SR_CLK_PIN); #elif ENABLED(LCM1602) - + #warning "LCD_CLASS: LiquidCrystal_I2C (LCM1602)" LCD_CLASS lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #elif ENABLED(YHCB2004) @@ -119,10 +131,11 @@ #error "YHCB2004 display requires YHCB2004_SS_PIN, YHCB2004_SCK_PIN, YHCB2004_MOSI_PIN, and YHCB2004_MISO_PIN." #endif + #warning "LCD_CLASS: LiquidCrystal_AIP31068_SPI (YHCB2004)" LCD_CLASS lcd(YHCB2004_SS_PIN, 20, 4, YHCB2004_SCK_PIN, YHCB2004_MOSI_PIN, YHCB2004_MISO_PIN); // SS, cols, rows, SCK, MOSI, MISO #else - + #warning "LCD_CLASS: LiquidCrystal (Standard Direct)" // Standard direct-connected LCD implementations LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_EN, LCD_PINS_D4, LCD_PINS_D5, LCD_PINS_D6, LCD_PINS_D7); @@ -378,6 +391,8 @@ void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARS void MarlinUI::init_lcd() { + SERIAL_ECHOLN("DEBUG_LCD: about to call lcd.begin()"); + #if ENABLED(LCD_I2C_TYPE_PCF8575) lcd.begin(LCD_WIDTH, LCD_HEIGHT); #ifdef LCD_I2C_PIN_BL @@ -402,6 +417,8 @@ void MarlinUI::init_lcd() { lcd.begin(LCD_WIDTH, LCD_HEIGHT); #endif + SERIAL_ECHOLN("DEBUG_LCD: lcd.begin returned"); + set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU); lcd.clear(); diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.h b/Marlin/src/lcd/HD44780/marlinui_HD44780.h index 15f268f8d9..09050d2996 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.h +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.h @@ -89,6 +89,15 @@ #include #define LCD_CLASS LiquidCrystal_SR +#elif ENABLED(MIGHTYBOARD_LCD) + + // 3-wire shift-register LCD for Mightyboard + // Optimized in-tree implementation + // Pin mapping: SR_STROBE_PIN, SR_DATA_PIN, SR_CLK_PIN + + #include "MightyboardLCDSerial.h" + #define LCD_CLASS MightyboardLCDSerial + #elif ENABLED(SR_LCD_3W_NL) // NewLiquidCrystal didn't work, so this uses diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 94e911dba1..9d10d2b2ad 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -304,6 +304,11 @@ void MarlinUI::init_lcd() { u8g.init(U8G_PARAM); did_init_u8g = true; } + SERIAL_ECHOLN("init LCD"); + #if PIN_EXISTS(LCD_PWR_PIN) + SERIAL_ECHOLN("Pwr pin low"); + digitalWrite(LCD_PWR_PIN, LOW); + #endif #if PIN_EXISTS(LCD_BACKLIGHT) OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away @@ -339,6 +344,7 @@ void MarlinUI::init_lcd() { #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) WRITE(LCD_BACKLIGHT_PIN, HIGH); + SERIAL_ECHOLN("Backlight high"); #endif TERN_(HAS_LCD_CONTRAST, refresh_contrast()); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index f4d4c28fa7..ee372aca69 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -273,7 +273,11 @@ void MarlinUI::init() { SET_INPUT_PULLUP(BTN_EN2); #endif #if BUTTON_EXISTS(ENC) - SET_INPUT_PULLUP(BTN_ENC); + #if ENABLED(MIGHTYBOARD_DISABLE_ENC_PULLUP) + SET_INPUT(BTN_ENC); + #else + SET_INPUT_PULLUP(BTN_ENC); + #endif #endif #if BUTTON_EXISTS(ENC_EN) SET_INPUT_PULLUP(BTN_ENC_EN); @@ -282,18 +286,68 @@ void MarlinUI::init() { SET_INPUT_PULLUP(BTN_BACK); #endif #if BUTTON_EXISTS(UP) - SET_INPUT(BTN_UP); + #if ENABLED(MIGHTYBOARD_BUTTON_PULLUPS) + SET_INPUT_PULLUP(BTN_UP); + #else + SET_INPUT(BTN_UP); + #endif #endif #if BUTTON_EXISTS(DOWN) - SET_INPUT(BTN_DOWN); + #if ENABLED(MIGHTYBOARD_BUTTON_PULLUPS) + SET_INPUT_PULLUP(BTN_DOWN); + #else + SET_INPUT(BTN_DOWN); + #endif #endif #if BUTTON_EXISTS(LFT) - SET_INPUT(BTN_LEFT); + #if ENABLED(MIGHTYBOARD_BUTTON_PULLUPS) + SET_INPUT_PULLUP(BTN_LEFT); + #else + SET_INPUT(BTN_LEFT); + #endif #endif #if BUTTON_EXISTS(RT) - SET_INPUT(BTN_RIGHT); + #if ENABLED(MIGHTYBOARD_BUTTON_PULLUPS) + SET_INPUT_PULLUP(BTN_RIGHT); + #else + SET_INPUT(BTN_RIGHT); + #endif #endif + // // Compile-time warnings to confirm whether this directional-button init block + // // is compiled for the current board. These will appear in the compiler output + // // only when ANY_BUTTON(UP, DOWN, LFT, RT) evaluates true for the current build. + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) && ANY_BUTTON(UP, DOWN, LFT, RT) + // #warning "Marlin: Compiling directional button init (UP/DOWN/LEFT/RIGHT)" + // #endif + + // // Optional runtime trace for MightyBoard UI/button flow. + // // Enable by uncommenting `#define MIGHTYBOARD_RUNTIME_DEBUG` in the board pins file. + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // SERIAL_ECHOLN("MarlinUI::init() - MIGHTYBOARD_RUNTIME_DEBUG active"); + // #if ENABLED(MIGHTYBOARD_BUTTON_PULLUPS) + // SERIAL_ECHOLN("MIGHTYBOARD_BUTTON_PULLUPS: ENABLED"); + // #else + // SERIAL_ECHOLN("MIGHTYBOARD_BUTTON_PULLUPS: DISABLED"); + // #endif + // SERIAL_ECHO_MSG("LCD dimensions: ", LCD_WIDTH, " x ", LCD_HEIGHT); + // SERIAL_ECHOLN(""); + + // // Report encoder/click compile-time presence and pin numbers (if defined) + // #if BUTTON_EXISTS(ENC) + // SERIAL_ECHOLN("BUTTON_EXISTS(ENC): defined"); + // SERIAL_ECHO_MSG("BTN_ENC pin: ", BTN_ENC); + // SERIAL_ECHOLN(""); + // #else + // SERIAL_ECHOLN("BUTTON_EXISTS(ENC): NOT defined"); + // #endif + + // #ifdef BTN_CLICK + // SERIAL_ECHO_MSG("BTN_CLICK pin: ", BTN_CLICK); + // SERIAL_ECHOLN(""); + // #endif + // #endif + #if HAS_SHIFT_ENCODER #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register @@ -1326,6 +1380,18 @@ void MarlinUI::init() { void MarlinUI::update_buttons() { const millis_t now = millis(); + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // // Debug: print raw pin reads for encoder/click to diagnose BTN_ENC alias + // #if BUTTON_EXISTS(ENC) + // SERIAL_ECHO_MSG("DBG: READ(BTN_ENC) = ", READ(BTN_ENC)); + // SERIAL_ECHOLN(""); + // #endif + // #ifdef BTN_CLICK + // SERIAL_ECHO_MSG("DBG: READ(BTN_CLICK) = ", READ(BTN_CLICK)); + // SERIAL_ECHOLN(""); + // #endif + // #endif + #if HAS_MARLINUI_ENCODER const int8_t delta = get_encoder_delta(now); @@ -1358,18 +1424,34 @@ void MarlinUI::init() { if (BUTTON_PRESSED(UP)) { encoderDiff = pulses * (ENCODER_STEPS_PER_MENU_ITEM); next_button_update_ms = now + 300; + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // SERIAL_ECHO_MSG("update_buttons(): UP -> encoderDiff=", encoderDiff); + // SERIAL_ECHOLN(""); + // #endif } else if (BUTTON_PRESSED(DOWN)) { encoderDiff = pulses * -(ENCODER_STEPS_PER_MENU_ITEM); next_button_update_ms = now + 300; + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // SERIAL_ECHO_MSG("update_buttons(): DOWN -> encoderDiff=", encoderDiff); + // SERIAL_ECHOLN(""); + // #endif } else if (BUTTON_PRESSED(LEFT)) { encoderDiff = -pulses; next_button_update_ms = now + 300; + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // SERIAL_ECHO_MSG("update_buttons(): LEFT -> encoderDiff=", encoderDiff); + // SERIAL_ECHOLN(""); + // #endif } else if (BUTTON_PRESSED(RIGHT)) { encoderDiff = pulses; next_button_update_ms = now + 300; + // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) + // SERIAL_ECHO_MSG("update_buttons(): RIGHT -> encoderDiff=", encoderDiff); + // SERIAL_ECHOLN(""); + // #endif } #endif // UP || DOWN || LEFT || RIGHT diff --git a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVG.h b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVG.h index 7c1e866cd6..bfd351ea96 100644 --- a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVG.h +++ b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVG.h @@ -26,6 +26,7 @@ * Schematic: not avalable (as rev G and H are not open source) * Pins based on the work of https://github.com/Sgail7/Replicator-Revival-Project/ * Pin number according to Mega extended mega2560ext: .\buildroot\share\PlatformIO\variants\MARLIN_MEGA_EXTENDED\pins_arduino.h + * Corrected pins based on Marlin\src\libs\softspi.h * Use env:MightyBoard2560 or env:MightyBoard1280 in platformio.ini */ @@ -40,7 +41,7 @@ // #define X_STOP_PIN 30 // C7 #define Y_STOP_PIN 31 // C6 -#define Z_MIN_PIN 32 // C5 +#define Z_STOP_PIN 32 // C5 // // Steppers @@ -76,7 +77,7 @@ #define DIGIPOTS_I2C_SDA_Y 43 // L6 #define DIGIPOTS_I2C_SDA_Z 46 // L3 #define DIGIPOTS_I2C_SDA_E0 26 // A4 -#define DIGIPOTS_I2C_SDA_E1 77 // J7 +#define DIGIPOTS_I2C_SDA_E1 74 // J7 #ifndef DIGIPOT_I2C_ADDRESS_A #define DIGIPOT_I2C_ADDRESS_A 0x2F // unshifted slave address (5E <- 2F << 1) @@ -138,7 +139,7 @@ // #if HAS_WIRED_LCD - +#warning "HAS_WIRED_LCD is defined." #if IS_RRD_FG_SC #define LCD_PINS_RS 33 // C4: LCD-STROBE @@ -160,27 +161,30 @@ #define STAT_LED_BLUE_PIN SERVO1_PIN // C0 (1280-EX2, DEBUG3) #else + #warning "Using SR pins." // Replicator 2 and 2X uses a HD44780 SPI display, pins: mosi, sclk, miso (not used), missing: latch, click, power - #define SPI_SOFT_MOSI_PIN 37 // C0 - #define SPI_SOFT_SCLK_PIN 36 // C1 - #define SPI_SOFT_MISO_PIN 33 // C4 + + #define SR_DATA_PIN 37 // C0 + #define SR_CLK_PIN 36 // C1 + #define SR_STROBE_PIN 34 // C3 - #define BTN_LATCH_PIN 34 // C3 - #define BTN_CLICK_PIN 39 // G2 + #define SR_DETECT_PIN 33 // C4 - #define BTN_UP_PIN 76 // J5 - #define BTN_DOWN_PIN 75 // J4 - #define BTN_LEFT_PIN 77 // J6/J13 + #define BUTTON_LED_PIN 35 // C2 To be implemented... - #define LCD_POWER_PIN 29 // A7 + #define BTN_CENTER 39 // G2 + #define BTN_UP 76 // J5 + #define BTN_DOWN 75 // J4 + #define BTN_LEFT 77 // J6 + #define BTN_RIGHT 73 // J3 - #define LCD_LED1_PIN 35 // C2 - - // Leave Old pins defined for now - #define SR_DATA_PIN 37 // C0 * - #define SR_CLK_PIN 36 // C1 * - #define SR_STROBE_PIN 33 // C4 * + // Map the CLICK button to the encoder 'click' so Marlin treats it as SELECT + #ifndef BTN_ENC + #define BTN_ENC BTN_CENTER + #endif + #define LCD_PWR_PIN 29 // A7 + // Disable encoder #undef BTN_EN1 #undef BTN_EN2 @@ -190,3 +194,5 @@ #endif #endif // HAS_WIRED_LCD + + diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index ad17fe2436..ba1aeb8816 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -954,6 +954,10 @@ #if PIN_EXISTS(LCD_BACKLIGHT) REPORT_NAME_DIGITAL(__LINE__, LCD_BACKLIGHT_PIN) #endif +#if PIN_EXISTS(LCD_PWR) + REPORT_NAME_DIGITAL(__LINE__, LCD_PWR_PIN) +#endif + // // LED Lights diff --git a/platformio.ini b/platformio.ini index 4d03696b5a..3e5e0e652c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -54,7 +54,8 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py pre:buildroot/share/PlatformIO/scripts/preflight-checks.py post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py -lib_deps = +lib_deps = + https://github.com/mikeshub/SailfishLCD.git default_src_filter = + - - ; LCDs and Controllers - - - - -