2 Implementation for EFI_SIMPLE_TEXT_INPUT_PROTOCOL protocol.
4 Copyright (c) 2006 - 2007 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
22 IN BOOLEAN ExtendedVerification
27 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
28 This driver only perform dependent serial device reset regardless of
29 the value of ExtendeVerification
33 This - Indicates the calling context.
35 ExtendedVerification - Skip by this driver.
40 The reset operation succeeds.
43 The dependent serial port reset fails.
48 TERMINAL_DEV
*TerminalDevice
;
50 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
53 // Report progress code here
55 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
57 PcdGet32 (PcdStatusCodeValueRemoteConsoleReset
),
58 TerminalDevice
->DevicePath
61 Status
= TerminalDevice
->SerialIo
->Reset (TerminalDevice
->SerialIo
);
64 // clear all the internal buffer for keys
66 InitializeRawFiFo (TerminalDevice
);
67 InitializeUnicodeFiFo (TerminalDevice
);
68 InitializeEfiKeyFiFo (TerminalDevice
);
70 if (EFI_ERROR (Status
)) {
71 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
72 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
73 PcdGet32 (PcdStatusCodeValueRemoteConsoleError
),
74 TerminalDevice
->DevicePath
83 TerminalConInReadKeyStroke (
84 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
85 OUT EFI_INPUT_KEY
*Key
90 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
94 This - Indicates the calling context.
96 Key - A pointer to a buffer that is filled in with the keystroke
97 information for the key that was sent from terminal.
102 The keystroke information is returned successfully.
105 There is no keystroke data available.
108 The dependent serial device encounters error.
112 TERMINAL_DEV
*TerminalDevice
;
116 // Initialize *Key to nonsense value.
118 Key
->ScanCode
= SCAN_NULL
;
119 Key
->UnicodeChar
= 0;
121 // get TERMINAL_DEV from "This" parameter.
123 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
125 Status
= TerminalConInCheckForKey (This
);
126 if (EFI_ERROR (Status
)) {
127 return EFI_NOT_READY
;
130 EfiKeyFiFoRemoveOneKey (TerminalDevice
, Key
);
137 TranslateRawDataToEfiKey (
138 IN TERMINAL_DEV
*TerminalDevice
141 Step1: Turn raw data into Unicode (according to different encode).
142 Step2: Translate Unicode into key information.
143 (according to different terminal standard).
146 switch (TerminalDevice
->TerminalType
) {
151 AnsiRawDataToUnicode (TerminalDevice
);
152 UnicodeToEfiKey (TerminalDevice
);
157 // Process all the raw data in the RawFIFO,
158 // put the processed key into UnicodeFIFO.
160 VTUTF8RawDataToUnicode (TerminalDevice
);
163 // Translate all the Unicode data in the UnicodeFIFO to Efi key,
164 // then put into EfiKeyFIFO.
166 UnicodeToEfiKey (TerminalDevice
);
174 TerminalConInWaitForKey (
181 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
182 Signal the event if there is key available
186 Event - Indicates the event that invoke this function.
188 Context - Indicates the calling context.
197 // Someone is waiting on the keystroke event, if there's
198 // a key pending, signal the event
200 // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
202 if (!EFI_ERROR (TerminalConInCheckForKey (Context
))) {
204 gBS
->SignalEvent (Event
);
209 TerminalConInCheckForKey (
210 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
215 Check for a pending key in the Efi Key FIFO or Serial device buffer.
219 This - Indicates the calling context.
224 There is key pending.
227 There is no key pending.
234 TERMINAL_DEV
*TerminalDevice
;
237 EFI_SERIAL_IO_MODE
*Mode
;
238 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
239 UINTN SerialInTimeOut
;
241 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
243 SerialIo
= TerminalDevice
->SerialIo
;
244 if (SerialIo
== NULL
) {
245 return EFI_DEVICE_ERROR
;
248 // if current timeout value for serial device is not identical with
249 // the value saved in TERMINAL_DEV structure, then recalculate the
250 // timeout value again and set serial attribute according to this value.
252 Mode
= SerialIo
->Mode
;
253 if (Mode
->Timeout
!= TerminalDevice
->SerialInTimeOut
) {
256 if (Mode
->BaudRate
!= 0) {
257 SerialInTimeOut
= (1 + Mode
->DataBits
+ Mode
->StopBits
) * 2 * 1000000 / (UINTN
) Mode
->BaudRate
;
260 Status
= SerialIo
->SetAttributes (
263 Mode
->ReceiveFifoDepth
,
264 (UINT32
) SerialInTimeOut
,
265 (EFI_PARITY_TYPE
) (Mode
->Parity
),
266 (UINT8
) Mode
->DataBits
,
267 (EFI_STOP_BITS_TYPE
) (Mode
->StopBits
)
270 if (EFI_ERROR (Status
)) {
271 TerminalDevice
->SerialInTimeOut
= 0;
273 TerminalDevice
->SerialInTimeOut
= SerialInTimeOut
;
277 // check whether serial buffer is empty
279 Status
= SerialIo
->GetControl (SerialIo
, &Control
);
281 if (Control
& EFI_SERIAL_INPUT_BUFFER_EMPTY
) {
283 // Translate all the raw data in RawFIFO into EFI Key,
284 // according to different terminal type supported.
286 TranslateRawDataToEfiKey (TerminalDevice
);
289 // if there is pre-fetched Efi Key in EfiKeyFIFO buffer,
292 if (!IsEfiKeyFiFoEmpty (TerminalDevice
)) {
295 return EFI_NOT_READY
;
299 // Fetch all the keys in the serial buffer,
300 // and insert the byte stream into RawFIFO.
304 Status
= GetOneKeyFromSerial (TerminalDevice
->SerialIo
, &Input
);
306 if (EFI_ERROR (Status
)) {
307 if (Status
== EFI_DEVICE_ERROR
) {
308 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
309 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
310 PcdGet32 (PcdStatusCodeValueRemoteConsoleInputError
),
311 TerminalDevice
->DevicePath
317 RawFiFoInsertOneKey (TerminalDevice
, Input
);
321 // Translate all the raw data in RawFIFO into EFI Key,
322 // according to different terminal type supported.
324 TranslateRawDataToEfiKey (TerminalDevice
);
326 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
327 return EFI_NOT_READY
;
334 GetOneKeyFromSerial (
335 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
339 Get one key out of serial buffer.
340 If serial buffer is empty, return EFI_NOT_READY;
341 if reading serial buffer encounter error, returns EFI_DEVICE_ERROR;
342 if reading serial buffer successfully, put the fetched key to
343 the parameter "Input", and return EFI_SUCCESS.
352 Status
= SerialIo
->Read (SerialIo
, &Size
, Input
);
354 if (EFI_ERROR (Status
)) {
356 if (Status
== EFI_TIMEOUT
) {
357 return EFI_NOT_READY
;
360 return EFI_DEVICE_ERROR
;
365 return EFI_NOT_READY
;
372 RawFiFoInsertOneKey (
373 TERMINAL_DEV
*TerminalDevice
,
377 Insert one byte raw data into the Raw Data FIFO.
378 If FIFO is FULL before data insertion,
379 return FALSE, and the key is lost.
384 Tail
= TerminalDevice
->RawFiFo
.Tail
;
386 if (IsRawFiFoFull (TerminalDevice
)) {
393 TerminalDevice
->RawFiFo
.Data
[Tail
] = Input
;
395 TerminalDevice
->RawFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
401 RawFiFoRemoveOneKey (
402 TERMINAL_DEV
*TerminalDevice
,
406 Remove one byte raw data out of the Raw Data FIFO.
407 If FIFO buffer is empty before remove operation,
413 Head
= TerminalDevice
->RawFiFo
.Head
;
415 if (IsRawFiFoEmpty (TerminalDevice
)) {
423 *Output
= TerminalDevice
->RawFiFo
.Data
[Head
];
425 TerminalDevice
->RawFiFo
.Head
= (UINT8
) ((Head
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
432 TERMINAL_DEV
*TerminalDevice
435 Clarify whether FIFO buffer is empty.
438 if (TerminalDevice
->RawFiFo
.Head
== TerminalDevice
->RawFiFo
.Tail
) {
447 TERMINAL_DEV
*TerminalDevice
450 Clarify whether FIFO buffer is full.
456 Tail
= TerminalDevice
->RawFiFo
.Tail
;
457 Head
= TerminalDevice
->RawFiFo
.Head
;
459 if (((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1)) == Head
) {
468 EfiKeyFiFoInsertOneKey (
469 TERMINAL_DEV
*TerminalDevice
,
473 Insert one pre-fetched key into the FIFO buffer.
474 If FIFO buffer is FULL before key insertion,
475 return FALSE, and the key is lost.
480 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
482 if (IsEfiKeyFiFoFull (TerminalDevice
)) {
484 // Efi Key FIFO is full
489 TerminalDevice
->EfiKeyFiFo
.Data
[Tail
] = Key
;
491 TerminalDevice
->EfiKeyFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
497 EfiKeyFiFoRemoveOneKey (
498 TERMINAL_DEV
*TerminalDevice
,
499 EFI_INPUT_KEY
*Output
502 Remove one pre-fetched key out of the FIFO buffer.
503 If FIFO buffer is empty before remove operation,
509 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
511 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
515 Output
->ScanCode
= SCAN_NULL
;
516 Output
->UnicodeChar
= 0;
520 *Output
= TerminalDevice
->EfiKeyFiFo
.Data
[Head
];
522 TerminalDevice
->EfiKeyFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
529 TERMINAL_DEV
*TerminalDevice
532 Clarify whether FIFO buffer is empty.
535 if (TerminalDevice
->EfiKeyFiFo
.Head
== TerminalDevice
->EfiKeyFiFo
.Tail
) {
544 TERMINAL_DEV
*TerminalDevice
547 Clarify whether FIFO buffer is full.
553 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
554 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
556 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
565 UnicodeFiFoInsertOneKey (
566 TERMINAL_DEV
*TerminalDevice
,
570 Insert one pre-fetched key into the FIFO buffer.
571 If FIFO buffer is FULL before key insertion,
572 return FALSE, and the key is lost.
577 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
579 if (IsUnicodeFiFoFull (TerminalDevice
)) {
581 // Unicode FIFO is full
586 TerminalDevice
->UnicodeFiFo
.Data
[Tail
] = Input
;
588 TerminalDevice
->UnicodeFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
594 UnicodeFiFoRemoveOneKey (
595 TERMINAL_DEV
*TerminalDevice
,
599 Remove one pre-fetched key out of the FIFO buffer.
600 If FIFO buffer is empty before remove operation,
606 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
608 if (IsUnicodeFiFoEmpty (TerminalDevice
)) {
616 *Output
= TerminalDevice
->UnicodeFiFo
.Data
[Head
];
618 TerminalDevice
->UnicodeFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
625 TERMINAL_DEV
*TerminalDevice
628 Clarify whether FIFO buffer is empty.
631 if (TerminalDevice
->UnicodeFiFo
.Head
== TerminalDevice
->UnicodeFiFo
.Tail
) {
640 TERMINAL_DEV
*TerminalDevice
643 Clarify whether FIFO buffer is full.
649 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
650 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
652 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
661 UnicodeFiFoGetKeyCount (
662 TERMINAL_DEV
*TerminalDevice
668 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
669 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
672 return (UINT8
) (Tail
- Head
);
674 return (UINT8
) (Tail
+ FIFO_MAX_NUMBER
+ 1 - Head
);
680 UnicodeToEfiKeyFlushState (
681 IN TERMINAL_DEV
*TerminalDevice
686 if (TerminalDevice
->InputState
& INPUT_STATE_ESC
) {
687 Key
.ScanCode
= SCAN_ESC
;
689 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
692 if (TerminalDevice
->InputState
& INPUT_STATE_CSI
) {
693 Key
.ScanCode
= SCAN_NULL
;
694 Key
.UnicodeChar
= CSI
;
695 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
698 if (TerminalDevice
->InputState
& INPUT_STATE_LEFTOPENBRACKET
) {
699 Key
.ScanCode
= SCAN_NULL
;
700 Key
.UnicodeChar
= LEFTOPENBRACKET
;
701 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
704 if (TerminalDevice
->InputState
& INPUT_STATE_O
) {
705 Key
.ScanCode
= SCAN_NULL
;
706 Key
.UnicodeChar
= 'O';
707 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
710 if (TerminalDevice
->InputState
& INPUT_STATE_2
) {
711 Key
.ScanCode
= SCAN_NULL
;
712 Key
.UnicodeChar
= '2';
713 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
717 TerminalDevice
->TwoSecondTimeOut
,
722 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
727 IN TERMINAL_DEV
*TerminalDevice
732 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
733 can be read through the Simple Input Protocol. The table below shows the keyboard
734 input mappings that this function supports. If the ESC sequence listed in one of the
735 columns is presented, then it is translated into the coorespoding EFI Scan Code. If a
736 matching sequence is not found, then the raw key strokes are converted into EFI Keys.
738 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
739 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
740 converted into EFI Keys.
742 There is one special input sequence that will force the system to reset.
743 This is ESC R ESC r ESC R.
747 TerminaDevice : The terminal device to use to translate raw input into EFI Keys
753 Symbols used in table below
754 ===========================
760 +=========+======+===========+==========+==========+
761 | | EFI | EFI 1.10 | | |
762 | | Scan | | VT100+ | |
763 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
764 +=========+======+===========+==========+==========+
765 | NULL | 0x00 | | | |
766 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
767 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
768 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
769 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
770 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
771 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
772 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
773 | | | ESC [ L | | ESC [ L |
774 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
775 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
777 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
779 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
780 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
781 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
782 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
783 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
784 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
785 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
786 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
787 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
788 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
789 | Escape | 0x17 | ESC | ESC | ESC |
790 +=========+======+===========+==========+=========+
794 ESC R ESC r ESC R = Reset System
799 EFI_STATUS TimerStatus
;
802 BOOLEAN SetDefaultResetState
;
804 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
806 if (!EFI_ERROR (TimerStatus
)) {
807 UnicodeToEfiKeyFlushState (TerminalDevice
);
808 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
811 while (!IsUnicodeFiFoEmpty(TerminalDevice
)) {
813 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
815 // Check to see if the 2 second timer has expired
817 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
818 if (!EFI_ERROR (TimerStatus
)) {
819 UnicodeToEfiKeyFlushState (TerminalDevice
);
820 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
825 // Fetch one Unicode character from the Unicode FIFO
827 UnicodeFiFoRemoveOneKey (TerminalDevice
,&UnicodeChar
);
829 SetDefaultResetState
= TRUE
;
831 switch (TerminalDevice
->InputState
) {
832 case INPUT_STATE_DEFAULT
:
836 case INPUT_STATE_ESC
:
838 if (UnicodeChar
== LEFTOPENBRACKET
) {
839 TerminalDevice
->InputState
|= INPUT_STATE_LEFTOPENBRACKET
;
840 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
844 if (UnicodeChar
== 'O' && TerminalDevice
->TerminalType
== VT100Type
) {
845 TerminalDevice
->InputState
|= INPUT_STATE_O
;
846 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
850 Key
.ScanCode
= SCAN_NULL
;
852 if (TerminalDevice
->TerminalType
== VT100PlusType
||
853 TerminalDevice
->TerminalType
== VTUTF8Type
) {
854 switch (UnicodeChar
) {
856 Key
.ScanCode
= SCAN_F1
;
859 Key
.ScanCode
= SCAN_F2
;
862 Key
.ScanCode
= SCAN_F3
;
865 Key
.ScanCode
= SCAN_F4
;
868 Key
.ScanCode
= SCAN_F5
;
871 Key
.ScanCode
= SCAN_F6
;
874 Key
.ScanCode
= SCAN_F7
;
877 Key
.ScanCode
= SCAN_F8
;
880 Key
.ScanCode
= SCAN_F9
;
883 Key
.ScanCode
= SCAN_F10
;
886 Key
.ScanCode
= SCAN_HOME
;
889 Key
.ScanCode
= SCAN_END
;
892 Key
.ScanCode
= SCAN_INSERT
;
895 Key
.ScanCode
= SCAN_DELETE
;
898 Key
.ScanCode
= SCAN_PAGE_DOWN
;
901 Key
.ScanCode
= SCAN_PAGE_UP
;
908 switch (UnicodeChar
) {
910 if (TerminalDevice
->ResetState
== RESET_STATE_DEFAULT
) {
911 TerminalDevice
->ResetState
= RESET_STATE_ESC_R
;
912 SetDefaultResetState
= FALSE
;
913 } else if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R_ESC_r
) {
914 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
916 Key
.ScanCode
= SCAN_NULL
;
919 if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R
) {
920 TerminalDevice
->ResetState
= RESET_STATE_ESC_R_ESC_r
;
921 SetDefaultResetState
= FALSE
;
923 Key
.ScanCode
= SCAN_NULL
;
929 if (SetDefaultResetState
) {
930 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
933 if (Key
.ScanCode
!= SCAN_NULL
) {
935 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
936 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
937 UnicodeToEfiKeyFlushState (TerminalDevice
);
941 UnicodeToEfiKeyFlushState (TerminalDevice
);
945 case INPUT_STATE_ESC
| INPUT_STATE_O
:
947 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
949 Key
.ScanCode
= SCAN_NULL
;
951 if (TerminalDevice
->TerminalType
== VT100Type
) {
952 switch (UnicodeChar
) {
954 Key
.ScanCode
= SCAN_F1
;
957 Key
.ScanCode
= SCAN_F2
;
960 Key
.ScanCode
= SCAN_F3
;
963 Key
.ScanCode
= SCAN_F4
;
966 Key
.ScanCode
= SCAN_F5
;
969 Key
.ScanCode
= SCAN_F6
;
972 Key
.ScanCode
= SCAN_F7
;
975 Key
.ScanCode
= SCAN_F8
;
978 Key
.ScanCode
= SCAN_F9
;
981 Key
.ScanCode
= SCAN_F10
;
988 if (Key
.ScanCode
!= SCAN_NULL
) {
990 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
991 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
992 UnicodeToEfiKeyFlushState (TerminalDevice
);
996 UnicodeToEfiKeyFlushState (TerminalDevice
);
1000 case INPUT_STATE_ESC
| INPUT_STATE_LEFTOPENBRACKET
:
1002 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1004 Key
.ScanCode
= SCAN_NULL
;
1006 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1007 TerminalDevice
->TerminalType
== VT100Type
||
1008 TerminalDevice
->TerminalType
== VT100PlusType
||
1009 TerminalDevice
->TerminalType
== VTUTF8Type
) {
1010 switch (UnicodeChar
) {
1012 Key
.ScanCode
= SCAN_UP
;
1015 Key
.ScanCode
= SCAN_DOWN
;
1018 Key
.ScanCode
= SCAN_RIGHT
;
1021 Key
.ScanCode
= SCAN_LEFT
;
1024 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1025 TerminalDevice
->TerminalType
== VT100Type
) {
1026 Key
.ScanCode
= SCAN_HOME
;
1030 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1031 Key
.ScanCode
= SCAN_END
;
1035 if (TerminalDevice
->TerminalType
== VT100Type
) {
1036 Key
.ScanCode
= SCAN_END
;
1041 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1042 TerminalDevice
->TerminalType
== VT100Type
) {
1043 Key
.ScanCode
= SCAN_INSERT
;
1047 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1048 Key
.ScanCode
= SCAN_DELETE
;
1052 if (TerminalDevice
->TerminalType
== VT100Type
) {
1053 Key
.ScanCode
= SCAN_DELETE
;
1054 } else if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1055 Key
.ScanCode
= SCAN_F4
;
1059 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1060 Key
.ScanCode
= SCAN_PAGE_UP
;
1064 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1065 Key
.ScanCode
= SCAN_F10
;
1068 if (TerminalDevice
->TerminalType
== VT100Type
) {
1069 Key
.ScanCode
= SCAN_PAGE_UP
;
1073 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1074 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1078 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1079 Key
.ScanCode
= SCAN_F9
;
1082 if (TerminalDevice
->TerminalType
== VT100Type
) {
1083 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1087 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1088 Key
.ScanCode
= SCAN_F1
;
1092 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1093 Key
.ScanCode
= SCAN_F2
;
1097 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1098 Key
.ScanCode
= SCAN_F3
;
1102 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1103 Key
.ScanCode
= SCAN_F5
;
1107 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1108 Key
.ScanCode
= SCAN_F6
;
1112 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1113 Key
.ScanCode
= SCAN_F7
;
1117 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1118 Key
.ScanCode
= SCAN_F8
;
1126 if (Key
.ScanCode
!= SCAN_NULL
) {
1127 Key
.UnicodeChar
= 0;
1128 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
1129 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1130 UnicodeToEfiKeyFlushState (TerminalDevice
);
1134 UnicodeToEfiKeyFlushState (TerminalDevice
);
1141 // Invalid state. This should never happen.
1145 UnicodeToEfiKeyFlushState (TerminalDevice
);
1150 if (UnicodeChar
== ESC
) {
1151 TerminalDevice
->InputState
= INPUT_STATE_ESC
;
1154 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
1155 Status
= gBS
->SetTimer(
1156 TerminalDevice
->TwoSecondTimeOut
,
1160 ASSERT_EFI_ERROR (Status
);
1164 if (SetDefaultResetState
) {
1165 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1168 if (UnicodeChar
== DEL
) {
1169 Key
.ScanCode
= SCAN_DELETE
;
1170 Key
.UnicodeChar
= 0;
1172 Key
.ScanCode
= SCAN_NULL
;
1173 Key
.UnicodeChar
= UnicodeChar
;
1176 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);