add motor enable handling with a new ON_ENABLE event
[clinton/Smoothieware.git] / src / modules / utils / motordrivercontrol / MotorDriverControl.h
CommitLineData
3eca6882
JM
1#pragma once
2
3#include "Module.h"
4#include "Pin.h"
5
6#include <stdint.h>
7
8namespace mbed {
9 class SPI;
10}
11
45ef09fd
JM
12class DRV8711DRV;
13class TMC26X;
14class StreamOutput;
15
3eca6882
JM
16class MotorDriverControl : public Module {
17 public:
fc320ac5 18 MotorDriverControl(uint8_t id);
3eca6882
JM
19 virtual ~MotorDriverControl();
20
21 void on_module_loaded();
22 void on_gcode_received(void *);
7b35a4c8 23 void on_halt(void *argument);
0bfaf040
JM
24 void on_enable(void *argument);
25 void on_idle(void *argument);
3eca6882
JM
26
27 private:
fc320ac5 28 bool config_module(uint16_t cs);
45ef09fd
JM
29 void initialize_chip();
30 void set_current( uint32_t current );
fc320ac5 31 uint32_t set_microstep( uint32_t ms );
5b0cf319 32 void set_decay_mode( uint8_t dm );
45ef09fd
JM
33 void dump_status(StreamOutput*);
34 void enable(bool on);
35 int sendSPI(uint8_t *b, int cnt, uint8_t *r);
5b0cf319
JM
36
37 Pin spi_cs_pin;
38 mbed::SPI *spi;
39
40 enum CHIP_TYPE {
41 DRV8711,
42 TMC2660
43 };
44 CHIP_TYPE chip;
3eca6882 45
45ef09fd
JM
46 // one of these drivers
47 union {
48 DRV8711DRV *drv8711;
49 TMC26X *tmc26x;
50 };
51
3eca6882 52 float current_factor;
45ef09fd
JM
53 uint32_t max_current; // in milliamps
54 uint32_t current; // in milliamps
fc320ac5 55 uint32_t microsteps;
5b0cf319 56
3eca6882 57 char designator;
7b35a4c8
JM
58
59 struct{
60 uint8_t id:4;
61 uint8_t decay_mode:4;
62 bool rawreg:1;
0bfaf040
JM
63 bool enable_event:1;
64 bool enable_flg:1;
7b35a4c8 65 };
5b0cf319 66
3eca6882 67};