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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #ifdef TARGET_LPC1768
  23. #include <usb/usb.h>
  24. #include <usb/usbcfg.h>
  25. #include <usb/usbhw.h>
  26. #include <usb/usbcore.h>
  27. #include <usb/cdc.h>
  28. #include <usb/cdcuser.h>
  29. #include <usb/mscuser.h>
  30. #include <CDCSerial.h>
  31. #include <usb/mscuser.h>
  32. extern "C" {
  33. #include <debug_frmwrk.h>
  34. }
  35. #include "../../sd/cardreader.h"
  36. #include "../../inc/MarlinConfig.h"
  37. #include "HAL.h"
  38. #include "HAL_timers.h"
  39. extern uint32_t MSC_SD_Init(uint8_t pdrv);
  40. extern "C" int isLPC1769();
  41. extern "C" void disk_timerproc(void);
  42. void SysTick_Callback() {
  43. disk_timerproc();
  44. }
  45. void HAL_init(void) {
  46. // Init LEDs
  47. #if PIN_EXISTS(LED)
  48. SET_DIR_OUTPUT(LED_PIN);
  49. WRITE_PIN_CLR(LED_PIN);
  50. #if PIN_EXISTS(LED2)
  51. SET_DIR_OUTPUT(LED2_PIN);
  52. WRITE_PIN_CLR(LED2_PIN);
  53. #if PIN_EXISTS(LED3)
  54. SET_DIR_OUTPUT(LED3_PIN);
  55. WRITE_PIN_CLR(LED3_PIN);
  56. #if PIN_EXISTS(LED4)
  57. SET_DIR_OUTPUT(LED4_PIN);
  58. WRITE_PIN_CLR(LED4_PIN);
  59. #endif
  60. #endif
  61. #endif
  62. // Flash status LED 3 times to indicate Marlin has started booting
  63. for (uint8_t i = 0; i < 6; ++i) {
  64. TOGGLE(LED_PIN);
  65. delay(100);
  66. }
  67. #endif
  68. // Init Servo Pins
  69. #if PIN_EXISTS(SERVO0)
  70. OUT_WRITE(SERVO0_PIN, LOW);
  71. #endif
  72. #if PIN_EXISTS(SERVO1)
  73. OUT_WRITE(SERVO1_PIN, LOW);
  74. #endif
  75. #if PIN_EXISTS(SERVO2)
  76. OUT_WRITE(SERVO2_PIN, LOW);
  77. #endif
  78. #if PIN_EXISTS(SERVO3)
  79. OUT_WRITE(SERVO3_PIN, LOW);
  80. #endif
  81. //debug_frmwrk_init();
  82. //_DBG("\n\nDebug running\n");
  83. // Initialise the SD card chip select pins as soon as possible
  84. #if PIN_EXISTS(SS)
  85. OUT_WRITE(SS_PIN, HIGH);
  86. #endif
  87. #if PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != SS_PIN
  88. OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
  89. #endif
  90. USB_Init(); // USB Initialization
  91. USB_Connect(FALSE); // USB clear connection
  92. delay(1000); // Give OS time to notice
  93. USB_Connect(TRUE);
  94. #if !BOTH(SHARED_SD_CARD, INIT_SDCARD_ON_BOOT) && DISABLED(NO_SD_HOST_DRIVE)
  95. MSC_SD_Init(0); // Enable USB SD card access
  96. #endif
  97. const millis_t usb_timeout = millis() + 2000;
  98. while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
  99. delay(50);
  100. HAL_idletask();
  101. #if PIN_EXISTS(LED)
  102. TOGGLE(LED_PIN); // Flash quickly during USB initialization
  103. #endif
  104. }
  105. #if NUM_SERIAL > 0
  106. MYSERIAL0.begin(BAUDRATE);
  107. #if NUM_SERIAL > 1
  108. MYSERIAL1.begin(BAUDRATE);
  109. #endif
  110. SERIAL_PRINTF("\n\necho:%s (%dMhz) Initialized\n", isLPC1769() ? "LPC1769" : "LPC1768", SystemCoreClock / 1000000);
  111. SERIAL_FLUSHTX();
  112. #endif
  113. HAL_timer_init();
  114. }
  115. // HAL idle task
  116. void HAL_idletask(void) {
  117. #if ENABLED(SHARED_SD_CARD)
  118. // If Marlin is using the SD card we need to lock it to prevent access from
  119. // a PC via USB.
  120. // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
  121. // this will not reliably detect delete operations. To be safe we will lock
  122. // the disk if Marlin has it mounted. Unfortuately there is currently no way
  123. // to unmount the disk from the LCD menu.
  124. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
  125. if (card.isDetected())
  126. MSC_Aquire_Lock();
  127. else
  128. MSC_Release_Lock();
  129. #endif
  130. // Perform USB stack housekeeping
  131. MSC_RunDeferredCommands();
  132. }
  133. #endif // TARGET_LPC1768