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.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Description: HAL for Arduino Due and compatible (SAM3X8E)
  24. *
  25. * For ARDUINO_ARCH_SAM
  26. */
  27. #ifndef _HAL_DUE_H
  28. #define _HAL_DUE_H
  29. #define CPU_32_BIT
  30. #include <stdint.h>
  31. #include <Arduino.h>
  32. #include "../math_32bit.h"
  33. #include "../HAL_SPI.h"
  34. #include "fastio_Due.h"
  35. #include "watchdog_Due.h"
  36. #include "HAL_timers_Due.h"
  37. //
  38. // Defines
  39. //
  40. #define NUM_SERIAL 1
  41. #define MYSERIAL0 customizedSerial
  42. // We need the previous define before the include, or compilation bombs...
  43. #include "MarlinSerial_Due.h"
  44. #include "MarlinSerialUSB_Due.h"
  45. #ifndef analogInputToDigitalPin
  46. #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
  47. #endif
  48. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  49. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  50. #define ISRS_ENABLED() (!__get_PRIMASK())
  51. #define ENABLE_ISRS() __enable_irq()
  52. #define DISABLE_ISRS() __disable_irq()
  53. // On AVR this is in math.h?
  54. #define square(x) ((x)*(x))
  55. #ifndef strncpy_P
  56. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  57. #endif
  58. #ifndef vsnprintf_P
  59. #define vsnprintf_P vsnprintf
  60. #endif
  61. // Fix bug in pgm_read_ptr
  62. #undef pgm_read_ptr
  63. #define pgm_read_ptr(addr) (*((void**)(addr)))
  64. #undef pgm_read_word
  65. #define pgm_read_word(addr) (*((uint16_t*)(addr)))
  66. #define RST_POWER_ON 1
  67. #define RST_EXTERNAL 2
  68. #define RST_BROWN_OUT 4
  69. #define RST_WATCHDOG 8
  70. #define RST_JTAG 16
  71. #define RST_SOFTWARE 32
  72. #define RST_BACKUP 64
  73. // --------------------------------------------------------------------------
  74. // Types
  75. // --------------------------------------------------------------------------
  76. typedef int8_t pin_t;
  77. #define HAL_SERVO_LIB Servo
  78. // --------------------------------------------------------------------------
  79. // Public Variables
  80. // --------------------------------------------------------------------------
  81. extern uint16_t HAL_adc_result; // result of last ADC conversion
  82. void cli(void); // Disable interrupts
  83. void sei(void); // Enable interrupts
  84. void HAL_clear_reset_source(void); // clear reset reason
  85. uint8_t HAL_get_reset_source(void); // get reset reason
  86. void _delay_ms(const int delay);
  87. int freeMemory(void);
  88. /**
  89. * SPI: Extended functions taking a channel number (hardware SPI only)
  90. */
  91. // Write single byte to specified SPI channel
  92. void spiSend(uint32_t chan, byte b);
  93. // Write buffer to specified SPI channel
  94. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  95. // Read single byte from specified SPI channel
  96. uint8_t spiRec(uint32_t chan);
  97. /**
  98. * EEPROM
  99. */
  100. void eeprom_write_byte(unsigned char *pos, unsigned char value);
  101. unsigned char eeprom_read_byte(unsigned char *pos);
  102. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  103. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  104. /**
  105. * ADC
  106. */
  107. #define HAL_ANALOG_SELECT(pin)
  108. inline void HAL_adc_init(void) {}//todo
  109. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  110. #define HAL_READ_ADC HAL_adc_result
  111. void HAL_adc_start_conversion(const uint8_t adc_pin);
  112. uint16_t HAL_adc_get_result(void);
  113. uint16_t HAL_getAdcReading(uint8_t chan);
  114. void HAL_startAdcConversion(uint8_t chan);
  115. uint8_t HAL_pinToAdcChannel(int pin);
  116. uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
  117. //uint16_t HAL_getAdcSuperSample(uint8_t chan);
  118. void HAL_enable_AdcFreerun(void);
  119. //void HAL_disable_AdcFreerun(uint8_t chan);
  120. /**
  121. * Pin Map
  122. */
  123. #define GET_PIN_MAP_PIN(index) index
  124. #define GET_PIN_MAP_INDEX(pin) pin
  125. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  126. /**
  127. * Tone
  128. */
  129. void toneInit();
  130. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  131. void noTone(const pin_t _pin);
  132. // Enable hooks into idle and setup for HAL
  133. #define HAL_IDLETASK 1
  134. #define HAL_INIT 1
  135. void HAL_idletask(void);
  136. void HAL_init(void);
  137. #ifdef __cplusplus
  138. extern "C" {
  139. #endif
  140. char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif // _HAL_DUE_H