PyTmcStepper 0.13.0__tar.gz → 0.15.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/PKG-INFO +2 -2
  2. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/README.md +1 -1
  3. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/pyproject.toml +1 -1
  4. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/PyTmcStepper.egg-info/PKG-INFO +2 -2
  5. pytmcstepper-0.15.0/src/tmc_driver/__init__.py +96 -0
  6. pytmcstepper-0.15.0/src/tmc_driver/_tmc_stepperdriver.py +210 -0
  7. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/_tmc_xxxx.py +16 -9
  8. pytmcstepper-0.15.0/src/tmc_driver/com/__init__.py +64 -0
  9. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com.py +1 -1
  10. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_spi_base.py +4 -5
  11. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_uart_base.py +386 -341
  12. pytmcstepper-0.15.0/src/tmc_driver/enable_control/__init__.py +55 -0
  13. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -12
  14. pytmcstepper-0.15.0/src/tmc_driver/motion_control/__init__.py +111 -0
  15. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc.py +12 -2
  16. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +0 -12
  17. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -12
  18. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +0 -12
  19. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc220x_reg.py +1 -0
  20. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc224x_reg.py +1 -0
  21. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc5160_reg.py +1 -0
  22. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc_shared_regs.py +1 -1
  23. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_220x.py +2 -16
  24. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_2240.py +0 -22
  25. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_5160.py +0 -22
  26. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +2 -0
  27. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_modules.py +8 -0
  28. pytmcstepper-0.13.0/src/tmc_driver/_tmc_stepperdriver.py +0 -294
  29. pytmcstepper-0.13.0/src/tmc_driver/com/__init__.py +0 -0
  30. pytmcstepper-0.13.0/src/tmc_driver/enable_control/__init__.py +0 -0
  31. pytmcstepper-0.13.0/src/tmc_driver/motion_control/__init__.py +0 -0
  32. pytmcstepper-0.13.0/src/tmc_driver/reg/__init__.py +0 -0
  33. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/LICENSE +0 -0
  34. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/setup.cfg +0 -0
  35. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/PyTmcStepper.egg-info/SOURCES.txt +0 -0
  36. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  37. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  38. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  39. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/_tmc_exceptions.py +0 -0
  40. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/_tmc_math.py +0 -0
  41. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/_tmc_stallguard.py +0 -0
  42. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/_tmc_validation.py +0 -0
  43. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  44. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
  45. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
  46. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  47. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -0
  48. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  49. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  50. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +0 -0
  51. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
  52. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/platform_utils.py +0 -0
  53. {pytmcstepper-0.13.0/src/tmc_driver → pytmcstepper-0.15.0/src/tmc_driver/reg}/__init__.py +0 -0
  54. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  55. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/reg/_tmc_reg.py +0 -0
  56. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_2208.py +0 -0
  57. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_2209.py +0 -0
  58. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/__init__.py +0 -0
  59. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +0 -0
  60. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
  61. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +0 -0
  62. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
  63. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
  64. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
  65. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_logger/__init__.py +0 -0
  66. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_logger/_tmc_logger_base.py +0 -0
  67. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +0 -0
  68. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc2209.py +0 -0
  69. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc2240.py +0 -0
  70. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_com_spi.py +0 -0
  71. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_com_uart.py +0 -0
  72. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_ec_pin.py +0 -0
  73. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_math.py +0 -0
  74. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_move.py +0 -0
  75. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_set_current.py +0 -0
  76. {pytmcstepper-0.13.0 → pytmcstepper-0.15.0}/tests/test_tmc_stallguard.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.13.0
3
+ Version: 0.15.0
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Author-email: Christian Köhlke <christian@koehlke.de>
6
6
  License-Expression: GPL-3.0
@@ -283,7 +283,7 @@ from tmc_driver.tmc_2209 import *
283
283
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
284
284
 
285
285
  tmc.set_direction_reg(False)
286
- tmc.set_current(300)
286
+ tmc.set_current_rms(300)
287
287
  tmc.set_interpolation(True)
288
288
  tmc.set_spreadcycle(False)
289
289
  tmc.set_microstepping_resolution(2)
@@ -253,7 +253,7 @@ from tmc_driver.tmc_2209 import *
253
253
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
254
254
 
