My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Marlin.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
  2. // Licence: GPL
  3. #ifndef MARLIN_H
  4. #define MARLIN_H
  5. #define FORCE_INLINE __attribute__((always_inline)) inline
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <inttypes.h>
  11. #include <util/delay.h>
  12. #include <avr/pgmspace.h>
  13. #include <avr/eeprom.h>
  14. #include <avr/interrupt.h>
  15. #include "fastio.h"
  16. #include "Configuration.h"
  17. #include "pins.h"
  18. #ifndef AT90USB
  19. #define HardwareSerial_h // trick to disable the standard HWserial
  20. #endif
  21. #if ARDUINO >= 100
  22. #if defined(__AVR_ATmega644P__)
  23. #include "WProgram.h"
  24. #else
  25. #include "Arduino.h"
  26. #endif
  27. #else
  28. #include "WProgram.h"
  29. #endif
  30. #include "MarlinSerial.h"
  31. #ifndef cbi
  32. #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  33. #endif
  34. #ifndef sbi
  35. #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  36. #endif
  37. #include "WString.h"
  38. #ifdef AT90USB
  39. #define MYSERIAL Serial
  40. #else
  41. #define MYSERIAL MSerial
  42. #endif
  43. #define SERIAL_PROTOCOL(x) MYSERIAL.print(x);
  44. #define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y);
  45. #define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x));
  46. #define SERIAL_PROTOCOLLN(x) {MYSERIAL.print(x);MYSERIAL.write('\n');}
  47. #define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(PSTR(x));MYSERIAL.write('\n');}
  48. const char errormagic[] PROGMEM ="Error:";
  49. const char echomagic[] PROGMEM ="echo:";
  50. #define SERIAL_ERROR_START serialprintPGM(errormagic);
  51. #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
  52. #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
  53. #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
  54. #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  55. #define SERIAL_ECHO_START serialprintPGM(echomagic);
  56. #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
  57. #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
  58. #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
  59. #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  60. #define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
  61. void serial_echopair_P(const char *s_P, float v);
  62. void serial_echopair_P(const char *s_P, double v);
  63. void serial_echopair_P(const char *s_P, unsigned long v);
  64. //things to write to serial from Programmemory. saves 400 to 2k of RAM.
  65. FORCE_INLINE void serialprintPGM(const char *str)
  66. {
  67. char ch=pgm_read_byte(str);
  68. while(ch)
  69. {
  70. MYSERIAL.write(ch);
  71. ch=pgm_read_byte(++str);
  72. }
  73. }
  74. void get_command();
  75. void process_commands();
  76. void manage_inactivity();
  77. #if X_ENABLE_PIN > -1
  78. #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
  79. #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
  80. #else
  81. #define enable_x() ;
  82. #define disable_x() ;
  83. #endif
  84. #if Y_ENABLE_PIN > -1
  85. #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
  86. #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
  87. #else
  88. #define enable_y() ;
  89. #define disable_y() ;
  90. #endif
  91. #if Z_ENABLE_PIN > -1
  92. #ifdef Z_DUAL_STEPPER_DRIVERS
  93. #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
  94. #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); }
  95. #else
  96. #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
  97. #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
  98. #endif
  99. #else
  100. #define enable_z() ;
  101. #define disable_z() ;
  102. #endif
  103. #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
  104. #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
  105. #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
  106. #else
  107. #define enable_e0() /* nothing */
  108. #define disable_e0() /* nothing */
  109. #endif
  110. #if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
  111. #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
  112. #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
  113. #else
  114. #define enable_e1() /* nothing */
  115. #define disable_e1() /* nothing */
  116. #endif
  117. #if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
  118. #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
  119. #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
  120. #else
  121. #define enable_e2() /* nothing */
  122. #define disable_e2() /* nothing */
  123. #endif
  124. enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
  125. void FlushSerialRequestResend();
  126. void ClearToSend();
  127. void get_coordinates();
  128. void prepare_move();
  129. void kill();
  130. void Stop();
  131. bool IsStopped();
  132. void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
  133. void enquecommand_P(const char *cmd); //put an ascii command at the end of the current buffer, read from flash
  134. void prepare_arc_move(char isclockwise);
  135. void clamp_to_software_endstops(float target[3]);
  136. #ifdef FAST_PWM_FAN
  137. void setPwmFrequency(uint8_t pin, int val);
  138. #endif
  139. #ifndef CRITICAL_SECTION_START
  140. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  141. #define CRITICAL_SECTION_END SREG = _sreg;
  142. #endif //CRITICAL_SECTION_START
  143. extern float homing_feedrate[];
  144. extern bool axis_relative_modes[];
  145. extern int feedmultiply;
  146. extern int extrudemultiply; // Sets extrude multiply factor (in percent)
  147. extern float current_position[NUM_AXIS] ;
  148. extern float add_homeing[3];
  149. extern float min_pos[3];
  150. extern float max_pos[3];
  151. extern int fanSpeed;
  152. #ifdef FWRETRACT
  153. extern bool autoretract_enabled;
  154. extern bool retracted;
  155. extern float retract_length, retract_feedrate, retract_zlift;
  156. extern float retract_recover_length, retract_recover_feedrate;
  157. #endif
  158. extern unsigned long starttime;
  159. extern unsigned long stoptime;
  160. // Handling multiple extruders pins
  161. extern uint8_t active_extruder;
  162. #endif