PyTmcStepper 0.9.2__tar.gz → 0.9.3__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 (62) hide show
  1. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/PKG-INFO +1 -1
  2. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/pyproject.toml +1 -1
  3. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/PyTmcStepper.egg-info/PKG-INFO +1 -1
  4. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com.py +27 -21
  5. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_spi_base.py +13 -7
  6. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_spi_micropython.py +5 -1
  7. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_uart_base.py +28 -19
  8. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_uart_micropython.py +7 -0
  9. pytmcstepper-0.9.3/src/tmc_driver/enable_control/_tmc_ec.py +52 -0
  10. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/enable_control/_tmc_ec_toff.py +6 -1
  11. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/_tmc_mc.py +24 -0
  12. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +1 -1
  13. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +7 -13
  14. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +3 -2
  15. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/reg/_tmc_reg.py +16 -1
  16. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_220x.py +19 -3
  17. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_2240.py +21 -3
  18. pytmcstepper-0.9.2/src/tmc_driver/enable_control/_tmc_ec.py +0 -29
  19. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/LICENSE +0 -0
  20. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/README.md +0 -0
  21. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/setup.cfg +0 -0
  22. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/PyTmcStepper.egg-info/SOURCES.txt +0 -0
  23. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  24. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  25. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  26. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/__init__.py +0 -0
  27. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_exceptions.py +0 -0
  28. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_logger.py +0 -0
  29. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_math.py +0 -0
  30. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_stallguard.py +0 -0
  31. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_stepperdriver.py +0 -0
  32. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/_tmc_validation.py +0 -0
  33. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/__init__.py +0 -0
  34. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  35. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
  36. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  37. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/enable_control/__init__.py +0 -0
  38. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  39. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/__init__.py +0 -0
  40. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
  41. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/reg/__init__.py +0 -0
  42. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  43. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
  44. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/reg/_tmc224x_reg.py +0 -0
  45. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_2208.py +0 -0
  46. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_2209.py +0 -0
  47. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/__init__.py +0 -0
  48. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +0 -0
  49. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
  50. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +0 -0
  51. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
  52. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
  53. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
  54. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc2209.py +0 -0
  55. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc2240.py +0 -0
  56. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_com_spi.py +0 -0
  57. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_com_uart.py +0 -0
  58. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_ec_pin.py +0 -0
  59. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_math.py +0 -0
  60. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_modules.py +0 -0
  61. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_move.py +0 -0
  62. {pytmcstepper-0.9.2 → pytmcstepper-0.9.3}/tests/test_tmc_set_current.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.9.2
3
+ Version: 0.9.3
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyTmcStepper"
7
- version = "0.9.2"
7
+ version = "0.9.3"
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.9.2
3
+ Version: 0.9.3
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
@@ -8,6 +8,7 @@ import struct
8
8
  from abc import abstractmethod
9
9
  from .._tmc_logger import TmcLogger, Loglevel
10
10
  from .._tmc_exceptions import TmcComException
11
+ from ..reg._tmc_reg import TmcReg
11
12
 
12
13
 
13
14
  def compute_crc8_atm(datagram, initial_value=0):
@@ -31,17 +32,6 @@ def compute_crc8_atm(datagram, initial_value=0):
31
32
  return crc
32
33
 
33
34
 
34
- class IfcntRegister:
35
- """Interface for IFCNT register - defines only what tmc_com needs to know"""
36
-
37
- # pylint: disable=too-few-public-methods
38
-
39
- ifcnt: int
40
-
41
- def read(self):
42
- """Read the register"""
43
-
44
-
45
35
  class TmcCom:
46
36
  """TmcCom"""
47
37
 
