Go to the documentation of this file.
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wunused-function"
7 #pragma GCC diagnostic ignored "-Wunused-variable"
9 #if defined(ARDUINO) && ARDUINO >= 100
16 #if (__cplusplus == 201703L) && defined(__has_include)
17 #define SW_CAPABLE_PLATFORM __has_include(<SoftwareSerial.h>)
19 #define SW_CAPABLE_PLATFORM defined(__AVR__) || defined(TARGET_LPC1768) || defined(ARDUINO_ARCH_STM32)
22 #if SW_CAPABLE_PLATFORM
23 #include <SoftwareSerial.h>
29 #pragma GCC diagnostic pop
39 #define INIT_REGISTER(REG) REG##_t REG##_register = REG##_t
40 #define INIT2130_REGISTER(REG) TMC2130_n::REG##_t REG##_register = TMC2130_n::REG##_t
41 #define INIT2160_REGISTER(REG) TMC2160_n::REG##_t REG##_register = TMC2160_n::REG##_t
42 #define INIT5130_REGISTER(REG) TMC5130_n::REG##_t REG##_register = TMC5130_n::REG##_t
43 #define INIT5160_REGISTER(REG) TMC5160_n::REG##_t REG##_register = TMC5160_n::REG##_t
44 #define INIT2660_REGISTER(REG) TMC2660_n::REG##_t REG##_register = TMC2660_n::REG##_t
45 #define INIT2208_REGISTER(REG) TMC2208_n::REG##_t REG##_register = TMC2208_n::REG##_t
46 #define INIT2224_REGISTER(REG) TMC2224_n::REG##_t REG##_register = TMC2224_n::REG##_t
47 #define SET_ALIAS(TYPE, DRIVER, NEW, ARG, OLD) TYPE (DRIVER::*NEW)(ARG) = &DRIVER::OLD
49 #define TMCSTEPPER_VERSION 0x000602 // v0.6.2
53 uint16_t
cs2rms(uint8_t CS);
72 void GSTAT( uint8_t input);
81 void ihold( uint8_t B);
82 void irun( uint8_t B);
119 virtual void write(uint8_t, uint32_t) = 0;
120 virtual uint32_t
read(uint8_t) = 0;
121 virtual void vsense(
bool) = 0;
122 virtual bool vsense(
void) = 0;
124 virtual void hend(uint8_t) = 0;
125 virtual uint8_t
hend() = 0;
126 virtual void hstrt(uint8_t) = 0;
127 virtual uint8_t
hstrt() = 0;
128 virtual void mres(uint8_t) = 0;
129 virtual uint8_t
mres() = 0;
130 virtual void tbl(uint8_t) = 0;
131 virtual uint8_t
tbl() = 0;
141 TMC2130Stepper(uint16_t pinCS,
float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t
link_index = -1);
155 void GCONF( uint32_t value);
207 void THIGH( uint32_t input);
219 void VDCMIN( uint32_t input);
224 void toff( uint8_t B);
225 void hstrt( uint8_t B);
226 void hend( uint8_t B);
231 void tbl( uint8_t B);
235 void sync( uint8_t B);
236 void mres( uint8_t B);
260 void semin( uint8_t B);
261 void seup( uint8_t B);
262 void semax( uint8_t B);
263 void sedn( uint8_t B);
276 void DCCTRL(uint32_t input);
278 void dc_sg(uint8_t input);
332 void write(uint8_t addressByte, uint32_t config);
333 uint32_t
read(uint8_t addressByte);
364 TMC2160Stepper(uint16_t pinCS,
float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t
link_index = -1);
369 uint16_t
cs2rms(uint8_t CS);
463 TMC5130Stepper(uint16_t pinCS,
float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t
link_index = -1);
582 void VSTART(uint32_t input);
585 void A1(uint16_t input);
588 void V1(uint32_t input);
591 void AMAX(uint16_t input);
594 void VMAX(uint32_t input);
597 void DMAX(uint16_t input);
600 void D1(uint16_t input);
603 void VSTOP(uint32_t input);
614 void X_ENC(int32_t input);
707 TMC5160Stepper(uint16_t pinCS,
float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t
link_index = -1);
808 TMC2208Stepper(Stream * SerialPort,
float RS, uint8_t addr, uint16_t mul_pin1, uint16_t mul_pin2);
812 #if SW_CAPABLE_PLATFORM
813 TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin,
float RS) :
816 TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin,
float RS,
bool) :
825 #if SW_CAPABLE_PLATFORM
833 void GCONF(uint32_t input);
895 void toff(uint8_t B);
896 void hstrt(uint8_t B);
897 void hend(uint8_t B);
900 void mres(uint8_t B);
981 #if SW_CAPABLE_PLATFORM
982 TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin,
float RS, uint8_t addr);
986 #if SW_CAPABLE_PLATFORM
987 SoftwareSerial * SWSerial =
nullptr;
988 const uint16_t RXTX_pin = 0;
993 template<
class SERIAL_TYPE> int16_t
serial_read(SERIAL_TYPE &serPtr) __attribute__((weak));
994 template<
class SERIAL_TYPE> uint8_t
serial_write(SERIAL_TYPE &serPtr,
const uint8_t data) __attribute__((weak));
995 void write(uint8_t, uint32_t);
996 uint32_t
read(uint8_t);
998 uint8_t
calcCRC(uint8_t datagram[], uint8_t len);
1005 template<
typename SERIAL_TYPE>
1006 uint64_t
_sendDatagram(SERIAL_TYPE &, uint8_t [],
const uint8_t, uint16_t);
1014 #if SW_CAPABLE_PLATFORM
1015 TMC2209Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin,
float RS, uint8_t addr) :
1048 void semin(uint8_t B);
1049 void seup(uint8_t B);
1050 void semax(uint8_t B);
1051 void sedn(uint8_t B);
1082 TMC2660Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK);
1083 TMC2660Stepper(uint16_t pinCS,
float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK);
1084 void write(uint8_t addressByte, uint32_t config);
1090 uint16_t
cs2rms(uint8_t CS);
1116 void rdsel(uint8_t);
1152 void hstrt(uint8_t);
1191 void sedn(uint8_t B);
1192 void semax(uint8_t B);
1193 void seup(uint8_t B);
1194 void semin(uint8_t B);
1222 INIT_REGISTER(DRVCTRL_1){{.sr=0}};
1223 INIT_REGISTER(DRVCTRL_0){{.sr=0}};
1224 INIT2660_REGISTER(
CHOPCONF){{.sr=0}};
1225 INIT_REGISTER(
SMARTEN){{.sr=0}};
1227 INIT_REGISTER(
DRVCONF){{.sr=0}};
1228 INIT_REGISTER(READ_RDSEL00){{.sr=0}};
1229 INIT_REGISTER(READ_RDSEL01){{.sr=0}};
1230 INIT_REGISTER(READ_RDSEL10){{.sr=0}};
1232 const uint16_t _pinCS;
1234 static constexpr
float default_RS = 0.1;
1235 float holdMultiplier = 0.5;
1236 uint32_t spi_speed = 16000000/8;
1237 uint8_t _savedToff = 0;
INIT2208_REGISTER(PWMCONF)
static constexpr uint8_t TMC2208_SYNC
INIT_REGISTER(FACTORY_CONF)
void switchCSpin(bool state)
uint8_t hysteresis_start()
TMC5160Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
static constexpr float default_RS
INIT_REGISTER(GLOBAL_SCALER)
TMC2160Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
constexpr static uint8_t address
uint8_t sg_current_decrease()
INIT_REGISTER(TPOWERDOWN)
constexpr static uint8_t address
static constexpr uint8_t replyDelay
TMC5130Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
INIT2208_REGISTER(CHOPCONF)
void diag1_poscomp_pushpull(bool B)
TMC2209_n::COOLCONF_t COOLCONF_register
TMC2208Stepper(Stream *SerialPort, float RS, uint8_t addr, uint16_t mul_pin1, uint16_t mul_pin2)
TMC2130Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
bool diag1_steps_skipped()
void stop_l_enable(bool B)
static uint32_t spi_speed
virtual uint32_t read(uint8_t)=0
void rms_current(uint16_t mA, float mult)
constexpr static uint8_t address
constexpr static uint8_t address
static int8_t chain_length
virtual uint8_t hstrt()=0
void beginSerial(uint32_t)=delete
INIT2208_REGISTER(VACTUAL)
void switchCSpin(bool state)
void rms_current(uint16_t mA, float mult)
static constexpr uint8_t TMC_READ
uint16_t cs2rms(uint8_t CS)
constexpr static uint8_t address
uint32_t read(uint8_t addressByte)
virtual void write(uint8_t, uint32_t)=0
INIT_REGISTER(SHORT_CONF)
static constexpr uint8_t max_retries
static constexpr uint8_t TMC_WRITE
void hold_multiplier(float val)
uint8_t test_connection()
TMC5161Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index=-1)
uint8_t calcCRC(uint8_t datagram[], uint8_t len)
constexpr static uint8_t address
uint16_t pwm_scale_auto()
virtual bool vsense(void)=0
constexpr static uint8_t address
static constexpr uint8_t TMC2208_SLAVE_ADDR
static constexpr float default_RS
uint16_t cs2rms(uint8_t CS)
void setSPISpeed(uint32_t speed)
bool diag0_int_pushpull()
constexpr static uint8_t address
void write(uint8_t addressByte, uint32_t config)
TMC5161Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
void write(uint8_t, uint32_t)
constexpr static uint8_t address
INIT_REGISTER(IHOLD_IRUN)
INIT_REGISTER(ENC_DEVIATION)
constexpr static uint8_t address
TMC5161Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index=-1)
constexpr static uint8_t address
constexpr static uint8_t address
TMC2660Stepper(uint16_t pinCS, float RS=default_RS)
constexpr static uint8_t address
void rms_current(uint16_t mA)
static constexpr float default_RS
void rms_current(uint16_t mA)
virtual uint32_t DRV_STATUS()=0
static constexpr float default_RS
const uint8_t slave_address
void write(uint8_t addressByte, uint32_t config)
uint16_t cs2rms(uint8_t CS)
uint64_t _sendDatagram(SERIAL_TYPE &, uint8_t[], const uint8_t, uint16_t)
int16_t serial_read(SERIAL_TYPE &serPtr) __attribute__((weak))
constexpr static uint8_t address
uint8_t test_connection()
INIT2160_REGISTER(PWMCONF)
bool diag1_poscomp_pushpull()
constexpr static uint8_t address
constexpr static uint8_t address
uint8_t hysteresis_start()
uint8_t serial_write(SERIAL_TYPE &serPtr, const uint8_t data) __attribute__((weak))
void OTP_PROG(uint16_t input)
static constexpr uint8_t abort_window
TMC2208Stepper(Stream *SerialPort, float RS)
TMC2209Stepper(Stream *SerialPort, float RS, uint8_t addr)
TMC2209_n::SGTHRS_t SGTHRS_register