⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 efikey.c

📁 Next BIOS Source code : Extensible Firmware Interface
💻 C
📖 第 1 页 / 共 2 页
字号:
    gBS->CloseEvent(UsbKeyboardDevice->SimpleInput.WaitForKey);
    gBS->FreePool (UsbKeyboardDevice);
    gBS->CloseProtocol (
            Controller, 
            &gEfiUsbIoProtocolGuid, 
            This->DriverBindingHandle,   
            Controller   
         );
    return Status;
  }
    
  //
  // Reset USB Keyboard Device
  //
  Status = UsbKeyboardDevice->SimpleInput.Reset(
                          &UsbKeyboardDevice->SimpleInput,
                          TRUE
                          ); 
  if(EFI_ERROR(Status)) {
    gBS->UninstallMultipleProtocolInterfaces (
                 Controller,
                 &gEfiSimpleTextInProtocolGuid,
                 &UsbKeyboardDevice->SimpleInput,
                 &gEfiHotPlugDeviceGuid,
                 NULL,
                 NULL
                 );
    gBS->CloseEvent(UsbKeyboardDevice->SimpleInput.WaitForKey);
    gBS->FreePool(UsbKeyboardDevice);
    gBS->CloseProtocol (
            Controller, 
            &gEfiUsbIoProtocolGuid, 
            This->DriverBindingHandle,   
            Controller   
         );
    return Status;
  } 

  //
  // submit async interrupt transfer
  //
  EndpointAddr    = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress;
  PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval;
  PacketSize      = 
        (UINT8)(UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);
    
  Status = UsbIo->UsbAsyncInterruptTransfer(
                    UsbIo,
                    EndpointAddr,
                    TRUE,
                    PollingInterval,
                    PacketSize,
                    KeyboardHandler,
                    UsbKeyboardDevice
              );
    
  if(EFI_ERROR(Status)) {
    
    gBS->UninstallMultipleProtocolInterfaces (
                 Controller,
                 &gEfiSimpleTextInProtocolGuid,
                 &UsbKeyboardDevice->SimpleInput,
                 &gEfiHotPlugDeviceGuid,
                 NULL,
                 NULL
                 );
    gBS->CloseEvent(UsbKeyboardDevice->SimpleInput.WaitForKey);    
    gBS->FreePool(UsbKeyboardDevice);
    gBS->CloseProtocol (
            Controller, 
            &gEfiUsbIoProtocolGuid, 
            This->DriverBindingHandle,   
            Controller   
         );
    return Status;
  }

  UsbKeyboardDevice->ControllerNameTable = NULL;
  EfiLibAddUnicodeString (
    "eng", 
    gUsbKeyboardComponentName.SupportedLanguages, 
    &UsbKeyboardDevice->ControllerNameTable,
    L"Generic Usb Keyboard"
  );
      
  return EFI_SUCCESS;
}


EFI_STATUS
USBKeyboardDriverBindingStop (
  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,
  IN  EFI_HANDLE                     Controller,
  IN  UINTN                          NumberOfChildren,
  IN  EFI_HANDLE                     *ChildHandleBuffer
  )
/*++
  
  Routine Description:
    Stop.
  
  Arguments:
    (Standard DriverBinding Protocol Stop() function)
  
  Returns:
    EFI_STATUS
  
--*/       
{
  EFI_STATUS                      Status;
  EFI_SIMPLE_TEXT_IN_PROTOCOL     *SimpleInput;
  USB_KB_DEV                      *UsbKeyboardDevice;

  Status = gBS->OpenProtocol (
                    Controller, 
                    &gEfiSimpleTextInProtocolGuid, 
                    &SimpleInput,
                    This->DriverBindingHandle,   
                    Controller,   
                    EFI_OPEN_PROTOCOL_BY_DRIVER
                    );                     
  if (EFI_ERROR (Status)) {
    return EFI_UNSUPPORTED;
  }
  
  //
  // Get USB_KB_DEV instance.
  //
  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);
    
  gBS->CloseProtocol(
            Controller,
            &gEfiSimpleTextInProtocolGuid,
            This->DriverBindingHandle,
            Controller
            );
  
  //
  // Destroy asynchronous interrupt transfer
  //
  UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer(
                 UsbKeyboardDevice->UsbIo,
                 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
                 FALSE,
                 UsbKeyboardDevice->IntEndpointDescriptor.Interval,
                 0,
                 NULL,
                 NULL
                 );
      
  gBS->CloseProtocol (
              Controller, 
              &gEfiUsbIoProtocolGuid, 
              This->DriverBindingHandle, 
              Controller
           ); 
  
  Status = gBS->UninstallMultipleProtocolInterfaces (
                 Controller,
                 &gEfiSimpleTextInProtocolGuid,
                 &UsbKeyboardDevice->SimpleInput,
                 &gEfiHotPlugDeviceGuid,
                 NULL,
                 NULL
                 );
  //
  // free all the resources.
  //
  gBS->CloseEvent(UsbKeyboardDevice->RepeatTimer);
  gBS->CloseEvent((UsbKeyboardDevice->SimpleInput).WaitForKey);
  
  if (UsbKeyboardDevice->ControllerNameTable != NULL) {
    EfiLibFreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);
  }
      
  gBS->FreePool (UsbKeyboardDevice);
  
  return Status;
  
}


