Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 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
#include "MarlinConfig.h"
27
 
28
#if USE_MARLINSERIAL
29
  #include "MarlinSerial.h"
30
  #define MYSERIAL0 customizedSerial
31
#else
32
  #include <HardwareSerial.h>
33
  #if ENABLED(BLUETOOTH)
34
    extern HardwareSerial bluetoothSerial;
35
    #define MYSERIAL0 bluetoothSerial
36
  #else
37
    #define MYSERIAL0 Serial
38
  #endif // BLUETOOTH
39
#endif
40
 
41
extern const char echomagic[] PROGMEM;
42
extern const char errormagic[] PROGMEM;
43
 
44
#define SERIAL_CHAR(x) ((void)MYSERIAL0.write(x))
45
#define SERIAL_EOL() SERIAL_CHAR('\n')
46
 
47
#define SERIAL_PRINT(x,b)      MYSERIAL0.print(x,b)
48
#define SERIAL_PRINTLN(x,b)    MYSERIAL0.println(x,b)
49
#define SERIAL_PRINTF(args...) MYSERIAL0.printf(args)
50
 
51
#define SERIAL_FLUSH()         MYSERIAL0.flush()
52
#if TX_BUFFER_SIZE > 0
53
  #define SERIAL_FLUSHTX()     MYSERIAL0.flushTX()
54
#endif
55
 
56
#define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
57
#define SERIAL_PROTOCOL(x)                  MYSERIAL0.print(x)
58
#define SERIAL_PROTOCOL_F(x,y)              MYSERIAL0.print(x,y)
59
#define SERIAL_PROTOCOLPGM(x)               serialprintPGM(PSTR(x))
60
#define SERIAL_PROTOCOLLN(x)                do{ MYSERIAL0.print(x); SERIAL_EOL(); }while(0)
61
#define SERIAL_PROTOCOLLNPGM(x)             serialprintPGM(PSTR(x "\n"))
62
#define SERIAL_PROTOCOLPAIR(name, value)    serial_echopair_PGM(PSTR(name),(value))
63
#define SERIAL_PROTOCOLLNPAIR(name, value)  do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL(); }while(0)
64
 
65
#define SERIAL_ECHO_START()            serialprintPGM(echomagic)
66
#define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
67
#define SERIAL_ECHOPGM(x)              SERIAL_PROTOCOLPGM(x)
68
#define SERIAL_ECHOLN(x)               SERIAL_PROTOCOLLN(x)
69
#define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
70
#define SERIAL_ECHOPAIR(pre,value)     SERIAL_PROTOCOLPAIR(pre, value)
71
#define SERIAL_ECHOLNPAIR(pre,value)   SERIAL_PROTOCOLLNPAIR(pre, value)
72
#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x,y)
73
 
74
#define SERIAL_ERROR_START()           serialprintPGM(errormagic)
75
#define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
76
#define SERIAL_ERRORPGM(x)             SERIAL_PROTOCOLPGM(x)
77
#define SERIAL_ERRORLN(x)              SERIAL_PROTOCOLLN(x)
78
#define SERIAL_ERRORLNPGM(x)           SERIAL_PROTOCOLLNPGM(x)
79
 
80
// These macros compensate for float imprecision
81
#define SERIAL_PROTOCOLPAIR_F(pre, value)    SERIAL_PROTOCOLPAIR(pre, FIXFLOAT(value))
82
#define SERIAL_PROTOCOLLNPAIR_F(pre, value)  SERIAL_PROTOCOLLNPAIR(pre, FIXFLOAT(value))
83
#define SERIAL_ECHOPAIR_F(pre,value)         SERIAL_ECHOPAIR(pre, FIXFLOAT(value))
84
#define SERIAL_ECHOLNPAIR_F(pre, value)      SERIAL_ECHOLNPAIR(pre, FIXFLOAT(value))
85
 
86
//
87
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
88
//
89
FORCE_INLINE void serialprintPGM(const char* str) {
90
  while (char ch = pgm_read_byte(str++)) SERIAL_CHAR(ch);
91
}
92
 
93
void serial_echopair_PGM(const char* s_P, const char *v);
94
void serial_echopair_PGM(const char* s_P, char v);
95
void serial_echopair_PGM(const char* s_P, int v);
96
void serial_echopair_PGM(const char* s_P, long v);
97
void serial_echopair_PGM(const char* s_P, float v);
98
void serial_echopair_PGM(const char* s_P, double v);
99
void serial_echopair_PGM(const char* s_P, unsigned int v);
100
void serial_echopair_PGM(const char* s_P, unsigned long v);
101
FORCE_INLINE void serial_echopair_PGM(const char* s_P, uint8_t v) { serial_echopair_PGM(s_P, (int)v); }
102
FORCE_INLINE void serial_echopair_PGM(const char* s_P, uint16_t v) { serial_echopair_PGM(s_P, (int)v); }
103
FORCE_INLINE void serial_echopair_PGM(const char* s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
104
FORCE_INLINE void serial_echopair_PGM(const char* s_P, void *v) { serial_echopair_PGM(s_P, (unsigned long)v); }
105
 
106
void serial_spaces(uint8_t count);
107
#define SERIAL_ECHO_SP(C)     serial_spaces(C)
108
#define SERIAL_ERROR_SP(C)    serial_spaces(C)
109
#define SERIAL_PROTOCOL_SP(C) serial_spaces(C)
110
 
111
#endif // __SERIAL_H__