My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

serial.h 4.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef __SERIAL_H__
  23. #define __SERIAL_H__
  24. #ifdef USBCON
  25. #include "HardwareSerial.h"
  26. #if ENABLED(BLUETOOTH)
  27. #define MYSERIAL bluetoothSerial
  28. #else
  29. #define MYSERIAL Serial
  30. #endif // BLUETOOTH
  31. #else
  32. #include "MarlinSerial.h"
  33. #define MYSERIAL customizedSerial
  34. #endif
  35. extern const char echomagic[] PROGMEM;
  36. extern const char errormagic[] PROGMEM;
  37. #define SERIAL_CHAR(x) (MYSERIAL.write(x))
  38. #define SERIAL_EOL SERIAL_CHAR('\n')
  39. #define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)
  40. #define SERIAL_PROTOCOL(x) (MYSERIAL.print(x))
  41. #define SERIAL_PROTOCOL_F(x,y) (MYSERIAL.print(x,y))
  42. #define SERIAL_PROTOCOLPGM(x) (serialprintPGM(PSTR(x)))
  43. #define SERIAL_PROTOCOLLN(x) do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
  44. #define SERIAL_PROTOCOLLNPGM(x) (serialprintPGM(PSTR(x "\n")))
  45. #define SERIAL_PROTOCOLPAIR(name, value) (serial_echopair_P(PSTR(name),(value)))
  46. #define SERIAL_PROTOCOLLNPAIR(name, value) do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL; }while(0)
  47. #define SERIAL_ECHO_START (serialprintPGM(echomagic))
  48. #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
  49. #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
  50. #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
  51. #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  52. #define SERIAL_ECHOPAIR(name,value) SERIAL_PROTOCOLPAIR(name, value)
  53. #define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
  54. #define SERIAL_ECHO_F(x,y) SERIAL_PROTOCOL_F(x,y)
  55. #define SERIAL_ERROR_START (serialprintPGM(errormagic))
  56. #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
  57. #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
  58. #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
  59. #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  60. // These macros compensate for float imprecision
  61. #define SERIAL_PROTOCOLPAIR_F(name, value) SERIAL_PROTOCOLPAIR(name, FIXFLOAT(value))
  62. #define SERIAL_PROTOCOLLNPAIR_F(name, value) SERIAL_PROTOCOLLNPAIR(name, FIXFLOAT(value))
  63. #define SERIAL_ECHOPAIR_F(name,value) SERIAL_ECHOPAIR(name, FIXFLOAT(value))
  64. #define SERIAL_ECHOLNPAIR_F(name, value) SERIAL_ECHOLNPAIR(name, FIXFLOAT(value))
  65. void serial_echopair_P(const char* s_P, const char *v);
  66. void serial_echopair_P(const char* s_P, char v);
  67. void serial_echopair_P(const char* s_P, int v);
  68. void serial_echopair_P(const char* s_P, long v);
  69. void serial_echopair_P(const char* s_P, float v);
  70. void serial_echopair_P(const char* s_P, double v);
  71. void serial_echopair_P(const char* s_P, unsigned int v);
  72. void serial_echopair_P(const char* s_P, unsigned long v);
  73. FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
  74. FORCE_INLINE void serial_echopair_P(const char* s_P, uint16_t v) { serial_echopair_P(s_P, (int)v); }
  75. FORCE_INLINE void serial_echopair_P(const char* s_P, bool v) { serial_echopair_P(s_P, (int)v); }
  76. FORCE_INLINE void serial_echopair_P(const char* s_P, void *v) { serial_echopair_P(s_P, (unsigned long)v); }
  77. //
  78. // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
  79. //
  80. FORCE_INLINE void serialprintPGM(const char* str) {
  81. while (char ch = pgm_read_byte(str++)) MYSERIAL.write(ch);
  82. }
  83. #endif // __SERIAL_H__