From 185532f05e3b0d627dc4214ab6093687bd49fa31 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 12 Aug 2019 14:23:03 +0200 Subject: [PATCH 1/2] No more voltage alarms on simu --- radio/src/gui/128x64/view_main.cpp | 2 +- radio/src/gui/128x64/view_statistics.cpp | 2 +- radio/src/gui/212x64/view_main.cpp | 2 +- radio/src/gui/480x272/topbar.cpp | 2 +- radio/src/main.cpp | 2 +- radio/src/opentx.h | 23 +++-- radio/src/simu.cpp | 21 ---- radio/src/targets/horus/CMakeLists.txt | 2 +- radio/src/targets/horus/board.cpp | 6 +- radio/src/targets/simu/simpgmspace.cpp | 75 ++++++++++++--- radio/src/targets/sky9x/CMakeLists.txt | 2 +- radio/src/targets/sky9x/board.cpp | 117 ++++++++++------------- radio/src/targets/sky9x/board.h | 6 +- radio/src/targets/taranis/CMakeLists.txt | 2 +- radio/src/targets/taranis/board.cpp | 11 +-- 15 files changed, 147 insertions(+), 128 deletions(-) diff --git a/radio/src/gui/128x64/view_main.cpp b/radio/src/gui/128x64/view_main.cpp index 469dcdc97..653db74b7 100644 --- a/radio/src/gui/128x64/view_main.cpp +++ b/radio/src/gui/128x64/view_main.cpp @@ -198,7 +198,7 @@ void displayBattVoltage() putsVBat(VBATT_X-8, VBATT_Y+1, RIGHT); lcdDrawSolidFilledRect(VBATT_X-25, VBATT_Y+9, 21, 5); lcdDrawSolidVerticalLine(VBATT_X-4, VBATT_Y+10, 3); - uint8_t count = GET_TXBATT_BARS(); + uint8_t count = GET_TXBATT_BARS(20); for (uint8_t i=0; i 0) { diff --git a/radio/src/gui/480x272/topbar.cpp b/radio/src/gui/480x272/topbar.cpp index 8cf6cf9f0..3e54cab33 100644 --- a/radio/src/gui/480x272/topbar.cpp +++ b/radio/src/gui/480x272/topbar.cpp @@ -82,7 +82,7 @@ void drawTopBar() lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_4, MENU_TITLE_COLOR); /* Tx battery */ - uint8_t bars = limit(0, 6 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 5); + uint8_t bars = GET_TXBATT_BARS(5); lcdDrawBitmapPattern(LCD_W-130, 24, LBM_TOPMENU_TXBATT, MENU_TITLE_COLOR); for (unsigned int i = 0; i < 5; i++) { lcdDrawSolidFilledRect(LCD_W-122+4*i, 30, 2, 8, i >= bars ? MENU_TITLE_DISABLE_COLOR : MENU_TITLE_COLOR); diff --git a/radio/src/main.cpp b/radio/src/main.cpp index c7e42f5da..21fdc4246 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -541,7 +541,7 @@ void perMain() setTopSecondTimer(g_eeGeneral.globalTimer + sessionTimer); setTopRssi(TELEMETRY_RSSI()); setTopBatteryValue(g_vbat100mV); - setTopBatteryState(GET_TXBATT_BARS(), IS_TXBATT_WARNING()); + setTopBatteryState(GET_TXBATT_BARS(10), IS_TXBATT_WARNING()); toplcdRefreshEnd(); #endif diff --git a/radio/src/opentx.h b/radio/src/opentx.h index a67ef8531..6f17cad4b 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -721,16 +721,7 @@ extern const char vers_stamp[]; * @param buffer If non-null find the firmware version in the buffer instead * @return The opentx version string starting with "opentx-" or "no version found" if the version string is not found */ -const char* getOtherVersion(char* buffer); - -extern uint8_t g_vbat100mV; -#if LCD_W > 128 - #define GET_TXBATT_BARS() (limit(0, div_and_round(10 * (g_vbat100mV - g_eeGeneral.vBatMin - 90), 30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 10)) -#else - #define GET_TXBATT_BARS() (limit(2, 20 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 20)) -#endif -#define IS_TXBATT_WARNING() (g_vbat100mV <= g_eeGeneral.vBatWarn) - +const char * getOtherVersion(char * buffer); #define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms) extern uint8_t g_beepCnt; @@ -1260,6 +1251,18 @@ inline int div_and_round(int num, int den) return num / den; } +extern uint8_t g_vbat100mV; + +inline uint8_t GET_TXBATT_BARS(uint8_t barsMax) +{ + return limit(0, div_and_round(barsMax * (g_vbat100mV - g_eeGeneral.vBatMin - 90), 30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), barsMax); +} + +inline bool IS_TXBATT_WARNING() +{ + return g_vbat100mV <= g_eeGeneral.vBatWarn; +} + #if defined(TELEMETRY_FRSKY) enum TelemetryViews { TELEMETRY_CUSTOM_SCREEN_1, diff --git a/radio/src/simu.cpp b/radio/src/simu.cpp index 1ae2f523d..35bd87f0a 100644 --- a/radio/src/simu.cpp +++ b/radio/src/simu.cpp @@ -528,27 +528,6 @@ uint16_t anaIn(uint8_t chan) return opentxSim->sliders[chan]->getValue(); else if (chanknobs[chan-NUM_STICKS]->getValue(); -#if defined(PCBHORUS) - else if (chan == TX_VOLTAGE) - return 1737; //~10.6V -#elif defined(PCBX9E) - else if (chan == TX_VOLTAGE) - return 1420; //~10.6V -#elif defined(PCBXLITE) - else if (chan == TX_VOLTAGE) - return 1100; -#elif defined(PCBTARANIS) - else if (chan == TX_VOLTAGE) - return 1000; //~7.4V -#elif defined(PCBSKY9X) - else if (chan == TX_VOLTAGE) - return 5.1*1500/11.3; - else if (chan == TX_CURRENT) - return 100; -#else - else if (chan == TX_VOLTAGE) - return 1500; -#endif #if defined(PCBTARANIS) else if (chan == TX_RTC_VOLTAGE) return 800; // 2.34V diff --git a/radio/src/targets/horus/CMakeLists.txt b/radio/src/targets/horus/CMakeLists.txt index 7525f6d25..9e9625ece 100644 --- a/radio/src/targets/horus/CMakeLists.txt +++ b/radio/src/targets/horus/CMakeLists.txt @@ -126,7 +126,6 @@ set(GVAR_SCREEN model_gvars.cpp) set(TARGET_SRC ${TARGET_SRC} - board.cpp led_driver.cpp extmodule_driver.cpp trainer_driver.cpp @@ -140,6 +139,7 @@ set(TARGET_SRC set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} ${LCD_DRIVER} + board.cpp backlight_driver.cpp pwr_driver.cpp sdram_driver.c diff --git a/radio/src/targets/horus/board.cpp b/radio/src/targets/horus/board.cpp index 14355e0e3..56b37ac40 100644 --- a/radio/src/targets/horus/board.cpp +++ b/radio/src/targets/horus/board.cpp @@ -20,12 +20,12 @@ #include "opentx.h" -#if defined(__cplusplus) && !defined(SIMU) +#if defined(__cplusplus) extern "C" { #endif #include "usb_dcd_int.h" #include "usb_bsp.h" -#if defined(__cplusplus) && !defined(SIMU) +#if defined(__cplusplus) } #endif @@ -78,7 +78,6 @@ void boardInit() initialise_monitor_handles(); #endif -#if !defined(SIMU) RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | PCBREV_RCC_AHB1Periph | LED_RCC_AHB1Periph | @@ -182,7 +181,6 @@ void boardInit() #endif ledBlue(); -#endif } void boardOff() diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index d305f3c19..cc053e595 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -356,7 +356,7 @@ void * audioThread(void *) */ if ( SDL_OpenAudio(&wanted, &have) < 0 ) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); - return 0; + return nullptr; } SDL_PauseAudio(0); @@ -365,7 +365,7 @@ void * audioThread(void *) sleep(1); } SDL_CloseAudio(); - return 0; + return nullptr; } void StartAudioThread(int volumeGain) @@ -428,6 +428,18 @@ void telemetryPortInit() { } +void sportUpdatePowerOn() +{ +} + +void sportUpdatePowerOff() +{ +} + +void boardInit() +{ +} + display_t simuLcdBackupBuf[DISPLAY_BUFFER_SIZE]; void lcdStoreBackupBuffer() { @@ -648,21 +660,62 @@ void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef * RTC_DateStruct) RTC_DateStruct->RTC_Date = timeinfo->tm_mday; } +void unlockFlash() +{ +} -void unlockFlash() { } -void lockFlash() { } -void flashWrite(uint32_t *address, uint32_t *buffer) { simuSleep(100); } -uint32_t isBootloaderStart(const uint8_t * block) { return 1; } +void lockFlash() +{ +} + +void flashWrite(uint32_t *address, uint32_t *buffer) +{ + simuSleep(100); +} + +uint32_t isBootloaderStart(const uint8_t * block) +{ + return 1; +} #endif // defined(STM32) -#if defined(PCBHORUS) -void LCD_ControlLight(uint16_t dutyCycle) { } -#endif - #if defined(PCBXLITES) -bool isJackPlugged() { return false; } +bool isJackPlugged() +{ + return false; +} #endif void serialPrintf(const char * format, ...) { } void serialCrlf() { } void serialPutc(char c) { } + +uint16_t getBatteryVoltage() +{ + return (BATTERY_MAX + BATTERY_WARN) * 5; +} + +void boardOff() +{ +} + +#if defined(PCBHORUS) || defined(PCBTARANIS) +HardwareOptions hardwareOptions; +#endif + +uint32_t Master_frequency = 0; +uint32_t Current_used = 0; +uint16_t Current_max = 0; + +void setSticksGain(uint8_t) +{ +} + +uint16_t getCurrent() +{ + return 10; +} + +void calcConsumption() +{ +} diff --git a/radio/src/targets/sky9x/CMakeLists.txt b/radio/src/targets/sky9x/CMakeLists.txt index 2e9c92ff1..b4f37964b 100644 --- a/radio/src/targets/sky9x/CMakeLists.txt +++ b/radio/src/targets/sky9x/CMakeLists.txt @@ -82,6 +82,7 @@ endif() set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} ../common/arm/loadboot.cpp + board.cpp core_cm3.c board_lowlevel.c crt.c @@ -111,7 +112,6 @@ set(FIRMWARE_TARGET_SRC set(TARGET_SRC ${TARGET_SRC} - board.cpp telemetry_driver.cpp adc_driver.cpp pulses_driver.cpp diff --git a/radio/src/targets/sky9x/board.cpp b/radio/src/targets/sky9x/board.cpp index 5b1c2361e..e97cc8ccc 100644 --- a/radio/src/targets/sky9x/board.cpp +++ b/radio/src/targets/sky9x/board.cpp @@ -26,7 +26,6 @@ uint16_t ResetReason; uint32_t Master_frequency ; -volatile uint32_t Tenms ; volatile uint8_t lcdLock; volatile uint32_t lcdInputs; @@ -58,7 +57,6 @@ inline void setup_switches() configure_pins( 0x91114900, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP ) ; } -#if !defined(SIMU) inline void UART3_Configure(uint32_t baudrate, uint32_t masterClock) { Uart *pUart = BT_USART; @@ -85,7 +83,7 @@ inline void UART3_Configure(uint32_t baudrate, uint32_t masterClock) /* Enable receiver and transmitter */ pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN; - + #if 0 pUart->UART_IER = UART_IER_RXRDY ; NVIC_EnableIRQ(UART1_IRQn) ; @@ -247,72 +245,59 @@ void init_pwm() void configure_pins( uint32_t pins, uint16_t config ) { - Pio *pioptr ; + Pio * pioptr; - pioptr = PIOA + ( ( config & PIN_PORT_MASK ) >> 6) ; - if ( config & PIN_PULLUP ) - { - pioptr->PIO_PPDDR = pins ; - pioptr->PIO_PUER = pins ; - } - else - { - pioptr->PIO_PUDR = pins ; - } + pioptr = PIOA + ((config & PIN_PORT_MASK) >> 6); + if (config & PIN_PULLUP) { + pioptr->PIO_PPDDR = pins; + pioptr->PIO_PUER = pins; + } + else { + pioptr->PIO_PUDR = pins; + } - if ( config & PIN_PULLDOWN ) - { - pioptr->PIO_PUDR = pins ; - pioptr->PIO_PPDER = pins ; - } - else - { - pioptr->PIO_PPDDR = pins ; - } + if (config & PIN_PULLDOWN) { + pioptr->PIO_PUDR = pins; + pioptr->PIO_PPDER = pins; + } + else { + pioptr->PIO_PPDDR = pins; + } - if ( config & PIN_HIGH ) - { - pioptr->PIO_SODR = pins ; - } - else - { - pioptr->PIO_CODR = pins ; - } + if (config & PIN_HIGH) { + pioptr->PIO_SODR = pins; + } + else { + pioptr->PIO_CODR = pins; + } - if ( config & PIN_INPUT ) - { - pioptr->PIO_ODR = pins ; - } - else - { - pioptr->PIO_OER = pins ; - } + if (config & PIN_INPUT) { + pioptr->PIO_ODR = pins; + } + else { + pioptr->PIO_OER = pins; + } - if ( config & PIN_PERI_MASK_L ) - { - pioptr->PIO_ABCDSR[0] |= pins ; - } - else - { - pioptr->PIO_ABCDSR[0] &= ~pins ; - } - if ( config & PIN_PERI_MASK_H ) - { - pioptr->PIO_ABCDSR[1] |= pins ; - } - else - { - pioptr->PIO_ABCDSR[1] &= ~pins ; - } + if (config & PIN_PERI_MASK_L) { + pioptr->PIO_ABCDSR[0] |= pins; + } + else { + pioptr->PIO_ABCDSR[0] &= ~pins; + } - if ( config & PIN_ENABLE ) - { - pioptr->PIO_PER = pins ; - } - else - { - pioptr->PIO_PDR = pins ; - } + if (config & PIN_PERI_MASK_H) { + pioptr->PIO_ABCDSR[1] |= pins; + } + else { + pioptr->PIO_ABCDSR[1] &= ~pins; + } + + if (config & PIN_ENABLE) { + pioptr->PIO_PER = pins; + } + else { + pioptr->PIO_PDR = pins; + } } void opentxBootloader(); @@ -345,7 +330,6 @@ void i2cInit() TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing NVIC_EnableIRQ(TWI0_IRQn) ; } -#endif void boardInit() { @@ -502,3 +486,8 @@ uint16_t getBatteryVoltage() instant_vbat /= 5530; return (uint16_t)instant_vbat; } + +void boardOff() +{ + pwrOff(); +} diff --git a/radio/src/targets/sky9x/board.h b/radio/src/targets/sky9x/board.h index f80818b91..5d0d88dde 100644 --- a/radio/src/targets/sky9x/board.h +++ b/radio/src/targets/sky9x/board.h @@ -35,8 +35,8 @@ extern uint16_t ResetReason; #define FIRMWARE_ADDRESS 0x00400000 // Board driver -void boardInit(void); -#define boardOff() pwrOff() +void boardInit(); +void boardOff(); // Rotary Encoder driver void rotaryEncoderInit(); @@ -252,9 +252,11 @@ extern "C" { #if defined(WATCHDOG_DISABLED) || defined(SIMU) #define wdt_enable(x) #define wdt_reset() + #define IS_RESET_REASON_WATCHDOG() false #else #define wdt_enable(x) WDT->WDT_MR = 0x3FFF207F #define wdt_reset() WDT->WDT_CR = 0xA5000001 + #define IS_RESET_REASON_WATCHDOG() ((ResetReason & RSTC_SR_RSTTYP) == (2 << 8)) #endif // Backlight driver diff --git a/radio/src/targets/taranis/CMakeLists.txt b/radio/src/targets/taranis/CMakeLists.txt index 7afffdc8e..d7073617a 100644 --- a/radio/src/targets/taranis/CMakeLists.txt +++ b/radio/src/targets/taranis/CMakeLists.txt @@ -271,7 +271,6 @@ set(SRC set(TARGET_SRC ${TARGET_SRC} - board.cpp ${LED_DRIVER} backlight_driver.cpp extmodule_driver.cpp @@ -292,6 +291,7 @@ endif() set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} ${LCD_DRIVER} + board.cpp i2c_driver.cpp pwr_driver.cpp ../common/arm/loadboot.cpp diff --git a/radio/src/targets/taranis/board.cpp b/radio/src/targets/taranis/board.cpp index 6740b51d9..9cced91b9 100644 --- a/radio/src/targets/taranis/board.cpp +++ b/radio/src/targets/taranis/board.cpp @@ -20,12 +20,12 @@ #include "opentx.h" -#if defined(__cplusplus) && !defined(SIMU) +#if defined(__cplusplus) extern "C" { #endif #include "usb_dcd_int.h" #include "usb_bsp.h" -#if defined(__cplusplus) && !defined(SIMU) +#if defined(__cplusplus) } #endif @@ -81,7 +81,6 @@ void sportUpdatePowerOff() void boardInit() { -#if !defined(SIMU) RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | PCBREV_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | @@ -267,8 +266,6 @@ void boardInit() #if defined(GYRO) gyroInit(); #endif - -#endif // !defined(SIMU) } void boardOff() @@ -298,9 +295,7 @@ void boardOff() while (1) { wdt_reset(); -#if defined(SIMU) - return; -#elif defined(PWR_BUTTON_PRESS) +#if defined(PWR_BUTTON_PRESS) // X9E/X7 needs watchdog reset because CPU is still running while // the power key is held pressed by the user. // The power key should be released by now, but we must make sure From d1fc9474a6b1c8bf882e06997852fa022dd63bb7 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 12 Aug 2019 15:31:48 +0200 Subject: [PATCH 2/2] Compilantion fix --- radio/src/targets/simu/simpgmspace.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index cc053e595..70056de1c 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -719,3 +719,21 @@ uint16_t getCurrent() void calcConsumption() { } + +#if defined(HEADPHONE_TRAINER_SWITCH_GPIO) +void enableHeadphone() +{ +} + +void enableTrainer() +{ +} + +void enableSpeaker() +{ +} + +void disableSpeaker() +{ +} +#endif