Wykres commitów

6 Commity (392d75b00dcaf339af1116fa0fb7e1668addd605)

Autor SHA1 Wiadomość Data
Phil Howard 1b3d9d9fb2 Pimoroni I2C: Update to use modmachine.h consolidated header. 2024-01-08 10:15:28 +00:00
Phil Howard 9bf1583787 MicroPython: Change machine_hw_i2c_type to machine_i2c_type. 2023-01-11 09:46:45 +00:00
Phil Howard 1feefde00c MicroPython: Promote machine.I2C() to PimoroniI2C.
Create a new PimoroniI2C object internally if a "machine.I2C()" object is supplied in constructors.
2022-05-18 13:20:33 +01:00
Phil Howard 7d3b48c509 MicroPython: Make Pimoroni I2C compatible with machine.I2C 2022-05-18 13:15:12 +01:00
Phil Howard edf77ddb76 Add finaliser for Pimoroni I2C
This is the final piece of the puzzle.

Prior to this rather considerable change, Pimoroni breakouts were not de-init'ing I2C when they failed to init()

This change adds a __del__ method which cleans up the I2C instance attached to a MicroPython object.

Under the hood this calls i2c_deinit() and resets the associated pins to their default state.

This means that I2C is now cleaned up during a *soft* reset, so running a script with the wrong pins, seeing an error,
changing the pins and running it again will not result in subsequent I2C errors. Previously a hard reset was required.

To recreate on Breakout Garden run the following code:

```
from breakout_potentiometer import BreakoutPotentiometer
from pimoroni_i2c import PimoroniI2C

i2c = PimoroniI2C()
pot = BreakoutPotentiometer(i2c)
```

This will fail correctly with "Potentiometer breakout not found when initialising."
(The default pins are configured for Pico Explorer)

Now change that to the following and run again without hard-resetting:

```
from breakout_potentiometer import BreakoutPotentiometer
from pimoroni_i2c import PimoroniI2C

i2c = PimoroniI2C(4, 5)
pot = BreakoutPotentiometer(i2c)
```

This should now work, since the failed I2C instance was cleaned up.

Without this change, the second attempt would result in an inexplicable failure.

Since most? (many?) Pico users do not have a reset button, this trap requiring a hard-reset is pretty nasty and would likely have resulted in a support nightmare.

Whew.
2021-05-18 09:48:41 +01:00
Phil Howard b2056040e8 Port Encoder and Potentiometer to Pimoroni I2C
Wraps just enough of Pimoroni I2C to make it work in MicroPython.

Ports Encoder and Potentiometer to use a PimorniI2C() instance in lieu of sda/scl.
2021-05-17 18:09:39 +01:00