---------------------------------------------------------------------------- -- 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. -- -- ----------------------------------------------------------------------------
subtype Buffer_Len is System.Storage_Elements.Storage_Offset;
Control_Buffer_Size : constant := Usb_Embedded_Config.Control_Buffer_Size;
subtype Control_Packet_Size is Packet_Size range 0 .. 64;
type Data_Phase_Transfer_Direction is (Host_To_Device,
Device_To_Host)
with Size => 1;
type Device_Descriptor is record
bLength : UInt8;
bDescriptorType : UInt8;
bcdUSB : UInt16;
bDeviceClass : UInt8;
bDeviceSubClass : UInt8;
bDeviceProtocol : UInt8;
bMaxPacketSize0 : UInt8;
idVendor : UInt16;
idProduct : UInt16;
bcdDevice : UInt16;
iManufacturer : String_Id;
iProduct : String_Id;
iSerialNumber : String_Id;
bNumConfigurations : UInt8;
end record with Pack;
type Device_Qualifier is record
bLength : UInt8;
bDescriptorType : UInt8;
bcdUSB : UInt16;
bDeviceClass : UInt8;
bDeviceSubClass : UInt8;
bDeviceProtocol : UInt8;
bMaxPacketSize0 : UInt8;
bNumConfigurations : UInt8;
bReserved : UInt8;
end record with Pack;
type EP_Addr is record
Num : EP_Id;
Dir : EP_Dir;
end record;
type EP_Dir is (EP_In, EP_Out);
subtype EP_Id is UInt4;
type EP_Type is (Control, Isochronous, Bulk, Interrupt);
function Img (EP : EP_Addr) return String
function Img (D : Setup_Data) return String
type Interface_Id is new UInt8;
Invalid_String_Id : constant String_Id := 0;
type Lang_ID is new UInt16;
Max_Strings : constant := Usb_Embedded_Config.Max_Strings;
Max_Total_String_Chars : constant := Usb_Embedded_Config.String_Buffer_Size;
type Packet_Size is range 0 .. 1024;
type Request_Type is record
Recipient : Request_Type_Recipient;
Reserved : UInt3;
Typ : Request_Type_Type;
Dir : Data_Phase_Transfer_Direction;
end record with Pack, Size => 8;
type Request_Type_Recipient is (Dev, Iface, Endpoint, Other);
type Request_Type_Type is (Stand, Class, Vendor, Reserved)
with Size => 2;
type Setup_Data is record
RType : Request_Type;
Request : UInt8;
Value : UInt16;
Index : UInt16;
Length : UInt16;
end record with Pack, Size => 8 * 8;
type Setup_Request_Answer is (Handled, Not_Supported, Next_Callback);
type String_Descriptor (bLength : UInt8) is record
bDescriptorType : UInt8 := 3;
Str : USB_String (3 .. bLength);
end record with Pack;
type String_Descriptor_Zero is record
bLength : UInt8;
bDescriptorType : UInt8 := 3;
Str : String (1 .. 2);
end record;
type String_Id is new UInt8;
subtype String_Range is UInt8 range 0 .. 253;
The maximum length of a string is limited by the the bLength field of the String Descriptor. This field is one byte: 0 .. 255, but bLength encodes to total size of the descriptor including the bLenght and bDescriptorType fields (one byte each). So the remaining length for string is 255 - 2.
function To_USB_String (Str : String) return USB_String
Convert Ada ASCII string to USB UTF16 string
type USB_String is array (String_Range range <>) of Character;
Verbose : constant Boolean := False;