authorgravatar for mattettler@protonmail.comMatthew Ettler <mattettler@protonmail.com> 2024-07-28 06:37:53-06:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-28 12:37:53+00:00
logd30d37e356a7e5339c353b2aec94aa9eee59d8c6
treeb8c3ab9cc4ff3b95aa4172018a843b784bd4800b
parent642cd730c8b588778d8c1d6953134408b30dfab3
signaturebadge-check Signed by PGP key B5690EEEBB952194

feat(std.os.uefi.protocol): add Serial IO


2 files changed, 84 insertions(+), 0 deletions(-)

lib/std/os/uefi/protocol.zig+2
......@@ -14,6 +14,8 @@ pub const SimpleTextOutput = @import("protocol/simple_text_output.zig").SimpleTe
1414pub const SimplePointer = @import("protocol/simple_pointer.zig").SimplePointer;
1515pub const AbsolutePointer = @import("protocol/absolute_pointer.zig").AbsolutePointer;
1616
17pub const SerialIo = @import("protocol/serial_io.zig").SerialIo;
18
1719pub const GraphicsOutput = @import("protocol/graphics_output.zig").GraphicsOutput;
1820
1921pub const edid = @import("protocol/edid.zig");
lib/std/os/uefi/protocol/serial_io.zig created+82
......@@ -0,0 +1,82 @@
1const std = @import("std");
2const uefi = std.os.uefi;
3const Guid = uefi.Guid;
4const Status = uefi.Status;
5const cc = uefi.cc;
6
7pub const SerialIo = extern struct {
8 revision: u64,
9 _reset: *const fn (*const SerialIo) callconv(cc) Status,
10 _set_attribute: *const fn (*const SerialIo, u64, u32, u32, ParityType, u8, StopBitsType) callconv(cc) Status,
11 _set_control: *const fn (*const SerialIo, u32) callconv(cc) Status,
12 _get_control: *const fn (*const SerialIo, *u32) callconv(cc) Status,
13 _write: *const fn (*const SerialIo, *usize, *anyopaque) callconv(cc) Status,
14 _read: *const fn (*const SerialIo, *usize, *anyopaque) callconv(cc) Status,
15 mode: *Mode,
16 device_type_guid: ?*Guid,
17
18 ///Resets the serial device.
19 pub fn reset(self: *const SerialIo) Status {
20 return self._reset(self);
21 }
22
23 ///Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, data bits, and stop bits on a serial device.
24 pub fn setAttribute(self: *const SerialIo, baudRate: u64, receiverFifoDepth: u32, timeout: u32, parity: ParityType, dataBits: u8, stopBits: StopBitsType) Status {
25 return self._set_attribute(self, baudRate, receiverFifoDepth, timeout, parity, dataBits, stopBits);
26 }
27
28 ///Sets the control bits on a serial device.
29 pub fn setControl(self: *const SerialIo, control: u32) Status {
30 return self._set_control(self, control);
31 }
32
33 ///Retrieves the status of the control bits on a serial device.
34 pub fn getControl(self: *const SerialIo, control: *u32) Status {
35 return self._get_control(self, control);
36 }
37
38 ///Writes data to a serial device.
39 pub fn write(self: *const SerialIo, bufferSize: *usize, buffer: *anyopaque) Status {
40 return self._write(self, bufferSize, buffer);
41 }
42
43 ///Reads data from a serial device.
44 pub fn read(self: *const SerialIo, bufferSize: *usize, buffer: *anyopaque) Status {
45 return self._read(self, bufferSize, buffer);
46 }
47
48 pub const guid align(8) = Guid{
49 .time_low = 0xBB25CF6F,
50 .time_mid = 0xF1D4,
51 .time_high_and_version = 0x11D2,
52 .clock_seq_high_and_reserved = 0x9a,
53 .clock_seq_low = 0x0c,
54 .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd },
55 };
56
57 pub const ParityType = enum(u32) {
58 DefaultParity,
59 NoParity,
60 EvenParity,
61 OddParity,
62 MarkParity,
63 SpaceParity,
64 };
65
66 pub const StopBitsType = enum(u32) {
67 DefaultStopBits,
68 OneStopBit,
69 OneFiveStopBits,
70 TwoStopBits,
71 };
72
73 pub const Mode = extern struct {
74 control_mask: u32,
75 timeout: u32,
76 baud_rate: u64,
77 receive_fifo_depth: u32,
78 data_bits: u32,
79 parity: u32,
80 stop_bits: u32,
81 };
82};