micropython
micropython copied to clipboard
Add support for interrupts
-
Interrupts are working normally. Only IRQ types IRQ_RISING (2), IRQ_FALLING (3) and IRQ_RISING_FALLING (4) are working, IRQ_HIGH and IRQ_LOW in my tests halts the module and it stops working until reset. Did not test if it is counting the interrupts correctly, but seems right.
-
Also added on() and off() to Pin.
I didn't added an code example because I didn't really understood how the numbering there works. But could be as follow:
from machine import Pin
from utime import sleep_ms
def callback(self):
global irq_count
irq_count = irq_count + 1
def callback_arg(n):
global irq_count
irq_count = irq_count + 1
print(n + irq_count)
irq_count = 0
pirq = Pin(2, Pin.INT, Pin.PULL_UP)
irq = pirq.irq(trigger=Pin.IRQ_FALLING, handler=callback, debounce=200)
# irq = pirq.irq(trigger=3, handler=callback_arg, debounce=50, handler_arg=n)
while True:
print(irq_count)
sleep_ms(2000)
I think that there is a possible deadlock. mp_sched_schedule enters SYS_EnterCriticalSection internally. And if you try to reenter there from the interrupt handler it will hang up the board.
So, interrupts have to be disabled when code enters critical section (as in other ports). I will try to investigate SYS_EnterCriticalSection behavior with ghidra :-) or you should make some experiments.
Hi! Are there any news regarding if IRQ_HIGH and IRQ_LOW might be available anytime soon??
It would be great to be able to use them on the A9G.
I'm going to look at interrupts in February :)
That would be great! Interrupts are awesome and it would be great to be able to use them on the A9G.
I've been trying to compile @arlucio micropython with interrupts version but I keep getting an error when doing make.
I did make -C mpy-cross
in the main directory and then make
in ports/gprs_a9g and tried with Ubuntu and Parrot OS (both updated) but I keep getting the following error:
machine_pin.c:436: error: ‘machine_pin_irq_locals_dict’ undeclared here (not in a function)
make: *** [../../py/mkrules.mk:63: build/machine_pin.o] Error 1
Is there something I'm doing wrong ?
I've fixed that issue in my fork https://github.com/bokolob/micropython/tree/interrupts