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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 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. #pragma once
  23. /**
  24. * Description: HAL for Arduino Due and compatible (SAM3X8E)
  25. *
  26. * For ARDUINO_ARCH_SAM
  27. */
  28. #define CPU_32_BIT
  29. #include "../shared/Marduino.h"
  30. #include "../shared/math_32bit.h"
  31. #include "../shared/HAL_SPI.h"
  32. #include "fastio_Due.h"
  33. #include "watchdog_Due.h"
  34. #include "HAL_timers_Due.h"
  35. #include <stdint.h>
  36. // Serial ports
  37. #if !WITHIN(SERIAL_PORT, -1, 3)
  38. #error "SERIAL_PORT must be from -1 to 3"
  39. #endif
  40. // MYSERIAL0 required before MarlinSerial includes!
  41. #define MYSERIAL0 customizedSerial1
  42. #ifdef SERIAL_PORT_2
  43. #if !WITHIN(SERIAL_PORT_2, -1, 3)
  44. #error "SERIAL_PORT_2 must be from -1 to 3"
  45. #elif SERIAL_PORT_2 == SERIAL_PORT
  46. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  47. #endif
  48. #define NUM_SERIAL 2
  49. #define MYSERIAL1 customizedSerial2
  50. #else
  51. #define NUM_SERIAL 1
  52. #endif
  53. #include "MarlinSerial_Due.h"
  54. #include "MarlinSerialUSB_Due.h"
  55. // On AVR this is in math.h?
  56. #define square(x) ((x)*(x))
  57. #ifndef strncpy_P
  58. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  59. #endif
  60. #ifndef vsnprintf_P
  61. #define vsnprintf_P vsnprintf
  62. #endif
  63. // Fix bug in pgm_read_ptr
  64. #undef pgm_read_ptr
  65. #define pgm_read_ptr(addr) (*((void**)(addr)))
  66. #undef pgm_read_word
  67. #define pgm_read_word(addr) (*((uint16_t*)(addr)))
  68. typedef int8_t pin_t;
  69. #define SHARED_SERVOS HAS_SERVOS
  70. #define HAL_SERVO_LIB Servo
  71. //
  72. // Interrupts
  73. //
  74. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  75. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  76. #define ISRS_ENABLED() (!__get_PRIMASK())
  77. #define ENABLE_ISRS() __enable_irq()
  78. #define DISABLE_ISRS() __disable_irq()
  79. void cli(void); // Disable interrupts
  80. void sei(void); // Enable interrupts
  81. void HAL_clear_reset_source(void); // clear reset reason
  82. uint8_t HAL_get_reset_source(void); // get reset reason
  83. //
  84. // SPI: Extended functions taking a channel number (Hardware SPI only)
  85. //
  86. // Write single byte to specified SPI channel
  87. void spiSend(uint32_t chan, byte b);
  88. // Write buffer to specified SPI channel
  89. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  90. // Read single byte from specified SPI channel
  91. uint8_t spiRec(uint32_t chan);
  92. //
  93. // EEPROM
  94. //
  95. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  96. uint8_t eeprom_read_byte(uint8_t *pos);
  97. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  98. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  99. //
  100. // ADC
  101. //
  102. extern uint16_t HAL_adc_result; // result of last ADC conversion
  103. #ifndef analogInputToDigitalPin
  104. #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
  105. #endif
  106. #define HAL_ANALOG_SELECT(pin)
  107. inline void HAL_adc_init(void) {}//todo
  108. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  109. #define HAL_READ_ADC() HAL_adc_result
  110. #define HAL_ADC_READY() true
  111. void HAL_adc_start_conversion(const uint8_t adc_pin);
  112. uint16_t HAL_adc_get_result(void);
  113. //
  114. // Pin Map
  115. //
  116. #define GET_PIN_MAP_PIN(index) index
  117. #define GET_PIN_MAP_INDEX(pin) pin
  118. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  119. //
  120. // Tone
  121. //
  122. void toneInit();
  123. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  124. void noTone(const pin_t _pin);
  125. // Enable hooks into idle and setup for HAL
  126. #define HAL_IDLETASK 1
  127. void HAL_idletask(void);
  128. void HAL_init(void);
  129. //
  130. // Utility functions
  131. //
  132. void _delay_ms(const int delay);
  133. int freeMemory(void);
  134. #ifdef __cplusplus
  135. extern "C" {
  136. #endif
  137. char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);
  138. #ifdef __cplusplus
  139. }
  140. #endif