comparison Discovery/Src/base.c @ 217:ce05c801b002 Improve_IPC_Sync

Moved display refresh and button action function from tim callback to main loop The update of the display, especially for log book pages, may take some time causing problem because the execution of other functions (like SPI) was shifted => SPI errors.
author ideenmodellierer
date Sun, 31 Mar 2019 15:39:44 +0200
parents 0bb6a8e7be9d
children 5f535ef6a3db
comparison
equal deleted inserted replaced
216:7012a521fa95 217:ce05c801b002
290 uint8_t returnFromCommCleanUpRequest = 0; ///< use this to exit bluetooth mode and call tComm_exit() 290 uint8_t returnFromCommCleanUpRequest = 0; ///< use this to exit bluetooth mode and call tComm_exit()
291 uint32_t base_tempLightLevel = 0; 291 uint32_t base_tempLightLevel = 0;
292 uint8_t updateButtonsToDefault = 0; 292 uint8_t updateButtonsToDefault = 0;
293 uint8_t wasFirmwareUpdateCheckBattery = 0; 293 uint8_t wasFirmwareUpdateCheckBattery = 0;
294 294
295 static DoDisplayRefresh = 0; /* trigger to refresh display data */
296
295 /* Private function prototypes -----------------------------------------------*/ 297 /* Private function prototypes -----------------------------------------------*/
296 static void SystemClock_Config(void); 298 static void SystemClock_Config(void);
297 static void Error_Handler(void); 299 static void Error_Handler(void);
298 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); 300 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command);
299 static void SDRAM_Config(void); 301 static void SDRAM_Config(void);
302 static void TIM_BACKLIGHT_init(void); 304 static void TIM_BACKLIGHT_init(void);
303 static uint32_t TIM_BACKLIGHT_adjust(void); 305 static uint32_t TIM_BACKLIGHT_adjust(void);
304 static void gotoSleep(void); 306 static void gotoSleep(void);
305 static void deco_loop(void); 307 static void deco_loop(void);
306 static void resetToFirmwareUpdate(void); 308 static void resetToFirmwareUpdate(void);
307 void EvaluateButton(void); 309 static void TriggerButtonAction(void);
310 static void EvaluateButton(void);
311 static void RefreshDisplay(void);
308 312
309 /* ITM Trace-------- ---------------------------------------------------------*/ 313 /* ITM Trace-------- ---------------------------------------------------------*/
310 /* 314 /*
311 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) 315 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
312 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) 316 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
493 createDiveSettings(); 497 createDiveSettings();
494 updateMenu(); 498 updateMenu();
495 ext_flash_write_settings(); 499 ext_flash_write_settings();
496 } 500 }
497 deco_loop(); 501 deco_loop();
502 TriggerButtonAction();
503 if(DoDisplayRefresh)
504 {
505 DoDisplayRefresh = 0;
506 RefreshDisplay();
507 }
498 508
499 #ifdef DEBUG_RUNTIME 509 #ifdef DEBUG_RUNTIME
500 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime); 510 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime);
501 if(lastsecond == 0xFF) 511 if(lastsecond == 0xFF)
502 { 512 {
754 } 764 }
755 } 765 }
756 766
757 get_globalStateList(&status); 767 get_globalStateList(&status);
758 768
759 switch(status.base) 769 if(status.base == BaseComm) /* main loop not serviced in com mode */
760 { 770 {
761 case BaseHome: 771 tComm_refresh();
762 tHome_refresh(); 772 }
763 tM_check_content(); 773 else
764 break; 774 {
765 case BaseMenu: 775 DoDisplayRefresh = 1;
766 tM_refresh_live_content();
767 tMenuEdit_refresh_live_content();
768 break;
769 case BaseInfo:
770 tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
771 break;
772 case BaseComm:
773 tComm_refresh();
774 break;
775 default:
776 if(get_globalState() == StStop)
777 tHome_sleepmode_fun();
778 break;
779 } 776 }
780 } 777 }
781 778
782 779
783 /* button and VSYNC IRQ 780 /* button and VSYNC IRQ
828 GPIO_Pin &= 0x7F; 825 GPIO_Pin &= 0x7F;
829 } 826 }
830 #endif 827 #endif
831 } 828 }
832 829
833 void EvaluateButton() 830 static void RefreshDisplay()
834 { 831 {
835 uint8_t action = 0;
836 SStateList status; 832 SStateList status;
837 SSettings* pSettings; 833 get_globalStateList(&status);
838 pSettings = settingsGetPointer(); 834 switch(status.base)
839
840 if (GFX_logoStatus() != 0)
841 return;
842
843 if ((LastButtonPressed != INVALID_BUTTON) && (time_elapsed_ms(LastButtonPressedTick, HAL_GetTick())) > 50)
844 { 835 {
845 if (LastButtonPressed == BUTTON_BACK_PIN) { // links 836 case BaseHome:
846 if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) { 837 tHome_refresh();
847 action = ACTION_BUTTON_BACK; 838 tM_check_content();
848 } 839 break;
849 } 840 case BaseMenu:
850 841 tM_refresh_live_content();
851 else if (LastButtonPressed == BUTTON_ENTER_PIN) { // mitte 842 tMenuEdit_refresh_live_content();
852 if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) { 843 break;
853 action = ACTION_BUTTON_ENTER; 844 case BaseInfo:
854 } 845 tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
855 } 846 break;
856 847 case BaseComm: /* refresh already done in tim callback */
857 else if (LastButtonPressed == BUTTON_NEXT_PIN) { // rechts 848 break;
858 if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) { 849 default:
859 action = ACTION_BUTTON_NEXT; 850 if(get_globalState() == StStop)
860 } 851 tHome_sleepmode_fun();
861 } 852 break;
862 853 }
863 if(action != 0) 854 }
864 { 855 static uint8_t ButtonAction = ACTION_END;
865 time_without_button_pressed_deciseconds = 0; 856
866 if(pSettings->FlipDisplay) /* switch action resulting from pressed button */ 857 static void StoreButtonAction(uint8_t action)
867 { 858 {
868 if (action == ACTION_BUTTON_BACK) 859 ButtonAction = action;
869 { 860 }
870 action = ACTION_BUTTON_NEXT; 861
871 } 862 static void TriggerButtonAction()
872 else 863 {
873 { 864 uint8_t action = ButtonAction;
874 if (action == ACTION_BUTTON_NEXT) 865 SStateList status;
875 { 866
876 action = ACTION_BUTTON_BACK; 867 if(ButtonAction != ACTION_END)
877 } 868 {
878 }
879 }
880 }
881
882 #ifdef BUTTON_CUSTOM_PIN
883 else
884 if(LastButtonPressed == BUTTON_CUSTOM_PIN) // extra
885 action = ACTION_BUTTON_CUSTOM;
886 #endif
887
888 #ifdef DEMOMODE // user pressed button ?
889 if((!demoMachineCall) && demoModeActive())
890 {
891 demoSendCommand(action);
892 return;
893 }
894 #endif
895
896 get_globalStateList(&status); 869 get_globalStateList(&status);
897 870
898 if (action == ACTION_BUTTON_CUSTOM) { 871 if (action == ACTION_BUTTON_CUSTOM) {
899 GFX_screenshot(); 872 GFX_screenshot();
900 } 873 }
902 switch (status.base) { 875 switch (status.base) {
903 case BaseStop: 876 case BaseStop:
904 if (action == ACTION_BUTTON_BACK) 877 if (action == ACTION_BUTTON_BACK)
905 resetToFirmwareUpdate(); 878 resetToFirmwareUpdate();
906 break; 879 break;
907 case BaseComm: 880 case BaseComm: /* already handled in tim callback */
908 if (action == ACTION_BUTTON_BACK) {
909 settingsGetPointer()->bluetoothActive = 0;
910 MX_Bluetooth_PowerOff();
911 tComm_exit();
912 }
913 break; 881 break;
914 case BaseHome: 882 case BaseHome:
915 if (action == ACTION_BUTTON_NEXT) { 883 if (action == ACTION_BUTTON_NEXT) {
916 if (status.page == PageSurface) 884 if (status.page == PageSurface)
917 openMenu(1); 885 openMenu(1);
959 sendActionToInfo(action); 927 sendActionToInfo(action);
960 break; 928 break;
961 929
962 default: 930 default:
963 break; 931 break;
932 }
933 ButtonAction = ACTION_END;
934 }
935 }
936
937
938 void EvaluateButton()
939 {
940 uint8_t action = 0;
941 SStateList status;
942 SSettings* pSettings;
943 pSettings = settingsGetPointer();
944
945 if (GFX_logoStatus() != 0)
946 return;
947
948 if ((LastButtonPressed != INVALID_BUTTON) && (time_elapsed_ms(LastButtonPressedTick, HAL_GetTick())) > 50)
949 {
950 if (LastButtonPressed == BUTTON_BACK_PIN) { // links
951 if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) {
952 action = ACTION_BUTTON_BACK;
953 }
954 }
955
956 else if (LastButtonPressed == BUTTON_ENTER_PIN) { // mitte
957 if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) {
958 action = ACTION_BUTTON_ENTER;
959 }
960 }
961
962 else if (LastButtonPressed == BUTTON_NEXT_PIN) { // rechts
963 if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) {
964 action = ACTION_BUTTON_NEXT;
965 }
966 }
967
968 if(action != 0)
969 {
970 time_without_button_pressed_deciseconds = 0;
971 if(pSettings->FlipDisplay) /* switch action resulting from pressed button */
972 {
973 if (action == ACTION_BUTTON_BACK)
974 {
975 action = ACTION_BUTTON_NEXT;
976 }
977 else
978 {
979 if (action == ACTION_BUTTON_NEXT)
980 {
981 action = ACTION_BUTTON_BACK;
982 }
983 }
984 }
985 }
986
987 #ifdef BUTTON_CUSTOM_PIN
988 else
989 if(LastButtonPressed == BUTTON_CUSTOM_PIN) // extra
990 action = ACTION_BUTTON_CUSTOM;
991 #endif
992
993 #ifdef DEMOMODE // user pressed button ?
994 if((!demoMachineCall) && demoModeActive())
995 {
996 demoSendCommand(action);
997 return;
998 }
999 #endif
1000
1001 get_globalStateList(&status);
1002 if(status.base == BaseComm) /* main loop is not serviced in comm mode => react immediately */
1003 {
1004 if (action == ACTION_BUTTON_BACK) {
1005 settingsGetPointer()->bluetoothActive = 0;
1006 MX_Bluetooth_PowerOff();
1007 tComm_exit();
1008 }
1009 }
1010 else
1011 {
1012 StoreButtonAction(action); /* Handle action in main loop */
964 } 1013 }
965 LastButtonPressed = INVALID_BUTTON; 1014 LastButtonPressed = INVALID_BUTTON;
966 } 1015 }
967 } 1016 }
968 1017