mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +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
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) {
|
return buffer.read_buffered<128>(size, [&](u8 const* data, size_t data_size) {
|
||||||
for (size_t i = 0; i < data_size; i++)
|
for (size_t i = 0; i < data_size; i++)
|
||||||
IO::out8(m_base_addr, data[i]);
|
put_char(data[i]);
|
||||||
return data_size;
|
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
|
String SerialDevice::device_name() const
|
||||||
{
|
{
|
||||||
return String::formatted("ttyS{}", minor() - 64);
|
return String::formatted("ttyS{}", minor() - 64);
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||||
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||||
|
|
||||||
|
void put_char(char);
|
||||||
|
|
||||||
enum InterruptEnable {
|
enum InterruptEnable {
|
||||||
LowPowerMode = 0x01 << 5,
|
LowPowerMode = 0x01 << 5,
|
||||||
SleepMode = 0x01 << 4,
|
SleepMode = 0x01 << 4,
|
||||||
|
@ -129,6 +131,7 @@ private:
|
||||||
WordLength m_word_length { EightBits };
|
WordLength m_word_length { EightBits };
|
||||||
bool m_break_enable { false };
|
bool m_break_enable { false };
|
||||||
u8 m_modem_control { 0 };
|
u8 m_modem_control { 0 };
|
||||||
|
bool m_last_put_char_was_carriage_return { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue