Browse Source

Indentation of a SW SPI file

Scott Lahteine 6 years ago
parent
commit
2c4e03d2cf
1 changed files with 103 additions and 102 deletions
  1. 103
    102
      Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp

+ 103
- 102
Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp View File

@@ -57,25 +57,26 @@
57 57
 
58 58
 #ifdef __SAM3X8E__
59 59
 
60
-  #include <U8glib.h>
61
-  #include <Arduino.h>
62
-  #include "../../core/macros.h"
60
+#include <U8glib.h>
61
+#include <Arduino.h>
62
+#include "../../core/macros.h"
63 63
 
64
-  void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
65
-     PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
66
-       g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration);  // OUTPUT
67
-  }
64
+void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
65
+   PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
66
+     g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration);  // OUTPUT
67
+}
68 68
 
69
-  void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
70
-    volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
71
-    uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
72
-    if (level) port->PIO_SODR = mask;
73
-    else port->PIO_CODR = mask;
74
-  }
69
+void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
70
+  volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
71
+  uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
72
+  if (level) port->PIO_SODR = mask;
73
+  else port->PIO_CODR = mask;
74
+}
75 75
 
76 76
 #define nop() __asm__ __volatile__("nop;\n\t":::)
77 77
 
78 78
 void __delay_4cycles(uint32_t cy) __attribute__ ((weak));
79
+
79 80
 FORCE_INLINE void __delay_4cycles(uint32_t cy) { // +1 cycle
80 81
   #if ARCH_PIPELINE_RELOAD_CYCLES<2
81 82
     #define EXTRA_NOP_CYCLES "nop"
@@ -96,107 +97,107 @@ FORCE_INLINE void __delay_4cycles(uint32_t cy) { // +1 cycle
96 97
   );
97 98
 }
98 99
 
99
-  Pio *SCK_pPio, *MOSI_pPio;
100
-  uint32_t SCK_dwMask, MOSI_dwMask;
101
-
102
-  static void spiSend_sw_DUE(uint8_t val) { // 800KHz
103
-    for (uint8_t i = 0; i < 8; i++) {
104
-      if (val & 0x80)
105
-        MOSI_pPio->PIO_SODR = MOSI_dwMask;
106
-      else
107
-        MOSI_pPio->PIO_CODR = MOSI_dwMask;
108
-      val = val << 1;
109
-      __delay_4cycles(2);
110
-      SCK_pPio->PIO_SODR = SCK_dwMask;
111
-      __delay_4cycles(22);
112
-      SCK_pPio->PIO_CODR = SCK_dwMask;
113
-    }
100
+Pio *SCK_pPio, *MOSI_pPio;
101
+uint32_t SCK_dwMask, MOSI_dwMask;
102
+
103
+static void spiSend_sw_DUE(uint8_t val) { // 800KHz
104
+  for (uint8_t i = 0; i < 8; i++) {
105
+    if (val & 0x80)
106
+      MOSI_pPio->PIO_SODR = MOSI_dwMask;
107
+    else
108
+      MOSI_pPio->PIO_CODR = MOSI_dwMask;
109
+    val = val << 1;
110
+    __delay_4cycles(2);
111
+    SCK_pPio->PIO_SODR = SCK_dwMask;
112
+    __delay_4cycles(22);
113
+    SCK_pPio->PIO_CODR = SCK_dwMask;
114 114
   }
115
+}
115 116
 
116
-  static uint8_t rs_last_state = 255;
117
-
118
-  static void u8g_com_DUE_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
119
-    uint8_t i;
117
+static uint8_t rs_last_state = 255;
120 118
 
121
-    if ( rs != rs_last_state) {  // time to send a command/data byte
122
-      rs_last_state = rs;
119
+static void u8g_com_DUE_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
120
+  uint8_t i;
123 121
 
124
-      if ( rs == 0 )
125
-        /* command */
126
-        spiSend_sw_DUE(0x0f8);
127
-      else
128
-         /* data */
129
-        spiSend_sw_DUE(0x0fa);
122
+  if ( rs != rs_last_state) {  // time to send a command/data byte
123
+    rs_last_state = rs;
130 124
 
131
-      for( i = 0; i < 4; i++ )   // give the controller some time to process the data
132
-        u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
133
-    }
125
+    if ( rs == 0 )
126
+      /* command */
127
+      spiSend_sw_DUE(0x0f8);
128
+    else
129
+       /* data */
130
+      spiSend_sw_DUE(0x0fa);
134 131
 
135
-    spiSend_sw_DUE(val & 0x0f0);
136
-    spiSend_sw_DUE(val << 4);
132
+    for( i = 0; i < 4; i++ )   // give the controller some time to process the data
133
+      u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
137 134
   }
138 135
 
136
+  spiSend_sw_DUE(val & 0x0f0);
137
+  spiSend_sw_DUE(val << 4);
138
+}
139 139
 
