home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / MouseModule / MouseModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  4.7 KB  |  148 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MouseModuleHeader.c
  3.  
  4.     Contains:    Mouse 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.  
  18. #include "MouseModule.h"
  19. #include "MouseModuleVersion.h"
  20.  
  21. static     OSStatus     MouseModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  22. static     OSStatus     MouseModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  23. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  24.  
  25. extern    usbMousePBStruct myMousePB;
  26.  
  27. //------------------------------------------------------
  28. //
  29. //    This is the driver description structure that the expert looks for first.
  30. //  If it's here, the information within is used to match the driver
  31. //  to the device whose descriptor was passed to the expert.
  32. //    Information in this block is also used by the expert when an
  33. //  entry is created in the Name Registry.
  34. //
  35. //------------------------------------------------------
  36. USBDriverDescription    TheUSBDriverDescription = 
  37. {
  38.     // Signature info
  39.     kTheUSBDriverDescriptionSignature,
  40.     kInitialUSBDriverDescriptor,
  41.     
  42.     // Device Info
  43.     0,                                        // vendor = not device specific
  44.     0,                                        // product = not device specific
  45.     0,                                        // version of product = not device specific
  46.     kUSBMouseInterfaceProtocol,                // protocol = not device specific
  47.     
  48.     // Interface Info    (* I don't think this would always be required...*)                
  49.     0,                                        // Configuration Value
  50.     0,                                        // Interface Number
  51.     kUSBHIDInterfaceClass,                    // Interface Class
  52.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  53.     kUSBMouseInterfaceProtocol,                // Interface Protocol
  54.         
  55.     
  56.     // Driver Info
  57.     "\pUSBHIDMouseModule",                        // Driver name for Name Registry
  58.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  59.     kUSBBootInterfaceSubClass,                // Device Subclass 
  60.     kMouseHexMajorVers, 
  61.     kMouseHexMinorVers, 
  62.     kMouseCurrentRelease, 
  63.     kMouseReleaseStage,                        // version of driver
  64.     
  65.     // Driver Loading Info
  66.     kUSBProtocolMustMatch                    // Flags (currently undefined)
  67. };
  68.  
  69. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  70. {
  71.     kClassDriverPluginVersion,                // Version of this structure
  72.     0,                                        // Hardware Validation Procedure
  73.     MouseModuleInitialize,                    // Initialization Procedure
  74.     MouseInterfaceInitialize,                // Interface Initialization Procedure
  75.     MouseModuleFinalize,                    // Finalization Procedure
  76.     0,                                        // Driver Notification Procedure
  77. };
  78.     
  79.  
  80. // Initialization function
  81. // Called upon load by Expert
  82. static     OSStatus     MouseModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  83. {
  84. #pragma unused (busPowerAvailable)
  85. #pragma unused (pDesc)
  86.     USBExpertStatus(device, "\pUSBHIDMouseModule: Entered via KeyboardModuleInitialize", device);
  87.     return (OSStatus)noErr;
  88. }
  89.  
  90. // Interface Initialization Initialization function
  91. // Called upon load by Expert
  92. static     OSStatus     MouseInterfaceInitialize (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 MouseModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  103. {
  104. #pragma unused (pDesc)
  105. OSStatus myErr;
  106. //USBHIDData        theMouseData;
  107.  
  108.     USBExpertStatus(theDeviceRef, "\pUSBHIDMouseModule: Finalize", theDeviceRef);
  109.     
  110.     /*
  111.     if (myMousePB.pSHIMInterruptRoutine)            
  112.     {                                                
  113.         USBExpertStatus(theDeviceRef, "\pUSBHIDMouseModule: Release mouse buttons", theDeviceRef);
  114.         theMouseData.mouse.buttons = 0;
  115.         theMouseData.mouse.XDelta = 1;
  116.         theMouseData.mouse.YDelta = 1;
  117.         (*myMousePB.pSHIMInterruptRoutine)(myMousePB.interruptRefcon, (void *)&theMouseData);
  118.     }
  119.     */
  120.     
  121.     if (myMousePB.pCursorDeviceInfo != 0)                
  122.     {
  123.         USBExpertStatus(theDeviceRef, "\pUSBHIDMouseModule: Remove CDM device", theDeviceRef);
  124.         CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
  125.         myMousePB.pCursorDeviceInfo = 0;
  126.     }
  127.     
  128.     if (myMousePB.pFullConfigDescriptor != nil)
  129.     {
  130.         if (myMousePB.pipeRef)
  131.         {
  132.             USBExpertStatus(theDeviceRef, "\pUSBHIDMouseModule: Aborting interrupt pipe", theDeviceRef);
  133.             USBAbortPipeByReference(myMousePB.pipeRef);
  134.         }
  135.         myMousePB.pb.usbReference = theDeviceRef;
  136.         myMousePB.pb.pbVersion = kUSBCurrentPBVersion;
  137.         myMousePB.pb.usbFlags = 0;
  138.         myMousePB.pb.usbRefcon = 0;             
  139.         myMousePB.pb.usbBuffer = myMousePB.pFullConfigDescriptor;        
  140.         myMousePB.pb.usbCompletion = (USBCompletion)-1;
  141.         
  142.         myErr = USBDeallocMem(&myMousePB.pb);
  143.     }
  144.     
  145.     return (OSStatus)noErr;
  146. }
  147.  
  148.