← index #7831Issue #1118
Related · high · value 2.281
QUERY · ISSUE

ESP8266 Pin Get Physical Address

openby PsuFanopened 2021-09-21updated 2022-03-30
port-esp8266

Is there a way to get the physical address of a pin class? For example a IRQ pin handler, determine which pin has tripped?

from machine import Pin

def handle(p):
	print(int(str(p)[4:-1])) # Better way to get pin number 5?

pin = Pin(5, Pin.IN, Pin.PULL_UP)
pin.irq(trigger=Pin.IRQ_FALLING, handler=handle)
CANDIDATE · ISSUE

Provide external-irq functionality directly in Pin class

closedby dpgeorgeopened 2015-02-14updated 2018-01-28
rfcports

Now that we have a few ports to different MCUs, we can start to see some ways of making the functionality in the pyb module more MCU agnostic / more general. Eg see issue #1085.

I'd like to propose that the bulk of the ExtInt functionality be incorporated into the Pin class. In a general MCU a Pin object can generate an interrupt when the level changes. The pyboard supports this feature in a bit of a round-about way using ExtInt to configure the level changing external interrupt on a pin. This way of doing things does not map easily to the cc3200 or esp8266 ports, where it would make more sense to register the irq directly with a Pin object.

From a users point of view, I think being able to configure a pin directly for irq on level change is much easier that having to create a separate ExtInt object. Eg, new scheme would provide something like:

pin = Pin('X1', Pin.IN, Pin.PULL_DOWN)
pin.callback(pin.IRQ_RISING, lambda p: print("level change on pin:", p))

and/or you can set it in the init function directly:

pin = Pin('X1', Pin.IN, Pin.PULL_DOWN, callback=(Pin.IRQ_RISING, callback_fun))
pin.init(Pin.IN, Pin.PULL_UP, callback=(Pin.IRQ_FALLING, callback_fun))

Could also provide aux control such as pin.trigger_callback for software irq trigger, pin.disable_callback and pin.enable_callback.

Main benefits are:

  • conceptually simpler for end user
  • easier to map to other MCUs (cases in point: cc3200 and esp8266)

The stmhal port can still provide ExtInt for finer control, but this will be mostly unnecessary I think. It has support for non-pin irqs (eg RTC alarm), but actually this is not working properly and when I've been trying to implement proper RTC wakeup, I've anyway needed to rewrite specific ext-int support. Also, the fact that ExtInt actually calls HAL_GPIO to configure the irq means that it's much more suited to be part of the Pin class.

Any thoughts? Any suggestions for the API to setup and control the pin irq?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied