瀏覽代碼

Tweak some u8g interface code

Scott Lahteine 6 年之前
父節點
當前提交
50917ccda6

+ 5
- 13
Marlin/src/HAL/HAL_LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp 查看文件

@@ -68,23 +68,15 @@
68 68
 
69 69
 static pin_t SCK_pin_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL;
70 70
 static uint8_t SPI_speed = 0;
71
-static uint8_t rs_last_state = 255;
72 71
 
73 72
 static void u8g_com_LPC1768_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
74
-
75
-  if (rs != rs_last_state) {  // time to send a command/data byte
73
+  static uint8_t rs_last_state = 255;
74
+  if (rs != rs_last_state) {
75
+    // Transfer Data (FA) or Command (F8)
76
+    swSpiTransfer(rs ? 0x0FA : 0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
76 77
     rs_last_state = rs;
77
-
78
-    if (rs == 0)
79
-      /* command */
80
-      swSpiTransfer(0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
81
-    else
82
-       /* data */
83
-       swSpiTransfer(0x0FA, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
84
-
85
-    DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
78
+    DELAY_US(40); // Give the controller time to process the data: 20 is bad, 30 is OK, 40 is safe
86 79
   }
87
-
88 80
   swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
89 81
   swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
90 82
 }

+ 17
- 17
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp 查看文件

@@ -71,23 +71,23 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
71 71
       OUT_WRITE(ST7920_CLK_PIN, HIGH);
72 72
 
73 73
       ST7920_CS();
74
-      u8g_Delay(120);                 //initial delay for boot up
74
+      u8g_Delay(120);                 // Initial delay for boot up
75 75
       ST7920_SET_CMD();
76
-      ST7920_WRITE_BYTE(0x20);       //non-extended mode
77
-      ST7920_WRITE_BYTE(0x08);       //display off, cursor+blink off
78
-      ST7920_WRITE_BYTE(0x01);       //clear DDRAM ram
79
-      u8g_Delay(15);                    //delay for DDRAM clear
80
-      ST7920_WRITE_BYTE(0x24);       //extended mode
81
-      ST7920_WRITE_BYTE(0x26);       //extended mode + GDRAM active
82
-      for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
83
-        ST7920_WRITE_BYTE(0x80 | y); //set y
84
-        ST7920_WRITE_BYTE(0x80);     //set x = 0
76
+      ST7920_WRITE_BYTE(0x20);        // Non-extended mode
77
+      ST7920_WRITE_BYTE(0x08);        // Display off, cursor+blink off
78
+      ST7920_WRITE_BYTE(0x01);        // Clear DDRAM ram
79
+      u8g_Delay(15);                  // Delay for DDRAM clear
80
+      ST7920_WRITE_BYTE(0x24);        // Extended mode
81
+      ST7920_WRITE_BYTE(0x26);        // Extended mode + GDRAM active
82
+      for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) {  // Clear GDRAM
83
+        ST7920_WRITE_BYTE(0x80 | y);  // Set y
84
+        ST7920_WRITE_BYTE(0x80);      // Set x = 0
85 85
         ST7920_SET_DAT();
86
-        for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
86
+        for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) // 2x width clears both segments
87 87
           ST7920_WRITE_BYTE(0);
88 88
         ST7920_SET_CMD();
89 89
       }
90
-      ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
90
+      ST7920_WRITE_BYTE(0x0C);        // Display on, cursor+blink off
91 91
       ST7920_NCS();
92 92
     }
93 93
     break;
@@ -104,15 +104,15 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
104 104
       for (i = 0; i < PAGE_HEIGHT; i ++) {
105 105
         ST7920_SET_CMD();
106 106
         if (y < 32) {
107
-          ST7920_WRITE_BYTE(0x80 | y);       //y
108
-          ST7920_WRITE_BYTE(0x80);           //x=0
107
+          ST7920_WRITE_BYTE(0x80 | y);        // y
108
+          ST7920_WRITE_BYTE(0x80);            // x = 0
109 109
         }
110 110
         else {
111
-          ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
112
-          ST7920_WRITE_BYTE(0x80 | 8);       //x=64
111
+          ST7920_WRITE_BYTE(0x80 | (y - 32)); // y
112
+          ST7920_WRITE_BYTE(0x80 | 8);        // x = 64
113 113
         }
114 114
         ST7920_SET_DAT();
115
-        ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
115
+        ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); // ptr incremented inside of macro!
116 116
         y++;
117 117
       }
118 118
       ST7920_NCS();

Loading…
取消
儲存