Browse Source

M355 S0, S1 fixes & faster LCD, SD card

fix Travis error
Christopher Pepper 7 years ago
parent
commit
bea3ec2724

+ 3
- 0
.gitignore View File

@@ -158,6 +158,9 @@ src/.vs/
158 158
 #Visual Studio Code
159 159
 .vscode
160 160
 
161
+#Visual Studio Code
162
+.vscode
163
+
161 164
 #cmake
162 165
 CMakeLists.txt
163 166
 src/CMakeLists.txt

+ 2
- 1
Marlin/Configuration.h View File

@@ -1233,8 +1233,9 @@
1233 1233
  * SD CARD: SPI SPEED
1234 1234
  *
1235 1235
  * Enable one of the following items for a slower SPI transfer speed.
1236
- * This may be required to resolve "volume init" errors.
1236
+ * This may be required to resolve "volume init" errors or LCD issues.
1237 1237
  */
1238
+ 
1238 1239
 //#define SPI_SPEED SPI_HALF_SPEED
1239 1240
 //#define SPI_SPEED SPI_QUARTER_SPEED
1240 1241
 //#define SPI_SPEED SPI_EIGHTH_SPEED

+ 1
- 47
Marlin/src/HAL/HAL.h View File

@@ -29,53 +29,7 @@
29 29
 #ifndef _HAL_H
30 30
 #define _HAL_H
31 31
 
32
-#include <stdint.h>
33
-
34
-/**
35
- * SPI speed where 0 <= index <= 6
36
- *
37
- * Approximate rates :
38
- *
39
- *  0 :  8 - 10 MHz
40
- *  1 :  4 - 5 MHz
41
- *  2 :  2 - 2.5 MHz
42
- *  3 :  1 - 1.25 MHz
43
- *  4 :  500 - 625 kHz
44
- *  5 :  250 - 312 kHz
45
- *  6 :  125 - 156 kHz
46
- *
47
- *  On AVR, actual speed is F_CPU/2^(1 + index).
48
- *  On other platforms, speed should be in range given above where possible.
49
- */
50
-
51
-/** Set SCK to max rate */
52
-uint8_t const SPI_FULL_SPEED = 0;
53
-/** Set SCK rate to half max rate. */
54
-uint8_t const SPI_HALF_SPEED = 1;
55
-/** Set SCK rate to quarter max rate. */
56
-uint8_t const SPI_QUARTER_SPEED = 2;
57
-/** Set SCK rate to 1/8 max rate. */
58
-uint8_t const SPI_EIGHTH_SPEED = 3;
59
-/** Set SCK rate to 1/16 of max rate. */
60
-uint8_t const SPI_SIXTEENTH_SPEED = 4;
61
-/** Set SCK rate to 1/32 of max rate. */
62
-uint8_t const SPI_SPEED_5 = 5;
63
-/** Set SCK rate to 1/64 of max rate. */
64
-uint8_t const SPI_SPEED_6 = 6;
65
-
66
-// Standard SPI functions
67
-/** Initialise SPI bus */
68
-void spiBegin(void);
69
-/** Configure SPI for specified SPI speed */
70
-void spiInit(uint8_t spiRate);
71
-/** Write single byte to SPI */
72
-void spiSend(uint8_t b);
73
-/** Read single byte from SPI */
74
-uint8_t spiRec(void);
75
-/** Read from SPI into buffer */
76
-void spiRead(uint8_t* buf, uint16_t nbyte);
77
-/** Write token and then write from 512 byte buffer to SPI (for SD card) */
78
-void spiSendBlock(uint8_t token, const uint8_t* buf);
32
+#include "src/inc/SPI.h"
79 33
 
80 34
 #ifdef __AVR__
81 35
   #include "HAL_AVR/HAL_AVR.h"

+ 165
- 37
Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp View File

@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 4
  *
5 5
  * Based on Sprinter and grbl.
6 6
  * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
@@ -30,13 +30,32 @@
30 30
  * For TARGET_LPC1768
31 31
  */
32 32
 
33
+/**
34
+ * Hardware SPI and a software SPI implementations are included in this file.
35
+ * The hardware SPI runs faster and has higher throughput but is not compatible
36
+ * with some LCD interfaces/adapters.
37
+ *
38
+ * Control of the slave select pin(s) is handled by the calling routines.
39
+ *
40
+ * Some of the LCD interfaces/adapters result in the LCD SPI and the SD card
41
+ * SPI sharing pins. The SCK, MOSI & MISO pins can NOT be set/cleared with
42
+ * WRITE nor digitalWrite when the hardware SPI module within the LPC17xx is
43
+ * active.  If any of these pins are shared then the software SPI must be used.
44
+ *
45
+ * A more sophisticated hardware SPI can be found at the following link.  This
46
+ * implementation has not been fully debugged.
47
+ * https://github.com/MarlinFirmware/Marlin/tree/071c7a78f27078fd4aee9a3ef365fcf5e143531e
48
+ */
49
+
33 50
 #ifdef TARGET_LPC1768
34 51
 
35 52
 // --------------------------------------------------------------------------
36 53
 // Includes
37 54
 // --------------------------------------------------------------------------
38 55
 
39
-#include "../../inc/MarlinConfig.h"
56
+//#include "../../../MarlinConfig.h"  //works except in U8g
57
+#include "spi_pins.h"
58
+#include "fastio.h"
40 59
 
41 60
 // --------------------------------------------------------------------------
42 61
 // Public Variables
@@ -47,87 +66,122 @@
47 66
 // Public functions
48 67
 // --------------------------------------------------------------------------
49 68
 
50
-#if ENABLED(SOFTWARE_SPI)
69
+#if ENABLED(LPC_SOFTWARE_SPI)
51 70
   // --------------------------------------------------------------------------
52 71
   // software SPI
53 72
   // --------------------------------------------------------------------------
