What about platforms, that can use several different peripherals on the same pin, like the ESP32 with pretty much anything, or like the PyBoard with timers? How should the peripheral be picked in such cases?tannewt wrote: What has the experience been with the peripheral ID? I know some ports don't have it and it doesn't seem very portable to me. Seems like it'd be better to let the port's implementation match up a hardware peripheral to the given pins where its a different MCU on a board with a standard form factor like Arduino Uno or Adafruit Feather.
Also, if you want to allow that, I think the software I2C should be then moved to a separate class (SoftI2C), so that you don't get a software peripheral just because you picked the wrong pin.
I'm not sure that would work well, because unlike files, i2c peripherals will be often used throughout the whole lifetime of your program. That would lead to some quite mess code, like:tannewt wrote: In addition to close() why not add Context Manager support to match how files and network sockets are used in Python? ContextManagers are super nice because they deinit even when a KeyboardInterrupt happens.
Code: Select all
with machine.I2C(Pin(5), Pin(4)) as i2c:
# All the code of your application
Code: Select all
init_all_peripherals()
try:
# All the code of your application
finally:
deinit_all_peripherals()