Skip to content

Provide external-irq functionality directly in Pin class #1118

@dpgeorge

Description

@dpgeorge

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    portsRelates to multiple ports, or a new/proposed portrfcRequest for Comment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions