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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifdef __PLAT_LINUX__
  21. extern void setup();
  22. extern void loop();
  23. #include <thread>
  24. #include <iostream>
  25. #include <fstream>
  26. #include "../../inc/MarlinConfig.h"
  27. #include <stdio.h>
  28. #include <stdarg.h>
  29. #include "../shared/Delay.h"
  30. #include "hardware/IOLoggerCSV.h"
  31. #include "hardware/Heater.h"
  32. #include "hardware/LinearAxis.h"
  33. // simple stdout / stdin implementation for fake serial port
  34. void write_serial_thread() {
  35. for (;;) {
  36. for (std::size_t i = usb_serial.transmit_buffer.available(); i > 0; i--) {
  37. fputc(usb_serial.transmit_buffer.read(), stdout);
  38. }
  39. std::this_thread::yield();
  40. }
  41. }
  42. void read_serial_thread() {
  43. char buffer[255] = {};
  44. for (;;) {
  45. std::size_t len = _MIN(usb_serial.receive_buffer.free(), 254U);
  46. if (fgets(buffer, len, stdin))
  47. for (std::size_t i = 0; i < strlen(buffer); i++)
  48. usb_serial.receive_buffer.write(buffer[i]);
  49. std::this_thread::yield();
  50. }
  51. }
  52. void simulation_loop() {
  53. Heater hotend(HEATER_0_PIN, TEMP_0_PIN);
  54. Heater bed(HEATER_BED_PIN, TEMP_BED_PIN);
  55. LinearAxis x_axis(X_ENABLE_PIN, X_DIR_PIN, X_STEP_PIN, X_MIN_PIN, X_MAX_PIN);
  56. LinearAxis y_axis(Y_ENABLE_PIN, Y_DIR_PIN, Y_STEP_PIN, Y_MIN_PIN, Y_MAX_PIN);
  57. LinearAxis z_axis(Z_ENABLE_PIN, Z_DIR_PIN, Z_STEP_PIN, Z_MIN_PIN, Z_MAX_PIN);
  58. LinearAxis extruder0(E0_ENABLE_PIN, E0_DIR_PIN, E0_STEP_PIN, P_NC, P_NC);
  59. //#define GPIO_LOGGING // Full GPIO and Positional Logging
  60. #ifdef GPIO_LOGGING
  61. IOLoggerCSV logger("all_gpio_log.csv");
  62. Gpio::attachLogger(&logger);
  63. std::ofstream position_log;
  64. position_log.open("axis_position_log.csv");
  65. int32_t x,y,z;
  66. #endif
  67. for (;;) {
  68. hotend.update();
  69. bed.update();
  70. x_axis.update();
  71. y_axis.update();
  72. z_axis.update();
  73. extruder0.update();
  74. #ifdef GPIO_LOGGING
  75. if (x_axis.position != x || y_axis.position != y || z_axis.position != z) {
  76. uint64_t update = MAX3(x_axis.last_update, y_axis.last_update, z_axis.last_update);
  77. position_log << update << ", " << x_axis.position << ", " << y_axis.position << ", " << z_axis.position << std::endl;
  78. position_log.flush();
  79. x = x_axis.position;
  80. y = y_axis.position;
  81. z = z_axis.position;
  82. }
  83. // flush the logger
  84. logger.flush();
  85. #endif
  86. std::this_thread::yield();
  87. }
  88. }
  89. int main() {
  90. std::thread write_serial (write_serial_thread);
  91. std::thread read_serial (read_serial_thread);
  92. #if NUM_SERIAL > 0
  93. MYSERIAL0.begin(BAUDRATE);
  94. SERIAL_ECHOLNPGM("x86_64 Initialized");
  95. SERIAL_FLUSHTX();
  96. #endif
  97. Clock::setFrequency(F_CPU);
  98. Clock::setTimeMultiplier(1.0); // some testing at 10x
  99. HAL_timer_init();
  100. std::thread simulation (simulation_loop);
  101. DELAY_US(10000);
  102. setup();
  103. for (;;) {
  104. loop();
  105. std::this_thread::yield();
  106. }
  107. simulation.join();
  108. write_serial.join();
  109. read_serial.join();
  110. }
  111. #endif // __PLAT_LINUX__