blob: 310bb49faf63e37c89a918ec6a491383f633f43a [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"
Philipp Schrader790cb542023-07-05 21:06:52 -07004
Brian Silverman4787a6e2018-10-06 16:00:54 -07005#include "motors/core/semihosting.h"
6
Stephan Pleinesf63bde82024-01-13 15:59:33 -08007namespace frc971::motors {
Brian Silverman4787a6e2018-10-06 16:00:54 -07008
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
Stephan Pleinesf63bde82024-01-13 15:59:33 -080025} // namespace frc971::motors