FDO2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
fdo2_uart_interface.hpp
Go to the documentation of this file.
1// clang-format off: the table below must keep one row per line.
35// clang-format on
36#ifndef FDO2_UART_INTERFACE_HPP
37#define FDO2_UART_INTERFACE_HPP
38
39#include <concepts>
40#include <cstddef>
41#include <cstdint>
42
43#include "fdo2_detail.hpp"
44#include "fdo2_protocol.hpp"
45#include "fdo2_types.hpp"
46
47namespace fdo2 {
48
50enum class CtrlPin : uint8_t {
51 Power = 0,
52};
53
55enum class GpioSignal : uint8_t {
56 INACTIVE = 0,
57 ACTIVE = 1,
58};
59
68inline constexpr uint32_t kPortDefaultBaud = 19'200;
70inline constexpr uint32_t kLogicLevelMv = 3000;
72inline constexpr uint32_t kMaxLogicLevelMv = 3300;
74inline constexpr uint32_t kSupplyMinMv = 3300;
76inline constexpr uint32_t kSupplyMaxMv = 5000;
78inline constexpr uint32_t kPowerUpMs = 1000;
80inline constexpr uint32_t kRxBufferBytes = 800;
82inline constexpr uint32_t kMaxBaudRate = 115'200;
86inline constexpr uint32_t kTurnaroundUs = 2000;
99template <typename Derived>
101public:
103 UartInterface(const UartInterface&) = delete;
106
107protected:
109 UartInterface() noexcept = default;
111 ~UartInterface() noexcept = default;
112};
113
124template <typename Port>
125concept UartPort = std::derived_from<Port, UartInterface<Port>> && requires {
126 detail::ExactHook<Port, bool() noexcept>::Take(&Port::EnsureInitialized);
127 detail::ExactHook<Port, bool(const uint8_t*, std::size_t) noexcept>::Take(&Port::Write);
128 detail::ExactHook<Port, std::size_t(uint8_t*, std::size_t, uint32_t) noexcept>::Take(&Port::Read);
129 detail::ExactHook<Port, bool() noexcept>::Take(&Port::FlushInput);
130};
131
132} // namespace fdo2
133
134#endif // FDO2_UART_INTERFACE_HPP
CRTP base of the platform UART port.
Definition fdo2_uart_interface.hpp:100
UartInterface & operator=(const UartInterface &)=delete
Ports are not copied: the driver holds a reference.
UartInterface() noexcept=default
Only the derived port is constructed.
UartInterface(const UartInterface &)=delete
Ports are not copied: the driver holds a reference.
Satisfied by a class that derives from UartInterface<Port> and implements the required hooks with exa...
Definition fdo2_uart_interface.hpp:125
Compile-time helpers of the FDO2 driver: typed integer literals, exact hook matching,...
The FDO2 line protocol as pure functions: CRC-16, command encoders, the line assembler and the strict...
Public types of the FDO2 driver: errors, Result<T>, the status word, measurements,...
The FDO2 driver: everything it declares lives here; internals in detail.
Definition fdo2.hpp:33
constexpr uint32_t kPortDefaultBaud
Rate after every power-up (datasheet 4).
Definition fdo2_uart_interface.hpp:68
constexpr uint32_t kSupplyMinMv
Lowest supply the datasheet allows, millivolts (below it the readings can be wrong).
Definition fdo2_uart_interface.hpp:74
constexpr uint32_t kMaxLogicLevelMv
Absolute maximum on the module's UART pins, millivolts: a 5 V host needs a level shifter.
Definition fdo2_uart_interface.hpp:72
constexpr uint32_t kMaxBaudRate
Highest baud rate the module accepts (datasheet 4.3, #BAUD).
Definition fdo2_uart_interface.hpp:82
constexpr uint32_t kPowerUpMs
Time from power to the first answer, milliseconds ("ca. 1 sec", datasheet 4).
Definition fdo2_uart_interface.hpp:78
constexpr uint32_t kTurnaroundUs
Definition fdo2_uart_interface.hpp:86
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition fdo2_uart_interface.hpp:55
@ ACTIVE
The pin function is asserted (module powered).
@ INACTIVE
The pin function is deasserted (module unpowered).
constexpr uint32_t kLogicLevelMv
Logic level of the module's UART, millivolts (datasheet 2, Interface).
Definition fdo2_uart_interface.hpp:70
constexpr uint32_t kRxBufferBytes
Receive buffer a port needs to never lose a #RDUM reply, bytes (or it polls every 300 ms).
Definition fdo2_uart_interface.hpp:80
CtrlPin
Control pins the port may drive through the optional GpioSet() hook.
Definition fdo2_uart_interface.hpp:50
@ Power
Supply switch of the module: ACTIVE powers it. It idles INACTIVE (off).
constexpr uint32_t kSupplyMaxMv
Highest supply, millivolts (absolute maximum 5.5 V).
Definition fdo2_uart_interface.hpp:76