54
-  // bitbanging transfer
55
-  // run at ~100KHz (necessary for init)
56
-  static uint8_t spiTransfer(uint8_t b) { // using Mode 0
57
-    for (int bits = 0; bits < 8; bits++) {
58
-      if (b & 0x80) {
59
-        WRITE(MOSI_PIN, HIGH);
60
-      }
61
-      else {
62
-        WRITE(MOSI_PIN, LOW);
73
+
74
+  /**
75
+   * This software SPI runs at three rates. The SD software provides an index
76
+   * (spiRate) of 0-6. The mapping is:
77
+   *     0-1 - about 5 MHz peak
78
+   *     2-3 - about 2 MHz peak
79
+   *     all others - about 250 KHz
80
+   */
81
+
82
+  static uint8_t SPI_speed = 0;
83
+
84
+  static uint8_t spiTransfer(uint8_t b) {
85
+
86
+    if (!SPI_speed) {       // fastest - about 5 MHz peak
87
+      for (int bits = 0; bits < 8; bits++) {
88
+        if (b & 0x80) {
89
+          WRITE(MOSI_PIN, HIGH);
90
+          WRITE(MOSI_PIN, HIGH);  // delay to (hopefully) guarantee setup time
91
+        }
92
+        else {
93
+          WRITE(MOSI_PIN, LOW);
94
+          WRITE(MOSI_PIN, LOW);  // delay to (hopefully) guarantee setup time
95
+        }
96
+        b <<= 1;
97
+        WRITE(SCK_PIN, HIGH);
98
+        if (READ(MISO_PIN)) {
99
+          b |= 1;
100
+        }
101
+        WRITE(SCK_PIN, LOW);
63 102
       }
64
-      b <<= 1;
103
+    }
104
+    else if (SPI_speed == 1) { // medium - about 1 MHz
105
+      for (int bits = 0; bits < 8; bits++) {
106
+        if (b & 0x80) {
107
+          for (uint8_t i = 0; i < 8; i++) WRITE(MOSI_PIN, HIGH);
108
+        }
109
+        else {
110
+          for (uint8_t i = 0; i < 8; i++) WRITE(MOSI_PIN, LOW);
111
+        }
112
+        b <<= 1;
113
+
114
+        for (uint8_t i = 0; i < 6; i++) WRITE(SCK_PIN, HIGH);
65 115
 
66
-      WRITE(SCK_PIN, HIGH);
67
-      delayMicroseconds(3U);
116
+        if (READ(MISO_PIN)) {
117
+          b |= 1;
118
+        }
119
+        WRITE(SCK_PIN, LOW);
120
+      }
121
+    }
122
+    else { // slow - about 250 KHz
123
+      for (int bits = 0; bits < 8; bits++) {
124
+        if (b & 0x80) {
125
+          WRITE(MOSI_PIN, HIGH);
126
+        }
127
+        else {
128
+          WRITE(MOSI_PIN, LOW);
129
+        }
130
+        b <<= 1;
131
+        delayMicroseconds(1U);
132
+        WRITE(SCK_PIN, HIGH);
133
+        delayMicroseconds(2U);
68 134
 
69
-      if (READ(MISO_PIN)) {
70
-        b |= 1;
135
+        if (READ(MISO_PIN)) {
136
+          b |= 1;
137
+        }
138
+        WRITE(SCK_PIN, LOW);
139
+        delayMicroseconds(1U);
71 140
       }
72
-      WRITE(SCK_PIN, LOW);
73
-      delayMicroseconds(3U);
74 141
     }
75 142
     return b;
76 143
   }
77 144
 
78 145
   void spiBegin() {
79
-    SET_OUTPUT(SS_PIN);
80
-    WRITE(SS_PIN, HIGH);
81 146
     SET_OUTPUT(SCK_PIN);
82 147
     SET_INPUT(MISO_PIN);
83 148
     SET_OUTPUT(MOSI_PIN);
84 149
   }
85 150
 
86 151
   void spiInit(uint8_t spiRate) {
87
-    UNUSED(spiRate);
88
-    WRITE(SS_PIN, HIGH);
152
+    SPI_speed = spiRate >> 1;
89 153
     WRITE(MOSI_PIN, HIGH);
90 154
     WRITE(SCK_PIN, LOW);
91 155
   }
92 156
 
93 157
   uint8_t spiRec() {
94
-    WRITE(SS_PIN, LOW);
95 158
     uint8_t b = spiTransfer(0xff);
96
-    WRITE(SS_PIN, HIGH);
97 159
     return b;
98 160
   }
99 161
 
100 162
   void spiRead(uint8_t*buf, uint16_t nbyte) {
101 163
     if (nbyte == 0) return;
102
-    WRITE(SS_PIN, LOW);
103 164
     for (int i = 0; i < nbyte; i++) {
104 165
       buf[i] = spiTransfer(0xff);
105 166
     }
106
-    WRITE(SS_PIN, HIGH);
107 167
   }
108 168
 
109 169
   void spiSend(uint8_t b) {
110
-    WRITE(SS_PIN, LOW);
111 170
     uint8_t response = spiTransfer(b);
112 171
     UNUSED(response);
113
-    WRITE(SS_PIN, HIGH);
114 172
   }
115 173
 
116 174
   static void spiSend(const uint8_t* buf, size_t n) {
117 175
     uint8_t response;
118 176
     if (n == 0) return;
119
-    WRITE(SS_PIN, LOW);
120 177
     for (uint16_t i = 0; i < n; i++) {
121 178
       response = spiTransfer(buf[i]);
122 179
     }
123 180
     UNUSED(response);
124
-    WRITE(SS_PIN, HIGH);
125 181
   }
126 182
 
127 183
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
128 184
     uint8_t response;
129
-
130
-    WRITE(SS_PIN, LOW);
131 185
     response = spiTransfer(token);
132 186
 
133 187
     for (uint16_t i = 0; i < 512; i++) {
@@ -136,29 +190,97 @@
136 190
     UNUSED(response);
137 191
     WRITE(SS_PIN, HIGH);
138 192
   }
193
+
139 194
 #else
140
-  void spiBegin() {
195
+
196
+  // hardware SPI
197
+
198
+  #include <lpc17xx_pinsel.h>
199
+  #include <lpc17xx_ssp.h>
200
+  #include <lpc17xx_clkpwr.h>
201
+
202
+  void spiBegin() {  // setup SCK, MOSI & MISO pins for SSP0
203
+
204
+    PINSEL_CFG_Type PinCfg;  // data structure to hold init values
205
+    PinCfg.Funcnum = 2;
206
+    PinCfg.OpenDrain = 0;
207
+    PinCfg.Pinmode = 0;
208
+    PinCfg.Pinnum = pin_map[SCK_PIN].pin;
209
+    PinCfg.Portnum = pin_map[SCK_PIN].port;
210
+    PINSEL_ConfigPin(&PinCfg);
211
+    SET_OUTPUT(SCK_PIN);
212
+
213
+    PinCfg.Pinnum = pin_map[MISO_PIN].pin;
214
+    PinCfg.Portnum = pin_map[MISO_PIN].port;
215
+    PINSEL_ConfigPin(&PinCfg);
216
+    SET_INPUT(MISO_PIN);
217
+
218
+    PinCfg.Pinnum = pin_map[MOSI_PIN].pin;
219
+    PinCfg.Portnum = pin_map[MOSI_PIN].port;
220
+    PINSEL_ConfigPin(&PinCfg);
221
+    SET_OUTPUT(MOSI_PIN);
141 222
   }
142 223
 
224
+
143 225
   void spiInit(uint8_t spiRate) {
226
+
227
+   // table to convert Marlin spiRates (0-5 plus default) into bit rates
228
+    uint32_t Marlin_speed[7]; // CPSR is always 2
229
+    Marlin_speed[0] = 8333333; //(SCR:  2)  desired: 8,000,000  actual: 8,333,333  +4.2%  SPI_FULL_SPEED
230
+    Marlin_speed[1] = 4166667; //(SCR:  5)  desired: 4,000,000  actual: 4,166,667  +4.2%  SPI_HALF_SPEED
231
+    Marlin_speed[2] = 2083333; //(SCR: 11)  desired: 2,000,000  actual: 2,083,333  +4.2%  SPI_QUARTER_SPEED
232
+    Marlin_speed[3] = 1000000; //(SCR: 24)  desired: 1,000,000  actual: 1,000,000         SPI_EIGHTH_SPEED
233
+    Marlin_speed[4] =  500000; //(SCR: 49)  desired:   500,000  actual:   500,000         SPI_SPEED_5
234
+    Marlin_speed[5] =  250000; //(SCR: 99)  desired:   250,000  actual:   250,000         SPI_SPEED_6
235
+    Marlin_speed[6] =  125000; //(SCR:199)  desired:   125,000  actual:   125,000         Default from HAL.h
236
+
237
+
238
+   // select 50MHz PCLK for SSP0
239
+    CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_SSP0, CLKPWR_PCLKSEL_CCLK_DIV_2);
240
+
241
+   // setup for SPI mode
242
+    SSP_CFG_Type HW_SPI_init; // data structure to hold init values
243
+    SSP_ConfigStructInit(&HW_SPI_init);  // set values for SPI mode
244
+    HW_SPI_init.ClockRate = Marlin_speed[MIN(spiRate, 6)]; // put in the specified bit rate
245
+    SSP_Init(LPC_SSP0, &HW_SPI_init);  // puts the values into the proper bits in the SSP0 registers
246
+
247
+    SSP_Cmd(LPC_SSP0, ENABLE);  // start SSP0 running
144 248
   }
145 249
 
146
-  void spiSend(byte b) {
250
+  void spiSend(uint8_t b) {
251
+    while (!SSP_GetStatus(LPC_SSP0, SSP_STAT_TXFIFO_NOTFULL));   // wait for room in the buffer
252
+    SSP_SendData(LPC_SSP0, b & 0x00FF);
253
+    while (SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY));  // wait for it to finish
147 254
   }
148 255
 
256
+
149 257
   void spiSend(const uint8_t* buf, size_t n) {
258
+    if (n == 0) return;
259
+    for (uint16_t i = 0; i < n; i++) {
260
+      while (!SSP_GetStatus(LPC_SSP0, SSP_STAT_TXFIFO_NOTFULL));   // wait for room in the buffer
261
+      SSP_SendData(LPC_SSP0, buf[i] & 0x00FF);
262
+    }
263
+    while (SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY));  // wait for it to finish
150 264
   }
151 265
 
152 266
   void spiSend(uint32_t chan, byte b) {
153 267
   }
154 268
 
155 269
   void spiSend(uint32_t chan, const uint8_t* buf, size_t n) {
270
+  }
156 271
 
272
+
273
+  uint8_t get_one_byte() {
274
+   // send a dummy byte so can clock in receive data
275
+    SSP_SendData(LPC_SSP0,0x00FF);
276
+    while (SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY));  // wait for it to finish
277
+    return SSP_ReceiveData(LPC_SSP0) & 0x00FF;
157 278
   }
158 279
 
159 280
   // Read single byte from SPI
160 281
   uint8_t spiRec() {
161
-    return 0;
282
+    while (SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY) || SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY)) SSP_ReceiveData(LPC_SSP0);  //flush the receive buffer
283
+    return get_one_byte();
162 284
   }
