Skip to content

Commit feea477

Browse files
authored
simplify UART handler, require Micropython version >=1.26 (#166)
1 parent 29575ac commit feea477

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

devices/uart_handler.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from pyControl.hardware import IO_object, assign_ID, interrupt_queue, fw, sm
23

34

@@ -6,31 +7,20 @@ class UART_handler(IO_object):
67
This class is used to generate a framework event when a UART message is received.
78
"""
89

9-
def __init__(self, event_name, mcu="STM32_F4"):
10+
def __init__(self, event_name):
11+
major, minor, *_ = sys.implementation.version
12+
assert (major > 1) or (major == 1 and minor >= 26), "UART_handler requires MicroPython version >= 1.26"
13+
1014
self.event_name = event_name
11-
self.last_interrupt_time = 0
12-
self.mcu = mcu
13-
if self.mcu == "STM32_F4":
14-
self.accept_interrupt = True
1515
assign_ID(self)
1616

1717
def _initialise(self):
1818
self.event_ID = sm.events[self.event_name] if self.event_name in sm.events else False
1919

2020
def ISR(self, _):
2121
if self.event_ID:
22-
# - pyboard v1.1 (and other STM32F4 boards): IRQ_RXIDLE interrupt is triggered after the first character
23-
# AND at the end when the RX is idle.
24-
# - pyboard D-series board (STM32F7): IRQ_RXIDLE interrupt is triggered ONLY at the end when the RX is idle
25-
# - see Micropytyhon UART docs for more info: https://docs.micropython.org/en/latest/library/machine.UART.html
26-
if self.mcu == "STM32_F4": # respond to every other interrupt when using pyboard v1.1
27-
if self.accept_interrupt:
28-
self.timestamp = fw.current_time
29-
interrupt_queue.put(self.ID)
30-
self.accept_interrupt = not self.accept_interrupt
31-
elif self.mcu == "STM32_F7": # respond to every interrupt when using pyboard D-series
32-
self.timestamp = fw.current_time
33-
interrupt_queue.put(self.ID)
22+
self.timestamp = fw.current_time
23+
interrupt_queue.put(self.ID)
3424

3525
def _process_interrupt(self):
3626
fw.event_queue.put(fw.Datatuple(self.timestamp, fw.EVENT_TYP, "i", self.event_ID))

0 commit comments

Comments
 (0)