| namespace Protocols { | |
| template <typename BoardType, bool UseSecondaryPins = false> | |
| class UsartProtocol : public AbstractUsart<BoardType, typename BoardType::Gpio> { | |
| public: | |
| using Gpio = typename BoardType::Gpio; | |
| using Base = AbstractUsart<BoardType, Gpio>; | |
| explicit UsartProtocol(BoardType* board, const std::string& label = "USART") | |
| : Base(board), m_label(label) {} | |
| void write(Byte data) override { | |
| if constexpr (UseSecondaryPins) { | |
| Base::m_board->gpio().tx2.write(data); | |
| } else { | |
| Base::m_board->gpio().tx.write(data); | |
| } | |
| std::cout << "[" << m_label << "] TX: 0x" << std::hex | |
| << (int)static_cast<uint8_t>(data) << std::dec << '\n'; | |
| } | |
| Byte read() override { | |
| if (Base::m_buffer.empty()) return Byte{0x00}; | |
| Byte b = Base::m_buffer.front(); | |
| Base::m_buffer.pop(); | |
| return b; | |
| } | |
| void run(Gpio& gpio) override { | |
| if constexpr (UseSecondaryPins) { | |
| while (gpio.rx2.hasData()) { | |
| Byte data = gpio.rx2.read(); | |
| Base::m_buffer.push(data); | |
| } | |
| } else { | |
| while (gpio.rx.hasData()) { | |
| Byte data = gpio.rx.read(); | |
| Base::m_buffer.push(data); | |
| } | |
| } | |
| } | |
| private: | |
| std::string m_label; | |
| }; | |
| } // namespace Protocols | |
Xet Storage Details
- Size:
- 1.54 kB
- Xet hash:
- 2b16005a4819bd3b8f2e4cee4c49b63e71c999fc2339d18cffa34fe6c8ebcb1d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.