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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  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 <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. /**
  21. * HAL for Arduino Due and compatible (SAM3X8E)
  22. */
  23. #ifdef ARDUINO_ARCH_SAM
  24. #include "../../inc/MarlinConfig.h"
  25. #include "HAL.h"
  26. #include <Wire.h>
  27. #include "usb/usb_task.h"
  28. // ------------------------
  29. // Public Variables
  30. // ------------------------
  31. uint16_t HAL_adc_result;
  32. // ------------------------
  33. // Public functions
  34. // ------------------------
  35. // HAL initialization task
  36. void HAL_init() {
  37. // Initialize the USB stack
  38. #if ENABLED(SDSUPPORT)
  39. OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
  40. #endif
  41. usb_task_init();
  42. }
  43. // HAL idle task
  44. void HAL_idletask() {
  45. // Perform USB stack housekeeping
  46. usb_task_idle();
  47. }
  48. // Disable interrupts
  49. void cli() { noInterrupts(); }
  50. // Enable interrupts
  51. void sei() { interrupts(); }
  52. void HAL_clear_reset_source() { }
  53. uint8_t HAL_get_reset_source() {
  54. switch ((RSTC->RSTC_SR >> 8) & 0x07) {
  55. case 0: return RST_POWER_ON;
  56. case 1: return RST_BACKUP;
  57. case 2: return RST_WATCHDOG;
  58. case 3: return RST_SOFTWARE;
  59. case 4: return RST_EXTERNAL;
  60. default: return 0;
  61. }
  62. }
  63. void _delay_ms(const int delay_ms) {
  64. // Todo: port for Due?
  65. delay(delay_ms);
  66. }
  67. extern "C" {
  68. extern unsigned int _ebss; // end of bss section
  69. }
  70. // Return free memory between end of heap (or end bss) and whatever is current
  71. int freeMemory() {
  72. int free_memory, heap_end = (int)_sbrk(0);
  73. return (int)&free_memory - (heap_end ?: (int)&_ebss);
  74. }
  75. // ------------------------
  76. // ADC
  77. // ------------------------
  78. void HAL_adc_start_conversion(const uint8_t ch) {
  79. HAL_adc_result = analogRead(ch);
  80. }
  81. uint16_t HAL_adc_get_result() {
  82. // nop
  83. return HAL_adc_result;
  84. }
  85. #endif // ARDUINO_ARCH_SAM