Luna/kernel/src/arch/Serial.cpp

40 lines
830 B
C++
Raw Normal View History

2022-11-13 09:30:10 +00:00
#include "arch/Serial.h"
#include <luna/Format.h>
2022-12-07 11:25:42 +00:00
#include <luna/Result.h>
2022-12-07 10:40:02 +00:00
#include <stdarg.h>
2022-11-13 09:30:10 +00:00
namespace Serial
{
void write(const char* str, usize size)
2022-11-13 09:30:10 +00:00
{
while (size--) putchar((u8)*str++);
2022-11-13 09:30:10 +00:00
}
void print(const char* str)
{
while (*str) putchar((u8)*str++);
2022-11-13 09:30:10 +00:00
}
void println(const char* str)
{
print(str);
putchar('\n');
}
2022-11-19 11:30:36 +00:00
usize printf(const char* format, ...)
2022-11-19 11:30:36 +00:00
{
va_list ap;
va_start(ap, format);
auto rc = cstyle_format(
format,
[](char c, void*) -> Result<void> {
putchar((u8)c);
return {};
},
nullptr, ap)
.value();
2022-11-19 11:30:36 +00:00
va_end(ap);
2022-11-19 15:13:25 +00:00
return rc;
2022-11-19 11:30:36 +00:00
}
2023-01-02 12:07:29 +00:00
}