[Taranis] Trainer / Trainee again OK. Not tested on Horus
This commit is contained in:
@@ -43,7 +43,7 @@ void _send_1(uint8_t v)
|
||||
else
|
||||
v -= 2;
|
||||
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = v;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = v - 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index += 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest -= v;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void setupPulsesPPM(uint8_t port) // Don't enable interrupts through here
|
||||
template<class T>
|
||||
void setupPulsesPPM(uint8_t port, PpmPulsesData<T> * ppmPulsesData)
|
||||
{
|
||||
int16_t PPM_range = g_model.extendedLimits ? (512*LIMIT_EXT_PERCENT/100) * 2 : 512 * 2; //range of 0.7..1.7msec
|
||||
|
||||
@@ -31,19 +32,6 @@ void setupPulsesPPM(uint8_t port) // Don't enable interrupts t
|
||||
uint32_t firstCh = g_model.moduleData[port].channelsStart;
|
||||
uint32_t lastCh = min<unsigned int>(NUM_CHNOUT, firstCh + 8 + g_model.moduleData[port].channelsCount);
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
// TODO move register stuff to driver
|
||||
register Pwm *pwmptr = PWM;
|
||||
uint32_t pwmCh = (port == EXTERNAL_MODULE ? 3 : 1);
|
||||
pwmptr->PWM_CH_NUM[pwmCh].PWM_CDTYUPD = (g_model.moduleData[port].ppm.delay * 50 + 300) * 2; //Stoplen *2
|
||||
if (g_model.moduleData[port].ppm.pulsePol)
|
||||
pwmptr->PWM_CH_NUM[pwmCh].PWM_CMR &= ~0x00000200 ; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[pwmCh].PWM_CMR |= 0x00000200 ; // CPOL
|
||||
#endif
|
||||
|
||||
PpmPulsesData * ppmPulsesData = (port == TRAINER_MODULE ? &trainerPulsesData.ppm : &modulePulsesData[port].ppm);
|
||||
|
||||
#if defined(CPUSTM32)
|
||||
ppmPulsesData->ptr = ppmPulsesData->pulses;
|
||||
#else
|
||||
@@ -70,22 +58,14 @@ void setupPulsesPPM(uint8_t port) // Don't enable interrupts t
|
||||
*ptr = rest;
|
||||
*(ptr + 1) = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CPUSTM32)
|
||||
rest -= 1000;
|
||||
uint32_t ppmDelay = (g_model.moduleData[port].ppm.delay * 50 + 300) * 2;
|
||||
// set idle time, ppm delay and ppm polarity
|
||||
if (port == TRAINER_MODULE) {
|
||||
set_trainer_ppm_parameters(rest, ppmDelay, !g_model.moduleData[TRAINER_MODULE].ppm.pulsePol); // ppmPulsePol: 0 - positive, 1 - negative
|
||||
}
|
||||
else if (port == EXTERNAL_MODULE) {
|
||||
set_external_ppm_parameters(rest, ppmDelay, !g_model.moduleData[EXTERNAL_MODULE].ppm.pulsePol);
|
||||
}
|
||||
#endif
|
||||
void setupPulsesPPMModule(uint8_t port)
|
||||
{
|
||||
setupPulsesPPM<pulse_duration_t>(port, &modulePulsesData[port].ppm);
|
||||
}
|
||||
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
else if (port == INTERNAL_MODULE) {
|
||||
set_internal_ppm_parameters(rest, ppmDelay, !g_model.moduleData[INTERNAL_MODULE].ppm.pulsePol);
|
||||
}
|
||||
#endif // #if defined(TARANIS_INTERNAL_PPM)
|
||||
void setupPulsesPPMTrainer()
|
||||
{
|
||||
setupPulsesPPM<trainer_pulse_duration_t>(TRAINER_MODULE, &trainerPulsesData.ppm);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -28,16 +28,14 @@ uint8_t moduleFlag[NUM_MODULES] = { 0 };
|
||||
ModulePulsesData modulePulsesData[NUM_MODULES] __DMA;
|
||||
TrainerPulsesData trainerPulsesData __DMA;
|
||||
|
||||
void setupPulses(uint8_t port)
|
||||
uint8_t getRequiredProtocol(uint8_t port)
|
||||
{
|
||||
uint8_t required_protocol;
|
||||
|
||||
heartbeat |= (HEART_TIMER_PULSES << port);
|
||||
|
||||
switch (port) {
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
case INTERNAL_MODULE:
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
switch (g_model.moduleData[INTERNAL_MODULE].type) {
|
||||
case MODULE_TYPE_PPM:
|
||||
required_protocol = PROTO_PPM;
|
||||
@@ -49,9 +47,9 @@ void setupPulses(uint8_t port)
|
||||
required_protocol = PROTO_NONE;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
required_protocol = g_model.moduleData[INTERNAL_MODULE].rfProtocol == RF_PROTO_OFF ? PROTO_NONE : PROTO_PXX;
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -111,12 +109,23 @@ void setupPulses(uint8_t port)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_current_protocol[port] != required_protocol) {
|
||||
return required_protocol;
|
||||
}
|
||||
|
||||
void setupPulses(uint8_t port)
|
||||
{
|
||||
bool init_needed = false;
|
||||
uint8_t required_protocol = getRequiredProtocol(port);
|
||||
|
||||
heartbeat |= (HEART_TIMER_PULSES << port);
|
||||
|
||||
if (s_current_protocol[port] != required_protocol) {
|
||||
init_needed = true;
|
||||
switch (s_current_protocol[port]) { // stop existing protocol hardware
|
||||
case PROTO_PXX:
|
||||
disable_pxx(port);
|
||||
break;
|
||||
|
||||
#if defined(DSM2)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
@@ -124,30 +133,79 @@ void setupPulses(uint8_t port)
|
||||
disable_dsm2(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CROSSFIRE)
|
||||
case PROTO_CROSSFIRE:
|
||||
disable_crossfire(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
disable_dsm2(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PROTO_PPM:
|
||||
disable_ppm(port);
|
||||
break;
|
||||
|
||||
default:
|
||||
disable_no_pulses(port);
|
||||
break;
|
||||
}
|
||||
|
||||
s_current_protocol[port] = required_protocol;
|
||||
}
|
||||
|
||||
// Set up output data here
|
||||
switch (required_protocol) {
|
||||
case PROTO_PXX:
|
||||
setupPulsesPXX(port);
|
||||
scheduleNextMixerCalculation(port, 9);
|
||||
break;
|
||||
|
||||
#if defined(DSM2)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
setupPulsesDSM2(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CROSSFIRE)
|
||||
case PROTO_CROSSFIRE:
|
||||
if (telemetryProtocol == PROTOCOL_PULSES_CROSSFIRE && !init_needed) {
|
||||
uint8_t * crossfire = modulePulsesData[port].crossfire.pulses;
|
||||
createCrossfireFrame(crossfire, &channelOutputs[g_model.moduleData[port].channelsStart]);
|
||||
sportSendBuffer(crossfire, CROSSFIRE_FRAME_LEN);
|
||||
}
|
||||
scheduleNextMixerCalculation(port, CROSSFIRE_FRAME_PERIOD);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
setupPulsesMultimodule(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PROTO_PPM:
|
||||
setupPulsesPPMModule(port);
|
||||
scheduleNextMixerCalculation(port, (45+g_model.moduleData[port].ppm.frameLength)/2);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (init_needed) {
|
||||
switch (required_protocol) { // Start new protocol hardware here
|
||||
case PROTO_PXX:
|
||||
init_pxx(port);
|
||||
break;
|
||||
|
||||
#if defined(DSM2)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
@@ -155,16 +213,19 @@ void setupPulses(uint8_t port)
|
||||
init_dsm2(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CROSSFIRE)
|
||||
case PROTO_CROSSFIRE:
|
||||
init_crossfire(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
init_dsm2(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PROTO_PPM:
|
||||
init_ppm(port);
|
||||
break;
|
||||
@@ -174,44 +235,4 @@ void setupPulses(uint8_t port)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set up output data here
|
||||
switch (required_protocol) {
|
||||
case PROTO_PXX:
|
||||
setupPulsesPXX(port);
|
||||
scheduleNextMixerCalculation(port, 9);
|
||||
break;
|
||||
#if defined(DSM2)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
setupPulsesDSM2(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
break;
|
||||
#endif
|
||||
#if defined(CROSSFIRE)
|
||||
case PROTO_CROSSFIRE:
|
||||
{
|
||||
if (telemetryProtocol == PROTOCOL_PULSES_CROSSFIRE) {
|
||||
uint8_t * crossfire = modulePulsesData[port].crossfire.pulses;
|
||||
createCrossfireFrame(crossfire, &channelOutputs[g_model.moduleData[port].channelsStart]);
|
||||
sportSendBuffer(crossfire, CROSSFIRE_FRAME_LEN);
|
||||
scheduleNextMixerCalculation(port, CROSSFIRE_FRAME_PERIOD);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
setupPulsesMultimodule(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
break;
|
||||
#endif
|
||||
case PROTO_PPM:
|
||||
setupPulsesPPM(port);
|
||||
scheduleNextMixerCalculation(port, (45+g_model.moduleData[port].ppm.frameLength)/2);
|
||||
break ;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,30 +22,32 @@
|
||||
#define _PULSES_ARM_H_
|
||||
|
||||
#if NUM_MODULES == 2
|
||||
#define MODULES_INIT(...) __VA_ARGS__, __VA_ARGS__
|
||||
#define MODULES_INIT(...) __VA_ARGS__, __VA_ARGS__
|
||||
#else
|
||||
#define MODULES_INIT(...) __VA_ARGS__
|
||||
#define MODULES_INIT(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
#define pulse_duration_t uint32_t
|
||||
#define pulse_duration_t uint32_t
|
||||
#define trainer_pulse_duration_t uint16_t
|
||||
#else
|
||||
#define pulse_duration_t uint16_t
|
||||
#define pulse_duration_t uint16_t
|
||||
#define trainer_pulse_duration_t uint16_t
|
||||
#endif
|
||||
|
||||
extern uint8_t s_current_protocol[NUM_MODULES];
|
||||
extern uint8_t s_pulses_paused;
|
||||
extern uint16_t failsafeCounter[NUM_MODULES];
|
||||
|
||||
PACK(struct PpmPulsesData {
|
||||
pulse_duration_t pulses[20];
|
||||
pulse_duration_t * ptr;
|
||||
PACK(template<class T> struct PpmPulsesData {
|
||||
T pulses[20];
|
||||
T * ptr;
|
||||
});
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PACK(struct PxxSerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint8_t * ptr;
|
||||
uint16_t pcmValue;
|
||||
uint16_t pcmCrc;
|
||||
uint32_t pcmOnesCount;
|
||||
@@ -55,7 +57,7 @@ PACK(struct PxxSerialPulsesData {
|
||||
|
||||
PACK(struct Dsm2SerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint8_t * ptr;
|
||||
uint8_t serialByte ;
|
||||
uint8_t serialBitCount;
|
||||
});
|
||||
@@ -113,7 +115,7 @@ union ModulePulsesData {
|
||||
#if defined(PPM_PIN_UART)
|
||||
PxxUartPulsesData pxx_uart;
|
||||
#endif
|
||||
PpmPulsesData ppm;
|
||||
PpmPulsesData<pulse_duration_t> ppm;
|
||||
CrossfirePulsesData crossfire;
|
||||
} __DMA;
|
||||
|
||||
@@ -126,7 +128,7 @@ union ModulePulsesData {
|
||||
extern ModulePulsesData modulePulsesData[NUM_MODULES];
|
||||
|
||||
union TrainerPulsesData {
|
||||
PpmPulsesData ppm;
|
||||
PpmPulsesData<uint16_t> ppm;
|
||||
};
|
||||
|
||||
extern TrainerPulsesData trainerPulsesData;
|
||||
@@ -136,7 +138,8 @@ void setupPulses(uint8_t port);
|
||||
void setupPulsesDSM2(uint8_t port);
|
||||
void setupPulsesMultimodule(uint8_t port);
|
||||
void setupPulsesPXX(uint8_t port);
|
||||
void setupPulsesPPM(uint8_t port);
|
||||
void setupPulsesPPMModule(uint8_t port);
|
||||
void setupPulsesPPMTrainer();
|
||||
void sendByteDsm2(uint8_t b);
|
||||
void putDsm2Flush();
|
||||
void putDsm2SerialBit(uint8_t bit);
|
||||
|
||||
Reference in New Issue
Block a user