Paparazzi UAS  v5.15_devel-47-g0391b4d
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
esc_dshot.h File Reference

DSHOT driver based on ChibiOS. More...

#include <ch.h>
#include <hal.h>
#include "mcu_periph/hal_stm32_dma.h"
+ Include dependency graph for esc_dshot.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  DshotTelemetry
 telemetry packed as sent by some KISS ESC More...
 
struct  DSHOTConfig
 DSHOT Driver configuration structure. More...
 
union  DshotPacket
 
struct  DshotPackets
 
union  DshotDmaBuffer
 
struct  DSHOTDriver
 DSHOT driver structure. More...
 
union  DshotTelemetry.__unnamed__
 
struct  DshotTelemetry.__unnamed__.__unnamed__
 
struct  DshotPacket.__unnamed__
 

Macros

#define DSHOT_AT_LEAST_ONE_32B_TIMER   TRUE
 By default enable the possibility to mix 16 and 32 bits timer. More...
 
#define DSHOT_BIT_WIDTHS   16
 DMA buffer size and number of channels. More...
 
#define DSHOT_FRAME_SILENT_SYNC_BITS   4
 
#define DSHOT_DMA_BUFFER_SIZE   (DSHOT_BIT_WIDTHS+DSHOT_FRAME_SILENT_SYNC_BITS)
 
#define DSHOT_CHANNELS   4
 
#define DSHOT_ALL_MOTORS   255
 special value for index : send order to all channels More...
 

Typedefs

typedef struct DSHOTDriver DSHOTDriver
 Type of a structure representing an DSHOT driver. More...
 

Enumerations

enum  dshotstate_t {
  DSHOT_UNINIT = 0, DSHOT_STOP, DSHOT_READY, DSHOT_ONGOING_TELEMETRY_QUERY,
  DSHOT_ERROR
}
 Driver state machine possible states. More...
 
enum  dshot_special_commands_t {
  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
}
 DSHOT special commands (0-47) for KISS and BLHELI ESC. More...
 

Functions

void dshotStart (DSHOTDriver *driver, const DSHOTConfig *config)
 Configures and activates the DSHOT peripheral. More...
 
void dshotSetThrottle (DSHOTDriver *driver, const uint8_t index, const uint16_t throttle)
 prepare throttle order for specified ESC More...
 
void dshotSendFrame (DSHOTDriver *driver)
 send throttle order More...
 
void dshotSendThrottles (DSHOTDriver *driver, const uint16_t throttles[DSHOT_CHANNELS])
 send throttle packed order to all of the ESCs More...
 
void dshotSendSpecialCommand (DSHOTDriver *driver, const uint8_t index, const dshot_special_commands_t specmd)
 send special order to one of the ESC (BHELIX, KISS, ...) More...
 
uint32_t dshotGetCrcErrorsCount (DSHOTDriver *driver)
 return number of telemetry crc error since dshotStart More...
 
const DshotTelemetrydshotGetTelemetry (const DSHOTDriver *driver, const uint32_t index)
 return last received telemetry data More...
 

Detailed Description

DSHOT driver based on ChibiOS.

Author
Alexandre Bustico Gautier Hattenberger gauti.nosp@m.er.h.nosp@m.atten.nosp@m.berg.nosp@m.er@en.nosp@m.ac.f.nosp@m.r

Definition in file esc_dshot.h.


Data Structure Documentation

struct DshotTelemetry

telemetry packed as sent by some KISS ESC

Note
if other ESC use different binary representation in the future we'll have to add a little bit abstraction here

Definition at line 117 of file esc_dshot.h.

Data Fields
union DshotTelemetry __unnamed__
uint8_t crc8
struct DSHOTConfig

DSHOT Driver configuration structure.

Definition at line 141 of file esc_dshot.h.

