changeset 115:3834b6272ee5 FlipDisplay

Merge with 68181cd61f2069d061621c2cd2a6afddb7486f5e
author Ideenmodellierer
date Thu, 03 Jan 2019 19:59:36 +0100
parents 79b19d56ab08 (diff) 68181cd61f20 (current diff)
children b848056057ce
files Common/Inc/settings.h Discovery/Src/base.c Discovery/Src/data_exchange_main.c Discovery/Src/settings.c Discovery/Src/show_logbook.c Discovery/Src/t7.c Discovery/Src/tMenuEditHardware.c Discovery/Src/text_multilanguage.c ostc4pack/OSTC4_Firmware.bin ostc4pack/OSTC4_RTE.bin ostc4pack/OSTC4_RTE_upload.bin ostc4pack/OSTC4_firmware_upload.bin
diffstat 19 files changed, 2958 insertions(+), 1789 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/settings.h	Mon Dec 24 16:19:09 2018 +0300
+++ b/Common/Inc/settings.h	Thu Jan 03 19:59:36 2019 +0100
@@ -216,6 +216,9 @@
 	uint8_t FactoryButtonBase;
 	uint8_t FactoryButtonBalance[3];
 
+	/* new in 0xFFFF0018 */
+	uint8_t FlipDisplay;
+
 //to be continued
 } SSettings;
 
--- a/Discovery/Inc/text_multilanguage.h	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Inc/text_multilanguage.h	Thu Jan 03 19:59:36 2019 +0100
@@ -322,6 +322,7 @@
 		TXT2BYTE_ApneaTotal,
 		TXT2BYTE_ApneaSurface,
 		/* */
+		TXT2BYTE_FLIPDISPLAY,
 		TXT2BYTE_END
 
 		// unused TXT2BYTE_Button1,
--- a/Discovery/Src/base.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/base.c	Thu Jan 03 19:59:36 2019 +0100
@@ -25,176 +25,176 @@
 //////////////////////////////////////////////////////////////////////////////
 
 /**
- @verbatim
- ==============================================================================
- ##### Firmware Info #####
- ==============================================================================
- [..] In settings.c including text and magic stuff
- ==============================================================================
- ##### IRQs #####
- ==============================================================================
- [..] The IRQs are very important and most functions should only run there.
+@verbatim
+==============================================================================
+                        ##### Firmware Info #####
+==============================================================================
+[..] In settings.c including text and magic stuff
+==============================================================================
+                        ##### IRQs #####
+==============================================================================
+[..] The IRQs are very important and most functions should only run there.
 
- PreemptPriority are as follows
- (#) 2 (low)		sprintf _only_ here. Don't use in maintask or anywhere else.
- Called by Buttons und Timer3
- Timer3 is 1/10 second
- (#) 1 (mid)		anything that should work while in IRQ2 like HalDelay(), VSYNC
- and DMA2D Transfer Complete for housekeepingFrame();
- (#)	0 (high)	_very very short_ interrupts like The HAL hardware part for
- spi, uart, i2c.
+            PreemptPriority are as follows
+            (#) 2 (low)		sprintf _only_ here. Don't use in maintask or anywhere else.
+                                        Called by Buttons und Timer3
+                                        Timer3 is 1/10 second
+            (#) 1 (mid)		anything that should work while in IRQ2 like HalDelay(), VSYNC
+                                        and DMA2D Transfer Complete for housekeepingFrame();
+            (#)	0 (high)	_very very short_ interrupts like The HAL hardware part for
+                                        spi, uart, i2c.
 
- SubPriority within 	PreemptPriority give the order to execute.
- Introduced 30.Oct.14 as it used by several HAL examples.
- Three levelAmbients are available (2 low,1 mid,0 high)
+            SubPriority within 	PreemptPriority give the order to execute.
+            Introduced 30.Oct.14 as it used by several HAL examples.
+            Three levelAmbients are available (2 low,1 mid,0 high)
 
- The STM32F4 has 4bits for IRQ levelAmbients, divided 2/2 in this code
- with the NVIC_PRIORITYGROUP_2 setting.
+            The STM32F4 has 4bits for IRQ levelAmbients, divided 2/2 in this code
+            with the NVIC_PRIORITYGROUP_2 setting.
 
- ==============================================================================
- ##### MainTask #####
- ==============================================================================
- [..] For everthing slow without importance to be 'in time'.
- Like VPM and Buehlmann.
- No sprintf and probably no GFX_SetFramesTopBottom() stuff neither.
- If sprintf is called while sprintf is executed it blows up everything.
+==============================================================================
+                        ##### MainTask #####
+==============================================================================
+[..] For everthing slow without importance to be 'in time'.
+         Like VPM and Buehlmann.
+         No sprintf and probably no GFX_SetFramesTopBottom() stuff neither.
+         If sprintf is called while sprintf is executed it blows up everything.
 
- ==============================================================================
- ##### Frames / the external SDRAM #####
- ==============================================================================
- [..] The SDRAM is handled by getFrame() and releaseFrame().
- Each frame with 800*480*2 Bytes.
- Be carefull to release every frame
- otherwise there will be a memory leakage over time.
- housekeepingFrame() in the MainTask takes care of cleaning the frames.
- All frames are filled with 0x00. This will be transparent with color of
- CLUT_Font020 (is CLUT 0) if the alpha is set for a 16bit pair.
- housekeepingFrame() delays the cleaning of frames still used as screen
- buffer to prevent flickering.
+==============================================================================
+                        ##### Frames / the external SDRAM #####
+==============================================================================
+[..] The SDRAM is handled by getFrame() and releaseFrame().
+         Each frame with 800*480*2 Bytes.
+         Be carefull to release every frame
+         otherwise there will be a memory leakage over time.
+         housekeepingFrame() in the MainTask takes care of cleaning the frames.
+         All frames are filled with 0x00. This will be transparent with color of
+         CLUT_Font020 (is CLUT 0) if the alpha is set for a 16bit pair.
+         housekeepingFrame() delays the cleaning of frames still used as screen
+         buffer to prevent flickering.
 
- [..] use global variable frameCounter[] in gfxengine.c to control memory
- all but the last three are identical to caller_id
- for example 0x05 are the menu frames
- the last but one is a sum for higher numbers (shouldn't be any)
- the last but one are those in status RELEASED
- the last are those CLEAR (as of 151202 down to 4 in logbook mode)
+[..] use global variable frameCounter[] in gfxengine.c to control memory
+         all but the last three are identical to caller_id
+         for example 0x05 are the menu frames
+         the last but one is a sum for higher numbers (shouldn't be any)
+         the last but one are those in status RELEASED
+         the last are those CLEAR (as of 151202 down to 4 in logbook mode)
 
- [..] 4 pages are used for two double memories for screenshots (since Nov. 15)
+[..] 4 pages are used for two double memories for screenshots (since Nov. 15)
 
- ==============================================================================
- ##### Display #####
- ==============================================================================
- [..] There is a Top layer, Bottom layer and background color.
- All are perfectly alpha-blended by hardware.
+==============================================================================
+                        ##### Display #####
+==============================================================================
+[..] There is a Top layer, Bottom layer and background color.
+         All are perfectly alpha-blended by hardware.
 
- (#) top layer			has 800x480 option function calls only
- as it is not used for cursors here
- (#)	bottom layer	has free size and start option to be used
- for cursors (or sprites in the future ;-)
- (#) background		only black in the moment.
- ToDo: Could be anything else for warnings etc.
- if needed
+            (#) top layer			has 800x480 option function calls only
+                                                as it is not used for cursors here
+            (#)	bottom layer	has free size and start option to be used
+                                                for cursors (or sprites in the future ;-)
+            (#) background		only black in the moment.
+                                                ToDo: Could be anything else for warnings etc.
+                                                if needed
 
- [..] Frame updates, switching and cursors is done with
+[..] Frame updates, switching and cursors is done with
 
- (#) GFX_SetFramesTopBottom() and the subset
- GFX_SetFrameTop() + GFX_SetFrameBottom()
- Those do not change anything on the display but give commands to..
- (#) GFX_change_LTDC()	The only place that changes the pointer.
- This prevents erratic behaviour if several changes
- are made within one refresh rate of the screen.
- Is called in IRQ by PD4 and HAL_GPIO_EXTI_IRQHandler
- from VSYNC signal.
+            (#) GFX_SetFramesTopBottom() and the subset
+                    GFX_SetFrameTop() + GFX_SetFrameBottom()
+                    Those do not change anything on the display but give commands to..
+            (#) GFX_change_LTDC()	The only place that changes the pointer.
+                                                        This prevents erratic behaviour if several changes
+                                                        are made within one refresh rate of the screen.
+                                                        Is called in IRQ by PD4 and HAL_GPIO_EXTI_IRQHandler
+                                                        from VSYNC signal.
 
- [..] Content
+[..] Content
 
- (#) Colors	by LookupTable only. This could be modified by
- system settings in the future. (gfx_color.h/.c)
+            (#) Colors	by LookupTable only. This could be modified by
+                                    system settings in the future. (gfx_color.h/.c)
 
- (#) Text		by text_multilinguage.h/.c with one char
- necessary only starting from '\x80'
- with automatic language switch by
- selected_language in SSettings
- see openEdit_Language() in tMenuEditSystem.c
- Therefore there are differnent functions
- for example:
- write_label_fix() for single char multilanguage
- write_label_var() for strings that could include
- multilanguage as well
- see GFX_write_string() to get an overview of the controls
- as well as the command list in gfx_engine.h
- There is no clear before writing, text overlay is always on.
- Many options to have LargeFont.SmallFont for numbers etc.
+            (#) Text		by text_multilinguage.h/.c with one char
+                                    necessary only starting from '\x80'
+                                    with automatic language switch by
+                                    selected_language in SSettings
+                                    see openEdit_Language() in tMenuEditSystem.c
+                                    Therefore there are differnent functions
+                                    for example:
+                                    write_label_fix() for single char multilanguage
+                                    write_label_var() for strings that could include
+                                    multilanguage as well
+                                    see GFX_write_string() to get an overview of the controls
+                                    as well as the command list in gfx_engine.h
+                                    There is no clear before writing, text overlay is always on.
+                                    Many options to have LargeFont.SmallFont for numbers etc.
 
- ==============================================================================
- ##### Update, DualBoot and build-in FLASH memory usage #####
- ==============================================================================
- [..] Boot0 pin, Boot1/PB2 pin and BFB2 software bit control the behaviour.
- PB2 should be tied to GND.
- Boot0 == VDD -> bootloader on start, otherwise boot from Bank1 or Bank2
- depending on BFB2.
- Bank2 contains the Fonts and should contain a proper test code in future
- Bank1 is the main code (Bank1 is 1 MB too, usage as of Oct. 14 is 200 KB)
- [..] Bootloader should be either UART or USB (on FS pins _only_)
- USB HS to FS like on the Eval board does not work.
- [..] Bootloader for the smaller CPU2 is implemented via the SPI used for DMA copy.
+==============================================================================
+                        ##### Update, DualBoot and build-in FLASH memory usage #####
+==============================================================================
+[..] Boot0 pin, Boot1/PB2 pin and BFB2 software bit control the behaviour.
+            PB2 should be tied to GND.
+            Boot0 == VDD -> bootloader on start, otherwise boot from Bank1 or Bank2
+            depending on BFB2.
+            Bank2 contains the Fonts and should contain a proper test code in future
+            Bank1 is the main code (Bank1 is 1 MB too, usage as of Oct. 14 is 200 KB)
+[..] Bootloader should be either UART or USB (on FS pins _only_)
+            USB HS to FS like on the Eval board does not work.
+[..] Bootloader for the smaller CPU2 is implemented via the SPI used for DMA copy.
 
- ==============================================================================
- ##### Connection to CPU2 (STM32F411 as of Oct.14 #####
- ==============================================================================
- [..] Connected via SPI and DMA for every purpose.
- two entire arrays are transfered for data security reasons
- with respect to master (STM32F429) might interrupt internal
- data copy in CPU2 (like hi byte, low byte, etc.).
- [..] The entire life data is calculated in CPU2. Like tissues, CNS,...
- Therefore the main unit is _not_ necessarily a Real Time system.
- Simulation on the main unit can be executed without disrupting life data.
- [..] SPI is triggered and timed by calling DataEX_call() in data_exchange_main.c
- DataEX_copy_to_LifeData() does the transfer from buffer to variables used.
+==============================================================================
+                        ##### Connection to CPU2 (STM32F411 as of Oct.14 #####
+==============================================================================
+[..] Connected via SPI and DMA for every purpose.
+            two entire arrays are transfered for data security reasons
+            with respect to master (STM32F429) might interrupt internal
+            data copy in CPU2 (like hi byte, low byte, etc.).
+[..] The entire life data is calculated in CPU2. Like tissues, CNS,...
+            Therefore the main unit is _not_ necessarily a Real Time system.
+            Simulation on the main unit can be executed without disrupting life data.
+[..] SPI is triggered and timed by calling DataEX_call() in data_exchange_main.c
+            DataEX_copy_to_LifeData() does the transfer from buffer to variables used.
 
- ==============================================================================
- ##### Menu, MenuEdit, Info #####
- ==============================================================================
- [..] tMenu.c, tMenuEdit.c and tInfo.c is the system used.
- logbook is part of Info not Menu.
- The Info Menu is accessed by button 'Back'
- The regular Menu is accessed by button 'Enter'
- [..] Menu content is kept in frame memory for fast access.
- There is no need to build pages if the 'Enter' button is pressed.
- This is in contrast to MenuEdit pages.
- [..] Button control for new pages (and pages in general) have to implemented
- in tMenu.c, tMenuEdit.c or tInfo.c
+==============================================================================
+                        ##### Menu, MenuEdit, Info #####
+==============================================================================
+[..] tMenu.c, tMenuEdit.c and tInfo.c is the system used.
+            logbook is part of Info not Menu.
+            The Info Menu is accessed by button 'Back'
+            The regular Menu is accessed by button 'Enter'
+[..] Menu content is kept in frame memory for fast access.
+            There is no need to build pages if the 'Enter' button is pressed.
+            This is in contrast to MenuEdit pages.
+[..] Button control for new pages (and pages in general) have to implemented
+            in tMenu.c, tMenuEdit.c or tInfo.c
 
- [..] ToDo (Oct. 14) Timeout for menus via Timer3 / IRQ 2
+[..] ToDo (Oct. 14) Timeout for menus via Timer3 / IRQ 2
 
- ==============================================================================
- ##### settings #####
- ==============================================================================
- [..] files: settings.c, settings.h
- 1. adjust struct SSettings in settings.h
- 2. adjust const SSettings SettingsStandard in settings.c
- 3. adjust set_new_settings_missing_in_ext_flash()
- 4. adjust check_and_correct_settings()  IMPORTANT as it changes values!
+==============================================================================
+                        ##### settings #####
+==============================================================================
+[..] files: settings.c, settings.h
+            1. adjust struct SSettings in settings.h
+            2. adjust const SSettings SettingsStandard in settings.c
+            3. adjust set_new_settings_missing_in_ext_flash()
+            4. adjust check_and_correct_settings()  IMPORTANT as it changes values!
 
- ==============================================================================
- ##### specials #####
- ==============================================================================
- [..] There was code for vector graphics from great demos
- (peridiummmm and jupiter) that can be fitted again
+==============================================================================
+                        ##### specials #####
+==============================================================================
+[..] There was code for vector graphics from great demos
+            (peridiummmm and jupiter) that can be fitted again
 
- ==============================================================================
- ##### ppO2 sensors #####
- ==============================================================================
- [..] in tCCR.c is function get_ppO2SensorWeightedResult_cbar();
+==============================================================================
+                        ##### ppO2 sensors #####
+==============================================================================
+[..] in tCCR.c is function get_ppO2SensorWeightedResult_cbar();
 
  @endverbatim
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
- *
- ******************************************************************************
- */
+******************************************************************************
+* @attention
+*
+* <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
+*
+******************************************************************************
+*/
 
 /* Includes ------------------------------------------------------------------*/
 #include "stdio.h"
@@ -242,13 +242,14 @@
 //#include <stdlib.h> // for malloc and free
 
 /** @addtogroup OSTC 4
- * @{
- */
+    * @{
+    */
 
 /* Private typedef -----------------------------------------------------------*/
 
 //#define NO_TIMEOUT
 //#define	QUICK_SLEEP
+
 /* Private define ------------------------------------------------------------*/
 //#define BUFFER_SIZE         ((uint32_t)0x00177000)
 //#define WRITE_READ_ADDR     ((uint32_t)0x0000)
@@ -257,16 +258,16 @@
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 
-RTC_HandleTypeDef RtcHandle; /* used to change time and date, no RTC is running on this MCU */
-TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */
-TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */
-TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */
+RTC_HandleTypeDef		RtcHandle; /* used to change time and date, no RTC is running on this MCU */
+TIM_HandleTypeDef   TimHandle; /* used in stm32f4xx_it.c too */
+TIM_HandleTypeDef   TimBacklightHandle; /* used in stm32f4xx_it.c too */
+TIM_HandleTypeDef   TimDemoHandle; /* used in stm32f4xx_it.c too */
 
 /*
- uint32_t time_before;
- uint32_t time_between;
- uint32_t time_after;
- */
+uint32_t time_before;
+uint32_t time_between;
+uint32_t time_after;
+*/
 
 /* SDRAM handler declaration */
 SDRAM_HandleTypeDef hsdram;
@@ -276,24 +277,24 @@
 /* This was used for Dual Boot */
 //FLASH_OBProgramInitTypeDef    OBInit;
 //FLASH_AdvOBProgramInitTypeDef AdvOBInit;
+
 /* Private variables with external access ------------------------------------*/
 
 uint32_t globalStateID = 0;
 uint8_t globalModeID = SURFMODE;
 uint32_t time_without_button_pressed_deciseconds = 0; /**< langbeschreibung (eigenes Feld) warum diese variable verwendet wird um den sleepmode zu aktivieren */
-uint8_t bootToBootloader = 0;///< set  in tComm.c to install firmware updates, calls resetToFirmwareUpdate()
+uint8_t bootToBootloader = 0;	///< set  in tComm.c to install firmware updates, calls resetToFirmwareUpdate()
 //uint8_t dataEx_VPM_call = 0;
 uint8_t returnFromCommCleanUpRequest = 0; ///< use this to exit bluetooth mode and call tComm_exit()
 uint32_t base_tempLightLevel = 0;
-uint8_t updateButtonsToDefault = 0;
-uint8_t wasFirmwareUpdateCheckBattery = 0;
+uint8_t	updateButtonsToDefault = 0;
+uint8_t	wasFirmwareUpdateCheckBattery = 0;
 
 /* Private function prototypes -----------------------------------------------*/
 
 static void SystemClock_Config(void);
 static void Error_Handler(void);
-static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram,
-		FMC_SDRAM_CommandTypeDef *Command);
+static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command);
 static void SDRAM_Config(void);
 static void EXTILine_Buttons_Config(void);
 static void TIM_init(void);
@@ -305,25 +306,25 @@
 
 /* ITM Trace-------- ---------------------------------------------------------*/
 /*
- #define ITM_Port8(n)    (*((volatile unsigned char *)(0xE0000000+4*n)))
- #define ITM_Port16(n)   (*((volatile unsigned short*)(0xE0000000+4*n)))
- #define ITM_Port32(n)   (*((volatile unsigned long *)(0xE0000000+4*n)))
+#define ITM_Port8(n)    (*((volatile unsigned char *)(0xE0000000+4*n)))
+#define ITM_Port16(n)   (*((volatile unsigned short*)(0xE0000000+4*n)))
+#define ITM_Port32(n)   (*((volatile unsigned long *)(0xE0000000+4*n)))
 
- #define DEMCR           (*((volatile unsigned long *)(0xE000EDFC)))
- #define TRCENA          0x01000000
+#define DEMCR           (*((volatile unsigned long *)(0xE000EDFC)))
+#define TRCENA          0x01000000
 
- struct __FILE { int handle; };
- FILE __stdout;
- FILE __stdin;
+struct __FILE { int handle; };
+FILE __stdout;
+FILE __stdin;
 
- int fputc(int ch, FILE *f) {
- if (DEMCR & TRCENA) {
- while (ITM_Port32(0) == 0);
- ITM_Port8(0) = ch;
- }
- return(ch);
- }
- */
+int fputc(int ch, FILE *f) {
+    if (DEMCR & TRCENA) {
+        while (ITM_Port32(0) == 0);
+        ITM_Port8(0) = ch;
+    }
+    return(ch);
+}
+*/
 
 //  ===============================================================================
 //	main
@@ -331,172 +332,175 @@
 ///					for bluetooth and deco calculations
 ///
 //  ===============================================================================
-int main(void) {
-	uint32_t pLayerInvisible;
-	uint16_t totalDiveCounterFound;
+int main(void)
+{
+    uint32_t pLayerInvisible;
+    uint16_t totalDiveCounterFound;
 
-	set_globalState( StBoot0);
+    set_globalState( StBoot0 );
 
-	HAL_Init();
-	HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2);
+    HAL_Init();
+    HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 );
 
-	SystemClock_Config();
+    SystemClock_Config();
 
-	MX_GPIO_Init();
-	//  MX_SmallCPU_NO_Reset_Helper();	 //161116 hw
-	MX_SPI_Init();
-	MX_UART_Init();
-	SDRAM_Config();
-	HAL_Delay(100);
-	GFX_init(&pLayerInvisible);
+    MX_GPIO_Init();
+    //  MX_SmallCPU_NO_Reset_Helper();	 //161116 hw
+    MX_SPI_Init();
+    MX_UART_Init();
+    SDRAM_Config();
+    HAL_Delay( 100 );
+    GFX_init( &pLayerInvisible );
 
-	TIM_init();
-	TIM_BACKLIGHT_init();
+    TIM_init();
+    TIM_BACKLIGHT_init();
 
-	/*
-	 GFX_helper_font_memory_list(&FontT24);
-	 GFX_helper_font_memory_list(&FontT42);
-	 GFX_helper_font_memory_list(&FontT48);
-	 GFX_helper_font_memory_list(&FontT54);
-	 GFX_helper_font_memory_list(&FontT84);
-	 GFX_helper_font_memory_list(&FontT105);
-	 GFX_helper_font_memory_list(&FontT144);
-	 */
+    /*
+        GFX_helper_font_memory_list(&FontT24);
+        GFX_helper_font_memory_list(&FontT42);
+        GFX_helper_font_memory_list(&FontT48);
+        GFX_helper_font_memory_list(&FontT54);
+        GFX_helper_font_memory_list(&FontT84);
+        GFX_helper_font_memory_list(&FontT105);
+        GFX_helper_font_memory_list(&FontT144);
+    */
 
-	stateRealGetPointerWrite()->lastKnownBatteryPercentage = 0; // damit das nicht in settings kopiert wird.
-	set_settings_to_Standard();
-	mod_settings_for_first_start_with_empty_ext_flash();
-	ext_flash_read_settings();
-	if (newFirmwareVersionCheckViaSettings()) // test for old firmware version in loaded settings
-	{
-		wasFirmwareUpdateCheckBattery = 1;
-		set_settings_button_to_standard_with_individual_buttonBalance(); // will adapt individual values
-	}
-	//settingsGetPointer()->bluetoothActive = 0; 	/* MX_Bluetooth_PowerOff();  unnecessary as part of MX_GPIO_Init() */
-	//settingsGetPointer()->compassBearing = 0;
-	set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version  161121
+    stateRealGetPointerWrite()->lastKnownBatteryPercentage = 0; // damit das nicht in settings kopiert wird.
+    set_settings_to_Standard();
+    mod_settings_for_first_start_with_empty_ext_flash();
+    ext_flash_read_settings();
+    if( newFirmwareVersionCheckViaSettings() ) // test for old firmware version in loaded settings
+    {
+        wasFirmwareUpdateCheckBattery = 1;
+        set_settings_button_to_standard_with_individual_buttonBalance(); // will adapt individual values
+    }
+    //settingsGetPointer()->bluetoothActive = 0; 	/* MX_Bluetooth_PowerOff();  unnecessary as part of MX_GPIO_Init() */
+    //settingsGetPointer()->compassBearing = 0;
+    set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version  161121
 
-	// new 170508: bluetooth on at start
-	settingsGetPointer()->bluetoothActive = 1;
-	MX_Bluetooth_PowerOn();
+    // new 170508: bluetooth on at start
+    settingsGetPointer()->bluetoothActive = 1;
+    MX_Bluetooth_PowerOn();
 
-	// Haase Geburtstag:
-	//  settingsGetPointer()->serialHigh = (3012 / 256);
-	//  settingsGetPointer()->serialLow  = (3012 & 0xFF);
+    // Haase Geburtstag:
+    //  settingsGetPointer()->serialHigh = (3012 / 256);
+    //  settingsGetPointer()->serialLow  = (3012 & 0xFF);
 
-	//  settingsGetPointer()->showDebugInfo = 1;
+    //  settingsGetPointer()->showDebugInfo = 1;
 
-	/*
-	 if(settingsGetPointer()->scooterControl)
-	 {
-	 settingsGetPointer()->bluetoothActive = 1;
-	 MX_Bluetooth_PowerOn();
-	 if(settingsGetPointer()->scooterDeviceAddress[0] != 0)
-	 bC_setConnectRequest();
-	 }
-	 */
-	/*
-	 if( (hardwareDataGetPointer()->primarySerial == 20+18)
-	 || (hardwareDataGetPointer()->primarySerial == 20+25)
-	 || (hardwareDataGetPointer()->primarySerial == 20+27))
-	 {
-	 MX_Bluetooth_PowerOn();
-	 tComm_Set_Bluetooth_Name(1);
-	 }
-	 */
-	errorsInSettings = check_and_correct_settings();
-	createDiveSettings();
+    /*
+    if(settingsGetPointer()->scooterControl)
+    {
+         settingsGetPointer()->bluetoothActive = 1;
+         MX_Bluetooth_PowerOn();
+         if(settingsGetPointer()->scooterDeviceAddress[0] != 0)
+            bC_setConnectRequest();
+    }
+    */
+    /*
+    if( (hardwareDataGetPointer()->primarySerial == 20+18)
+     || (hardwareDataGetPointer()->primarySerial == 20+25)
+     || (hardwareDataGetPointer()->primarySerial == 20+27))
+    {
+        MX_Bluetooth_PowerOn();
+        tComm_Set_Bluetooth_Name(1);
+    }
+    */
+    errorsInSettings = check_and_correct_settings();
+    createDiveSettings();
 
 #ifdef QUICK_SLEEP
-	settingsGetPointer()->timeoutSurfacemode = 20;
+    settingsGetPointer()->timeoutSurfacemode = 20;
 #else
-	settingsGetPointer()->timeoutSurfacemode = 120;
+    settingsGetPointer()->timeoutSurfacemode = 120;
 #endif
 
 #ifdef DEMOMODE
-	demoConfigureSettings();
-	TIM_DEMO_init();
+    demoConfigureSettings();
+    TIM_DEMO_init();
 #endif
 
 // -----------------------------
 
