Browse Source

Use fastio for Alligator dac084s085

Scott Lahteine 7 years ago
parent
commit
297666ea14
2 changed files with 44 additions and 57 deletions
  1. 41
    56
      Marlin/src/feature/dac/dac_dac084s085.cpp
  2. 3
    1
      Marlin/src/feature/dac/dac_dac084s085.h

+ 41
- 56
Marlin/src/feature/dac/dac_dac084s085.cpp View File

13
 #include "../../Marlin.h"
13
 #include "../../Marlin.h"
14
 #include "../../module/stepper.h"
14
 #include "../../module/stepper.h"
15
 
15
 
16
-dac084s085::dac084s085() {
17
-  return ;
18
-}
16
+dac084s085::dac084s085() { }
19
 
17
 
20
 void dac084s085::begin() {
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
   // All SPI chip-select HIGH
21
   // All SPI chip-select HIGH
24
-  pinMode(DAC0_SYNC, OUTPUT);
25
-  digitalWrite( DAC0_SYNC , HIGH );
22
+  SET_OUTPUT(DAC0_SYNC);
26
   #if EXTRUDERS > 1
23
   #if EXTRUDERS > 1
27
-    pinMode(DAC1_SYNC, OUTPUT);
28
-    digitalWrite( DAC1_SYNC , HIGH );
24
+    SET_OUTPUT(DAC1_SYNC);
29
   #endif
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
   spiBegin();
27
   spiBegin();
35
 
28
 
36
   //init onboard DAC
29
   //init onboard DAC
37
   delayMicroseconds(2U);
30
   delayMicroseconds(2U);
38
-  digitalWrite( DAC0_SYNC , LOW );
31
+  WRITE(DAC0_SYNC, LOW);
39
   delayMicroseconds(2U);
32
   delayMicroseconds(2U);
40
-  digitalWrite( DAC0_SYNC , HIGH );
33
+  WRITE(DAC0_SYNC, HIGH);
41
   delayMicroseconds(2U);
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
   #if EXTRUDERS > 1
40
   #if EXTRUDERS > 1
48
     //init Piggy DAC
41
     //init Piggy DAC
49
     delayMicroseconds(2U);
42
     delayMicroseconds(2U);
50
-    digitalWrite( DAC1_SYNC , LOW );
43
+    WRITE(DAC1_SYNC, LOW);
51
     delayMicroseconds(2U);
44
     delayMicroseconds(2U);
52
-    digitalWrite( DAC1_SYNC , HIGH );
45
+    WRITE(DAC1_SYNC, HIGH);
53
     delayMicroseconds(2U);
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
   #endif
51
   #endif
59
 
52
 
60
   return;
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
   // All SPI chip-select HIGH
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
     delayMicroseconds(2U);
69
     delayMicroseconds(2U);
92
-    digitalWrite(DAC1_SYNC , HIGH);
70
+    WRITE(DAC1_SYNC, HIGH);
93
     delayMicroseconds(2U);
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
     delayMicroseconds(2U);
76
     delayMicroseconds(2U);
101
-    digitalWrite(DAC0_SYNC , HIGH);
77
+    WRITE(DAC0_SYNC, HIGH);
102
     delayMicroseconds(2U);
78
     delayMicroseconds(2U);
103
-    digitalWrite(DAC0_SYNC , LOW);
79
+    WRITE(DAC0_SYNC, LOW);
104
   }
80
   }
105
 
81
 
106
   delayMicroseconds(2U);
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
 #endif // MB(ALLIGATOR)
97
 #endif // MB(ALLIGATOR)

+ 3
- 1
Marlin/src/feature/dac/dac_dac084s085.h View File

5
   public:
5
   public:
6
     dac084s085();
6
     dac084s085();
7
     static void begin(void);
7
     static void begin(void);
8
-    static void setValue(uint8_t channel, uint8_t value);
8
+    static void setValue(const uint8_t channel, const uint8_t value);
9
+  private:
10
+    static void cshigh();
9
 };
11
 };
10
 
12
 
11
 #endif // DAC084S085_H
13
 #endif // DAC084S085_H

Loading…
Cancel
Save