Description
Love the new I2CTarget class, thanks for adding it!
I2CTarget.memaddr specifies the first memory address read/written by the controller, but there is no way to know how many bytes were read/written. This would be a very useful feature for some I2CTarget implementations.
As a slightly contrived example for motivation, suppose I'm creating an I2CTarget that controls multiple stepper motors, and is implemented as a "memory device". Whenever the I2C controller writes a byte to a memory address (or multiple bytes in a single transaction), the corresponding stepper motor(s) moves that many steps. The IRQ implementation would need to wait for a IRQ_END_WRITE event, then look at i2c_target.memaddr and a currently non-existent i2c_target.numbytes (or similar) to know which stepper motors to move.
I suppose this hypothetical device could be implemented as an arbitrary I2C device by handling all the events in the IRQ, instead of as a memory device, so you could count each time the IRQ_WRITE_REQ event occurs until IRQ_END_WRITE occurs. However this would be a lot more Python code, and I have yet to evaluate performance and whether this would result in unnecessary clock stretching (particularly at clock frequencies higher than 100kHz). Clock stretching should really be avoided if possible, it can cause a lot of obscure problems (example, example).
Code Size
IMO this should be required as part of I2CTarget. Can't imagine it would be a huge increase to the code size.
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
Description
Love the new
I2CTargetclass, thanks for adding it!I2CTarget.memaddrspecifies the first memory address read/written by the controller, but there is no way to know how many bytes were read/written. This would be a very useful feature for someI2CTargetimplementations.As a slightly contrived example for motivation, suppose I'm creating an
I2CTargetthat controls multiple stepper motors, and is implemented as a "memory device". Whenever the I2C controller writes a byte to a memory address (or multiple bytes in a single transaction), the corresponding stepper motor(s) moves that many steps. The IRQ implementation would need to wait for aIRQ_END_WRITEevent, then look ati2c_target.memaddrand a currently non-existenti2c_target.numbytes(or similar) to know which stepper motors to move.I suppose this hypothetical device could be implemented as an arbitrary I2C device by handling all the events in the IRQ, instead of as a memory device, so you could count each time the
IRQ_WRITE_REQevent occurs untilIRQ_END_WRITEoccurs. However this would be a lot more Python code, and I have yet to evaluate performance and whether this would result in unnecessary clock stretching (particularly at clock frequencies higher than 100kHz). Clock stretching should really be avoided if possible, it can cause a lot of obscure problems (example, example).Code Size
IMO this should be required as part of
I2CTarget. Can't imagine it would be a huge increase to the code size.Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree