forked from CarlosGS/grblForCyclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathramps.h
149 lines (127 loc) · 3.3 KB
/
ramps.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
/*
* File: ramps.h
* Author: arsi
*
* Created on September 1, 2014, 4:44 PM
*/
#ifndef RAMPS_H
#define RAMPS_H
#ifdef __cplusplus
extern "C" {
#endif
#include"cpu_map.h"
#include<stdint.h>
#include"fastio.h"
#define CHECK(var,pos) ((var) & (1<<(pos)))
extern void rampsInitCoolant();
extern void rampsInitSpindle();
extern void rampsInitSteppers();
extern void rampsWriteDisable(uint8_t value);
extern void rampsWriteSteps(uint8_t value);
extern void rampsWriteDirections(uint8_t value);
extern void rampsStartSpindle();
extern void rampsStopSpindle();
extern void rampsLeftSpindle();
extern void rampsRightSpindle();
extern void rampsCoolantOn();
extern void rampsCoolantOff();
inline void rampsCoolantOn() {
WRITE(COOLANT_FLOOD_PIN, 1);
}
inline void rampsCoolantOff() {
WRITE(COOLANT_FLOOD_PIN, 0);
}
inline void rampsLeftSpindle() {
WRITE(SPINDLE_DIRECTION_PIN, 1);
}
inline void rampsRightSpindle() {
WRITE(SPINDLE_DIRECTION_PIN, 0);
}
inline void rampsStartSpindle() {
WRITE(SPINDLE_ENABLE_PIN, 1);
}
inline void rampsStopSpindle() {
WRITE(SPINDLE_ENABLE_PIN, 0);
}
inline void rampsInitCoolant() {
SET_OUTPUT(COOLANT_FLOOD_PIN);
}
inline void rampsInitSpindle() {
SET_OUTPUT(SPINDLE_ENABLE_PIN);
SET_OUTPUT(SPINDLE_DIRECTION_PIN);
}
/**
* Perform port direction init for ramps for steppers
*/
inline void rampsInitSteppers() {
SET_OUTPUT(X_STEP_PIN);
SET_OUTPUT(Y_STEP_PIN);
SET_OUTPUT(Z_STEP_PIN);
SET_OUTPUT(X_DIR_PIN);
SET_OUTPUT(Y_DIR_PIN);
SET_OUTPUT(Z_DIR_PIN);
SET_OUTPUT(X_ENABLE_PIN);
SET_OUTPUT(Y_ENABLE_PIN);
SET_OUTPUT(Z_ENABLE_PIN);
}
/**
* Perform set of EN driver signal
* @param value
*/
inline void rampsWriteDisable(uint8_t value) {
if (CHECK(value, STEPPERS_DISABLE_BIT)) {
WRITE(X_ENABLE_PIN, 1);
WRITE(Y_ENABLE_PIN, 1);
WRITE(X_ENABLE_PIN, 1);
} else {
WRITE(X_ENABLE_PIN, 0);
WRITE(Y_ENABLE_PIN, 0);
WRITE(X_ENABLE_PIN, 0);
}
}
/**
* write stepper pulse
* @param value
*/
inline void rampsWriteSteps(uint8_t value) {
if (CHECK(value, X_STEP_BIT)) {
WRITE(X_STEP_PIN, 1);
} else {
WRITE(X_STEP_PIN, 0);
}
if (CHECK(value, Y_STEP_BIT)) {
WRITE(Y_STEP_PIN, 1);
} else {
WRITE(Y_STEP_PIN, 0);
}
if (CHECK(value, Z_STEP_BIT)) {
WRITE(Z_STEP_PIN, 1);
} else {
WRITE(Z_STEP_PIN, 0);
}
}
/**
* set stepper direction
* @param value
*/
inline void rampsWriteDirections(uint8_t value) {
if (CHECK(value, X_DIRECTION_BIT)) {
WRITE(X_DIR_PIN, 1);
} else {
WRITE(X_DIR_PIN, 0);
}
if (CHECK(value, Y_DIRECTION_BIT)) {
WRITE(Y_DIR_PIN, 1);
} else {
WRITE(Y_DIR_PIN, 0);
}
if (CHECK(value, Z_DIRECTION_BIT)) {
WRITE(Z_DIR_PIN, 0);
} else {
WRITE(Z_DIR_PIN, 1);
}
}
#ifdef __cplusplus
}
#endif
#endif /* RAMPS_H */