---------------------------------------------------------------------------- -- Copyright (C) 2018-2021, AdaCore -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are -- met: -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in -- the documentation and/or other materials provided with the -- distribution. -- 3. Neither the name of the copyright holder nor the names of its -- contributors may be used to endorse or promote products derived -- from this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- ----------------------------------------------------------------------------
type Any_USB_Device_Class is access all USB_Device_Class'Class;
subtype Class_Index is UInt8;
function Configure (This : in out USB_Device_Class;
UDC : in out USB_Device_Controller'Class;
Index : UInt16)
return Setup_Request_Answer
function Controller (This : USB_Device_Stack)
return not null Any_USB_Device_Controller
procedure Fill_Config_Descriptor (This : in out USB_Device_Class;
Data : out UInt8_Array)
procedure Get_Class_Info
(This : in out USB_Device_Class;
Number_Of_Interfaces : out Interface_Id;
Config_Descriptor_Length : out Natural)
type Init_Result is (Ok, Not_Enough_EPs, Not_Enough_EP_Buffer);
function Initialize (This : in out USB_Device_Class;
Dev : in out USB_Device_Stack'Class;
Base_Interface_Index : Interface_Id)
return Init_Result
function Initialize
(This : in out USB_Device_Stack;
Controller : not null Any_USB_Device_Controller;
Manufacturer : USB_String;
Product : USB_String;
Serial_Number : USB_String;
Max_Packet_Size : Control_Packet_Size)
return Init_Result
function Initialized (This : USB_Device_Stack) return Boolean
procedure Poll (This : in out USB_Device_Stack)
function Register_Class (This : in out USB_Device_Stack;
Class : not null Any_USB_Device_Class)
return Boolean
Return False if there is not space left to register the class
function Register_String (This : in out USB_Device_Stack;
Str : USB_String)
return String_Id
Register a USB string
function Request_Buffer (This : in out USB_Device_Stack;
EP : EP_Addr;
Len : Packet_Size)
return System.Address
Allocate a buffer for the corresponding End-Point. This buffer should then be used by the class for IN or OUT transfers depending on the given EP address.
Return Null_Address if resquest fails (e.g. no memory available).
function Request_Endpoint (This : in out USB_Device_Stack;
Typ : EP_Type;
EP : out EP_Id)
return Boolean
Allocate a non-control End-Point to be used by the class
procedure Reset (This : in out USB_Device_Stack)
function Setup_Read_Request (This : in out USB_Device_Class;
Req : Setup_Data;
Buf : out System.Address;
Len : out Buffer_Len)
return Setup_Request_Answer
function Setup_Write_Request (This : in out USB_Device_Class;
Req : Setup_Data;
Data : UInt8_Array)
return Setup_Request_Answer
procedure Start (This : in out USB_Device_Stack)
procedure Transfer_Complete (This : in out USB_Device_Class;
UDC : in out USB_Device_Controller'Class;
EP : EP_Addr;
CNT : Packet_Size)
type USB_Device_Class is limited interface;
type USB_Device_Stack (Max_Classes : Class_Index) is tagged private;