Mercurial > public > ostc4
comparison Small_CPU/Src/baseCPU2.c @ 185:1bb24fd3fc92
Merged in Ideenmodellierer/ostc4/Cleanup_Compass_Wireless (pull request #4)
Cleanup Compass Wireless
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Fri, 15 Mar 2019 08:22:16 +0000 |
parents | 9baecc0c24b2 |
children | b95741467355 |
comparison
equal
deleted
inserted
replaced
178:d36596281501 | 185:1bb24fd3fc92 |
---|---|
139 #include "compass.h" | 139 #include "compass.h" |
140 #include "pressure.h" | 140 #include "pressure.h" |
141 #include "batteryGasGauge.h" | 141 #include "batteryGasGauge.h" |
142 #include "batteryCharger.h" | 142 #include "batteryCharger.h" |
143 #include "scheduler.h" | 143 #include "scheduler.h" |
144 #include "wireless.h" | |
145 #include "tm_stm32f4_otp.h" | 144 #include "tm_stm32f4_otp.h" |
146 | 145 |
147 // From Common/Inc: | 146 // From Common/Inc: |
148 #include "calc_crush.h" | 147 #include "calc_crush.h" |
149 #include "decom.h" | 148 #include "decom.h" |
238 static void EXTI_Wakeup_Button_DeInit(void); | 237 static void EXTI_Wakeup_Button_DeInit(void); |
239 | 238 |
240 static void EXTI_Test_Button_Init(void); | 239 static void EXTI_Test_Button_Init(void); |
241 static void EXTI_Test_Button_DeInit(void); | 240 static void EXTI_Test_Button_DeInit(void); |
242 | 241 |
243 static void MX_EXTI_wireless_Init(void); | |
244 static void MX_EXTI_wireless_DeInit(void); | |
245 | |
246 //static void EXTILine01_Button_DeInit(void); | |
247 static void GPIO_LED_Init(void); | 242 static void GPIO_LED_Init(void); |
248 static void GPIO_Power_MainCPU_Init(void); | 243 static void GPIO_Power_MainCPU_Init(void); |
249 static void GPIO_Power_MainCPU_ON(void); | 244 static void GPIO_Power_MainCPU_ON(void); |
250 static void GPIO_Power_MainCPU_OFF(void); | 245 static void GPIO_Power_MainCPU_OFF(void); |
251 | 246 |
247 #ifdef DEBUG_I2C_LINES | |
252 void GPIO_test_I2C_lines(void); | 248 void GPIO_test_I2C_lines(void); |
253 | 249 #endif |
254 //void sleep_test(void); | 250 |
255 void sleep_prepare(void); | 251 void sleep_prepare(void); |
256 | 252 |
257 void SystemClock_Config(void); | 253 void SystemClock_Config(void); |
258 void SystemClock_Config_HSI(void); | 254 void SystemClock_Config_HSI(void); |
259 void SystemClock_Config_HSE(void); | 255 void SystemClock_Config_HSE(void); |
371 case MODE_POWERUP: | 367 case MODE_POWERUP: |
372 case MODE_BOOT: | 368 case MODE_BOOT: |
373 // ReInit_battery_charger_status_pins(); | 369 // ReInit_battery_charger_status_pins(); |
374 compass_init(0, 7); | 370 compass_init(0, 7); |
375 accelerator_init(); | 371 accelerator_init(); |
376 wireless_init(); | 372 |
377 if (global.mode == MODE_BOOT) { | 373 if (global.mode == MODE_BOOT) { |
378 GPIO_Power_MainCPU_OFF(); | 374 GPIO_Power_MainCPU_OFF(); |
379 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); | 375 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); |
380 GPIO_Power_MainCPU_ON(); | 376 GPIO_Power_MainCPU_ON(); |
381 } | 377 } |
382 SPI_synchronize_with_Master(); | 378 SPI_synchronize_with_Master(); |
383 MX_DMA_Init(); | 379 MX_DMA_Init(); |
384 MX_SPI1_Init(); | 380 MX_SPI1_Init(); |
385 MX_EXTI_wireless_Init(); | |
386 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ | 381 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
387 dohardspisync = 1; | 382 dohardspisync = 1; |
388 EXTI_Test_Button_Init(); | 383 EXTI_Test_Button_Init(); |
389 | |
390 /* | |
391 uint8_t dataWireless[64]; | |
392 while(1) | |
393 { | |
394 wireless_evaluate_and_debug(dataWireless,64); | |
395 } | |
396 */ | |
397 global.mode = MODE_SURFACE; | 384 global.mode = MODE_SURFACE; |
398 break; | 385 break; |
399 | 386 |
400 case MODE_CALIB: | 387 case MODE_CALIB: |
401 scheduleCompassCalibrationMode(); | 388 scheduleCompassCalibrationMode(); |
460 EXTI_Test_Button_DeInit(); | 447 EXTI_Test_Button_DeInit(); |
461 EXTI_Wakeup_Button_Init(); | 448 EXTI_Wakeup_Button_Init(); |
462 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | 449 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); |
463 */ | 450 */ |
464 EXTI_Test_Button_DeInit(); | 451 EXTI_Test_Button_DeInit(); |
465 MX_EXTI_wireless_DeInit(); | |
466 if (hasExternalClock()) | 452 if (hasExternalClock()) |
467 SystemClock_Config_HSI(); | 453 SystemClock_Config_HSI(); |
468 sleep_prepare(); | 454 sleep_prepare(); |
469 | 455 |
470 GPIO_LED_Init(); | 456 GPIO_LED_Init(); |
477 ADCx_Init(); | 463 ADCx_Init(); |
478 GPIO_Power_MainCPU_Init(); | 464 GPIO_Power_MainCPU_Init(); |
479 GPIO_Power_MainCPU_ON(); | 465 GPIO_Power_MainCPU_ON(); |
480 compass_init(0, 7); | 466 compass_init(0, 7); |
481 accelerator_init(); | 467 accelerator_init(); |
482 wireless_init(); | |
483 SPI_synchronize_with_Master(); | 468 SPI_synchronize_with_Master(); |
484 MX_DMA_Init(); | 469 MX_DMA_Init(); |
485 MX_SPI1_Init(); | 470 MX_SPI1_Init(); |
486 MX_EXTI_wireless_Init(); | |
487 SPI_Start_single_TxRx_with_Master(); | 471 SPI_Start_single_TxRx_with_Master(); |
488 | 472 |
489 // EXTILine0_Button_DeInit(); not now, later after testing | 473 // EXTILine0_Button_DeInit(); not now, later after testing |
490 break; | 474 break; |
491 } | 475 } |
517 * @param GPIO_Pin: Specifies the pins connected EXTI line | 501 * @param GPIO_Pin: Specifies the pins connected EXTI line |
518 * @retval None | 502 * @retval None |
519 */ | 503 */ |
520 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { | 504 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
521 | 505 |
522 if (GPIO_Pin == WIRELSS_RISING_GPIO_PIN) { | |
523 wireless_trigger_RisingEdgeSilence(); | |
524 } | |
525 | |
526 else | |
527 | |
528 if (GPIO_Pin == WIRELSS_FALLING_GPIO_PIN) { | |
529 wireless_trigger_FallingEdgeSignalHigh(); | |
530 } | |
531 | |
532 else | |
533 | |
534 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { | 506 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
535 if (global.mode == MODE_SLEEP) { | 507 if (global.mode == MODE_SLEEP) { |
536 global.mode = MODE_BOOT; | 508 global.mode = MODE_BOOT; |
537 } | 509 } |
538 } | 510 } |
539 | |
540 else | 511 else |
541 | |
542 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { | 512 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { |
543 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { | 513 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { |
544 global.demo_mode = 1; | 514 global.demo_mode = 1; |
545 global.mode = MODE_DIVE; | 515 global.mode = MODE_DIVE; |
546 } else if (global.demo_mode && (global.mode == MODE_DIVE) | 516 } else if (global.demo_mode && (global.mode == MODE_DIVE) |
898 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | 868 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
899 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | 869 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); |
900 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); | 870 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); |
901 } | 871 } |
902 | 872 |
903 static void MX_EXTI_wireless_Init(void) { | |
904 GPIO_InitTypeDef GPIO_InitStructure; | |
905 | |
906 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); | |
907 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
908 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
909 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
910 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); | |
911 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, | |
912 GPIO_PIN_SET); | |
913 | |
914 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); | |
915 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | |
916 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | |
917 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
918 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); | |
919 | |
920 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0); | |
921 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn); | |
922 | |
923 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); | |
924 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | |
925 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
926 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
927 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); | |
928 | |
929 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0); | |
930 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn); | |
931 | |
932 } | |
933 | |
934 static void MX_EXTI_wireless_DeInit(void) { | |
935 GPIO_InitTypeDef GPIO_InitStructure; | |
936 | |
937 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | |
938 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
939 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
940 | |
941 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | |
942 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); | |
943 | |
944 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | |
945 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); | |
946 | |
947 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
948 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); | |
949 | |
950 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn); | |
951 HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn); | |
952 } | |
953 | |
954 /* NUCLEO C 13 | 873 /* NUCLEO C 13 |
955 KEY_BUTTON_GPIO_CLK_ENABLE(); | 874 KEY_BUTTON_GPIO_CLK_ENABLE(); |
956 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | 875 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; |
957 GPIO_InitStructure.Pull = GPIO_NOPULL; | 876 GPIO_InitStructure.Pull = GPIO_NOPULL; |
958 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | 877 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; |