|
@@ -0,0 +1,190 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (C) 2018 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
|
+/**
|
|
24
|
+ * Support routines for Due
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+/**
|
|
28
|
+ * Translation of routines & variables used by pinsDebug.h
|
|
29
|
+ */
|
|
30
|
+
|
|
31
|
+#include "Arduino.h"
|
|
32
|
+
|
|
33
|
+/**
|
|
34
|
+ * Due/Marlin quirks
|
|
35
|
+ *
|
|
36
|
+ * a) determining the state of a pin
|
|
37
|
+ * The Due/Arduino status definitions for the g_pinStatus[pin] array are:
|
|
38
|
+ * #define PIN_STATUS_DIGITAL_INPUT_PULLUP (0x01)
|
|
39
|
+ * #define PIN_STATUS_DIGITAL_INPUT (0x02)
|
|
40
|
+ * #define PIN_STATUS_DIGITAL_OUTPUT (0x03)
|
|
41
|
+ * #define PIN_STATUS_ANALOG (0x04)
|
|
42
|
+ * #define PIN_STATUS_PWM (0x05)
|
|
43
|
+ * #define PIN_STATUS_TIMER (0x06)
|
|
44
|
+ *
|
|
45
|
+ * These are only valid if the following Due/Arduino provided functions are used:
|
|
46
|
+ * analogRead
|
|
47
|
+ * analogWrite
|
|
48
|
+ * digitalWrite
|
|
49
|
+ * pinMode
|
|
50
|
+ *
|
|
51
|
+ * The FASTIO routines do not touch the g_pinStatus[pin] array.
|
|
52
|
+ *
|
|
53
|
+ * The net result is that both the g_pinStatus[pin] array and the PIO_OSR register
|
|
54
|
+ * needs to be looked at when determining if a pin is an input or an output.
|
|
55
|
+ *
|
|
56
|
+ * b) Due has only pins 6, 7, 8 & 9 enabled for PWMs. FYI - they run at 1KHz
|
|
57
|
+ *
|
|
58
|
+ * c) NUM_DIGITAL_PINS does not include the analog pins
|
|
59
|
+ *
|
|
60
|
+ * d) Pins 0-78 are defined for Due but 78 has a comment of "unconnected!". 78 is
|
|
61
|
+ * included just in case.
|
|
62
|
+ */
|
|
63
|
+
|
|
64
|
+#define NUMBER_PINS_TOTAL PINS_COUNT
|
|
65
|
+
|
|
66
|
+#define digitalRead_mod(p) digitalRead(p) // AVR digitalRead disabled PWM before it read the pin
|
|
67
|
+#define PRINT_PORT(p)
|
|
68
|
+#define NAME_FORMAT(p) PSTR("%-##p##s")
|
|
69
|
+#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
|
|
70
|
+#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer);} while (0)
|
|
71
|
+#define GET_ARRAY_PIN(p) pin_array[p].pin
|
|
72
|
+#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
|
|
73
|
+#define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
|
|
74
|
+#define IS_ANALOG(P) (((P) >= analogInputToDigitalPin(0)) && ((P) <= analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
|
|
75
|
+#define pwm_status(pin) ((g_pinStatus[pin] & 0xF) == PIN_STATUS_PWM) && \
|
|
76
|
+ ((g_APinDescription[pin].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM)
|
|
77
|
+#define MULTI_NAME_PAD 14 // space needed to be pretty if not first name assigned to a pin
|
|
78
|
+
|
|
79
|
+bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
|
|
80
|
+ volatile Pio* port = g_APinDescription[pin].pPort;
|
|
81
|
+ uint32_t mask = g_APinDescription[pin].ulPin;
|
|
82
|
+ uint8_t pin_status = g_pinStatus[pin] & 0xF;
|
|
83
|
+ return ( (pin_status == 0 && (port->PIO_OSR & mask))
|
|
84
|
+ || pin_status == PIN_STATUS_DIGITAL_OUTPUT
|
|
85
|
+ || pwm_status(pin));
|
|
86
|
+}
|
|
87
|
+
|
|
88
|
+bool GET_ARRAY_IS_DIGITAL(int8_t pin) {
|
|
89
|
+ uint8_t pin_status = g_pinStatus[pin] & 0xF;
|
|
90
|
+ return !(pin_status == PIN_STATUS_ANALOG);
|
|
91
|
+}
|
|
92
|
+
|
|
93
|
+void pwm_details(int32_t pin) {
|
|
94
|
+ if (pwm_status(pin)) {
|
|
95
|
+ uint32_t chan = g_APinDescription[pin].ulPWMChannel;
|
|
96
|
+ SERIAL_PROTOCOLPAIR("PWM = ", PWM_INTERFACE->PWM_CH_NUM[chan].PWM_CDTY);
|
|
97
|
+ }
|
|
98
|
+}
|
|
99
|
+
|
|
100
|
+/**
|
|
101
|
+ * DUE Board pin | PORT | Label
|
|
102
|
+ * ----------------+--------+-------
|
|
103
|
+ * 0 | PA8 | "RX0"
|
|
104
|
+ * 1 | PA9 | "TX0"
|
|
105
|
+ * 2 TIOA0 | PB25 |
|
|
106
|
+ * 3 TIOA7 | PC28 |
|
|
107
|
+ * 4 NPCS1 | PA29 |
|
|
108
|
+ * TIOB6 | PC26 |
|
|
109
|
+ * 5 TIOA6 | PC25 |
|
|
110
|
+ * 6 PWML7 | PC24 |
|
|
111
|
+ * 7 PWML6 | PC23 |
|
|
112
|
+ * 8 PWML5 | PC22 |
|
|
113
|
+ * 9 PWML4 | PC21 |
|
|
114
|
+ * 10 NPCS0 | PA28 |
|
|
115
|
+ * TIOB7 | PC29 |
|
|
116
|
+ * 11 TIOA8 | PD7 |
|
|
117
|
+ * 12 TIOB8 | PD8 |
|
|
118
|
+ * 13 TIOB0 | PB27 | LED AMBER "L"
|
|
119
|
+ * 14 TXD3 | PD4 | "TX3"
|
|
120
|
+ * 15 RXD3 | PD5 | "RX3"
|
|
121
|
+ * 16 TXD1 | PA13 | "TX2"
|
|
122
|
+ * 17 RXD1 | PA12 | "RX2"
|
|
123
|
+ * 18 TXD0 | PA11 | "TX1"
|
|
124
|
+ * 19 RXD0 | PA10 | "RX1"
|
|
125
|
+ * 20 | PB12 | "SDA"
|
|
126
|
+ * 21 | PB13 | "SCL"
|
|
127
|
+ * 22 | PB26 |
|
|
128
|
+ * 23 | PA14 |
|
|
129
|
+ * 24 | PA15 |
|
|
130
|
+ * 25 | PD0 |
|
|
131
|
+ * 26 | PD1 |
|
|
132
|
+ * 27 | PD2 |
|
|
133
|
+ * 28 | PD3 |
|
|
134
|
+ * 29 | PD6 |
|
|
135
|
+ * 30 | PD9 |
|
|
136
|
+ * 31 | PA7 |
|
|
137
|
+ * 32 | PD10 |
|
|
138
|
+ * 33 | PC1 |
|
|
139
|
+ * 34 | PC2 |
|
|
140
|
+ * 35 | PC3 |
|
|
141
|
+ * 36 | PC4 |
|
|
142
|
+ * 37 | PC5 |
|
|
143
|
+ * 38 | PC6 |
|
|
144
|
+ * 39 | PC7 |
|
|
145
|
+ * 40 | PC8 |
|
|
146
|
+ * 41 | PC9 |
|
|
147
|
+ * 42 | PA19 |
|
|
148
|
+ * 43 | PA20 |
|
|
149
|
+ * 44 | PC19 |
|
|
150
|
+ * 45 | PC18 |
|
|
151
|
+ * 46 | PC17 |
|
|
152
|
+ * 47 | PC16 |
|
|
153
|
+ * 48 | PC15 |
|
|
154
|
+ * 49 | PC14 |
|
|
155
|
+ * 50 | PC13 |
|
|
156
|
+ * 51 | PC12 |
|
|
157
|
+ * 52 NPCS2 | PB21 |
|
|
158
|
+ * 53 | PB14 |
|
|
159
|
+ * 54 | PA16 | "A0"
|
|
160
|
+ * 55 | PA24 | "A1"
|
|
161
|
+ * 56 | PA23 | "A2"
|
|
162
|
+ * 57 | PA22 | "A3"
|
|
163
|
+ * 58 TIOB2 | PA6 | "A4"
|
|
164
|
+ * 69 | PA4 | "A5"
|
|
165
|
+ * 60 TIOB1 | PA3 | "A6"
|
|
166
|
+ * 61 TIOA1 | PA2 | "A7"
|
|
167
|
+ * 62 | PB17 | "A8"
|
|
168
|
+ * 63 | PB18 | "A9"
|
|
169
|
+ * 64 | PB19 | "A10"
|
|
170
|
+ * 65 | PB20 | "A11"
|
|
171
|
+ * 66 | PB15 | "DAC0"
|
|
172
|
+ * 67 | PB16 | "DAC1"
|
|
173
|
+ * 68 | PA1 | "CANRX"
|
|
174
|
+ * 69 | PA0 | "CANTX"
|
|
175
|
+ * 70 | PA17 | "SDA1"
|
|
176
|
+ * 71 | PA18 | "SCL1"
|
|
177
|
+ * 72 | PC30 | LED AMBER "RX"
|
|
178
|
+ * 73 | PA21 | LED AMBER "TX"
|
|
179
|
+ * 74 MISO | PA25 |
|
|
180
|
+ * 75 MOSI | PA26 |
|
|
181
|
+ * 76 SCLK | PA27 |
|
|
182
|
+ * 77 NPCS0 | PA28 |
|
|
183
|
+ * 78 NPCS3 | PB23 | unconnected!
|
|
184
|
+ *
|
|
185
|
+ * USB pin | PORT
|
|
186
|
+ * ----------------+--------
|
|
187
|
+ * ID | PB11
|
|
188
|
+ * VBOF | PB10
|
|
189
|
+ *
|
|
190
|
+ */
|