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.

HAL.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "../../inc/MarlinConfig.h"
  24. #include "../shared/Delay.h"
  25. #include "../../../gcode/parser.h"
  26. #if ENABLED(USE_WATCHDOG)
  27. #include "watchdog.h"
  28. #endif
  29. DefaultSerial USBSerial(false, UsbSerial);
  30. uint32_t HAL_adc_reading = 0;
  31. // U8glib required functions
  32. extern "C" {
  33. void u8g_xMicroDelay(uint16_t val) { DELAY_US(val); }
  34. void u8g_MicroDelay() { u8g_xMicroDelay(1); }
  35. void u8g_10MicroDelay() { u8g_xMicroDelay(10); }
  36. void u8g_Delay(uint16_t val) { delay(val); }
  37. }
  38. //************************//
  39. // return free heap space
  40. int freeMemory() {
  41. char stack_end;
  42. void *heap_start = malloc(sizeof(uint32_t));
  43. if (heap_start == 0) return 0;
  44. uint32_t result = (uint32_t)&stack_end - (uint32_t)heap_start;
  45. free(heap_start);
  46. return result;
  47. }
  48. // scan command line for code
  49. // return index into pin map array if found and the pin is valid.
  50. // return dval if not found or not a valid pin.
  51. int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
  52. const uint16_t val = (uint16_t)parser.intval(code, -1), port = val / 100, pin = val % 100;
  53. const int16_t ind = (port < ((NUM_DIGITAL_PINS) >> 5) && pin < 32) ? ((port << 5) | pin) : -2;
  54. return ind > -1 ? ind : dval;
  55. }
  56. void flashFirmware(const int16_t) {
  57. delay(500); // Give OS time to disconnect
  58. USB_Connect(false); // USB clear connection
  59. delay(1000); // Give OS time to notice
  60. NVIC_SystemReset();
  61. }
  62. void HAL_clear_reset_source(void) {
  63. TERN_(USE_WATCHDOG, watchdog_clear_timeout_flag());
  64. }
  65. uint8_t HAL_get_reset_source(void) {
  66. #if ENABLED(USE_WATCHDOG)
  67. if (watchdog_timed_out()) return RST_WATCHDOG;
  68. #endif
  69. return RST_POWER_ON;
  70. }
  71. #endif // TARGET_LPC1768