@@ -63,9 +53,8 @@ class TmcCom:
63
53
  """
64
54
  self._tmc_logger: TmcLogger
65
55
  self.driver_address = driver_address
66
- self.ifcnt: IfcntRegister | None = None
67
56
  self.communication_pause: int = 0
68
- self.error_handler_running: bool = False
57
+ self._get_register_callback = None
69
58
 
70
59
  @abstractmethod
71
60
  def init(self):
@@ -75,8 +64,29 @@ class TmcCom:
75
64
  def deinit(self):
76
65
  """deinit communication"""
77
66
 
67
+ def set_get_register_callback(self, callback):
68
+ """Set callback to get registers from parent TMC class
69
+
70
+ Args:
71
+ callback: Function that takes register name (str) and returns register object
72
+ """
73
+ self._get_register_callback = callback
74
+
75
+ def get_register(self, name: str) -> TmcReg | None:
76
+ """Get register by name from parent TMC class
77
+
78
+ Args:
79
+ name: Register name (e.g. 'gconf', 'chopconf')
80
+
81
+ Returns:
82
+ Register object or None if callback not set
83
+ """
84
+ if self._get_register_callback is not None:
85
+ return self._get_register_callback(name)
86
+ return None
87
+
78
88
  @abstractmethod
79
- def read_reg(self, addr: int) -> tuple[int, dict]:
89
+ def read_reg(self, addr: int) -> tuple[int, dict | None]:
80
90
  """reads the registry on the TMC with a given address.
81
91
  returns the binary value of that register
82
92
 
@@ -88,7 +98,7 @@ class TmcCom:
88
98
  """
89
99
 
90
100
  @abstractmethod
91
- def read_int(self, addr: int, tries: int = 10) -> tuple[int, dict]:
101
+ def read_int(self, addr: int, tries: int = 10) -> tuple[int, dict | None]:
92
102
  """this function tries to read the registry of the TMC 10 times
93
103
  if a valid answer is returned, this function returns it as an integer
94
104
 
@@ -129,9 +139,5 @@ class TmcCom:
129
139
  """this function clear the communication buffers of the Raspberry Pi"""
130
140
 
131
141
  @abstractmethod
132
- def test_com(self, addr):
133
- """test com connection
134
-
135
- Args:
136
- addr (int): HEX, which register to test
137
- """
142
+ def test_com(self):
143
+ """test com connection"""
@@ -141,19 +141,25 @@ class TmcComSpiBase(TmcCom):
141
141
  def flush_serial_buffer(self):
142
142
  """this function clear the communication buffers of the Raspberry Pi"""
143
143
 
144
- def test_com(self, addr):
144
+ def test_com(self):
145
145
  """test com connection
146
146
 
147
- Args:
148
- addr (int): HEX, which register to test
147
+ Returns:
148
+ bool: True if communication is OK, False otherwise
149
+
150
+ Raises:
151
+ TmcComException: if TMC register IOIN not available
149
152
  """
150
- data, flags = self.read_int(addr)
153
+ ioin = self.get_register("ioin")
154
+ if ioin is None:
155
+ raise TmcComException("TMC register IOIN not available")
156
+ data, flags = ioin.read()
151
157
  del flags # unused
152
158
 
153
159
  if data == 0:
154
160
  self._tmc_logger.log("No answer from TMC received", Loglevel.ERROR)
155
161
  return False
156
- # if self._tmc_registers["ioin"].version < 0x40:
157
- # self._tmc_logger.log("No correct Version from TMC received", Loglevel.ERROR)
158
- # return False
162
+ if ioin.version < 0x21:
163
+ self._tmc_logger.log("No correct Version from TMC received", Loglevel.ERROR)
164
+ return False
159
165
  return True
@@ -10,6 +10,7 @@ Uses the machine.SPI interface available on RP2040 and similar boards.
10
10
  # Detect if we're running on MicroPython
11
11
  from machine import SPI, Pin # pylint: disable=import-error
12
12
  from ._tmc_com_spi_base import TmcComSpiBase
13
+ from .._tmc_exceptions import TmcComException
13
14
 
14
15
 
15
16
  class TmcComSpiMicroPython(TmcComSpiBase):
@@ -52,7 +53,7 @@ class TmcComSpiMicroPython(TmcComSpiBase):
52
53
  self._miso_pin = miso_pin
53
54
  self._baudrate = baudrate
54
55
 
55
- self._spi = None
56
+ self._spi: SPI | None = None
56
57
  self._cs = None
57
58
 
58
59
  def init(self):
