PyTmcStepper 0.15.0__py3-none-any.whl
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.
- pytmcstepper-0.15.0.dist-info/METADATA +338 -0
- pytmcstepper-0.15.0.dist-info/RECORD +56 -0
- pytmcstepper-0.15.0.dist-info/WHEEL +5 -0
- pytmcstepper-0.15.0.dist-info/licenses/LICENSE +683 -0
- pytmcstepper-0.15.0.dist-info/top_level.txt +1 -0
- tmc_driver/__init__.py +96 -0
- tmc_driver/_tmc_exceptions.py +21 -0
- tmc_driver/_tmc_math.py +122 -0
- tmc_driver/_tmc_stallguard.py +340 -0
- tmc_driver/_tmc_stepperdriver.py +210 -0
- tmc_driver/_tmc_validation.py +29 -0
- tmc_driver/_tmc_xxxx.py +489 -0
- tmc_driver/com/__init__.py +64 -0
- tmc_driver/com/_tmc_com.py +148 -0
- tmc_driver/com/_tmc_com_spi.py +81 -0
- tmc_driver/com/_tmc_com_spi_base.py +159 -0
- tmc_driver/com/_tmc_com_spi_ftdi.py +48 -0
- tmc_driver/com/_tmc_com_spi_micropython.py +99 -0
- tmc_driver/com/_tmc_com_uart.py +113 -0
- tmc_driver/com/_tmc_com_uart_base.py +386 -0
- tmc_driver/com/_tmc_com_uart_micropython.py +115 -0
- tmc_driver/enable_control/__init__.py +55 -0
- tmc_driver/enable_control/_tmc_ec.py +59 -0
- tmc_driver/enable_control/_tmc_ec_pin.py +48 -0
- tmc_driver/enable_control/_tmc_ec_toff.py +30 -0
- tmc_driver/motion_control/__init__.py +111 -0
- tmc_driver/motion_control/_tmc_mc.py +280 -0
- tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +218 -0
- tmc_driver/motion_control/_tmc_mc_step_dir.py +415 -0
- tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +78 -0
- tmc_driver/motion_control/_tmc_mc_step_reg.py +36 -0
- tmc_driver/motion_control/_tmc_mc_vactual.py +221 -0
- tmc_driver/platform_utils.py +13 -0
- tmc_driver/reg/__init__.py +0 -0
- tmc_driver/reg/_tmc2209_reg.py +55 -0
- tmc_driver/reg/_tmc220x_reg.py +261 -0
- tmc_driver/reg/_tmc224x_reg.py +414 -0
- tmc_driver/reg/_tmc5160_reg.py +526 -0
- tmc_driver/reg/_tmc_reg.py +202 -0
- tmc_driver/reg/_tmc_shared_regs.py +314 -0
- tmc_driver/tmc_2208.py +17 -0
- tmc_driver/tmc_2209.py +75 -0
- tmc_driver/tmc_220x.py +383 -0
- tmc_driver/tmc_2240.py +340 -0
- tmc_driver/tmc_5160.py +344 -0
- tmc_driver/tmc_gpio/__init__.py +101 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +106 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +162 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +135 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +108 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +87 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +182 -0
- tmc_driver/tmc_logger/__init__.py +15 -0
- tmc_driver/tmc_logger/_tmc_logger_base.py +111 -0
- tmc_driver/tmc_logger/_tmc_logger_cpython.py +155 -0
- tmc_driver/tmc_logger/_tmc_logger_micropython.py +52 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=unused-import
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Register module
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ..tmc_logger import TmcLogger, Loglevel
|
|
9
|
+
from ..com._tmc_com import TmcCom
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TmcRegField:
|
|
13
|
+
"""Register field class"""
|
|
14
|
+
|
|
15
|
+
# pylint: disable=too-many-arguments
|
|
16
|
+
# pylint: disable=too-many-positional-arguments
|
|
17
|
+
# pylint: disable=too-few-public-methods
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
name: str,
|
|
22
|
+
pos: int,
|
|
23
|
+
mask: int,
|
|
24
|
+
reg_class: type,
|
|
25
|
+
conv_func,
|
|
26
|
+
unit: str,
|
|
27
|
+
clear_value: int | None = None,
|
|
28
|
+
signed: bool = False,
|
|
29
|
+
):
|
|
30
|
+
"""Constructor
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name (str): field name
|
|
34
|
+
pos (int): bit position
|
|
35
|
+
mask (int): bit mask
|
|
36
|
+
reg_class (type): type of the field value
|
|
37
|
+
conv_func: conversion function name (optional)
|
|
38
|
+
unit (str): unit string for display
|
|
39
|
+
clear_value (int|None): value to set when clearing (optional)
|
|
40
|
+
signed (bool): whether the field is signed (two's complement)
|
|
41
|
+
"""
|
|
42
|
+
self.name = name
|
|
43
|
+
self.pos = pos
|
|
44
|
+
self.mask = mask
|
|
45
|
+
self.reg_class = reg_class
|
|
46
|
+
self.conv_func = conv_func
|
|
47
|
+
self.unit = unit
|
|
48
|
+
self.clear_value = clear_value
|
|
49
|
+
self.signed = signed
|
|
50
|
+
|
|
51
|
+
def get_bit_width(self) -> int:
|
|
52
|
+
"""Get the bit width of this field based on the mask"""
|
|
53
|
+
width = 0
|
|
54
|
+
mask = self.mask
|
|
55
|
+
while mask:
|
|
56
|
+
width += 1
|
|
57
|
+
mask >>= 1
|
|
58
|
+
return width
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class TmcReg:
|
|
62
|
+
"""Register class"""
|
|
63
|
+
|
|
64
|
+
ADDR: int
|
|
65
|
+
_REG_MAP: tuple[TmcRegField, ...] = ()
|
|
66
|
+
_data_int: int
|
|
67
|
+
_flags: dict | None
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def reg_map(self) -> tuple[TmcRegField, ...]:
|
|
71
|
+
"""returns the register map"""
|
|
72
|
+
return self._REG_MAP
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def data_int(self) -> int:
|
|
76
|
+
"""returns the raw register data as integer"""
|
|
77
|
+
return self._data_int
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def flags(self) -> dict | None:
|
|
81
|
+
"""returns the flags from the last read operation"""
|
|
82
|
+
return self._flags
|
|
83
|
+
|
|
84
|
+
def __init__(self, tmc_com: TmcCom):
|
|
85
|
+
"""Constructor"""
|
|
86
|
+
|
|
87
|
+
self._tmc_com = tmc_com
|
|
88
|
+
|
|
89
|
+
self.deserialise(0)
|
|
90
|
+
|
|
91
|
+
def deserialise(self, data: int):
|
|
92
|
+
"""Deserialises the register value
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
data (int): register value
|
|
96
|
+
"""
|
|
97
|
+
for reg in self._REG_MAP:
|
|
98
|
+
value = data >> reg.pos & reg.mask
|
|
99
|
+
# Convert from two's complement if signed
|
|
100
|
+
if reg.signed:
|
|
101
|
+
bit_width = reg.get_bit_width()
|
|
102
|
+
if value >= (1 << (bit_width - 1)):
|
|
103
|
+
value -= 1 << bit_width
|
|
104
|
+
setattr(self, reg.name, reg.reg_class(value))
|
|
105
|
+
|
|
106
|
+
def serialise(self) -> int:
|
|
107
|
+
"""Serialises the object to a register value
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
int: register value
|
|
111
|
+
"""
|
|
112
|
+
data = 0
|
|
113
|
+
|
|
114
|
+
for reg in self._REG_MAP:
|
|
115
|
+
value = getattr(self, reg.name)
|
|
116
|
+
int_value = int(value)
|
|
117
|
+
# Convert to two's complement if signed and negative
|
|
118
|
+
if reg.signed and int_value < 0:
|
|
119
|
+
bit_width = reg.get_bit_width()
|
|
120
|
+
int_value = (1 << bit_width) + int_value
|
|
121
|
+
data |= (int_value & reg.mask) << reg.pos
|
|
122
|
+
|
|
123
|
+
return data
|
|
124
|
+
|
|
125
|
+
def __str__(self) -> str:
|
|
126
|
+
"""string representation of this register"""
|
|
127
|
+
out_string = f"{self.__class__.__name__.upper()} | {hex(self.ADDR)} | {bin(self._data_int)}\n"
|
|
128
|
+
for reg in self._REG_MAP:
|
|
129
|
+
value = getattr(self, reg.name)
|
|
130
|
+
out_string += f" {reg.name:<20}{value:<10}"
|
|
131
|
+
if reg.conv_func is not None:
|
|
132
|
+
out_string += f"{getattr(self, reg.conv_func, '')} {reg.unit}"
|
|
133
|
+
out_string += "\n"
|
|
134
|
+
return out_string
|
|
135
|
+
|
|
136
|
+
def log(self, logger: TmcLogger | None):
|
|
137
|
+
"""log this register"""
|
|
138
|
+
if logger is None:
|
|
139
|
+
return
|
|
140
|
+
logger.log(str(self), Loglevel.INFO)
|
|
141
|
+
|
|
142
|
+
def read(self) -> tuple[int, dict | None]:
|
|
143
|
+
"""read this register"""
|
|
144
|
+
data, flags = self._tmc_com.read_int(self.ADDR)
|
|
145
|
+
|
|
146
|
+
self._data_int = data
|
|
147
|
+
self._flags = flags
|
|
148
|
+
|
|
149
|
+
self.deserialise(data)
|
|
150
|
+
return data, flags
|
|
151
|
+
|
|
152
|
+
def write(self):
|
|
153
|
+
"""write this register"""
|
|
154
|
+
data = self.serialise()
|
|
155
|
+
self._tmc_com.write_reg(self.ADDR, data)
|
|
156
|
+
|
|
157
|
+
def write_check(self):
|
|
158
|
+
"""write this register and checks that the write was successful"""
|
|
159
|
+
data = self.serialise()
|
|
160
|
+
self._tmc_com.write_reg_check(self.ADDR, data)
|
|
161
|
+
|
|
162
|
+
def modify(self, name: str, value):
|
|
163
|
+
"""modify a register value
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
name (str): register name
|
|
167
|
+
value: new value
|
|
168
|
+
"""
|
|
169
|
+
self.read()
|
|
170
|
+
setattr(self, name, value)
|
|
171
|
+
self.write_check()
|
|
172
|
+
|
|
173
|
+
def get(self, name: str):
|
|
174
|
+
"""get a register value
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
name (str): register name
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
value: register value
|
|
181
|
+
"""
|
|
182
|
+
self.read()
|
|
183
|
+
return getattr(self, name)
|
|
184
|
+
|
|
185
|
+
def clear(self):
|
|
186
|
+
"""clear this register (set to 0)"""
|
|
187
|
+
self._data_int = 0
|
|
188
|
+
for reg in self._REG_MAP:
|
|
189
|
+
if reg.clear_value is not None:
|
|
190
|
+
setattr(self, reg.name, reg.reg_class(reg.clear_value))
|
|
191
|
+
self.write_check()
|
|
192
|
+
|
|
193
|
+
def clear_verify(self) -> bool:
|
|
194
|
+
"""clear this register and verify that it was cleared"""
|
|
195
|
+
self.clear()
|
|
196
|
+
self.read()
|
|
197
|
+
for reg in self._REG_MAP:
|
|
198
|
+
if reg.clear_value is not None:
|
|
199
|
+
value = getattr(self, reg.name)
|
|
200
|
+
if int(value) != reg.reg_class(0):
|
|
201
|
+
return False
|
|
202
|
+
return True
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=wildcard-import
|
|
3
|
+
# pylint: disable=unused-wildcard-import
|
|
4
|
+
# pylint: disable=too-few-public-methods
|
|
5
|
+
"""
|
|
6
|
+
Register module with shared registers without implementation
|
|
7
|
+
Register only contain the register fields shared between all TMC chips
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from ._tmc_reg import TmcReg
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class GStat(TmcReg):
|
|
14
|
+
"""GSTAT register class stub"""
|
|
15
|
+
|
|
16
|
+
uv_cp: bool
|
|
17
|
+
drv_err: bool
|
|
18
|
+
reset: bool
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class IfCnt(TmcReg):
|
|
22
|
+
"""IFCNT register class stub"""
|
|
23
|
+
|
|
24
|
+
ifcnt: int
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Ioin(TmcReg):
|
|
28
|
+
"""IOIN register class stub"""
|
|
29
|
+
|
|
30
|
+
version: int
|
|
31
|
+
enn: bool
|
|
32
|
+
dir: bool
|
|
33
|
+
step: bool
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class DrvConf(TmcReg):
|
|
37
|
+
"""DRV_CONF register class stub"""
|
|
38
|
+
|
|
39
|
+
slope_control: int
|
|
40
|
+
current_range: int
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class GlobalScaler(TmcReg):
|
|
44
|
+
"""GLOBAL_SCALER register class stub"""
|
|
45
|
+
|
|
46
|
+
global_scaler: int
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class IHoldIRun(TmcReg):
|
|
50
|
+
"""IHOLD_IRUN register class stub"""
|
|
51
|
+
|
|
52
|
+
iholddelay: int
|
|
53
|
+
irun: int
|
|
54
|
+
ihold: int
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class TPowerDown(TmcReg):
|
|
58
|
+
"""TPowerDown register class stub"""
|
|
59
|
+
|
|
60
|
+
tpowerdown: int
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TStep(TmcReg):
|
|
64
|
+
"""TSTEP register class stub"""
|
|
65
|
+
|
|
66
|
+
tstep: int
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class TPwmThrs(TmcReg):
|
|
70
|
+
"""TPWMTHRS register class stub"""
|
|
71
|
+
|
|
72
|
+
tpwmthrs: int
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class TCoolThrs(TmcReg):
|
|
76
|
+
"""TCOOLTHRS register class stub"""
|
|
77
|
+
|
|
78
|
+
tcoolthrs: int
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class THigh(TmcReg):
|
|
82
|
+
"""THIGH register class stub"""
|
|
83
|
+
|
|
84
|
+
thigh: int
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ADCVSupplyAIN(TmcReg):
|
|
88
|
+
"""ADCV_SUPPLY_AIN register class stub"""
|
|
89
|
+
|
|
90
|
+
adc_ain: int
|
|
91
|
+
adc_vsupply: int
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ADCTemp(TmcReg):
|
|
95
|
+
"""ADC_TEMP register class stub"""
|
|
96
|
+
|
|
97
|
+
adc_temp: int
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class MsCnt(TmcReg):
|
|
101
|
+
"""MSCNT register class stub"""
|
|
102
|
+
|
|
103
|
+
mscnt: int
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ChopConf(TmcReg):
|
|
107
|
+
"""CHOPCONF register class stub"""
|
|
108
|
+
|
|
109
|
+
diss2vs: bool
|
|
110
|
+
diss2g: bool
|
|
111
|
+
dedge: bool
|
|
112
|
+
intpol: bool
|
|
113
|
+
mres: int
|
|
114
|
+
mres_ms: int
|
|
115
|
+
tbl: int
|
|
116
|
+
hend: int
|
|
117
|
+
hstrt: int
|
|
118
|
+
toff: int
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class GConf(TmcReg):
|
|
122
|
+
"""GCONF register class stub
|
|
123
|
+
|
|
124
|
+
has all fields of the GCONF register from all TMC chips
|
|
125
|
+
combined into one class. actual chips will only use a subset of these
|
|
126
|
+
fields.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
multistep_filt: bool
|
|
130
|
+
shaft: bool
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class VDcMin(TmcReg):
|
|
134
|
+
"""THIGH register class stub"""
|
|
135
|
+
|
|
136
|
+
vdcmin: int
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class RampMode(TmcReg):
|
|
140
|
+
"""THIGH register class stub"""
|
|
141
|
+
|
|
142
|
+
rampmode: int
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class XActual(TmcReg):
|
|
146
|
+
"""THIGH register class stub"""
|
|
147
|
+
|
|
148
|
+
xactual: int
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class VActual(TmcReg):
|
|
152
|
+
"""VACTUAL register class stub"""
|
|
153
|
+
|
|
154
|
+
vactual: int
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class VStart(TmcReg):
|
|
158
|
+
"""THIGH register class stub"""
|
|
159
|
+
|
|
160
|
+
vstart: int
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class A1(TmcReg):
|
|
164
|
+
"""THIGH register class stub"""
|
|
165
|
+
|
|
166
|
+
a1: int
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class V1(TmcReg):
|
|
170
|
+
"""THIGH register class stub"""
|
|
171
|
+
|
|
172
|
+
v1: int
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class AMax(TmcReg):
|
|
176
|
+
"""THIGH register class stub"""
|
|
177
|
+
|
|
178
|
+
amax: int
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class VMax(TmcReg):
|
|
182
|
+
"""THIGH register class stub"""
|
|
183
|
+
|
|
184
|
+
vmax: int
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class DMax(TmcReg):
|
|
188
|
+
"""THIGH register class stub"""
|
|
189
|
+
|
|
190
|
+
dmax: int
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class D1(TmcReg):
|
|
194
|
+
"""THIGH register class stub"""
|
|
195
|
+
|
|
196
|
+
d1: int
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class VStop(TmcReg):
|
|
200
|
+
"""THIGH register class stub"""
|
|
201
|
+
|
|
202
|
+
vstop: int
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class TZeroWait(TmcReg):
|
|
206
|
+
"""THIGH register class stub"""
|
|
207
|
+
|
|
208
|
+
tzerowait: int
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class XTarget(TmcReg):
|
|
212
|
+
"""THIGH register class stub"""
|
|
213
|
+
|
|
214
|
+
xtarget: int
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class SWMode(TmcReg):
|
|
218
|
+
"""THIGH register class stub"""
|
|
219
|
+
|
|
220
|
+
en_softstop: bool
|
|
221
|
+
sg_stop: bool
|
|
222
|
+
en_latch_encoder: bool
|
|
223
|
+
latch_r_inactive: bool
|
|
224
|
+
latch_r_active: bool
|
|
225
|
+
latch_l_inactive: bool
|
|
226
|
+
latch_l_active: bool
|
|
227
|
+
swap_lr: bool
|
|
228
|
+
pol_stop_r: bool
|
|
229
|
+
pol_stop_l: bool
|
|
230
|
+
stop_r_enable: bool
|
|
231
|
+
stop_l_enable: bool
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class RampStat(TmcReg):
|
|
235
|
+
"""THIGH register class stub"""
|
|
236
|
+
|
|
237
|
+
status_sg: bool
|
|
238
|
+
second_move: bool
|
|
239
|
+
t_zerowait_active: bool
|
|
240
|
+
vzero: bool
|
|
241
|
+
position_reached: bool
|
|
242
|
+
velocity_reached: bool
|
|
243
|
+
event_stop_sg: bool
|
|
244
|
+
event_stop_r: bool
|
|
245
|
+
event_stop_l: bool
|
|
246
|
+
status_latch_r: bool
|
|
247
|
+
status_latch_l: bool
|
|
248
|
+
status_stop_r: bool
|
|
249
|
+
status_stop_l: bool
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class PwmConf(TmcReg):
|
|
253
|
+
"""PWMCONF register class stub"""
|
|
254
|
+
|
|
255
|
+
pwm_lim: int
|
|
256
|
+
pwm_reg: int
|
|
257
|
+
freewheel: int
|
|
258
|
+
pwm_autograd: bool
|
|
259
|
+
pwm_autoscale: bool
|
|
260
|
+
pwm_freq: int
|
|
261
|
+
pwm_grad: int
|
|
262
|
+
pwm_ofs: int
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class CoolConf(TmcReg):
|
|
266
|
+
"""COOLCONF register class stub"""
|
|
267
|
+
|
|
268
|
+
seimin: bool
|
|
269
|
+
sedn: int
|
|
270
|
+
semax: int
|
|
271
|
+
seup: int
|
|
272
|
+
semin: int
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class DrvStatus(TmcReg):
|
|
276
|
+
"""DRVSTATUS register class stub"""
|
|
277
|
+
|
|
278
|
+
stst: bool
|
|
279
|
+
stealth: bool
|
|
280
|
+
cs_actual: int
|
|
281
|
+
olb: bool
|
|
282
|
+
ola: bool
|
|
283
|
+
s2vsb: bool
|
|
284
|
+
s2vsa: bool
|
|
285
|
+
s2gb: bool
|
|
286
|
+
s2ga: bool
|
|
287
|
+
ot: bool
|
|
288
|
+
otpw: bool
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
class SgThrs(TmcReg):
|
|
292
|
+
"""SGTHRS register class stub"""
|
|
293
|
+
|
|
294
|
+
sgthrs: int
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
class SgResult(TmcReg):
|
|
298
|
+
"""SGRESULT register class stub"""
|
|
299
|
+
|
|
300
|
+
sgresult: int
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class SgInd(TmcReg):
|
|
304
|
+
"""SGIND register class stub"""
|
|
305
|
+
|
|
306
|
+
sg_ind_2: int
|
|
307
|
+
sg_ind_1: int
|
|
308
|
+
sg_ind_0: int
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class LostSteps(TmcReg):
|
|
312
|
+
"""LOST_STEPS register class stub"""
|
|
313
|
+
|
|
314
|
+
lost_steps: int
|
tmc_driver/tmc_2208.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# pylint: disable=wildcard-import
|
|
2
|
+
# pylint: disable=unused-wildcard-import
|
|
3
|
+
"""Tmc2208 stepper driver module
|
|
4
|
+
|
|
5
|
+
this module has two different functions:
|
|
6
|
+
1. access register via tmc_com (UART, SPI)
|
|
7
|
+
2. Enable motor control via tmc_ec (TOFF, PIN)
|
|
8
|
+
3. move the motor via tmc_mc (STEP/DIR, STEP/REG, VACTUAL)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .tmc_220x import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Tmc2208(Tmc220x):
|
|
15
|
+
"""Tmc2208"""
|
|
16
|
+
|
|
17
|
+
DRIVER_FAMILY = "TMC2208"
|
tmc_driver/tmc_2209.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# pylint: disable=wildcard-import
|
|
2
|
+
# pylint: disable=unused-wildcard-import
|
|
3
|
+
# pylint: disable=too-many-arguments
|
|
4
|
+
# pylint: disable=too-many-positional-arguments
|
|
5
|
+
"""Tmc2209 stepper driver module
|
|
6
|
+
|
|
7
|
+
this module has two different functions:
|
|
8
|
+
1. access register via tmc_com (UART, SPI)
|
|
9
|
+
2. Enable motor control via tmc_ec (TOFF, PIN)
|
|
10
|
+
3. move the motor via tmc_mc (STEP/DIR, STEP/REG, VACTUAL)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .tmc_220x import *
|
|
14
|
+
from ._tmc_stallguard import StallGuard
|
|
15
|
+
from .reg._tmc2209_reg import *
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Tmc2209(Tmc220x, StallGuard):
|
|
19
|
+
"""Tmc2209"""
|
|
20
|
+
|
|
21
|
+
DRIVER_FAMILY = "TMC2209"
|
|
22
|
+
|
|
23
|
+
# Constructor/Destructor
|
|
24
|
+
# ----------------------------
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
tmc_ec: TmcEnableControl,
|
|
28
|
+
tmc_mc: TmcMotionControl,
|
|
29
|
+
tmc_com: TmcCom | None = None,
|
|
30
|
+
driver_address: int = 0,
|
|
31
|
+
gpio_mode=None,
|
|
32
|
+
loglevel: Loglevel = Loglevel.INFO,
|
|
33
|
+
logprefix: str | None = None,
|
|
34
|
+
log_handlers: list | None = None,
|
|
35
|
+
log_formatter: logging.Formatter | None = None,
|
|
36
|
+
):
|
|
37
|
+
"""constructor
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
tmc_ec (TmcEnableControl): enable control object
|
|
41
|
+
tmc_mc (TmcMotionControl): motion control object
|
|
42
|
+
tmc_com (TmcCom, optional): communication object. Defaults to None.
|
|
43
|
+
driver_address (int, optional): driver address [0-3]. Defaults to 0.
|
|
44
|
+
gpio_mode (enum, optional): gpio mode. Defaults to None.
|
|
45
|
+
loglevel (enum, optional): loglevel. Defaults to None.
|
|
46
|
+
logprefix (str, optional): log prefix (name of the logger).
|
|
47
|
+
Defaults to None (standard TMC prefix).
|
|
48
|
+
log_handlers (list, optional): list of logging handlers.
|
|
49
|
+
Defaults to None (log to console).
|
|
50
|
+
log_formatter (logging.Formatter, optional): formatter for the log messages.
|
|
51
|
+
Defaults to None (messages are logged in the format
|
|
52
|
+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
53
|
+
"""
|
|
54
|
+
super().__init__(
|
|
55
|
+
tmc_ec,
|
|
56
|
+
tmc_mc,
|
|
57
|
+
tmc_com,
|
|
58
|
+
driver_address,
|
|
59
|
+
gpio_mode,
|
|
60
|
+
loglevel,
|
|
61
|
+
logprefix,
|
|
62
|
+
log_handlers,
|
|
63
|
+
log_formatter,
|
|
64
|
+
)
|
|
65
|
+
StallGuard.__init__(self)
|
|
66
|
+
|
|
67
|
+
if self.tmc_com is not None:
|
|
68
|
+
self.tcoolthrs: TCoolThrs = TCoolThrs(self.tmc_com)
|
|
69
|
+
self.sgthrs: SgThrs = SgThrs(self.tmc_com)
|
|
70
|
+
self.sgresult: SgResult = SgResult(self.tmc_com)
|
|
71
|
+
|
|
72
|
+
def deinit(self):
|
|
73
|
+
"""destructor"""
|
|
74
|
+
super().deinit()
|
|
75
|
+
StallGuard.deinit(self)
|