Merge pull request #5036 from thinkyhead/rc_dac_code_deps

Fix DAC current code
This commit is contained in:
Scott Lahteine 2016-10-17 16:19:00 -05:00 committed by GitHub
commit f257c4bcae
2 changed files with 9 additions and 8 deletions

View File

@ -31,6 +31,7 @@
*/ */
#include "dac_mcp4728.h" #include "dac_mcp4728.h"
#include "enum.h"
#if ENABLED(DAC_STEPPER_CURRENT) #if ENABLED(DAC_STEPPER_CURRENT)
@ -69,9 +70,9 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
uint8_t mcp4728_eepromWrite() { uint8_t mcp4728_eepromWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS); Wire.beginTransmission(DAC_DEV_ADDRESS);
Wire.write(SEQWRITE); Wire.write(SEQWRITE);
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) { LOOP_XYZE(i) {
Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel])); Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i]));
Wire.write(lowByte(mcp4728_values[channel])); Wire.write(lowByte(mcp4728_values[i]));
} }
return Wire.endTransmission(); return Wire.endTransmission();
} }
@ -119,7 +120,7 @@ uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_va
* Receives all Drive strengths as 0-100 percent values, updates * Receives all Drive strengths as 0-100 percent values, updates
* DAC Values array and calls fastwrite to update the DAC. * DAC Values array and calls fastwrite to update the DAC.
*/ */
void mcp4728_setDrvPct(int16_t pct[XYZE]) { void mcp4728_setDrvPct(uint16_t pct[XYZE]) {
LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX); LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
mcp4728_fastWrite(); mcp4728_fastWrite();
} }
@ -131,9 +132,9 @@ void mcp4728_setDrvPct(int16_t pct[XYZE]) {
*/ */
uint8_t mcp4728_fastWrite() { uint8_t mcp4728_fastWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS); Wire.beginTransmission(DAC_DEV_ADDRESS);
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) { LOOP_XYZE(i) {
Wire.write(highByte(mcp4728_values[channel])); Wire.write(highByte(mcp4728_values[i]));
Wire.write(lowByte(mcp4728_values[channel])); Wire.write(lowByte(mcp4728_values[i]));
} }
return Wire.endTransmission(); return Wire.endTransmission();
} }

View File

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