EFI_STATUS
USBKeyboardReset (
    IN  EFI_SIMPLE_TEXT_IN_PROTOCOL   *This, 
    IN  BOOLEAN             ExtendedVerification
    )
/*++

  Routine Description:
    Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset() function.
  
  Arguments:
    This:     The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.
    ExtendedVerification:
              Indicates that the driver may perform a more exhaustive
              verification operation of the device during reset.              
    
  Returns:  

--*/      
{
  EFI_STATUS        Status;
  USB_KB_DEV        *UsbKeyboardDevice;
  
  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
  
  //
  // Non Exhaustive reset:
  // only reset private data structures.
  //
  if(!ExtendedVerification) {
    InitUSBKeyBuffer(&(UsbKeyboardDevice->KeyboardBuffer));
    UsbKeyboardDevice->CurKeyChar = 0;
    return EFI_SUCCESS;
  }
  
  //
  // Exhaustive reset
  //
  Status = InitUSBKeyboard(UsbKeyboardDevice);
  if(EFI_ERROR(Status)) {
    return EFI_DEVICE_ERROR;
  }
  
  return EFI_SUCCESS;
}     
    

STATIC
EFI_STATUS 
EFIAPI 
USBKeyboardReadKeyStroke (
    IN  EFI_SIMPLE_TEXT_IN_PROTOCOL   *This, 
    OUT EFI_INPUT_KEY                 *Key
    )
/*++

  Routine Description:
    Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke() function.
  
  Arguments:
    This:     The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.
    Key:      A pointer to a buffer that is filled in with the keystroke
              information for the key that was pressed.
    
  Returns:  

--*/       
{
  USB_KB_DEV      *UsbKeyboardDevice;
  EFI_STATUS      Status;
  UINT8           KeyChar;
  
  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS(This);
  
  //
  // if there is no saved ASCII byte, fetch it 
  // by calling USBKeyboardCheckForKey().
  //
  if(UsbKeyboardDevice->CurKeyChar == 0) {
    Status = USBKeyboardCheckForKey(UsbKeyboardDevice);
    if(EFI_ERROR(Status)) {
      return Status;
    }
  }

  Key->UnicodeChar = 0;
  Key->ScanCode = SCAN_NULL;

  KeyChar = UsbKeyboardDevice->CurKeyChar;
  
  UsbKeyboardDevice->CurKeyChar = 0;
  
  //
  // Translate saved ASCII byte into EFI_INPUT_KEY
  //
  Status = USBKeyCodeToEFIScanCode(UsbKeyboardDevice, KeyChar,Key);
  
  return Status;  
  
}     

STATIC
VOID 
EFIAPI
USBKeyboardWaitForKey (
    IN  EFI_EVENT               Event,
    IN  VOID                    *Context
    )
/*++

  Routine Description:
    Handler function for WaitForKey event.    
  
  Arguments:
    Event:        Event to be signaled when a key is pressed.
    Context:      Points to USB_KB_DEV instance.
    
  Returns:  

--*/       
{
  USB_KB_DEV        *UsbKeyboardDevice;
  
  UsbKeyboardDevice = (USB_KB_DEV*)Context;
  
  if(UsbKeyboardDevice->CurKeyChar == 0) {
    
    if (EFI_ERROR(USBKeyboardCheckForKey(UsbKeyboardDevice))) {
      return;
    }
  }
  //
  // If has key pending, signal the event.
  //
  gBS->SignalEvent(Event);
}


STATIC
EFI_STATUS
USBKeyboardCheckForKey (
  IN  USB_KB_DEV    *UsbKeyboardDevice
  )
/*++

  Routine Description:
    Check whether there is key pending.
  
  Arguments:
    UsbKeyboardDevice:    The USB_KB_DEV instance.
    
  Returns:  

--*/       
{
  EFI_STATUS      Status;
  UINT8           KeyChar;
  
  //
  // Fetch raw data from the USB keyboard input,
  // and translate it into ASCII data.
  //
  Status = USBParseKey(UsbKeyboardDevice,&KeyChar);
  if(EFI_ERROR(Status)) {
    return Status;
  }
  UsbKeyboardDevice->CurKeyChar = KeyChar;
  return EFI_SUCCESS;
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -