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

     1  package descriptor
     2  
     3  var interfaceAssociationMIDI = [interfaceAssociationTypeLen]byte{
     4  	interfaceAssociationTypeLen,
     5  	TypeInterfaceAssociation,
     6  	0x02, // EndpointAddress
     7  	0x02, // Attributes
     8  	0x01, // MaxPacketSizeL
     9  	0x01, // MaxPacketSizeH
    10  	0x00, // Interval
    11  	0x00, // Interval
    12  }
    13  
    14  var InterfaceAssociationMIDI = InterfaceAssociationType{
    15  	data: interfaceAssociationMIDI[:],
    16  }
    17  
    18  var interfaceAudio = [interfaceTypeLen]byte{
    19  	interfaceTypeLen,
    20  	TypeInterface,
    21  	0x02, // InterfaceNumber
    22  	0x00, // AlternateSetting
    23  	0x00, // NumEndpoints
    24  	0x01, // InterfaceClass
    25  	0x01, // InterfaceSubClass
    26  	0x00, // InterfaceProtocol
    27  	0x00, // Interface
    28  }
    29  
    30  var InterfaceAudio = InterfaceType{
    31  	data: interfaceAudio[:],
    32  }
    33  
    34  var interfaceMIDIStreaming = [interfaceTypeLen]byte{
    35  	interfaceTypeLen,
    36  	TypeInterface,
    37  	0x03, // InterfaceNumber
    38  	0x00, // AlternateSetting
    39  	0x02, // NumEndpoints
    40  	0x01, // InterfaceClass
    41  	0x03, // InterfaceSubClass
    42  	0x00, // InterfaceProtocol
    43  	0x00, // Interface
    44  }
    45  
    46  var InterfaceMIDIStreaming = InterfaceType{
    47  	data: interfaceMIDIStreaming[:],
    48  }
    49  
    50  const classSpecificAudioTypeLen = 9
    51  
    52  var classSpecificAudioInterface = [classSpecificAudioTypeLen]byte{
    53  	classSpecificAudioTypeLen,
    54  	TypeClassSpecific,
    55  	0x01,
    56  	0x00, //
    57  	0x01, //
    58  	0x09,
    59  	0x00,
    60  	0x01,
    61  	0x03,
    62  }
    63  
    64  var ClassSpecificAudioInterface = ClassSpecificType{
    65  	data: classSpecificAudioInterface[:],
    66  }
    67  
    68  const classSpecificMIDIHeaderLen = 7
    69  
    70  var classSpecificMIDIHeader = [classSpecificMIDIHeaderLen]byte{
    71  	classSpecificMIDIHeaderLen,
    72  	TypeClassSpecific,
    73  	0x01,
    74  	0x00, //
    75  	0x01, //
    76  	0x41,
    77  	0x00,
    78  }
    79  
    80  var ClassSpecificMIDIHeader = ClassSpecificType{
    81  	data: classSpecificMIDIHeader[:],
    82  }
    83  
    84  const classSpecificMIDIInJackLen = 6
    85  
    86  var classSpecificMIDIInJack1 = [classSpecificMIDIInJackLen]byte{
    87  	classSpecificMIDIInJackLen,
    88  	TypeClassSpecific,
    89  	0x02, // MIDI In jack
    90  	0x01, // Jack type (embedded)
    91  	0x01, // Jack ID
    92  	0x00, // iJack
    93  }
    94  
    95  var ClassSpecificMIDIInJack1 = ClassSpecificType{
    96  	data: classSpecificMIDIInJack1[:],
    97  }
    98  
    99  var classSpecificMIDIInJack2 = [classSpecificMIDIInJackLen]byte{
   100  	classSpecificMIDIInJackLen,
   101  	TypeClassSpecific,
   102  	0x02, // MIDI In jack
   103  	0x02, // Jack type (external)
   104  	0x02, // Jack ID
   105  	0x00, // iJack
   106  }
   107  
   108  var ClassSpecificMIDIInJack2 = ClassSpecificType{
   109  	data: classSpecificMIDIInJack2[:],
   110  }
   111  
   112  const classSpecificMIDIOutJackLen = 9
   113  
   114  var classSpecificMIDIOutJack1 = [classSpecificMIDIOutJackLen]byte{
   115  	classSpecificMIDIOutJackLen,
   116  	TypeClassSpecific,
   117  	0x03, // MIDI Out jack
   118  	0x01, // Jack type (embedded)
   119  	0x03, // Jack ID
   120  	0x01, // number of input pins
   121  	0x02, // source ID
   122  	0x01, // source pin
   123  	0x00, // iJack
   124  }
   125  
   126  var ClassSpecificMIDIOutJack1 = ClassSpecificType{
   127  	data: classSpecificMIDIOutJack1[:],
   128  }
   129  
   130  var classSpecificMIDIOutJack2 = [classSpecificMIDIOutJackLen]byte{
   131  	classSpecificMIDIOutJackLen,
   132  	TypeClassSpecific,
   133  	0x03, // MIDI Out jack
   134  	0x02, // Jack type (external)
   135  	0x04, // Jack ID
   136  	0x01, // number of input pins
   137  	0x01, // source ID
   138  	0x01, // source pin
   139  	0x00, // iJack
   140  }
   141  
   142  var ClassSpecificMIDIOutJack2 = ClassSpecificType{
   143  	data: classSpecificMIDIOutJack2[:],
   144  }
   145  
   146  const classSpecificMIDIEndpointLen = 5
   147  
   148  var classSpecificMIDIOutEndpoint = [classSpecificMIDIEndpointLen]byte{
   149  	classSpecificMIDIEndpointLen,
   150  	TypeClassSpecificEndpoint,
   151  	0x01, // CS endpoint
   152  	0x01, // number MIDI IN jacks
   153  	0x01, // assoc Jack ID
   154  }
   155  
   156  var ClassSpecificMIDIOutEndpoint = ClassSpecificType{
   157  	data: classSpecificMIDIOutEndpoint[:],
   158  }
   159  
   160  var classSpecificMIDIInEndpoint = [classSpecificMIDIEndpointLen]byte{
   161  	classSpecificMIDIEndpointLen,
   162  	TypeClassSpecificEndpoint,
   163  	0x01, // CS endpoint
   164  	0x01, // number MIDI Out jacks
   165  	0x03, // assoc Jack ID
   166  }
   167  
   168  var ClassSpecificMIDIInEndpoint = ClassSpecificType{
   169  	data: classSpecificMIDIInEndpoint[:],
   170  }
   171  
   172  const endpointMIDITypeLen = 9
   173  
   174  var endpointEP6IN = [endpointMIDITypeLen]byte{
   175  	endpointMIDITypeLen,
   176  	TypeEndpoint,
   177  	0x86, // EndpointAddress
   178  	0x02, // Attributes
   179  	0x40, // MaxPacketSizeL
   180  	0x00, // MaxPacketSizeH
   181  	0x00, // Interval
   182  	0x00, // refresh
   183  	0x00, // sync address
   184  }
   185  
   186  var EndpointEP6IN = EndpointType{
   187  	data: endpointEP6IN[:],
   188  }
   189  
   190  var endpointEP7OUT = [endpointMIDITypeLen]byte{
   191  	endpointMIDITypeLen,
   192  	TypeEndpoint,
   193  	0x07, // EndpointAddress
   194  	0x02, // Attributes
   195  	0x40, // MaxPacketSizeL
   196  	0x00, // MaxPacketSizeH
   197  	0x00, // Interval
   198  	0x00, // refresh
   199  	0x00, // sync address
   200  }
   201  
   202  var EndpointEP7OUT = EndpointType{
   203  	data: endpointEP7OUT[:],
   204  }
   205  
   206  var configurationCDCMIDI = [configurationTypeLen]byte{
   207  	configurationTypeLen,
   208  	TypeConfiguration,
   209  	0xaf, 0x00, // adjust length as needed
   210  	0x04, // number of interfaces
   211  	0x01, // configuration value
   212  	0x00, // index to string description
   213  	0xa0, // attributes
   214  	0x32, // maxpower
   215  }
   216  
   217  var ConfigurationCDCMIDI = ConfigurationType{
   218  	data: configurationCDCMIDI[:],
   219  }
   220  
   221  var CDCMIDI = Descriptor{
   222  	Device: DeviceCDC.Bytes(),
   223  	Configuration: Append([][]byte{
   224  		ConfigurationCDCMIDI.Bytes(),
   225  		InterfaceAssociationCDC.Bytes(),
   226  		InterfaceCDCControl.Bytes(),
   227  		ClassSpecificCDCHeader.Bytes(),
   228  		ClassSpecificCDCACM.Bytes(),
   229  		ClassSpecificCDCUnion.Bytes(),
   230  		ClassSpecificCDCCallManagement.Bytes(),
   231  		EndpointEP1IN.Bytes(),
   232  		InterfaceCDCData.Bytes(),
   233  		EndpointEP2OUT.Bytes(),
   234  		EndpointEP3IN.Bytes(),
   235  		InterfaceAssociationMIDI.Bytes(),
   236  		InterfaceAudio.Bytes(),
   237  		ClassSpecificAudioInterface.Bytes(),
   238  		InterfaceMIDIStreaming.Bytes(),
   239  		ClassSpecificMIDIHeader.Bytes(),
   240  		ClassSpecificMIDIInJack1.Bytes(),
   241  		ClassSpecificMIDIInJack2.Bytes(),
   242  		ClassSpecificMIDIOutJack1.Bytes(),
   243  		ClassSpecificMIDIOutJack2.Bytes(),
   244  		EndpointEP7OUT.Bytes(),
   245  		ClassSpecificMIDIOutEndpoint.Bytes(),
   246  		EndpointEP6IN.Bytes(),
   247  		ClassSpecificMIDIInEndpoint.Bytes(),
   248  	}),
   249  }