diff --git a/src/TMC2208Stepper.h b/src/TMC2208Stepper.h index 7bc6442..e1c57ec 100644 --- a/src/TMC2208Stepper.h +++ b/src/TMC2208Stepper.h @@ -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); @@ -239,7 +242,6 @@ class TMC2208Stepper { tmp_sr = 0x00000000UL; bool write_only; - bool uses_sw_serial; uint16_t mA_val = 0; }; diff --git a/src/source/TMC2208Stepper.cpp b/src/source/TMC2208Stepper.cpp index d2dfe5c..c89d400 100644 --- a/src/source/TMC2208Stepper.cpp +++ b/src/source/TMC2208Stepper.cpp @@ -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; } /* @@ -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; @@ -28,7 +32,8 @@ TMC2208Stepper::TMC2208Stepper(HardwareSerial &SerialPort, bool has_rx) { if (uses_sw_serial) SWSerial->begin(baudrate); //else static_cast(SerialObject)->begin(baudrate); } -#endif + +#endif // SW_CAPABLE_PLATFORM /* Requested current = mA = I_rms/1000 @@ -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); } @@ -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); } @@ -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; -} \ No newline at end of file +} diff --git a/src/source/TMC2208Stepper_PWMCONF.cpp b/src/source/TMC2208Stepper_PWMCONF.cpp index acc722a..225d77a 100644 --- a/src/source/TMC2208Stepper_PWMCONF.cpp +++ b/src/source/TMC2208Stepper_PWMCONF.cpp @@ -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); } -