mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
usbcdc: fix handling of CDC SET_LINE_CODING request
The SET_LINE_CODING request contains data and must be handled as such. Previously, the only requests that had data were IN requests. SET_LINE_CODING is an OUT request so it required additional changes to support a new type of data request.
This commit is contained in:
parent
5e37448814
commit
215ff56fe8
@ -341,7 +341,7 @@ static struct usb_cdc_line_coding line_coding = {
|
||||
.bDataBits = 8,
|
||||
};
|
||||
|
||||
RESULT PIOS_USB_CDC_SetLineCoding(void)
|
||||
uint8_t *PIOS_USB_CDC_SetLineCoding(uint16_t Length)
|
||||
{
|
||||
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
|
||||
|
||||
@ -351,7 +351,15 @@ RESULT PIOS_USB_CDC_SetLineCoding(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return USB_SUCCESS;
|
||||
if (Length == 0) {
|
||||
/* Report the number of bytes we're prepared to consume */
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(line_coding);
|
||||
pInformation->Ctrl_Info.Usb_rLength = sizeof(line_coding);
|
||||
return NULL;
|
||||
} else {
|
||||
/* Give out a pointer to the data struct */
|
||||
return ((uint8_t *) &line_coding);
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length)
|
||||
|
@ -293,13 +293,16 @@ static void PIOS_USBHOOK_Status_Out(void)
|
||||
* Output : None.
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
extern uint8_t *PIOS_USB_CDC_SetLineCoding(uint16_t Length);
|
||||
extern const uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length);
|
||||
|
||||
static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
const uint8_t *(*CopyRoutine) (uint16_t);
|
||||
uint8_t *(*CopyOutRoutine) (uint16_t);
|
||||
const uint8_t *(*CopyInRoutine) (uint16_t);
|
||||
|
||||
CopyRoutine = NULL;
|
||||
CopyInRoutine = NULL;
|
||||
CopyOutRoutine = NULL;
|
||||
|
||||
switch (Type_Recipient) {
|
||||
case (STANDARD_REQUEST | INTERFACE_RECIPIENT):
|
||||
@ -313,10 +316,10 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
case GET_DESCRIPTOR:
|
||||
switch (pInformation->USBwValue1) {
|
||||
case USB_DESC_TYPE_REPORT:
|
||||
CopyRoutine = PIOS_USBHOOK_GetReportDescriptor;
|
||||
CopyInRoutine = PIOS_USBHOOK_GetReportDescriptor;
|
||||
break;
|
||||
case USB_DESC_TYPE_HID:
|
||||
CopyRoutine = PIOS_USBHOOK_GetHIDDescriptor;
|
||||
CopyInRoutine = PIOS_USBHOOK_GetHIDDescriptor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -332,7 +335,7 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
#endif
|
||||
switch (RequestNo) {
|
||||
case USB_HID_REQ_GET_PROTOCOL:
|
||||
CopyRoutine = PIOS_USBHOOK_GetProtocolValue;
|
||||
CopyInRoutine = PIOS_USBHOOK_GetProtocolValue;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -340,6 +343,9 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
#if defined(PIOS_INCLUDE_USB_CDC)
|
||||
case 0: /* CDC Call Control Interface */
|
||||
switch (RequestNo) {
|
||||
case USB_CDC_REQ_SET_LINE_CODING:
|
||||
CopyOutRoutine = PIOS_USB_CDC_SetLineCoding;
|
||||
break;
|
||||
case USB_CDC_REQ_GET_LINE_CODING:
|
||||
CopyInRoutine = PIOS_USB_CDC_GetLineCoding;
|
||||
break;
|
||||
@ -359,13 +365,27 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
break;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL) {
|
||||
/* No registered copy routine */
|
||||
if ((CopyInRoutine == NULL) && (CopyOutRoutine == NULL)) {
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
pInformation->Ctrl_Info.CopyDataIn = CopyRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyRoutine) (0);
|
||||
/* Registered copy in AND copy out routine */
|
||||
if ((CopyInRoutine != NULL) && (CopyOutRoutine != NULL)) {
|
||||
/* This should never happen */
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
if (CopyInRoutine != NULL) {
|
||||
pInformation->Ctrl_Info.CopyDataIn = CopyInRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyInRoutine) (0);
|
||||
} else if (CopyOutRoutine != NULL) {
|
||||
pInformation->Ctrl_Info.CopyDataOut = CopyOutRoutine;
|
||||
pInformation->Ctrl_Info.Usb_rOffset = 0;
|
||||
(*CopyOutRoutine) (0);
|
||||
}
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
@ -377,7 +397,6 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
extern RESULT PIOS_USB_CDC_SetControlLineState(void);
|
||||
extern RESULT PIOS_USB_CDC_SetLineCoding(void);
|
||||
|
||||
static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
@ -400,9 +419,6 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
|
||||
#if defined(PIOS_INCLUDE_USB_CDC)
|
||||
case 0: /* CDC Call Control Interface */
|
||||
switch (RequestNo) {
|
||||
case USB_CDC_REQ_SET_LINE_CODING:
|
||||
return PIOS_USB_CDC_SetLineCoding();
|
||||
break;
|
||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
|
||||
return PIOS_USB_CDC_SetControlLineState();
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user