255
255
  tmc.set_direction_reg(False)
256
- tmc.set_current(300)
256
+ tmc.set_current_rms(300)
257
257
  tmc.set_interpolation(True)
258
258
  tmc.set_spreadcycle(False)
259
259
  tmc.set_microstepping_resolution(2)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyTmcStepper"
7
- version = "0.13.0"
7
+ version = "0.15.0"
8
8
  authors = [{ name = "Christian Köhlke", email = "christian@koehlke.de" }]
9
9
  description = "This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi"
10
10
  readme = "README.md"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.13.0
3
+ Version: 0.15.0
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Author-email: Christian Köhlke <christian@koehlke.de>
6
6
  License-Expression: GPL-3.0
@@ -283,7 +283,7 @@ from tmc_driver.tmc_2209 import *
283
283
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
284
284
 
285
285
  tmc.set_direction_reg(False)
286
- tmc.set_current(300)
286
+ tmc.set_current_rms(300)
287
287
  tmc.set_interpolation(True)
288
288
  tmc.set_spreadcycle(False)
289
289
  tmc.set_microstepping_resolution(2)
@@ -0,0 +1,96 @@
1
+ """
2
+ PyTmcStepper - Python library for Trinamic TMC stepper motor drivers
3
+
4
+ This package provides a high-level interface for controlling TMC stepper motor drivers
5
+ via UART or SPI communication on various platforms including Raspberry Pi, Jetson, and MicroPython.
6
+
7
+ Main Components:
8
+ - Driver Classes: Tmc2208, Tmc2209, Tmc2240, Tmc5160
9
+ - Communication: TmcCom and subclasses for UART/SPI
10
+ - Motion Control: Various strategies for motor movement
11
+ - Enable Control: Motor enable/disable functionality
12
+ - GPIO Abstraction: Platform-independent GPIO access
13
+ - Logging: Configurable logging support
14
+
15
+ Example:
16
+ >>> from tmc_driver import Tmc2209, Loglevel
17
+ >>> from tmc_driver.com import TmcComUart
18
+ >>> from tmc_driver.motion_control import TmcMotionControlStepDir
19
+ >>> from tmc_driver.enable_control import TmcEnableControlPin
20
+ >>>
21
+ >>> tmc = Tmc2209(
22
+ ... TmcEnableControlPin(21),
23
+ ... TmcMotionControlStepDir(16, 20),
24
+ ... TmcComUart("/dev/serial0"),
25
+ ... loglevel=Loglevel.INFO
26
+ ... )
27
+ """
28
+
29
+ # Driver classes
30
+ from .tmc_2208 import Tmc2208
31
+ from .tmc_2209 import Tmc2209
32
+ from .tmc_2240 import Tmc2240
33
+ from .tmc_5160 import Tmc5160
34
+
35
+ # Exceptions
36
+ from ._tmc_exceptions import (
37
+ TmcException,
38
+ TmcDriverException,
39
+ TmcComException,
40
+ TmcMotionControlException,
41
+ TmcEnableControlException,
42
+ )
43
+
44
+ # Logger
45
+ from .tmc_logger import TmcLogger, Loglevel
46
+
47
+ # GPIO
48
+ from . import tmc_gpio
49
+ from .tmc_gpio import Board
50
+
51
+ # Enable Control
52
+ from .enable_control._tmc_ec_pin import TmcEnableControlPin
53
+ from .enable_control._tmc_ec_toff import TmcEnableControlToff
54
+
55
+ # Motion Control
56
+ from .motion_control._tmc_mc import StopMode, MovementAbsRel, MovementPhase, Direction
57
+ from .motion_control._tmc_mc_step_dir import TmcMotionControlStepDir
58
+ from .motion_control._tmc_mc_step_pwm_dir import TmcMotionControlStepPwmDir
59
+ from .motion_control._tmc_mc_step_reg import TmcMotionControlStepReg
60
+ from .motion_control._tmc_mc_vactual import TmcMotionControlVActual
61
+ from .motion_control._tmc_mc_int_ramp_generator import TmcMotionControlIntRampGenerator
62
+
63
+ __all__ = [
64
+ # Driver classes
65
+ "Tmc2208",
66
+ "Tmc2209",
67
+ "Tmc2240",
68
+ "Tmc5160",
69
+ # Exceptions
70
+ "TmcException",
71
+ "TmcDriverException",
72
+ "TmcComException",
73
+ "TmcMotionControlException",
74
+ "TmcEnableControlException",
75
+ # Logger
76
+ "TmcLogger",
77
+ "Loglevel",
78
+ # GPIO
79
+ "tmc_gpio",
80
+ "Board",
81
+ # Enable Control
82
+ "TmcEnableControlPin",
83
+ "TmcEnableControlToff",
84
+ # Motion Control
85
+ "StopMode",
86
+ "MovementAbsRel",
87
+ "MovementPhase",
88
+ "Direction",
89
+ "TmcMotionControlStepDir",
90
+ "TmcMotionControlStepPwmDir",
91
+ "TmcMotionControlStepReg",
92
+ "TmcMotionControlVActual",
93
+ "TmcMotionControlIntRampGenerator",
94
+ ]
95
+
96
+ __version__ = "0.5.0"
@@ -0,0 +1,210 @@
1
+ # pylint: disable=too-many-arguments
2
+ # pylint: disable=too-many-public-methods
3
+ # pylint: disable=too-many-branches
4
+ # pylint: disable=too-many-positional-arguments
5
+ # pylint: disable=import-outside-toplevel
6
+ # pylint: disable=bare-except
7
+ # pylint: disable=unused-import
8
+ # pylint: disable=wildcard-import
9
+ # pylint: disable=unused-wildcard-import
10
+ """TmcStepperDriver module
11
+
12
+ this module has the function to move the motor via STEP/DIR pins
13
+ """
14
+
15
+ try:
16
+ from typing import TYPE_CHECKING
17
+ except ImportError:
18
+ TYPE_CHECKING = False
19
+ from .tmc_gpio import Board
20
+ from . import tmc_gpio
21
+ from .motion_control._tmc_mc import (
22
+ TmcMotionControl,
23
+ MovementAbsRel,
24
+ MovementPhase,
25
+ StopMode,
26
+ Direction,
27
+ )
28
+ from .enable_control._tmc_ec import TmcEnableControl
29
+ from .enable_control._tmc_ec_pin import TmcEnableControlPin
30
+ from .motion_control._tmc_mc_step_dir import TmcMotionControlStepDir
31
+ from .motion_control._tmc_mc_step_pwm_dir import TmcMotionControlStepPwmDir
32
+ from .tmc_logger import *
33
+ from . import _tmc_math as tmc_math
34
+
35
+
36
+ class TmcStepperDriver:
37
+ """TmcStepperDriver
38
+
39
+ this class has two different functions:
40
+ 1. change setting in the TMC-driver via UART
41
+ 2. move the motor via STEP/DIR pins
42
+
43
+ Attributes forwarded to tmc_mc (motion control):
44
+ current_pos, current_pos_fullstep, mres, steps_per_rev, fullsteps_per_rev,
45
+ movement_abs_rel, movement_phase, speed, max_speed, max_speed_fullstep,
46
+ acceleration, acceleration_fullstep
47
+ """
48
+
49
+ # Attributes that are automatically forwarded to tmc_mc submodule
50
+ _MC_FORWARDED_ATTRS = {
51
+ "current_pos",
52
+ "current_pos_fullstep",
53
+ "mres",
54
+ "steps_per_rev",
55
+ "fullsteps_per_rev",
56
+ "movement_abs_rel",
57
+ "movement_phase",
58
+ "speed",
59
+ "max_speed",
60
+ "max_speed_fullstep",
61
+ "acceleration",
62
+ "acceleration_fullstep",
63
+ }
64
+
65
+ if TYPE_CHECKING:
66
+ # Type hints for IDE/type checkers - these attributes are forwarded via __getattr__
67
+ current_pos: int
68
+ current_pos_fullstep: int
69
+ mres: int
70
+ steps_per_rev: int
71
+ fullsteps_per_rev: int
72
+ movement_abs_rel: MovementAbsRel
73
+ movement_phase: MovementPhase
74
+ speed: float
75
+ max_speed: int
76
+ max_speed_fullstep: int
77
+ acceleration: int
78
+ acceleration_fullstep: int
79
+
80
+ # Constructor/Destructor
81
+ # ----------------------------
82
+ def __init__(
83
+ self,
84
+ tmc_ec: TmcEnableControl,
85
+ tmc_mc: TmcMotionControl,
86
+ gpio_mode=None,
87
+ loglevel: Loglevel = Loglevel.INFO,
88
+ logprefix: str | None = None,
89
+ log_handlers: list | None = None,
90
+ log_formatter: logging.Formatter | None = None,
91
+ ):
92
+ """constructor
93
+
94
+ Args:
95
+ tmc_ec (TmcEnableControl): TMC Enable Control object
96
+ tmc_mc (TmcMotionControl): TMC Motion Control object
97
+ gpio_mode (enum, optional): gpio mode. Defaults to None.
98
+ loglevel (enum, optional): loglevel. Defaults to None.
99
+ logprefix (str, optional): log prefix (name of the logger).
100
+ Defaults to None (standard TMC prefix).
101
+ log_handlers (list, optional): list of logging handlers.
102
+ Defaults to None (log to console).
103
+ log_formatter (logging.Formatter, optional): formatter for the log messages.
104
+ Defaults to None (messages are logged in the format
105
+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s').
106
+ """
107
+ self.BOARD: Board = tmc_gpio.BOARD
108
+ self.tmc_ec = tmc_ec
109
+ self.tmc_mc = tmc_mc
110
+ self.tmc_logger: TmcLogger
111
+
112
+ if logprefix is None:
113
+ logprefix = "StepperDriver"
114
+ self.tmc_logger = TmcLogger(loglevel, logprefix, log_handlers, log_formatter)
115
+
116
+ self.tmc_logger.log("Init", Loglevel.INFO)
117
+
118
+ tmc_gpio.tmc_gpio.init(gpio_mode)
119
+
120
+ if self.tmc_mc is not None:
121
+ self.tmc_mc.init(self.tmc_logger)
122
+
123
+ if self.tmc_ec is not None:
124
+ self.tmc_ec.init(self.tmc_logger)
125
+
126
+ def __del__(self):
127
+ self.deinit()
128
+
129
+ def deinit(self):
130
+ """destructor"""
131
+ if hasattr(self, "tmc_ec") and self.tmc_ec is not None:
132
+ self.tmc_ec.deinit()
133
+ self.tmc_ec = None
134
+ if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
135
+ self.tmc_mc.deinit()
136
+ self.tmc_mc = None
137
+ if hasattr(self, "tmc_logger") and self.tmc_logger is not None:
138
+ self.tmc_logger.deinit()
139
+ del self.tmc_logger
140
+
141
+ # Attribute Forwarding
142
+ # ----------------------------
143
+ def __getattr__(self, name):
144
+ """Forward attribute access to tmc_mc submodule dynamically"""
145
+ if name in self._MC_FORWARDED_ATTRS:
146
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
147
+ raise AttributeError(
148
+ f"Cannot access '{name}': TmcMotionControl is not set"
149
+ )
150
+ return getattr(self.tmc_mc, name)
151
+
152
+ raise AttributeError(
153
+ f"'{type(self).__name__}' object has no attribute '{name}'"
154
+ )
155
+
156
+ def __setattr__(self, name, value):
157
+ """Forward attribute setting to tmc_mc submodule dynamically"""
158
+ # Forward to tmc_mc if it's a forwarded attribute and tmc_mc exists
159
+ if name in self._MC_FORWARDED_ATTRS:
160
+ # Only forward if tmc_mc is already initialized (not during __init__)
161
+ if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
162
+ setattr(self.tmc_mc, name, value)
163
+ return
164
+ # During __init__, tmc_mc doesn't exist yet, so fall through
165
+
166
+ # Normal attribute assignment (self.tmc_mc, self.tmc_ec, etc.)
167
+ super().__setattr__(name, value)
168
+
169
+ # TmcEnableControl Wrapper
170
+ # ----------------------------
171
+ def set_motor_enabled(self, en: bool):
172
+ """enable control wrapper"""
173
+ if self.tmc_ec is not None:
174
+ self.tmc_ec.set_motor_enabled(en)
175
+
176
+ # TmcMotionControl Wrapper
177
+ # ----------------------------
178
+ def run_to_position_steps(
179
+ self, steps, movement_abs_rel: MovementAbsRel | None = None
180
+ ) -> StopMode:
181
+ """motioncontrol wrapper"""
182
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
183
+ raise AttributeError("TmcMotionControl is not set")
184
+ return self.tmc_mc.run_to_position_steps(steps, movement_abs_rel)
185
+
186
+ def run_to_position_fullsteps(
187
+ self, steps, movement_abs_rel: MovementAbsRel | None = None
188
+ ) -> StopMode:
189
+ """motioncontrol wrapper"""
190
+ return self.run_to_position_steps(steps * self.mres, movement_abs_rel)
191
+
192
+ def run_to_position_revolutions(
193
+ self, revs, movement_abs_rel: MovementAbsRel | None = None
194
+ ) -> StopMode:
195
+ """motioncontrol wrapper"""
196
+ return self.run_to_position_steps(revs * self.steps_per_rev, movement_abs_rel)
197
+
198
+ def reset_position(self):
199
+ """resets the current position to 0"""
200
+ self.current_pos_fullstep = 0
201
+
202
+ # Test Methods
203
+ # ----------------------------
204
+ def test_step(self):
205
+ """test method"""
206
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
207
+ raise AttributeError("TmcMotionControl is not set")
208
+ for _ in range(100):
209
+ self.tmc_mc.set_direction(Direction.CW)
210
+ self.tmc_mc.make_a_step()
@@ -1,5 +1,6 @@
1
1
  # pylint: disable=wildcard-import
