Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
7extern "C" {
8#endif
9
14 typedef enum {
18 EDT_STATUS=0xE
20
21typedef enum {
24 } EdtStatus;
25
26
30typedef union {
31 struct {
32 uint16_t crc:4;
33 uint16_t mantisse:9;
34 uint16_t exponent:3;
35 };
38
42typedef 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
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}
107 return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
108}
116 return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value * 100U / 4U;
117}
125 return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
126}
127
135 return (DshotEPeriodTelemetry) {.rawFrame = derpsp->ep.rawFrame}.edt_value;
136}
137
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
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
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
const DshotErps * DshotErpsSetFromRpm(DshotErps *derpsp, uint32_t rpm)
initialise from rpm value
Definition dshot_erps.c:57
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
const DshotErps * DshotErpsSetFromFrame(DshotErps *derpsp, uint32_t frame)
initialise from GCR encoded frame
Definition dshot_erps.c:44
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
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 foo
Definition main_demo5.c:58
uint16_t rpm
Definition rpm_sensor.c:33
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.