diff --git a/src/machine/machine_atsamd21_usb.go b/src/machine/machine_atsamd21_usb.go index 51f276c0..f47b1ee3 100644 --- a/src/machine/machine_atsamd21_usb.go +++ b/src/machine/machine_atsamd21_usb.go @@ -275,15 +275,15 @@ func handleUSBIRQ(intr interrupt.Interrupt) { usbEndpointDescriptors[0].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos) ok := false - if (setup.bmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { + if (setup.BmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { // Standard Requests ok = handleStandardSetup(setup) } else { // Class Interface Requests - if setup.wIndex == usb_CDC_ACM_INTERFACE { + if setup.WIndex == usb_CDC_ACM_INTERFACE { ok = cdcSetup(setup) - } else if setup.bmRequestType == usb_SET_REPORT_TYPE && setup.bRequest == usb_SET_IDLE { - sendZlp() + } else if setup.BmRequestType == usb_SET_REPORT_TYPE && setup.BRequest == usb_SET_IDLE { + SendZlp() ok = true } } @@ -411,37 +411,37 @@ func initEndpoint(ep, config uint32) { } } -func handleStandardSetup(setup usbSetup) bool { - switch setup.bRequest { +func handleStandardSetup(setup USBSetup) bool { + switch setup.BRequest { case usb_GET_STATUS: buf := []byte{0, 0} - if setup.bmRequestType != 0 { // endpoint + if setup.BmRequestType != 0 { // endpoint // TODO: actually check if the endpoint in question is currently halted if isEndpointHalt { buf[0] = 1 } } - sendUSBPacket(0, buf, setup.wLength) + sendUSBPacket(0, buf, setup.WLength) return true case usb_CLEAR_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = false - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = false } - sendZlp() + SendZlp() return true case usb_SET_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = true - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = true } - sendZlp() + SendZlp() return true case usb_SET_ADDRESS: @@ -465,7 +465,7 @@ func handleStandardSetup(setup usbSetup) bool { } // last, set the device address to that requested by host - sam.USB_DEVICE.DADD.SetBits(setup.wValueL) + sam.USB_DEVICE.DADD.SetBits(setup.WValueL) sam.USB_DEVICE.DADD.SetBits(sam.USB_DEVICE_DADD_ADDEN) return true @@ -479,16 +479,16 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_CONFIGURATION: buff := []byte{usbConfiguration} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_CONFIGURATION: - if setup.bmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { + if setup.BmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { for i := 1; i < len(endPoints); i++ { initEndpoint(uint32(i), endPoints[i]) } - usbConfiguration = setup.wValueL + usbConfiguration = setup.WValueL // Enable interrupt for CDC control messages from host (OUT packet) setEPINTENSET(usb_CDC_ENDPOINT_ACM, sam.USB_DEVICE_EPINTENSET_TRCPT1) @@ -501,7 +501,7 @@ func handleStandardSetup(setup usbSetup) bool { setEPINTENSET(usb_HID_ENDPOINT_IN, sam.USB_DEVICE_EPINTENSET_TRCPT1) } - sendZlp() + SendZlp() return true } else { return false @@ -509,13 +509,13 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_INTERFACE: buff := []byte{usbSetInterface} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_INTERFACE: - usbSetInterface = setup.wValueL + usbSetInterface = setup.WValueL - sendZlp() + SendZlp() return true default: @@ -523,9 +523,9 @@ func handleStandardSetup(setup usbSetup) bool { } } -func cdcSetup(setup usbSetup) bool { - if setup.bmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_GET_LINE_CODING { +func cdcSetup(setup USBSetup) bool { + if setup.BmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_GET_LINE_CODING { var b [cdcLineInfoSize]byte b[0] = byte(usbLineInfo.dwDTERate) b[1] = byte(usbLineInfo.dwDTERate >> 8) @@ -535,13 +535,13 @@ func cdcSetup(setup usbSetup) bool { b[5] = byte(usbLineInfo.bParityType) b[6] = byte(usbLineInfo.bDataBits) - sendUSBPacket(0, b[:], setup.wLength) + sendUSBPacket(0, b[:], setup.WLength) return true } } - if setup.bmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_SET_LINE_CODING { + if setup.BmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_SET_LINE_CODING { b, err := receiveUSBControlPacket() if err != nil { return false @@ -553,25 +553,25 @@ func cdcSetup(setup usbSetup) bool { usbLineInfo.bDataBits = b[6] } - if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { - usbLineInfo.lineState = setup.wValueL + if setup.BRequest == usb_CDC_SET_CONTROL_LINE_STATE { + usbLineInfo.lineState = setup.WValueL } - if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { + if setup.BRequest == usb_CDC_SET_LINE_CODING || setup.BRequest == usb_CDC_SET_CONTROL_LINE_STATE { // auto-reset into the bootloader if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { EnterBootloader() } else { // TODO: cancel any reset } - sendZlp() + SendZlp() } - if setup.bRequest == usb_CDC_SEND_BREAK { + if setup.BRequest == usb_CDC_SEND_BREAK { // TODO: something with this value? // breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL; // return false; - sendZlp() + SendZlp() } return true } @@ -678,7 +678,7 @@ func handleEndpoint(ep uint32) { setEPSTATUSCLR(ep, sam.USB_DEVICE_EPSTATUSCLR_BK0RDY) } -func sendZlp() { +func SendZlp() { usbEndpointDescriptors[0].DeviceDescBank[1].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos) } diff --git a/src/machine/machine_atsamd51_usb.go b/src/machine/machine_atsamd51_usb.go index f0f7e114..d49a68b4 100644 --- a/src/machine/machine_atsamd51_usb.go +++ b/src/machine/machine_atsamd51_usb.go @@ -279,15 +279,15 @@ func handleUSBIRQ(interrupt.Interrupt) { usbEndpointDescriptors[0].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos) ok := false - if (setup.bmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { + if (setup.BmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { // Standard Requests ok = handleStandardSetup(setup) } else { // Class Interface Requests - if setup.wIndex == usb_CDC_ACM_INTERFACE { + if setup.WIndex == usb_CDC_ACM_INTERFACE { ok = cdcSetup(setup) - } else if setup.bmRequestType == usb_SET_REPORT_TYPE && setup.bRequest == usb_SET_IDLE { - sendZlp() + } else if setup.BmRequestType == usb_SET_REPORT_TYPE && setup.BRequest == usb_SET_IDLE { + SendZlp() ok = true } } @@ -415,37 +415,37 @@ func initEndpoint(ep, config uint32) { } } -func handleStandardSetup(setup usbSetup) bool { - switch setup.bRequest { +func handleStandardSetup(setup USBSetup) bool { + switch setup.BRequest { case usb_GET_STATUS: buf := []byte{0, 0} - if setup.bmRequestType != 0 { // endpoint + if setup.BmRequestType != 0 { // endpoint // TODO: actually check if the endpoint in question is currently halted if isEndpointHalt { buf[0] = 1 } } - sendUSBPacket(0, buf, setup.wLength) + sendUSBPacket(0, buf, setup.WLength) return true case usb_CLEAR_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = false - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = false } - sendZlp() + SendZlp() return true case usb_SET_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = true - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = true } - sendZlp() + SendZlp() return true case usb_SET_ADDRESS: @@ -469,7 +469,7 @@ func handleStandardSetup(setup usbSetup) bool { } // last, set the device address to that requested by host - sam.USB_DEVICE.DADD.SetBits(setup.wValueL) + sam.USB_DEVICE.DADD.SetBits(setup.WValueL) sam.USB_DEVICE.DADD.SetBits(sam.USB_DEVICE_DADD_ADDEN) return true @@ -483,16 +483,16 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_CONFIGURATION: buff := []byte{usbConfiguration} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_CONFIGURATION: - if setup.bmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { + if setup.BmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { for i := 1; i < len(endPoints); i++ { initEndpoint(uint32(i), endPoints[i]) } - usbConfiguration = setup.wValueL + usbConfiguration = setup.WValueL // Enable interrupt for CDC control messages from host (OUT packet) setEPINTENSET(usb_CDC_ENDPOINT_ACM, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT1) @@ -505,7 +505,7 @@ func handleStandardSetup(setup usbSetup) bool { setEPINTENSET(usb_HID_ENDPOINT_IN, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT1) } - sendZlp() + SendZlp() return true } else { return false @@ -513,13 +513,13 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_INTERFACE: buff := []byte{usbSetInterface} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_INTERFACE: - usbSetInterface = setup.wValueL + usbSetInterface = setup.WValueL - sendZlp() + SendZlp() return true default: @@ -527,9 +527,9 @@ func handleStandardSetup(setup usbSetup) bool { } } -func cdcSetup(setup usbSetup) bool { - if setup.bmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_GET_LINE_CODING { +func cdcSetup(setup USBSetup) bool { + if setup.BmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_GET_LINE_CODING { var b [cdcLineInfoSize]byte b[0] = byte(usbLineInfo.dwDTERate) b[1] = byte(usbLineInfo.dwDTERate >> 8) @@ -539,13 +539,13 @@ func cdcSetup(setup usbSetup) bool { b[5] = byte(usbLineInfo.bParityType) b[6] = byte(usbLineInfo.bDataBits) - sendUSBPacket(0, b[:], setup.wLength) + sendUSBPacket(0, b[:], setup.WLength) return true } } - if setup.bmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_SET_LINE_CODING { + if setup.BmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_SET_LINE_CODING { b, err := receiveUSBControlPacket() if err != nil { return false @@ -557,25 +557,25 @@ func cdcSetup(setup usbSetup) bool { usbLineInfo.bDataBits = b[6] } - if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { - usbLineInfo.lineState = setup.wValueL + if setup.BRequest == usb_CDC_SET_CONTROL_LINE_STATE { + usbLineInfo.lineState = setup.WValueL } - if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { + if setup.BRequest == usb_CDC_SET_LINE_CODING || setup.BRequest == usb_CDC_SET_CONTROL_LINE_STATE { // auto-reset into the bootloader if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { EnterBootloader() } else { // TODO: cancel any reset } - sendZlp() + SendZlp() } - if setup.bRequest == usb_CDC_SEND_BREAK { + if setup.BRequest == usb_CDC_SEND_BREAK { // TODO: something with this value? // breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL; // return false; - sendZlp() + SendZlp() } return true } @@ -683,7 +683,7 @@ func handleEndpoint(ep uint32) { setEPSTATUSCLR(ep, sam.USB_DEVICE_ENDPOINT_EPSTATUSCLR_BK0RDY) } -func sendZlp() { +func SendZlp() { usbEndpointDescriptors[0].DeviceDescBank[1].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos) } diff --git a/src/machine/machine_nrf52840_usb.go b/src/machine/machine_nrf52840_usb.go index 663f9e22..a01285f3 100644 --- a/src/machine/machine_nrf52840_usb.go +++ b/src/machine/machine_nrf52840_usb.go @@ -242,14 +242,14 @@ func handleUSBIRQ(interrupt.Interrupt) { setup := parseUSBSetupRegisters() ok := false - if (setup.bmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { + if (setup.BmRequestType & usb_REQUEST_TYPE) == usb_REQUEST_STANDARD { // Standard Requests ok = handleStandardSetup(setup) } else { - if setup.wIndex == usb_CDC_ACM_INTERFACE { + if setup.WIndex == usb_CDC_ACM_INTERFACE { ok = cdcSetup(setup) - } else if setup.bmRequestType == usb_SET_REPORT_TYPE && setup.bRequest == usb_SET_IDLE { - sendZlp() + } else if setup.BmRequestType == usb_SET_REPORT_TYPE && setup.BRequest == usb_SET_IDLE { + SendZlp() ok = true } } @@ -323,14 +323,14 @@ func parseUSBLineInfo(b []byte) { usbLineInfo.bDataBits = b[6] } -func parseUSBSetupRegisters() usbSetup { - return usbSetup{ - bmRequestType: uint8(nrf.USBD.BMREQUESTTYPE.Get()), - bRequest: uint8(nrf.USBD.BREQUEST.Get()), - wValueL: uint8(nrf.USBD.WVALUEL.Get()), - wValueH: uint8(nrf.USBD.WVALUEH.Get()), - wIndex: uint16((nrf.USBD.WINDEXH.Get() << 8) | nrf.USBD.WINDEXL.Get()), - wLength: uint16(((nrf.USBD.WLENGTHH.Get() & 0xff) << 8) | (nrf.USBD.WLENGTHL.Get() & 0xff)), +func parseUSBSetupRegisters() USBSetup { + return USBSetup{ + BmRequestType: uint8(nrf.USBD.BMREQUESTTYPE.Get()), + BRequest: uint8(nrf.USBD.BREQUEST.Get()), + WValueL: uint8(nrf.USBD.WVALUEL.Get()), + WValueH: uint8(nrf.USBD.WVALUEH.Get()), + WIndex: uint16((nrf.USBD.WINDEXH.Get() << 8) | nrf.USBD.WINDEXL.Get()), + WLength: uint16(((nrf.USBD.WLENGTHH.Get() & 0xff) << 8) | (nrf.USBD.WLENGTHL.Get() & 0xff)), } } @@ -360,33 +360,33 @@ func initEndpoint(ep, config uint32) { } } -func handleStandardSetup(setup usbSetup) bool { - switch setup.bRequest { +func handleStandardSetup(setup USBSetup) bool { + switch setup.BRequest { case usb_GET_STATUS: buf := []byte{0, 0} - if setup.bmRequestType != 0 { // endpoint + if setup.BmRequestType != 0 { // endpoint if isEndpointHalt { buf[0] = 1 } } - sendUSBPacket(0, buf, setup.wLength) + sendUSBPacket(0, buf, setup.WLength) return true case usb_CLEAR_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = false - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = false } nrf.USBD.TASKS_EP0STATUS.Set(1) return true case usb_SET_FEATURE: - if setup.wValueL == 1 { // DEVICEREMOTEWAKEUP + if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP isRemoteWakeUpEnabled = true - } else if setup.wValueL == 0 { // ENDPOINTHALT + } else if setup.WValueL == 0 { // ENDPOINTHALT isEndpointHalt = true } nrf.USBD.TASKS_EP0STATUS.Set(1) @@ -405,11 +405,11 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_CONFIGURATION: buff := []byte{usbConfiguration} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_CONFIGURATION: - if setup.bmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { + if setup.BmRequestType&usb_REQUEST_RECIPIENT == usb_REQUEST_DEVICE { nrf.USBD.TASKS_EP0STATUS.Set(1) for i := 1; i < len(endPoints); i++ { initEndpoint(uint32(i), endPoints[i]) @@ -420,7 +420,7 @@ func handleStandardSetup(setup usbSetup) bool { nrf.USBD.INTENSET.Set(nrf.USBD_INTENSET_ENDEPOUT0 << usb_HID_ENDPOINT_IN) } - usbConfiguration = setup.wValueL + usbConfiguration = setup.WValueL return true } else { return false @@ -428,11 +428,11 @@ func handleStandardSetup(setup usbSetup) bool { case usb_GET_INTERFACE: buff := []byte{usbSetInterface} - sendUSBPacket(0, buff, setup.wLength) + sendUSBPacket(0, buff, setup.WLength) return true case usb_SET_INTERFACE: - usbSetInterface = setup.wValueL + usbSetInterface = setup.WValueL nrf.USBD.TASKS_EP0STATUS.Set(1) return true @@ -442,9 +442,9 @@ func handleStandardSetup(setup usbSetup) bool { } } -func cdcSetup(setup usbSetup) bool { - if setup.bmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_GET_LINE_CODING { +func cdcSetup(setup USBSetup) bool { + if setup.BmRequestType == usb_REQUEST_DEVICETOHOST_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_GET_LINE_CODING { var b [cdcLineInfoSize]byte b[0] = byte(usbLineInfo.dwDTERate) b[1] = byte(usbLineInfo.dwDTERate >> 8) @@ -454,27 +454,27 @@ func cdcSetup(setup usbSetup) bool { b[5] = byte(usbLineInfo.bParityType) b[6] = byte(usbLineInfo.bDataBits) - sendUSBPacket(0, b[:], setup.wLength) + sendUSBPacket(0, b[:], setup.WLength) return true } } - if setup.bmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { - if setup.bRequest == usb_CDC_SET_LINE_CODING { + if setup.BmRequestType == usb_REQUEST_HOSTTODEVICE_CLASS_INTERFACE { + if setup.BRequest == usb_CDC_SET_LINE_CODING { epout0data_setlinecoding = true nrf.USBD.TASKS_EP0RCVOUT.Set(1) return true } - if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { - usbLineInfo.lineState = setup.wValueL + if setup.BRequest == usb_CDC_SET_CONTROL_LINE_STATE { + usbLineInfo.lineState = setup.WValueL if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { EnterBootloader() } nrf.USBD.TASKS_EP0STATUS.Set(1) } - if setup.bRequest == usb_CDC_SEND_BREAK { + if setup.BRequest == usb_CDC_SEND_BREAK { nrf.USBD.TASKS_EP0STATUS.Set(1) } return true @@ -530,7 +530,7 @@ func (usbcdc *USBCDC) handleEndpoint(ep uint32) { nrf.USBD.SIZE.EPOUT[ep].Set(0) } -func sendZlp() { +func SendZlp() { nrf.USBD.TASKS_EP0STATUS.Set(1) } diff --git a/src/machine/usb.go b/src/machine/usb.go index cc7e4534..2e5811b5 100644 --- a/src/machine/usb.go +++ b/src/machine/usb.go @@ -176,13 +176,6 @@ const ( ) // usbDeviceDescBank is the USB device endpoint descriptor. -// typedef struct { -// __IO USB_DEVICE_ADDR_Type ADDR; /**< \brief Offset: 0x000 (R/W 32) DEVICE_DESC_BANK Endpoint Bank, Adress of Data Buffer */ -// __IO USB_DEVICE_PCKSIZE_Type PCKSIZE; /**< \brief Offset: 0x004 (R/W 32) DEVICE_DESC_BANK Endpoint Bank, Packet Size */ -// __IO USB_DEVICE_EXTREG_Type EXTREG; /**< \brief Offset: 0x008 (R/W 16) DEVICE_DESC_BANK Endpoint Bank, Extended */ -// __IO USB_DEVICE_STATUS_BK_Type STATUS_BK; /**< \brief Offset: 0x00A (R/W 8) DEVICE_DESC_BANK Enpoint Bank, Status of Bank */ -// RoReg8 Reserved1[0x5]; -// } UsbDeviceDescBank; type usbDeviceDescBank struct { ADDR volatile.Register32 PCKSIZE volatile.Register32 @@ -195,38 +188,23 @@ type usbDeviceDescriptor struct { DeviceDescBank [2]usbDeviceDescBank } -// typedef struct { -// union { -// uint8_t bmRequestType; -// struct { -// uint8_t direction : 5; -// uint8_t type : 2; -// uint8_t transferDirection : 1; -// }; -// }; -// uint8_t bRequest; -// uint8_t wValueL; -// uint8_t wValueH; -// uint16_t wIndex; -// uint16_t wLength; -// } USBSetup; -type usbSetup struct { - bmRequestType uint8 - bRequest uint8 - wValueL uint8 - wValueH uint8 - wIndex uint16 - wLength uint16 +type USBSetup struct { + BmRequestType uint8 + BRequest uint8 + WValueL uint8 + WValueH uint8 + WIndex uint16 + WLength uint16 } -func newUSBSetup(data []byte) usbSetup { - u := usbSetup{} - u.bmRequestType = uint8(data[0]) - u.bRequest = uint8(data[1]) - u.wValueL = uint8(data[2]) - u.wValueH = uint8(data[3]) - u.wIndex = uint16(data[4]) | (uint16(data[5]) << 8) - u.wLength = uint16(data[6]) | (uint16(data[7]) << 8) +func newUSBSetup(data []byte) USBSetup { + u := USBSetup{} + u.BmRequestType = uint8(data[0]) + u.BRequest = uint8(data[1]) + u.WValueL = uint8(data[2]) + u.WValueH = uint8(data[3]) + u.WIndex = uint16(data[4]) | (uint16(data[5]) << 8) + u.WLength = uint16(data[6]) | (uint16(data[7]) << 8) return u } @@ -299,41 +277,41 @@ func (usbcdc *USBCDC) Receive(data byte) { // sendDescriptor creates and sends the various USB descriptor types that // can be requested by the host. -func sendDescriptor(setup usbSetup) { - switch setup.wValueH { +func sendDescriptor(setup USBSetup) { + switch setup.WValueH { case usb_CONFIGURATION_DESCRIPTOR_TYPE: - sendUSBPacket(0, usbDescriptor.Configuration, setup.wLength) + sendUSBPacket(0, usbDescriptor.Configuration, setup.WLength) return case usb_DEVICE_DESCRIPTOR_TYPE: // composite descriptor usbDescriptor.Configure(usb_VID, usb_PID) - sendUSBPacket(0, usbDescriptor.Device, setup.wLength) + sendUSBPacket(0, usbDescriptor.Device, setup.WLength) return case usb_STRING_DESCRIPTOR_TYPE: - switch setup.wValueL { + switch setup.WValueL { case 0: b := []byte{0x04, 0x03, 0x09, 0x04} - sendUSBPacket(0, b, setup.wLength) + sendUSBPacket(0, b, setup.WLength) case usb_IPRODUCT: b := make([]byte, (len(usb_STRING_PRODUCT)<<1)+2) strToUTF16LEDescriptor(usb_STRING_PRODUCT, b) - sendUSBPacket(0, b, setup.wLength) + sendUSBPacket(0, b, setup.WLength) case usb_IMANUFACTURER: b := make([]byte, (len(usb_STRING_MANUFACTURER)<<1)+2) strToUTF16LEDescriptor(usb_STRING_MANUFACTURER, b) - sendUSBPacket(0, b, setup.wLength) + sendUSBPacket(0, b, setup.WLength) case usb_ISERIAL: // TODO: allow returning a product serial number - sendZlp() + SendZlp() } return case usb_HID_REPORT_TYPE: - if h, ok := usbDescriptor.HID[setup.wIndex]; ok { - sendUSBPacket(0, h, setup.wLength) + if h, ok := usbDescriptor.HID[setup.WIndex]; ok { + sendUSBPacket(0, h, setup.WLength) return } case usb_DEVICE_QUALIFIER: @@ -342,7 +320,7 @@ func sendDescriptor(setup usbSetup) { } // do not know how to handle this message, so return zero - sendZlp() + SendZlp() return }