-	display_power_on__1_of_2__pre_RGB();
-	GFX_LTDC_Init();
-	GFX_LTDC_LayerDefaultInit( TOP_LAYER, pLayerInvisible);
-	GFX_LTDC_LayerDefaultInit( BACKGRD_LAYER, pLayerInvisible);
-	GFX_SetFramesTopBottom(pLayerInvisible, pLayerInvisible, 480);
-	HAL_Delay(20);
-	display_power_on__2_of_2__post_RGB();
-	GFX_use_colorscheme(settingsGetPointer()->tX_colorscheme);
+    display_power_on__1_of_2__pre_RGB();
+    GFX_LTDC_Init();
+    GFX_LTDC_LayerDefaultInit( TOP_LAYER, pLayerInvisible );
+    GFX_LTDC_LayerDefaultInit( BACKGRD_LAYER, pLayerInvisible );
+    GFX_SetFramesTopBottom( pLayerInvisible, pLayerInvisible, 480 );
+    HAL_Delay( 20 );
+    display_power_on__2_of_2__post_RGB();
+    GFX_use_colorscheme( settingsGetPointer()->tX_colorscheme );
 
 // -----------------------------
-	tHome_init();
-	tI_init();
-	tM_init();
-	tMenuEdit_init();
-	tInfoLog_init();
-	tComm_init();
-	DataEX_init();
-	setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness);
-	set_globalState_tHome();
+    tHome_init();
+    tI_init();
+    tM_init();
+    tMenuEdit_init();
+    tInfoLog_init();
+    tComm_init();
+    DataEX_init();
+    setButtonResponsiveness( settingsGetPointer()->ButtonResponsiveness );
+    set_globalState_tHome();
 
-	GFX_start_VSYNC_IRQ();
-	tCCR_init();
+    GFX_start_VSYNC_IRQ();
+    tCCR_init();
+
+    GFX_logoAutoOff();
+    EXTILine_Buttons_Config();
 
-	GFX_logoAutoOff();
-	EXTILine_Buttons_Config();
+    ext_flash_repair_dive_log();
+    //ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(1);
 
-	ext_flash_repair_dive_log();
-	//ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(1);
+    totalDiveCounterFound = logbook_lastDive_diveNumber();
+    if( settingsGetPointer()->totalDiveCounter < totalDiveCounterFound )
+            settingsGetPointer()->totalDiveCounter = totalDiveCounterFound;
 
-	totalDiveCounterFound = logbook_lastDive_diveNumber();
-	if (settingsGetPointer()->totalDiveCounter < totalDiveCounterFound)
-		settingsGetPointer()->totalDiveCounter = totalDiveCounterFound;
-
-	if (settingsGetPointer()->debugModeOnStart) {
-		settingsGetPointer()->debugModeOnStart = 0;
-		ext_flash_write_settings();
-		setDebugMode();
-		openInfo( StIDEBUG);
-	}
+    if( settingsGetPointer()->debugModeOnStart )
+    {
+        settingsGetPointer()->debugModeOnStart = 0;
+        ext_flash_write_settings();
+        setDebugMode();
+        openInfo( StIDEBUG );
+    }
 
-	/* @brief main LOOP
-	 *
-	 * this is executed while no IRQ interrupts it
-	 * - deco calculation
-	 * - bluetooth
-	 * and resetToFirmwareUpdate()
-	 * because tComm_control() does not exit before disconnection
-	 */
-	while (1) {
-		if (bootToBootloader)
-			resetToFirmwareUpdate();
+    /* @brief main LOOP
+     *
+     * this is executed while no IRQ interrupts it
+     * - deco calculation
+     * - bluetooth
+     * and resetToFirmwareUpdate()
+     * because tComm_control() does not exit before disconnection
+     */
+    while( 1 )
+    {
+        if( bootToBootloader )
+            resetToFirmwareUpdate();
 
-		// this will allways reset after RTE reset -> no good!
+        // this will allways reset after RTE reset -> no good!
 //		if(DataEX_was_power_on()) // new to allow for update after RTE update
 //			resetToFirmwareUpdate();
 
-		tCCR_control();
-		if (tComm_control()) // will stop while loop if tComm Mode started until exit from UART
-		{
-			createDiveSettings();
-			updateMenu();
-			ext_flash_write_settings();
-		}
-		deco_loop();
-		/*
-		 bonexControl();
-		 if(bC_getStatus() == BC_DISCONNECTED)
-		 {
-		 if(tComm_control())			// will stop while loop if tComm Mode started until exit from UART
-		 {
-		 createDiveSettings();
-		 updateMenu();
-		 ext_flash_write_settings();
-		 }
-		 }
-		 */
-	}
+        tCCR_control();
+        if( tComm_control() )// will stop while loop if tComm Mode started until exit from UART
+        {
+            createDiveSettings();
+            updateMenu();
+            ext_flash_write_settings();
+        }
+        deco_loop();
+        /*
+        bonexControl();
+        if(bC_getStatus() == BC_DISCONNECTED)
+        {
+            if(tComm_control())			// will stop while loop if tComm Mode started until exit from UART
+            {
+                createDiveSettings();
+                updateMenu();
+                ext_flash_write_settings();
+            }
+        }
+        */
+    }
 }
 
 //  ===============================================================================
@@ -514,245 +518,248 @@
 /// to be called
 ///
 //  ===============================================================================
-void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
-//	DataEX_call();
+void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
+{
 #ifdef DEMOMODE
-	if(htim->Instance==TIM7)
-	{
-		HAL_GPIO_EXTI_Callback(demoGetCommand());
-		return;
-	}
+    if(htim->Instance==TIM7)
+    {
+        HAL_GPIO_EXTI_Callback(demoGetCommand());
+        return;
+    }
 #endif
-	static uint8_t last_base;
+    static uint8_t last_base;
 
-	SStateList status;
-	uint32_t timeout_in_seconds;
-	uint32_t timeout_limit_Surface_in_seconds;
+    SStateList status;
+    uint32_t timeout_in_seconds;
+    uint32_t timeout_limit_Surface_in_seconds;
 
-	_Bool InDiveMode = 0;
-	_Bool modeChange = 0; // to exit from menu and logbook
+    _Bool InDiveMode = 0;
+    _Bool modeChange = 0; // to exit from menu and logbook
 
-	if (stateUsed->mode == MODE_DIVE)
-		InDiveMode = 1;
-	else
-		InDiveMode = 0;
+    if(stateUsed->mode == MODE_DIVE)
+        InDiveMode = 1;
+    else
+        InDiveMode = 0;
 
-	if (returnFromCommCleanUpRequest) {
-		tComm_exit();
-		returnFromCommCleanUpRequest = 0;
-	}
+    if(returnFromCommCleanUpRequest)
+    {
+        tComm_exit();
+        returnFromCommCleanUpRequest = 0;
+    }
 
-	get_globalStateList(&status);
+    get_globalStateList(&status);
 
-	switch (status.base) {
-	case BaseHome:
-	case BaseMenu:
-	case BaseInfo:
-		updateSetpointStateUsed();
-		DateEx_copy_to_dataOut();
-		DataEX_call();
-		DataEX_copy_to_LifeData(&modeChange);
+    switch(status.base)
+    {
+    case BaseHome:
+    case BaseMenu:
+    case BaseInfo:
+        updateSetpointStateUsed();
+        DateEx_copy_to_dataOut();
+        DataEX_call();
+        DataEX_copy_to_LifeData(&modeChange);
 //foto session :-)  stateRealGetPointerWrite()->lifeData.battery_charge = 99;
 //foto session :-)  stateSimGetPointerWrite()->lifeData.battery_charge = 99;
-		DataEX_copy_to_deco();
-		if (stateUsed == stateSimGetPointer())
-			simulation_UpdateLifeData(1);
-		check_warning();
-		if (stateUsed == stateRealGetPointer())
-			logbook_InitAndWrite();
-		updateMiniLiveLogbook(1);
-		timer_UpdateSecond(1);
-		base_tempLightLevel = TIM_BACKLIGHT_adjust();
-		tCCR_tick();
-		tHome_tick();
-		if (status.base == BaseHome)
-			tMenuEdit_writeSettingsToFlash(); // takes 900 ms!!
-		break;
-	case BaseStop:
-		DateEx_copy_to_dataOut();
-		DataEX_call();
-		DataEX_control_connection_while_asking_for_sleep();
-		break;
-	default:
-	case BaseComm:
-		if (get_globalState() == StUART_RTECONNECT) {
-			DateEx_copy_to_dataOut();
-			DataEX_call();
-			DataEX_copy_to_LifeData(0);
-		}
-		break;
-	}
+        DataEX_copy_to_deco();
+        if(stateUsed == stateSimGetPointer())
+            simulation_UpdateLifeData(1);
+        check_warning();
+        if(stateUsed == stateRealGetPointer())
+            logbook_InitAndWrite();
+        updateMiniLiveLogbook(1);
+        timer_UpdateSecond(1);
+base_tempLightLevel =			TIM_BACKLIGHT_adjust();
+        tCCR_tick();
+        tHome_tick();
+        if(status.base == BaseHome)
+            tMenuEdit_writeSettingsToFlash(); // takes 900 ms!!
+        break;
+    case BaseStop:
+        DateEx_copy_to_dataOut();
+        DataEX_call();
+        DataEX_control_connection_while_asking_for_sleep();
+        break;
+    default:
+    case BaseComm:
+        if(get_globalState() == StUART_RTECONNECT)
+        {
+            DateEx_copy_to_dataOut();
+            DataEX_call();
+            DataEX_copy_to_LifeData(0);
+        }
+        break;
+    }
 
-	/* timeout control */
-	if (modeChange) ///< from RTE, set in data_exchange_main.c
-		time_without_button_pressed_deciseconds =
-				(settingsGetPointer()->timeoutSurfacemode / 4) * 3;
-	if (status.base != last_base)
-		time_without_button_pressed_deciseconds = 0;
-	last_base = status.base;
-	timeout_in_seconds = time_without_button_pressed_deciseconds / 10;
-	time_without_button_pressed_deciseconds += 1;
-	if (modeChange
-			|| (timeout_in_seconds
-					!= time_without_button_pressed_deciseconds / 10)) {
+    /* timeout control */
+    if(modeChange) ///< from RTE, set in data_exchange_main.c
+        time_without_button_pressed_deciseconds = (settingsGetPointer()->timeoutSurfacemode / 4) * 3;
+    if(status.base != last_base)
+        time_without_button_pressed_deciseconds = 0;
+    last_base = status.base;
+    timeout_in_seconds = time_without_button_pressed_deciseconds / 10;
+    time_without_button_pressed_deciseconds += 1;
+    if(modeChange || (timeout_in_seconds != time_without_button_pressed_deciseconds / 10))
+    {
 #ifdef NO_TIMEOUT
-		timeout_in_seconds = 0;
+        timeout_in_seconds = 0;
 #else
-		timeout_in_seconds += 1;
+        timeout_in_seconds += 1;
 #endif
 
-		if (InDiveMode) {
-			switch (status.base) {
-			case BaseHome:
-				if ((status.line != 0)
-						&& (timeout_in_seconds
-								>= settingsGetPointer()->timeoutEnterButtonSelectDive)) {
-					set_globalState(StD);
-					timeout_in_seconds = 0;
-				}
-				break;
-
-			case BaseMenu:
-				if ((status.line == 0)
-						&& ((timeout_in_seconds
-								>= settingsGetPointer()->timeoutMenuDive)
-								|| modeChange)) {
-					exitMenu();
-					timeout_in_seconds = 0;
-				}
-				if ((status.line != 0)
-						&& ((timeout_in_seconds
-								>= settingsGetPointer()->timeoutMenuEdit)
-								|| modeChange)) {
-					exitMenuEdit_to_Home();
-					timeout_in_seconds = 0;
-				}
-				break;
-				/* why was this here? 160317 hw
-				 case BaseInfo:
-				 if(status.page == InfoPageLogList)
-				 {
-				 exitLog();
-				 }
-				 else
-				 if(status.page == InfoPageLogShow)
-				 {
-				 show_logbook_exit();
-				 exitLog();
-				 }
-				 else
-				 if(status.page != InfoPageCompass)
-				 {
-				 exitInfo();
-				 }
-				 timeout_in_seconds = 0;
-				 break;
-				 */
-			default:
-				break;
-			}
-		} else /* surface mode */
-		{
-			switch (status.base) {
-			case BaseHome:
-				// added hw 161027
-				if (!(stateRealGetPointer()->warnings.lowBattery) && (stateRealGetPointer()->lifeData.battery_charge > 9)) {
-					stateRealGetPointerWrite()->lastKnownBatteryPercentage =stateRealGetPointer()->lifeData.battery_charge;
-				} else if ((wasFirmwareUpdateCheckBattery) && (timeout_in_seconds > 3)) {
-					wasFirmwareUpdateCheckBattery = 0;
-					setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); // added 170306
-					if ((settingsGetPointer()->lastKnownBatteryPercentage > 0) &&
-							(settingsGetPointer()->lastKnownBatteryPercentage <= 100) &&
-							(stateRealGetPointer()->warnings.lowBattery))
-					{
-//						If PowerOff, and battery is <=100, and lifeData.battery_charge < 10 - ALWAYS!!! set DataOutnewBatteryGaugePercentageFloat
-//						Need to fix in smallCPU handled. Compeled.
-						//upd.Fixed.
-						setBatteryPercentage(settingsGetPointer()->lastKnownBatteryPercentage);
+        if(InDiveMode)
+        {
+            switch(status.base)
+            {
+            case BaseHome:
+                if((status.line != 0) && (timeout_in_seconds  >= settingsGetPointer()->timeoutEnterButtonSelectDive))
+                {
+                    set_globalState(StD);
+                    timeout_in_seconds = 0;
+                }
+            break;
 
-					}
-				}
-				// stuff before and new @161121 CCR-sensor limit 10 minutes
-				if ((settingsGetPointer()->dive_mode == DIVEMODE_CCR)
-						&& (settingsGetPointer()->CCR_Mode == CCRMODE_Sensors)) {
-					timeout_limit_Surface_in_seconds =
-							settingsGetPointer()->timeoutSurfacemodeWithSensors;
-				} else {
-					timeout_limit_Surface_in_seconds =
-							settingsGetPointer()->timeoutSurfacemode;
-				}
-				if (timeout_in_seconds >= timeout_limit_Surface_in_seconds) {
-					gotoSleep();
-				}
-				break;
-			case BaseMenu:
-				if ((status.line == 0)
-						&& ((timeout_in_seconds
-								>= settingsGetPointer()->timeoutMenuSurface)
-								|| modeChange)) {
-					exitMenu();
-					timeout_in_seconds = 0;
-				}
-				if ((status.line != 0)
-						&& ((timeout_in_seconds
-								>= settingsGetPointer()->timeoutMenuEdit)
-								|| modeChange)) {
-					if ((status.page != (uint8_t) ((StMPLAN >> 24) & 0x0F))
-							|| (timeout_in_seconds
-									>= 10
-											* (settingsGetPointer()->timeoutMenuEdit))) {
-						exitMenuEdit_to_Home();
-						timeout_in_seconds = 0;
-					}
-				}
-				break;
+            case BaseMenu:
+                if((status.line == 0) && ((timeout_in_seconds  >= settingsGetPointer()->timeoutMenuDive) || modeChange))
+                {
+                    exitMenu();
+                    timeout_in_seconds = 0;
+                }
+                if((status.line != 0) && ((timeout_in_seconds  >= settingsGetPointer()->timeoutMenuEdit) || modeChange))
+                {
+                    exitMenuEdit_to_Home();
+                    timeout_in_seconds = 0;
+                }
+            break;
+/* why was this here? 160317 hw
+            case BaseInfo:
+                if(status.page == InfoPageLogList)
+                {
+                    exitLog();
+                }
+                else
+                if(status.page == InfoPageLogShow)
+                {
+                    show_logbook_exit();
+                    exitLog();
+                }
+                else
+                if(status.page != InfoPageCompass)
+                {
+                    exitInfo();
+                }
+                timeout_in_seconds = 0;
+            break;
+*/
+            default:
+                break;
+            }
+        }
+        else /* surface mode */
+        {
+            switch(status.base)
+            {
+            case BaseHome:
+                // added hw 161027
+                if(!(stateRealGetPointer()->warnings.lowBattery) && (stateRealGetPointer()->lifeData.battery_charge > 9))
+                {
+                    stateRealGetPointerWrite()->lastKnownBatteryPercentage = stateRealGetPointer()->lifeData.battery_charge;
+                }
+                else if((wasFirmwareUpdateCheckBattery) && (timeout_in_seconds > 3))
+                {
+                    wasFirmwareUpdateCheckBattery = 0;
+                    setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); // added 170306
+                    if(	(settingsGetPointer()->lastKnownBatteryPercentage > 0)
+                    && 	(settingsGetPointer()->lastKnownBatteryPercentage <= 100)
+                    && 	(stateRealGetPointer()->warnings.lowBattery))
+                    {
+                        setBatteryPercentage(settingsGetPointer()->lastKnownBatteryPercentage);
+                    }
+                }
+                // stuff before and new @161121 CCR-sensor limit 10 minutes
+                if((settingsGetPointer()->dive_mode == DIVEMODE_CCR) && (settingsGetPointer()->CCR_Mode == CCRMODE_Sensors))
+                {
+                    timeout_limit_Surface_in_seconds = settingsGetPointer()->timeoutSurfacemodeWithSensors;
+                }
+                else
+                {
+                    timeout_limit_Surface_in_seconds = settingsGetPointer()->timeoutSurfacemode;
+                }
+                if(timeout_in_seconds  >= timeout_limit_Surface_in_seconds)
+                {
+                    gotoSleep();
+                }
+                break;
+            case BaseMenu:
+                if((status.line == 0) && ((timeout_in_seconds  >= settingsGetPointer()->timeoutMenuSurface) || modeChange))
+                {
+                    exitMenu();
+                    timeout_in_seconds = 0;
+                }
+                if((status.line != 0) && ((timeout_in_seconds  >= settingsGetPointer()->timeoutMenuEdit) || modeChange))
+                {
+                    if((status.page != (uint8_t)((StMPLAN >> 24) & 0x0F)) || (timeout_in_seconds  >= 10*(settingsGetPointer()->timeoutMenuEdit)))
+                    {
+                        exitMenuEdit_to_Home();
+                        timeout_in_seconds = 0;
+                    }
+                }
+                break;
 
-			case BaseInfo:
-				if ((timeout_in_seconds >= settingsGetPointer()->timeoutInfo)
-						|| modeChange) {
-					if (status.page == InfoPageLogList) {
-						exitLog();
-						timeout_in_seconds = 0;
-					} else if (status.page == InfoPageLogShow) {
-						show_logbook_exit();
-						exitLog();
-						timeout_in_seconds = 0;
-					} else if (status.page != InfoPageCompass) {
-						exitInfo();
-						timeout_in_seconds = 0;
-					}
-				}
-				break;
-			default:
-				break;
-			}
-		}
-	}
+            case BaseInfo:
+                if((timeout_in_seconds  >= settingsGetPointer()->timeoutInfo) || modeChange)
+                {
+                    if(status.page == InfoPageLogList)
+                    {
+                        exitLog();
+                        timeout_in_seconds = 0;
+                    }
+                    else
+                    if(status.page == InfoPageLogShow)
+                    {
+                        show_logbook_exit();
+                        exitLog();
+                        timeout_in_seconds = 0;
+                    }
+                    else
+                    if(status.page != InfoPageCompass)
+                    {
+                        exitInfo();
+                        timeout_in_seconds = 0;
+                    }
+                }
+                break;
+            default:
+                break;
+            }
+        }
+    }
 
-	get_globalStateList(&status);
+    get_globalStateList(&status);
 
-	switch (status.base) {
-	case BaseHome:
-		tHome_refresh();
-		tM_check_content();
-		break;
-	case BaseMenu:
-		tM_refresh_live_content();
-		tMenuEdit_refresh_live_content();
-		break;
-	case BaseInfo:
-		tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
-		break;
-	case BaseComm:
-		tComm_refresh();
-		break;
-	default:
-		if (get_globalState() == StStop)
-			tHome_sleepmode_fun();
-		break;
-	}
+    switch(status.base)
+    {
+    case BaseHome:
+        tHome_refresh();
+        tM_check_content();
+        break;
+    case BaseMenu:
+        tM_refresh_live_content();
+        tMenuEdit_refresh_live_content();
+        break;
+    case BaseInfo:
+        tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
+        break;
+    case BaseComm:
+         tComm_refresh();
+        break;
+    default:
+        if(get_globalState() == StStop)
+            tHome_sleepmode_fun();
+        break;
+    }
 }
 
+
 /* button and VSYNC IRQ
  *
  * VSYNC will switch foreground and background picture
@@ -792,6 +799,27 @@
 		 */
 		return;
 	}
+	
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+	if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten
+	{
+		GFX_change_LTDC();
+		housekeepingFrame();
+		/*
+		 #ifdef DEMOMODE
+		 static uint8_t countCall = 0;
+		 if(countCall++ < 10)
+		 return;
+		 countCall = 0;
+		 uint8_t buttonAction = demoGetCommand();
+		 if(buttonAction)
+		 GPIO_Pin = buttonAction;
+		 else
+		 #endif
+		 */
+		return;
+	}
 
 #ifdef DEMOMODE
 	uint8_t demoMachineCall = 0;
@@ -828,11 +856,35 @@
 		}
 	}
 
-#ifdef BUTTON_CUSTOM_PIN
-	else
-	if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra
-	action = ACTION_BUTTON_CUSTOM;
-#endif
+    if(GPIO_Pin == BUTTON_BACK_PIN) // links
+    {
+    	if(!pSettings->FlipDisplay)
+    	{
+    		action = ACTION_BUTTON_BACK;
+    	}
+    	else
+    	{
+    		action = ACTION_BUTTON_NEXT;
+    	}
+    }
+    else
+    {
+		if(GPIO_Pin == BUTTON_ENTER_PIN) // mitte
+			action = ACTION_BUTTON_ENTER;
+		else
+		{
+			if(GPIO_Pin == BUTTON_NEXT_PIN) // rechts
+			{
+				if(!pSettings->FlipDisplay)	action = ACTION_BUTTON_NEXT;
+				 else action = ACTION_BUTTON_BACK;
+			}
+		}
+    }
+	#ifdef BUTTON_CUSTOM_PIN
+		else
+		if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra
+			action = ACTION_BUTTON_CUSTOM;
+	#endif
 
 #ifdef DEMOMODE // user pressed button ?
 	if((!demoMachineCall) && demoModeActive())
@@ -913,209 +965,241 @@
 	}
 }
 
