34#ifndef TMC51X0_NO_ERROR_STRINGS
45 return "Driver not initialized";
47 return "Communication error";
49 return "Invalid parameter value";
51 return "Invalid state for operation";
53 return "Operation timed out";
55 return "Operation cancelled";
57 return "Hardware fault detected";
59 return "Short circuit detected";
61 return "Open load detected";
63 return "Overtemperature warning";
65 return "Overtemperature shutdown";
67 return "Feature not supported";
69 return "Unknown error";
126 [[nodiscard]]
explicit operator bool() const noexcept {
148#ifndef TMC51X0_NO_ERROR_STRINGS
177 [[nodiscard]] T
ValueOr(
const T &default_value)
const noexcept {
184 template <std::
size_t N>
185 std::enable_if_t<N == 0, ErrorCode>
get() const & noexcept {
189 template <std::
size_t N>
190 std::enable_if_t<N == 1, const T &>
get() const & noexcept {
194 template <std::
size_t N>
195 std::enable_if_t<N == 0, ErrorCode>
get() &
noexcept {
199 template <std::
size_t N> std::enable_if_t<N == 1, T &>
get() &
noexcept {
203 template <std::
size_t N>
204 std::enable_if_t<N == 0, ErrorCode>
get() &&
noexcept {
208 template <std::
size_t N> std::enable_if_t<N == 1, T &&>
get() &&
noexcept {
254 [[nodiscard]]
explicit operator bool() const noexcept {
276#ifndef TMC51X0_NO_ERROR_STRINGS
296template <std::
size_t N,
typename T>
298 return r.template get<N>();
301template <std::
size_t N,
typename T>
303 return r.template get<N>();
306template <std::
size_t N,
typename T>
308 return std::move(r).template get<N>();
312template <std::
size_t N>
317template <std::
size_t N>
322template <std::
size_t N>
332struct tuple_size<
tmc51x0::Result<T>> : integral_constant<size_t, 2> {};
335struct tuple_size<
tmc51x0::Result<void>> : integral_constant<size_t, 1> {};
337template <
typename T>
struct tuple_element<0,
tmc51x0::Result<T>> {
341template <
typename T>
struct tuple_element<1,
tmc51x0::Result<T>> {
345template <>
struct tuple_element<0,
tmc51x0::Result<void>> {
Result type for operations that don't return a value.
Definition tmc51x0_result.hpp:225
Result(ErrorCode error) noexcept
Construct an error result.
Definition tmc51x0_result.hpp:238
ErrorCode error_
Definition tmc51x0_result.hpp:227
Result() noexcept
Construct a successful result.
Definition tmc51x0_result.hpp:233
bool IsOk() const noexcept
Check if result is OK.
Definition tmc51x0_result.hpp:262
const char * ErrorMessage() const noexcept
Get human-readable error message.
Definition tmc51x0_result.hpp:281
bool IsErr() const noexcept
Check if result is an error.
Definition tmc51x0_result.hpp:268
ErrorCode Error() const noexcept
Get the error code.
Definition tmc51x0_result.hpp:274
Result type for operations that return a value.
Definition tmc51x0_result.hpp:90
std::enable_if_t< N==1, T && > get() &&noexcept
Definition tmc51x0_result.hpp:208
ErrorCode Error() const noexcept
Get the error code.
Definition tmc51x0_result.hpp:146
const char * ErrorMessage() const noexcept
Get human-readable error message.
Definition tmc51x0_result.hpp:153
const T & Value() const noexcept
Get the result value (const reference)
Definition tmc51x0_result.hpp:170
std::enable_if_t< N==0, ErrorCode > get() &noexcept
Definition tmc51x0_result.hpp:195
bool IsOk() const noexcept
Check if result is OK.
Definition tmc51x0_result.hpp:134
T & Value() noexcept
Get the result value (mutable reference)
Definition tmc51x0_result.hpp:163
bool IsErr() const noexcept
Check if result is an error.
Definition tmc51x0_result.hpp:140
std::enable_if_t< N==0, ErrorCode > get() &&noexcept
Definition tmc51x0_result.hpp:204
ErrorCode error_
Definition tmc51x0_result.hpp:92
std::enable_if_t< N==1, const T & > get() const &noexcept
Definition tmc51x0_result.hpp:190
Result(ErrorCode error) noexcept
Construct an error result.
Definition tmc51x0_result.hpp:111
Result(T &&value) noexcept
Construct a successful result with value.
Definition tmc51x0_result.hpp:99
std::enable_if_t< N==0, ErrorCode > get() const &noexcept
Support structured bindings: auto [err, value] = result;.
Definition tmc51x0_result.hpp:185
T ValueOr(const T &default_value) const noexcept
Get the result value or a default.
Definition tmc51x0_result.hpp:177
Result(const T &value) noexcept
Construct a successful result with value (copy)
Definition tmc51x0_result.hpp:105
std::enable_if_t< N==1, T & > get() &noexcept
Definition tmc51x0_result.hpp:199
T value_
Definition tmc51x0_result.hpp:93
Definition tmc51x0_result.hpp:330
Definition tmc51x0_register_defs.cpp:10
const char * ErrorMessage(ErrorCode code)
Get human-readable error message.
Definition tmc51x0_result.hpp:40
ErrorCode
Error codes for TMC51x0 operations.
Definition tmc51x0_result.hpp:18
@ SHORT_CIRCUIT
Short circuit detected.
@ NOT_INITIALIZED
Driver not initialized.
@ TIMEOUT
Operation timed out.
@ UNSUPPORTED
Feature not supported by this chip variant.
@ INVALID_STATE
Operation not valid in current state.
@ HARDWARE_ERROR
Hardware fault detected.
@ CANCELLED
Operation cancelled by user/request.
@ COMM_ERROR
Communication interface error (SPI/UART)
@ OVERTEMP_WARNING
Overtemperature warning threshold.
@ INVALID_VALUE
Invalid parameter value.
@ OVERTEMP_SHUTDOWN
Overtemperature shutdown.
@ OPEN_LOAD
Open load detected.
decltype(auto) get(Result< T > &r) noexcept
Tuple-like access for structured bindings (C++17)
Definition tmc51x0_result.hpp:297
T type
Definition tmc51x0_result.hpp:342