Files
bds.mr.devmgr/src.devmgr/dev/usb/mr.dev.usb.configuration.pas
T
2026-01-03 18:53:14 +01:00

138 lines
4.3 KiB
ObjectPascal

unit mr.dev.usb.configuration;
interface
uses
Generics.Collections,
mr.drv.usb,
mr.drv.usb.types,
mr.dev.usb.pipe,
mr.dev.usb.pipe0;
type
TUsbConfiguration = class
strict protected
type
TPipeMap = TObjectDictionary<byte,TPipe>;
strict protected
fDriver : TUsbDriver;
fPipeMap : TPipeMap;
fConfiguration : TUsbConfigurationDescriptor;
strict protected
function GetPipe( id: byte): TPipe;
public
constructor Create( Driver: TUsbDriver);
destructor Destroy; override;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
public
property Pipes[i:byte] : TPipe read GetPipe;
end;
implementation
uses
SysUtils,
Windows;
{ TUsbConfiguration }
// @@@: Construction / destruction ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Construction / destruction
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ================================================================================================
// Constructor
// ================================================================================================
constructor TUsbConfiguration.Create(Driver: TUsbDriver);
begin
fDriver := Driver;
fPipeMap := TPipeMap.Create([doOwnsValues]);
end;
// ================================================================================================
// Destructor
// ================================================================================================
destructor TUsbConfiguration.Destroy;
begin
FreeAndNil(fPipeMap);
inherited;
end;
// ================================================================================================
// After construction
// ================================================================================================
procedure TUsbConfiguration.AfterConstruction;
var
intf : TUsbAlternateSettingDescriptor;
info : TusbPipeInformation;
pipe : TPipe;
len : cardinal;
i : integer;
begin
inherited;
if Assigned( fDriver) then
begin
// ------------------------------------------------------------
// Get configuration
// ------------------------------------------------------------
fDriver.GetDescriptor( DSCR_CONFIGURATION,
0, 0,
@fConfiguration,
sizeof( TUsbConfigurationDescriptor),
len);
// ------------------------------------------------------------
// Query interface/alternate settings
// ------------------------------------------------------------
if fDriver.QueryInterfaceSettings(0,intf) then
begin
for i:=0 to intf.EndpointCount-1 do
begin
info.PipeType := ptIsochronous;
info.PipeId := $FF;
info.MaxPacketSize := $AABB;
info.Interval := $CC;
if fDriver.QueryPipe( 0, i, info) then
begin
pipe := TPipe.Create( fDriver, info);
fPipeMap.Add( info.PipeId, pipe);
end;
end;
end;
end
end;
// ================================================================================================
// Before destruction
// ================================================================================================
procedure TUsbConfiguration.BeforeDestruction;
begin
inherited
end;
// ================================================================================================
// Get Pipe by ID
// ================================================================================================
function TUsbConfiguration.GetPipe(id: byte): TPipe;
begin
if not fPipeMap.TryGetValue( id, result) then
result := nil;
end;
end.