apio
de38eb6877
All checks were successful
continuous-integration/drone/push Build is passing
It was causing a lot of code duplication. If someone doesn't have errors, just return {} from the callback and unwrap the Result.
40 lines
830 B
C++
40 lines
830 B
C++
#include "arch/Serial.h"
|
|
#include <luna/Format.h>
|
|
#include <luna/Result.h>
|
|
#include <stdarg.h>
|
|
|
|
namespace Serial
|
|
{
|
|
void write(const char* str, usize size)
|
|
{
|
|
while (size--) putchar((u8)*str++);
|
|
}
|
|
|
|
void print(const char* str)
|
|
{
|
|
while (*str) putchar((u8)*str++);
|
|
}
|
|
|
|
void println(const char* str)
|
|
{
|
|
print(str);
|
|
putchar('\n');
|
|
}
|
|
|
|
usize printf(const char* format, ...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, format);
|
|
auto rc = cstyle_format(
|
|
format,
|
|
[](char c, void*) -> Result<void> {
|
|
putchar((u8)c);
|
|
return {};
|
|
},
|
|
nullptr, ap)
|
|
.value();
|
|
va_end(ap);
|
|
return rc;
|
|
}
|
|
}
|