diff --git a/lib/usbd/usbd_ep0.c b/lib/usbd/usbd_ep0.c index 1081f080..1ddfcca9 100644 --- a/lib/usbd/usbd_ep0.c +++ b/lib/usbd/usbd_ep0.c @@ -177,21 +177,21 @@ static int utf8_to_utf16(const uint8_t *utf8, uint16_t *utf16, /* Reference: https://en.wikipedia.org/wiki/UTF-16 */ /* utf-8? */ - if (utf32_ch & 0b10000000) { + if ((utf32_ch & 0x80) != 0) { /* Decoding header */ uint8_t trailing_bytes_utf8; - if ((utf32_ch & 0b11100000) == 0b11000000) { + if ((utf32_ch & 0xe0) == 0xc0) { /* 110xxxxx 10xxxxxx */ trailing_bytes_utf8 = 1; - utf32_ch &= 0b00011111; - } else if ((utf32_ch & 0b11110000) == 0b11100000) { + utf32_ch &= 0x1f; + } else if ((utf32_ch & 0xf0) == 0xe0) { /* 1110xxxx 10xxxxxx 10xxxxxx */ trailing_bytes_utf8 = 2; - utf32_ch &= 0b00001111; - } else if ((utf32_ch & 0b11111000) == 0b11110000) { + utf32_ch &= 0x0f; + } else if ((utf32_ch & 0xf8) == 0xf0) { /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ trailing_bytes_utf8 = 3; - utf32_ch &= 0b00000111; + utf32_ch &= 0x07; } else { /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ @@ -208,7 +208,7 @@ static int utf8_to_utf16(const uint8_t *utf8, uint16_t *utf16, /* trailing bytes payload */ while (trailing_bytes_utf8-- > 0) { - utf32_ch = (utf32_ch << 6) | (utf8[i++] & 0b00111111); + utf32_ch = (utf32_ch << 6) | (utf8[i++] & 0x3f); } /* UTF-8 was restricted by RFC 3629 to end at U+10FFFF, in order @@ -340,13 +340,13 @@ standard_get_descriptor_string(usbd_device *dev, if (!index) { /* Build the list of available langauge strings */ - used = build_available_lang(dev, sd->wData, max_count); + used = build_available_lang(dev, (uint16_t*)sd->wData, max_count); } else { /* Search for the UTF-8 string and convert it to UTF-16 */ const uint8_t *utf8_str; utf8_str = search_utf8_string(dev, arg->setup->wIndex, index - 1); used = (utf8_str == NULL) ? -1 : - utf8_to_utf16(utf8_str, sd->wData, max_count); + utf8_to_utf16(utf8_str, (uint16_t*)sd->wData, max_count); } if (used < 0) { @@ -833,9 +833,7 @@ standard_request(usbd_device *dev, struct usbd_control_arg *arg) void usbd_ep0_setup(usbd_device *dev, const struct usb_setup_data *setup_data) { /* Only handle Standard request. */ - if ((setup_data->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD) { - goto stall; - } + if ((setup_data->bmRequestType & USB_REQ_TYPE_TYPE) == USB_REQ_TYPE_STANDARD) { struct usbd_control_arg arg = { .setup = setup_data, @@ -849,8 +847,9 @@ void usbd_ep0_setup(usbd_device *dev, const struct usb_setup_data *setup_data) arg.complete); return; } + }//if ( ...== USB_REQ_TYPE_STANDARD) - stall: + //stall: usbd_ep0_stall(dev); } diff --git a/lib/usbd/usbd_private.h b/lib/usbd/usbd_private.h index dc6cc74d..ac42c8e5 100644 --- a/lib/usbd/usbd_private.h +++ b/lib/usbd/usbd_private.h @@ -309,7 +309,8 @@ inline void mark_ep_as_free(usbd_device *dev, uint8_t ep_addr, bool yes); * @param[in] ep_addr Endpoint address (including direction) * @return mask */ -inline uint32_t ep_free_mask(uint8_t ep_addr) +static inline +uint32_t ep_free_mask(uint8_t ep_addr) { uint32_t num = ENDPOINT_NUMBER(ep_addr); @@ -408,7 +409,8 @@ inline void usbd_handle_reset(usbd_device *dev) * @param[in] dev USB Device * @param[in] ep_addr Endpoint (including direction) */ -inline bool is_ep_free(usbd_device *dev, uint8_t ep_addr) +static inline +bool is_ep_free(usbd_device *dev, uint8_t ep_addr) { return !!(dev->urbs.ep_free & ep_free_mask(ep_addr)); } @@ -419,7 +421,8 @@ inline bool is_ep_free(usbd_device *dev, uint8_t ep_addr) * @param[in] ep_addr Endpoint address (including direction) * @param[in] yes Yes (if true, mark it as unused) */ -inline void mark_ep_as_free(usbd_device *dev, uint8_t ep_addr, bool yes) +static inline +void mark_ep_as_free(usbd_device *dev, uint8_t ep_addr, bool yes) { uint32_t mask = ep_free_mask(ep_addr); if (yes) { diff --git a/lib/usbd/usbd_transfer.c b/lib/usbd/usbd_transfer.c index fccc0d22..895c6e3d 100644 --- a/lib/usbd/usbd_transfer.c +++ b/lib/usbd/usbd_transfer.c @@ -670,7 +670,7 @@ static void _control_status_callback(usbd_device *dev, return; } - usbd_control_transfer_callback callback = transfer->user_data; + usbd_control_transfer_callback callback = (usbd_control_transfer_callback)transfer->user_data; if (callback != NULL) { callback(dev, NULL); } @@ -720,7 +720,7 @@ static void _control_data_callback(usbd_device *dev, return; } - usbd_control_transfer_callback callback = transfer->user_data; + usbd_control_transfer_callback callback = (usbd_control_transfer_callback)transfer->user_data; usbd_control_transfer_feedback feedback = USBD_CONTROL_TRANSFER_OK; if (callback != NULL) { @@ -897,7 +897,7 @@ void *usbd_urb_get_buffer_pointer(usbd_device *dev, usbd_urb *urb, size_t len) return transfer->buffer; } - return transfer->buffer + transfer->transferred; + return (void*)((uintptr_t)transfer->buffer + transfer->transferred); } /**