Browse Source

Squish code in ST7920

Scott Lahteine 8 years ago
parent
commit
a7684eef7a
1 changed files with 43 additions and 110 deletions
  1. 43
    110
      Marlin/ultralcd_st7920_u8glib_rrd.h

+ 43
- 110
Marlin/ultralcd_st7920_u8glib_rrd.h View File

@@ -43,11 +43,11 @@
43 43
 //set optimization so ARDUINO optimizes this file
44 44
 #pragma GCC optimize (3)
45 45
 
46
-#define DELAY_0_NOP  ;
47
-#define DELAY_1_NOP  __asm__("nop\n\t");
48
-#define DELAY_2_NOP  __asm__("nop\n\t" "nop\n\t");
49
-#define DELAY_3_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t");
50
-#define DELAY_4_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t");
46
+#define DELAY_0_NOP  NOOP
47
+#define DELAY_1_NOP  __asm__("nop\n\t")
48
+#define DELAY_2_NOP  __asm__("nop\n\t" "nop\n\t")
49
+#define DELAY_3_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t")
50
+#define DELAY_4_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t")
51 51
 
52 52
 
53 53
 // If you want you can define your own set of delays in Configuration.h
@@ -56,121 +56,54 @@
56 56
 //#define ST7920_DELAY_3 DELAY_0_NOP
57 57
 
58 58
 #if F_CPU >= 20000000
59
-  #ifndef ST7920_DELAY_1
60
-    #define ST7920_DELAY_1 DELAY_0_NOP
61
-  #endif
62
-  #ifndef ST7920_DELAY_2
63
-    #define ST7920_DELAY_2 DELAY_0_NOP
64
-  #endif
65
-  #ifndef ST7920_DELAY_3
66
-    #define ST7920_DELAY_3 DELAY_1_NOP
67
-  #endif
59
+  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
60
+  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
61
+  #define CPU_ST7920_DELAY_3 DELAY_1_NOP
68 62
 #elif (MOTHERBOARD == BOARD_3DRAG) || (MOTHERBOARD == BOARD_K8200)
69
-  #ifndef ST7920_DELAY_1
70
-    #define ST7920_DELAY_1 DELAY_0_NOP
71
-  #endif
72
-  #ifndef ST7920_DELAY_2
73
-    #define ST7920_DELAY_2 DELAY_3_NOP
74
-  #endif
75
-  #ifndef ST7920_DELAY_3
76
-    #define ST7920_DELAY_3 DELAY_0_NOP
77
-  #endif
63
+  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
64
+  #define CPU_ST7920_DELAY_2 DELAY_3_NOP
65
+  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
78 66
 #elif (MOTHERBOARD == BOARD_MINIRAMBO)
79
-  #ifndef ST7920_DELAY_1
80
-    #define ST7920_DELAY_1 DELAY_0_NOP
81
-  #endif
82
-  #ifndef ST7920_DELAY_2
83
-    #define ST7920_DELAY_2 DELAY_4_NOP
84
-  #endif
85
-  #ifndef ST7920_DELAY_3
86
-    #define ST7920_DELAY_3 DELAY_0_NOP
87
-  #endif
67
+  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
68
+  #define CPU_ST7920_DELAY_2 DELAY_4_NOP
69
+  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
88 70
 #elif (MOTHERBOARD == BOARD_RAMBO)
89
-  #ifndef ST7920_DELAY_1
90
-    #define ST7920_DELAY_1 DELAY_0_NOP
91
-  #endif
92
-  #ifndef ST7920_DELAY_2
93
-    #define ST7920_DELAY_2 DELAY_0_NOP
94
-  #endif
95
-  #ifndef ST7920_DELAY_3
96
-    #define ST7920_DELAY_3 DELAY_0_NOP
97
-  #endif
71
+  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
72
+  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
73
+  #define CPU_ST7920_DELAY_3 DELAY_0_NOP
98 74
 #elif F_CPU == 16000000
99
-  #ifndef ST7920_DELAY_1
100
-    #define ST7920_DELAY_1 DELAY_0_NOP
101
-  #endif
102
-  #ifndef ST7920_DELAY_2
103
-    #define ST7920_DELAY_2 DELAY_0_NOP
104
-  #endif
105
-  #ifndef ST7920_DELAY_3
106
-    #define ST7920_DELAY_3 DELAY_1_NOP
107
-  #endif
75
+  #define CPU_ST7920_DELAY_1 DELAY_0_NOP
76
+  #define CPU_ST7920_DELAY_2 DELAY_0_NOP
77
+  #define CPU_ST7920_DELAY_3 DELAY_1_NOP
108 78
 #else
