TMCStepper
TMCStepper copied to clipboard
add callback function to TMC2208/TMC2209
I had a problem using TMCStepper from Marlin where Marlin controls a multiplexer to route the serial line to the appropriate stepper. This is similar in spirit to the SSwitch multiplexing that is used by TMC2208Stepper, except that the pins are not Arduino pins, but are extended pins available only to Marlin. (Specifically, it uses the I2S output of the ESP32 and shift register to generate several more output pins.)
To achieve the appropriate multiplexer switching in preReadCommunication and preWriteCommunication, I have added a callback function. Ordinarily the callback function is null and has no effect, but if a callback function and callback parameters are passed to the constructor, then it invokes the function during preReadCommunication and preWriteCommunication.
The parameters cb_vala
and cb_valb
are opaque to TMCStepper, but the callback function unpacks the values to know which pins and what values need to be assigned to the multiplexer pins.
What are your thoughts on whether this can be merged into the TMCStepper library? Eventually I am hoping the Marlin code that uses the callback can also be merged into the Marlin code, but for that to work, this would be a prerequisite.