mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +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:
parent
c75ca4ea8f
commit
a5699a141d
Notes:
sideshowbarker
2024-07-18 17:57:09 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/a5699a141dc Pull-request: https://github.com/SerenityOS/serenity/pull/7116 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/supercomputer7
2 changed files with 17 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||
|
||||
void put_char(char);
|
||||
|
||||
enum InterruptEnable {
|
||||
LowPowerMode = 0x01 << 5,
|
||||
SleepMode = 0x01 << 4,
|
||||
|
@ -129,6 +131,7 @@ private:
|
|||
WordLength m_word_length { EightBits };
|
||||
bool m_break_enable { false };
|
||||
u8 m_modem_control { 0 };
|
||||
bool m_last_put_char_was_carriage_return { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue