Clean up printing in MCU code and add new options
We now have four different ways of getting debug prints off of boards,
with varying tradeoffs. Split out the printing into dedicated libraries
that are easy to switch between to avoid duplicating even more code, and
also make using the new options easy.
USB is handy for testing the code on a Teensy.
Semihosting is nice in theory, but in practice it's super slow and
messes up the code's timing.
ITM works well, as long as you have a debugger attached.
Serial also works pretty well, but it means having another cable.
Change-Id: I7af5099d421c33f0324aeca92b46732e341848d4
diff --git a/motors/print/uart.h b/motors/print/uart.h
new file mode 100644
index 0000000..f4a61c8
--- /dev/null
+++ b/motors/print/uart.h
@@ -0,0 +1,34 @@
+#ifndef MOTORS_PRINT_UART_H_
+#define MOTORS_PRINT_UART_H_
+
+#include "motors/peripheral/uart.h"
+#include "motors/print/print.h"
+
+namespace frc971 {
+namespace motors {
+
+// A printing implementation using a hardware UART. This has a reasonably sized
+// buffer in memory and uses interrupts to keep the hardware busy. It could
+// support DMA too in the future.
+class UartPrinting : public PrintingImplementation {
+ public:
+ // All required parameters must be filled out.
+ UartPrinting(const PrintingParameters ¶meters);
+ ~UartPrinting() override;
+
+ void Initialize() override;
+
+ int WriteStdout(gsl::span<const char> buffer) override;
+
+ private:
+ teensy::InterruptBufferedUart stdout_uart_;
+ const int stdout_status_interrupt_;
+};
+
+// Could easily create a subclass of UartPrinting that also implements
+// WriteDebug on a second UART, and conditionally instantiate that.
+
+} // namespace motors
+} // namespace frc971
+
+#endif // MOTORS_PRINT_UART_H_