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 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 7 | namespace frc971::motors { |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 8 | |
| 9 | ::std::unique_ptr<PrintingImplementation> CreatePrinting( |
| 10 | const PrintingParameters & /*parameters*/) { |
| 11 | return ::std::unique_ptr<PrintingImplementation>(new SemihostingPrinting()); |
| 12 | } |
| 13 | |
| 14 | 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] | 15 | semihosting::Write operation{2 /* stderr */, |
| 16 | absl::Span<const char>(ptr, len)}; |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 17 | return len - operation.Execute(); |
| 18 | } |
| 19 | |
Austin Schuh | 7fe0449 | 2022-01-02 13:37:21 -0800 | [diff] [blame] | 20 | int SemihostingPrinting::WriteStdout(absl::Span<const char> buffer) { |
Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 21 | semihosting::Write operation{2 /* stderr */, buffer}; |
| 22 | return buffer.size() - operation.Execute(); |
| 23 | } |
| 24 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 25 | } // namespace frc971::motors |