@@ -87,6 +88,9 @@ class TmcComSpiMicroPython(TmcComSpiBase):
87
88
  Returns:
88
89
  List of received bytes
89
90
  """
91
+ if self._spi is None or self._cs is None:
92
+ raise TmcComException("SPI not initialized")
93
+
90
94
  tx_data = bytes(data)
91
95
  rx_data = bytearray(len(data))
92
96
 
@@ -66,7 +66,7 @@ class TmcComUartBase(TmcCom):
66
66
  def _uart_flush(self):
67
67
  """Flush UART buffers - to be implemented by subclass"""
68
68
 
69
- def read_reg(self, addr: int) -> tuple[bytes, dict]:
69
+ def read_reg(self, addr: int) -> tuple[bytes, None]:
70
70
  """reads the registry on the TMC with a given address.
71
71
  returns the binary value of that register
72
72
 
@@ -93,8 +93,7 @@ class TmcComUartBase(TmcCom):
93
93
 
94
94
  rtn = self._uart_write(self.r_frame)
95
95
  if rtn != len(self.r_frame):
96
- self._tmc_logger.log("Err in write", Loglevel.ERROR)
97
- return None, None
96
+ raise TmcComException("Error in UART write")
98
97
 
99
98
  # adjust per baud and hardware. Sequential reads without some delay fail.
100
99
  time.sleep(self.communication_pause)
@@ -105,7 +104,7 @@ class TmcComUartBase(TmcCom):
105
104
 
106
105
  return rtn, None
107
106
 
108
- def read_int(self, addr: int, tries: int = 10) -> tuple[int, dict]:
107
+ def read_int(self, addr: int, tries: int = 10) -> tuple[int, None]:
109
108
  """this function tries to read the registry of the TMC 10 times
110
109
  if a valid answer is returned, this function returns it as an integer
111
110
 
@@ -213,11 +212,12 @@ class TmcComUartBase(TmcCom):
213
212
  Raises:
214
213
  TmcComException: if IFCNT register is not set or write fails after retries
215
214
  """
216
- if self.ifcnt is None:
217
- raise TmcComException("IFCNT register not set for UART communication")
215
+ ifcnt = self.get_register("ifcnt")
216
+ if ifcnt is None:
217
+ raise TmcComException("TMC register IFCNT not available")
218
218
 
219
- self.ifcnt.read()
220
- ifcnt1 = self.ifcnt.ifcnt
219
+ ifcnt.read()
220
+ ifcnt1 = ifcnt.ifcnt
221
221
 
222
222
  if ifcnt1 == 255:
223
223
  ifcnt1 = -1
@@ -225,8 +225,8 @@ class TmcComUartBase(TmcCom):
225
225
  while True:
226
226
  self.write_reg(addr, val)
227
227
  tries -= 1
228
- self.ifcnt.read()
229
- ifcnt2 = self.ifcnt.ifcnt
228
+ ifcnt.read()
229
+ ifcnt2 = ifcnt.ifcnt
230
230
  if ifcnt2 >= ifcnt1:
231
231
  return True
232
232
  self._tmc_logger.log("writing not successful!", Loglevel.ERROR)
@@ -240,27 +240,28 @@ class TmcComUartBase(TmcCom):
240
240
  return
241
241
  self._uart_flush()
242
242
 
243
- def test_com(self, addr):
243
+ def test_com(self):
244
244
  """test UART connection
245
245
 
246
- Args:
247
- addr (int): HEX, which register to test
248
-
249
246
  Returns:
250
247
  bool: True if communication is OK, False otherwise
251
248
 
252
249
  Raises:
253
- TmcComException: if serial is not initialized or port is closed
250
+ TmcComException: if TMC register IOIN not available or serial not initialized
254
251
  """
252
+ # pylint: disable=too-many-statements
253
+ # pylint: disable=too-many-branches
255
254
  if self.ser is None:
256
255
  raise TmcComException("Cannot test com, serial is not initialized")
257
256
  if not self.ser.is_open:
258
257
  raise TmcComException("Cannot test com, serial port is closed")
259
258
 
