2022-11-13 09:30:10 +00:00
|
|
|
#include "arch/Serial.h"
|
2022-12-04 11:42:43 +00:00
|
|
|
#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
|
|
|
|
{
|
2022-11-16 19:30:34 +00:00
|
|
|
void write(const char* str, usize size)
|
2022-11-13 09:30:10 +00:00
|
|
|
{
|
2022-12-08 14:09:32 +00:00
|
|
|
while (size--) putchar((u8)*str++);
|
2022-11-13 09:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print(const char* str)
|
|
|
|
{
|
2022-12-08 14:09:32 +00:00
|
|
|
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
|
|
|
|
2022-12-16 17:32:29 +00:00
|
|
|
usize printf(const char* format, ...)
|
2022-11-19 11:30:36 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2023-03-02 12:38:21 +00:00
|
|
|
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
|
|
|
}
|