void MainWindowWrapper::InitOpenGLWindow(int argc, char** argv) { if(m_params.bGPU) glutInitDisplayMode(GLUT_RGBA | GLUT_MULTISAMPLE); else glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_SINGLE); glutInitWindowSize(m_params.w, m_params.h ); glutInitWindowPosition(m_params.x, m_params.y); glutInit(&argc, argv); m_MainWindow = glutCreateWindow(m_params.title.c_str()); glutReshapeFunc(MainWindowWrapper::MainReshape); glutDisplayFunc(MainWindowWrapper::MainDisplay); glutKeyboardFunc(MainWindowWrapper::KeyboardExitCommand); m_SimuWindow = glutCreateSubWindow(m_MainWindow, m_params.simu_window.x, m_params.simu_window.y, m_params.simu_window.w, m_params.simu_window.h); glutReshapeFunc(MainWindowWrapper::SimuReshape); glutDisplayFunc(MainWindowWrapper::SimuDisplay); glutKeyboardFunc(MainWindowWrapper::KeyboardCommand); glutSpecialFunc(MainWindowWrapper::KeyboardSpecialCommand); glutPostRedisplay(); KeyboardCommand('f', 0,0); atexit(CleanUp); cout << "Before The OpenGL Main Loop" << endl; glutMainLoop(); }
/** Disable the keyboard interface of the 8042 controller. @param ConsoleIn The device instance @return status of issuing disable command **/ EFI_STATUS DisableKeyboard ( IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn ) { EFI_STATUS Status; // // Disable keyboard interface // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"\n\r"); return EFI_DEVICE_ERROR; } return Status; }
/** Perform 8042 controller and keyboard Initialization. If ExtendedVerification is TRUE, do additional test for the keyboard interface @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer @param ExtendedVerification - indicates a thorough initialization @retval EFI_DEVICE_ERROR Fail to init keyboard @retval EFI_SUCCESS Success to init keyboard **/ EFI_STATUS InitKeyboard ( IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn, IN BOOLEAN ExtendedVerification ) { EFI_STATUS Status; EFI_STATUS Status1; UINT8 CommandByte; EFI_PS2_POLICY_PROTOCOL *Ps2Policy; UINT32 TryTime; Status = EFI_SUCCESS; mEnableMouseInterface = TRUE; TryTime = 0; // // Get Ps2 policy to set this // gBS->LocateProtocol ( &gEfiPs2PolicyProtocolGuid, NULL, (VOID **) &Ps2Policy ); REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER, ConsoleIn->DevicePath ); // // Perform a read to cleanup the Status Register's // output buffer full bits within MAX TRY times // while (!EFI_ERROR (Status) && TryTime < KEYBOARD_MAX_TRY) { Status = KeyboardRead (ConsoleIn, &CommandByte); TryTime ++; } // // Exceed the max try times. The device may be error. // if (TryTime == KEYBOARD_MAX_TRY) { Status = EFI_DEVICE_ERROR; goto Done; } // // We should disable mouse interface during the initialization process // since mouse device output could block keyboard device output in the // 60H port of 8042 controller. // // So if we are not initializing 8042 controller for the // first time, we have to remember the previous mouse interface // enabling state // // Test the system flag in to determine whether this is the first // time initialization // if ((KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG) != 0) { // // 8042 controller is already setup (by myself or by mouse driver): // See whether mouse interface is already enabled // which determines whether we should enable it later // // // Read the command byte of 8042 controller // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_READ); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"\n\r"); goto Done; } Status = KeyboardRead (ConsoleIn, &CommandByte); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"\n\r"); goto Done; } // // Test the mouse enabling bit // if ((CommandByte & 0x20) != 0) { mEnableMouseInterface = FALSE; } else { mEnableMouseInterface = TRUE; } } else { // // 8042 controller is not setup yet: // 8042 controller selftest; // Don't enable mouse interface later. // // // Disable keyboard and mouse interfaces // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"\n\r"); goto Done; } Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"\n\r"); goto Done; } REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST, ConsoleIn->DevicePath ); // // 8042 Controller Self Test // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, 0x55); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller self test failed!\n\r"); goto Done; } // // Don't enable mouse interface later // mEnableMouseInterface = FALSE; } if (Ps2Policy != NULL) { Ps2Policy->Ps2InitHardware (ConsoleIn->Handle); } // // Write 8042 Command Byte, set System Flag // While at the same time: // 1. disable mouse interface, // 2. enable kbd interface, // 3. enable PC/XT kbd translation mode // 4. enable mouse and kbd interrupts // // ( Command Byte bits: // 7: Reserved // 6: PC/XT translation mode // 5: Disable Auxiliary device interface // 4: Disable keyboard interface // 3: Reserved // 2: System Flag // 1: Enable Auxiliary device interrupt // 0: Enable Keyboard interrupt ) // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_WRITE); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r"); goto Done; } Status = KeyboardWrite (ConsoleIn, 0x67); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r"); goto Done; } // // Clear Memory Scancode Buffer // ConsoleIn->ScancodeBufStartPos = 0; ConsoleIn->ScancodeBufEndPos = KEYBOARD_BUFFER_MAX_COUNT - 1; ConsoleIn->ScancodeBufCount = 0; ConsoleIn->Ctrled = FALSE; ConsoleIn->Alted = FALSE; // // Reset the status indicators // ConsoleIn->Ctrl = FALSE; ConsoleIn->Alt = FALSE; ConsoleIn->Shift = FALSE; ConsoleIn->CapsLock = FALSE; ConsoleIn->NumLock = FALSE; ConsoleIn->ScrollLock = FALSE; ConsoleIn->LeftShift = FALSE; ConsoleIn->RightShift = FALSE; ConsoleIn->LeftLogo = FALSE; ConsoleIn->RightLogo = FALSE; ConsoleIn->Menu = FALSE; ConsoleIn->SysReq = FALSE; // // For reseting keyboard is not mandatory before booting OS and sometimes keyboard responses very slow, // and to support KB hot plug, we need to let the InitKB succeed no matter whether there is a KB device connected // to system. So we only do the real reseting for keyboard when user asks and there is a real KB connected t system, // and normally during booting an OS, it's skipped. // if (ExtendedVerification && CheckKeyboardConnect (ConsoleIn)) { // // Additional verifications for keyboard interface // // // Keyboard Interface Test // Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, 0x00); if (EFI_ERROR (Status)) { KeyboardError ( ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r" ); goto Done; } // // Keyboard reset with a BAT(Basic Assurance Test) // Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_RESET); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r"); goto Done; } // // wait for BAT completion code // mWaitForValueTimeOut = KEYBOARD_BAT_TIMEOUT; Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_BAT_SUCCESS); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Keyboard self test failed!\n\r"); goto Done; } mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT; // // Set Keyboard to use Scan Code Set 2 // Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r"); goto Done; } Status = KeyboardWrite (ConsoleIn, 0x02); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller data write error!!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r"); goto Done; } // // Clear Keyboard Scancode Buffer // Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r"); goto Done; } Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r"); goto Done; } // if (Ps2Policy != NULL) { if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_CAPSLOCK) == EFI_KEYBOARD_CAPSLOCK) { ConsoleIn->CapsLock = TRUE; } if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_NUMLOCK) == EFI_KEYBOARD_NUMLOCK) { ConsoleIn->NumLock = TRUE; } if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_SCROLLLOCK) == EFI_KEYBOARD_SCROLLLOCK) { ConsoleIn->ScrollLock = TRUE; } } // // Update Keyboard Lights // Status = UpdateStatusLights (ConsoleIn); if (EFI_ERROR (Status)) { KeyboardError (ConsoleIn, L"Update keyboard status lights error!\n\r"); goto Done; } } // // At last, we can now enable the mouse interface if appropriate // Done: if (mEnableMouseInterface) { // // Enable mouse interface // Status1 = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE); if (EFI_ERROR (Status1)) { KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r"); return EFI_DEVICE_ERROR; } } if (!EFI_ERROR (Status)) { return EFI_SUCCESS; } else { return EFI_DEVICE_ERROR; } }