AutoTest.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * AutoTest.c
  3. *
  4. * Created on: Jun 13, 2024
  5. * Author: Administrator
  6. */
  7. #include "TouchInclude.h"
  8. #if AUTO_TEST
  9. TEST_STATE TestState;
  10. /*********************************************************************
  11. * @fn EXTI0_INT_INIT
  12. *
  13. * @brief Initializes EXTI0 collection.
  14. *
  15. * @return none
  16. */
  17. void EXTI0_INT_INIT(void)
  18. {
  19. EXTI_InitTypeDef EXTI_InitStructure = {0};
  20. //NVIC_InitTypeDef NVIC_InitStructure = {0};
  21. GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource5);
  22. EXTI_InitStructure.EXTI_Line = EXTI_Line5;
  23. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;//EXTI_Mode_Interrupt;
  24. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  25. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  26. EXTI_Init(&EXTI_InitStructure);
  27. EXTI->INTENR |= EXTI_INTENR_MR5;
  28. // NVIC_InitStructure.NVIC_IRQChannel = EXTI7_0_IRQn;
  29. // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  30. // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  31. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  32. // NVIC_Init(&NVIC_InitStructure);
  33. }
  34. AT(.com_text.gpio_isr)
  35. void gpio_isr_callback(void)
  36. {
  37. gpio_edge_pending_clear();
  38. printf(info);
  39. }
  40. void io_interrupt_init(void)
  41. {
  42. gpio_edge_cap_typedef config;
  43. config.edge = GPIO_EDGE_FALLING;
  44. config.gpiox = IOKEY_PORT;
  45. config.gpio_pin = IOKEY_PIN;
  46. gpio_edge_capture_config(&config);
  47. gpio_edge_pic_config(gpio_isr_callback, 0);
  48. }
  49. void AutoTestInit(void)
  50. {
  51. GPIO_InitTypeDef GPIO_InitStructure = {0};
  52. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  53. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  54. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  55. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  56. GPIO_InitStructure.GPIO_Pin = TEST_START_PIN;
  57. GPIO_Init(GPIOA, &GPIO_InitStructure);
  58. GPIO_SetBits(GPIOB, TEST_BUSY_PIN);
  59. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  60. GPIO_InitStructure.GPIO_Pin = TEST_BUSY_PIN;
  61. GPIO_Init(GPIOB, &GPIO_InitStructure);
  62. GPIO_SetBits(GPIOA, TEST_OK_PIN);
  63. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  64. GPIO_InitStructure.GPIO_Pin = TEST_OK_PIN;
  65. GPIO_Init(GPIOA, &GPIO_InitStructure);
  66. GPIO_SetBits(GPIOA, TEST_NG_PIN);
  67. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  68. GPIO_InitStructure.GPIO_Pin = TEST_NG_PIN;
  69. GPIO_Init(GPIOA, &GPIO_InitStructure);
  70. TestState = TEST_INIT;
  71. EXTI0_INT_INIT();
  72. }
  73. TEST_STATE GetTestState(void)
  74. {
  75. return TestState;
  76. }
  77. void ReturnTestResult(BOOL rst)
  78. {
  79. if(rst)//OK
  80. {
  81. GPIO_ResetBits(GPIOA, TEST_OK_PIN);
  82. GPIO_SetBits(GPIOA, TEST_NG_PIN);
  83. }
  84. else //NG
  85. {
  86. GPIO_SetBits(GPIOA, TEST_OK_PIN);
  87. GPIO_ResetBits(GPIOA, TEST_NG_PIN);
  88. }
  89. TestState = TEST_FINISH;
  90. GPIO_SetBits(GPIOB, TEST_BUSY_PIN);
  91. }
  92. void AutoTestHandle(void)
  93. {
  94. if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
  95. {
  96. if(TestState==TEST_INIT || TestState==TEST_FINISH)
  97. {
  98. GPIO_ResetBits(GPIOB, TEST_BUSY_PIN);
  99. TestState = TEST_READY;
  100. }
  101. EXTI_ClearITPendingBit(EXTI_Line5); /* Clear Flag */
  102. }
  103. }
  104. //void EXTI7_0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  105. //
  106. ///*********************************************************************
  107. // * @fn EXTI0_IRQHandler
  108. // *
  109. // * @brief This function handles EXTI0 Handler.
  110. // *
  111. // * @return none
  112. // */
  113. //void EXTI7_0_IRQHandler(void)
  114. //{
  115. // if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
  116. // {
  117. // GPIO_ResetBits(GPIOB, TEST_BUSY_PIN);
  118. //
  119. // TestState = TEST_READY;
  120. // EXTI_ClearITPendingBit(EXTI_Line5); /* Clear Flag */
  121. // //GPIO_SetBits(GPIOB, TEST_BUSY_PIN);
  122. // }
  123. //}
  124. #endif