Procházet zdrojové kódy

inlineing of small functions in serial

Bernhard před 12 roky
rodič
revize
85da81e673
2 změnil soubory, kde provedl 30 přidání a 34 odebrání
  1. 1
    27
      Marlin/MarlinSerial.cpp
  2. 29
    7
      Marlin/MarlinSerial.h

+ 1
- 27
Marlin/MarlinSerial.cpp Zobrazit soubor

@@ -161,31 +161,9 @@ void MarlinSerial::flush()
161 161
 
162 162
 
163 163
 /// imports from print.h
164
-/* default implementation: may be overridden */
165
-void MarlinSerial::write(const char *str)
166
-{
167
-  while (*str)
168
-    write(*str++);
169
-}
170 164
 
171
-/* default implementation: may be overridden */
172
-void MarlinSerial::write(const uint8_t *buffer, size_t size)
173
-{
174
-  while (size--)
175
-    write(*buffer++);
176
-}
177 165
 
178
-void MarlinSerial::print(const String &s)
179
-{
180
-  for (int i = 0; i < s.length(); i++) {
181
-    write(s[i]);
182
-  }
183
-}
184 166
 
185
-void MarlinSerial::print(const char str[])
186
-{
187
-  write(str);
188
-}
189 167
 
190 168
 void MarlinSerial::print(char c, int base)
191 169
 {
@@ -353,11 +331,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits)
353 331
 
354 332
 // Preinstantiate Objects //////////////////////////////////////////////////////
355 333
 
356
-#if defined(UBRR0H) && defined(UBRR0L)
357
-  MarlinSerial MSerial;
358
-#else
359
-  #error no serial port defined  (port 0)
360
-#endif
334
+MarlinSerial MSerial;
361 335
 
362 336
 
363 337
 #endif // whole file

+ 29
- 7
Marlin/MarlinSerial.h Zobrazit soubor

@@ -51,13 +51,15 @@ class MarlinSerial //: public Stream
51 51
     MarlinSerial();
52 52
     void begin(long);
53 53
     void end();
54
+    int peek(void);
55
+    int read(void);
56
+    void flush(void);
57
+    
54 58
     inline int available(void)
55 59
     {
56 60
       return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
57 61
     }
58
-    int peek(void);
59
-    int read(void);
60
-    void flush(void);
62
+    
61 63
     inline void write(uint8_t c)
62 64
     {
63 65
       while (!((UCSR0A) & (1 << UDRE0)))
@@ -91,11 +93,31 @@ class MarlinSerial //: public Stream
91 93
     
92 94
     
93 95
   public:
94
-    void write(const char *str);
95
-    void write( const uint8_t *buffer, size_t size);
96 96
     
97
-    void print(const String &);
98
-    void print(const char[]);
97
+    inline void write(const char *str)
98
+    {
99
+      while (*str)
100
+        write(*str++);
101
+    }
102
+
103
+
104
+    inline void write(const uint8_t *buffer, size_t size)
105
+    {
106
+      while (size--)
107
+        write(*buffer++);
108
+    }
109
+
110
+    inline void print(const String &s)
111
+    {
112
+      for (int i = 0; i < s.length(); i++) {
113
+        write(s[i]);
114
+      }
115
+    }
116
+    
117
+    inline void print(const char *str)
118
+    {
119
+      write(str);
120
+    }
99 121
     void print(char, int = BYTE);
100 122
     void print(unsigned char, int = BYTE);
101 123
     void print(int, int = DEC);

Loading…
Zrušit
Uložit