kernel/hil/
text_screen.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 2022.
4
5//! Interface for text screen and displays.
6
7use crate::ErrorCode;
8
9pub trait TextScreen<'a> {
10    fn set_client(&self, client: Option<&'a dyn TextScreenClient>);
11
12    /// Returns a tuple (width, height) with the resolution of the
13    /// screen that is being used. This function is synchronous as the
14    /// resolution is known by the driver at any moment.
15    ///
16    /// The resolution is constant.
17    fn get_size(&self) -> (usize, usize);
18
19    /// Sends a write command to the driver, and the buffer to write from
20    /// and the len are sent as arguments. When the `write` operation is
21    /// finished, the driver will call the `write_complete()` callback.
22    ///
23    /// Return values:
24    /// - `Ok(())`: The write command is valid and will be sent to the driver.
25    /// - `BUSY`: The driver is busy with another command.
26    fn print(
27        &self,
28        buffer: &'static mut [u8],
29        len: usize,
30    ) -> Result<(), (ErrorCode, &'static mut [u8])>;
31
32    /// Sends to the driver a command to set the cursor at a given position
33    /// (x_position, y_position). When finished, the driver will call the
34    /// `command_complete()` callback.
35    ///
36    /// Return values:
37    /// - `Ok(())`: The command is valid and will be sent to the driver.
38    /// - `BUSY`: Another command is in progress.
39    fn set_cursor(&self, x_position: usize, y_position: usize) -> Result<(), ErrorCode>;
40
41    /// Sends to the driver a command to hide the cursor. When finished,
42    /// the driver will call the `command_complete()` callback.
43    ///
44    /// Return values:
45    /// - `Ok(())`: The command is valid and will be sent to the driver.
46    /// - `BUSY`: Another command is in progress.
47    fn hide_cursor(&self) -> Result<(), ErrorCode>;
48
49    /// Sends to the driver a command to show the cursor. When finished,
50    /// the driver will call the `command_complete()` callback.
51    ///
52    /// Return values:
53    /// - `Ok(())`: The command is valid and will be sent to the driver.
54    /// - `BUSY`: Another command is in progress.
55    fn show_cursor(&self) -> Result<(), ErrorCode>;
56
57    /// Sends to the driver a command to turn on the blinking cursor. When finished,
58    /// the driver will call the `command_complete()` callback.
59    ///
60    /// Return values:
61    /// - `Ok(())`: The command is valid and will be sent to the driver.
62    /// - `BUSY`: Another command is in progress.
63    fn blink_cursor_on(&self) -> Result<(), ErrorCode>;
64
65    /// Sends to the driver a command to turn off the blinking cursor. When finished,
66    /// the driver will call the `command_complete()` callback.
67    ///
68    /// Return values:
69    /// - `Ok(())`: The command is valid and will be sent to the driver.
70    /// - `BUSY`: Another command is in progress.
71    fn blink_cursor_off(&self) -> Result<(), ErrorCode>;
72
73    /// Sends to the driver a command to turn on the display of the screen.
74    /// When finished, the driver will call the `command_complete()` callback.
75    ///
76    /// Return values:
77    /// - `Ok(())`: The command is valid and will be sent to the driver.
78    /// - `BUSY`: Another command is in progress.
79    fn display_on(&self) -> Result<(), ErrorCode>;
80
81    /// Sends to the driver a command to turn off the display of the screen.
82    /// When finished, the driver will call the `command_complete()` callback.
83    ///
84    /// Return values:
85    /// - `Ok(())`: The command is valid and will be sent to the driver.
86    /// - `BUSY`: Another command is in progress.
87    fn display_off(&self) -> Result<(), ErrorCode>;
88
89    /// Sends to the driver a command to clear the display of the screen.
90    /// When finished, the driver will call the `command_complete()` callback.
91    ///
92    /// Return values:
93    /// - `Ok(())`: The command is valid and will be sent to the driver.
94    /// - `BUSY`: Another command is in progress.
95    fn clear(&self) -> Result<(), ErrorCode>;
96}
97
98pub trait TextScreenClient {
99    /// The driver calls this function when any command (but a write one)
100    /// finishes executing.
101    fn command_complete(&self, r: Result<(), ErrorCode>);
102
103    /// The driver calls this function when a write command finishes executing.
104    fn write_complete(&self, buffer: &'static mut [u8], len: usize, r: Result<(), ErrorCode>);
105}