Browse Source

Fix Teensy 3.5/3.6 ADC access for ADC1 (#12258)

mholeys 6 years ago
parent
commit
63ce8baa55
1 changed files with 24 additions and 4 deletions
  1. 24
    4
      Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp

+ 24
- 4
Marlin/src/HAL/HAL_TEENSY35_36/HAL.cpp View File

18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 ****************************************************************************/
19
 ****************************************************************************/
20
 
20
 
21
-
22
 /**
21
 /**
23
  * Description: HAL for Teensy35 (MK64FX512)
22
  * Description: HAL for Teensy35 (MK64FX512)
24
  */
23
  */
30
 
29
 
31
 #include <Wire.h>
30
 #include <Wire.h>
32
 
31
 
33
-uint16_t HAL_adc_result;
32
+uint16_t HAL_adc_result, HAL_adc_select;
34
 
33
 
35
 static const uint8_t pin2sc1a[] = {
34
 static const uint8_t pin2sc1a[] = {
36
   5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
35
   5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
59
 void HAL_adc_init() {
58
 void HAL_adc_init() {
60
   analog_init();
59
   analog_init();
61
   while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
60
   while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
61
+  while (ADC1_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
62
   NVIC_ENABLE_IRQ(IRQ_FTM1);
62
   NVIC_ENABLE_IRQ(IRQ_FTM1);
63
 }
63
 }
64
 
64
 
91
   }
91
   }
92
 }
92
 }
93
 
93
 
94
-void HAL_adc_start_conversion(const uint8_t adc_pin) { ADC0_SC1A = pin2sc1a[adc_pin]; }
94
+void HAL_adc_start_conversion(const uint8_t adc_pin) {
95
+  uint16_t pin = pin2sc1a[adc_pin];
96
+  if (pin == 0xFF) {
97
+    // Digital only
98
+    HAL_adc_select = -1;
99
+  }
100
+  else if (pin & 0x80) {
101
+    HAL_adc_select = 1;
102
+    ADC1_SC1A = pin & 0x7F;
103
+  }
104
+  else {
105
+    HAL_adc_select = 0;
106
+    ADC0_SC1A = pin;
107
+  }
108
+}
95
 
109
 
96
-uint16_t HAL_adc_get_result(void) { return ADC0_RA; }
110
+uint16_t HAL_adc_get_result(void) {
111
+  switch (HAL_adc_select) {
112
+    case 0: return ADC0_RA;
113
+    case 1: return ADC1_RA;
114
+  }
115
+  return 0;
116
+}
97
 
117
 
98
 #endif // __MK64FX512__ || __MK66FX1M0__
118
 #endif // __MK64FX512__ || __MK66FX1M0__

Loading…
Cancel
Save