260
- self._uart_flush()
259
+ ioin = self.get_register("ioin")
260
+ if ioin is None:
261
+ raise TmcComException("TMC register IOIN not available")
261
262
 
262
263
  self.r_frame[1] = self.driver_address
263
- self.r_frame[2] = addr
264
+ self.r_frame[2] = ioin.addr
264
265
  self.r_frame[3] = compute_crc8_atm(self.r_frame[:-1])
265
266
 
266
267
  rtn = self._uart_write(self.r_frame)
@@ -275,8 +276,6 @@ class TmcComUartBase(TmcCom):
275
276
  f"received {len(rtn)} bytes; {len(rtn)*8} bits", Loglevel.DEBUG
276
277
  )
277
278
  self._tmc_logger.log(f"hex: {rtn.hex()}", Loglevel.DEBUG)
278
- rtn_bin = format(int(rtn.hex(), 16), f"0>{len(rtn)*8}b")
279
- self._tmc_logger.log(f"bin: {rtn_bin}", Loglevel.DEBUG)
280
279
 
281
280
  self.tmc_logger.log(f"length snd: {len(snd)}", Loglevel.DEBUG)
282
281
  self.tmc_logger.log(f"length rtn: {len(rtn)}", Loglevel.DEBUG)
@@ -328,6 +327,16 @@ class TmcComUartBase(TmcCom):
328
327
  )
329
328
  status = False
330
329
 
330
+ if status:
331
+ ioin.read()
332
+
333
+ if ioin.version < 0x21:
334
+ self._tmc_logger.log(
335
+ f"No correct Version from TMC received: {ioin.version}",
336
+ Loglevel.ERROR,
337
+ )
338
+ status = False
339
+
331
340
  self.tmc_logger.log("---")
332
341
  if status:
333
342
  self.tmc_logger.log("UART connection: OK", Loglevel.INFO)
@@ -13,6 +13,7 @@ import sys
13
13
  import time
14
14
  from machine import UART, Pin # pylint: disable=import-error
15
15
  from ._tmc_com_uart_base import TmcComUartBase
16
+ from .._tmc_exceptions import TmcComException
16
17
 
17
18
  MICROPYTHON = sys.implementation.name == "micropython"
18
19
 
@@ -75,6 +76,8 @@ class TmcComUartMicroPython(TmcComUartBase):
75
76
  Returns:
76
77
  Number of bytes written
77
78
  """
79
+ if self._uart is None:
80
+ raise TmcComException("UART not initialized")
78
81
  return self._uart.write(bytes(data))
79
82
 
80
83
  def _uart_read(self, length):
@@ -86,6 +89,8 @@ class TmcComUartMicroPython(TmcComUartBase):
86
89
  Returns:
87
90
  Bytes read or empty bytes if timeout
88
91
  """
92
+ if self._uart is None:
93
+ raise TmcComException("UART not initialized")
89
94
  # Wait a bit for data to arrive
90
95
  time.sleep_ms(10) # pylint: disable=no-member
91
96
 
@@ -96,6 +101,8 @@ class TmcComUartMicroPython(TmcComUartBase):
96
101
 
97
102
  def _uart_flush(self):
98
103
  """Flush UART receive buffer"""
104
+ if self._uart is None:
105
+ raise TmcComException("UART not initialized")
99
106
  # Read and discard any pending data
100
107
  while self._uart.any():
101
108
  self._uart.read()
