Mercurial > public > ostc4
comparison Discovery/Src/base.c @ 152:bc7795161549 FlipDisplay
Moved button evaluation out of interrupt handler
author | Ideenmodellierer |
---|---|
date | Sun, 03 Mar 2019 12:18:44 +0100 |
parents | e1d66bc78f9a |
children | a16ce69f8a86 |
comparison
equal
deleted
inserted
replaced
151:a98f91cca107 | 152:bc7795161549 |
---|---|
251 | 251 |
252 /* Private define ------------------------------------------------------------*/ | 252 /* Private define ------------------------------------------------------------*/ |
253 //#define BUFFER_SIZE ((uint32_t)0x00177000) | 253 //#define BUFFER_SIZE ((uint32_t)0x00177000) |
254 //#define WRITE_READ_ADDR ((uint32_t)0x0000) | 254 //#define WRITE_READ_ADDR ((uint32_t)0x0000) |
255 #define REFRESH_COUNT ((uint32_t)0x0569) /**< for SDRAM refresh counter (90Mhz SD clock) */ | 255 #define REFRESH_COUNT ((uint32_t)0x0569) /**< for SDRAM refresh counter (90Mhz SD clock) */ |
256 | 256 #define INVALID_BUTTON ((uint8_t) 0xFF) |
257 /* Private macro -------------------------------------------------------------*/ | 257 /* Private macro -------------------------------------------------------------*/ |
258 /* Private variables ---------------------------------------------------------*/ | 258 /* Private variables ---------------------------------------------------------*/ |
259 | 259 |
260 RTC_HandleTypeDef RtcHandle; /* used to change time and date, no RTC is running on this MCU */ | 260 RTC_HandleTypeDef RtcHandle; /* used to change time and date, no RTC is running on this MCU */ |
261 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ | 261 TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ |
262 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ | 262 TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ |
263 TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */ | 263 TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */ |
264 | |
265 uint8_t LastButtonPressed; | |
266 uint32_t LastButtonPressedTick; | |
264 | 267 |
265 /* | 268 /* |
266 uint32_t time_before; | 269 uint32_t time_before; |
267 uint32_t time_between; | 270 uint32_t time_between; |
268 uint32_t time_after; | 271 uint32_t time_after; |
288 uint32_t base_tempLightLevel = 0; | 291 uint32_t base_tempLightLevel = 0; |
289 uint8_t updateButtonsToDefault = 0; | 292 uint8_t updateButtonsToDefault = 0; |
290 uint8_t wasFirmwareUpdateCheckBattery = 0; | 293 uint8_t wasFirmwareUpdateCheckBattery = 0; |
291 | 294 |
292 /* Private function prototypes -----------------------------------------------*/ | 295 /* Private function prototypes -----------------------------------------------*/ |
293 | |
294 static void SystemClock_Config(void); | 296 static void SystemClock_Config(void); |
295 static void Error_Handler(void); | 297 static void Error_Handler(void); |
296 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); | 298 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); |
297 static void SDRAM_Config(void); | 299 static void SDRAM_Config(void); |
298 static void EXTILine_Buttons_Config(void); | 300 static void EXTILine_Buttons_Config(void); |
300 static void TIM_BACKLIGHT_init(void); | 302 static void TIM_BACKLIGHT_init(void); |
301 static uint32_t TIM_BACKLIGHT_adjust(void); | 303 static uint32_t TIM_BACKLIGHT_adjust(void); |
302 static void gotoSleep(void); | 304 static void gotoSleep(void); |
303 static void deco_loop(void); | 305 static void deco_loop(void); |
304 static void resetToFirmwareUpdate(void); | 306 static void resetToFirmwareUpdate(void); |
307 void EvaluateButton(void); | |
305 | 308 |
306 /* ITM Trace-------- ---------------------------------------------------------*/ | 309 /* ITM Trace-------- ---------------------------------------------------------*/ |
307 /* | 310 /* |
308 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) | 311 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) |
309 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) | 312 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) |
345 uint8_t lastsecond = 0xFF; | 348 uint8_t lastsecond = 0xFF; |
346 #endif | 349 #endif |
347 | 350 |
348 | 351 |
349 set_globalState( StBoot0 ); | 352 set_globalState( StBoot0 ); |
353 LastButtonPressed = 0; | |
350 | 354 |
351 HAL_Init(); | 355 HAL_Init(); |
352 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 ); | 356 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 ); |
353 | 357 |
354 SystemClock_Config(); | 358 SystemClock_Config(); |
489 createDiveSettings(); | 493 createDiveSettings(); |
490 updateMenu(); | 494 updateMenu(); |
491 ext_flash_write_settings(); | 495 ext_flash_write_settings(); |
492 } | 496 } |
493 deco_loop(); | 497 deco_loop(); |
498 EvaluateButton(); | |
494 | 499 |
495 #ifdef DEBUG_RUNTIME | 500 #ifdef DEBUG_RUNTIME |
496 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime); | 501 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime); |
497 if(lastsecond == 0xFF) | 502 if(lastsecond == 0xFF) |
498 { | 503 { |
790 // =============================================================================== | 795 // =============================================================================== |
791 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { | 796 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
792 if (!GPIO_Pin) | 797 if (!GPIO_Pin) |
793 return; | 798 return; |
794 | 799 |
795 uint8_t action = 0; | |
796 SStateList status; | |
797 | |
798 if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | 800 if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten |
799 { | 801 { |
800 GFX_change_LTDC(); | 802 GFX_change_LTDC(); |
801 housekeepingFrame(); | 803 housekeepingFrame(); |
802 /* | 804 /* |
812 #endif | 814 #endif |
813 */ | 815 */ |
814 return; | 816 return; |
815 } | 817 } |
816 | 818 |
817 SSettings* pSettings; | 819 LastButtonPressed = GPIO_Pin; |
818 pSettings = settingsGetPointer(); | 820 LastButtonPressedTick = HAL_GetTick(); |
819 if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten | |
820 { | |
821 GFX_change_LTDC(); | |
822 housekeepingFrame(); | |
823 /* | |
824 #ifdef DEMOMODE | |
825 static uint8_t countCall = 0; | |
826 if(countCall++ < 10) | |
827 return; | |
828 countCall = 0; | |
829 uint8_t buttonAction = demoGetCommand(); | |
830 if(buttonAction) | |
831 GPIO_Pin = buttonAction; | |
832 else | |
833 #endif | |
834 */ | |
835 return; | |
836 } | |
837 | 821 |
838 #ifdef DEMOMODE | 822 #ifdef DEMOMODE |
839 uint8_t demoMachineCall = 0; | 823 uint8_t demoMachineCall = 0; |
840 if(GPIO_Pin & 0x80) | 824 if(GPIO_Pin & 0x80) |
841 { | 825 { |
842 demoMachineCall = 1; | 826 demoMachineCall = 1; |
843 GPIO_Pin &= 0x7F; | 827 GPIO_Pin &= 0x7F; |
844 } | 828 } |
845 #endif | 829 #endif |
846 | 830 } |
847 time_without_button_pressed_deciseconds = 0; | 831 |
832 void EvaluateButton() | |
833 { | |
834 uint8_t action = 0; | |
835 SStateList status; | |
836 SSettings* pSettings; | |
837 pSettings = settingsGetPointer(); | |
848 | 838 |
849 if (GFX_logoStatus() != 0) | 839 if (GFX_logoStatus() != 0) |
850 return; | 840 return; |
851 | 841 |
852 if (GPIO_Pin == BUTTON_BACK_PIN) { // links | 842 if ((LastButtonPressed != INVALID_BUTTON) && (time_elapsed_ms(LastButtonPressedTick, HAL_GetTick())) > 50) |
853 HAL_Delay(BUTTON_DEBOUNCE_DELAY); | 843 { |
854 if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) { | 844 if (LastButtonPressed == BUTTON_BACK_PIN) { // links |
855 action = ACTION_BUTTON_BACK; | 845 if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) { |
856 } | 846 action = ACTION_BUTTON_BACK; |
857 } | |
858 | |
859 else if (GPIO_Pin == BUTTON_ENTER_PIN) { // mitte | |
860 HAL_Delay(BUTTON_DEBOUNCE_DELAY); | |
861 if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) { | |
862 action = ACTION_BUTTON_ENTER; | |
863 } | |
864 } | |
865 | |
866 else if (GPIO_Pin == BUTTON_NEXT_PIN) { // rechts | |
867 HAL_Delay(BUTTON_DEBOUNCE_DELAY); | |
868 if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) { | |
869 action = ACTION_BUTTON_NEXT; | |
870 } | |
871 } | |
872 | |
873 if(GPIO_Pin == BUTTON_BACK_PIN) // links | |
874 { | |
875 if(!pSettings->FlipDisplay) | |
876 { | |
877 action = ACTION_BUTTON_BACK; | |
878 } | |
879 else | |
880 { | |
881 action = ACTION_BUTTON_NEXT; | |
882 } | |
883 } | |
884 else | |
885 { | |
886 if(GPIO_Pin == BUTTON_ENTER_PIN) // mitte | |
887 action = ACTION_BUTTON_ENTER; | |
888 else | |
889 { | |
890 if(GPIO_Pin == BUTTON_NEXT_PIN) // rechts | |
891 { | |
892 if(!pSettings->FlipDisplay) action = ACTION_BUTTON_NEXT; | |
893 else action = ACTION_BUTTON_BACK; | |
894 } | 847 } |
895 } | 848 } |
896 } | 849 |
897 #ifdef BUTTON_CUSTOM_PIN | 850 else if (LastButtonPressed == BUTTON_ENTER_PIN) { // mitte |
851 if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) { | |
852 action = ACTION_BUTTON_ENTER; | |
853 } | |
854 } | |
855 | |
856 else if (LastButtonPressed == BUTTON_NEXT_PIN) { // rechts | |
857 if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) { | |
858 action = ACTION_BUTTON_NEXT; | |
859 } | |
860 } | |
861 | |
862 if(action != 0) | |
863 { | |
864 time_without_button_pressed_deciseconds = 0; | |
865 if(pSettings->FlipDisplay) /* switch action resulting from pressed button */ | |
866 { | |
867 if (action == ACTION_BUTTON_BACK) | |
868 { | |
869 action = ACTION_BUTTON_NEXT; | |
870 } | |
871 if (action == ACTION_BUTTON_NEXT) | |
872 { | |
873 action = ACTION_BUTTON_BACK; | |
874 } | |
875 } | |
876 } | |
877 | |
878 #ifdef BUTTON_CUSTOM_PIN | |
898 else | 879 else |
899 if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra | 880 if(LastButtonPressed == BUTTON_CUSTOM_PIN) // extra |
900 action = ACTION_BUTTON_CUSTOM; | 881 action = ACTION_BUTTON_CUSTOM; |
882 #endif | |
883 | |
884 #ifdef DEMOMODE // user pressed button ? | |
885 if((!demoMachineCall) && demoModeActive()) | |
886 { | |
887 demoSendCommand(action); | |
888 return; | |
889 } | |
901 #endif | 890 #endif |
902 | 891 |
903 #ifdef DEMOMODE // user pressed button ? | 892 get_globalStateList(&status); |
904 if((!demoMachineCall) && demoModeActive()) | 893 |
905 { | 894 if (action == ACTION_BUTTON_CUSTOM) { |
906 demoSendCommand(action); | 895 GFX_screenshot(); |
907 return; | 896 } |
897 | |
898 switch (status.base) { | |
899 case BaseStop: | |
900 if (action == ACTION_BUTTON_BACK) | |
901 resetToFirmwareUpdate(); | |
902 break; | |
903 case BaseComm: | |
904 if (action == ACTION_BUTTON_BACK) { | |
905 settingsGetPointer()->bluetoothActive = 0; | |
906 MX_Bluetooth_PowerOff(); | |
907 tComm_exit(); | |
908 } | |
909 break; | |
910 case BaseHome: | |
911 if (action == ACTION_BUTTON_NEXT) { | |
912 if (status.page == PageSurface) | |
913 openMenu(1); | |
914 else | |
915 tHomeDiveMenuControl(action); | |
916 } else if (action == ACTION_BUTTON_BACK) { | |
917 if (get_globalState() == StS) | |
918 openInfo(StILOGLIST); | |
919 else if ((status.page == PageDive) | |
920 && (settingsGetPointer()->design < 7)) { | |
921 settingsGetPointer()->design = 7; // auto switch to 9 if necessary | |
922 } else if ((status.page == PageDive) && (status.line != 0)) { | |
923 if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT) | |
924 settingsGetPointer()->design = 3; | |
925 else if (settingsGetPointer()->extraDisplay | |
926 == EXTRADISPLAY_DECOGAME) | |
927 settingsGetPointer()->design = 4; | |
928 | |
929 set_globalState(StD); | |
930 } else | |
931 tHome_change_field_button_pressed(); | |
932 } else if (action == ACTION_BUTTON_ENTER) { | |
933 if ((status.page == PageDive) && (status.line == 0)) | |
934 tHome_change_customview_button_pressed(); | |
935 else if (status.page == PageSurface) | |
936 tHome_change_customview_button_pressed(); | |
937 else | |
938 tHomeDiveMenuControl(action); | |
939 } | |
940 break; | |
941 | |
942 case BaseMenu: | |
943 if (status.line == 0) | |
944 sendActionToMenu(action); | |
945 else | |
946 sendActionToMenuEdit(action); | |
947 break; | |
948 | |
949 case BaseInfo: | |
950 if (status.page == InfoPageLogList) | |
951 sendActionToInfoLogList(action); | |
952 else if (status.page == InfoPageLogShow) | |
953 sendActionToInfoLogShow(action); | |
954 else | |
955 sendActionToInfo(action); | |
956 break; | |
957 | |
958 default: | |
959 break; | |
960 } | |
961 LastButtonPressed = INVALID_BUTTON; | |
908 } | 962 } |
909 #endif | 963 } |
910 | |
911 get_globalStateList(&status); | |
912 | |
913 if (action == ACTION_BUTTON_CUSTOM) { | |
914 GFX_screenshot(); | |
915 } | |
916 | |
917 switch (status.base) { | |
918 case BaseStop: | |
919 if (action == ACTION_BUTTON_BACK) | |
920 resetToFirmwareUpdate(); | |
921 break; | |
922 case BaseComm: | |
923 if (action == ACTION_BUTTON_BACK) { | |
924 settingsGetPointer()->bluetoothActive = 0; | |
925 MX_Bluetooth_PowerOff(); | |
926 tComm_exit(); | |
927 } | |
928 break; | |
929 case BaseHome: | |
930 if (action == ACTION_BUTTON_NEXT) { | |
931 if (status.page == PageSurface) | |
932 openMenu(1); | |
933 else | |
934 tHomeDiveMenuControl(action); | |
935 } else if (action == ACTION_BUTTON_BACK) { | |
936 if (get_globalState() == StS) | |
937 openInfo(StILOGLIST); | |
938 else if ((status.page == PageDive) | |
939 && (settingsGetPointer()->design < 7)) { | |
940 settingsGetPointer()->design = 7; // auto switch to 9 if necessary | |
941 } else if ((status.page == PageDive) && (status.line != 0)) { | |
942 if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT) | |
943 settingsGetPointer()->design = 3; | |
944 else if (settingsGetPointer()->extraDisplay | |
945 == EXTRADISPLAY_DECOGAME) | |
946 settingsGetPointer()->design = 4; | |
947 | |
948 set_globalState(StD); | |
949 } else | |
950 tHome_change_field_button_pressed(); | |
951 } else if (action == ACTION_BUTTON_ENTER) { | |
952 if ((status.page == PageDive) && (status.line == 0)) | |
953 tHome_change_customview_button_pressed(); | |
954 else if (status.page == PageSurface) | |
955 tHome_change_customview_button_pressed(); | |
956 else | |
957 tHomeDiveMenuControl(action); | |
958 } | |
959 break; | |
960 | |
961 case BaseMenu: | |
962 if (status.line == 0) | |
963 sendActionToMenu(action); | |
964 else | |
965 sendActionToMenuEdit(action); | |
966 break; | |
967 | |
968 case BaseInfo: | |
969 if (status.page == InfoPageLogList) | |
970 sendActionToInfoLogList(action); | |
971 else if (status.page == InfoPageLogShow) | |
972 sendActionToInfoLogShow(action); | |
973 else | |
974 sendActionToInfo(action); | |
975 break; | |
976 | |
977 default: | |
978 break; | |
979 } | |
980 } | |
981 | |
982 | 964 |
983 void gotoSleep(void) | 965 void gotoSleep(void) |
984 { | 966 { |
985 /* not at the moment of testing */ | 967 /* not at the moment of testing */ |
986 // ext_flash_erase_firmware_if_not_empty(); | 968 // ext_flash_erase_firmware_if_not_empty(); |