add callback function to TMC2208/TMC2209 #291
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andcb_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.