@@ -0,0 +1,52 @@
1
+ """
2
+ Enable Control base module
3
+ """
4
+
5
+ from abc import abstractmethod
6
+ from .._tmc_logger import TmcLogger
7
+ from ..reg._tmc_reg import TmcReg
8
+
9
+
10
+ class TmcEnableControl:
11
+ """Enable Control base class"""
12
+
13
+ def __init__(self):
14
+ """constructor"""
15
+ self._tmc_logger: TmcLogger
16
+ self._get_register_callback = None
17
+
18
+ def init(self, tmc_logger: TmcLogger):
19
+ """init: called by the Tmc class"""
20
+ self._tmc_logger = tmc_logger
21
+
22
+ def set_get_register_callback(self, callback):
23
+ """Set callback to get registers from parent TMC class
24
+
25
+ Args:
26
+ callback: Function that takes register name (str) and returns register object
27
+ """
28
+ self._get_register_callback = callback
29
+
30
+ def get_register(self, name: str) -> TmcReg | None:
31
+ """Get register by name from parent TMC class
32
+
33
+ Args:
34
+ name: Register name (e.g. 'gconf', 'chopconf')
35
+
36
+ Returns:
37
+ Register object or None if callback not set
38
+ """
39
+ if self._get_register_callback is not None:
40
+ return self._get_register_callback(name)
41
+ return None
42
+
43
+ def deinit(self):
44
+ """destructor"""
45
+
46
+ @abstractmethod
47
+ def set_motor_enabled(self, en):
48
+ """enables or disables the motor current output
49
+
50
+ Args:
51
+ en (bool): whether the motor current output should be enabled
52
+ """
@@ -5,6 +5,7 @@ Enable Control base module
5
5
  from ._tmc_ec import TmcEnableControl
6
6
  from ..com._tmc_com import TmcCom
7
7
  from .._tmc_logger import Loglevel
8
+ from .._tmc_exceptions import TmcEnableControlException
8
9
 
9
10
 
10
11
  class TmcEnableControlToff(TmcEnableControl):
@@ -36,4 +37,8 @@ class TmcEnableControlToff(TmcEnableControl):
36
37
 
37
38
  val = self._default_toff if en else 0
38
39
 
39
- self._tmc_com.tmc_registers["chopconf"].modify("toff", val)
40
+ chopconf = self.get_register("chopconf")
41
+ if chopconf is None:
42
+ raise TmcEnableControlException("TMC register CHOPCONF not available")
43
+
44
+ chopconf.modify("toff", val)
@@ -7,6 +7,7 @@ Motion Control base module
7
7
  from enum import IntEnum
8
8
  from abc import abstractmethod
9
9
  from .._tmc_logger import TmcLogger, Loglevel
10
+ from ..reg._tmc_reg import TmcReg
10
11
 
11
12
 
12
13
  class Direction(IntEnum):
@@ -184,12 +185,35 @@ class TmcMotionControl:
184
185
  self._movement_abs_rel: MovementAbsRel = MovementAbsRel.ABSOLUTE
185
186
  self._movement_phase: MovementPhase = MovementPhase.STANDSTILL
186
187
 
188
+ self._get_register_callback = None
189
+
187
190
  def init(self, tmc_logger: TmcLogger):
188
191
  """init: called by the Tmc class"""
189
192
  self._tmc_logger = tmc_logger
190
193
  self.max_speed_fullstep = 100
191
194
  self.acceleration_fullstep = 100
192
195
 
196
+ def set_get_register_callback(self, callback):
197
+ """Set callback to get registers from parent TMC class
198
+
199
+ Args:
200
+ callback: Function that takes register name (str) and returns register object
201
+ """
202
+ self._get_register_callback = callback
203
+
204
+ def get_register(self, name: str) -> TmcReg | None:
205
+ """Get register by name from parent TMC class
206
+
207
+ Args:
208
+ name: Register name (e.g. 'gconf', 'chopconf')
209
+
210
+ Returns:
211
+ Register object or None if callback not set
212
+ """
213
+ if self._get_register_callback is not None:
214
+ return self._get_register_callback(name)
215
+ return None
216
+
193
217
  def deinit(self):
194
218
  """destructor"""
195
219
 
@@ -121,7 +121,7 @@ class TmcMotionControlStepDir(TmcMotionControl):
121
121
  """_pin_dir property"""
122
122
  return self._pin_dir
123
123
 
124
- def __init__(self, pin_step: int, pin_dir: int):
124
+ def __init__(self, pin_step: int, pin_dir: int | None):
125
125
  """constructor"""
126
126
  super().__init__()
127
127
  self._pin_step = pin_step
@@ -1,4 +1,3 @@
1
- # pylint: disable=too-many-instance-attributes
2
1
  """
3
2
  STEP/REG Motion Control module
4
3
  """
@@ -6,9 +5,9 @@ STEP/REG Motion Control module
6
5
  from ._tmc_mc import Direction
