mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-01-06 14:47:42 -07:00
✨ LIGHTWEIGHT_UI for Native/Simulator (#28049)
This commit is contained in:
parent
dcbcbb54f9
commit
8fe6bc6745
7 changed files with 45 additions and 31 deletions
|
|
@ -71,13 +71,13 @@ static uint8_t SPI_speed = 0;
|
|||
|
||||
static uint8_t swSpiTransfer(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
WRITE_PIN(mosi_pin, !!(b & 0x80));
|
||||
WRITE_PIN(sck_pin, TERN(U8G_SPI_USE_MODE_3, LOW, HIGH));
|
||||
DELAY_CYCLES(SPI_SPEED);
|
||||
WRITE_PIN(sck_pin, HIGH);
|
||||
WRITE_PIN(mosi_pin, !!(b & 0x80));
|
||||
DELAY_CYCLES(SPI_SPEED);
|
||||
b <<= 1;
|
||||
if (miso_pin >= 0 && READ_PIN(miso_pin)) b |= 1;
|
||||
WRITE_PIN(sck_pin, LOW);
|
||||
WRITE_PIN(sck_pin, TERN(U8G_SPI_USE_MODE_3, HIGH, LOW));
|
||||
DELAY_CYCLES(SPI_SPEED);
|
||||
}
|
||||
return b;
|
||||
|
|
@ -85,7 +85,7 @@ static uint8_t swSpiTransfer(uint8_t b, const uint8_t spi_speed, const pin_t sck
|
|||
|
||||
static uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin) {
|
||||
WRITE_PIN(mosi_pin, HIGH);
|
||||
WRITE_PIN(sck_pin, LOW);
|
||||
WRITE_PIN(sck_pin, TERN(U8G_SPI_USE_MODE_3, HIGH, LOW));
|
||||
return spiRate;
|
||||
}
|
||||
|
||||
|
|
@ -93,11 +93,11 @@ static void u8g_com_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
|
|||
static uint8_t rs_last_state = 255;
|
||||
if (rs != rs_last_state) {
|
||||
// Transfer Data (FA) or Command (F8)
|
||||
swSpiTransfer(rs ? 0x0FA : 0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
|
||||
swSpiTransfer(rs ? 0xFA : 0xF8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
|
||||
rs_last_state = rs;
|
||||
DELAY_US(40); // Give the controller time to process the data: 20 is bad, 30 is OK, 40 is safe
|
||||
}
|
||||
swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
|
||||
swSpiTransfer(val & 0xF0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
|
||||
swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
|
||||
}
|
||||
|
||||
|
|
@ -169,5 +169,32 @@ uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
|||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(LIGHTWEIGHT_UI)
|
||||
|
||||
#define ST7920_CS() { WRITE(LCD_PINS_RS, HIGH); }
|
||||
#define ST7920_NCS() { WRITE(LCD_PINS_RS, LOW); }
|
||||
#define ST7920_SET_CMD() { ST7920_SWSPI_SND_8BIT(0xF8); }
|
||||
#define ST7920_SET_DAT() { ST7920_SWSPI_SND_8BIT(0xFA); }
|
||||
#define ST7920_WRITE_BYTE(a) { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4U)); }
|
||||
|
||||
#define ST7920_DAT(V) !!((V) & 0x80)
|
||||
|
||||
#define ST7920_SND_BIT(...) do{ \
|
||||
WRITE(LCD_PINS_D4, LOW); \
|
||||
WRITE(LCD_PINS_EN, ST7920_DAT(val)); \
|
||||
WRITE(LCD_PINS_D4, HIGH); \
|
||||
val <<= 1; }while(0);
|
||||
|
||||
void ST7920_SWSPI_SND_8BIT(uint8_t val) {
|
||||
REPEAT(8, ST7920_SND_BIT);
|
||||
}
|
||||
|
||||
void ST7920_cs() { ST7920_CS(); }
|
||||
void ST7920_ncs() { ST7920_NCS(); }
|
||||
void ST7920_set_cmd() { ST7920_SET_CMD(); }
|
||||
void ST7920_set_dat() { ST7920_SET_DAT(); }
|
||||
void ST7920_write_byte(const uint8_t val) { ST7920_WRITE_BYTE(val); }
|
||||
#endif // LIGHTWEIGHT_UI
|
||||
|
||||
#endif // IS_U8GLIB_ST7920
|
||||
#endif // __PLAT_NATIVE_SIM__
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck
|
|||
static uint8_t SPI_speed = 0;
|
||||
|
||||
static uint8_t swSpiInit(const uint8_t spi_speed, const uint8_t clk_pin, const uint8_t mosi_pin) {
|
||||
return spi_speed;
|
||||
return spi_speed;
|
||||
}
|
||||
|
||||
static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
|
||||
|
|
|
|||
|
|
@ -308,10 +308,6 @@
|
|||
|
||||
#endif
|
||||
|
||||
#if ANY(FYSETC_MINI_12864, MKS_MINI_12864)
|
||||
#define U8G_SPI_USE_MODE_3 1
|
||||
#endif
|
||||
|
||||
// ST7920-based graphical displays
|
||||
#if ANY(IS_RRD_FG_SC, LCD_FOR_MELZI, SILVER_GATE_GLCD_CONTROLLER)
|
||||
#define DOGLCD
|
||||
|
|
@ -319,6 +315,10 @@
|
|||
#define IS_RRD_SC 1
|
||||
#endif
|
||||
|
||||
#if ANY(FYSETC_MINI_12864, MKS_MINI_12864) || ALL(__PLAT_NATIVE_SIM__, IS_U8GLIB_ST7920)
|
||||
#define U8G_SPI_USE_MODE_3 1
|
||||
#endif
|
||||
|
||||
// ST7565 / 64128N graphical displays
|
||||
#if ANY(MAKRPANEL, MINIPANEL)
|
||||
#define IS_ULTIPANEL 1
|
||||
|
|
|
|||
|
|
@ -478,13 +478,7 @@ void ST7920_Lite_Status_Screen::draw_fan_icon(const bool whichIcon) {
|
|||
}
|
||||
|
||||
void ST7920_Lite_Status_Screen::draw_heat_icon(const bool whichIcon, const bool heating) {
|
||||
set_ddram_address(
|
||||
#if HOTENDS == 1
|
||||
DDRAM_LINE_2
|
||||
#else
|
||||
DDRAM_LINE_3
|
||||
#endif
|
||||
);
|
||||
set_ddram_address((HOTENDS < 2) ? DDRAM_LINE_2 : DDRAM_LINE_3);
|
||||
begin_data();
|
||||
if (heating)
|
||||
write_word(whichIcon ? CGRAM_ICON_1_WORD : CGRAM_ICON_2_WORD);
|
||||
|
|
@ -920,7 +914,7 @@ void ST7920_Lite_Status_Screen::update(const bool forceUpdate) {
|
|||
cs();
|
||||
update_indicators(forceUpdate);
|
||||
update_status_or_position(forceUpdate);
|
||||
update_progress(forceUpdate);
|
||||
TERN_(HAS_PRINT_PROGRESS, update_progress(forceUpdate));
|
||||
ncs();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ST7920_Lite_Status_Screen {
|
|||
} current_bits;
|
||||
|
||||
static void cs() { ST7920_cs(); current_bits.synced = false; }
|
||||
static void ncs() { ST7920_cs(); current_bits.synced = false; }
|
||||
static void ncs() { ST7920_ncs(); current_bits.synced = false; }
|
||||
static void sync_cmd() { ST7920_set_cmd(); }
|
||||
static void sync_dat() { ST7920_set_dat(); }
|
||||
static void write_byte(const uint8_t w) { ST7920_write_byte(w); }
|
||||
|
|
|
|||
|
|
@ -91,24 +91,17 @@
|
|||
#define ST7920_DAT(V) ((V) & 0x80)
|
||||
#endif
|
||||
|
||||
#define ST7920_SND_BIT do{ \
|
||||
#define ST7920_SND_BIT(...) do{ \
|
||||
WRITE(ST7920_CLK_PIN, LOW); ST7920_DELAY_1; \
|
||||
WRITE(ST7920_DAT_PIN, ST7920_DAT(val)); ST7920_DELAY_2; \
|
||||
WRITE(ST7920_CLK_PIN, HIGH); ST7920_DELAY_3; \
|
||||
val <<= 1; }while(0)
|
||||
val <<= 1; }while(0);
|
||||
|
||||
// Optimize this code with -O3
|
||||
#pragma GCC optimize (3)
|
||||
|
||||
void ST7920_SWSPI_SND_8BIT(uint8_t val) {
|
||||
ST7920_SND_BIT; // 1
|
||||
ST7920_SND_BIT; // 2
|
||||
ST7920_SND_BIT; // 3
|
||||
ST7920_SND_BIT; // 4
|
||||
ST7920_SND_BIT; // 5
|
||||
ST7920_SND_BIT; // 6
|
||||
ST7920_SND_BIT; // 7
|
||||
ST7920_SND_BIT; // 8
|
||||
REPEAT(8, ST7920_SND_BIT);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ debug_build_flags = -fstack-protector-strong -g -g3 -ggdb
|
|||
lib_compat_mode = off
|
||||
build_src_filter = ${common.default_src_filter} +<src/HAL/NATIVE_SIM>
|
||||
lib_deps = ${common.lib_deps}
|
||||
MarlinSimUI=https://github.com/p3p/MarlinSimUI/archive/af62611296.zip
|
||||
MarlinSimUI=https://github.com/p3p/MarlinSimUI/archive/2e71215018.zip
|
||||
Adafruit NeoPixel=https://github.com/p3p/Adafruit_NeoPixel/archive/c6b319f447.zip
|
||||
LiquidCrystal=https://github.com/p3p/LiquidCrystal/archive/322fb5fc23.zip
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue