device/uart.rs
1//! UART device node control contract (`/devices/uart/<name>`).
2//!
3//! # Control commands (kind `b'u'`)
4//!
5//! | Number | Command | Direction | Input | Output | Effect |
6//! |--------|--------------|-----------|--------------|--------------|-------------------------------------|
7//! | `0x00` | `GET_CONFIG` | Read | `VersionAbi` | `ConfigAbi` | Returns the current configuration. |
8//! | `0x01` | `SET_CONFIG` | Write | `ConfigAbi` | `VersionAbi` | Applies a configuration atomically. |
9//! | `0x02` | `FLUSH_RX` | Write | `VersionAbi` | `VersionAbi` | Discards received, unread data. |
10//! | `0x03` | `FLUSH_TX` | Write | `VersionAbi` | `VersionAbi` | Discards queued, untransmitted data.|
11//!
12//! Every struct starts with a `version` field that must equal [`ABI_VERSION`];
13//! any other value is `InvalidArgument`. Enum fields use the numeric codes
14//! below; an unknown code is `InvalidArgument`, and a setting the driver
15//! cannot express is `Unsupported`.
16
17use file_system::{ControlCommand, define_command};
18
19/// Version of every UART control ABI struct in this module.
20pub const ABI_VERSION: u32 = 1;
21
22/// Parity codes in [`ConfigAbi::parity`].
23pub const PARITY_NONE: u8 = 0;
24pub const PARITY_EVEN: u8 = 1;
25pub const PARITY_ODD: u8 = 2;
26
27/// Flow control codes in [`ConfigAbi::flow_control`].
28pub const FLOW_CONTROL_NONE: u8 = 0;
29pub const FLOW_CONTROL_RTS_CTS: u8 = 1;
30pub const FLOW_CONTROL_XON_XOFF: u8 = 2;
31
32file_system::plain_data! {
33 #[repr(C)]
34 /// Carries only the ABI version. Used as input and output of commands that
35 /// have no other payload.
36 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37 pub struct VersionAbi {
38 pub version: u32,
39 }
40}
41
42file_system::plain_data! {
43 #[repr(C)]
44 /// UART line configuration.
45 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
46 pub struct ConfigAbi {
47 pub version: u32,
48 pub baud_rate: u32,
49 /// 5, 6, 7 or 8.
50 pub data_bits: u8,
51 /// 1 or 2.
52 pub stop_bits: u8,
53 /// One of `PARITY_NONE`, `PARITY_EVEN`, `PARITY_ODD`.
54 pub parity: u8,
55 /// One of `FLOW_CONTROL_NONE`, `FLOW_CONTROL_RTS_CTS`, `FLOW_CONTROL_XON_XOFF`.
56 pub flow_control: u8,
57 }
58}
59
60define_command!(
61 GET_CONFIG,
62 Read,
63 crate::kind::UART,
64 0x00,
65 VersionAbi,
66 ConfigAbi
67);
68define_command!(
69 SET_CONFIG,
70 Write,
71 crate::kind::UART,
72 0x01,
73 ConfigAbi,
74 VersionAbi
75);
76define_command!(
77 FLUSH_RX,
78 Write,
79 crate::kind::UART,
80 0x02,
81 VersionAbi,
82 VersionAbi
83);
84define_command!(
85 FLUSH_TX,
86 Write,
87 crate::kind::UART,
88 0x03,
89 VersionAbi,
90 VersionAbi
91);