7
6
  from ._tmc_mc_step_dir import TmcMotionControlStepDir
8
7
  from ..com._tmc_com import TmcCom
9
- from .._tmc_logger import TmcLogger, Loglevel
10
- from ..tmc_gpio import Gpio, GpioMode
8
+ from .._tmc_logger import Loglevel
11
9
  from .. import tmc_gpio
10
+ from .._tmc_exceptions import TmcMotionControlException
12
11
 
13
12
 
14
13
  class TmcMotionControlStepReg(TmcMotionControlStepDir):
@@ -29,15 +28,6 @@ class TmcMotionControlStepReg(TmcMotionControlStepDir):
29
28
  super().__init__(pin_step, None)
30
29
  self._tmc_com: TmcCom | None = None
31
30
 
32
- def init(self, tmc_logger: TmcLogger):
33
- """init: called by the Tmc class"""
34
- super().init(tmc_logger)
35
- self._tmc_logger.log(f"STEP Pin: {self._pin_step}", Loglevel.DEBUG)
36
- tmc_gpio.tmc_gpio.gpio_setup(self._pin_step, GpioMode.OUT, initial=Gpio.LOW)
37
-
38
- self.max_speed_fullstep = 100
39
- self.acceleration_fullstep = 100
40
-
41
31
  def __del__(self):
42
32
  self.deinit()
43
33
 
@@ -56,4 +46,8 @@ class TmcMotionControlStepReg(TmcMotionControlStepDir):
56
46
  self._direction = direction
57
47
  self._tmc_logger.log(f"New Direction is: {direction}", Loglevel.MOVEMENT)
58
48
 
59
- self._tmc_com.tmc_registers["gconf"].modify("shaft", bool(int(direction)))
49
+ gconf = self.get_register("gconf")
50
+ if gconf is None:
51
+ raise TmcMotionControlException("TMC register GCONF not available")
52
+
53
+ gconf.modify("shaft", bool(int(direction)))
@@ -105,9 +105,10 @@ class TmcMotionControlVActual(TmcMotionControl):
105
105
  Args:
106
106
  vactual (int): value for VACTUAL
107
107
  """
108
- if "vactual" not in self.tmc_com.tmc_registers:
108
+ vactual_reg = self.get_register("vactual")
109
+ if vactual_reg is None:
109
110
  raise TmcMotionControlException("TMC register VACTUAL not available")
110
- self.tmc_com.tmc_registers["vactual"].modify("vactual", vactual)
111
+ vactual_reg.modify("vactual", vactual)
111
112
 
112
113
  def set_vactual_dur(
113
114
  self,
@@ -5,7 +5,22 @@ Register module
5
5
  """
6
6
 
7
7
  from .._tmc_logger import TmcLogger, Loglevel
8
- from ..com._tmc_com import TmcCom
8
+
9
+
10
+ class TmcCom:
11
+ """Stub for type hints"""
12
+
13
+ def read_int(self, address: int):
14
+ """Stub for type hints"""
15
+ raise NotImplementedError
16
+
17
+ def write_reg(self, address: int, data: int):
18
+ """Stub for type hints"""
19
+ raise NotImplementedError
20
+
21
+ def write_reg_check(self, address: int, data: int):
22
+ """Stub for type hints"""
23
+ raise NotImplementedError
9
24
 
10
25
 
11
26
  class TmcReg:
@@ -122,6 +122,13 @@ class Tmc220x(TmcStepperDriver):
122
122
 
123
123
  self.tmc_com.ifcnt = self.ifcnt
124
124
 
125
+ # Register callback for submodules to access registers
126
+ self.tmc_com.set_get_register_callback(self._get_register)
127
+ if self.tmc_mc is not None:
128
+ self.tmc_mc.set_get_register_callback(self._get_register)
129
+ if self.tmc_ec is not None:
130
+ self.tmc_ec.set_get_register_callback(self._get_register)
131
+
125
132
  self.clear_gstat()
126
133
  if self.tmc_mc is not None:
127
134
  self.read_steps_per_rev()