-void gotoSleep(void) {
-	/* not at the moment of testing */
+
+void gotoSleep(void)
+{
+    /* not at the moment of testing */
 //	ext_flash_erase_firmware_if_not_empty();
-	GFX_logoAutoOff();
-	set_globalState(StStop);
+    GFX_logoAutoOff();
+    set_globalState(StStop);
 }
 
+
 // -----------------------------
 
-uint8_t get_globalMode(void) {
-	return globalModeID;
+uint8_t get_globalMode(void)
+{
+    return globalModeID;
 }
 
-void set_globalMode(uint8_t newMode) {
-	if ((newMode != DIVEMODE) && (newMode != SURFMODE))
-		return;
 
-	globalModeID = newMode;
+void set_globalMode(uint8_t newMode)
+{
+    if((newMode != DIVEMODE) && (newMode != SURFMODE))
+        return;
+
+    globalModeID = newMode;
 }
 
-uint32_t get_globalState(void) {
-	return globalStateID;
+
+uint32_t get_globalState(void)
+{
+    return globalStateID;
 }
 
-void get_globalStateList(SStateList *output) {
-	output->base = (uint8_t) ((globalStateID >> 28) & 0x0F);
-	output->page = (uint8_t) ((globalStateID >> 24) & 0x0F);
-	output->line = (uint8_t) ((globalStateID >> 16) & 0xFF);
-	output->field = (uint8_t) ((globalStateID >> 8) & 0xFF);
-	output->mode = (uint8_t) ((globalStateID) & 0xFF);
+
+void get_globalStateList(SStateList *output)
+{
+    output->base  = (uint8_t)((globalStateID >> 28) & 0x0F);
+    output->page  = (uint8_t)((globalStateID >> 24) & 0x0F);
+    output->line  = (uint8_t)((globalStateID >> 16) & 0xFF);
+    output->field = (uint8_t)((globalStateID >> 8) & 0xFF);
+    output->mode  = (uint8_t)((globalStateID     ) & 0xFF);
 }
 
-void get_idSpecificStateList(uint32_t id, SStateList *output) {
-	output->base = (uint8_t) ((id >> 28) & 0x0F);
-	output->page = (uint8_t) ((id >> 24) & 0x0F);
-	output->line = (uint8_t) ((id >> 16) & 0xFF);
-	output->field = (uint8_t) ((id >> 8) & 0xFF);
-	output->mode = (uint8_t) ((id) & 0xFF);
+
+void get_idSpecificStateList(uint32_t id, SStateList *output)
+{
+    output->base  = (uint8_t)((id >> 28) & 0x0F);
+    output->page  = (uint8_t)((id >> 24) & 0x0F);
+    output->line  = (uint8_t)((id >> 16) & 0xFF);
+    output->field = (uint8_t)((id >> 8) & 0xFF);
+    output->mode  = (uint8_t)((id     ) & 0xFF);
 }
 
-void set_globalState_Menu_Page(uint8_t page) {
-	globalStateID = ((BaseMenu << 28) + (page << 24));
+
+void set_globalState_Menu_Page(uint8_t page)
+{
+    globalStateID = ((BaseMenu << 28) + (page << 24));
 }
 
-void set_globalState_Log_Page(uint8_t pageIsLine) {
-	globalStateID = StILOGLIST + (pageIsLine << 16);
+void set_globalState_Log_Page(uint8_t pageIsLine)
+{
+    globalStateID = StILOGLIST + (pageIsLine << 16);
 }
 
-void set_globalState_Menu_Line(uint8_t line) {
-	globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16));
+
+void set_globalState_Menu_Line(uint8_t line)
+{
+    globalStateID = ((globalStateID & MaskLineFieldDigit) + (line << 16));
 }
 
-void set_globalState(uint32_t newID) {
-	globalStateID = newID;
+
+void set_globalState(uint32_t newID)
+{
+    globalStateID = newID;
 }
 
-void set_returnFromComm(void) {
-	returnFromCommCleanUpRequest = 1;
+void set_returnFromComm(void)
+{
+    returnFromCommCleanUpRequest = 1;
 }
 
-uint8_t font_update_required(void) {
-	uint8_t *fontVersionHigh;
-	uint8_t *fontVersionLow;
+uint8_t font_update_required(void)
+{
+    uint8_t *fontVersionHigh;
+    uint8_t *fontVersionLow;
 
-	fontVersionHigh = (uint8_t *) 0x08132000;
-	fontVersionLow = (uint8_t *) 0x08132001;
+    fontVersionHigh = (uint8_t *)0x08132000;
+    fontVersionLow = (uint8_t *)0x08132001;
 
-	if (FONTminimum_required_high() < *fontVersionHigh)
-		return 0;
+    if(FONTminimum_required_high() < *fontVersionHigh)
+        return 0;
 
-	if ((FONTminimum_required_high() == *fontVersionHigh)
-			&& (FONTminimum_required_low() <= *fontVersionLow))
-		return 0;
+    if((FONTminimum_required_high() == *fontVersionHigh) && (FONTminimum_required_low() <= *fontVersionLow))
+        return 0;
 
-	return 1;
+    return 1;
 }
 
-void delayMicros(uint32_t micros) {
-	micros = micros * (168 / 4) - 10;
-	while (micros--)
-		;
+
+void delayMicros(uint32_t micros)
+{
+    micros = micros * (168/4) - 10;
+    while(micros--);
 }
 
-void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget,
-		RTC_TimeTypeDef * stimestructureget) {
-	/* Get the RTC current Time */
-	if (sdatestructureget)
-		HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN);
-	/* Get the RTC current Date */
-	if (stimestructureget)
-		HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN);
+
+void get_RTC_DateTime(RTC_DateTypeDef * sdatestructureget, RTC_TimeTypeDef * stimestructureget)
+{
+    /* Get the RTC current Time */
+    if(sdatestructureget)
+        HAL_RTC_GetTime(&RtcHandle, stimestructureget, FORMAT_BIN);
+    /* Get the RTC current Date */
+    if(stimestructureget)
+        HAL_RTC_GetDate(&RtcHandle, sdatestructureget, FORMAT_BIN);
 }
 
-void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure,
-		RTC_TimeTypeDef * stimestructure) {
-	if (sdatestructure)
-		if (HAL_RTC_SetDate(&RtcHandle, sdatestructure, FORMAT_BCD) != HAL_OK) {
-			/* Initialization Error */
-			Error_Handler();
-		}
 
-	if (stimestructure)
-		if (HAL_RTC_SetTime(&RtcHandle, stimestructure, FORMAT_BCD) != HAL_OK) {
-			/* Initialization Error */
-			Error_Handler();
-		}
+void set_RTC_DateTime(RTC_DateTypeDef * sdatestructure, RTC_TimeTypeDef * stimestructure)
+{
+    if(sdatestructure)
+        if(HAL_RTC_SetDate(&RtcHandle,sdatestructure,FORMAT_BCD) != HAL_OK)
+        {
+            /* Initialization Error */
+            Error_Handler();
+        }
+
+    if(stimestructure)
+        if(HAL_RTC_SetTime(&RtcHandle,stimestructure,FORMAT_BCD) != HAL_OK)
+        {
+            /* Initialization Error */
+            Error_Handler();
+        }
 }
 
-static void TIM_init(void) {
-	uint16_t uwPrescalerValue = 0;
+static void TIM_init(void)
+{
+    uint16_t uwPrescalerValue = 0;
 
-	uwPrescalerValue = (uint32_t) ((SystemCoreClock / 2) / 10000) - 1;
+    uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1;
 
-	/* Set TIMx instance */
-	TimHandle.Instance = TIMx;
+    /* Set TIMx instance */
+    TimHandle.Instance = TIMx;
 
-	/* Initialize TIM3 peripheral as follows:
-	 + Period = 10000 - 1
-	 + Prescaler = ((SystemCoreClock/2)/10000) - 1
-	 + ClockDivision = 0
-	 + Counter direction = Up
-	 */
-	TimHandle.Init.Period = 1000 - 1;
-	TimHandle.Init.Prescaler = uwPrescalerValue;
-	TimHandle.Init.ClockDivision = 0;
-	TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
-	if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK) {
-		/* Initialization Error */
-		Error_Handler();
-	}
+    /* Initialize TIM3 peripheral as follows:
+             + Period = 10000 - 1
+             + Prescaler = ((SystemCoreClock/2)/10000) - 1
+             + ClockDivision = 0
+             + Counter direction = Up
+    */
+    TimHandle.Init.Period = 1000 - 1;
+    TimHandle.Init.Prescaler = uwPrescalerValue;
+    TimHandle.Init.ClockDivision = 0;
+    TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
+    if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
+    {
+        /* Initialization Error */
+        Error_Handler();
+    }
 
-	/*##-2- Start the TIM Base generation in interrupt mode ####################*/
-	/* Start Channel1 */
-	if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) {
-		/* Starting Error */
-		Error_Handler();
-	}
+    /*##-2- Start the TIM Base generation in interrupt mode ####################*/
+    /* Start Channel1 */
+    if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
+    {
+        /* Starting Error */
+        Error_Handler();
+    }
 }
 
 #ifdef DEMOMODE
 static void TIM_DEMO_init(void)
 {
-	uint16_t uwPrescalerValue = 0;
+    uint16_t uwPrescalerValue = 0;
 
-	uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1;
+    uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 10000) - 1;
 
-	/* Set TIMx instance */
-	TimDemoHandle.Instance = TIM7;
+    /* Set TIMx instance */
+    TimDemoHandle.Instance = TIM7;
 
-	/* Initialize TIM3 peripheral as follows:
-	 + Period = 10000 - 1
-	 + Prescaler = ((SystemCoreClock/2)/10000) - 1
-	 + ClockDivision = 0
-	 + Counter direction = Up
-	 */
-	TimDemoHandle.Init.Period = 1000 - 1;
-	TimDemoHandle.Init.Prescaler = uwPrescalerValue;
-	TimDemoHandle.Init.ClockDivision = 0;
-	TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
-	if(HAL_TIM_Base_Init(&TimDemoHandle) != HAL_OK)
-	{
-		/* Initialization Error */
-		Error_Handler();
-	}
+    /* Initialize TIM3 peripheral as follows:
+             + Period = 10000 - 1
+             + Prescaler = ((SystemCoreClock/2)/10000) - 1
+             + ClockDivision = 0
+             + Counter direction = Up
+    */
+    TimDemoHandle.Init.Period = 1000 - 1;
+    TimDemoHandle.Init.Prescaler = uwPrescalerValue;
+    TimDemoHandle.Init.ClockDivision = 0;
+    TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
+    if(HAL_TIM_Base_Init(&TimDemoHandle) != HAL_OK)
+    {
+        /* Initialization Error */
+        Error_Handler();
+    }
 
-	/*##-2- Start the TIM Base generation in interrupt mode ####################*/
-	/* Start Channel1 */
-	if(HAL_TIM_Base_Start_IT(&TimDemoHandle) != HAL_OK)
-	{
-		/* Starting Error */
-		Error_Handler();
-	}
+    /*##-2- Start the TIM Base generation in interrupt mode ####################*/
+    /* Start Channel1 */
+    if(HAL_TIM_Base_Start_IT(&TimDemoHandle) != HAL_OK)
+    {
+        /* Starting Error */
+        Error_Handler();
+    }
 }
 #endif
 
+
+
 #ifndef TIM_BACKLIGHT
 
 static uint32_t TIM_BACKLIGHT_adjust(void)
 {
-	return 0;
+    return 0;
 }
 
 static void TIM_BACKLIGHT_init(void)
 {
 }
 #else
-static uint32_t TIM_BACKLIGHT_adjust(void) {
-	static uint32_t levelActual = 12000;
-	static uint8_t brightnessModeLast = 0;
+static uint32_t TIM_BACKLIGHT_adjust(void)
+{
+    static uint32_t levelActual = 12000;
+    static uint8_t brightnessModeLast = 0;
 //	static _Bool wasLostConnection = 0;
 
-	uint32_t levelAmbient;
-	uint32_t levelMax;
-	uint32_t levelMin;
-	uint32_t levelUpStep_100ms = 200;
-	uint32_t levelDnStep_100ms = 20;
+    uint32_t levelAmbient;
+    uint32_t levelMax;
+    uint32_t levelMin;
+    uint32_t levelUpStep_100ms	= 200;
+    uint32_t levelDnStep_100ms	= 20;
 
-	TIM_OC_InitTypeDef sConfig;
-	sConfig.OCMode = TIM_OCMODE_PWM1;
-	sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
-	sConfig.OCFastMode = TIM_OCFAST_DISABLE;
+    TIM_OC_InitTypeDef sConfig;
+    sConfig.OCMode     = TIM_OCMODE_PWM1;
+    sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
+    sConfig.OCFastMode = TIM_OCFAST_DISABLE;
 
-	const SDiveState * pStateReal = stateRealGetPointer();
+    const SDiveState * pStateReal = stateRealGetPointer();
+
 
 //	if(pStateReal->data_old__lost_connection_to_slave)
 //	{
@@ -1127,562 +1211,582 @@
 //	}
 //	else
 //	{
-	SSettings *pSettings = settingsGetPointer();
-	/* 300 - 4000 */
-	/* important levelAmbient 300 - 1200 */
-	levelAmbient = 10 * pStateReal->lifeData.ambient_light_level;
+        SSettings *pSettings = settingsGetPointer();
+        /* 300 - 4000 */
+        /* important levelAmbient 300 - 1200 */
+        levelAmbient = 10 * pStateReal->lifeData.ambient_light_level;
 
-	switch (pSettings->brightness) {
-	case 0: /* Cave */
-		levelMax = 3000;/* max 25 % (x2) */
-		levelMin = 1500;
-		break;
-	case 1: /* Eco */
-		levelMax = 6000;/* max 50 % (x2) */
-		levelMin = 3000;
-		break;
-	case 2: /* Std */
-		levelAmbient += 1000;
-		levelMax = 9000;
-		levelMin = 4500;
-		levelUpStep_100ms += levelUpStep_100ms / 2; // 4500 instead of 3000
-		levelDnStep_100ms += levelDnStep_100ms / 2;
-		break;
-	case 3: /* High */
-	default:
-		levelAmbient += 3000;
-		levelMax = 12000; /* max 100% (x2) */
-		levelMin = 6000;
-		levelUpStep_100ms += levelUpStep_100ms; // 6000 instead of 3000
-		levelDnStep_100ms += levelDnStep_100ms;
-		break;
-	case 4: /* New Max */
-		levelAmbient = 12000;
-		levelMax = 12000; /* max 100% (x2) */
-		levelMin = 12000;
-		levelUpStep_100ms += 12000;
-		levelDnStep_100ms += 0;
-		break;
-	}
+        switch(	pSettings->brightness)
+        {
+        case 0: /* Cave */
+            levelMax = 3000;/* max 25 % (x2) */
+            levelMin = 1500;
+            break;
+        case 1: /* Eco */
+            levelMax = 6000;/* max 50 % (x2) */
+            levelMin = 3000;
+            break;
+        case 2: /* Std */
+            levelAmbient += 1000;
+            levelMax = 9000;
+            levelMin = 4500;
+            levelUpStep_100ms += levelUpStep_100ms/2; // 4500 instead of 3000
+            levelDnStep_100ms += levelDnStep_100ms/2;
+            break;
+        case 3: /* High */
+        default:
+            levelAmbient += 3000;
+            levelMax = 12000; /* max 100% (x2) */
+            levelMin = 6000;
+            levelUpStep_100ms += levelUpStep_100ms; // 6000 instead of 3000
+            levelDnStep_100ms += levelDnStep_100ms;
+            break;
+        case 4: /* New Max */
+            levelAmbient = 12000;
+            levelMax = 12000; /* max 100% (x2) */
+            levelMin = 12000;
+            levelUpStep_100ms += 12000;
+            levelDnStep_100ms += 0;
+            break;
+        }
 
-	if ((pSettings->brightness != brightnessModeLast)) // || wasLostConnection)
-	{
-		levelActual = levelAmbient;
-		brightnessModeLast = pSettings->brightness;
+        if((pSettings->brightness != brightnessModeLast))// || wasLostConnection)
+        {
+            levelActual = levelAmbient;
+            brightnessModeLast = pSettings->brightness;
 //			wasLostConnection = 0;
-	}
+        }
 //	}
 
-	if (levelAmbient > levelActual)
-		levelActual += levelUpStep_100ms;
-	else if ((levelAmbient < levelActual) && (levelActual > levelMin)
-			&& (levelActual > levelDnStep_100ms))
-		levelActual -= levelDnStep_100ms;
+    if(levelAmbient > levelActual)
+        levelActual += levelUpStep_100ms;
+    else
+    if((levelAmbient < levelActual) && (levelActual > levelMin) && (levelActual > levelDnStep_100ms))
+        levelActual -= levelDnStep_100ms;
 
-	if (levelActual > levelMax)
-		levelActual = levelMax;
-	else if (levelActual < levelMin)
-		levelActual = levelMin;
+    if(levelActual > levelMax)
+        levelActual = levelMax;
+    else
+    if(levelActual < levelMin)
+        levelActual = levelMin;
 
 //	sConfig.Pulse = levelActual / 20;
-	sConfig.Pulse = (levelMin + ((levelMax - levelMin) / 2)) / 20; // added 170306
+    sConfig.Pulse = (levelMin + ((levelMax - levelMin)/2)) / 20; // added 170306
 
-	/* xx - 600 */
-	if (sConfig.Pulse > 600)
-		sConfig.Pulse = 600;
-	else if (sConfig.Pulse < 100)
-		sConfig.Pulse = 100;
+    /* xx - 600 */
+    if(sConfig.Pulse > 600)
+        sConfig.Pulse = 600;
+    else
+    if(sConfig.Pulse < 100)
+        sConfig.Pulse = 100;
 
-	HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig,
-			TIM_BACKLIGHT_CHANNEL);
-	HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
+    HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
+    HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
 
-	return levelActual;
+    return levelActual;
 }
 
-static void TIM_BACKLIGHT_init(void) {
-	uint32_t uwPrescalerValue = 0;
-	TIM_OC_InitTypeDef sConfig;
+static void TIM_BACKLIGHT_init(void)
+{
+    uint32_t uwPrescalerValue = 0;
+    TIM_OC_InitTypeDef sConfig;
 
-	uwPrescalerValue = (uint32_t) ((SystemCoreClock / 2) / 18000000) - 1;
+    uwPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 18000000) - 1;
 
-	TimBacklightHandle.Instance = TIM_BACKLIGHT;
+    TimBacklightHandle.Instance = TIM_BACKLIGHT;
 
-	/* Initialize TIM3 peripheral as follows:
-	 30 kHz
-	 */
-	TimBacklightHandle.Init.Period = 600 - 1;
-	TimBacklightHandle.Init.Prescaler = uwPrescalerValue;
-	TimBacklightHandle.Init.ClockDivision = 0;
-	TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
-	HAL_TIM_PWM_Init(&TimBacklightHandle);
+    /* Initialize TIM3 peripheral as follows:
+        30 kHz
+    */
+    TimBacklightHandle.Init.Period = 600 - 1;
+    TimBacklightHandle.Init.Prescaler = uwPrescalerValue;
+    TimBacklightHandle.Init.ClockDivision = 0;
+    TimBacklightHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
+    HAL_TIM_PWM_Init(&TimBacklightHandle);
 
-	sConfig.OCMode = TIM_OCMODE_PWM1;
-	sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
-	sConfig.OCFastMode = TIM_OCFAST_DISABLE;
-	sConfig.Pulse = 50 * 6;
+    sConfig.OCMode     = TIM_OCMODE_PWM1;
+    sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
+    sConfig.OCFastMode = TIM_OCFAST_DISABLE;
+    sConfig.Pulse = 50 * 6;
 
-	HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig,
-			TIM_BACKLIGHT_CHANNEL);
-	HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
+    HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
+    HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
 }
 #endif
 
-static void EXTILine_Buttons_Config(void) {
-	GPIO_InitTypeDef GPIO_InitStructure;
+
+static void EXTILine_Buttons_Config(void)
+{
+    GPIO_InitTypeDef   GPIO_InitStructure;
 
-	BUTTON_ENTER_GPIO_ENABLE();
-	BUTTON_NEXT_GPIO_ENABLE();
-	BUTTON_BACK_GPIO_ENABLE();
+    BUTTON_ENTER_GPIO_ENABLE();
+    BUTTON_NEXT_GPIO_ENABLE();
+    BUTTON_BACK_GPIO_ENABLE();
 
-	/* Configure pin as weak PULLUP input  */
-	/* buttons */
-	GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
-	GPIO_InitStructure.Pull = GPIO_NOPULL;
-	GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
+    /* Configure pin as weak PULLUP input  */
+    /* buttons */
+    GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
+    GPIO_InitStructure.Pull = GPIO_NOPULL;
+    GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
 
-	GPIO_InitStructure.Pin = BUTTON_ENTER_PIN;
-	HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure);
+    GPIO_InitStructure.Pin = BUTTON_ENTER_PIN;
+    HAL_GPIO_Init(BUTTON_ENTER_GPIO_PORT, &GPIO_InitStructure);
 
-	GPIO_InitStructure.Pin = BUTTON_NEXT_PIN;
-	HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure);
+    GPIO_InitStructure.Pin = BUTTON_NEXT_PIN;
+    HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStructure);
 
-	GPIO_InitStructure.Pin = BUTTON_BACK_PIN;
-	HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure);
+    GPIO_InitStructure.Pin = BUTTON_BACK_PIN;
+    HAL_GPIO_Init(BUTTON_BACK_GPIO_PORT, &GPIO_InitStructure);
 
-	/* Enable and set EXTI Line0 Interrupt to the lowest priority */
-	HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0);
-	HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn, 2, 0);
-	HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn, 2, 0);
-	HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn);
-	HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn);
-	HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn);
+    /* Enable and set EXTI Line0 Interrupt to the lowest priority */
+    HAL_NVIC_SetPriority(BUTTON_ENTER_EXTI_IRQn, 2, 0);
+    HAL_NVIC_SetPriority(BUTTON_NEXT_EXTI_IRQn,  2, 0);
+    HAL_NVIC_SetPriority(BUTTON_BACK_EXTI_IRQn,  2, 0);
+    HAL_NVIC_EnableIRQ(BUTTON_ENTER_EXTI_IRQn);
+    HAL_NVIC_EnableIRQ(BUTTON_NEXT_EXTI_IRQn);
+    HAL_NVIC_EnableIRQ(BUTTON_BACK_EXTI_IRQn);
 
 #ifdef BUTTON_CUSTOM_PIN
-	BUTTON_CUSTOM_GPIO_ENABLE();
-	GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN;
-	HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure);
-	HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn, 2, 0);
-	HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn);
+    BUTTON_CUSTOM_GPIO_ENABLE();
+    GPIO_InitStructure.Pin = BUTTON_CUSTOM_PIN;
+    HAL_GPIO_Init(BUTTON_CUSTOM_GPIO_PORT, &GPIO_InitStructure);
+    HAL_NVIC_SetPriority(BUTTON_CUSTOM_EXTI_IRQn,  2, 0);
+    HAL_NVIC_EnableIRQ(BUTTON_CUSTOM_EXTI_IRQn);
 #endif
 }
 
+
+/**
+    * @brief  System Clock Configuration
+    *         The system Clock is configured as follow :
+    *            System Clock source            = PLL (HSE)
+    *            SYSCLK(Hz)                     = 180000000
+    *            HCLK(Hz)                       = 180000000
+    *            AHB Prescaler                  = 1
+    *            APB1 Prescaler                 = 4
+    *            APB2 Prescaler                 = 2
+    *            HSE Frequency(Hz)              = 8000000
+    *            PLL_M                          = 8
+    *            PLL_N                          = 360
+    *            PLL_P                          = 2
+    *            PLL_Q                          = 7
+    *            VDD(V)                         = 3.3
+    *            Main regulator output voltage  = Scale1 mode
+    *            Flash Latency(WS)              = 5
+    *         The LTDC Clock is configured as follow :
+    *            PLLSAIN                        = 192
+    *            PLLSAIR                        = 4
+    *            PLLSAIDivR                     = 8
+    * @param  None
+    * @retval None
+    */
+static void SystemClock_Config(void)
+{
+
+    /* Enable Power Control clock */
+    __PWR_CLK_ENABLE();
+
+    /* The voltage scaling allows optimizing the power consumption when the device is
+     clocked below the maximum system frequency, to update the voltage scaling value
+     regarding system frequency refer to product datasheet.  */
+    __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 );
+
+    /*##-1- System Clock Configuration #########################################*/
+    /* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */
+    RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
+#ifdef DISC1_BOARD
+    // Use High Speed Internal (HSI) oscillator, running at 16MHz.
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+    RCC_OscInitStruct.HSIState       = RCC_HSI_ON;
+    RCC_OscInitStruct.HSICalibrationValue = 0x10;
+    RCC_OscInitStruct.PLL.PLLSource  = RCC_PLLSOURCE_HSI;
+    RCC_OscInitStruct.PLL.PLLM       = 16;				// HSI/16 is 1Mhz.
+#else
+    // Use High Speed External oscillator, running at 8MHz
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+    RCC_OscInitStruct.HSEState       = RCC_HSE_ON;
+    RCC_OscInitStruct.PLL.PLLSource  = RCC_PLLSOURCE_HSE;
+    RCC_OscInitStruct.PLL.PLLM       = 8;               // HSE/8 is 1Mhz.
+#endif
+    // System clock = PLL (1MHz) * N/p = 180 MHz.
+    RCC_OscInitStruct.PLL.PLLN = 360;
+    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+    RCC_OscInitStruct.PLL.PLLQ = 7;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    HAL_RCC_OscConfig( &RCC_OscInitStruct );
+
+//  HAL_PWREx_ActivateOverDrive();
+    HAL_PWREx_DeactivateOverDrive();
+
+    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+    RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
+    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
+                                                            | RCC_CLOCKTYPE_PCLK1  | RCC_CLOCKTYPE_PCLK2;
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
+    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
+    HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_8 );	//FLASH_LATENCY_5);
+
+    /*##-2- LTDC Clock Configuration ###########################################*/
+    /* LCD clock configuration */
+    /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
+    /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
+    /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
+    /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */
+
+    /* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */
+    RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
+    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
+    PeriphClkInitStruct.PLLSAI.PLLSAIN = 300;				//192;
+    PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;				//4;
+    PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8
+    HAL_RCCEx_PeriphCLKConfig( &PeriphClkInitStruct );
+}
+
+
+/**
+    * @brief  This function is executed in case of error occurrence.
+    * @param  None
+    * @retval None
+    */
+static void Error_Handler(void)
+{
+    /* Turn LED3 on */
+//    BSP_LED_On(LED3);
+    while(1)
+    {
+    }
+}
+
 /**
- * @brief  System Clock Configuration
- *         The system Clock is configured as follow :
- *            System Clock source            = PLL (HSE)
- *            SYSCLK(Hz)                     = 180000000
- *            HCLK(Hz)                       = 180000000
- *            AHB Prescaler                  = 1
- *            APB1 Prescaler                 = 4
- *            APB2 Prescaler                 = 2
- *            HSE Frequency(Hz)              = 8000000
- *            PLL_M                          = 8
- *            PLL_N                          = 360
- *            PLL_P                          = 2
- *            PLL_Q                          = 7
- *            VDD(V)                         = 3.3
- *            Main regulator output voltage  = Scale1 mode
- *            Flash Latency(WS)              = 5
- *         The LTDC Clock is configured as follow :
- *            PLLSAIN                        = 192
- *            PLLSAIR                        = 4
- *            PLLSAIDivR                     = 8
- * @param  None
- * @retval None
- */
-static void SystemClock_Config(void) {
+    * @brief  Perform the SDRAM exernal memory inialization sequence
+    * @param  hsdram: SDRAM handle
+    * @param  Command: Pointer to SDRAM command structure
+    * @retval None
+    */
+static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command)
+{
+    __IO uint32_t tmpmrd =0;
+    /* Step 3:  Configure a clock configuration enable command */
+    Command->CommandMode 			 = FMC_SDRAM_CMD_CLK_ENABLE;
+    Command->CommandTarget 		 = FMC_SDRAM_CMD_TARGET_BANK2;
+    Command->AutoRefreshNumber 	 = 1;
+    Command->ModeRegisterDefinition = 0;
 
-	/* Enable Power Control clock */
-	__PWR_CLK_ENABLE();
+    /* Send the command */
+    HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
+
+    /* Step 4: Insert 100 ms delay */
+    HAL_Delay(100);
 
-	/* The voltage scaling allows optimizing the power consumption when the device is
-	 clocked below the maximum system frequency, to update the voltage scaling value
-	 regarding system frequency refer to product datasheet.  */
-	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+    /* Step 5: Configure a PALL (precharge all) command */
+    Command->CommandMode 			 = FMC_SDRAM_CMD_PALL;
+    Command->CommandTarget 	     = FMC_SDRAM_CMD_TARGET_BANK2;
+    Command->AutoRefreshNumber 	 = 1;
+    Command->ModeRegisterDefinition = 0;
+
+    /* Send the command */
+    HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
 
-	/*##-1- System Clock Configuration #########################################*/
-	/* Enable HighSpeed Oscillator and activate PLL with HSE/HSI as source */
-	RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
-#ifdef DISC1_BOARD
-	// Use High Speed Internal (HSI) oscillator, running at 16MHz.
-	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
-	RCC_OscInitStruct.HSIState = RCC_HSI_ON;
-	RCC_OscInitStruct.HSICalibrationValue = 0x10;
-	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
-	RCC_OscInitStruct.PLL.PLLM = 16;// HSI/16 is 1Mhz.
-#else
-	// Use High Speed External oscillator, running at 8MHz
-	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
-	RCC_OscInitStruct.HSEState = RCC_HSE_ON;
-	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-	RCC_OscInitStruct.PLL.PLLM = 8;               // HSE/8 is 1Mhz.
-#endif
-	// System clock = PLL (1MHz) * N/p = 180 MHz.
-	RCC_OscInitStruct.PLL.PLLN = 360;
-	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
-	RCC_OscInitStruct.PLL.PLLQ = 7;
-	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-	HAL_RCC_OscConfig(&RCC_OscInitStruct);
+    /* Step 6 : Configure a Auto-Refresh command */
+    Command->CommandMode 			 = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
+    Command->CommandTarget 		 = FMC_SDRAM_CMD_TARGET_BANK2;
+    Command->AutoRefreshNumber 	 = 4;
+    Command->ModeRegisterDefinition = 0;
+
+    /* Send the command */
+    HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
 
-//  HAL_PWREx_ActivateOverDrive();
-	HAL_PWREx_DeactivateOverDrive();
-
-	/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
-	RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
-	RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
-			| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
-	RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
-	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
-	HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);//FLASH_LATENCY_5);
+    /* Step 7: Program the external memory mode register */
+    tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2          |
+                                         SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL   |
+                                         SDRAM_MODEREG_CAS_LATENCY_3           |
+                                         SDRAM_MODEREG_OPERATING_MODE_STANDARD |
+                                         SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
 
-	/*##-2- LTDC Clock Configuration ###########################################*/
-	/* LCD clock configuration */
-	/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
-	/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
-	/* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
-	/* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */
+    Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
+    Command->CommandTarget 		 = FMC_SDRAM_CMD_TARGET_BANK2;
+    Command->AutoRefreshNumber 	 = 1;
+    Command->ModeRegisterDefinition = tmpmrd;
 
-	/* neu: 8MHz/8*300/5/8 = 7,5 MHz = 19,5 Hz bei 800 x 480 */
-	RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
-	PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
-	PeriphClkInitStruct.PLLSAI.PLLSAIN = 300;				//192;
-	PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;				//4;
-	PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;//RCC_PLLSAIDIVR_4;// RCC_PLLSAIDIVR_2; // RCC_PLLSAIDIVR_8
-	HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+    /* Send the command */
+    HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
+
+    /* Step 8: Set the refresh rate counter */
+    /* (15.62 us x Freq) - 20 */
+    /* neu: (8 us x Freq) - 20 */
+    /* Set the device refresh counter */
+    HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT);
 }
 
