Aruna
Dshot.h
Go to the documentation of this file.
1 //
2 // Created by noeel on 22-03-20.
3 //
4 
5 #ifndef ARUNA_DSHOT_H
6 #define ARUNA_DSHOT_H
7 
9 #include "pthread.h"
10 
11 namespace aruna {
12  namespace driver {
13  class Dshot: public movement::Actuator {
14  private:
15  bool _continues_write = false;
16  pthread_mutex_t write_mut;
17  const uint32_t frequency;
19 
20 
25  void add_CRC(uint16_t &bits);
26 
27 
34  uint16_t create_dshotFrame(uint16_t speed, uint8_t telemetry);
35 
36  err_t _set(movement::axis_mask_t axisMask, int16_t speed) override;
37 
45  err_t write_frame_continuous(uint16_t dshot_frame);
46 
54  virtual err_t _write_frame_continuous(uint16_t dshot_frame) = 0;
55 
56  protected:
57  uint16_t T0H_ns;
58  uint16_t T1H_ns;
59  uint16_t T0L_ns;
60  uint16_t T1L_ns;
61  public:
67  Dshot(uint32_t speed_hz = 150000, bool bidirectional = false);
68 
73  uint32_t get_frequency();
74 
82  err_t set_speed(int16_t speed);
83 
88  bool get_bidirectional();
89 
94  void set_bidirectional(bool is_bidirectional);
95 
99  void arm_ESC();
100 
101  ~Dshot();
102 
103 
104  };
105  }
106 }
107 
108 
109 #endif //ARUNA_DSHOT_H
uint32_t get_frequency()
get frequency of the driver
Definition: Dshot.cpp:120
Definition: comm.cpp:14
bool bidirectional
Definition: Dshot.h:18
err_t _set(movement::axis_mask_t axisMask, int16_t speed) override
Implementation of axis movement, this function is called from set(...).
Definition: Dshot.cpp:35
uint16_t T1H_ns
Definition: Dshot.h:58
err_t write_frame_continuous(uint16_t dshot_frame)
Write set Dshot frame continuously on the bus.
Definition: Dshot.cpp:108
const uint32_t frequency
Definition: Dshot.h:17
void add_CRC(uint16_t &bits)
add CRC to end of bit stream.
Definition: Dshot.cpp:62
Dshot(uint32_t speed_hz=150000, bool bidirectional=false)
Dshot parent object.
Definition: Dshot.cpp:13
bool get_bidirectional()
Is this Dshot driver birectional (can spin both ways)
Definition: Dshot.cpp:124
void set_bidirectional(bool is_bidirectional)
Set bidirectional property of the driver.
Definition: Dshot.cpp:128
err_t set_speed(int16_t speed)
Set speed, use negative values to rotate in the other direction if bidirectional is enabled...
Definition: Dshot.cpp:39
virtual err_t _write_frame_continuous(uint16_t dshot_frame)=0
Write set Dshot frame continuously on the bus.
uint16_t T0L_ns
Definition: Dshot.h:59
void arm_ESC()
Call the function after the constructor to arm the ESC.
Definition: Dshot.cpp:83
pthread_mutex_t write_mut
Definition: Dshot.h:16
Link * driver
stores the driver.
Definition: comm.cpp:45
uint16_t T1L_ns
Definition: Dshot.h:60
uint16_t T0H_ns
Definition: Dshot.h:57
uint16_t create_dshotFrame(uint16_t speed, uint8_t telemetry)
craft dshot package
Definition: Dshot.cpp:75
bool _continues_write
Definition: Dshot.h:15