blob: 13bd78b8a580bf5e69a2613d029811ee314cd60d [file] [log] [blame]
Brian Silverman4787a6e2018-10-06 16:00:54 -07001#include "motors/print/semihosting.h"
2
Austin Schuh7fe04492022-01-02 13:37:21 -08003#include "absl/types/span.h"
Brian Silverman4787a6e2018-10-06 16:00:54 -07004#include "motors/core/semihosting.h"
5
6namespace frc971 {
7namespace motors {
8
9::std::unique_ptr<PrintingImplementation> CreatePrinting(
10 const PrintingParameters & /*parameters*/) {
11 return ::std::unique_ptr<PrintingImplementation>(new SemihostingPrinting());
12}
13
14extern "C" int _write(const int /*file*/, char *const ptr, const int len) {
Austin Schuh7fe04492022-01-02 13:37:21 -080015 semihosting::Write operation{2 /* stderr */,
16 absl::Span<const char>(ptr, len)};
Brian Silverman4787a6e2018-10-06 16:00:54 -070017 return len - operation.Execute();
18}
19
Austin Schuh7fe04492022-01-02 13:37:21 -080020int SemihostingPrinting::WriteStdout(absl::Span<const char> buffer) {
Brian Silverman4787a6e2018-10-06 16:00:54 -070021 semihosting::Write operation{2 /* stderr */, buffer};
22 return buffer.size() - operation.Execute();
23}
24
25} // namespace motors
26} // namespace frc971