-/**
- * @brief  This function is executed in case of error occurrence.
- * @param  None
- * @retval None
- */
-static void Error_Handler(void) {
-	/* Turn LED3 on */
-//    BSP_LED_On(LED3);
-	while (1) {
-	}
-}
 
 /**
- * @brief  Perform the SDRAM exernal memory inialization sequence
- * @param  hsdram: SDRAM handle
- * @param  Command: Pointer to SDRAM command structure
- * @retval None
- */
-static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram,
-		FMC_SDRAM_CommandTypeDef *Command) {
-	__IO uint32_t tmpmrd = 0;
-	/* Step 3:  Configure a clock configuration enable command */
-	Command->CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
-	Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
-	Command->AutoRefreshNumber = 1;
-	Command->ModeRegisterDefinition = 0;
+******************************************************************************
+******************************************************************************
+******************************************************************************
+*/
+
 
-	/* Send the command */
-	HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
-
-	/* Step 4: Insert 100 ms delay */
-	HAL_Delay(100);
+/**
+    * @brief DMA2D configuration.
+    * @note  This function Configure tha DMA2D peripheral :
+    *        1) Configure the transfer mode : memory to memory W/ pixel format conversion
+    *        2) Configure the output color mode as ARGB4444
+    *        3) Configure the output memory address at SRAM memory
+    *        4) Configure the data size : 320x120 (pixels)
+    *        5) Configure the input color mode as ARGB8888
+    *        6) Configure the input memory address at FLASH memory
+    * @retval
+    *  None
+    */
 
-	/* Step 5: Configure a PALL (precharge all) command */
-	Command->CommandMode = FMC_SDRAM_CMD_PALL;
-	Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
-	Command->AutoRefreshNumber = 1;
-	Command->ModeRegisterDefinition = 0;
-
-	/* Send the command */
-	HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
+static void SDRAM_Config(void)
+{
+    /*##-1- Configure the SDRAM device #########################################*/
+    /* SDRAM device configuration */
+    hsdram.Instance = FMC_SDRAM_DEVICE;
 
-	/* Step 6 : Configure a Auto-Refresh command */
-	Command->CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
-	Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
-	Command->AutoRefreshNumber = 4;
-	Command->ModeRegisterDefinition = 0;
-
-	/* Send the command */
-	HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
+    /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */
+    /* TMRD: 2 Clock cycles */
+    SDRAM_Timing.LoadToActiveDelay    = 2;
+    /* TXSR: min=70ns (6x11.90ns) */
+    SDRAM_Timing.ExitSelfRefreshDelay = 7;
+    /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */
+    SDRAM_Timing.SelfRefreshTime      = 4;
+    /* TRC:  min=63 (6x11.90ns) */
+    SDRAM_Timing.RowCycleDelay        = 7;
+    /* TWR:  2 Clock cycles */
+    SDRAM_Timing.WriteRecoveryTime    = 2;
+    /* TRP:  15ns => 2x11.90ns */
+    SDRAM_Timing.RPDelay              = 2;
+    /* TRCD: 15ns => 2x11.90ns */
+    SDRAM_Timing.RCDDelay             = 2;
 
-	/* Step 7: Program the external memory mode register */
-	tmpmrd = (uint32_t) SDRAM_MODEREG_BURST_LENGTH_2 |
-	SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
-	SDRAM_MODEREG_CAS_LATENCY_3 |
-	SDRAM_MODEREG_OPERATING_MODE_STANDARD |
-	SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
+    hsdram.Init.SDBank             = FMC_SDRAM_BANK2;
+    hsdram.Init.ColumnBitsNumber   = FMC_SDRAM_COLUMN_BITS_NUM_9;
+    hsdram.Init.RowBitsNumber      = FMC_SDRAM_ROW_BITS_NUM_13;
+    hsdram.Init.MemoryDataWidth    = SDRAM_MEMORY_WIDTH;
+    hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
+    hsdram.Init.CASLatency         = FMC_SDRAM_CAS_LATENCY_3;
+    hsdram.Init.WriteProtection    = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
+    hsdram.Init.SDClockPeriod      = SDCLOCK_PERIOD;
+    hsdram.Init.ReadBurst          = FMC_SDRAM_RBURST_DISABLE;
+    hsdram.Init.ReadPipeDelay      = FMC_SDRAM_RPIPE_DELAY_1;
 
-	Command->CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
-	Command->CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2;
-	Command->AutoRefreshNumber = 1;
-	Command->ModeRegisterDefinition = tmpmrd;
+    /* Initialize the SDRAM controller */
+    if(HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK)
+    {
+        /* Initialization Error */
+        Error_Handler();
+    }
 
-	/* Send the command */
-	HAL_SDRAM_SendCommand(hsdram, Command, 0x1000);
-
-	/* Step 8: Set the refresh rate counter */
-	/* (15.62 us x Freq) - 20 */
-	/* neu: (8 us x Freq) - 20 */
-	/* Set the device refresh counter */
-	HAL_SDRAM_ProgramRefreshRate(hsdram, REFRESH_COUNT);
+    /* Program the SDRAM external device */
+    SDRAM_Initialization_Sequence(&hsdram, &command);
 }
 
-/**
- ******************************************************************************
- ******************************************************************************
- ******************************************************************************
- */
-
-/**
- * @brief DMA2D configuration.
- * @note  This function Configure tha DMA2D peripheral :
- *        1) Configure the transfer mode : memory to memory W/ pixel format conversion
- *        2) Configure the output color mode as ARGB4444
- *        3) Configure the output memory address at SRAM memory
- *        4) Configure the data size : 320x120 (pixels)
- *        5) Configure the input color mode as ARGB8888
- *        6) Configure the input memory address at FLASH memory
- * @retval
- *  None
- */
-
-static void SDRAM_Config(void) {
-	/*##-1- Configure the SDRAM device #########################################*/
-	/* SDRAM device configuration */
-	hsdram.Instance = FMC_SDRAM_DEVICE;
-
-	/* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */
-	/* TMRD: 2 Clock cycles */
-	SDRAM_Timing.LoadToActiveDelay = 2;
-	/* TXSR: min=70ns (6x11.90ns) */
-	SDRAM_Timing.ExitSelfRefreshDelay = 7;
-	/* TRAS: min=42ns (4x11.90ns) max=120k (ns) */
-	SDRAM_Timing.SelfRefreshTime = 4;
-	/* TRC:  min=63 (6x11.90ns) */
-	SDRAM_Timing.RowCycleDelay = 7;
-	/* TWR:  2 Clock cycles */
-	SDRAM_Timing.WriteRecoveryTime = 2;
-	/* TRP:  15ns => 2x11.90ns */
-	SDRAM_Timing.RPDelay = 2;
-	/* TRCD: 15ns => 2x11.90ns */
-	SDRAM_Timing.RCDDelay = 2;
-
-	hsdram.Init.SDBank = FMC_SDRAM_BANK2;
-	hsdram.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9;
-	hsdram.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13;
-	hsdram.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH;
-	hsdram.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
-	hsdram.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
-	hsdram.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
-	hsdram.Init.SDClockPeriod = SDCLOCK_PERIOD;
-	hsdram.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
-	hsdram.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
-
-	/* Initialize the SDRAM controller */
-	if (HAL_SDRAM_Init(&hsdram, &SDRAM_Timing) != HAL_OK) {
-		/* Initialization Error */
-		Error_Handler();
-	}
-
-	/* Program the SDRAM external device */
-	SDRAM_Initialization_Sequence(&hsdram, &command);
-}
 
 #ifdef  USE_FULL_ASSERT
 
 /**
- * @brief  Reports the name of the source file and the source line number
- *         where the assert_param error has occurred.
- * @param  file: pointer to the source file name
- * @param  line: assert_param error line source number
- * @retval None
- */
+    * @brief  Reports the name of the source file and the source line number
+    *         where the assert_param error has occurred.
+    * @param  file: pointer to the source file name
+    * @param  line: assert_param error line source number
+    * @retval None
+    */
 void assert_failed(uint8_t* file, uint32_t line)
 {
-	/* User can add his own implementation to report the file name and line number,
-	 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+    /* User can add his own implementation to report the file name and line number,
+         ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
-	/* Infinite loop */
-	while (1)
-	{
-	}
+    /* Infinite loop */
+    while (1)
+    {
+    }
 }
 #endif
 
-void deco_loop(void) {
-	typedef enum {
-		CALC_VPM, CALC_VPM_FUTURE, CALC_BUEHLMANN, CALC_BUEHLMANN_FUTURE,
-	} CALC_WHAT;
 
-	static int what = -1;
-	int counter = 0;
-	if ((stateUsed->mode != MODE_DIVE)
-			|| (stateUsed->diveSettings.diveMode == DIVEMODE_Apnea)
-			|| (decoLock != DECO_CALC_ready))
-		return;
-
-	decoLock = DECO_CALC_running;
+void deco_loop(void)
+{
+    typedef enum
+    {
+        CALC_VPM,
+        CALC_VPM_FUTURE,
+        CALC_BUEHLMANN,
+        CALC_BUEHLMANN_FUTURE,
+    } CALC_WHAT;
 
-	if (stateDeco.diveSettings.deco_type.ub.standard == GF_MODE) {
-// hw 151110 mh wants future TTS even in deco zone     if((what == CALC_BUEHLMANN) && (stateDeco.lifeData.pressure_ambient_bar > stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero))
-		if (what == CALC_BUEHLMANN) {
-			//Calc future
-			what = CALC_BUEHLMANN_FUTURE;
-		} else
-			what = CALC_BUEHLMANN;
+    static int what = -1;
+    int counter = 0;
+    if((stateUsed->mode != MODE_DIVE) || (stateUsed->diveSettings.diveMode == DIVEMODE_Apnea) || (decoLock != DECO_CALC_ready ))
+        return;
+
+    decoLock = DECO_CALC_running;
 
-	} else {
-// hw 151110 mh wants future TTS even in deco zone           if((what == CALC_VPM) && (!stateDeco.vpm.deco_zone_reached))
-		if (what == CALC_VPM) {
-			//Calc future
-			what = CALC_VPM_FUTURE;
-		} else
-			what = CALC_VPM;
-	}
+    if(stateDeco.diveSettings.deco_type.ub.standard == GF_MODE)
+    {
+// hw 151110 mh wants future TTS even in deco zone     if((what == CALC_BUEHLMANN) && (stateDeco.lifeData.pressure_ambient_bar > stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero))
+        if(what == CALC_BUEHLMANN)
+        {
+            //Calc future
+            what = CALC_BUEHLMANN_FUTURE;
+        }
+        else
+            what = CALC_BUEHLMANN;
 
-	//In one of ten calc the other option
-	if (counter == 10) {
-		if (what == CALC_VPM)
-			what = CALC_BUEHLMANN;
-		if (what == CALC_BUEHLMANN)
-			what = CALC_VPM;
-		counter = 0;
-	}
+    }
+    else
+    {
+// hw 151110 mh wants future TTS even in deco zone           if((what == CALC_VPM) && (!stateDeco.vpm.deco_zone_reached))
+        if(what == CALC_VPM)
+        {
+            //Calc future
+            what = CALC_VPM_FUTURE;
+        }
+        else
+            what = CALC_VPM;
+    }
 
-	decom_CreateGasChangeList(&stateDeco.diveSettings, &stateDeco.lifeData);
+    //In one of ten calc the other option
+    if(counter == 10)
+    {
+        if(what == CALC_VPM)
+             what = CALC_BUEHLMANN;
+        if(what == CALC_BUEHLMANN)
+                what = CALC_VPM;
+        counter = 0;
+    }
+
+    decom_CreateGasChangeList(&stateDeco.diveSettings, &stateDeco.lifeData);
 
-	switch (what) {
-	case CALC_VPM:
-		vpm_calc(&stateDeco.lifeData, &stateDeco.diveSettings, &stateDeco.vpm,
-				&stateDeco.decolistVPM, DECOSTOPS);
-		decoLock = DECO_CALC_FINSHED_vpm;
-		return;
-	case CALC_VPM_FUTURE:
-		decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,
-				&stateDeco.lifeData);
-		vpm_calc(&stateDeco.lifeData, &stateDeco.diveSettings, &stateDeco.vpm,
-				&stateDeco.decolistFutureVPM, FUTURESTOPS);
-		decoLock = DECO_CALC_FINSHED_Futurevpm;
-		return;
-	case CALC_BUEHLMANN:
-		buehlmann_calc_deco(&stateDeco.lifeData, &stateDeco.diveSettings,
-				&stateDeco.decolistBuehlmann);
-		buehlmann_ceiling_calculator(&stateDeco.lifeData,
-				&stateDeco.diveSettings, &stateDeco.decolistBuehlmann);
-		buehlmann_relative_gradient_calculator(&stateDeco.lifeData,
-				&stateDeco.diveSettings, &stateDeco.decolistBuehlmann);
-		decoLock = DECO_CALC_FINSHED_Buehlmann;
-		return;
-	case CALC_BUEHLMANN_FUTURE:
-		decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,
-				&stateDeco.lifeData);
-		buehlmann_calc_deco(&stateDeco.lifeData, &stateDeco.diveSettings,
-				&stateDeco.decolistFutureBuehlmann);
-		//buehlmann_ceiling_calculator(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistBuehlmann);
-		decoLock = DECO_CALC_FINSHED_FutureBuehlmann;
-		return;
-	}
-	counter++;
+    switch(what)
+    {
+    case CALC_VPM:
+            vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistVPM, DECOSTOPS);
+            decoLock = DECO_CALC_FINSHED_vpm;
+            return;
+     case CALC_VPM_FUTURE:
+            decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,&stateDeco.lifeData);
+            vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistFutureVPM, FUTURESTOPS);
+            decoLock = DECO_CALC_FINSHED_Futurevpm;
+            return;
+    case CALC_BUEHLMANN:
+            buehlmann_calc_deco(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistBuehlmann);
+            buehlmann_ceiling_calculator(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistBuehlmann);
+            buehlmann_relative_gradient_calculator(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistBuehlmann);
+            decoLock = DECO_CALC_FINSHED_Buehlmann;
+            return;
+     case CALC_BUEHLMANN_FUTURE:
+            decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,&stateDeco.lifeData);
+            buehlmann_calc_deco(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistFutureBuehlmann);
+            //buehlmann_ceiling_calculator(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.decolistBuehlmann);
+            decoLock = DECO_CALC_FINSHED_FutureBuehlmann;
+            return;
+    }
+    counter++;
 }
 
-void resetToFirmwareUpdate(void) {
-	__HAL_RCC_CLEAR_RESET_FLAGS();
-	HAL_NVIC_SystemReset();
+void resetToFirmwareUpdate(void)
+{
+    __HAL_RCC_CLEAR_RESET_FLAGS();
+    HAL_NVIC_SystemReset();
 }
 
 // debugging by https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/
 
 /*
- void printErrorMsg(const char * errMsg)
- {
+void printErrorMsg(const char * errMsg)
+{
 
- //	printf(errMsg);
- //	return;
+//	printf(errMsg);
+//	return;
 
- while(*errMsg != 0){
- ITM_SendChar(*errMsg);
- ++errMsg;
- }
- }
+     while(*errMsg != 0){
+            ITM_SendChar(*errMsg);
+            ++errMsg;
+     }
+}
 
- enum { r0, r1, r2, r3, r12, lr, pc, psr};
+enum { r0, r1, r2, r3, r12, lr, pc, psr};
 
- void stackDump(uint32_t stack[])
- {
- static char msg[80];
- sprintf(msg, "r0  = 0x%08x\n", stack[r0]);  printErrorMsg(msg);
- sprintf(msg, "r1  = 0x%08x\n", stack[r1]);  printErrorMsg(msg);
- sprintf(msg, "r2  = 0x%08x\n", stack[r2]);  printErrorMsg(msg);
- sprintf(msg, "r3  = 0x%08x\n", stack[r3]);  printErrorMsg(msg);
- sprintf(msg, "r12 = 0x%08x\n", stack[r12]); printErrorMsg(msg);
- sprintf(msg, "lr  = 0x%08x\n", stack[lr]);  printErrorMsg(msg);
- sprintf(msg, "pc  = 0x%08x\n", stack[pc]);  printErrorMsg(msg);
- sprintf(msg, "psr = 0x%08x\n", stack[psr]); printErrorMsg(msg);
- }
+void stackDump(uint32_t stack[])
+{
+     static char msg[80];
+     sprintf(msg, "r0  = 0x%08x\n", stack[r0]);  printErrorMsg(msg);
+     sprintf(msg, "r1  = 0x%08x\n", stack[r1]);  printErrorMsg(msg);
+     sprintf(msg, "r2  = 0x%08x\n", stack[r2]);  printErrorMsg(msg);
+     sprintf(msg, "r3  = 0x%08x\n", stack[r3]);  printErrorMsg(msg);
+     sprintf(msg, "r12 = 0x%08x\n", stack[r12]); printErrorMsg(msg);
+     sprintf(msg, "lr  = 0x%08x\n", stack[lr]);  printErrorMsg(msg);
+     sprintf(msg, "pc  = 0x%08x\n", stack[pc]);  printErrorMsg(msg);
+     sprintf(msg, "psr = 0x%08x\n", stack[psr]); printErrorMsg(msg);
+}
 
- void printUsageErrorMsg(uint32_t CFSRValue)
- {
- printErrorMsg("Usage fault: ");
- CFSRValue >>= 16;                  // right shift to lsb
- if((CFSRValue & (1 << 9)) != 0) {
- printErrorMsg("Divide by zero\n");
- }
- }
+void printUsageErrorMsg(uint32_t CFSRValue)
+{
+     printErrorMsg("Usage fault: ");
+     CFSRValue >>= 16;                  // right shift to lsb
+     if((CFSRValue & (1 << 9)) != 0) {
+            printErrorMsg("Divide by zero\n");
+     }
+}
 
- void Hard_Fault_Handler()//uint32_t stack[])
- {
- static char msg[80];
- printErrorMsg("In Hard Fault Handler\n");
- sprintf(msg, "SCB->HFSR = 0x%08x\n", SCB->HFSR);
- printErrorMsg(msg);
- if ((SCB->HFSR & (1 << 30)) != 0) {
- printErrorMsg("Forced Hard Fault\n");
- sprintf(msg, "SCB->CFSR = 0x%08x\n", SCB->CFSR );
- printErrorMsg(msg);
- if((SCB->CFSR & 0xFFFF0000) != 0) {
- printUsageErrorMsg(SCB->CFSR);
- }
- }
- __ASM volatile("BKPT #01");
- while(1);
- }
+void Hard_Fault_Handler()//uint32_t stack[])
+    {
+     static char msg[80];
+     printErrorMsg("In Hard Fault Handler\n");
+     sprintf(msg, "SCB->HFSR = 0x%08x\n", SCB->HFSR);
+     printErrorMsg(msg);
+     if ((SCB->HFSR & (1 << 30)) != 0) {
+             printErrorMsg("Forced Hard Fault\n");
+             sprintf(msg, "SCB->CFSR = 0x%08x\n", SCB->CFSR );
+             printErrorMsg(msg);
+             if((SCB->CFSR & 0xFFFF0000) != 0) {
+                 printUsageErrorMsg(SCB->CFSR);
+            }
+     }
+     __ASM volatile("BKPT #01");
+     while(1);
+}
 
- int my_store_of_MSP;
+int my_store_of_MSP;
 
- void HardFault_Handler(void)
- {
- __asm ("MRS my_store_of_MSP, MSP");
- Hard_Fault_Handler();
- }
- */
+void HardFault_Handler(void)
+{
+    __asm ("MRS my_store_of_MSP, MSP");
+    Hard_Fault_Handler();
+}
+*/
 
 /*
- __asm void HardFault_Handler(void)
- {
- TST lr, #4     // Test for MSP or PSP
- ITE EQ
- MRSEQ r0, MSP
- MRSNE r0, PSP
- B __cpp(Hard_Fault_Handler)
- }
- */
+__asm void HardFault_Handler(void)
+{
+    TST lr, #4     // Test for MSP or PSP
+    ITE EQ
+    MRSEQ r0, MSP
+    MRSNE r0, PSP
+    B __cpp(Hard_Fault_Handler)
+}
+*/
 /*
- HardFault_Handler\
+HardFault_Handler\
     PROC
- EXPORT  HardFault_Handler
- B       .
- ENDP
- */
+    EXPORT  HardFault_Handler
+    B       .
+    ENDP
+*/
 
 /*
- __asm int f(int i)
- {
- ADD i, i, #1 // error
- }
+__asm int f(int i)
+{
+        ADD i, i, #1 // error
+}
 
- EXPORT HardFault_Handler
- HardFault_Handler FUNCTION
- MRS r0, MSP
- B __cpp(Hard_Fault_Handler)
- ENDFUNC
- */
+EXPORT HardFault_Handler
+HardFault_Handler FUNCTION
+    MRS r0, MSP
+    B __cpp(Hard_Fault_Handler)
+ENDFUNC
+*/
--- a/Discovery/Src/data_exchange_main.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/data_exchange_main.c	Thu Jan 03 19:59:36 2019 +0100
@@ -940,7 +940,15 @@
 	pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
 	pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
 
+
 	pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading;
+	if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */
+	{
+		pStateReal->lifeData.compass_heading -= 180.0;
+		if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0;
+	}
+
+
 	pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll;
 	pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch;
 
--- a/Discovery/Src/gfx_engine.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/gfx_engine.c	Thu Jan 03 19:59:36 2019 +0100
@@ -904,18 +904,33 @@
 
 static inline void gfx_brush(uint8_t thickness, GFX_DrawCfgScreen *hgfx, uint16_t x0, uint16_t y0, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint8_t offset = thickness/2;
-
-	pDestination = hgfx->FBStartAdress + 2*(x0 - offset)*hgfx->ImageHeight + 2*(y0-offset);
+	int16_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination = (uint16_t*)hgfx->FBStartAdress;
+		pDestination += (hgfx->ImageHeight * (hgfx->ImageWidth - x0 + offset)) + (480 - y0+offset);
+		stepdir = -1;
+	}
+	else
+	{
+		pDestination = (uint16_t*)hgfx->FBStartAdress;
+		pDestination += (x0 - offset)*hgfx->ImageHeight + (y0-offset);
+		stepdir = 1;
+	}
 	for(int x=thickness;x>0;x--)
 	{
 		for(int y=thickness;y>0;y--)
 		{
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination +=2;
+			pDestination += stepdir;
 		}
-		pDestination += 2*(hgfx->ImageHeight - thickness);
+		pDestination += stepdir * (hgfx->ImageHeight - thickness);
 	}
 }
 
@@ -968,35 +983,63 @@
 
 void GFX_draw_line(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
 	uint32_t j;
-
+	int16_t stepdir;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
+	/* horizontal line */
 	if(start.x == stop.x)
 	{
 		if(start.y > stop.y) gfx_flip(&start,&stop);
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += start.x * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
+
+		pDestination = (uint16_t*)hgfx->FBStartAdress;
+		if(pSettings->FlipDisplay)
+		{
+			pDestination += (800 - start.x) * hgfx->ImageHeight;
+			pDestination += (480 - start.y);
+			stepdir = -1;
+		}
+		else
+		{
+			pDestination += start.x * hgfx->ImageHeight;
+			pDestination += start.y;
+			stepdir = 1;
+		}
 		for (j = stop.y - start.y; j > 0; j--)
 		{
-			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination += 2;
+				*(__IO uint16_t*)pDestination = 0xFF00 + color;
+				pDestination += stepdir;
 		}
 	}
-	else
+	else /* vertical line ? */
 	if(start.y == stop.y)
 	{
 		if(start.x > stop.x) gfx_flip(&start,&stop);
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += start.x * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
+		pDestination = (uint16_t*)hgfx->FBStartAdress;
+
+		if(pSettings->FlipDisplay)
+		{
+			pDestination += (800 - start.x) * hgfx->ImageHeight;
+			pDestination += (480 - start.y);
+			stepdir = -1;
+		}
+		else
+		{
+			pDestination += start.x * hgfx->ImageHeight;
+			pDestination += start.y;
+			stepdir = 1;
+		}
+
 		for (j = stop.x - start.x; j > 0; j--)
 		{
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
-			pDestination += hgfx->ImageHeight * 2;
+			pDestination += stepdir * hgfx->ImageHeight;
 		}
 	}
-	else // diagonal
+	else /* diagonal */
 	{
 		int x0 = start.x;
 		int y0 = start.y;
@@ -1008,8 +1051,17 @@
 	 
 		for(;;)
 		{
-			pDestination = (uint32_t)hgfx->FBStartAdress;
-			pDestination += ((x0 * hgfx->ImageHeight) + y0) * 2;
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+
+			if(pSettings->FlipDisplay)
+			{
+				pDestination += (((800 - x0) * hgfx->ImageHeight) + (480 - y0));
+			}
+			else
+			{
+				pDestination += ((x0 * hgfx->ImageHeight) + y0);
+			}
+
 			*(__IO uint16_t*)pDestination = 0xFF00 + color;
 			if (x0==x1 && y0==y1) break;
 			e2 = err;
@@ -1022,7 +1074,53 @@
 
 void GFX_draw_image_monochrome(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image, uint8_t color)
 {
-	uint32_t pDestination;
+	uint16_t* pDestination;
+	uint32_t j;
+	point_t start, stop;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	start.x = window.left;
+	start.y = (hgfx->ImageHeight - image->height - window.top);
+	stop.y = start.y + image->height;
+	stop.x = start.x + image->width;
+	j = 0;
+
+	if(pSettings->FlipDisplay)
+	{
+		for(int xx = start.x; xx < stop.x; xx++)
+		{
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+			pDestination += (hgfx->ImageHeight - start.y) + (stop.x * hgfx->ImageHeight) ;
+			pDestination -= (xx - start.x) * hgfx->ImageHeight;
+
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination-- = (image->data[j++] << 8) + color;
+			}
+		}
+	}
+	else
+	{
+		for(int xx = start.x; xx < stop.x; xx++)
+		{
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+			pDestination += xx * hgfx->ImageHeight;
+			pDestination += start.y;
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination++ = (image->data[j++] << 8) + color;
+			}
+		}
+	}
+}
+	
+
+void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
+{
+	uint16_t* pDestination;
+
 	uint32_t j;
 	point_t start, stop;
 
@@ -1032,47 +1130,37 @@
 	stop.x = start.x + image->width;
 	j = 0;
 	
-	for(int xx = start.x; xx < stop.x; xx++)
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
 	{
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += xx * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
-		for(int yy = start.y; yy < stop.y; yy++)
+		for(int xx = start.x; xx < stop.x; xx++)
 		{
-			*(__IO uint8_t*)pDestination = color;
-			pDestination += 1;
-			*(__IO uint8_t*)pDestination = image->data[j++];
-			pDestination += 1;
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+			pDestination += (hgfx->ImageHeight - start.y) + (stop.x * hgfx->ImageHeight);
+			pDestination -= (xx - start.x) * hgfx->ImageHeight;
+
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+			//	*(__IO uint16_t*)pDestination-- = image->data[j++] << 8 | 0xFF;
+				*(__IO uint16_t*)pDestination-- = 0xFF << 8 | image->data[j++];
+			}
 		}
-	}	
-}
-	
-
-void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
-{
-	uint32_t pDestination;
-	uint32_t j;
-	point_t start, stop;
-
-	start.x = window.left;
-	start.y = (hgfx->ImageHeight - image->height - window.top);
-	stop.y = start.y + image->height;
-	stop.x = start.x + image->width;
-	j = 0;
-	
-	for(int xx = start.x; xx < stop.x; xx++)
+	}
+	else
 	{
-		pDestination = (uint32_t)hgfx->FBStartAdress;
-		pDestination += xx * hgfx->ImageHeight * 2;
-		pDestination += start.y * 2;
-		for(int yy = start.y; yy < stop.y; yy++)
+		for(int xx = start.x; xx < stop.x; xx++)
 		{
-			*(__IO uint8_t*)pDestination = image->data[j++];
-			pDestination += 1;
-			*(__IO uint8_t*)pDestination = 0xFF;
-			pDestination += 1;
+			pDestination = (uint16_t*)hgfx->FBStartAdress;
+			pDestination += xx * hgfx->ImageHeight;
+			pDestination += start.y;
+			for(int yy = start.y; yy < stop.y; yy++)
+			{
+				*(__IO uint16_t*)pDestination++ = 0xFF << 8 | image->data[j++];
+			}
 		}
-	}	
+	}
 }
 
 
