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

+ 20
- 49
Marlin/MarlinSerial.h View File

23
 #define MarlinSerial_h
23
 #define MarlinSerial_h
24
 #include "Marlin.h"
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
 #endif
28
 #endif
29
 
29
 
30
 // The presence of the UBRRH register is used to detect a UART.
30
 // The presence of the UBRRH register is used to detect a UART.
36
 // requires two levels of indirection to expand macro values properly)
36
 // requires two levels of indirection to expand macro values properly)
37
 #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
37
 #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
38
 #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
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
 #else
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
 #endif
42
 #endif
43
 
43
 
44
 // Registers used by MarlinSerial class (these are expanded 
44
 // Registers used by MarlinSerial class (these are expanded 
57
 #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,)
57
 #define M_U2Xx SERIAL_REGNAME(U2X,SERIAL_PORT,)
58
 
58
 
59
 
59
 
60
-
61
 #define DEC 10
60
 #define DEC 10
62
 #define HEX 16
61
 #define HEX 16
63
 #define OCT 8
62
 #define OCT 8
73
 #define RX_BUFFER_SIZE 128
72
 #define RX_BUFFER_SIZE 128
74
 
73
 
75
 
74
 
76
-struct ring_buffer
77
-{
75
+struct ring_buffer {
78
   unsigned char buffer[RX_BUFFER_SIZE];
76
   unsigned char buffer[RX_BUFFER_SIZE];
79
   int head;
77
   int head;
80
   int tail;
78
   int tail;
84
   extern ring_buffer rx_buffer;
82
   extern ring_buffer rx_buffer;
85
 #endif
83
 #endif
86
 
84
 
87
-class MarlinSerial //: public Stream
88
-{
85
+class MarlinSerial { //: public Stream
89
 
86
 
90
   public:
87
   public:
91
     MarlinSerial();
88
     MarlinSerial();
94
     int peek(void);
91
     int peek(void);
95
     int read(void);
92
     int read(void);
96
     void flush(void);
93
     void flush(void);
97
-    
98
-    FORCE_INLINE int available(void)
99
-    {
94
+
95
+    FORCE_INLINE int available(void) {
100
       return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
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
       while (!((M_UCSRxA) & (1 << M_UDREx)))
100
       while (!((M_UCSRxA) & (1 << M_UDREx)))
106
         ;
101
         ;
107
 
102
 
108
       M_UDRx = c;
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
         unsigned char c  =  M_UDRx;
108
         unsigned char c  =  M_UDRx;
116
         int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
109
         int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
117
 
110
 
125
         }
118
         }
126
       }
119
       }
127
     }
120
     }
128
-    
129
-    
130
-    private:
121
+
122
+  private:
131
     void printNumber(unsigned long, uint8_t);
123
     void printNumber(unsigned long, uint8_t);
132
     void printFloat(double, uint8_t);
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
     void print(char, int = BYTE);
132
     void print(char, int = BYTE);
162
     void print(unsigned char, int = BYTE);
133
     void print(unsigned char, int = BYTE);
163
     void print(int, int = DEC);
134
     void print(int, int = DEC);

Loading…
Cancel
Save