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

     1  package descriptor
     2  
     3  import (
     4  	"encoding/binary"
     5  )
     6  
     7  var endpointEP1IN = [endpointTypeLen]byte{
     8  	endpointTypeLen,
     9  	TypeEndpoint,
    10  	0x81, // EndpointAddress
    11  	0x03, // Attributes
    12  	0x10, // MaxPacketSizeL
    13  	0x00, // MaxPacketSizeH
    14  	0x10, // Interval
    15  }
    16  
    17  var EndpointEP1IN = EndpointType{
    18  	data: endpointEP1IN[:],
    19  }
    20  
    21  var endpointEP2OUT = [endpointTypeLen]byte{
    22  	endpointTypeLen,
    23  	TypeEndpoint,
    24  	0x02, // EndpointAddress
    25  	0x02, // Attributes
    26  	0x40, // MaxPacketSizeL
    27  	0x00, // MaxPacketSizeH
    28  	0x00, // Interval
    29  }
    30  
    31  var EndpointEP2OUT = EndpointType{
    32  	data: endpointEP2OUT[:],
    33  }
    34  
    35  var endpointEP3IN = [endpointTypeLen]byte{
    36  	endpointTypeLen,
    37  	TypeEndpoint,
    38  	0x83, // EndpointAddress
    39  	0x02, // Attributes
    40  	0x40, // MaxPacketSizeL
    41  	0x00, // MaxPacketSizeH
    42  	0x00, // Interval
    43  }
    44  
    45  var EndpointEP3IN = EndpointType{
    46  	data: endpointEP3IN[:],
    47  }
    48  
    49  var endpointEP4IN = [endpointTypeLen]byte{
    50  	endpointTypeLen,
    51  	TypeEndpoint,
    52  	0x84, // EndpointAddress
    53  	0x03, // Attributes
    54  	0x40, // MaxPacketSizeL
    55  	0x00, // MaxPacketSizeH
    56  	0x01, // Interval
    57  }
    58  
    59  var EndpointEP4IN = EndpointType{
    60  	data: endpointEP4IN[:],
    61  }
    62  
    63  var endpointEP5OUT = [endpointTypeLen]byte{
    64  	endpointTypeLen,
    65  	TypeEndpoint,
    66  	0x05, // EndpointAddress
    67  	0x03, // Attributes
    68  	0x40, // MaxPacketSizeL
    69  	0x00, // MaxPacketSizeH
    70  	0x01, // Interval
    71  }
    72  
    73  var EndpointEP5OUT = EndpointType{
    74  	data: endpointEP5OUT[:],
    75  }
    76  
    77  const (
    78  	endpointTypeLen = 7
    79  )
    80  
    81  type EndpointType struct {
    82  	data []byte
    83  }
    84  
    85  func (d EndpointType) Bytes() []byte {
    86  	return d.data
    87  }
    88  
    89  func (d EndpointType) Length(v uint8) {
    90  	d.data[0] = byte(v)
    91  }
    92  
    93  func (d EndpointType) Type(v uint8) {
    94  	d.data[1] = byte(v)
    95  }
    96  
    97  func (d EndpointType) EndpointAddress(v uint8) {
    98  	d.data[2] = byte(v)
    99  }
   100  
   101  func (d EndpointType) Attributes(v uint8) {
   102  	d.data[3] = byte(v)
   103  }
   104  
   105  func (d EndpointType) MaxPacketSize(v uint16) {
   106  	binary.LittleEndian.PutUint16(d.data[4:6], v)
   107  }
   108  
   109  func (d EndpointType) Interval(v uint8) {
   110  	d.data[6] = byte(v)
   111  }