github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/usb/descriptor/cdc.go (about)

     1  package descriptor
     2  
     3  const (
     4  	cdcFunctionalHeader         = 0
     5  	cdcFunctionalCallManagement = 0x1
     6  	cdcFunctionalACM            = 0x2
     7  	cdcFunctionalDirect         = 0x3
     8  	cdcFunctionalRinger         = 0x4
     9  	cdcFunctionalCall           = 0x5
    10  	cdcFunctionalUnion          = 0x6
    11  	cdcFunctionalCountry        = 0x7
    12  	cdcFunctionalOperational    = 0x8
    13  	cdcFunctionalUSB            = 0x9
    14  	cdcFunctionalNetwork        = 0xa
    15  	cdcFunctionalProtocol       = 0xb
    16  	cdcFunctionalExtension      = 0xc
    17  	cdcFunctionalMulti          = 0xd
    18  	cdcFunctionalCAPI           = 0xe
    19  	cdcFunctionalEthernet       = 0xf
    20  	cdcFunctionalATM            = 0x10
    21  )
    22  
    23  var classSpecificCDCHeader = [classSpecificTypeLen]byte{
    24  	classSpecificTypeLen,
    25  	TypeClassSpecific,
    26  	cdcFunctionalHeader,
    27  	0x10, //
    28  	0x1,  //
    29  }
    30  
    31  var ClassSpecificCDCHeader = ClassSpecificType{
    32  	data: classSpecificCDCHeader[:],
    33  }
    34  
    35  var classSpecificCDCCallManagement = [classSpecificTypeLen]byte{
    36  	classSpecificTypeLen,
    37  	TypeClassSpecific,
    38  	cdcFunctionalCallManagement,
    39  	0x0, //
    40  	0x1, //
    41  }
    42  
    43  var ClassSpecificCDCCallManagement = ClassSpecificType{
    44  	data: classSpecificCDCCallManagement[:],
    45  }
    46  
    47  var classSpecificCDCACM = [classSpecificTypeLen]byte{
    48  	4,
    49  	TypeClassSpecific,
    50  	cdcFunctionalACM,
    51  	0x2, //
    52  }
    53  
    54  var ClassSpecificCDCACM = ClassSpecificType{
    55  	data: classSpecificCDCACM[:],
    56  }
    57  
    58  var classSpecificCDCUnion = [classSpecificTypeLen]byte{
    59  	classSpecificTypeLen,
    60  	TypeClassSpecific,
    61  	cdcFunctionalUnion,
    62  	0x0, //
    63  	0x1, //
    64  }
    65  
    66  var ClassSpecificCDCUnion = ClassSpecificType{
    67  	data: classSpecificCDCUnion[:],
    68  }
    69  
    70  var interfaceAssociationCDC = [interfaceAssociationTypeLen]byte{
    71  	interfaceAssociationTypeLen,
    72  	TypeInterfaceAssociation,
    73  	0x00, // FirstInterface
    74  	0x02, // InterfaceCount
    75  	0x02, // FunctionClass
    76  	0x02, // FunctionSubClass
    77  	0x01, // FunctionProtocol
    78  	0x00, // Function
    79  }
    80  
    81  var InterfaceAssociationCDC = InterfaceAssociationType{
    82  	data: interfaceAssociationCDC[:],
    83  }
    84  
    85  var deviceCDC = [deviceTypeLen]byte{
    86  	deviceTypeLen,
    87  	TypeDevice,
    88  	0x00, 0x02, // USB version
    89  	0xef,       // device class
    90  	0x02,       // device subclass
    91  	0x01,       // protocol
    92  	0x40,       // maxpacketsize
    93  	0x86, 0x28, // vendor id
    94  	0x2d, 0x80, // product id
    95  	0x00, 0x01, // device
    96  	0x01, // manufacturer
    97  	0x02, // product
    98  	0x03, // SerialNumber
    99  	0x01, // NumConfigurations
   100  }
   101  
   102  var DeviceCDC = DeviceType{
   103  	data: deviceCDC[:],
   104  }
   105  
   106  var configurationCDC = [configurationTypeLen]byte{
   107  	configurationTypeLen,
   108  	TypeConfiguration,
   109  	0x4b, 0x00, // adjust length as needed
   110  	0x02, // number of interfaces
   111  	0x01, // configuration value
   112  	0x00, // index to string description
   113  	0xa0, // attributes
   114  	0x32, // maxpower
   115  }
   116  
   117  var ConfigurationCDC = ConfigurationType{
   118  	data: configurationCDC[:],
   119  }
   120  
   121  var interfaceCDCControl = [interfaceTypeLen]byte{
   122  	interfaceTypeLen,
   123  	TypeInterface,
   124  	0x00, // InterfaceNumber
   125  	0x00, // AlternateSetting
   126  	0x01, // NumEndpoints
   127  	0x02, // InterfaceClass
   128  	0x02, // InterfaceSubClass
   129  	0x01, // InterfaceProtocol
   130  	0x00, // Interface
   131  }
   132  
   133  var InterfaceCDCControl = InterfaceType{
   134  	data: interfaceCDCControl[:],
   135  }
   136  
   137  var interfaceCDCData = [interfaceTypeLen]byte{
   138  	interfaceTypeLen,
   139  	TypeInterface,
   140  	0x01, // InterfaceNumber
   141  	0x00, // AlternateSetting
   142  	0x02, // NumEndpoints
   143  	0x0a, // InterfaceClass
   144  	0x00, // InterfaceSubClass
   145  	0x00, // InterfaceProtocol
   146  	0x00, // Interface
   147  }
   148  
   149  var InterfaceCDCData = InterfaceType{
   150  	data: interfaceCDCData[:],
   151  }
   152  
   153  var CDC = Descriptor{
   154  	Device: DeviceCDC.Bytes(),
   155  	Configuration: Append([][]byte{
   156  		ConfigurationCDC.Bytes(),
   157  		InterfaceAssociationCDC.Bytes(),
   158  		InterfaceCDCControl.Bytes(),
   159  		ClassSpecificCDCHeader.Bytes(),
   160  		ClassSpecificCDCCallManagement.Bytes(),
   161  		ClassSpecificCDCACM.Bytes(),
   162  		ClassSpecificCDCUnion.Bytes(),
   163  		EndpointEP1IN.Bytes(),
   164  		InterfaceCDCData.Bytes(),
   165  		EndpointEP2OUT.Bytes(),
   166  		EndpointEP3IN.Bytes(),
   167  	}),
   168  }