From ef6f87aa891940314cf18b0c5fde65e827ea44d6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 20:36:08 +0000 Subject: [PATCH 1/2] Initial plan From a4e7ebee1771ff372dbba06debdfdd95102721ba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 20:48:44 +0000 Subject: [PATCH 2/2] Add hard parameter to machine.Timer signatures Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com> --- reference/micropython/machine/Timer.pyi | 19 +++++++++++++++++ .../check_machine/check_Timer_hard.py | 21 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/quality_tests/feat_machine/check_machine/check_Timer_hard.py diff --git a/reference/micropython/machine/Timer.pyi b/reference/micropython/machine/Timer.pyi index 8c34d5963..28eb8c574 100644 --- a/reference/micropython/machine/Timer.pyi +++ b/reference/micropython/machine/Timer.pyi @@ -52,6 +52,7 @@ class Timer: mode: int = PERIODIC, period: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ): """ Construct a new timer object of the given ``id``. ``id`` of -1 constructs a @@ -70,6 +71,7 @@ class Timer: mode: int = PERIODIC, freq: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ): """ Construct a new timer object of the given ``id``. ``id`` of -1 constructs a @@ -88,6 +90,7 @@ class Timer: mode: int = PERIODIC, tick_hz: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ): """ Construct a new timer object of the given ``id``. ``id`` of -1 constructs a @@ -104,6 +107,7 @@ class Timer: mode: int = PERIODIC, period: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ) -> None: ... @overload def init( @@ -112,6 +116,7 @@ class Timer: mode: int = PERIODIC, freq: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ) -> None: ... @overload def init( @@ -120,6 +125,7 @@ class Timer: mode: int = PERIODIC, tick_hz: int | None = None, callback: Callable[[Timer], None] | None = None, + hard: bool | None = None, ) -> None: """ Initialise the timer. Example:: @@ -157,6 +163,19 @@ class Timer: The ``callback`` argument shall be specified. Otherwise an exception will occur upon timer expiration: ``TypeError: 'NoneType' object isn't callable`` + + - ``hard`` can be one of: + + - ``True`` - The callback will be executed in hard interrupt + context, which minimises delay and jitter but is subject to the + limitations described in :ref:`isr_rules` including being unable + to allocate on the heap. + - ``False`` - The callback will be scheduled as a soft interrupt, + allowing it to allocate but possibly also introducing + garbage-collection delays and jitter. + + The default value of this option is port-specific for historical + reasons. """ ... diff --git a/tests/quality_tests/feat_machine/check_machine/check_Timer_hard.py b/tests/quality_tests/feat_machine/check_machine/check_Timer_hard.py new file mode 100644 index 000000000..03e911724 --- /dev/null +++ b/tests/quality_tests/feat_machine/check_machine/check_Timer_hard.py @@ -0,0 +1,21 @@ +# Test Timer with hard parameter (added in MicroPython v1.27+) + +from machine import Timer + + +def mycallback(t): + pass + + +# Timer with hard interrupt context +tim = Timer(-1) +tim.init(mode=Timer.PERIODIC, freq=1000, callback=mycallback, hard=True) + +# Timer with soft interrupt context +tim.init(mode=Timer.PERIODIC, period=100, callback=mycallback, hard=False) + +# Timer with hard parameter using freq +tim.init(freq=500, callback=mycallback, hard=True) + +# Constructor with hard parameter +tim2 = Timer(-1, mode=Timer.ONE_SHOT, period=1000, callback=mycallback, hard=False)