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.

main.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #ifdef __PLAT_LINUX__
  20. //#define GPIO_LOGGING // Full GPIO and Positional Logging
  21. #include "../../inc/MarlinConfig.h"
  22. #include "../shared/Delay.h"
  23. #include "hardware/IOLoggerCSV.h"
  24. #include "hardware/Heater.h"
  25. #include "hardware/LinearAxis.h"
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28. #include <thread>
  29. #include <iostream>
  30. #include <fstream>
  31. extern void setup();
  32. extern void loop();
  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. #ifdef GPIO_LOGGING
  60. IOLoggerCSV logger("all_gpio_log.csv");
  61. Gpio::attachLogger(&logger);
  62. std::ofstream position_log;
  63. position_log.open("axis_position_log.csv");
  64. int32_t x,y,z;
  65. #endif
  66. for (;;) {
  67. hotend.update();
  68. bed.update();
  69. x_axis.update();
  70. y_axis.update();
  71. z_axis.update();
  72. extruder0.update();
  73. #ifdef GPIO_LOGGING
  74. if (x_axis.position != x || y_axis.position != y || z_axis.position != z) {
  75. uint64_t update = _MAX(x_axis.last_update, y_axis.last_update, z_axis.last_update);
  76. position_log << update << ", " << x_axis.position << ", " << y_axis.position << ", " << z_axis.position << std::endl;
  77. position_log.flush();
  78. x = x_axis.position;
  79. y = y_axis.position;
  80. z = z_axis.position;
  81. }
  82. // flush the logger
  83. logger.flush();
  84. #endif
  85. std::this_thread::yield();
  86. }
  87. }
  88. int main() {
  89. std::thread write_serial (write_serial_thread);
  90. std::thread read_serial (read_serial_thread);
  91. #ifdef MYSERIAL1
  92. MYSERIAL1.begin(BAUDRATE);
  93. SERIAL_ECHOLNPGM("x86_64 Initialized");
  94. SERIAL_FLUSHTX();
  95. #endif
  96. Clock::setFrequency(F_CPU);
  97. Clock::setTimeMultiplier(1.0); // some testing at 10x
  98. HAL_timer_init();
  99. std::thread simulation (simulation_loop);
  100. DELAY_US(10000);
  101. setup();
  102. for (;;) {
  103. loop();
  104. std::this_thread::yield();
  105. }
  106. simulation.join();
  107. write_serial.join();
  108. read_serial.join();
  109. }
  110. #endif // __PLAT_LINUX__