Mercurial > public > ostc4
comparison Small_CPU/Src/baseCPU2.c @ 880:f012fcd7f465 Evo_2_23
support for led and vibration
author | heinrichsweikamp |
---|---|
date | Thu, 29 Aug 2024 15:01:30 +0200 |
parents | 2cab242c9a4a |
children | 17f02ac9da67 |
comparison
equal
deleted
inserted
replaced
879:fe955104901c | 880:f012fcd7f465 |
---|---|
210 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | 210 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 |
211 #define BUTTON_OSTC_GPIO_PORT GPIOA | 211 #define BUTTON_OSTC_GPIO_PORT GPIOA |
212 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | 212 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() |
213 #define BUTTON_OSTC_IRQn EXTI0_IRQn | 213 #define BUTTON_OSTC_IRQn EXTI0_IRQn |
214 | 214 |
215 #define BUTTON_TEST_GPIO_PIN GPIO_PIN_3 | 215 #define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */ |
216 #define BUTTON_TEST_GPIO_PORT GPIOA | 216 #define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */ |
217 #define BUTTON_TEST_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE() | 217 #define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */ |
218 #define BUTTON_TEST_IRQn EXTI3_IRQn | |
219 | |
220 #define WIRELSS_RISING_GPIO_PIN GPIO_PIN_1 | |
221 #define WIRELSS_RISING_GPIO_PORT GPIOA | |
222 #define WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
223 #define WIRELSS_RISING_IRQn EXTI1_IRQn | |
224 | |
225 #define WIRELSS_FALLING_GPIO_PIN GPIO_PIN_2 | |
226 #define WIRELSS_FALLING_GPIO_PORT GPIOA | |
227 #define WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
228 #define WIRELSS_FALLING_IRQn EXTI2_IRQn | |
229 | |
230 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 | |
231 #define WIRELSS_POWER_GPIO_PORT GPIOB | |
232 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() | |
233 | |
234 | |
235 #define LED_CONTROL_PIN GPIO_PIN_3 /* PortC */ | |
236 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ | 218 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ |
237 | 219 |
238 /* Private macro -------------------------------------------------------------*/ | 220 /* Private macro -------------------------------------------------------------*/ |
239 | 221 |
240 /* Private variables ---------------------------------------------------------*/ | 222 /* Private variables ---------------------------------------------------------*/ |
243 | 225 |
244 /* Private function prototypes -----------------------------------------------*/ | 226 /* Private function prototypes -----------------------------------------------*/ |
245 static void EXTI_Wakeup_Button_Init(void); | 227 static void EXTI_Wakeup_Button_Init(void); |
246 static void EXTI_Wakeup_Button_DeInit(void); | 228 static void EXTI_Wakeup_Button_DeInit(void); |
247 | 229 |
248 static void EXTI_Test_Button_Init(void); | 230 static void GPIO_LEDs_VIBRATION_Init(void); |
249 static void EXTI_Test_Button_DeInit(void); | |
250 | |
251 static void GPIO_LED_Init(void); | |
252 static void GPIO_Power_MainCPU_Init(void); | 231 static void GPIO_Power_MainCPU_Init(void); |
253 static void GPIO_Power_MainCPU_ON(void); | 232 static void GPIO_Power_MainCPU_ON(void); |
254 static void GPIO_Power_MainCPU_OFF(void); | 233 static void GPIO_Power_MainCPU_OFF(void); |
234 static void GPIO_LED_RED_OFF(void); | |
235 static void GPIO_LED_RED_ON(void); | |
236 static void GPIO_LED_GREEN_OFF(void); | |
237 static void GPIO_LED_GREEN_ON(void); | |
238 static void GPIO_VIBRATION_OFF(void); | |
239 static void GPIO_VIBRATION_ON(void); | |
255 | 240 |
256 #ifdef DEBUG_I2C_LINES | 241 #ifdef DEBUG_I2C_LINES |
257 void GPIO_test_I2C_lines(void); | 242 void GPIO_test_I2C_lines(void); |
258 #endif | 243 #endif |
259 | 244 |
304 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); | 289 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
305 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); | 290 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); |
306 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | 291 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
307 | 292 |
308 MX_RTC_init(); | 293 MX_RTC_init(); |
309 GPIO_LED_Init(); | 294 GPIO_LEDs_VIBRATION_Init(); |
310 GPIO_new_DEBUG_Init(); // added 170322 hw | 295 GPIO_new_DEBUG_Init(); // added 170322 hw |
311 initGlobals(); | 296 initGlobals(); |
312 | 297 |
313 /* printf("CPU2-RTE running...\n"); */ | 298 /* printf("CPU2-RTE running...\n"); */ |
314 | 299 |
414 accelerator_init(); | 399 accelerator_init(); |
415 externalInterface_Init(); | 400 externalInterface_Init(); |
416 | 401 |
417 if (global.mode == MODE_BOOT) { | 402 if (global.mode == MODE_BOOT) { |
418 GPIO_Power_MainCPU_OFF(); | 403 GPIO_Power_MainCPU_OFF(); |
404 | |
405 GPIO_LED_GREEN_ON(); | |
419 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); | 406 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); |
420 GPIO_Power_MainCPU_ON(); | 407 GPIO_Power_MainCPU_ON(); |
408 | |
409 GPIO_LED_GREEN_OFF(); | |
410 | |
411 GPIO_LED_RED_ON(); | |
412 GPIO_VIBRATION_ON(); | |
413 HAL_Delay(100); | |
414 GPIO_LED_RED_OFF(); | |
415 GPIO_VIBRATION_OFF(); | |
421 } | 416 } |
422 SPI_synchronize_with_Master(); | 417 SPI_synchronize_with_Master(); |
423 MX_DMA_Init(); | 418 MX_DMA_Init(); |
424 MX_SPI1_Init(); | 419 MX_SPI1_Init(); |
425 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ | 420 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
426 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); | 421 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
427 EXTI_Test_Button_Init(); | |
428 global.mode = MODE_SURFACE; | 422 global.mode = MODE_SURFACE; |
429 break; | 423 break; |
430 | 424 |
431 case MODE_CALIB: | 425 case MODE_CALIB: |
432 scheduleCompassCalibrationMode(); | 426 scheduleCompassCalibrationMode(); |
491 EXTI_Test_Button_DeInit(); | 485 EXTI_Test_Button_DeInit(); |
492 EXTI_Wakeup_Button_Init(); | 486 EXTI_Wakeup_Button_Init(); |
493 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | 487 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); |
494 */ | 488 */ |
495 | 489 |
496 EXTI_Test_Button_DeInit(); | |
497 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); | 490 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
498 externalInterface_SwitchPower33(false); | 491 externalInterface_SwitchPower33(false); |
499 if (hasExternalClock()) | 492 if (hasExternalClock()) |
500 SystemClock_Config_HSI(); | 493 SystemClock_Config_HSI(); |
501 sleep_prepare(); | 494 sleep_prepare(); |
502 | 495 |
503 GPIO_LED_Init(); | 496 GPIO_LEDs_VIBRATION_Init(); |
504 | 497 |
505 scheduleSleepMode(); | 498 scheduleSleepMode(); |
506 if (hasExternalClock()) | 499 if (hasExternalClock()) |
507 SystemClock_Config_HSE(); | 500 SystemClock_Config_HSE(); |
508 GPIO_LED_Init(); | |
509 EXTI_Wakeup_Button_DeInit(); | 501 EXTI_Wakeup_Button_DeInit(); |
510 ADCx_Init(); | 502 ADCx_Init(); |
511 GPIO_Power_MainCPU_Init(); | 503 GPIO_Power_MainCPU_Init(); |
512 GPIO_Power_MainCPU_ON(); | 504 GPIO_Power_MainCPU_ON(); |
513 compass_init(0, 7); | 505 compass_init(0, 7); |
559 if (global.mode == MODE_SLEEP) { | 551 if (global.mode == MODE_SLEEP) { |
560 global.mode = MODE_BOOT; | 552 global.mode = MODE_BOOT; |
561 } | 553 } |
562 } | 554 } |
563 else | 555 else |
564 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { | 556 { |
565 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { | 557 |
566 global.demo_mode = 1; | |
567 global.mode = MODE_DIVE; | |
568 } else if (global.demo_mode && (global.mode == MODE_DIVE) | |
569 && (global.lifeData.dive_time_seconds > 10)) { | |
570 global.demo_mode = 0; | |
571 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
572 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
573 } | |
574 } | 558 } |
575 } | 559 } |
576 | 560 |
577 /** | 561 /** |
578 * @brief System Clock Configuration | 562 * @brief System Clock Configuration |
809 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | 793 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); |
810 HAL_Delay(10); | 794 HAL_Delay(10); |
811 } | 795 } |
812 */ | 796 */ |
813 | 797 |
814 static void GPIO_LED_Init(void) { | 798 static void GPIO_LEDs_VIBRATION_Init(void) { |
815 GPIO_InitTypeDef GPIO_InitStructure; | 799 GPIO_InitTypeDef GPIO_InitStructure; |
816 | 800 |
817 __GPIOC_CLK_ENABLE(); | 801 __GPIOA_CLK_ENABLE(); |
818 GPIO_InitStructure.Pin = LED_CONTROL_PIN; | 802 GPIO_InitStructure.Pin = LED_CONTROL_PIN_RED; |
819 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 803 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
820 GPIO_InitStructure.Pull = GPIO_PULLUP; | 804 GPIO_InitStructure.Pull = GPIO_PULLUP; |
821 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | 805 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
822 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | 806 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); |
807 | |
808 GPIO_InitStructure.Pin = LED_CONTROL_PIN_GREEN; | |
809 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
810 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
811 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
812 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
813 | |
814 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN; | |
815 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
816 GPIO_InitStructure.Pull = GPIO_PULLDOWN; | |
817 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
818 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
823 } | 819 } |
824 | 820 |
825 void GPIO_new_DEBUG_Init(void) { | 821 void GPIO_new_DEBUG_Init(void) { |
826 #ifdef DEBUG_PIN_ACTIVE | 822 #ifdef DEBUG_PIN_ACTIVE |
827 GPIO_InitTypeDef GPIO_InitStructure; | 823 GPIO_InitTypeDef GPIO_InitStructure; |
864 | 860 |
865 static void GPIO_Power_MainCPU_OFF(void) { | 861 static void GPIO_Power_MainCPU_OFF(void) { |
866 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); | 862 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); |
867 } | 863 } |
868 | 864 |
865 static void GPIO_LED_GREEN_ON(void) { | |
866 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_RESET); | |
867 } | |
868 | |
869 static void GPIO_LED_GREEN_OFF(void) { | |
870 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); | |
871 } | |
872 | |
873 static void GPIO_LED_RED_ON(void) { | |
874 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_RESET); | |
875 } | |
876 | |
877 static void GPIO_LED_RED_OFF(void) { | |
878 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); | |
879 } | |
880 | |
881 static void GPIO_VIBRATION_ON(void) { | |
882 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_SET); | |
883 } | |
884 | |
885 static void GPIO_VIBRATION_OFF(void) { | |
886 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); | |
887 } | |
888 | |
889 | |
869 /** | 890 /** |
870 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | 891 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode |
871 * @param None | 892 * @param None |
872 * @retval None | 893 * @retval None |
873 */ | 894 */ |
895 | 916 |
896 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | 917 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
897 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | 918 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); |
898 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); | 919 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); |
899 } | 920 } |
900 | |
901 static void EXTI_Test_Button_Init(void) { | |
902 GPIO_InitTypeDef GPIO_InitStructure; | |
903 | |
904 BUTTON_TEST_GPIO_CLK_ENABLE(); | |
905 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
906 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
907 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
908 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
909 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0); | |
910 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn); | |
911 } | |
912 | |
913 static void EXTI_Test_Button_DeInit(void) { | |
914 GPIO_InitTypeDef GPIO_InitStructure; | |
915 | |
916 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | |
917 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
918 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
919 | |
920 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
921 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
922 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); | |
923 } | |
924 | |
925 /* NUCLEO C 13 | |
926 KEY_BUTTON_GPIO_CLK_ENABLE(); | |
927 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
928 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
929 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | |
930 HAL_GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); | |
931 HAL_NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, 2, 0); | |
932 HAL_NVIC_EnableIRQ(KEY_BUTTON_EXTI_IRQn); | |
933 */ | |
934 | 921 |
935 /** | 922 /** |
936 * @brief Wake Up Timer callback | 923 * @brief Wake Up Timer callback |
937 * @param hrtc: RTC handle | 924 * @param hrtc: RTC handle |
938 * @retval None | 925 * @retval None |
988 #endif | 975 #endif |
989 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); | 976 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
990 | 977 |
991 GPIO_InitStruct.Pin = | 978 GPIO_InitStruct.Pin = |
992 GPIO_PIN_All | 979 GPIO_PIN_All |
993 ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | CHARGE_IN_PIN | EXT33V_CONTROL_PIN | LED_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ | 980 ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | CHARGE_IN_PIN | EXT33V_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); /* power off & charger in & charge out & OSC32 & ext33Volt */ |
994 | 981 |
995 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | 982 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
996 | 983 |
997 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | 984 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); |
998 #ifdef DEBUGMODE | 985 #ifdef DEBUGMODE |
1002 | 989 |
1003 GPIO_InitStruct.Pin = GPIO_PIN_All; | 990 GPIO_InitStruct.Pin = GPIO_PIN_All; |
1004 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | 991 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); |
1005 | 992 |
1006 GPIO_Power_MainCPU_OFF(); | 993 GPIO_Power_MainCPU_OFF(); |
994 GPIO_LED_GREEN_OFF(); | |
995 GPIO_LED_RED_OFF(); | |
996 | |
1007 | 997 |
1008 #ifndef DEBUGMODE | 998 #ifndef DEBUGMODE |
1009 __HAL_RCC_GPIOB_CLK_DISABLE(); | 999 __HAL_RCC_GPIOB_CLK_DISABLE(); |
1010 #endif | 1000 #endif |
1011 __HAL_RCC_GPIOH_CLK_DISABLE(); | 1001 __HAL_RCC_GPIOH_CLK_DISABLE(); |