pub const BufferedOutStream = struct { plic: Plic, uart: Uart, fifo: Fifo, const Fifo = std.fifo.LinearFifo(u8, .{ .Static = 100 }); const Error = error{OutOfMemory}; const OutStream = io.OutStream(*Self, Error, write); const Self = @This(); fn write(self: *BufferedOutStream, data: []const u8) Error!usize { try self.fifo.write(data); self.uart.writeIe(Uart.ie{ .txwm = true, .rxwm = false, }); return data.len; } pub fn init(irq: Irq, pdriver: Plic, udriver: Uart) !OutStream { var stream = BufferedOutStream{ .plic = pdriver, .uart = udriver, .fifo = Fifo.init(), }; pdriver.setThreshold(0); const ptr = &stream; irq_stream = ptr; try pdriver.registerHandler(irq, irqHandler); udriver.writeTxctrl(Uart.txctrl{ .txen = true, .nstop = 0, .txcnt = 1, }); return OutStream{ .context = ptr }; } };