-
Notifications
You must be signed in to change notification settings - Fork 8
!warnings:ARM compiler - fixed code vs inconsisting with standart C, … #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/insane-adding-machines/unicore-mx/blob/master/include/unicore-mx/usb/usbstd.h#L257 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that is not: sd->wData is of type "packed" uint16_t*, since it got from packed struct. |
||
} | ||
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code style: 👎 from me. |
||
|
||
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); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C standard says: void * will automatically cast to any other type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But with some stricts - you can assign any pointer TO void* , but if you want assign some* to typed* - need casts to destination type |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isnt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. void* have no information about what entry size is. So yes - compiler is right, when error on such a trick. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You point is valid. |
||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was a specific reason (readability imo) to write these specific constant in binary notation.
but hexadecimal notation wont do any improvement either.Update: (0b binary notation) dont seems to be in C specs, your point is valid.