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

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