1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:58:11 +00:00

Kernel: Add a put_char(char) method to SerialDevice

This can be used to print a single char to the serial port the
SerialDevice instance handles.
This commit is contained in:
Idan Horowitz 2021-04-23 17:25:40 +03:00 committed by Andreas Kling
parent c75ca4ea8f
commit a5699a141d
2 changed files with 17 additions and 1 deletions

View file

@ -56,11 +56,24 @@ KResultOr<size_t> SerialDevice::write(FileDescription&, u64, const UserOrKernelB
return buffer.read_buffered<128>(size, [&](u8 const* data, size_t data_size) {
for (size_t i = 0; i < data_size; i++)
IO::out8(m_base_addr, data[i]);
put_char(data[i]);
return data_size;
});
}
void SerialDevice::put_char(char ch)
{
while ((get_line_status() & EmptyTransmitterHoldingRegister) == 0)
;
if (ch == '\n' && !m_last_put_char_was_carriage_return)
IO::out8(m_base_addr, '\r');
IO::out8(m_base_addr, ch);
m_last_put_char_was_carriage_return = (ch == '\r');
}
String SerialDevice::device_name() const
{
return String::formatted("ttyS{}", minor() - 64);