2
2
  # pylint: disable=unused-wildcard-import
3
+ # pylint: disable=unused-import
3
4
  # pylint: disable=too-many-arguments
4
5
  # pylint: disable=too-many-positional-arguments
5
6
  # pylint: disable=too-many-public-methods
@@ -13,6 +14,7 @@ this module has two different functions:
13
14
 
14
15
  import time
15
16
  from abc import abstractmethod
17
+ from .tmc_gpio import Gpio
16
18
  from ._tmc_stepperdriver import *
17
19
  from .tmc_logger import Loglevel
18
20
  from .enable_control._tmc_ec import TmcEnableControl
@@ -21,7 +23,13 @@ from .com._tmc_com import TmcCom
21
23
  from .reg._tmc_reg import TmcReg
22
24
  from .reg import _tmc_shared_regs as tmc_shared_regs
23
25
  from ._tmc_validation import validate_submodule
24
- from ._tmc_exceptions import TmcDriverException, TmcComException
26
+ from ._tmc_exceptions import (
27
+ TmcException,
28
+ TmcComException,
29
+ TmcMotionControlException,
30
+ TmcEnableControlException,
31
+ TmcDriverException,
32
+ )
25
33
 
26
34
 
27
35
  class TmcXXXX(TmcStepperDriver):
