ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
tmc22xx.cpp
Go to the documentation of this file.
1#include "tmc22xx.h"
3#include "esphome/core/log.h"
5
6#include <cmath>
7#include <cstring>
8#include <numbers>
9
11
12ESPHOME_LOG_TAG(TAG, "tmc22xx");
13
14static constexpr uint8_t SYNC_BYTE = 0x05;
15static constexpr uint8_t MASTER_ADDRESS = 0xFF;
16static constexpr uint8_t WRITE_BIT = 0x80;
17static constexpr size_t READ_REQUEST_SIZE = 4;
18static constexpr size_t DATAGRAM_SIZE = 8;
19static constexpr uint8_t DEFAULT_TOFF = 3;
20static constexpr float SENSE_RESISTOR_OFFSET = 0.02f; // Ohm, added to RSENSE in the datasheet current formula
21static constexpr float INTERNAL_RSENSE_OHM = 0.17f; // Equivalent sense resistance when using internal sensing
22// INDEX pulses are counted once per loop, so near the target the speed is limited to cover the remaining
23// distance in no less than this time. A slow loop pass then cannot run far past the target.
24static constexpr float APPROACH_TIME_S = 0.02f;
25// Skip VACTUAL writes that change the speed by less than 1/16, each write blocks the loop for the UART transfer
26static constexpr int32_t VACTUAL_CHANGE_DIVISOR = 16;
27static constexpr uint32_t STATUS_POLL_INTERVAL_MS = 1000;
28// While the driver does not answer, for example without motor supply, only poll every 10 s; each failed read
29// blocks the loop for the UART timeout
30static constexpr uint8_t UNREACHABLE_POLL_SKIP = 9;
31static constexpr uint32_t GSTAT_FLAGS = 0x07; // reset, drv_err, uv_cp
32static constexpr uint32_t DRV_STATUS_FLAGS = 0x0FFF;
33
34// Indexed by DriverEvent
35PROGMEM_STRING_TABLE(DriverEventStrings, "Driver reset", "Driver error", "Charge pump undervoltage",
36 "Overtemperature prewarning", "Overtemperature shutdown", "Short to ground on phase A",
37 "Short to ground on phase B", "Low side short on phase A", "Low side short on phase B",
38 "Open load on phase A", "Open load on phase B", "Temperature above 120C", "Temperature above 143C",
39 "Temperature above 150C", "Temperature above 157C", "Unknown");
40
41// CRC-8 with polynomial 0x07 over the datagram bits in the order they go out on the wire, LSB first
42static uint8_t datagram_crc(const uint8_t *data, size_t len) {
43 uint8_t crc = 0;
44 for (size_t i = 0; i < len; i++) {
45 const uint8_t reflected = reverse_bits(data[i]);
46 crc = crc8(&reflected, 1, crc, 0x07, true);
47 }
48 return crc;
49}
50
51// Index into RESTORED_REGISTERS, or -1 when the register is not restored after a driver reset
52static int restored_index(uint8_t reg) {
53 for (size_t i = 0; i < RESTORED_REGISTERS.size(); i++) {
54 if (RESTORED_REGISTERS[i] == reg)
55 return static_cast<int>(i);
56 }
57 return -1;
58}
59
60void IRAM_ATTR IndexPulseStore::gpio_intr(IndexPulseStore *arg) { arg->pulses = arg->pulses + arg->direction; }
61
62void IRAM_ATTR DiagPinStore::gpio_intr(DiagPinStore *arg) { arg->triggered = true; }
63
65 setup_output_pin(this->enn_pin_, true);
66
67 auto version = this->read_field(VERSION);
68 if (!version.has_value()) {
69 ESP_LOGE(TAG, "No response from driver at address %u", this->address_);
70 this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
71 return;
72 }
73 this->version_ = *version;
74 if (this->version_ != this->expected_version()) {
75 ESP_LOGW(TAG, "Unexpected IC version 0x%02X", this->version_);
76 }
77
78 this->restore_registers();
79 this->write_register(REG_GSTAT, GSTAT_FLAGS);
80 this->apply_config_();
81 // Currents live in a write-only register, so later changes survive a driver reset through its cached value
82 if (!std::isnan(this->initial_run_current_))
84 if (!std::isnan(this->initial_hold_current_))
86
87 if (this->index_pin_ != nullptr) {
88 this->index_pin_->setup();
90 } else {
91 setup_output_pin(this->step_pin_, false);
92 setup_output_pin(this->dir_pin_, false);
93 }
94
95 if (this->diag_pin_ != nullptr) {
96 this->diag_pin_->setup();
98 }
99 // Polling notices a driver reset, and conditions that clear without a DIAG edge
100 this->set_interval(STATUS_POLL_INTERVAL_MS, [this]() {
101 if (this->status_poll_skip_ > 0) {
102 this->status_poll_skip_--;
103 return;
104 }
105 if (!this->update_status_())
106 this->status_poll_skip_ = UNREACHABLE_POLL_SKIP;
107 });
108
109 this->set_enabled(true);
110}
111
113 this->write_register(REG_IHOLD_IRUN, this->ihold_irun_);
114 this->write_register(REG_TPOWERDOWN, this->tpowerdown_);
115 this->write_register(REG_TPWMTHRS, this->tpwmthrs_);
116 this->write_register(REG_VACTUAL, 0);
117 for (size_t i = 0; i < RESTORED_REGISTERS.size(); i++) {
118 if ((this->restored_written_ & (1u << i)) != 0)
119 this->write_register(RESTORED_REGISTERS[i], this->restored_values_[i]);
120 }
121}
122
124 this->write_field(PDN_DISABLE, true);
125 this->write_field(MSTEP_REG_SELECT, true);
126 this->write_field(INTERNAL_RSENSE, std::isnan(this->rsense_));
127 this->write_field(I_SCALE_ANALOG, this->analog_current_scale_);
128 if (this->vsense_.has_value())
129 this->write_field(VSENSE, *this->vsense_);
130 if (this->ottrim_.has_value())
131 this->write_field(OTTRIM, *this->ottrim_);
132 this->vsense_active_ = this->read_field(VSENSE).value_or(0);
133
134 // TOFF=0 disables the outputs, keep the current value so it can be restored on enable
135 auto toff = this->read_field(TOFF);
136 if (toff.has_value() && *toff != 0)
137 this->toff_ = *toff;
138
140
141 if (this->index_pin_ != nullptr) {
142 // INDEX toggles on every step of the internal pulse generator that VACTUAL drives
143 this->write_field(INDEX_OTPW, false);
144 this->write_field(INDEX_STEP, true);
145 } else {
146 // Step on both edges, so every step pin toggle is one step
147 this->write_field(DEDGE, true);
148 this->write_field(MULTISTEP_FILT, false);
149 }
150}
151
153 auto gstat = this->read_register(REG_GSTAT);
154 if (!gstat.has_value())
155 return false;
156 uint32_t drv_status = 0;
157 // DRV_STATUS only feeds on_status and the DIAG check, skip the transfer when neither is used
158 if (this->diag_pin_ != nullptr || !this->status_callback_.empty()) {
159 auto value = this->read_register(REG_DRV_STATUS);
160 if (!value.has_value())
161 return false;
162 drv_status = *value;
163 }
164 // GSTAT flags stay set until written with 1; they are set again while the condition lasts
165 if ((*gstat & GSTAT_FLAGS) != 0)
166 this->write_register(REG_GSTAT, *gstat & GSTAT_FLAGS);
167
168 uint16_t status = (*gstat & GSTAT_FLAGS) | ((drv_status & DRV_STATUS_FLAGS) << 3);
169 // Restore before reporting, so an on_status automation for the reset sees and can change the restored settings
170 if ((status & (1u << DRIVER_EVENT_RESET)) != 0) {
171 ESP_LOGW(TAG, "Restoring settings after driver reset");
172 this->restore_registers();
173 // The motor stopped with the reset, ramp up again from standstill
174 this->current_speed_ = 0.0f;
175 this->set_enabled(this->enabled_);
176 }
177 uint16_t changed = status ^ this->status_;
178 this->status_ = status;
179 for (uint8_t event = 0; event < DRIVER_EVENT_COUNT; event++) {
180 if ((changed & (1u << event)) == 0)
181 continue;
182 bool active = (status & (1u << event)) != 0;
183 // Open load and temperature levels are informational, the driver keeps running
184 if (active && event < DRIVER_EVENT_OPEN_LOAD_A) {
185 ESP_LOGW(TAG, "%s", LOG_STR_ARG(DriverEventStrings::get_log_str(event)));
186 } else {
187 ESP_LOGD(TAG, "%s: %s", LOG_STR_ARG(DriverEventStrings::get_log_str(event)),
188 active ? LOG_STR_LITERAL("active") : LOG_STR_LITERAL("cleared"));
189 }
190 this->status_callback_.call(static_cast<DriverEvent>(event), active);
191 }
192 return true;
193}
194
196 ESP_LOGCONFIG(TAG,
197 " Address: %u\n"
198 " IC version: 0x%02X",
199 this->address_, this->version_);
200 // Register reads on a failed driver would only wait for the UART timeout
201 if (!this->is_failed()) {
202 uint8_t irun = this->read_field(IRUN).value_or(0);
203 uint8_t ihold = this->read_field(IHOLD).value_or(0);
204 ESP_LOGCONFIG(TAG, " Microsteps: %u", this->get_microsteps());
205 if (this->analog_current_scale_) {
206 ESP_LOGCONFIG(TAG,
207 " Run current scale: %u\n"
208 " Hold current scale: %u\n"
209 " Current scaled by VREF",
210 irun, ihold);
211 } else {
212 ESP_LOGCONFIG(TAG,
213 " Run current: %.2f A\n"
214 " Hold current: %.2f A\n"
215 " Max current: %.2f A",
216 this->scale_to_current(irun), this->scale_to_current(ihold), this->scale_to_current(31));
217 }
218 }
219 LOG_PIN(" ENN Pin: ", this->enn_pin_);
220 LOG_PIN(" STEP Pin: ", this->step_pin_);
221 LOG_PIN(" DIR Pin: ", this->dir_pin_);
222 LOG_PIN(" INDEX Pin: ", this->index_pin_);
223 LOG_PIN(" DIAG Pin: ", this->diag_pin_);
224 LOG_STEPPER(this);
225}
226
228 if (this->index_pin_ != nullptr)
229 this->add_index_pulses_();
230 if (this->diag_store_.triggered) {
231 this->diag_store_.triggered = false;
232 // DIAG rises on a driver error, any other rise is chip specific
233 if (!this->update_status_()) {
234 ESP_LOGW(TAG, "DIAG rose, but the driver status could not be read");
235 } else if ((this->status_ & GSTAT_FLAGS) == 0) {
236 this->on_diag_without_error();
237 }
238 }
239
240 const bool reached = this->has_reached_target();
241 this->high_freq_.set(!reached);
242 if (reached) {
243 this->moving_ = false;
244 } else {
245 if (!this->enabled_)
246 this->set_enabled(true);
247 // An unreachable driver is polled only every 10 s. Read it before the first step, so settings lost when the
248 // motor supply dropped are restored before the move runs on the chip defaults.
249 if (!this->moving_ && this->status_poll_skip_ > 0) {
250 this->status_poll_skip_ = this->update_status_() ? 0 : UNREACHABLE_POLL_SKIP;
251 }
252 this->moving_ = true;
253 }
254
255 if (this->index_pin_ != nullptr) {
256 this->loop_serial_();
257 } else {
258 this->loop_step_dir_();
259 }
260}
261
267
269 int32_t remaining = this->target_position - this->current_position;
270 int8_t direction = (remaining > 0) - (remaining < 0);
271 // Ran past the target, restart the ramp from standstill in the other direction
272 if (direction != 0 && direction == -this->direction_)
273 this->current_speed_ = 0.0f;
274 this->calculate_speed_(micros());
275 this->current_speed_ = std::min(this->current_speed_, static_cast<float>(std::abs(remaining)) / APPROACH_TIME_S);
276
277 int32_t vactual = direction * this->speed_to_vactual_(this->current_speed_);
278 int32_t last = this->get_vactual_();
279 if (vactual == last)
280 return;
281 if (vactual != 0 && (vactual > 0) == (last > 0) && std::abs(vactual - last) < std::abs(last) / VACTUAL_CHANGE_DIVISOR)
282 return;
283 // Pulses that arrive while VACTUAL changes direction are counted in the new direction
285 this->direction_ = direction;
286 this->write_field(VACTUAL, static_cast<uint32_t>(vactual));
287}
288
290 int32_t direction = this->should_step_();
291 if (direction == 0)
292 return;
293 if (direction != this->direction_) {
294 this->dir_pin_->digital_write(direction > 0);
295 this->direction_ = direction;
297 }
298 this->step_state_ = !this->step_state_;
299 this->step_pin_->digital_write(this->step_state_);
300}
301
303 if (this->get_vactual_() != 0)
304 this->write_field(VACTUAL, 0);
305}
306
307void TMC22XXStepper::set_enabled(bool enabled) {
308 if (!enabled) {
309 if (this->get_vactual_() != 0)
310 this->write_field(VACTUAL, 0);
311 if (this->index_pin_ != nullptr) {
312 // Count the pulses up to the stop, so the position is current before the target is set
313 this->add_index_pulses_();
314 this->index_store_.direction = 0;
315 this->direction_ = 0;
316 }
317 // Stop at the current position, so the motor does not run off again when re-enabled
318 this->target_position = this->current_position;
319 }
320 if (this->enn_pin_ != nullptr) {
321 this->enn_pin_->digital_write(!enabled);
322 } else {
323 this->write_field(TOFF, enabled ? this->toff_ : 0);
324 }
325 this->enabled_ = enabled;
326}
327
328void TMC22XXStepper::set_toff(uint8_t toff) {
329 this->toff_ = toff;
330 // Without an ENN pin, TOFF=0 is what keeps the outputs disabled
331 if (this->enabled_ || this->enn_pin_ != nullptr)
332 this->write_field(TOFF, toff);
333}
334
335void TMC22XXStepper::set_microsteps(uint16_t microsteps) {
336 for (uint8_t mres = 0; mres <= 8; mres++) {
337 if ((256u >> mres) == microsteps) {
338 this->write_field(MRES, mres);
339 return;
340 }
341 }
342 ESP_LOGW(TAG, "Invalid microsteps %u", microsteps);
343}
344
346 auto mres = this->read_field(MRES);
347 if (!mres.has_value() || *mres > 8)
348 return 0;
349 return 256u >> *mres;
350}
351
353 if (auto scale = this->current_to_scale_(current))
354 this->write_field(IRUN, *scale);
355}
356
358 if (auto scale = this->current_to_scale_(current))
359 this->write_field(IHOLD, *scale);
360}
361
363 return (this->vsense_active_ ? 0.180f : 0.325f) /
364 ((std::isnan(this->rsense_) ? INTERNAL_RSENSE_OHM : this->rsense_) + SENSE_RESISTOR_OFFSET);
365}
366
368 return (std::min<uint8_t>(scale, 31) + 1) / 32.0f * this->full_scale_current_() / std::numbers::sqrt2_v<float>;
369}
370
371optional<uint8_t> TMC22XXStepper::current_to_scale_(float current) {
372 if (this->analog_current_scale_) {
373 ESP_LOGW(TAG, "Current in A is not supported with analog current scale, use irun/ihold");
374 return {};
375 }
376 float scale = 32.0f * std::numbers::sqrt2_v<float> * current / this->full_scale_current_() - 1.0f;
377 if (scale > 31.0f) {
378 ESP_LOGW(TAG, "%.2f A is above the %.2f A limit, using the limit", current, this->scale_to_current(31));
379 return 31;
380 }
381 return static_cast<uint8_t>(std::max(0.0f, std::round(scale)));
382}
383
384int32_t TMC22XXStepper::speed_to_vactual_(float speed) const {
385 // VACTUAL is in microsteps per 2^24 clock cycles
386 return static_cast<int32_t>(std::lround(speed * 16777216.0f / this->clock_frequency_));
387}
388
390 switch (reg) {
391 case REG_IHOLD_IRUN:
392 return &this->ihold_irun_;
393 case REG_TPOWERDOWN:
394 return &this->tpowerdown_;
395 case REG_TPWMTHRS:
396 return &this->tpwmthrs_;
397 case REG_VACTUAL:
398 return &this->vactual_reg_;
399 default:
400 return nullptr;
401 }
402}
403
405 uint8_t datagram[DATAGRAM_SIZE] = {SYNC_BYTE,
406 this->address_,
407 static_cast<uint8_t>(reg | WRITE_BIT),
408 static_cast<uint8_t>(value >> 24),
409 static_cast<uint8_t>(value >> 16),
410 static_cast<uint8_t>(value >> 8),
411 static_cast<uint8_t>(value),
412 0};
413 datagram[7] = datagram_crc(datagram, 7);
414
415 this->discard_available();
416 this->write_array(datagram, DATAGRAM_SIZE);
417 this->flush();
418 // On the single wire bus every byte sent is also received, drop that echo
419 uint8_t echo[DATAGRAM_SIZE];
420 if (!this->status_comm_result(this->read_array(echo, DATAGRAM_SIZE) && memcmp(echo, datagram, DATAGRAM_SIZE) == 0)) {
421 ESP_LOGV(TAG, "No echo writing register 0x%02X", reg);
422 return false;
423 }
424
425 if (uint32_t *shadow = this->shadow_register(reg)) {
426 *shadow = value;
427 } else if (int index = restored_index(reg); index >= 0) {
428 this->restored_values_[index] = value;
429 this->restored_written_ |= 1u << index;
430 }
431 return true;
432}
433
434optional<uint32_t> TMC22XXStepper::read_register(uint8_t reg) {
435 if (uint32_t *shadow = this->shadow_register(reg))
436 return *shadow;
437
438 uint8_t request[READ_REQUEST_SIZE] = {SYNC_BYTE, this->address_, reg, 0};
439 request[3] = datagram_crc(request, 3);
440
441 this->discard_available();
442 this->write_array(request, READ_REQUEST_SIZE);
443 this->flush();
444 uint8_t reply[DATAGRAM_SIZE];
445 if (!this->read_array(reply, READ_REQUEST_SIZE) || !this->read_array(reply, DATAGRAM_SIZE)) {
446 ESP_LOGV(TAG, "No reply reading register 0x%02X", reg);
447 this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
448 return {};
449 }
450 if (!this->status_comm_result(reply[0] == SYNC_BYTE && reply[1] == MASTER_ADDRESS && reply[2] == reg &&
451 reply[7] == datagram_crc(reply, 7))) {
452 ESP_LOGV(TAG, "Invalid reply reading register 0x%02X", reg);
453 return {};
454 }
455 return encode_uint32(reply[3], reply[4], reply[5], reply[6]);
456}
457
459 // Skip the UART timeout when the driver never answered during setup
460 if (this->is_failed())
461 return false;
462 optional<uint32_t> data;
463 int index = restored_index(field.reg);
464 if (index >= 0 && (this->restored_written_ & (1u << index)) != 0) {
465 // Modify the last written value, not the chip: after a driver reset that the poll has not seen yet, the chip
466 // holds its defaults, and those would replace the values to restore
467 data = this->restored_values_[index];
468 } else {
469 data = this->read_register(field.reg);
470 }
471 if (!data.has_value())
472 return false;
473 uint32_t mask = field.mask();
474 return this->write_register(field.reg, (*data & ~mask) | ((value << field.shift) & mask));
475}
476
477optional<uint32_t> TMC22XXStepper::read_field(const RegisterField &field) {
478 auto data = this->read_register(field.reg);
479 if (!data.has_value())
480 return {};
481 return extract_field(*data, field);
482}
483
485 uint32_t value = (data & field.mask()) >> field.shift;
486 if (field.is_signed && field.width < 32) {
487 uint32_t sign_bit = 1u << (field.width - 1);
488 value = (value ^ sign_bit) - sign_bit;
489 }
490 return value;
491}
492
493} // namespace esphome::tmc22xx
uint8_t status
Definition bl0942.h:8
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:288
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
void set_interval(const char *name, uint32_t interval, SchedulerCallback &&f)
Set an interval function with a const char* name.
Definition component.cpp:88
virtual void digital_write(bool value)=0
void set(bool active)
Run the loop continuously while active is true. Repeating the current value does nothing.
Definition helpers.cpp:863
Helper class to disable interrupts.
Definition helpers.h:2523
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
Definition gpio.h:32
void calculate_speed_(uint32_t now)
Definition stepper.cpp:9
int32_t speed_to_vactual_(float speed) const
Definition tmc22xx.cpp:384
void apply_config_()
Write the settings from the configuration to the readable registers.
Definition tmc22xx.cpp:123
std::array< uint32_t, RESTORED_REGISTERS.size()> restored_values_
Definition tmc22xx.h:230
bool write_register(uint8_t reg, uint32_t value)
Definition tmc22xx.cpp:404
static uint32_t extract_field(uint32_t data, const RegisterField &field)
Definition tmc22xx.cpp:484
void set_microsteps(uint16_t microsteps)
Definition tmc22xx.cpp:335
void set_toff(uint8_t toff)
Chopper off time (1-15). TOFF=0 is used to disable the outputs, so this is applied on the next enable...
Definition tmc22xx.cpp:328
optional< uint8_t > current_to_scale_(float current)
Definition tmc22xx.cpp:371
virtual uint32_t * shadow_register(uint8_t reg)
Return the cached value of a write-only register, or nullptr when the register is readable.
Definition tmc22xx.cpp:389
virtual void restore_registers()
Write the cached write-only registers and the last written configuration registers to the driver,...
Definition tmc22xx.cpp:112
void set_enabled(bool enabled)
Enable or disable the motor outputs, using the ENN pin when configured and TOFF otherwise.
Definition tmc22xx.cpp:307
optional< uint32_t > read_register(uint8_t reg)
Definition tmc22xx.cpp:434
HighFrequencyLoopRequester high_freq_
Definition tmc22xx.h:252
optional< uint32_t > read_field(const RegisterField &field)
Definition tmc22xx.cpp:477
InternalGPIOPin * diag_pin_
Definition tmc22xx.h:222
void set_hold_current(float current)
Definition tmc22xx.cpp:357
LazyCallbackManager< void(DriverEvent, bool)> status_callback_
Definition tmc22xx.h:223
virtual uint8_t expected_version() const =0
IC version reported in IOIN by the supported chip.
float scale_to_current(uint8_t scale)
Convert a current scale (0-31) to A RMS, without analog current scale.
Definition tmc22xx.cpp:367
InternalGPIOPin * index_pin_
Definition tmc22xx.h:221
bool update_status_()
Read GSTAT and DRV_STATUS and report changes. Returns false when the status could not be read.
Definition tmc22xx.cpp:152
optional< uint8_t > ottrim_
Definition tmc22xx.h:239
void set_run_current(float current)
Set the motor run or hold current in A RMS.
Definition tmc22xx.cpp:352
bool write_field(const RegisterField &field, uint32_t value)
Definition tmc22xx.cpp:458
virtual void on_diag_without_error()
Called when DIAG rises without a driver error.
Definition tmc22xx.h:207
UARTFlushResult flush()
Definition uart.h:109
optional< std::array< uint8_t, N > > read_array()
Definition uart.h:43
void discard_available()
Read and drop every byte waiting in the receive buffer.
Definition uart.cpp:36
void write_array(const uint8_t *data, size_t len)
Definition uart.h:30
FanDirection direction
Definition fan.h:5
int speed
Definition fan.h:3
@ INTERRUPT_RISING_EDGE
Definition gpio_pin.h:52
@ INTERRUPT_ANY_EDGE
Definition gpio_pin.h:54
ESPHOME_LOG_TAG(TAG, "tmc22xx")
PROGMEM_STRING_TABLE(DriverEventStrings, "Driver reset", "Driver error", "Charge pump undervoltage", "Overtemperature prewarning", "Overtemperature shutdown", "Short to ground on phase A", "Short to ground on phase B", "Low side short on phase A", "Low side short on phase B", "Open load on phase A", "Open load on phase B", "Temperature above 120C", "Temperature above 143C", "Temperature above 150C", "Temperature above 157C", "Unknown")
DriverEvent
Driver conditions reported to on_status, in the order of their status bits: GSTAT bits 0-2,...
Definition tmc22xx.h:90
@ DRIVER_EVENT_OPEN_LOAD_A
Definition tmc22xx.h:100
uint32_t value
Definition hal.cpp:59
const void size_t len
Definition hal.h:68
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
Definition helpers.h:1235
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.
Definition helpers.cpp:87
void setup_output_pin(GPIOPin *pin, bool level)
Set up pin and drive it to level. Does nothing when pin is null, so an optional pin needs no check.
Definition gpio.cpp:44
uint8_t reverse_bits(uint8_t x)
Reverse the order of 8 bits.
Definition helpers.h:1343
static void uint32_t
Set by a rising edge on DIAG, which signals a driver error or, on chips that support it,...
Definition tmc22xx.h:110
static void gpio_intr(DiagPinStore *arg)
Definition tmc22xx.cpp:62
Counts the step pulses the driver reports on INDEX while it runs from VACTUAL.
Definition tmc22xx.h:116
static void gpio_intr(IndexPulseStore *arg)
Definition tmc22xx.cpp:60
A bit field inside one register.
Definition tmc22xx.h:15
constexpr uint32_t mask() const
Definition tmc22xx.h:21
SemaphoreHandle_t lock