- Notifications
You must be signed in to change notification settings - Fork1.3k
i2ctarget: Add deinit() to I2CTargetRequest; remove close()#10366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
17e24b8
to7d3dd30
CompareNeradoc commentedMay 21, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The following test code triggers the issue in 9.2.7 and works as expected with this PR. Controller code (running on a tiny2350) importboardimportrandomimporttimefromadafruit_bus_device.i2c_deviceimportI2CDevicei2c=board.STEMMA_I2C()device=I2CDevice(i2c,0x40)buffer=bytearray(1)whileTrue:try:withdevice:device.readinto(buffer)print(f"device responded with #{buffer[0]:02X}")time.sleep(1)withdevice:buffer[0]=random.randint(0,255)device.write(buffer)print(f"wrote to device: #{buffer[0]:02X}")time.sleep(1)exceptOSError:# target resetting or in errortime.sleep(1) Target code (pro micro 2040) - that's the code being tested. importboardfromi2ctargetimportI2CTargetmemory=0x55withI2CTarget(board.SCL,board.SDA, (0x40,))asdevice:whileTrue:i2c_target_request=device.request()ifnoti2c_target_request:continuewithi2c_target_request:ifi2c_target_request.is_read:print(f"read request: #{memory:02X}")buffer=memory.to_bytes(1)i2c_target_request.write(buffer)else:data=i2c_target_request.read(1)print(f"write request: #{data[0]:02X}")memory=data[0] Could we have the call to |
I considered that, but wasn't sure if there was another use case. But I think not. I'll do that, yes, thanks. |
7306e5e
to8da8e31
Compare
Neradoc left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Runs fine, looks good.
I will open a separate issue to fix the example. |
c6e4d72
intoadafruit:mainUh oh!
There was an error while loading.Please reload this page.
Removes visible
I2CTargetRequest.close()
method. AddsI2CTargetRequest.deinit()
. Doesclose()
anddeinit()
inI2CTargetRequest.__exit__()
. MakesI2CTargetRequest
have a finalizer:__del__()
callsdeinit()
.I tried testing with the more extensive example in the
I2CTarget
documentation, which tries to write and then read a value to an I2C register. It did not work, but I could not get that example to work with 8.2.9 or 9.2.3 either.@Neradoc if you or someone else would like to test this with some previously-working code, I would be grateful.