瀏覽代碼

Fix up various spacing, comments, and typos

Scott Lahteine 7 年之前
父節點
當前提交
ca577c1638

+ 2
- 2
Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp 查看文件

93
       #define MAXNOPS 4
93
       #define MAXNOPS 4
94
 
94
 
95
       if (x <= (MAXNOPS)) {
95
       if (x <= (MAXNOPS)) {
96
-        switch(x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
96
+        switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
97
       }
97
       }
98
       else { // because of +1 cycle inside delay_4cycles
98
       else { // because of +1 cycle inside delay_4cycles
99
         const uint32_t rem = (x - 1) % (MAXNOPS);
99
         const uint32_t rem = (x - 1) % (MAXNOPS);
100
-        switch(rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
100
+        switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
101
         if ((x = (x - 1) / (MAXNOPS)))
101
         if ((x = (x - 1) / (MAXNOPS)))
102
           __delay_4cycles(x); // if need more then 4 nop loop is more optimal
102
           __delay_4cycles(x); // if need more then 4 nop loop is more optimal
103
       }
103
       }

+ 32
- 34
Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*
23
+/**
24
-
24
+ * Based on u8g_com_st7920_hw_spi.c
25
-  based on u8g_com_st7920_hw_spi.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library
27
-  Universal 8bit Graphics Library
27
+ *
28
-
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-  Copyright (c) 2011, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-*/
57
 
55
 
58
 #ifdef ARDUINO_ARCH_SAM
56
 #ifdef ARDUINO_ARCH_SAM
59
 
57
 

+ 3
- 3
Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp 查看文件

218
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));  // Sometimes the upper byte is garbled
218
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));  // Sometimes the upper byte is garbled
219
 
219
 
220
 ////  direct control PWM code
220
 ////  direct control PWM code
221
-  switch(pin) {
221
+  switch (pin) {
222
     case P1_23:                                       // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
222
     case P1_23:                                       // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
223
       direct_table[P1_23_PWM_channel - 1].min = min;
223
       direct_table[P1_23_PWM_channel - 1].min = min;
224
       direct_table[P1_23_PWM_channel - 1].max = MIN(max, LPC_PWM1_MR0 - MR0_MARGIN);
224
       direct_table[P1_23_PWM_channel - 1].max = MIN(max, LPC_PWM1_MR0 - MR0_MARGIN);
298
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));
298
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));
299
 
299
 
300
 ////  direct control PWM code
300
 ////  direct control PWM code
301
-  switch(pin) {
301
+  switch (pin) {
302
     case P1_23:                                       // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
302
     case P1_23:                                       // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
303
       if (!direct_table[P1_23_PWM_channel - 1].assigned) return false;
303
       if (!direct_table[P1_23_PWM_channel - 1].assigned) return false;
304
       CBI(LPC_PWM1->PCR, 8 + P1_23_PWM_channel);      // disable PWM1 module control of this pin
304
       CBI(LPC_PWM1->PCR, 8 + P1_23_PWM_channel);      // disable PWM1 module control of this pin
373
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));
373
   pin = GET_PIN_MAP_PIN(GET_PIN_MAP_INDEX(pin & 0xFF));
374
 
374
 
375
 ////  direct control PWM code
375
 ////  direct control PWM code
376
-  switch(pin) {
376
+  switch (pin) {
377
     case P1_23:                                                           // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
377
     case P1_23:                                                           // MKS Sbase Servo 0, PWM1 channel 4  (J3-8 PWM1.4)
378
       if (!direct_table[P1_23_PWM_channel - 1].assigned) return false;
378
       if (!direct_table[P1_23_PWM_channel - 1].assigned) return false;
379
       LPC_PWM1->PCR |=  _BV(8 + P1_23_PWM_channel); // enable PWM1 module control of this pin
379
       LPC_PWM1->PCR |=  _BV(8 + P1_23_PWM_channel); // enable PWM1 module control of this pin

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/arduino.cpp 查看文件

70
 }
70
 }
71
 
71
 
72
 // IO functions
72
 // IO functions
