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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // --------------------------------------------------------------------------
  26. // Includes
  27. // --------------------------------------------------------------------------
  28. #include "../../core/macros.h"
  29. #include "../shared/Marduino.h"
  30. #include "../shared/math_32bit.h"
  31. #include "../shared/HAL_SPI.h"
  32. #include "fastio_STM32.h"
  33. #include "watchdog_STM32.h"
  34. #include "../../inc/MarlinConfigPre.h"
  35. #include <stdint.h>
  36. #ifdef USBCON
  37. #include <USBSerial.h>
  38. #endif
  39. // --------------------------------------------------------------------------
  40. // Defines
  41. // --------------------------------------------------------------------------
  42. #if SERIAL_PORT == 0
  43. #error "Serial port 0 does not exist"
  44. #endif
  45. #if !WITHIN(SERIAL_PORT, -1, 6)
  46. #error "SERIAL_PORT must be from -1 to 6"
  47. #endif
  48. #if SERIAL_PORT == -1
  49. #define MYSERIAL0 SerialUSB
  50. #elif SERIAL_PORT == 1
  51. #define MYSERIAL0 Serial1
  52. #elif SERIAL_PORT == 2
  53. #define MYSERIAL0 Serial2
  54. #elif SERIAL_PORT == 3
  55. #define MYSERIAL0 Serial3
  56. #elif SERIAL_PORT == 4
  57. #define MYSERIAL0 Serial4
  58. #elif SERIAL_PORT == 5
  59. #define MYSERIAL0 Serial5
  60. #elif SERIAL_PORT == 6
  61. #define MYSERIAL0 Serial6
  62. #endif
  63. #ifdef SERIAL_PORT_2
  64. #if SERIAL_PORT_2 == 0
  65. #error "Serial port 0 does not exist"
  66. #endif
  67. #if !WITHIN(SERIAL_PORT_2, -1, 6)
  68. #error "SERIAL_PORT_2 must be from -1 to 6"
  69. #elif SERIAL_PORT_2 == SERIAL_PORT
  70. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  71. #endif
  72. #define NUM_SERIAL 2
  73. #if SERIAL_PORT_2 == -1
  74. #define MYSERIAL1 SerialUSB
  75. #elif SERIAL_PORT_2 == 1
  76. #define MYSERIAL1 Serial1
  77. #elif SERIAL_PORT_2 == 2
  78. #define MYSERIAL1 Serial2
  79. #elif SERIAL_PORT_2 == 3
  80. #define MYSERIAL1 Serial3
  81. #elif SERIAL_PORT_2 == 4
  82. #define MYSERIAL1 Serial4
  83. #elif SERIAL_PORT_2 == 5
  84. #define MYSERIAL1 Serial5
  85. #elif SERIAL_PORT_2 == 6
  86. #define MYSERIAL1 Serial6
  87. #endif
  88. #else
  89. #define NUM_SERIAL 1
  90. #endif
  91. #include "HAL_timers_STM32.h"
  92. /**
  93. * TODO: review this to return 1 for pins that are not analog input
  94. */
  95. #ifndef analogInputToDigitalPin
  96. #define analogInputToDigitalPin(p) (p)
  97. #endif
  98. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  99. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  100. #define ISRS_ENABLED() (!__get_PRIMASK())
  101. #define ENABLE_ISRS() __enable_irq()
  102. #define DISABLE_ISRS() __disable_irq()
  103. #define cli() __disable_irq()
  104. #define sei() __enable_irq()
  105. // On AVR this is in math.h?
  106. #define square(x) ((x)*(x))
  107. #ifndef strncpy_P
  108. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  109. #endif
  110. // Fix bug in pgm_read_ptr
  111. #undef pgm_read_ptr
  112. #define pgm_read_ptr(addr) (*(addr))
  113. // --------------------------------------------------------------------------
  114. // Types
  115. // --------------------------------------------------------------------------
  116. typedef int8_t pin_t;
  117. #define HAL_SERVO_LIB libServo
  118. // --------------------------------------------------------------------------
  119. // Public Variables
  120. // --------------------------------------------------------------------------
  121. /** result of last ADC conversion */
  122. extern uint16_t HAL_adc_result;
  123. // --------------------------------------------------------------------------
  124. // Public functions
  125. // --------------------------------------------------------------------------
  126. // Memory related
  127. #define __bss_end __bss_end__
  128. // Enable hooks into setup for HAL
  129. void HAL_init(void);
  130. /** clear reset reason */
  131. void HAL_clear_reset_source (void);
  132. /** reset reason */
  133. uint8_t HAL_get_reset_source(void);
  134. void _delay_ms(const int delay);
  135. extern "C" char* _sbrk(int incr);
  136. static inline int freeMemory() {
  137. volatile char top;
  138. return &top - reinterpret_cast<char*>(_sbrk(0));
  139. }
  140. //
  141. // SPI: Extended functions which take a channel number (hardware SPI only)
  142. //
  143. /** Write single byte to specified SPI channel */
  144. void spiSend(uint32_t chan, byte b);
  145. /** Write buffer to specified SPI channel */
  146. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  147. /** Read single byte from specified SPI channel */
  148. uint8_t spiRec(uint32_t chan);
  149. //
  150. // EEPROM
  151. //
  152. // Wire library should work for i2c EEPROMs
  153. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  154. uint8_t eeprom_read_byte(uint8_t *pos);
  155. void eeprom_read_block (void *__dst, const void *__src, size_t __n);
  156. void eeprom_update_block (const void *__src, void *__dst, size_t __n);
  157. //
  158. // ADC
  159. //
  160. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  161. inline void HAL_adc_init(void) {}
  162. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  163. #define HAL_READ_ADC() HAL_adc_result
  164. #define HAL_ADC_READY() true
  165. void HAL_adc_start_conversion(const uint8_t adc_pin);
  166. uint16_t HAL_adc_get_result(void);
  167. #define GET_PIN_MAP_PIN(index) index
  168. #define GET_PIN_MAP_INDEX(pin) pin
  169. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)