109 79
   #error "No valid condition for delays in 'ultralcd_st7920_u8glib_rrd.h'"
110 80
 #endif
111 81
 
112
-static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
113
-    WRITE(ST7920_CLK_PIN,0);
114
-    ST7920_DELAY_1
115
-    WRITE(ST7920_DAT_PIN,val&0x80);
116
-    ST7920_DELAY_2
117
-    WRITE(ST7920_CLK_PIN,1);
118
-    val<<=1;
119
-    ST7920_DELAY_3
120
-
121
-    WRITE(ST7920_CLK_PIN,0);
122
-    ST7920_DELAY_1
123
-    WRITE(ST7920_DAT_PIN,val&0x80);
124
-    ST7920_DELAY_2
125
-    WRITE(ST7920_CLK_PIN,1);
126
-    val<<=1;
127
-    ST7920_DELAY_3
128
-
129
-    WRITE(ST7920_CLK_PIN,0);
130
-    ST7920_DELAY_1
131
-    WRITE(ST7920_DAT_PIN,val&0x80);
132
-    ST7920_DELAY_2
133
-    WRITE(ST7920_CLK_PIN,1);
134
-    val<<=1;
135
-    ST7920_DELAY_3
136
-
137
-    WRITE(ST7920_CLK_PIN,0);
138
-    ST7920_DELAY_1
139
-    WRITE(ST7920_DAT_PIN,val&0x80);
140
-    ST7920_DELAY_2
141
-    WRITE(ST7920_CLK_PIN,1);
142
-    val<<=1;
143
-    ST7920_DELAY_3
144
-
145
-    WRITE(ST7920_CLK_PIN,0);
146
-    ST7920_DELAY_1
147
-    WRITE(ST7920_DAT_PIN,val&0x80);
148
-    ST7920_DELAY_2
149
-    WRITE(ST7920_CLK_PIN,1);
150
-    val<<=1;
151
-    ST7920_DELAY_3
152
-
153
-    WRITE(ST7920_CLK_PIN,0);
154
-    ST7920_DELAY_1
155
-    WRITE(ST7920_DAT_PIN,val&0x80);
156
-    ST7920_DELAY_2
157
-    WRITE(ST7920_CLK_PIN,1);
158
-    val<<=1;
159
-    ST7920_DELAY_3
82
+#ifndef ST7920_DELAY_1
83
+  #define ST7920_DELAY_1 CPU_ST7920_DELAY_1
84
+#endif
85
+#ifndef ST7920_DELAY_2
86
+  #define ST7920_DELAY_2 CPU_ST7920_DELAY_2
87
+#endif
88
+#ifndef ST7920_DELAY_3
89
+  #define ST7920_DELAY_3 CPU_ST7920_DELAY_3
90
+#endif
160 91
 
161
-    WRITE(ST7920_CLK_PIN,0);
162
-    ST7920_DELAY_1
163
-    WRITE(ST7920_DAT_PIN,val&0x80);
164
-    ST7920_DELAY_2
165
-    WRITE(ST7920_CLK_PIN,1);
166
-    val<<=1;
167
-    ST7920_DELAY_3
92
+#define ST7920_SND_BIT \
93
+  WRITE(ST7920_CLK_PIN, LOW);        ST7920_DELAY_1; \
94
+  WRITE(ST7920_DAT_PIN, val & 0x80); ST7920_DELAY_2; \
95
+  WRITE(ST7920_CLK_PIN, HIGH);       ST7920_DELAY_3; \
96
+  val <<= 1
168 97
 
169
-    WRITE(ST7920_CLK_PIN,0);
170
-    ST7920_DELAY_1
171
-    WRITE(ST7920_DAT_PIN,val&0x80);
172
-    ST7920_DELAY_2
173
-    WRITE(ST7920_CLK_PIN,1);
98
+static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
99
+  ST7920_SND_BIT; // 1
100
+  ST7920_SND_BIT; // 2
101
+  ST7920_SND_BIT; // 3
102
+  ST7920_SND_BIT; // 4
103
+  ST7920_SND_BIT; // 5
104
+  ST7920_SND_BIT; // 6
105
+  ST7920_SND_BIT; // 7
106
+  ST7920_SND_BIT; // 8
174 107
 }
175 108
 
176 109
 #define ST7920_CS()              {WRITE(ST7920_CS_PIN,1);u8g_10MicroDelay();}

Loading…
Cancel
Save