예제 #1
0
/**
  * @brief  Main routine for Keyboard application
  * @param  phost: Host handle
  * @retval None
  */
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost)
{
    HID_KEYBD_Info_TypeDef *k_pinfo;
    char c;
    k_pinfo = USBH_HID_GetKeybdInfo(phost);

    if(k_pinfo != NULL)
    {
        c = USBH_HID_GetASCIICode(k_pinfo);
        if(c != 0)
        {
            USR_KEYBRD_ProcessData(c);
        }
    }
}
/**
  * @brief  Main routine for Keyboard application
  * @param  phost: Host handle
  * @retval None
  */
static void USBH_KeybdDemo(USBH_HandleTypeDef *phost)
{
  HID_KEYBD_Info_TypeDef *k_pinfo; 
  char c;
  
  if(hid_demo.keyboard_state != HID_KEYBOARD_START)
  {
    
    k_pinfo = USBH_HID_GetKeybdInfo(phost);
    
    if(k_pinfo != NULL)
    {
      c = USBH_HID_GetASCIICode(k_pinfo);
      if(c != 0)
      {
        USR_KEYBRD_ProcessData(c);
      }
    }
  }
}
TM_USBH_HID_t TM_USBH_HID_GetKeyboard(TM_USB_t USB_Mode, TM_USBH_HID_Keyboard_t* KeyboardStruct) {
	HID_KEYBD_Info_TypeDef* k_pinfo; 
	uint8_t i;
	
	/* Get keyboard informations */
	k_pinfo = USBH_HID_GetKeybdInfo(TM_USBH_GetUSBPointer(USB_Mode));

	/* Check for ASCII value */
	if (k_pinfo != NULL) {
		/* Get ASCII value */
		KeyboardStruct->C = USBH_HID_GetASCIICode(k_pinfo);
		
		/* Copy everything */
		for (i = 0; i < 6; i++) {
			KeyboardStruct->Keys[i] = k_pinfo->keys[i];
		}
		
		/* Control pins */
		KeyboardStruct->Special.S.LAlt = k_pinfo->lalt ? 1 : 0;
		KeyboardStruct->Special.S.LShift = k_pinfo->lshift ? 1 : 0;
		KeyboardStruct->Special.S.LCtrl = k_pinfo->lctrl ? 1 : 0;
		KeyboardStruct->Special.S.LGUI = k_pinfo->lgui ? 1 : 0;
		KeyboardStruct->Special.S.RAlt = k_pinfo->ralt ? 1 : 0;
		KeyboardStruct->Special.S.RShift = k_pinfo->rshift ? 1 : 0;
		KeyboardStruct->Special.S.RCtrl = k_pinfo->rctrl ? 1 : 0;
		KeyboardStruct->Special.S.RGUI = k_pinfo->rgui ? 1 : 0;
		KeyboardStruct->Status = k_pinfo->state;
		
		/* Set flags if needed */
		KeyboardStruct->Special.S.Alt = KeyboardStruct->Special.S.LAlt | KeyboardStruct->Special.S.RAlt;
		KeyboardStruct->Special.S.Shift = KeyboardStruct->Special.S.LShift | KeyboardStruct->Special.S.RShift;
		KeyboardStruct->Special.S.Ctrl = KeyboardStruct->Special.S.LCtrl | KeyboardStruct->Special.S.RCtrl;
		KeyboardStruct->Special.S.GUI = KeyboardStruct->Special.S.LGUI | KeyboardStruct->Special.S.RGUI;
	
		/* Keyboard connected and OK */
		return TM_USBH_HID_Keyboard;
	}
	
	/* Return ERROR */
	return TM_USBH_HID_None;
}