Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/machine/usb/descriptor/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ var InterfaceCDCData = InterfaceType{
data: interfaceCDCData[:],
}

// EP1 IN : CDC Call Management
// EP2 OUT: CDC OUT
// EP2 IN : CDC IN
var CDC = Descriptor{
Device: DeviceCDC.Bytes(),
Configuration: Append([][]byte{
Expand All @@ -160,9 +163,9 @@ var CDC = Descriptor{
ClassSpecificCDCCallManagement.Bytes(),
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
EndpointEP1IN.Bytes(),
EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
EndpointIN(EndpointEP3, TransferTypeBulk, 0x40, 0x00).Bytes(),
}),
}
128 changes: 34 additions & 94 deletions src/machine/usb/descriptor/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,104 +15,44 @@ const (
TransferTypeInterrupt
)

var endpointEP1IN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x81, // EndpointAddress
0x03, // Attributes
0x10, // MaxPacketSizeL
0x00, // MaxPacketSizeH
0x10, // Interval
}

var EndpointEP1IN = EndpointType{
data: endpointEP1IN[:],
}

var endpointEP2OUT = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x02, // EndpointAddress
0x02, // Attributes
0x40, // MaxPacketSizeL
0x00, // MaxPacketSizeH
0x00, // Interval
}

var EndpointEP2OUT = EndpointType{
data: endpointEP2OUT[:],
}
type EndpointNumber uint8

var endpointEP3IN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x83, // EndpointAddress
0x02, // Attributes
0x40, // MaxPacketSizeL
0x00, // MaxPacketSizeH
0x00, // Interval
}

var EndpointEP3IN = EndpointType{
data: endpointEP3IN[:],
}

var endpointEP4IN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x84, // EndpointAddress
0x03, // Attributes
0x40, // MaxPacketSizeL
0x00, // MaxPacketSizeH
0x01, // Interval
}

var EndpointEP4IN = EndpointType{
data: endpointEP4IN[:],
}

var endpointEP5OUT = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x05, // EndpointAddress
0x03, // Attributes
0x40, // MaxPacketSizeL
0x00, // MaxPacketSizeH
0x01, // Interval
}

var EndpointEP5OUT = EndpointType{
data: endpointEP5OUT[:],
}

// Mass Storage Class bulk in endpoint
var endpointMSCIN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x86, // EndpointAddress
TransferTypeBulk, // Attributes
0x40, // MaxPacketSizeL (64 bytes)
0x00, // MaxPacketSizeH
0x00, // Interval
}
const (
EndpointEP1 EndpointNumber = iota
EndpointEP2
EndpointEP3
EndpointEP4
)

var EndpointMSCIN = EndpointType{
data: endpointMSCIN[:],
}
const (
maxEndpoints = 4
)

// Mass Storage Class bulk out endpoint
var endpointMSCOUT = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x07, // EndpointAddress
TransferTypeBulk, // Attributes
0x40, // MaxPacketSizeL (64 bytes)
0x00, // MaxPacketSizeH
0x00, // Interval
}
var (
endpointEPIn = [maxEndpoints][endpointTypeLen]byte{}
endpointEPOut = [maxEndpoints][endpointTypeLen]byte{}
)

