Procházet zdrojové kódy

Relocate serial macros and functions

Scott Lahteine před 7 roky
rodič
revize
2cbc7b4b73
4 změnil soubory, kde provedl 123 přidání a 71 odebrání
  1. 1
    61
      Marlin/Marlin.h
  2. 0
    10
      Marlin/Marlin_main.cpp
  3. 34
    0
      Marlin/serial.cpp
  4. 88
    0
      Marlin/serial.h

+ 1
- 61
Marlin/Marlin.h Zobrazit soubor

@@ -39,19 +39,7 @@
39 39
 #include "types.h"
40 40
 #include "fastio.h"
41 41
 #include "utility.h"
42
-
43
-#ifdef USBCON
44
-  #include "HardwareSerial.h"
45
-  #if ENABLED(BLUETOOTH)
46
-    #define MYSERIAL bluetoothSerial
47
-  #else
48
-    #define MYSERIAL Serial
49
-  #endif // BLUETOOTH
50
-#else
51
-  #include "MarlinSerial.h"
52
-  #define MYSERIAL customizedSerial
53
-#endif
54
-
42
+#include "serial.h"
55 43
 #include "WString.h"
56 44
 
57 45
 #if ENABLED(PRINTCOUNTER)
@@ -60,54 +48,6 @@
60 48
   #include "stopwatch.h"
61 49
 #endif
62 50
 
63
-extern const char echomagic[] PROGMEM;
64
-extern const char errormagic[] PROGMEM;
65
-
66
-#define SERIAL_CHAR(x) (MYSERIAL.write(x))
67
-#define SERIAL_EOL SERIAL_CHAR('\n')
68
-
69
-#define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
70
-#define SERIAL_PROTOCOL(x)                  (MYSERIAL.print(x))
71
-#define SERIAL_PROTOCOL_F(x,y)              (MYSERIAL.print(x,y))
72
-#define SERIAL_PROTOCOLPGM(x)               (serialprintPGM(PSTR(x)))
73
-#define SERIAL_PROTOCOLLN(x)                do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
74
-#define SERIAL_PROTOCOLLNPGM(x)             (serialprintPGM(PSTR(x "\n")))
75
-#define SERIAL_PROTOCOLPAIR(name, value)    (serial_echopair_P(PSTR(name),(value)))
76
-#define SERIAL_PROTOCOLLNPAIR(name, value)  do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL; }while(0)
77
-
78
-#define SERIAL_ECHO_START             (serialprintPGM(echomagic))
79
-#define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
80
-#define SERIAL_ECHOPGM(x)              SERIAL_PROTOCOLPGM(x)
81
-#define SERIAL_ECHOLN(x)               SERIAL_PROTOCOLLN(x)
82
-#define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
83
-#define SERIAL_ECHOPAIR(name,value)    SERIAL_PROTOCOLPAIR(name, value)
84
-#define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
85
-#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x,y)
86
-
87
-#define SERIAL_ERROR_START            (serialprintPGM(errormagic))
88
-#define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
89
-#define SERIAL_ERRORPGM(x)             SERIAL_PROTOCOLPGM(x)
90
-#define SERIAL_ERRORLN(x)              SERIAL_PROTOCOLLN(x)
91
-#define SERIAL_ERRORLNPGM(x)           SERIAL_PROTOCOLLNPGM(x)
92
-
93
-void serial_echopair_P(const char* s_P, const char *v);
94
-void serial_echopair_P(const char* s_P, char v);
95
-void serial_echopair_P(const char* s_P, int v);
96
-void serial_echopair_P(const char* s_P, long v);
97
-void serial_echopair_P(const char* s_P, float v);
98
-void serial_echopair_P(const char* s_P, double v);
99
-void serial_echopair_P(const char* s_P, unsigned int v);
100
-void serial_echopair_P(const char* s_P, unsigned long v);
101
-FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
102
-FORCE_INLINE void serial_echopair_P(const char* s_P, uint16_t v) { serial_echopair_P(s_P, (int)v); }
103
-FORCE_INLINE void serial_echopair_P(const char* s_P, bool v) { serial_echopair_P(s_P, (int)v); }
104
-FORCE_INLINE void serial_echopair_P(const char* s_P, void *v) { serial_echopair_P(s_P, (unsigned long)v); }
105
-
106
-// Things to write to serial from Program memory. Saves 400 to 2k of RAM.
107
-FORCE_INLINE void serialprintPGM(const char* str) {
108
-  while (char ch = pgm_read_byte(str++)) MYSERIAL.write(ch);
109
-}
110
-
111 51
 void idle(
112 52
   #if ENABLED(FILAMENT_CHANGE_FEATURE)
113 53
     bool no_stepper_sleep = false  // pass true to keep steppers from disabling on timeout

+ 0
- 10
Marlin/Marlin_main.cpp Zobrazit soubor

@@ -447,8 +447,6 @@ volatile bool wait_for_heatup = true;
447 447
   volatile bool wait_for_user = false;
448 448
 #endif
449 449
 
450
-const char errormagic[] PROGMEM = "Error:";
451
-const char echomagic[] PROGMEM = "echo:";
452 450
 const char axis_codes[XYZE] = {'X', 'Y', 'Z', 'E'};
453 451
 
454 452
 // Number of characters read in the current line of serial input
@@ -696,14 +694,6 @@ void set_current_from_steppers_for_axis(const AxisEnum axis);
696 694
   void plan_cubic_move(const float offset[4]);
697 695
 #endif
698 696
 
699
-void serial_echopair_P(const char* s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
700
-void serial_echopair_P(const char* s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
701
-void serial_echopair_P(const char* s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
702
-void serial_echopair_P(const char* s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
703
-void serial_echopair_P(const char* s_P, float v)         { serialprintPGM(s_P); SERIAL_ECHO(v); }
704
-void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
705
-void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
706
-
707 697
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
708 698
 static void report_current_position();
709 699
 

+ 34
- 0
Marlin/serial.cpp Zobrazit soubor

@@ -0,0 +1,34 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "serial.h"
24
+
25
+const char errormagic[] PROGMEM = "Error:";
26
+const char echomagic[] PROGMEM = "echo:";
27
+
28
+void serial_echopair_P(const char* s_P, const char *v)   { serialprintPGM(s_P); SERIAL_ECHO(v); }
29
+void serial_echopair_P(const char* s_P, char v)          { serialprintPGM(s_P); SERIAL_CHAR(v); }
30
+void serial_echopair_P(const char* s_P, int v)           { serialprintPGM(s_P); SERIAL_ECHO(v); }
31
+void serial_echopair_P(const char* s_P, long v)          { serialprintPGM(s_P); SERIAL_ECHO(v); }
32
+void serial_echopair_P(const char* s_P, float v)         { serialprintPGM(s_P); SERIAL_ECHO(v); }
33
+void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
34
+void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }

+ 88
- 0
Marlin/serial.h Zobrazit soubor

@@ -0,0 +1,88 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef __SERIAL_H__
24
+#define __SERIAL_H__
25
+
26
+#ifdef USBCON
27
+  #include "HardwareSerial.h"
28
+  #if ENABLED(BLUETOOTH)
29
+    #define MYSERIAL bluetoothSerial
30
+  #else
31
+    #define MYSERIAL Serial
32
+  #endif // BLUETOOTH
33
+#else
34
+  #include "MarlinSerial.h"
35
+  #define MYSERIAL customizedSerial
36
+#endif
37
+
38
+extern const char echomagic[] PROGMEM;
39
+extern const char errormagic[] PROGMEM;
40
+
41
+#define SERIAL_CHAR(x) (MYSERIAL.write(x))
42
+#define SERIAL_EOL SERIAL_CHAR('\n')
43
+
44
+#define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
45
+#define SERIAL_PROTOCOL(x)                  (MYSERIAL.print(x))
46
+#define SERIAL_PROTOCOL_F(x,y)              (MYSERIAL.print(x,y))
47
+#define SERIAL_PROTOCOLPGM(x)               (serialprintPGM(PSTR(x)))
48
+#define SERIAL_PROTOCOLLN(x)                do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
49
+#define SERIAL_PROTOCOLLNPGM(x)             (serialprintPGM(PSTR(x "\n")))
50
+#define SERIAL_PROTOCOLPAIR(name, value)    (serial_echopair_P(PSTR(name),(value)))
51
+#define SERIAL_PROTOCOLLNPAIR(name, value)  do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL; }while(0)
52
+
53
+#define SERIAL_ECHO_START             (serialprintPGM(echomagic))
54
+#define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
55
+#define SERIAL_ECHOPGM(x)              SERIAL_PROTOCOLPGM(x)
56
+#define SERIAL_ECHOLN(x)               SERIAL_PROTOCOLLN(x)
57
+#define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
58
+#define SERIAL_ECHOPAIR(name,value)    SERIAL_PROTOCOLPAIR(name, value)
59
+#define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
60
+#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x,y)
61
+
62
+#define SERIAL_ERROR_START            (serialprintPGM(errormagic))
63
+#define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
64
+#define SERIAL_ERRORPGM(x)             SERIAL_PROTOCOLPGM(x)
65
+#define SERIAL_ERRORLN(x)              SERIAL_PROTOCOLLN(x)
66
+#define SERIAL_ERRORLNPGM(x)           SERIAL_PROTOCOLLNPGM(x)
67
+
68
+void serial_echopair_P(const char* s_P, const char *v);
69
+void serial_echopair_P(const char* s_P, char v);
70
+void serial_echopair_P(const char* s_P, int v);
71
+void serial_echopair_P(const char* s_P, long v);
72
+void serial_echopair_P(const char* s_P, float v);
73
+void serial_echopair_P(const char* s_P, double v);
74
+void serial_echopair_P(const char* s_P, unsigned int v);
75
+void serial_echopair_P(const char* s_P, unsigned long v);
76
+FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
77
+FORCE_INLINE void serial_echopair_P(const char* s_P, uint16_t v) { serial_echopair_P(s_P, (int)v); }
78
+FORCE_INLINE void serial_echopair_P(const char* s_P, bool v) { serial_echopair_P(s_P, (int)v); }
79
+FORCE_INLINE void serial_echopair_P(const char* s_P, void *v) { serial_echopair_P(s_P, (unsigned long)v); }
80
+
81
+//
82
+// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
83
+//
84
+FORCE_INLINE void serialprintPGM(const char* str) {
85
+  while (char ch = pgm_read_byte(str++)) MYSERIAL.write(ch);
86
+}
87
+
88
+#endif // __SERIAL_H__

Loading…
Zrušit
Uložit