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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. * Copyright (c) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #pragma once
  24. #define CPU_32_BIT
  25. #include "../../core/macros.h"
  26. #include "../shared/Marduino.h"
  27. #include "../shared/math_32bit.h"
  28. #include "../shared/HAL_SPI.h"
  29. #include "fastio.h"
  30. #include "watchdog.h"
  31. #include "../../inc/MarlinConfigPre.h"
  32. #include <stdint.h>
  33. #ifdef USBCON
  34. #include <USBSerial.h>
  35. #endif
  36. // ------------------------
  37. // Defines
  38. // ------------------------
  39. #if SERIAL_PORT == 0
  40. #error "Serial port 0 does not exist"
  41. #endif
  42. #if !WITHIN(SERIAL_PORT, -1, 6)
  43. #error "SERIAL_PORT must be from -1 to 6"
  44. #endif
  45. #if SERIAL_PORT == -1
  46. #define MYSERIAL0 SerialUSB
  47. #elif SERIAL_PORT == 1
  48. #define MYSERIAL0 Serial1
  49. #elif SERIAL_PORT == 2
  50. #define MYSERIAL0 Serial2
  51. #elif SERIAL_PORT == 3
  52. #define MYSERIAL0 Serial3
  53. #elif SERIAL_PORT == 4
  54. #define MYSERIAL0 Serial4
  55. #elif SERIAL_PORT == 5
  56. #define MYSERIAL0 Serial5
  57. #elif SERIAL_PORT == 6
  58. #define MYSERIAL0 Serial6
  59. #endif
  60. #ifdef SERIAL_PORT_2
  61. #if SERIAL_PORT_2 == 0
  62. #error "Serial port 0 does not exist"
  63. #endif
  64. #if !WITHIN(SERIAL_PORT_2, -1, 6)
  65. #error "SERIAL_PORT_2 must be from -1 to 6"
  66. #elif SERIAL_PORT_2 == SERIAL_PORT
  67. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  68. #endif
  69. #define NUM_SERIAL 2
  70. #if SERIAL_PORT_2 == -1
  71. #define MYSERIAL1 SerialUSB
  72. #elif SERIAL_PORT_2 == 1
  73. #define MYSERIAL1 Serial1
  74. #elif SERIAL_PORT_2 == 2
  75. #define MYSERIAL1 Serial2
  76. #elif SERIAL_PORT_2 == 3
  77. #define MYSERIAL1 Serial3
  78. #elif SERIAL_PORT_2 == 4
  79. #define MYSERIAL1 Serial4
  80. #elif SERIAL_PORT_2 == 5
  81. #define MYSERIAL1 Serial5
  82. #elif SERIAL_PORT_2 == 6
  83. #define MYSERIAL1 Serial6
  84. #endif
  85. #else
  86. #define NUM_SERIAL 1
  87. #endif
  88. #include "timers.h"
  89. /**
  90. * TODO: review this to return 1 for pins that are not analog input
  91. */
  92. #ifndef analogInputToDigitalPin
  93. #define analogInputToDigitalPin(p) (p)
  94. #endif
  95. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  96. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  97. #define ISRS_ENABLED() (!__get_PRIMASK())
  98. #define ENABLE_ISRS() __enable_irq()
  99. #define DISABLE_ISRS() __disable_irq()
  100. #define cli() __disable_irq()
  101. #define sei() __enable_irq()
  102. // On AVR this is in math.h?
  103. #define square(x) ((x)*(x))
  104. #ifndef strncpy_P
  105. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  106. #endif
  107. // Fix bug in pgm_read_ptr
  108. #undef pgm_read_ptr
  109. #define pgm_read_ptr(addr) (*(addr))
  110. // ------------------------
  111. // Types
  112. // ------------------------
  113. typedef int16_t pin_t;
  114. #define HAL_SERVO_LIB libServo
  115. // ------------------------
  116. // Public Variables
  117. // ------------------------
  118. // result of last ADC conversion
  119. extern uint16_t HAL_adc_result;
  120. // ------------------------
  121. // Public functions
  122. // ------------------------
  123. // Memory related
  124. #define __bss_end __bss_end__
  125. // Enable hooks into setup for HAL
  126. void HAL_init(void);
  127. // Clear reset reason
  128. void HAL_clear_reset_source(void);
  129. // Reset reason
  130. uint8_t HAL_get_reset_source(void);
  131. void _delay_ms(const int delay);
  132. extern "C" char* _sbrk(int incr);
  133. #pragma GCC diagnostic push
  134. #pragma GCC diagnostic ignored "-Wunused-function"
  135. static inline int freeMemory() {
  136. volatile char top;
  137. return &top - reinterpret_cast<char*>(_sbrk(0));
  138. }
  139. #pragma GCC diagnostic pop
  140. //
  141. // EEPROM
  142. //
  143. // Wire library should work for i2c EEPROMs
  144. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  145. uint8_t eeprom_read_byte(uint8_t *pos);
  146. void eeprom_read_block(void *__dst, const void *__src, size_t __n);
  147. void eeprom_update_block(const void *__src, void *__dst, size_t __n);
  148. //
  149. // ADC
  150. //
  151. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  152. inline void HAL_adc_init(void) {}
  153. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  154. #define HAL_READ_ADC() HAL_adc_result
  155. #define HAL_ADC_READY() true
  156. void HAL_adc_start_conversion(const uint8_t adc_pin);
  157. uint16_t HAL_adc_get_result(void);
  158. #define GET_PIN_MAP_PIN(index) index
  159. #define GET_PIN_MAP_INDEX(pin) pin
  160. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)