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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://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. // --------------------------------------------------------------------------
  26. // Includes
  27. // --------------------------------------------------------------------------
  28. #include "../../inc/MarlinConfig.h"
  29. #include "HAL.h"
  30. #include <Wire.h>
  31. #include "usb/usb_task.h"
  32. // --------------------------------------------------------------------------
  33. // Externals
  34. // --------------------------------------------------------------------------
  35. // --------------------------------------------------------------------------
  36. // Local defines
  37. // --------------------------------------------------------------------------
  38. // --------------------------------------------------------------------------
  39. // Types
  40. // --------------------------------------------------------------------------
  41. // --------------------------------------------------------------------------
  42. // Variables
  43. // --------------------------------------------------------------------------
  44. // --------------------------------------------------------------------------
  45. // Public Variables
  46. // --------------------------------------------------------------------------
  47. uint16_t HAL_adc_result;
  48. // --------------------------------------------------------------------------
  49. // Private Variables
  50. // --------------------------------------------------------------------------
  51. // --------------------------------------------------------------------------
  52. // Function prototypes
  53. // --------------------------------------------------------------------------
  54. // --------------------------------------------------------------------------
  55. // Private functions
  56. // --------------------------------------------------------------------------
  57. // --------------------------------------------------------------------------
  58. // Public functions
  59. // --------------------------------------------------------------------------
  60. // HAL initialization task
  61. void HAL_init(void) {
  62. // Initialize the USB stack
  63. #if ENABLED(SDSUPPORT)
  64. OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
  65. #endif
  66. usb_task_init();
  67. }
  68. // HAL idle task
  69. void HAL_idletask(void) {
  70. // Perform USB stack housekeeping
  71. usb_task_idle();
  72. }
  73. // Disable interrupts
  74. void cli(void) { noInterrupts(); }
  75. // Enable interrupts
  76. void sei(void) { interrupts(); }
  77. void HAL_clear_reset_source(void) { }
  78. uint8_t HAL_get_reset_source(void) {
  79. switch ((RSTC->RSTC_SR >> 8) & 0x07) {
  80. case 0: return RST_POWER_ON;
  81. case 1: return RST_BACKUP;
  82. case 2: return RST_WATCHDOG;
  83. case 3: return RST_SOFTWARE;
  84. case 4: return RST_EXTERNAL;
  85. default: return 0;
  86. }
  87. }
  88. void _delay_ms(const int delay_ms) {
  89. // Todo: port for Due?
  90. delay(delay_ms);
  91. }
  92. extern "C" {
  93. extern unsigned int _ebss; // end of bss section
  94. }
  95. // Return free memory between end of heap (or end bss) and whatever is current
  96. int freeMemory() {
  97. int free_memory, heap_end = (int)_sbrk(0);
  98. return (int)&free_memory - (heap_end ? heap_end : (int)&_ebss);
  99. }
  100. // --------------------------------------------------------------------------
  101. // ADC
  102. // --------------------------------------------------------------------------
  103. void HAL_adc_start_conversion(const uint8_t adc_pin) {
  104. HAL_adc_result = analogRead(adc_pin);
  105. }
  106. uint16_t HAL_adc_get_result(void) {
  107. // nop
  108. return HAL_adc_result;
  109. }
  110. #endif // ARDUINO_ARCH_SAM