Another lot of refactoring
This commit is contained in:
+212
-15
@@ -21,20 +21,15 @@
|
||||
#ifndef _PULSES_H_
|
||||
#define _PULSES_H_
|
||||
|
||||
enum ModuleFlag
|
||||
{
|
||||
MODULE_NORMAL_MODE,
|
||||
MODULE_RANGECHECK,
|
||||
MODULE_BIND,
|
||||
// MODULE_OFF, // will need an EEPROM conversion
|
||||
};
|
||||
|
||||
extern uint8_t moduleFlag[NUM_MODULES];
|
||||
#include "definitions.h"
|
||||
#include "dataconstants.h"
|
||||
#include "pulses/pxx2.h"
|
||||
#include "pulses/pxx1.h"
|
||||
|
||||
#if NUM_MODULES > 1
|
||||
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK || moduleFlag[1] == MODULE_RANGECHECK)
|
||||
#define IS_RANGECHECK_ENABLE() (moduleSettings[0].mode == MODULE_MODE_RANGECHECK || moduleSettings[1].mode == MODULE_MODE_RANGECHECK)
|
||||
#else
|
||||
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK)
|
||||
#define IS_RANGECHECK_ENABLE() (moduleSettings[0].mode == MODULE_MODE_RANGECHECK)
|
||||
#endif
|
||||
|
||||
#if defined(DSM2) && !defined(PCBTARANIS)
|
||||
@@ -42,8 +37,6 @@ enum ModuleFlag
|
||||
extern uint8_t dsm2BindTimer;
|
||||
#endif
|
||||
|
||||
#define IS_PPM_PROTOCOL(protocol) (protocol==PROTO_PPM)
|
||||
|
||||
#if defined(PXX)
|
||||
#define IS_PXX_PROTOCOL(protocol) (protocol==PROTO_PXX)
|
||||
#else
|
||||
@@ -71,9 +64,213 @@ enum ModuleFlag
|
||||
#define IS_MULTIMODULE_PROTOCOL(protocol) (0)
|
||||
#endif
|
||||
|
||||
#define IS_SBUS_PROTOCOL(protocol) (protocol == PROTOCOL_CHANNELS_SBUS)
|
||||
#define IS_SBUS_PROTOCOL(protocol) (protocol == PROTOCOL_CHANNELS_SBUS)
|
||||
|
||||
#if NUM_MODULES == 2
|
||||
#define MODULES_INIT(...) __VA_ARGS__, __VA_ARGS__
|
||||
#else
|
||||
#define MODULES_INIT(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
extern uint8_t s_pulses_paused;
|
||||
|
||||
enum ModuleSettingsMode
|
||||
{
|
||||
MODULE_MODE_NORMAL,
|
||||
MODULE_MODE_RANGECHECK,
|
||||
MODULE_MODE_BIND,
|
||||
MODULE_MODE_REGISTER
|
||||
};
|
||||
|
||||
PACK(struct ModuleSettings {
|
||||
uint8_t protocol:5;
|
||||
uint8_t paused:1;
|
||||
uint8_t mode:2;
|
||||
uint16_t failsafeCounter;
|
||||
});
|
||||
|
||||
extern ModuleSettings moduleSettings[NUM_MODULES];
|
||||
|
||||
template<class T> struct PpmPulsesData {
|
||||
T pulses[20];
|
||||
T * ptr;
|
||||
};
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PACK(struct Dsm2SerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t * ptr;
|
||||
uint8_t serialByte ;
|
||||
uint8_t serialBitCount;
|
||||
uint16_t _alignment;
|
||||
});
|
||||
#else
|
||||
#define MAX_PULSES_TRANSITIONS 300
|
||||
PACK(struct Dsm2TimerPulsesData {
|
||||
pulse_duration_t pulses[MAX_PULSES_TRANSITIONS];
|
||||
pulse_duration_t * ptr;
|
||||
uint16_t rest;
|
||||
uint8_t index;
|
||||
});
|
||||
#endif
|
||||
|
||||
#define PPM_PERIOD_HALF_US(module) ((g_model.moduleData[module].ppm.frameLength * 5 + 225) * 200) /*half us*/
|
||||
#define PPM_PERIOD(module) (PPM_PERIOD_HALF_US(module) / 2000) /*ms*/
|
||||
#define DSM2_BAUDRATE 125000
|
||||
#define DSM2_PERIOD 22 /*ms*/
|
||||
#define SBUS_BAUDRATE 100000
|
||||
#define SBUS_PERIOD_HALF_US ((g_model.moduleData[EXTERNAL_MODULE].sbus.refreshRate * 5 + 225) * 200) /*half us*/
|
||||
#define SBUS_PERIOD (SBUS_PERIOD_HALF_US / 2000) /*ms*/
|
||||
#define MULTIMODULE_BAUDRATE 100000
|
||||
#define MULTIMODULE_PERIOD 7 /*ms*/
|
||||
|
||||
#define CROSSFIRE_FRAME_MAXLEN 64
|
||||
PACK(struct CrossfirePulsesData {
|
||||
uint8_t pulses[CROSSFIRE_FRAME_MAXLEN];
|
||||
});
|
||||
|
||||
union ModulePulsesData {
|
||||
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
|
||||
UartPxxPulses pxx_uart;
|
||||
#endif
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
SerialPxxPulses pxx;
|
||||
#elif !defined(INTMODULE_USART) || !defined(EXTMODULE_USART)
|
||||
PwmPxxPulses pxx;
|
||||
#endif
|
||||
|
||||
Pxx2Pulses pxx2;
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
Dsm2SerialPulsesData dsm2;
|
||||
#else
|
||||
Dsm2TimerPulsesData dsm2;
|
||||
#endif
|
||||
|
||||
PpmPulsesData<pulse_duration_t> ppm;
|
||||
CrossfirePulsesData crossfire;
|
||||
} __ALIGNED(4);
|
||||
|
||||
/* The __ALIGNED keyword is required to align the struct inside the modulePulsesData below,
|
||||
* which is also defined to be __DMA (which includes __ALIGNED) aligned.
|
||||
* Arrays in C/C++ are always defined to be *contiguously*. The first byte of the second element is therefore always
|
||||
* sizeof(ModulePulsesData). __ALIGNED is required for sizeof(ModulePulsesData) to be a multiple of the alignment.
|
||||
*/
|
||||
|
||||
/* TODO: internal pulsedata only needs 200 bytes vs 300 bytes for external, both use 300 byte since we have a common struct */
|
||||
extern ModulePulsesData modulePulsesData[NUM_MODULES];
|
||||
|
||||
union TrainerPulsesData {
|
||||
PpmPulsesData<trainer_pulse_duration_t> ppm;
|
||||
};
|
||||
|
||||
extern TrainerPulsesData trainerPulsesData;
|
||||
extern const uint16_t CRCTable[];
|
||||
|
||||
void setupPulses(uint8_t port);
|
||||
void setupPulsesDSM2(uint8_t port);
|
||||
void setupPulsesMultimodule(uint8_t port);
|
||||
void setupPulsesSbus(uint8_t port);
|
||||
void setupPulsesPXX(uint8_t port);
|
||||
void setupPulsesPPMModule(uint8_t port);
|
||||
void setupPulsesPPMTrainer();
|
||||
void sendByteDsm2(uint8_t b);
|
||||
void putDsm2Flush();
|
||||
void putDsm2SerialBit(uint8_t bit);
|
||||
void sendByteSbus(uint8_t byte);
|
||||
|
||||
#if defined(HUBSAN)
|
||||
void Hubsan_Init();
|
||||
#endif
|
||||
|
||||
inline void startPulses()
|
||||
{
|
||||
s_pulses_paused = false;
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
setupPulses(INTERNAL_MODULE);
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
#else
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
#endif
|
||||
|
||||
#if defined(HUBSAN)
|
||||
Hubsan_Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool pulsesStarted() { return moduleSettings[0].protocol != PROTOCOL_CHANNELS_UNINITIALIZED; }
|
||||
inline void pausePulses() { s_pulses_paused = true; }
|
||||
inline void resumePulses() { s_pulses_paused = false; }
|
||||
|
||||
#define SEND_FAILSAFE_NOW(idx) moduleSettings[idx].failsafeCounter = 1
|
||||
|
||||
inline void SEND_FAILSAFE_1S()
|
||||
{
|
||||
for (int i=0; i<NUM_MODULES; i++) {
|
||||
moduleSettings[i].failsafeCounter = 100;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign failsafe values using the current channel outputs
|
||||
// for channels not set previously to HOLD or NOPULSE
|
||||
void setCustomFailsafe(uint8_t moduleIndex);
|
||||
|
||||
#if defined(PCBXLITE) && !defined(MODULE_R9M_FULLSIZE)
|
||||
#define LEN_R9M_REGION "\006"
|
||||
#define TR_R9M_REGION "FCC\0 ""EU\0 ""868MHz""915MHz"
|
||||
#define LEN_R9M_FCC_POWER_VALUES "\010"
|
||||
#define LEN_R9M_LBT_POWER_VALUES "\015"
|
||||
#define TR_R9M_FCC_POWER_VALUES "(100 mW)"
|
||||
#define TR_R9M_LBT_POWER_VALUES "25 mW 8ch\0 ""25 mW 16ch\0 ""100mW no tele"
|
||||
#define LEN_R9MFLEX_FREQ "\006"
|
||||
#define TR_R9MFLEX_FREQ "868Mhz""915Mhz"
|
||||
|
||||
enum R9MFCCPowerValues {
|
||||
R9M_FCC_POWER_100 = 0,
|
||||
R9M_FCC_POWER_MAX = R9M_FCC_POWER_100
|
||||
};
|
||||
|
||||
enum R9MLBTPowerValues {
|
||||
R9M_LBT_POWER_25 = 0,
|
||||
R9M_LBT_POWER_25_16,
|
||||
R9M_LBT_POWER_100,
|
||||
R9M_LBT_POWER_MAX = R9M_LBT_POWER_100
|
||||
};
|
||||
|
||||
#define BIND_TELEM_ALLOWED(idx) (!(IS_TELEMETRY_INTERNAL_MODULE() && moduleIdx == EXTERNAL_MODULE) && (!isModuleR9M_LBT(idx) || g_model.moduleData[idx].pxx.power < R9M_LBT_POWER_100))
|
||||
#define BIND_CH9TO16_ALLOWED(idx) (!isModuleR9M_LBT(idx) || g_model.moduleData[idx].pxx.power != R9M_LBT_POWER_25)
|
||||
|
||||
#else
|
||||
|
||||
#define LEN_R9M_REGION "\004"
|
||||
#define TR_R9M_REGION "FCC\0""EU\0 ""FLEX"
|
||||
#define LEN_R9MFLEX_FREQ "\006"
|
||||
#define TR_R9MFLEX_FREQ "868Mhz""915Mhz"
|
||||
#define LEN_R9M_FCC_POWER_VALUES "\006"
|
||||
#define LEN_R9M_LBT_POWER_VALUES "\013"
|
||||
#define TR_R9M_FCC_POWER_VALUES "10 mW\0" "100 mW" "500 mW" "1 W\0"
|
||||
#define TR_R9M_LBT_POWER_VALUES "25 mW 8ch\0 ""25 mW 16ch\0" "200 mW 16ch" "500 mW 16ch"
|
||||
|
||||
enum R9MFCCPowerValues {
|
||||
R9M_FCC_POWER_10 = 0,
|
||||
R9M_FCC_POWER_100,
|
||||
R9M_FCC_POWER_500,
|
||||
R9M_FCC_POWER_1000,
|
||||
R9M_FCC_POWER_MAX = R9M_FCC_POWER_1000
|
||||
};
|
||||
|
||||
enum R9MLBTPowerValues {
|
||||
R9M_LBT_POWER_25 = 0,
|
||||
R9M_LBT_POWER_25_16,
|
||||
R9M_LBT_POWER_200,
|
||||
R9M_LBT_POWER_500,
|
||||
R9M_LBT_POWER_MAX = R9M_LBT_POWER_500
|
||||
};
|
||||
|
||||
#define BIND_TELEM_ALLOWED(idx) (!(IS_TELEMETRY_INTERNAL_MODULE() && moduleIdx == EXTERNAL_MODULE) && (!isModuleR9M_LBT(idx) || g_model.moduleData[idx].pxx.power < R9M_LBT_POWER_200))
|
||||
#define BIND_CH9TO16_ALLOWED(idx) (!isModuleR9M_LBT(idx) || g_model.moduleData[idx].pxx.power != R9M_LBT_POWER_25)
|
||||
#endif
|
||||
|
||||
#include "pulses_arm.h"
|
||||
|
||||
#endif // _PULSES_H_
|
||||
|
||||
Reference in New Issue
Block a user