@@ -1120,15 +1208,23 @@
 /* this is NOT fast nor optimized */
 void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color)
 {
-	uint32_t pDestination;
-	
-	pDestination = (uint32_t)hgfx->FBStartAdress;
-	pDestination += x * hgfx->ImageHeight * 2;
-	pDestination += y * 2;
-	
-	*(__IO uint8_t*)pDestination = color;
-	pDestination += 1;
-	*(__IO uint8_t*)pDestination = 0xFF;
+	uint16_t* pDestination;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	pDestination = (uint16_t*)hgfx->FBStartAdress;
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (800 - x) * hgfx->ImageHeight;
+		pDestination += (480 - y);
+	}
+	else
+	{
+		pDestination += x * hgfx->ImageHeight;
+		pDestination += y;
+	}
+	*(__IO uint16_t*)pDestination = 0xFF << 8 | color;
 }
 
 
@@ -1271,7 +1367,8 @@
 		{
             p1.x = window.left + (int)(i * deltaline + 0.5f);
             p2.x = p1.x ;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+            //GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
     if(vdeltaline > 0)
@@ -1282,7 +1379,8 @@
 		{
             p1.x = window.left + (int)(i * vdeltaline + 0.5f);
             p2.x = p1.x ;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+          //  GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
     if(hlines > 0)
@@ -1294,7 +1392,8 @@
 		{
             p1.y = 479 - window.top - (int)(i * deltaline + 0.5f);
             p2.y = p1.y;
-            GFX_draw_colorline(hgfx, p1,p2, color );
+           // GFX_draw_colorline(hgfx, p1,p2, color );
+            GFX_draw_line(hgfx, p1,p2, color );
 		}
     }
 }
@@ -1406,10 +1505,14 @@
 //  ===============================================================================
 
 
-void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const  SWindowGimpStyle *window, int16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax,  uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
+void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const  SWindowGimpStyle *window, const int16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax,  uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
 {
-  //uint32_t pDestination,pDestination_old,
-	uint32_t pDestination_tmp,pDestination_end, pDestination_start, pDestination_zero_veil;
+	uint16_t* pDestination_tmp;
+	uint16_t* pDestination_start;
+	uint16_t* pDestination_end;
+	uint16_t* pDestination_zero_veil;
+
+	SSettings* pSettings;
 
 	uint32_t max = 0;
 	int windowheight = -1;
@@ -1429,6 +1532,9 @@
 	uint8_t colorDataTemp;
 	uint8_t	colormask = 0;
 
+	pSettings = settingsGetPointer();
+	pDestination_zero_veil = 0;
+
 	if(dataMin > dataMax)
 	{
 		uint16_t dataFlip;
@@ -1441,7 +1547,8 @@
 		invert = 0;
 
 	colormask = color;
-	
+
+	pSettings = settingsGetPointer();
 		
 	if(window->bottom > 479)
 		return;
@@ -1522,15 +1629,32 @@
 		if(h_ulong > (window->bottom - window->top))
 			h_ulong = (window->bottom - window->top);
 
-		if(drawVeilUntil > 0)
+		if(!pSettings->FlipDisplay)
 		{
-				pDestination_zero_veil = hgfx->FBStartAdress + 2 * (  (479 - (drawVeilUntil - 2) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
+			if(drawVeilUntil > 0)
+			{
+					pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
+					pDestination_zero_veil += ((479 - (drawVeilUntil - 2) ) + ((w1 + window->left) * hgfx->ImageHeight) );
+			}
+			else if(drawVeilUntil < 0 )
+			{
+					pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
+					pDestination_zero_veil += ((479 + (drawVeilUntil)) + ((w1 + window->left) * hgfx->ImageHeight) );
+			}
 		}
-		else if(drawVeilUntil < 0 )
+		else
 		{
-				pDestination_zero_veil = hgfx->FBStartAdress + 2 * (  (479 + (drawVeilUntil) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
+			if(drawVeilUntil > 0)
+			{
+				pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
+				pDestination_zero_veil += (((drawVeilUntil) ) + ( (window->right - w1) * hgfx->ImageHeight) );
+							}
+			else if(drawVeilUntil < 0 )
+			{
+				pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
+				pDestination_zero_veil += 479 -  drawVeilUntil + ( (window->right - w1 -1) * hgfx->ImageHeight);
+			}
 		}
-
 		if(h_ulong + window->top > max)
 		{
 			max = h_ulong + window->top;
@@ -1543,29 +1667,65 @@
 			//output_mask[pointer] = true;
 			if(w1 > 0)
 			{
-				pDestination_start = hgfx->FBStartAdress +  (2 * ((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
-				pDestination_end = pDestination_start;
-				if(h_ulong >= h_ulong_old)
+				pDestination_start = (uint16_t*)hgfx->FBStartAdress;
+				if(!pSettings->FlipDisplay)
 				{
-					pDestination_start -= 2 * h_ulong_old;
-					pDestination_end -= 2 * h_ulong;
+					pDestination_start += (((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
 				}
 				else
 				{
-					pDestination_start -= 2 * h_ulong;
-					pDestination_end -= 2 * h_ulong_old;
+					pDestination_start += (((window->top) + ((window->right - w1) * hgfx->ImageHeight)));
 				}
+				pDestination_end = pDestination_start;
+
+				if(!pSettings->FlipDisplay)
+				{
+					if(h_ulong >= h_ulong_old)
+					{
+						pDestination_start -= h_ulong_old;
+						pDestination_end -= h_ulong;
+					}
+					else
+					{
+						pDestination_start -= h_ulong;
+						pDestination_end -= h_ulong_old;
+					}
+				}
+				else
+				{
+					if(h_ulong < h_ulong_old)
+					{
+						pDestination_start += h_ulong_old;
+						pDestination_end += h_ulong;
+					}
+					else
+					{
+						pDestination_start += h_ulong;
+						pDestination_end += h_ulong_old;
+					}
+				}
+
 				
 				// deco stops
 				if(drawVeilUntil < 0)
 				{
-					pDestination_tmp = pDestination_end;
-					while(pDestination_tmp <= pDestination_zero_veil)
+					if(!pSettings->FlipDisplay)
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp -= 1;
-											*(__IO uint8_t*)pDestination_tmp = 0x80;
-											pDestination_tmp += 3;
+						pDestination_tmp = pDestination_end;
+						while(pDestination_tmp <= pDestination_zero_veil)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x80 << 8) | colormask;
+							pDestination_tmp++;
+						}
+					}
+					else
+					{
+						pDestination_tmp = pDestination_zero_veil;
+						while(pDestination_tmp <=  pDestination_end)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x80 << 8) | colormask;
+							pDestination_tmp++;
+						}
 					}
 				}
 				else
@@ -1573,20 +1733,31 @@
 					// regular graph with veil underneath if requested
 					// von oben nach unten
 					// von grossen pDestination Werten zu kleinen pDestination Werten
-					pDestination_tmp = pDestination_start;
-					while(pDestination_tmp >= pDestination_end)
+					{
+						pDestination_tmp = pDestination_start;
+						while(pDestination_tmp >= pDestination_end)
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0xFF << 8) | colormask ;
+							pDestination_tmp--;
+						}
+					}
+
+					if(!pSettings->FlipDisplay)
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp += 1;
-											*(__IO uint8_t*)pDestination_tmp = 0xFF;
-											pDestination_tmp -= 3;
+						while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x20 << 8) | colormask ;
+							pDestination_tmp--;
+						}
 					}
-					while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
+					else
 					{
-							*(__IO uint8_t*)pDestination_tmp = colormask;
-											pDestination_tmp += 1;
-											*(__IO uint8_t*)pDestination_tmp = 0x20;
-											pDestination_tmp -= 3;
+						pDestination_tmp = pDestination_start;
+						while((drawVeilUntil > 0) && (pDestination_tmp <=  pDestination_zero_veil))
+						{
+							*(__IO uint16_t*)pDestination_tmp = (0x20 << 8) | colormask ;
+							pDestination_tmp++;
+						}
 					}
 				}
 			}
@@ -1671,11 +1842,13 @@
 
 void GFX_draw_box(GFX_DrawCfgScreen *hgfx, point_t LeftLow, point_t WidthHeight, uint8_t Style, uint8_t color)
 {
-	uint32_t pDestination, pStart;
+	uint16_t* pDestination;
+	uint16_t* pStart;
 	uint32_t j;
 	uint32_t lineWidth, lineHeight;
 	int x, y;
 	uint8_t intensity;
+	int stepdir;
 
 	typedef struct {
 			int x;
@@ -1701,66 +1874,85 @@
 		{4,3,110}
 	};
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	lineWidth = WidthHeight.x;
 	lineHeight = WidthHeight.y;
-
-	pStart = (uint32_t)hgfx->FBStartAdress;
-	pStart += LeftLow.x * hgfx->ImageHeight * 2;
-	pStart += LeftLow.y * 2;
+	pStart = (uint16_t*)hgfx->FBStartAdress;
+
+	if(!pSettings->FlipDisplay)
+	{
+		pStart += LeftLow.x * hgfx->ImageHeight;
+		pStart += LeftLow.y;
+		stepdir = 1;
+	}
+	else
+	{
+		pStart += (800 - LeftLow.x - 1) * hgfx->ImageHeight;
+		pStart += (480 - LeftLow.y);
+		stepdir = -1;
+	}
 
 	// Untere Linie
 	pDestination = pStart;
 	if(Style)
 	{
-		pDestination += 2 * 10 * hgfx->ImageHeight;
+		pDestination += stepdir * 10 * hgfx->ImageHeight;
 		lineWidth -= 18;
 	}
 	for (j = lineWidth; j > 0; j--)
 	{
+
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += hgfx->ImageHeight * 2;
+		pDestination += stepdir * hgfx->ImageHeight;
 	}
 
 	// Obere Linie
-	pDestination = pStart + 2 * WidthHeight.y;
+
+	pDestination = pStart + stepdir * WidthHeight.y;
 	if(Style)
 	{
-		pDestination += 2 * 10 * hgfx->ImageHeight;
+		pDestination += stepdir * 10 * hgfx->ImageHeight;
 	}
 
 	for (j = lineWidth; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += hgfx->ImageHeight * 2;
+		pDestination += stepdir * hgfx->ImageHeight;
 	}
 
 	// Linke Linie
 	pDestination = pStart;
+
 	if(Style)
 	{
-		pDestination += 2 * 10;
+		pDestination += stepdir * 10;
 		lineHeight -= 18;
 	}
 
 	for (j = lineHeight; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += 2;
+		pDestination += stepdir;
 	}
 
+
 	// Rechte Linie
-	pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
+
+	pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
 	if(Style)
 	{
-		pDestination += 2 * 10;
+		pDestination += stepdir * 10;
 	}
 
 	for (j = lineHeight; j > 0; j--)
 	{
 		*(__IO uint16_t*)pDestination = 0xFF00 + color;
-		pDestination += 2;
+		pDestination += stepdir;
 	}
 
+
 	// Ecken wenn notwendig == Style
 	if(Style)
 	{
@@ -1769,60 +1961,61 @@
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination  + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+
+    *(__IO uint16_t*)(pDestination  + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2	* (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir	* (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// links oben
-		pDestination = pStart + 2 * WidthHeight.y;
+		pDestination = pStart + stepdir * WidthHeight.y;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2 * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// rechts unten
-		pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
+		pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination + 2 * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 		// rechts oben
-		pDestination = pStart + 2 * WidthHeight.y + 2 * WidthHeight.x * hgfx->ImageHeight;
+		pDestination = pStart + stepdir * WidthHeight.y + stepdir * WidthHeight.x * hgfx->ImageHeight;
 		x = corner[0].x;
 		y = corner[0].y;
 		intensity = corner[0].intensity;
-    *(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+    *(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
 
 		for(j = 15; j > 0; j--)
 		{
 			x = corner[j].x;
 			y = corner[j].y;
 			intensity = corner[j].intensity;
-			*(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
-			*(__IO uint16_t*)(pDestination - 2 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
+			*(__IO uint16_t*)(pDestination + stepdir * -1 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
 		}
 	}
 }
@@ -1871,6 +2064,11 @@
 
     GFX_DrawCfgWindow	hgfx;
 
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
 	if(XrightGimpStyle > 799)
 		XrightGimpStyle = 799;
 	if(XleftGimpStyle >= XrightGimpStyle)
@@ -1881,14 +2079,27 @@
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX0 = XleftGimpStyle;
-	hgfx.WindowX1 = XrightGimpStyle;
-	hgfx.WindowY1 = 479 - YtopGimpStyle;
-	if(hgfx.WindowY1 < Font->height)
-		hgfx.WindowY0 = 0;
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
 	else
-		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+	{
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 + Font->height > 480)
+			hgfx.WindowY1 = 480;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+	}
 	GFX_write_label(Font, &hgfx, text, color);
 }
 
@@ -2374,8 +2585,7 @@
 	uint32_t i, j;
 	uint32_t width, height;
 	uint32_t found;
-	uint32_t pDestination;
-	uint32_t pDestinationColor;
+	uint16_t* pDestination;
 	uint32_t pSource;
 	uint32_t OffsetDestination;
 	uint32_t width_left;
@@ -2385,7 +2595,20 @@
 	uint8_t fill;
 	uint32_t widthFont, heightFont;
 	uint32_t nextLine;
-	
+	int32_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		stepdir = -1;	/* decrement address while putting pixels */
+	}
+	else
+	{
+		stepdir = 1;
+	}
+
 
 	if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
 		return 0x0000FFFF;
@@ -2404,23 +2627,32 @@
 		return cfg->Xdelta;
 
 	pSource = ((uint32_t)Font->chars[i].image->data);
-	pDestination = 1 + (uint32_t)hgfx->Image->FBStartAdress;
+	pDestination = (uint16_t*)(hgfx->Image->FBStartAdress+1);
 
 	heightFont = Font->chars[i].image->height;
 	widthFont = Font->chars[i].image->width;
 
 	height = heightFont*2;
 	width = widthFont*2;
-	
-	OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
-
-	pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
-	pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
-	nextLine = hgfx->Image->ImageHeight * 2;
+
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (uint32_t)(hgfx->WindowX1 - cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY1 - cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	else
+	{
+		pDestination += (uint32_t)(hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight;  /* set pointer to delta row */
+		pDestination += (hgfx->WindowY0 + cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	OffsetDestination = (hgfx->Image->ImageHeight - height);
+	nextLine = hgfx->Image->ImageHeight;
 
 // -----------------------------
 	char_truncated_WidthFlag = 0;
 	width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
+
 	if(width_left < width)
 	{
 		char_truncated_WidthFlag = 1;
@@ -2428,6 +2660,7 @@
 		widthFont = width/2;
 	}
 // -----------------------------
+
 	char_truncated_Height = 0;
 	height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
 	if(height_left < height)
@@ -2441,26 +2674,12 @@
 		height = height_left;
 		heightFont = height/2;
 	}
-	OffsetDestination += 2 * char_truncated_Height;
+
+	OffsetDestination += char_truncated_Height;
 // -----------------------------
 	if(height == 0)
 		return 0x0000FFFF;
 // -----------------------------
-	
-	if((cfg->color > 0) )
-	{
-		pDestinationColor = pDestination - 1;
-
-		for(i = width; i > 0; i--)
-		{
-			for (j = height; j > 0; j--)
-			{
-				*(__IO uint32_t*)pDestinationColor =  cfg->color;
-				pDestinationColor += 2;
-			}
-			pDestinationColor += OffsetDestination;
-		}
-	}
 
 	if(cfg->singleSpaceWithSizeOfNextChar)
 	{
@@ -2476,12 +2695,12 @@
 		{
 			for (j = height; j > 0; j--)
 			{
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
 			}
-			pDestination += OffsetDestination;
+			pDestination += stepdir * OffsetDestination;
 		}
 	}
 	else
@@ -2496,37 +2715,37 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2535,33 +2754,33 @@
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 |0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += (OffsetDestination + nextLine) * stepdir;
 			}
 		}
 		else
@@ -2573,21 +2792,21 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource);
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2596,24 +2815,24 @@
 					pSource++;
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						*(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						*(__IO uint16_t*)(pDestination + nextLine) =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += (OffsetDestination + nextLine) * stepdir;
 			}
 		}
-	}
+	} /* inverted */
 	else
 	{
 		if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
@@ -2625,46 +2844,46 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height;
+					pDestination +=  stepdir * height;
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += stepdir * (OffsetDestination + nextLine);
 			}
 		}
 		else
@@ -2676,30 +2895,30 @@
 				{
 					for (j = heightFont; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
-
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						*(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
+
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource;
+						*(__IO uint16_t*)(pDestination + (stepdir * nextLine)) =  cfg->color << 8 |  *(uint8_t*)pSource;
+						pDestination += stepdir;
 						pSource++;
-						pDestination += 2;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height;
+					pDestination +=  stepdir * height;
 				}
-				pDestination += OffsetDestination + nextLine;
+				pDestination += stepdir * (OffsetDestination + nextLine);
 			}
 		}
 	}
@@ -2747,8 +2966,7 @@
 	uint32_t i, j;
 	uint32_t width, height;
 	uint32_t found;
-	uint32_t pDestination;
-	uint32_t pDestinationColor;
+	uint16_t* pDestination;
 	uint32_t pSource;
 	uint32_t OffsetDestination;
 	uint32_t width_left;
@@ -2756,6 +2974,19 @@
 	uint32_t char_truncated_WidthFlag;
 	uint32_t char_truncated_Height;
 	uint8_t fill;
+	int16_t stepdir;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(pSettings->FlipDisplay)
+	{
+		stepdir = -1;	/* decrement address while putting pixels */
+	}
+	else
+	{
+		stepdir = 1;
+	}
 
 	if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
 		return 0x0000FFFF;
@@ -2784,16 +3015,28 @@
 
 
 	pSource = ((uint32_t)Font->chars[i].image->data);
-	pDestination = 1 + (uint32_t)hgfx->Image->FBStartAdress;
+	pDestination = (uint16_t*)(hgfx->Image->FBStartAdress + 1);
 
 	height = Font->chars[i].image->height;
 	width = Font->chars[i].image->width;
 
-	OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
-
-	pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
-	pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
-
+	OffsetDestination = hgfx->Image->ImageHeight - height;
+
+
+	/* Xyyyyy   y= height */
+	/* Xyyyyy   x= width  */
+	/* Xyyyyy             */
+
+	if(pSettings->FlipDisplay)
+	{
+		pDestination += (hgfx->WindowX1 - cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY1 - cfg->Ydelta);							   /* set pointer to delta colum */
+	}
+	else
+	{
+		pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
+		pDestination += (hgfx->WindowY0 + cfg->Ydelta);							   /* set pointer to delta colum */
+	}
 
 
 // -----------------------------
@@ -2817,27 +3060,12 @@
 		}
 		height = height_left;
 	}
-	OffsetDestination += 2 * char_truncated_Height;
+	OffsetDestination += char_truncated_Height;
 // -----------------------------
 	if(height == 0)
 		return 0x0000FFFF;
 // -----------------------------
 	
-	if((cfg->color > 0) )//&& (cfg->color < 6))
-	{
-		pDestinationColor = pDestination - 1;
-
-		for(i = width; i > 0; i--)
-		{
-			for (j = height; j > 0; j--)
-			{
-				*(__IO uint32_t*)pDestinationColor =  cfg->color;//ColorLUT[cfg->color - 1];
-				pDestinationColor += 2;
-			}
-			pDestinationColor += OffsetDestination;
-		}
-	}
-
 	if(cfg->singleSpaceWithSizeOfNextChar)
 	{
 		cfg->singleSpaceWithSizeOfNextChar = 0;
@@ -2852,12 +3080,12 @@
 		{
 			for (j = height; j > 0; j--)
 			{
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
-				*(__IO uint8_t*)pDestination = fill;
-				pDestination += 2;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
+				*(__IO uint16_t*)pDestination =  cfg->color << 8 | fill;
+				pDestination += stepdir;
 			}
-			pDestination += OffsetDestination;
+			pDestination += stepdir * OffsetDestination;
 		}
 	}
 	else
@@ -2870,39 +3098,36 @@
 			{
 				if(*(uint8_t*)pSource != 0x01)
 				{
+
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
-				else
+				else /* empty line => fast fill */
 				{
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 		else
@@ -2914,12 +3139,10 @@
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | (0xFF - *(uint8_t*)pSource++);
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
@@ -2928,50 +3151,49 @@
 					pSource++;
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = 0xFF;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 | 0xFF;
+						pDestination += stepdir;
 					}
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 	}
-	else
+	else  /* not inverted */
 	{
 		if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
 		{
+
 			height /= 4;
+
 			for(i = width; i > 0; i--)
 			{
 				if(*(uint8_t*)pSource != 0x01)
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
+							*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+							pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height * 4;
+					pDestination += stepdir * height * 4;
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
+
 		else
 		{
 			height /= 2;
@@ -2981,21 +3203,19 @@
 				{
 					for (j = height; j > 0; j--)
 					{
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
-						*(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
-						pSource++;
-						pDestination += 2;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+						pDestination += stepdir;
+						*(__IO uint16_t*)pDestination =  cfg->color << 8 |  *(uint8_t*)pSource++;
+						pDestination += stepdir;
 					}
 					pSource += char_truncated_Height;
 				}
 				else
 				{
 					pSource++;
-					pDestination +=  2 * height * 2;
+					pDestination += stepdir * height * 2;
 				}
-				pDestination += OffsetDestination;
+				pDestination += stepdir * OffsetDestination;
 			}
 		}
 	}
@@ -3831,24 +4051,43 @@
 {
 	GFX_DrawCfgWindow	hgfx;
 
-	if(XrightGimpStyle > 799)
-		XrightGimpStyle = 799;
-	if(XleftGimpStyle >= XrightGimpStyle)
-		XleftGimpStyle = 0;
-	if(YtopGimpStyle > 479)
-		YtopGimpStyle = 479;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(!pSettings->FlipDisplay)
+	{
+		if(XrightGimpStyle > 799)
+			XrightGimpStyle = 799;
+		if(XleftGimpStyle >= XrightGimpStyle)
+			XleftGimpStyle = 0;
+		if(YtopGimpStyle > 479)
+			YtopGimpStyle = 479;
+	}
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX0 = XleftGimpStyle;
-	hgfx.WindowX1 = XrightGimpStyle;
-	hgfx.WindowY1 = 479 - YtopGimpStyle;
-	if(hgfx.WindowY1 < Font->height)
-		hgfx.WindowY0 = 0;
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
 	else
-		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+	{
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 + Font->height >= 479)
+			hgfx.WindowY1 = 479;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+	}
 	GFX_write_string_color(Font, &hgfx, text, 0, color);
 }
 
@@ -3861,14 +4100,25 @@
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	hgfx.WindowTab = 0;
 	hgfx.WindowX0 = 20;
 	hgfx.WindowX1 = 779;
-	hgfx.WindowY1 = 479;
-	hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-	
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowY1 = 479;
+		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
+	else
+	{
+		hgfx.WindowY0 = 0;
+		hgfx.WindowY1 = Font->height;
+	}
 	GFX_write_label(Font, &hgfx, text, color);
-	
 }
 
 
@@ -3878,16 +4128,29 @@
 	const tFont *Font = &FontT48;
 	char text[7];
 	uint8_t i, secondDigitPage, secondDigitTotal;
-	
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 	hgfx.Image = tMscreen;
 	hgfx.WindowNumberOfTextLines = 1;
 	hgfx.WindowLineSpacing = 0;
 	hgfx.WindowTab = 0;
-	hgfx.WindowX1 = 779;
-	hgfx.WindowX0 = hgfx.WindowX1 - (25*5);
-	hgfx.WindowY1 = 479;
-	hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-	
+
+	if(!pSettings->FlipDisplay)
+	{
+		hgfx.WindowX1 = 779;
+		hgfx.WindowX0 = hgfx.WindowX1 - (25*5);
+		hgfx.WindowY1 = 479;
+		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+	}
+	else
+	{
+		hgfx.WindowX1 = 25*5;
+		hgfx.WindowX0 = 0;
+		hgfx.WindowY1 = Font->height;;
+		hgfx.WindowY0 = 0;
+	}
 	if(page > 99)
 		page = 99;
 	if(total > 99)
--- a/Discovery/Src/settings.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/settings.c	Thu Jan 03 19:59:36 2019 +0100
@@ -82,7 +82,7 @@
  * There might even be entries with fixed values that have no range
  */
 const SSettings SettingsStandard = {
-    .header = 0xFFFF0017,
+    .header = 0xFFFF0018,
     .warning_blink_dsec = 8 * 2,
     .lastDiveLogId = 0,
     .logFlashNextSampleStartAddress = 0,
@@ -305,6 +305,7 @@
     .FactoryButtonBalance[0] = 3,
     .FactoryButtonBalance[1] = 3,
     .FactoryButtonBalance[2] = 3,
+	.FlipDisplay = 0,
 };
 
 /* Private function prototypes -----------------------------------------------*/
@@ -442,6 +443,9 @@
         pSettings->FactoryButtonBalance[1]          = pStandard->FactoryButtonBalance[1];
         pSettings->FactoryButtonBalance[2]          = pStandard->FactoryButtonBalance[2];
         // no break
+    case 0xFFFF0017:
+    	pSettings->FlipDisplay = 0;
+    	// no break
     default:
         pSettings->header 																= pStandard->header;
         break; // no break before!!
@@ -1381,6 +1385,11 @@
         corrections++;
     }
 
+    if(Settings.FlipDisplay > 1) /* only boolean values allowed */
+   	{
+    	Settings.FlipDisplay = 0;
+	    corrections++;
+   	}
 
     if(corrections > 255)
         return 255;
