PyTmcStepper 0.21.0__tar.gz → 0.21.1__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 (85) hide show
  1. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/PKG-INFO +14 -9
  2. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/README.md +7 -7
  3. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/pyproject.toml +10 -7
  4. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/PyTmcStepper.egg-info/PKG-INFO +14 -9
  5. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/PyTmcStepper.egg-info/SOURCES.txt +20 -1
  6. pytmcstepper-0.21.1/src/PyTmcStepper.egg-info/requires.txt +24 -0
  7. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_step_pio.py +81 -82
  8. pytmcstepper-0.21.1/src/tmc_driver/motion_control/_tmc_mc_step_pio_base.py +74 -0
  9. pytmcstepper-0.21.1/src/tmc_driver/motion_control/_tmc_mc_step_pio_circuitpython.py +101 -0
  10. pytmcstepper-0.21.1/src/tmc_driver/motion_control/_tmc_mc_step_pio_micropython.py +107 -0
  11. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/platform_utils.py +8 -0
  12. pytmcstepper-0.21.1/tests/test_gpiozero.py +118 -0
  13. pytmcstepper-0.21.1/tests/test_tmc2209.py +143 -0
  14. pytmcstepper-0.21.1/tests/test_tmc2240.py +152 -0
  15. pytmcstepper-0.21.1/tests/test_tmc_com_spi.py +32 -0
  16. pytmcstepper-0.21.1/tests/test_tmc_com_uart.py +43 -0
  17. pytmcstepper-0.21.1/tests/test_tmc_ec_pin.py +26 -0
  18. pytmcstepper-0.21.1/tests/test_tmc_imports.py +46 -0
  19. pytmcstepper-0.21.1/tests/test_tmc_math.py +68 -0
  20. pytmcstepper-0.21.1/tests/test_tmc_modules.py +233 -0
  21. pytmcstepper-0.21.1/tests/test_tmc_move_intramp.py +132 -0
  22. pytmcstepper-0.21.1/tests/test_tmc_move_stepdir.py +110 -0
  23. pytmcstepper-0.21.1/tests/test_tmc_move_steppwmdir.py +93 -0
  24. pytmcstepper-0.21.1/tests/test_tmc_move_stepreg.py +146 -0
  25. pytmcstepper-0.21.1/tests/test_tmc_move_vactual.py +120 -0
  26. pytmcstepper-0.21.1/tests/test_tmc_set_current.py +204 -0
  27. pytmcstepper-0.21.1/tests/test_tmc_stallguard.py +138 -0
  28. pytmcstepper-0.21.0/src/PyTmcStepper.egg-info/requires.txt +0 -16
  29. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/LICENSE +0 -0
  30. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/setup.cfg +0 -0
  31. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  32. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  33. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/__init__.py +0 -0
  34. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_exceptions.py +0 -0
  35. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_math.py +0 -0
  36. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_stallguard.py +0 -0
  37. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_stepperdriver.py +0 -0
  38. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_validation.py +0 -0
  39. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/_tmc_xxxx.py +0 -0
  40. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/__init__.py +0 -0
  41. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com.py +0 -0
  42. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  43. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_spi_base.py +0 -0
  44. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_spi_circuitpython.py +0 -0
  45. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
  46. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
  47. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  48. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_uart_base.py +0 -0
  49. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_uart_circuitpython.py +0 -0
  50. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -0
  51. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/enable_control/__init__.py +0 -0
  52. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  53. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  54. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  55. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/__init__.py +0 -0
  56. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  57. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +0 -0
  58. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +0 -0
  59. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
  60. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  61. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +0 -0
  62. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/__init__.py +0 -0
  63. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  64. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
  65. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc224x_reg.py +0 -0
  66. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc5160_reg.py +0 -0
  67. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc_reg.py +0 -0
  68. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/reg/_tmc_shared_regs.py +0 -0
  69. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_2208.py +0 -0
  70. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_2209.py +0 -0
  71. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_220x.py +0 -0
  72. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_2240.py +0 -0
  73. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_5160.py +0 -0
  74. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/__init__.py +0 -0
  75. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +0 -0
  76. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_circuitpython.py +0 -0
  77. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
  78. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +0 -0
  79. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
  80. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
  81. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
  82. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_logger/__init__.py +0 -0
  83. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_logger/_tmc_logger_base.py +0 -0
  84. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +0 -0
  85. {pytmcstepper-0.21.0 → pytmcstepper-0.21.1}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.21.0