73
-// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
73
+// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
74
 void pinMode(const pin_t pin, const uint8_t mode) {
74
 void pinMode(const pin_t pin, const uint8_t mode) {
75
   if (!VALID_PIN(pin)) return;
75
   if (!VALID_PIN(pin)) return;
76
 
76
 

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_pin_routines.c 查看文件

54
 #endif
54
 #endif
55
 
55
 
56
 // I/O functions
56
 // I/O functions
57
-// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
57
+// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
58
 void pinMode_LCD(uint8_t pin, uint8_t mode) {
58
 void pinMode_LCD(uint8_t pin, uint8_t mode) {
59
   #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
59
   #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
60
   #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
60
   #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))

+ 105
- 112
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_hw_spi.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-
23
+/**
24
-/*
24
+ * Based on u8g_com_msp430_hw_spi.c
25
-
25
+ *
26
-  based on u8g_com_msp430_hw_spi.c
26
+ * Universal 8bit Graphics Library
27
-
27
+ *
28
-  Universal 8bit Graphics Library
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-
29
+ * All rights reserved.
30
-  Copyright (c) 2012, olikraus@gmail.com
30
+ *
31
-  All rights reserved.
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-
32
+ * are permitted provided that the following conditions are met:
33
-  Redistribution and use in source and binary forms, with or without modification,
33
+ *
34
-  are permitted provided that the following conditions are met:
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-
35
+ *    of conditions and the following disclaimer.
36
-  * Redistributions of source code must retain the above copyright notice, this list
36
+ *
37
-  of conditions and the following disclaimer.
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-  * Redistributions in binary form must reproduce the above copyright notice, this
39
+ *    materials provided with the distribution.
40
-  list of conditions and the following disclaimer in the documentation and/or other
40
+ *
41
-  materials provided with the distribution.
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+ */
55
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
-
57
-*/
58
-
59
 
55
 
60
 #ifdef TARGET_LPC1768
56
 #ifdef TARGET_LPC1768
61
 
57
 
62
-  //#include <inttypes.h>
58
+//#include <inttypes.h>
63
-
59
+
64
-  //#include "src/core/macros.h"
60
+//#include "src/core/macros.h"
65
-  //#include "Configuration.h"
61
+//#include "Configuration.h"
66
-
62
+
67
-  #include <U8glib.h>
63
+#include <U8glib.h>
68
-
64
+
69
-  #define SPI_FULL_SPEED 0
65
+#define SPI_FULL_SPEED 0
70
-  #define SPI_HALF_SPEED 1
66
+#define SPI_HALF_SPEED 1
71
-  #define SPI_QUARTER_SPEED 2
67
+#define SPI_QUARTER_SPEED 2
72
-  #define SPI_EIGHTH_SPEED 3
68
+#define SPI_EIGHTH_SPEED 3
73
-  #define SPI_SIXTEENTH_SPEED 4
69
+#define SPI_SIXTEENTH_SPEED 4
74
-  #define SPI_SPEED_5 5
70
+#define SPI_SPEED_5 5
75
-  #define SPI_SPEED_6 6
71
+#define SPI_SPEED_6 6
76
-
72
+
77
-  void spiBegin();
73
+void spiBegin();
78
-  void spiInit(uint8_t spiRate);
74
+void spiInit(uint8_t spiRate);
79
-  void spiSend(uint8_t b);
75
+void spiSend(uint8_t b);
80
-  void spiSend(const uint8_t* buf, size_t n);
76
+void spiSend(const uint8_t* buf, size_t n);
81
-
77
+
82
-
78
+uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
83
-  uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
79
+  switch (msg) {
84
-  {
80
+    case U8G_COM_MSG_STOP:
85
-    switch(msg)
81
+      break;
86
-    {
82
+
87
-      case U8G_COM_MSG_STOP:
83
+    case U8G_COM_MSG_INIT:
88
-        break;
84
+      u8g_SetPILevel(u8g, U8G_PI_CS, 1);
89
-
85
+      u8g_SetPILevel(u8g, U8G_PI_A0, 1);
90
-      case U8G_COM_MSG_INIT:
86
+      u8g_SetPILevel(u8g, U8G_PI_RESET, 1);
91
-        u8g_SetPILevel(u8g, U8G_PI_CS, 1);
87
+      u8g_SetPIOutput(u8g, U8G_PI_CS);
92
-        u8g_SetPILevel(u8g, U8G_PI_A0, 1);
88
+      u8g_SetPIOutput(u8g, U8G_PI_A0);
93
-        u8g_SetPILevel(u8g, U8G_PI_RESET, 1);
89
+      u8g_SetPIOutput(u8g, U8G_PI_RESET);
94
-        u8g_SetPIOutput(u8g, U8G_PI_CS);
90
+      u8g_Delay(5);
95
-        u8g_SetPIOutput(u8g, U8G_PI_A0);
91
+      spiBegin();
96
-        u8g_SetPIOutput(u8g, U8G_PI_RESET);
92
+      #ifndef SPI_SPEED
97
-        u8g_Delay(5);
93
+        #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
98
-        spiBegin();
94
+      #endif
99
-        #ifndef SPI_SPEED
95
+      spiInit(SPI_SPEED);
100
-          #define SPI_SPEED SPI_FULL_SPEED  // use same SPI speed as SD card
96
+      break;
101
-        #endif
97
+
102
-        spiInit(SPI_SPEED);
98
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
103
-        break;
99
+      u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
104
-
100
+      break;
105
-      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
101
+
106
-        u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
102
+    case U8G_COM_MSG_CHIP_SELECT:
107
-        break;
103
+      u8g_SetPILevel(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
108
-
104
+      break;
109
-      case U8G_COM_MSG_CHIP_SELECT:
105
+
110
-        u8g_SetPILevel(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
106
+    case U8G_COM_MSG_RESET:
111
-        break;
107
+      u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
112
-
108
+      break;
113
-      case U8G_COM_MSG_RESET:
109
+
114
-        u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
110
+    case U8G_COM_MSG_WRITE_BYTE:
115
-        break;
111
+      spiSend((uint8_t)arg_val);
116
-
112
+      break;
117
-      case U8G_COM_MSG_WRITE_BYTE:
113
+
118
-        spiSend((uint8_t)arg_val);
114
+    case U8G_COM_MSG_WRITE_SEQ: {
119
-        break;
115
+        uint8_t *ptr = (uint8_t*) arg_ptr;
120
-
116
+        while (arg_val > 0) {
121
-      case U8G_COM_MSG_WRITE_SEQ: {
117
+          spiSend(*ptr++);
122
-          uint8_t *ptr = (uint8_t*) arg_ptr;
118
+          arg_val--;
123
-          while (arg_val > 0) {
124
-            spiSend(*ptr++);
125
-            arg_val--;
126
-          }
127
         }
119
         }
128
-        break;
120
+      }
129
-
121
+      break;
130
-      case U8G_COM_MSG_WRITE_SEQ_P: {
122
+
131
-          uint8_t *ptr = (uint8_t*) arg_ptr;
123
+    case U8G_COM_MSG_WRITE_SEQ_P: {
132
-          while (arg_val > 0) {
124
+        uint8_t *ptr = (uint8_t*) arg_ptr;
133
-            spiSend(*ptr++);
125
+        while (arg_val > 0) {
134
-            arg_val--;
126
+          spiSend(*ptr++);
135
-          }
127
+          arg_val--;
136
         }
128
         }
137
-        break;
129
+      }
138
-    }
130
+      break;
139
-    return 1;
140
   }
131
   }
132
+  return 1;
133
+}
141
 
134
 
142
 #endif  //TARGET_LPC1768
135
 #endif  //TARGET_LPC1768

+ 82
- 95
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+/**
24
+ * Based on u8g_com_arduino_ssd_i2c.c
25
+ *
26
+ * COM interface for Arduino (AND ATmega) and the SSDxxxx chip (SOLOMON) variant
27
+ * I2C protocol
28
+ *
29
+ * ToDo: Rename this to u8g_com_avr_ssd_i2c.c
30
+ *
31
+ * Universal 8bit Graphics Library
32
+ *
33
+ * Copyright (c) 2011, olikraus@gmail.com
34
+ * All rights reserved.
35
+ *
36
+ * Redistribution and use in source and binary forms, with or without modification,
37
+ * are permitted provided that the following conditions are met:
38
+ *
39
+ *  * Redistributions of source code must retain the above copyright notice, this list
40
+ *    of conditions and the following disclaimer.
41
+ *
42
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
43
+ *    list of conditions and the following disclaimer in the documentation and/or other
44
+ *    materials provided with the distribution.
45
+ *
46
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
47
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
48
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
49
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
51
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
56
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
58
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
+ */
23
 
60
 
24
-/*
61
+/**
25
-
62
+ * Special pin usage:
26
-  based on u8g_com_arduino_ssd_i2c.c
63
+ * U8G_PI_I2C_OPTION additional options
27
-
64
+ * U8G_PI_A0_STATE used to store the last value of the command/data register selection
28
-  com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
65
+ * U8G_PI_SET_A0   1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
29
-  I2C protocol
66
+ * U8G_PI_SCL    clock line (NOT USED)
30
-
67
+ * U8G_PI_SDA    data line (NOT USED)
31
-  ToDo: Rename this to u8g_com_avr_ssd_i2c.c
68
+ *
32
-
69
+ * U8G_PI_RESET    reset line (currently disabled, see below)
33
-  Universal 8bit Graphics Library
70
+ *
34
-
71
+ * Protocol:
35
-  Copyright (c) 2012, olikraus@gmail.com
72
+ * SLA, Cmd/Data Selection, Arguments
36
-  All rights reserved.
73
+ * The command/data register is selected by a special instruction byte, which is sent after SLA
37
-
74
+ *
38
-  Redistribution and use in source and binary forms, with or without modification,
75
+ * The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
39
-  are permitted provided that the following conditions are met:
76
+ */
40
-
41
-  * Redistributions of source code must retain the above copyright notice, this list
42
-  of conditions and the following disclaimer.
43
-
44
-  * Redistributions in binary form must reproduce the above copyright notice, this
45
-  list of conditions and the following disclaimer in the documentation and/or other
46
-  materials provided with the distribution.
47
-
48
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
49
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
50
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
51
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
53
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
58
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61
-
62
-  Special pin usage:
63
-  U8G_PI_I2C_OPTION additional options
64
-  U8G_PI_A0_STATE used to store the last value of the command/data register selection
65
-  U8G_PI_SET_A0   1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
66
-  U8G_PI_SCL    clock line (NOT USED)
67
-  U8G_PI_SDA    data line (NOT USED)
68
-
69
-  U8G_PI_RESET    reset line (currently disabled, see below)
70
-
71
-  Protocol:
72
-  SLA, Cmd/Data Selection, Arguments
73
-  The command/data register is selected by a special instruction byte, which is sent after SLA
74
-
75
-  The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
76
-*/
77
 
77
 
78
 #ifdef TARGET_LPC1768
78
 #ifdef TARGET_LPC1768
79
 
79
 
84
   #define I2C_CMD_MODE    0x000
84
   #define I2C_CMD_MODE    0x000
85
   #define I2C_DATA_MODE   0x040
85
   #define I2C_DATA_MODE   0x040
86
 
86
 
87
-//    #define U8G_I2C_OPT_FAST 16
87
+  //#define U8G_I2C_OPT_FAST 16
88
 
88
 
89
-  uint8_t  u8g_com_ssd_I2C_start_sequence(u8g_t *u8g)
89
+  uint8_t u8g_com_ssd_I2C_start_sequence(u8g_t *u8g) {
90
-  {
91
     /* are we requested to set the a0 state? */
90
     /* are we requested to set the a0 state? */
92
-    if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
91
+    if (u8g->pin_list[U8G_PI_SET_A0] == 0) return 1;
93
-      return 1;
94
 
92
 
95
     /* setup bus, might be a repeated start */
93
     /* setup bus, might be a repeated start */
96
-    if ( u8g_i2c_start(I2C_SLA) == 0 )
94
+    if (u8g_i2c_start(I2C_SLA) == 0)
97
       return 0;
95
       return 0;
98
-    if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
96
+    if (u8g->pin_list[U8G_PI_A0_STATE] == 0 ) {
99
-    {
97
+      if (u8g_i2c_send_byte(I2C_CMD_MODE) == 0) return 0;
100
-      if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
101
-        return 0;
102
-    }
103
-    else
104
-    {
105
-      if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
106
-        return 0;
107
     }
98
     }
99
+    else if (u8g_i2c_send_byte(I2C_DATA_MODE) == 0)
100
+      return 0;
108
 
101
 
109
     u8g->pin_list[U8G_PI_SET_A0] = 0;
102
     u8g->pin_list[U8G_PI_SET_A0] = 0;
110
-      return 1;
103
+    return 1;
111
   }
104
   }
112
 
105
 
113
-  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
106
+  uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
114
-  {
107
+    switch(msg) {
115
-    switch(msg)
116
-    {
117
       case U8G_COM_MSG_INIT:
108
       case U8G_COM_MSG_INIT:
118
         //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
109
         //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
119
         //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
110
         //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
134
       case U8G_COM_MSG_CHIP_SELECT:
125
       case U8G_COM_MSG_CHIP_SELECT:
135
         u8g->pin_list[U8G_PI_A0_STATE] = 0;
126
         u8g->pin_list[U8G_PI_A0_STATE] = 0;
136
         u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
127
         u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
137
-        if ( arg_val == 0 )
128
+        if (arg_val == 0 ) {
138
-        {
139
           /* disable chip, send stop condition */
129
           /* disable chip, send stop condition */
140
           u8g_i2c_stop();
130
           u8g_i2c_stop();
141
         }
131
         }
142
-        else
132
+        else {
143
-        {
144
           /* enable, do nothing: any byte writing will trigger the i2c start */
133
           /* enable, do nothing: any byte writing will trigger the i2c start */
145
         }
134
         }
146
         break;
135
         break;
147
 
136
 
148
       case U8G_COM_MSG_WRITE_BYTE:
137
       case U8G_COM_MSG_WRITE_BYTE:
149
         //u8g->pin_list[U8G_PI_SET_A0] = 1;
138
         //u8g->pin_list[U8G_PI_SET_A0] = 1;
150
-//          if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
139
+        //if (u8g_com_arduino_ssd_start_sequence(u8g) == 0)
151
-//            return u8g_i2c_stop(), 0;
140
+        //  return u8g_i2c_stop(), 0;
152
-        if ( u8g_i2c_send_byte(arg_val) == 0 )
141
+        if (u8g_i2c_send_byte(arg_val) == 0)
153
           return u8g_i2c_stop(), 0;
142
           return u8g_i2c_stop(), 0;
154
         // u8g_i2c_stop();
143
         // u8g_i2c_stop();
155
         break;
144
         break;
156
 
145
 
157
-      case U8G_COM_MSG_WRITE_SEQ:
146
+      case U8G_COM_MSG_WRITE_SEQ: {
158
         //u8g->pin_list[U8G_PI_SET_A0] = 1;
147
         //u8g->pin_list[U8G_PI_SET_A0] = 1;
159
-        if ( u8g_com_ssd_I2C_start_sequence(u8g) == 0 )
148
+        if (u8g_com_ssd_I2C_start_sequence(u8g) == 0)
160
           return u8g_i2c_stop(), 0;
149
           return u8g_i2c_stop(), 0;
161
-        {
150
+
162
           register uint8_t *ptr = (uint8_t *)arg_ptr;
151
           register uint8_t *ptr = (uint8_t *)arg_ptr;
163
           while (arg_val > 0) {
152
           while (arg_val > 0) {
164
-            if ( u8g_i2c_send_byte(*ptr++) == 0 )
153
+            if (u8g_i2c_send_byte(*ptr++) == 0)
165
               return u8g_i2c_stop(), 0;
154
               return u8g_i2c_stop(), 0;
166
             arg_val--;
155
             arg_val--;
167
           }
156
           }
169
         // u8g_i2c_stop();
158
         // u8g_i2c_stop();
170
         break;
159
         break;
171
 
160
 
172
-      case U8G_COM_MSG_WRITE_SEQ_P:
161
+      case U8G_COM_MSG_WRITE_SEQ_P: {
173
-        //u8g->pin_list[U8G_PI_SET_A0] = 1;
162
+          //u8g->pin_list[U8G_PI_SET_A0] = 1;
174
-        if ( u8g_com_ssd_I2C_start_sequence(u8g) == 0 )
163
+          if (u8g_com_ssd_I2C_start_sequence(u8g) == 0)
175
-          return u8g_i2c_stop(), 0;
164
+            return u8g_i2c_stop(), 0;
176
-        {
165
+
177
           register uint8_t *ptr = (uint8_t *)arg_ptr;
166
           register uint8_t *ptr = (uint8_t *)arg_ptr;
178
           while (arg_val > 0) {
167
           while (arg_val > 0) {
179
-            if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
168
+            if (u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0)
180
               return 0;
169
               return 0;
181
             ptr++;
170
             ptr++;
182
             arg_val--;
171
             arg_val--;
190
         u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
179
         u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
191
 
180
 
192
         u8g_i2c_start(0); // send slave address and write bit
181
         u8g_i2c_start(0); // send slave address and write bit
193
-        if (arg_val)
182
+        u8g_i2c_send_byte(arg_val ? 0x40 : 0x80);  // Write to ? Graphics DRAM mode : Command mode
194
-          u8g_i2c_send_byte(0x40);  // write to graphics DRAM mode
195
-        else
196
-          u8g_i2c_send_byte(0x80);  //command mode
197
         break;
183
         break;
198
-    }
184
+
185
+    } // switch
199
     return 1;
186
     return 1;
200
   }
187
   }
201
 
188
 

+ 138
- 170
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_ssd_sw_i2c.cpp under construction 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*  based on U8G2 code
23
+/**
24
-
24
+ * Based on U8G2 code - u8x8_byte.c
25
-  u8x8_byte.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
27
-  Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
27
+ *
28
-
28
+ * Copyright (c) 2016, olikraus@gmail.com
29
-  Copyright (c) 2016, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-
57
-*/
58
 
55
 
59
-/*
56
+/**
60
-  software i2c,
57
+ * Software i2c,
61
-  ignores ACK response (which is anyway not provided by some displays)
58
+ * ignores ACK response (which is anyway not provided by some displays)
62
-  also does not allow reading from the device
59
+ * also does not allow reading from the device
63
-*/
60
+ */
64
 
61
 
65
 #ifdef TARGET_LPC1768
62
 #ifdef TARGET_LPC1768
66
 
63
 
80
 //#define SPEED_400KHz 3
77
 //#define SPEED_400KHz 3
81
 //#define SPEED_100KHz 13
78
 //#define SPEED_100KHz 13
82
 
79
 
83
-
84
 //    #define U8G_I2C_OPT_FAST 16
80
 //    #define U8G_I2C_OPT_FAST 16
85
 
81
 
86
-
87
-
88
 uint8_t SCL_pin_HAL_LPC1768_sw_I2C, SCL_port_HAL_LPC1768_sw_I2C, SDA_pin_HAL_LPC1768_sw_I2C, SDA_port_HAL_LPC1768_sw_I2C;
82
 uint8_t SCL_pin_HAL_LPC1768_sw_I2C, SCL_port_HAL_LPC1768_sw_I2C, SDA_pin_HAL_LPC1768_sw_I2C, SDA_port_HAL_LPC1768_sw_I2C;
89
 
83
 
90
 #define SPI_SPEED 2  //20: 200KHz 5:750KHz 2:3-4MHz
84
 #define SPI_SPEED 2  //20: 200KHz 5:750KHz 2:3-4MHz
91
 
85
 
92
 uint8_t u8g_i2c_send_byte_sw(uint8_t data) {
86
 uint8_t u8g_i2c_send_byte_sw(uint8_t data) {
93
-{
94
   for (uint8_t i = 0; i < 9; i++) {   // 1 extra bit for the ack/nak
87
   for (uint8_t i = 0; i < 9; i++) {   // 1 extra bit for the ack/nak
95
 
88
 
96
     if (val & 0x80)
89
     if (val & 0x80)
118
       LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
111
       LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
119
       LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
112
       LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
120
     }
113
     }
121
-    val = val << 1;
114
+    val <<= 1;
122
   }
115
   }
123
   return 1;
116
   return 1;
124
 }
117
 }
125
 
118
 
126
 
119
 
127
 uint8_t u8g_i2c_start_sw(uint8_t sla) {  // assert start condition and then send slave address with write bit
120
 uint8_t u8g_i2c_start_sw(uint8_t sla) {  // assert start condition and then send slave address with write bit
128
-{
129
   /* send the start condition, both lines go from 1 to 0 */
121
   /* send the start condition, both lines go from 1 to 0 */
130
 
122
 
131
   LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
123
   LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
143
 }
135
 }
144
 
136
 
145
 
137
 
146
-void u8g_i2c_stop_sw(void) {
138
+void u8g_i2c_stop_sw(void) { }
147
-}
148
 
139
 
149
-void u8g_i2c_init_sw(uint8_t clock_option) {
140
+void u8g_i2c_init_sw(uint8_t clock_option) { u8g_i2c_start(0); } // send slave address and write bit
150
-  u8g_i2c_start(0); // send slave address and write bit
151
-}
152
 
141
 
142
+uint8_t  u8g_com_ssd_I2C_start_sequence_sw(u8g_t *u8g) {
143
+  /* are we requested to set the a0 state? */
144
+  if (u8g->pin_list[U8G_PI_SET_A0] == 0) return 1;
153
 
145
 
146
+  /* setup bus, might be a repeated start */
147
+  if (u8g_i2c_start(I2C_SLA) == 0) return 0;
148
+  if (u8g->pin_list[U8G_PI_A0_STATE] == 0) {
149
+    if (u8g_i2c_send_byte(I2C_CMD_MODE) == 0) return 0;
150
+  }
151
+  else if (u8g_i2c_send_byte(I2C_DATA_MODE) == 0) return 0;
154
 
152
 
155
-  uint8_t  u8g_com_ssd_I2C_start_sequence_sw(u8g_t *u8g)
153
+  u8g->pin_list[U8G_PI_SET_A0] = 0;
156
-  {
157
-    /* are we requested to set the a0 state? */
158
-    if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
159
-      return 1;
160
 
154
 
161
-    /* setup bus, might be a repeated start */
155
+  return 1;
162
-    if ( u8g_i2c_start(I2C_SLA) == 0 )
156
+}
163
-      return 0;
164
-    if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
165
-    {
166
-      if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
167
-        return 0;
168
-    }
169
-    else
170
-    {
171
-      if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
172
-        return 0;
173
-    }
174
-
175
-    u8g->pin_list[U8G_PI_SET_A0] = 0;
176
-      return 1;
177
-  }
178
 
157
 
179
-  uint8_t u8g_com_HAL_LPC1768_ssd_sw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
158
+uint8_t u8g_com_HAL_LPC1768_ssd_sw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
180
-  {
159
+  switch (msg) {
181
-    switch(msg)
160
+    case U8G_COM_MSG_INIT:
182
-    {
161
+
183
-      case U8G_COM_MSG_INIT:
162
+      #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
184
-
163
+      #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
185
-        #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111))
164
+      SCL_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCL]);
186
-        #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111))
165
+      SCL_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCL]);
187
-        SCL_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SCL]);
166
+      SDA_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SDA]);
188
-        SCL_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SCL]);
167
+      SDA_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SDA]);
189
-        SDA_pin_HAL_LPC1768_sw_I2C = LPC1768_PIN_PIN(u8g->pin_list[U8G_PI_SDA]);
168
+      // As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
190
-        SDA_port_HAL_LPC1768_sw_I2C = LPC1768_PIN_PORT(u8g->pin_list[U8G_PI_SDA]);
169
+      #define OUTPUT 0x1
191
-        // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
170
+      u8g_SetPIOutput(u8g, U8G_PI_SCL);
192
-        #define OUPUT 0x1
171
+      u8g_SetPIOutput(u8g, U8G_PI_SDA);
193
-        u8g_SetPIOutput(u8g, U8G_PI_SCL);
172
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])  u8g_SetPIOutput(u8g, U8G_PI_CS);
194
-        u8g_SetPIOutput(u8g, U8G_PI_SDA);
173
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_A0])  u8g_SetPIOutput(u8g, U8G_PI_A0);
195
-        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])  u8g_SetPIOutput(u8g, U8G_PI_CS);
174
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET])  u8g_SetPIOutput(u8g, U8G_PI_RESET);
196
-        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_A0])  u8g_SetPIOutput(u8g, U8G_PI_A0);
175
+
197
-        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET])  u8g_SetPIOutput(u8g, U8G_PI_RESET);
176
+      //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
198
-
177
+      //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
199
-        //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
178
+      //u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: unknown mode */
200
-        //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
179
+
201
-        //u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: unknown mode */
180
+      u8g_i2c_init_sw(u8g->pin_list[U8G_PI_I2C_OPTION]);
202
-
181
+      u8g_com_ssd_I2C_start_sequence_sw(u8g);
203
-        u8g_i2c_init_sw(u8g->pin_list[U8G_PI_I2C_OPTION]);
182
+      break;
204
-        u8g_com_ssd_I2C_start_sequence_sw((u8g);
183
+
205
-        break;
184
+    case U8G_COM_MSG_STOP: break;
206
-
185
+
207
-      case U8G_COM_MSG_STOP:
186
+    case U8G_COM_MSG_RESET: break;
208
-        break;
187
+
209
-
188
+    case U8G_COM_MSG_CHIP_SELECT:
210
-      case U8G_COM_MSG_RESET:
189
+      u8g->pin_list[U8G_PI_A0_STATE] = 0;
211
-        break;
190
+      u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
212
-
191
+      if (arg_val == 0) {
213
-      case U8G_COM_MSG_CHIP_SELECT:
192
+        /* disable chip, send stop condition */
214
-        u8g->pin_list[U8G_PI_A0_STATE] = 0;
193
+        u8g_i2c_stop_sw();
215
-        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again, also forces start condition */
194
+      }
216
-        if ( arg_val == 0 )
195
+      else {
217
-        {
196
+        /* enable, do nothing: any byte writing will trigger the i2c start */
218
-          /* disable chip, send stop condition */
197
+      }
219
-          u8g_i2c_stop_sw();
198
+      break;
220
-        }
199
+
221
-        else
200
+    case U8G_COM_MSG_WRITE_BYTE:
222
-        {
201
+      //u8g->pin_list[U8G_PI_SET_A0] = 1;
223
-          /* enable, do nothing: any byte writing will trigger the i2c start */
202
+      //if (u8g_com_arduino_ssd_start_sequence(u8g) == 0)
224
-        }
203
+      //  return u8g_i2c_stop(), 0;
225
-        break;
204
+      if (u8g_i2c_send_byte_sw(arg_val) == 0)
226
-
205
+        return u8g_i2c_stop_sw(), 0;
227
-      case U8G_COM_MSG_WRITE_BYTE:
228
-        //u8g->pin_list[U8G_PI_SET_A0] = 1;
229
-//          if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
230
-//            return u8g_i2c_stop(), 0;
231
-        if ( u8g_i2c_send_byte_sw(arg_val) == 0 )
232
-          return u8g_i2c_stop_sw(), 0;
233
         // u8g_i2c_stop();
206
         // u8g_i2c_stop();
234
-        break;
207
+      break;
235
-
208
+
236
-      case U8G_COM_MSG_WRITE_SEQ:
209
+    case U8G_COM_MSG_WRITE_SEQ: {
237
-        //u8g->pin_list[U8G_PI_SET_A0] = 1;
210
+      //u8g->pin_list[U8G_PI_SET_A0] = 1;
238
-        if ( u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0 )
211
+      if (u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0)
239
-          return u8g_i2c_stop_sw(), 0;
212
+        return u8g_i2c_stop_sw(), 0;
240
-        {
213
+
241
-          register uint8_t *ptr = (uint8_t *)arg_ptr;
214
+        register uint8_t *ptr = (uint8_t *)arg_ptr;
242
-          while (arg_val > 0) {
215
+        while (arg_val > 0) {
243
-            if ( u8g_i2c_send_byte_sw(*ptr++) == 0 )
216
+          if (u8g_i2c_send_byte_sw(*ptr++) == 0)
244
-              return u8g_i2c_stop_sw(), 0;
217
+            return u8g_i2c_stop_sw(), 0;
245
-            arg_val--;
218
+          arg_val--;
246
-          }
247
         }
219
         }
248
-        // u8g_i2c_stop();
220
+      }
249
-        break;
221
+      // u8g_i2c_stop();
250
-
222
+      break;
251
-      case U8G_COM_MSG_WRITE_SEQ_P:
223
+
252
-        //u8g->pin_list[U8G_PI_SET_A0] = 1;
224
+    case U8G_COM_MSG_WRITE_SEQ_P: {
253
-        if ( u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0 )
225
+      //u8g->pin_list[U8G_PI_SET_A0] = 1;
254
-          return u8g_i2c_stop_sw(), 0;
226
+      if (u8g_com_ssd_I2C_start_sequence_sw(u8g) == 0)
255
-        {
227
+        return u8g_i2c_stop_sw(), 0;
256
-          register uint8_t *ptr = (uint8_t *)arg_ptr;
228
+
257
-          while (arg_val > 0) {
229
+        register uint8_t *ptr = (uint8_t *)arg_ptr;
258
-            if ( u8g_i2c_send_byte_sw(u8g_pgm_read(ptr)) == 0 )
230
+        while (arg_val > 0) {
259
-              return 0;
231
+          if (u8g_i2c_send_byte_sw(u8g_pgm_read(ptr)) == 0) return 0;
260
-            ptr++;
232
+          ptr++;
261
-            arg_val--;
233
+          arg_val--;
262
-          }
263
         }
234
         }
264
-        // u8g_i2c_stop();
235
+      }
265
-        break;
236
+      // u8g_i2c_stop();
266
-
237
+      break;
267
-      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
238
+
268
-        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
239
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
269
-        u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
240
+      u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
270
-
241
+      u8g->pin_list[U8G_PI_SET_A0] = 1;   /* force a0 to set again */
271
-        u8g_i2c_start_sw(0); // send slave address and write bit
242
+      u8g_i2c_start_sw(0); // send slave address and write bit
272
-        if (arg_val)
243
+      u8g_i2c_send_byte_sw(arg_val ? 0x40 : 0x80);  // Write to ? Graphics DRAM mode : Command mode
273
-          u8g_i2c_send_byte_sw(0x40);  // write to graphics DRAM mode
244
+      break;
274
-        else
275
-          u8g_i2c_send_byte_sw(0x80);  //command mode
276
-        break;
277
-    }
278
-    return 1;
279
   }
