Browse Source

Merge pull request #8860 from Bob-the-Kuhn/2.0.x-DUE-RRDFGSC

[2.0.x] DUE - update for Reprap Discount Full Graphic Smart Controller
Scott Lahteine 6 years ago
parent
commit
db32c185ae
No account linked to committer's email address

+ 204
- 0
Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp View File

@@ -0,0 +1,204 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*
24
+
25
+  based on u8g_com_st7920_hw_spi.c
26
+
27
+  Universal 8bit Graphics Library
28
+
29
+  Copyright (c) 2011, olikraus@gmail.com
30
+  All rights reserved.
31
+
32
+  Redistribution and use in source and binary forms, with or without modification,
33
+  are permitted provided that the following conditions are met:
34
+
35
+  * Redistributions of source code must retain the above copyright notice, this list
36
+    of conditions and the following disclaimer.
37
+
38
+  * Redistributions in binary form must reproduce the above copyright notice, this
39
+    list of conditions and the following disclaimer in the documentation and/or other
40
+    materials provided with the distribution.
41
+
42
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+*/
57
+
58
+#ifdef __SAM3X8E__
59
+
60
+#include <U8glib.h>
61
+#include <Arduino.h>
62
+#include "../../core/macros.h"
63
+
64
+void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
65
+   PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
66
+     g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration);  // OUTPUT
67
+}
68
+
69
+void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
70
+  volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
71
+  uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
72
+  if (level) port->PIO_SODR = mask;
73
+  else port->PIO_CODR = mask;
74
+}
75
+
76
+#define nop() __asm__ __volatile__("nop;\n\t":::)
77
+
78
+void __delay_4cycles(uint32_t cy) __attribute__ ((weak));
79
+
80
+FORCE_INLINE void __delay_4cycles(uint32_t cy) { // +1 cycle
81
+  #if ARCH_PIPELINE_RELOAD_CYCLES<2
82
+    #define EXTRA_NOP_CYCLES "nop"
83
+  #else
84
+    #define EXTRA_NOP_CYCLES ""
85
+  #endif
86
+
87
+  __asm__ __volatile__(
88
+    ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
89
+
90
+    "loop%=:" "\n\t"
91
+    " subs %[cnt],#1" "\n\t"
92
+    EXTRA_NOP_CYCLES "\n\t"
93
+    " bne loop%=" "\n\t"
94
+    : [cnt]"+r"(cy) // output: +r means input+output
95
+    : // input:
96
+    : "cc" // clobbers:
97
+  );
98
+}
99
+
100
+Pio *SCK_pPio, *MOSI_pPio;
101
+uint32_t SCK_dwMask, MOSI_dwMask;
102
+
103
+static void spiSend_sw_DUE(uint8_t val) { // 800KHz
104
+  for (uint8_t i = 0; i < 8; i++) {
105
+    if (val & 0x80)
106
+      MOSI_pPio->PIO_SODR = MOSI_dwMask;
107
+    else
108
+      MOSI_pPio->PIO_CODR = MOSI_dwMask;
109
+    val = val << 1;
110
+    __delay_4cycles(2);
111
+    SCK_pPio->PIO_SODR = SCK_dwMask;
112
+    __delay_4cycles(22);
113
+    SCK_pPio->PIO_CODR = SCK_dwMask;
114
+  }
115
+}
116
+
117
+static uint8_t rs_last_state = 255;
118
+
119
+static void u8g_com_DUE_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
120
+  uint8_t i;
121
+
122
+  if ( rs != rs_last_state) {  // time to send a command/data byte
123
+    rs_last_state = rs;
124
+
125
+    if ( rs == 0 )
126
+      /* command */
127
+      spiSend_sw_DUE(0x0f8);
128
+    else
129
+       /* data */
130
+      spiSend_sw_DUE(0x0fa);
131
+
132
+    for( i = 0; i < 4; i++ )   // give the controller some time to process the data
133
+      u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
134
+  }
135
+
136
+  spiSend_sw_DUE(val & 0x0f0);
137
+  spiSend_sw_DUE(val << 4);
138
+}
139
+
140
+
141
+uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
142
+  switch (msg) {
143
+    case U8G_COM_MSG_INIT:
144
+      SCK_pPio = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].pPort;
145
+      SCK_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].ulPin;
146
+      MOSI_pPio = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].pPort;
147
+      MOSI_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].ulPin;
148
+
149
+      u8g_SetPILevel_DUE(u8g, U8G_PI_CS, 0);
150
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_CS);
151
+      u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 0);
152
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_SCK);
153
+      u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 0);
154
+      u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 1);
155
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_MOSI);
156
+      u8g_Delay(5);
157
+      u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: command mode */
158
+      break;
159
+
160
+    case U8G_COM_MSG_STOP:
161
+      break;
162
+
163
+    case U8G_COM_MSG_RESET:
164
+       if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel_DUE(u8g, U8G_PI_RESET, arg_val);
165
+      break;
166
+
167
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
168
+      u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
169
+      break;
170
+
171
+    case U8G_COM_MSG_CHIP_SELECT:
172
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])
173
+        u8g_SetPILevel_DUE(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
174
+      break;
175
+
176
+    case U8G_COM_MSG_WRITE_BYTE:
177
+
178
+      u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
179
+      break;
180
+
181
+    case U8G_COM_MSG_WRITE_SEQ: {
182
+        uint8_t *ptr = (uint8_t*) arg_ptr;
183
+        while (arg_val > 0) {
184
+          u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
185
+          arg_val--;
186
+        }
187
+      }
188
+      break;
189
+
190
+      case U8G_COM_MSG_WRITE_SEQ_P: {
191
+        uint8_t *ptr = (uint8_t*) arg_ptr;
192
+        while (arg_val > 0) {
193
+          u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
194
+          arg_val--;
195
+        }
196
+      }
197
+      break;
198
+  }
199
+  return 1;
200
+}
201
+
202
+#pragma GCC reset_options
203
+
204
+#endif  //ARDUINO_ARCH_SAM

+ 4
- 8
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_hw_spi.cpp View File

@@ -118,22 +118,18 @@
118 118
         spiSend((uint8_t)arg_val);
119 119
         break;
120 120
 
121
-      case U8G_COM_MSG_WRITE_SEQ:
122
-        {
121
+      case U8G_COM_MSG_WRITE_SEQ: {
123 122
           uint8_t *ptr = (uint8_t*) arg_ptr;
124
-          while( arg_val > 0 )
125
-          {
123
+          while (arg_val > 0) {
126 124
             spiSend(*ptr++);
127 125
             arg_val--;
128 126
           }
129 127
         }
130 128
         break;
131 129
 
132
-      case U8G_COM_MSG_WRITE_SEQ_P:
133
-        {
130
+      case U8G_COM_MSG_WRITE_SEQ_P: {
134 131
           uint8_t *ptr = (uint8_t*) arg_ptr;
135
-          while( arg_val > 0 )
136
-          {
132
+          while (arg_val > 0) {
137 133
             spiSend(*ptr++);
138 134
             arg_val--;
139 135
           }

+ 2
- 4
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp View File

@@ -160,8 +160,7 @@
160 160
           return u8g_i2c_stop(), 0;
161 161
         {
162 162
           register uint8_t *ptr = (uint8_t *)arg_ptr;
163
-          while( arg_val > 0 )
164
-          {
163
+          while (arg_val > 0) {
165 164
             if ( u8g_i2c_send_byte(*ptr++) == 0 )
166 165
               return u8g_i2c_stop(), 0;
167 166
             arg_val--;
@@ -176,8 +175,7 @@
176 175
           return u8g_i2c_stop(), 0;
177 176
         {
178 177
           register uint8_t *ptr = (uint8_t *)arg_ptr;
179
-          while( arg_val > 0 )
180
-          {
178
+          while (arg_val > 0) {
181 179
             if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
182 180
               return 0;
183 181
             ptr++;

+ 2
- 4
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction View File

@@ -239,8 +239,7 @@ void u8g_i2c_init_sw(uint8_t clock_option) {
239 239
           return u8g_i2c_stop_sw(), 0;
240 240
         {
241 241
           register uint8_t *ptr = (uint8_t *)arg_ptr;
242
-          while( arg_val > 0 )
243
-          {
242
+          while (arg_val > 0) {
244 243
             if ( u8g_i2c_send_byte_sw(*ptr++) == 0 )
245 244
               return u8g_i2c_stop_sw(), 0;
246 245
             arg_val--;
@@ -255,8 +254,7 @@ void u8g_i2c_init_sw(uint8_t clock_option) {
255 254
           return u8g_i2c_stop_sw(), 0;
256 255
         {
257 256
           register uint8_t *ptr = (uint8_t *)arg_ptr;
258
-          while( arg_val > 0 )
259
-          {
257
+          while (arg_val > 0) {
260 258
             if ( u8g_i2c_send_byte_sw(u8g_pgm_read(ptr)) == 0 )
261 259
               return 0;
262 260
             ptr++;

+ 4
- 8
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp View File

@@ -136,22 +136,18 @@
136 136
         u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
137 137
         break;
138 138
 
139
-      case U8G_COM_MSG_WRITE_SEQ:
140
-        {
139
+      case U8G_COM_MSG_WRITE_SEQ: {
141 140
           uint8_t *ptr = (uint8_t*) arg_ptr;
142
-          while( arg_val > 0 )
143
-          {
141
+          while (arg_val > 0) {
144 142
             u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
145 143
             arg_val--;
146 144
           }
147 145
         }
148 146
         break;
149 147
 
150
-        case U8G_COM_MSG_WRITE_SEQ_P:
151
-        {
148
+        case U8G_COM_MSG_WRITE_SEQ_P: {
152 149
           uint8_t *ptr = (uint8_t*) arg_ptr;
153
-          while( arg_val > 0 )
154
-          {
150
+          while (arg_val > 0) {
155 151
             u8g_com_LPC1768_st7920_write_byte_hw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
156 152
             arg_val--;
157 153
           }

+ 4
- 8
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp View File

@@ -170,22 +170,18 @@
170 170
         u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
171 171
         break;
172 172
 
173
-      case U8G_COM_MSG_WRITE_SEQ:
174
-        {
173
+      case U8G_COM_MSG_WRITE_SEQ: {
175 174
           uint8_t *ptr = (uint8_t*) arg_ptr;
176
-          while( arg_val > 0 )
177
-          {
175
+          while (arg_val > 0) {
178 176
             u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
179 177
             arg_val--;
180 178
           }
181 179
         }
182 180
         break;
183 181
 
184
-        case U8G_COM_MSG_WRITE_SEQ_P:
185
-        {
182
+        case U8G_COM_MSG_WRITE_SEQ_P: {
186 183
           uint8_t *ptr = (uint8_t*) arg_ptr;
187
-          while( arg_val > 0 )
188
-          {
184
+          while (arg_val > 0) {
189 185
             u8g_com_LPC1768_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
190 186
             arg_val--;
191 187
           }

+ 4
- 8
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_sw_spi.cpp View File

@@ -150,22 +150,18 @@ uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
150 150
       u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
151 151
       break;
152 152
 
153
-    case U8G_COM_MSG_WRITE_SEQ:
154
-      {
153
+    case U8G_COM_MSG_WRITE_SEQ: {
155 154
         uint8_t *ptr = (uint8_t *)arg_ptr;
156
-        while( arg_val > 0 )
157
-        {
155
+        while (arg_val > 0) {
158 156
           u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
159 157
           arg_val--;
160 158
         }
161 159
       }
162 160
       break;
163 161
 
164
-      case U8G_COM_MSG_WRITE_SEQ_P:
165
-      {
162
+      case U8G_COM_MSG_WRITE_SEQ_P: {
166 163
         uint8_t *ptr = (uint8_t *)arg_ptr;
167
-        while( arg_val > 0 )
168
-        {
164
+        while (arg_val > 0) {
169 165
           u8g_sw_spi_HAL_LPC1768_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
170 166
           ptr++;
171 167
           arg_val--;

+ 3
- 6
Marlin/src/gcode/feature/trinamic/M122.cpp View File

@@ -110,8 +110,7 @@ static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
110 110
 #if ENABLED(HAVE_TMC2208)
111 111
   static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
112 112
     switch(i) {
113
-      case TMC_TSTEP:
114
-        {
113
+      case TMC_TSTEP: {
115 114
           uint32_t data = 0;
116 115
           st.TSTEP(&data);
117 116
           MYSERIAL.print(data);
@@ -159,14 +158,12 @@ static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const
159 158
     case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
160 159
 
161 160
     case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
162
-    case TMC_TPWMTHRS:
163
-      {
161
+    case TMC_TPWMTHRS: {
164 162
         uint32_t tpwmthrs_val = st.TPWMTHRS();
165 163
         SERIAL_ECHO(tpwmthrs_val);
166 164
       }
167 165
       break;
168
-    case TMC_TPWMTHRS_MMS:
169
-      {
166
+    case TMC_TPWMTHRS_MMS: {
170 167
         uint32_t tpwmthrs_val = st.TPWMTHRS();
171 168
         tpwmthrs_val ? SERIAL_ECHO(12650000UL * st.microsteps() / (256 * tpwmthrs_val * spmm)) : SERIAL_ECHO('-');
172 169
       }

+ 0
- 8
Marlin/src/lcd/dogm/HAL_LCD_class_defines.h View File

@@ -62,14 +62,6 @@ class U8GLIB_ST7920_128X64_RRD : public U8GLIB
62 62
 };
63 63
 
64 64
 
65
-extern u8g_dev_t u8g_dev_st7920_128x64_custom_sw_spi;
66
-class U8GLIB_ST7920_128X64_CUSTOM_SW_SPI : public U8GLIB {
67
-  public:
68
-    U8GLIB_ST7920_128X64_CUSTOM_SW_SPI()
69
-    : U8GLIB(&u8g_dev_st7920_128x64_custom_sw_spi)
70
-    {  }
71
-};
72
-
73 65
 extern u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire;
74 66
 class U8GLIB_SH1106_128X64_2X_I2C_2_WIRE : public U8GLIB {
75 67
   public:

+ 7
- 2
Marlin/src/lcd/dogm/HAL_LCD_com_defines.h View File

@@ -31,8 +31,13 @@
31 31
   uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
32 32
   #define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
33 33
 
34
-  uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
35
-  #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
34
+  #ifdef __SAM3X8E__
35
+    uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
36
+    #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_DUE_ST7920_sw_spi_fn
37
+  #else
38
+    uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
39
+    #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
40
+  #endif
36 41
 
37 42
   uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
38 43
   #define U8G_COM_ST7920_HAL_HW_SPI u8g_com_arduino_st7920_hw_spi_fn

+ 2
- 4
Marlin/src/lcd/dogm/u8g_dev_ssd1306_sh1106_128x64_I2C.cpp View File

@@ -128,8 +128,7 @@ uint8_t u8g_dev_sh1106_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
128 128
       break;
129 129
     case U8G_DEV_MSG_STOP:
130 130
       break;
131
-    case U8G_DEV_MSG_PAGE_NEXT:
132
-      {
131
+    case U8G_DEV_MSG_PAGE_NEXT: {
133 132
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
134 133
         u8g_SetAddress(u8g, dev, 0);           // instruction mode
135 134
         u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_data_start_2_wire);
@@ -202,8 +201,7 @@ uint8_t u8g_dev_ssd1306_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t
202 201
       break;
203 202
     case U8G_DEV_MSG_STOP:
204 203
       break;
205
-    case U8G_DEV_MSG_PAGE_NEXT:
206
-      {
204
+    case U8G_DEV_MSG_PAGE_NEXT: {
207 205
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
208 206
         u8g_SetAddress(u8g, dev, 0);           // instruction mode
209 207
         u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_data_start_2_wire);

+ 2
- 4
Marlin/src/lcd/dogm/u8g_dev_st7565_64128n_HAL.cpp View File

@@ -149,8 +149,7 @@ uint8_t u8g_dev_st7565_64128n_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
149 149
       break;
150 150
     case U8G_DEV_MSG_STOP:
151 151
       break;
152
-    case U8G_DEV_MSG_PAGE_NEXT:
153
-      {
152
+    case U8G_DEV_MSG_PAGE_NEXT: {
154 153
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
155 154
         u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
156 155
         u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
@@ -187,8 +186,7 @@ uint8_t u8g_dev_st7565_64128n_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
187 186
       break;
188 187
     case U8G_DEV_MSG_STOP:
189 188
       break;
190
-    case U8G_DEV_MSG_PAGE_NEXT:
191
-      {
189
+    case U8G_DEV_MSG_PAGE_NEXT: {
192 190
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
193 191
 
194 192
         u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);

+ 0
- 276
Marlin/src/lcd/dogm/u8g_dev_st7920_128_64_sw_spi.cpp View File

@@ -1,276 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
- *
8
- * This program is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-/*
24
- * PLEASE NOTE >>>
25
- *  We need our custom implementation for Software SPI, as the default implementation
26
- * of U8GLIB, when running in an ARM based board, is too fast and the display will not
27
- * recognize commands and/or data at such speeds. This implementation autoderives the
28
- * required delays to get the maximum possible performance by using the F_CPU macro that
29
- * specifies the CPU speed. According to the ST7920 datasheet, the maximum SCLK is 1MHz.
30
- */
31
-
32
-#ifndef ULCDST7920_SWSPI_H
33
-#define ULCDST7920_SWSPI_H
34
-
35
-#include "../../inc/MarlinConfig.h"
36
-
37
-#if ENABLED(U8GLIB_ST7920)
38
-
39
-#include <U8glib.h>
40
-#include "HAL_LCD_com_defines.h"
41
-
42
-#define ST7920_CLK_PIN  LCD_PINS_D4
43
-#define ST7920_DAT_PIN  LCD_PINS_ENABLE
44
-#define ST7920_CS_PIN   LCD_PINS_RS
45
-
46
-//#define PAGE_HEIGHT 8   //128 byte framebuffer
47
-#define PAGE_HEIGHT 16    //256 byte framebuffer
48
-//#define PAGE_HEIGHT 32  //512 byte framebuffer
49
-
50
-#define LCD_PIXEL_WIDTH 128
51
-#define LCD_PIXEL_HEIGHT 64
52
-
53
-//set optimization so ARDUINO optimizes this file
54
-#pragma GCC optimize (3)
55
-
56
-/* ---------------- Delay Cycles routine -------------- */
57
-
58
-#ifdef __arm__
59
-/* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */
60
-
61
-#define nop() __asm__ __volatile__("nop;\n\t":::)
62
-
63
-FORCE_INLINE static void __delay_4cycles(uint32_t cy) { // +1 cycle
64
-  #if ARCH_PIPELINE_RELOAD_CYCLES<2
65
-    #define EXTRA_NOP_CYCLES "nop"
66
-  #else
67
-    #define EXTRA_NOP_CYCLES ""
68
-  #endif
69
-
70
-  __asm__ __volatile__(
71
-    ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
72
-
73
-    "loop%=:" "\n\t"
74
-    " subs %[cnt],#1" "\n\t"
75
-    EXTRA_NOP_CYCLES "\n\t"
76
-    " bne loop%=" "\n\t"
77
-    : [cnt]"+r"(cy) // output: +r means input+output
78
-    : // input:
79
-    : "cc" // clobbers:
80
-  );
81
-}
82
-
83
-FORCE_INLINE static void DELAY_CYCLES(uint32_t x) {
84
-
85
-  if (__builtin_constant_p(x)) {
86
-
87
-    #define MAXNOPS 4
88
-
89
-    if (x <= (MAXNOPS)) {
90
-      switch(x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
91
-    }
92
-    else { // because of +1 cycle inside delay_4cycles
93
-      const uint32_t rem = (x - 1) % (MAXNOPS);
94
-      switch(rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
95
-      if ((x = (x - 1) / (MAXNOPS)))
96
-        __delay_4cycles(x); // if need more then 4 nop loop is more optimal
97
-    }
98
-  }
99
-  else
100
-    __delay_4cycles(x / 4);
101
-  }
102
-
103
-#ifdef __TEST_DELAY
104
-
105
-  void calibrateTimer() {
106
-
107
-    // Use DWT to calibrate cycles
108
-    uint32_t count = 0;
109
-
110
-    // addresses of registers
111
-    volatile uint32_t *DWT_CONTROL = (uint32_t *)0xE0001000,
112
-                      *DWT_CYCCNT = (uint32_t *)0xE0001004,
113
-                      *DEMCR = (uint32_t *)0xE000EDFC;
114
-
115
-    cli();
116
-
117
-    // enable the use DWT
118
-    *DEMCR = *DEMCR | 0x01000000;
119
-
120
-    // Reset cycle counter
121
-    *DWT_CYCCNT = 0;
122
-
123
-    // enable cycle counter
124
-    *DWT_CONTROL = *DWT_CONTROL | 1;
125
-
126
-    // Perform a delay of 10000 cycles
127
-    DELAY_CYCLES(10000U);
128
-
129
-    // number of cycles stored in count variable
130
-    count = *DWT_CYCCNT;
131
-
132
-    sei();
133
-
134
-    SERIAL_ECHO_START();
135
-    SERIAL_ECHOLNPAIR("calibrated Cycles: ", (int)count);
136
-  }
137
-
138
-#endif // __TEST_DELAY
139
-
140
-#elif defined(__AVR__)
141
-  #define DELAY_CYCLES(cycles) __builtin_avr_delay_cycles(cycles)
142
-#else
143
-  #error "DELAY_CYCLES not implemented for this architecture."
144
-#endif
145
-
146
-/* ---------------- Delay in nanoseconds and in microseconds */
147
-
148
-#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000) / 1000)
149
-#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU/1000000))
150
-
151
-/* ---------------- ST7920 commands ------------------------ */
152
-
153
-#ifdef __arm__
154
-
155
-  /* ARM: Plain implementation is more than enough */
156
-  static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
157
-    uint8_t n = 8;
158
-    do {
159
-      WRITE(ST7920_CLK_PIN, LOW);
160
-      WRITE(ST7920_DAT_PIN, val & 0x80);
161
-      DELAY_NS(700); /* RE-ARM requires 700ns to be stable, RAMPS4DUE works with 500ns */
162
-      WRITE(ST7920_CLK_PIN, HIGH);
163
-      DELAY_NS(700); /* RE-ARM requires 700ns to be stable, RAMPS4DUE works with 500ns */
164
-      val <<= 1;
165
-    } while (--n);
166
-  }
167
-
168
-#else // !ARM
169
-
170
-  /* AVR: Unrolling loop makes sense */
171
-  #define ST7920_SND_BIT(nr)              \
172
-    WRITE(ST7920_CLK_PIN, LOW);           \
173
-    WRITE(ST7920_DAT_PIN, TEST(val, nr)); \
174
-    DELAY_NS(700);                        \
175
-    WRITE(ST7920_CLK_PIN, HIGH);          \
176
-    DELAY_NS(700);
177
-
178
-  static void ST7920_SWSPI_SND_8BIT(const uint8_t val) {
179
-    ST7920_SND_BIT(7); // MSBit
180
-    ST7920_SND_BIT(6); //
181
-    ST7920_SND_BIT(5); //
182
-    ST7920_SND_BIT(4); //
183
-    ST7920_SND_BIT(3); //
184
-    ST7920_SND_BIT(2); //
185
-    ST7920_SND_BIT(1); //
186
-    ST7920_SND_BIT(0); // LSBit
187
-  }
188
-
189
-#endif // !ARM
190
-
191
-#define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); DELAY_NS(200); }
192
-#define ST7920_NCS()             { WRITE(ST7920_CS_PIN,0); }
193
-#define ST7920_SET_CMD()         { ST7920_SWSPI_SND_8BIT(0xF8); DELAY_US(3); }
194
-#define ST7920_SET_DAT()         { ST7920_SWSPI_SND_8BIT(0xFA); DELAY_US(3); }
195
-#define ST7920_WRITE_BYTE(a)     { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); DELAY_US(3); }
196
-#define ST7920_WRITE_BYTES(p,l)  { for (uint8_t i = l + 1; --i;) { ST7920_SWSPI_SND_8BIT(*p&0xF0); ST7920_SWSPI_SND_8BIT(*p<<4); p++; } DELAY_US(3); }
197
-
198
-
199
-uint8_t u8g_dev_st7920_custom_sw_spi_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
200
-
201
-  uint8_t i, y;
202
-  switch (msg) {
203
-    case U8G_DEV_MSG_INIT: {
204
-
205
-      /* Set to output and write */
206
-      OUT_WRITE(ST7920_CS_PIN, LOW);
207
-      OUT_WRITE(ST7920_DAT_PIN, LOW);
208
-      OUT_WRITE(ST7920_CLK_PIN, HIGH);
209
-
210
-      ST7920_CS();
211
-      u8g_Delay(120);                //initial delay for boot up
212
-
213
-      ST7920_SET_CMD();
214
-      ST7920_WRITE_BYTE(0x08);       //display off, cursor+blink off
215
-      ST7920_WRITE_BYTE(0x01);       //clear CGRAM ram
216
-      u8g_Delay(15);                 //delay for CGRAM clear
217
-      ST7920_WRITE_BYTE(0x3E);       //extended mode + GDRAM active
218
-      for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM
219
-        ST7920_WRITE_BYTE(0x80 | y); //set y
220
-        ST7920_WRITE_BYTE(0x80);     //set x = 0
221
-        ST7920_SET_DAT();
222
-        for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) //2x width clears both segments
223
-          ST7920_WRITE_BYTE(0);
224
-        ST7920_SET_CMD();
225
-      }
226
-
227
-      ST7920_WRITE_BYTE(0x0C);       //display on, cursor+blink off
228
-      ST7920_NCS();
229
-    }
230
-    break;
231
-
232
-    case U8G_DEV_MSG_STOP:
233
-      break;
234
-
235
-    case U8G_DEV_MSG_PAGE_NEXT: {
236
-      u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
237
-      y = pb->p.page_y0;
238
-      uint8_t* ptr = (uint8_t*)pb->buf;
239
-
240
-      ST7920_CS();
241
-      for (i = 0; i < PAGE_HEIGHT; i ++) {
242
-        ST7920_SET_CMD();
243
-        if (y < 32) {
244
-          ST7920_WRITE_BYTE(0x80 | y);   //y
245
-          ST7920_WRITE_BYTE(0x80);       //x=0
246
-        }
247
-        else {
248
-          ST7920_WRITE_BYTE(0x80 | (y - 32)); //y
249
-          ST7920_WRITE_BYTE(0x80 | 8);   //x=64
250
-        }
251
-        ST7920_SET_DAT();
252
-        ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
253
-        y++;
254
-      }
255
-
256
-      ST7920_NCS();
257
-    }
258
-    break;
259
-  }
260
-  #if PAGE_HEIGHT == 8
261
-    return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
262
-  #elif PAGE_HEIGHT == 16
263
-    return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
264
-  #else
265
-    return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
266
-  #endif
267
-}
268
-
269
-static uint8_t   u8g_dev_st7920_128x64_custom_sw_spi_buf[(LCD_PIXEL_WIDTH) * (PAGE_HEIGHT) / 8] U8G_NOCOMMON;
270
-static u8g_pb_t  u8g_dev_st7920_128x64_custom_sw_spi_pb = {{PAGE_HEIGHT, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7920_128x64_custom_sw_spi_buf};
271
-u8g_dev_t u8g_dev_st7920_128x64_custom_sw_spi = {u8g_dev_st7920_custom_sw_spi_128x64_fn, &u8g_dev_st7920_128x64_custom_sw_spi_pb, &u8g_com_null_fn};
272
-
273
-#pragma GCC reset_options
274
-
275
-#endif // U8GLIB_ST7920
276
-#endif // ULCDST7920_SWSPI_H

+ 3
- 5
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp View File

@@ -99,8 +99,7 @@ uint8_t u8g_dev_st7920_128x64_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
99 99
       break;
100 100
     case U8G_DEV_MSG_STOP:
101 101
       break;
102
-    case U8G_DEV_MSG_PAGE_NEXT:
103
-      {
102
+    case U8G_DEV_MSG_PAGE_NEXT: {
104 103
         uint8_t y, i;
105 104
         uint8_t *ptr;
106 105
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
@@ -149,8 +148,7 @@ uint8_t u8g_dev_st7920_128x64_HAL_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
149 148
     case U8G_DEV_MSG_STOP:
150 149
       break;
151 150
 
152
-    case U8G_DEV_MSG_PAGE_NEXT:
153
-      {
151
+    case U8G_DEV_MSG_PAGE_NEXT: {
154 152
         uint8_t y, i;
155 153
         uint8_t *ptr;
156 154
         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
@@ -199,7 +197,7 @@ U8G_PB_DEV(u8g_dev_st7920_128x64_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev
199 197
 u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_hw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_HW_SPI };
200 198
 
201 199
 
202
-#ifdef U8G_HAL_LINKS
200
+#if defined(U8G_HAL_LINKS) || defined(__SAM3X8E__)
203 201
   // Also use this device for HAL version of rrd class. This results in the same device being used
204 202
   // for the ST7920 for HAL systems no matter what is selected in ultralcd_impl_DOGM.h.
205 203
   u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_SW_SPI };

+ 1
- 1
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp View File

@@ -27,7 +27,7 @@
27 27
 
28 28
 #if ENABLED(U8GLIB_ST7920)
29 29
 
30
-#ifndef U8G_HAL_LINKS
30
+#if !(defined(U8G_HAL_LINKS) || defined(__SAM3X8E__))
31 31
 
32 32
 #define ST7920_CLK_PIN  LCD_PINS_D4
33 33
 #define ST7920_DAT_PIN  LCD_PINS_ENABLE

+ 1
- 3
Marlin/src/lcd/ultralcd_impl_DOGM.h View File

@@ -169,9 +169,6 @@
169 169
   #else
170 170
     U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes, HW SPI (shared with SD card)
171 171
   #endif
172
-#elif ENABLED(U8GLIB_ST7920) && defined(__arm__)
173
-  // RepRap Discount Full Graphics Smart Controller on an ARM target
174
-    U8GLIB_ST7920_128X64_CUSTOM_SW_SPI u8g;
175 172
 
176 173
 #elif ENABLED(U8GLIB_ST7920)
177 174
   // RepRap Discount Full Graphics Smart Controller
@@ -190,6 +187,7 @@
190 187
   // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
191 188
     //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes
192 189
     U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
190
+    
193 191
 #elif ENABLED(U8GLIB_ST7565_64128N)
194 192
   // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller
195 193
     //U8GLIB_64128N_2X_HAL u8g(DOGLCD_CS, DOGLCD_A0);  // using HW-SPI

+ 1
- 0
platformio.ini View File

@@ -95,6 +95,7 @@ framework   = arduino
95 95
 board       = due
96 96
 build_flags = ${common.build_flags} -I $BUILDSRC_DIR
97 97
 lib_deps    = ${common.lib_deps}
98
+lib_ignore  = TMC26XStepper
98 99
 src_filter  = ${common.default_src_filter}
99 100
 
100 101
 #

Loading…
Cancel
Save