aboutsummaryrefslogtreecommitdiff
path: root/quantum/deferred_exec.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/deferred_exec.h')
-rw-r--r--quantum/deferred_exec.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/quantum/deferred_exec.h b/quantum/deferred_exec.h
new file mode 100644
index 000000000..f80d35316
--- /dev/null
+++ b/quantum/deferred_exec.h
@@ -0,0 +1,38 @@
1// Copyright 2021 Nick Brassel (@tzarc)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <stdbool.h>
7#include <stdint.h>
8
9// A token that can be used to cancel an existing deferred execution.
10typedef uint8_t deferred_token;
11#define INVALID_DEFERRED_TOKEN 0
12
13// Callback to execute.
14// -- Parameter trigger_time: the intended trigger time to execute the callback -- equivalent time-space as timer_read32()
15// cb_arg: the callback argument specified when enqueueing the deferred executor
16// -- Return value: Non-zero re-queues the callback to execute after the returned number of milliseconds. Zero cancels repeated execution.
17typedef uint32_t (*deferred_exec_callback)(uint32_t trigger_time, void *cb_arg);
18
19// Configures the supplied deferred executor to be executed after the required number of milliseconds.
20// -- Parameter delay_ms: the number of milliseconds before executing the callback
21// -- callback: the executor to invoke
22// -- cb_arg: the argument to pass to the executor, may be NULL if unused by the executor
23// -- Return value: a token usable for cancellation, or INVALID_DEFERRED_TOKEN if an error occurred
24deferred_token defer_exec(uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg);
25
26// Allows for extending the timeframe before an existing deferred execution is invoked.
27// -- Parameter token: the returned value from defer_exec for the deferred execution you wish to extend.
28// -- delay_ms: the new delay (with respect to the current time)
29// -- Return value: if the token was found, and the delay was extended
30bool extend_deferred_exec(deferred_token token, uint32_t delay_ms);
31
32// Allows for cancellation of an existing deferred execution.
33// -- Parameter token: the returned value from defer_exec for the deferred execution you wish to cancel.
34// -- Return value: if the token was found, and the executor was cancelled
35bool cancel_deferred_exec(deferred_token token);
36
37// Forward declaration for the main loop in order to execute any deferred executors. Should not be invoked by keyboard/user code.
38void deferred_exec_task(void);