245
   }
246
+  return 1;
247
+}
280
 
248
 
281
 #endif  // TARGET_LPC1768
249
 #endif  // TARGET_LPC1768

+ 32
- 34
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*
23
+/**
24
-
24
+ * Based on u8g_com_LPC1768_st7920_hw_spi.c
25
-  based on u8g_com_LPC1768_st7920_hw_spi.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library
27
-  Universal 8bit Graphics Library
27
+ *
28
-
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-  Copyright (c) 2011, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-*/
57
 
55
 
58
 #ifdef TARGET_LPC1768
56
 #ifdef TARGET_LPC1768
59
 
57
 

+ 32
- 34
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*
23
+/**
24
-
24
+ * Based on u8g_com_st7920_hw_spi.c
25
-  based on u8g_com_st7920_hw_spi.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library
27
-  Universal 8bit Graphics Library
27
+ *
28
-
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-  Copyright (c) 2011, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-*/
57
 
55
 
58
 #ifdef TARGET_LPC1768
56
 #ifdef TARGET_LPC1768
59
 
57
 

+ 35
- 40
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_sw_spi.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*
23
+/**
24
-
24
+ * Based on u8g_com_std_sw_spi.c
25
-  adapted from u8g_com_std_sw_spi.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library
27
-  Universal 8bit Graphics Library
27
+ *
28
-
28
+ * Copyright (c) 2015, olikraus@gmail.com
29
-  Copyright (c) 2015, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-*/
57
 
