Browse Source

inlineing of small functions in serial

Bernhard 13 years ago
parent
commit
85da81e673
2 changed files with 30 additions and 34 deletions
  1. 1
    27
      Marlin/MarlinSerial.cpp
  2. 29
    7
      Marlin/MarlinSerial.h

+ 1
- 27
Marlin/MarlinSerial.cpp View File

161
 
161
 
162
 
162
 
163
 /// imports from print.h
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
 void MarlinSerial::print(char c, int base)
168
 void MarlinSerial::print(char c, int base)
191
 {
169
 {
353
 
331
 
354
 // Preinstantiate Objects //////////////////////////////////////////////////////
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
 #endif // whole file
337
 #endif // whole file

+ 29
- 7
Marlin/MarlinSerial.h View File

51
     MarlinSerial();
51
     MarlinSerial();
52
     void begin(long);
52
     void begin(long);
53
     void end();
53
     void end();
54
+    int peek(void);
55
+    int read(void);
56
+    void flush(void);
57
+    
54
     inline int available(void)
58
     inline int available(void)
55
     {
59
     {
56
       return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
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
     inline void write(uint8_t c)
63
     inline void write(uint8_t c)
62
     {
64
     {
63
       while (!((UCSR0A) & (1 << UDRE0)))
65
       while (!((UCSR0A) & (1 << UDRE0)))
91
     
93
     
92
     
94
     
93
   public:
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
     void print(char, int = BYTE);
121
     void print(char, int = BYTE);
100
     void print(unsigned char, int = BYTE);
122
     void print(unsigned char, int = BYTE);
101
     void print(int, int = DEC);
123
     void print(int, int = DEC);

Loading…
Cancel
Save