Пример #1
0
/**
  * @brief  GPIO EXTI Callback function
  *         Handle remote-wakeup through key button
  * @param  GPIO_Pin
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
//   U8 i,y;
//     uint32_t wInterrupt_Mask = 0;
//  GPIO_InitTypeDef GPIO_InitStruct;
    if ((hUsbDeviceFS.dev_remote_wakeup == 1)&&
         ( hUsbDeviceFS.dev_state == USBD_STATE_SUSPENDED))
//     if ( hUsbDeviceFS.dev_state == USBD_STATE_SUSPENDED)
    {
      if (hpcd_USB_FS.Init.low_power_enable)
      {
        /* Reset SLEEPDEEP bit of Cortex System Control Register */
        SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));  
    
        SystemClockConfig_Resume();
        remotewakeupon = 1;
//        HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
      }
      
//      /* Activate Remote wakeup */
//      HAL_PCD_ActivateRemoteWakeup((&hpcd_USB_FS));

//      /* remote wakeup delay */
//      HAL_Delay(10);
//      
//      /* Disable Remote wakeup */
//      HAL_PCD_DeActivateRemoteWakeup((&hpcd_USB_FS));
//       for (y = 0; y < COLS; y++) {   
//         gpio_setDirvalue(matrix[y].port, matrix[y].pin, 0, 1);
 //     }
//        HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
//    HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
//    HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
//    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn); 
//      GPIO_InitStruct.Pin = R0_Pin|R1_Pin|R2_Pin|R3_Pin 
//                          |R4_Pin|R5_Pin|R6_Pin|R7_Pin 
//                          |LED_INT_Pin|SCROLL_UP_Pin|SCROLL_DOWN_Pin;
//  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
//  GPIO_InitStruct.Pull = GPIO_PULLUP;
//  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
//  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  
//  MX_TIM2_Init();  
//    for (i=0;i<3;i++) {
//    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_IDLE;
//      }      
//    wInterrupt_Mask = USB_CNTR_CTRM  | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
//      | USB_CNTR_ESOFM | USB_CNTR_RESETM;
//    
//    /*Set interrupt mask*/
//    hpcd_USB_FS.Instance->CNTR = wInterrupt_Mask;
//    switchModeDetect();      
    wakeupEvents |= 1;
    } 
}
Пример #2
0
/**
  * @brief  Resume callback.
  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
{
  /* USER CODE BEGIN 3 */
  if (hpcd->Init.low_power_enable)
  {
    /* Reset SLEEPDEEP bit of Cortex System Control Register */
    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));   
    SystemClockConfig_Resume(); 
  }
  /* USER CODE END 3 */
  USBD_LL_Resume(hpcd->pData);
  
}
Пример #3
0
/**
  * @brief  Resume callback.
  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
{
  U8 i,y;
  uint32_t wInterrupt_Mask = 0;
//  USBD_HID_HandleTypeDef *ptr;
//  ptr = (USBD_HID_HandleTypeDef *)(hUsbDeviceFS.pClassData);
  GPIO_InitTypeDef GPIO_InitStruct;
//__GPIOC_CLK_ENABLE();
//__GPIOA_CLK_ENABLE();
//__GPIOB_CLK_ENABLE();
   if (hpcd->Init.low_power_enable) {
//    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));   
//    SystemClockConfig_Resume();      
     if (remotewakeupon == 0)
//  if ((hpcd->Init.low_power_enable)&&(remotewakeupon == 0))
  {    
    /* Reset SLEEPDEEP bit of Cortex System Control Register */
    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));   
    SystemClockConfig_Resume(); 
   USBD_LL_Resume(hpcd->pData); 
   HAL_Delay(10);    
    for (i=0;i<3;i++) {
    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_IDLE;
//      ptr->state[i] = HID_IDLE;
    }
     for (y = 0; y < COLS; y++) {   
         gpio_setDirvalue(matrix[y].port, matrix[y].pin, 0, 1);
//         for (i = 0; i < 10; i++);
     }
        /* Handle Resume state machine */  
     HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
//     EXTI->FTSR = 0;
////     for (i = 0; i < 10; i++);
//        __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All); 
    HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
    HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);  
//    
//    HAL_NVIC_EnableIRQ(I2C2_IRQn);
      GPIO_InitStruct.Pin = R0_Pin|R1_Pin|R2_Pin|R3_Pin 
                          |R4_Pin|R5_Pin|R6_Pin|R7_Pin 
                          |LED_INT_Pin|SCROLL_UP_Pin|SCROLL_DOWN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
//  MX_GPIO_Init();
//  MX_CRC_Init();
////  MX_IWDG_Init();
////  MX_TIM6_Init();
////  MX_TIM7_Init();
////  MX_WWDG_Init();
////  MX_USB_DEVICE_Init();
  MX_I2C2_Init();
  MX_TIM2_Init();
//  initLedModule(0);  // initialize LED  
  } else {
      HAL_PCD_ActivateRemoteWakeup((&hpcd_USB_FS));

      /* remote wakeup delay */
      HAL_Delay(10);
      
      /* Disable Remote wakeup */
      HAL_PCD_DeActivateRemoteWakeup((&hpcd_USB_FS));
      USBD_LL_Resume(hpcd->pData);
      HAL_Delay(10);
 //     }
      /* change remote_wakeup feature to 0*/
//      hUsbDeviceFS.dev_remote_wakeup = 0;
       for (y = 0; y < COLS; y++) {   
         gpio_setDirvalue(matrix[y].port, matrix[y].pin, 0, 1);
//         for (i = 0; i < 10; i++);
  }
      HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
//      EXTI->FTSR = 0;
// //   __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);    
    HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
    HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);
//    HAL_NVIC_EnableIRQ(I2C2_IRQn); 
      GPIO_InitStruct.Pin = R0_Pin|R1_Pin|R2_Pin|R3_Pin 
                          |R4_Pin|R5_Pin|R6_Pin|R7_Pin 
                          |LED_INT_Pin|SCROLL_UP_Pin|SCROLL_DOWN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  
  MX_I2C2_Init();
  MX_TIM2_Init();  
    for (i=0;i<3;i++) {
    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_IDLE;
//      ptr->state[i] = HID_IDLE;
    }  
    wInterrupt_Mask = USB_CNTR_CTRM  | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
      | USB_CNTR_ESOFM | USB_CNTR_RESETM;
    
    /*Set interrupt mask*/
    hpcd_USB_FS.Instance->CNTR = wInterrupt_Mask;
    switchModeDetect(); 
        
  }
}
//  MX_GPIO_Init();  
//  MX_I2C2_Init();
//  MX_TIM2_Init(); 
//  initLedModule(0); 
  /* USER CODE END 3 */
//  USBD_LL_Resume(hpcd->pData);
  remotewakeupon=0;
}