Browse Source

Formatting cleanup of quiet sources

Scott Lahteine 9 years ago
parent
commit
fd78902194
2 changed files with 62 additions and 125 deletions
  1. 42
    76
      Marlin/MarlinSerial.cpp
  2. 20
    49
      Marlin/MarlinSerial.h

+ 42
- 76
Marlin/MarlinSerial.cpp View File

@@ -32,8 +32,7 @@
32 32
   ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
33 33
 #endif
34 34
 
35
-FORCE_INLINE void store_char(unsigned char c)
36
-{
35
+FORCE_INLINE void store_char(unsigned char c) {
37 36
   int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
38 37
 
39 38
   // if we should be storing the received character into the location
@@ -51,8 +50,7 @@ FORCE_INLINE void store_char(unsigned char c)
51 50
 #if defined(M_USARTx_RX_vect)
52 51
   // fixed by Mark Sproul this is on the 644/644p
53 52
   //SIGNAL(SIG_USART_RECV)
54
-  SIGNAL(M_USARTx_RX_vect)
55
-  {
53
+  SIGNAL(M_USARTx_RX_vect) {
56 54
     unsigned char c  =  M_UDRx;
57 55
     store_char(c);
58 56
   }
@@ -60,26 +58,22 @@ FORCE_INLINE void store_char(unsigned char c)
60 58
 
61 59
 // Constructors ////////////////////////////////////////////////////////////////
62 60
 
63
-MarlinSerial::MarlinSerial()
64
-{
65
-
66
-}
61
+MarlinSerial::MarlinSerial() { }
67 62
 
68 63
 // Public Methods //////////////////////////////////////////////////////////////
69 64
 
70
-void MarlinSerial::begin(long baud)
71
-{
65
+void MarlinSerial::begin(long baud) {
72 66
   uint16_t baud_setting;
73 67
   bool useU2X = true;
74 68
 
75
-#if F_CPU == 16000000UL && SERIAL_PORT == 0
76
-  // hard-coded exception for compatibility with the bootloader shipped
77
-  // with the Duemilanove and previous boards and the firmware on the 8U2
78
-  // on the Uno and Mega 2560.
79
-  if (baud == 57600) {
80
-    useU2X = false;
81
-  }
82
-#endif
69
+  #if F_CPU == 16000000UL && SERIAL_PORT == 0
70
+    // hard-coded exception for compatibility with the bootloader shipped
71
+    // with the Duemilanove and previous boards and the firmware on the 8U2
72
+    // on the Uno and Mega 2560.
73
+    if (baud == 57600) {
74
+      useU2X = false;
75
+    }
76
+  #endif
83 77
   
84 78
   if (useU2X) {
85 79
     M_UCSRxA = 1 << M_U2Xx;
@@ -98,17 +92,14 @@ void MarlinSerial::begin(long baud)
98 92
   sbi(M_UCSRxB, M_RXCIEx);
99 93
 }
100 94
 
101
-void MarlinSerial::end()
102
-{
95
+void MarlinSerial::end() {
103 96
   cbi(M_UCSRxB, M_RXENx);
104 97
   cbi(M_UCSRxB, M_TXENx);
105 98
   cbi(M_UCSRxB, M_RXCIEx);  
106 99
 }
107 100
 
108 101
 
109
-
110
-int MarlinSerial::peek(void)
111
-{
102
+int MarlinSerial::peek(void) {
112 103
   if (rx_buffer.head == rx_buffer.tail) {
113 104
     return -1;
114 105
   } else {
@@ -116,20 +107,19 @@ int MarlinSerial::peek(void)
116 107
   }
117 108
 }
118 109
 
119
-int MarlinSerial::read(void)
120
-{
110
+int MarlinSerial::read(void) {
121 111
   // if the head isn't ahead of the tail, we don't have any characters
122 112
   if (rx_buffer.head == rx_buffer.tail) {
123 113
     return -1;
124
-  } else {
114
+  }
115
+  else {
125 116
     unsigned char c = rx_buffer.buffer[rx_buffer.tail];
126 117
     rx_buffer.tail = (unsigned int)(rx_buffer.tail + 1) % RX_BUFFER_SIZE;
127 118
     return c;
128 119
   }
129 120
 }
130 121
 
131
-void MarlinSerial::flush()
132
-{
122
+void MarlinSerial::flush() {
133 123
   // don't reverse this or there may be problems if the RX interrupt
134 124
   // occurs after reading the value of rx_buffer_head but before writing
135 125
   // the value to rx_buffer_tail; the previous value of rx_buffer_head
@@ -143,38 +133,30 @@ void MarlinSerial::flush()
143 133
 }
144 134
 
145 135
 
146
-
147
-
148 136
 /// imports from print.h
149 137
 
150 138
 
151
-
152
-
153
-void MarlinSerial::print(char c, int base)
154
-{
139
+void MarlinSerial::print(char c, int base) {
155 140
   print((long) c, base);
156 141
 }
157 142
 
158
-void MarlinSerial::print(unsigned char b, int base)
159
-{
143
+void MarlinSerial::print(unsigned char b, int base) {
160 144
   print((unsigned long) b, base);
161 145
 }
162 146
 
163
-void MarlinSerial::print(int n, int base)
164
-{
147
+void MarlinSerial::print(int n, int base) {
165 148
   print((long) n, base);
166 149
 }
167 150
 
168
-void MarlinSerial::print(unsigned int n, int base)
169
-{
151
+void MarlinSerial::print(unsigned int n, int base) {
170 152
   print((unsigned long) n, base);
171 153
 }
172 154
 
173
-void MarlinSerial::print(long n, int base)
174
-{
155
+void MarlinSerial::print(long n, int base) {
175 156
   if (base == 0) {
176 157
     write(n);
177
-  } else if (base == 10) {
158
+  }
159
+  else if (base == 10) {
178 160
     if (n < 0) {
179 161
       print('-');
180 162
       n = -n;
@@ -185,81 +167,68 @@ void MarlinSerial::print(long n, int base)
185 167
   }
186 168
 }
187 169
 
188
-void MarlinSerial::print(unsigned long n, int base)
189
-{
170
+void MarlinSerial::print(unsigned long n, int base) {
190 171
   if (base == 0) write(n);
191 172
   else printNumber(n, base);
192 173
 }
193 174
 
194
-void MarlinSerial::print(double n, int digits)
195
-{
175
+void MarlinSerial::print(double n, int digits) {
196 176
   printFloat(n, digits);
197 177
 }
198 178
 
199
-void MarlinSerial::println(void)
200
-{
179
+void MarlinSerial::println(void) {
201 180
   print('\r');
202 181
   print('\n');  
203 182
 }
204 183
 
205
-void MarlinSerial::println(const String &s)
206
-{
184
+void MarlinSerial::println(const String &s) {
207 185
   print(s);
208 186
   println();
209 187
 }
210 188
 
211
-void MarlinSerial::println(const char c[])
212
-{
189
+void MarlinSerial::println(const char c[]) {
213 190
   print(c);
214 191
   println();
215 192
 }
216 193
 
217
-void MarlinSerial::println(char c, int base)
218
-{
194
+void MarlinSerial::println(char c, int base) {
219 195
   print(c, base);
220 196
   println();
221 197
 }
222 198
 
223
-void MarlinSerial::println(unsigned char b, int base)
224
-{
199
+void MarlinSerial::println(unsigned char b, int base) {
225 200
   print(b, base);
226 201
   println();
227 202
 }
228 203
 
229
-void MarlinSerial::println(int n, int base)
230
-{
204
+void MarlinSerial::println(int n, int base) {
231 205
   print(n, base);
232 206
   println();
233 207
 }
234 208
 
235
-void MarlinSerial::println(unsigned int n, int base)
236
-{
209
+void MarlinSerial::println(unsigned int n, int base) {
237 210
   print(n, base);
238 211
   println();
239 212
 }
240 213
 
241
-void MarlinSerial::println(long n, int base)
242
-{
214
+void MarlinSerial::println(long n, int base) {
243 215
   print(n, base);
244 216
   println();
245 217
 }
246 218
 
247
-void MarlinSerial::println(unsigned long n, int base)
248
-{
219
+void MarlinSerial::println(unsigned long n, int base) {
249 220
   print(n, base);
250 221
   println();
251 222
 }
252 223
 
253
-void MarlinSerial::println(double n, int digits)
254
-{
224
+void MarlinSerial::println(double n, int digits) {
255 225
   print(n, digits);
256 226
   println();
257 227
 }
258 228
 
259 229
 // Private Methods /////////////////////////////////////////////////////////////
260 230
 
261
-void MarlinSerial::printNumber(unsigned long n, uint8_t base)
262
-{
231
+void MarlinSerial::printNumber(unsigned long n, uint8_t base) {
263 232
   unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
264 233
   unsigned long i = 0;
265 234
 
@@ -279,18 +248,16 @@ void MarlinSerial::printNumber(unsigned long n, uint8_t base)
279 248
       'A' + buf[i - 1] - 10));
280 249
 }
281 250
 
282
-void MarlinSerial::printFloat(double number, uint8_t digits) 
283
-{ 
251
+void MarlinSerial::printFloat(double number, uint8_t digits) {
284 252
   // Handle negative numbers
285
-  if (number < 0.0)
286
-  {
253
+  if (number < 0.0) {
287 254
      print('-');
288 255
      number = -number;
289 256
   }
290 257
 
291 258
   // Round correctly so that print(1.999, 2) prints as "2.00"
292 259
   double rounding = 0.5;
293
-  for (uint8_t i=0; i<digits; ++i)
260
+  for (uint8_t i = 0; i < digits; ++i)
294 261
     rounding /= 10.0;
295 262
   
296 263
   number += rounding;
@@ -305,8 +272,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits)
305 272
     print("."); 
306 273
 
307 274
   // Extract digits from the remainder one at a time
308
-  while (digits-- > 0)
309
-  {
275
+  while (digits-- > 0) {
310 276
     remainder *= 10.0;
311 277
     int toPrint = int(remainder);
312 278
     print(toPrint);

+ 20
- 49
Marlin/MarlinSerial.h View File

@@ -23,8 +23,8 @@
23 23
 #define MarlinSerial_h
24 24
 #include "Marlin.h"
25 25
 
26
-#if !defined(SERIAL_PORT) 
27
-#define SERIAL_PORT 0
26
+#ifndef SERIAL_PORT
27
+  #define SERIAL_PORT 0
28 28
 #endif
29 29
 
30 30
 // The presence of the UBRRH register is used to detect a UART.
@@ -36,9 +36,9 @@
36 36
 // requires two levels of indirection to expand macro values properly)
37 37
 #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
38 38
 #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
39
-#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix
39
+  #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix
40 40
 #else
41
-#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
41
+  #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
42 42
 #endif
43 43
 
44 44
 // Registers used by MarlinSerial class (these are expanded 
@@ -57,7 +57,6 @@
57 57
 #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,)
58 58
 
59 59
 
60
-
61 60
 #define DEC 10
62 61
 #define HEX 16
63 62
 #define OCT 8
@@ -73,8 +72,7 @@
73 72
 #define RX_BUFFER_SIZE 128
74 73
 
75 74
 
76
-struct ring_buffer
77
-{
75
+struct ring_buffer {
78 76
   unsigned char buffer[RX_BUFFER_SIZE];
79 77
   int head;
80 78
   int tail;
@@ -84,8 +82,7 @@ struct ring_buffer
84 82
   extern ring_buffer rx_buffer;
85 83
 #endif
86 84
 
87
-class MarlinSerial //: public Stream
88
-{
85
+class MarlinSerial { //: public Stream
89 86
 
90 87
   public:
91 88
     MarlinSerial();
@@ -94,24 +91,20 @@ class MarlinSerial //: public Stream
94 91
     int peek(void);
95 92
     int read(void);
96 93
     void flush(void);
97
-    
98
-    FORCE_INLINE int available(void)
99
-    {
94
+
95
+    FORCE_INLINE int available(void) {
100 96
       return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
101 97
     }
102
-    
103
-    FORCE_INLINE void write(uint8_t c)
104
-    {
98
+
99
+    FORCE_INLINE void write(uint8_t c) {
105 100
       while (!((M_UCSRxA) & (1 << M_UDREx)))
106 101
         ;
107 102
 
108 103
       M_UDRx = c;
109 104
     }
110
-    
111
-    
112
-    FORCE_INLINE void checkRx(void)
113
-    {
114
-      if((M_UCSRxA & (1<<M_RXCx)) != 0) {
105
+
106
+    FORCE_INLINE void checkRx(void) {
107
+      if ((M_UCSRxA & (1<<M_RXCx)) != 0) {
115 108
         unsigned char c  =  M_UDRx;
116 109
         int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
117 110
 
@@ -125,39 +118,17 @@ class MarlinSerial //: public Stream
125 118
         }
126 119
       }
127 120
     }
128
-    
129
-    
130
-    private:
121
+
122
+  private:
131 123
     void printNumber(unsigned long, uint8_t);
132 124
     void printFloat(double, uint8_t);
133
-    
134
-    
135
-  public:
136
-    
137
-    FORCE_INLINE void write(const char *str)
138
-    {
139
-      while (*str)
140
-        write(*str++);
141
-    }
142 125
 
126
+  public:
127
+    FORCE_INLINE void write(const char *str) { while (*str) write(*str++); }
128
+    FORCE_INLINE void write(const uint8_t *buffer, size_t size) { while (size--) write(*buffer++); }
129
+    FORCE_INLINE void print(const String &s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
130
+    FORCE_INLINE void print(const char *str) { write(str); }
143 131
 
144
-    FORCE_INLINE void write(const uint8_t *buffer, size_t size)
145
-    {
146
-      while (size--)
147
-        write(*buffer++);
148
-    }
149
-
150
-    FORCE_INLINE void print(const String &s)
151
-    {
152
-      for (int i = 0; i < (int)s.length(); i++) {
153
-        write(s[i]);
154
-      }
155
-    }
156
-    
157
-    FORCE_INLINE void print(const char *str)
158
-    {
159
-      write(str);
160
-    }
161 132
     void print(char, int = BYTE);
162 133
     void print(unsigned char, int = BYTE);
163 134
     void print(int, int = DEC);

Loading…
Cancel
Save