Initial check in
This commit is contained in:
@@ -0,0 +1,258 @@
|
||||
unit mr.drv.usb;
|
||||
|
||||
interface
|
||||
uses
|
||||
WinApi.Windows,
|
||||
System.Classes,
|
||||
spring.Collections,
|
||||
spring.Collections.Lists,
|
||||
mr.drv.usb.types,
|
||||
mr.drv;
|
||||
|
||||
|
||||
type
|
||||
TUsbDriver = class;
|
||||
TUsbDriverClass= class of TUsbDriver;
|
||||
|
||||
TScanCallback = reference to procedure( DevicePath: string);
|
||||
|
||||
|
||||
TUsbDeviceInfo = class
|
||||
private
|
||||
fDriverClass : TUsbDriverClass;
|
||||
fDevicePath : string;
|
||||
fVendorID : word;
|
||||
fProductID : word;
|
||||
fLocation : string;
|
||||
fDescription : string;
|
||||
|
||||
public
|
||||
property DriverClass : TUsbDriverClass read fDriverClass;
|
||||
property DevicePath : string read fDevicePath;
|
||||
property Location : string read fLocation;
|
||||
property Description : string read fDescription;
|
||||
property VendorID : word read fVendorID;
|
||||
property ProductID : word read fProductID;
|
||||
|
||||
public
|
||||
constructor Create( DevicePath: string; DriverClass: TUsbDriverClass);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
IUsbDriverMap = IDictionary<string, TUsbDeviceInfo>;
|
||||
|
||||
|
||||
|
||||
|
||||
TAnsiStringList = TList<AnsiString>;
|
||||
TList = spring.Collections.IList<string>;
|
||||
|
||||
|
||||
TUsbDriver = class abstract(TDriver, IUsbDriver)
|
||||
public
|
||||
class procedure Scan( ScanCallback: TScanCallback); virtual; abstract;
|
||||
|
||||
public
|
||||
class procedure ParseInstanceId( InstanceId : string;
|
||||
var VendorID : word;
|
||||
var ProductID : word;
|
||||
var Location : string;
|
||||
var Description : string);
|
||||
|
||||
protected
|
||||
class var fDriverID: TGUID;
|
||||
|
||||
protected
|
||||
fVendorID : word;
|
||||
fProductID : word;
|
||||
fLocation : string;
|
||||
fDescription : string;
|
||||
fDeviceSpeed : TusbDeviceSpeed;
|
||||
|
||||
fDeviceDescriptor : TUsbDeviceDescriptor;
|
||||
|
||||
public
|
||||
function GetDescriptor( DescriptorType : byte;
|
||||
Index : byte;
|
||||
LanguageID : word;
|
||||
Buffer : pointer;
|
||||
BufferLength : cardinal;
|
||||
var Transferred : cardinal) : boolean; virtual; abstract;
|
||||
|
||||
function GetAssociatedInterface( InterfaceIndex : byte;
|
||||
var InterfaceHandle) : boolean; virtual; abstract;
|
||||
|
||||
function QueryInterfaceSettings( AlternateSettingNumber : byte;
|
||||
var AlternateSettingDescriptor : TUsbAlternateSettingDescriptor): boolean; virtual; abstract;
|
||||
|
||||
function QueryPipe( AlternateInterfaceNumber : byte;
|
||||
PipeIndex : byte;
|
||||
var PipeInformation : TusbPipeInformation): boolean; virtual; abstract;
|
||||
|
||||
|
||||
function ControlTransfer( SetupPacket : TUsbSetupPacket;
|
||||
Buffer : pointer;
|
||||
BufferLength : cardinal;
|
||||
var Transferred : cardinal;
|
||||
Overlapped : POverlapped = nil): boolean; virtual; abstract;
|
||||
|
||||
function AbortPipe( PipeID : byte): boolean; virtual; abstract;
|
||||
function FlushPipe( PipeID : byte): boolean; virtual; abstract;
|
||||
function ResetPipe( PipeID : byte): boolean; virtual; abstract;
|
||||
|
||||
function ReadPipe( PipeID : byte;
|
||||
Buffer : pointer;
|
||||
BufferLength : cardinal;
|
||||
var Transferred : cardinal;
|
||||
Overlapped : POverlapped = nil): boolean; virtual; abstract;
|
||||
|
||||
function WritePipe( PipeID : byte;
|
||||
Buffer : pointer;
|
||||
BufferLength : cardinal;
|
||||
var Transferred : cardinal;
|
||||
Overlapped : POverlapped = nil): boolean; virtual; abstract;
|
||||
|
||||
function GetOverlappedResult( Overlapped : POverlapped;
|
||||
var Transferred : cardinal;
|
||||
Wait : boolean): boolean; virtual; abstract;
|
||||
|
||||
|
||||
|
||||
public
|
||||
constructor Create( DevicePath: string);
|
||||
|
||||
public
|
||||
property VendorID : word read fVendorID;
|
||||
property ProductID : word read fProductID;
|
||||
property Location : string read fLocation;
|
||||
property Description : string read fDescription;
|
||||
property DeviceSpeed : TusbDeviceSpeed read fDeviceSpeed;
|
||||
end;
|
||||
|
||||
// TUsbDriverClass = class of TUsbDriver;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
mr.dev.usb,
|
||||
System.SysUtils;
|
||||
|
||||
{ TUsbDriver }
|
||||
|
||||
// @@@: Construction / destruction ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//
|
||||
// Construction / destruction
|
||||
//
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ================================================================================================
|
||||
// Create
|
||||
// ================================================================================================
|
||||
constructor TUsbDriver.Create( DevicePath: string);
|
||||
begin
|
||||
fDeviceHandle := INVALID_HANDLE_VALUE;
|
||||
fDevicePath := DevicePath;
|
||||
fDeviceSpeed := LowSpeed;
|
||||
|
||||
ParseInstanceId( fDevicePath, fVendorID, fProductID, fLocation, fDescription);
|
||||
end;
|
||||
|
||||
// @@@: INTERNALS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//
|
||||
// INTERNALS
|
||||
//
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ================================================================================================
|
||||
// parse instance id
|
||||
// ================================================================================================
|
||||
class procedure TUsbDriver.ParseInstanceId( InstanceId : string;
|
||||
var VendorID : word;
|
||||
var ProductID : word;
|
||||
var Location : string;
|
||||
var Description : string);
|
||||
var
|
||||
i : integer;
|
||||
l : integer;
|
||||
id : string;
|
||||
loc: string;
|
||||
dsc: string;
|
||||
|
||||
begin
|
||||
i := 1;
|
||||
l := Length(InstanceId);
|
||||
|
||||
while (i<=l) and (InstanceId[i] <> '\') do
|
||||
inc(i);
|
||||
|
||||
inc(i);
|
||||
|
||||
while (i<=l) and (InstanceId[i] <> '\') do
|
||||
begin
|
||||
id := id + InstanceId[i];
|
||||
inc(i)
|
||||
end;
|
||||
|
||||
inc(i);
|
||||
|
||||
while (i<=l) and (InstanceId[i] <> '#') do
|
||||
begin
|
||||
loc := loc + InstanceId[i];
|
||||
inc(i)
|
||||
end;
|
||||
|
||||
inc(i);
|
||||
|
||||
while (i<=l) do
|
||||
begin
|
||||
dsc := dsc + InstanceId[i];
|
||||
inc(i)
|
||||
end;
|
||||
|
||||
VendorId := StrToInt('$'+Copy( id, 5, 4));
|
||||
ProductId := StrToInt('$'+Copy( id, 14, 4));
|
||||
Location := loc;
|
||||
Description := dsc;
|
||||
end;
|
||||
|
||||
{ TUsbDeviceInfo }
|
||||
|
||||
// @@@: construction / destruction ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//
|
||||
// construction / destruction
|
||||
//
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
// ================================================================================================
|
||||
// constructor
|
||||
// ================================================================================================
|
||||
constructor TUsbDeviceInfo.Create(DevicePath: string; DriverClass: TUsbDriverClass);
|
||||
begin
|
||||
fDevicePath := DevicePath;
|
||||
fDriverClass := DriverClass;
|
||||
|
||||
DriverClass.ParseInstanceId( fDevicePath, fVendorID, fProductID, fLocation, fDescription)
|
||||
end;
|
||||
|
||||
// ================================================================================================
|
||||
// destructor
|
||||
// ================================================================================================
|
||||
destructor TUsbDeviceInfo.Destroy;
|
||||
begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user