1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # TMC2209 Driver
//!
//! A `no_std` Rust driver for the TMC2209 stepper motor driver.
//!
//! This crate provides:
//! - Full register definitions for all 24 TMC2209 registers
//! - Type-safe register access with bitfield getters/setters
//! - High-level `Tmc2209` driver struct for UART communication
//! - Blocking API (feature `blocking`)
//! - Async API (feature `async`)
//! - Utility functions for current/velocity calculations
//!
//! ## Features
//!
//! - `blocking` (default): Enable blocking UART API using `embedded_io` traits
//! - `async`: Enable async UART API using `embedded_io_async` traits
//! - `defmt`: Enable `defmt::Format` derives for debugging
//!
//! ## Example
//!
//! ```ignore
//! use tmc2209::{Tmc2209, registers::{IholdIrun, Chopconf, MicrostepResolution}};
//!
//! // Create driver with UART and slave address 0
//! let mut driver = Tmc2209::new(uart, 0);
//!
//! // Check connection
//! if driver.is_connected() {
//! // Set motor current (run=16, hold=8)
//! driver.set_current(16, 8, 1)?;
//!
//! // Set microstep resolution
//! driver.set_microsteps(MicrostepResolution::M16)?;
//!
//! // Enable StealthChop for quiet operation
//! driver.enable_stealthchop()?;
//!
//! // Start moving at velocity 1000
//! driver.set_velocity(1000)?;
//! }
//! ```
//!
//! ## Protocol Overview
//!
//! The TMC2209 uses a simple UART protocol at 115200 baud (configurable):
//!
//! - Read request: 4 bytes `[0x05, slave_addr, reg_addr, CRC]`
//! - Write request: 8 bytes `[0x05, slave_addr, reg_addr|0x80, data[3:0], CRC]`
//! - Read response: 8 bytes `[0x05, 0xFF, reg_addr, data[3:0], CRC]`
//!
//! The driver handles echo bytes automatically (TMC2209 echoes all sent data
//! on its single-wire UART interface).
// Re-export main types at crate root
pub use Tmc2209;
pub use Error;
// Re-export commonly used register types
pub use ;
// Re-export utility functions
pub use ;
// Re-export datagram types for advanced usage
pub use ;