home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Mac OS USB DDK_v1.0.1 / Examples / KeyboardModule / KeyboardModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  4.2 KB  |  129 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        KeyboardModuleHeader.c
  3.  
  4.     Contains:    Keyboard Module Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17. #include "KeyboardModule.h"
  18. #include "KeyboardModuleVersion.h"
  19.  
  20. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  21. static     OSStatus     KeyboardModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  22. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  23.  
  24. extern    usbKeyboardPBStruct myKeyboardPB;
  25.  
  26. //------------------------------------------------------
  27. //
  28. //    This is the driver description structure that the expert looks for first.
  29. //  If it's here, the information within is used to match the driver
  30. //  to the device whose descriptor was passed to the expert.
  31. //    Information in this block is also used by the expert when an
  32. //  entry is created in the Name Registry.
  33. //
  34. //------------------------------------------------------
  35. USBDriverDescription    TheUSBDriverDescription = 
  36. {
  37.     // Signature info
  38.     kTheUSBDriverDescriptionSignature,
  39.     kInitialUSBDriverDescriptor,
  40.     
  41.     // Device Info
  42.     0,                                        // vendor = not device specific
  43.     0,                                        // product = not device specific
  44.     0,                                        // version of product = not device specific
  45.     kUSBKeyboardInterfaceProtocol,                // protocol = not device specific
  46.     
  47.     // Interface Info    (* I don't think this would always be required...*)                
  48.     0,                                        // Configuration Value
  49.     0,                                        // Interface Number
  50.     kUSBHIDInterfaceClass,                    // Interface Class
  51.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  52.     kUSBKeyboardInterfaceProtocol,                // Interface Protocol
  53.         
  54.     
  55.     // Driver Info
  56.     "\pUSBHIDKeyboardModule",                // Driver name for Name Registry
  57.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  58.     kUSBBootInterfaceSubClass,                // Device Subclass 
  59.     kKBDHexMajorVers, 
  60.     kKBDHexMinorVers, 
  61.     kKBDCurrentRelease, 
  62.     kKBDReleaseStage,                        // version of driver
  63.     
  64.     // Driver Loading Info
  65.     kUSBProtocolMustMatch                    // Flags 
  66. };
  67.  
  68. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  69. {
  70.     kClassDriverPluginVersion,                // Version of this structure
  71.     0,                                        // Hardware Validation Procedure
  72.     KeyboardModuleInitialize,                    // Initialization Procedure
  73.     KeyboardInterfaceInitialize,                // Interface Initialization Procedure
  74.     KeyboardModuleFinalize,                    // Finalization Procedure
  75.     0,                                        // Driver Notification Procedure
  76. };
  77.     
  78.  
  79.     
  80. // Initialization function
  81. // Called upon load by Expert
  82. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  83. {
  84. #pragma unused (busPowerAvailable)
  85. #pragma unused (pDesc)
  86.     USBExpertStatus(device, "\pUSBHIDKeyboardModule: Entered via KeyboardModuleInitialize", device);
  87.     return (OSStatus)noErr;
  88. }
  89.  
  90. // Interface Initialization Initialization function
  91. // Called upon load by Expert
  92. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  93. {
  94.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  95.     return (OSStatus)noErr;
  96. }
  97.  
  98.  
  99.  
  100. // Termination function
  101. // Called by Expert when driver is being shut down
  102. static OSStatus KeyboardModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  103. {
  104. #pragma unused (pDesc)
  105.  
  106. OSStatus myErr;
  107.  
  108.     USBExpertStatus(theDeviceRef, "\pUSBHIDKeyboardModule: Finalize", theDeviceRef);
  109.     if (myKeyboardPB.pFullConfigDescriptor != nil)
  110.     {
  111.         if (myKeyboardPB.pipeRef)
  112.         {
  113.             USBExpertStatus(theDeviceRef, "\pUSBHIDKeyboardModule: Aborting interrupt pipe", theDeviceRef);
  114.             USBAbortPipeByReference(myKeyboardPB.pipeRef);
  115.         }
  116.             
  117.         myKeyboardPB.pb.usbReference = theDeviceRef;
  118.         myKeyboardPB.pb.pbVersion = kUSBCurrentPBVersion;
  119.         myKeyboardPB.pb.usbFlags = 0;
  120.         myKeyboardPB.pb.usbRefcon = 0;             
  121.         myKeyboardPB.pb.usbBuffer = myKeyboardPB.pFullConfigDescriptor;        
  122.         myKeyboardPB.pb.usbCompletion = (USBCompletion)-1;
  123.         
  124.         myErr = USBDeallocMem(&myKeyboardPB.pb);
  125.     };
  126.     return (OSStatus)noErr;
  127. }
  128.  
  129.