var EndpointMSCOUT = EndpointType{
data: endpointMSCOUT[:],
func EndpointIN(ep EndpointNumber, transferType uint8, maxPacketSize uint16, interval uint8) EndpointType {
e := EndpointType{data: endpointEPIn[ep][:]}
e.Length(endpointTypeLen)
e.Type(TypeEndpoint)
e.EndpointAddress(uint8(ep+1) | 0x80) // EndpointNumber is 0-based, addresses are 1-based
e.Attributes(transferType)
e.MaxPacketSize(maxPacketSize)
e.Interval(interval)
return e
}

func EndpointOUT(ep EndpointNumber, transferType uint8, maxPacketSize uint16, interval uint8) EndpointType {
e := EndpointType{data: endpointEPOut[ep][:]}
e.Length(endpointTypeLen)
e.Type(TypeEndpoint)
e.EndpointAddress(uint8(ep + 1)) // EndpointNumber is 0-based, addresses are 1-based
e.Attributes(transferType)
e.MaxPacketSize(maxPacketSize)
e.Interval(interval)
return e
}

const (
Expand Down
15 changes: 10 additions & 5 deletions src/machine/usb/descriptor/hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ var ClassHID = ClassHIDType{
data: classHID[:],
}

// EP1 IN : CDC Call Management
// EP1 OUT: HID OUT
// EP2 IN : HID IN
// EP2 OUT: CDC OUT
// EP3 IN : CDC IN
var CDCHID = Descriptor{
Device: DeviceCDC.Bytes(),
Configuration: Append([][]byte{
Expand All @@ -121,14 +126,14 @@ var CDCHID = Descriptor{
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
ClassSpecificCDCCallManagement.Bytes(),
EndpointEP1IN.Bytes(),
EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
EndpointIN(EndpointEP3, TransferTypeBulk, 0x40, 0x00).Bytes(),
InterfaceHID.Bytes(),
ClassHID.Bytes(),
EndpointEP4IN.Bytes(),
EndpointEP5OUT.Bytes(),
EndpointIN(EndpointEP2, TransferTypeInterrupt, 0x40, 0x01).Bytes(),
EndpointOUT(EndpointEP1, TransferTypeInterrupt, 0x40, 0x01).Bytes(),
}),
HID: map[uint16][]byte{
2: Append([][]byte{ // Update ClassLength in classHID whenever the array length is modified!
Expand Down
15 changes: 10 additions & 5 deletions src/machine/usb/descriptor/joystick.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ var JoystickDefaultHIDReport = Append([][]byte{
// CDCJoystick requires that you append the JoystickDescriptor
// to the Configuration before using. This is in order to support
// custom configurations.
// EP1 IN : CDC Call Management
// EP1 OUT: HID OUT
// EP2 IN : HID IN
// EP2 OUT: CDC OUT
// EP2 IN : CDC IN
var CDCJoystick = Descriptor{
Device: DeviceJoystick.Bytes(),
Configuration: Append([][]byte{
Expand All @@ -131,14 +136,14 @@ var CDCJoystick = Descriptor{
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
ClassSpecificCDCCallManagement.Bytes(),
EndpointEP1IN.Bytes(),
EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
EndpointIN(EndpointEP3, TransferTypeBulk, 0x40, 0x00).Bytes(),
InterfaceHIDJoystick.Bytes(),
ClassHIDJoystick.Bytes(),
EndpointEP4IN.Bytes(),
EndpointEP5OUT.Bytes(),
EndpointIN(EndpointEP2, TransferTypeInterrupt, 0x40, 0x01).Bytes(),
EndpointOUT(EndpointEP1, TransferTypeInterrupt, 0x40, 0x01).Bytes(),
}),
HID: map[uint16][]byte{},
}
11 changes: 8 additions & 3 deletions src/machine/usb/descriptor/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ var ConfigurationCDCMIDI = ConfigurationType{
data: configurationCDCMIDI[:],
}

// EP1 IN : CDC Call Management
// EP2 OUT: CDC OUT
// EP3 IN : CDC IN
// EP6 IN : MIDI IN (custom endpoint descriptor)
// EP7 OUT: MIDI OUT (custom endpoint descriptor)
var CDCMIDI = Descriptor{
Device: DeviceCDC.Bytes(),
Configuration: Append([][]byte{
Expand All @@ -228,10 +233,10 @@ var CDCMIDI = Descriptor{
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
ClassSpecificCDCCallManagement.Bytes(),
EndpointEP1IN.Bytes(),
EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
EndpointIN(EndpointEP3, TransferTypeBulk, 0x40, 0x00).Bytes(),
InterfaceAssociationMIDI.Bytes(),
InterfaceAudio.Bytes(),
ClassSpecificAudioInterface.Bytes(),
Expand Down
17 changes: 14 additions & 3 deletions src/machine/usb/descriptor/msc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ var ConfigurationMSC = ConfigurationType{
data: configurationMSC[:],
}

var (
EndpointMSCIN = EndpointIN(EndpointEP2, TransferTypeBulk, 0x40, 0x00)
EndpointMSCOUT = EndpointOUT(EndpointEP3, TransferTypeBulk, 0x40, 0x00)
)

// Mass Storage Class
// EP1 IN : CDC Call Management
// EP1 OUT: x
// EP2 IN : MSC IN
// EP2 OUT: CDC OUT
// EP3 IN : CDC IN
// EP3 OUT: MSC OUT
var MSC = Descriptor{
Device: DeviceCDC.Bytes(),
Configuration: Append([][]byte{
Expand All @@ -63,10 +74,10 @@ var MSC = Descriptor{
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
ClassSpecificCDCCallManagement.Bytes(),
EndpointEP1IN.Bytes(),
EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
EndpointIN(EndpointEP3, TransferTypeBulk, 0x40, 0x00).Bytes(),
InterfaceAssociationMSC.Bytes(),
InterfaceMSC.Bytes(),
EndpointMSCIN.Bytes(),
Expand Down
Loading