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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
/* ***********************************************************
 * This file was automatically generated on 2018-11-08.      *
 *                                                           *
 * Rust Bindings Version 2.0.3                               *
 *                                                           *
 * If you have a bugfix for this file and want to commit it, *
 * please fix the bug in the generator. You can find a link  *
 * to the generators git repository on tinkerforge.com       *
 *************************************************************/

//! Drives one bipolar stepper motor with up to 38V and 2.5A per phase
use crate::{
    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
    ip_connection::IpConnection,
};
pub enum StepperBrickFunction {
    SetMaxVelocity,
    GetMaxVelocity,
    GetCurrentVelocity,
    SetSpeedRamping,
    GetSpeedRamping,
    FullBrake,
    SetCurrentPosition,
    GetCurrentPosition,
    SetTargetPosition,
    GetTargetPosition,
    SetSteps,
    GetSteps,
    GetRemainingSteps,
    SetStepMode,
    GetStepMode,
    DriveForward,
    DriveBackward,
    Stop,
    GetStackInputVoltage,
    GetExternalInputVoltage,
    GetCurrentConsumption,
    SetMotorCurrent,
    GetMotorCurrent,
    Enable,
    Disable,
    IsEnabled,
    SetDecay,
    GetDecay,
    SetMinimumVoltage,
    GetMinimumVoltage,
    SetSyncRect,
    IsSyncRect,
    SetTimeBase,
    GetTimeBase,
    GetAllData,
    SetAllDataPeriod,
    GetAllDataPeriod,
    SetSpitfpBaudrateConfig,
    GetSpitfpBaudrateConfig,
    GetSendTimeoutCount,
    SetSpitfpBaudrate,
    GetSpitfpBaudrate,
    GetSpitfpErrorCount,
    EnableStatusLed,
    DisableStatusLed,
    IsStatusLedEnabled,
    GetProtocol1BrickletName,
    GetChipTemperature,
    Reset,
    GetIdentity,
    CallbackUnderVoltage,
    CallbackPositionReached,
    CallbackAllData,
    CallbackNewState,
}
impl From<StepperBrickFunction> for u8 {
    fn from(fun: StepperBrickFunction) -> Self {
        match fun {
            StepperBrickFunction::SetMaxVelocity => 1,
            StepperBrickFunction::GetMaxVelocity => 2,
            StepperBrickFunction::GetCurrentVelocity => 3,
            StepperBrickFunction::SetSpeedRamping => 4,
            StepperBrickFunction::GetSpeedRamping => 5,
            StepperBrickFunction::FullBrake => 6,
            StepperBrickFunction::SetCurrentPosition => 7,
            StepperBrickFunction::GetCurrentPosition => 8,
            StepperBrickFunction::SetTargetPosition => 9,
            StepperBrickFunction::GetTargetPosition => 10,
            StepperBrickFunction::SetSteps => 11,
            StepperBrickFunction::GetSteps => 12,
            StepperBrickFunction::GetRemainingSteps => 13,
            StepperBrickFunction::SetStepMode => 14,
            StepperBrickFunction::GetStepMode => 15,
            StepperBrickFunction::DriveForward => 16,
            StepperBrickFunction::DriveBackward => 17,
            StepperBrickFunction::Stop => 18,
            StepperBrickFunction::GetStackInputVoltage => 19,
            StepperBrickFunction::GetExternalInputVoltage => 20,
            StepperBrickFunction::GetCurrentConsumption => 21,
            StepperBrickFunction::SetMotorCurrent => 22,
            StepperBrickFunction::GetMotorCurrent => 23,
            StepperBrickFunction::Enable => 24,
            StepperBrickFunction::Disable => 25,
            StepperBrickFunction::IsEnabled => 26,
            StepperBrickFunction::SetDecay => 27,
            StepperBrickFunction::GetDecay => 28,
            StepperBrickFunction::SetMinimumVoltage => 29,
            StepperBrickFunction::GetMinimumVoltage => 30,
            StepperBrickFunction::SetSyncRect => 33,
            StepperBrickFunction::IsSyncRect => 34,
            StepperBrickFunction::SetTimeBase => 35,
            StepperBrickFunction::GetTimeBase => 36,
            StepperBrickFunction::GetAllData => 37,
            StepperBrickFunction::SetAllDataPeriod => 38,
            StepperBrickFunction::GetAllDataPeriod => 39,
            StepperBrickFunction::SetSpitfpBaudrateConfig => 231,
            StepperBrickFunction::GetSpitfpBaudrateConfig => 232,
            StepperBrickFunction::GetSendTimeoutCount => 233,
            StepperBrickFunction::SetSpitfpBaudrate => 234,
            StepperBrickFunction::GetSpitfpBaudrate => 235,
            StepperBrickFunction::GetSpitfpErrorCount => 237,
            StepperBrickFunction::EnableStatusLed => 238,
            StepperBrickFunction::DisableStatusLed => 239,
            StepperBrickFunction::IsStatusLedEnabled => 240,
            StepperBrickFunction::GetProtocol1BrickletName => 241,
            StepperBrickFunction::GetChipTemperature => 242,
            StepperBrickFunction::Reset => 243,
            StepperBrickFunction::GetIdentity => 255,
            StepperBrickFunction::CallbackUnderVoltage => 31,
            StepperBrickFunction::CallbackPositionReached => 32,
            StepperBrickFunction::CallbackAllData => 40,
            StepperBrickFunction::CallbackNewState => 41,
        }
    }
}
pub const STEPPER_BRICK_STEP_MODE_FULL_STEP: u8 = 1;
pub const STEPPER_BRICK_STEP_MODE_HALF_STEP: u8 = 2;
pub const STEPPER_BRICK_STEP_MODE_QUARTER_STEP: u8 = 4;
pub const STEPPER_BRICK_STEP_MODE_EIGHTH_STEP: u8 = 8;
pub const STEPPER_BRICK_STATE_STOP: u8 = 1;
pub const STEPPER_BRICK_STATE_ACCELERATION: u8 = 2;
pub const STEPPER_BRICK_STATE_RUN: u8 = 3;
pub const STEPPER_BRICK_STATE_DEACCELERATION: u8 = 4;
pub const STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_FORWARD: u8 = 5;
pub const STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_BACKWARD: u8 = 6;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
pub const STEPPER_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpeedRamping {
    pub acceleration: u16,
    pub deacceleration: u16,
}
impl FromByteSlice for SpeedRamping {
    fn bytes_expected() -> usize { 4 }
    fn from_le_bytes(bytes: &[u8]) -> SpeedRamping {
        SpeedRamping { acceleration: <u16>::from_le_bytes(&bytes[0..2]), deacceleration: <u16>::from_le_bytes(&bytes[2..4]) }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AllData {
    pub current_velocity: u16,
    pub current_position: i32,
    pub remaining_steps: i32,
    pub stack_voltage: u16,
    pub external_voltage: u16,
    pub current_consumption: u16,
}
impl FromByteSlice for AllData {
    fn bytes_expected() -> usize { 16 }
    fn from_le_bytes(bytes: &[u8]) -> AllData {
        AllData {
            current_velocity: <u16>::from_le_bytes(&bytes[0..2]),
            current_position: <i32>::from_le_bytes(&bytes[2..6]),
            remaining_steps: <i32>::from_le_bytes(&bytes[6..10]),
            stack_voltage: <u16>::from_le_bytes(&bytes[10..12]),
            external_voltage: <u16>::from_le_bytes(&bytes[12..14]),
            current_consumption: <u16>::from_le_bytes(&bytes[14..16]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AllDataEvent {
    pub current_velocity: u16,
    pub current_position: i32,
    pub remaining_steps: i32,
    pub stack_voltage: u16,
    pub external_voltage: u16,
    pub current_consumption: u16,
}
impl FromByteSlice for AllDataEvent {
    fn bytes_expected() -> usize { 16 }
    fn from_le_bytes(bytes: &[u8]) -> AllDataEvent {
        AllDataEvent {
            current_velocity: <u16>::from_le_bytes(&bytes[0..2]),
            current_position: <i32>::from_le_bytes(&bytes[2..6]),
            remaining_steps: <i32>::from_le_bytes(&bytes[6..10]),
            stack_voltage: <u16>::from_le_bytes(&bytes[10..12]),
            external_voltage: <u16>::from_le_bytes(&bytes[12..14]),
            current_consumption: <u16>::from_le_bytes(&bytes[14..16]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct NewStateEvent {
    pub state_new: u8,
    pub state_previous: u8,
}
impl FromByteSlice for NewStateEvent {
    fn bytes_expected() -> usize { 2 }
    fn from_le_bytes(bytes: &[u8]) -> NewStateEvent {
        NewStateEvent { state_new: <u8>::from_le_bytes(&bytes[0..1]), state_previous: <u8>::from_le_bytes(&bytes[1..2]) }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpBaudrateConfig {
    pub enable_dynamic_baudrate: bool,
    pub minimum_dynamic_baudrate: u32,
}
impl FromByteSlice for SpitfpBaudrateConfig {
    fn bytes_expected() -> usize { 5 }
    fn from_le_bytes(bytes: &[u8]) -> SpitfpBaudrateConfig {
        SpitfpBaudrateConfig {
            enable_dynamic_baudrate: <bool>::from_le_bytes(&bytes[0..1]),
            minimum_dynamic_baudrate: <u32>::from_le_bytes(&bytes[1..5]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpErrorCount {
    pub error_count_ack_checksum: u32,
    pub error_count_message_checksum: u32,
    pub error_count_frame: u32,
    pub error_count_overflow: u32,
}
impl FromByteSlice for SpitfpErrorCount {
    fn bytes_expected() -> usize { 16 }
    fn from_le_bytes(bytes: &[u8]) -> SpitfpErrorCount {
        SpitfpErrorCount {
            error_count_ack_checksum: <u32>::from_le_bytes(&bytes[0..4]),
            error_count_message_checksum: <u32>::from_le_bytes(&bytes[4..8]),
            error_count_frame: <u32>::from_le_bytes(&bytes[8..12]),
            error_count_overflow: <u32>::from_le_bytes(&bytes[12..16]),
        }
    }
}

#[derive(Clone)]
pub struct Protocol1BrickletName {
    pub protocol_version: u8,
    pub firmware_version: [u8; 3],
    pub name: String,
}
impl FromByteSlice for Protocol1BrickletName {
    fn bytes_expected() -> usize { 44 }
    fn from_le_bytes(bytes: &[u8]) -> Protocol1BrickletName {
        Protocol1BrickletName {
            protocol_version: <u8>::from_le_bytes(&bytes[0..1]),
            firmware_version: <[u8; 3]>::from_le_bytes(&bytes[1..4]),
            name: <String>::from_le_bytes(&bytes[4..44]),
        }
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Identity {
    pub uid: String,
    pub connected_uid: String,
    pub position: char,
    pub hardware_version: [u8; 3],
    pub firmware_version: [u8; 3],
    pub device_identifier: u16,
}
impl FromByteSlice for Identity {
    fn bytes_expected() -> usize { 25 }
    fn from_le_bytes(bytes: &[u8]) -> Identity {
        Identity {
            uid: <String>::from_le_bytes(&bytes[0..8]),
            connected_uid: <String>::from_le_bytes(&bytes[8..16]),
            position: <char>::from_le_bytes(&bytes[16..17]),
            hardware_version: <[u8; 3]>::from_le_bytes(&bytes[17..20]),
            firmware_version: <[u8; 3]>::from_le_bytes(&bytes[20..23]),
            device_identifier: <u16>::from_le_bytes(&bytes[23..25]),
        }
    }
}

/// Drives one bipolar stepper motor with up to 38V and 2.5A per phase
#[derive(Clone)]
pub struct StepperBrick {
    device: Device,
}
impl StepperBrick {
    pub const DEVICE_IDENTIFIER: u16 = 15;
    pub const DEVICE_DISPLAY_NAME: &'static str = "Stepper Brick";
    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
    pub fn new(uid: &str, ip_connection: &IpConnection) -> StepperBrick {
        let mut result = StepperBrick { device: Device::new([2, 0, 4], uid, ip_connection, 0) };
        result.device.response_expected[u8::from(StepperBrickFunction::SetMaxVelocity) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetMaxVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetSpeedRamping) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSpeedRamping) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::SetCurrentPosition) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetTargetPosition) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetTargetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetSteps) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSteps) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetRemainingSteps) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetStepMode) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetStepMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::DriveForward) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::DriveBackward) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::Stop) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetStackInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetExternalInputVoltage) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentConsumption) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetMotorCurrent) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetMotorCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetDecay) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetDecay) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(StepperBrickFunction::GetMinimumVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetSyncRect) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::IsSyncRect) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetTimeBase) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetTimeBase) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetAllData) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetAllDataPeriod) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(StepperBrickFunction::GetAllDataPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpBaudrateConfig) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetProtocol1BrickletName) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(StepperBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(StepperBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result
    }

    /// Returns the response expected flag for the function specified by the function ID parameter.
    /// It is true if the function is expected to send a response, false otherwise.
    ///
    /// For getter functions this is enabled by default and cannot be disabled, because those
    /// functions will always send a response. For callback configuration functions it is enabled
    /// by default too, but can be disabled by [`set_response_expected`](crate::stepper_brick::StepperBrick::set_response_expected).
    /// For setter functions it is disabled by default and can be enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts
    /// and other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    ///
    /// See [`set_response_expected`](crate::stepper_brick::StepperBrick::set_response_expected) for the list of function ID constants available for this function.
    pub fn get_response_expected(&mut self, fun: StepperBrickFunction) -> Result<bool, GetResponseExpectedError> {
        self.device.get_response_expected(u8::from(fun))
    }

    /// Changes the response expected flag of the function specified by the function ID parameter.
    /// This flag can only be changed for setter (default value: false) and callback configuration
    /// functions (default value: true). For getter functions it is always enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts and
    /// other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    pub fn set_response_expected(&mut self, fun: StepperBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
        self.device.set_response_expected(u8::from(fun), response_expected)
    }

    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }

    /// This receiver is triggered when the input voltage drops below the value set by
    /// `Set Minimum Voltage`. The parameter is the current voltage given
    /// in mV.
    pub fn get_under_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
        self.device.get_callback_receiver(u8::from(StepperBrickFunction::CallbackUnderVoltage))
    }

    /// This receiver is triggered when a position set by `Set Steps` or
    /// `Set Target Position` is reached.
    ///
    /// # Note
    ///  Since we can't get any feedback from the stepper motor, this only works if the
    ///  acceleration (see `Set Speed Ramping`) is set smaller or equal to the
    ///  maximum acceleration of the motor. Otherwise the motor will lag behind the
    ///  control value and the receiver will be triggered too early.
    pub fn get_position_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<i32> {
        self.device.get_callback_receiver(u8::from(StepperBrickFunction::CallbackPositionReached))
    }

    /// This receiver is triggered periodically with the period that is set by
    /// `Set All Data Period`. The parameters are: the current velocity,
    /// the current position, the remaining steps, the stack voltage, the external
    /// voltage and the current consumption of the stepper motor.
    pub fn get_all_data_callback_receiver(&self) -> ConvertingCallbackReceiver<AllDataEvent> {
        self.device.get_callback_receiver(u8::from(StepperBrickFunction::CallbackAllData))
    }

    /// This receiver is triggered whenever the Stepper Brick enters a new state.
    /// It returns the new state as well as the previous state.
    pub fn get_new_state_callback_receiver(&self) -> ConvertingCallbackReceiver<NewStateEvent> {
        self.device.get_callback_receiver(u8::from(StepperBrickFunction::CallbackNewState))
    }

    /// Sets the maximum velocity of the stepper motor in steps per second.
    /// This function does *not* start the motor, it merely sets the maximum
    /// velocity the stepper motor is accelerated to. To get the motor running use
    /// either `Set Target Position`, `Set Steps`, `Drive Forward` or
    /// `Drive Backward`.
    pub fn set_max_velocity(&self, velocity: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(velocity));

        self.device.set(u8::from(StepperBrickFunction::SetMaxVelocity), payload)
    }

    /// Returns the velocity as set by `Set Max Velocity`.
    pub fn get_max_velocity(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetMaxVelocity), payload)
    }

    /// Returns the *current* velocity of the stepper motor in steps per second.
    pub fn get_current_velocity(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetCurrentVelocity), payload)
    }

    /// Sets the acceleration and deacceleration of the stepper motor. The values
    /// are given in *steps/s²*. An acceleration of 1000 means, that
    /// every second the velocity is increased by 1000 *steps/s*.
    ///
    /// For example: If the current velocity is 0 and you want to accelerate to a
    /// velocity of 8000 *steps/s* in 10 seconds, you should set an acceleration
    /// of 800 *steps/s²*.
    ///
    /// An acceleration/deacceleration of 0 means instantaneous
    /// acceleration/deacceleration (not recommended)
    ///
    /// The default value is 1000 for both
    pub fn set_speed_ramping(&self, acceleration: u16, deacceleration: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(acceleration));
        payload[2..4].copy_from_slice(&<u16>::to_le_bytes(deacceleration));

        self.device.set(u8::from(StepperBrickFunction::SetSpeedRamping), payload)
    }

    /// Returns the acceleration and deacceleration as set by
    /// `Set Speed Ramping`.
    pub fn get_speed_ramping(&self) -> ConvertingReceiver<SpeedRamping> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetSpeedRamping), payload)
    }

    /// Executes an active full brake.
    ///
    /// # Warning
    ///  This function is for emergency purposes,
    ///  where an immediate brake is necessary. Depending on the current velocity and
    ///  the strength of the motor, a full brake can be quite violent.
    ///
    /// Call `Stop` if you just want to stop the motor.
    pub fn full_brake(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::FullBrake), payload)
    }

    /// Sets the current steps of the internal step counter. This can be used to
    /// set the current position to 0 when some kind of starting position
    /// is reached (e.g. when a CNC machine reaches a corner).
    pub fn set_current_position(&self, position: i32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<i32>::to_le_bytes(position));

        self.device.set(u8::from(StepperBrickFunction::SetCurrentPosition), payload)
    }

    /// Returns the current position of the stepper motor in steps. On startup
    /// the position is 0. The steps are counted with all possible driving
    /// functions (`Set Target Position`, `Set Steps`, `Drive Forward` or
    /// `Drive Backward`). It also is possible to reset the steps to 0 or
    /// set them to any other desired value with `Set Current Position`.
    pub fn get_current_position(&self) -> ConvertingReceiver<i32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetCurrentPosition), payload)
    }

    /// Sets the target position of the stepper motor in steps. For example,
    /// if the current position of the motor is 500 and `Set Target Position` is
    /// called with 1000, the stepper motor will drive 500 steps forward. It will
    /// use the velocity, acceleration and deacceleration as set by
    /// `Set Max Velocity` and `Set Speed Ramping`.
    ///
    /// A call of `Set Target Position` with the parameter *x* is equivalent to
    /// a call of `Set Steps` with the parameter
    /// (*x* - `Get Current Position`).
    pub fn set_target_position(&self, position: i32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<i32>::to_le_bytes(position));

        self.device.set(u8::from(StepperBrickFunction::SetTargetPosition), payload)
    }

    /// Returns the last target position as set by `Set Target Position`.
    pub fn get_target_position(&self) -> ConvertingReceiver<i32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetTargetPosition), payload)
    }

    /// Sets the number of steps the stepper motor should run. Positive values
    /// will drive the motor forward and negative values backward.
    /// The velocity, acceleration and deacceleration as set by
    /// `Set Max Velocity` and `Set Speed Ramping` will be used.
    pub fn set_steps(&self, steps: i32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<i32>::to_le_bytes(steps));

        self.device.set(u8::from(StepperBrickFunction::SetSteps), payload)
    }

    /// Returns the last steps as set by `Set Steps`.
    pub fn get_steps(&self) -> ConvertingReceiver<i32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetSteps), payload)
    }

    /// Returns the remaining steps of the last call of `Set Steps`.
    /// For example, if `Set Steps` is called with 2000 and
    /// `Get Remaining Steps` is called after the motor has run for 500 steps,
    /// it will return 1500.
    pub fn get_remaining_steps(&self) -> ConvertingReceiver<i32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetRemainingSteps), payload)
    }

    /// Sets the step mode of the stepper motor. Possible values are:
    ///
    /// * Full Step = 1
    /// * Half Step = 2
    /// * Quarter Step = 4
    /// * Eighth Step = 8
    ///
    /// A higher value will increase the resolution and
    /// decrease the torque of the stepper motor.
    ///
    /// The default value is 8 (Eighth Step).
    ///
    /// Associated constants:
    /// * STEPPERBRICK_STEP_MODE_FULL_STEP
    ///	* STEPPERBRICK_STEP_MODE_HALF_STEP
    ///	* STEPPERBRICK_STEP_MODE_QUARTER_STEP
    ///	* STEPPERBRICK_STEP_MODE_EIGHTH_STEP
    pub fn set_step_mode(&self, mode: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(mode));

        self.device.set(u8::from(StepperBrickFunction::SetStepMode), payload)
    }

    /// Returns the step mode as set by `Set Step Mode`.
    ///
    /// Associated constants:
    /// * STEPPERBRICK_STEP_MODE_FULL_STEP
    ///	* STEPPERBRICK_STEP_MODE_HALF_STEP
    ///	* STEPPERBRICK_STEP_MODE_QUARTER_STEP
    ///	* STEPPERBRICK_STEP_MODE_EIGHTH_STEP
    pub fn get_step_mode(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetStepMode), payload)
    }

    /// Drives the stepper motor forward until `Drive Backward` or
    /// `Stop` is called. The velocity, acceleration and deacceleration as
    /// set by `Set Max Velocity` and `Set Speed Ramping` will be used.
    pub fn drive_forward(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::DriveForward), payload)
    }

    /// Drives the stepper motor backward until `Drive Forward` or
    /// `Stop` is triggered. The velocity, acceleration and deacceleration as
    /// set by `Set Max Velocity` and `Set Speed Ramping` will be used.
    pub fn drive_backward(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::DriveBackward), payload)
    }

    /// Stops the stepper motor with the deacceleration as set by
    /// `Set Speed Ramping`.
    pub fn stop(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::Stop), payload)
    }

    /// Returns the stack input voltage in mV. The stack input voltage is the
    /// voltage that is supplied via the stack, i.e. it is given by a
    /// Step-Down or Step-Up Power Supply.
    pub fn get_stack_input_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetStackInputVoltage), payload)
    }

    /// Returns the external input voltage in mV. The external input voltage is
    /// given via the black power input connector on the Stepper Brick.
    ///
    /// If there is an external input voltage and a stack input voltage, the motor
    /// will be driven by the external input voltage. If there is only a stack
    /// voltage present, the motor will be driven by this voltage.
    ///
    /// # Warning
    ///  This means, if you have a high stack voltage and a low external voltage,
    ///  the motor will be driven with the low external voltage. If you then remove
    ///  the external connection, it will immediately be driven by the high
    ///  stack voltage
    pub fn get_external_input_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetExternalInputVoltage), payload)
    }

    /// Returns the current consumption of the motor in mA.
    pub fn get_current_consumption(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetCurrentConsumption), payload)
    }

    /// Sets the current in mA with which the motor will be driven.
    /// The minimum value is 100mA, the maximum value 2291mA and the
    /// default value is 800mA.
    ///
    /// # Warning
    ///  Do not set this value above the specifications of your stepper motor.
    ///  Otherwise it may damage your motor.
    pub fn set_motor_current(&self, current: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(current));

        self.device.set(u8::from(StepperBrickFunction::SetMotorCurrent), payload)
    }

    /// Returns the current as set by `Set Motor Current`.
    pub fn get_motor_current(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetMotorCurrent), payload)
    }

    /// Enables the driver chip. The driver parameters can be configured (maximum velocity,
    /// acceleration, etc) before it is enabled.
    pub fn enable(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::Enable), payload)
    }

    /// Disables the driver chip. The configurations are kept (maximum velocity,
    /// acceleration, etc) but the motor is not driven until it is enabled again.
    pub fn disable(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::Disable), payload)
    }

    /// Returns *true* if the driver chip is enabled, *false* otherwise.
    pub fn is_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::IsEnabled), payload)
    }

    /// Sets the decay mode of the stepper motor. The possible value range is
    /// between 0 and 65535. A value of 0 sets the fast decay mode, a value of
    /// 65535 sets the slow decay mode and a value in between sets the mixed
    /// decay mode.
    ///
    /// Changing the decay mode is only possible if synchronous rectification
    /// is enabled (see [Set Sync Rect`).
    ///
    /// For a good explanation of the different decay modes see
    /// `this](http://ebldc.com/?p=86/)__ blog post by Avayan.
    ///
    /// A good decay mode is unfortunately different for every motor. The best
    /// way to work out a good decay mode for your stepper motor, if you can't
    /// measure the current with an oscilloscope, is to listen to the sound of
    /// the motor. If the value is too low, you often hear a high pitched
    /// sound and if it is too high you can often hear a humming sound.
    ///
    /// Generally, fast decay mode (small value) will be noisier but also
    /// allow higher motor speeds.
    ///
    /// The default value is 10000.
    ///
    /// # Note
    ///  There is unfortunately no formula to calculate a perfect decay
    ///  mode for a given stepper motor. If you have problems with loud noises
    ///  or the maximum motor speed is too slow, you should try to tinker with
    ///  the decay value
    pub fn set_decay(&self, decay: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(decay));

        self.device.set(u8::from(StepperBrickFunction::SetDecay), payload)
    }

    /// Returns the decay mode as set by `Set Decay`.
    pub fn get_decay(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetDecay), payload)
    }

    /// Sets the minimum voltage in mV, below which the [`get_under_voltage_callback_receiver`] receiver
    /// is triggered. The minimum possible value that works with the Stepper Brick is 8V.
    /// You can use this function to detect the discharge of a battery that is used
    /// to drive the stepper motor. If you have a fixed power supply, you likely do
    /// not need this functionality.
    ///
    /// The default value is 8V.
    ///
    /// [`get_under_voltage_callback_receiver`]: #method.get_under_voltage_callback_receiver
    pub fn set_minimum_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_bytes(voltage));

        self.device.set(u8::from(StepperBrickFunction::SetMinimumVoltage), payload)
    }

    /// Returns the minimum voltage as set by `Set Minimum Voltage`.
    pub fn get_minimum_voltage(&self) -> ConvertingReceiver<u16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetMinimumVoltage), payload)
    }

    /// Turns synchronous rectification on or off (*true* or *false*).
    ///
    /// With synchronous rectification on, the decay can be changed
    /// (see [Set Decay`). Without synchronous rectification fast
    /// decay is used.
    ///
    /// For an explanation of synchronous rectification see
    /// `here](https://en.wikipedia.org/wiki/Active_rectification)__.
    ///
    /// # Warning
    ///  If you want to use high speeds (> 10000 steps/s) for a large
    ///  stepper motor with a large inductivity we strongly
    ///  suggest that you disable synchronous rectification. Otherwise the
    ///  Brick may not be able to cope with the load and overheat.
    ///
    /// The default value is *false*.
    pub fn set_sync_rect(&self, sync_rect: bool) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<bool>::to_le_bytes(sync_rect));

        self.device.set(u8::from(StepperBrickFunction::SetSyncRect), payload)
    }

    /// Returns *true* if synchronous rectification is enabled, *false* otherwise.
    pub fn is_sync_rect(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::IsSyncRect), payload)
    }

    /// Sets the time base of the velocity and the acceleration of the stepper brick
    /// (in seconds).
    ///
    /// For example, if you want to make one step every 1.5 seconds, you can set
    /// the time base to 15 and the velocity to 10. Now the velocity is
    /// 10steps/15s = 1steps/1.5s.
    ///
    /// The default value is 1.
    pub fn set_time_base(&self, time_base: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<u32>::to_le_bytes(time_base));

        self.device.set(u8::from(StepperBrickFunction::SetTimeBase), payload)
    }

    /// Returns the time base as set by `Set Time Base`.
    pub fn get_time_base(&self) -> ConvertingReceiver<u32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetTimeBase), payload)
    }

    /// Returns the following parameters: The current velocity,
    /// the current position, the remaining steps, the stack voltage, the external
    /// voltage and the current consumption of the stepper motor.
    ///
    /// There is also a receiver for this function, see [`get_all_data_callback_receiver`] receiver.
    ///
    /// [`get_all_data_callback_receiver`]: #method.get_all_data_callback_receiver
    pub fn get_all_data(&self) -> ConvertingReceiver<AllData> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetAllData), payload)
    }

    /// Sets the period in ms with which the [`get_all_data_callback_receiver`] receiver is triggered
    /// periodically. A value of 0 turns the receiver off.
    ///
    /// [`get_all_data_callback_receiver`]: #method.get_all_data_callback_receiver
    pub fn set_all_data_period(&self, period: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<u32>::to_le_bytes(period));

        self.device.set(u8::from(StepperBrickFunction::SetAllDataPeriod), payload)
    }

    /// Returns the period as set by `Set All Data Period`.
    pub fn get_all_data_period(&self) -> ConvertingReceiver<u32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetAllDataPeriod), payload)
    }

    /// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
    /// enabled, the Brick will try to adapt the baudrate for the communication
    /// between Bricks and Bricklets according to the amount of data that is transferred.
    ///
    /// The baudrate will be increased exponentially if lots of data is send/received and
    /// decreased linearly if little data is send/received.
    ///
    /// This lowers the baudrate in applications where little data is transferred (e.g.
    /// a weather station) and increases the robustness. If there is lots of data to transfer
    /// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
    ///
    /// In cases where some data has to transferred as fast as possible every few seconds
    /// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
    /// the dynamic baudrate off to get the highest possible performance.
    ///
    /// The maximum value of the baudrate can be set per port with the function
    /// `Set SPITFP Baudrate`. If the dynamic baudrate is disabled, the baudrate
    /// as set by `Set SPITFP Baudrate` will be used statically.
    ///
    /// The minimum dynamic baudrate has a value range of 400000 to 2000000 baud.
    ///
    /// By default dynamic baudrate is enabled and the minimum dynamic baudrate is 400000.
    ///
    ///
    /// .. versionadded:: 2.3.6$nbsp;(Firmware)
    pub fn set_spitfp_baudrate_config(&self, enable_dynamic_baudrate: bool, minimum_dynamic_baudrate: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<bool>::to_le_bytes(enable_dynamic_baudrate));
        payload[1..5].copy_from_slice(&<u32>::to_le_bytes(minimum_dynamic_baudrate));

        self.device.set(u8::from(StepperBrickFunction::SetSpitfpBaudrateConfig), payload)
    }

    /// Returns the baudrate config, see `Set SPITFP Baudrate Config`.
    ///
    ///
    /// .. versionadded:: 2.3.6$nbsp;(Firmware)
    pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetSpitfpBaudrateConfig), payload)
    }

    /// Returns the timeout count for the different communication methods.
    ///
    /// The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
    ///
    /// This function is mostly used for debugging during development, in normal operation
    /// the counters should nearly always stay at 0.
    ///
    ///
    /// .. versionadded:: 2.3.4$nbsp;(Firmware)
    ///
    /// Associated constants:
    /// * STEPPERBRICK_COMMUNICATION_METHOD_NONE
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_USB
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_SPI_STACK
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_CHIBI
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_RS485
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_WIFI
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_ETHERNET
    ///	* STEPPERBRICK_COMMUNICATION_METHOD_WIFI_V2
    pub fn get_send_timeout_count(&self, communication_method: u8) -> ConvertingReceiver<u32> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_bytes(communication_method));

        self.device.get(u8::from(StepperBrickFunction::GetSendTimeoutCount), payload)
    }

    /// Sets the baudrate for a specific Bricklet port ('a' - 'd'). The
    /// baudrate can be in the range 400000 to 2000000.
    ///
    /// If you want to increase the throughput of Bricklets you can increase
    /// the baudrate. If you get a high error count because of high
    /// interference (see `Get SPITFP Error Count`) you can decrease the
    /// baudrate.
    ///
    /// If the dynamic baudrate feature is enabled, the baudrate set by this
    /// function corresponds to the maximum baudrate (see `Set SPITFP Baudrate Config`).
    ///
    /// Regulatory testing is done with the default baudrate. If CE compatibility
    /// or similar is necessary in you applications we recommend to not change
    /// the baudrate.
    ///
    /// The default baudrate for all ports is 1400000.
    ///
    ///
    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
    pub fn set_spitfp_baudrate(&self, bricklet_port: char, baudrate: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));
        payload[1..5].copy_from_slice(&<u32>::to_le_bytes(baudrate));

        self.device.set(u8::from(StepperBrickFunction::SetSpitfpBaudrate), payload)
    }

    /// Returns the baudrate for a given Bricklet port, see `Set SPITFP Baudrate`.
    ///
    ///
    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
    pub fn get_spitfp_baudrate(&self, bricklet_port: char) -> ConvertingReceiver<u32> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));

        self.device.get(u8::from(StepperBrickFunction::GetSpitfpBaudrate), payload)
    }

    /// Returns the error count for the communication between Brick and Bricklet.
    ///
    /// The errors are divided into
    ///
    /// * ACK checksum errors,
    /// * message checksum errors,
    /// * framing errors and
    /// * overflow errors.
    ///
    /// The errors counts are for errors that occur on the Brick side. All
    /// Bricklets have a similar function that returns the errors on the Bricklet side.
    ///
    ///
    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
    pub fn get_spitfp_error_count(&self, bricklet_port: char) -> ConvertingReceiver<SpitfpErrorCount> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(bricklet_port));

        self.device.get(u8::from(StepperBrickFunction::GetSpitfpErrorCount), payload)
    }

    /// Enables the status LED.
    ///
    /// The status LED is the blue LED next to the USB connector. If enabled is is
    /// on and it flickers if data is transfered. If disabled it is always off.
    ///
    /// The default state is enabled.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::EnableStatusLed), payload)
    }

    /// Disables the status LED.
    ///
    /// The status LED is the blue LED next to the USB connector. If enabled is is
    /// on and it flickers if data is transfered. If disabled it is always off.
    ///
    /// The default state is enabled.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::DisableStatusLed), payload)
    }

    /// Returns *true* if the status LED is enabled, *false* otherwise.
    ///
    ///
    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
    pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::IsStatusLedEnabled), payload)
    }

    /// Returns the firmware and protocol version and the name of the Bricklet for a
    /// given port.
    ///
    /// This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
    /// plugins.
    pub fn get_protocol1_bricklet_name(&self, port: char) -> ConvertingReceiver<Protocol1BrickletName> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<char>::to_le_bytes(port));

        self.device.get(u8::from(StepperBrickFunction::GetProtocol1BrickletName), payload)
    }

    /// Returns the temperature in °C/10 as measured inside the microcontroller. The
    /// value returned is not the ambient temperature!
    ///
    /// The temperature is only proportional to the real temperature and it has an
    /// accuracy of +-15%. Practically it is only useful as an indicator for
    /// temperature changes.
    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetChipTemperature), payload)
    }

    /// Calling this function will reset the Brick. Calling this function
    /// on a Brick inside of a stack will reset the whole stack.
    ///
    /// After a reset you have to create new device objects,
    /// calling functions on the existing ones will result in
    /// undefined behavior!
    pub fn reset(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(StepperBrickFunction::Reset), payload)
    }

    /// Returns the UID, the UID where the Brick is connected to,
    /// the position, the hardware and firmware version as well as the
    /// device identifier.
    ///
    /// The position can be '0'-'8' (stack position).
    ///
    /// The device identifier numbers can be found [here](device_identifier).
    /// |device_identifier_constant|
    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
        let payload = vec![0; 0];

        self.device.get(u8::from(StepperBrickFunction::GetIdentity), payload)
    }
}