Browse Source

update code to libopencm3 API change

spark_strober
King Kévin 4 years ago
parent
commit
0ac0af5d52
  1. 12
      lib/usb_cdcacm.c
  2. 12
      lib/usb_dfu.c

12
lib/usb_cdcacm.c

@ -285,10 +285,10 @@ static void usb_dfu_detach(usbd_device *usbd_dev, struct usb_setup_data *req) @@ -285,10 +285,10 @@ static void usb_dfu_detach(usbd_device *usbd_dev, struct usb_setup_data *req)
* @param[in] buf control request data
* @param[in] len control request data length
* @param[in] complete function to run after request completed
* @return 0 if succeeded, error else
* @return USBD_REQ_HANDLED if handled correctly, USBD_REQ_NOTSUPP else
* @note resets device when configured with 5 bits
*/
static int usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
static enum usbd_request_return_codes usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{
if (usb_dfu_interface.bInterfaceNumber==req->wIndex) { // check if request is for DFU
switch (req->bRequest) {
@ -305,7 +305,7 @@ static int usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_da @@ -305,7 +305,7 @@ static int usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_da
*len = 6; // set length of buffer to return
break;
default: // other requests are not supported
return 0;
return USBD_REQ_NOTSUPP;
}
} else if (usb_cdcacm_communication_interface.bInterfaceNumber==req->wIndex) { // check if request is for CDC
switch (req->bRequest) {
@ -332,17 +332,17 @@ static int usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_da @@ -332,17 +332,17 @@ static int usb_cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_da
case USB_CDC_REQ_SET_LINE_CODING:
// ignore if length is wrong
if (*len < sizeof(struct usb_cdc_line_coding)) {
return 0;
return USBD_REQ_NOTSUPP;
}
// line coding is ignored
// to get the line coding
// struct usb_cdc_line_coding *coding = (struct usb_cdc_line_coding *)*buf;
break;
default:
return 0;
return USBD_REQ_NOTSUPP;
}
}
return 1;
return USBD_REQ_HANDLED;
}
/** USB CDC ACM communication callback

12
lib/usb_dfu.c

@ -187,21 +187,21 @@ static void usb_dfu_reset(usbd_device *usbd_dev, struct usb_setup_data *req) @@ -187,21 +187,21 @@ static void usb_dfu_reset(usbd_device *usbd_dev, struct usb_setup_data *req)
* @param[in] buf control request data
* @param[in] len control request data length
* @param[in] complete not used
* @return 0 if succeeded, error else
* @return USBD_REQ_HANDLED if handled correctly, USBD_REQ_NOTSUPP else
* @note resets device when configured with 5 bits
*/
static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
static enum usbd_request_return_codes usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{
(void)complete;
(void)usbd_dev; // device is not used
// DFU only requires handling class requests
if ((req->bmRequestType & USB_REQ_TYPE_TYPE)!=USB_REQ_TYPE_CLASS) {
return 0;
return USBD_REQ_NOTSUPP;
}
led_off(); // indicate we are processing request
int to_return = 1; // value to return
int to_return = USBD_REQ_HANDLED; // value to return
switch (req->bRequest) {
case DFU_DETACH: // USB detach requested
*complete = usb_dfu_reset; // reset after reply
@ -243,7 +243,7 @@ static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data @@ -243,7 +243,7 @@ static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data
}
break;
case DFU_UPLOAD: // upload firmware from flash
to_return = 0; // upload no supported
to_return = USBD_REQ_NOTSUPP; // upload no supported
break;
case DFU_GETSTATUS: // get status
(*buf)[0] = usb_dfu_status; // set status
@ -276,7 +276,7 @@ static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data @@ -276,7 +276,7 @@ static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data
flash_pointer = (uint32_t)&__application_beginning; // reset download location
break;
default:
to_return = 0;
to_return = USBD_REQ_NOTSUPP;
}
led_on(); // indicate we finished processing

Loading…
Cancel
Save