{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1118","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1118/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1118/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1118/events","html_url":"https://github.com/micropython/micropython/issues/1118","id":57693494,"number":1118,"title":"Provide external-irq functionality directly in Pin class","user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/micropython/micropython/labels/ports","name":"ports","color":"bfe5bf"},{"url":"https://api.github.com/repos/micropython/micropython/labels/rfc","name":"rfc","color":"FF66CC"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-02-14T13:46:53Z","updated_at":"2015-02-15T19:52:28Z","closed_at":null,"body":"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.\r\n\r\nI'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.\r\n\r\nFrom 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:\r\n```python\r\npin = Pin('X1', Pin.IN, Pin.PULL_DOWN)\r\npin.callback(pin.IRQ_RISING, lambda p: print(\"level change on pin:\", p))\r\n```\r\nand/or you can set it in the init function directly:\r\n```python\r\npin = Pin('X1', Pin.IN, Pin.PULL_DOWN, callback=(Pin.IRQ_RISING, callback_fun))\r\npin.init(Pin.IN, Pin.PULL_UP, callback=(Pin.IRQ_FALLING, callback_fun))\r\n```\r\n\r\nCould also provide aux control such as `pin.trigger_callback` for software irq trigger, `pin.disable_callback` and `pin.enable_callback`.\r\n\r\nMain benefits are:\r\n- conceptually simpler for end user\r\n- easier to map to other MCUs (cases in point: cc3200 and esp8266)\r\n\r\nThe 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.\r\n\r\nAny thoughts?  Any suggestions for the API to setup and control the pin irq?"},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/74433500","html_url":"https://github.com/micropython/micropython/issues/1118#issuecomment-74433500","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1118","id":74433500,"user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"created_at":"2015-02-15T19:52:28Z","updated_at":"2015-02-15T19:52:28Z","body":"> It only couples irq handing for pin change to gpio.\r\n\r\nIn fact, the way the ST HAL library is implemented, EXTI control is actually part of the GPIO module and there is no real way to decouple them in this case."}}