163 285
 
164 286
   uint8_t spiRec(uint32_t chan) {
@@ -167,11 +289,17 @@
167 289
 
168 290
   // Read from SPI into buffer
169 291
   void spiRead(uint8_t*buf, uint16_t nbyte) {
292
+    while (SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY) || SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY)) SSP_ReceiveData(LPC_SSP0);  //flush the receive buffer
293
+    if (nbyte == 0) return;
294
+    for (int i = 0; i < nbyte; i++) {
295
+      buf[i] = get_one_byte();
296
+    }
170 297
   }
171 298
 
172 299
   // Write from buffer to SPI
173 300
   void spiSendBlock(uint8_t token, const uint8_t* buf) {
174 301
   }
175
-#endif // ENABLED(SOFTWARE_SPI)
302
+#endif // ENABLED(LPC_SOFTWARE_SPI)
176 303
 
177 304
 #endif // TARGET_LPC1768
305
+

+ 10
- 0
Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.h View File

@@ -399,6 +399,16 @@ bool LPC1768_PWM_detach_pin(uint8_t pin) {
399 399
   return 1;
400 400
 }
401 401
 
402
+
403
+bool useable_hardware_PWM(uint8_t pin) {
404
+  COPY_ACTIVE_TABLE;  // copy active table into work table
405
+  for (uint8_t i = 0; i < NUM_PWMS; i++)         // see if it's already setup
406
+    if (work_table[i].logical_pin == pin && work_table[i].sequence) return true;
407
+  for (uint8_t i = 0; i < NUM_PWMS; i++)         // see if there is an empty slot
408
+    if (!work_table[i].sequence) return true;
409
+  return false;    // only get here if neither the above are true
410
+}
411
+
402 412
 ////////////////////////////////////////////////////////////////////////////////
403 413
 
404 414
 #define HAL_PWM_LPC1768_ISR  extern "C" void PWM1_IRQHandler(void)

+ 3
- 0
Marlin/src/HAL/HAL_LPC1768/fastio.h View File

@@ -38,6 +38,9 @@
38 38
 #include "arduino.h"
39 39
 #include "pinmapping.h"
40 40
 
41
+bool useable_hardware_PWM(uint8_t pin);
42
+#define USEABLE_HARDWARE_PWM(pin) useable_hardware_PWM(pin)
43
+
41 44
 #define LPC_PORT_OFFSET         (0x0020)
42 45
 #define LPC_PIN(pin)            (1UL << pin)
43 46
 #define LPC_GPIO(port)          ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))

+ 8
- 1
Marlin/src/HAL/HAL_LPC1768/spi_pins.h View File

@@ -23,7 +23,8 @@
23 23
 #ifndef SPI_PINS_LPC1768_H
24 24
 #define SPI_PINS_LPC1768_H
25 25
 
26
-#define SOFTWARE_SPI
26
+#define LPC_SOFTWARE_SPI
27
+
27 28
 /** onboard SD card */
28 29
 //#define SCK_PIN           P0_7
29 30
 //#define MISO_PIN          P0_8
@@ -34,4 +35,10 @@
34 35
 #define MISO_PIN          50 //P0_17
35 36
 #define MOSI_PIN          51 //P0_18
36 37
 #define SS_PIN            53 //P1_23
38
+#define SDSS              SS_PIN
39
+
40
+#if (defined(IS_REARM) && !(defined(LPC_SOFTWARE_SPI)))   // signal LCDs that they need to use the hardware SPI
41
+  #define SHARED_SPI
42
+#endif
43
+
37 44
 #endif /* SPI_PINS_LPC1768_H */

+ 20
- 1
Marlin/src/feature/caselight.cpp View File

@@ -27,19 +27,38 @@
27 27
 uint8_t case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
28 28
 bool case_light_on = CASE_LIGHT_DEFAULT_ON;
29 29
 
30
+/**
31
+ * The following are needed because ARM chips ignore a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that
32
+ * are directly controlled by the PWM module. In order to turn them off the brightness level needs to be
33
+ * set to off.  Since we can't use the pwm register to save the last brightness level we need a variable
34
+ * to save it.
35
+ */
36
+uint8_t case_light_brightness_sav;   // saves brighness info so can restore when "M355 S1" received
37
+bool case_light_arg_flag;  // flag to notify if S or P arguement type
38
+
30 39
 #ifndef INVERT_CASE_LIGHT
31 40
   #define INVERT_CASE_LIGHT false
32 41
 #endif
33 42
 
34 43
 void update_case_light() {
35 44
   SET_OUTPUT(CASE_LIGHT_PIN);
45
+
46
+  if (!(case_light_arg_flag && !case_light_on))
47
+    case_light_brightness_sav = case_light_brightness;  // save brightness except if this is an S0 arguement
48
+  if (case_light_arg_flag && case_light_on)
49
+    case_light_brightness = case_light_brightness_sav;  // restore last brightens if this is an S1 arguement
50
+
36 51
   if (case_light_on) {
37 52
     if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
38 53
       analogWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? 255 - case_light_brightness : case_light_brightness );
39 54
     }
40 55
     else WRITE(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? LOW : HIGH);
41 56
   }
42
-  else WRITE(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? HIGH : LOW);
57
+  else {
58
+    if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN))
59
+      analogWrite(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? 255 : 0 );  // turn the light off
60
+    WRITE(CASE_LIGHT_PIN, INVERT_CASE_LIGHT ? HIGH : LOW);
61
+  }
43 62
 }
44 63
 
45 64
 #endif // HAS_CASE_LIGHT

+ 2
- 0
Marlin/src/feature/caselight.h View File

@@ -25,6 +25,8 @@
25 25
 
26 26
 extern uint8_t case_light_brightness;
27 27
 extern bool case_light_on;
28
+extern uint8_t case_light_brightness_sav;   // saves brighness info when case_light_on is false
29
+extern bool case_light_arg_flag;  // flag to notify if S or P arguement type
28 30
 
29 31
 void update_case_light();
30 32
 

+ 8
- 2
Marlin/src/gcode/feature/caselight/M355.cpp View File

@@ -43,8 +43,14 @@
43 43
 void GcodeSuite::M355() {
44 44
   #if HAS_CASE_LIGHT
45 45
     uint8_t args = 0;
46
-    if (parser.seenval('P')) ++args, case_light_brightness = parser.value_byte();
47
-    if (parser.seenval('S')) ++args, case_light_on = parser.value_bool();
46
+    if (parser.seenval('P')) {
47
+      ++args, case_light_brightness = parser.value_byte();
48
+      case_light_arg_flag = false;
49
+    }  
50
+    if (parser.seenval('S')) {
51
+      ++args, case_light_on = parser.value_bool();
52
+      case_light_arg_flag = true;
53
+    }
48 54
     if (args) update_case_light();
49 55
 
50 56
     // always report case light status

+ 1
- 0
Marlin/src/inc/MarlinConfig.h View File

@@ -26,6 +26,7 @@
26 26
 #include "../core/boards.h"
27 27
 #include "../core/macros.h"
28 28
 #include "Version.h"
29
+#include "SPI.h"
29 30
 #include "../../Configuration.h"
30 31
 #include "Conditionals_LCD.h"
31 32
 #include "../../Configuration_adv.h"

+ 52
- 0
Marlin/src/inc/SPI.h View File

@@ -0,0 +1,52 @@
1
+#include <stdint.h>
2
+
3
+
4
+#if !defined(SPI_FULL_SPEED)
5
+
6
+/**
7
+ * SPI speed where 0 <= index <= 6
8
+ *
9
+ * Approximate rates :
10
+ *
11
+ *  0 :  8 - 10 MHz
12
+ *  1 :  4 - 5 MHz
13
+ *  2 :  2 - 2.5 MHz
14
+ *  3 :  1 - 1.25 MHz
15
+ *  4 :  500 - 625 kHz
16
+ *  5 :  250 - 312 kHz
17
+ *  6 :  125 - 156 kHz
18
+ *
19
+ *  On AVR, actual speed is F_CPU/2^(1 + index).
20
+ *  On other platforms, speed should be in range given above where possible.
21
+ */
22
+
23
+/** Set SCK to max rate */
24
+#define SPI_FULL_SPEED 0
25
+/** Set SCK rate to half max rate. */
26
+#define SPI_HALF_SPEED 1
27
+/** Set SCK rate to quarter max rate. */
28
+#define SPI_QUARTER_SPEED 2
29
+/** Set SCK rate to 1/8 max rate. */
30
+#define SPI_EIGHTH_SPEED 3
31
+/** Set SCK rate to 1/16 of max rate. */
32
+#define SPI_SIXTEENTH_SPEED 4
33
+/** Set SCK rate to 1/32 of max rate. */
34
+#define SPI_SPEED_5 5
35
+/** Set SCK rate to 1/64 of max rate. */
36
+#define SPI_SPEED_6 6
37
+
38
+// Standard SPI functions
39
+/** Initialise SPI bus */
40
+void spiBegin(void);
41
+/** Configure SPI for specified SPI speed */
42
+void spiInit(uint8_t spiRate);
43
+/** Write single byte to SPI */
44
+void spiSend(uint8_t b);
45
+/** Read single byte from SPI */
46
+uint8_t spiRec(void);
47
+/** Read from SPI into buffer */
48
+void spiRead(uint8_t* buf, uint16_t nbyte);
49
+/** Write token and then write from 512 byte buffer to SPI (for SD card) */
50
+void spiSendBlock(uint8_t token, const uint8_t* buf);
51
+
52
+#endif

+ 127
- 100
Marlin/src/lcd/dogm/ultralcd_st7565_u8glib_VIKI.h View File

@@ -23,20 +23,21 @@
23 23
 #ifndef ULCDST7565_H
24 24
 #define ULCDST7565_H
25 25
 
26
-#include "../../inc/MarlinConfig.h"
26
+#include <src/Marlin.h>
27
+
28
+#if ENABLED(U8GLIB_ST7565_64128N)
27 29
 
28
-#if !( defined(DOGLCD_SCK) && DOGLCD_SCK >= 0 \
29
-    && defined(DOGLCD_MOSI) && DOGLCD_MOSI >= 0 \
30
-    && defined(DOGLCD_CS) && DOGLCD_CS >= 0 \
31
-    && defined(DOGLCD_A0) && DOGLCD_A0 >= 0 )
32
-  #error "DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, and DOGLCD_A0 are required for VIKI."
33
-#endif
34 30
 
35 31
 #define ST7565_CLK_PIN  DOGLCD_SCK
36 32
 #define ST7565_DAT_PIN  DOGLCD_MOSI