Data Fields
uint8_t dma_channel : dma channel associated with pwm timer used to generate dshot output
uint32_t dma_stream : dma stream associated with pwm timer used to generate dshot output
PWMDriver * pwmp PWM driver that feed up to 4 dshot lines.
SerialDriver * tlm_sd if non null : dshot telemetry serial driver
union DshotPacket

Definition at line 182 of file esc_dshot.h.

+ Collaboration diagram for DshotPacket:
Data Fields
struct DshotPacket __unnamed__
uint16_t rawFrame
struct DshotPackets

Definition at line 191 of file esc_dshot.h.

+ Collaboration diagram for DshotPackets:
Data Fields
volatile uint8_t currentTlmQry
DshotPacket dp[DSHOT_CHANNELS]
DshotTelemetry dt[DSHOT_CHANNELS]
volatile bool onGoingQry
union DshotDmaBuffer

Definition at line 198 of file esc_dshot.h.

Data Fields
uint16_t widths16[DSHOT_DMA_BUFFER_SIZE][DSHOT_CHANNELS]
union DshotTelemetry.__unnamed__

Definition at line 118 of file esc_dshot.h.

Data Fields
__unnamed__ __unnamed__
uint8_t rawData[9]
struct DshotTelemetry.__unnamed__.__unnamed__

Definition at line 119 of file esc_dshot.h.

Data Fields
uint16_t consumption
uint16_t current
uint16_t rpm
uint8_t temp
uint16_t voltage
struct DshotPacket.__unnamed__

Definition at line 183 of file esc_dshot.h.

Data Fields
uint16_t crc: 4
uint16_t telemetryRequest: 1
uint16_t throttle: 11

Macro Definition Documentation

#define DSHOT_ALL_MOTORS   255

special value for index : send order to all channels

Note
could be used as index in dshotSetThrottle and dshotSendSpecialCommand functions

Definition at line 55 of file esc_dshot.h.

Referenced by dshotSendSpecialCommand(), and dshotSetThrottle().

#define DSHOT_AT_LEAST_ONE_32B_TIMER   TRUE

By default enable the possibility to mix 16 and 32 bits timer.

Definition at line 40 of file esc_dshot.h.

#define DSHOT_BIT_WIDTHS   16

DMA buffer size and number of channels.

Definition at line 45 of file esc_dshot.h.

Referenced by buildDshotDmaBuffer().

#define DSHOT_CHANNELS   4
#define DSHOT_DMA_BUFFER_SIZE   (DSHOT_BIT_WIDTHS+DSHOT_FRAME_SILENT_SYNC_BITS)

Definition at line 47 of file esc_dshot.h.

Referenced by dshotSendFrame(), and dshotStart().

#define DSHOT_FRAME_SILENT_SYNC_BITS   4

Definition at line 46 of file esc_dshot.h.

Typedef Documentation

typedef struct DSHOTDriver DSHOTDriver

Type of a structure representing an DSHOT driver.

Definition at line 135 of file esc_dshot.h.

Enumeration Type Documentation

DSHOT special commands (0-47) for KISS and BLHELI ESC.

Note
commands 48-2047 are used to send motor power
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 

Definition at line 83 of file esc_dshot.h.

Driver state machine possible states.

Enumerator
DSHOT_UNINIT 

Not initialized.

DSHOT_STOP 

Stopped.

DSHOT_READY 

Ready.

DSHOT_ONGOING_TELEMETRY_QUERY 

Transfering.

DSHOT_ERROR 

Transfert error.

Definition at line 60 of file esc_dshot.h.

Function Documentation

uint32_t dshotGetCrcErrorsCount ( DSHOTDriver driver)

return number of telemetry crc error since dshotStart

Parameters
[in]driverpointer to the DSHOTDriver object
Returns
number of CRC errors

Definition at line 330 of file esc_dshot.c.

References DSHOTDriver::crc_errors.

const DshotTelemetry* dshotGetTelemetry ( const DSHOTDriver driver,
const uint32_t  index 
)

return last received telemetry data

Parameters
[in]driverpointer to the DSHOTDriver object
[in]indexchannel : [0..3] or [0..1] depending on driver used
Returns
pointer on a telemetry structure

Definition at line 343 of file esc_dshot.c.

References DSHOTDriver::dshotMotors, and DshotPackets::dt.

void dshotSendFrame ( DSHOTDriver driver)

send throttle order

Parameters
[in]driverpointer to the DSHOTDriver object
Note
dshotSetXXX api should be called prior to this function

Definition at line 303 of file esc_dshot.c.

References buildDshotDmaBuffer(), DSHOTDriver::config, DshotPackets::currentTlmQry, DMA_READY, DSHOTDriver::dmap, dmaStartTransfert(), DshotPackets::dp, DSHOTDriver::dsdb, DSHOT_CHANNELS, DSHOT_DMA_BUFFER_SIZE, DSHOTDriver::dshotMotors, getTimerWidth(), DSHOTDriver::mb, DshotPackets::onGoingQry, DSHOTConfig::pwmp, setDshotPacketTlm(), DMADriver::state, and DSHOTConfig::tlm_sd.

Referenced by actuators_dshot_arch_commit(), dshotSendSpecialCommand(), and dshotSendThrottles().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dshotSendSpecialCommand ( DSHOTDriver driver,
const uint8_t  index,
const dshot_special_commands_t  specmd 
)

send special order to one of the ESC (BHELIX, KISS, ...)

Parameters
[in]driverpointer to the DSHOTDriver object
[in]indexchannel : [0..3] or [0..1] depending on driver used
[in]specmdspecial commands, see enum

Definition at line 240 of file esc_dshot.c.

References DSHOTDriver::config, DshotPackets::dp, DSHOT_ALL_MOTORS, DSHOT_CHANNELS, DSHOT_CMD_3D_MODE_OFF, DSHOT_CMD_3D_MODE_ON, DSHOT_CMD_AUDIO_STREAM_MODE_ON_OFF, DSHOT_CMD_MAX, DSHOT_CMD_SAVE_SETTINGS, DSHOT_CMD_SETTINGS_REQUEST, DSHOT_CMD_SILENT_MODE_ON_OFF, DSHOT_CMD_SPIN_DIRECTION_1, DSHOT_CMD_SPIN_DIRECTION_2, DSHOTDriver::dshotMotors, dshotSendFrame(), setDshotPacketThrottle(), setDshotPacketTlm(), and DSHOTConfig::tlm_sd.

+ Here is the call graph for this function:

void dshotSendThrottles ( DSHOTDriver driver,
const uint16_t  throttles[DSHOT_CHANNELS] 
)

send throttle packed order to all of the ESCs

Parameters
[in]driverpointer to the DSHOTDriver object
[in]throttle[DSHOT_CHANNELS][48 .. 2047]
Note
dshotSendFrame is called by this function
telemetry bit is set in turn for each ESC of the ESCs

Definition at line 287 of file esc_dshot.c.

References DshotPackets::dp, DSHOT_CHANNELS, DSHOTDriver::dshotMotors, dshotSendFrame(), and setDshotPacketThrottle().

+ Here is the call graph for this function:

void dshotSetThrottle ( DSHOTDriver driver,
const uint8_t  index,
const uint16_t  throttle 
)

prepare throttle order for specified ESC

Parameters
[in]driverpointer to the DSHOTDriver object
[in]indexchannel : [0..3] or [0..1] depending on driver used
[in]throttle[48 .. 2047]
Note
dshotSendFrame has to be called after using this function
see also dshotSendThrottles

Definition at line 215 of file esc_dshot.c.

References DshotPackets::dp, DSHOT_ALL_MOTORS, DSHOT_CHANNELS, DSHOT_CMD_MAX, DSHOT_MAX_VALUE, DSHOTDriver::dshotMotors, Min, and setDshotPacketThrottle().

Referenced by actuators_dshot_arch_commit().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: