From e6d8218dc20d4d5d4b3a2700c0e3fc26bb4059ed Mon Sep 17 00:00:00 2001 From: Msq001 <760675063@qq.com> Date: Sat, 23 May 2020 16:55:37 +0800 Subject: [PATCH] cleanup & fix st7920 simulator (add klipper support) (#705) * fix bug * improve st7920 simulator for klipper --- TFT/src/User/API/Colors.c | 4 +- TFT/src/User/API/LCD_Encoder.h | 2 +- TFT/src/User/API/UI/Numpad.c | 2 +- TFT/src/User/API/UI/Numpad.h | 2 +- TFT/src/User/API/UI/ST7920_Simulator.c | 613 ++++++++++++++++++++++--- TFT/src/User/API/UI/ST7920_Simulator.h | 170 ++++++- TFT/src/User/API/config.c | 2 - TFT/src/User/API/config.h | 4 +- TFT/src/User/API/config.inc | 2 +- TFT/src/User/API/flashStore.c | 46 +- TFT/src/User/API/flashStore.h | 5 +- TFT/src/User/API/interfaceCmd.c | 8 +- TFT/src/User/Hal/stm32f10x/spi_slave.c | 26 +- TFT/src/User/Hal/stm32f2xx/spi_slave.c | 20 +- TFT/src/User/Menu/FeatureSettings.c | 8 +- TFT/src/User/Menu/Popup.c | 3 +- TFT/src/User/Menu/Popup.h | 2 +- TFT/src/User/Menu/Settings.c | 3 +- TFT/src/User/main.c | 20 +- 19 files changed, 813 insertions(+), 129 deletions(-) diff --git a/TFT/src/User/API/Colors.c b/TFT/src/User/API/Colors.c index 43a6ae0e76..3b4d00e74c 100644 --- a/TFT/src/User/API/Colors.c +++ b/TFT/src/User/API/Colors.c @@ -1,4 +1,4 @@ -#include "Colors.h" +#include "Colors.h" const u32 lcd_colors[LCD_COLOR_COUNT] = { WHITE, @@ -37,4 +37,4 @@ const LABEL lcd_color_names[LCD_COLOR_COUNT] = LABEL_DARKGREEN, LABEL_GRAY, LABEL_DARKGRAY - }; \ No newline at end of file + }; diff --git a/TFT/src/User/API/LCD_Encoder.h b/TFT/src/User/API/LCD_Encoder.h index 042cb702f1..020e0bccb1 100644 --- a/TFT/src/User/API/LCD_Encoder.h +++ b/TFT/src/User/API/LCD_Encoder.h @@ -28,4 +28,4 @@ bool encoder_CheckState(void); void sendEncoder(uint8_t num); void loopCheckEncoder(void); -#endif \ No newline at end of file +#endif diff --git a/TFT/src/User/API/UI/Numpad.c b/TFT/src/User/API/UI/Numpad.c index d0a492a413..63dee5df99 100644 --- a/TFT/src/User/API/UI/Numpad.c +++ b/TFT/src/User/API/UI/Numpad.c @@ -234,4 +234,4 @@ u32 numPadInt(u32 old_val) } loopBackEnd(); } -} \ No newline at end of file +} diff --git a/TFT/src/User/API/UI/Numpad.h b/TFT/src/User/API/UI/Numpad.h index e32832937e..81704dba73 100644 --- a/TFT/src/User/API/UI/Numpad.h +++ b/TFT/src/User/API/UI/Numpad.h @@ -53,4 +53,4 @@ float numPadFloat(float old_val, bool negative_val); u32 numPadInt(u32 old_val); -#endif \ No newline at end of file +#endif diff --git a/TFT/src/User/API/UI/ST7920_Simulator.c b/TFT/src/User/API/UI/ST7920_Simulator.c index f716228194..7a4f9d7077 100644 --- a/TFT/src/User/API/UI/ST7920_Simulator.c +++ b/TFT/src/User/API/UI/ST7920_Simulator.c @@ -5,68 +5,543 @@ #ifdef ST7920_SPI -ST7920_PIXEL st7920 = {ST7920_XSTART, ST7920_YSTART, 0}; -ST7920_CTRL_STATUS status = ST7920_IDLE; +// CGRAM buffer +uint8_t ST7920_CGRAM[64][2]; // [64*2] = [4 * 16*2*8], means 4 * [16*16] bitmap font, -void ST7920_DrawPixel(int16_t x, int16_t y, uint16_t color) +const uint8_t ascii16x8[] = { + /****************************************************************************** +* Font Width:8 +* Font Height:16 +* Font Count:95 +*******************************************************************************/ +//UNICODE:20 +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:21 +0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:22 +0x00,0x00,0x08,0x00,0x30,0x00,0x40,0x00,0x08,0x00,0x30,0x00,0x40,0x00,0x00,0x00, + +//UNICODE:23 +0x00,0x00,0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x03,0xFC,0x1E,0x20,0x00,0x00, + +//UNICODE:24 +0x00,0x00,0x0E,0x18,0x11,0x04,0x11,0x04,0x3F,0xFF,0x10,0x84,0x0C,0x78,0x00,0x00, + +//UNICODE:25 +0x0F,0x00,0x10,0x8C,0x0F,0x30,0x01,0xC0,0x06,0x78,0x18,0x84,0x00,0x78,0x00,0x00, + +//UNICODE:26 +0x00,0x78,0x0F,0x84,0x10,0xC4,0x11,0x34,0x0E,0x98,0x00,0xE4,0x00,0x84,0x00,0x08, + +//UNICODE:27 +0x00,0x00,0x48,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:28 +0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x20,0x04,0x40,0x02,0x00,0x00, + +//UNICODE:29 +0x00,0x00,0x40,0x02,0x20,0x04,0x18,0x18,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:2A +0x02,0x40,0x02,0x40,0x01,0x80,0x0F,0xF0,0x01,0x80,0x02,0x40,0x02,0x40,0x00,0x00, + +//UNICODE:2B +0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x07,0xF0,0x00,0x80,0x00,0x80,0x00,0x80, + +//UNICODE:2C +0x00,0x00,0x00,0x09,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:2D +0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00, + +//UNICODE:2E +0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:2F +0x00,0x00,0x00,0x06,0x00,0x18,0x00,0xE0,0x03,0x00,0x1C,0x00,0x20,0x00,0x00,0x00, + +//UNICODE:30 +0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00, + +//UNICODE:31 +0x00,0x00,0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00, + +//UNICODE:32 +0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x10,0x84,0x0F,0x0C,0x00,0x00, + +//UNICODE:33 +0x00,0x00,0x0C,0x18,0x10,0x04,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00, + +//UNICODE:34 +0x00,0x00,0x00,0x60,0x01,0xA0,0x02,0x24,0x0C,0x24,0x1F,0xFC,0x00,0x24,0x00,0x24, + +//UNICODE:35 +0x00,0x00,0x1F,0x98,0x11,0x04,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00, + +//UNICODE:36 +0x00,0x00,0x07,0xF0,0x08,0x88,0x11,0x04,0x11,0x04,0x09,0x04,0x00,0xF8,0x00,0x00, + +//UNICODE:37 +0x00,0x00,0x18,0x00,0x10,0x00,0x10,0x7C,0x11,0x80,0x16,0x00,0x18,0x00,0x00,0x00, + +//UNICODE:38 +0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00, + +//UNICODE:39 +0x00,0x00,0x0F,0x80,0x10,0x48,0x10,0x44,0x10,0x44,0x08,0x88,0x07,0xF0,0x00,0x00, + +//UNICODE:3A +0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x03,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:3B +0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:3C +0x00,0x00,0x00,0x80,0x01,0x40,0x02,0x20,0x04,0x10,0x08,0x08,0x10,0x04,0x00,0x00, + +//UNICODE:3D +0x00,0x00,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x00,0x00, + +//UNICODE:3E +0x00,0x00,0x10,0x04,0x08,0x08,0x04,0x10,0x02,0x20,0x01,0x40,0x00,0x80,0x00,0x00, + +//UNICODE:3F +0x00,0x00,0x0E,0x00,0x12,0x00,0x10,0x0C,0x10,0xEC,0x11,0x00,0x0E,0x00,0x00,0x00, + +//UNICODE:40 +0x03,0xE0,0x0C,0x18,0x13,0xE4,0x14,0x14,0x17,0xF4,0x08,0x14,0x07,0xE8,0x00,0x00, + +//UNICODE:41 +0x00,0x04,0x00,0x3C,0x03,0xC4,0x1C,0x40,0x07,0x40,0x00,0xE4,0x00,0x1C,0x00,0x04, + +//UNICODE:42 +0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x11,0x04,0x0E,0x88,0x00,0x70,0x00,0x00, + +//UNICODE:43 +0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x1C,0x10,0x00,0x00, + +//UNICODE:44 +0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00, + +//UNICODE:45 +0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00, + +//UNICODE:46 +0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x17,0xC0,0x10,0x00,0x08,0x00,0x00,0x00, + +//UNICODE:47 +0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x44,0x1C,0x78,0x00,0x40,0x00,0x00, + +//UNICODE:48 +0x10,0x04,0x1F,0xFC,0x10,0x84,0x00,0x80,0x00,0x80,0x10,0x84,0x1F,0xFC,0x10,0x04, + +//UNICODE:49 +0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x00,0x00,0x00,0x00, + +//UNICODE:4A +0x00,0x03,0x00,0x01,0x10,0x01,0x10,0x01,0x1F,0xFE,0x10,0x00,0x10,0x00,0x00,0x00, + +//UNICODE:4B +0x10,0x04,0x1F,0xFC,0x11,0x04,0x03,0x80,0x14,0x64,0x18,0x1C,0x10,0x04,0x00,0x00, + +//UNICODE:4C +0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00, + +//UNICODE:4D +0x10,0x04,0x1F,0xFC,0x1F,0x80,0x00,0x7C,0x1F,0x80,0x1F,0xFC,0x10,0x04,0x00,0x00, + +//UNICODE:4E +0x10,0x04,0x1F,0xFC,0x0C,0x04,0x03,0x00,0x00,0xE0,0x10,0x18,0x1F,0xFC,0x10,0x00, + +//UNICODE:4F +0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00, + +//UNICODE:50 +0x10,0x04,0x1F,0xFC,0x10,0x84,0x10,0x80,0x10,0x80,0x10,0x80,0x0F,0x00,0x00,0x00, + +//UNICODE:51 +0x07,0xF0,0x08,0x08,0x10,0x14,0x10,0x14,0x10,0x0C,0x08,0x0A,0x07,0xF2,0x00,0x00, + +//UNICODE:52 +0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04, + +//UNICODE:53 +0x00,0x00,0x0E,0x1C,0x11,0x04,0x10,0x84,0x10,0x84,0x10,0x44,0x1C,0x38,0x00,0x00, + +//UNICODE:54 +0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00, + +//UNICODE:55 +0x10,0x00,0x1F,0xF8,0x10,0x04,0x00,0x04,0x00,0x04,0x10,0x04,0x1F,0xF8,0x10,0x00, + +//UNICODE:56 +0x10,0x00,0x1E,0x00,0x11,0xE0,0x00,0x1C,0x00,0x70,0x13,0x80,0x1C,0x00,0x10,0x00, + +//UNICODE:57 +0x10,0x00,0x1F,0xC0,0x00,0x7C,0x1F,0x80,0x00,0x7C,0x1F,0xC0,0x10,0x00,0x00,0x00, + +//UNICODE:58 +0x10,0x04,0x18,0x0C,0x16,0x34,0x01,0xC0,0x01,0xC0,0x16,0x34,0x18,0x0C,0x10,0x04, + +//UNICODE:59 +0x10,0x00,0x1C,0x00,0x13,0x04,0x00,0xFC,0x13,0x04,0x1C,0x00,0x10,0x00,0x00,0x00, + +//UNICODE:5A +0x08,0x04,0x10,0x1C,0x10,0x64,0x10,0x84,0x13,0x04,0x1C,0x04,0x10,0x18,0x00,0x00, + +//UNICODE:5B +0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x40,0x02,0x40,0x02,0x40,0x02,0x00,0x00, + +//UNICODE:5C +0x00,0x00,0x20,0x00,0x1C,0x00,0x03,0x80,0x00,0x60,0x00,0x1C,0x00,0x03,0x00,0x00, + +//UNICODE:5D +0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:5E +0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:5F +0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + +//UNICODE:60 +0x00,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:61 +0x00,0x00,0x00,0x98,0x01,0x24,0x01,0x24,0x01,0x48,0x00,0xFC,0x00,0x04,0x00,0x00, + +//UNICODE:62 +0x08,0x00,0x0F,0xFC,0x00,0x88,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00, + +//UNICODE:63 +0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x00, + +//UNICODE:64 +0x00,0x00,0x00,0xF8,0x01,0x04,0x01,0x04,0x01,0x04,0x09,0x08,0x0F,0xFC,0x00,0x04, + +//UNICODE:65 +0x00,0x00,0x00,0xF8,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x24,0x00,0xE8,0x00,0x00, + +//UNICODE:66 +0x00,0x00,0x01,0x04,0x01,0x04,0x07,0xFC,0x09,0x04,0x09,0x04,0x04,0x00,0x00,0x00, + +//UNICODE:67 +0x00,0x00,0x00,0xD6,0x01,0x29,0x01,0x29,0x01,0x29,0x01,0xC9,0x01,0x06,0x00,0x00, + +//UNICODE:68 +0x08,0x04,0x0F,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04, + +//UNICODE:69 +0x00,0x00,0x01,0x04,0x19,0x04,0x19,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00, + +//UNICODE:6A +0x00,0x00,0x00,0x03,0x00,0x01,0x01,0x01,0x19,0x01,0x19,0xFE,0x00,0x00,0x00,0x00, + +//UNICODE:6B +0x08,0x04,0x0F,0xFC,0x00,0x24,0x00,0x60,0x01,0x94,0x01,0x0C,0x01,0x04,0x00,0x00, + +//UNICODE:6C +0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00, + +//UNICODE:6D +0x01,0x04,0x01,0xFC,0x01,0x04,0x01,0x00,0x01,0xFC,0x01,0x04,0x01,0x00,0x00,0xFC, + +//UNICODE:6E +0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04, + +//UNICODE:6F +0x00,0x00,0x00,0xF8,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0xF8,0x00,0x00, + +//UNICODE:70 +0x01,0x01,0x01,0xFF,0x00,0x89,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00, + +//UNICODE:71 +0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x00,0x89,0x01,0xFF,0x00,0x01, + +//UNICODE:72 +0x01,0x04,0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x04,0x01,0x00,0x01,0x80,0x00,0x00, + +//UNICODE:73 +0x00,0x00,0x00,0xCC,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x98,0x00,0x00, + +//UNICODE:74 +0x00,0x00,0x01,0x00,0x01,0x00,0x07,0xF8,0x01,0x04,0x01,0x04,0x00,0x08,0x00,0x00, + +//UNICODE:75 +0x01,0x00,0x01,0xF8,0x00,0x04,0x00,0x04,0x00,0x04,0x01,0x08,0x01,0xFC,0x00,0x04, + +//UNICODE:76 +0x01,0x00,0x01,0xC0,0x01,0x30,0x00,0x0C,0x01,0x30,0x01,0xC0,0x01,0x00,0x00,0x00, + +//UNICODE:77 +0x01,0x80,0x01,0x70,0x00,0x0C,0x01,0x30,0x01,0xE0,0x00,0x1C,0x01,0x60,0x01,0x80, + +//UNICODE:78 +0x00,0x00,0x01,0x04,0x01,0x8C,0x01,0x70,0x00,0x74,0x01,0x8C,0x01,0x04,0x00,0x00, + +//UNICODE:79 +0x01,0x00,0x01,0x81,0x01,0x61,0x00,0x1E,0x00,0x18,0x01,0x60,0x01,0x80,0x01,0x00, + +//UNICODE:7A +0x00,0x00,0x01,0x84,0x01,0x0C,0x01,0x34,0x01,0x44,0x01,0x84,0x01,0x0C,0x00,0x00, + +//UNICODE:7B +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3F,0x7C,0x40,0x02,0x40,0x02, + +//UNICODE:7C +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:7D +0x40,0x02,0x40,0x02,0x3F,0x7C,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +//UNICODE:7E +0x00,0x00,0x40,0x00,0x80,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x40,0x00,0x00,0x00, +}; + + +ST7920_PIXEL st7920 = { + .x = 0, // current x pixel, range is 0 - 127 + .y = 0, // current y pixel, range is 0 - 63 + .address_is_y = 1, // Extended Instruction, The first address set Y, second address set X +}; + +ST7920_REG st7920_reg = { + .fs = //0x00, // default basic instruction, 8-bit MPU interface, Graphic display OFF + 0x26, // default extended instruction, 4-bit MPU interface, Graphic display On + .bi = { + .ems = 0x02, // Cursor move to right ,DDRAM address counter (AC) plus 1 + .dc = 0x00, // Display, cursor and blink are ALL OFF + .cdsc = 0x00, // No cursor or display shift operation + }, + .ei = { + .vsra = 0x00, // Allow vertical scroll or set CGRAM address + .rev = 0x00, // Begin with normal and toggle to reverse + }, + .reverse = 0, // Begin with normal and toggle to reverse + .cgram = 0, + .data_type = ST7920_DATA_DDRAM, + .ctrl_status = ST7920_IDLE, +}; + +void ST7920_DrawPixel(int16_t x, int16_t y, bool isForeGround) { // GUI_DrawPixel(x, y, color); - if(infoSettings.marlin_mode_fullscreen) + if (infoSettings.marlin_mode_fullscreen) { GUI_FillRectColor(SIMULATOR_XSTART_FULLSCREEN + PIXEL_XSIZE_FULLSCREEN*x, SIMULATOR_YSTART_FULLSCREEN + PIXEL_YSIZE_FULLSCREEN*y, SIMULATOR_XSTART_FULLSCREEN + PIXEL_XSIZE_FULLSCREEN*(x+1), SIMULATOR_YSTART_FULLSCREEN + PIXEL_YSIZE_FULLSCREEN*(y+1), - color); + lcd_colors[isForeGround ? infoSettings.marlin_mode_font_color : infoSettings.marlin_mode_bg_color]); } else { GUI_FillRectColor(SIMULATOR_XSTART + PIXEL_XSIZE*x, SIMULATOR_YSTART + PIXEL_YSIZE*y , SIMULATOR_XSTART + PIXEL_XSIZE*(x+1), SIMULATOR_YSTART + PIXEL_YSIZE*(y+1), - color); + lcd_colors[isForeGround ? infoSettings.marlin_mode_font_color : infoSettings.marlin_mode_bg_color]); } } -int16_t ST7920_MapCoordinateX(void) +// Display graphic +void ST7920_DrawGDRAM(uint8_t data) { - return (st7920.x & 0x07) * 16 + st7920.x_record; + if (st7920_reg.fs.g != 1) return; // Graphic display off + for (uint8_t i = 0; i < 8; i++) { + if (data & 0x80) + ST7920_DrawPixel(st7920.x, st7920.y, true); + else + ST7920_DrawPixel(st7920.x, st7920.y, false); + data <<= 1; + st7920.x++; + } + + if (st7920.x >= 128) { + st7920.x = 0; + st7920.y = (st7920.y + 32); + if (st7920.y >= 64) st7920.y = (st7920.y + 1) & (64 - 1); + } } -int16_t ST7920_MapCoordinateY(void) +// Display CGRAM fonts, only 0x0000, 0x0002, 0x0004, 0x0006 +void ST7920_DispCGRAM(uint8_t data) { - return ((st7920.x & 0x08)>>3)*32 + (st7920.y - ST7920_YSTART); + uint8_t ex = st7920.x + 16, // GRAM, 16*16 bitmap font + ey = st7920.y + 16, + yIndex = data * 8; + + for (uint8_t y = st7920.y; y < ey; y++) { + uint16_t temp = ST7920_CGRAM[yIndex][0] << 8 | ST7920_CGRAM[yIndex][1]; + for (uint8_t x = st7920.x; x < ex; x++) { + ST7920_DrawPixel(x, y, temp & (1<<15)); + temp <<= 1; + } + yIndex++; + } + + st7920.x += 16; + if (st7920.x >= 128) { + st7920.x = 0; + st7920.y = (st7920.y + 32); + if (st7920.y == 64) st7920.y = 16; + else if (st7920.y == 80) st7920.y = 0; + } } -void ST7920_SetCursor(int16_t x, int16_t y) +// Display HCGROM fonts, 02H~7FH. +void ST7920_DispHCGROM(uint8_t p) { - st7920.x = x; - st7920.y = y; - st7920.x_record = 0; + const uint8_t *pStart = ascii16x8 + (p - ' ') * 16; + uint8_t ex = st7920.x + 8, + ey = st7920.y + 16; + + if (p < ' ' || p > '~') return; + + for (uint8_t x = st7920.x; x < ex; x++) { + uint16_t temp = *(pStart++) << 8; + temp |= *pStart++; + + for (uint8_t y = st7920.y; y < ey; y++) { + ST7920_DrawPixel(x, y, temp & (1<<15)); + temp <<= 1; + } + } + st7920.x += 8; + if (st7920.x >= 128) { + st7920.x = 0; + st7920.y = (st7920.y + 32); + if (st7920.y == 64) st7920.y = 16; + else if (st7920.y == 80) st7920.y = 0; + } } -void ST7920_DrawByte(u8 data) +/*** Common instruction ***/ +// cmd : 1 << 5 +void ST7920_CI15_FunctionSet(uint8_t cmd) { - uint8_t i = 0; - int16_t x = ST7920_MapCoordinateX(), - y = ST7920_MapCoordinateY(); + st7920_reg.fs.reg = cmd; +} - for(; i<8; i++) - { - if(data & 0x80) - ST7920_DrawPixel(x, y, lcd_colors[infoSettings.marlin_mode_font_color]); - else - ST7920_DrawPixel(x, y, lcd_colors[infoSettings.marlin_mode_bg_color]); - data <<= 1; - x++; +/*** Basic instruction ***/ +// cmd : 1 << 0 +void ST7920_BI10_DisplayClear(uint8_t cmd) +{ + // Fill DDRAM with "20H"(space code). + for (uint8_t y = 0; y < 64; y++) { + for (uint8_t x = 0; x < 128; x++) { + ST7920_DrawPixel(x, y, false); + } } - st7920.x_record += 8; - if(st7920.x_record == 16) - { - st7920.x_record = 0; - st7920.x = (st7920.x + 1) & 0x8F; + // Set DDRAM address counter (AC) to"00H" + st7920.x = st7920.y = 0; + // Set Entry Mode I/D bit to be "1". Cursor moves right and AC adds 1 after write or read operation + st7920_reg.bi.ems.id = 1; +} +// cmd : 1 << 1 +void ST7920_BI11_ReturnHome(uint8_t cmd) +{ + // Set address counter (AC) to "00H". + st7920.x = st7920.y = 0; +} +// cmd : 1 << 2 +void ST7920_BI12_EntryModeSet(uint8_t cmd) +{ + st7920_reg.bi.ems.reg = cmd; +} +// cmd : 1 << 3 +void ST7920_BI13_DisplayControl(uint8_t cmd) +{ + st7920_reg.bi.dc.reg = cmd; +} +// cmd : 1 << 4 +void ST7920_BI14_CursorDisplayControl(uint8_t cmd) +{ + st7920_reg.bi.cdsc.reg = cmd; +} +// cmd : 1 << 6 +void ST7920_BI16_SetCGRAMAddress(uint8_t cmd) +{ + st7920_reg.bi.cgrama.reg = cmd; + uint8_t address = st7920_reg.bi.cgrama.ac; + // Set CGRAM address + // x is 0-1 = [2*8], y is 0-64 = [4*16], means 4 * [16*16] bitmap font + st7920.x = 0; + st7920.y = address; + st7920_reg.data_type = ST7920_DATA_CGRAM; +} +// the data follow cmd : 1 << 6 +void ST7920_BI_SetCGRAMData(uint8_t data) +{ + ST7920_CGRAM[st7920.y][st7920.x++] = data; + if (st7920.x >= 2) { + st7920.x = 0; + st7920.y = (st7920.y + 1) & (64 - 1); + } +} +// cmd : 1 << 7 +void ST7920_BI17_SetDDRAMAddress(uint8_t cmd) +{ + st7920_reg.bi.ddrama.reg = cmd; + uint8_t address = st7920_reg.bi.ddrama.ac; + // Set DDRAM address + // x is 0-127. y is 0-63 + st7920.x = (address & 0x07) * 16; + st7920.y = ((address >> 4) & 0x01) * 16 + ((address >> 3) & 0x01) * 32; + st7920_reg.data_type = ST7920_DATA_DDRAM; +} + +/*** Extended Instruction ***/ +// cmd : 1 << 0 +void ST7920_EI10_StandBy(uint8_t cmd) +{ + st7920_reg.ei.sb.reg = cmd; +} +// cmd : 1 << 1 +void ST7920_EI11_ScrollOrRAMAddress(uint8_t cmd) +{ + st7920_reg.ei.vsra.reg = cmd; +} +// cmd : 1 << 2 +void ST7920_EI12_Reverse(uint8_t cmd) +{ + st7920_reg.ei.rev.reg = cmd; + st7920_reg.reverse = !st7920_reg.reverse; // Reverse the display by toggling this instruction +} +// cmd : 1 << 6 +void ST7920_EI16_SetScrollAddress(uint8_t cmd) +{ + st7920_reg.ei.sa.reg = cmd; +} +// cmd : 1 << 7 +void ST7920_EI17_SetGRAMAddress(uint8_t cmd) +{ + st7920_reg.ei.grama.reg = cmd; + uint8_t address = st7920_reg.ei.grama.ac; + if (st7920.address_is_y) { + st7920.y = address; + st7920.address_is_y = 0; + } else { + if (address & 0x08) st7920.y += 32; + st7920.x = (address & 0x07) * 16; + st7920.address_is_y = 1; } + st7920_reg.data_type = ST7920_DATA_GDRAM; } +const FP_CMD cmdCallBack[8][2] = { +// Basic Instruction Extended Instruction +{ ST7920_BI10_DisplayClear, ST7920_EI10_StandBy}, // cmd 1 << 0 +{ ST7920_BI11_ReturnHome, ST7920_EI11_ScrollOrRAMAddress}, // cmd 1 << 1 +{ ST7920_BI12_EntryModeSet, ST7920_EI12_Reverse}, // cmd 1 << 2 +{ ST7920_BI13_DisplayControl, NULL}, // cmd 1 << 3 +{ ST7920_BI14_CursorDisplayControl, NULL}, // cmd 1 << 4 +{ ST7920_CI15_FunctionSet, ST7920_CI15_FunctionSet}, // cmd 1 << 5 +{ ST7920_BI16_SetCGRAMAddress, ST7920_EI16_SetScrollAddress}, // cmd 1 << 6 +{ ST7920_BI17_SetDDRAMAddress, ST7920_EI17_SetGRAMAddress}, // cmd 1 << 7 +}; + + u8 ST7920_IsCtrlByte(u8 data) { if(data == ST7920_WCMD || data == ST7920_WDATA || data == ST7920_RCMD || data == ST7920_RDATA) @@ -75,30 +550,37 @@ u8 ST7920_IsCtrlByte(u8 data) return false; } -u8 rcvData[64]; -u8 rcvIndex = 0; - void ST7920_ParseRecv(u8 val) { + static u8 rcvData = 0; + static u8 rcvIndex = 0; if (ST7920_IsCtrlByte(val)) { - status = (ST7920_CTRL_STATUS)val; + st7920_reg.ctrl_status = (ST7920_CTRL_STATUS)val; rcvIndex = 0; + st7920.address_is_y = 1; + st7920_reg.cgram = 0; } else { - rcvData[rcvIndex++] = val; - if(rcvIndex == 1) return; //high 4 bits in first byte and - rcvIndex = 0; //low 4 bits in second byte is valid + val &= 0xF0; // Every 8 bits instruction/data will be separated into 2 groups, lower 4 bits always 0 in every groups + if (rcvIndex == 0) { + rcvData = val; // Higher 4 bits in first byte + rcvIndex++; + return; + } else { + rcvData |= val >> 4; // Lower 4 bits in second byte + rcvIndex = 0; + } - switch (status) + switch (st7920_reg.ctrl_status) { case ST7920_WCMD: - ST7920_ST7920_ParseWCmd(rcvData[0] | (rcvData[1]>>4)); + ST7920_ST7920_ParseWCmd(rcvData); break; case ST7920_WDATA: - ST7920_DrawByte(rcvData[0] | (rcvData[1]>>4)); + ST7920_ST7920_ParseWData(rcvData); break; case ST7920_RCMD: @@ -113,24 +595,41 @@ void ST7920_ParseRecv(u8 val) } } -void ST7920_WriteXY(u8 xy) -{ - static uint8_t i = 0; - if(i == 0) //y first - st7920.y = xy; - else - st7920.x = xy; - i = (i + 1) % 2; -} void ST7920_ST7920_ParseWCmd(u8 cmd) { - if(cmd & 0x80) - { - ST7920_WriteXY(cmd); + for (int8_t i = 7; i >= 0; i--) { + if (cmd & (1 << i)) { + if (cmdCallBack[i][st7920_reg.fs.re] != NULL) { + (*cmdCallBack[i][st7920_reg.fs.re])(cmd); + } + break; + } } } +void ST7920_ST7920_ParseWData(u8 data) +{ + switch (st7920_reg.data_type) { + case ST7920_DATA_DDRAM: + if (st7920_reg.cgram == 1) { + st7920_reg.cgram = 0; + ST7920_DispCGRAM(data); + } else if (data == 0x00) { + st7920_reg.cgram = 1; + return; + } else { + ST7920_DispHCGROM(data); + } + break; + case ST7920_DATA_CGRAM: + ST7920_BI_SetCGRAMData(data); + break; + case ST7920_DATA_GDRAM: + ST7920_DrawGDRAM(data); + break; + } +} void menuST7920(void) { @@ -139,20 +638,18 @@ void menuST7920(void) GUI_SetBkColor(lcd_colors[infoSettings.marlin_mode_bg_color]); if(infoSettings.marlin_mode_showtitle == 1){ - STRINGS_STORE tempST; - W25Qxx_ReadBuffer((uint8_t *)&tempST,STRINGS_STORE_ADDR,sizeof(STRINGS_STORE)); - GUI_DispStringInRect(0, 0, LCD_WIDTH, SIMULATOR_YSTART, (u8*)tempST.marlin_title); + STRINGS_STORE tempST; + W25Qxx_ReadBuffer((uint8_t *)&tempST,STRINGS_STORE_ADDR,sizeof(STRINGS_STORE)); + GUI_DispStringInRect(0, 0, LCD_WIDTH, SIMULATOR_YSTART, (uint8_t *)tempST.marlin_title); } SPI_Slave(); - SPI_Slave_CS_Config(); while(infoMenu.menu[infoMenu.cur] == menuST7920) { while(SPISlave.rIndex != SPISlave.wIndex) { ST7920_ParseRecv(SPISlave.data[SPISlave.rIndex]); - SPISlave.rIndex = (SPISlave.rIndex + 1) % SPI_SLAVE_MAX; } diff --git a/TFT/src/User/API/UI/ST7920_Simulator.h b/TFT/src/User/API/UI/ST7920_Simulator.h index 9fca975e7e..5456afbf86 100644 --- a/TFT/src/User/API/UI/ST7920_Simulator.h +++ b/TFT/src/User/API/UI/ST7920_Simulator.h @@ -32,6 +32,8 @@ #define SIMULATOR_XSTART ((LCD_WIDTH - PIXEL_XSIZE*LCD_XROWS) / 2) #define SIMULATOR_YSTART ((LCD_HEIGHT - PIXEL_YSIZE*LCD_YROWS) / 2) +typedef void (*FP_CMD)(uint8_t); + typedef enum { ST7920_IDLE = 0, @@ -41,17 +43,177 @@ typedef enum ST7920_RDATA = 0xFE, } ST7920_CTRL_STATUS; +typedef enum +{ + ST7920_DATA_DDRAM = 0, + ST7920_DATA_CGRAM, + ST7920_DATA_GDRAM, +} ST7920_DATA_TYPE; + typedef struct { - int16_t x, y; - uint8_t x_cur; - uint8_t x_record; + int16_t x; // current x pixel, range is 0 - 127 + int16_t y; // current y pixel, range is 0 - 63 + // Extended Instruction, The first address set Y, second address set X + uint8_t address_is_y; // record current address is Y or X }ST7920_PIXEL; +/*** Common Instruction ***/ +typedef struct { + union { + uint8_t reg; + struct { + uint8_t : 1, + g : 1, // Graphic display control bit + re : 1, // extended instruction set control bit + :1, + dl : 1; // 4/8-bit interface control bit (0-4bit, 1-8bit) + }; + }; +}ST7920_REG_FS; // Function Set + + +/*** Basic Instruction ***/ +typedef struct { + union { + uint8_t reg; + struct { + uint8_t slr : 1, // Display Shift Control: (Shift Left/Right) + id : 1; // Address Counter Control: (Increase/Decrease) + }; + }; +}ST7920_BIREG_EMS; // Entry Mode Set + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t blink : 1, // Character Blink ON/OFF control bit + cursor : 1, // Cursor ON/OFF control bit + display : 1; // Display ON/OFF control bit + }; + }; +}ST7920_BIREG_DC; // Display Control + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t : 2, + rl : 1, // Cursor moves/shift left/right + sc : 1; // Display shift, cursor also follows to shift + }; + }; +}ST7920_BIREG_CDSC; // Cursor/Display Shift Control + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t ac : 6; // AC range is 00H…3FH + }; + }; +}ST7920_BIREG_CGRAMA; // Set CGRAM Address + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t ac : 7; // First line AC range is 00H…0FH + // Second line AC range is 10H…1FH + // Third line AC range is 20H…2FH + // Fourth line AC range is 30H…3FH + }; + }; +}ST7920_BIREG_DDRAMA; // Set DDRAM Address + + +/*** Extended Instruction ***/ +typedef struct { + union { + uint8_t reg; + struct { + uint8_t sb : 1; + }; + }; +}ST7920_EIREG_SB; // Standby + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t sr : 1; // "1", the Vertical Scroll mode is enabled. + // "0", “Set CGRAM Address” instruction (basic instruction) is enabled + }; + }; +}ST7920_EIREG_VSRA; // Vertical Scroll or RAM Address Select + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t r0 : 1, // R1 R0 Description + r1 : 1; // 0 0 First line normal or reverse + // 0 1 Second line normal or reverse + // 1 0 Third line normal or reverse + // 1 1 Fourth line normal or reverse + }; + }; +}ST7920_EIREG_REV; // Reverse + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t ac : 6; // ST7920_EIREG_VSR.sr = 1: AC5~AC0 is vertical scroll displacement address + }; + }; +}ST7920_EIREG_SA; // Set Scroll Address + +typedef struct { + union { + uint8_t reg; + struct { + uint8_t ac : 6; // + }; + }; +}ST7920_EIREG_GRAMA; // Set Graphic RAM Address + +typedef struct { + // 1 << 0 : Display Clear + // 1 << 1 : Return Home + ST7920_BIREG_EMS ems; // 1 << 2 : Entry Mode Set + ST7920_BIREG_DC dc; // 1 << 3 : Display Control + ST7920_BIREG_CDSC cdsc; // 1 << 4 : Cursor/Display Shift Control + // 1 << 5 : Function Set + ST7920_BIREG_CGRAMA cgrama; // 1 << 6 : Set CGRAM Address + ST7920_BIREG_DDRAMA ddrama; // 1 << 7 : Set DDRAM Address +}ST7920_BI; // Basic Instruction + +typedef struct { + ST7920_EIREG_SB sb; // 1 << 0 : Standby + ST7920_EIREG_VSRA vsra; // 1 << 1 : Vertical Scroll or RAM Address Select + ST7920_EIREG_REV rev; // 1 << 2 : Reverse + // 1 << 3 : Reserved + // 1 << 4 : Reserved + // 1 << 5 : Function Set + ST7920_EIREG_SA sa; // 1 << 6 : Set Scroll Address + ST7920_EIREG_GRAMA grama; // 1 << 7 : Set Graphic RAM Address +}ST7920_EI; // Extended Instruction + +typedef struct { + ST7920_REG_FS fs; // Function Set + ST7920_BI bi; // Basic Instruction + ST7920_EI ei; // Extended Instruction + uint8_t reverse; // Begin with normal and toggle to reverse + uint8_t cgram; + ST7920_DATA_TYPE data_type; + ST7920_CTRL_STATUS ctrl_status; +}ST7920_REG; // Extended Instruction void ST7920_WriteXY(uint8_t xy); void ST7920_ST7920_ParseWCmd(uint8_t cmd); -void ST7920_DrawPixel(int16_t x, int16_t y, uint16_t color); +void ST7920_ST7920_ParseWData(uint8_t data); void menuST7920(void); diff --git a/TFT/src/User/API/config.c b/TFT/src/User/API/config.c index 41926d468e..32438eb809 100644 --- a/TFT/src/User/API/config.c +++ b/TFT/src/User/API/config.c @@ -1,4 +1,3 @@ - #include "config.h" //#define CONFIG_DEBUG // To be used only when calling 'getConfigFromFile()' after boot process @@ -458,7 +457,6 @@ void parseConfigKey(u16 index) case C_INDEX_LIST_MODE: infoSettings.file_listmode = getOnOff(); break; - break; //---------------------------------------------------------Marlin Mode Settings (Only for TFT35_V3.0/TFT24_V1.1/TFT28V3.0) diff --git a/TFT/src/User/API/config.h b/TFT/src/User/API/config.h index eefb43ca53..b5f85556c1 100644 --- a/TFT/src/User/API/config.h +++ b/TFT/src/User/API/config.h @@ -1,4 +1,4 @@ -#ifndef _CONFIG_H_ +#ifndef _CONFIG_H_ #define _CONFIG_H_ #include "variants.h" @@ -188,4 +188,4 @@ enum CONFIG_COUNT, }; -#endif \ No newline at end of file +#endif diff --git a/TFT/src/User/API/config.inc b/TFT/src/User/API/config.inc index 71c4b7058b..19777c3b2e 100644 --- a/TFT/src/User/API/config.inc +++ b/TFT/src/User/API/config.inc @@ -1,4 +1,4 @@ -/** +/** * CONFIG Kewords Generation * Usage: X_CONFIG(VALUE) * 'VALUE' is the keyword name without the 'CONFIG_' diff --git a/TFT/src/User/API/flashStore.c b/TFT/src/User/API/flashStore.c index 5ff28dcf28..3dcff83e65 100644 --- a/TFT/src/User/API/flashStore.c +++ b/TFT/src/User/API/flashStore.c @@ -1,12 +1,17 @@ #include "flashStore.h" #include "STM32_Flash.h" -#define TSC_SIGN 0x20190827 // DO NOT MODIFY -#define PARA_SIGN 0x20200517 // (YYYMMDD) If a new setting parameter is added, modify here and initialize the initial value in the "infoSettingsReset()" function +#define TSC_SIGN 0x20200512 // DO NOT MODIFY +#define PARA_SIGN 0x20200513 // (YYYMMDD) If a new setting parameter is added, modify here and initialize the initial value in the "infoSettingsReset()" function extern u32 TSC_Para[7]; // extern SETTINGS infoSettings; // -bool wasRestored = false; + +enum{ + PARA_TSC_EXIST = (1 << 0), + PARA_WAS_RESTORED = (1<< 1), +}; +uint8_t paraStatus = 0; void wordToByte(u32 word, u8 *bytes) // { @@ -33,25 +38,32 @@ u32 byteToWord(u8 *bytes, u8 len) // Read settings parameter if exist, or reset settings parameter // return value: whether the touch screen calibration parameter exists -bool readStoredPara(void) +void readStoredPara(void) { - bool paraExist = true; u8 data[PARA_SIZE]; u32 index = 0; u32 sign = 0; STM32_FlashRead(data, PARA_SIZE); sign = byteToWord(data + (index += 4), 4); - if(sign != TSC_SIGN) paraExist = false; // If the touch screen calibration parameter does not exist - for(int i=0; iIDR & (1<<12)) != 0) + { + ST7920_SPI_NUM->CR1 |= (1<<6); + } } void SPI_SlaveDeInit(void) @@ -84,45 +90,41 @@ void SPI2_IRQHandler(void) SPISlave.wIndex = (SPISlave.wIndex + 1) % SPI_SLAVE_MAX; } -/* �ⲿ�ж����� */ void SPI_Slave_CS_Config(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); - /* ��GPIOA_0���ж������� */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12); - /* �����ж���0λ�ⲿ�½����ж� */ EXTI_InitStructure.EXTI_Line = EXTI_Line12; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); - NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ʹ�ܰ������ڵ��ⲿ�ж�ͨ�� - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; //��ռ���ȼ�2�� - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //�����ȼ�1 - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ���ⲿ�ж�ͨ�� + NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } -/* �ⲿ�ж� */ void EXTI15_10_IRQHandler(void) { if((GPIOB->IDR & (1<<12)) != 0) { - SPI_ReEnable(!!(GPIOB->IDR & (1<<13))); //����Ӧ spi mode0/mode3 + SPI_ReEnable(!!(GPIOB->IDR & (1<<13))); // Adaptive spi mode0 / mode3 ST7920_SPI_NUM->CR1 |= (1<<6); } else { - RCC->APB1RSTR |= 1<<14; //��λSPI1 + RCC->APB1RSTR |= 1<<14; // Reset SPI2 RCC->APB1RSTR &= ~(1<<14); } -/* ����ж�״�?�Ĵ��� */ + EXTI->PR = 1<<12; } diff --git a/TFT/src/User/Hal/stm32f2xx/spi_slave.c b/TFT/src/User/Hal/stm32f2xx/spi_slave.c index f402caf158..898354d917 100644 --- a/TFT/src/User/Hal/stm32f2xx/spi_slave.c +++ b/TFT/src/User/Hal/stm32f2xx/spi_slave.c @@ -15,8 +15,6 @@ #define ST7920_SPI_NUM SPI3 #endif -//#define _SPI_SLAVE_IRQ(n) n##_IRQHandler -//#define SPI_SLAVE_IRQ _SPI_SLAVE_IRQ(W25QXX_SPI_NUM) SPI_QUEUE SPISlave; @@ -56,7 +54,13 @@ void SPI_Slave(void) NVIC_Init(&NVIC_InitStructure); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE); - SPI_ReEnable(1); + SPI_Slave_CS_Config(); + SPI_ReEnable(0); // spi mode0 + + if((GPIOB->IDR & (1<<12)) != 0) + { + ST7920_SPI_NUM->CR1 |= (1<<6); + } } void SPI_SlaveDeInit(void) @@ -86,11 +90,11 @@ void SPI_Slave_CS_Config(void) EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - /* Connect GPIOA_0 to the interrupt line */ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//Enable SYSCFG clock - SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource12);//PB12 is connected to interrupt line 12 + /* Connect GPIOB12 to the interrupt line */ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//Enable SYSCFG clock + SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource12);//PB12 is connected to interrupt line 12 - /*Set interrupt line 0 bit external falling edge interrupt */ + /*Set interrupt line 12 bit external falling edge interrupt */ EXTI_InitStructure.EXTI_Line = EXTI_Line12; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; @@ -116,7 +120,7 @@ void EXTI15_10_IRQHandler(void) } else { - RCC->APB1RSTR |= 1<<14; //Reset SPI1 + RCC->APB1RSTR |= 1<<14; // Reset SPI2 RCC->APB1RSTR &= ~(1<<14); } /* Clear interrupt status register */ diff --git a/TFT/src/User/Menu/FeatureSettings.c b/TFT/src/User/Menu/FeatureSettings.c index ee4ecd68e6..75132df1e2 100644 --- a/TFT/src/User/Menu/FeatureSettings.c +++ b/TFT/src/User/Menu/FeatureSettings.c @@ -67,12 +67,12 @@ typedef enum SKEY_KNOB, #endif #ifdef LCD_LED_PWM_CHANNEL - SKEY_LCD_BRIGHTNESS, - SKEY_LCD_BRIGTHNESS_DIM, - SKEY_LCD_DIM_IDLE_TIMER, + SKEY_LCD_BRIGHTNESS, + SKEY_LCD_BRIGTHNESS_DIM, + SKEY_LCD_DIM_IDLE_TIMER, #endif #ifdef ST7920_SPI - SKEY_ST7920_FULLSCREEN, + SKEY_ST7920_FULLSCREEN, #endif SKEY_RESET_SETTINGS, // Keep reset always at the bottom of the settings menu list. SKEY_COUNT //keep this always at the end diff --git a/TFT/src/User/Menu/Popup.c b/TFT/src/User/Menu/Popup.c index f196bdd39d..2206041bfa 100644 --- a/TFT/src/User/Menu/Popup.c +++ b/TFT/src/User/Menu/Popup.c @@ -115,8 +115,7 @@ void menuPopupPauseForUser(void) } } -void popupPauseForUser() -{ +void popupPauseForUser(void) { if (infoSettings.serial_alwaysOn == 1 && infoSettings.mode == LCD12864) return; popupDrawPage(&bottomSingleBtn , (u8*)"Printer Paused", (u8*)"OK to continue", textSelect(LABEL_CONFIRM), NULL); diff --git a/TFT/src/User/Menu/Popup.h b/TFT/src/User/Menu/Popup.h index d0db8978af..d78d8c77c3 100644 --- a/TFT/src/User/Menu/Popup.h +++ b/TFT/src/User/Menu/Popup.h @@ -19,6 +19,6 @@ void windowSetButton(const BUTTON *btn); void windowReDrawButton(uint8_t positon, uint8_t is_press); void popupDrawPage(BUTTON *btn, const uint8_t *title, const uint8_t *context, const uint8_t *yes, const uint8_t *no); void popupReminder(u8* info, u8* context); -void popupPauseForUser(); +void popupPauseForUser(void); #endif diff --git a/TFT/src/User/Menu/Settings.c b/TFT/src/User/Menu/Settings.c index ea2dbc2534..9a179c878d 100644 --- a/TFT/src/User/Menu/Settings.c +++ b/TFT/src/User/Menu/Settings.c @@ -24,7 +24,6 @@ void infoSettingsReset(void) infoSettings.language = DEFAULT_LANGUAGE; infoSettings.mode = DEFAULT_LCD_MODE; infoSettings.unified_menu = UNIFIED_MENU; - infoSettings.rotate_ui = DISABLED; infoSettings.bg_color = BACKGROUND_COLOR; infoSettings.font_color = FONT_COLOR; @@ -38,7 +37,7 @@ void infoSettingsReset(void) infoSettings.silent = DISABLED; infoSettings.terminalACK = DISABLED; infoSettings.move_speed = ENABLED; - infoSettings.knob_led_color = (STARTUP_KNOB_LED_COLOR - 1); + infoSettings.knob_led_color = STARTUP_KNOB_LED_COLOR; infoSettings.send_start_gcode = DISABLED; infoSettings.send_end_gcode = DISABLED; infoSettings.send_cancel_gcode = ENABLED; diff --git a/TFT/src/User/main.c b/TFT/src/User/main.c index 1a356f8fa0..c7a4bbf87e 100644 --- a/TFT/src/User/main.c +++ b/TFT/src/User/main.c @@ -45,14 +45,8 @@ void Hardware_GenericInit(void) XPT2046_Init(); W25Qxx_Init(); LCD_Init(); - - if(readStoredPara() == false) // Read settings parameter - { - TSC_Calibration(); - storePara(); - } + readStoredPara(); // Read settings parameter LCD_RefreshDirection(); //refresh display direction after reading settings - scanUpdates(); // scan icon, fonts and config files #ifndef MKS_32_V1_4 @@ -79,9 +73,19 @@ void Hardware_GenericInit(void) USBH_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USB_Host, &USBH_MSC_cb, &USR_cb); #endif + if (readIsTSCExist() == false) // Read settings parameter + { + TSC_Calibration(); + storePara(); + } + else if (readIsRestored()) + { + storePara(); + } + printSetUpdateWaiting(infoSettings.m27_active); #ifdef LCD_LED_PWM_CHANNEL - Set_LCD_Brightness(LCD_BRIGHTNESS[infoSettings.lcd_brightness]); + Set_LCD_Brightness(LCD_BRIGHTNESS[infoSettings.lcd_brightness]); #endif GUI_RestoreColorDefault(); infoMenuSelect();