|
@@ -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
|
}
|