[stock / gruvin9x] FrSky and DSM2 serial mode
[Sky9x] Bootloader mode on REVC
This commit is contained in:
+1
-5
@@ -69,10 +69,6 @@ inline void init_soft_power()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(REVC)
|
|
||||||
bool bootloader_allowed = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint32_t check_soft_power()
|
uint32_t check_soft_power()
|
||||||
{
|
{
|
||||||
#ifdef SIMU
|
#ifdef SIMU
|
||||||
@@ -1267,7 +1263,7 @@ void end_bt_tx_interrupt()
|
|||||||
NVIC_DisableIRQ(UART1_IRQn) ;
|
NVIC_DisableIRQ(UART1_IRQn) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_mode()
|
void usbBootloader()
|
||||||
{
|
{
|
||||||
// This might be replaced by a software reset
|
// This might be replaced by a software reset
|
||||||
// Any interrupts that have been enabled must be disabled here
|
// Any interrupts that have been enabled must be disabled here
|
||||||
|
|||||||
+2
-5
@@ -100,12 +100,9 @@ extern uint16_t sessionTimer;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(REVC)
|
#if defined(REVC)
|
||||||
extern bool bootloader_allowed;
|
#define BOOTLOADER_REQUEST() (usbPlugged())
|
||||||
#define SKIP_INIT() (check_soft_power() == e_power_off || (bootloader_allowed && usbPlugged()))
|
|
||||||
#define BOOTLOADER_REQ() (bootloader_allowed && usbPlugged())
|
|
||||||
#else
|
#else
|
||||||
#define SKIP_INIT() (check_soft_power() >= e_power_usb)
|
#define BOOTLOADER_REQUEST() (check_soft_power() == e_power_usb)
|
||||||
#define BOOTLOADER_REQ() (check_soft_power() == e_power_usb)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SLAVE_MODE() (check_soft_power() == e_power_trainer)
|
#define SLAVE_MODE() (check_soft_power() == e_power_trainer)
|
||||||
|
|||||||
+9
-7
@@ -500,8 +500,6 @@ void eeLoadModel(uint8_t id)
|
|||||||
activeFunctions = 0;
|
activeFunctions = 0;
|
||||||
activeFunctionSwitches = 0;
|
activeFunctionSwitches = 0;
|
||||||
|
|
||||||
resetProto();
|
|
||||||
|
|
||||||
for (uint8_t i=0; i<MAX_TIMERS; i++) {
|
for (uint8_t i=0; i<MAX_TIMERS; i++) {
|
||||||
if (g_model.timers[i].remanent) {
|
if (g_model.timers[i].remanent) {
|
||||||
s_timerVal[i] = g_model.timers[i].value;
|
s_timerVal[i] = g_model.timers[i].value;
|
||||||
@@ -511,6 +509,10 @@ void eeLoadModel(uint8_t id)
|
|||||||
resumeMixerCalculations();
|
resumeMixerCalculations();
|
||||||
// TODO pulses should be started after mixer calculations ...
|
// TODO pulses should be started after mixer calculations ...
|
||||||
|
|
||||||
|
#if defined(FRSKY)
|
||||||
|
FRSKY_setModelAlarms();
|
||||||
|
#endif
|
||||||
|
|
||||||
LOAD_MODEL_BITMAP();
|
LOAD_MODEL_BITMAP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -542,7 +544,11 @@ void eeReadAll()
|
|||||||
|
|
||||||
modelDefault(0);
|
modelDefault(0);
|
||||||
|
|
||||||
if (!SKIP_INIT()) {
|
if (check_soft_power()==e_power_off) {
|
||||||
|
// we don't want to store anything
|
||||||
|
s_eeDirtyMsk = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
/* we remove all models */
|
/* we remove all models */
|
||||||
for (uint32_t i=0; i<MAX_MODELS; i++)
|
for (uint32_t i=0; i<MAX_MODELS; i++)
|
||||||
eeDeleteModel(i);
|
eeDeleteModel(i);
|
||||||
@@ -550,10 +556,6 @@ void eeReadAll()
|
|||||||
STORE_GENERALVARS;
|
STORE_GENERALVARS;
|
||||||
STORE_MODELVARS;
|
STORE_MODELVARS;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// we don't want to store anything
|
|
||||||
s_eeDirtyMsk = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-2
@@ -896,8 +896,6 @@ void eeLoadModel(uint8_t id)
|
|||||||
activeFunctions = 0;
|
activeFunctions = 0;
|
||||||
activeFunctionSwitches = 0;
|
activeFunctionSwitches = 0;
|
||||||
|
|
||||||
resetProto();
|
|
||||||
|
|
||||||
#if defined(PCBGRUVIN9X)
|
#if defined(PCBGRUVIN9X)
|
||||||
for (uint8_t i=0; i<MAX_TIMERS; i++) {
|
for (uint8_t i=0; i<MAX_TIMERS; i++) {
|
||||||
if (g_model.timers[i].remanent) {
|
if (g_model.timers[i].remanent) {
|
||||||
@@ -905,6 +903,10 @@ void eeLoadModel(uint8_t id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(FRSKY)
|
||||||
|
FRSKY_setModelAlarms();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -834,9 +834,6 @@ void menuModelSetup(uint8_t event)
|
|||||||
switch (m_posHorz) {
|
switch (m_posHorz) {
|
||||||
case 0:
|
case 0:
|
||||||
CHECK_INCDEC_MODELVAR(event, g_model.protocol, 0, PROTO_MAX-1);
|
CHECK_INCDEC_MODELVAR(event, g_model.protocol, 0, PROTO_MAX-1);
|
||||||
#if defined(DSM2_SERIAL)
|
|
||||||
if (checkIncDec_Ret) resetProto();
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#if defined(DSM2)
|
#if defined(DSM2)
|
||||||
|
|||||||
+15
-39
@@ -335,33 +335,6 @@ void modelDefault(uint8_t id)
|
|||||||
applyDefaultTemplate();
|
applyDefaultTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetProto()
|
|
||||||
{
|
|
||||||
#if defined(DSM2_SERIAL)
|
|
||||||
if (g_model.protocol == PROTO_DSM2) {
|
|
||||||
cli();
|
|
||||||
#if defined(FRSKY)
|
|
||||||
DSM2_Init();
|
|
||||||
#endif
|
|
||||||
sei();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cli();
|
|
||||||
#if defined(FRSKY)
|
|
||||||
FRSKY_Init();
|
|
||||||
#else
|
|
||||||
DSM2_Done();
|
|
||||||
#endif
|
|
||||||
sei();
|
|
||||||
#if defined(FRSKY)
|
|
||||||
FRSKY_setModelAlarms();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#elif defined(FRSKY)
|
|
||||||
FRSKY_setModelAlarms();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t intpol(int16_t x, uint8_t idx) // -100, -75, -50, -25, 0 ,25 ,50, 75, 100
|
int16_t intpol(int16_t x, uint8_t idx) // -100, -75, -50, -25, 0 ,25 ,50, 75, 100
|
||||||
{
|
{
|
||||||
CurveInfo crv = curveinfo(idx);
|
CurveInfo crv = curveinfo(idx);
|
||||||
@@ -1192,9 +1165,9 @@ void doSplash()
|
|||||||
#if defined(FSPLASH) || defined(XSPLASH)
|
#if defined(FSPLASH) || defined(XSPLASH)
|
||||||
if (!(g_eeGeneral.splashMode & 0x04))
|
if (!(g_eeGeneral.splashMode & 0x04))
|
||||||
#endif
|
#endif
|
||||||
if (keyDown() || (tsum!=inacSum)) return; // wait for key release
|
if (keyDown() || tsum!=inacSum) return; // wait for key release
|
||||||
|
|
||||||
if (SKIP_INIT()) return;
|
if (check_soft_power()==e_power_off) return;
|
||||||
|
|
||||||
#if !defined(PCBSTD)
|
#if !defined(PCBSTD)
|
||||||
if (curTime < get_tmr10ms()) {
|
if (curTime < get_tmr10ms()) {
|
||||||
@@ -1263,7 +1236,7 @@ void checkTHR()
|
|||||||
|
|
||||||
int16_t v = thrAnaIn(thrchn);
|
int16_t v = thrAnaIn(thrchn);
|
||||||
|
|
||||||
if (SKIP_INIT() || v<=lowLim || keyDown())
|
if (check_soft_power()==e_power_off || keyDown() || v<=lowLim)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
checkBacklight();
|
checkBacklight();
|
||||||
@@ -1307,7 +1280,7 @@ void checkSwitches()
|
|||||||
last_bad_switches = switches_states;
|
last_bad_switches = switches_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyDown() || SKIP_INIT()) return; // Usb on or power off
|
if (check_soft_power()==e_power_off || keyDown()) return; // Usb on or power off
|
||||||
|
|
||||||
checkBacklight();
|
checkBacklight();
|
||||||
|
|
||||||
@@ -1325,7 +1298,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG)
|
|||||||
{
|
{
|
||||||
SIMU_SLEEP(1);
|
SIMU_SLEEP(1);
|
||||||
|
|
||||||
if (SKIP_INIT()) return;
|
if (check_soft_power() == e_power_off) return;
|
||||||
|
|
||||||
if (keyDown()) return; // wait for key release
|
if (keyDown()) return; // wait for key release
|
||||||
|
|
||||||
@@ -3008,7 +2981,12 @@ ISR(TIMER_10MS_VECT, ISR_NOBLOCK) // 10ms timer
|
|||||||
|
|
||||||
#if defined(FRSKY)
|
#if defined(FRSKY)
|
||||||
if (cnt10ms == 30) {
|
if (cnt10ms == 30) {
|
||||||
|
#if defined(DSM2_SERIAL)
|
||||||
|
if (s_current_protocol != PROTO_DSM2)
|
||||||
|
check_frsky();
|
||||||
|
#else
|
||||||
check_frsky();
|
check_frsky();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -3382,9 +3360,7 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
|
|||||||
|
|
||||||
startPulses();
|
startPulses();
|
||||||
|
|
||||||
if (!SKIP_INIT()) {
|
wdt_enable(WDTO_500MS);
|
||||||
wdt_enable(WDTO_500MS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBSKY9X)
|
||||||
@@ -3500,11 +3476,11 @@ int main(void)
|
|||||||
|
|
||||||
sei(); // interrupts needed for FRSKY_Init and eeReadAll.
|
sei(); // interrupts needed for FRSKY_Init and eeReadAll.
|
||||||
|
|
||||||
#if defined(FRSKY)
|
#if defined(FRSKY) && !defined(DSM2_SERIAL)
|
||||||
FRSKY_Init();
|
FRSKY_Init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DSM2_SERIAL)
|
#if defined(DSM2_SERIAL) && !defined(FRSKY)
|
||||||
DSM2_Init();
|
DSM2_Init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -3533,7 +3509,7 @@ int main(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBSKY9X)
|
||||||
if (BOOTLOADER_REQ()) {
|
if (BOOTLOADER_REQUEST()) {
|
||||||
soft_power_off(); // Only turn power off if necessary
|
soft_power_off(); // Only turn power off if necessary
|
||||||
|
|
||||||
#if defined(HAPTIC)
|
#if defined(HAPTIC)
|
||||||
@@ -3556,7 +3532,7 @@ int main(void)
|
|||||||
lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ;
|
lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ;
|
||||||
refreshDisplay() ;
|
refreshDisplay() ;
|
||||||
|
|
||||||
usb_mode();
|
usbBootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
CoInitOS();
|
CoInitOS();
|
||||||
|
|||||||
@@ -1012,7 +1012,6 @@ uint16_t eeLoadModelName(uint8_t id, char *name);
|
|||||||
void eeLoadModel(uint8_t id);
|
void eeLoadModel(uint8_t id);
|
||||||
void generalDefault();
|
void generalDefault();
|
||||||
void modelDefault(uint8_t id);
|
void modelDefault(uint8_t id);
|
||||||
void resetProto();
|
|
||||||
|
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBSKY9X)
|
||||||
inline int32_t calc100toRESX(register int8_t x)
|
inline int32_t calc100toRESX(register int8_t x)
|
||||||
|
|||||||
@@ -741,6 +741,12 @@ void setupPulses()
|
|||||||
|
|
||||||
if (s_current_protocol != required_protocol) {
|
if (s_current_protocol != required_protocol) {
|
||||||
|
|
||||||
|
#if defined(DSM2_SERIAL) && defined(FRSKY)
|
||||||
|
if (s_current_protocol == PROTO_DSM2) {
|
||||||
|
FRSKY_Init();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
s_current_protocol = required_protocol;
|
s_current_protocol = required_protocol;
|
||||||
|
|
||||||
TCCR1B = 0; // Stop counter
|
TCCR1B = 0; // Stop counter
|
||||||
@@ -824,6 +830,12 @@ void setupPulses()
|
|||||||
PORTB &= ~(1<<OUT_B_PPM); // Hold PPM output low
|
PORTB &= ~(1<<OUT_B_PPM); // Hold PPM output low
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
|
#if defined(DSM2_SERIAL) && defined(FRSKY)
|
||||||
|
case PROTO_DSM2:
|
||||||
|
DSM2_Init();
|
||||||
|
// no break
|
||||||
|
#endif
|
||||||
|
|
||||||
default: // PPM and DSM2=SERIAL modes
|
default: // PPM and DSM2=SERIAL modes
|
||||||
set_timer3_capture();
|
set_timer3_capture();
|
||||||
OCR1A = 44000; // Next frame starts in 22ms -- DSM mode.
|
OCR1A = 44000; // Next frame starts in 22ms -- DSM mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user