37 33
 #define ST7565_CS_PIN   DOGLCD_CS
38 34
 #define ST7565_A0_PIN   DOGLCD_A0
39 35
 
36
+
37
+
38
+
39
+
40
+
40 41
 #include <U8glib.h>
41 42
 
42 43
 #define WIDTH 128
@@ -91,23 +92,34 @@
91 92
   #define ST7565_DELAY_3 CPU_ST7565_DELAY_3
92 93
 #endif
93 94
 
94
-#define ST7565_SND_BIT \
95
-  WRITE(ST7565_CLK_PIN, LOW);        ST7565_DELAY_1; \
96
-  WRITE(ST7565_DAT_PIN, val & 0x80); ST7565_DELAY_2; \
97
-  WRITE(ST7565_CLK_PIN, HIGH);       ST7565_DELAY_3; \
98
-  WRITE(ST7565_CLK_PIN, LOW);\
99
-  val <<= 1
100
-
101
-static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
102
-  ST7565_SND_BIT; // 1
103
-  ST7565_SND_BIT; // 2
104
-  ST7565_SND_BIT; // 3
105
-  ST7565_SND_BIT; // 4
106
-  ST7565_SND_BIT; // 5
107
-  ST7565_SND_BIT; // 6
108
-  ST7565_SND_BIT; // 7
109
-  ST7565_SND_BIT; // 8
110
-}
95
+
96
+#if ENABLED(SHARED_SPI)  // Re-ARM requires that the LCD and the SD card share a single SPI
97
+
98
+  #define ST7565_WRITE_BYTE(a)                 { spiSend((uint8_t)a); U8G_DELAY; }
99
+  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {spiSend( *ptr++);} DELAY_10US; }
100
+
101
+#else
102
+  #define ST7565_SND_BIT \
103
+    WRITE(ST7565_CLK_PIN, LOW);        ST7565_DELAY_1; \
104
+    WRITE(ST7565_DAT_PIN, val & 0x80); ST7565_DELAY_2; \
105
+    WRITE(ST7565_CLK_PIN, HIGH);       ST7565_DELAY_3; \
106
+    WRITE(ST7565_CLK_PIN, LOW);\
107
+    val <<= 1
108
+
109
+  static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
110
+    ST7565_SND_BIT; // 1
111
+    ST7565_SND_BIT; // 2
112
+    ST7565_SND_BIT; // 3
113
+    ST7565_SND_BIT; // 4
114
+    ST7565_SND_BIT; // 5
115
+    ST7565_SND_BIT; // 6
116
+    ST7565_SND_BIT; // 7
117
+    ST7565_SND_BIT; // 8
118
+  }
119
+
120
+  #define ST7565_WRITE_BYTE(a)                 { ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY; }
121
+  #define ST7560_WriteSequence(count, pointer) { uint8_t *ptr = pointer; for (uint8_t i = 0; i <  count; i++) {ST7565_SWSPI_SND_8BIT( *ptr++);} DELAY_10US; }
122
+#endif
111 123
 
112 124
 #if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
113 125
   #define U8G_DELAY delayMicroseconds(DOGM_SPI_DELAY_US)
