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

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