소스 검색

General cleanup of HAL code

Scott Lahteine 6 년 전
부모
커밋
b13099de3f

+ 21
- 40
Marlin/src/HAL/HAL_LPC1768/Wire.cpp 파일 보기

@@ -75,7 +75,8 @@ void TwoWire::begin(void) {
75 75
   PINSEL_CFG_Type PinCfg;
76 76
   PinCfg.OpenDrain = 0;
77 77
   PinCfg.Pinmode = 0;
78
-  #if ((USEDI2CDEV_M == 0))
78
+
79
+  #if USEDI2CDEV_M == 0
79 80
     PinCfg.Funcnum = 1;
80 81
     PinCfg.Pinnum = 27;
81 82
     PinCfg.Portnum = 0;
@@ -83,7 +84,8 @@ void TwoWire::begin(void) {
83 84
     PinCfg.Pinnum = 28;
84 85
     PINSEL_ConfigPin(&PinCfg); // SCL0 / D58  AUX-1
85 86
   #endif
86
-  #if ((USEDI2CDEV_M == 1))
87
+
88
+  #if USEDI2CDEV_M == 1
87 89
     PinCfg.Funcnum = 3;
88 90
     PinCfg.Pinnum = 0;
89 91
     PinCfg.Portnum = 0;
@@ -91,7 +93,8 @@ void TwoWire::begin(void) {
91 93
     PinCfg.Pinnum = 1;
92 94
     PINSEL_ConfigPin(&PinCfg);  // SCL1 / D21 SCL
93 95
   #endif
94
-  #if ((USEDI2CDEV_M == 2))
96
+
97
+  #if USEDI2CDEV_M == 2
95 98
     PinCfg.Funcnum = 2;
96 99
     PinCfg.Pinnum = 10;
97 100
     PinCfg.Portnum = 0;
@@ -102,17 +105,16 @@ void TwoWire::begin(void) {
102 105
 
103 106
   // Initialize I2C peripheral
104 107
   I2C_Init(I2CDEV_M, 100000);
105
-  
108
+
106 109
   // Enable Master I2C operation
107 110
   I2C_Cmd(I2CDEV_M, I2C_MASTER_MODE, ENABLE);
108 111
 }
109 112
 
110 113
 uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) {
111 114
   // clamp to buffer length
112
-  if(quantity > BUFFER_LENGTH){
115
+  if (quantity > BUFFER_LENGTH)
113 116
     quantity = BUFFER_LENGTH;
114
-  }
115
-  
117
+
116 118
   // perform blocking read into buffer
117 119
   I2C_M_SETUP_Type transferMCfg;
118 120
   transferMCfg.sl_addr7bit = address >> 1; // not sure about the right shift
@@ -158,7 +160,7 @@ uint8_t TwoWire::endTransmission(void) {
158 160
 	transferMCfg.rx_length = 0;
159 161
 	transferMCfg.retransmissions_max = 3;
160 162
   Status status = I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
161
-  
163
+
162 164
   // reset tx buffer iterator vars
163 165
   txBufferIndex = 0;
164 166
   txBufferLength = 0;
@@ -166,25 +168,19 @@ uint8_t TwoWire::endTransmission(void) {
166 168
   // indicate that we are done transmitting
167 169
   transmitting = 0;
168 170
 
169
-  if (status == SUCCESS)
170
-    return 0; // success
171
-  else
172
-    return 4; // other error
171
+  return status == SUCCESS ? 0 : 4;
173 172
 }
174 173
 
175 174
 // must be called after beginTransmission(address)
176 175
 size_t TwoWire::write(uint8_t data) {
177 176
   if (transmitting) {
178 177
     // don't bother if buffer is full
179
-    if (txBufferLength >= BUFFER_LENGTH) {
180
-      return 0;
181
-    }
178
+    if (txBufferLength >= BUFFER_LENGTH) return 0;
182 179
 
183 180
     // put byte in tx buffer
184
-    txBuffer[txBufferIndex] = data;
185
-    ++txBufferIndex;
181
+    txBuffer[txBufferIndex++] = data;
186 182
 
187
-    // update amount in buffer   
183
+    // update amount in buffer
188 184
     txBufferLength = txBufferIndex;
189 185
   }
190 186
 
@@ -195,40 +191,25 @@ size_t TwoWire::write(uint8_t data) {
195 191
 size_t TwoWire::write(const uint8_t *data, size_t quantity) {
196 192
   size_t sent = 0;
197 193
   if (transmitting)
198
-    for(sent = 0; sent < quantity; ++sent)
199
-      if (!write(data[sent]))
200
-        break;
194
+    for (sent = 0; sent < quantity; ++sent)
195
+      if (!write(data[sent])) break;
201 196
 
202 197
   return sent;
203 198
 }
204 199
 
205
-// must be called after requestFrom(address, numBytes)
200
+// Must be called after requestFrom(address, numBytes)
206 201
 int TwoWire::available(void) {
207 202
   return rxBufferLength - rxBufferIndex;
208 203
 }
209 204
 
210
-// must be called after requestFrom(address, numBytes)
205
+// Must be called after requestFrom(address, numBytes)
211 206
 int TwoWire::read(void) {
212
-  int value = -1;
213
-  
214
-  // get each successive byte on each call
215
-  if(rxBufferIndex < rxBufferLength) {
216
-    value = rxBuffer[rxBufferIndex];
217
-    ++rxBufferIndex;
218
-  }
219
-
220
-  return value;
207
+  return rxBufferIndex < rxBufferLength ? rxBuffer[rxBufferIndex++] : -1;
221 208
 }
222 209
 
223
-// must be called after requestFrom(address, numBytes)
210
+// Must be called after requestFrom(address, numBytes)
224 211
 int TwoWire::peek(void) {
225
-  int value = -1;
226
-  
227
-  if(rxBufferIndex < rxBufferLength){
228
-    value = rxBuffer[rxBufferIndex];
229
-  }
230
-
231
-  return value;
212
+  return rxBufferIndex < rxBufferLength ? rxBuffer[rxBufferIndex] : -1;
232 213
 }
233 214
 
234 215
 // Preinstantiate Objects //////////////////////////////////////////////////////

+ 3
- 3
Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp 파일 보기

@@ -91,12 +91,12 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
91 91
   SPI.beginTransaction(spiConfig);
92 92
   SPDR = token;
93 93
   for (uint16_t i = 0; i < 512; i += 2) {
94
-    while (!TEST(SPSR, SPIF)) { /* nada */ }; 
94
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
95 95
     SPDR = buf[i];
96
-    while (!TEST(SPSR, SPIF)) { /* nada */ }; 
96
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
97 97
     SPDR = buf[i + 1];
98 98
   }
99
-  while (!TEST(SPSR, SPIF)) { /* nada */ }; 
99
+  while (!TEST(SPSR, SPIF)) { /* nada */ };
100 100
   SPI.endTransaction();
101 101
 }
102 102
 

+ 3
- 3
frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h 파일 보기

@@ -60,7 +60,7 @@ public:
60 60
   void init(uint8_t fourbitmode, pin_t rs, pin_t rw, pin_t enable,
61 61
             pin_t d0, pin_t d1, pin_t d2, pin_t d3,
62 62
             pin_t d4, pin_t d5, pin_t d6, pin_t d7);
63
-    
63
+
64 64
   void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
65 65
 
66 66
   void clear();
@@ -81,10 +81,10 @@ public:
81 81
 
82 82
   void setRowOffsets(int row1, int row2, int row3, int row4);
83 83
   void createChar(uint8_t, uint8_t[]);
84
-  void setCursor(uint8_t, uint8_t); 
84
+  void setCursor(uint8_t, uint8_t);
85 85
   virtual size_t write(uint8_t);
86 86
   void command(uint8_t);
87
-  
87
+
88 88
   using Print::write;
89 89
 private:
90 90
   void send(uint8_t, uint8_t);

+ 26
- 26
frameworks/CMSIS/LPC1768/lib/Print.cpp 파일 보기

@@ -1,21 +1,21 @@
1 1
 /*
2 2
  Print.cpp - Base class that provides print() and println()
3 3
  Copyright (c) 2008 David A. Mellis.  All right reserved.
4
- 
4
+
5 5
  This library is free software; you can redistribute it and/or
6 6
  modify it under the terms of the GNU Lesser General Public
7 7
  License as published by the Free Software Foundation; either
8 8
  version 2.1 of the License, or (at your option) any later version.
9
- 
9
+
10 10
  This library is distributed in the hope that it will be useful,
11 11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 13
  Lesser General Public License for more details.
14
- 
14
+
15 15
  You should have received a copy of the GNU Lesser General Public
16 16
  License along with this library; if not, write to the Free Software
17 17
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
- 
18
+
19 19
  Modified 23 November 2006 by David A. Mellis
20 20
  Modified 03 August 2015 by Chuck Todd
21 21
  */
@@ -37,7 +37,7 @@ typedef signed long sint32_t;
37 37
 /* default implementation: may be overridden */
38 38
 size_t Print::write(const uint8_t *buffer, size_t size)
39 39
 {
40
-	
40
+
41 41
   size_t n = 0;
42 42
   while (size--) {
43 43
     if (write(*buffer++)) n++;
@@ -49,7 +49,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)
49 49
 
50 50
 size_t Print::print(const char str[])
51 51
 {
52
-	
52
+
53 53
 	//while(1);
54 54
   return write(str);
55 55
 }
@@ -195,15 +195,15 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
195 195
   return write(str);
196 196
 }
197 197
 
198
-size_t Print::printFloat(double number, uint8_t digits) 
199
-{ 
198
+size_t Print::printFloat(double number, uint8_t digits)
199
+{
200 200
   size_t n = 0;
201
-  
201
+
202 202
   if (isnan(number)) return print("nan");
203 203
   if (isinf(number)) return print("inf");
204 204
   if (number > 4294967040.0) return print ("ovf");  // constant determined empirically
205 205
   if (number <-4294967040.0) return print ("ovf");  // constant determined empirically
206
-  
206
+
207 207
   // Handle negative numbers
208 208
   if (number < 0.0)
209 209
   {
@@ -215,7 +215,7 @@ size_t Print::printFloat(double number, uint8_t digits)
215 215
   double rounding = 0.5;
216 216
   for (uint8_t i=0; i<digits; ++i)
217 217
     rounding /= 10.0;
218
-  
218
+
219 219
   number += rounding;
220 220
 
221 221
   // Extract the integer part of the number and print it
@@ -225,7 +225,7 @@ size_t Print::printFloat(double number, uint8_t digits)
225 225
 
226 226
   // Print the decimal point, but only if there are digits beyond
227 227
   if (digits > 0) {
228
-    n += print("."); 
228
+    n += print(".");
229 229
   }
230 230
 
231 231
   // Extract digits from the remainder one at a time
@@ -234,14 +234,14 @@ size_t Print::printFloat(double number, uint8_t digits)
234 234
     remainder *= 10.0;
235 235
     int toPrint = int(remainder);
236 236
     n += print(toPrint);
237
-    remainder -= toPrint; 
238
-  } 
239
-  
237
+    remainder -= toPrint;
238
+  }
239
+
240 240
   return n;
241 241
 }
242 242
 
243 243
 
244
-#if (PrintfEnable == 1) 
244
+#if (PrintfEnable == 1)
245 245
 size_t Print::printf(const char *argList, ...)
246 246
 {
247 247
     const char *ptr;
@@ -279,7 +279,7 @@ size_t Print::printf(const char *argList, ...)
279 279
             else
280 280
             {
281 281
                 numOfDigits = 0xff;
282
-            }                
282
+            }
283 283
 
284 284
 
285 285
             switch(ch)       /* Decode the type of the argument */
@@ -297,14 +297,14 @@ size_t Print::printf(const char *argList, ...)
297 297
             case 'D':
298 298
                 num_s32 = va_arg(argp, int);
299 299
                 print(num_s32, 10);
300
-                break;  
300
+                break;
301 301
 
302 302
 
303 303
             case 'u':
304 304
             case 'U':    /* Argument type is of integer, hence read 32bit unsigend data */
305 305
                 num_u32 = va_arg(argp, uint32_t);
306
-                print(num_u32, 10);               
307
-                break;            
306
+                print(num_u32, 10);
307
+                break;
308 308
 
309 309
 
310 310
 
@@ -312,21 +312,21 @@ size_t Print::printf(const char *argList, ...)
312 312
             case 'x':
313 313
             case 'X':  /* Argument type is of hex, hence hexadecimal data from the argp */
314 314
                 num_u32 = va_arg(argp, uint32_t);
315
-                print(num_u32, 16);                 
315
+                print(num_u32, 16);
316 316
                 break;
317 317
 
318 318
 
319 319
             case 'b':
320 320
             case 'B':  /* Argument type is of binary,Read int and convert to binary */
321
-                num_u32 = va_arg(argp, uint32_t); 
322
-                print(num_u32, 2);                 
321
+                num_u32 = va_arg(argp, uint32_t);
322
+                print(num_u32, 2);
323 323
                 break;
324 324
 
325 325
 
326 326
 
327 327
             case 'F':
328 328
             case 'f': /* Argument type is of float, hence read double data from the argp */
329
-                floatNum_f32 = va_arg(argp, double);              
329
+                floatNum_f32 = va_arg(argp, double);
330 330
                 printFloat(floatNum_f32,10);
331 331
                 break;
332 332
 
@@ -335,7 +335,7 @@ size_t Print::printf(const char *argList, ...)
335 335
             case 'S':
336 336
             case 's': /* Argument type is of string, hence get the pointer to sting passed */
337 337
                 str = va_arg(argp, char *);
338
-                print(str);                
338
+                print(str);
339 339
                 break;
340 340
 
341 341
 
@@ -356,4 +356,4 @@ size_t Print::printf(const char *argList, ...)
356 356
 }
357 357
 
358 358
 
359
-#endif    
359
+#endif

Loading…
취소
저장