140
-  uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
141
-    switch (msg) {
142
-      case U8G_COM_MSG_INIT:
143
-        SCK_pPio = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].pPort;
144
-        SCK_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].ulPin;
145
-        MOSI_pPio = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].pPort;
146
-        MOSI_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].ulPin;
147
-
148
-        u8g_SetPILevel_DUE(u8g, U8G_PI_CS, 0);
149
-        u8g_SetPIOutput_DUE(u8g, U8G_PI_CS);
150
-        u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 0);
151
-        u8g_SetPIOutput_DUE(u8g, U8G_PI_SCK);
152
-        u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 0);
153
-        u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 1);
154
-        u8g_SetPIOutput_DUE(u8g, U8G_PI_MOSI);
155
-        u8g_Delay(5);
156
-        u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: command mode */
157
-        break;
158
-
159
-      case U8G_COM_MSG_STOP:
160
-        break;
161
-
162
-      case U8G_COM_MSG_RESET:
163
-         if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel_DUE(u8g, U8G_PI_RESET, arg_val);
164
-        break;
165
-
166
-      case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
167
-        u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
168
-        break;
169
-
170
-      case U8G_COM_MSG_CHIP_SELECT:
171
-        if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])
172
-          u8g_SetPILevel_DUE(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
173
-        break;
174
-
175
-      case U8G_COM_MSG_WRITE_BYTE:
176
-
177
-        u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
178
-        break;
179
-
180
-      case U8G_COM_MSG_WRITE_SEQ: {
181
-          uint8_t *ptr = (uint8_t*) arg_ptr;
182
-          while (arg_val > 0) {
183
-            u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
184
-            arg_val--;
185
-          }
140
+
141
+uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
142
+  switch (msg) {
143
+    case U8G_COM_MSG_INIT:
144
+      SCK_pPio = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].pPort;
145
+      SCK_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_SCK]].ulPin;
146
+      MOSI_pPio = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].pPort;
147
+      MOSI_dwMask = g_APinDescription[u8g->pin_list[U8G_PI_MOSI]].ulPin;
148
+
149
+      u8g_SetPILevel_DUE(u8g, U8G_PI_CS, 0);
150
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_CS);
151
+      u8g_SetPILevel_DUE(u8g, U8G_PI_SCK, 0);
152
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_SCK);
153
+      u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 0);
154
+      u8g_SetPILevel_DUE(u8g, U8G_PI_MOSI, 1);
155
+      u8g_SetPIOutput_DUE(u8g, U8G_PI_MOSI);
156
+      u8g_Delay(5);
157
+      u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* inital RS state: command mode */
158
+      break;
159
+
160
+    case U8G_COM_MSG_STOP:
161
+      break;
162
+
163
+    case U8G_COM_MSG_RESET:
164
+       if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel_DUE(u8g, U8G_PI_RESET, arg_val);
165
+      break;
166
+
167
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
168
+      u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
169
+      break;
170
+
171
+    case U8G_COM_MSG_CHIP_SELECT:
172
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS])
173
+        u8g_SetPILevel_DUE(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
174
+      break;
175
+
176
+    case U8G_COM_MSG_WRITE_BYTE:
177
+
178
+      u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
179
+      break;
180
+
181
+    case U8G_COM_MSG_WRITE_SEQ: {
182
+        uint8_t *ptr = (uint8_t*) arg_ptr;
183
+        while (arg_val > 0) {
184
+          u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
185
+          arg_val--;
186 186
         }
187
-        break;
188
-
189
-        case U8G_COM_MSG_WRITE_SEQ_P: {
190
-          uint8_t *ptr = (uint8_t*) arg_ptr;
191
-          while (arg_val > 0) {
192
-            u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
193
-            arg_val--;
194
-          }
187
+      }
188
+      break;
189
+
190
+      case U8G_COM_MSG_WRITE_SEQ_P: {
191
+        uint8_t *ptr = (uint8_t*) arg_ptr;
192
+        while (arg_val > 0) {
193
+          u8g_com_DUE_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
194
+          arg_val--;
195 195
         }
196
-        break;
197
-    }
198
-    return 1;
196
+      }
197
+      break;
199 198
   }
199
+  return 1;
200
+}
200 201
 
201 202
 #pragma GCC reset_options
202 203
 

Loading…
Cancel
Save