Skip to content

Commit d30d37e

Browse files
authored
feat(std.os.uefi.protocol): add Serial IO
1 parent 642cd73 commit d30d37e

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

lib/std/os/uefi/protocol.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub const SimpleTextOutput = @import("protocol/simple_text_output.zig").SimpleTe
1414
pub const SimplePointer = @import("protocol/simple_pointer.zig").SimplePointer;
1515
pub const AbsolutePointer = @import("protocol/absolute_pointer.zig").AbsolutePointer;
1616

17+
pub const SerialIo = @import("protocol/serial_io.zig").SerialIo;
18+
1719
pub const GraphicsOutput = @import("protocol/graphics_output.zig").GraphicsOutput;
1820

1921
pub const edid = @import("protocol/edid.zig");
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const std = @import("std");
2+
const uefi = std.os.uefi;
3+
const Guid = uefi.Guid;
4+
const Status = uefi.Status;
5+
const cc = uefi.cc;
6+
7+
pub 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+
};

0 commit comments

Comments
 (0)