TMC5160 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
tmc5160_kconfig.hpp
Go to the documentation of this file.
1
20#ifndef TMC5160_KCONFIG_HPP
21#define TMC5160_KCONFIG_HPP
22
23#ifdef __has_include
24#if __has_include("sdkconfig.h")
25#include "sdkconfig.h"
26#endif
27#endif
28
29#include "tmc5160_types.hpp"
30
31namespace tmc5160 {
32
39constexpr Config KconfigDefaults() noexcept {
40#if defined(CONFIG_TMC5160_MOTOR_RATED_MA) && defined(CONFIG_TMC5160_RSENSE_MOHM) && \
41 defined(CONFIG_TMC5160_SUPPLY_MV)
42 Motor motor{};
43 motor.rated_rms_ma = static_cast<uint32_t>(CONFIG_TMC5160_MOTOR_RATED_MA);
44#ifdef CONFIG_TMC5160_MOTOR_MAX_MA
45 motor.max_rms_ma = static_cast<uint32_t>(CONFIG_TMC5160_MOTOR_MAX_MA);
46#endif
47 Board board{};
48 board.rsense_mohm = static_cast<uint32_t>(CONFIG_TMC5160_RSENSE_MOHM);
49 board.supply_mv = static_cast<uint32_t>(CONFIG_TMC5160_SUPPLY_MV);
50 Config c = MakeConfig(motor, board);
51#if defined(CONFIG_TMC5160_RUN_MA) && (CONFIG_TMC5160_RUN_MA > 0)
52 c.current.run_ma = static_cast<uint32_t>(CONFIG_TMC5160_RUN_MA);
53#endif
54 // The hold current once: the configured one, else 30 percent of a configured run current.
55#if defined(CONFIG_TMC5160_HOLD_MA) && (CONFIG_TMC5160_HOLD_MA > 0)
56 c.current.hold_ma = static_cast<uint32_t>(CONFIG_TMC5160_HOLD_MA);
57#elif defined(CONFIG_TMC5160_RUN_MA) && (CONFIG_TMC5160_RUN_MA > 0)
58 c.current.hold_ma = (c.current.run_ma * 3U) / 10U;
59#endif
60#ifdef CONFIG_TMC5160_MRES
61 c.chopper.mres = static_cast<Microsteps>(CONFIG_TMC5160_MRES);
62#endif
63#if defined(CONFIG_TMC5160_STEALTHCHOP) && CONFIG_TMC5160_STEALTHCHOP
64 c.stealth.enable = true;
65#endif
66#ifdef CONFIG_TMC5160_UART_BAUD
67 c.uart.baud = static_cast<uint32_t>(CONFIG_TMC5160_UART_BAUD);
68#endif
69#ifdef CONFIG_TMC5160_UART_NODE
70 c.uart.node = static_cast<uint8_t>(CONFIG_TMC5160_UART_NODE);
71#endif
72#ifdef CONFIG_TMC5160_SPI_CHAIN_LENGTH
73 c.spi.chain_length = static_cast<uint8_t>(CONFIG_TMC5160_SPI_CHAIN_LENGTH);
74#endif
75#ifdef CONFIG_TMC5160_SPI_CHAIN_INDEX
76 c.spi.chain_index = static_cast<uint8_t>(CONFIG_TMC5160_SPI_CHAIN_INDEX);
77#endif
78#if defined(CONFIG_TMC5160_VERIFY_STARTUP) && CONFIG_TMC5160_VERIFY_STARTUP
80#endif
81 return c;
82#else
83 return Config{};
84#endif
85}
86
87} // namespace tmc5160
88
89#endif // TMC5160_KCONFIG_HPP
Microsteps
Microstep resolution (CHOPCONF.MRES): the value is the shift from 256 microsteps.
Definition tmc5160_types.hpp:226
constexpr Config MakeConfig(const Motor &motor, const Board &board) noexcept
A valid configuration for a declared motor and power stage: run current 90 percent of the rated curre...
Definition tmc5160_types.hpp:952
@ ReadBack
Read the register back where the chip allows it (one or two transfers).
The TMC5160 driver: everything it declares lives here; internals in detail.
Definition tmc5160.hpp:34
constexpr Config KconfigDefaults() noexcept
The configuration menuconfig selected.
Definition tmc5160_kconfig.hpp:39
The power stage as built: the sense resistor and the supply.
Definition tmc5160_types.hpp:319
uint32_t rsense_mohm
Sense resistor per coil in mOhm. Required, 1 or more.
Definition tmc5160_types.hpp:320
Microsteps mres
Microstep resolution.
Definition tmc5160_types.hpp:355
Everything EnsureInitialized() writes to the chip. See docs/configuration.md.
Definition tmc5160_types.hpp:536
UartOptions uart
UART options.
Definition tmc5160_types.hpp:561
StealthChop stealth
StealthChop.
Definition tmc5160_types.hpp:547
Chopper chopper
Chopper.
Definition tmc5160_types.hpp:546
SpiOptions spi
SPI options.
Definition tmc5160_types.hpp:562
Current current
Run and hold current.
Definition tmc5160_types.hpp:544
Verify verify
Verification the start-up uses on its writes.
Definition tmc5160_types.hpp:563
uint32_t hold_ma
Standstill current in mA; at most run_ma unless Ack::HoldAboveRun.
Definition tmc5160_types.hpp:334
uint32_t run_ma
Run current in mA, 1 or more.
Definition tmc5160_types.hpp:333
The motor as its data sheet declares it; the current ceiling comes from here.
Definition tmc5160_types.hpp:310
uint32_t rated_rms_ma
Rated coil current, RMS, in mA. Required, 1 or more.
Definition tmc5160_types.hpp:311
uint8_t chain_index
This chip: 0 is the one whose SDI is on MOSI.
Definition tmc5160_types.hpp:532
uint8_t chain_length
Chips in the daisy chain, 1 to kMaxChain.
Definition tmc5160_types.hpp:531
bool enable
GCONF.en_pwm_mode.
Definition tmc5160_types.hpp:364
uint8_t node
NODEADDR 0 to 253 (254 only inside the addressing procedure).
Definition tmc5160_types.hpp:523
uint32_t baud
Baud rate the port runs; 9000 to fCLK / 16.
Definition tmc5160_types.hpp:526
Public types of the TMC5160 driver: errors, Result<T>, configuration, validation and advice.