Closed jfreymuth closed 1 month ago
This is really great @jfreymuth thank you very much for working on it. Please see my comments inline.
Oh yeah, one thing I almost forgot is we need to also add a smoke test for i2c on esp32.
Mostly copied from
machine_esp32c3_i2c.go
, but there are some differences, especially with timeout handling (see line 165).
That's going to increase the maintenance burden. Can you refactor the code so that most/all common code is shared and only the chip-specific things are in the appropriate chip specific files? For example:
machine_esp32xx_i2c.go
for the esp32 and esp32c3 with most of the I2C codemachine_esp32c3_i2c.go
contains the esp32c3 specific bits (for example, constants or functions called from machine_esp32xx_i2c.go)machine_esp32_i2c.go
This is also important because I expect other chips in the ESP32 family to be very similar, they can share code in a similar way.
We have something similar for the nrf chips:
setPins
method because it varies by chipI can try, but I don't have any esp32c3 devices, so I'm not sure how to verify I'm not breaking anything with the refactor
Perhaps we can merge this PR (with a smoketest added, please) and then refactor the i2c implementation as described by @aykevl in a separate PR. I have both boards and am willing to help out with this.
Sounds good to me! (I'm just hoping we won't forget this...)
I'm not sure about the smoketest though: what would be gained from that? We already have a smoketest for the esp32, so any syntax or type errors would already be caught.
I'm not sure about the smoketest though: what would be gained from that? We already have a smoketest for the esp32, so any syntax or type errors would already be caught.
Just to ensure that the i2c parts compile for the esp32
build tag.
In that case I'd suggest adding the ESP32 here: https://github.com/tinygo-org/tinygo/blob/6384ecace093df2d0b93915886954abfc4ecfe01/src/machine/i2c.go#L1
We already have plenty of smoke tests that show the machine package (including I2C) compiles for the ESP32: https://github.com/tinygo-org/tinygo/blob/6384ecace093df2d0b93915886954abfc4ecfe01/GNUmakefile#L751-L764
In that case I'd suggest adding the ESP32 here:
That is in fact in this very PR already! :) In which case I think we can merge now.
Now going to squash/merge. Thank you @jfreymuth for working on this and to @aykevl for review.
Mostly copied from
machine_esp32c3_i2c.go
, but there are some differences, especially with timeout handling (see line 165).Tested on an M5Paper, where I could successfully communicate with multiple devices and recover from errors in a long-running program.