Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
dshot_erps.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ch.h>
4 #include <hal.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
14  typedef enum {
16  EDT_TEMP=0x2, EDT_VOLT=0x4, EDT_CURRENT=0x6,
17  EDT_DBG1=0x8, EDT_DBG2=0xA, EDT_STRESS=0xC,
18  EDT_STATUS=0xE
20 
21 typedef enum {
23  EDT_STATUS_MAX_STRESS_MASK=0b111<1
24  } EdtStatus;
25 
26 
30 typedef union {
31  struct {
32  uint16_t crc:4;
33  uint16_t mantisse:9;
34  uint16_t exponent:3;
35  };
38 
42 typedef union {
43  struct {
44  uint16_t crc:4;
45  uint16_t edt_value:8;
46  EdtType edt_type:4;
47  } ;
50 
51 _Static_assert(sizeof(DshotEPeriodPacket) == sizeof(uint16_t), "DshotEPeriodPacket size error");
52 _Static_assert(sizeof(DshotEPeriodTelemetry) == sizeof(uint16_t), "DshotEPeriodTelemetry size error");
53 
54 
58  typedef struct {
59  DshotEPeriodPacket ep; // 16 bits packet
60  uint32_t ef; // 21 bits frame
61  } DshotErps;
62 
63 
64 
67  uint32_t DshotErpsGetEperiod(const DshotErps *derpsp);
68  uint32_t DshotErpsGetRpm(const DshotErps *derpsp);
69  bool DshotErpsCheckCrc4(const DshotErps *derpsp);
70 
77  static inline uint32_t DshotErpsGetFrame(const DshotErps *derpsp) {return derpsp->ef;}
84  static inline bool DshotErpsIsEdt(const DshotErps *derpsp) {
85  const DshotEPeriodTelemetry tm = {.rawFrame = derpsp->ep.rawFrame};
86  return
87  ((tm.edt_type & 0b0001) == 0) &&
88  ((tm.edt_type & 0b1110) != 0);
89  }
90 
97  static inline EdtType DshotErpsEdtType(const DshotErps *derpsp) {
98  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_type;
99 }
106 static inline uint8_t DshotErpsEdtTempCentigrade(const DshotErps *derpsp) {
107  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
108 }
115 static inline uint16_t DshotErpsEdtCentiVolts(const DshotErps *derpsp) {
116  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value * 100U / 4U;
117 }
124 static inline uint16_t DshotErpsEdtCurrentAmp(const DshotErps *derpsp) {
125  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
126 }
127 
134 static inline uint16_t DshotErpsEdtStress(const DshotErps *derpsp) {
135  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
136 }
137 
144 static inline uint16_t DshotErpsEdtStatus(const DshotErps *derpsp) {
145  return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
146 }
147 
148 #ifdef __cplusplus
149 }
150 #endif
static uint8_t frame[20]
static uint16_t DshotErpsEdtStatus(const DshotErps *derpsp)
return status value
Definition: dshot_erps.h:144
const DshotErps * DshotErpsSetFromFrame(DshotErps *derpsp, uint32_t frame)
initialise from GCR encoded frame
Definition: dshot_erps.c:44
EdtType
ERPS telemetry type.
Definition: dshot_erps.h:14
@ EDT_CURRENT
Definition: dshot_erps.h:16
@ EDT_STATUS
Definition: dshot_erps.h:18
@ EDT_NOTEDT
Definition: dshot_erps.h:15
@ EDT_STRESS
Definition: dshot_erps.h:17
@ EDT_VOLT
Definition: dshot_erps.h:16
@ EDT_TEMP
Definition: dshot_erps.h:16
@ EDT_DBG1
Definition: dshot_erps.h:17
@ EDT_DBG2
Definition: dshot_erps.h:17
uint32_t DshotErpsGetRpm(const DshotErps *derpsp)
calculate and return rpm
Definition: dshot_erps.c:87
uint16_t rawFrame
Definition: dshot_erps.h:36
uint32_t DshotErpsGetEperiod(const DshotErps *derpsp)
return eperiod from mantisse and exponent
Definition: dshot_erps.c:72
EdtStatus
Definition: dshot_erps.h:21
@ EDT_STATUS_WARNING
Definition: dshot_erps.h:22
@ EDT_STATUS_ALERT
Definition: dshot_erps.h:22
@ EDT_STATUS_ERROR
Definition: dshot_erps.h:22
DshotEPeriodPacket ep
Definition: dshot_erps.h:59
static uint8_t DshotErpsEdtTempCentigrade(const DshotErps *derpsp)
return temperature for a temperature telemetry frame
Definition: dshot_erps.h:106
bool DshotErpsCheckCrc4(const DshotErps *derpsp)
check packed validity
Definition: dshot_erps.c:99
static uint16_t DshotErpsEdtStress(const DshotErps *derpsp)
return stress value
Definition: dshot_erps.h:134
static uint32_t DshotErpsGetFrame(const DshotErps *derpsp)
return encoded frame
Definition: dshot_erps.h:77
static EdtType DshotErpsEdtType(const DshotErps *derpsp)
return type of a telemetry frame
Definition: dshot_erps.h:97
uint32_t ef
Definition: dshot_erps.h:60
const DshotErps * DshotErpsSetFromRpm(DshotErps *derpsp, uint32_t rpm)
initialise from rpm value
Definition: dshot_erps.c:57
_Static_assert(sizeof(DshotEPeriodPacket)==sizeof(uint16_t), "DshotEPeriodPacket size error")
static uint16_t DshotErpsEdtCentiVolts(const DshotErps *derpsp)
return voltage for a voltage telemetry frame
Definition: dshot_erps.h:115
static uint16_t DshotErpsEdtCurrentAmp(const DshotErps *derpsp)
return current intensity for a current telemetry frame
Definition: dshot_erps.h:124
static bool DshotErpsIsEdt(const DshotErps *derpsp)
return true if current frame is a telemetry frame
Definition: dshot_erps.h:84
ERPS complete frame, raw and decoded.
Definition: dshot_erps.h:58
ERPS classic rpm frame.
Definition: dshot_erps.h:30
ERPS telemetry frame.
Definition: dshot_erps.h:42
uint16_t rpm
Definition: rpm_sensor.c:33
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98