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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include <iostream>
  24. #include <stdint.h>
  25. #include <stdarg.h>
  26. #undef min
  27. #undef max
  28. #include <algorithm>
  29. #include "hardware/Clock.h"
  30. #include "../shared/Marduino.h"
  31. #include "../shared/math_32bit.h"
  32. #include "../shared/HAL_SPI.h"
  33. #include "fastio.h"
  34. #include "watchdog.h"
  35. #include "serial.h"
  36. // ------------------------
  37. // Defines
  38. // ------------------------
  39. #define CPU_32_BIT
  40. #define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
  41. #define F_CPU 100000000UL
  42. #define SystemCoreClock F_CPU
  43. #define DELAY_CYCLES(x) Clock::delayCycles(x)
  44. #define CPU_ST7920_DELAY_1 600
  45. #define CPU_ST7920_DELAY_2 750
  46. #define CPU_ST7920_DELAY_3 750
  47. void _printf(const char *format, ...);
  48. void _putc(uint8_t c);
  49. uint8_t _getc();
  50. //arduino: Print.h
  51. #define DEC 10
  52. #define HEX 16
  53. #define OCT 8
  54. #define BIN 2
  55. //arduino: binary.h (weird defines)
  56. #define B01 1
  57. #define B10 2
  58. // ------------------------
  59. // Serial ports
  60. // ------------------------
  61. extern MSerialT usb_serial;
  62. #define MYSERIAL1 usb_serial
  63. //
  64. // Interrupts
  65. //
  66. #define CRITICAL_SECTION_START()
  67. #define CRITICAL_SECTION_END()
  68. // ADC
  69. #define HAL_ADC_VREF 5.0
  70. #define HAL_ADC_RESOLUTION 10
  71. // ------------------------
  72. // Class Utilities
  73. // ------------------------
  74. #pragma GCC diagnostic push
  75. #if GCC_VERSION <= 50000
  76. #pragma GCC diagnostic ignored "-Wunused-function"
  77. #endif
  78. int freeMemory();
  79. #pragma GCC diagnostic pop
  80. // ------------------------
  81. // MarlinHAL Class
  82. // ------------------------
  83. class MarlinHAL {
  84. public:
  85. // Earliest possible init, before setup()
  86. MarlinHAL() {}
  87. static void init() {} // Called early in setup()
  88. static void init_board() {} // Called less early in setup()
  89. static void reboot(); // Reset the application state and GPIO
  90. // Interrupts
  91. static bool isr_state() { return true; }
  92. static void isr_on() {}
  93. static void isr_off() {}
  94. static void delay_ms(const int ms) { _delay_ms(ms); }
  95. // Tasks, called from idle()
  96. static void idletask() {}
  97. // Reset
  98. static constexpr uint8_t reset_reason = RST_POWER_ON;
  99. static uint8_t get_reset_source() { return reset_reason; }
  100. static void clear_reset_source() {}
  101. // Free SRAM
  102. static int freeMemory() { return ::freeMemory(); }
  103. //
  104. // ADC Methods
  105. //
  106. static uint8_t active_ch;
  107. // Called by Temperature::init once at startup
  108. static void adc_init() {}
  109. // Called by Temperature::init for each sensor at startup
  110. static void adc_enable(const uint8_t) {}
  111. // Begin ADC sampling on the given channel
  112. static void adc_start(const uint8_t ch) { active_ch = ch; }
  113. // Is the ADC ready for reading?
  114. static bool adc_ready() { return true; }
  115. // The current value of the ADC register
  116. static uint16_t adc_value();
  117. /**
  118. * Set the PWM duty cycle for the pin to the given value.
  119. * No option to change the resolution or invert the duty cycle.
  120. */
  121. static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
  122. analogWrite(pin, v);
  123. }
  124. static void set_pwm_frequency(const pin_t, int) {}
  125. };