My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HAL.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  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. /**
  23. * Description: HAL for Teensy35 (MK64FX512)
  24. */
  25. #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
  26. #include "HAL.h"
  27. #include "../shared/Delay.h"
  28. #include <Wire.h>
  29. uint16_t HAL_adc_result, HAL_adc_select;
  30. static const uint8_t pin2sc1a[] = {
  31. 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
  32. 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9
  33. 255, 255, 255, 255, 255, 255, 255, // 24-30 are digital only
  34. 14+128, 15+128, 17, 18, 4+128, 5+128, 6+128, 7+128, 17+128, // 31-39 are A12-A20
  35. 255, 255, 255, 255, 255, 255, 255, 255, 255, // 40-48 are digital only
  36. 10+128, 11+128, // 49-50 are A23-A24
  37. 255, 255, 255, 255, 255, 255, 255, // 51-57 are digital only
  38. 255, 255, 255, 255, 255, 255, // 58-63 (sd card pins) are digital only
  39. 3, 19+128, // 64-65 are A10-A11
  40. 23, 23+128,// 66-67 are A21-A22 (DAC pins)
  41. 1, 1+128, // 68-69 are A25-A26 (unused USB host port on Teensy 3.5)
  42. 26, // 70 is Temperature Sensor
  43. 18+128 // 71 is Vref
  44. };
  45. /*
  46. // disable interrupts
  47. void cli() { noInterrupts(); }
  48. // enable interrupts
  49. void sei() { interrupts(); }
  50. */
  51. void HAL_adc_init() {
  52. analog_init();
  53. while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
  54. while (ADC1_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
  55. NVIC_ENABLE_IRQ(IRQ_FTM1);
  56. }
  57. void HAL_clear_reset_source() { }
  58. uint8_t HAL_get_reset_source() {
  59. switch (RCM_SRS0) {
  60. case 128: return RST_POWER_ON; break;
  61. case 64: return RST_EXTERNAL; break;
  62. case 32: return RST_WATCHDOG; break;
  63. // case 8: return RST_LOSS_OF_LOCK; break;
  64. // case 4: return RST_LOSS_OF_CLOCK; break;
  65. // case 2: return RST_LOW_VOLTAGE; break;
  66. }
  67. return 0;
  68. }
  69. extern "C" {
  70. extern char __bss_end;
  71. extern char __heap_start;
  72. extern void* __brkval;
  73. int freeMemory() {
  74. int free_memory;
  75. if ((int)__brkval == 0)
  76. free_memory = ((int)&free_memory) - ((int)&__bss_end);
  77. else
  78. free_memory = ((int)&free_memory) - ((int)__brkval);
  79. return free_memory;
  80. }
  81. }
  82. void HAL_adc_start_conversion(const uint8_t adc_pin) {
  83. const uint16_t pin = pin2sc1a[adc_pin];
  84. if (pin == 0xFF) {
  85. // Digital only
  86. HAL_adc_select = -1;
  87. }
  88. else if (pin & 0x80) {
  89. HAL_adc_select = 1;
  90. ADC1_SC1A = pin & 0x7F;
  91. }
  92. else {
  93. HAL_adc_select = 0;
  94. ADC0_SC1A = pin;
  95. }
  96. }
  97. uint16_t HAL_adc_get_result() {
  98. switch (HAL_adc_select) {
  99. case 0: return ADC0_RA;
  100. case 1: return ADC1_RA;
  101. }
  102. return 0;
  103. }
  104. #endif // __MK64FX512__ || __MK66FX1M0__