TMC9660 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
tmc9660_spi_interface.hpp
Go to the documentation of this file.
1
24#ifndef TMC9660_SPI_INTERFACE_HPP
25#define TMC9660_SPI_INTERFACE_HPP
26
27#include <concepts>
28#include <cstddef>
29#include <cstdint>
30
31#include "tmc9660_detail.hpp"
32#include "tmc9660_types.hpp"
33
34namespace tmc9660 {
35
43inline constexpr uint8_t kSpiMode = 3;
45inline constexpr bool kMsbFirst = true;
47inline constexpr uint32_t kMaxClockHz = 10'000'000;
49inline constexpr uint32_t kCsSetupNs = 100;
51inline constexpr uint32_t kCsHoldNs = 100;
53inline constexpr bool kContinuousWord = true;
55inline constexpr uint32_t kMinCsHighNs = 100;
57inline constexpr uint32_t kClockPhaseNs = 20;
59inline constexpr uint32_t kDataSetupNs = 20;
61inline constexpr std::size_t kBootloaderDatagramBytes = 5;
63inline constexpr std::size_t kParameterDatagramBytes = 8;
65inline constexpr std::size_t kRegisterDatagramBytes = 6;
78template <typename Derived>
80public:
82 SpiInterface(const SpiInterface&) = delete;
85
86protected:
88 SpiInterface() noexcept = default;
90 ~SpiInterface() noexcept = default;
91};
92
104template <typename Port>
105concept SpiPort = std::derived_from<Port, SpiInterface<Port>> && requires {
106 detail::ExactHook<Port, bool() noexcept>::Take(&Port::EnsureInitialized);
107 detail::ExactHook<Port, bool(const uint8_t*, uint8_t*, std::size_t) noexcept>::Take(
108 &Port::Transfer);
109};
110
111} // namespace tmc9660
112
113#endif // TMC9660_SPI_INTERFACE_HPP
CRTP base of the platform SPI port.
Definition tmc9660_spi_interface.hpp:79
SpiInterface() noexcept=default
Only the derived port is constructed.
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.
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exac...
Definition tmc9660_spi_interface.hpp:105
The TMC9660 driver: everything it declares lives here; internals in detail.
Definition tmc9660.hpp:37
constexpr std::size_t kBootloaderDatagramBytes
Bootloader datagram length in bytes.
Definition tmc9660_spi_interface.hpp:61
constexpr uint32_t kDataSetupNs
Data setup and hold time, t_DU and t_DH.
Definition tmc9660_spi_interface.hpp:59
constexpr uint32_t kCsSetupNs
CS low to the first SCK edge, t_CSS.
Definition tmc9660_spi_interface.hpp:49
constexpr std::size_t kRegisterDatagramBytes
Register-mode datagram length in bytes.
Definition tmc9660_spi_interface.hpp:65
constexpr bool kMsbFirst
Each byte is clocked most significant bit first; multi-byte values are big endian.
Definition tmc9660_spi_interface.hpp:45
constexpr std::size_t kParameterDatagramBytes
Parameter-mode (TMCL) datagram length in bytes.
Definition tmc9660_spi_interface.hpp:63
constexpr uint8_t kSpiMode
SPI mode: CPOL 1, CPHA 1 (the default of the chip's SPI peripheral).
Definition tmc9660_spi_interface.hpp:43
constexpr uint32_t kMaxClockHz
Highest SCK frequency.
Definition tmc9660_spi_interface.hpp:47
constexpr uint32_t kMinCsHighNs
Shortest time CS stays high between two datagrams, t_CSH (4 system clocks at 40 MHz).
Definition tmc9660_spi_interface.hpp:55
constexpr uint32_t kCsHoldNs
SCK edge to CS change, t_CC (data sheet p. 27: one SCK period, 100 ns at 10 MHz).
Definition tmc9660_spi_interface.hpp:51
constexpr bool kContinuousWord
true: a datagram is clocked in one CS low period, without a CS pulse between its bytes.
Definition tmc9660_spi_interface.hpp:53
constexpr uint32_t kClockPhaseNs
SCK low and high time, t_CL and t_CH.
Definition tmc9660_spi_interface.hpp:57
Compile-time helpers of the TMC9660 driver: byte copy, exact hook matching, typed register fields and...
Public types of the TMC9660 driver: errors, Result<T>, the protocol enumerations, Config and its mode...