Browse Source

LPC1768 Pin Mapping and M43 cleanup (#8119)

* LPC1768 M43 cleanup

* Update pinmapping.h to #define pins
Thomas Moore 7 years ago
parent
commit
50b4f9cbf7

+ 139
- 79
Marlin/src/HAL/HAL_LPC1768/pinmapping.h View File

26
 
26
 
27
 typedef int16_t pin_t;
27
 typedef int16_t pin_t;
28
 
28
 
29
-const uint8_t PIN_FEATURE_INTERRUPT = 1 << 0;
30
-const uint8_t PIN_FEATURE_PWM = 1 << 1;
31
-constexpr uint8_t PIN_FEATURE_ADC(const int8_t chan) { return (((chan + 1) & 0b1111) << 2); }
29
+#define PORT_0  000
30
+#define PORT_1  001
31
+#define PORT_2  010
32
+#define PORT_3  011
33
+#define PORT_4  100
32
 
34
 
33
-constexpr pin_t LPC1768_PIN(const uint8_t port, const uint8_t pin, const uint8_t feat = 0) {
34
-  return (((pin_t)feat << 8) | (((pin_t)port & 0x7) << 5) | ((pin_t)pin & 0x1F));
35
-}
35
+#define PORT_(p)  PORT_##p
36
+#define PORT(p)   PORT_(p)
37
+
38
+#define PIN_0  00000
39
+#define PIN_1  00001
40
+#define PIN_2  00010
41
+#define PIN_3  00011
42
+#define PIN_4  00100
43
+#define PIN_5  00101
44
+#define PIN_6  00110
45
+#define PIN_7  00111
46
+#define PIN_8  01000
47
+#define PIN_9  01001
48
+#define PIN_10 01010
49
+#define PIN_11 01011
50
+#define PIN_12 01100
51
+#define PIN_13 01101
52
+#define PIN_14 01110
53
+#define PIN_15 01111
54
+#define PIN_16 10000
55
+#define PIN_17 10001
56
+#define PIN_18 10010
57
+#define PIN_19 10011
58
+#define PIN_20 10100
59
+#define PIN_21 10101
60
+#define PIN_22 10110
61
+#define PIN_23 10111
62
+#define PIN_24 11000
63
+#define PIN_25 11001
64
+#define PIN_26 11010
65
+#define PIN_27 11011
66
+#define PIN_28 11100
67
+#define PIN_29 11101
68
+#define PIN_30 11110
69
+#define PIN_31 11111
70
+
71
+#define PIN_(p) PIN_##p
72
+#define PIN(p)  PIN_(p)
73
+
74
+#define ADC_NONE    0000
75
+#define ADC_CHAN_0  0001
76
+#define ADC_CHAN_1  0010
77
+#define ADC_CHAN_2  0011
78
+#define ADC_CHAN_3  0100
79
+#define ADC_CHAN_4  0101
80
+#define ADC_CHAN_5  0110
81
+#define ADC_CHAN_6  0111
82
+#define ADC_CHAN_7  1000
83
+
84
+#define ADC_CHAN_(c)  ADC_CHAN_##c
85
+#define ADC_CHAN(p)   ADC_CHAN_(p)
86
+
87
+#define BOOL_0 0
88
+#define BOOL_1 1
89
+#define BOOL_(b)      BOOL_##b
90
+
91
+#define INTERRUPT(b)  BOOL_(b)
92
+#define PWM(b)        BOOL_(b)
93
+
94
+#define LPC1768_PIN_(port, pin, int, pwm, adc)  0b00##adc##pwm##int##port##pin
95
+#define LPC1768_PIN(port, pin, int, pwm, adc)   LPC1768_PIN_(port, pin, int, pwm, adc)
36
 
96
 
37
 constexpr uint8_t LPC1768_PIN_PORT(const pin_t pin) { return ((uint8_t)((pin >> 5) & 0b111)); }
97
 constexpr uint8_t LPC1768_PIN_PORT(const pin_t pin) { return ((uint8_t)((pin >> 5) & 0b111)); }
38
 constexpr uint8_t LPC1768_PIN_PIN(const pin_t pin) { return ((uint8_t)(pin & 0b11111)); }
98
 constexpr uint8_t LPC1768_PIN_PIN(const pin_t pin) { return ((uint8_t)(pin & 0b11111)); }
39
-constexpr bool LPC1768_PIN_INTERRUPT(const pin_t pin) { return (((pin >> 8) & PIN_FEATURE_INTERRUPT) != 0); }
40
-constexpr bool LPC1768_PIN_PWM(const pin_t pin) { return (((pin >> 8) & PIN_FEATURE_PWM) != 0); }
41
-constexpr int8_t LPC1768_PIN_ADC(const pin_t pin) { return (int8_t)((pin >> 8) & 0b1111) - 1; }
99
+constexpr bool LPC1768_PIN_INTERRUPT(const pin_t pin) { return (((pin >> 8) & 0b1) != 0); }
100
+constexpr bool LPC1768_PIN_PWM(const pin_t pin) { return (((pin >> 9) & 0b1) != 0); }
101
+constexpr int8_t LPC1768_PIN_ADC(const pin_t pin) { return (int8_t)((pin >> 10) & 0b1111) - 1; }
42
 
102
 
43
 // ******************
103
 // ******************
44
 // Runtime pinmapping
104
 // Runtime pinmapping
45
 // ******************
105
 // ******************
46
 #if SERIAL_PORT != 3
106
 #if SERIAL_PORT != 3
47
-  const pin_t P0_0  = LPC1768_PIN(0,  0, PIN_FEATURE_INTERRUPT);
48
-  const pin_t P0_1  = LPC1768_PIN(0,  1, PIN_FEATURE_INTERRUPT);
107
+  #define P0_0   LPC1768_PIN(PORT(0), PIN(0), INTERRUPT(1), PWM(0), ADC_NONE)
108
+  #define P0_1   LPC1768_PIN(PORT(0), PIN(1), INTERRUPT(1), PWM(0), ADC_NONE)
49
 #endif
109
 #endif
50
 #if SERIAL_PORT != 0
110
 #if SERIAL_PORT != 0
51
-  const pin_t P0_2  = LPC1768_PIN(0,  2, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(7));
52
-  const pin_t P0_3  = LPC1768_PIN(0,  3, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(6));
111
+  #define P0_2   LPC1768_PIN(PORT(0), PIN(2), INTERRUPT(1), PWM(0), ADC_CHAN(7))
112
+  #define P0_3   LPC1768_PIN(PORT(0), PIN(3), INTERRUPT(1), PWM(0), ADC_CHAN(6))
53
 #endif
113
 #endif
54
-const pin_t P0_4  = LPC1768_PIN(0,  4, PIN_FEATURE_INTERRUPT);
55
-const pin_t P0_5  = LPC1768_PIN(0,  5, PIN_FEATURE_INTERRUPT);
56
-const pin_t P0_6  = LPC1768_PIN(0,  6, PIN_FEATURE_INTERRUPT);
57
-const pin_t P0_7  = LPC1768_PIN(0,  7, PIN_FEATURE_INTERRUPT);
58
-const pin_t P0_8  = LPC1768_PIN(0,  8, PIN_FEATURE_INTERRUPT);
59
-const pin_t P0_9  = LPC1768_PIN(0,  9, PIN_FEATURE_INTERRUPT);
114
+#define P0_4   LPC1768_PIN(PORT(0), PIN(4), INTERRUPT(1), PWM(0), ADC_NONE)
115
+#define P0_5   LPC1768_PIN(PORT(0), PIN(5), INTERRUPT(1), PWM(0), ADC_NONE)
116
+#define P0_6   LPC1768_PIN(PORT(0), PIN(6), INTERRUPT(1), PWM(0), ADC_NONE)
117
+#define P0_7   LPC1768_PIN(PORT(0), PIN(7), INTERRUPT(1), PWM(0), ADC_NONE)
118
+#define P0_8   LPC1768_PIN(PORT(0), PIN(8), INTERRUPT(1), PWM(0), ADC_NONE)
119
+#define P0_9   LPC1768_PIN(PORT(0), PIN(9), INTERRUPT(1), PWM(0), ADC_NONE)
60
 #if SERIAL_PORT != 2
120
 #if SERIAL_PORT != 2
61
-  const pin_t P0_10 = LPC1768_PIN(0, 10, PIN_FEATURE_INTERRUPT);
62
-  const pin_t P0_11 = LPC1768_PIN(0, 11, PIN_FEATURE_INTERRUPT);
121
+  #define P0_10  LPC1768_PIN(PORT(0), PIN(10), INTERRUPT(1), PWM(0), ADC_NONE)
122
+  #define P0_11  LPC1768_PIN(PORT(0), PIN(11), INTERRUPT(1), PWM(0), ADC_NONE)
63
 #endif
123
 #endif
64
 #if SERIAL_PORT != 1
124
 #if SERIAL_PORT != 1
65
-  const pin_t P0_15 = LPC1768_PIN(0, 15, PIN_FEATURE_INTERRUPT);
66
-  const pin_t P0_16 = LPC1768_PIN(0, 16, PIN_FEATURE_INTERRUPT);
125
+  #define P0_15  LPC1768_PIN(PORT(0), PIN(15), INTERRUPT(1), PWM(0), ADC_NONE)
126
+  #define P0_16  LPC1768_PIN(PORT(0), PIN(16), INTERRUPT(1), PWM(0), ADC_NONE)
67
 #endif
127
 #endif
68
-const pin_t P0_17 = LPC1768_PIN(0, 17, PIN_FEATURE_INTERRUPT);
69
-const pin_t P0_18 = LPC1768_PIN(0, 18, PIN_FEATURE_INTERRUPT);
70
-const pin_t P0_19 = LPC1768_PIN(0, 19, PIN_FEATURE_INTERRUPT);
71
-const pin_t P0_20 = LPC1768_PIN(0, 20, PIN_FEATURE_INTERRUPT);
72
-const pin_t P0_21 = LPC1768_PIN(0, 21, PIN_FEATURE_INTERRUPT);
73
-const pin_t P0_22 = LPC1768_PIN(0, 22, PIN_FEATURE_INTERRUPT);
74
-const pin_t P0_23 = LPC1768_PIN(0, 23, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(0));
75
-const pin_t P0_24 = LPC1768_PIN(0, 24, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(1));
76
-const pin_t P0_25 = LPC1768_PIN(0, 25, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(2));
77
-const pin_t P0_26 = LPC1768_PIN(0, 26, PIN_FEATURE_INTERRUPT | PIN_FEATURE_ADC(3));
78
-const pin_t P0_27 = LPC1768_PIN(0, 27, PIN_FEATURE_INTERRUPT);
79
-const pin_t P0_28 = LPC1768_PIN(0, 28, PIN_FEATURE_INTERRUPT);
80
-const pin_t P0_29 = LPC1768_PIN(0, 29, PIN_FEATURE_INTERRUPT);
81
-const pin_t P0_30 = LPC1768_PIN(0, 30, PIN_FEATURE_INTERRUPT);
82
-const pin_t P1_0  = LPC1768_PIN(1,  0);
83
-const pin_t P1_1  = LPC1768_PIN(1,  1);
84
-const pin_t P1_4  = LPC1768_PIN(1,  4);
85
-const pin_t P1_8  = LPC1768_PIN(1,  8);
86
-const pin_t P1_9  = LPC1768_PIN(1,  9);
87
-const pin_t P1_10 = LPC1768_PIN(1, 10);
88
-const pin_t P1_14 = LPC1768_PIN(1, 14);
89
-const pin_t P1_15 = LPC1768_PIN(1, 15);
90
-const pin_t P1_16 = LPC1768_PIN(1, 16);
91
-const pin_t P1_17 = LPC1768_PIN(1, 17);
92
-const pin_t P1_18 = LPC1768_PIN(1, 18, PIN_FEATURE_PWM);
93
-const pin_t P1_19 = LPC1768_PIN(1, 19);
94
-const pin_t P1_20 = LPC1768_PIN(1, 20, PIN_FEATURE_PWM);
95
-const pin_t P1_21 = LPC1768_PIN(1, 21, PIN_FEATURE_PWM);
96
-const pin_t P1_22 = LPC1768_PIN(1, 22);
97
-const pin_t P1_23 = LPC1768_PIN(1, 23, PIN_FEATURE_PWM);
98
-const pin_t P1_24 = LPC1768_PIN(1, 24, PIN_FEATURE_PWM);
99
-const pin_t P1_25 = LPC1768_PIN(1, 25);
100
-const pin_t P1_26 = LPC1768_PIN(1, 26, PIN_FEATURE_PWM);
101
-const pin_t P1_27 = LPC1768_PIN(1, 27);
102
-const pin_t P1_28 = LPC1768_PIN(1, 28);
103
-const pin_t P1_29 = LPC1768_PIN(1, 29);
104
-const pin_t P1_30 = LPC1768_PIN(1, 30, PIN_FEATURE_ADC(4));
105
-const pin_t P1_31 = LPC1768_PIN(1, 31, PIN_FEATURE_ADC(5));
106
-const pin_t P2_0  = LPC1768_PIN(2,  0, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
107
-const pin_t P2_1  = LPC1768_PIN(2,  1, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
108
-const pin_t P2_2  = LPC1768_PIN(2,  2, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
109
-const pin_t P2_3  = LPC1768_PIN(2,  3, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
110
-const pin_t P2_4  = LPC1768_PIN(2,  4, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
111
-const pin_t P2_5  = LPC1768_PIN(2,  5, PIN_FEATURE_INTERRUPT | PIN_FEATURE_PWM);
112
-const pin_t P2_6  = LPC1768_PIN(2,  6, PIN_FEATURE_INTERRUPT);
113
-const pin_t P2_7  = LPC1768_PIN(2,  7, PIN_FEATURE_INTERRUPT);
114
-const pin_t P2_8  = LPC1768_PIN(2,  8, PIN_FEATURE_INTERRUPT);
115
-const pin_t P2_9  = LPC1768_PIN(2,  9, PIN_FEATURE_INTERRUPT);
116
-const pin_t P2_10 = LPC1768_PIN(2, 10, PIN_FEATURE_INTERRUPT);
117
-const pin_t P2_11 = LPC1768_PIN(2, 11, PIN_FEATURE_INTERRUPT);
118
-const pin_t P2_12 = LPC1768_PIN(2, 12, PIN_FEATURE_INTERRUPT);
119
-const pin_t P2_13 = LPC1768_PIN(2, 13, PIN_FEATURE_INTERRUPT);
120
-const pin_t P3_25 = LPC1768_PIN(3, 25, PIN_FEATURE_PWM);
121
-const pin_t P3_26 = LPC1768_PIN(3, 26, PIN_FEATURE_PWM);
122
-const pin_t P4_28 = LPC1768_PIN(4, 28);
123
-const pin_t P4_29 = LPC1768_PIN(4, 29);
128
+#define P0_17  LPC1768_PIN(PORT(0), PIN(17), INTERRUPT(1), PWM(0), ADC_NONE)
129
+#define P0_18  LPC1768_PIN(PORT(0), PIN(18), INTERRUPT(1), PWM(0), ADC_NONE)
130
+#define P0_19  LPC1768_PIN(PORT(0), PIN(19), INTERRUPT(1), PWM(0), ADC_NONE)
131
+#define P0_20  LPC1768_PIN(PORT(0), PIN(20), INTERRUPT(1), PWM(0), ADC_NONE)
132
+#define P0_21  LPC1768_PIN(PORT(0), PIN(21), INTERRUPT(1), PWM(0), ADC_NONE)
133
+#define P0_22  LPC1768_PIN(PORT(0), PIN(22), INTERRUPT(1), PWM(0), ADC_NONE)
134
+#define P0_23  LPC1768_PIN(PORT(0), PIN(23), INTERRUPT(1), PWM(0), ADC_CHAN(0))
135
+#define P0_24  LPC1768_PIN(PORT(0), PIN(24), INTERRUPT(1), PWM(0), ADC_CHAN(1))
136
+#define P0_25  LPC1768_PIN(PORT(0), PIN(25), INTERRUPT(1), PWM(0), ADC_CHAN(2))
137
+#define P0_26  LPC1768_PIN(PORT(0), PIN(26), INTERRUPT(1), PWM(0), ADC_CHAN(3))
138
+#define P0_27  LPC1768_PIN(PORT(0), PIN(27), INTERRUPT(1), PWM(0), ADC_NONE)
139
+#define P0_28  LPC1768_PIN(PORT(0), PIN(28), INTERRUPT(1), PWM(0), ADC_NONE)
140
+#define P0_29  LPC1768_PIN(PORT(0), PIN(29), INTERRUPT(1), PWM(0), ADC_NONE)
141
+#define P0_30  LPC1768_PIN(PORT(0), PIN(30), INTERRUPT(1), PWM(0), ADC_NONE)
142
+#define P1_0   LPC1768_PIN(PORT(1), PIN(0), INTERRUPT(0), PWM(0), ADC_NONE)
143
+#define P1_1   LPC1768_PIN(PORT(1), PIN(1), INTERRUPT(0), PWM(0), ADC_NONE)
144
+#define P1_4   LPC1768_PIN(PORT(1), PIN(4), INTERRUPT(0), PWM(0), ADC_NONE)
145
+#define P1_8   LPC1768_PIN(PORT(1), PIN(8), INTERRUPT(0), PWM(0), ADC_NONE)
146
+#define P1_9   LPC1768_PIN(PORT(1), PIN(9), INTERRUPT(0), PWM(0), ADC_NONE)
147
+#define P1_10  LPC1768_PIN(PORT(1), PIN(10), INTERRUPT(0), PWM(0), ADC_NONE)
148
+#define P1_14  LPC1768_PIN(PORT(1), PIN(14), INTERRUPT(0), PWM(0), ADC_NONE)
149
+#define P1_15  LPC1768_PIN(PORT(1), PIN(15), INTERRUPT(0), PWM(0), ADC_NONE)
150
+#define P1_16  LPC1768_PIN(PORT(1), PIN(16), INTERRUPT(0), PWM(0), ADC_NONE)
151
+#define P1_17  LPC1768_PIN(PORT(1), PIN(17), INTERRUPT(0), PWM(0), ADC_NONE)
152
+#define P1_18  LPC1768_PIN(PORT(1), PIN(18), INTERRUPT(0), PWM(1), ADC_NONE)
153
+#define P1_19  LPC1768_PIN(PORT(1), PIN(19), INTERRUPT(0), PWM(0), ADC_NONE)
154
+#define P1_20  LPC1768_PIN(PORT(1), PIN(20), INTERRUPT(0), PWM(1), ADC_NONE)
155
+#define P1_21  LPC1768_PIN(PORT(1), PIN(21), INTERRUPT(0), PWM(1), ADC_NONE)
156
+#define P1_22  LPC1768_PIN(PORT(1), PIN(22), INTERRUPT(0), PWM(0), ADC_NONE)
157
+#define P1_23  LPC1768_PIN(PORT(1), PIN(23), INTERRUPT(0), PWM(1), ADC_NONE)
158
+#define P1_24  LPC1768_PIN(PORT(1), PIN(24), INTERRUPT(0), PWM(1), ADC_NONE)
159
+#define P1_25  LPC1768_PIN(PORT(1), PIN(25), INTERRUPT(0), PWM(0), ADC_NONE)
160
+#define P1_26  LPC1768_PIN(PORT(1), PIN(26), INTERRUPT(0), PWM(1), ADC_NONE)
161
+#define P1_27  LPC1768_PIN(PORT(1), PIN(27), INTERRUPT(0), PWM(0), ADC_NONE)
162
+#define P1_28  LPC1768_PIN(PORT(1), PIN(28), INTERRUPT(0), PWM(0), ADC_NONE)
163
+#define P1_29  LPC1768_PIN(PORT(1), PIN(29), INTERRUPT(0), PWM(0), ADC_NONE)
164
+#define P1_30  LPC1768_PIN(PORT(1), PIN(30), INTERRUPT(0), PWM(0), ADC_CHAN(4))
165
+#define P1_31  LPC1768_PIN(PORT(1), PIN(31), INTERRUPT(0), PWM(0), ADC_CHAN(5))
166
+#define P2_0   LPC1768_PIN(PORT(2), PIN(0), INTERRUPT(1), PWM(1), ADC_NONE)
167
+#define P2_1   LPC1768_PIN(PORT(2), PIN(1), INTERRUPT(1), PWM(1), ADC_NONE)
168
+#define P2_2   LPC1768_PIN(PORT(2), PIN(2), INTERRUPT(1), PWM(1), ADC_NONE)
169
+#define P2_3   LPC1768_PIN(PORT(2), PIN(3), INTERRUPT(1), PWM(1), ADC_NONE)
170
+#define P2_4   LPC1768_PIN(PORT(2), PIN(4), INTERRUPT(1), PWM(1), ADC_NONE)
171
+#define P2_5   LPC1768_PIN(PORT(2), PIN(5), INTERRUPT(1), PWM(1), ADC_NONE)
172
+#define P2_6   LPC1768_PIN(PORT(2), PIN(6), INTERRUPT(1), PWM(0), ADC_NONE)
173
+#define P2_7   LPC1768_PIN(PORT(2), PIN(7), INTERRUPT(1), PWM(0), ADC_NONE)
174
+#define P2_8   LPC1768_PIN(PORT(2), PIN(8), INTERRUPT(1), PWM(0), ADC_NONE)
175
+#define P2_9   LPC1768_PIN(PORT(2), PIN(9), INTERRUPT(1), PWM(0), ADC_NONE)
176
+#define P2_10  LPC1768_PIN(PORT(2), PIN(10), INTERRUPT(1), PWM(0), ADC_NONE)
177
+#define P2_11  LPC1768_PIN(PORT(2), PIN(11), INTERRUPT(1), PWM(0), ADC_NONE)
178
+#define P2_12  LPC1768_PIN(PORT(2), PIN(12), INTERRUPT(1), PWM(0), ADC_NONE)
179
+#define P2_13  LPC1768_PIN(PORT(2), PIN(13), INTERRUPT(1), PWM(0), ADC_NONE)
180
+#define P3_25  LPC1768_PIN(PORT(3), PIN(25), INTERRUPT(0), PWM(1), ADC_NONE)
181
+#define P3_26  LPC1768_PIN(PORT(3), PIN(26), INTERRUPT(0), PWM(1), ADC_NONE)
182
+#define P4_28  LPC1768_PIN(PORT(4), PIN(28), INTERRUPT(0), PWM(0), ADC_NONE)
183
+#define P4_29  LPC1768_PIN(PORT(4), PIN(29), INTERRUPT(0), PWM(0), ADC_NONE)
124
 
184
 
125
 constexpr bool VALID_PIN(const pin_t p) {
185
 constexpr bool VALID_PIN(const pin_t p) {
126
   return (
186
   return (

+ 27
- 31
Marlin/src/HAL/HAL_LPC1768/pinsDebug_LPC1768.h View File

24
  * Support routines for LPC1768
24
  * Support routines for LPC1768
25
 */
25
 */
26
 
26
 
27
+/**
28
+ * translation of routines & variables used by pinsDebug.h
29
+ */
30
+
31
+#define pwm_details(pin) pin = pin    // do nothing  // print PWM details
32
+#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
33
+#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
34
+#define digitalRead_mod(p)  digitalRead(p)
35
+#define digitalPinToPort_DEBUG(p)  0
36
+#define digitalPinToBitMask_DEBUG(pin) 0
37
+#define PRINT_PORT(p) SERIAL_ECHO_SP(10);
38
+#define GET_ARRAY_PIN(p) pin_array[p].pin
39
+#define NAME_FORMAT(p) PSTR("%-##p##s")
40
+#define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
41
+#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%d.%02d"), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer);} while (0)
42
+
27
 // active ADC function/mode/code values for PINSEL registers
43
 // active ADC function/mode/code values for PINSEL registers
28
-int8_t ADC_pin_mode(pin_t pin) {
29
-  uint8_t pin_port = LPC1768_PIN_PORT(pin);
30
-  uint8_t pin_port_pin = LPC1768_PIN_PIN(pin);
31
-  return (pin_port == 0 && pin_port_pin == 2  ? 2 :
32
-          pin_port == 0 && pin_port_pin == 3  ? 2 :
33
-          pin_port == 0 && pin_port_pin == 23 ? 1 :
34
-          pin_port == 0 && pin_port_pin == 24 ? 1 :
35
-          pin_port == 0 && pin_port_pin == 25 ? 1 :
36
-          pin_port == 0 && pin_port_pin == 26 ? 1 :
37
-          pin_port == 1 && pin_port_pin == 30 ? 3 :
38
-          pin_port == 1 && pin_port_pin == 31 ? 3 : -1);
44
+constexpr int8_t ADC_pin_mode(pin_t pin) {
45
+  return (LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 2  ? 2 :
46
+          LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 3  ? 2 :
47
+          LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 23 ? 1 :
48
+          LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 24 ? 1 :
49
+          LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 25 ? 1 :
50
+          LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 26 ? 1 :
51
+          LPC1768_PIN_PORT(pin) == 1 && LPC1768_PIN_PIN(pin) == 30 ? 3 :
52
+          LPC1768_PIN_PORT(pin) == 1 && LPC1768_PIN_PIN(pin) == 31 ? 3 : -1);
39
 }
53
 }
40
 
54
 
41
 int8_t get_pin_mode(pin_t pin) {
55
 int8_t get_pin_mode(pin_t pin) {
56
 
70
 
57
 bool GET_PINMODE(pin_t pin) {
71
 bool GET_PINMODE(pin_t pin) {
58
   int8_t pin_mode = get_pin_mode(pin);
72
   int8_t pin_mode = get_pin_mode(pin);
59
-  if (pin_mode == -1 || (pin_mode && pin_mode == ADC_pin_mode(pin))) // found an invalid pin or active analog pin
73
+  if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
60
     return false;
74
     return false;
61
 
75
 
62
   uint32_t * FIO_reg[5] PROGMEM = {(uint32_t*) 0x2009C000,(uint32_t*)  0x2009C020,(uint32_t*)  0x2009C040,(uint32_t*)  0x2009C060,(uint32_t*)  0x2009C080};
76
   uint32_t * FIO_reg[5] PROGMEM = {(uint32_t*) 0x2009C000,(uint32_t*)  0x2009C020,(uint32_t*)  0x2009C040,(uint32_t*)  0x2009C060,(uint32_t*)  0x2009C080};
64
 }
78
 }
65
 
79
 
66
 bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
80
 bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
67
-  int8_t pin_mode = get_pin_mode(pin);
68
-  return (pin_mode != -1 && (!get_pin_mode(pin) || pin_mode != ADC_pin_mode(pin)));
81
+  return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
69
 }
82
 }
70
-
71
-/**
72
- * translation of routines & variables used by pinsDebug.h
73
- */
74
-
75
-#define pwm_details(pin) pin = pin    // do nothing  // print PWM details
76
-#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
77
-#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
78
-#define digitalRead_mod(p)  digitalRead(p)
79
-#define digitalPinToPort_DEBUG(p)  0
80
-#define digitalPinToBitMask_DEBUG(pin) 0
81
-#define PRINT_PORT(p) SERIAL_ECHO_SP(10);
82
-#define GET_ARRAY_PIN(p) pin_array[p].pin
83
-#define NAME_FORMAT(p) PSTR("%-##p##s")
84
-//  #define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, NAME_FORMAT(MAX_NAME_LENGTH) , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
85
-#define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, PSTR("%-35s") , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
86
-#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%d.%02d "), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer);} while (0)

+ 4
- 4
Marlin/src/pins/pinsDebug.h View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#define MAX_NAME_LENGTH  35    // one place to specify the format of all the sources of names
24
-                               // "-" left justify, "35" minimum width of name, pad with blanks
23
+#define MAX_NAME_LENGTH  39    // one place to specify the format of all the sources of names
24
+                               // "-" left justify, "39" minimum width of name, pad with blanks
25
 
25
 
26
 /**
26
 /**
27
  *  This routine minimizes RAM usage by creating a FLASH resident array to
27
  *  This routine minimizes RAM usage by creating a FLASH resident array to
110
 
110
 
111
 // pretty report with PWM info
111
 // pretty report with PWM info
112
 inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
112
 inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
113
-  char buffer[30];   // for the sprintf statements
113
+  char buffer[MAX_NAME_LENGTH + 1];   // for the sprintf statements
114
   bool found = false, multi_name_pin = false;
114
   bool found = false, multi_name_pin = false;
115
 
115
 
116
   for (uint8_t x = 0; x < COUNT(pin_array); x++)  {    // scan entire array and report all instances of this pin
116
   for (uint8_t x = 0; x < COUNT(pin_array); x++)  {    // scan entire array and report all instances of this pin
151
             else
151
             else
152
           #endif
152
           #endif
153
           {
153
           {
154
-            if (!GET_ARRAY_IS_DIGITAL(x)) {
154
+            if (!GET_ARRAY_IS_DIGITAL(pin)) {
155
               sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
155
               sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
156
               SERIAL_ECHO(buffer);
156
               SERIAL_ECHO(buffer);
157
             }
157
             }

Loading…
Cancel
Save