Browse Source

Merge pull request #5036 from thinkyhead/rc_dac_code_deps

Fix DAC current code
Scott Lahteine 8 years ago
parent
commit
f257c4bcae
2 changed files with 9 additions and 8 deletions
  1. 8
    7
      Marlin/dac_mcp4728.cpp
  2. 1
    1
      Marlin/dac_mcp4728.h

+ 8
- 7
Marlin/dac_mcp4728.cpp View File

@@ -31,6 +31,7 @@
31 31
  */
32 32
 
33 33
 #include "dac_mcp4728.h"
34
+#include "enum.h"
34 35
 
35 36
 #if ENABLED(DAC_STEPPER_CURRENT)
36 37
 
@@ -69,9 +70,9 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
69 70
 uint8_t mcp4728_eepromWrite() {
70 71
   Wire.beginTransmission(DAC_DEV_ADDRESS);
71 72
   Wire.write(SEQWRITE);
72
-  for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
73
-    Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
74
-    Wire.write(lowByte(mcp4728_values[channel]));
73
+  LOOP_XYZE(i) {
74
+    Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i]));
75
+    Wire.write(lowByte(mcp4728_values[i]));
75 76
   }
76 77
   return Wire.endTransmission();
77 78
 }
@@ -119,7 +120,7 @@ uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_va
119 120
  * Receives all Drive strengths as 0-100 percent values, updates
120 121
  * DAC Values array and calls fastwrite to update the DAC.
121 122
  */
122
-void mcp4728_setDrvPct(int16_t pct[XYZE]) {
123
+void mcp4728_setDrvPct(uint16_t pct[XYZE]) {
123 124
   LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
124 125
   mcp4728_fastWrite();
125 126
 }
@@ -131,9 +132,9 @@ void mcp4728_setDrvPct(int16_t pct[XYZE]) {
131 132
  */
132 133
 uint8_t mcp4728_fastWrite() {
133 134
   Wire.beginTransmission(DAC_DEV_ADDRESS);
134
-  for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
135
-    Wire.write(highByte(mcp4728_values[channel]));
136
-    Wire.write(lowByte(mcp4728_values[channel]));
135
+  LOOP_XYZE(i) {
136
+    Wire.write(highByte(mcp4728_values[i]));
137
+    Wire.write(lowByte(mcp4728_values[i]));
137 138
   }
138 139
   return Wire.endTransmission();
139 140
 }

+ 1
- 1
Marlin/dac_mcp4728.h View File

@@ -60,7 +60,7 @@ uint16_t mcp4728_getValue(uint8_t channel);
60 60
 uint8_t mcp4728_fastWrite();
61 61
 uint8_t mcp4728_simpleCommand(byte simpleCommand);
62 62
 uint16_t mcp4728_getDrvPct(uint8_t channel);
63
-void mcp4728_setDrvPct(int16_t pct[XYZE]);
63
+void mcp4728_setDrvPct(uint16_t pct[XYZE]);
64 64
 
65 65
 #endif
66 66
 #endif // DAC_MCP4728_H

Loading…
Cancel
Save