@@ -143,6 +150,17 @@ class Tmc220x(TmcStepperDriver):
143
150
  """set deinitialize to true"""
144
151
  self._deinit_finished = True
145
152
 
153
+ def _get_register(self, name: str) -> TmcReg | None:
154
+ """Get register by name - callback for submodules
155
+
156
+ Args:
157
+ name: Register name (e.g. 'gconf', 'chopconf')
158
+
159
+ Returns:
160
+ Register object or None if not found
161
+ """
162
+ return getattr(self, name, None)
163
+
146
164
  # Tmc220x methods
147
165
  # ----------------------------
148
166
  def read_steps_per_rev(self) -> int:
@@ -634,6 +652,4 @@ class Tmc220x(TmcStepperDriver):
634
652
  self.tmc_logger.log("---")
635
653
  self.tmc_logger.log("TEST COM")
636
654
 
637
- ioin = Ioin(self.tmc_com)
638
-
639
- return self.tmc_com.test_com(ioin.addr)
655
+ return self.tmc_com.test_com()
@@ -77,6 +77,8 @@ class Tmc2240(TmcStepperDriver, StallGuard):
77
77
  Defaults to None (messages are logged in the format
78
78
  '%(asctime)s - %(name)s - %(levelname)s - %(message)s').
79
79
  """
80
+ # pylint: disable=too-many-statements
81
+
80
82
  self.tmc_com: TmcCom | None = None
81
83
  self._pin_stallguard: int | None = None
82
84
  self._sg_callback: types.FunctionType | None = None
@@ -135,6 +137,13 @@ class Tmc2240(TmcStepperDriver, StallGuard):
135
137
 
136
138
  self.tmc_com.ifcnt = self.ifcnt
137
139
 
140
+ # Register callback for submodules to access registers
141
+ self.tmc_com.set_get_register_callback(self._get_register)
142
+ if self.tmc_mc is not None:
143
+ self.tmc_mc.set_get_register_callback(self._get_register)
144
+ if self.tmc_ec is not None:
145
+ self.tmc_ec.set_get_register_callback(self._get_register)
146
+
138
147
  self.clear_gstat()
139
148
  if self.tmc_mc is not None:
140
149
  self.read_steps_per_rev()
@@ -159,6 +168,17 @@ class Tmc2240(TmcStepperDriver, StallGuard):
159
168
  """set deinitialize to true"""
160
169
  self._deinit_finished = True
161
170
 
171
+ def _get_register(self, name: str) -> TmcReg | None:
172
+ """Get register by name - callback for submodules
173
+
174
+ Args:
175
+ name: Register name (e.g. 'gconf', 'chopconf')
176
+
177
+ Returns:
178
+ Register object or None if not found
179
+ """
180
+ return getattr(self, name, None)
181
+
162
182
  # Tmc224x methods
163
183
  # ----------------------------
164
184
  def read_steps_per_rev(self) -> int:
@@ -683,6 +703,4 @@ class Tmc2240(TmcStepperDriver, StallGuard):
683
703
  self.tmc_logger.log("---")
684
704
  self.tmc_logger.log("TEST COM")
685
705
 
686
- ioin = Ioin(self.tmc_com)
687
-
688
- return self.tmc_com.test_com(ioin.addr)
706
+ return self.tmc_com.test_com()
@@ -1,29 +0,0 @@
1
- """
2
- Enable Control base module
3
- """
4
-
5
- from abc import abstractmethod
6
- from .._tmc_logger import TmcLogger
7
-
8
-
9
- class TmcEnableControl:
10
- """Enable Control base class"""
11
-
12
- def __init__(self):
13
- """constructor"""
14
- self._tmc_logger: TmcLogger | None = None
15
-
16
- def init(self, tmc_logger: TmcLogger):
17
- """init: called by the Tmc class"""
18
- self._tmc_logger = tmc_logger
19
-
20
- def deinit(self):
21
- """destructor"""
22
-
23
- @abstractmethod
24
- def set_motor_enabled(self, en):
25
- """enables or disables the motor current output
26
-
27
- Args:
28
- en (bool): whether the motor current output should be enabled
29
- """
File without changes
File without changes
File without changes