Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
uart.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_UART_HPP_
25#define TAPROOT_UART_HPP_
26
27#include <cstdint>
28#include <cstdlib>
29
30#ifndef PLATFORM_HOSTED
31#include "modm/platform.hpp"
32#include "modm/platform/uart/uart_base.hpp"
33#endif
34
35#include "tap/board/board.hpp"
36#include "tap/util_macros.hpp"
37
39{
47class Uart
48{
49public:
51 {
55 };
56
57#ifdef PLATFORM_HOSTED
58 enum Parity
59 {
60 Disabled,
61 Even,
62 Odd
63 };
64#else
65 using Parity = modm::platform::UartBase::Parity;
66#endif
67
68 Uart() = default;
70 mockable ~Uart() = default;
71
80 template <UartPort port, modm::baudrate_t baudrate, Parity parity = Parity::Disabled>
81 void init()
82 {
83#ifndef PLATFORM_HOSTED
84 if constexpr (port == UartPort::Uart1)
85 {
86 modm::platform::Usart1::connect<GpioA9::Tx, GpioB7::Rx>();
87 modm::platform::Usart1::initialize<Board::SystemClock, baudrate>(parity);
88 }
89 else if constexpr (port == UartPort::Uart3)
90 {
91 modm::platform::Usart3::connect<GpioC11::Rx>();
92 modm::platform::Usart3::initialize<Board::SystemClock, baudrate>(parity);
93 }
94 else if constexpr (port == UartPort::Uart6)
95 {
96 modm::platform::Usart6::connect<GpioG14::Tx, GpioG9::Rx>();
97 modm::platform::Usart6::initialize<Board::SystemClock, baudrate>(parity);
98 }
99#endif
100 }
101
110 mockable bool read(UartPort port, uint8_t *data);
111
121 mockable std::size_t read(UartPort port, uint8_t *data, std::size_t length);
122
129 mockable std::size_t discardReceiveBuffer(UartPort port);
130
138 mockable bool write(UartPort port, uint8_t data);
139
149 mockable std::size_t write(UartPort port, const uint8_t *data, std::size_t length);
150
158 mockable bool isWriteFinished(UartPort port) const;
159
161};
162
163} // namespace tap::communication::serial
164
165#endif // TAPROOT_UART_HPP_
Definition uart.hpp:48
mockable bool write(UartPort port, uint8_t data)
Definition uart.cpp:96
void init()
Definition uart.hpp:81
mockable void flushWriteBuffer(UartPort port)
Definition uart.cpp:159
modm::platform::UartBase::Parity Parity
Definition uart.hpp:65
mockable bool read(UartPort port, uint8_t *data)
Definition uart.cpp:33
UartPort
Definition uart.hpp:51
@ Uart6
Definition uart.hpp:54
@ Uart3
Definition uart.hpp:53
@ Uart1
Definition uart.hpp:52
mockable bool isWriteFinished(UartPort port) const
Definition uart.cpp:139
mockable std::size_t discardReceiveBuffer(UartPort port)
Definition uart.cpp:76
Definition can.hpp:32
Definition dji_serial.cpp:41
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27