comparison Discovery/Src/base.c @ 981:c6c781a2e85b default

Merge into default
author heinrichsweikamp
date Tue, 11 Feb 2025 18:12:00 +0100
parents 6d8ae8fbccf5
children 5a690195b6b7
comparison
equal deleted inserted replaced
871:f7318457df4d 981:c6c781a2e85b
211 #include "text_multilanguage.h" 211 #include "text_multilanguage.h"
212 #include "tHome.h" 212 #include "tHome.h"
213 #include "tInfo.h" 213 #include "tInfo.h"
214 #include "tInfoLog.h" 214 #include "tInfoLog.h"
215 #include "tInfoSensor.h" 215 #include "tInfoSensor.h"
216 #include "tInfoPreDive.h"
216 #include "tMenu.h" 217 #include "tMenu.h"
217 #include "tMenuEdit.h" 218 #include "tMenuEdit.h"
218 #include "tMenuEditGasOC.h" 219 #include "tMenuEditGasOC.h"
219 #include "tStructure.h" 220 #include "tStructure.h"
220 #include "externLogbookFlash.h" 221 #include "externLogbookFlash.h"
295 static uint8_t wasFirmwareUpdateCheckBattery = 0; 296 static uint8_t wasFirmwareUpdateCheckBattery = 0;
296 static uint8_t DoDisplayRefresh = 0; /* trigger to refresh display data */ 297 static uint8_t DoDisplayRefresh = 0; /* trigger to refresh display data */
297 static uint8_t DoHousekeeping = 0; /* trigger to cleanup the frame buffers */ 298 static uint8_t DoHousekeeping = 0; /* trigger to cleanup the frame buffers */
298 static SButtonLock ButtonLockState = LOCK_OFF; /* Used for button unlock sequence */ 299 static SButtonLock ButtonLockState = LOCK_OFF; /* Used for button unlock sequence */
299 300
301 #ifdef T7_DEBUG_RUNTIME
302 static uint32_t startTimeMainLoop = 0;
303 static uint32_t startTimeDecoLoop = 0;
304 static uint32_t startTimeGfxLoop = 0;
305 static uint32_t timeMainLoop = 0;
306 static uint32_t timeDecoLoop = 0;
307 static uint32_t timeGfxLoop = 0;
308 #endif
300 309
301 /* Private function prototypes -----------------------------------------------*/ 310 /* Private function prototypes -----------------------------------------------*/
302 static void SystemClock_Config(void); 311 static void SystemClock_Config(void);
303 static void Error_Handler(void); 312 static void Error_Handler(void);
304 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command); 313 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command);
484 * and resetToFirmwareUpdate() 493 * and resetToFirmwareUpdate()
485 * because tComm_control() does not exit before disconnection 494 * because tComm_control() does not exit before disconnection
486 */ 495 */
487 while( 1 ) 496 while( 1 )
488 { 497 {
498 #ifdef T7_DEBUG_RUNTIME
499 startTimeMainLoop = HAL_GetTick();
500 #endif
489 if( bootToBootloader ) 501 if( bootToBootloader )
490 resetToFirmwareUpdate(); 502 resetToFirmwareUpdate();
491 503
492 tCCR_control(); 504 tCCR_control();
493 if( tComm_control() )// will stop while loop if tComm Mode started until exit from UART 505 if( tComm_control() )// will stop while loop if tComm Mode started until exit from UART
528 { 540 {
529 simulation_UpdateLifeData(1); 541 simulation_UpdateLifeData(1);
530 } 542 }
531 check_warning(); 543 check_warning();
532 updateMiniLiveLogbook(1); 544 updateMiniLiveLogbook(1);
533 545 #ifdef T7_DEBUG_RUNTIME
546 startTimeGfxLoop = HAL_GetTick();
547 #endif
534 RefreshDisplay(); 548 RefreshDisplay();
549 #ifdef T7_DEBUG_RUNTIME
550 timeGfxLoop = time_elapsed_ms(startTimeGfxLoop, HAL_GetTick());
551 #endif
535 TimeoutControl(); /* exit menus if needed */ 552 TimeoutControl(); /* exit menus if needed */
536 553
537 #ifdef ENABLE_MOTION_CONTROL 554 #ifdef ENABLE_MOTION_CONTROL
538 if((stateUsed->mode == MODE_DIVE) && (settingsGetPointer()->MotionDetection != MOTION_DETECT_OFF)) /* handle motion events in divemode only */ 555 if((stateUsed->mode == MODE_DIVE) && (settingsGetPointer()->MotionDetection != MOTION_DETECT_OFF)) /* handle motion events in divemode only */
539 { 556 {
542 suspendMotionDetection(10); /* do not change custom views while divers is operating the computer */ 559 suspendMotionDetection(10); /* do not change custom views while divers is operating the computer */
543 } 560 }
544 HandleMotionDetection(); 561 HandleMotionDetection();
545 } 562 }
546 #endif 563 #endif
547 564 /* Autofocus for T3 view */
565 if((settingsGetPointer()->cvAutofocus) && (settingsGetPointer()->design == 3) && (get_globalState() == StD) && (stateUsed->mode == MODE_DIVE))
566 {
567 t3_handleAutofocus();
568 }
548 #ifdef SIM_WRITES_LOGBOOK 569 #ifdef SIM_WRITES_LOGBOOK
549 if(stateUsed == stateSimGetPointer()) 570 if(stateUsed == stateSimGetPointer())
550 logbook_InitAndWrite(stateUsed); 571 logbook_InitAndWrite(stateUsed);
551 #endif 572 #endif
552 if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/ 573 if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/
553 logbook_InitAndWrite(stateUsed); 574 logbook_InitAndWrite((SDiveState*)stateUsed);
554 } 575 }
576 #ifdef T7_DEBUG_RUNTIME
577 timeMainLoop = time_elapsed_ms(startTimeMainLoop, HAL_GetTick());
578 #endif
555 } 579 }
556 } 580 }
557 581
558 582
559 583
892 break; 916 break;
893 case InfoPageLogShow: sendActionToInfoLogShow(action); 917 case InfoPageLogShow: sendActionToInfoLogShow(action);
894 break; 918 break;
895 case InfoPageSensor: sendActionToInfoSensor(action); 919 case InfoPageSensor: sendActionToInfoSensor(action);
896 break; 920 break;
921 case InfoPagePreDive: sendActionToInfoPreDive(action);
922 break;
897 default: sendActionToInfo(action); 923 default: sendActionToInfo(action);
898 break; 924 break;
899 } 925 }
900 break; 926 break;
901 927
993 1019
994 static void gotoSleep(void) 1020 static void gotoSleep(void)
995 { 1021 {
996 /* not at the moment of testing */ 1022 /* not at the moment of testing */
997 // ext_flash_erase_firmware_if_not_empty(); 1023 // ext_flash_erase_firmware_if_not_empty();
998 GFX_logoAutoOff(); 1024 GFX_logoAutoOff();
1025 display_power_off();
999 ext_flash_write_devicedata(true); /* write data at default position */ 1026 ext_flash_write_devicedata(true); /* write data at default position */
1000 ext_flash_write_settings(true); /* write data at default position */ 1027 ext_flash_write_settings(true); /* write data at default position */
1001 set_globalState(StStop); 1028 set_globalState(StStop);
1002 } 1029 }
1003 1030
1248 switch( pSettings->brightness + blBoost) 1275 switch( pSettings->brightness + blBoost)
1249 { 1276 {
1250 case 0: /* Cave */ 1277 case 0: /* Cave */
1251 levelMax = 3000;/* max 25 % (x2) */ 1278 levelMax = 3000;/* max 25 % (x2) */
1252 levelMin = 1500; 1279 levelMin = 1500;
1280 if( isNewDisplay()) display_1_brightness_cave();
1253 break; 1281 break;
1254 case 1: /* Eco */ 1282 case 1: /* Eco */
1255 levelMax = 6000;/* max 50 % (x2) */ 1283 levelMax = 6000;/* max 50 % (x2) */
1256 levelMin = 3000; 1284 levelMin = 3000;
1285 if ( isNewDisplay()) display_1_brightness_eco();
1257 break; 1286 break;
1258 case 2: /* Std */ 1287 case 2: /* Std */
1259 levelAmbient += 1000; 1288 levelAmbient += 1000;
1260 levelMax = 9000; 1289 levelMax = 9000;
1261 levelMin = 4500; 1290 levelMin = 4500;
1262 levelUpStep_100ms += levelUpStep_100ms/2; // 4500 instead of 3000 1291 levelUpStep_100ms += levelUpStep_100ms/2; // 4500 instead of 3000
1263 levelDnStep_100ms += levelDnStep_100ms/2; 1292 levelDnStep_100ms += levelDnStep_100ms/2;
1293 if ( isNewDisplay()) display_1_brightness_std();
1264 break; 1294 break;
1265 case 3: /* High */ 1295 case 3: /* High */
1266 default: 1296 default:
1267 levelAmbient += 3000; 1297 levelAmbient += 3000;
1268 levelMax = 12000; /* max 100% (x2) */ 1298 levelMax = 12000; /* max 100% (x2) */
1269 levelMin = 6000; 1299 levelMin = 6000;
1270 levelUpStep_100ms += levelUpStep_100ms; // 6000 instead of 3000 1300 levelUpStep_100ms += levelUpStep_100ms; // 6000 instead of 3000
1271 levelDnStep_100ms += levelDnStep_100ms; 1301 levelDnStep_100ms += levelDnStep_100ms;
1302 if ( isNewDisplay()) display_1_brightness_high();
1272 break; 1303 break;
1273 case 4: /* New Max */ 1304 case 4: /* New Max */
1274 levelAmbient = 12000; 1305 levelAmbient = 12000;
1275 levelMax = 12000; /* max 100% (x2) */ 1306 levelMax = 12000; /* max 100% (x2) */
1276 levelMin = 12000; 1307 levelMin = 12000;
1277 levelUpStep_100ms += 12000; 1308 levelUpStep_100ms += 12000;
1278 levelDnStep_100ms += 0; 1309 levelDnStep_100ms += 0;
1310 if ( isNewDisplay()) display_1_brightness_max();
1279 break; 1311 break;
1280 } 1312 }
1281 1313
1282 if((pSettings->brightness != brightnessModeLast))// || wasLostConnection) 1314 if((pSettings->brightness != brightnessModeLast))// || wasLostConnection)
1283 { 1315 {
1336 HAL_TIM_PWM_Init(&TimBacklightHandle); 1368 HAL_TIM_PWM_Init(&TimBacklightHandle);
1337 1369
1338 sConfig.OCMode = TIM_OCMODE_PWM1; 1370 sConfig.OCMode = TIM_OCMODE_PWM1;
1339 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; 1371 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
1340 sConfig.OCFastMode = TIM_OCFAST_DISABLE; 1372 sConfig.OCFastMode = TIM_OCFAST_DISABLE;
1341 sConfig.Pulse = 100; /* Initial brigthness of display */ 1373 sConfig.Pulse = 100; /* Initial brightness of display */
1342 1374
1343 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); 1375 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
1344 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); 1376 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
1345 } 1377 }
1346 #endif 1378 #endif
1707 decom_CreateGasChangeList(&stateDeco.diveSettings, &stateDeco.lifeData); 1739 decom_CreateGasChangeList(&stateDeco.diveSettings, &stateDeco.lifeData);
1708 1740
1709 switch(what) 1741 switch(what)
1710 { 1742 {
1711 case CALC_VPM: 1743 case CALC_VPM:
1744 #ifdef T7_DEBUG_RUNTIME
1745 startTimeDecoLoop = HAL_GetTick();
1746 #endif
1712 vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistVPM, DECOSTOPS); 1747 vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistVPM, DECOSTOPS);
1748 #ifdef T7_DEBUG_RUNTIME
1749 timeDecoLoop = time_elapsed_ms(startTimeDecoLoop, HAL_GetTick());
1750 #endif
1713 decoLock = DECO_CALC_FINSHED_vpm; 1751 decoLock = DECO_CALC_FINSHED_vpm;
1714 return; 1752 return;
1715 case CALC_VPM_FUTURE: 1753 case CALC_VPM_FUTURE:
1716 decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,&stateDeco.lifeData); 1754 decom_tissues_exposure(stateDeco.diveSettings.future_TTS_minutes * 60,&stateDeco.lifeData);
1717 vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistFutureVPM, FUTURESTOPS); 1755 vpm_calc(&stateDeco.lifeData,&stateDeco.diveSettings,&stateDeco.vpm,&stateDeco.decolistFutureVPM, FUTURESTOPS);
1901 } 1939 }
1902 } 1940 }
1903 } 1941 }
1904 RequestModeChange = 0; 1942 RequestModeChange = 0;
1905 } 1943 }
1944
1945 #ifdef T7_DEBUG_RUNTIME
1946 uint32_t getMainLoopTime()
1947 {
1948 return timeMainLoop;
1949 }
1950 uint32_t getDecoLoopTime()
1951 {
1952 return timeDecoLoop;
1953 }
1954 uint32_t getGfxLoopTime()
1955 {
1956 return timeGfxLoop;
1957 }
1958 #endif
1906 // debugging by https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/ 1959 // debugging by https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/
1907 1960
1908 /* 1961 /*
1909 void printErrorMsg(const char * errMsg) 1962 void printErrorMsg(const char * errMsg)
1910 { 1963 {