diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index c539e5780..b0dd96212 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1352,13 +1352,6 @@ uint8_t checkTrim(uint8_t event) #endif } -#if defined(PCBSKY9X) && !defined(REVA) -uint16_t Current_analogue; -uint16_t Current_max; -uint32_t Current_accumulator; -uint32_t Current_used; -#endif - #if !defined(SIMU) static uint16_t s_anaFilt[NUMBER_ANALOG]; #endif diff --git a/radio/src/targets/sky9x/board_sky9x.cpp b/radio/src/targets/sky9x/board_sky9x.cpp index 40cb33aa1..dcbdac3bf 100644 --- a/radio/src/targets/sky9x/board_sky9x.cpp +++ b/radio/src/targets/sky9x/board_sky9x.cpp @@ -42,6 +42,13 @@ volatile uint32_t Tenms ; volatile uint8_t lcdLock; volatile uint32_t lcdInputs; +#if !defined(REVA) +uint16_t Current_analogue; +uint16_t Current_max; +uint32_t Current_accumulator; +uint32_t Current_used; +#endif + extern "C" void sam_boot( void ) ; // Prototype @@ -672,3 +679,28 @@ void setSticksGain(uint8_t gains) padc->ADC_CGR = gain; padc->ADC_COR = offset; } + + +#if !defined(REVA) +void calcConsumption() +{ + Current_accumulator += Current_analogue ; + static uint32_t OneSecTimer; + if (++OneSecTimer >= 100) { + OneSecTimer -= 100 ; + Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) + Current_accumulator = 0 ; + } +} +#endif + +void checkTrainerSettings() +{ + if (SLAVE_MODE()) { + PIOC->PIO_PDR = PIO_PC22; + } + else { + PIOC->PIO_PER = PIO_PC22; + } +} + diff --git a/radio/src/targets/sky9x/board_sky9x.h b/radio/src/targets/sky9x/board_sky9x.h index 5d7e360bc..f0e6078a4 100644 --- a/radio/src/targets/sky9x/board_sky9x.h +++ b/radio/src/targets/sky9x/board_sky9x.h @@ -168,11 +168,14 @@ extern uint16_t Current_max; extern uint32_t Current_accumulator; extern uint32_t Current_used; extern uint16_t sessionTimer; +void calcConsumption(); #endif #define SLAVE_MODE() (pwrCheck() == e_power_trainer) -#define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22 -#define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22 +// #define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22 +// #define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22 +void checkTrainerSettings(); + void setSticksGain(uint8_t gains); diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index b8d4719b4..98170bfe6 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -82,8 +82,8 @@ extern "C" { #define TIMER_MULT_APB1 2 #define TIMER_MULT_APB2 2 -#define JACK_PPM_OUT() -#define JACK_PPM_IN() +// #define JACK_PPM_OUT() +// #define JACK_PPM_IN() #define PIN_MODE_MASK 0x0003 #define PIN_INPUT 0x0000 diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp index 10f1871c5..8883b6fcc 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks_arm.cpp @@ -42,49 +42,8 @@ uint8_t requiredSpeakerVolume; extern void batteryCheck(); -void perMainArm() +void handleUsbConnection() { -#if defined(PCBSKY9X) - Current_accumulator += Current_analogue ; - static uint32_t OneSecTimer; - if (++OneSecTimer >= 100) { - OneSecTimer -= 100 ; - Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) - Current_accumulator = 0 ; - } -#endif - - if (currentSpeakerVolume != requiredSpeakerVolume) { - currentSpeakerVolume = requiredSpeakerVolume; - setVolume(currentSpeakerVolume); - } - - if (!usbPlugged()) { - // TODO merge these 2 branches -#if defined(PCBSKY9X) - if (Eeprom32_process_state != E32_IDLE) - ee32_process(); - else if (TIME_TO_WRITE()) - eeCheck(false); -#else - if (theFile.isWriting()) - theFile.nextWriteStep(); - else if (TIME_TO_WRITE()) - eeCheck(false); -#endif - } - - sdMountPoll(); - writeLogs(); - - uint8_t evt = getEvent(false); - if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on - checkBacklight(); - -#if defined(PCBTARANIS) - checkTrainerSettings(); -#endif - #if defined(PCBTARANIS) && !defined(SIMU) static bool usbStarted = false; if (!usbStarted && usbPlugged()) { @@ -111,12 +70,55 @@ void perMainArm() } #endif #endif //#if defined(PCBTARANIS) && !defined(SIMU) +} +void checkSpeakerVolume() +{ + if (currentSpeakerVolume != requiredSpeakerVolume) { + currentSpeakerVolume = requiredSpeakerVolume; + setVolume(currentSpeakerVolume); + } +} + +void checkEeprom() +{ + if (!usbPlugged()) { + // TODO merge these 2 branches +#if defined(PCBSKY9X) + if (Eeprom32_process_state != E32_IDLE) + ee32_process(); + else if (TIME_TO_WRITE()) + eeCheck(false); +#else + if (theFile.isWriting()) + theFile.nextWriteStep(); + else if (TIME_TO_WRITE()) + eeCheck(false); +#endif + } +} + +void perMainArm() +{ +#if defined(PCBSKY9X) && !defined(REVA) + calcConsumption(); +#endif + checkSpeakerVolume(); + checkEeprom(); + sdMountPoll(); + writeLogs(); + handleUsbConnection(); + checkTrainerSettings(); + + uint8_t evt = getEvent(false); + if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on + checkBacklight(); #if defined(NAVIGATION_STICKS) uint8_t sticks_evt = getSticksNavigationEvent(); if (sticks_evt) evt = sticks_evt; #endif + #if defined(USB_MASS_STORAGE) if (usbPlugged()) { lcd_clear(); @@ -157,16 +159,7 @@ void perMainArm() } drawStatusLine(); - lcdRefresh(); - - if (SLAVE_MODE()) { - JACK_PPM_OUT(); - } - else { - JACK_PPM_IN(); - } - batteryCheck(); }