--- a/Discovery/Src/show_logbook.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/show_logbook.c	Thu Jan 03 19:59:36 2019 +0100
@@ -149,18 +149,19 @@
     winsmal.right = wintemp.left -1;
     winsmal.bottom = winsmal.top + 16;
 
-    write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor1,"[m]");
-    winsmal.left = wintemp.left - 48;
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_GasSensor1,"[m]");
+
+ //   winsmal.left = wintemp.left - 48;
     char msg[3];
     float deltaline = ((float)(wintemp.bottom - wintemp.top))/5;
     for(int i = 1; i<=5; i++)
     {
-
         winsmal.top	= wintemp.top + deltaline * i - 14;
         winsmal.bottom = winsmal.top + 16;
-        winsmal.right = wintemp.left - 2;
+
+    //    winsmal.right = wintemp.left - 2;
         snprintf(msg,5,"%i",i * vstep);
-        write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor1,msg);
+        Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_GasSensor1,msg);
     }
 
     //vertical (Time) *******************************************************************
@@ -188,18 +189,17 @@
     winsmal.right = winsmal.left + 60;
     winsmal.bottom = winsmal.top + 16;
 
-
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_GasSensor1,"min");
     for(int i = 1; i<=lines; i++)
     {
         winsmal.left= wintemp.left + vdeltaline * i - 15;
         winsmal.right = winsmal.left + 30;
         snprintf(msg,5,"%3i",i * timestep);
-        write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor1,msg);
+        Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_GasSensor1,msg);
     }
     winsmal.left = wintemp.left;// - 9;
     winsmal.top	=  wintemp.top - 40;
     winsmal.right = winsmal.left + 60;
-    write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor1,"min");;
 
     //--- print depth graph ---
     //adapt window
@@ -238,21 +238,35 @@
             GFX_graph_print(hgfx,&wintemp,saveTop,1,0,datamax, decostopdata,dataLength, CLUT_NiceGreen, NULL);
     }
 
+    if(settingsGetPointer()->FlipDisplay)
+    {
+		winsmal.right = 800 - wintemp.left;
+		winsmal.left = 800 - wintemp.right;
+		winsmal.bottom = wintemp.bottom;
+		winsmal.top = wintemp.top;
+    }
+    else
+    {
+		winsmal.right = wintemp.right;
+		winsmal.left = wintemp.left;
+		winsmal.bottom = wintemp.bottom;
+		winsmal.top = wintemp.top;
+    }
+
     switch(mode)
     {
     case 0:
-        GFX_graph_print(hgfx,&wintemp,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor1, NULL);
+        GFX_graph_print(hgfx,&winsmal,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor1, NULL);
         break;
     case 1:
-        GFX_graph_print(hgfx,&wintemp,saveBottom,1,0,datamax, depthdata,dataLength,CLUT_GasSensor0,colordata);
+        GFX_graph_print(hgfx,&winsmal,saveBottom,1,0,datamax, depthdata,dataLength,CLUT_GasSensor0,colordata);
         break;
     case 2:
         if(*colordata)
-            GFX_graph_print(hgfx,&wintemp,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor0,colordata);
+            GFX_graph_print(hgfx,&winsmal,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor0,colordata);
         else
-            GFX_graph_print(hgfx,&wintemp,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor1, NULL);
+            GFX_graph_print(hgfx,&winsmal,0,1,0,datamax, depthdata,dataLength,CLUT_GasSensor1, NULL);
     }
-
 }
 
 
@@ -452,7 +466,9 @@
     uint8_t day =  logbookHeader.dateDay;
     char text[40];
     snprintf(text, 20, "20%02i-%02i-%02i", year, month, day);
-    Gfx_write_label_var(hgfx, 30, 150,10, &FontT42,CLUT_GasSensor1,text);
+
+    Gfx_write_label_var(hgfx, 30, 250,10, &FontT42,CLUT_GasSensor1,text);
+
 
     // Print logbook number with offset
     if(settingsGetPointer()->logbookOffset)
@@ -535,7 +551,7 @@
     winsmal.left = 30;
     winsmal.top = top -3;
     winsmal.bottom = winsmal.top + FontT42.height;
-    winsmal.right = winsmal.left + 50;
+
     if(maxdepth < 10)
     {
         winsmal.left  = 137;
@@ -548,7 +564,9 @@
     {
         winsmal.left  = 147;
     }
-    write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor4,"max");
+    winsmal.right = winsmal.left + 50;
+
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,top, &FontT24,CLUT_GasSensor4,"max");
     snprintf(text,3,"%c%c"
         , unit_depth_char1()
         , unit_depth_char2()
@@ -570,10 +588,12 @@
         snprintf(text,20,"%i.%i",avrdepth,avrdepth_dcm);
     }
     Gfx_write_label_var(hgfx, 30, 250,top, &FontT42,CLUT_GasSensor1,text);
+
     winsmal.left = 30;
     winsmal.top = top -3;
     winsmal.bottom = winsmal.top + FontT42.height;
-    winsmal.right = winsmal.left + 50;
+
+/* put avg behind previous string */
     if(avrdepth < 10)
     {
         winsmal.left  = 137                               ;
@@ -586,7 +606,9 @@
     {
         winsmal.left  = 147;
     }
-    write_label_(hgfx, winsmal,&FontT24,CLUT_GasSensor4,"avg");
+    winsmal.right = winsmal.left + 50;
+
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_GasSensor4,"avg");
     snprintf(text,3,"%c%c"
         , unit_depth_char1()
         , unit_depth_char2()
@@ -634,6 +656,7 @@
     wintemp.left 	= 330;
     wintemp.top	=  160;
     wintemp.bottom -= 40;
+
     show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL);
 }
 
@@ -682,8 +705,7 @@
     winsmal.right =  wintemp.right + 30;
     winsmal.bottom = winsmal.top + 16;
 
-    write_label_(hgfx, winsmal,&FontT24,CLUT_LogbookTemperature,"[C]");
-
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_LogbookTemperature,"[C]");
 
     int16_t minVal = 0;
     int16_t maxVal = 0;
@@ -715,7 +737,7 @@
             snprintf(msg,2,"%1i",tmp);
         else
             snprintf(msg,3,"%2i",tmp);
-        write_label_(hgfx, winsmal,&FontT24,CLUT_LogbookTemperature,msg);
+        Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_LogbookTemperature,msg);
     }
 
 
@@ -1017,7 +1039,7 @@
             print_gas_name(gas_name,15,logbookHeader.gasordil[i].oxygen_percentage,logbookHeader.gasordil[i].helium_percentage);
             snprintf(msg,15,"G%i: %s",i + 1, gas_name);
             //msg[10] = 0;
-            write_label_(hgfx, winsmal,&FontT24,color,msg);
+            Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,msg);
         }
     }
 
@@ -1089,7 +1111,7 @@
         winsmal.right =  winsmal.left + 55;
          color = CLUT_GasSensor1;//LOGBOOK_GRAPH_DEPTH;
 
-        write_label_(hgfx, winsmal,&FontT24,color,"depth");
+         Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"depth");
 
     }
     winsmal.left = 799 - 67;//wintemp.right -67;
@@ -1097,12 +1119,12 @@
 
     color = CLUT_LogbookTemperature;//LOGBOOK_GRAPH_DEPTH;
     if(logbookHeader.diveMode != DIVEMODE_CCR)
-        write_label_(hgfx, winsmal,&FontT24,color,"\002PP O2");
+    	Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002PP O2");
     else
     if(logbookHeader.CCRmode != CCRMODE_Sensors)
-        write_label_(hgfx, winsmal,&FontT24,color,"\002SETPOINT");
+    	Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SETPOINT");
     else
-        write_label_(hgfx, winsmal,&FontT24,color,"\002SENSORS");
+    	Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"\002SENSORS");
 
     //*** PP O2 ****************************************************
     //calc lines and labels
@@ -1142,7 +1164,7 @@
     //winsmal.font = ft_tiny + ft_SLIM;
     color = CLUT_LogbookTemperature;// = LOGBOOK_GRAPH_TEMP;
 
-    write_label_(hgfx, winsmal,&FontT24,color,"bar");
+    Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,"bar");
 
     int deltaline = (wintemp.bottom - wintemp.top)/5;
     char msg[4];
@@ -1155,7 +1177,7 @@
         winsmal.top	= wintemp.top + deltaline * i - 8;
         winsmal.bottom = winsmal.top + 16;
         snprintf(msg,4,"%1.1f",oxy);
-        write_label_(hgfx, winsmal,&FontT24,color,msg);
+        Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,color,msg);
         //oled_write(OVERLAY, &winsmal,msg,false,true);
     }
 