3
+ Version: 0.21.1
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
@@ -17,7 +17,12 @@ Classifier: Topic :: System :: Hardware :: Hardware Drivers
17
17
  Requires-Python: >=3.10
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
- Requires-Dist: pyserial
20
+ Provides-Extra: uart
21
+ Requires-Dist: pyserial; extra == "uart"
22
+ Provides-Extra: spi
23
+ Requires-Dist: spidev; extra == "spi"
24
+ Provides-Extra: ftdi
25
+ Requires-Dist: pyftdi; extra == "ftdi"
21
26
  Provides-Extra: raspberry-pi
22
27
  Requires-Dist: RPi.GPIO; extra == "raspberry-pi"
23
28
  Provides-Extra: raspberry-pi5
@@ -104,19 +109,19 @@ The following table shows the supported boards and which libraries for GPIO acce
104
109
 
105
110
  Library | Installation Parameter | Boards
106
111
  ----------- | ------------------------- | -----------
107
- RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
108
- gpiozero | RASPBERRY_PI5 | Pi5
109
- Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
110
- periphery | LUCKFOX_PICO | Luckfox Pico
111
- OPi.GPIO | ORANGE_PI | Orange Pi
112
- pyftdi | - | Windows/Linux
112
+ RPi.GPIO | raspberry_pi | Pi4, Pi3 etc.
113
+ gpiozero | raspberry_pi5 | Pi5
114
+ Jetson.GPIO | nvidia_jetson | Nvidia Jetson
115
+ periphery | luckfox_pico | Luckfox Pico
116
+ OPi.GPIO | orange_pi | Orange Pi
117
+ pyftdi | ftdi | Windows/Linux
113
118
  machine | - | Pico, Pico2, ESP32, etc.
114
119
 
115
120
  Those libraries are needed for this library to work. You can either install the correct library yourself.
116
121
  You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
117
122
 
118
123
  ```shell
119
- pip3 install PyTmcStepper[RASPBERRY_PI]
124
+ pip3 install PyTmcStepper[raspberry_pi, uart]
120
125
  ```
121
126
 
122
127
  ## Driver Support
@@ -72,19 +72,19 @@ The following table shows the supported boards and which libraries for GPIO acce
72
72
 
73
73
  Library | Installation Parameter | Boards
74
74
  ----------- | ------------------------- | -----------
75
- RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
76
- gpiozero | RASPBERRY_PI5 | Pi5
77
- Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
78
- periphery | LUCKFOX_PICO | Luckfox Pico
79
- OPi.GPIO | ORANGE_PI | Orange Pi
80
- pyftdi | - | Windows/Linux
75
+ RPi.GPIO | raspberry_pi | Pi4, Pi3 etc.
76
+ gpiozero | raspberry_pi5 | Pi5
77
+ Jetson.GPIO | nvidia_jetson | Nvidia Jetson
78
+ periphery | luckfox_pico | Luckfox Pico
79
+ OPi.GPIO | orange_pi | Orange Pi
80
+ pyftdi | ftdi | Windows/Linux
81
81
  machine | - | Pico, Pico2, ESP32, etc.
82
82
 
83
83
  Those libraries are needed for this library to work. You can either install the correct library yourself.
84
84
  You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
85
85
 
86
86
  ```shell
87
- pip3 install PyTmcStepper[RASPBERRY_PI]
87
+ pip3 install PyTmcStepper[raspberry_pi, uart]
88
88
  ```
89
89
 
90
90
  ## Driver Support
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyTmcStepper"
7
- version = "0.21.0"
7
+ version = "0.21.1"
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"
@@ -20,18 +20,20 @@ classifiers = [
20
20
  "Natural Language :: English",
21
21
  "Topic :: System :: Hardware :: Hardware Drivers",
22
22
  ]
23
- dependencies = ["pyserial"]
24
23
 
25
24
  [project.urls]
26
25
  Homepage = "https://github.com/Chr157i4n/PyTmcStepper"
