Added support for Lemon-Rx DSMP

This commit is contained in:
Raphael Coeffic
2022-03-24 10:40:17 +01:00
committed by Raphael Coeffic
parent f09c10b49d
commit 9d5cd1876c
36 changed files with 630 additions and 392 deletions
+114 -9
View File
@@ -33,29 +33,40 @@
#define BITLEN_DSM2 (8*2) //125000 Baud => 8uS per bit
void _send_1(uint8_t v)
static void reset_dsm2_buffer()
{
extmodulePulsesData.dsm2.index = 0;
extmodulePulsesData.dsm2.ptr = extmodulePulsesData.dsm2.pulses;
}
static void _send_1(uint8_t v)
{
*extmodulePulsesData.dsm2.ptr++ = v - 1;
extmodulePulsesData.dsm2.index += 1;
}
void sendByteDsm2(uint8_t b) // max 10 changes 0 10 10 10 10 1
static void _sendByte(uint8_t b, uint8_t bit_len) // max 10 changes 0 10 10 10 10 1
{
bool lev = 0;
uint8_t len = BITLEN_DSM2; // max val: 9*16 < 256
uint8_t len = bit_len; // max val: 9*16 < 256
for (uint8_t i=0; i<=8; i++) { // 8Bits + Stop=1
bool nlev = b & 1; // lsb first
if (lev == nlev) {
len += BITLEN_DSM2;
len += bit_len;
}
else {
_send_1(len);
len = BITLEN_DSM2;
len = bit_len;
lev = nlev;
}
b = (b>>1) | 0x80; // shift in stop bit
}
_send_1(len); // stop bit (len is already BITLEN_DSM2)
_send_1(len); // stop bit (len is already bit_len)
}
static void sendByteDsm2(uint8_t b)
{
_sendByte(b, BITLEN_DSM2);
}
void putDsm2Flush()
@@ -73,9 +84,7 @@ void setupPulsesDSM2()
{
uint8_t dsmDat[14];
extmodulePulsesData.dsm2.index = 0;
extmodulePulsesData.dsm2.ptr = extmodulePulsesData.dsm2.pulses;
reset_dsm2_buffer();
switch (moduleState[EXTERNAL_MODULE].protocol) {
case PROTOCOL_CHANNELS_DSM2_LP45:
@@ -112,3 +121,99 @@ void setupPulsesDSM2()
putDsm2Flush();
}
#define BITLEN_DSMP (17)
static void sendByteDSMP(uint8_t b)
{
_sendByte(b, BITLEN_DSMP);
}
void setupPulsesLemonDSMP()
{
static uint8_t pass = 0;
reset_dsm2_buffer();
const auto& md = g_model.moduleData[EXTERNAL_MODULE];
// TODO: sanetize 'channels'
auto channels = md.getChannelsCount();
auto flags = md.dsmp.flags;
// Force setup packet in Bind mode.
auto module_mode = getModuleMode(EXTERNAL_MODULE);
sendByteDSMP( 0xAA );
sendByteDSMP( pass );
// Setup packet
if (pass == 0) {
if (module_mode == MODULE_MODE_BIND) {
flags = DSM2_SEND_BIND | (1 << 6 /* AUTO */);
channels = 12;
}
sendByteDSMP( flags );
uint8_t pwr = 7;
if (module_mode == MODULE_MODE_RANGECHECK) {
pwr = 4;
}
sendByteDSMP( pwr );
sendByteDSMP( channels );
// Model number
sendByteDSMP( 1 );
// Send only 1 single Setup packet
pass = 1;
} else {
uint8_t start_channel = 0;
if (pass == 2) {
start_channel += 7;
}
// Send channels
for (int i=0; i<7; i++) {
uint8_t channel = start_channel + i;
if (channel < channels) {
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
uint16_t pulse;
// Use 11-bit ?
if (flags & (1 << 2)) {
pulse = limit(0, ((value*349)>>9)+1024, 2047) | (channel << 11);
} else {
pulse = limit(0, ((value*13)>>5)+512, 1023) | (channel << 10);
}
sendByteDSMP( pulse >> 8 );
sendByteDSMP( pulse & 0xFF );
} else {
// Outside of announced number of channels:
// -> send invalid values
sendByteDSMP( 0xFF );
sendByteDSMP( 0xFF );
}
}
}
putDsm2Flush();
if (++pass > 2) pass = 1;
if (channels < 8) pass = 1;
if (module_mode == MODULE_MODE_BIND) {
// bind packet is setup
pass = 0;
}
else if (--moduleState[EXTERNAL_MODULE].counter == 0) {
// every 100th packet is setup
pass = 0;
moduleState[EXTERNAL_MODULE].counter = 100;
}
}
+3 -2
View File
@@ -36,11 +36,12 @@ enum ModuleType {
MODULE_TYPE_R9M_PXX2, // R9M ACCESS
MODULE_TYPE_R9M_LITE_PXX1, //R9MLite
MODULE_TYPE_R9M_LITE_PXX2, //R9MLP
MODULE_TYPE_GHOST, // Replaces MODULE_TYPE_R9M_LITE_PRO_PXX1 which doesn't exist
MODULE_TYPE_GHOST,
MODULE_TYPE_R9M_LITE_PRO_PXX2,
MODULE_TYPE_SBUS,
MODULE_TYPE_XJT_LITE_PXX2,
MODULE_TYPE_FLYSKY, //no more protocols possible because of 4 bits value
MODULE_TYPE_FLYSKY,
MODULE_TYPE_LEMON_DSMP,
MODULE_TYPE_COUNT SKIP,
MODULE_TYPE_MAX SKIP = MODULE_TYPE_COUNT - 1
};
+7 -1
View File
@@ -410,6 +410,11 @@ inline bool isModuleAFHDS3(uint8_t idx)
&& (g_model.moduleData[idx].subType == FLYSKY_SUBTYPE_AFHDS3);
}
inline bool isModuleDSMP(uint8_t idx)
{
return g_model.moduleData[idx].type == MODULE_TYPE_LEMON_DSMP;
}
// See enum ModuleType in modules_constant.h
// relative to 8!
static const int8_t maxChannelsModules_M8[] = {
@@ -429,6 +434,7 @@ static const int8_t maxChannelsModules_M8[] = {
8, // MODULE_TYPE_SBUS
0, // MODULE_TYPE_XJT_LITE_PXX2: index NOT USED
6, // MODULE_TYPE_FLYSKY: 14 channels for AFHDS2A, AFHDS3 special cased
4, // MODULE_TYPE_LEMON_DSMP: 12 channels for DSMX
};
static_assert(MODULE_TYPE_COUNT == sizeof(maxChannelsModules_M8),
@@ -616,7 +622,7 @@ inline bool isModuleBindRangeAvailable(uint8_t moduleIdx)
{
return isModulePXX2(moduleIdx) || isModulePXX1(moduleIdx) ||
isModuleDSM2(moduleIdx) || isModuleMultimodule(moduleIdx) ||
isModuleFlySky(moduleIdx);
isModuleFlySky(moduleIdx) || isModuleDSMP(moduleIdx);
}
inline uint32_t getNV14RfFwVersion()
+45 -33
View File
@@ -55,6 +55,32 @@ InternalModulePulsesData intmodulePulsesData __DMA;
ExternalModulePulsesData extmodulePulsesData __DMA;
TrainerPulsesData trainerPulsesData __DMA;
void restartModule(uint8_t idx)
{
if (idx == INTERNAL_MODULE) {
if (!IS_INTERNAL_MODULE_ON()) return;
} else if (idx == EXTERNAL_MODULE){
if (!IS_EXTERNAL_MODULE_ON()) return;
} else {
return;
}
pauseMixerCalculations();
pausePulses();
if (idx == INTERNAL_MODULE) INTERNAL_MODULE_OFF();
else EXTERNAL_MODULE_OFF();
RTOS_WAIT_MS(20); // 20ms so that the pulses interrupt will reinit the frame rate
telemetryProtocol = 255; // force telemetry port + module reinitialization
if (idx == INTERNAL_MODULE) INTERNAL_MODULE_ON();
else EXTERNAL_MODULE_ON();
resumePulses();
resumeMixerCalculations();
}
// use only for PXX
void ModuleState::startBind(BindInformation* destination,
ModuleCallback bindCallback)
@@ -69,39 +95,6 @@ void ModuleState::startBind(BindInformation* destination,
#endif
}
#if defined(HARDWARE_INTERNAL_MODULE)
void restartInternalModule()
{
if (!IS_INTERNAL_MODULE_ON()) {
return;
}
pauseMixerCalculations();
pausePulses();
INTERNAL_MODULE_OFF();
RTOS_WAIT_MS(20); // 20ms so that the pulses interrupt will reinit the frame rate
telemetryProtocol = 255; // force telemetry port + module reinitialization
INTERNAL_MODULE_ON();
resumePulses();
resumeMixerCalculations();
}
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
void restartExternalModule()
{
if (!IS_EXTERNAL_MODULE_ON()) {
return;
}
pauseMixerCalculations();
pausePulses();
EXTERNAL_MODULE_OFF();
RTOS_WAIT_MS(20); // 20ms so that the pulses interrupt will reinit the frame rate
telemetryProtocol = 255; // force telemetry port + module reinitialization
EXTERNAL_MODULE_ON();
resumePulses();
resumeMixerCalculations();
}
#endif
void ModuleState::readModuleInformation(ModuleInformation* destination,
int8_t first, int8_t last)
{
@@ -305,6 +298,10 @@ uint8_t getRequiredProtocol(uint8_t module)
break;
#endif
case MODULE_TYPE_LEMON_DSMP:
protocol = PROTOCOL_CHANNELS_DSMP;
break;
default:
protocol = PROTOCOL_CHANNELS_NONE;
break;
@@ -589,6 +586,11 @@ void enablePulsesExternalModule(uint8_t protocol)
break;
#endif
case PROTOCOL_CHANNELS_DSMP:
extmoduleSerialStart();
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 11 * 1000 /* 11ms in us */);
break;
default:
// external module stopped, use default mixer period
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0);
@@ -670,6 +672,10 @@ bool setupPulsesExternalModule(uint8_t protocol)
return true;
#endif
case PROTOCOL_CHANNELS_DSMP:
setupPulsesLemonDSMP();
return true;
default:
return false;
}
@@ -730,6 +736,12 @@ void extmoduleSendNextFrame()
extmodulePulsesData.dsm2.ptr - extmodulePulsesData.dsm2.pulses);
break;
#endif
case PROTOCOL_CHANNELS_DSMP:
extmoduleSendNextFrameSoftSerial(
extmodulePulsesData.dsm2.pulses,
extmodulePulsesData.dsm2.ptr - extmodulePulsesData.dsm2.pulses,
true);
break;
#if defined(GHOST)
case PROTOCOL_CHANNELS_GHOST:
+4 -6
View File
@@ -67,10 +67,10 @@ extern uint8_t s_pulses_paused;
typedef void (* ModuleCallback)();
PACK(struct ModuleState {
uint8_t protocol:4;
uint8_t protocol;
uint8_t mode:4;
uint8_t paused:1;
uint8_t spare:7;
uint8_t spare:3;
uint16_t counter;
// PXX specific items
@@ -233,7 +233,9 @@ bool setupPulsesExternalModule();
void stopPulsesExternalModule();
void extmoduleSendNextFrame();
#endif
void restartModule(uint8_t idx);
void setupPulsesDSM2();
void setupPulsesLemonDSMP();
void setupPulsesCrossfire(uint8_t idx);
void setupPulsesGhost();
void setupPulsesMultiExternalModule();
@@ -242,9 +244,7 @@ void setupPulsesSbus();
void setupPulsesPPMInternalModule();
void setupPulsesPPMExternalModule();
void setupPulsesPPMTrainer();
void sendByteDsm2(uint8_t b);
void putDsm2Flush();
void putDsm2SerialBit(uint8_t bit);
void sendByteSbus(uint8_t b);
void intmodulePpmStart();
void intmodulePxx1PulsesStart();
@@ -254,8 +254,6 @@ void extmodulePxx1SerialStart();
void extmodulePpmStart();
void intmoduleStop();
void extmoduleStop();
void restartInternalModule();
void restartExternalModule();
void getModuleStatusString(uint8_t moduleIdx, char * statusText);
void getModuleSyncStatusString(uint8_t moduleIdx, char * statusText);
#if defined(AFHDS3)