This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/feature/dac/dac_dac084s085.cpp

98 lines
2.2 KiB
C++
Raw Normal View History

/***************************************************************
*
* External DAC for Alligator Board
*
****************************************************************/
2017-09-06 13:28:32 +02:00
#include "../../inc/MarlinConfig.h"
2017-09-06 13:28:32 +02:00
#if MB(ALLIGATOR)
2017-09-06 13:28:32 +02:00
#include "dac_dac084s085.h"
#include "../../Marlin.h"
#include "../../module/stepper.h"
2017-11-06 02:13:40 +01:00
dac084s085::dac084s085() { }
2017-09-06 13:28:32 +02:00
void dac084s085::begin() {
2017-11-06 02:13:40 +01:00
uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off
2017-09-06 13:28:32 +02:00
// All SPI chip-select HIGH
2017-11-06 02:13:40 +01:00
SET_OUTPUT(DAC0_SYNC);
2017-09-06 13:28:32 +02:00
#if EXTRUDERS > 1
2017-11-06 02:13:40 +01:00
SET_OUTPUT(DAC1_SYNC);
2017-09-06 13:28:32 +02:00
#endif
2017-11-06 02:13:40 +01:00
cshigh();
2017-09-06 13:28:32 +02:00
spiBegin();
//init onboard DAC
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC0_SYNC, LOW);
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC0_SYNC, HIGH);
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC0_SYNC, LOW);
2017-09-06 13:28:32 +02:00
2017-11-06 02:13:40 +01:00
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
WRITE(DAC0_SYNC, HIGH);
2017-09-06 13:28:32 +02:00
#if EXTRUDERS > 1
//init Piggy DAC
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC1_SYNC, LOW);
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC1_SYNC, HIGH);
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC1_SYNC, LOW);
2017-11-06 02:13:40 +01:00
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
WRITE(DAC1_SYNC, HIGH);
2017-09-06 13:28:32 +02:00
#endif
2017-09-06 13:28:32 +02:00
return;
}
2017-11-06 02:13:40 +01:00
void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
if (channel >= 7) return; // max channel (X,Y,Z,E0,E1,E2,E3)
2017-09-06 13:28:32 +02:00
2017-11-06 02:13:40 +01:00
const uint8_t externalDac_buf[] = {
0x10 | ((channel > 3 ? 7 : 3) - channel << 6) | (value >> 4),
0x00 | (value << 4)
};
2017-09-27 11:57:14 +02:00
2017-09-06 13:28:32 +02:00
// All SPI chip-select HIGH
2017-11-06 02:13:40 +01:00
cshigh();
2017-09-06 13:28:32 +02:00
2017-11-06 02:13:40 +01:00
if (channel > 3) { // DAC Piggy E1,E2,E3
WRITE(DAC1_SYNC, LOW);
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC1_SYNC, HIGH);
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC1_SYNC, LOW);
}
2017-11-06 02:13:40 +01:00
else { // DAC onboard X,Y,Z,E0
WRITE(DAC0_SYNC, LOW);
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC0_SYNC, HIGH);
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
WRITE(DAC0_SYNC, LOW);
}
2017-09-06 13:28:32 +02:00
delayMicroseconds(2U);
2017-11-06 02:13:40 +01:00
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
}
2017-09-06 13:28:32 +02:00
2017-11-06 02:13:40 +01:00
void dac084s085::cshigh() {
WRITE(DAC0_SYNC, HIGH);
#if EXTRUDERS > 1
WRITE(DAC1_SYNC, HIGH);
#endif
WRITE(SPI_EEPROM1_CS, HIGH);
WRITE(SPI_EEPROM2_CS, HIGH);
WRITE(SPI_FLASH_CS, HIGH);
WRITE(SS_PIN, HIGH);
2017-09-06 13:28:32 +02:00
}
#endif // MB(ALLIGATOR)