27
26
  "Bug Tracker" = "https://github.com/Chr157i4n/PyTmcStepper/issues"
28
27
 
29
28
  [project.optional-dependencies]
30
- RASPBERRY_PI = ["RPi.GPIO"]
31
- RASPBERRY_PI5 = ["gpiozero"]
32
- NVIDIA_JETSON = ["Jetson.GPIO"]
33
- LUCKFOX_PICO = ["python-periphery"]
34
- ORANGE_PI = ["OPi.GPIO"]
29
+ uart = ["pyserial"]
30
+ spi = ["spidev"]
31
+ ftdi = ["pyftdi"]
32
+ raspberry_pi = ["RPi.GPIO"]
33
+ raspberry_pi5 = ["gpiozero"]
34
+ nvidia_jetson = ["Jetson.GPIO"]
35
+ luckfox_pico = ["python-periphery"]
36
+ orange_pi = ["OPi.GPIO"]
35
37
 
36
38
  [tool.setuptools.packages.find]
37
39
  where = ["src"]
@@ -58,6 +60,7 @@ omit = [
58
60
  "*_ftdi.py",
59
61
  "*_periphery.py",
60
62
  "*_pio.py",
63
+ "*_pio*.py",
61
64
  ]
62
65
  exclude_lines = [
63
66
  "pragma: no cover",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.21.0
3
+ Version: 0.21.1
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
@@ -17,7 +17,12 @@ Classifier: Topic :: System :: Hardware :: Hardware Drivers
17
17
  Requires-Python: >=3.10
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
- Requires-Dist: pyserial
20
+ Provides-Extra: uart
21
+ Requires-Dist: pyserial; extra == "uart"
22
+ Provides-Extra: spi
23
+ Requires-Dist: spidev; extra == "spi"
24
+ Provides-Extra: ftdi
25
+ Requires-Dist: pyftdi; extra == "ftdi"
21
26
  Provides-Extra: raspberry-pi
22
27
  Requires-Dist: RPi.GPIO; extra == "raspberry-pi"
23
28
  Provides-Extra: raspberry-pi5
@@ -104,19 +109,19 @@ The following table shows the supported boards and which libraries for GPIO acce
104
109
 
105
110
  Library | Installation Parameter | Boards
106
111
  ----------- | ------------------------- | -----------
107
- RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
108
- gpiozero | RASPBERRY_PI5 | Pi5
109
- Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
110
- periphery | LUCKFOX_PICO | Luckfox Pico
111
- OPi.GPIO | ORANGE_PI | Orange Pi
112
- pyftdi | - | Windows/Linux
112
+ RPi.GPIO | raspberry_pi | Pi4, Pi3 etc.
113
+ gpiozero | raspberry_pi5 | Pi5
114
+ Jetson.GPIO | nvidia_jetson | Nvidia Jetson
115
+ periphery | luckfox_pico | Luckfox Pico
116
+ OPi.GPIO | orange_pi | Orange Pi
117
+ pyftdi | ftdi | Windows/Linux
113
118
  machine | - | Pico, Pico2, ESP32, etc.
114
119
 
115
120
  Those libraries are needed for this library to work. You can either install the correct library yourself.
116
121
  You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
117
122
 
118
123
  ```shell
119
- pip3 install PyTmcStepper[RASPBERRY_PI]
124
+ pip3 install PyTmcStepper[raspberry_pi, uart]
120
125
  ```
121
126
 
122
127
  ## Driver Support
@@ -39,6 +39,9 @@ src/tmc_driver/motion_control/_tmc_mc.py
39
39
  src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py
40
40
  src/tmc_driver/motion_control/_tmc_mc_step_dir.py
41
41
  src/tmc_driver/motion_control/_tmc_mc_step_pio.py
42
+ src/tmc_driver/motion_control/_tmc_mc_step_pio_base.py
43
+ src/tmc_driver/motion_control/_tmc_mc_step_pio_circuitpython.py
44
+ src/tmc_driver/motion_control/_tmc_mc_step_pio_micropython.py
42
45
  src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py
43
46
  src/tmc_driver/motion_control/_tmc_mc_step_reg.py
44
47
  src/tmc_driver/motion_control/_tmc_mc_vactual.py
@@ -60,4 +63,20 @@ src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py
60
63
  src/tmc_driver/tmc_logger/__init__.py
61
64
  src/tmc_driver/tmc_logger/_tmc_logger_base.py
62
65
  src/tmc_driver/tmc_logger/_tmc_logger_cpython.py
63
- src/tmc_driver/tmc_logger/_tmc_logger_micropython.py
66
+ src/tmc_driver/tmc_logger/_tmc_logger_micropython.py
67
+ tests/test_gpiozero.py
68
+ tests/test_tmc2209.py
69
+ tests/test_tmc2240.py
70
+ tests/test_tmc_com_spi.py
71
+ tests/test_tmc_com_uart.py
72
+ tests/test_tmc_ec_pin.py
73
+ tests/test_tmc_imports.py
74
+ tests/test_tmc_math.py
75
+ tests/test_tmc_modules.py
76
+ tests/test_tmc_move_intramp.py
77
+ tests/test_tmc_move_stepdir.py
78
+ tests/test_tmc_move_steppwmdir.py
79
+ tests/test_tmc_move_stepreg.py
80
+ tests/test_tmc_move_vactual.py
81
+ tests/test_tmc_set_current.py
82
+ tests/test_tmc_stallguard.py
@@ -0,0 +1,24 @@
1
+
2
+ [ftdi]
3
+ pyftdi
4
+
5
+ [luckfox_pico]
6
+ python-periphery
7
+
8
+ [nvidia_jetson]
9
+ Jetson.GPIO
10
+
11
+ [orange_pi]
12
+ OPi.GPIO
13
+
14
+ [raspberry_pi]
15
+ RPi.GPIO
16
+
17
+ [raspberry_pi5]
18
+ gpiozero
19
+
20
+ [spi]
21
+ spidev
22
+
23
+ [uart]
24
+ pyserial
@@ -6,17 +6,18 @@
6
6
  # pyright: reportUndefinedVariable=false
7
7
  """
8
8
  STEP/DIR Motion Control module using PIO (Programmable I/O)
9
- for Raspberry Pi Pico (RP2040/RP2350) under MicroPython
9
+ for Raspberry Pi Pico (RP2040/RP2350) under MicroPython and CircuitPython
10
10
 
11
11
  This module provides precise step pulse generation using the PIO hardware
12
12
  of the RP2040/RP2350 microcontroller. The PIO generates step pulses with
13
13
  consistent timing, independent of Python execution.
14
+
15
+ Supports both MicroPython (using rp2 module) and CircuitPython (using
16
+ rp2pio and adafruit_pioasm modules).
14
17
  """
15
18
 
16
19
  import time
17
20
  import math
18
- from machine import Pin
19
- import rp2
20
21
 
21
22
  from ._tmc_mc import (
22
23
  TmcMotionControl,
@@ -29,7 +30,14 @@ from ..tmc_logger import TmcLogger, Loglevel
29
30
  from ..tmc_gpio import GpioMode
30
31
  from .. import tmc_gpio
31
32
  from .._tmc_exceptions import TmcMotionControlException
32
- from ..platform_utils import get_time_us
33
+ from ..platform_utils import sleep_us, MICROPYTHON, CIRCUITPYTHON
34
+ from ._tmc_mc_step_pio_base import BasePioWrapper, PIO_MAGIC_PATTERN
35
+
36
+ # Import platform-specific PIO wrapper
37
+ if MICROPYTHON:
38
+ from ._tmc_mc_step_pio_micropython import MicroPythonPioWrapper
39
+ elif CIRCUITPYTHON:
40
+ from ._tmc_mc_step_pio_circuitpython import CircuitPythonPioWrapper
33
41
 
34
42
 
35
43
  class PioData:
@@ -45,12 +53,12 @@ class PioData:
45
53
  self.steps = min(steps, 0xFFFF)
46
54
  self.delay = min(delay, 0xFFFF)
47
55
 
48
- def put(self, sm: rp2.StateMachine, pio_freq=2000):
56
+ def put(self, sm: BasePioWrapper, pio_freq=2000):
49
57
  """
50
58
  Put the steps and delay into the PIO state machine FIFO
51
59
 
52
60
  Args:
53
- sm (rp2.StateMachine): The PIO state machine
61
+ sm (BasePioWrapper): The PIO state machine wrapper
54
62
  pio_freq (int): Frequency of the PIO state machine in Hz
55
63
  """
56
64
  if self.steps == 0:
@@ -67,39 +75,6 @@ class PioData:
67
75
  sm.put(data)
68
76
 
69
77
 
70
- @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
71
- def step_pulse_pio():
72
- wrap_target()
73
- # Pull data (steps << 16 | delay) from FIFO into OSR
74
- pull(block)
75
- # Shift right 16 bits and move to Y (step count)
76
- out(y, 16)
77
- # Move remaining 16 bits to ISR (delay value)
78
- out(isr, 16)
79
-
80
- # Main loop - repeat for Y toggle cycles
81
- label("step_loop")
82
-
83
- # Set pin high for one cycle only
84
- set(pins, 1) # pyright: ignore[reportCallIssue]
85
- # Set pin low immediately (no delay while high)
86
- set(pins, 0) # pyright: ignore[reportCallIssue]
87
-
88
- # Trigger IRQ 0 to notify controller about step
89
- irq(0)
90
-
91
- # Delay countdown - restore delay from ISR to X, then count down
92
- mov(x, isr)
93
- label("low_delay")
94
- jmp(x_dec, "low_delay")
95
-
96
- # Decrement remaining steps (Y) and repeat if not zero
97
- jmp(y_dec, "step_loop")
98
-
99
- # All steps done, wrap to beginning for next data
100
- wrap()
101
-
102
-
103
78
  class TmcMotionControlStepPio(TmcMotionControl):
104
79
  """STEP/DIR Motion Control class using PIO
105
80
 
@@ -163,16 +138,16 @@ class TmcMotionControlStepPio(TmcMotionControl):
163
138
 
164
139
  def __init__(
165
140
  self,
166
- pin_step: int,
167
- pin_dir: int | None,
141
+ pin_step,
142
+ pin_dir=None,
168
143
  pio_id: int = 0,
169
144
  sm_id: int = 0,
170
145
  ):
171
146
  """constructor
172
147
 
173
148
  Args:
174
- pin_step: GPIO pin number for step signal
175
- pin_dir: GPIO pin number for direction signal (None if not used)
149
+ pin_step: GPIO pin for step signal (int for MicroPython, board.GPxx for CircuitPython)
150
+ pin_dir: GPIO pin for direction signal (None if not used)
176
151
  pio_id: PIO block to use (0 or 1), default 0
177
152
  sm_id: State machine ID within the PIO block (0-3), default 0
178
153
  """
@@ -182,9 +157,10 @@ class TmcMotionControlStepPio(TmcMotionControl):
182
157
  self._pio_id = pio_id
183
158
  self._sm_id = sm_id
184
159
 
185
- self._sm: rp2.StateMachine | None = None
160
+ self._sm: BasePioWrapper
186
161
  self._pio_frequency: int = 20000 # PIO frequency in Hz
187
162
  self._steps_completed: int = 0
163
+ self._total_steps_sent: int = 0 # Track total steps sent for FIFO completion
188
164
  self._sqrt_twoa: float = 1.0
189
165
  self._step_interval: int = 0
190
166
  self._min_pulse_width: int = 1
@@ -213,31 +189,37 @@ class TmcMotionControlStepPio(TmcMotionControl):
213
189
 
214
190
  def _init_pio(self):
215
191
  """Initialize or reinitialize the PIO state machine"""
216
- if self._sm is not None:
192
+ if hasattr(self, "_sm") and self._sm is not None:
217
193
  self._sm.active(0)
218
-
219
- # Fixed high frequency - speed control via delay values
220
- self._sm = rp2.StateMachine(
221
- self._pio_id * 4 + self._sm_id,
222
- step_pulse_pio,
223
- freq=self._pio_frequency,
224
- set_base=Pin(self._pin_step),
225
- )
226
-
227
- # Register IRQ handler once for step counting
228
- self._sm.irq(handler=self.pio_irq_handler)
194
+ self._sm.deinit()
195
+
196
+ # Create platform-specific PIO wrapper
197
+ if MICROPYTHON:
198
+ self._sm = MicroPythonPioWrapper(
199
+ self._pio_id,
200
+ self._sm_id,
201
+ self._pin_step,
202
+ self._pio_frequency,
203
+ )
204
+ # Register IRQ handler for step counting (MicroPython only)
205
+ self._sm.irq(handler=self.pio_irq_handler)
206
+ elif CIRCUITPYTHON:
207
+ self._sm = CircuitPythonPioWrapper(
208
+ self._pio_id,
209
+ self._sm_id,
210
+ self._pin_step,
211
+ self._pio_frequency,
212
+ )
213
+ # CircuitPython does not support IRQ handlers
229
214
 
230
215
  self._sm.active(1)
231
216
 
232
217
  def deinit(self):
233
218
  """destructor"""
234
- if self._sm is not None:
219
+ if hasattr(self, "_sm") and self._sm is not None:
235
220
  self._sm.active(0)
236
- self._sm = None
237
-
238
- sm_key = (self._pio_id, self._sm_id)
239
- if sm_key in TmcMotionControlStepPio._used_state_machines:
240
- del TmcMotionControlStepPio._used_state_machines[sm_key]
221
+ self._sm.deinit()
222
+ del self._sm
241
223
 
242
224
  if hasattr(self, "_pin_dir") and self._pin_dir is not None:
243
225
  tmc_gpio.tmc_gpio.gpio_cleanup(self._pin_dir)
@@ -256,10 +238,16 @@ class TmcMotionControlStepPio(TmcMotionControl):
256
238
  # Restart the state machine to reset its state
257
239
  self._sm.active(0)
258
240
  # Brief delay to ensure clean stop
259
- time.sleep_ms(1)
241
+ if MICROPYTHON:
242
+ time.sleep_ms(1)
243
+ else:
244
+ time.sleep(0.001)
245
+ # Drain RX FIFO before restarting
246
+ self._drain_rx_fifo()
260
247
  self._sm.restart()
261
248
  self._sm.active(1)
262
249
  self._steps_completed = 0
250
+ self._total_steps_sent = 0
263
251
 
264
252
  def _drain_rx_fifo(self):
265
253
  """Drain the RX FIFO to clear old data"""
@@ -308,6 +296,8 @@ class TmcMotionControlStepPio(TmcMotionControl):
308
296
  if steps == 0:
309
297
  return StopMode.NO
310
298
 
299
+ self._stop = StopMode.NO
300
+
311
301
  # Set direction based on steps
312
302
  self.set_direction(Direction.CW if steps > 0 else Direction.CCW)
313
303
  steps = abs(steps)
@@ -349,7 +339,7 @@ class TmcMotionControlStepPio(TmcMotionControl):
349
339
 
350
340
  # Wait for FIFO space (max 4 entries)
351
341
  while self._sm.tx_fifo() >= 4:
352
- time.sleep_us(100)
342
+ sleep_us(100)
353
343
  if self._stop != StopMode.NO:
354
344
  break
355
345
 
@@ -415,43 +405,52 @@ class TmcMotionControlStepPio(TmcMotionControl):
415
405
  pio_data.put(self._sm, self._pio_frequency)
416
406
 
417
407
  steps_sent += block_steps
408
+ self._total_steps_sent += block_steps
418
409
 
419
- # Wait for all steps to complete
410
+ # Wait for all steps to complete using RX FIFO completion signals
411
+ # The PIO pushes magic pattern to RX FIFO after each block completes
420
412
  self._tmc_logger.log(
421
- f"Waiting for completion: sent={steps_sent}, target={steps}, stopmode={self._stop}",
413
+ f"Waiting for completion: sent={steps_sent} | target={steps} | stopmode={self._stop}",
422
414
  Loglevel.MOVEMENT,
423
415
  )
416
+
424
417
  timeout_counter = 0
425
- while self._steps_completed < steps and self._stop == StopMode.NO:
426
- time.sleep_us(100)
427
- timeout_counter += 1
428
- if timeout_counter % 1000 == 0: # Every second
418
+
419
+ while self._stop == StopMode.NO:
420
+ has_results = self._sm.rx_fifo() > 0
421
+
422
+ # Check for completion signals in RX FIFO
423
+ if has_results:
424
+ self._sm.get() # Read and discard the value
429
425
  self._tmc_logger.log(
430
- f"Still waiting: completed={self._steps_completed}/{steps}, sent={steps_sent}",
426
+ f"FIFO received completion signal",
431
427
  Loglevel.MOVEMENT,
432
428
  )
433
- if timeout_counter > 10000: # 10 second timeout
429
+ break
430
+ else:
431
+ sleep_us(100)
432
+ timeout_counter += 1
433
+
434
+ if timeout_counter % 10000 == 0 and timeout_counter > 0: # Every second
434
435
  self._tmc_logger.log(
435
- f"TIMEOUT! completed={self._steps_completed}/{steps}",
436
+ f"Still waiting: completed={self._steps_completed} | sent={self._total_steps_sent} | target={steps}",
437
+ Loglevel.MOVEMENT,
438
+ )
439
+ if timeout_counter > 100000: # 10 second timeout
440
+ self._tmc_logger.log(
441
+ f"TIMEOUT! completed={self._steps_completed} | sent={self._total_steps_sent} | target={steps}",
436
442
  Loglevel.ERROR,
437
443
  )
438
444
  break
439
445
 
440
446
  self._tmc_logger.log(
441
- f"Movement complete: completed={self._steps_completed}, target={steps}",
447
+ f"Movement complete: target_steps={steps} | completed_steps={self._steps_completed}",
442
448
  Loglevel.MOVEMENT,
443
449
  )
444
450
 
445
- # Don't unregister IRQ handler - it stays registered from _init_pio()
446
- # self._sm.irq(handler=None)
447
451
  self._movement_phase = MovementPhase.STANDSTILL
448
452
 
449
- if self._stop != StopMode.NO:
450
- stop_mode = self._stop
451
- self._stop = StopMode.NO
452
- return stop_mode
453
-
454
- return StopMode.NO
453
+ return self._stop
455
454
 
456
455
  def stop(self, stop_mode: StopMode = StopMode.HARDSTOP):
457
456
  """stop the current movement
@@ -0,0 +1,74 @@
1
+ """
2
+ Base class for PIO state machine wrappers
3
+
4
+ This module provides the abstract base class that defines the interface
5
+ for platform-specific PIO implementations (MicroPython and CircuitPython).
6
+ """
7
+
8
+ from abc import abstractmethod
9
+
10
+ # Magic pattern used by PIO to signal block completion
11
+ # Controller waits for this value in RX FIFO
12
+ PIO_MAGIC_PATTERN = 0x1234
13
+
14
+
15
+ class BasePioWrapper:
16
+ """Base class for PIO state machine wrappers
17
+
18
+ Defines the common interface for MicroPython and CircuitPython
19
+ PIO state machine implementations.
20
+ """
21
+
22
+ @abstractmethod
23
+ def put(self, data: int):
24
+ """Put data into TX FIFO
25
+
26
+ Args:
27
+ data: 32-bit data word to send to PIO
28
+ """
29
+
30
+ @abstractmethod
31
+ def get(self) -> int:
32
+ """Get data from RX FIFO
33
+
34
+ Returns:
35
+ 32-bit data word received from PIO
36
+ """
37
+
38
+ @abstractmethod
39
+ def active(self, value: int):
40
+ """Set state machine active state
41
+
42
+ Args:
43
+ value: 0 to stop, 1 to run
44
+ """
45
+
46
+ @abstractmethod
47
+ def restart(self):
48
+ """Restart the state machine"""
49
+
50
+ @abstractmethod
51
+ def tx_fifo(self) -> int:
52
+ """Get number of entries in TX FIFO
53
+
54
+ Returns:
55
+ Number of entries waiting to be processed
56
+ """
57
+
58
+ @abstractmethod
59
+ def rx_fifo(self) -> int:
60
+ """Get number of entries in RX FIFO
61
+
62
+ Returns:
63
+ Number of entries available to read
64
+ """
65
+
66
+ def irq(self, handler=None):
67
+ """Set IRQ handler (MicroPython only, no-op on CircuitPython)
68
+
69
+ Args:
70
+ handler: Callback function for IRQ events, or None to disable
71
+ """
72
+
73
+ def deinit(self):
74
+ """Deinitialize the state machine"""