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.
Files changed (56) hide show
  1. pytmcstepper-0.15.0.dist-info/METADATA +338 -0
  2. pytmcstepper-0.15.0.dist-info/RECORD +56 -0
  3. pytmcstepper-0.15.0.dist-info/WHEEL +5 -0
  4. pytmcstepper-0.15.0.dist-info/licenses/LICENSE +683 -0
  5. pytmcstepper-0.15.0.dist-info/top_level.txt +1 -0
  6. tmc_driver/__init__.py +96 -0
  7. tmc_driver/_tmc_exceptions.py +21 -0
  8. tmc_driver/_tmc_math.py +122 -0
  9. tmc_driver/_tmc_stallguard.py +340 -0
  10. tmc_driver/_tmc_stepperdriver.py +210 -0
  11. tmc_driver/_tmc_validation.py +29 -0
  12. tmc_driver/_tmc_xxxx.py +489 -0
  13. tmc_driver/com/__init__.py +64 -0
  14. tmc_driver/com/_tmc_com.py +148 -0
  15. tmc_driver/com/_tmc_com_spi.py +81 -0
  16. tmc_driver/com/_tmc_com_spi_base.py +159 -0
  17. tmc_driver/com/_tmc_com_spi_ftdi.py +48 -0
  18. tmc_driver/com/_tmc_com_spi_micropython.py +99 -0
  19. tmc_driver/com/_tmc_com_uart.py +113 -0
  20. tmc_driver/com/_tmc_com_uart_base.py +386 -0
  21. tmc_driver/com/_tmc_com_uart_micropython.py +115 -0
  22. tmc_driver/enable_control/__init__.py +55 -0
  23. tmc_driver/enable_control/_tmc_ec.py +59 -0
  24. tmc_driver/enable_control/_tmc_ec_pin.py +48 -0
  25. tmc_driver/enable_control/_tmc_ec_toff.py +30 -0
  26. tmc_driver/motion_control/__init__.py +111 -0
  27. tmc_driver/motion_control/_tmc_mc.py +280 -0
  28. tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +218 -0
  29. tmc_driver/motion_control/_tmc_mc_step_dir.py +415 -0
  30. tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +78 -0
  31. tmc_driver/motion_control/_tmc_mc_step_reg.py +36 -0
  32. tmc_driver/motion_control/_tmc_mc_vactual.py +221 -0
  33. tmc_driver/platform_utils.py +13 -0
  34. tmc_driver/reg/__init__.py +0 -0
  35. tmc_driver/reg/_tmc2209_reg.py +55 -0
  36. tmc_driver/reg/_tmc220x_reg.py +261 -0
  37. tmc_driver/reg/_tmc224x_reg.py +414 -0
  38. tmc_driver/reg/_tmc5160_reg.py +526 -0
  39. tmc_driver/reg/_tmc_reg.py +202 -0
  40. tmc_driver/reg/_tmc_shared_regs.py +314 -0
  41. tmc_driver/tmc_2208.py +17 -0
  42. tmc_driver/tmc_2209.py +75 -0
  43. tmc_driver/tmc_220x.py +383 -0
  44. tmc_driver/tmc_2240.py +340 -0
  45. tmc_driver/tmc_5160.py +344 -0
  46. tmc_driver/tmc_gpio/__init__.py +101 -0
  47. tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +106 -0
  48. tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +162 -0
  49. tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +135 -0
  50. tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +108 -0
  51. tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +87 -0
  52. tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +182 -0
  53. tmc_driver/tmc_logger/__init__.py +15 -0
  54. tmc_driver/tmc_logger/_tmc_logger_base.py +111 -0
  55. tmc_driver/tmc_logger/_tmc_logger_cpython.py +155 -0
  56. tmc_driver/tmc_logger/_tmc_logger_micropython.py +52 -0
