Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 1 | #include "motors/print/semihosting.h" |
| 2 | |
Austin Schuh | 7fe0449 | 2022-01-02 13:37:21 -0800 | [diff] [blame] | 3 | #include "absl/types/span.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame^] | 4 | |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 5 | #include "motors/core/semihosting.h" |
| 6 | |
| 7 | namespace frc971 { |
| 8 | namespace motors { |
| 9 | |
| 10 | ::std::unique_ptr<PrintingImplementation> CreatePrinting( |
| 11 | const PrintingParameters & /*parameters*/) { |
| 12 | return ::std::unique_ptr<PrintingImplementation>(new SemihostingPrinting()); |
| 13 | } |
| 14 | |
| 15 | extern "C" int _write(const int /*file*/, char *const ptr, const int len) { |
Austin Schuh | 7fe0449 | 2022-01-02 13:37:21 -0800 | [diff] [blame] | 16 | semihosting::Write operation{2 /* stderr */, |
| 17 | absl::Span<const char>(ptr, len)}; |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 18 | return len - operation.Execute(); |
| 19 | } |
| 20 | |
Austin Schuh | 7fe0449 | 2022-01-02 13:37:21 -0800 | [diff] [blame] | 21 | int SemihostingPrinting::WriteStdout(absl::Span<const char> buffer) { |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 22 | semihosting::Write operation{2 /* stderr */, buffer}; |
| 23 | return buffer.size() - operation.Execute(); |
| 24 | } |
| 25 | |
| 26 | } // namespace motors |
| 27 | } // namespace frc971 |