--- a/Discovery/Src/t3.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/t3.c	Thu Jan 03 19:59:36 2019 +0100
@@ -103,6 +103,9 @@
 
 void t3_init(void)
 {
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     if(getLicence() == LICENCEBONEX)
     {
         t3_customviews = t3_customviewsScooter;
@@ -119,17 +122,37 @@
     t3l1.WindowNumberOfTextLines = 2;
     t3l1.WindowLineSpacing = 19; // Abstand von Y0
     t3l1.WindowTab = 100;
-    t3l1.WindowX0 = 0;
-    t3l1.WindowX1 = BigFontSeperationLeftRight - 5;
-    t3l1.WindowY0 = BigFontSeperationTopBottom + 5;
-    t3l1.WindowY1 = 479;
+
+    if(!pSettings->FlipDisplay)
+    {
+		t3l1.WindowX0 = 0;
+		t3l1.WindowX1 = BigFontSeperationLeftRight - 5;
+		t3l1.WindowY0 = BigFontSeperationTopBottom + 5;
+		t3l1.WindowY1 = 479;
+    }
+    else
+    {
+		t3l1.WindowX0 = 800 - BigFontSeperationLeftRight + 5;
+		t3l1.WindowX1 = 799;
+		t3l1.WindowY0 = 0;
+		t3l1.WindowY1 = 479 - BigFontSeperationTopBottom + 5 ;
+    }
 
     t3r1.Image = &t3screen;
     t3r1.WindowNumberOfTextLines = t3l1.WindowNumberOfTextLines;
     t3r1.WindowLineSpacing = t3l1.WindowLineSpacing;
     t3r1.WindowTab = t3l1.WindowTab;
-    t3r1.WindowX0 = BigFontSeperationLeftRight + 5;
-    t3r1.WindowX1 = 799;
+    if(!pSettings->FlipDisplay)
+    {
+		t3r1.WindowX0 = BigFontSeperationLeftRight + 5;
+		t3r1.WindowX1 = 799;
+    }
+    else
+    {
+		t3r1.WindowX0 = 0;
+		t3r1.WindowX1 = BigFontSeperationLeftRight - 5;
+    }
+
     t3r1.WindowY0 = t3l1.WindowY0;
     t3r1.WindowY1 = t3l1.WindowY1;
 
@@ -138,16 +161,24 @@
     t3c1.WindowLineSpacing = t3l1.WindowLineSpacing;
     t3c1.WindowX0 = 0;
     t3c1.WindowX1 = 799;
-    t3c1.WindowY0 = 0;
-    t3c1.WindowY1 = BigFontSeperationTopBottom - 5;
+    if(!pSettings->FlipDisplay)
+    {
+    	t3c1.WindowY0 = 0;
+    	t3c1.WindowY1 = BigFontSeperationTopBottom - 5;
+    }
+	else
+	{
+		t3c1.WindowY0 = 480 - BigFontSeperationTopBottom + 5;
+		t3c1.WindowY1 = 479;
+	}
 
     t3c2.Image = &t3screen;
     t3c2.WindowNumberOfTextLines = 3;
     t3c2.WindowLineSpacing = 58;
     t3c2.WindowX0 = 370;
     t3c2.WindowX1 = 799;
-    t3c2.WindowY0 = 0;
-    t3c2.WindowY1 = BigFontSeperationTopBottom - 5;
+    t3c2.WindowY0 = t3c1.WindowY0;
+    t3c2.WindowY1 = t3c1.WindowY1;
     t3c2.WindowTab = 600;
 }
 
@@ -183,6 +214,9 @@
     uint8_t depthChangeAscent;
     point_t start, stop, startZeroLine;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     start.x = 0;
     stop.x = 799;
     stop.y = start.y = BigFontSeperationTopBottom;
@@ -190,6 +224,7 @@
 
     start.y = BigFontSeperationTopBottom;
     stop.y = 479;
+
     stop.x = start.x = BigFontSeperationLeftRight;
     GFX_draw_line(tXscreen, start, stop, CLUT_Font020);
 
@@ -322,19 +357,50 @@
         /* ascentrate graph -standard mode */
         if(stateUsed->lifeData.ascent_rate_meter_per_min > 0)
         {
-            start.y = tXl1->WindowY0 - 1;
+        	 if(!pSettings->FlipDisplay)
+        	 {
+        		 start.y = tXl1->WindowY0 - 1;
+        	 }
+        	 else
+        	 {
+        		 start.y = tXl1->WindowY1 + 1;
+        	 }
+
             for(int i = 0; i<4;i++)
             {
                 start.y += 5*8;
                 stop.y = start.y;
-                start.x = tXl1->WindowX1 - 1;
+                if(!pSettings->FlipDisplay)
+                {
+                	start.x = tXl1->WindowX1 - 1;
+                }
+                else
+                {
+                	start.x = tXr1->WindowX1 - 1;
+                }
                 stop.x = start.x - 17;
                 GFX_draw_line(tXscreen, start, stop, 0);
             }
             // new thick bar design Sept. 2015
-            start.x = tXl1->WindowX1 - 3 - 5;
+            if(!pSettings->FlipDisplay)
+            {
+            	start.x = tXl1->WindowX1 - 3 - 5;
+            }
+            else
+            {
+            	start.x = tXr1->WindowX1 - 3 - 5;
+            }
+
             stop.x = start.x;
-            start.y = tXl1->WindowY0 - 1;
+            if(!pSettings->FlipDisplay)
+            {
+            	start.y = tXl1->WindowY0 - 1;
+            }
+            else
+            {
+            	start.y = tXl1->WindowY1 + 1;
+            }
+
             stop.y = start.y + (uint16_t)(stateUsed->lifeData.ascent_rate_meter_per_min * 8);
             stop.y -= 3; // wegen der Liniendicke von 12 anstelle von 9
             if(stop.y >= 470)
@@ -600,6 +666,9 @@
     char text[512];
     uint16_t textpointer = 0;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     // CVIEW_T3_Decostop and CVIEW_T3_TTS
     const SDecoinfo * pDecoinfo;
     if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
@@ -632,7 +701,9 @@
 
 
     uint16_t tempWinX0;
+    uint16_t tempWinX1;
     uint16_t tempWinY0;
+    uint16_t tempWinY1;
     uint16_t tempWinC2X0;
     uint16_t tempWinC2Tab;
 
@@ -676,6 +747,12 @@
         break;
 
     case CVIEW_T3_StopWatch:
+
+        tempWinX0 = tXc1->WindowX0;
+        tempWinY0 = tXc1->WindowY0;
+        tempWinX1 = tXc1->WindowX1;
+        tempWinY1 = tXc1->WindowY1;
+
         Stopwatch.Total = timer_Stopwatch_GetTime();
         Stopwatch.Minutes = Stopwatch.Total / 60;
         Stopwatch.Seconds = Stopwatch.Total - ( Stopwatch.Minutes * 60 );
@@ -687,19 +764,39 @@
         snprintf(text,TEXTSIZE,"\030\003\016%01.1f",unit_depth_float(fAverageDepthAbsolute));
         GFX_write_string(&FontT105,tXc1,text,0);
 
-        tempWinX0 = tXc1->WindowX0;
-        tempWinY0 = tXc1->WindowY0;
-        tXc1->WindowX0 = 480;
+
+
+        if(!pSettings->FlipDisplay)
+        {
+        	tXc1->WindowX0 = 480;
+        }
+        else
+        {
+        	tXc1->WindowX1 = 320;
+        	tXc1->WindowY0 = t3c1.WindowY0; /* select customer window */
+        }
 //			snprintf(text,TEXTSIZE,"\032\f%c%c - %c",TXT_2BYTE, TXT2BYTE_Clock, TXT_AvgDepth);
+
         snprintf(text,TEXTSIZE,"\032\f%c", TXT_Stopwatch);
         GFX_write_string(&FontT42,tXc1,text,0);
         snprintf(text,TEXTSIZE,"\030\016%01.1f",unit_depth_float(fAverageDepth));
         GFX_write_string(&FontT105,tXc1,text,0);
-        tXc1->WindowY0 = 100;
+        if(!pSettings->FlipDisplay)
+        {
+        	tXc1->WindowY0 = 100;
+        }
+        else
+        {
+        	tXc1->WindowY1 -= 100; /* jump to upper of two lines */
+        }
+
         snprintf(text,TEXTSIZE,"\030%u:\016\016%02u",Stopwatch.Minutes, Stopwatch.Seconds);
         GFX_write_string(&FontT105,tXc1,text,0);
+
         tXc1->WindowX0 = tempWinX0;
         tXc1->WindowY0 = tempWinY0;
+        tXc1->WindowX1 = tempWinX1;
+        tXc1->WindowY1 = tempWinY1;
         break;
 
     case CVIEW_T3_GasList:
--- a/Discovery/Src/t7.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/t7.c	Thu Jan 03 19:59:36 2019 +0100
@@ -187,15 +187,23 @@
 
 #define CUSTOMBOX_LINE_LEFT (250)
 #define CUSTOMBOX_LINE_RIGHT (549)
+#define CUSTOMBOX_LINE_TOP	  (0)
+#define CUSTOMBOX_LINE_MIDDLE  (142)
+#define CUSTOMBOX_LINE_BOTTOM  (318)
 #define CUSTOMBOX_INSIDE_OFFSET (2)
 #define CUSTOMBOX_OUTSIDE_OFFSET (2)
 #define CUSTOMBOX_SPACE_INSIDE (CUSTOMBOX_LINE_RIGHT + 1 - (CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET + CUSTOMBOX_INSIDE_OFFSET))
-
+#define TOP_LINE_HIGHT (25)
 
 /* Exported functions --------------------------------------------------------*/
 
 void t7_init(void)
 {
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
     if(getLicence() == LICENCEBONEX)
     {
         customviewsDive     = customviewsDiveScooter;
@@ -215,48 +223,217 @@
     t7screenCompass.ImageWidth = 1600;
     t7screenCompass.LayerIndex = 0;
 
+    if(!pSettings->FlipDisplay)
+    {
+		t7l1.Image = &t7screen;
+		t7l1.WindowNumberOfTextLines = 2;
+		t7l1.WindowLineSpacing = 19; // Abstand von Y0
+		t7l1.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
+		t7l1.WindowX0 = 0;
+		t7l1.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
+		t7l1.WindowY0 = 318;
+		t7l1.WindowY1 = 479;
+
+		t7l2.Image = &t7screen;
+		t7l2.WindowNumberOfTextLines = 2;
+		t7l2.WindowLineSpacing = 22; // Abstand von Y0
+		t7l2.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
+		t7l2.WindowX0 = 0;
+		t7l2.WindowX1 = t7l1.WindowX1;
+		t7l2.WindowY0 = 142;
+		t7l2.WindowY1 = t7l1.WindowY0 - 5;
+
+		t7l3.Image = &t7screen;
+		t7l3.WindowNumberOfTextLines = 2;
+		t7l3.WindowLineSpacing = 58; // Abstand von Y0
+		t7l3.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
+		t7l3.WindowX0 = 0;
+		t7l3.WindowX1 = t7l1.WindowX1;
+		t7l3.WindowY0 = 0;
+		t7l3.WindowY1 = t7l2.WindowY0 - 5;
+
+		t7r1.Image = &t7screen;
+		t7r1.WindowNumberOfTextLines = 2;
+		t7r1.WindowLineSpacing = t7l1.WindowLineSpacing;
+		t7r1.WindowTab = 100;
+		t7r1.WindowX0 = 550;
+		t7r1.WindowX1 = 799;
+		t7r1.WindowY0 = t7l1.WindowY0;
+		t7r1.WindowY1 = 479;
+
+		t7r2.Image = &t7screen;
+		t7r2.WindowNumberOfTextLines = 2;
+		t7r2.WindowLineSpacing = t7l2.WindowLineSpacing;
+		t7r2.WindowTab = 100;
+		t7r2.WindowX0 = 550;
+		t7r2.WindowX1 = 799;
+		t7r2.WindowY0 = t7l2.WindowY0;
+		t7r2.WindowY1 = t7l2.WindowY1;
+
+		t7r3.Image = &t7screen;
+		t7r3.WindowNumberOfTextLines = 2;
+		t7r3.WindowLineSpacing = 0;//t7l3.WindowLineSpacing;
+		t7r3.WindowTab = 100;
+		t7r3.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
+		t7r3.WindowX1 = 799;
+		t7r3.WindowY0 = t7l3.WindowY0;
+		t7r3.WindowY1 = t7l3.WindowY1;
+
+		t7cC.Image = &t7screen;
+		t7cC.WindowNumberOfTextLines = 3;
+		t7cC.WindowLineSpacing = 95; // Abstand von Y0
+		t7cC.WindowTab = 100;
+		t7cC.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7cC.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7cC.WindowY0 = 90;
+		t7cC.WindowY1 = 434 - 95;
+
+		t7cH.Image = &t7screen;
+		t7cH.WindowNumberOfTextLines = 1;
+		t7cH.WindowLineSpacing = 95; // Abstand von Y0
+		t7cH.WindowTab = 100;
+		t7cH.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7cH.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7cH.WindowY0 = 434 - 94;
+		t7cH.WindowY1 = 434;
+
+		t7cW.Image = &t7screen;
+		t7cW.WindowNumberOfTextLines = 3;
+		t7cW.WindowLineSpacing = 95; // Abstand von Y0
+		t7cW.WindowTab = 100;
+		t7cW.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7cW.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7cW.WindowY0 = 90;
+		t7cW.WindowY1 = 434 - 95;
+
+
+		t7surfaceL.Image = &t7screen;
+		t7surfaceL.WindowNumberOfTextLines = 9;
+		t7surfaceL.WindowLineSpacing = 53;
+		t7surfaceL.WindowTab = 100;
+		t7surfaceL.WindowX0 = 0;
+		t7surfaceL.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
+		t7surfaceL.WindowY0 = 0;
+		t7surfaceL.WindowY1 = 480;
+
+		t7surfaceR.Image = &t7screen;
+		t7surfaceR.WindowNumberOfTextLines = 9;
+		t7surfaceR.WindowLineSpacing = 53;
+		t7surfaceR.WindowTab = 100;
+		t7surfaceR.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
+		t7surfaceR.WindowX1 = 800;
+		t7surfaceR.WindowY0 = 0;
+		t7surfaceR.WindowY1 = 480;
+
+		t7cY0free.Image = &t7screen;
+		t7cY0free.WindowNumberOfTextLines = 1;
+		t7cY0free.WindowLineSpacing = 95;
+		t7cY0free.WindowTab = 100;
+		t7cY0free.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7cY0free.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7cY0free.WindowY0 = 90;
+		t7cY0free.WindowY1 = 434 - 95;
+
+		t7batt.Image = &t7screen;
+		t7batt.WindowNumberOfTextLines = 1;
+		t7batt.WindowLineSpacing = 10;
+		t7batt.WindowTab = 100;
+		t7batt.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7batt.WindowX0 = t7batt.WindowX1 - (52+52);
+		t7batt.WindowY1 = 479;
+		t7batt.WindowY0 = t7batt.WindowY1 - 25;
+
+		t7charge.Image = &t7screen;
+		t7charge.WindowNumberOfTextLines = 1;
+		t7charge.WindowLineSpacing = 10;
+		t7charge.WindowTab = 100;
+		t7charge.WindowX1 = t7batt.WindowX1 - 18;
+		t7charge.WindowX0 = t7charge.WindowX1 - 14;
+		t7charge.WindowY1 = 479;
+		t7charge.WindowY0 = t7batt.WindowY1 - 25;
+
+		t7voltage.Image = &t7screen;
+		t7voltage.WindowNumberOfTextLines = 1;
+		t7voltage.WindowLineSpacing = 10;
+		t7voltage.WindowTab = 100;
+		t7voltage.WindowX0 = t7charge.WindowX0 - 30; //10
+		t7voltage.WindowX1 = t7voltage.WindowX0 + (18*3)+ 9;
+		t7voltage.WindowY1 = 479;
+		t7voltage.WindowY0 = t7batt.WindowY1 - 25;
+
+		t7c1.Image = &t7screen;
+		t7c1.WindowNumberOfTextLines = 1;
+		t7c1.WindowLineSpacing = 10;
+		t7c1.WindowTab = 100;
+		t7c1.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7c1.WindowX1 = t7batt.WindowX0 - 18;
+		t7c1.WindowY0 = 435;
+		t7c1.WindowY1 = 479;
+
+		t7c2.Image = &t7screen;
+		t7c2.WindowNumberOfTextLines = 1;
+		t7c2.WindowLineSpacing = 0; // Abstand von Y0
+		t7c2.WindowTab = 100;
+		t7c2.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+		t7c2.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
+		t7c2.WindowY0 = 0;
+		t7c2.WindowY1 = 69;
+
+		t7pCompass.Image = &t7screenCompass;
+		t7pCompass.WindowNumberOfTextLines = 1;
+		t7pCompass.WindowLineSpacing = 100; // Abstand von Y0
+		t7pCompass.WindowTab = 100;
+		t7pCompass.WindowX0 = 0;
+		t7pCompass.WindowX1 = 1600-1;
+		t7pCompass.WindowY0 = 0;
+		t7pCompass.WindowY1 = 100-1;
+    }
+    else
+    {
+/* 6 segments (left / right) used to show data during dive */
+
     t7l1.Image = &t7screen;
     t7l1.WindowNumberOfTextLines = 2;
     t7l1.WindowLineSpacing = 19; // Abstand von Y0
     t7l1.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
-    t7l1.WindowX0 = 0;
-    t7l1.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
-    t7l1.WindowY0 = 318;
-    t7l1.WindowY1 = 479;
+    t7l1.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
+    t7l1.WindowX1 = 799;
+    t7l1.WindowY0 = CUSTOMBOX_LINE_TOP;
+    t7l1.WindowY1 = 150 + TOP_LINE_HIGHT;
 
     t7l2.Image = &t7screen;
     t7l2.WindowNumberOfTextLines = 2;
     t7l2.WindowLineSpacing = 22; // Abstand von Y0
     t7l2.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
-    t7l2.WindowX0 = 0;
+    t7l2.WindowX0 = t7l1.WindowX0;
     t7l2.WindowX1 = t7l1.WindowX1;
-    t7l2.WindowY0 = 142;
-    t7l2.WindowY1 = t7l1.WindowY0 - 5;
+    t7l2.WindowY0 = t7l1.WindowY1 + 5;
+    t7l2.WindowY1 = t7l2.WindowY0 + 146;
 
     t7l3.Image = &t7screen;
     t7l3.WindowNumberOfTextLines = 2;
     t7l3.WindowLineSpacing = 58; // Abstand von Y0
     t7l3.WindowTab = 100; // vermtl. ohne Verwendung in diesem Fenster
-    t7l3.WindowX0 = 0;
-    t7l3.WindowX1 = t7l1.WindowX1;
-    t7l3.WindowY0 = 0;
-    t7l3.WindowY1 = t7l2.WindowY0 - 5;
+    t7l3.WindowX0 = t7l1.WindowX0;
+    t7l3.WindowX1 = t7l1.WindowX1;;
+    t7l3.WindowY0 = 479 - 150;
+    t7l3.WindowY1 = 479;
 
     t7r1.Image = &t7screen;
     t7r1.WindowNumberOfTextLines = 2;
     t7r1.WindowLineSpacing = t7l1.WindowLineSpacing;
     t7r1.WindowTab = 100;
-    t7r1.WindowX0 = 550;
-    t7r1.WindowX1 = 799;
+    t7r1.WindowX0 = 0;
+    t7r1.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
     t7r1.WindowY0 = t7l1.WindowY0;
-    t7r1.WindowY1 = 479;
+    t7r1.WindowY1 = t7l1.WindowY1;
 
     t7r2.Image = &t7screen;
     t7r2.WindowNumberOfTextLines = 2;
     t7r2.WindowLineSpacing = t7l2.WindowLineSpacing;
     t7r2.WindowTab = 100;
-    t7r2.WindowX0 = 550;
-    t7r2.WindowX1 = 799;
+    t7r2.WindowX0 = t7r1.WindowX0;
+    t7r2.WindowX1 = t7r1.WindowX1;
     t7r2.WindowY0 = t7l2.WindowY0;
     t7r2.WindowY1 = t7l2.WindowY1;
 
@@ -264,118 +441,132 @@
     t7r3.WindowNumberOfTextLines = 2;
     t7r3.WindowLineSpacing = 0;//t7l3.WindowLineSpacing;
     t7r3.WindowTab = 100;
-    t7r3.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
-    t7r3.WindowX1 = 799;
+    t7r3.WindowX0 = t7r1.WindowX0;
+    t7r3.WindowX1 = t7r1.WindowX1;
     t7r3.WindowY0 = t7l3.WindowY0;
     t7r3.WindowY1 = t7l3.WindowY1;
 
+/* screen for CustomText / serial number */
     t7cC.Image = &t7screen;
     t7cC.WindowNumberOfTextLines = 3;
     t7cC.WindowLineSpacing = 95; // Abstand von Y0
     t7cC.WindowTab = 100;
     t7cC.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     t7cC.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7cC.WindowY0 = 90;
-    t7cC.WindowY1 = 434 - 95;
-
+    t7cC.WindowY0 = 165; //90;
+    t7cC.WindowY1 = 415;
+
+    /* used by warning message box */
     t7cH.Image = &t7screen;
     t7cH.WindowNumberOfTextLines = 1;
     t7cH.WindowLineSpacing = 95; // Abstand von Y0
     t7cH.WindowTab = 100;
     t7cH.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     t7cH.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7cH.WindowY0 = 434 - 94;
-    t7cH.WindowY1 = 434;
-
+    t7cH.WindowY0 = 46; //480 - 434;
+    t7cH.WindowY1 = 390 - 46;// - 90; //46 + 390; //480 - (434 - 94); //434;
+
+    /* used by warning custom box */
     t7cW.Image = &t7screen;
     t7cW.WindowNumberOfTextLines = 3;
     t7cW.WindowLineSpacing = 95; // Abstand von Y0
     t7cW.WindowTab = 100;
     t7cW.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     t7cW.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7cW.WindowY0 = 90;
-    t7cW.WindowY1 = 434 - 95;
-
+    t7cW.WindowY0 = 480 - (434 - 90);
+    t7cW.WindowY1 = 480 - 90; //434 - 95;
+
+/* time and environment */
     t7surfaceL.Image = &t7screen;
     t7surfaceL.WindowNumberOfTextLines = 9;
     t7surfaceL.WindowLineSpacing = 53;
     t7surfaceL.WindowTab = 100;
-    t7surfaceL.WindowX0 = 0;
-    t7surfaceL.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
+    t7surfaceL.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
+    t7surfaceL.WindowX1 = 799;
     t7surfaceL.WindowY0 = 0;
-    t7surfaceL.WindowY1 = 480;
+    t7surfaceL.WindowY1 = 479;
 
     t7surfaceR.Image = &t7screen;
     t7surfaceR.WindowNumberOfTextLines = 9;
     t7surfaceR.WindowLineSpacing = 53;
     t7surfaceR.WindowTab = 100;
-    t7surfaceR.WindowX0 = CUSTOMBOX_LINE_RIGHT + CUSTOMBOX_OUTSIDE_OFFSET;
-    t7surfaceR.WindowX1 = 800;
+    t7surfaceR.WindowX0 = 0;
+    t7surfaceR.WindowX1 = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET;
     t7surfaceR.WindowY0 = 0;
-    t7surfaceR.WindowY1 = 480;
-
+    t7surfaceR.WindowY1 = 479;
+
+/* info screen in the middle */
     t7cY0free.Image = &t7screen;
     t7cY0free.WindowNumberOfTextLines = 1;
     t7cY0free.WindowLineSpacing = 95;
     t7cY0free.WindowTab = 100;
     t7cY0free.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     t7cY0free.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7cY0free.WindowY0 = 90;
-    t7cY0free.WindowY1 = 434 - 95;
-
+    t7cY0free.WindowY0 = 115;
+    t7cY0free.WindowY1 = 365;
+
+/* voltage value (V or %) */
+    t7voltage.Image = &t7screen;
+    t7voltage.WindowNumberOfTextLines = 1;
+    t7voltage.WindowLineSpacing = 10;
+    t7voltage.WindowTab = 100;
+    t7voltage.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+    t7voltage.WindowX1 = t7voltage.WindowX0 + (18*3) +9;
+    t7voltage.WindowY1 = TOP_LINE_HIGHT;
+    t7voltage.WindowY0 = 0;
+
+/* battery symbol */
     t7batt.Image = &t7screen;
     t7batt.WindowNumberOfTextLines = 1;
     t7batt.WindowLineSpacing = 10;
     t7batt.WindowTab = 100;
-    t7batt.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7batt.WindowX0 = t7batt.WindowX1 - (52+52);
-    t7batt.WindowY1 = 479;
-    t7batt.WindowY0 = t7batt.WindowY1 - 25;
-
+    t7batt.WindowX0 = t7voltage.WindowX1;
+    t7batt.WindowX1 = t7batt.WindowX0 + (52);
+    t7batt.WindowY1 = TOP_LINE_HIGHT;
+    t7batt.WindowY0 = 0;
+
+/* charger symbol */
     t7charge.Image = &t7screen;
     t7charge.WindowNumberOfTextLines = 1;
     t7charge.WindowLineSpacing = 10;
     t7charge.WindowTab = 100;
-    t7charge.WindowX1 = t7batt.WindowX1 - 18;
+    t7charge.WindowX1 = t7batt.WindowX0 - 18;
     t7charge.WindowX0 = t7charge.WindowX1 - 14;
-    t7charge.WindowY1 = 479;
-    t7charge.WindowY0 = t7batt.WindowY1 - 25;
-
-    t7voltage.Image = &t7screen;
-    t7voltage.WindowNumberOfTextLines = 1;
-    t7voltage.WindowLineSpacing = 10;
-    t7voltage.WindowTab = 100;
-    t7voltage.WindowX0 = t7charge.WindowX0 - 10;
-    t7voltage.WindowX1 = t7voltage.WindowX0 + (18*3)+ 9;
-    t7voltage.WindowY1 = 479;
-    t7voltage.WindowY0 = t7batt.WindowY1 - 25;
-
+
+    t7charge.WindowY1 = TOP_LINE_HIGHT;
+    t7charge.WindowY0 = 0;
+
+/* show dive mode OC / CC */
     t7c1.Image = &t7screen;
     t7c1.WindowNumberOfTextLines = 1;
     t7c1.WindowLineSpacing = 10;
     t7c1.WindowTab = 100;
-    t7c1.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
-    t7c1.WindowX1 = t7batt.WindowX0 - 18;
-    t7c1.WindowY0 = 435;
-    t7c1.WindowY1 = 479;
-
+    t7c1.WindowX0 = t7batt.WindowX1 + 18; //CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
+    t7c1.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET; //t7batt.WindowX1 + 18;
+    t7c1.WindowY0 = 0;
+    t7c1.WindowY1 = 479 - 435;
+
+/* Gas warnings and exit Sim*/
     t7c2.Image = &t7screen;
     t7c2.WindowNumberOfTextLines = 1;
     t7c2.WindowLineSpacing = 0; // Abstand von Y0
     t7c2.WindowTab = 100;
     t7c2.WindowX0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     t7c2.WindowX1 = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_INSIDE_OFFSET;
-    t7c2.WindowY0 = 0;
-    t7c2.WindowY1 = 69;
-
+    t7c2.WindowY0 = 480 - 69;
+    t7c2.WindowY1 = 479;
+
+/* Rotating compass */
     t7pCompass.Image = &t7screenCompass;
     t7pCompass.WindowNumberOfTextLines = 1;
     t7pCompass.WindowLineSpacing = 100; // Abstand von Y0
     t7pCompass.WindowTab = 100;
     t7pCompass.WindowX0 = 0;
     t7pCompass.WindowX1 = 1600-1;
-    t7pCompass.WindowY0 = 0;
-    t7pCompass.WindowY1 = 100-1;
+    t7pCompass.WindowY0 = 479 - 75;
+    t7pCompass.WindowY1 = 479;
+
+    }
 
     init_t7_compass();
 }
@@ -538,6 +729,10 @@
 //	uint16_t bottleFirstGas_bar;
     point_t start, stop;//, other;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
     // update in all customview modes
     if(DataEX_check_RTE_version__needs_update() || font_update_required())
         updateNecessary = 1;
@@ -548,19 +743,19 @@
     text[0] = TXT_2BYTE;
     text[1] = TXT2BYTE_ButtonLogbook;
     text[2] = 0;
-    write_content_simple(&t7screen, 0, 800, 480-24, &FontT24,text,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&t7screen, 0, 799, 479-TOP_LINE_HIGHT, &FontT24,text,CLUT_ButtonSurfaceScreen);
 
     text[0] = '\001';
     text[1] = TXT_2BYTE;
     text[2] = TXT2BYTE_ButtonView;
     text[3] = 0;
-    write_content_simple(&t7screen, 0, 800, 480-24, &FontT24,text,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&t7screen, 0, 799, 479-TOP_LINE_HIGHT, &FontT24,text,CLUT_ButtonSurfaceScreen);
 
     text[0] = '\002';
     text[1] = TXT_2BYTE;
     text[2] = TXT2BYTE_ButtonMenu;
     text[3] = 0;
-    write_content_simple(&t7screen, 0, 800, 480-24, &FontT24,text,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&t7screen, 0, 799, 479-TOP_LINE_HIGHT, &FontT24,text,CLUT_ButtonSurfaceScreen);
 
 /*
     // scooter connected?
@@ -865,8 +1060,17 @@
         // after gas name :-)
         if(actualGasID > gasOffset) // security
         {
-            start.y = t7surfaceL.WindowY0 + (3 * t7surfaceL.WindowLineSpacing);
-            start.x = t7surfaceL.WindowX0 + ((stateUsed->lifeData.actualGas.GasIdInSettings - gasOffset - 1) * 35);
+        	if(!pSettings->FlipDisplay)
+        	{
+        		start.y = t7surfaceL.WindowY0 + (3 * t7surfaceL.WindowLineSpacing);
+        		start.x = t7surfaceL.WindowX0 + ((stateUsed->lifeData.actualGas.GasIdInSettings - gasOffset - 1) * 35);
+        	}
+			else
+			{
+				start.y = t7surfaceR.WindowY0 + (3 * t7surfaceR.WindowLineSpacing);
+				start.x = t7surfaceR.WindowX0 + ((stateUsed->lifeData.actualGas.GasIdInSettings - gasOffset - 1) * 35);
+			}
+
             stop.x = start.x + 25;
             stop.y = start.y + 52;
             GFX_draw_box2(&t7screen, start, stop, CLUT_Font020, 1);
@@ -921,7 +1125,7 @@
                 snprintf(text,16,"\004\025\f\002%u%%",(uint8_t)stateUsed->lifeData.battery_charge);
                 if(warning_count_high_time)
                     text[0] = '\a';
-                GFX_write_string(&FontT24,&t7batt,text,0);
+                GFX_write_string(&FontT24,&t7voltage,text,0);
             }
             else
             {
@@ -936,7 +1140,8 @@
             if((stateUsed->lifeData.battery_charge > 0) && (stateUsed->lifeData.battery_charge < 140))
             {
                 snprintf(text,16,"\f\002%u%%",(uint8_t)stateUsed->lifeData.battery_charge);
-                GFX_write_string(&FontT24,&t7batt,text,0);
+        //        GFX_write_string(&FontT24,&t7batt,text,0);
+                GFX_write_string(&FontT24,&t7voltage,text,0);
             }
             else
             {
@@ -1403,16 +1608,6 @@
 
 void t7_refresh_customview(void)
 {
-    if((selection_customview == CVIEW_Scooter) && (getLicence() != LICENCEBONEX))
-        t7_change_customview();
-    if((selection_customview == CVIEW_Scooter) && (!DataEX_scooterFoundAndValidLicence() && (stateRealGetPointer()->mode == MODE_DIVE)))
-        t7_change_customview();
-    if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
-    if((selection_customview == CVIEW_sensors_mV) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
-    if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
 
     char text[256];
     uint16_t textpointer = 0;
@@ -1426,6 +1621,21 @@
     uint8_t oxygen, helium; // CVIEW_Gaslist
     float depth, surface, fraction_nitrogen, fraction_helium, ead, end; // CVIEW_EADTime
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+
+    if((selection_customview == CVIEW_Scooter) && (getLicence() != LICENCEBONEX))
+        t7_change_customview();
+    if((selection_customview == CVIEW_Scooter) && (!DataEX_scooterFoundAndValidLicence() && (stateRealGetPointer()->mode == MODE_DIVE)))
+        t7_change_customview();
+    if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
+        t7_change_customview();
+    if((selection_customview == CVIEW_sensors_mV) &&(stateUsed->diveSettings.ccrOption == 0))
+        t7_change_customview();
+    if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
+        t7_change_customview();
+
     switch(selection_customview)
     {
     case CVIEW_noneOrDebug:
@@ -1547,7 +1757,15 @@
         GFX_write_string(&FontT42,&t7cH,text,0);
         // content
         textpointer = 0;
-        t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+
+        if(!pSettings->FlipDisplay)
+        {
+        	t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+        }
+        else
+        {
+        	t7cY0free.WindowY1 = 400;
+        }
         t7cY0free.WindowLineSpacing = 48+9;
         t7cY0free.WindowNumberOfTextLines = 5; // NUM_GASES == 5
         t7cY0free.WindowTab = 420;
@@ -1588,6 +1806,10 @@
         textpointer = 0;
 
         t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+        if(pSettings->FlipDisplay)
+        {
+        	t7cY0free.WindowY1 = 400;
+        }
         t7cY0free.WindowLineSpacing = 48;
         t7cY0free.WindowNumberOfTextLines = 6;
 
@@ -1716,11 +1938,28 @@
         snprintf(text,100,"\032\f\001%c%c",TXT_2BYTE, TXT2BYTE_Compass);
         GFX_write_string(&FontT42,&t7cH,text,0);
         t7_compass((uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading);
-        t7cY0free.WindowY0 = 230;
-        t7cY0free.WindowX0 += 15;
+
+        if(!pSettings->FlipDisplay)
+        {
+        	t7cY0free.WindowX0 += 15;
+        	t7cY0free.WindowY0 = 230;
+        }
+        else
+        {
+        	t7cY0free.WindowX0 -= 15;
+        	t7cY0free.WindowY0 = 0;
+        	t7cY0free.WindowY1 = 250;
+        }
         snprintf(text,100,"\030\001%03i`",(uint16_t)stateUsed->lifeData.compass_heading);
         GFX_write_string(&FontT54,&t7cY0free,text,0);
-        t7cY0free.WindowX0 -= 15;
+        if(!pSettings->FlipDisplay)
+        {
+        	t7cY0free.WindowX0 -= 15;
+        }
+        else
+        {
+        	t7cY0free.WindowX0 += 15;
+        }
         break;
 
     case CVIEW_Decolist:
@@ -1765,7 +2004,16 @@
                 textpointer += snprintf(&text[textpointer],20,"\031\034   %2u\016\016%c%c\017\n\r",depthNext, unit_depth_char1(), unit_depth_char2());
             if(textpointer > 200) break;
         }
-        t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+        if(!pSettings->FlipDisplay)
+        {
+        	t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+        }
+        else
+        {
+        	t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
+        	t7cY0free.WindowY1 = 400;
+        }
+
         t7cY0free.WindowLineSpacing = 48;
         t7cY0free.WindowNumberOfTextLines = 6;
         GFX_write_string(&FontT42, &t7cY0free, text, 1);
@@ -1803,6 +2051,9 @@
     uint8_t  customview_warnings = 0;
     const SDecoinfo * pDecoinfo;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     Divetime.Total = stateUsed->lifeData.dive_time_seconds_without_surface_time;
     Divetime.Minutes = Divetime.Total / 60;
     Divetime.Seconds = Divetime.Total - ( Divetime.Minutes * 60 );
@@ -1898,7 +2149,15 @@
     /* ascentrate graph */
     if(stateUsed->lifeData.ascent_rate_meter_per_min > 0)
     {
-        start.y = t7l1.WindowY0 - 1;
+    	if(!pSettings->FlipDisplay)
+    	{
+    		start.y = t7l1.WindowY0 - 1;
+    	}
+    	else
+    	{
+    		start.y = t7l3.WindowY0 - 25;
+    	}
+
         for(int i = 0; i<4;i++)
         {
             start.y += 5*6;
@@ -1913,7 +2172,14 @@
         // new thick bar design Sept. 2015
         start.x = CUSTOMBOX_LINE_LEFT - CUSTOMBOX_OUTSIDE_OFFSET - 3 - 5;
         stop.x = start.x;
-        start.y = t7l1.WindowY0 - 1;
+    	if(!pSettings->FlipDisplay)
+    	{
+    		start.y = t7l1.WindowY0 - 1;
+    	}
+    	else
+    	{
+    		start.y = t7l3.WindowY0 - 25;
+    	}
         stop.y = start.y + (uint16_t)(stateUsed->lifeData.ascent_rate_meter_per_min * 6);
         stop.y -= 3; // wegen der Liniendicke von 12 anstelle von 9
         if(stop.y >= 470)
@@ -2227,7 +2493,7 @@
             snprintf(TextC1,16,"\004\025\f\002%u%%",(uint8_t)stateUsed->lifeData.battery_charge);
             if(warning_count_high_time)
                 TextC1[0] = '\a';
-            GFX_write_string(&FontT24,&t7batt,TextC1,0);
+            GFX_write_string(&FontT24,&t7voltage,TextC1,0);
         }
     }
     else
@@ -2239,7 +2505,7 @@
         {
             snprintf(TextC1,16,"\020\f\002%u%%",(uint8_t)stateUsed->lifeData.battery_charge);
             t7_colorscheme_mod(TextC1);
-            GFX_write_string(&FontT24,&t7batt,TextC1,0);
+            GFX_write_string(&FontT24,&t7voltage,TextC1,0); // t7batt
         }
     }
 
@@ -2484,6 +2750,9 @@
     point_t LeftLow, WidthHeight;
     point_t start, stop;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     // plugin box
     LeftLow.x = CUSTOMBOX_LINE_LEFT;
     WidthHeight.x = CUSTOMBOX_LINE_RIGHT - CUSTOMBOX_LINE_LEFT;
@@ -2505,17 +2774,47 @@
         // aufteilung links
         start.x = 0;
         stop.x = CUSTOMBOX_LINE_LEFT;
-        stop.y = start.y = t7l1.WindowY0 - 1;
+        if(!pSettings->FlipDisplay)
+        {
+        	stop.y = start.y = t7l1.WindowY0 - 1;
+        }
+        else
+        {
+        	stop.y = start.y = 480 - t7l1.WindowY1 - 1;
+        }
+
         GFX_draw_line(&t7screen, start, stop, colorLinesOnTheSide);
-        stop.y = start.y = t7l2.WindowY0 -1;
+        if(!pSettings->FlipDisplay)
+        {
+        	stop.y = start.y = t7l2.WindowY0 -1;
+        }
+        else
+        {
+        	stop.y = start.y = 480 - t7l2.WindowY1 -1;
+        }
         GFX_draw_line(&t7screen, start, stop, colorLinesOnTheSide);
 
         // aufteilung rechts
         start.x = CUSTOMBOX_LINE_RIGHT;
         stop.x = 799;
-        stop.y = start.y = t7l1.WindowY0 - 1;
+        if(!pSettings->FlipDisplay)
+        {
+        	stop.y = start.y = t7l1.WindowY0 - 1;
+        }
+        else
+        {
+        	stop.y = start.y = 480 - t7l1.WindowY1 - 1;
+        }
+
         GFX_draw_line(&t7screen, start, stop, colorLinesOnTheSide);
-        stop.y = start.y = t7l2.WindowY0 - 1;
+        if(!pSettings->FlipDisplay)
+        {
+        	stop.y = start.y = t7l2.WindowY0 - 1;
+        }
+        else
+        {
+        	stop.y = start.y = 480 - t7l2.WindowY1 - 1;
+        }
         GFX_draw_line(&t7screen, start, stop, colorLinesOnTheSide);
     }
 }
@@ -2541,7 +2840,7 @@
 
     static point_t r[4][360] = { 0 };
 
-    if(r[0][0].y == 0)
+    if(r[0][0].y == 0)		/* calc table at first call only */
     {
         for(int i=0;i<360;i++)
         {
@@ -2576,10 +2875,21 @@
     float partial_pressure_N2;
     float partial_pressure_He;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
 
     /* N2 */
     t7cY0free.WindowLineSpacing = 28 + 48 + 14;
-    t7cY0free.WindowY0 = t7cH.WindowY0 - 5 - 2 * t7cY0free.WindowLineSpacing;
+    if(!pSettings->FlipDisplay)
+    {
+    	t7cY0free.WindowY0 = t7cH.WindowY0 - 5 - 2 * t7cY0free.WindowLineSpacing;
+    }
+    else
+    {
+    	t7cY0free.WindowY0 = t7cH.WindowY0 + 15;
+    	t7cY0free.WindowY1 = t7cY0free.WindowY0 + 250;
+    }
     t7cY0free.WindowNumberOfTextLines = 3;
 
     text[textpointer++] = '\030';
@@ -2597,7 +2907,14 @@
 
     GFX_write_string(&FontT24, &t7cY0free, text, 1);
 
-    start.y = t7cH.WindowY0 - 5;
+    if(!pSettings->FlipDisplay)
+    {
+    	start.y = t7cH.WindowY0 - 5;
+    }
+    else
+    {
+    	start.y = t7cH.WindowY1 - 5;
+    }
     start.x = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     stop.x = start.x + CUSTOMBOX_SPACE_INSIDE;
 
@@ -2694,7 +3011,15 @@
     partial_pressure_He = (pState->lifeData.pressure_ambient_bar - WATER_VAPOUR_PRESSURE) * percent_He;
 
     // Nitrogen vertical bar
-    start.y = t7cH.WindowY0 + 1 - 5;
+    if(!pSettings->FlipDisplay)
+    {
+    	start.y = t7cH.WindowY0 + 1 - 5;
+    }
+    else
+    {
+    	start.y = t7cH.WindowY1 - 5;
+    }
+
     stop.y = start.y - (3 * 15) - 1;
     if((percent_N2 > 0) && (partial_pressure_N2 > 0.8f))//(0.8f + 0.5f)))
     {
@@ -2718,7 +3043,15 @@
 
 
     // Helium vertical bar
-    start.y = t7cH.WindowY0 + 1 - 5 - 3*16 - 28 - 14;
+    if(!pSettings->FlipDisplay)
+    {
+    	start.y = t7cH.WindowY0 + 1 - 5 - 3*16 - 28 - 14;
+    }
+    else
+    {
+    	start.y = t7cH.WindowY1 - 5 - 3*16 - 28 - 14;
+    }
+
     stop.y = start.y - (3 * 15) - 1;
     if((percent_He > 0) && (partial_pressure_He > 0.01f)) // 0.5f
     {
@@ -2743,12 +3076,21 @@
     GFX_draw_thick_line(2,&t7screen, start, stop, CLUT_EverythingOkayGreen);
 
     // Oxygen vertical bar
-    start.y = t7cH.WindowY0 + 1 - 5 - 6*16 - 2*28 - 2*14;
+    if(!pSettings->FlipDisplay)
+    {
+    	start.y = t7cH.WindowY0 + 1 - 5 - 6*16 - 2*28 - 2*14;
+    }
+    else
+    {
+    	start.y = t7cH.WindowY1 - 5 - 6*16 - 2*28 - 2*14;
+    }
+
     stop.y = start.y - (3 * 15) - 1;
 
     start.x = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET + cns100pixel;
     stop.x = start.x;
     GFX_draw_thick_line(2, &t7screen, start, stop, CLUT_WarningRed);
+
 }
 
 
@@ -3367,17 +3709,22 @@
 
     lastHeading = ActualHeading;
 */
+	uint16_t ActualHeadingRose;
     uint16_t LeftBorderHeading, LineHeading;
     uint32_t offsetPicture;
     point_t start, stop, center;
     static int32_t LastHeading = 0;
     int32_t newHeading = 0;
+    int32_t FlipHeading = 0;
     int32_t diff = 0;
     int32_t diff2 = 0;
 
     int32_t diffAbs = 0;
     int32_t diffAbs2 = 0;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     newHeading = ActualHeading;
 
     diff = newHeading - LastHeading;
@@ -3409,6 +3756,7 @@
 
     LastHeading = newHeading;
     ActualHeading = newHeading;
+    ActualHeadingRose = ActualHeading;
 /*
     if (ActualHeading < 90)
         ActualHeading += 360;
@@ -3425,20 +3773,42 @@
             ActualHeading = LastHeading - 1;
     }
 */
-    if (ActualHeading < 90)
-        ActualHeading += 360;
+    if(pSettings->FlipDisplay)
+    {
+    	ActualHeadingRose = 360 - ActualHeadingRose;
+    	if (ActualHeadingRose < 170) ActualHeadingRose += 360;
+    }
+    else
+    {
+    	if (ActualHeadingRose < 90) ActualHeadingRose += 360;
+    	ActualHeading = ActualHeadingRose;
+    }
 
     // new hw 160822
 //	if (ActualHeading >= 360 + 90)
 //		ActualHeading = 360;
 
-    LeftBorderHeading = 2 * (ActualHeading - (CUSTOMBOX_SPACE_INSIDE/4));
+    LeftBorderHeading = 2 * (ActualHeadingRose - (CUSTOMBOX_SPACE_INSIDE/4));
+
+    if(pSettings->FlipDisplay) /* add offset caused by mirrowed drawing */
+    {
+    	LeftBorderHeading += 2 * 80;
+    }
 
     offsetPicture = LeftBorderHeading * t7screenCompass.ImageHeight * 2;
 
+/* the background is used to draw the rotating compass rose */
     background.pointer = t7screenCompass.FBStartAdress+offsetPicture;
     background.x0 = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
-    background.y0 = 65;
+    if(!pSettings->FlipDisplay)
+    {
+    	background.y0 = 65;
+    }
+    else
+    {
+    	background.y0 = 480 - t7screenCompass.ImageHeight - 65;
+    }
+
     background.width = CUSTOMBOX_SPACE_INSIDE;
     background.height = t7screenCompass.ImageHeight;
 
@@ -3644,10 +4014,21 @@
 void t7_miniLiveLogProfile(void)
 {
     SWindowGimpStyle wintemp;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     wintemp.left = CUSTOMBOX_LINE_LEFT + CUSTOMBOX_INSIDE_OFFSET;
     wintemp.right = wintemp.left + CUSTOMBOX_SPACE_INSIDE;
-    wintemp.top = 480 - t7l1.WindowY0;
-    wintemp.bottom = wintemp. top + 200;
+    if(!pSettings->FlipDisplay)
+    {
+    	wintemp.top = 480 - t7l1.WindowY0;
+    	wintemp.bottom = wintemp. top + 200;
+    }
+    else
+    {
+    	wintemp.top = t7l1.WindowY1;
+    	wintemp.bottom = wintemp. top + 200;
+    }
 
     uint16_t max_depth = (uint16_t)(stateUsed->lifeData.max_depth_meter * 10);
 
@@ -3657,8 +4038,19 @@
 void t7_logo_OSTC(void)
 {
     SWindowGimpStyle windowGimp;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     /* OSTC logo */
-    windowGimp.left = t7l1.WindowX1 + 32;
+	if(!pSettings->FlipDisplay)
+	{
+		windowGimp.left = t7l1.WindowX1 + 32;
+	}
+	else
+	{
+		windowGimp.left = t7r1.WindowX1 + 32;
+	}
+
     windowGimp.top = 40 + 32;
     GFX_draw_image_monochrome(&t7screen, windowGimp, &ImgOSTC, 0);
 }
--- a/Discovery/Src/tInfoLog.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/tInfoLog.c	Thu Jan 03 19:59:36 2019 +0100
@@ -80,8 +80,16 @@
     INFOLOGwindow.WindowTab = 400;
     INFOLOGwindow.WindowX0 = 20;
     INFOLOGwindow.WindowX1 = 779;
-    INFOLOGwindow.WindowY0 = 4 + 25;
-    INFOLOGwindow.WindowY1 = 390 + 25;
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+    	INFOLOGwindow.WindowY0 = 4 + 25;
+    	INFOLOGwindow.WindowY1 = 390 + 25;
+    }
+    else
+    {
+    	INFOLOGwindow.WindowY0 = 479 - 390;
+    	INFOLOGwindow.WindowY1 = 479 - 25;
+    }
 }
 
 
@@ -209,7 +217,16 @@
     {
         infolog.line = 0;
         infolog.modeFlipPages = 1;
-        GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 25, 800, 390);
+
+        if(!settingsGetPointer()->FlipDisplay)
+        {
+        	GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 25, 800, 390);
+        }
+        else
+        {
+        	GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 65, 800, 390);
+        }
+
     }
     else
         exitLog();
