|
@@ -13,100 +13,85 @@
|
13
|
13
|
#include "../../Marlin.h"
|
14
|
14
|
#include "../../module/stepper.h"
|
15
|
15
|
|
16
|
|
-dac084s085::dac084s085() {
|
17
|
|
- return ;
|
18
|
|
-}
|
|
16
|
+dac084s085::dac084s085() { }
|
19
|
17
|
|
20
|
18
|
void dac084s085::begin() {
|
21
|
|
- uint8_t externalDac_buf[2] = {0x20,0x00};//all off
|
|
19
|
+ uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off
|
22
|
20
|
|
23
|
21
|
// All SPI chip-select HIGH
|
24
|
|
- pinMode(DAC0_SYNC, OUTPUT);
|
25
|
|
- digitalWrite( DAC0_SYNC , HIGH );
|
|
22
|
+ SET_OUTPUT(DAC0_SYNC);
|
26
|
23
|
#if EXTRUDERS > 1
|
27
|
|
- pinMode(DAC1_SYNC, OUTPUT);
|
28
|
|
- digitalWrite( DAC1_SYNC , HIGH );
|
|
24
|
+ SET_OUTPUT(DAC1_SYNC);
|
29
|
25
|
#endif
|
30
|
|
- digitalWrite( SPI_EEPROM1_CS , HIGH );
|
31
|
|
- digitalWrite( SPI_EEPROM2_CS , HIGH );
|
32
|
|
- digitalWrite( SPI_FLASH_CS , HIGH );
|
33
|
|
- digitalWrite( SS_PIN , HIGH );
|
|
26
|
+ cshigh();
|
34
|
27
|
spiBegin();
|
35
|
28
|
|
36
|
29
|
//init onboard DAC
|
37
|
30
|
delayMicroseconds(2U);
|
38
|
|
- digitalWrite( DAC0_SYNC , LOW );
|
|
31
|
+ WRITE(DAC0_SYNC, LOW);
|
39
|
32
|
delayMicroseconds(2U);
|
40
|
|
- digitalWrite( DAC0_SYNC , HIGH );
|
|
33
|
+ WRITE(DAC0_SYNC, HIGH);
|
41
|
34
|
delayMicroseconds(2U);
|
42
|
|
- digitalWrite( DAC0_SYNC , LOW );
|
|
35
|
+ WRITE(DAC0_SYNC, LOW);
|
43
|
36
|
|
44
|
|
- spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
45
|
|
- digitalWrite( DAC0_SYNC , HIGH );
|
|
37
|
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
|
|
38
|
+ WRITE(DAC0_SYNC, HIGH);
|
46
|
39
|
|
47
|
40
|
#if EXTRUDERS > 1
|
48
|
41
|
//init Piggy DAC
|
49
|
42
|
delayMicroseconds(2U);
|
50
|
|
- digitalWrite( DAC1_SYNC , LOW );
|
|
43
|
+ WRITE(DAC1_SYNC, LOW);
|
51
|
44
|
delayMicroseconds(2U);
|
52
|
|
- digitalWrite( DAC1_SYNC , HIGH );
|
|
45
|
+ WRITE(DAC1_SYNC, HIGH);
|
53
|
46
|
delayMicroseconds(2U);
|
54
|
|
- digitalWrite( DAC1_SYNC , LOW );
|
|
47
|
+ WRITE(DAC1_SYNC, LOW);
|
55
|
48
|
|
56
|
|
- spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
57
|
|
- digitalWrite( DAC1_SYNC , HIGH );
|
|
49
|
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
|
|
50
|
+ WRITE(DAC1_SYNC, HIGH);
|
58
|
51
|
#endif
|
59
|
52
|
|
60
|
53
|
return;
|
61
|
54
|
}
|
62
|
55
|
|
63
|
|
-void dac084s085::setValue(uint8_t channel, uint8_t value) {
|
64
|
|
- if(channel >= 7) // max channel (X,Y,Z,E0,E1,E2,E3)
|
65
|
|
- return;
|
66
|
|
- if(value > 255) value = 255;
|
67
|
|
-
|
68
|
|
- uint8_t externalDac_buf[2] = {0x10,0x00};
|
69
|
|
-
|
70
|
|
- if(channel > 3)
|
71
|
|
- externalDac_buf[0] |= (7 - channel << 6);
|
72
|
|
- else
|
73
|
|
- externalDac_buf[0] |= (3 - channel << 6);
|
|
56
|
+void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
|
|
57
|
+ if (channel >= 7) return; // max channel (X,Y,Z,E0,E1,E2,E3)
|
74
|
58
|
|
75
|
|
- externalDac_buf[0] |= (value >> 4);
|
76
|
|
- externalDac_buf[1] |= (value << 4);
|
|
59
|
+ const uint8_t externalDac_buf[] = {
|
|
60
|
+ 0x10 | ((channel > 3 ? 7 : 3) - channel << 6) | (value >> 4),
|
|
61
|
+ 0x00 | (value << 4)
|
|
62
|
+ };
|
77
|
63
|
|
78
|
64
|
// All SPI chip-select HIGH
|
79
|
|
- digitalWrite( DAC0_SYNC , HIGH );
|
80
|
|
- #if EXTRUDERS > 1
|
81
|
|
- digitalWrite( DAC1_SYNC , HIGH );
|
82
|
|
- #endif
|
83
|
|
- digitalWrite( SPI_EEPROM1_CS , HIGH );
|
84
|
|
- digitalWrite( SPI_EEPROM2_CS , HIGH );
|
85
|
|
- digitalWrite( SPI_FLASH_CS , HIGH );
|
86
|
|
- digitalWrite( SS_PIN , HIGH );
|
87
|
|
-
|
88
|
|
- if(channel > 3) { // DAC Piggy E1,E2,E3
|
|
65
|
+ cshigh();
|
89
|
66
|
|
90
|
|
- digitalWrite(DAC1_SYNC , LOW);
|
|
67
|
+ if (channel > 3) { // DAC Piggy E1,E2,E3
|
|
68
|
+ WRITE(DAC1_SYNC, LOW);
|
91
|
69
|
delayMicroseconds(2U);
|
92
|
|
- digitalWrite(DAC1_SYNC , HIGH);
|
|
70
|
+ WRITE(DAC1_SYNC, HIGH);
|
93
|
71
|
delayMicroseconds(2U);
|
94
|
|
- digitalWrite(DAC1_SYNC , LOW);
|
|
72
|
+ WRITE(DAC1_SYNC, LOW);
|
95
|
73
|
}
|
96
|
|
-
|
97
|
|
- else { // DAC onboard X,Y,Z,E0
|
98
|
|
-
|
99
|
|
- digitalWrite(DAC0_SYNC , LOW);
|
|
74
|
+ else { // DAC onboard X,Y,Z,E0
|
|
75
|
+ WRITE(DAC0_SYNC, LOW);
|
100
|
76
|
delayMicroseconds(2U);
|
101
|
|
- digitalWrite(DAC0_SYNC , HIGH);
|
|
77
|
+ WRITE(DAC0_SYNC, HIGH);
|
102
|
78
|
delayMicroseconds(2U);
|
103
|
|
- digitalWrite(DAC0_SYNC , LOW);
|
|
79
|
+ WRITE(DAC0_SYNC, LOW);
|
104
|
80
|
}
|
105
|
81
|
|
106
|
82
|
delayMicroseconds(2U);
|
107
|
|
- spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
|
83
|
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
|
|
84
|
+}
|
108
|
85
|
|
109
|
|
- return;
|
|
86
|
+void dac084s085::cshigh() {
|
|
87
|
+ WRITE(DAC0_SYNC, HIGH);
|
|
88
|
+ #if EXTRUDERS > 1
|
|
89
|
+ WRITE(DAC1_SYNC, HIGH);
|
|
90
|
+ #endif
|
|
91
|
+ WRITE(SPI_EEPROM1_CS, HIGH);
|
|
92
|
+ WRITE(SPI_EEPROM2_CS, HIGH);
|
|
93
|
+ WRITE(SPI_FLASH_CS, HIGH);
|
|
94
|
+ WRITE(SS_PIN, HIGH);
|
110
|
95
|
}
|
111
|
96
|
|
112
|
97
|
#endif // MB(ALLIGATOR)
|