@@ -0,0 +1,414 @@
1
+ # pylint: disable=too-many-instance-attributes
2
+ """
3
+ Register module
4
+ """
5
+
6
+ import math
7
+ from ._tmc_reg import TmcRegField
8
+ from . import _tmc_shared_regs as shared
9
+ from .._tmc_exceptions import TmcDriverException
10
+
11
+
12
+ class GConf(shared.GConf):
13
+ """GCONF register class"""
14
+
15
+ ADDR = 0x0
16
+
17
+ direct_mode: bool
18
+ stop_enable: bool
19
+ small_hysteresis: bool
20
+ diag1_pushpull: bool
21
+ diag0_pushpull: bool
22
+ diag1_onstate: bool
23
+ diag1_index: bool
24
+ diag1_stall: bool
25
+ diag0_stall: bool
26
+ diag0_otpw: bool
27
+ diag0_error: bool
28
+ shaft: bool
29
+ multistep_filt: bool
30
+ en_pwm_mode: bool
31
+ fast_standstill: bool
32
+ _REG_MAP = (
33
+ TmcRegField("direct_mode", 16, 0x1, bool, None, ""),
34
+ TmcRegField("stop_enable", 15, 0x1, bool, None, ""),
35
+ TmcRegField("small_hysteresis", 14, 0x1, bool, None, ""),
36
+ TmcRegField("diag1_pushpull", 13, 0x1, bool, None, ""),
37
+ TmcRegField("diag0_pushpull", 12, 0x1, bool, None, ""),
38
+ TmcRegField("diag1_onstate", 10, 0x1, bool, None, ""),
39
+ TmcRegField("diag1_index", 9, 0x1, bool, None, ""),
40
+ TmcRegField("diag1_stall", 8, 0x1, bool, None, ""),
41
+ TmcRegField("diag0_stall", 7, 0x1, bool, None, ""),
42
+ TmcRegField("diag0_otpw", 6, 0x1, bool, None, ""),
43
+ TmcRegField("diag0_error", 5, 0x1, bool, None, ""),
44
+ TmcRegField("shaft", 4, 0x1, bool, None, ""),
45
+ TmcRegField("multistep_filt", 3, 0x1, bool, None, ""),
46
+ TmcRegField("en_pwm_mode", 2, 0x1, bool, None, ""),
47
+ TmcRegField("fast_standstill", 1, 0x1, bool, None, ""),
48
+ )
49
+
50
+
51
+ class GStat(shared.GStat):
52
+ """GSTAT register class"""
53
+
54
+ ADDR = 0x1
55
+
56
+ vm_uvlo: bool
57
+ register_reset: bool
58
+ uv_cp: bool
59
+ drv_err: bool
60
+ reset: bool
61
+ _REG_MAP = (
62
+ TmcRegField("vm_uvlo", 4, 0x1, bool, None, "", 1),
63
+ TmcRegField("register_reset", 3, 0x1, bool, None, "", 1),
64
+ TmcRegField("uv_cp", 2, 0x1, bool, None, "", 1),
65
+ TmcRegField("drv_err", 1, 0x1, bool, None, "", 1),
66
+ TmcRegField("reset", 0, 0x1, bool, None, "", 1),
67
+ )
68
+
69
+ def check(self):
70
+ """check if the driver is ok"""
71
+ self.read()
72
+ if self.vm_uvlo:
73
+ raise TmcDriverException("TMC224X: Vmotor undervoltage detected")
74
+ if self.register_reset:
75
+ raise TmcDriverException("TMC224X: register reset detected")
76
+ if self.uv_cp:
77
+ raise TmcDriverException("TMC224X: Charge Pump undervoltage detected")
78
+ if self.drv_err:
79
+ raise TmcDriverException("TMC224X: driver error detected")
80
+ if self.reset:
81
+ raise TmcDriverException("TMC224X: reset detected")
82
+
83
+
84
+ class IfCnt(shared.IfCnt):
85
+ """IFCNT register class"""
86
+
87
+ ADDR = 0x2
88
+
89
+ ifcnt: int
90
+ _REG_MAP = (TmcRegField("ifcnt", 0, 0xFF, int, None, ""),)
91
+
92
+
93
+ class Ioin(shared.Ioin):
94
+ """IOIN register class"""
95
+
96
+ ADDR = 0x4
97
+ DRIVER_NAME = "TMC2240"
98
+
99
+ version: int
100
+ silicon_rv: int
101
+ adc_err: bool
102
+ ext_clk: bool
103
+ ext_res_det: bool
104
+ output: bool
105
+ comp_b1_b2: bool
106
+ comp_a1_a2: bool
107
+ comp_b: bool
108
+ comp_a: bool
109
+ uart_en: bool
110
+ encn: bool
111
+ enn: bool
112
+ enca: bool
113
+ encb: bool
114
+ dir: bool
115
+ step: bool
116
+ _REG_MAP = (
117
+ TmcRegField("version", 24, 0xFF, int, None, ""),
118
+ TmcRegField("silicon_rv", 24, 0xFF, int, None, ""),
119
+ TmcRegField("adc_err", 15, 0x1, bool, None, ""),
120
+ TmcRegField("ext_clk", 14, 0x1, bool, None, ""),
121
+ TmcRegField("ext_res_det", 13, 0x1, bool, None, ""),
122
+ TmcRegField("output", 12, 0x1, bool, None, ""),
123
+ TmcRegField("comp_b1_b2", 11, 0x1, bool, None, ""),
124
+ TmcRegField("comp_a1_a2", 10, 0x1, bool, None, ""),
125
+ TmcRegField("comp_b", 9, 0x1, bool, None, ""),
126
+ TmcRegField("comp_a", 8, 0x1, bool, None, ""),
127
+ TmcRegField("uart_en", 6, 0x1, bool, None, ""),
128
+ TmcRegField("encn", 5, 0x1, bool, None, ""),
129
+ TmcRegField("enn", 4, 0x1, bool, None, ""),
130
+ TmcRegField("enca", 3, 0x1, bool, None, ""),
131
+ TmcRegField("encb", 2, 0x1, bool, None, ""),
132
+ TmcRegField("dir", 1, 0x1, bool, None, ""),
133
+ TmcRegField("step", 0, 0x1, bool, None, ""),
134
+ )
135
+
136
+
137
+ class DrvConf(shared.DrvConf):
138
+ """DRV_CONF register class"""
139
+
140
+ ADDR = 0x6
141
+
142
+ slope_control: int
143
+ current_range: int
144
+ _REG_MAP = (
145
+ TmcRegField("slope_control", 4, 0x3, int, None, ""),
146
+ TmcRegField("current_range", 0, 0x3, int, None, ""),
147
+ )
148
+
149
+
150
+ class GlobalScaler(shared.GlobalScaler):
151
+ """GLOBAL_SCALER register class"""
152
+
153
+ ADDR = 0xB
154
+
155
+ global_scaler: int
156
+ _REG_MAP = (TmcRegField("global_scaler", 0, 0xFF, int, None, ""),)
157
+
158
+
159
+ class IHoldIRun(shared.IHoldIRun):
160
+ """IHOLD_IRUN register class"""
161
+
162
+ ADDR = 0x10
163
+
164
+ irundelay: int
165
+ iholddelay: int
166
+ irun: int
167
+ ihold: int
168
+ _REG_MAP = (
169
+ TmcRegField("irundelay", 24, 0xF, int, None, ""),
170
+ TmcRegField("iholddelay", 16, 0xF, int, None, ""),
171
+ TmcRegField("irun", 8, 0x1F, int, None, ""),
172
+ TmcRegField("ihold", 0, 0x1F, int, None, ""),
173
+ )
174
+
175
+
176
+ class TPowerDown(shared.TPowerDown):
177
+ """TPOWERDOWN register class"""
178
+
179
+ ADDR = 0x11
180
+
181
+ tpowerdown: int
182
+ _REG_MAP = (TmcRegField("tpowerdown", 0, 0xFF, int, None, ""),)
183
+
184
+
185
+ class TStep(shared.TStep):
186
+ """TSTEP register class"""
187
+
188
+ ADDR = 0x12
189
+
190
+ tstep: int
191
+ _REG_MAP = (TmcRegField("tstep", 0, 0xFFFFF, int, None, ""),)
192
+
193
+
194
+ class TPwmThrs(shared.TPwmThrs):
195
+ """TCOOLTHRS register class"""
196
+
197
+ ADDR = 0x13
198
+
199
+ tpwmthrs: int
200
+ _REG_MAP = (TmcRegField("tpwmthrs", 0, 0xFFFFF, int, None, ""),)
201
+
202
+
203
+ class TCoolThrs(shared.TCoolThrs):
204
+ """TCOOLTHRS register class"""
205
+
206
+ ADDR = 0x14
207
+
208
+ tcoolthrs: int
209
+ _REG_MAP = (TmcRegField("tcoolthrs", 0, 0xFFFFF, int, None, ""),)
210
+
211
+
212
+ class THigh(shared.THigh):
213
+ """THIGH register class"""
214
+
215
+ ADDR = 0x15
216
+
217
+ thigh: int
218
+ _REG_MAP = (TmcRegField("thigh", 0, 0xFFFFF, int, None, ""),)
219
+
220
+
221
+ class ADCVSupplyAIN(shared.ADCVSupplyAIN):
222
+ """ADCV_SUPPLY_AIN register class"""
223
+
224
+ ADDR = 0x50
225
+
226
+ adc_ain: int
227
+ adc_vsupply: int
228
+ _REG_MAP = (
229
+ TmcRegField("adc_ain", 16, 0xFFFF, int, "adc_ain_v", "V"),
230
+ TmcRegField("adc_vsupply", 0, 0xFFFF, int, "adc_vsupply_v", "V"),
231
+ )
232
+
233
+ @property
234
+ def adc_vsupply_v(self) -> float:
235
+ """return Supplyvoltage in V"""
236
+ return round(self.adc_vsupply * 9.732 / 1000, 2)
237
+
238
+ @property
239
+ def adc_ain_v(self) -> float:
240
+ """return voltage on AIN in V"""
241
+ return round(self.adc_ain * 305.2 / 1000 / 1000, 2)
242
+
243
+
244
+ class ADCTemp(shared.ADCTemp):
245
+ """ADC_TEMP register class"""
246
+
247
+ ADDR = 0x51
248
+
249
+ adc_temp: int
250
+ _REG_MAP = (TmcRegField("adc_temp", 0, 0xFFFF, int, "adc_temp_c", "°C"),)
251
+
252
+ @property
253
+ def adc_temp_c(self) -> float:
254
+ """return temperature in °C"""
255
+ return round((self.adc_temp - 2038) / 7.7, 1)
256
+
257
+
258
+ class MsCnt(shared.MsCnt):
259
+ """MSCNT register class"""
260
+
261
+ ADDR = 0x6A
262
+
263
+ mscnt: int
264
+ _REG_MAP = (TmcRegField("mscnt", 0, 0xFF, int, None, ""),)
265
+
266
+
267
+ class ChopConf(shared.ChopConf):
268
+ """CHOPCONF register class"""
269
+
270
+ ADDR = 0x6C
271
+
272
+ diss2vs: bool
273
+ diss2g: bool
274
+ dedge: bool
275
+ intpol: bool
276
+ mres: int
277
+ tpfd: int
278
+ vhighchm: bool
279
+ vhighfs: bool
280
+ tbl: int
281
+ chm: int
282
+ disfdcc: bool
283
+ fd3: bool
284
+ hend: int
285
+ hstrt: int
286
+ toff: int
287
+ _REG_MAP = (
288
+ TmcRegField("diss2vs", 31, 0x1, bool, None, ""),
289
+ TmcRegField("diss2g", 30, 0x1, bool, None, ""),
290
+ TmcRegField("dedge", 29, 0x1, bool, None, ""),
291
+ TmcRegField("intpol", 28, 0x1, bool, None, ""),
292
+ TmcRegField("mres", 24, 0xF, int, "mres_ms", "mStep"),
293
+ TmcRegField("tpfd", 20, 0xF, int, None, ""),
294
+ TmcRegField("vhighchm", 19, 0x1, bool, None, ""),
295
+ TmcRegField("vhighfs", 18, 0x1, bool, None, ""),
296
+ TmcRegField("tbl", 15, 0x3, int, None, ""),
297
+ TmcRegField("chm", 14, 0x3, int, None, ""),
298
+ TmcRegField("disfdcc", 12, 0x1, bool, None, ""),
299
+ TmcRegField("fd3", 11, 0x1, bool, None, ""),
300
+ TmcRegField("hend", 7, 0xF, int, None, ""),
301
+ TmcRegField("hstrt", 4, 0x7, int, None, ""),
302
+ TmcRegField("toff", 0, 0xF, int, None, ""),
303
+ )
304
+
305
+ @property
306
+ def mres_ms(self) -> int:
307
+ """return µstep resolution"""
308
+ return int(math.pow(2, 8 - self.mres))
309
+
310
+ @mres_ms.setter
311
+ def mres_ms(self, mres: int):
312
+ """set µstep resolution"""
313
+ mres_bit = int(math.log2(mres))
314
+ mres_bit = 8 - mres_bit
315
+ self.mres = mres_bit
316
+
317
+
318
+ class CoolConf(shared.CoolConf):
319
+ """COOLCONF register class"""
320
+
321
+ ADDR = 0x6D
322
+
323
+ sfilt: bool
324
+ sgt: int
325
+ seimin: bool
326
+ sedn: int
327
+ semax: int
328
+ seup: int
329
+ semin: int
330
+ _REG_MAP = (
331
+ TmcRegField("sfilt", 24, 0x1, bool, None, ""),
332
+ TmcRegField("sgt", 16, 0x7F, int, None, ""),
333
+ TmcRegField("seimin", 15, 0x1, bool, None, ""),
334
+ TmcRegField("sedn", 13, 0x3, int, None, ""),
335
+ TmcRegField("semax", 8, 0xF, int, None, ""),
336
+ TmcRegField("seup", 5, 0x3, int, None, ""),
337
+ TmcRegField("semin", 0, 0xF, int, None, ""),
338
+ )
339
+
340
+
341
+ class DrvStatus(shared.DrvStatus):
342
+ """DRVSTATUS register class"""
343
+
344
+ ADDR = 0x6F
345
+
346
+ stst: bool
347
+ olb: bool
348
+ ola: bool
349
+ s2gb: bool
350
+ s2ga: bool
351
+ otpw: bool
352
+ ot: bool
353
+ stallguard: bool
354
+ cs_actual: int
355
+ fsactive: bool
356
+ stealth: bool
357
+ s2vsb: bool
358
+ s2vsa: bool
359
+ sgresult: int
360
+ _REG_MAP = (
361
+ TmcRegField("stst", 31, 0x1, bool, None, ""),
362
+ TmcRegField("olb", 30, 0x1, bool, None, ""),
363
+ TmcRegField("ola", 29, 0x1, bool, None, ""),
364
+ TmcRegField("s2gb", 28, 0x1, bool, None, ""),
365
+ TmcRegField("s2ga", 27, 0x1, bool, None, ""),
366
+ TmcRegField("otpw", 26, 0x1, bool, None, ""),
367
+ TmcRegField("ot", 25, 0x1, bool, None, ""),
368
+ TmcRegField("stallguard", 24, 0x1, bool, None, ""),
369
+ TmcRegField("cs_actual", 16, 0x1F, int, None, ""),
370
+ TmcRegField("fsactive", 15, 0x1, bool, None, ""),
371
+ TmcRegField("stealth", 14, 0x1, bool, None, ""),
372
+ TmcRegField("s2vsb", 13, 0x1, bool, None, ""),
373
+ TmcRegField("s2vsa", 12, 0x1, bool, None, ""),
374
+ TmcRegField("sgresult", 0, 0x3FF, int, None, ""),
375
+ )
376
+
377
+
378
+ class SgThrs(shared.SgThrs):
379
+ """SGTHRS register class"""
380
+
381
+ ADDR = 0x74
382
+
383
+ sg_angle_offset: bool
384
+ sg4_filt_en: bool
385
+ sgthrs: int
386
+ _REG_MAP = (
387
+ TmcRegField("sg_angle_offset", 9, 0x1, bool, None, ""),
388
+ TmcRegField("sg4_filt_en", 8, 0x1, bool, None, ""),
389
+ TmcRegField("sgthrs", 0, 0xFFF, int, None, ""),
390
+ )
391
+
392
+
393
+ class SgResult(shared.SgResult):
394
+ """SGRESULT register class"""
395
+
396
+ ADDR = 0x75
397
+
398
+ sgresult: int
399
+ _REG_MAP = (TmcRegField("sgresult", 0, 0xFFFFF, int, None, ""),)
400
+
401
+
402
+ class SgInd(shared.SgInd):
403
+ """SGIND register class"""
404
+
405
+ ADDR = 0x76
406
+
407
+ sg_ind_2: int
408
+ sg_ind_1: int
409
+ sg_ind_0: int
410
+ _REG_MAP = (
411
+ TmcRegField("sg_ind_2", 16, 0xFF, int, None, ""),
412
+ TmcRegField("sg_ind_1", 8, 0xFF, int, None, ""),
413
+ TmcRegField("sg_ind_0", 0, 0xFF, int, None, ""),
414
+ )