I happen to be working with a Pico image. Was looking for a way to release or clean up Pin allocation? For example in Pi OS, GPIO.cleanup(). But for (machine.)Pin, no method?
>>> from machine import Pin
>>> dir(Pin)
['__class__', '__name__', 'value', '__bases__', '__dict__', 'ALT', 'IN', 'IRQ_FALLING', 'IRQ_RISING', 'OPEN_DRAIN', 'OUT', 'PULL_DOWN', 'PULL_UP', 'high', 'init', 'irq', 'low', 'off', 'on', 'toggle']
Was expecting, maybe, 'deinit'?
Release (machine.)Pin resources?
Re: Release (machine.)Pin resources?
With MicroPython, that's left up to you. Since pins aren't guaranteed to be initialized in a known state on powerup, it might be hard to know what state to leave them in.
-
- Posts: 144
- Joined: Mon Jul 25, 2022 9:45 pm
Re: Release (machine.)Pin resources?
Yeah, I guess a reasonable compromise is to always leave a given pin something consistent, maybe Pin.OUT, 0. But I was also thinking of releasing the resources of the actual Pin object, but that should or could be handled via object variable set to None, then call gc.collect(), right?
Re: Release (machine.)Pin resources?
On most ports (including rp2) the pins are statically allocated in RAM and do not live in the heap, there's nothing to free. (See the table at the top of rp2/machine_pin.c)
-
- Posts: 144
- Joined: Mon Jul 25, 2022 9:45 pm
Re: Release (machine.)Pin resources?
Ah, good to know, if a bit of bummer.