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