Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 1 | #ifndef MOTORS_PRINT_UART_H_ |
| 2 | #define MOTORS_PRINT_UART_H_ |
| 3 | |
| 4 | #include "motors/peripheral/uart.h" |
| 5 | #include "motors/print/print.h" |
| 6 | |
| 7 | namespace frc971 { |
| 8 | namespace motors { |
| 9 | |
| 10 | // A printing implementation using a hardware UART. This has a reasonably sized |
| 11 | // buffer in memory and uses interrupts to keep the hardware busy. It could |
| 12 | // support DMA too in the future. |
| 13 | class UartPrinting : public PrintingImplementation { |
| 14 | public: |
| 15 | // All required parameters must be filled out. |
| 16 | UartPrinting(const PrintingParameters ¶meters); |
| 17 | ~UartPrinting() override; |
| 18 | |
| 19 | void Initialize() override; |
| 20 | |
| 21 | int WriteStdout(gsl::span<const char> buffer) override; |
| 22 | |
| 23 | private: |
| 24 | teensy::InterruptBufferedUart stdout_uart_; |
| 25 | const int stdout_status_interrupt_; |
| 26 | }; |
| 27 | |
| 28 | // Could easily create a subclass of UartPrinting that also implements |
| 29 | // WriteDebug on a second UART, and conditionally instantiate that. |
| 30 | |
| 31 | } // namespace motors |
| 32 | } // namespace frc971 |
| 33 | |
| 34 | #endif // MOTORS_PRINT_UART_H_ |