@@ -92,14 +100,8 @@ class TmcXXXX(TmcStepperDriver):
92
100
  if self.tmc_com is not None:
93
101
  self.tmc_com.tmc_logger = self.tmc_logger
94
102
  self.tmc_com.driver_address = driver_address
95
-
96
103
  self.tmc_com.init()
97
104
 
98
- if self.tmc_mc is not None:
99
- setattr(self.tmc_mc, "tmc_com", self.tmc_com)
100
- if self.tmc_ec is not None:
101
- setattr(self.tmc_ec, "tmc_com", self.tmc_com)
102
-
103
105
  # Register callback for submodules to access registers
104
106
  self.tmc_com.set_get_register_callback(self._get_register)
105
107
  if self.tmc_mc is not None:
@@ -269,13 +271,18 @@ class TmcXXXX(TmcStepperDriver):
269
271
  )
270
272
  return self.tmc_mc.mres
271
273
 
272
- @abstractmethod
273
274
  def set_microstepping_resolution(self, mres: int):
274
275
  """sets the current native microstep resolution (1,2,4,8,16,32,64,128,256)
275
276
 
276
277
  Args:
277
278
  mres (int): µstep resolution; has to be a power of 2 or 1 for fullstep
278
279
  """
280
+ if self.tmc_mc is not None:
281
+ self.tmc_mc.mres = mres
282
+
283
+ self.chopconf.read()
284
+ self.chopconf.mres_ms = mres
285
+ self.chopconf.write_check()
279
286
 
