mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-30 04:20:26 +00:00
fix -Wcast-qual
This commit is contained in:
parent
7596cb3079
commit
0b249618b0
@ -14,19 +14,7 @@ CFLAGS += \
|
|||||||
-DCONFIG_GPIO_AS_PINRESET
|
-DCONFIG_GPIO_AS_PINRESET
|
||||||
|
|
||||||
# suppress warning caused by vendor mcu driver
|
# suppress warning caused by vendor mcu driver
|
||||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align
|
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual
|
||||||
|
|
||||||
# due to tusb_hal_nrf_power_event
|
|
||||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
|
||||||
ifeq ($(CMDEXE),1)
|
|
||||||
ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1)
|
|
||||||
CFLAGS += -Wno-error=cast-function-type
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
|
||||||
CFLAGS += -Wno-error=cast-function-type
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# All source paths should be relative to the top level.
|
# All source paths should be relative to the top level.
|
||||||
LD_FILE ?= hw/bsp/nrf/boards/$(BOARD)/nrf52840_s140_v6.ld
|
LD_FILE ?= hw/bsp/nrf/boards/$(BOARD)/nrf52840_s140_v6.ld
|
||||||
|
@ -190,7 +190,7 @@ uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc,
|
|||||||
_dfu_ctx.attrs = func_desc->bAttributes;
|
_dfu_ctx.attrs = func_desc->bAttributes;
|
||||||
|
|
||||||
// CFG_TUD_DFU_XFER_BUFSIZE has to be set to the buffer size used in TUD_DFU_DESCRIPTOR
|
// CFG_TUD_DFU_XFER_BUFSIZE has to be set to the buffer size used in TUD_DFU_DESCRIPTOR
|
||||||
uint16_t const transfer_size = tu_le16toh( tu_unaligned_read16((uint8_t*) func_desc + offsetof(tusb_desc_dfu_functional_t, wTransferSize)) );
|
uint16_t const transfer_size = tu_le16toh( tu_unaligned_read16((uint8_t const*) func_desc + offsetof(tusb_desc_dfu_functional_t, wTransferSize)) );
|
||||||
TU_ASSERT(transfer_size <= CFG_TUD_DFU_XFER_BUFSIZE, drv_len);
|
TU_ASSERT(transfer_size <= CFG_TUD_DFU_XFER_BUFSIZE, drv_len);
|
||||||
|
|
||||||
return drv_len;
|
return drv_len;
|
||||||
|
@ -206,8 +206,8 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1
|
|||||||
|
|
||||||
//------------- HID descriptor -------------//
|
//------------- HID descriptor -------------//
|
||||||
p_desc = tu_desc_next(p_desc);
|
p_desc = tu_desc_next(p_desc);
|
||||||
|
TU_ASSERT(HID_DESC_TYPE_HID == tu_desc_type(p_desc), 0);
|
||||||
p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc;
|
p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||||
TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType, 0);
|
|
||||||
|
|
||||||
//------------- Endpoint Descriptor -------------//
|
//------------- Endpoint Descriptor -------------//
|
||||||
p_desc = tu_desc_next(p_desc);
|
p_desc = tu_desc_next(p_desc);
|
||||||
@ -216,10 +216,10 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1
|
|||||||
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
|
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
|
||||||
|
|
||||||
p_hid->protocol_mode = HID_PROTOCOL_REPORT; // Per Specs: default is report mode
|
p_hid->protocol_mode = HID_PROTOCOL_REPORT; // Per Specs: default is report mode
|
||||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||||
|
|
||||||
// Use offsetof to avoid pointer to the odd/misaligned address
|
// Use offsetof to avoid pointer to the odd/misaligned address
|
||||||
memcpy(&p_hid->report_desc_len, (uint8_t*) p_hid->hid_descriptor + offsetof(tusb_hid_descriptor_hid_t, wReportLength), 2);
|
p_hid->report_desc_len = tu_unaligned_read16((uint8_t const*) p_hid->hid_descriptor + offsetof(tusb_hid_descriptor_hid_t, wReportLength));
|
||||||
|
|
||||||
// Prepare for output endpoint
|
// Prepare for output endpoint
|
||||||
if (p_hid->ep_out)
|
if (p_hid->ep_out)
|
||||||
@ -256,13 +256,13 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
|
|||||||
|
|
||||||
if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID)
|
if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID)
|
||||||
{
|
{
|
||||||
TU_VERIFY(p_hid->hid_descriptor != NULL);
|
TU_VERIFY(p_hid->hid_descriptor);
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength));
|
TU_VERIFY(tud_control_xfer(rhport, request, (void*)(uintptr_t) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength));
|
||||||
}
|
}
|
||||||
else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||||
{
|
{
|
||||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb(hid_itf);
|
uint8_t const * desc_report = tud_hid_descriptor_report_cb(hid_itf);
|
||||||
tud_control_xfer(rhport, request, (void*) desc_report, p_hid->report_desc_len);
|
tud_control_xfer(rhport, request, (void*)(uintptr_t) desc_report, p_hid->report_desc_len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
* usbtmc.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 9, 2019
|
|
||||||
* Author: nconrad
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
@ -205,7 +198,7 @@ bool tud_usbtmc_transmit_dev_msg_data(
|
|||||||
{
|
{
|
||||||
TU_ASSERT(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
|
TU_ASSERT(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
|
||||||
TU_ASSERT(termCharRequested);
|
TU_ASSERT(termCharRequested);
|
||||||
TU_ASSERT(((uint8_t*)data)[len-1u] == termChar);
|
TU_ASSERT(((uint8_t const*)data)[len-1u] == termChar);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -228,7 +221,7 @@ bool tud_usbtmc_transmit_dev_msg_data(
|
|||||||
memcpy((uint8_t*)(usbtmc_state.ep_bulk_in_buf) + headerLen, data, dataLen);
|
memcpy((uint8_t*)(usbtmc_state.ep_bulk_in_buf) + headerLen, data, dataLen);
|
||||||
usbtmc_state.transfer_size_remaining = len - dataLen;
|
usbtmc_state.transfer_size_remaining = len - dataLen;
|
||||||
usbtmc_state.transfer_size_sent = dataLen;
|
usbtmc_state.transfer_size_sent = dataLen;
|
||||||
usbtmc_state.devInBuffer = (uint8_t*)data + (dataLen);
|
usbtmc_state.devInBuffer = (uint8_t const*) data + (dataLen);
|
||||||
|
|
||||||
bool stateChanged =
|
bool stateChanged =
|
||||||
atomicChangeState(STATE_TX_REQUESTED, (packetLen >= txBufLen) ? STATE_TX_INITIATED : STATE_TX_SHORTED);
|
atomicChangeState(STATE_TX_REQUESTED, (packetLen >= txBufLen) ? STATE_TX_INITIATED : STATE_TX_SHORTED);
|
||||||
@ -508,13 +501,13 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
|
|||||||
case STATE_ABORTING_BULK_OUT:
|
case STATE_ABORTING_BULK_OUT:
|
||||||
TU_VERIFY(false);
|
TU_VERIFY(false);
|
||||||
return false; // Should be stalled by now, shouldn't have received a packet.
|
return false; // Should be stalled by now, shouldn't have received a packet.
|
||||||
|
|
||||||
case STATE_TX_REQUESTED:
|
case STATE_TX_REQUESTED:
|
||||||
case STATE_TX_INITIATED:
|
case STATE_TX_INITIATED:
|
||||||
case STATE_ABORTING_BULK_IN:
|
case STATE_ABORTING_BULK_IN:
|
||||||
case STATE_ABORTING_BULK_IN_SHORTED:
|
case STATE_ABORTING_BULK_IN_SHORTED:
|
||||||
case STATE_ABORTING_BULK_IN_ABORTED:
|
case STATE_ABORTING_BULK_IN_ABORTED:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
TU_VERIFY(false);
|
TU_VERIFY(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -528,16 +521,16 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
|
|||||||
|
|
||||||
case STATE_TX_INITIATED:
|
case STATE_TX_INITIATED:
|
||||||
if(usbtmc_state.transfer_size_remaining >=sizeof(usbtmc_state.ep_bulk_in_buf))
|
if(usbtmc_state.transfer_size_remaining >=sizeof(usbtmc_state.ep_bulk_in_buf))
|
||||||
{
|
{
|
||||||
// FIXME! This removes const below!
|
// FIXME! This removes const below!
|
||||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in,
|
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in,
|
||||||
(void*)usbtmc_state.devInBuffer,sizeof(usbtmc_state.ep_bulk_in_buf)));
|
(void*)(uintptr_t) usbtmc_state.devInBuffer, sizeof(usbtmc_state.ep_bulk_in_buf)));
|
||||||
usbtmc_state.devInBuffer += sizeof(usbtmc_state.ep_bulk_in_buf);
|
usbtmc_state.devInBuffer += sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||||
usbtmc_state.transfer_size_remaining -= sizeof(usbtmc_state.ep_bulk_in_buf);
|
usbtmc_state.transfer_size_remaining -= sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||||
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.ep_bulk_in_buf);
|
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||||
}
|
}
|
||||||
else // last packet
|
else // last packet
|
||||||
{
|
{
|
||||||
size_t packetLen = usbtmc_state.transfer_size_remaining;
|
size_t packetLen = usbtmc_state.transfer_size_remaining;
|
||||||
memcpy(usbtmc_state.ep_bulk_in_buf, usbtmc_state.devInBuffer, usbtmc_state.transfer_size_remaining);
|
memcpy(usbtmc_state.ep_bulk_in_buf, usbtmc_state.devInBuffer, usbtmc_state.transfer_size_remaining);
|
||||||
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.transfer_size_remaining);
|
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.transfer_size_remaining);
|
||||||
@ -550,15 +543,18 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case STATE_ABORTING_BULK_IN:
|
case STATE_ABORTING_BULK_IN:
|
||||||
// need to send short packet (ZLP?)
|
// need to send short packet (ZLP?)
|
||||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
|
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
|
||||||
usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
|
usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case STATE_ABORTING_BULK_IN_SHORTED:
|
case STATE_ABORTING_BULK_IN_SHORTED:
|
||||||
/* Done. :)*/
|
/* Done. :)*/
|
||||||
usbtmc_state.state = STATE_ABORTING_BULK_IN_ABORTED;
|
usbtmc_state.state = STATE_ABORTING_BULK_IN_ABORTED;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
TU_ASSERT(false);
|
TU_ASSERT(false);
|
||||||
return false;
|
return false;
|
||||||
@ -787,7 +783,7 @@ bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
|
|||||||
{
|
{
|
||||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||||
TU_VERIFY(request->wLength == sizeof(*(usbtmc_state.capabilities)));
|
TU_VERIFY(request->wLength == sizeof(*(usbtmc_state.capabilities)));
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)usbtmc_state.capabilities, sizeof(*usbtmc_state.capabilities)));
|
TU_VERIFY(tud_control_xfer(rhport, request, (void*)(uintptr_t) usbtmc_state.capabilities, sizeof(*usbtmc_state.capabilities)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// USBTMC Optional Requests
|
// USBTMC Optional Requests
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
* usbtmc_device.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 10, 2019
|
|
||||||
* Author: nconrad
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
|
@ -585,8 +585,9 @@ static int handle_video_ctl_std_req(uint8_t rhport, uint8_t stage,
|
|||||||
tusb_desc_vc_itf_t const *vc = _get_desc_vc(&_videod_itf[ctl_idx]);
|
tusb_desc_vc_itf_t const *vc = _get_desc_vc(&_videod_itf[ctl_idx]);
|
||||||
TU_VERIFY(vc, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(vc, VIDEO_ERROR_UNKNOWN);
|
||||||
|
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&vc->std.bAlternateSetting, sizeof(vc->std.bAlternateSetting)),
|
uint8_t alt_num = vc->std.bAlternateSetting;
|
||||||
VIDEO_ERROR_UNKNOWN);
|
|
||||||
|
TU_VERIFY(tud_control_xfer(rhport, request, &alt_num, sizeof(alt_num)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -637,7 +638,7 @@ static int handle_video_ctl_cs_req(uint8_t rhport, uint8_t stage,
|
|||||||
if (stage == CONTROL_STAGE_SETUP)
|
if (stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -657,7 +658,7 @@ static int handle_video_ctl_cs_req(uint8_t rhport, uint8_t stage,
|
|||||||
case VIDEO_REQUEST_GET_INFO:
|
case VIDEO_REQUEST_GET_INFO:
|
||||||
if (stage == CONTROL_STAGE_SETUP)
|
if (stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&_cap_get, sizeof(_cap_get)), VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get, sizeof(_cap_get)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -708,7 +709,9 @@ static int handle_video_stm_std_req(uint8_t rhport, uint8_t stage,
|
|||||||
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
||||||
tusb_desc_vs_itf_t const *vs = _get_desc_vs(self);
|
tusb_desc_vs_itf_t const *vs = _get_desc_vs(self);
|
||||||
TU_VERIFY(vs, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(vs, VIDEO_ERROR_UNKNOWN);
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&vs->std.bAlternateSetting, sizeof(vs->std.bAlternateSetting)), VIDEO_ERROR_UNKNOWN);
|
uint8_t alt_num = vs->std.bAlternateSetting;
|
||||||
|
|
||||||
|
TU_VERIFY(tud_control_xfer(rhport, request, &alt_num, sizeof(alt_num)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -748,7 +751,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|||||||
case VIDEO_REQUEST_GET_INFO:
|
case VIDEO_REQUEST_GET_INFO:
|
||||||
if (stage == CONTROL_STAGE_SETUP)
|
if (stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&_cap_get, sizeof(_cap_get)), VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get, sizeof(_cap_get)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -808,7 +811,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|||||||
if (stage == CONTROL_STAGE_SETUP)
|
if (stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
@ -842,7 +845,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|||||||
if (stage == CONTROL_STAGE_SETUP)
|
if (stage == CONTROL_STAGE_SETUP)
|
||||||
{
|
{
|
||||||
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
||||||
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
return VIDEO_ERROR_NONE;
|
return VIDEO_ERROR_NONE;
|
||||||
|
|
||||||
|
@ -161,7 +161,6 @@ static inline uint8_t tu_log2(uint32_t value)
|
|||||||
#if TUP_ARCH_STRICT_ALIGN
|
#if TUP_ARCH_STRICT_ALIGN
|
||||||
|
|
||||||
// Rely on compiler to generate correct code for unaligned access
|
// Rely on compiler to generate correct code for unaligned access
|
||||||
|
|
||||||
typedef struct { uint16_t val; } TU_ATTR_PACKED tu_unaligned_uint16_t;
|
typedef struct { uint16_t val; } TU_ATTR_PACKED tu_unaligned_uint16_t;
|
||||||
typedef struct { uint32_t val; } TU_ATTR_PACKED tu_unaligned_uint32_t;
|
typedef struct { uint32_t val; } TU_ATTR_PACKED tu_unaligned_uint32_t;
|
||||||
|
|
||||||
@ -227,8 +226,8 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16(void* mem, uint16_
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// MCU that could access unaligned memory natively
|
// MCU that could access unaligned memory natively
|
||||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32 (const void* mem ) { return *((uint32_t*) mem); }
|
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32 (const void* mem) { return *((uint32_t const *) mem); }
|
||||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16 (const void* mem ) { return *((uint16_t*) mem); }
|
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16 (const void* mem) { return *((uint16_t const *) mem); }
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write32 (void* mem, uint32_t value ) { *((uint32_t*) mem) = value; }
|
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write32 (void* mem, uint32_t value ) { *((uint32_t*) mem) = value; }
|
||||||
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, uint16_t value ) { *((uint16_t*) mem) = value; }
|
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, uint16_t value ) { *((uint16_t*) mem) = value; }
|
||||||
|
@ -102,7 +102,7 @@ static inline uint16_t _ff_mod(uint16_t idx, uint16_t depth)
|
|||||||
// TODO generalize with configurable 1 byte or 4 byte each read
|
// TODO generalize with configurable 1 byte or 4 byte each read
|
||||||
static void _ff_push_const_addr(uint8_t * ff_buf, const void * app_buf, uint16_t len)
|
static void _ff_push_const_addr(uint8_t * ff_buf, const void * app_buf, uint16_t len)
|
||||||
{
|
{
|
||||||
volatile uint32_t * rx_fifo = (volatile uint32_t *) app_buf;
|
volatile const uint32_t * rx_fifo = (volatile const uint32_t *) app_buf;
|
||||||
|
|
||||||
// Reading full available 32 bit words from const app address
|
// Reading full available 32 bit words from const app address
|
||||||
uint16_t full_words = len >> 2;
|
uint16_t full_words = len >> 2;
|
||||||
@ -201,7 +201,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
|
|||||||
ff_buf += nLin_4n_bytes;
|
ff_buf += nLin_4n_bytes;
|
||||||
|
|
||||||
// There could be odd 1-3 bytes before the wrap-around boundary
|
// There could be odd 1-3 bytes before the wrap-around boundary
|
||||||
volatile uint32_t * rx_fifo = (volatile uint32_t *) app_buf;
|
volatile const uint32_t * rx_fifo = (volatile const uint32_t *) app_buf;
|
||||||
uint8_t rem = nLin_bytes & 0x03;
|
uint8_t rem = nLin_bytes & 0x03;
|
||||||
if (rem > 0)
|
if (rem > 0)
|
||||||
{
|
{
|
||||||
|
@ -990,21 +990,23 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
|||||||
{
|
{
|
||||||
TU_LOG2(" Device\r\n");
|
TU_LOG2(" Device\r\n");
|
||||||
|
|
||||||
uint16_t len = sizeof(tusb_desc_device_t);
|
void* desc_device = (void*) (uintptr_t) tud_descriptor_device_cb();
|
||||||
|
|
||||||
// Only send up to EP0 Packet Size if not addressed and host requested more data
|
// Only response with exactly 1 Packet if: not addressed and host requested more data than device descriptor has.
|
||||||
// that device descriptor has.
|
|
||||||
// This only happens with the very first get device descriptor and EP0 size = 8 or 16.
|
// This only happens with the very first get device descriptor and EP0 size = 8 or 16.
|
||||||
if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed &&
|
if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed &&
|
||||||
((tusb_control_request_t*) p_request)->wLength > sizeof(tusb_desc_device_t))
|
((tusb_control_request_t const*) p_request)->wLength > sizeof(tusb_desc_device_t))
|
||||||
{
|
{
|
||||||
len = CFG_TUD_ENDPOINT0_SIZE;
|
|
||||||
|
|
||||||
// Hack here: we modify the request length to prevent usbd_control response with zlp
|
// Hack here: we modify the request length to prevent usbd_control response with zlp
|
||||||
((tusb_control_request_t*) p_request)->wLength = CFG_TUD_ENDPOINT0_SIZE;
|
// since we are responding with 1 packet & less data than wLength.
|
||||||
}
|
tusb_control_request_t mod_request = *p_request;
|
||||||
|
mod_request.wLength = CFG_TUD_ENDPOINT0_SIZE;
|
||||||
|
|
||||||
return tud_control_xfer(rhport, p_request, (void*) tud_descriptor_device_cb(), len);
|
tud_control_xfer(rhport, &mod_request, desc_device, CFG_TUD_ENDPOINT0_SIZE);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1015,10 +1017,11 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
|||||||
// requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
|
// requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
|
||||||
if (!tud_descriptor_bos_cb) return false;
|
if (!tud_descriptor_bos_cb) return false;
|
||||||
|
|
||||||
tusb_desc_bos_t const* desc_bos = (tusb_desc_bos_t const*) tud_descriptor_bos_cb();
|
uintptr_t desc_bos = (uintptr_t) tud_descriptor_bos_cb();
|
||||||
|
TU_ASSERT(desc_bos);
|
||||||
|
|
||||||
// Use offsetof to avoid pointer to the odd/misaligned address
|
// Use offsetof to avoid pointer to the odd/misaligned address
|
||||||
uint16_t const total_len = tu_le16toh( tu_unaligned_read16((uint8_t*) desc_bos + offsetof(tusb_desc_bos_t, wTotalLength)) );
|
uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_bos + offsetof(tusb_desc_bos_t, wTotalLength))) );
|
||||||
|
|
||||||
return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
|
return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
|
||||||
}
|
}
|
||||||
@ -1027,24 +1030,24 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
|||||||
case TUSB_DESC_CONFIGURATION:
|
case TUSB_DESC_CONFIGURATION:
|
||||||
case TUSB_DESC_OTHER_SPEED_CONFIG:
|
case TUSB_DESC_OTHER_SPEED_CONFIG:
|
||||||
{
|
{
|
||||||
tusb_desc_configuration_t const* desc_config;
|
uintptr_t desc_config;
|
||||||
|
|
||||||
if ( desc_type == TUSB_DESC_CONFIGURATION )
|
if ( desc_type == TUSB_DESC_CONFIGURATION )
|
||||||
{
|
{
|
||||||
TU_LOG2(" Configuration[%u]\r\n", desc_index);
|
TU_LOG2(" Configuration[%u]\r\n", desc_index);
|
||||||
desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
|
desc_config = (uintptr_t) tud_descriptor_configuration_cb(desc_index);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
// Host only request this after getting Device Qualifier descriptor
|
// Host only request this after getting Device Qualifier descriptor
|
||||||
TU_LOG2(" Other Speed Configuration\r\n");
|
TU_LOG2(" Other Speed Configuration\r\n");
|
||||||
TU_VERIFY( tud_descriptor_other_speed_configuration_cb );
|
TU_VERIFY( tud_descriptor_other_speed_configuration_cb );
|
||||||
desc_config = (tusb_desc_configuration_t const*) tud_descriptor_other_speed_configuration_cb(desc_index);
|
desc_config = (uintptr_t) tud_descriptor_other_speed_configuration_cb(desc_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ASSERT(desc_config);
|
TU_ASSERT(desc_config);
|
||||||
|
|
||||||
// Use offsetof to avoid pointer to the odd/misaligned address
|
// Use offsetof to avoid pointer to the odd/misaligned address
|
||||||
uint16_t const total_len = tu_le16toh( tu_unaligned_read16((uint8_t*) desc_config + offsetof(tusb_desc_configuration_t, wTotalLength)) );
|
uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_config + offsetof(tusb_desc_configuration_t, wTotalLength))) );
|
||||||
|
|
||||||
return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
|
return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
|
||||||
}
|
}
|
||||||
@ -1055,11 +1058,11 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
|||||||
TU_LOG2(" String[%u]\r\n", desc_index);
|
TU_LOG2(" String[%u]\r\n", desc_index);
|
||||||
|
|
||||||
// String Descriptor always uses the desc set from user
|
// String Descriptor always uses the desc set from user
|
||||||
uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index, p_request->wIndex);
|
uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index, tu_le16toh(p_request->wIndex));
|
||||||
TU_VERIFY(desc_str);
|
TU_VERIFY(desc_str);
|
||||||
|
|
||||||
// first byte of descriptor is its size
|
// first byte of descriptor is its size
|
||||||
return tud_control_xfer(rhport, p_request, (void*) desc_str, desc_str[0]);
|
return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_str, tu_desc_len(desc_str));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1073,7 +1076,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
|||||||
TU_VERIFY(desc_qualifier);
|
TU_VERIFY(desc_qualifier);
|
||||||
|
|
||||||
// first byte of descriptor is its size
|
// first byte of descriptor is its size
|
||||||
return tud_control_xfer(rhport, p_request, (void*) desc_qualifier, desc_qualifier[0]);
|
return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_qualifier, tu_desc_len(desc_qualifier));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ static void edpt_dma_start(volatile uint32_t* reg_startep)
|
|||||||
if (is_in_isr())
|
if (is_in_isr())
|
||||||
{
|
{
|
||||||
// Called within ISR, use usbd task to defer later
|
// Called within ISR, use usbd task to defer later
|
||||||
usbd_defer_func( (osal_task_func_t) edpt_dma_start, (void*) reg_startep, true );
|
usbd_defer_func((osal_task_func_t) edpt_dma_start, (void*) (uintptr_t) reg_startep, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -773,7 +773,7 @@ void dcd_int_handler(uint8_t rhport)
|
|||||||
if ( _dcd.dma_pending )
|
if ( _dcd.dma_pending )
|
||||||
{
|
{
|
||||||
// use usbd task to defer later
|
// use usbd task to defer later
|
||||||
usbd_defer_func( (osal_task_func_t) start_ep0_task, (void*) &NRF_USBD->TASKS_EP0RCVOUT, true );
|
usbd_defer_func((osal_task_func_t) start_ep0_task, (void*) (uintptr_t) &NRF_USBD->TASKS_EP0RCVOUT, true);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
|
start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user