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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. * HAL_LPC1768/HAL.h
  25. * Hardware Abstraction Layer for NXP LPC1768
  26. */
  27. #define CPU_32_BIT
  28. #define HAL_INIT
  29. void HAL_init();
  30. #include <stdint.h>
  31. #include <stdarg.h>
  32. #include <algorithm>
  33. extern "C" volatile millis_t _millis;
  34. #include <Arduino.h>
  35. #include <pinmapping.h>
  36. #include <CDCSerial.h>
  37. #include "../shared/math_32bit.h"
  38. #include "../shared/HAL_SPI.h"
  39. #include "fastio.h"
  40. #include <adc.h>
  41. #include "watchdog.h"
  42. #include "HAL_timers.h"
  43. #include "MarlinSerial.h"
  44. //
  45. // Default graphical display delays
  46. //
  47. #ifndef ST7920_DELAY_1
  48. #define ST7920_DELAY_1 DELAY_NS(600)
  49. #endif
  50. #ifndef ST7920_DELAY_2
  51. #define ST7920_DELAY_2 DELAY_NS(750)
  52. #endif
  53. #ifndef ST7920_DELAY_3
  54. #define ST7920_DELAY_3 DELAY_NS(750)
  55. #endif
  56. #if !WITHIN(SERIAL_PORT, -1, 3)
  57. #error "SERIAL_PORT must be from -1 to 3"
  58. #endif
  59. #if SERIAL_PORT == -1
  60. #define MYSERIAL0 UsbSerial
  61. #elif SERIAL_PORT == 0
  62. #define MYSERIAL0 MSerial
  63. #elif SERIAL_PORT == 1
  64. #define MYSERIAL0 MSerial1
  65. #elif SERIAL_PORT == 2
  66. #define MYSERIAL0 MSerial2
  67. #elif SERIAL_PORT == 3
  68. #define MYSERIAL0 MSerial3
  69. #endif
  70. #ifdef SERIAL_PORT_2
  71. #if !WITHIN(SERIAL_PORT_2, -1, 3)
  72. #error "SERIAL_PORT_2 must be from -1 to 3"
  73. #elif SERIAL_PORT_2 == SERIAL_PORT
  74. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  75. #endif
  76. #define NUM_SERIAL 2
  77. #if SERIAL_PORT_2 == -1
  78. #define MYSERIAL1 UsbSerial
  79. #elif SERIAL_PORT_2 == 0
  80. #define MYSERIAL1 MSerial
  81. #elif SERIAL_PORT_2 == 1
  82. #define MYSERIAL1 MSerial1
  83. #elif SERIAL_PORT_2 == 2
  84. #define MYSERIAL1 MSerial2
  85. #elif SERIAL_PORT_2 == 3
  86. #define MYSERIAL1 MSerial3
  87. #endif
  88. #else
  89. #define NUM_SERIAL 1
  90. #endif
  91. //
  92. // Interrupts
  93. //
  94. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  95. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  96. #define ISRS_ENABLED() (!__get_PRIMASK())
  97. #define ENABLE_ISRS() __enable_irq()
  98. #define DISABLE_ISRS() __disable_irq()
  99. //
  100. // Utility functions
  101. //
  102. int freeMemory(void);
  103. //
  104. // SPI: Extended functions taking a channel number (Hardware SPI only)
  105. //
  106. // Write single byte to specified SPI channel
  107. void spiSend(uint32_t chan, byte b);
  108. // Write buffer to specified SPI channel
  109. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  110. // Read single byte from specified SPI channel
  111. uint8_t spiRec(uint32_t chan);
  112. //
  113. // ADC API
  114. //
  115. #define ADC_MEDIAN_FILTER_SIZE (23) // Higher values increase step delay (phase shift),
  116. // (ADC_MEDIAN_FILTER_SIZE + 1) / 2 sample step delay (12 samples @ 500Hz: 24ms phase shift)
  117. // Memory usage per ADC channel (bytes): (6 * ADC_MEDIAN_FILTER_SIZE) + 16
  118. // 8 * ((6 * 23) + 16 ) = 1232 Bytes for 8 channels
  119. #define ADC_LOWPASS_K_VALUE (6) // Higher values increase rise time
  120. // Rise time sample delays for 100% signal convergence on full range step
  121. // (1 : 13, 2 : 32, 3 : 67, 4 : 139, 5 : 281, 6 : 565, 7 : 1135, 8 : 2273)
  122. // K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
  123. // Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
  124. using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
  125. #define HAL_adc_init() FilteredADC::init()
  126. #define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin)
  127. #define HAL_START_ADC(pin) FilteredADC::start_conversion(pin)
  128. #define HAL_READ_ADC() FilteredADC::get_result()
  129. #define HAL_ADC_READY() FilteredADC::finished_conversion()
  130. // Parse a G-code word into a pin index
  131. int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
  132. // P0.6 thru P0.9 are for the onboard SD card
  133. #define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09
  134. #define HAL_IDLETASK 1
  135. void HAL_idletask(void);