280
287
  @abstractmethod
281
288
  def set_current_peak(
@@ -479,4 +486,4 @@ class TmcXXXX(TmcStepperDriver):
479
486
  self.tmc_logger.log("---")
480
487
  self.tmc_logger.log("TEST COM")
481
488
 
482
- return self.tmc_com.test_com()
489
+ return self.tmc_com.test_com(self.ioin)
@@ -0,0 +1,64 @@
1
+ # pylint: disable=import-outside-toplevel
2
+ """Communication module for TMC stepper drivers
3
+
4
+ Provides UART and SPI communication implementations for different platforms:
5
+ - TmcComUart: Standard UART communication (CPython with pyserial)
6
+ - TmcComSpi: Standard SPI communication (CPython with spidev)
7
+ - TmcComUartMicroPython: UART for MicroPython
8
+ - TmcComSpiMicroPython: SPI for MicroPython
9
+ - TmcComSpiFtdi: SPI via FTDI USB devices
10
+
11
+ Example:
12
+ >>> from tmc_driver.com import TmcComUart
13
+ >>> tmc_com = TmcComUart("/dev/serial0")
14
+
15
+ Note: Base classes (TmcCom, TmcComUartBase, TmcComSpiBase) can be imported
16
+ directly from their respective files if needed for type hints or subclassing.
17
+ """
18
+
19
+ try:
20
+ from typing import TYPE_CHECKING
21
+
22
+ if TYPE_CHECKING:
23
+ # Import for type checkers/IDE only - not executed at runtime
24
+ from ._tmc_com_uart import TmcComUart
25
+ from ._tmc_com_spi import TmcComSpi
26
+ from ._tmc_com_uart_micropython import TmcComUartMicroPython
27
+ from ._tmc_com_spi_micropython import TmcComSpiMicroPython
28
+ from ._tmc_com_spi_ftdi import TmcComSpiFtdi
29
+ except ImportError:
30
+ pass
31
+
32
+
33
+ def __getattr__(name):
34
+ """Lazy import of communication classes to avoid circular imports"""
35
+ if name == "TmcComUart":
36
+ from ._tmc_com_uart import TmcComUart
37
+
38
+ return TmcComUart
39
+ if name == "TmcComSpi":
40
+ from ._tmc_com_spi import TmcComSpi
41
+
42
+ return TmcComSpi
43
+ if name == "TmcComUartMicroPython":
44
+ from ._tmc_com_uart_micropython import TmcComUartMicroPython
45
+
46
+ return TmcComUartMicroPython
47
+ if name == "TmcComSpiMicroPython":
48
+ from ._tmc_com_spi_micropython import TmcComSpiMicroPython
49
+
50
+ return TmcComSpiMicroPython
51
+ if name == "TmcComSpiFtdi":
52
+ from ._tmc_com_spi_ftdi import TmcComSpiFtdi
53
+
54
+ return TmcComSpiFtdi
55
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
56
+
57
+
58
+ __all__ = [
59
+ "TmcComUart",
60
+ "TmcComSpi",
61
+ "TmcComUartMicroPython",
62
+ "TmcComSpiMicroPython",
63
+ "TmcComSpiFtdi",
64
+ ]
@@ -144,5 +144,5 @@ class TmcCom:
144
144
  """this function clear the communication buffers of the Raspberry Pi"""
145
145
 
146
146
  @abstractmethod
147
- def test_com(self):
147
+ def test_com(self, ioin) -> bool:
148
148
  """test com connection"""
@@ -138,16 +138,15 @@ class TmcComSpiBase(TmcCom):
138
138
  def flush_com_buffer(self):
139
139
  """this function clear the communication buffers of the Raspberry Pi"""
140
140
 
141
- def test_com(self):
141
+ def test_com(self, ioin: tmc_shared_reg.Ioin):
142
142
  """test com connection
143
143
 
144
+ Args:
145
+ ioin: IOIN register instance
146
+
144
147
  Returns:
145
148
  bool: True if communication is OK, False otherwise
146
-
147
- Raises:
148
- TmcComException: if TMC register IOIN not available
149
149
  """
150
- ioin: tmc_shared_reg.Ioin = self.get_register("ioin") # type: ignore
151
150
  data, flags = ioin.read()
152
151
  del flags # unused
153
152