kernel/hil/
keyboard.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2025.
4
5//! Interface for keyboard key presses.
6
7use crate::ErrorCode;
8
9/// Receiver for keyboard key presses.
10pub trait KeyboardClient {
11    /// Called when one or more keys are pressed or un-pressed.
12    ///
13    /// `keys` is an array of `(key_code, is_pressed)` tuples. `key_code` is the
14    /// same as the codes used by Linux to identify different keys.
15    /// `is_pressed` is true if the key was pressed, and false if the key was
16    /// un-pressed. A list of keycodes can be found here:
17    /// https://manpages.ubuntu.com/manpages/focal/man7/virkeycode-linux.7.html
18    ///
19    /// `result` is `Ok(())` if the keys were received correctly.
20    fn keys_pressed(&self, keys: &[(u16, bool)], result: Result<(), ErrorCode>);
21}
22
23/// Represents a keyboard that can generate button presses.
24pub trait Keyboard<'a> {
25    fn set_client(&self, client: &'a dyn KeyboardClient);
26}