I2Cwrapper v0.5.0
Generic framework for Arduino I2C target devices
Todo List
File AccelStepperI2C.h

add emergency stop/break pin for target (just use reset pin for the moment)

ATM data is not protected against updates from ISRs while it is being used in the main program (see http://gammon.com.au/interrupts). Check if this could be a problem in our case.

ESP32: make use of dual cores?

use interrupts for endstops instead of main loop polling (not sure how much of a difference this would make in practice, though. The main loop isn't doing much else, what really takes time are the computations.)

update keywords.txt

clean up example sketches

implement runToPosition() and runToNewPosition() in controller - implemented

test (and adapt) target firmware for ESP8266 - implemented. However, I2C target mode on ESP8266s is no fun. Run only with 160MHz CPU and start testing with 10kHz (that's right: ten kHz) I2C clock speed.

checking each transmission with sentOK and resultOK is tedious. We could use some counter to accumulate errors and check them summarily, e.g. at the end of setup etc. - AccelStepperI2C::sentErrors(), AccelStepperI2C::resultErrors() and AccelStepperI2C::transmissionErrors() added

make time the target has to answer I2C requests (I2CrequestDelay) configurable, as it will depend on µC and bus frequency etc. - setI2Cdelay() implemented

Versioning, I2C command to request version (important, as library and firmware always need to match) - getVersion() and checkVersion() implemented

Implement interrupt mechanism, so that the target can inform the controller about finished tasks or other events - setInterruptPin() and enableInterrupts() implemented

implement diagnostic functions, e.g. measurements how long messages take to be processed or current stepper pulse frequency - done, performance graphs included in documentation

add ESP32 compatibility for target - done, but needs further testing

Make the I2C address programmable and persistent in EEPROM. - done

Error handling and sanity checks are rudimentary. Currently the system is not stable against transmission errors, partly due to the limitations of Wire.requestFrom() and Wire.available(). A better protocol would be needed, which would mean more overhead. Need testing to see how important this is in practics. - CRC8 implemented

Implement end stops/reference stops. - endstop polling implemented, interrupt would be better

Member AccelStepperI2C::enableEndstops (bool enable=true)
Find solution for moving a stepper out of an endstop's zone. implemented debounce and active-flank detection so that there's no danger of repeated interrupts being triggered while in an endstop's active zone.
File ESP32sensorsI2C_firmware.h
touchAttachInterruptArg() is available since May 2022 with esp32 release 2.0.3. Implement it for a much easier and cleaner solution. Also implement touchInterruptSetThresholdDirection() Also adapt for SOC_TOUCH_SENSOR_NUM no. of sensors (I think newer ESP32 variants have more than 10)
File firmware.ino

make I2C address configurable by hardware (with module?)

return messages (results) should ideally come with an id, too, so that controller can be sure it's the correct result. Currently only CRC8, i.e. correct transmission is checked.

volatile variables / ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {}

Reduce memory use to make it fit into an 8k Attiny4k ATtiny

File I2Cwrapper.h
Enhance diagnostics with a self-diagnosing function to determine the optimal/minimal I2Cdelay in a given controller-target setup.
Class PinI2C
Only tested on AVRs.
File PinI2C.h
implement interrupts?
File ServoI2C_firmware.h
Need to typecast the transmission of int values to int16_t.
File TM1638liteI2C_firmware.h
Implement interrupt mechanism for button presses like ESP32sensors.