3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
28 IN BOOLEAN ExtendedVerification
33 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset().
34 This driver only perform dependent serial device reset regardless of
35 the value of ExtendeVerification
39 This - Indicates the calling context.
41 ExtendedVerification - Skip by this driver.
46 The reset operation succeeds.
49 The dependent serial port reset fails.
54 TERMINAL_DEV
*TerminalDevice
;
56 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
59 // Report progress code here
61 Status
= REPORT_STATUS_CODE_WITH_DEVICE_PATH (
63 EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_PC_RESET
,
64 TerminalDevice
->DevicePath
67 Status
= TerminalDevice
->SerialIo
->Reset (TerminalDevice
->SerialIo
);
70 // clear all the internal buffer for keys
72 InitializeRawFiFo (TerminalDevice
);
73 InitializeUnicodeFiFo (TerminalDevice
);
74 InitializeEfiKeyFiFo (TerminalDevice
);
76 if (EFI_ERROR (Status
)) {
77 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
78 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
79 EFI_PERIPHERAL_LOCAL_CONSOLE
| EFI_P_EC_CONTROLLER_ERROR
,
80 TerminalDevice
->DevicePath
89 TerminalConInReadKeyStroke (
90 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
91 OUT EFI_INPUT_KEY
*Key
96 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke().
100 This - Indicates the calling context.
102 Key - A pointer to a buffer that is filled in with the keystroke
103 information for the key that was sent from terminal.
108 The keystroke information is returned successfully.
111 There is no keystroke data available.
114 The dependent serial device encounters error.
118 TERMINAL_DEV
*TerminalDevice
;
122 // Initialize *Key to nonsense value.
124 Key
->ScanCode
= SCAN_NULL
;
125 Key
->UnicodeChar
= 0;
127 // get TERMINAL_DEV from "This" parameter.
129 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
131 Status
= TerminalConInCheckForKey (This
);
132 if (EFI_ERROR (Status
)) {
133 return EFI_NOT_READY
;
136 EfiKeyFiFoRemoveOneKey (TerminalDevice
, Key
);
143 TranslateRawDataToEfiKey (
144 IN TERMINAL_DEV
*TerminalDevice
147 Step1: Turn raw data into Unicode (according to different encode).
148 Step2: Translate Unicode into key information.
149 (according to different terminal standard).
152 switch (TerminalDevice
->TerminalType
) {
157 AnsiRawDataToUnicode (TerminalDevice
);
158 UnicodeToEfiKey (TerminalDevice
);
163 // Process all the raw data in the RawFIFO,
164 // put the processed key into UnicodeFIFO.
166 VTUTF8RawDataToUnicode (TerminalDevice
);
169 // Translate all the Unicode data in the UnicodeFIFO to Efi key,
170 // then put into EfiKeyFIFO.
172 UnicodeToEfiKey (TerminalDevice
);
180 TerminalConInWaitForKey (
187 Event notification function for EFI_SIMPLE_TEXT_IN_PROTOCOL.WaitForKey event
188 Signal the event if there is key available
192 Event - Indicates the event that invoke this function.
194 Context - Indicates the calling context.
203 // Someone is waiting on the keystroke event, if there's
204 // a key pending, signal the event
206 // Context is the pointer to EFI_SIMPLE_TEXT_IN_PROTOCOL
208 if (!EFI_ERROR (TerminalConInCheckForKey (Context
))) {
210 gBS
->SignalEvent (Event
);
215 TerminalConInCheckForKey (
216 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
221 Check for a pending key in the Efi Key FIFO or Serial device buffer.
225 This - Indicates the calling context.
230 There is key pending.
233 There is no key pending.
240 TERMINAL_DEV
*TerminalDevice
;
243 EFI_SERIAL_IO_MODE
*Mode
;
244 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
245 UINTN SerialInTimeOut
;
247 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
249 SerialIo
= TerminalDevice
->SerialIo
;
250 if (SerialIo
== NULL
) {
251 return EFI_DEVICE_ERROR
;
254 // if current timeout value for serial device is not identical with
255 // the value saved in TERMINAL_DEV structure, then recalculate the
256 // timeout value again and set serial attribute according to this value.
258 Mode
= SerialIo
->Mode
;
259 if (Mode
->Timeout
!= TerminalDevice
->SerialInTimeOut
) {
262 if (Mode
->BaudRate
!= 0) {
263 SerialInTimeOut
= (1 + Mode
->DataBits
+ Mode
->StopBits
) * 2 * 1000000 / (UINTN
) Mode
->BaudRate
;
266 Status
= SerialIo
->SetAttributes (
269 Mode
->ReceiveFifoDepth
,
270 (UINT32
) SerialInTimeOut
,
271 (EFI_PARITY_TYPE
) (Mode
->Parity
),
272 (UINT8
) Mode
->DataBits
,
273 (EFI_STOP_BITS_TYPE
) (Mode
->StopBits
)
276 if (EFI_ERROR (Status
)) {
277 TerminalDevice
->SerialInTimeOut
= 0;
279 TerminalDevice
->SerialInTimeOut
= SerialInTimeOut
;
283 // check whether serial buffer is empty
285 Status
= SerialIo
->GetControl (SerialIo
, &Control
);
287 if (Control
& EFI_SERIAL_INPUT_BUFFER_EMPTY
) {
289 // Translate all the raw data in RawFIFO into EFI Key,
290 // according to different terminal type supported.
292 TranslateRawDataToEfiKey (TerminalDevice
);
295 // if there is pre-fetched Efi Key in EfiKeyFIFO buffer,
298 if (!IsEfiKeyFiFoEmpty (TerminalDevice
)) {
301 return EFI_NOT_READY
;
305 // Fetch all the keys in the serial buffer,
306 // and insert the byte stream into RawFIFO.
310 Status
= GetOneKeyFromSerial (TerminalDevice
->SerialIo
, &Input
);
312 if (EFI_ERROR (Status
)) {
313 if (Status
== EFI_DEVICE_ERROR
) {
314 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
315 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
316 EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_EC_INPUT_ERROR
,
317 TerminalDevice
->DevicePath
323 RawFiFoInsertOneKey (TerminalDevice
, Input
);
327 // Translate all the raw data in RawFIFO into EFI Key,
328 // according to different terminal type supported.
330 TranslateRawDataToEfiKey (TerminalDevice
);
332 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
333 return EFI_NOT_READY
;
340 GetOneKeyFromSerial (
341 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
345 Get one key out of serial buffer.
346 If serial buffer is empty, return EFI_NOT_READY;
347 if reading serial buffer encounter error, returns EFI_DEVICE_ERROR;
348 if reading serial buffer successfully, put the fetched key to
349 the parameter "Input", and return EFI_SUCCESS.
358 Status
= SerialIo
->Read (SerialIo
, &Size
, Input
);
360 if (EFI_ERROR (Status
)) {
362 if (Status
== EFI_TIMEOUT
) {
363 return EFI_NOT_READY
;
366 return EFI_DEVICE_ERROR
;
371 return EFI_NOT_READY
;
378 RawFiFoInsertOneKey (
379 TERMINAL_DEV
*TerminalDevice
,
383 Insert one byte raw data into the Raw Data FIFO.
384 If FIFO is FULL before data insertion,
385 return FALSE, and the key is lost.
390 Tail
= TerminalDevice
->RawFiFo
.Tail
;
392 if (IsRawFiFoFull (TerminalDevice
)) {
399 TerminalDevice
->RawFiFo
.Data
[Tail
] = Input
;
401 TerminalDevice
->RawFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
407 RawFiFoRemoveOneKey (
408 TERMINAL_DEV
*TerminalDevice
,
412 Remove one byte raw data out of the Raw Data FIFO.
413 If FIFO buffer is empty before remove operation,
419 Head
= TerminalDevice
->RawFiFo
.Head
;
421 if (IsRawFiFoEmpty (TerminalDevice
)) {
429 *Output
= TerminalDevice
->RawFiFo
.Data
[Head
];
431 TerminalDevice
->RawFiFo
.Head
= (UINT8
) ((Head
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
438 TERMINAL_DEV
*TerminalDevice
441 Clarify whether FIFO buffer is empty.
444 if (TerminalDevice
->RawFiFo
.Head
== TerminalDevice
->RawFiFo
.Tail
) {
453 TERMINAL_DEV
*TerminalDevice
456 Clarify whether FIFO buffer is full.
462 Tail
= TerminalDevice
->RawFiFo
.Tail
;
463 Head
= TerminalDevice
->RawFiFo
.Head
;
465 if (((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1)) == Head
) {
474 EfiKeyFiFoInsertOneKey (
475 TERMINAL_DEV
*TerminalDevice
,
479 Insert one pre-fetched key into the FIFO buffer.
480 If FIFO buffer is FULL before key insertion,
481 return FALSE, and the key is lost.
486 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
488 if (IsEfiKeyFiFoFull (TerminalDevice
)) {
490 // Efi Key FIFO is full
495 TerminalDevice
->EfiKeyFiFo
.Data
[Tail
] = Key
;
497 TerminalDevice
->EfiKeyFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
503 EfiKeyFiFoRemoveOneKey (
504 TERMINAL_DEV
*TerminalDevice
,
505 EFI_INPUT_KEY
*Output
508 Remove one pre-fetched key out of the FIFO buffer.
509 If FIFO buffer is empty before remove operation,
515 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
517 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
521 Output
->ScanCode
= SCAN_NULL
;
522 Output
->UnicodeChar
= 0;
526 *Output
= TerminalDevice
->EfiKeyFiFo
.Data
[Head
];
528 TerminalDevice
->EfiKeyFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
535 TERMINAL_DEV
*TerminalDevice
538 Clarify whether FIFO buffer is empty.
541 if (TerminalDevice
->EfiKeyFiFo
.Head
== TerminalDevice
->EfiKeyFiFo
.Tail
) {
550 TERMINAL_DEV
*TerminalDevice
553 Clarify whether FIFO buffer is full.
559 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
560 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
562 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
571 UnicodeFiFoInsertOneKey (
572 TERMINAL_DEV
*TerminalDevice
,
576 Insert one pre-fetched key into the FIFO buffer.
577 If FIFO buffer is FULL before key insertion,
578 return FALSE, and the key is lost.
583 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
585 if (IsUnicodeFiFoFull (TerminalDevice
)) {
587 // Unicode FIFO is full
592 TerminalDevice
->UnicodeFiFo
.Data
[Tail
] = Input
;
594 TerminalDevice
->UnicodeFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
600 UnicodeFiFoRemoveOneKey (
601 TERMINAL_DEV
*TerminalDevice
,
605 Remove one pre-fetched key out of the FIFO buffer.
606 If FIFO buffer is empty before remove operation,
612 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
614 if (IsUnicodeFiFoEmpty (TerminalDevice
)) {
622 *Output
= TerminalDevice
->UnicodeFiFo
.Data
[Head
];
624 TerminalDevice
->UnicodeFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
631 TERMINAL_DEV
*TerminalDevice
634 Clarify whether FIFO buffer is empty.
637 if (TerminalDevice
->UnicodeFiFo
.Head
== TerminalDevice
->UnicodeFiFo
.Tail
) {
646 TERMINAL_DEV
*TerminalDevice
649 Clarify whether FIFO buffer is full.
655 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
656 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
658 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
667 UnicodeFiFoGetKeyCount (
668 TERMINAL_DEV
*TerminalDevice
674 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
675 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
678 return (UINT8
) (Tail
- Head
);
680 return (UINT8
) (Tail
+ FIFO_MAX_NUMBER
+ 1 - Head
);
686 UnicodeToEfiKeyFlushState (
687 IN TERMINAL_DEV
*TerminalDevice
692 if (TerminalDevice
->InputState
& INPUT_STATE_ESC
) {
693 Key
.ScanCode
= SCAN_ESC
;
695 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
698 if (TerminalDevice
->InputState
& INPUT_STATE_CSI
) {
699 Key
.ScanCode
= SCAN_NULL
;
700 Key
.UnicodeChar
= CSI
;
701 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
704 if (TerminalDevice
->InputState
& INPUT_STATE_LEFTOPENBRACKET
) {
705 Key
.ScanCode
= SCAN_NULL
;
706 Key
.UnicodeChar
= LEFTOPENBRACKET
;
707 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
710 if (TerminalDevice
->InputState
& INPUT_STATE_O
) {
711 Key
.ScanCode
= SCAN_NULL
;
712 Key
.UnicodeChar
= 'O';
713 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
716 if (TerminalDevice
->InputState
& INPUT_STATE_2
) {
717 Key
.ScanCode
= SCAN_NULL
;
718 Key
.UnicodeChar
= '2';
719 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
723 TerminalDevice
->TwoSecondTimeOut
,
728 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
733 IN TERMINAL_DEV
*TerminalDevice
738 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
739 can be read through the Simple Input Protocol. The table below shows the keyboard
740 input mappings that this function supports. If the ESC sequence listed in one of the
741 columns is presented, then it is translated into the coorespoding EFI Scan Code. If a
742 matching sequence is not found, then the raw key strokes are converted into EFI Keys.
744 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
745 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
746 converted into EFI Keys.
748 There is one special input sequence that will force the system to reset.
749 This is ESC R ESC r ESC R.
753 TerminaDevice : The terminal device to use to translate raw input into EFI Keys
759 Symbols used in table below
760 ===========================
766 +=========+======+===========+==========+==========+
767 | | EFI | EFI 1.10 | | |
768 | | Scan | | VT100+ | |
769 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
770 +=========+======+===========+==========+==========+
771 | NULL | 0x00 | | | |
772 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
773 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
774 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
775 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
776 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
777 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
778 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
779 | | | ESC [ L | | ESC [ L |
780 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
781 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
783 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
785 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
786 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
787 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
788 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
789 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
790 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
791 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
792 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
793 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
794 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
795 | Escape | 0x17 | ESC | ESC | ESC |
796 +=========+======+===========+==========+=========+
800 ESC R ESC r ESC R = Reset System
805 EFI_STATUS TimerStatus
;
808 BOOLEAN SetDefaultResetState
;
810 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
812 if (!EFI_ERROR (TimerStatus
)) {
813 UnicodeToEfiKeyFlushState (TerminalDevice
);
814 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
817 while (!IsUnicodeFiFoEmpty(TerminalDevice
)) {
819 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
821 // Check to see if the 2 second timer has expired
823 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
824 if (!EFI_ERROR (TimerStatus
)) {
825 UnicodeToEfiKeyFlushState (TerminalDevice
);
826 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
831 // Fetch one Unicode character from the Unicode FIFO
833 UnicodeFiFoRemoveOneKey (TerminalDevice
,&UnicodeChar
);
835 SetDefaultResetState
= TRUE
;
837 switch (TerminalDevice
->InputState
) {
838 case INPUT_STATE_DEFAULT
:
842 case INPUT_STATE_ESC
:
844 if (UnicodeChar
== LEFTOPENBRACKET
) {
845 TerminalDevice
->InputState
|= INPUT_STATE_LEFTOPENBRACKET
;
846 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
850 if (UnicodeChar
== 'O' && TerminalDevice
->TerminalType
== VT100Type
) {
851 TerminalDevice
->InputState
|= INPUT_STATE_O
;
852 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
856 Key
.ScanCode
= SCAN_NULL
;
858 if (TerminalDevice
->TerminalType
== VT100PlusType
||
859 TerminalDevice
->TerminalType
== VTUTF8Type
) {
860 switch (UnicodeChar
) {
862 Key
.ScanCode
= SCAN_F1
;
865 Key
.ScanCode
= SCAN_F2
;
868 Key
.ScanCode
= SCAN_F3
;
871 Key
.ScanCode
= SCAN_F4
;
874 Key
.ScanCode
= SCAN_F5
;
877 Key
.ScanCode
= SCAN_F6
;
880 Key
.ScanCode
= SCAN_F7
;
883 Key
.ScanCode
= SCAN_F8
;
886 Key
.ScanCode
= SCAN_F9
;
889 Key
.ScanCode
= SCAN_F10
;
892 Key
.ScanCode
= SCAN_HOME
;
895 Key
.ScanCode
= SCAN_END
;
898 Key
.ScanCode
= SCAN_INSERT
;
901 Key
.ScanCode
= SCAN_DELETE
;
904 Key
.ScanCode
= SCAN_PAGE_DOWN
;
907 Key
.ScanCode
= SCAN_PAGE_UP
;
914 switch (UnicodeChar
) {
916 if (TerminalDevice
->ResetState
== RESET_STATE_DEFAULT
) {
917 TerminalDevice
->ResetState
= RESET_STATE_ESC_R
;
918 SetDefaultResetState
= FALSE
;
919 } else if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R_ESC_r
) {
920 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
922 Key
.ScanCode
= SCAN_NULL
;
925 if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R
) {
926 TerminalDevice
->ResetState
= RESET_STATE_ESC_R_ESC_r
;
927 SetDefaultResetState
= FALSE
;
929 Key
.ScanCode
= SCAN_NULL
;
935 if (SetDefaultResetState
) {
936 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
939 if (Key
.ScanCode
!= SCAN_NULL
) {
941 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
942 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
943 UnicodeToEfiKeyFlushState (TerminalDevice
);
947 UnicodeToEfiKeyFlushState (TerminalDevice
);
951 case INPUT_STATE_ESC
| INPUT_STATE_O
:
953 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
955 Key
.ScanCode
= SCAN_NULL
;
957 if (TerminalDevice
->TerminalType
== VT100Type
) {
958 switch (UnicodeChar
) {
960 Key
.ScanCode
= SCAN_F1
;
963 Key
.ScanCode
= SCAN_F2
;
966 Key
.ScanCode
= SCAN_F3
;
969 Key
.ScanCode
= SCAN_F4
;
972 Key
.ScanCode
= SCAN_F5
;
975 Key
.ScanCode
= SCAN_F6
;
978 Key
.ScanCode
= SCAN_F7
;
981 Key
.ScanCode
= SCAN_F8
;
984 Key
.ScanCode
= SCAN_F9
;
987 Key
.ScanCode
= SCAN_F10
;
994 if (Key
.ScanCode
!= SCAN_NULL
) {
996 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
997 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
998 UnicodeToEfiKeyFlushState (TerminalDevice
);
1002 UnicodeToEfiKeyFlushState (TerminalDevice
);
1006 case INPUT_STATE_ESC
| INPUT_STATE_LEFTOPENBRACKET
:
1008 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1010 Key
.ScanCode
= SCAN_NULL
;
1012 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1013 TerminalDevice
->TerminalType
== VT100Type
||
1014 TerminalDevice
->TerminalType
== VT100PlusType
||
1015 TerminalDevice
->TerminalType
== VTUTF8Type
) {
1016 switch (UnicodeChar
) {
1018 Key
.ScanCode
= SCAN_UP
;
1021 Key
.ScanCode
= SCAN_DOWN
;
1024 Key
.ScanCode
= SCAN_RIGHT
;
1027 Key
.ScanCode
= SCAN_LEFT
;
1030 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1031 TerminalDevice
->TerminalType
== VT100Type
) {
1032 Key
.ScanCode
= SCAN_HOME
;
1036 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1037 Key
.ScanCode
= SCAN_END
;
1041 if (TerminalDevice
->TerminalType
== VT100Type
) {
1042 Key
.ScanCode
= SCAN_END
;
1047 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1048 TerminalDevice
->TerminalType
== VT100Type
) {
1049 Key
.ScanCode
= SCAN_INSERT
;
1053 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1054 Key
.ScanCode
= SCAN_DELETE
;
1058 if (TerminalDevice
->TerminalType
== VT100Type
) {
1059 Key
.ScanCode
= SCAN_DELETE
;
1060 } else if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1061 Key
.ScanCode
= SCAN_F4
;
1065 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1066 Key
.ScanCode
= SCAN_PAGE_UP
;
1070 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1071 Key
.ScanCode
= SCAN_F10
;
1074 if (TerminalDevice
->TerminalType
== VT100Type
) {
1075 Key
.ScanCode
= SCAN_PAGE_UP
;
1079 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1080 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1084 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1085 Key
.ScanCode
= SCAN_F9
;
1088 if (TerminalDevice
->TerminalType
== VT100Type
) {
1089 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1093 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1094 Key
.ScanCode
= SCAN_F1
;
1098 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1099 Key
.ScanCode
= SCAN_F2
;
1103 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1104 Key
.ScanCode
= SCAN_F3
;
1108 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1109 Key
.ScanCode
= SCAN_F5
;
1113 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1114 Key
.ScanCode
= SCAN_F6
;
1118 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1119 Key
.ScanCode
= SCAN_F7
;
1123 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1124 Key
.ScanCode
= SCAN_F8
;
1132 if (Key
.ScanCode
!= SCAN_NULL
) {
1133 Key
.UnicodeChar
= 0;
1134 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
1135 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1136 UnicodeToEfiKeyFlushState (TerminalDevice
);
1140 UnicodeToEfiKeyFlushState (TerminalDevice
);
1147 // Invalid state. This should never happen.
1151 UnicodeToEfiKeyFlushState (TerminalDevice
);
1156 if (UnicodeChar
== ESC
) {
1157 TerminalDevice
->InputState
= INPUT_STATE_ESC
;
1160 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
1161 Status
= gBS
->SetTimer(
1162 TerminalDevice
->TwoSecondTimeOut
,
1166 ASSERT_EFI_ERROR (Status
);
1170 if (SetDefaultResetState
) {
1171 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1174 if (UnicodeChar
== DEL
) {
1175 Key
.ScanCode
= SCAN_DELETE
;
1176 Key
.UnicodeChar
= 0;
1178 Key
.ScanCode
= SCAN_NULL
;
1179 Key
.UnicodeChar
= UnicodeChar
;
1182 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);