Replies: 2 comments 4 replies
-
I think |
Beta Was this translation helpful? Give feedback.
1 reply
-
I don't think this ha ever been requested before. I guess people have worked round this in the ISR: def my_irq_callback(_):
if my_irq_enabled: # Global
# handle interrupt |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Premise
A feature which I've always been surprised to see missing in the Micropython
machine.Pin
andmachine.Timer
libraries is the ability to enable and disable an IRQ which has been created, without having to specify the callback handler and trigger conditions/timer period again.As far as I'm aware, at the moment, the only way to disable a
Timer
object is to calldeinit()
, which gets rid of the previously specifiedmode
,period
andcallback
parameters, meaning that an instantiated Timer object can't simply have its underlying interrupt enabled/disabled, without having to re-specify those parameters when enabling it again.It's a somewhat similar story with
Pin.irq
as far as I can tell - here, one has to callPin.irq(trigger=0)
to disable a pin interrupt, meaning that if you want the Pin interrupt to function again, you have to supply thehandler
andtrigger
parameters again.This feels rather clumsy and somewhat limiting in my opinion, as any time Part Y of a program wants to enable/disable interrupts that were initialized by Part X - in response to some particular event, for example - it will have to know the original parameters that Part X supplied - which does feel a little clumsy to me, if I'm honest.
Suggestion
An interface to enable/disable interrupts using the
machine.Pin.irq()
/machine.Timer
objects directly: e.gA common implementation between Timers and Pin Interrupts might be especially useful, as it could possibly allow the same code to be reused whether the interrupt in question is triggered externally or according to a periodic count.
Implementation
As I've been primarily been using the Pico 2 as my MP development platform, I thought I'd try to explore the feasibility of implementing this feature for
machine.Pin
on therp2
port, as a test case. Consulting the Pico C SDK, thegpio_set_irq_enabled
function looked promising, through which I was able to come up with a working implementation which can be found here.Pin interrupts can be created as usual,
Calling
irq().enabled()
without any arguments returns the state of the interrupt (whether it is enabled or not); supplyingTrue
as an argument will enable it,False
disables it:This was tested using v1.24.0, but I don't think there should be any problems using it on v1.25.0.
Question
Does this feature seem useful to anyone else? The fact that it hadn't already been implemented has me wondering whether there's a particular reason not to do so...am I missing anything?
Beta Was this translation helpful? Give feedback.
All reactions