From 9ef47a1e6363eb66f9f8bffc72c4d447d2607206 Mon Sep 17 00:00:00 2001 From: bsongis Date: Fri, 25 May 2012 13:52:39 +0000 Subject: [PATCH] Switch and Throttle Warnings when loading a model. To be tested and re-tested ... --- src/drivers.cpp | 2 +- src/eeprom_arm.cpp | 13 ++++++++- src/eeprom_avr.cpp | 13 ++++++++- src/frsky.cpp | 8 +++--- src/model_menus.cpp | 2 +- src/myeeprom.h | 9 ++++--- src/open9x.cpp | 6 ++++- src/pulses_arm.cpp | 66 ++++++++++++++++++++++----------------------- src/pulses_arm.h | 6 +++++ src/pulses_avr.cpp | 40 +++++++++++++++------------ src/pulses_avr.h | 14 +++++++--- 11 files changed, 112 insertions(+), 67 deletions(-) diff --git a/src/drivers.cpp b/src/drivers.cpp index c48ae54b6..92f0bdbc8 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -41,7 +41,7 @@ void putEvent(uint8_t evt) uint8_t getEvent() { uint8_t evt = s_evt; - s_evt=0; + s_evt = 0; return evt; } diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index 5b02de1ae..c52196bfb 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -471,6 +471,10 @@ void eeLoadModel(uint8_t id) if (idPIO_ABCDSR[0] &= ~PIO_PA17 ; // Peripheral C - pioptr->PIO_ABCDSR[1] |= PIO_PA17 ; // Peripheral C - pioptr->PIO_PDR = PIO_PA17 ; // Disable bit A17 Assign to peripheral + pioptr->PIO_ABCDSR[1] |= PIO_PA17 ; // Peripheral C + pioptr->PIO_PDR = PIO_PA17 ; // Disable bit A17 Assign to peripheral } pwmptr = PWM ; @@ -409,18 +410,8 @@ extern "C" void PWM_IRQHandler(void) pwmptr = PWM; if (pwmptr->PWM_ISR1 & PWM_ISR1_CHID3) { - switch (Current_protocol) // Use the current, don't switch until set_up_pulses + switch (s_current_protocol) // Use the current, don't switch until set_up_pulses { - case PROTO_PPM: - case PROTO_PPM16: - pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = Pulses[Pulses_index++]; // Period in half uS - if (Pulses[Pulses_index] == 0) { - Pulses_index = 0; - - setupPulses(); - } - break; - case PROTO_PXX: // Alternate periods of 15.5mS and 2.5 mS period = pwmptr->PWM_CH_NUM[3].PWM_CPDR; @@ -459,7 +450,7 @@ extern "C" void PWM_IRQHandler(void) } pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS if (period != 5000) // 2.5 mS - { + { setupPulses(); } else { @@ -472,6 +463,15 @@ extern "C" void PWM_IRQHandler(void) sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers } break; + + default: + pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = Pulses[Pulses_index++]; // Period in half uS + if (Pulses[Pulses_index] == 0) { + Pulses_index = 0; + setupPulses(); + } + break; + } } } @@ -480,27 +480,27 @@ void setupPulses() { heartbeat |= HEART_TIMER_PULSES; - if (Current_protocol != g_model.protocol) { - switch (Current_protocol) { // stop existing protocol hardware - case PROTO_PPM: - disable_main_ppm(); - break; + uint8_t required_protocol = g_model.protocol; + if (s_pulses_paused) + required_protocol = PROTO_NONE; + + if (s_current_protocol != required_protocol) { + + switch (s_current_protocol) { // stop existing protocol hardware case PROTO_PXX: disable_ssc(); break; case PROTO_DSM2: disable_ssc(); break; - case PROTO_PPM16: + default: disable_main_ppm(); break; } - Current_protocol = g_model.protocol; - switch (Current_protocol) { // Start new protocol hardware here - case PROTO_PPM: - init_main_ppm(3000, 1); // Initial period 1.5 mS, output on - break; + s_current_protocol = required_protocol; + + switch (required_protocol) { // Start new protocol hardware here case PROTO_PXX: init_main_ppm(5000, 0); // Initial period 2.5 mS, output off init_ssc(); @@ -509,24 +509,24 @@ void setupPulses() init_main_ppm(5000, 0); // Initial period 2.5 mS, output off init_ssc(); break; - case PROTO_PPM16: + case PROTO_NONE: + init_main_ppm(3000, 0); // Initial period 1.5 mS, output on + break; + default: init_main_ppm(3000, 1); // Initial period 1.5 mS, output on break; } } -// Set up output data here - switch (Current_protocol) { - case PROTO_PPM: - setupPulsesPPM(); // Don't enable interrupts through here - break; + // Set up output data here + switch (required_protocol) { case PROTO_PXX: setupPulsesPXX(); break; case PROTO_DSM2: setupPulsesDsm2(6); break; - case PROTO_PPM16: + default: setupPulsesPPM(); // Don't enable interrupts through here break ; } diff --git a/src/pulses_arm.h b/src/pulses_arm.h index 25c32731e..81fa5d298 100644 --- a/src/pulses_arm.h +++ b/src/pulses_arm.h @@ -34,7 +34,13 @@ #ifndef pulses_arm_h #define pulses_arm_h +extern uint8_t s_current_protocol; +extern uint8_t s_pulses_paused; + void startPulses(); +inline bool pulsesStarted() { return s_current_protocol != 255; } +inline void pausePulses() { s_pulses_paused = true; } +inline void resumePulses() { s_pulses_paused = false; } void disable_main_ppm(); void disable_ssc(); diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index 8db85332e..d9c8ba8ca 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -44,6 +44,7 @@ #endif uint8_t s_current_protocol = 255; +uint8_t s_pulses_paused = 0; #ifdef DSM2_SERIAL inline void DSM2_EnableTXD(void) @@ -118,15 +119,17 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation else #endif { - // Orginal bitbang for PPM + // Original bitbang for PPM #if !defined(PCBV4) - if (pulsePol) { - PORTB |= (1<