55
 
58
 #ifdef TARGET_LPC1768
56
 #ifdef TARGET_LPC1768
59
 
57
 
64
 
62
 
65
 static uint8_t SPI_speed = 0;
63
 static uint8_t SPI_speed = 0;
66
 
64
 
67
-static void u8g_sw_spi_HAL_LPC1768_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val)
65
+static void u8g_sw_spi_HAL_LPC1768_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
68
-{
69
   swSpiTransfer(val, SPI_speed, clockPin, -1, dataPin);
66
   swSpiTransfer(val, SPI_speed, clockPin, -1, dataPin);
70
 }
67
 }
71
 
68
 
72
-uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
69
+uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
73
-{
70
+  switch(msg) {
74
-  switch(msg)
75
-  {
76
     case U8G_COM_MSG_INIT:
71
     case U8G_COM_MSG_INIT:
77
       u8g_SetPIOutput(u8g, U8G_PI_SCK);
72
       u8g_SetPIOutput(u8g, U8G_PI_SCK);
78
       u8g_SetPIOutput(u8g, U8G_PI_MOSI);
73
       u8g_SetPIOutput(u8g, U8G_PI_MOSI);

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp 查看文件

513
           }
513
           }
514
           else {
514
           else {
515
             const float cvf = parser.value_float();
515
             const float cvf = parser.value_float();
516
-            switch((int)truncf(cvf * 10.0) - 30) {   // 3.1 -> 1
516
+            switch ((int)truncf(cvf * 10.0) - 30) {   // 3.1 -> 1
517
               #if ENABLED(UBL_G29_P31)
517
               #if ENABLED(UBL_G29_P31)
518
                 case 1: {
518
                 case 1: {
519
 
519
 

+ 6
- 6
Marlin/src/feature/tmc_util.cpp 查看文件

314
 
314
 
315
   #if ENABLED(HAVE_TMC2130)
315
   #if ENABLED(HAVE_TMC2130)
316
     static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
316
     static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
317
-      switch(i) {
317
+      switch (i) {
318
         case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
318
         case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
319
         case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
319
         case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
320
         case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
320
         case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
323
       }
323
       }
324
     }
324
     }
325
     static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
325
     static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
326
-      switch(i) {
326
+      switch (i) {
327
         case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break;
327
         case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break;
328
         case TMC_SG_RESULT:  SERIAL_PRINT(st.sg_result(), DEC);   break;
328
         case TMC_SG_RESULT:  SERIAL_PRINT(st.sg_result(), DEC);   break;
329
         case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_CHAR('X'); break;
329
         case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_CHAR('X'); break;
333
   #endif
333
   #endif
334
   #if ENABLED(HAVE_TMC2208)
334
   #if ENABLED(HAVE_TMC2208)
335
     static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
335
     static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
336
-      switch(i) {
336
+      switch (i) {
337
         case TMC_TSTEP: { uint32_t data = 0; st.TSTEP(&data); SERIAL_PROTOCOL(data); break; }
337
         case TMC_TSTEP: { uint32_t data = 0; st.TSTEP(&data); SERIAL_PROTOCOL(data); break; }
338
         case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
338
         case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
339
         case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
339
         case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
343
       }
343
       }
344
     }
344
     }
345
     static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
345
     static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
346
-      switch(i) {
346
+      switch (i) {
347
         case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break;
347
         case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break;
348
         case TMC_T150: if (st.t150()) SERIAL_CHAR('X'); break;
348
         case TMC_T150: if (st.t150()) SERIAL_CHAR('X'); break;
349
         case TMC_T143: if (st.t143()) SERIAL_CHAR('X'); break;
349
         case TMC_T143: if (st.t143()) SERIAL_CHAR('X'); break;
356
   template <typename TMC>
356
   template <typename TMC>
357
   static void tmc_status(TMC &st, const TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
357
   static void tmc_status(TMC &st, const TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
358
     SERIAL_ECHO('\t');
358
     SERIAL_ECHO('\t');
359
-    switch(i) {
359
+    switch (i) {
360
       case TMC_CODES: _tmc_say_axis(axis); break;
360
       case TMC_CODES: _tmc_say_axis(axis); break;
361
       case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
361
       case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
362
       case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
362
       case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
401
   template <typename TMC>
401
   template <typename TMC>
402
   static void tmc_parse_drv_status(TMC &st, const TMC_AxisEnum axis, const TMC_drv_status_enum i) {
402
   static void tmc_parse_drv_status(TMC &st, const TMC_AxisEnum axis, const TMC_drv_status_enum i) {
403
     SERIAL_CHAR('\t');
403
     SERIAL_CHAR('\t');
404
-    switch(i) {
404
+    switch (i) {
405
       case TMC_DRV_CODES:     _tmc_say_axis(axis);  break;
405
       case TMC_DRV_CODES:     _tmc_say_axis(axis);  break;
406
       case TMC_STST:          if (st.stst())         SERIAL_CHAR('X'); break;
406
       case TMC_STST:          if (st.stst())         SERIAL_CHAR('X'); break;
407
       case TMC_OLB:           if (st.olb())          SERIAL_CHAR('X'); break;
407
       case TMC_OLB:           if (st.olb())          SERIAL_CHAR('X'); break;

+ 102
- 131
Marlin/src/lcd/dogm/u8g_dev_ssd1306_sh1106_128x64_I2C.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-
23
+/**
24
-/*
24
+ * Based on u8g_dev_ssd1306_128x64.c
25
-
25
+ *
26
-  u8g_dev_ssd1306_128x64.c
26
+ * Universal 8bit Graphics Library
27
-
27
+ *
28
-  Universal 8bit Graphics Library
28
+ * Copyright (c) 2015, olikraus@gmail.com
29
-
29
+ * All rights reserved.
30
-  Copyright (c) 2011, olikraus@gmail.com
30
+ *
31
-  All rights reserved.
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-
32
+ * are permitted provided that the following conditions are met:
33
-  Redistribution and use in source and binary forms, with or without modification,
33
+ *
34
-  are permitted provided that the following conditions are met:
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-
35
+ *    of conditions and the following disclaimer.
36
-  * Redistributions of source code must retain the above copyright notice, this list
36
+ *
37
-    of conditions and the following disclaimer.
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-  * Redistributions in binary form must reproduce the above copyright notice, this
39
+ *    materials provided with the distribution.
40
-    list of conditions and the following disclaimer in the documentation and/or other
40
+ *
41
-    materials provided with the distribution.
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+ */
55
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
-
57
-
58
-*/
59
 
55
 
60
 /**
56
 /**
61
  * These routines are meant for two wire I2C interfaces.
57
  * These routines are meant for two wire I2C interfaces.
85
 // The sh1106 is compatible to the ssd1306, but is 132x64. 128x64 display area is centered within
81
 // The sh1106 is compatible to the ssd1306, but is 132x64. 128x64 display area is centered within
86
 // the 132x64.
82
 // the 132x64.
87
 
83
 
88
-
89
 static const uint8_t u8g_dev_sh1106_128x64_data_start_2_wire[] PROGMEM = {
84
 static const uint8_t u8g_dev_sh1106_128x64_data_start_2_wire[] PROGMEM = {
90
-  0x010,    // set upper 4 bit of the col adr to 0
85
+  0x010,          // set upper 4 bit of the col adr to 0
91
-  0x002,    // set lower 4 bit of the col adr to 2 (centered display with ssd1306)
86
+  0x002,          // set lower 4 bit of the col adr to 2 (centered display with ssd1306)
92
-  U8G_ESC_END                // end of sequence
87
+  U8G_ESC_END     // end of sequence
93
 };
88
 };
94
 
89
 
95
-
96
 static const uint8_t u8g_dev_sh1106_128x64_init_seq_2_wire[] PROGMEM = {
90
 static const uint8_t u8g_dev_sh1106_128x64_init_seq_2_wire[] PROGMEM = {
97
-  U8G_ESC_ADR(0),  // initiate command mode
91
+  U8G_ESC_ADR(0), // initiate command mode
98
-  0x0ae,        /* display off, sleep mode */
92
+  0x0AE,          // display off, sleep mode
99
-  0x0a8, 0x03f,   /* mux ratio */
93
+  0x0A8, 0x03F,   // mux ratio
100
-  0x0d3, 0x00,    /* display offset */
94
+  0x0D3, 0x00,    // display offset
101
-  0x040,        /* start line */
95
+  0x040,          // start line
102
-  0x0a1,        /* segment remap a0/a1*/
96
+  0x0A1,          // segment remap a0/a1
103
-  0x0c8,        /* c0: scan dir normal, c8: reverse */
97
+  0x0C8,          // c0: scan dir normal, c8: reverse
104
-  0x0da, 0x012,   /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
98
+  0x0DA, 0x012,   // com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5)
105
-  0x081, 0x0cf,   /* [2] set contrast control */
99
+  0x081, 0x0CF,   // [2] set contrast control
106
-  0x020, 0x002,   /* 2012-05-27: page addressing mode */
100
+  0x020, 0x002,   // 2012-05-27: page addressing mode
107
-  0x21, 2, 0x81,   // set column range from 0 through 131
101
+  0x21, 2, 0x81,  // set column range from 0 through 131
108
-  0x22, 0, 7,   // set page range from 0 through 7
102
+  0x22, 0, 7,     // set page range from 0 through 7
109
-  0x0d9, 0x0f1,   /* [2] pre-charge period 0x022/f1*/
103
+  0x0D9, 0x0F1,   // [2] pre-charge period 0x022/f1
110
-  0x0db, 0x040,   /* vcomh deselect level */
104
+  0x0DB, 0x040,   // vcomh deselect level
111
-  0x0a4,        /* output ram to display */
105
+  0x0A4,          // output ram to display
112
-  0x0a6,        /* none inverted normal display mode */
106
+  0x0A6,          // none inverted normal display mode
113
-  0x0d5, 0x080,   /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
107
+  0x0D5, 0x080,   // clock divide ratio (0x00=1) and oscillator frequency (0x8)
114
-  0x08d, 0x014,   /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
108
+  0x08D, 0x014,   // [2] charge pump setting (p62): 0x014 enable, 0x010 disable
115
-  0x02e,        /* 2012-05-27: Deactivate scroll */
109
+  0x02E,          // 2012-05-27: Deactivate scroll
116
-  0x0af,        /* display on */
110
+  0x0AF,          // display on
117
-  U8G_ESC_END                /* end of sequence */
111
+  U8G_ESC_END     // end of sequence
118
 };
112
 };
119
 
113
 
120
-
114
+uint8_t u8g_dev_sh1106_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
121
-uint8_t u8g_dev_sh1106_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
115
+  switch(msg) {
122
-{
123
-  switch(msg)
124
-  {
125
     case U8G_DEV_MSG_INIT:
116
     case U8G_DEV_MSG_INIT:
126
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
117
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
127
       u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_init_seq_2_wire);
118
       u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_sh1106_128x64_init_seq_2_wire);
152
   return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
143
   return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
153
 }
144
 }
154
 
145
 
155
-
156
 uint8_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf[WIDTH*2] U8G_NOCOMMON ;
146
 uint8_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf[WIDTH*2] U8G_NOCOMMON ;
157
 u8g_pb_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf};
147
 u8g_pb_t u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_sh1106_128x64_2x_i2c_2_wire_buf};
158
 u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire = { u8g_dev_sh1106_128x64_2x_2_wire_fn, &u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb, U8G_COM_SSD_I2C_HAL };
148
 u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire = { u8g_dev_sh1106_128x64_2x_2_wire_fn, &u8g_dev_sh1106_128x64_2x_i2c_2_wire_pb, U8G_COM_SSD_I2C_HAL };
160
 /////////////////////////////////////////////////////////////////////////////////////////////
150
 /////////////////////////////////////////////////////////////////////////////////////////////
161
 
151
 
162
 static const uint8_t u8g_dev_ssd1306_128x64_data_start_2_wire[] PROGMEM = {
152
 static const uint8_t u8g_dev_ssd1306_128x64_data_start_2_wire[] PROGMEM = {
163
-  0x010,    // set upper 4 bit of the col adr to 0
153
+  0x010,          // set upper 4 bit of the col adr to 0
164
-  0x000,    // set lower 4 bit of the col adr to 0
154
+  0x000,          // set lower 4 bit of the col adr to 0
165
-  U8G_ESC_END                // end of sequence
155
+  U8G_ESC_END     // end of sequence
166
 };
156
 };
167
 
157
 
168
-
169
 static const uint8_t u8g_dev_ssd1306_128x64_init_seq_2_wire[] PROGMEM = {
158
 static const uint8_t u8g_dev_ssd1306_128x64_init_seq_2_wire[] PROGMEM = {
170
-  U8G_ESC_ADR(0),  // initiate command mode
159
+  U8G_ESC_ADR(0), // initiate command mode
171
-  0x0ae,        /* display off, sleep mode */
160
+  0x0AE,          // display off, sleep mode
172
-  0x0a8, 0x03f,   /* mux ratio */
161
+  0x0A8, 0x03F,   // mux ratio
173
-  0x0d3, 0x00,    /* display offset */
162
+  0x0D3, 0x00,    // display offset
174
-  0x040,        /* start line */
163
+  0x040,          // start line
175
-  0x0a1,        /* segment remap a0/a1*/
164
+  0x0A1,          // segment remap a0/a1
176
-  0x0c8,        /* c0: scan dir normal, c8: reverse */
165
+  0x0C8,          // c0: scan dir normal, c8: reverse
177
-  0x0da, 0x012,   /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
166
+  0x0DA, 0x012,   // com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5)
178
-  0x081, 0x0cf,   /* [2] set contrast control */
167
+  0x081, 0x0CF,   // [2] set contrast control
179
-  0x020, 0x002,   /* 2012-05-27: page addressing mode */
168
+  0x020, 0x002,   // 2012-05-27: page addressing mode
180
-  0x21, 0, 0x7f,   // set column range from 0 through 127
169
+  0x21, 0, 0x7F,  // set column range from 0 through 127
181
-  0x22, 0, 7,   // set page range from 0 through 7
170
+  0x22, 0, 7,     // set page range from 0 through 7
182
-  0x0d9, 0x0f1,   /* [2] pre-charge period 0x022/f1*/
171
+  0x0D9, 0x0F1,   // [2] pre-charge period 0x022/f1
183
-  0x0db, 0x040,   /* vcomh deselect level */
172
+  0x0DB, 0x040,   // vcomh deselect level
184
-  0x0a4,        /* output ram to display */
173
+  0x0A4,          // output ram to display
185
-  0x0a6,        /* none inverted normal display mode */
174
+  0x0A6,          // none inverted normal display mode
186
-  0x0d5, 0x080,   /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
175
+  0x0D5, 0x080,   // clock divide ratio (0x00=1) and oscillator frequency (0x8)
187
-  0x08d, 0x014,   /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
176
+  0x08D, 0x014,   // [2] charge pump setting (p62): 0x014 enable, 0x010 disable
188
-  0x02e,        /* 2012-05-27: Deactivate scroll */
177
+  0x02E,          // 2012-05-27: Deactivate scroll
189
-  0x0af,        /* display on */
178
+  0x0AF,          // display on
190
-  U8G_ESC_END                /* end of sequence */
179
+  U8G_ESC_END     // end of sequence
191
 };
180
 };
192
 
181
 
193
-
182
+uint8_t u8g_dev_ssd1306_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
194
-uint8_t u8g_dev_ssd1306_128x64_2x_2_wire_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
183
+  switch(msg) {
195
-{
196
-  switch(msg)
197
-  {
198
     case U8G_DEV_MSG_INIT:
184
     case U8G_DEV_MSG_INIT:
199
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
185
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
200
       u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_init_seq_2_wire);
186
       u8g_WriteEscSeqP_2_wire(u8g, dev, u8g_dev_ssd1306_128x64_init_seq_2_wire);
238
 
224
 
239
 #define I2C_CMD_MODE    0x080
225
 #define I2C_CMD_MODE    0x080
240
 
226
 
241
-uint8_t u8g_WriteEscSeqP_2_wire(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq)
227
+uint8_t u8g_WriteEscSeqP_2_wire(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) {
242
-{
243
   uint8_t is_escape = 0;
228
   uint8_t is_escape = 0;
244
   uint8_t value;
229
   uint8_t value;
245
-  for(;;)
230
+  for(;;) {
246
-  {
247
     value = u8g_pgm_read(esc_seq);
231
     value = u8g_pgm_read(esc_seq);
248
-    if ( is_escape == 0 )
232
+    if (is_escape == 0) {
249
-    {
233
+      if (value != 255) {
250
-      if ( value != 255 )
234
+        if (u8g_WriteByte(u8g, dev, value) == 0 )
251
-      {
252
-        if ( u8g_WriteByte(u8g, dev, value) == 0 )
253
           return 0;
235
           return 0;
254
-        if ( u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
236
+        if (u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
255
           return 0;
237
           return 0;
256
       }
238
       }
257
-      else
239
+      else {
258
-      {
259
         is_escape = 1;
240
         is_escape = 1;
260
       }
241
       }
261
     }
242
     }
262
-    else
243
+    else {
263
-    {
244
+      if (value == 255) {
264
-      if ( value == 255 )
245
+        if (u8g_WriteByte(u8g, dev, value) == 0 )
265
-      {
266
-        if ( u8g_WriteByte(u8g, dev, value) == 0 )
267
           return 0;
246
           return 0;
268
-        if ( u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
247
+        if (u8g_WriteByte(u8g, dev, I2C_CMD_MODE) == 0 )
269
           return 0;
248
           return 0;
270
       }
249
       }
271
-      else if ( value == 254 )
250
+      else if (value == 254) {
272
-      {
273
         break;
251
         break;
274
       }
252
       }
275
-      else if ( value >= 0x0f0 )
253
+      else if (value >= 0x0f0) {
276
-      {
277
         /* not yet used, do nothing */
254
         /* not yet used, do nothing */
278
       }
255
       }
279
-      else if ( value >= 0xe0  )
256
+      else if (value >= 0xe0 ) {
280
-      {
281
         u8g_SetAddress(u8g, dev, value & 0x0f);
257
         u8g_SetAddress(u8g, dev, value & 0x0f);
282
       }
258
       }
283
-      else if ( value >= 0xd0 )
259
+      else if (value >= 0xd0) {
284
-      {
285
         u8g_SetChipSelect(u8g, dev, value & 0x0f);
260
         u8g_SetChipSelect(u8g, dev, value & 0x0f);
286
       }
261
       }
287
-      else if ( value >= 0xc0 )
262
+      else if (value >= 0xc0) {
288
-      {
289
         u8g_SetResetLow(u8g, dev);
263
         u8g_SetResetLow(u8g, dev);
290
         value &= 0x0f;
264
         value &= 0x0f;
291
         value <<= 4;
265
         value <<= 4;
294
         u8g_SetResetHigh(u8g, dev);
268
         u8g_SetResetHigh(u8g, dev);
295
         u8g_Delay(value);
269
         u8g_Delay(value);
296
       }
270
       }
297
-      else if ( value >= 0xbe )
271
+      else if (value >= 0xbe) {                       /* not yet implemented */
298
-      {
299
-  /* not yet implemented */
300
         /* u8g_SetVCC(u8g, dev, value & 0x01); */
272
         /* u8g_SetVCC(u8g, dev, value & 0x01); */
301
       }
273
       }
302
-      else if ( value <= 127 )
274
+      else if (value <= 127) {
303
-      {
304
         u8g_Delay(value);
275
         u8g_Delay(value);
305
       }
276
       }
306
       is_escape = 0;
277
       is_escape = 0;

+ 82
- 90
Marlin/src/lcd/dogm/u8g_dev_st7565_64128n_HAL.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-
23
+/**
24
-/*
24
+ * u8g_dev_st7565_64128n_HAL.c (Displaytech)
25
-
25
+ *
26
-  u8g_dev_st7565_64128n_HAL.c (Displaytech)
26
+ * Universal 8bit Graphics Library
27
-
27
+ *
28
-  Universal 8bit Graphics Library
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-
29
+ * All rights reserved.
30
-  Copyright (c) 2011, olikraus@gmail.com
30
+ *
31
-  All rights reserved.
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-
32
+ * are permitted provided that the following conditions are met:
33
-  Redistribution and use in source and binary forms, with or without modification,
33
+ *
34
-  are permitted provided that the following conditions are met:
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-
35
+ *    of conditions and the following disclaimer.
36
-  * Redistributions of source code must retain the above copyright notice, this list
36
+ *
37
-    of conditions and the following disclaimer.
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-  * Redistributions in binary form must reproduce the above copyright notice, this
39
+ *    materials provided with the distribution.
40
-    list of conditions and the following disclaimer in the documentation and/or other
40
+ *
41
-    materials provided with the distribution.
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
+ */
55
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
-
57
-
58
-*/
59
 
55
 
60
 #include "../../inc/MarlinConfig.h"
56
 #include "../../inc/MarlinConfig.h"
61
 
57
 
71
 
67
 
72
 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
68
 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
73
 static const uint8_t u8g_dev_st7565_64128n_HAL_init_seq[] PROGMEM = {
69
 static const uint8_t u8g_dev_st7565_64128n_HAL_init_seq[] PROGMEM = {
74
-   U8G_ESC_CS(0),            /* disable chip */
70
+   U8G_ESC_CS(0),       // disable chip
75
-    U8G_ESC_ADR(0),          /* instruction mode */
71
+    U8G_ESC_ADR(0),     // instruction mode
76
-    U8G_ESC_CS(1),           /* enable chip */
72
+    U8G_ESC_CS(1),      // enable chip
77
-    U8G_ESC_RST(15),         /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
73
+    U8G_ESC_RST(15),    // do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
78
 
74
 
79
-    0x0A2,             /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
75
+    0x0A2,              // 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
80
-    0x0A0,             /* Normal ADC Select (according to Displaytech 64128N datasheet) */
76
+    0x0A0,              // Normal ADC Select (according to Displaytech 64128N datasheet)
81
 
77
 
82
-    0x0c8,                   /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
78
+    0x0c8,              // common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1
83
-    0x040,               /* Display start line for Displaytech 64128N */
79
+    0x040,              // Display start line for Displaytech 64128N
84
 
80
 
85
-    0x028 | 0x04,            /* power control: turn on voltage converter */
81
+    0x028 | 0x04,       // power control: turn on voltage converter
86
-    U8G_ESC_DLY(50),         /* delay 50 ms */
82
+    U8G_ESC_DLY(50),    // delay 50 ms
87
 
83
 
88
-    0x028 | 0x06,            /* power control: turn on voltage regulator */
84
+    0x028 | 0x06,       // power control: turn on voltage regulator
89
-    U8G_ESC_DLY(50),         /* delay 50 ms */
85
+    U8G_ESC_DLY(50),    // delay 50 ms
90
 
86
 
91
-    0x028 | 0x07,            /* power control: turn on voltage follower */
87
+    0x028 | 0x07,       // power control: turn on voltage follower
92
-    U8G_ESC_DLY(50),         /* delay 50 ms */
88
+    U8G_ESC_DLY(50),    // delay 50 ms
93
 
89
 
94
-    0x010,                   /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
90
+    0x010,              // Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N
95
 
91
 
96
-    0x0a6,                   /* display normal, bit val 0: LCD pixel off. */
92
+    0x0a6,              // display normal, bit val 0: LCD pixel off.
97
 
93
 
98
-    0x081,                   /* set contrast */
94
+    0x081,              // set contrast
99
-    0x01e,                 /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
95
+    0x01e,              // Contrast value. Setting for controlling brightness of Displaytech 64128N
100
 
96
 
101
 
97
 
102
-    0x0af,               /* display on */
98
+    0x0af,              // display on
103
 
99
 
104
-    U8G_ESC_DLY(100),        /* delay 100 ms */
100
+    U8G_ESC_DLY(100),   // delay 100 ms
105
-    0x0a5,               /* display all points, ST7565 */
101
+    0x0a5,              // display all points, ST7565
106
-    U8G_ESC_DLY(100),        /* delay 100 ms */
102
+    U8G_ESC_DLY(100),   // delay 100 ms
107
-    U8G_ESC_DLY(100),        /* delay 100 ms */
103
+    U8G_ESC_DLY(100),   // delay 100 ms
108
-    0x0a4,               /* normal display */
104
+    0x0a4,              // normal display
109
-    U8G_ESC_CS(0),           /* disable chip */
105
+    U8G_ESC_CS(0),      // disable chip
110
-    U8G_ESC_END              /* end of sequence */
106
+    U8G_ESC_END         // end of sequence
111
 };
107
 };
112
 
108
 
113
 static const uint8_t u8g_dev_st7565_64128n_HAL_data_start[] PROGMEM = {
109
 static const uint8_t u8g_dev_st7565_64128n_HAL_data_start[] PROGMEM = {
114
-  U8G_ESC_ADR(0),           /* instruction mode */
110
+  U8G_ESC_ADR(0),       // instruction mode
115
-  U8G_ESC_CS(1),            /* enable chip */
111
+  U8G_ESC_CS(1),        // enable chip
116
-  0x010,                  /* set upper 4 bit of the col adr to 0x10 */
112
+  0x010,                // set upper 4 bit of the col adr to 0x10
117
-  0x000,                /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
113
+  0x000,                // set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N
118
-  U8G_ESC_END               /* end of sequence */
114
+  U8G_ESC_END           // end of sequence
119
 };
115
 };
120
 
116
 
121
 static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_on[] PROGMEM = {
117
 static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_on[] PROGMEM = {
122
-  U8G_ESC_ADR(0),           /* instruction mode */
118
+  U8G_ESC_ADR(0),       // instruction mode
123
-  U8G_ESC_CS(1),             /* enable chip */
119
+  U8G_ESC_CS(1),        // enable chip
124
-  0x0ac,    /* static indicator off */
120
+  0x0ac,                // static indicator off
125
-  0x000,                    /* indicator register set (not sure if this is required) */
121
+  0x000,                // indicator register set (not sure if this is required)
126
-  0x0ae,    /* display off */
122
+  0x0ae,                // display off
127
-  0x0a5,    /* all points on */
123
+  0x0a5,                // all points on
128
-  U8G_ESC_CS(0),             /* disable chip, bugfix 12 nov 2014 */
124
+  U8G_ESC_CS(0),        // disable chip, bugfix 12 nov 2014
129
-  U8G_ESC_END                /* end of sequence */
125
+  U8G_ESC_END           // end of sequence
130
   };
126
   };
131
 
127
 
132
 static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_off[] PROGMEM = {
128
 static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_off[] PROGMEM = {
133
-  U8G_ESC_ADR(0),           /* instruction mode */
129
+  U8G_ESC_ADR(0),       // instruction mode
134
-  U8G_ESC_CS(1),             /* enable chip */
130
+  U8G_ESC_CS(1),        // enable chip
135
-  0x0a4,    /* all points off */
131
+  0x0a4,                // all points off
136
-  0x0af,    /* display on */
132
+  0x0af,                // display on
137
-  U8G_ESC_DLY(50),       /* delay 50 ms */
133
+  U8G_ESC_DLY(50),      // delay 50 ms
138
-  U8G_ESC_CS(0),             /* disable chip, bugfix 12 nov 2014 */
134
+  U8G_ESC_CS(0),        // disable chip, bugfix 12 nov 2014
139
-  U8G_ESC_END                /* end of sequence */
135
+  U8G_ESC_END           // end of sequence
140
 };
136
 };
141
 
137
 
142
-uint8_t u8g_dev_st7565_64128n_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
138
+uint8_t u8g_dev_st7565_64128n_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
143
-{
139
+  switch(msg) {
144
-  switch(msg)
145
-  {
146
     case U8G_DEV_MSG_INIT:
140
     case U8G_DEV_MSG_INIT:
147
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
141
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
148
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
142
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
176
   return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
170
   return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
177
 }
171
 }
178
 
172
 
179
-uint8_t u8g_dev_st7565_64128n_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
173
+uint8_t u8g_dev_st7565_64128n_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
180
-{
174
+  switch(msg) {
181
-  switch(msg)
182
-  {
183
     case U8G_DEV_MSG_INIT:
175
     case U8G_DEV_MSG_INIT:
184
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
176
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
185
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
177
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);

+ 104
- 121
Marlin/src/lcd/dogm/u8g_dev_st7920_128x64_HAL.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-/*
23
+/**
24
-
24
+ * u8g_dev_st7920_128x64_HAL.c
25
-  u8g_dev_st7920_128x64_HAL.c
25
+ *
26
-
26
+ * Universal 8bit Graphics Library
27
-  Universal 8bit Graphics Library
27
+ *
28
-
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
-  Copyright (c) 2011, olikraus@gmail.com
29
+ * All rights reserved.
30
-  All rights reserved.
30
+ *
31
-
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
-  Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
-  are permitted provided that the following conditions are met:
33
+ *
34
-
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
-  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
-    of conditions and the following disclaimer.
36
+ *
37
-
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
-  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
-    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
-    materials provided with the distribution.
40
+ *
41
-
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
-  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
-  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
-  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
-  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
-  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
-  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
-  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
-  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
-  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
-  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
-  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
-
56
-
57
-*/
58
 
55
 
59
 #include "../../inc/MarlinConfig.h"
56
 #include "../../inc/MarlinConfig.h"
60
 
57
 
68
 #define HEIGHT 64
65
 #define HEIGHT 64
69
 #define PAGE_HEIGHT 8
66
 #define PAGE_HEIGHT 8
70
 
67
 
71
-
72
 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
68
 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
73
 static const uint8_t u8g_dev_st7920_128x64_HAL_init_seq[] PROGMEM = {
69
 static const uint8_t u8g_dev_st7920_128x64_HAL_init_seq[] PROGMEM = {
74
-  U8G_ESC_CS(0),             /* disable chip */
70
+  U8G_ESC_CS(0),      // disable chip
75
-  U8G_ESC_ADR(0),           /* instruction mode */
71
+  U8G_ESC_ADR(0),     // instruction mode
76
-  U8G_ESC_RST(15),           /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
72
+  U8G_ESC_RST(15),    // do reset low pulse with (15*16)+2 milliseconds (=maximum delay)
77
-  U8G_ESC_DLY(100),         /* 8 Dez 2012: additional delay 100 ms because of reset*/
73
+  U8G_ESC_DLY(100),   // 8 Dez 2012: additional delay 100 ms because of reset
78
-  U8G_ESC_CS(1),             /* enable chip */
74
+  U8G_ESC_CS(1),      // enable chip
79
-  U8G_ESC_DLY(50),         /* delay 50 ms */
75
+  U8G_ESC_DLY(50),    // delay 50 ms
80
-
76
+
81
-  0x038,                                /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
77
+  0x038,              // 8 Bit interface (DL=1), basic instruction set (RE=0)
82
-  0x00c,                                /* display on, cursor & blink off; 0x08: all off */
78
+  0x00c,              // display on, cursor & blink off; 0x08: all off
83
-  0x006,                                /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
79
+  0x006,              // Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift
84
-  0x002,                                /* disable scroll, enable CGRAM adress */
80
+  0x002,              // disable scroll, enable CGRAM adress
85
-  0x001,                                /* clear RAM, needs 1.6 ms */
81
+  0x001,              // clear RAM, needs 1.6 ms
86
-  U8G_ESC_DLY(100),               /* delay 100 ms */
82
+  U8G_ESC_DLY(100),   // delay 100 ms
87
-
83
+
88
-  U8G_ESC_CS(0),             /* disable chip */
84
+  U8G_ESC_CS(0),      // disable chip
89
-  U8G_ESC_END                /* end of sequence */
85
+  U8G_ESC_END         // end of sequence
90
 };
86
 };
91
 
87
 
92
 void clear_graphics_DRAM(u8g_t *u8g, u8g_dev_t *dev){
88
 void clear_graphics_DRAM(u8g_t *u8g, u8g_dev_t *dev){
107
   u8g_WriteByte(u8g, dev, 0x0C); //display on, cursor+blink off
103
   u8g_WriteByte(u8g, dev, 0x0C); //display on, cursor+blink off
108
 
104
 
109
   u8g_SetChipSelect(u8g, dev, 0);
105
   u8g_SetChipSelect(u8g, dev, 0);
110
-
111
 }
106
 }
112
 
107
 
113
-uint8_t u8g_dev_st7920_128x64_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
108
+uint8_t u8g_dev_st7920_128x64_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
114
-{
109
+  switch(msg) {
115
-  switch(msg)
116
-  {
117
     case U8G_DEV_MSG_INIT:
110
     case U8G_DEV_MSG_INIT:
118
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
111
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
119
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
112
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
122
     case U8G_DEV_MSG_STOP:
115
     case U8G_DEV_MSG_STOP:
123
       break;
116
       break;
124
     case U8G_DEV_MSG_PAGE_NEXT: {
117
     case U8G_DEV_MSG_PAGE_NEXT: {
125
-        uint8_t y, i;
118
+      uint8_t y, i;
126
-        uint8_t *ptr;
119
+      uint8_t *ptr;
127
-        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
120
+      u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
128
-
121
+
122
+      u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
123
+      u8g_SetChipSelect(u8g, dev, 1);
124
+      y = pb->p.page_y0;
125
+      ptr = (uint8_t *)pb->buf;
126
+      for (i = 0; i < 8; i ++) {
129
         u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
127
         u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
130
-        u8g_SetChipSelect(u8g, dev, 1);
128
+        u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
131
-        y = pb->p.page_y0;
129
+
132
-        ptr = (uint8_t *)pb->buf;
130
+        if (y < 32) {
133
-        for( i = 0; i < 8; i ++ )
131
+          u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
134
-        {
132
+          u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
135
-          u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
133
+        }
136
-          u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
134
+        else {
137
-
135
+          u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
138
-          if ( y < 32 )
136
+          u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
139
-          {
140
-                  u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
141
-                  u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
142
-          }
143
-          else
144
-          {
145
-                  u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
146
-                  u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
147
-          }
148
-
149
-          u8g_SetAddress(u8g, dev, 1);                  /* data mode */
150
-          u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
151
-          ptr += WIDTH/8;
152
-          y++;
153
         }
137
         }
154
-        u8g_SetChipSelect(u8g, dev, 0);
138
+
139
+        u8g_SetAddress(u8g, dev, 1);                  /* data mode */
140
+        u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
141
+        ptr += WIDTH/8;
142
+        y++;
155
       }
143
       }
156
-      break;
144
+      u8g_SetChipSelect(u8g, dev, 0);
145
+    }
146
+    break;
157
   }
147
   }
158
   return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
148
   return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
159
 }
149
 }
160
 
150
 
161
-uint8_t u8g_dev_st7920_128x64_HAL_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
151
+uint8_t u8g_dev_st7920_128x64_HAL_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
162
-{
152
+  switch(msg) {
163
-  switch(msg)
164
-  {
165
     case U8G_DEV_MSG_INIT:
153
     case U8G_DEV_MSG_INIT:
166
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
154
       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
167
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
155
       u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_HAL_init_seq);
172
       break;
160
       break;
173
 
161
 
174
     case U8G_DEV_MSG_PAGE_NEXT: {
162
     case U8G_DEV_MSG_PAGE_NEXT: {
175
-        uint8_t y, i;
163
+      uint8_t y, i;
176
-        uint8_t *ptr;
164
+      uint8_t *ptr;
177
-        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
165
+      u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
178
-
166
+
167
+      u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
168
+      u8g_SetChipSelect(u8g, dev, 1);
169
+      y = pb->p.page_y0;
170
+      ptr = (uint8_t *)pb->buf;
171
+      for (i = 0; i < 32; i ++) {
179
         u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
172
         u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
180
-        u8g_SetChipSelect(u8g, dev, 1);
173
+        u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
181
-        y = pb->p.page_y0;
174
+
182
-        ptr = (uint8_t *)pb->buf;
175
+        if (y < 32) {
183
-        for( i = 0; i < 32; i ++ )
176
+          u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
184
-        {
177
+          u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
185
-          u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
186
-          u8g_WriteByte(u8g, dev, 0x03e );      /* enable extended mode */
187
-
188
-          if ( y < 32 )
189
-          {
190
-                  u8g_WriteByte(u8g, dev, 0x080 | y );      /* y pos  */
191
-                  u8g_WriteByte(u8g, dev, 0x080  );      /* set x pos to 0*/
192
-          }
193
-          else
194
-          {
195
-                  u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
196
-                  u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
197
-          }
198
-
199
-          u8g_SetAddress(u8g, dev, 1);                  /* data mode */
200
-          u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
201
-          ptr += WIDTH/8;
202
-          y++;
203
         }
178
         }
204
-        u8g_SetChipSelect(u8g, dev, 0);
179
+        else {
180
+          u8g_WriteByte(u8g, dev, 0x080 | (y-32) );      /* y pos  */
181
+          u8g_WriteByte(u8g, dev, 0x080 | 8);      /* set x pos to 64*/
182
+        }
183
+
184
+        u8g_SetAddress(u8g, dev, 1);                  /* data mode */
185
+        u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
186
+        ptr += WIDTH/8;
187
+        y++;
205
       }
188
       }
206
-      break;
189
+      u8g_SetChipSelect(u8g, dev, 0);
190
+    }
191
+    break;
207
   }
192
   }
208
   return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
193
   return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
209
 }
194
 }
215
 u8g_pb_t u8g_dev_st7920_128x64_HAL_4x_pb = { {32, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7920_128x64_HAL_4x_buf};
200
 u8g_pb_t u8g_dev_st7920_128x64_HAL_4x_pb = { {32, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_st7920_128x64_HAL_4x_buf};
216
 u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_sw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_SW_SPI };
201
 u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_sw_spi = { u8g_dev_st7920_128x64_HAL_4x_fn, &u8g_dev_st7920_128x64_HAL_4x_pb, U8G_COM_ST7920_HAL_SW_SPI };
217
 
202
 
218
-
219
 U8G_PB_DEV(u8g_dev_st7920_128x64_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_HAL_fn, U8G_COM_ST7920_HAL_HW_SPI);
203
 U8G_PB_DEV(u8g_dev_st7920_128x64_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_HAL_fn, U8G_COM_ST7920_HAL_HW_SPI);
220
 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 };
204
 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 };
221
 
205
 
222
-
223
 #if defined(U8G_HAL_LINKS) || defined(__SAM3X8E__)
206
 #if defined(U8G_HAL_LINKS) || defined(__SAM3X8E__)
224
   // Also use this device for HAL version of rrd class. This results in the same device being used
207
   // Also use this device for HAL version of rrd class. This results in the same device being used
225
   // for the ST7920 for HAL systems no matter what is selected in ultralcd_impl_DOGM.h.
208
   // for the ST7920 for HAL systems no matter what is selected in ultralcd_impl_DOGM.h.

Loading…
取消
儲存