added M911 to set the raw registers of an advanced chip, for expert users.
[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 33 void dump_status(StreamOutput*);
7b0f0de5
JM
34 void set_raw_register(StreamOutput *stream, uint32_t reg, uint32_t val);
35
45ef09fd
JM
36 void enable(bool on);
37 int sendSPI(uint8_t *b, int cnt, uint8_t *r);
5b0cf319
JM
38
39 Pin spi_cs_pin;
40 mbed::SPI *spi;
41
42 enum CHIP_TYPE {
43 DRV8711,
44 TMC2660
45 };
46 CHIP_TYPE chip;
3eca6882 47
45ef09fd
JM
48 // one of these drivers
49 union {
50 DRV8711DRV *drv8711;
51 TMC26X *tmc26x;
52 };
53
7b0f0de5 54 //float current_factor;
45ef09fd
JM
55 uint32_t max_current; // in milliamps
56 uint32_t current; // in milliamps
fc320ac5 57 uint32_t microsteps;
5b0cf319 58
3eca6882 59 char designator;
7b35a4c8
JM
60
61 struct{
62 uint8_t id:4;
63 uint8_t decay_mode:4;
64 bool rawreg:1;
0bfaf040
JM
65 bool enable_event:1;
66 bool enable_flg:1;
7b35a4c8 67 };
5b0cf319 68
3eca6882 69};