aboutsummaryrefslogtreecommitdiff
path: root/Marlin/src/feature/dac/dac_dac084s085.cpp
diff options
context:
space:
mode:
authorGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
committerGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
commite8701195e66f2d27ffe17fb514eae8173795aaf7 (patch)
tree9f519c4abf6556b9ae7190a6210d87ead1dfadde /Marlin/src/feature/dac/dac_dac084s085.cpp
downloadkp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz
kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip
Initial commit
Diffstat (limited to 'Marlin/src/feature/dac/dac_dac084s085.cpp')
-rw-r--r--Marlin/src/feature/dac/dac_dac084s085.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/Marlin/src/feature/dac/dac_dac084s085.cpp b/Marlin/src/feature/dac/dac_dac084s085.cpp
new file mode 100644
index 0000000..649aa55
--- /dev/null
+++ b/Marlin/src/feature/dac/dac_dac084s085.cpp
@@ -0,0 +1,98 @@
+/***************************************************************
+ *
+ * External DAC for Alligator Board
+ *
+ ****************************************************************/
+
+#include "../../inc/MarlinConfig.h"
+
+#if MB(ALLIGATOR)
+
+#include "dac_dac084s085.h"
+
+#include "../../MarlinCore.h"
+#include "../../module/stepper.h"
+#include "../../HAL/shared/Delay.h"
+
+dac084s085::dac084s085() { }
+
+void dac084s085::begin() {
+ uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off
+
+ // All SPI chip-select HIGH
+ SET_OUTPUT(DAC0_SYNC);
+ #if HAS_MULTI_EXTRUDER
+ SET_OUTPUT(DAC1_SYNC);
+ #endif
+ cshigh();
+ spiBegin();
+
+ //init onboard DAC
+ DELAY_US(2);
+ WRITE(DAC0_SYNC, LOW);
+ DELAY_US(2);
+ WRITE(DAC0_SYNC, HIGH);
+ DELAY_US(2);
+ WRITE(DAC0_SYNC, LOW);
+
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
+ WRITE(DAC0_SYNC, HIGH);
+
+ #if HAS_MULTI_EXTRUDER
+ //init Piggy DAC
+ DELAY_US(2);
+ WRITE(DAC1_SYNC, LOW);
+ DELAY_US(2);
+ WRITE(DAC1_SYNC, HIGH);
+ DELAY_US(2);
+ WRITE(DAC1_SYNC, LOW);
+
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
+ WRITE(DAC1_SYNC, HIGH);
+ #endif
+
+ return;
+}
+
+void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
+ if (channel >= 7) return; // max channel (X,Y,Z,E0,E1,E2,E3)
+
+ const uint8_t externalDac_buf[] = {
+ 0x10 | ((channel > 3 ? 7 : 3) - channel << 6) | (value >> 4),
+ 0x00 | (value << 4)
+ };
+
+ // All SPI chip-select HIGH
+ cshigh();
+
+ if (channel > 3) { // DAC Piggy E1,E2,E3
+ WRITE(DAC1_SYNC, LOW);
+ DELAY_US(2);
+ WRITE(DAC1_SYNC, HIGH);
+ DELAY_US(2);
+ WRITE(DAC1_SYNC, LOW);
+ }
+ else { // DAC onboard X,Y,Z,E0
+ WRITE(DAC0_SYNC, LOW);
+ DELAY_US(2);
+ WRITE(DAC0_SYNC, HIGH);
+ DELAY_US(2);
+ WRITE(DAC0_SYNC, LOW);
+ }
+
+ DELAY_US(2);
+ spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
+}
+
+void dac084s085::cshigh() {
+ WRITE(DAC0_SYNC, HIGH);
+ #if HAS_MULTI_EXTRUDER
+ WRITE(DAC1_SYNC, HIGH);
+ #endif
+ WRITE(SPI_EEPROM1_CS, HIGH);
+ WRITE(SPI_EEPROM2_CS, HIGH);
+ WRITE(SPI_FLASH_CS, HIGH);
+ WRITE(SD_SS_PIN, HIGH);
+}
+
+#endif // MB(ALLIGATOR)