-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathTMCStepper.h
1254 lines (1113 loc) · 31.9 KB
/
TMCStepper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
//#define TMCDEBUG
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#include <SPI.h>
#include <Stream.h>
#elif defined(bcm2835)
#include <bcm2835.h>
#include "source/bcm2835_spi.h"
#include "source/bcm2835_stream.h"
#endif
#if (__cplusplus == 201703L) && defined(__has_include)
#define SW_CAPABLE_PLATFORM __has_include(<SoftwareSerial.h>)
#elif defined(__AVR__) || defined(TARGET_LPC1768) || defined(ARDUINO_ARCH_STM32)
#define SW_CAPABLE_PLATFORM true
#else
#define SW_CAPABLE_PLATFORM false
#endif
#if SW_CAPABLE_PLATFORM
#include <SoftwareSerial.h>
#endif
#include "source/SERIAL_SWITCH.h"
#include "source/SW_SPI.h"
#pragma GCC diagnostic pop
#include "source/TMC2130_bitfields.h"
#include "source/TMC2160_bitfields.h"
#include "source/TMC5130_bitfields.h"
#include "source/TMC5160_bitfields.h"
#include "source/TMC2208_bitfields.h"
#include "source/TMC2209_bitfields.h"
#include "source/TMC2660_bitfields.h"
#define INIT_REGISTER(REG) REG##_t REG##_register = REG##_t
#define INIT2130_REGISTER(REG) TMC2130_n::REG##_t REG##_register = TMC2130_n::REG##_t
#define INIT2160_REGISTER(REG) TMC2160_n::REG##_t REG##_register = TMC2160_n::REG##_t
#define INIT5130_REGISTER(REG) TMC5130_n::REG##_t REG##_register = TMC5130_n::REG##_t
#define INIT5160_REGISTER(REG) TMC5160_n::REG##_t REG##_register = TMC5160_n::REG##_t
#define INIT2660_REGISTER(REG) TMC2660_n::REG##_t REG##_register = TMC2660_n::REG##_t
#define INIT2208_REGISTER(REG) TMC2208_n::REG##_t REG##_register = TMC2208_n::REG##_t
#define INIT2224_REGISTER(REG) TMC2224_n::REG##_t REG##_register = TMC2224_n::REG##_t
#define SET_ALIAS(TYPE, DRIVER, NEW, ARG, OLD) TYPE (DRIVER::*NEW)(ARG) = &DRIVER::OLD
#define TMCSTEPPER_VERSION 0x000701 // v0.7.1
class TMCStepper {
public:
uint16_t cs2rms(uint8_t CS);
void rms_current(uint16_t mA);
void rms_current(uint16_t mA, float mult);
uint16_t rms_current();
void hold_multiplier(float val) { holdMultiplier = val; }
float hold_multiplier() { return holdMultiplier; }
uint8_t test_connection();
// Helper functions
void microsteps(uint16_t ms);
uint16_t microsteps();
void blank_time(uint8_t value);
uint8_t blank_time();
void hysteresis_end(int8_t value);
int8_t hysteresis_end();
void hysteresis_start(uint8_t value);
uint8_t hysteresis_start();
// R+WC: GSTAT
void GSTAT( uint8_t input);
uint8_t GSTAT();
bool reset();
bool drv_err();
bool uv_cp();
// W: IHOLD_IRUN
void IHOLD_IRUN( uint32_t input);
uint32_t IHOLD_IRUN();
void ihold( uint8_t B);
void irun( uint8_t B);
void iholddelay( uint8_t B);
uint8_t ihold();
uint8_t irun();
uint8_t iholddelay();
// W: TPOWERDOWN
uint8_t TPOWERDOWN();
void TPOWERDOWN( uint8_t input);
// R: TSTEP
uint32_t TSTEP();
// W: TPWMTHRS
uint32_t TPWMTHRS();
void TPWMTHRS( uint32_t input);
// R: MSCNT
uint16_t MSCNT();
// R: MSCURACT
uint32_t MSCURACT();
int16_t cur_a();
int16_t cur_b();
protected:
TMCStepper(float RS) : Rsense(RS) {};
INIT_REGISTER(IHOLD_IRUN){{.sr=0}}; // 32b
INIT_REGISTER(TPOWERDOWN){.sr=0}; // 8b
INIT_REGISTER(TPWMTHRS){.sr=0}; // 32b
static constexpr uint8_t TMC_READ = 0x00,
TMC_WRITE = 0x80;
struct TSTEP_t { constexpr static uint8_t address = 0x12; };
struct MSCNT_t { constexpr static uint8_t address = 0x6A; };
virtual void write(uint8_t, uint32_t) = 0;
virtual uint32_t read(uint8_t) = 0;
virtual void vsense(bool) = 0;
virtual bool vsense(void) = 0;
virtual uint32_t DRV_STATUS() = 0;
virtual void hend(uint8_t) = 0;
virtual uint8_t hend() = 0;
virtual void hstrt(uint8_t) = 0;
virtual uint8_t hstrt() = 0;
virtual void mres(uint8_t) = 0;
virtual uint8_t mres() = 0;
virtual void tbl(uint8_t) = 0;
virtual uint8_t tbl() = 0;
const float Rsense;
float holdMultiplier = 0.5;
};
class TMC2130Stepper : public TMCStepper {
public:
TMC2130Stepper(uint16_t pinCS, float RS = default_RS, int8_t link_index = -1);
TMC2130Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
TMC2130Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
void begin();
void defaults();
void setSPISpeed(uint32_t speed);
void switchCSpin(bool state);
bool isEnabled();
void push();
// Helper functions
void sg_current_decrease(uint8_t value);
uint8_t sg_current_decrease();
// RW: GCONF
uint32_t GCONF();
void GCONF( uint32_t value);
void I_scale_analog( bool B);
void internal_Rsense( bool B);
void en_pwm_mode( bool B);
void enc_commutation( bool B);
void shaft( bool B);
void diag0_error( bool B);
void diag0_otpw( bool B);
void diag0_stall( bool B);
void diag1_stall( bool B);
void diag1_index( bool B);
void diag1_onstate( bool B);
void diag1_steps_skipped( bool B);
void diag0_int_pushpull( bool B);
void diag1_pushpull( bool B);
void small_hysteresis( bool B);
void stop_enable( bool B);
void direct_mode( bool B);
bool I_scale_analog();
bool internal_Rsense();
bool en_pwm_mode();
bool enc_commutation();
bool shaft();
bool diag0_error();
bool diag0_otpw();
bool diag0_stall();
bool diag1_stall();
bool diag1_index();
bool diag1_onstate();
bool diag1_steps_skipped();
bool diag0_int_pushpull();
bool diag1_pushpull();
bool small_hysteresis();
bool stop_enable();
bool direct_mode();
// R: IOIN
uint32_t IOIN();
bool step();
bool dir();
bool dcen_cfg4();
bool dcin_cfg5();
bool drv_enn_cfg6();
bool dco();
uint8_t version();
// W: TCOOLTHRS
uint32_t TCOOLTHRS();
void TCOOLTHRS( uint32_t input);
// W: THIGH
uint32_t THIGH();
void THIGH( uint32_t input);
// RW: XDRIRECT
uint32_t XDIRECT();
void XDIRECT( uint32_t input);
void coil_A( int16_t B);
void coil_B( int16_t B);
int16_t coil_A();
int16_t coil_B();
// W: VDCMIN
uint32_t VDCMIN();
void VDCMIN( uint32_t input);
// RW: CHOPCONF
uint32_t CHOPCONF();
void CHOPCONF( uint32_t value);
void toff( uint8_t B);
void hstrt( uint8_t B);
void hend( uint8_t B);
//void fd( uint8_t B);
void disfdcc( bool B);
void rndtf( bool B);
void chm( bool B);
void tbl( uint8_t B);
void vsense( bool B);
void vhighfs( bool B);
void vhighchm( bool B);
void sync( uint8_t B);
void mres( uint8_t B);
void intpol( bool B);
void dedge( bool B);
void diss2g( bool B);
uint8_t toff();
uint8_t hstrt();
uint8_t hend();
//uint8_t fd();
bool disfdcc();
bool rndtf();
bool chm();
uint8_t tbl();
bool vsense();
bool vhighfs();
bool vhighchm();
uint8_t sync();
uint8_t mres();
bool intpol();
bool dedge();
bool diss2g();
// W: COOLCONF
void COOLCONF(uint32_t value);
uint32_t COOLCONF();
void semin( uint8_t B);
void seup( uint8_t B);
void semax( uint8_t B);
void sedn( uint8_t B);
void seimin( bool B);
void sgt( int8_t B);
void sfilt( bool B);
uint8_t semin();
uint8_t seup();
uint8_t semax();
uint8_t sedn();
bool seimin();
int8_t sgt();
bool sfilt();
// W: DCCTRL
void DCCTRL(uint32_t input);
void dc_time(uint16_t input);
void dc_sg(uint8_t input);
uint32_t DCCTRL();
uint16_t dc_time();
uint8_t dc_sg();
// R: DRV_STATUS
uint32_t DRV_STATUS();
uint16_t sg_result();
bool fsactive();
uint8_t cs_actual();
bool stallguard();
bool ot();
bool otpw();
bool s2ga();
bool s2gb();
bool ola();
bool olb();
bool stst();
// W: PWMCONF
void PWMCONF( uint32_t value);
uint32_t PWMCONF();
void pwm_ampl( uint8_t B);
void pwm_grad( uint8_t B);
void pwm_freq( uint8_t B);
void pwm_autoscale( bool B);
void pwm_symmetric( bool B);
void freewheel( uint8_t B);
uint8_t pwm_ampl();
uint8_t pwm_grad();
uint8_t pwm_freq();
bool pwm_autoscale();
bool pwm_symmetric();
uint8_t freewheel();
// R: PWM_SCALE
uint8_t PWM_SCALE();
// W: ENCM_CTRL
uint8_t ENCM_CTRL();
void ENCM_CTRL( uint8_t input);
void inv( bool B);
void maxspeed( bool B);
bool inv();
bool maxspeed();
// R: LOST_STEPS
uint32_t LOST_STEPS();
// Function aliases
uint8_t status_response;
protected:
void beginTransaction();
void endTransaction();
uint8_t transfer(const uint8_t data);
void transferEmptyBytes(const uint8_t n);
void write(uint8_t addressByte, uint32_t config);
uint32_t read(uint8_t addressByte);
INIT_REGISTER(GCONF){{.sr=0}}; // 32b
INIT_REGISTER(TCOOLTHRS){.sr=0}; // 32b
INIT_REGISTER(THIGH){.sr=0}; // 32b
INIT_REGISTER(XDIRECT){{.sr=0}}; // 32b
INIT_REGISTER(VDCMIN){.sr=0}; // 32b
INIT_REGISTER(CHOPCONF){{.sr=0}}; // 32b
INIT_REGISTER(COOLCONF){{.sr=0}}; // 32b
INIT_REGISTER(DCCTRL){{.sr = 0}}; // 32b
INIT_REGISTER(PWMCONF){{.sr=0}}; // 32b
INIT_REGISTER(ENCM_CTRL){{.sr=0}};// 8b
struct IOINT_t { constexpr static uint8_t address = 0x04; };
struct PWM_SCALE_t { constexpr static uint8_t address = 0x71; };
struct LOST_STEPS_t { constexpr static uint8_t address = 0x73; };
struct DRV_STATUS_t { constexpr static uint8_t address = 0X6F; };
static uint32_t spi_speed; // Default 2MHz
const uint16_t _pinCS;
SW_SPIClass * TMC_SW_SPI = nullptr;
static constexpr float default_RS = 0.11;
int8_t link_index;
static int8_t chain_length;
};
class TMC2160Stepper : public TMC2130Stepper {
public:
TMC2160Stepper(uint16_t pinCS, float RS = default_RS, int8_t link_index = -1);
TMC2160Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
TMC2160Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
void begin();
void defaults();
void push();
uint16_t cs2rms(uint8_t CS);
void rms_current(uint16_t mA);
void rms_current(uint16_t mA, float mult);
uint16_t rms_current();
// IOIN
uint32_t IOIN();
bool refl_step();
bool refr_dir();
bool encb_dcen_cfg4();
bool enca_dcin_cfg5();
bool drv_enn();
bool dco_cfg6();
uint8_t version();
// W: OTP_PROG
// R: OTP_READ
// RW: FACTORY_CONF
// W: SHORT_CONF
void SHORT_CONF(uint32_t);
void s2vs_level(uint8_t);
void s2g_level(uint8_t);
void shortfilter(uint8_t);
void shortdelay(bool);
uint32_t SHORT_CONF();
uint8_t s2vs_level();
uint8_t s2g_level();
uint8_t shortfilter();
bool shortdelay();
// W: DRV_CONF
void DRV_CONF(uint32_t);
void bbmtime(uint8_t);
void bbmclks(uint8_t);
void otselect(uint8_t);
void drvstrength(uint8_t);
void filt_isense(uint8_t);
uint32_t DRV_CONF();
uint8_t bbmtime();
uint8_t bbmclks();
uint8_t otselect();
uint8_t drvstrength();
uint8_t filt_isense();
// W: GLOBAL_SCALER
void GLOBAL_SCALER(uint8_t);
uint8_t GLOBAL_SCALER();
// R: OFFSET_READ
uint16_t OFFSET_READ();
// W: PWMCONF
void PWMCONF(uint32_t input);
void pwm_ofs(uint8_t B);
void pwm_grad(uint8_t B);
void pwm_freq(uint8_t B);
void pwm_autoscale(bool B);
void pwm_autograd(bool B);
void freewheel(uint8_t B);
void pwm_reg(uint8_t B);
void pwm_lim(uint8_t B);
uint32_t PWMCONF();
uint8_t pwm_ofs();
uint8_t pwm_grad();
uint8_t pwm_freq();
bool pwm_autoscale();
bool pwm_autograd();
uint8_t freewheel();
uint8_t pwm_reg();
uint8_t pwm_lim();
// R: PWM_SCALE
uint32_t PWM_SCALE();
uint8_t pwm_scale_sum();
uint16_t pwm_scale_auto();
protected:
using TMC2130Stepper::ENCM_CTRL;
using TMC2130Stepper::pwm_ampl;
using TMC2130Stepper::pwm_symmetric;
INIT_REGISTER(SHORT_CONF){{.sr=0}};
INIT_REGISTER(DRV_CONF){{.sr=0}};
INIT_REGISTER(GLOBAL_SCALER){.sr=0};
INIT2160_REGISTER(PWMCONF){{.sr=0}};
static constexpr float default_RS = 0.075;
};
class TMC5130Stepper : public TMC2160Stepper {
public:
TMC5130Stepper(uint16_t pinCS, float RS = default_RS, int8_t link_index = -1);
TMC5130Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
TMC5130Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
void begin();
void defaults();
void push();
void rms_current(uint16_t mA) { TMC2130Stepper::rms_current(mA); }
void rms_current(uint16_t mA, float mult) { TMC2130Stepper::rms_current(mA, mult); }
uint16_t rms_current() { return TMC2130Stepper::rms_current(); }
// R: IFCNT
uint8_t IFCNT();
// W: SLAVECONF
uint16_t SLAVECONF();
void SLAVECONF(uint16_t input);
// R: IOIN
uint32_t IOIN();
bool refl_step();
bool refr_dir();
bool encb_dcen_cfg4();
bool enca_dcin_cfg5();
bool drv_enn_cfg6();
bool enc_n_dco();
bool sd_mode();
bool swcomp_in();
uint8_t version();
// RW: GCONF
void diag1_poscomp_pushpull(bool B) { diag1_pushpull(B); }
bool diag1_poscomp_pushpull() { return diag1_pushpull(); }
// RW: SW_MODE
uint32_t SW_MODE();
void SW_MODE(uint32_t input);
void stop_l_enable(bool B);
void stop_r_enable(bool B);
void pol_stop_l(bool B);
void pol_stop_r(bool B);
void swap_lr(bool B);
void latch_l_active(bool B);
void latch_l_inactive(bool B);
void latch_r_active(bool B);
void latch_r_inactive(bool B);
void en_latch_encoder(bool B);
void sg_stop(bool B);
void en_softstop(bool B);
bool stop_r_enable();
bool pol_stop_l();
bool pol_stop_r();
bool swap_lr();
bool latch_l_active();
bool latch_l_inactive();
bool latch_r_active();
bool latch_r_inactive();
bool en_latch_encoder();
bool sg_stop();
bool en_softstop();
// R+C: RAMP_STAT
uint32_t RAMP_STAT();
bool status_stop_l();
bool status_stop_r();
bool status_latch_l();
bool status_latch_r();
bool event_stop_l();
bool event_stop_r();
bool event_stop_sg();
bool event_pos_reached();
bool velocity_reached();
bool position_reached();
bool vzero();
bool t_zerowait_active();
bool second_move();
bool status_sg();
// RW: ENCMODE
uint32_t ENCMODE();
void ENCMODE(uint32_t input);
void pol_a(bool B);
void pol_b(bool B);
void pol_n(bool B);
void ignore_ab(bool B);
void clr_cont(bool B);
void clr_once(bool B);
void pos_edge(bool B);
void neg_edge(bool B);
void clr_enc_x(bool B);
void latch_x_act(bool B);
void enc_sel_decimal(bool B);
bool pol_a();
bool pol_b();
bool pol_n();
bool ignore_ab();
bool clr_cont();
bool clr_once();
bool pos_edge();
bool neg_edge();
bool clr_enc_x();
bool latch_x_act();
bool enc_sel_decimal();
// W: OUTPUT
bool TMC_OUTPUT();
void TMC_OUTPUT(bool input);
// W: X_COMPARE
uint32_t X_COMPARE();
void X_COMPARE(uint32_t input);
// RW: RAMPMODE
uint8_t RAMPMODE();
void RAMPMODE(uint8_t input);
// RW: XACTUAL
int32_t XACTUAL();
void XACTUAL(int32_t input);
// R: VACTUAL
int32_t VACTUAL();
// W: VSTART
uint32_t VSTART();
void VSTART(uint32_t input);
// W: A1
uint16_t A1();
void A1(uint16_t input);
// W: V1
uint32_t V1();
void V1(uint32_t input);
// W: AMAX
uint16_t AMAX();
void AMAX(uint16_t input);
// W: VMAX
uint32_t VMAX();
void VMAX(uint32_t input);
// W: DMAX
uint16_t DMAX();
void DMAX(uint16_t input);
// W: D1
uint16_t D1();
void D1(uint16_t input);
// W: VSTOP
uint32_t VSTOP();
void VSTOP(uint32_t input);
// W: TZEROWAIT
uint16_t TZEROWAIT();
void TZEROWAIT(uint16_t input);
// RW: XTARGET
int32_t XTARGET();
void XTARGET(int32_t input);
// R: XLATCH
uint32_t XLATCH();
// RW: X_ENC
int32_t X_ENC();
void X_ENC(int32_t input);
// W: ENC_CONST
uint32_t ENC_CONST();
void ENC_CONST(uint32_t input);
// R: ENC_STATUS
bool ENC_STATUS();
// R: ENC_LATCH
uint32_t ENC_LATCH();
using TMC2130Stepper::ENCM_CTRL;
using TMC2130Stepper::PWMCONF;
using TMC2130Stepper::pwm_ampl;
using TMC2130Stepper::pwm_grad;
using TMC2130Stepper::pwm_freq;
using TMC2130Stepper::pwm_autoscale;
using TMC2130Stepper::pwm_symmetric;
using TMC2130Stepper::freewheel;
using TMC2130Stepper::PWM_SCALE;
protected:
INIT_REGISTER(SLAVECONF){{.sr=0}};
INIT_REGISTER(OUTPUT){.sr=0};
INIT_REGISTER(X_COMPARE){.sr=0};
INIT_REGISTER(RAMPMODE){.sr=0};
INIT_REGISTER(XACTUAL){.sr=0};
INIT_REGISTER(VSTART){.sr=0};
INIT_REGISTER(A1){.sr=0};
INIT_REGISTER(V1){.sr=0};
INIT_REGISTER(AMAX){.sr=0};
INIT_REGISTER(VMAX){.sr=0};
INIT_REGISTER(DMAX){.sr=0};
INIT_REGISTER(D1){.sr=0};
INIT_REGISTER(VSTOP){.sr=0};
INIT_REGISTER(TZEROWAIT){.sr=0};
INIT_REGISTER(SW_MODE){{.sr=0}};
INIT_REGISTER(ENCMODE){{.sr=0}};
INIT_REGISTER(ENC_CONST){.sr=0};
struct IFCNT_t { constexpr static uint8_t address = 0x02; }; // R
struct VACTUAL_t { constexpr static uint8_t address = 0x22; }; // R
struct XTARGET_t { constexpr static uint8_t address = 0x2D; }; // RW
struct XLATCH_t { constexpr static uint8_t address = 0x36; }; // R
struct X_ENC_t { constexpr static uint8_t address = 0x39; }; // RW
struct ENC_STATUS_t { constexpr static uint8_t address = 0x3B; }; // R+C
struct ENC_LATCH_t { constexpr static uint8_t address = 0x3C; }; // R
/*
INIT_REGISTER(MSLUT0){0};
INIT_REGISTER(MSLUT1){0};
INIT_REGISTER(MSLUT2){0};
INIT_REGISTER(MSLUT3){0};
INIT_REGISTER(MSLUT4){0};
INIT_REGISTER(MSLUT5){0};
INIT_REGISTER(MSLUT6){0};
INIT_REGISTER(MSLUT7){0};
INIT_REGISTER(MSLUTSEL){0};
INIT_REGISTER(MSLUTSTART){0};
INIT_REGISTER(MSCNT){0};
INIT_REGISTER(MSCURACT){0};
*/
static constexpr float default_RS = 0.15;
protected:
using TMC2160Stepper::SHORT_CONF;
using TMC2160Stepper::s2vs_level;
using TMC2160Stepper::s2g_level;
using TMC2160Stepper::shortfilter;
using TMC2160Stepper::shortdelay;
using TMC2160Stepper::DRV_CONF;
using TMC2160Stepper::bbmtime;
using TMC2160Stepper::bbmclks;
using TMC2160Stepper::otselect;
using TMC2160Stepper::drvstrength;
using TMC2160Stepper::filt_isense;
using TMC2160Stepper::GLOBAL_SCALER;
using TMC2160Stepper::OFFSET_READ;
using TMC2160Stepper::pwm_ofs;
using TMC2160Stepper::pwm_autograd;
using TMC2160Stepper::pwm_reg;
using TMC2160Stepper::pwm_lim;
using TMC2160Stepper::pwm_scale_sum;
using TMC2160Stepper::pwm_scale_auto;
};
class TMC5160Stepper : public TMC5130Stepper {
public:
TMC5160Stepper(uint16_t pinCS, float RS = default_RS, int8_t link_index = -1);
TMC5160Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
TMC5160Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
void rms_current(uint16_t mA) { TMC2160Stepper::rms_current(mA); }
void rms_current(uint16_t mA, float mult) { TMC2160Stepper::rms_current(mA, mult); }
uint16_t rms_current() { return TMC2160Stepper::rms_current(); }
void defaults();
void push();
// RW: GCONF
void recalibrate(bool);
void faststandstill(bool);
void multistep_filt(bool);
bool recalibrate();
bool faststandstill();
bool multistep_filt();
// R: IOIN
bool drv_enn() { return drv_enn_cfg6(); }
bool enc_n_dco_cfg6() { return enc_n_dco(); }
// W: SHORT_CONF
using TMC2160Stepper::SHORT_CONF;
using TMC2160Stepper::s2vs_level;
using TMC2160Stepper::s2g_level;
using TMC2160Stepper::shortfilter;
using TMC2160Stepper::shortdelay;
// W: DRV_CONF
using TMC2160Stepper::DRV_CONF;
using TMC2160Stepper::bbmtime;
using TMC2160Stepper::bbmclks;
using TMC2160Stepper::otselect;
using TMC2160Stepper::drvstrength;
using TMC2160Stepper::filt_isense;
// W: GLOBAL_SCALER
using TMC2160Stepper::GLOBAL_SCALER;
// R: OFFSET_READ
using TMC2160Stepper::OFFSET_READ;
// R+WC: ENC_STATUS
void ENC_STATUS(uint8_t);
uint8_t ENC_STATUS();
// W: ENC_DEVIATION
void ENC_DEVIATION(uint32_t);
uint32_t ENC_DEVIATION();
// R: PWM_AUTO
uint32_t PWM_AUTO();
uint8_t pwm_ofs_auto();
uint8_t pwm_grad_auto();
// RW: CHOPCONF
void diss2vs(bool);
void tpfd(uint8_t);
bool diss2vs();
uint8_t tpfd();
// W: PWM_CONF
using TMC2160Stepper::PWMCONF;
using TMC2160Stepper::pwm_ofs;
using TMC2160Stepper::pwm_grad;
using TMC2160Stepper::pwm_freq;
using TMC2160Stepper::pwm_autoscale;
using TMC2160Stepper::pwm_autograd;
using TMC2160Stepper::freewheel;
using TMC2160Stepper::pwm_reg;
using TMC2160Stepper::pwm_lim;
using TMC2160Stepper::PWM_SCALE;
using TMC2160Stepper::pwm_scale_sum;
using TMC2160Stepper::pwm_scale_auto;
protected:
using TMC5130Stepper::I_scale_analog;
using TMC5130Stepper::internal_Rsense;
using TMC5130Stepper::enc_commutation;
using TMC5130Stepper::drv_enn_cfg6;
using TMC5130Stepper::enc_n_dco;
using TMC5130Stepper::ENCM_CTRL;
using TMC5130Stepper::vsense;
using TMC5130Stepper::rndtf;
INIT_REGISTER(ENC_DEVIATION){.sr=0};
static constexpr float default_RS = 0.075;
};
class TMC5161Stepper : public TMC5160Stepper {
public:
TMC5161Stepper(uint16_t pinCS, float RS = default_RS, int8_t link_index = -1) : TMC5160Stepper(pinCS, RS, link_index) {}
TMC5161Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1) :
TMC5160Stepper(pinCS, pinMOSI, pinMISO, pinSCK, link_index) {}
TMC5161Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1) :
TMC5160Stepper(pinCS, RS, pinMOSI, pinMISO, pinSCK, link_index) {}
};
class TMC2208Stepper : public TMCStepper {
public:
TMC2208Stepper(Stream * SerialPort, float RS, uint8_t addr, uint16_t mul_pin1, uint16_t mul_pin2);
TMC2208Stepper(Stream * SerialPort, float RS) :
TMC2208Stepper(SerialPort, RS, TMC2208_SLAVE_ADDR)
{}
#if SW_CAPABLE_PLATFORM
TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin, float RS) :
TMC2208Stepper(SW_RX_pin, SW_TX_pin, RS, TMC2208_SLAVE_ADDR)
{}
__attribute__((deprecated("Boolean argument has been deprecated and does nothing")))
TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin, float RS, bool) :
TMC2208Stepper(SW_RX_pin, SW_TX_pin, RS, TMC2208_SLAVE_ADDR)
{};
#else
TMC2208Stepper(uint16_t, uint16_t, float) = delete; // Your platform does not currently support Software Serial
#endif
void defaults();
void push();
void begin();
#if SW_CAPABLE_PLATFORM
void beginSerial(uint32_t baudrate) __attribute__((weak));
#else
void beginSerial(uint32_t) = delete; // Your platform does not currently support Software Serial
#endif
bool isEnabled();
// RW: GCONF
void GCONF(uint32_t input);
void I_scale_analog(bool B);
void internal_Rsense(bool B);
void en_spreadCycle(bool B);
void shaft(bool B);
void index_otpw(bool B);
void index_step(bool B);
void pdn_disable(bool B);
void mstep_reg_select(bool B);
void multistep_filt(bool B);
uint32_t GCONF();
bool I_scale_analog();
bool internal_Rsense();
bool en_spreadCycle();
bool shaft();
bool index_otpw();
bool index_step();
bool pdn_disable();
bool mstep_reg_select();
bool multistep_filt();
// R: IFCNT
uint8_t IFCNT();
// W: SLAVECONF
void SLAVECONF(uint16_t input);
uint16_t SLAVECONF();
void senddelay(uint8_t B);
uint8_t senddelay();
// W: OTP_PROG
void OTP_PROG(uint16_t input);
// R: OTP_READ
uint32_t OTP_READ();
// R: IOIN
uint32_t IOIN();
bool enn();
bool ms1();
bool ms2();
bool diag();
bool pdn_uart();
bool step();
bool sel_a();
bool dir();
uint8_t version();
// RW: FACTORY_CONF
void FACTORY_CONF(uint16_t input);
uint16_t FACTORY_CONF();
void fclktrim(uint8_t B);
void ottrim(uint8_t B);
uint8_t fclktrim();
uint8_t ottrim();
// W: VACTUAL
void VACTUAL(uint32_t input);
uint32_t VACTUAL();
// RW: CHOPCONF
void CHOPCONF(uint32_t input);
void toff(uint8_t B);
void hstrt(uint8_t B);
void hend(uint8_t B);
void tbl(uint8_t B);
void vsense(bool B);
void mres(uint8_t B);
void intpol(bool B);
void dedge(bool B);
void diss2g(bool B);
void diss2vs(bool B);
uint32_t CHOPCONF();
uint8_t toff();
uint8_t hstrt();
uint8_t hend();
uint8_t tbl();
bool vsense();
uint8_t mres();
bool intpol();
bool dedge();
bool diss2g();
bool diss2vs();
// R: DRV_STATUS
uint32_t DRV_STATUS();
bool otpw();
bool ot();
bool s2ga();
bool s2gb();
bool s2vsa();
bool s2vsb();
bool ola();
bool olb();
bool t120();
bool t143();
bool t150();
bool t157();
uint16_t cs_actual();
bool stealth();
bool stst();
// RW: PWMCONF
void PWMCONF(uint32_t input);
void pwm_ofs(uint8_t B);
void pwm_grad(uint8_t B);
void pwm_freq(uint8_t B);
void pwm_autoscale(bool B);
void pwm_autograd(bool B);
void freewheel(uint8_t B);
void pwm_reg(uint8_t B);
void pwm_lim(uint8_t B);
uint32_t PWMCONF();
uint8_t pwm_ofs();
uint8_t pwm_grad();
uint8_t pwm_freq();
bool pwm_autoscale();
bool pwm_autograd();
uint8_t freewheel();
uint8_t pwm_reg();
uint8_t pwm_lim();
// R: PWM_SCALE
uint32_t PWM_SCALE();
uint8_t pwm_scale_sum();
int16_t pwm_scale_auto();
// R: PWM_AUTO (0x72)
uint32_t PWM_AUTO();
uint8_t pwm_ofs_auto();
uint8_t pwm_grad_auto();
uint16_t bytesWritten = 0;
float Rsense = 0.11;
bool CRCerror = false;
protected:
INIT2208_REGISTER(GCONF) {{.sr=0}};
INIT_REGISTER(SLAVECONF) {{.sr=0}};
INIT_REGISTER(FACTORY_CONF) {{.sr=0}};
INIT2208_REGISTER(VACTUAL) {.sr=0};
INIT2208_REGISTER(CHOPCONF) {{.sr=0}};
INIT2208_REGISTER(PWMCONF) {{.sr=0}};
struct IFCNT_t { constexpr static uint8_t address = 0x02; };
struct OTP_PROG_t { constexpr static uint8_t address = 0x04; };
struct OTP_READ_t { constexpr static uint8_t address = 0x05; };
TMC2208Stepper(Stream * SerialPort, float RS, uint8_t addr);
#if SW_CAPABLE_PLATFORM
TMC2208Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin, float RS, uint8_t addr);
#endif
Stream * HWSerial = nullptr;
#if SW_CAPABLE_PLATFORM
SoftwareSerial * SWSerial = nullptr;
const uint16_t RXTX_pin = 0; // Half duplex
#endif