TMC5160 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
tmc5160_spi_interface.hpp
Go to the documentation of this file.
1// clang-format off: the table below must keep one row per line.
20// clang-format on
21#ifndef TMC5160_SPI_INTERFACE_HPP
22#define TMC5160_SPI_INTERFACE_HPP
23
24#include <concepts>
25#include <cstddef>
26#include <cstdint>
27
28#include "tmc5160_detail.hpp"
29#include "tmc5160_types.hpp"
30
31namespace tmc5160 {
32
40inline constexpr uint8_t kSpiMode = 3;
42inline constexpr bool kMsbFirst = true;
45inline constexpr uint32_t kMaxClockHz = 4'000'000;
47inline constexpr uint32_t kDatagramBytes = 5;
49inline constexpr uint32_t kMinCsHighNs = 200;
52inline constexpr uint32_t kCsHoldNs = 100;
54inline constexpr uint32_t kCsSetupNs = 10;
56inline constexpr bool kContinuousWord = true;
68template <typename Derived>
70public:
72 SpiInterface(const SpiInterface&) = delete;
75
76protected:
78 SpiInterface() noexcept = default;
80 ~SpiInterface() noexcept = default;
81};
82
88template <typename Port>
89concept SpiPort = std::derived_from<Port, SpiInterface<Port>> && requires {
90 detail::ExactHook<Port, bool() noexcept>::Take(&Port::EnsureInitialized);
91 detail::ExactHook<Port, bool(const uint8_t*, uint8_t*, std::size_t) noexcept>::Take(
92 &Port::Transfer);
93};
94
95} // namespace tmc5160
96
97#endif // TMC5160_SPI_INTERFACE_HPP
CRTP base of the platform SPI port.
Definition tmc5160_spi_interface.hpp:69
SpiInterface(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface & operator=(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface() noexcept=default
Only the derived port is constructed.
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exac...
Definition tmc5160_spi_interface.hpp:89
The TMC5160 driver: everything it declares lives here; internals in detail.
Definition tmc5160.hpp:34
constexpr uint8_t kSpiMode
SPI mode: SCK idles high, data is latched on the rising edge ("usually referred to as mode 3").
Definition tmc5160_spi_interface.hpp:40
constexpr uint32_t kMaxClockHz
Definition tmc5160_spi_interface.hpp:45
constexpr uint32_t kMinCsHighNs
CSN high time between datagrams is more than 2 clocks + 10 ns: 200 ns covers the slowest clock.
Definition tmc5160_spi_interface.hpp:49
constexpr uint32_t kCsSetupNs
CSN low to the first SCK edge, t_CC, minimum.
Definition tmc5160_spi_interface.hpp:54
constexpr bool kContinuousWord
true: the chip needs the 40 bits of a datagram without a CSN pulse in between.
Definition tmc5160_spi_interface.hpp:56
constexpr uint32_t kCsHoldNs
Definition tmc5160_spi_interface.hpp:52
constexpr bool kMsbFirst
Each byte is clocked most significant bit first.
Definition tmc5160_spi_interface.hpp:42
constexpr uint32_t kDatagramBytes
A datagram is 40 bits; the whole datagram (5 bytes per chip in a chain) is one CSN low period.
Definition tmc5160_spi_interface.hpp:47
Compile-time helpers of the TMC5160 driver: typed integer literals, exact hook matching,...
Public types of the TMC5160 driver: errors, Result<T>, configuration, validation and advice.