forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinio.h
201 lines (175 loc) · 4.63 KB
/
pinio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/** \file
\brief I/O primitives - step, enable, direction, endstops etc
*/
#ifndef _PINIO_H
#define _PINIO_H
#include "config.h"
#ifndef X_INVERT_ENABLE
#define X_INVERT_ENABLE 0
#endif
#ifndef Y_INVERT_ENABLE
#define Y_INVERT_ENABLE 0
#endif
#ifndef Z_INVERT_ENABLE
#define Z_INVERT_ENABLE 0
#endif
#ifndef E_INVERT_ENABLE
#define E_INVERT_ENABLE 0
#endif
#ifndef STEPPER_ENABLE_INVERT
#define STEPPER_ENABLE_INVERT 0
#endif
/*
Power
*/
#ifdef STEPPER_ENABLE_PIN
#define power_on() do { WRITE(STEPPER_ENABLE_PIN, STEPPER_ENABLE_INVERT); SET_OUTPUT(STEPPER_ENABLE_PIN); } while (0)
#elif defined PS_ON_PIN
#define power_on() do { WRITE(PS_ON_PIN, 0); SET_OUTPUT(PS_ON_PIN); } while (0)
#else
#define power_on() do { } while (0)
#endif
void power_off(void);
/*
X Stepper
*/
#define _x_step(st) WRITE(X_STEP_PIN, st)
#define x_step() _x_step(1);
#ifndef X_INVERT_DIR
#define x_direction(dir) WRITE(X_DIR_PIN, dir)
#else
#define x_direction(dir) WRITE(X_DIR_PIN, dir^1)
#endif
#ifdef X_MIN_PIN
#ifndef X_INVERT_MIN
#define x_min() (READ(X_MIN_PIN)?1:0)
#else
#define x_min() (READ(X_MIN_PIN)?0:1)
#endif
#else
#define x_min() (0)
#endif
#ifdef X_MAX_PIN
#ifndef X_INVERT_MAX
#define x_max() (READ(X_MAX_PIN)?1:0)
#else
#define x_max() (READ(X_MAX_PIN)?0:1)
#endif
#else
#define x_max() (0)
#endif
/*
Y Stepper
*/
#define _y_step(st) WRITE(Y_STEP_PIN, st)
#define y_step() _y_step(1);
#ifndef Y_INVERT_DIR
#define y_direction(dir) WRITE(Y_DIR_PIN, dir)
#else
#define y_direction(dir) WRITE(Y_DIR_PIN, dir^1)
#endif
#ifdef Y_MIN_PIN
#ifndef Y_INVERT_MIN
#define y_min() (READ(Y_MIN_PIN)?1:0)
#else
#define y_min() (READ(Y_MIN_PIN)?0:1)
#endif
#else
#define y_min() (0)
#endif
#ifdef Y_MAX_PIN
#ifndef Y_INVERT_MAX
#define y_max() (READ(Y_MAX_PIN)?1:0)
#else
#define y_max() (READ(Y_MAX_PIN)?0:1)
#endif
#else
#define y_max() (0)
#endif
/*
Z Stepper
*/
#if defined Z_STEP_PIN && defined Z_DIR_PIN
#define _z_step(st) WRITE(Z_STEP_PIN, st)
#define z_step() _z_step(1);
#ifndef Z_INVERT_DIR
#define z_direction(dir) WRITE(Z_DIR_PIN, dir)
#else
#define z_direction(dir) WRITE(Z_DIR_PIN, dir^1)
#endif
#else
#define _z_step(x) do { } while (0)
#define z_step() do { } while (0)
#define z_direction(x) do { } while (0)
#endif
#ifdef Z_MIN_PIN
#ifndef Z_INVERT_MIN
#define z_min() (READ(Z_MIN_PIN)?1:0)
#else
#define z_min() (READ(Z_MIN_PIN)?0:1)
#endif
#else
#define z_min() (0)
#endif
#ifdef Z_MAX_PIN
#ifndef Z_INVERT_MAX
#define z_max() (READ(Z_MAX_PIN)?1:0)
#else
#define z_max() (READ(Z_MAX_PIN)?0:1)
#endif
#else
#define z_max() (0)
#endif
/*
Extruder
*/
#if defined E_STEP_PIN && defined E_DIR_PIN
#define _e_step(st) WRITE(E_STEP_PIN, st)
#define e_step() _e_step(1);
#ifndef E_INVERT_DIR
#define e_direction(dir) WRITE(E_DIR_PIN, dir)
#else
#define e_direction(dir) WRITE(E_DIR_PIN, dir^1)
#endif
#else
#define _e_step(st) do { } while (0)
#define e_step() do { } while (0)
#define e_direction(dir) do { } while (0)
#endif
/*
End Step - All Steppers
(so we don't have to delay in interrupt context)
*/
#define unstep() do { _x_step(0); _y_step(0); _z_step(0); _e_step(0); } while (0)
/*
Stepper Enable Pins
*/
#ifdef X_ENABLE_PIN
#define x_enable() do { WRITE(X_ENABLE_PIN, X_INVERT_ENABLE); SET_OUTPUT(X_ENABLE_PIN); } while (0)
#define x_disable() do { WRITE(X_ENABLE_PIN, X_INVERT_ENABLE ^ 1); SET_OUTPUT(X_ENABLE_PIN); } while (0)
#else
#define x_enable() do { } while (0)
#define x_disable() do { } while (0)
#endif
#ifdef Y_ENABLE_PIN
#define y_enable() do { WRITE(Y_ENABLE_PIN, Y_INVERT_ENABLE); SET_OUTPUT(Y_ENABLE_PIN); } while (0)
#define y_disable() do { WRITE(Y_ENABLE_PIN, Y_INVERT_ENABLE ^ 1); SET_OUTPUT(Y_ENABLE_PIN); } while (0)
#else
#define y_enable() do { } while (0)
#define y_disable() do { } while (0)
#endif
#ifdef Z_ENABLE_PIN
#define z_enable() do { WRITE(Z_ENABLE_PIN, Z_INVERT_ENABLE); SET_OUTPUT(Z_ENABLE_PIN); } while (0)
#define z_disable() do { WRITE(Z_ENABLE_PIN, Z_INVERT_ENABLE ^ 1); SET_OUTPUT(Z_ENABLE_PIN); } while (0)
#else
#define z_enable() do { } while (0)
#define z_disable() do { } while (0)
#endif
#ifdef E_ENABLE_PIN
#define e_enable() do { WRITE(E_ENABLE_PIN, E_INVERT_ENABLE); SET_OUTPUT(E_ENABLE_PIN); } while (0)
#define e_disable() do { WRITE(E_ENABLE_PIN, E_INVERT_ENABLE ^ 1); SET_OUTPUT(E_ENABLE_PIN); } while (0)
#else
#define e_enable() do { } while (0)
#define e_disable() do { } while (0)
#endif
#endif /* _PINIO_H */