Changeset 27969 in vbox for trunk/src/VBox/Devices/Input
- Timestamp:
- Apr 2, 2010 9:32:57 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/UsbKbd.cpp
r27917 r27969 1 /* $Id$ */ 1 2 /** @file 2 * UsbKbd - USB Human Interface Device Emulation (Keyboard).3 * UsbKbd - USB Human Interface Device Emulation, Keyboard. 3 4 */ 4 5 … … 117 118 typedef struct USBHIDK_REPORT 118 119 { 119 uint8_t ShiftState; /* Modifier keys bitfield */120 uint8_t Reserved; /* Currently unused */121 uint8_t aKeys[6]; /* Normal keys */120 uint8_t ShiftState; /**< Modifier keys bitfield */ 121 uint8_t Reserved; /**< Currently unused */ 122 uint8_t aKeys[6]; /**< Normal keys */ 122 123 } USBHIDK_REPORT, *PUSBHIDK_REPORT; 123 124 124 /* Scancode translator state. */125 /** Scancode translator state. */ 125 126 typedef enum { 126 SS_IDLE, /* Starting state. */127 SS_EXT, /* E0 byte was received. */128 SS_EXT1 /* E1 byte was received. */127 SS_IDLE, /**< Starting state. */ 128 SS_EXT, /**< E0 byte was received. */ 129 SS_EXT1 /**< E1 byte was received. */ 129 130 } scan_state_t; 130 131 … … 137 138 PPDMUSBINS pUsbIns; 138 139 /** Critical section protecting the device state. */ 139 RTCRITSECT csLock;140 RTCRITSECT CritSect; 140 141 141 142 /** The current configuration. … … 169 170 /** Someone is waiting on the done queue. */ 170 171 bool fHaveDoneQueueWaiter; 171 /** If no URB since last key press */172 /** If no URB since last key press. */ 172 173 bool fNoUrbSinceLastPress; 173 /* If device has pending changes*/174 /** If device has pending changes. */ 174 175 bool fHasPendingChanges; 175 /* Keys released since last URB*/176 uint8_t a ReleasedKeys[6];176 /** Keys released since last URB. */ 177 uint8_t abReleasedKeys[6]; 177 178 178 179 /** … … 229 230 }; 230 231 231 /* HID report descriptor. */232 /** HID report descriptor. */ 232 233 static const uint8_t g_UsbHidReportDesc[] = 233 234 { … … 266 267 }; 267 268 268 /* Additional HID class interface descriptor. */269 /** Additional HID class interface descriptor. */ 269 270 static const uint8_t g_UsbHidIfHidDesc[] = 270 271 { … … 357 358 */ 358 359 359 /* Lookup table for converting PC/XT scan codes to USB HID usage codes. */360 /** Lookup table for converting PC/XT scan codes to USB HID usage codes. */ 360 361 static uint8_t aScancode2Hid[] = 361 362 { … … 378 379 }; 379 380 380 /* Lookup table for extended scancodes (arrow keys etc.). */381 /** Lookup table for extended scancodes (arrow keys etc.). */ 381 382 static uint8_t aExtScan2Hid[] = 382 383 { … … 449 450 *******************************************************************************/ 450 451 451 /* Everything happens in R3 */452 /**453 * Lock device state mutex.454 */455 DECLINLINE(int) usbKbdLock(PUSBHID pThis)456 {457 return RTCritSectEnter(&pThis->csLock);458 }459 460 /**461 * Unlock device state mutex.462 */463 DECLINLINE(void) usbKbdUnlock(PUSBHID pThis)464 {465 RTCritSectLeave(&pThis->csLock);466 }467 452 468 453 /** … … 635 620 pThis->fNoUrbSinceLastPress = false; 636 621 pThis->fHasPendingChanges = false; 637 memset(&pThis->a ReleasedKeys[0], 0, sizeof(pThis->aReleasedKeys));622 memset(&pThis->abReleasedKeys[0], 0, sizeof(pThis->abReleasedKeys)); 638 623 639 624 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aEps); i++) … … 682 667 { 683 668 unsigned i; 684 for (i =0; i < RT_ELEMENTS(pThis->aReleasedKeys); ++i)685 { 686 if (pThis->a ReleasedKeys[i] != 0)669 for (i = 0; i < RT_ELEMENTS(pThis->abReleasedKeys); ++i) 670 { 671 if (pThis->abReleasedKeys[i] != 0) 687 672 { 688 usbHidUpdateReportReleased(pThis, pThis->a ReleasedKeys[i]);689 pThis->a ReleasedKeys[i] = 0;673 usbHidUpdateReportReleased(pThis, pThis->abReleasedKeys[i]); 674 pThis->abReleasedKeys[i] = 0; 690 675 } 691 676 } … … 693 678 694 679 #ifdef DEBUG 695 #define HEX_DIGIT(x) (((x) < 0xa) ? ((x) + '0') : ((x) - 0xa + 'a')) 696 static void usbHidComputePressed(PUSBHIDK_REPORT pReport, char* pszBuf, unsigned uBufLen) 697 { 698 unsigned i, uBufPos = 0; 699 for (i=0; i < RT_ELEMENTS(pReport->aKeys); ++i) 680 # define HEX_DIGIT(x) (((x) < 0xa) ? ((x) + '0') : ((x) - 0xa + 'a')) 681 static void usbHidComputePressed(PUSBHIDK_REPORT pReport, char* pszBuf, unsigned cbBuf) 682 { 683 unsigned offBuf = 0; 684 unsigned i; 685 for (i = 0; i < RT_ELEMENTS(pReport->aKeys); ++i) 700 686 { 701 687 uint8_t uCode = pReport->aKeys[i]; 702 688 if (uCode != 0) 703 689 { 704 if ( uBufPos + 4 >= uBufLen)690 if (offBuf + 4 >= cbBuf) 705 691 break; 706 pszBuf[ uBufPos++] = HEX_DIGIT(uCode >> 4);707 pszBuf[ uBufPos++] = HEX_DIGIT(uCode & 0xf);708 pszBuf[ uBufPos++] = ' ';692 pszBuf[offBuf++] = HEX_DIGIT(uCode >> 4); 693 pszBuf[offBuf++] = HEX_DIGIT(uCode & 0xf); 694 pszBuf[offBuf++] = ' '; 709 695 } 710 696 } 711 pszBuf[ uBufPos++] = '\0';712 } 713 # undef HEX_DIGIT697 pszBuf[offBuf++] = '\0'; 698 } 699 # undef HEX_DIGIT 714 700 #endif 715 701 … … 778 764 unsigned i; 779 765 780 usbKbdLock(pThis);766 RTCritSectEnter(&pThis->CritSect); 781 767 782 768 pThis->XlatState = ScancodeToHidUsage(pThis->XlatState, u8KeyCode, &u32Usage); … … 799 785 /* Skip repeat events. */ 800 786 fHaveEvent = false; 801 break; 787 break; 802 788 } 803 789 } … … 813 799 } 814 800 } 815 801 816 802 pThis->fNoUrbSinceLastPress = true; 817 803 818 804 if (i == RT_ELEMENTS(pReport->aKeys)) 819 805 { 820 806 /* We ran out of room. Report error. */ 821 807 Log(("no more room in usbHidKeyboardPutEvent\n")); 822 // @todo!!808 /// @todo!! 823 809 } 824 810 } … … 833 819 if (pThis->fNoUrbSinceLastPress) 834 820 { 835 for (i = 0; i < RT_ELEMENTS(pThis->a ReleasedKeys); ++i)821 for (i = 0; i < RT_ELEMENTS(pThis->abReleasedKeys); ++i) 836 822 { 837 if (pThis->a ReleasedKeys[i] == u8HidCode)823 if (pThis->abReleasedKeys[i] == u8HidCode) 838 824 break; 839 825 840 if (pThis->a ReleasedKeys[i] == 0)826 if (pThis->abReleasedKeys[i] == 0) 841 827 { 842 pThis->a ReleasedKeys[i] = u8HidCode;828 pThis->abReleasedKeys[i] = u8HidCode; 843 829 break; 844 830 } … … 854 840 } 855 841 856 usbKbdUnlock(pThis);842 RTCritSectLeave(&pThis->CritSect); 857 843 858 844 return VINF_SUCCESS; … … 867 853 //LogFlow(("usbHidUrbReap/#%u: cMillies=%u\n", pUsbIns->iInstance, cMillies)); 868 854 869 usbKbdLock(pThis);855 RTCritSectEnter(&pThis->CritSect); 870 856 871 857 PVUSBURB pUrb = usbHidQueueRemoveHead(&pThis->DoneQueue); … … 874 860 /* Wait */ 875 861 pThis->fHaveDoneQueueWaiter = true; 876 usbKbdUnlock(pThis);862 RTCritSectLeave(&pThis->CritSect); 877 863 878 864 RTSemEventWait(pThis->hEvtDoneQueue, cMillies); 879 865 880 usbKbdLock(pThis);866 RTCritSectEnter(&pThis->CritSect); 881 867 pThis->fHaveDoneQueueWaiter = false; 882 868 … … 884 870 } 885 871 886 usbKbdUnlock(pThis);872 RTCritSectLeave(&pThis->CritSect); 887 873 888 874 if (pUrb) … … 899 885 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 900 886 LogFlow(("usbHidUrbCancel/#%u: pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc)); 901 usbKbdLock(pThis);887 RTCritSectEnter(&pThis->CritSect); 902 888 903 889 /* … … 907 893 usbHidLinkDone(pThis, pUrb); 908 894 909 usbKbdUnlock(pThis);895 RTCritSectLeave(&pThis->CritSect); 910 896 return VINF_SUCCESS; 911 897 } … … 1153 1139 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1154 1140 LogFlow(("usbHidQueue/#%u: pUrb=%p:%s EndPt=%#x\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->EndPt)); 1155 usbKbdLock(pThis);1141 RTCritSectEnter(&pThis->CritSect); 1156 1142 1157 1143 /* … … 1177 1163 } 1178 1164 1179 usbKbdUnlock(pThis);1165 RTCritSectLeave(&pThis->CritSect); 1180 1166 return rc; 1181 1167 } … … 1192 1178 if ((uEndpoint & ~0x80) < RT_ELEMENTS(pThis->aEps)) 1193 1179 { 1194 usbKbdLock(pThis);1180 RTCritSectEnter(&pThis->CritSect); 1195 1181 pThis->aEps[(uEndpoint & ~0x80)].fHalted = false; 1196 usbKbdUnlock(pThis);1182 RTCritSectLeave(&pThis->CritSect); 1197 1183 } 1198 1184 … … 1221 1207 LogFlow(("usbHidUsbSetConfiguration/#%u: bConfigurationValue=%u\n", pUsbIns->iInstance, bConfigurationValue)); 1222 1208 Assert(bConfigurationValue == 1); 1223 usbKbdLock(pThis);1209 RTCritSectEnter(&pThis->CritSect); 1224 1210 1225 1211 /* … … 1230 1216 pThis->bConfigurationValue = bConfigurationValue; 1231 1217 1232 usbKbdUnlock(pThis);1218 RTCritSectLeave(&pThis->CritSect); 1233 1219 return VINF_SUCCESS; 1234 1220 } … … 1253 1239 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1254 1240 LogFlow(("usbHidUsbReset/#%u:\n", pUsbIns->iInstance)); 1255 usbKbdLock(pThis);1241 RTCritSectEnter(&pThis->CritSect); 1256 1242 1257 1243 int rc = usbHidResetWorker(pThis, NULL, false /*fSetConfig*/); 1258 1244 1259 usbKbdUnlock(pThis);1245 RTCritSectLeave(&pThis->CritSect); 1260 1246 return rc; 1261 1247 } … … 1270 1256 LogFlow(("usbHidDestruct/#%u:\n", pUsbIns->iInstance)); 1271 1257 1272 if (RTCritSectIsInitialized(&pThis-> csLock))1273 { 1274 /* Let whoever runs in this critical section complete */1275 usbKbdLock(pThis);1276 usbKbdUnlock(pThis);1277 RTCritSectDelete(&pThis-> csLock);1258 if (RTCritSectIsInitialized(&pThis->CritSect)) 1259 { 1260 /* Let whoever runs in this critical section complete. */ 1261 RTCritSectEnter(&pThis->CritSect); 1262 RTCritSectLeave(&pThis->CritSect); 1263 RTCritSectDelete(&pThis->CritSect); 1278 1264 } 1279 1265 … … 1304 1290 usbHidQueueInit(&pThis->DoneQueue); 1305 1291 1306 int rc = RTCritSectInit(&pThis-> csLock);1292 int rc = RTCritSectInit(&pThis->CritSect); 1307 1293 AssertRCReturn(rc, rc); 1308 1294
Note:
See TracChangeset
for help on using the changeset viewer.