@@ -115,116 +127,128 @@ static void ST7565_SWSPI_SND_8BIT(uint8_t val) {
115 127
   #define U8G_DELAY u8g_10MicroDelay()
116 128
 #endif
117 129
 
118
-#define ST7565_CS()                          do{ WRITE(ST7565_CS_PIN, HIGH); U8G_DELAY; }while(0)
119
-#define ST7565_NCS()                         WRITE(ST7565_CS_PIN, LOW)
120
-#define ST7565_A0()                          do{ WRITE(ST7565_A0_PIN, HIGH); U8G_DELAY; }while(0)
121
-#define ST7565_NA0()                         WRITE(ST7565_A0_PIN, LOW)
122
-#define ST7565_WRITE_BYTE(a)                 do{ ST7565_SWSPI_SND_8BIT((uint8_t)a); U8G_DELAY; }while(0)
123
-#define ST7560_WriteSequence(count, pointer) do{ uint8_t *ptr = pointer; for (uint8_t i = 0; i < count; ++i) { ST7565_SWSPI_SND_8BIT(*ptr++); } DELAY_10US; }while(0)
130
+#define ST7565_CS()                          { WRITE(ST7565_CS_PIN,1); U8G_DELAY; }
131
+#define ST7565_NCS()                         { WRITE(ST7565_CS_PIN,0); }
132
+#define ST7565_A0()                          { WRITE(ST7565_A0_PIN,1); U8G_DELAY; }
133
+#define ST7565_NA0()                         { WRITE(ST7565_A0_PIN,0); }
124 134
 
125 135
 
126 136
 uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
127 137
   switch (msg) {
128
-    case U8G_DEV_MSG_INIT: {
138
+    case U8G_DEV_MSG_INIT:
139
+    {
129 140
       OUT_WRITE(ST7565_CS_PIN, LOW);
130
-      OUT_WRITE(ST7565_DAT_PIN, LOW);
131
-      OUT_WRITE(ST7565_CLK_PIN, LOW);
141
+      #if ENABLED(SHARED_SPI)
142
+        u8g_Delay(250);
143
+        spiBegin();
144
+        #ifndef SPI_SPEED
145
+          #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
146
+        #endif
147
+        spiInit(SPI_SPEED);
148
+      #else
149
+        OUT_WRITE(ST7565_DAT_PIN, LOW);
150
+        OUT_WRITE(ST7565_CLK_PIN, LOW);
151
+      #endif
132 152
       OUT_WRITE(ST7565_A0_PIN, LOW);
133 153
 
134
-      ST7565_CS();                      // disable chip
135
-      ST7565_NA0();                     // instruction mode
136
-      ST7565_NCS();                     // enable chip
154
+      ST7565_CS();                      /* disable chip */
155
+      ST7565_NA0();                     /* instruction mode */
156
+      ST7565_NCS();                     /* enable chip */
157
+
137 158
 
138
-      ST7565_WRITE_BYTE(0xA2);          // 0xA2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
139
-      ST7565_WRITE_BYTE(0xA0);          // Normal ADC Select (according to Displaytech 64128N datasheet)
159
+      ST7565_WRITE_BYTE(0x0A2);         /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
160
+      ST7565_WRITE_BYTE(0x0A0);         /* Normal ADC Select (according to Displaytech 64128N datasheet) */
140 161
 
141
-      ST7565_WRITE_BYTE(0xC8);          // common output mode: set scan direction normal operation/SHL Select; 0xC0 --> SHL = 0; normal; 0xC8 --> SHL = 1
142
-      ST7565_WRITE_BYTE(0x40);          // Display start line for Displaytech 64128N
162
+      ST7565_WRITE_BYTE(0x0c8);         /* common output mode: set scan direction normal operation/SHL Select; 0x0c0 --> SHL = 0; normal; 0x0c8 --> SHL = 1 */
163
+      ST7565_WRITE_BYTE(0x040);         /* Display start line for Displaytech 64128N */
143 164
 
144
-      ST7565_WRITE_BYTE(0x28 | 0x04);   // power control: turn on voltage converter
145
-      //U8G_ESC_DLY(50);                  // delay 50 ms - hangs after a reset if used
165
+      ST7565_WRITE_BYTE(0x028 | 0x04);  /* power control: turn on voltage converter */
166
+//    U8G_ESC_DLY(50);                  /* delay 50 ms - hangs after a reset if used */
146 167
 
147
-      ST7565_WRITE_BYTE(0x28 | 0x06);   // power control: turn on voltage regulator
148
-      //U8G_ESC_DLY(50);                  // delay 50 ms - hangs after a reset if used
168
+      ST7565_WRITE_BYTE(0x028 | 0x06);  /* power control: turn on voltage regulator */
169
+//    U8G_ESC_DLY(50);                  /* delay 50 ms - hangs after a reset if used */
149 170
 
150
-      ST7565_WRITE_BYTE(0x28 | 0x07);   // power control: turn on voltage follower
151
-      //U8G_ESC_DLY(50);                  // delay 50 ms - hangs after a reset if used
171
+      ST7565_WRITE_BYTE(0x028 | 0x07);  /* power control: turn on voltage follower */
172
+//   U8G_ESC_DLY(50);                   /* delay 50 ms - hangs after a reset if used */
152 173
 
153
-      ST7565_WRITE_BYTE(0x10);          // Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N
154 174
 
155
-      ST7565_WRITE_BYTE(0xA6);          // display normal, bit val 0: LCD pixel off.
175
+      ST7565_WRITE_BYTE(0x010);         /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
156 176
 
157
-      ST7565_WRITE_BYTE(0x81);          // set contrast
158
-      ST7565_WRITE_BYTE(0x1E);          // Contrast value. Setting for controlling brightness of Displaytech 64128N
177
+      ST7565_WRITE_BYTE(0x0a6);         /* display normal, bit val 0: LCD pixel off. */
159 178
 
160
-      ST7565_WRITE_BYTE(0xAF);          // display on
179
+      ST7565_WRITE_BYTE(0x081);         /* set contrast */
180
+      ST7565_WRITE_BYTE(0x01e);         /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
161 181
 
162
-      U8G_ESC_DLY(100);                 // delay 100 ms
163
-      ST7565_WRITE_BYTE(0xA5);          // display all points; ST7565
164
-      U8G_ESC_DLY(100);                 // delay 100 ms
165
-      U8G_ESC_DLY(100);                 // delay 100 ms
166
-      ST7565_WRITE_BYTE(0xA4);          // normal display
167
-      ST7565_CS();                      // disable chip
168
-    }                                   // end of sequence
182
+
183
+      ST7565_WRITE_BYTE(0x0af);         /* display on */
184
+
185
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
186
+      ST7565_WRITE_BYTE(0x0a5);         /* display all points; ST7565 */
187
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
188
+      U8G_ESC_DLY(100);                 /* delay 100 ms */
189
+      ST7565_WRITE_BYTE(0x0a4);         /* normal display */
190
+      ST7565_CS();                      /* disable chip */
191
+    }                                   /* end of sequence */
169 192
       break;
170 193
     case U8G_DEV_MSG_STOP:
171 194
       break;
172
-    case U8G_DEV_MSG_PAGE_NEXT: {
173
-      u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
174
-      ST7565_CS();                      // disable chip
175
-      ST7565_NA0();                     // instruction mode
176
-      ST7565_NCS();                     // enable chip
177
-      ST7565_WRITE_BYTE(0x10);          // set upper 4 bit of the col adr to 0x10
178
-      ST7565_WRITE_BYTE(0x00);          // set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N
179
-                                        // end of sequence
180
-      ST7565_WRITE_BYTE(0xB0 | (2 * pb->p.page)); // select current page (ST7565R)
181
-      ST7565_A0();                      // data mode
182
-      ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)pb->buf);
183
-      ST7565_CS();                      // disable chip
184
-      ST7565_NA0();                     // instruction mode
185
-      ST7565_NCS();                     // enable chip
186
-      ST7565_WRITE_BYTE(0x10);          // set upper 4 bit of the col adr to 0x10
187
-      ST7565_WRITE_BYTE(0x00);          // set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N
188
-                                        // end of sequence
189
-      ST7565_WRITE_BYTE(0xB0 | (2 * pb->p.page + 1)); // select current page (ST7565R)
190
-      ST7565_A0();                      // data mode
191
-      ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)(pb->buf)+pb->width);
192
-      ST7565_CS();                      // disable chip
195
+    case U8G_DEV_MSG_PAGE_NEXT:
196
+    { u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
197
+      ST7565_CS();                      /* disable chip */
198
+      ST7565_NA0();                     /* instruction mode */
199
+      ST7565_NCS();                     /* enable chip */
200
+      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
201
+      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
202
+                                        /* end of sequence */
203
+      ST7565_WRITE_BYTE(0x0b0 | (2*pb->p.page));; /* select current page (ST7565R) */
204
+      ST7565_A0();                      /* data mode */
205
+      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
206
+      ST7565_CS();                      /* disable chip */
207
+      ST7565_NA0();                     /* instruction mode */
208
+      ST7565_NCS();                     /* enable chip */
209
+      ST7565_WRITE_BYTE(0x010);         /* set upper 4 bit of the col adr to 0x10 */
210
+      ST7565_WRITE_BYTE(0x000);         /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
211
+                                        /* end of sequence */
212
+      ST7565_WRITE_BYTE(0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
213
+      ST7565_A0();                      /* data mode */
214
+      ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
215
+      ST7565_CS();                      /* disable chip */
193 216
     }
194 217
       break;
195 218
     case U8G_DEV_MSG_CONTRAST:
196 219
       ST7565_NCS();
197
-      ST7565_NA0();                     // instruction mode
198
-      ST7565_WRITE_BYTE(0x81);
220
+      ST7565_NA0();                     /* instruction mode */
221
+      ST7565_WRITE_BYTE(0x081);
199 222
       ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
200
-      ST7565_CS();                      // disable chip
223
+      ST7565_CS();                      /* disable chip */
201 224
       return 1;
202 225
     case U8G_DEV_MSG_SLEEP_ON:
203
-      ST7565_NA0();                     // instruction mode
204
-      ST7565_NCS();                     // enable chip
205
-      ST7565_WRITE_BYTE(0xAC);          // static indicator off
206
-      ST7565_WRITE_BYTE(0x00);          // indicator register set (not sure if this is required)
207
-      ST7565_WRITE_BYTE(0xAE);          // display off
208
-      ST7565_WRITE_BYTE(0xA5);          // all points on
209
-      ST7565_CS();                      // disable chip , bugfix 12 nov 2014
210
-                                        // end of sequence
226
+      ST7565_NA0();                     /* instruction mode */
227
+      ST7565_NCS();                     /* enable chip */
228
+      ST7565_WRITE_BYTE(0x0ac);         /* static indicator off */
229
+      ST7565_WRITE_BYTE(0x000);         /* indicator register set (not sure if this is required) */
230
+      ST7565_WRITE_BYTE(0x0ae);         /* display off */
231
+      ST7565_WRITE_BYTE(0x0a5);         /* all points on */
232
+      ST7565_CS();                      /* disable chip , bugfix 12 nov 2014 */
233
+                                        /* end of sequence */
211 234
       return 1;
212 235
     case U8G_DEV_MSG_SLEEP_OFF:
213
-      ST7565_NA0();                     // instruction mode
214
-      ST7565_NCS();                     // enable chip
215
-      ST7565_WRITE_BYTE(0xA4);          // all points off
216
-      ST7565_WRITE_BYTE(0xAF);          // display on
217
-      U8G_ESC_DLY(50);                  // delay 50 ms
218
-      ST7565_CS();                      // disable chip ,  bugfix 12 nov 2014
219
-                                        // end of sequence
236
+      ST7565_NA0();                     /* instruction mode */
237
+      ST7565_NCS();                     /* enable chip */
238
+      ST7565_WRITE_BYTE(0x0a4);         /* all points off */
239
+      ST7565_WRITE_BYTE(0x0af);         /* display on */
240
+      U8G_ESC_DLY(50);                  /* delay 50 ms */
241
+      ST7565_CS();                      /* disable chip ,  bugfix 12 nov 2014 */
242
+                                        /* end of sequence */
220 243
       return 1;
221 244
   }
222 245
   return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
223 246
 }
224 247
 
225
-uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[WIDTH*2] U8G_NOCOMMON;
226
-u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = { { 16, HEIGHT, 0, 0, 0 }, WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf };
227
-u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = { u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn };
248
+uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[WIDTH*2] U8G_NOCOMMON ;
249
+u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
250
+u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = { u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn};
251
+
228 252
 
229 253
 class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
230 254
   public:
@@ -236,6 +260,9 @@ class U8GLIB_ST7565_64128n_2x_VIKI : public U8GLIB {
236 260
     {  }
237 261
 };
238 262
 
263
+
264
+
239 265
 #pragma GCC reset_options
240 266
 
267
+#endif // U8GLIB_ST7565
241 268
 #endif // ULCDST7565_H

+ 60
- 24
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd.h View File

@@ -23,7 +23,9 @@
23 23
 #ifndef ULCDST7920_H
24 24
 #define ULCDST7920_H
25 25
 
26
-#include "../../Marlin.h"
26
+#include <src/Marlin.h>
27
+
28
+#if ENABLED(U8GLIB_ST7920)
27 29
 
28 30
 #define ST7920_CLK_PIN  LCD_PINS_D4
29 31
 #define ST7920_DAT_PIN  LCD_PINS_ENABLE
@@ -80,43 +82,63 @@
80 82
   #define ST7920_DELAY_3 CPU_ST7920_DELAY_3
81 83
 #endif
82 84
 
83
-#define ST7920_SND_BIT \
84
-  WRITE(ST7920_CLK_PIN, LOW);        ST7920_DELAY_1; \
85
-  WRITE(ST7920_DAT_PIN, val & 0x80); ST7920_DELAY_2; \
86
-  WRITE(ST7920_CLK_PIN, HIGH);       ST7920_DELAY_3; \
87
-  val <<= 1
88
-
89
-static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
90
-  ST7920_SND_BIT; // 1
91
-  ST7920_SND_BIT; // 2
92
-  ST7920_SND_BIT; // 3
93
-  ST7920_SND_BIT; // 4
94
-  ST7920_SND_BIT; // 5
95
-  ST7920_SND_BIT; // 6
96
-  ST7920_SND_BIT; // 7
97
-  ST7920_SND_BIT; // 8
98
-}
99
-
100 85
 #if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
101 86
   #define U8G_DELAY() delayMicroseconds(DOGM_SPI_DELAY_US)
102 87
 #else
103 88
   #define U8G_DELAY() u8g_10MicroDelay()
104 89
 #endif
105 90
 
91
+#if ENABLED(SHARED_SPI)   // Re-ARM requires that the LCD and the SD card share a single SPI
92
+
93
+  #define ST7920_SET_CMD()         { spiSend(0xF8); U8G_DELAY(); }
94
+  #define ST7920_SET_DAT()         { spiSend(0xFA); U8G_DELAY(); }
95
+  #define ST7920_WRITE_BYTE(a)     { spiSend((uint8_t)((a)&0xF0u)); U8G_DELAY(); spiSend((uint8_t)((a)<<4u)); U8G_DELAY(); }
96
+  #define ST7920_WRITE_BYTES(p,l)  { for (uint8_t i = l + 1; --i;) { spiSend(*p&0xF0); spiSend(*p<<4); p++; } U8G_DELAY(); }
97
+
98
+#else
99
+
100
+  #define ST7920_SND_BIT \
101
+    WRITE(ST7920_CLK_PIN, LOW);        ST7920_DELAY_1; \
102
+    WRITE(ST7920_DAT_PIN, val & 0x80); ST7920_DELAY_2; \
103
+    WRITE(ST7920_CLK_PIN, HIGH);       ST7920_DELAY_3; \
104
+    val <<= 1
105
+
106
+  static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
107
+    ST7920_SND_BIT; // 1
108
+    ST7920_SND_BIT; // 2
109
+    ST7920_SND_BIT; // 3
110
+    ST7920_SND_BIT; // 4
111
+    ST7920_SND_BIT; // 5
112
+    ST7920_SND_BIT; // 6
113
+    ST7920_SND_BIT; // 7
114
+    ST7920_SND_BIT; // 8
115
+  }
116
+
117
+  #define ST7920_SET_CMD()         { ST7920_SWSPI_SND_8BIT(0xF8); U8G_DELAY(); }
118
+  #define ST7920_SET_DAT()         { ST7920_SWSPI_SND_8BIT(0xFA); U8G_DELAY(); }
119
+  #define ST7920_WRITE_BYTE(a)     { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); U8G_DELAY(); }
120
+  #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++; } U8G_DELAY(); }
121
+#endif
122
+
106 123
 #define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }
107 124
 #define ST7920_NCS()             { WRITE(ST7920_CS_PIN,0); }
108
-#define ST7920_SET_CMD()         { ST7920_SWSPI_SND_8BIT(0xF8); U8G_DELAY(); }
109
-#define ST7920_SET_DAT()         { ST7920_SWSPI_SND_8BIT(0xFA); U8G_DELAY(); }
110
-#define ST7920_WRITE_BYTE(a)     { ST7920_SWSPI_SND_8BIT((uint8_t)((a)&0xF0u)); ST7920_SWSPI_SND_8BIT((uint8_t)((a)<<4u)); U8G_DELAY(); }
111
-#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++; } U8G_DELAY(); }
125
+
126
+
112 127
 
113 128
 uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
114 129
   uint8_t i, y;
115 130
   switch (msg) {
116 131
     case U8G_DEV_MSG_INIT: {
117 132
       OUT_WRITE(ST7920_CS_PIN, LOW);
118
-      OUT_WRITE(ST7920_DAT_PIN, LOW);
119
-      OUT_WRITE(ST7920_CLK_PIN, HIGH);
133
+
134
+      #if ENABLED(SHARED_SPI)
135
+        u8g_Delay(250);
136
+        spiBegin();
137
+        spiInit(SPI_EIGHTH_SPEED);  // run LCD at 1 MHz - garbled display if run at 2 MHz
138
+      #else
139
+        OUT_WRITE(ST7920_DAT_PIN, LOW);
140
+        OUT_WRITE(ST7920_CLK_PIN, HIGH);
141
+      #endif
120 142
 
121 143
       ST7920_CS();
122 144
       u8g_Delay(120);                 //initial delay for boot up
@@ -133,13 +155,23 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
133 155
           ST7920_WRITE_BYTE(0);
134 156
         ST7920_SET_CMD();
135 157
       }
158
+
136 159
       ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
160
+      #if ENABLED(SHARED_SPI)
161
+        #ifndef SPI_SPEED
162
+            #define SPI_SPEED SPI_FULL_SPEED  // switch SPI speed back to SD card speed
163
+        #endif
164
+        spiInit(SPI_SPEED);
165
+      #endif
137 166
       ST7920_NCS();
138 167
     }
139 168
     break;
140 169
     case U8G_DEV_MSG_STOP:
141 170
       break;
142 171
     case U8G_DEV_MSG_PAGE_NEXT: {
172
+      #if ENABLED(SHARED_SPI)
173
+        spiInit(SPI_EIGHTH_SPEED);  // run LCD at 1 MHz - garbled display if run at 2 MHz
174
+      #endif
143 175
       uint8_t* ptr;
144 176
       u8g_pb_t* pb = (u8g_pb_t*)(dev->dev_mem);
145 177
       y = pb->p.page_y0;
@@ -160,6 +192,9 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
160 192
         ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro
161 193
         y++;
162 194
       }
195
+      #if ENABLED(SHARED_SPI)
196
+        spiInit(SPI_SPEED);   // switch SPI speed back to SD card speed
197
+      #endif
163 198
       ST7920_NCS();
164 199
     }
165 200
     break;
@@ -184,4 +219,5 @@ class U8GLIB_ST7920_128X64_RRD : public U8GLIB {
184 219
 
185 220
 #pragma GCC reset_options
186 221
 
222
+#endif // U8GLIB_ST7920
187 223
 #endif // ULCDST7920_H

+ 0
- 3
Marlin/src/pins/pins.h View File

@@ -403,9 +403,6 @@
403 403
 #ifndef SDPOWER
404 404
   #define SDPOWER -1
405 405
 #endif
406
-#ifndef SDSS
407
-  #define SDSS -1
408
-#endif
409 406
 #ifndef LED_PIN
410 407
   #define LED_PIN -1
411 408
 #endif

+ 1
- 3
Marlin/src/pins/pins_RAMPS_RE_ARM.h View File

@@ -105,7 +105,7 @@
105 105
 #define TEMP_1_PIN         2  //A2 (T2) - D69 - TEMP_1_PIN
106 106
 #define TEMP_2_PIN         3  //A3 - D63 - J5-3 & AUX-2
107 107
 #define TEMP_3_PIN         4  //A4 - D37 - BUZZER_PIN
108
-#define TEMP_4_PIN         5  //A5 - D49 - SD_DETECT_PIN
108
+//#define TEMP_4_PIN         5  //A5 - D49 - SD_DETECT_PIN
109 109
 //#define ??               6  //A6 - D0  - RXD0 - J4-4 & AUX-1
110 110
 #define FILWIDTH_PIN       7  //A7 - D1  - TXD0 - J4-5 & AUX-1
111 111
 
@@ -288,8 +288,6 @@
288 288
  #if ENABLED(VIKI2) || ENABLED(miniVIKI)
289 289
 //    #define LCD_SCREEN_ROT_180
290 290
 
291
-    #define SOFTWARE_SPI  // temp to see if it fixes the  "not found" error
292
-
293 291
     #undef  BEEPER_PIN
294 292
     #define BEEPER_PIN          37  // may change if cable changes
295 293
 

+ 3
- 0
buildroot/bin/build_marlin_teensy35 View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env bash
2
+
3
+arduino --verify --board teensy:avr:teensy35:usb=serial,speed=120,opt=o1std,keys=en-us Marlin/Marlin.ino

+ 21
- 0
debug_extra_script.py View File

@@ -0,0 +1,21 @@
1
+Import("env")
2
+
3
+env.AddPostAction(
4
+    "$BUILD_DIR/firmware.hex",
5
+    env.VerboseAction(" ".join([
6
+        "sed", "-i.bak",
7
+        "s/:10040000FFFFFFFFFFFFFFFFFFFFFFFFDEF9FFFF23/:10040000FFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFD/",
8
+        "$BUILD_DIR/firmware.hex"
9
+    ]), "Fixing $BUILD_DIR/firmware.hex secure flash flags"))
10
+env.AddPreAction(
11
+    "upload",
12
+     env.VerboseAction(" ".join([
13
+         "echo",
14
+         "'h\\nloadfile $BUILD_DIR/firmware.hex\\nr\\nq\\n'",
15
+         ">$BUILD_DIR/aux.jlink"
16
+     ]), "Creating auxiliary files"))
17
+
18
+env.Replace(
19
+    UPLOADHEXCMD=
20
+    'JLinkExe -device MK20DX256xxx7 -speed 4000 -if swd -autoconnect 1 -CommanderScript $BUILD_DIR/aux.jlink -SkipProgOnCRCMatch = 1 -VerifyDownload = 1'
21
+)

+ 28
- 0
platformio.ini View File

@@ -121,3 +121,31 @@ lib_ldf_mode = off
121 121
 lib_extra_dirs = frameworks
122 122
 lib_deps = U8glib-ARM, CMSIS-LPC1768
123 123
 extra_scripts = Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
124
+
125
+
126
+[env:Re-ARM_debug_and_upload]
127
+# Segger JLink
128
+platform = nxplpc
129
+#framework = mbed
130
+board = lpc1768
131
+board_f_cpu = 100000000L
132
+build_flags = !python Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
133
+lib_ldf_mode = off
134
+lib_deps = U8glib-ARM
135
+src_filter =
136
+extra_scripts = debug_extra_script.py,  Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
137
+debug_tool = custom
138
+debug_server =
139
+  C:\Program Files (x86)\SEGGER\JLink_V618d\JLinkGDBServerCL.exe
140
+  -select
141
+  USB
142
+  -port
143
+  2331
144
+  -device
145
+  LPC1768
146
+  -if
147
+  JTAG
148
+  -speed
149
+  auto
150
+  -noir
151
+  

Loading…
Cancel
Save