@@ -367,7 +384,14 @@
 
     infolog.modeFlipPages = 0;
 
-    GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+    	GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
+    }
+    else
+    {
+    	GFX_SetFrameBottom((pMenuCursor->FBStartAdress)+ (390 - 65 *(infolog.line)) *2, 0, 480-390-25, 800, 390);
+    }
 }
 
 
--- a/Discovery/Src/tMenu.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/tMenu.c	Thu Jan 03 19:59:36 2019 +0100
@@ -49,7 +49,12 @@
 #include "tMenuXtra.h"
 
 /* Private types -------------------------------------------------------------*/
-#define MAXPAGES 10
+#define MAXPAGES 		10
+#define CURSOR_HIGH 	25
+#define TAB_HEADER_HIGH	25
+#define TAB_BAR_HIGH	5
+#define MENU_WDW_HIGH	390
+#define KEY_LABEL_HIGH	25	/* Height of the label used for the the user keys */
 
 typedef struct
 {
@@ -123,6 +128,9 @@
 {
     uint8_t i;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     tMdesignCursor.FBStartAdress = getFrame(3);
     tMdesignCursor.ImageHeight = 390;
     tMdesignCursor.ImageWidth = 800;
@@ -155,9 +163,17 @@
     tMwindow.WindowTab = 400;
     tMwindow.WindowX0 = 20;
     tMwindow.WindowX1 = 779;
-    tMwindow.WindowY0 = 4 + 25;
-    tMwindow.WindowY1 = 390 + 25;
 
+    if(!pSettings->FlipDisplay)
+    {
+		tMwindow.WindowY0 = 4 + KEY_LABEL_HIGH;
+		tMwindow.WindowY1 = 390 + KEY_LABEL_HIGH;
+    }
+    else
+    {
+		tMwindow.WindowY0 = 480 - MENU_WDW_HIGH - TAB_HEADER_HIGH;// - TAB_BAR_HIGH;
+		tMwindow.WindowY1 = 480 - TAB_HEADER_HIGH - TAB_BAR_HIGH;
+    }
     actual_menu_content = MENU_UNDEFINED;
 }
 
@@ -196,8 +212,7 @@
     tM_rebuild_pages();
 }
 
-#
-    void tM_check_content(void)
+void tM_check_content(void)
 {
     uint8_t mode = 0;
 
@@ -272,19 +287,19 @@
     localtext[0] = TXT_2BYTE;
     localtext[1] = TXT2BYTE_ButtonBack;
     localtext[2] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 
     localtext[0] = '\001';
     localtext[1] = TXT_2BYTE;
     localtext[2] = TXT2BYTE_ButtonEnter;
     localtext[3] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 
     localtext[0] = '\002';
     localtext[1] = TXT_2BYTE;
     localtext[2] = TXT2BYTE_ButtonNext;
     localtext[3] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 
 //	gfx_write_page_number(&tMscreen ,menu.pageCountNumber[page],menu.pageCountTotal,0);
 
@@ -388,19 +403,19 @@
     localtext[0] = TXT_2BYTE;
     localtext[1] = TXT2BYTE_ButtonBack;
     localtext[2] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 
     localtext[0] = '\001';
     localtext[1] = TXT_2BYTE;
     localtext[2] = TXT2BYTE_ButtonEnter;
     localtext[3] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 
     localtext[0] = '\002';
     localtext[1] = TXT_2BYTE;
     localtext[2] = TXT2BYTE_ButtonNext;
     localtext[3] = 0;
-    write_content_simple(&tMscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+    write_content_simple(&tMscreen, 0, 800, 480-KEY_LABEL_HIGH, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
 }
 
 /*
@@ -782,6 +797,8 @@
 void openMenu(uint8_t freshWithFlipPages)
 {
     uint8_t page, line;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
 
     callerID = get_globalState();
 
@@ -818,10 +835,24 @@
 
     GFX_SetFrameTop(menu.StartAddressForPage[page]);
     /* new test for 3button design */
-    if(freshWithFlipPages)
-        GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+
+    if(!pSettings->FlipDisplay)
+    {
+		if(freshWithFlipPages)
+			GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+		else
+			GFX_SetFrameBottom((tMdesignCursor.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    }
     else
-        GFX_SetFrameBottom((tMdesignCursor.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    {
+		if(freshWithFlipPages)
+		{
+			GFX_SetFrameBottom((tMdesignSolo.FBStartAdress), 0, 480-390-KEY_LABEL_HIGH, 800, 390); //- (25 * 2 * 800), 0, 25, 800, 390);
+		}
+		else
+			GFX_SetFrameBottom((tMdesignCursor.FBStartAdress + (390 - 65 *(line)) *2), 0,480-390-KEY_LABEL_HIGH, 800, 390); //480-390-KEY_LABEL_HIGH + 65*2*(line - 1)
+    }
+
 }
 
 void block_diluent_handler(_Bool Unblock)
@@ -857,6 +888,9 @@
 {
     uint8_t page, line;
 
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
     menu.pageMemoryForNavigation += 1;
 
     findValidPosition(&page, &line);
@@ -873,14 +907,23 @@
 
     GFX_SetFrameTop(menu.StartAddressForPage[page]);
     /* new test for 3button design */
-    //GFX_SetFrameBottom((tMdesignCursor.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
-    GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+    //GFX_SetFrameBottom((.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    if(!pSettings->FlipDisplay)
+    {
+    	GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+    }
+    else
+    {
+    	GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 65, 800, 390);
+    }
 }
 
 
 void nextLine(void)
 {
     uint8_t page, line;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
 
     page = menu.pageMemoryForNavigation;
     menu.lineMemoryForNavigationForPage[page] += 1;
@@ -890,8 +933,14 @@
 
     /* new test for 3button design */
     menu.modeFlipPages = 0;
-
-    GFX_SetFrameBottom((tMdesignCursor.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    if(!pSettings->FlipDisplay)
+    {
+    	GFX_SetFrameBottom((tMdesignCursor.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    }
+    else
+    {
+    	GFX_SetFrameBottom((tMdesignCursor.FBStartAdress)+ (390 - 65 *(line)) *2, 0, 480-390-KEY_LABEL_HIGH, 800, 390);
+    }
 }
 
 
@@ -901,10 +950,19 @@
     {
         menu.lineMemoryForNavigationForPage[menu.pageMemoryForNavigation] = 0;
         menu.modeFlipPages = 1;
-        GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+        if(!settingsGetPointer()->FlipDisplay)
+        {
+        	GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 25, 800, 390);
+        }
+		else
+		{
+			GFX_SetFrameBottom(tMdesignSolo.FBStartAdress, 0, 480-390-KEY_LABEL_HIGH, 800, 390);
+		}
     }
     else
+    {
         exitMenu();
+    }
 }
 
 
@@ -1023,6 +1081,8 @@
         uint16_t al88;
     };
 
+    uint16_t* prunning = *ppDestination;
+
     union al88_u color_seperator;
     union al88_u color_unselected;
     int i;
@@ -1033,21 +1093,18 @@
     color_seperator.al8[1] = 0xFF;
     color_unselected.al8[1] = 0xFF;
 
-    *(__IO uint16_t*)*ppDestination = color_seperator.al88;
-        *ppDestination += 2;
-    *(__IO uint16_t*)*ppDestination = color_seperator.al88;
-        *ppDestination += 2;
+    *(__IO uint16_t*)prunning++ = color_seperator.al88;
+    *(__IO uint16_t*)prunning++ = color_seperator.al88;
 
     for(i = 61; i > 0; i--)
     {
-        *(__IO uint16_t*)*ppDestination = color_unselected.al88;
-        *ppDestination += 2;
+        *(__IO uint16_t*)prunning++ = color_unselected.al88;
     }
 
-    *(__IO uint16_t*)*ppDestination = color_seperator.al88;
-        *ppDestination += 2;
-    *(__IO uint16_t*)*ppDestination = color_seperator.al88;
-        *ppDestination += 2;
+    *(__IO uint16_t*)prunning++ = color_seperator.al88;
+    *(__IO uint16_t*)prunning++ = color_seperator.al88;
+
+    *ppDestination = prunning;
 }
 
 
@@ -1129,6 +1186,7 @@
             draw_tMdesignSubSelected(&pDestination);
     }
 
+/* Draw menu background boxes which are visible if nothing is selected */
     pDestination = tMdesignSolo.FBStartAdress;
 
     for(j = 801; j > 0; j--)
@@ -1151,7 +1209,7 @@
     union al88_u color_top;
     int i,j, k, k4text;
     uint32_t pBackup;
-    uint32_t pDestination;
+    uint16_t* pDestination;
     uint8_t colorText;
     uint16_t positionText;
     uint8_t pageText;
@@ -1230,35 +1288,67 @@
             if((text8max[k][0] == 0) && (menu.pageCountNumber[k-1] == 0))
                 write_content_simple(&tMscreen,positionText,775,0,&FontT42,text8max[k-1],colorText);
     */
-            pDestination += 2 * 5 * 480;
+/* Draw color bars */
+            if(!settingsGetPointer()->FlipDisplay)
+            {
+				pDestination +=  5 * 480;
 
-            for(j = 60; j > 0; j--)
-            {
-                pDestination += (390 + 26)* 2;
+					for(j = 60; j > 0; j--)
+					{
+						pDestination += (390 + 26);
 
-//				for(i = 64; i > 0; i--)
-                for(i = 16; i > 0; i--)
-                {
-                *(__IO uint16_t*)pDestination = color_top.al88;
-                    pDestination += 2;
-                }
-                pDestination += 2 * 48;
-            }
+						for(i = 16; i > 0; i--)
+						{
+							*(__IO uint16_t*)pDestination++ = color_top.al88;
+						}
+						pDestination += 48;
+					}
+
+					pDestination += 5 * 480;
+					positionText += 70;
+
+					if((k == 4) || ((k == 6) && (menu.pageCountNumber[5] == 0)))
+					{
+						pDestination += 70 * 480;
+						positionText += 70;
+					}
 
-            pDestination += 2 * 5 * 480;
-            positionText += 70;
+					if(spacing[k])
+					{
+						pDestination += 35 * 480;
+						positionText += 35;
+					}
+				}
+			else
+			{
+				pDestination += (800 - 5)* 480;
+
+				for(j = 60; j > 0; j--)
+				{
+					pDestination -= (390 + 26);
 
-            if((k == 4) || ((k == 6) && (menu.pageCountNumber[5] == 0)))
-            {
-                pDestination += 2 * 70 * 480;
-                positionText += 70;
-            }
+					for(i = 16; i > 0; i--)
+					{
+					*(__IO uint16_t*)pDestination-- = color_top.al88;
+					}
+					pDestination -= 48;
+				}
+
+				pDestination -= (800) * 480;
+				positionText += 70;
 
-            if(spacing[k])
-            {
-                pDestination += 35 * 2 * 480;
-                positionText += 35;
-            }
+				if((k == 4) || ((k == 6) && (menu.pageCountNumber[5] == 0)))
+				{
+					pDestination -= 70 * 480;
+					positionText += 70;
+				}
+
+				if(spacing[k])
+				{
+					pDestination -= 35 * 480;
+					positionText += 35;
+				}
+			}
         }
     }
     tMscreen.FBStartAdress = pBackup;
--- a/Discovery/Src/tMenuEdit.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/tMenuEdit.c	Thu Jan 03 19:59:36 2019 +0100
@@ -186,7 +186,14 @@
     uint8_t line = 1;
 //	GFX_SetFramesTopBottom(tMEscreen.FBStartAdress, (tMEcursorNew.FBStartAdress) + 65*2*(line - 1),390);
     GFX_SetFrameTop(tMEscreen.FBStartAdress);
-    GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+    	GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
+    }
+    else
+    {
+    	GFX_SetFrameBottom((tMEcursorNew.FBStartAdress)+ (390 - 65 *(line)) *2, 0, 480-390-25, 800, 390);
+    }
 }
 
 
@@ -1592,15 +1599,29 @@
     int16_t y0;
     uint8_t lineMinusOne;
 
-    y0 = (int16_t)ident[forThisIdentID].coord[2];
-
+   if(!settingsGetPointer()->FlipDisplay)
+   {
+	   y0 = (int16_t)ident[forThisIdentID].coord[2];
+	}
+	else
+	{
+    	y0 = 390 - (int16_t)ident[forThisIdentID].coord[2];
+	}
     y0 -= ME_Y_LINE1;
     y0 /= ME_Y_LINE_STEP;
     if((y0 >= 0) && (y0 <=5))
         lineMinusOne = y0;
     else
         lineMinusOne = 0;
-    GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(lineMinusOne), 0, 25, 800, 390);
+
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+    	GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(lineMinusOne), 0, 25, 800, 390);
+    }
+    else
+    {
+    	GFX_SetFrameBottom((tMEcursorNew.FBStartAdress)+ (390 - 65 *(5-lineMinusOne-1)) *2, 0, 480-390-25, 800, 390);
+    }
 }
 
 
@@ -1615,16 +1636,34 @@
     hgfx.WindowTab = 0;
     hgfx.WindowX0 = 20;
     hgfx.WindowX1 = 779;
-    hgfx.WindowY1 = 479;
-    hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+		hgfx.WindowY1 = 479;
+		hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+    }
+	else
+	{
+		hgfx.WindowY0 = 0;
+		hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+	}
     GFX_write_label(Font, &hgfx, text, menuColor);
 }
 
 
 void write_buttonTextline( uint8_t left2ByteCode, char middle2ByteCode, char right2ByteCode)
 {
-    GFX_clean_area(&tMEscreen, 0, 800, 480-24,480);
+
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
+
+	if(!pSettings->FlipDisplay)
+	{
+		GFX_clean_area(&tMEscreen, 0, 800, 480-24,480);
+	}
+	else
+	{
+		GFX_clean_area(&tMEscreen, 0, 800, 0, 24);
+	}
 
     char localtext[32];
 
@@ -1633,7 +1672,14 @@
         localtext[0] = TXT_2BYTE;
         localtext[1] = left2ByteCode;
         localtext[2] = 0;
-        write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        if(!pSettings->FlipDisplay)
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
+        else
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 0, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
     }
 
     if(middle2ByteCode)
@@ -1642,7 +1688,14 @@
         localtext[1] = TXT_2BYTE;
         localtext[2] = middle2ByteCode;
         localtext[3] = 0;
-        write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        if(!pSettings->FlipDisplay)
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
+        else
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 0, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
     }
 
     if(right2ByteCode)
@@ -1651,7 +1704,14 @@
         localtext[1] = TXT_2BYTE;
         localtext[2] = right2ByteCode;
         localtext[3] = 0;
-        write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        if(!pSettings->FlipDisplay)
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
+        else
+        {
+        	write_content_simple(&tMEscreen, 0, 800, 0, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
+        }
     }
 }
 
@@ -1671,14 +1731,26 @@
     hgfx.WindowNumberOfTextLines = 1;
     hgfx.WindowLineSpacing = 0;
     hgfx.WindowTab = 0;
-    hgfx.WindowX0 = XleftGimpStyle;
-    hgfx.WindowX1 = XrightGimpStyle;
-    hgfx.WindowY1 = 479 - YtopGimpStyle;
-    if(hgfx.WindowY1 < Font->height)
-        hgfx.WindowY0 = 0;
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+    }
     else
-        hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+    {
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 < Font->height)
+			hgfx.WindowY1 = 0;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+    }
     GFX_write_label(Font, &hgfx, text, 0);/*menuColor);*/
 }
 
@@ -1697,14 +1769,27 @@
     hgfx.WindowNumberOfTextLines = 1;
     hgfx.WindowLineSpacing = 0;
     hgfx.WindowTab = 0;
-    hgfx.WindowX0 = XleftGimpStyle;
-    hgfx.WindowX1 = XrightGimpStyle;
-    hgfx.WindowY1 = 479 - YtopGimpStyle;
-    if(hgfx.WindowY1 < Font->height)
-        hgfx.WindowY0 = 0;
+
+    if(!settingsGetPointer()->FlipDisplay)
+    {
+		hgfx.WindowX0 = XleftGimpStyle;
+		hgfx.WindowX1 = XrightGimpStyle;
+		hgfx.WindowY1 = 479 - YtopGimpStyle;
+		if(hgfx.WindowY1 < Font->height)
+			hgfx.WindowY0 = 0;
+		else
+			hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
+    }
     else
-        hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+    {
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 < Font->height)
+			hgfx.WindowY1 = 0;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+    }
     GFX_write_label(Font, &hgfx, text, color);
 }
 
@@ -1731,6 +1816,8 @@
     if(YtopGimpStyle > 479)
         YtopGimpStyle = 479;
     hgfx.Image = &tMEscreen;
+    if(!settingsGetPointer()->FlipDisplay)
+    {
     hgfx.WindowX0 = XleftGimpStyle;
     hgfx.WindowX1 = XrightGimpStyle;
     hgfx.WindowY1 = 479 - YtopGimpStyle;
@@ -1738,7 +1825,17 @@
         hgfx.WindowY0 = 0;
     else
         hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
-
+    }
+    else
+    {
+		hgfx.WindowX0 = 800 - XrightGimpStyle;
+		hgfx.WindowX1 = 800 - XleftGimpStyle;
+		hgfx.WindowY0 = YtopGimpStyle;
+		if(hgfx.WindowY0 < Font->height)
+			hgfx.WindowY1 = 0;
+		else
+			hgfx.WindowY1 = hgfx.WindowY0 + Font->height;
+    }
     GFX_clear_window_immediately(&hgfx);
 }
 
--- a/Discovery/Src/tMenuEditHardware.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/tMenuEditHardware.c	Thu Jan 03 19:59:36 2019 +0100
@@ -45,6 +45,7 @@
 //void openEdit_Luftintegration(void);
 void openEdit_ButtonSens(void);
 void openEdit_ScooterControl(void);
+void openEdit_FlipDisplay(void);
 
 /* Announced function prototypes -----------------------------------------------*/
 uint8_t OnAction_Compass		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
@@ -89,7 +90,14 @@
         openEdit_ButtonSens();
     break;
     case 6:
-        openEdit_ScooterControl();
+    	if(getLicence() == LICENCEBONEX)
+    	{
+    		openEdit_ScooterControl();
+    	}
+    	else
+    	{
+    		openEdit_FlipDisplay();
+    	}
     break;
     }
 }
@@ -114,6 +122,32 @@
     exitMenuEdit_to_Menu_with_Menu_Update_do_not_write_settings_for_this_only();
 }
 
+void openEdit_FlipDisplay(void)
+{
+/* does not work like this	resetEnterPressedToStateBeforeButtonAction(); */
+
+    SSettings *pSettings = settingsGetPointer();
+
+    if(pSettings->FlipDisplay == 0)
+    {
+        pSettings->FlipDisplay = 1;
+    }
+    else
+    {
+        pSettings->FlipDisplay = 0;
+    }
+    /* reinit all views */
+    tHome_init();
+    tI_init();
+    tM_init();
+    tMenuEdit_init();
+    tInfoLog_init();
+    tM_build_pages();
+
+
+    exitEditWithUpdate();
+    exitMenuEdit_to_Home();
+}
 /*
 void refresh_ScooterControl(void)
 {
@@ -470,7 +504,7 @@
 
 void refresh_O2Sensors(void)
 {
-    char text[10];
+    char text[16];
     uint16_t y_line;
 
     text[0] = '\001';
--- a/Discovery/Src/tMenuHardware.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/tMenuHardware.c	Thu Jan 03 19:59:36 2019 +0100
@@ -162,16 +162,32 @@
     }
     nextline(text,&textPointer);
 
-    if((getLicence() == LICENCEBONEX) &&((line == 0) || (line == 6)))
+    if((line == 0) || (line == 6))
     {
-        text[textPointer++] = TXT_2BYTE;
-        text[textPointer++] = TXT2BYTE_ScooterSetup;
-        text[textPointer++] = '\t';
+    	if(getLicence() == LICENCEBONEX)
+    	{
+			text[textPointer++] = TXT_2BYTE;
+			text[textPointer++] = TXT2BYTE_ScooterSetup;
+			text[textPointer++] = '\t';
 
-//		textPointer += snprintf(&text[textPointer],25,"D%i  L%i  ",settingsGetPointer()->scooterDrag, settingsGetPointer()->scooterLoad);
-        textPointer += snprintf(&text[textPointer],25,"D%i  L%i  %i\016\016 Wh\017",settingsGetPointer()->scooterDrag, settingsGetPointer()->scooterLoad, settingsGetPointer()->scooterBattSize);
-//		textPointer += bo4GetBatteryName(&text[textPointer], settingsGetPointer()->scooterBattType);
-        nextline(text,&textPointer);
+	//		textPointer += snprintf(&text[textPointer],25,"D%i  L%i  ",settingsGetPointer()->scooterDrag, settingsGetPointer()->scooterLoad);
+			textPointer += snprintf(&text[textPointer],25,"D%i  L%i  %i\016\016 Wh\017",settingsGetPointer()->scooterDrag, settingsGetPointer()->scooterLoad, settingsGetPointer()->scooterBattSize);
+	//		textPointer += bo4GetBatteryName(&text[textPointer], settingsGetPointer()->scooterBattType);
+			nextline(text,&textPointer);
+    	}
+    	else
+    	{
+            text[textPointer++] = TXT_2BYTE;
+            text[textPointer++] = TXT2BYTE_FLIPDISPLAY;
+            text[textPointer++] = '\t';
+            if(settingsGetPointer()->FlipDisplay)
+                text[textPointer++] = '\005';
+            else
+                text[textPointer++] = '\006';
+            text[textPointer] = 0;
+            nextline(text,&textPointer);
+    	}
     }
+
     return StMHARD;
 }
--- a/Discovery/Src/text_multilanguage.c	Mon Dec 24 16:19:09 2018 +0300
+++ b/Discovery/Src/text_multilanguage.c	Thu Jan 03 19:59:36 2019 +0100
@@ -1651,6 +1651,12 @@
 static uint8_t text_ES_Luftintegration[] = "aire integrado";
 */
 
+static uint8_t text_EN_FlipDisplay[] = "Flip display";
+static uint8_t text_DE_FlipDisplay[] = "Anzeige spiegeln";
+static uint8_t text_FR_FlipDisplay[] = "";
+static uint8_t text_IT_FlipDisplay[] = "";
+static uint8_t text_ES_FlipDisplay[] = "";
+
 /* Lookup Table -------------------------------------------------------------*/
 
 const tText text_array[] =
@@ -1891,6 +1897,9 @@
     {(uint8_t)TXT2BYTE_ApneaTotal,		{text_EN_ApneaTotal, text_DE_ApneaTotal, text_FR_ApneaTotal, text_IT_ApneaTotal, text_ES_ApneaTotal}},
     {(uint8_t)TXT2BYTE_ApneaSurface,	{text_EN_ApneaSurface, text_DE_ApneaSurface, text_FR_ApneaSurface, text_IT_ApneaSurface, text_ES_ApneaSurface}},
 
+	{(uint8_t)TXT2BYTE_FLIPDISPLAY,		{text_EN_FlipDisplay, text_DE_FlipDisplay, text_FR_FlipDisplay, text_IT_FlipDisplay, text_ES_FlipDisplay}},
+
+
 //	{(uint8_t)TXT2BYTE_ApneaCount,          {text_EN_ApneaCount, text_DE_ApneaCount, text_FR_ApneaCount, text_IT_ApneaCount, text_ES_ApneaCount}},
     // unused {(uint8_t)TXT2BYTE_Button1,	{text_EN_Button1, text_DE_Button1, text_FR_Button1, text_IT_Button1, text_ES_Button1}},
     // unused {(uint8_t)TXT2BYTE_Button2,	{text_EN_Button2, text_DE_Button2, text_FR_Button2, text_IT_Button2, text_ES_Button2}},
Binary file ostc4pack/OSTC4_Firmware.bin has changed
Binary file ostc4pack/OSTC4_RTE.bin has changed
Binary file ostc4pack/OSTC4_RTE_upload.bin has changed
Binary file ostc4pack/OSTC4_firmware_upload.bin has changed