Autodrone
Multi-Domain Vehicle
drv_dshot.h File Reference

This files enables the gpio, timer, and dma peripherals to send dshot commands with pwm. More...

Go to the source code of this file.

Macros

#define TIMER_CLOCK   108000000
 
#define MHZ_TO_HZ(x)   ((x) * 1000000)
 
#define DSHOT600_HZ   MHZ_TO_HZ(108)
 
#define DSHOT300_HZ   MHZ_TO_HZ(54)
 
#define DSHOT150_HZ   MHZ_TO_HZ(27)
 
#define MOTOR_BIT_0   60
 
#define MOTOR_BIT_1   120
 
#define MOTOR_BITLENGTH   180
 
#define DSHOT_FRAME_SIZE   16
 
#define DSHOT_DMA_BUFFER_SIZE   18 /* resolution + frame reset (2us) */
 
#define DSHOT_MIN_THROTTLE   48
 
#define DSHOT_MAX_THROTTLE   2047
 
#define DSHOT_RANGE   (DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE)
 
#define DSHOT_ARM_COUNT   1500
 
#define DSHOT_SETTINGS_COUNT   10
 

Enumerations

enum  dshot_type_e { DSHOT150 , DSHOT300 , DSHOT600 }
 
enum  dshotCommands_e {
  DSHOT_CMD_MOTOR_STOP = 0 , DSHOT_CMD_BEACON1 , DSHOT_CMD_BEACON2 , DSHOT_CMD_BEACON3 ,
  DSHOT_CMD_BEACON4 , DSHOT_CMD_BEACON5 , DSHOT_CMD_ESC_INFO , DSHOT_CMD_SPIN_DIRECTION_1 ,
  DSHOT_CMD_SPIN_DIRECTION_2 , DSHOT_CMD_3D_MODE_OFF , DSHOT_CMD_3D_MODE_ON , DSHOT_CMD_SETTINGS_REQUEST ,
  DSHOT_CMD_SAVE_SETTINGS , DSHOT_CMD_SPIN_DIRECTION_NORMAL = 20 , DSHOT_CMD_SPIN_DIRECTION_REVERSED = 21 , DSHOT_CMD_LED0_ON ,
  DSHOT_CMD_LED1_ON , DSHOT_CMD_LED2_ON , DSHOT_CMD_LED3_ON , DSHOT_CMD_LED0_OFF ,
  DSHOT_CMD_LED1_OFF , DSHOT_CMD_LED2_OFF , DSHOT_CMD_LED3_OFF , DSHOT_CMD_AUDIO_STREAM_MODE_ON_OFF = 30 ,
  DSHOT_CMD_SILENT_MODE_ON_OFF = 31 , DSHOT_CMD_MAX = 47
}
 

Functions

void dshotInit (dshot_type_e dshot_type)
 Initializes the low level registers to set up the timer with PWM DMA. More...
 
void dshotWrite (uint16_t *motor_value)
 Writes to the DMA buffer and starts the DMA stream. More...
 
void dshotWait (uint16_t wait_counts)
 Waits for a certain amount of dshot commands. More...
 

Variables

volatile uint16_t dshot_command_count
 
bool dshot_telemetry
 

Detailed Description

This files enables the gpio, timer, and dma peripherals to send dshot commands with pwm.

Author
Jeremy Wolfe
Date
23 FEB 2022

Macro Definition Documentation

◆ DSHOT150_HZ

#define DSHOT150_HZ   MHZ_TO_HZ(27)

◆ DSHOT300_HZ

#define DSHOT300_HZ   MHZ_TO_HZ(54)

◆ DSHOT600_HZ

#define DSHOT600_HZ   MHZ_TO_HZ(108)

◆ DSHOT_ARM_COUNT

#define DSHOT_ARM_COUNT   1500

◆ DSHOT_DMA_BUFFER_SIZE

#define DSHOT_DMA_BUFFER_SIZE   18 /* resolution + frame reset (2us) */

◆ DSHOT_FRAME_SIZE

#define DSHOT_FRAME_SIZE   16

◆ DSHOT_MAX_THROTTLE

#define DSHOT_MAX_THROTTLE   2047

◆ DSHOT_MIN_THROTTLE

#define DSHOT_MIN_THROTTLE   48

◆ DSHOT_RANGE

#define DSHOT_RANGE   (DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE)

◆ DSHOT_SETTINGS_COUNT

#define DSHOT_SETTINGS_COUNT   10

◆ MHZ_TO_HZ

#define MHZ_TO_HZ (   x)    ((x) * 1000000)

◆ MOTOR_BIT_0

#define MOTOR_BIT_0   60

◆ MOTOR_BIT_1

#define MOTOR_BIT_1   120

◆ MOTOR_BITLENGTH

#define MOTOR_BITLENGTH   180

◆ TIMER_CLOCK

#define TIMER_CLOCK   108000000

Enumeration Type Documentation

◆ dshot_type_e

Enumerator
DSHOT150 
DSHOT300 
DSHOT600 

◆ dshotCommands_e

Enumerator
DSHOT_CMD_MOTOR_STOP 
DSHOT_CMD_BEACON1 
DSHOT_CMD_BEACON2 
DSHOT_CMD_BEACON3 
DSHOT_CMD_BEACON4 
DSHOT_CMD_BEACON5 
DSHOT_CMD_ESC_INFO 
DSHOT_CMD_SPIN_DIRECTION_1 
DSHOT_CMD_SPIN_DIRECTION_2 
DSHOT_CMD_3D_MODE_OFF 
DSHOT_CMD_3D_MODE_ON 
DSHOT_CMD_SETTINGS_REQUEST 
DSHOT_CMD_SAVE_SETTINGS 
DSHOT_CMD_SPIN_DIRECTION_NORMAL 
DSHOT_CMD_SPIN_DIRECTION_REVERSED 
DSHOT_CMD_LED0_ON 
DSHOT_CMD_LED1_ON 
DSHOT_CMD_LED2_ON 
DSHOT_CMD_LED3_ON 
DSHOT_CMD_LED0_OFF 
DSHOT_CMD_LED1_OFF 
DSHOT_CMD_LED2_OFF 
DSHOT_CMD_LED3_OFF 
DSHOT_CMD_AUDIO_STREAM_MODE_ON_OFF 
DSHOT_CMD_SILENT_MODE_ON_OFF 
DSHOT_CMD_MAX 

Function Documentation

◆ dshotInit()

void dshotInit ( dshot_type_e  dshot_type)

Initializes the low level registers to set up the timer with PWM DMA.

Parameters
dshot_typeDSHOT150/300/600. Allows you to adjust the speed. DSHOT600 is preferred
Returns
Void.

◆ dshotWait()

void dshotWait ( uint16_t  wait_counts)

Waits for a certain amount of dshot commands.

Parameters
wait_countsNumber of commands to wait for.
Returns
Void.

◆ dshotWrite()

void dshotWrite ( uint16_t *  motor_value)

Writes to the DMA buffer and starts the DMA stream.

Parameters
*motor_valueA four length array with elements from 0 to 2047.
Returns
Void.

Variable Documentation

◆ dshot_command_count

volatile uint16_t dshot_command_count
extern

◆ dshot_telemetry

bool dshot_telemetry
extern