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

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