Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/TMC2208Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class TMC2208Stepper {
Stream * HWSerial = NULL;
#if SW_CAPABLE_PLATFORM
SoftwareSerial * SWSerial = NULL;
bool uses_sw_serial;
#else
constexpr static bool uses_sw_serial = false;
#endif
void sendDatagram(uint8_t addr, uint32_t regVal, uint8_t len=7);
bool sendDatagram(uint8_t addr, uint32_t *data, uint8_t len=3);
Expand All @@ -239,7 +242,6 @@ class TMC2208Stepper {
tmp_sr = 0x00000000UL;

bool write_only;
bool uses_sw_serial;
uint16_t mA_val = 0;
};

Expand Down
32 changes: 21 additions & 11 deletions src/source/TMC2208Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//TMC2208Stepper::TMC2208Stepper(HardwareSerial& SR) : TMC_SERIAL(SR) {}
TMC2208Stepper::TMC2208Stepper(Stream * SerialPort, bool has_rx) {
write_only = !has_rx;
uses_sw_serial = false;
#if SW_CAPABLE_PLATFORM
uses_sw_serial = false;
#endif
HWSerial = SerialPort;
}
/*
Expand All @@ -16,7 +18,9 @@ TMC2208Stepper::TMC2208Stepper(HardwareSerial &SerialPort, bool has_rx) {
SerialObject = &SerialPort;
}
*/
#ifdef SW_CAPABLE_PLATFORM

#if SW_CAPABLE_PLATFORM

TMC2208Stepper::TMC2208Stepper(int16_t SW_RX_pin, int16_t SW_TX_pin, bool has_rx) {
write_only = !has_rx;
uses_sw_serial = true;
Expand All @@ -28,7 +32,8 @@ TMC2208Stepper::TMC2208Stepper(HardwareSerial &SerialPort, bool has_rx) {
if (uses_sw_serial) SWSerial->begin(baudrate);
//else static_cast<HardwareSerial*>(SerialObject)->begin(baudrate);
}
#endif

#endif // SW_CAPABLE_PLATFORM

/*
Requested current = mA = I_rms/1000
Expand Down Expand Up @@ -177,15 +182,18 @@ void TMC2208Stepper::sendDatagram(uint8_t addr, uint32_t regVal, uint8_t len) {
datagram[len] = calcCRC(datagram, len);

if (uses_sw_serial) {
#ifdef SW_CAPABLE_PLATFORM
for(int i=0; i<=len; i++){

#if SW_CAPABLE_PLATFORM

for(int i=0; i<=len; i++)
bytesWritten += SWSerial->write(datagram[i]);
}

#endif
} else {
for(int i=0; i<=len; i++){

}
else {
for(int i=0; i<=len; i++)
bytesWritten += HWSerial->write(datagram[i]);
}
}
delay(replyDelay);
}
Expand Down Expand Up @@ -214,10 +222,12 @@ bool TMC2208Stepper::sendDatagram(uint8_t addr, uint32_t *data, uint8_t len) {
uint64_t out = 0x00000000UL;

if (uses_sw_serial) {
#ifdef SW_CAPABLE_PLATFORM

#if SW_CAPABLE_PLATFORM
SWSerial->listen();
out = _sendDatagram(*SWSerial, datagram, len, replyDelay);
#endif

} else {
out = _sendDatagram(*HWSerial, datagram, len, replyDelay);
}
Expand Down Expand Up @@ -399,4 +409,4 @@ int16_t TMC2208Stepper::pwm_scale_auto() {
int16_t response = (d>>PWM_SCALE_AUTO_bp)&0xFF;
if (((d&PWM_SCALE_AUTO_bm) >> 24) & 0x1) return -response;
else return response;
}
}
1 change: 0 additions & 1 deletion src/source/TMC2208Stepper_PWMCONF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ bool TMC2208Stepper::pwm_autograd() { GET_BYTE(PWMCONF, PWM_AUTOGRAD); }
uint8_t TMC2208Stepper::freewheel() { GET_BYTE(PWMCONF, FREEWHEEL); }
uint8_t TMC2208Stepper::pwm_reg() { GET_BYTE(PWMCONF, PWM_REG); }
uint8_t TMC2208Stepper::pwm_lim() { GET_BYTE(PWMCONF, PWM_LIM); }