My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://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 "../../core/millis_t.h"
  38. extern uint32_t MSC_SD_Init(uint8_t pdrv);
  39. extern "C" int isLPC1769();
  40. extern "C" void disk_timerproc();
  41. void SysTick_Callback() { disk_timerproc(); }
  42. void HAL_init() {
  43. // Init LEDs
  44. #if PIN_EXISTS(LED)
  45. SET_DIR_OUTPUT(LED_PIN);
  46. WRITE_PIN_CLR(LED_PIN);
  47. #if PIN_EXISTS(LED2)
  48. SET_DIR_OUTPUT(LED2_PIN);
  49. WRITE_PIN_CLR(LED2_PIN);
  50. #if PIN_EXISTS(LED3)
  51. SET_DIR_OUTPUT(LED3_PIN);
  52. WRITE_PIN_CLR(LED3_PIN);
  53. #if PIN_EXISTS(LED4)
  54. SET_DIR_OUTPUT(LED4_PIN);
  55. WRITE_PIN_CLR(LED4_PIN);
  56. #endif
  57. #endif
  58. #endif
  59. // Flash status LED 3 times to indicate Marlin has started booting
  60. LOOP_L_N(i, 6) {
  61. TOGGLE(LED_PIN);
  62. delay(100);
  63. }
  64. #endif
  65. // Init Servo Pins
  66. #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
  67. #if HAS_SERVO_0
  68. INIT_SERVO(0);
  69. #endif
  70. #if HAS_SERVO_1
  71. INIT_SERVO(1);
  72. #endif
  73. #if HAS_SERVO_2
  74. INIT_SERVO(2);
  75. #endif
  76. #if HAS_SERVO_3
  77. INIT_SERVO(3);
  78. #endif
  79. //debug_frmwrk_init();
  80. //_DBG("\n\nDebug running\n");
  81. // Initialize the SD card chip select pins as soon as possible
  82. #if PIN_EXISTS(SS)
  83. OUT_WRITE(SS_PIN, HIGH);
  84. #endif
  85. #if PIN_EXISTS(ONBOARD_SD_CS) && ONBOARD_SD_CS_PIN != SS_PIN
  86. OUT_WRITE(ONBOARD_SD_CS_PIN, HIGH);
  87. #endif
  88. #ifdef LPC1768_ENABLE_CLKOUT_12M
  89. /**
  90. * CLKOUTCFG register
  91. * bit 8 (CLKOUT_EN) = enables CLKOUT signal. Disabled for now to prevent glitch when enabling GPIO.
  92. * bits 7:4 (CLKOUTDIV) = set to 0 for divider setting of /1
  93. * bits 3:0 (CLKOUTSEL) = set to 1 to select main crystal oscillator as CLKOUT source
  94. */
  95. LPC_SC->CLKOUTCFG = (0<<8)|(0<<4)|(1<<0);
  96. // set P1.27 pin to function 01 (CLKOUT)
  97. PINSEL_CFG_Type PinCfg;
  98. PinCfg.Portnum = 1;
  99. PinCfg.Pinnum = 27;
  100. PinCfg.Funcnum = 1; // function 01 (CLKOUT)
  101. PinCfg.OpenDrain = 0; // not open drain
  102. PinCfg.Pinmode = 2; // no pull-up/pull-down
  103. PINSEL_ConfigPin(&PinCfg);
  104. // now set CLKOUT_EN bit
  105. LPC_SC->CLKOUTCFG |= (1<<8);
  106. #endif
  107. USB_Init(); // USB Initialization
  108. USB_Connect(FALSE); // USB clear connection
  109. delay(1000); // Give OS time to notice
  110. USB_Connect(TRUE);
  111. #if DISABLED(NO_SD_HOST_DRIVE)
  112. MSC_SD_Init(0); // Enable USB SD card access
  113. #endif
  114. const millis_t usb_timeout = millis() + 2000;
  115. while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
  116. delay(50);
  117. HAL_idletask();
  118. #if PIN_EXISTS(LED)
  119. TOGGLE(LED_PIN); // Flash quickly during USB initialization
  120. #endif
  121. }
  122. HAL_timer_init();
  123. }
  124. // HAL idle task
  125. void HAL_idletask() {
  126. #if HAS_SHARED_MEDIA
  127. // If Marlin is using the SD card we need to lock it to prevent access from
  128. // a PC via USB.
  129. // Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
  130. // this will not reliably detect delete operations. To be safe we will lock
  131. // the disk if Marlin has it mounted. Unfortunately there is currently no way
  132. // to unmount the disk from the LCD menu.
  133. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
  134. if (card.isMounted())
  135. MSC_Aquire_Lock();
  136. else
  137. MSC_Release_Lock();
  138. #endif
  139. // Perform USB stack housekeeping
  140. MSC_RunDeferredCommands();
  141. }
  142. #endif // TARGET_LPC1768