|
|
|
@ -114,6 +114,8 @@ typedef struct TU_ATTR_PACKED {
|
|
|
|
|
uint32_t max_payload_transfer_size;
|
|
|
|
|
uint8_t error_code;/* error code */
|
|
|
|
|
uint8_t state; /* 0:probing 1:committed 2:streaming */
|
|
|
|
|
|
|
|
|
|
video_probe_and_commit_control_t probe_commit_payload; /* Probe and Commit control */
|
|
|
|
|
/*------------- From this point, data is not cleared by bus reset -------------*/
|
|
|
|
|
CFG_TUSB_MEM_ALIGN uint8_t ep_buf[CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE]; /* EP transfer buffer for streaming */
|
|
|
|
|
} videod_streaming_interface_t;
|
|
|
|
@ -143,13 +145,65 @@ CFG_TUD_MEM_SECTION tu_static videod_streaming_interface_t _videod_streaming_itf
|
|
|
|
|
tu_static uint8_t const _cap_get = 0x1u; /* support for GET */
|
|
|
|
|
tu_static uint8_t const _cap_get_set = 0x3u; /* support for GET and SET */
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
// Debug
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
#if CFG_TUSB_DEBUG >= CFG_TUD_VIDEO_LOG_LEVEL
|
|
|
|
|
|
|
|
|
|
static tu_lookup_entry_t const tu_lookup_video_request[] = {
|
|
|
|
|
{.key = VIDEO_REQUEST_UNDEFINED, .data = "Undefined"},
|
|
|
|
|
{.key = VIDEO_REQUEST_SET_CUR, .data = "SetCur"},
|
|
|
|
|
{.key = VIDEO_REQUEST_SET_CUR_ALL, .data = "SetCurAll"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_CUR, .data = "GetCur"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_MIN, .data = "GetMin"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_MAX, .data = "GetMax"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_RES, .data = "GetRes"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_LEN, .data = "GetLen"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_INFO, .data = "GetInfo"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_DEF, .data = "GetDef"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_CUR_ALL, .data = "GetCurAll"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_MIN_ALL, .data = "GetMinAll"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_MAX_ALL, .data = "GetMaxAll"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_RES_ALL, .data = "GetResAll"},
|
|
|
|
|
{.key = VIDEO_REQUEST_GET_DEF_ALL, .data = "GetDefAll"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static tu_lookup_table_t const tu_table_video_request = {
|
|
|
|
|
.count = TU_ARRAY_SIZE(tu_lookup_video_request),
|
|
|
|
|
.items = tu_lookup_video_request
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static char const* const tu_str_video_vc_control_selector[] = {
|
|
|
|
|
"Undefined",
|
|
|
|
|
"Video Power Mode",
|
|
|
|
|
"Request Error Code",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static char const* const tu_str_video_vs_control_selector[] = {
|
|
|
|
|
"Undefined",
|
|
|
|
|
"Probe",
|
|
|
|
|
"Commit",
|
|
|
|
|
"Still Probe",
|
|
|
|
|
"Still Commit",
|
|
|
|
|
"Still Image Trigger",
|
|
|
|
|
"Stream Error Code",
|
|
|
|
|
"Generate Key Frame",
|
|
|
|
|
"Update Frame Segment",
|
|
|
|
|
"Sync Delay",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
//
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
|
|
|
|
|
/** Get interface number from the interface descriptor
|
|
|
|
|
*
|
|
|
|
|
* @param[in] desc interface descriptor
|
|
|
|
|
*
|
|
|
|
|
* @return bInterfaceNumber */
|
|
|
|
|
static inline uint8_t _desc_itfnum(void const *desc)
|
|
|
|
|
{
|
|
|
|
|
static inline uint8_t _desc_itfnum(void const *desc) {
|
|
|
|
|
return ((uint8_t const*)desc)[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -158,8 +212,7 @@ static inline uint8_t _desc_itfnum(void const *desc)
|
|
|
|
|
* @param[in] desc endpoint descriptor
|
|
|
|
|
*
|
|
|
|
|
* @return bEndpointAddress */
|
|
|
|
|
static inline uint8_t _desc_ep_addr(void const *desc)
|
|
|
|
|
{
|
|
|
|
|
static inline uint8_t _desc_ep_addr(void const *desc) {
|
|
|
|
|
return ((uint8_t const*)desc)[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -169,8 +222,7 @@ static inline uint8_t _desc_ep_addr(void const *desc)
|
|
|
|
|
* @param[in] stm_idx index number of streaming interface
|
|
|
|
|
*
|
|
|
|
|
* @return instance */
|
|
|
|
|
static videod_streaming_interface_t* _get_instance_streaming(uint_fast8_t ctl_idx, uint_fast8_t stm_idx)
|
|
|
|
|
{
|
|
|
|
|
static videod_streaming_interface_t* _get_instance_streaming(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
|
|
|
|
|
videod_interface_t *ctl = &_videod_itf[ctl_idx];
|
|
|
|
|
if (!ctl->beg) return NULL;
|
|
|
|
|
videod_streaming_interface_t *stm = &_videod_streaming_itf[ctl->stm[stm_idx]];
|
|
|
|
@ -178,13 +230,11 @@ static videod_streaming_interface_t* _get_instance_streaming(uint_fast8_t ctl_id
|
|
|
|
|
return stm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static tusb_desc_vc_itf_t const* _get_desc_vc(videod_interface_t const *self)
|
|
|
|
|
{
|
|
|
|
|
static tusb_desc_vc_itf_t const* _get_desc_vc(videod_interface_t const *self) {
|
|
|
|
|
return (tusb_desc_vc_itf_t const *)(self->beg + self->cur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static tusb_desc_vs_itf_t const* _get_desc_vs(videod_streaming_interface_t const *self)
|
|
|
|
|
{
|
|
|
|
|
static tusb_desc_vs_itf_t const* _get_desc_vs(videod_streaming_interface_t const *self) {
|
|
|
|
|
if (!self->desc.cur) return NULL;
|
|
|
|
|
uint8_t const *desc = _videod_itf[self->index_vc].beg;
|
|
|
|
|
return (tusb_desc_vs_itf_t const*)(desc + self->desc.cur);
|
|
|
|
@ -198,8 +248,7 @@ static tusb_desc_vs_itf_t const* _get_desc_vs(videod_streaming_interface_t const
|
|
|
|
|
*
|
|
|
|
|
* @return The pointer for interface descriptor.
|
|
|
|
|
* @retval end did not found interface descriptor */
|
|
|
|
|
static void const* _find_desc(void const *beg, void const *end, uint_fast8_t desc_type)
|
|
|
|
|
{
|
|
|
|
|
static void const* _find_desc(void const *beg, void const *end, uint_fast8_t desc_type) {
|
|
|
|
|
void const *cur = beg;
|
|
|
|
|
while ((cur < end) && (desc_type != tu_desc_type(cur))) {
|
|
|
|
|
cur = tu_desc_next(cur);
|
|
|
|
@ -238,8 +287,7 @@ static void const* _find_desc_2_type(void const *beg, void const *end, uint_fast
|
|
|
|
|
static void const* _find_desc_3(void const *beg, void const *end,
|
|
|
|
|
uint_fast8_t desc_type,
|
|
|
|
|
uint_fast8_t element_0,
|
|
|
|
|
uint_fast8_t element_1)
|
|
|
|
|
{
|
|
|
|
|
uint_fast8_t element_1) {
|
|
|
|
|
for (void const *cur = beg; cur < end; cur = _find_desc(cur, end, desc_type)) {
|
|
|
|
|
uint8_t const *p = (uint8_t const *)cur;
|
|
|
|
|
if ((p[2] == element_0) && (p[3] == element_1)) {
|
|
|
|
@ -261,8 +309,7 @@ static void const* _find_desc_3(void const *beg, void const *end,
|
|
|
|
|
*
|
|
|
|
|
* @return The pointer for interface descriptor.
|
|
|
|
|
* @retval end did not found interface descriptor */
|
|
|
|
|
static void const* _next_desc_itf(void const *beg, void const *end)
|
|
|
|
|
{
|
|
|
|
|
static void const* _next_desc_itf(void const *beg, void const *end) {
|
|
|
|
|
void const *cur = beg;
|
|
|
|
|
uint_fast8_t itfnum = ((tusb_desc_interface_t const*)cur)->bInterfaceNumber;
|
|
|
|
|
while ((cur < end) &&
|
|
|
|
@ -413,8 +460,10 @@ static bool _update_streaming_parameters(videod_streaming_interface_t const *stm
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED:
|
|
|
|
|
param->wCompQuality = 1; /* 1 to 10000 */
|
|
|
|
|
break;
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -435,9 +484,11 @@ static bool _update_streaming_parameters(videod_streaming_interface_t const *stm
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED:
|
|
|
|
|
frame_size = (uint_fast32_t)frm->wWidth * frm->wHeight * fmt->uncompressed.bBitsPerPixel / 8;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
frame_size = (uint_fast32_t)frm->wWidth * frm->wHeight * 16 / 8; /* YUV422 */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
param->dwMaxVideoFrameSize = frame_size;
|
|
|
|
@ -478,10 +529,12 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
|
|
|
|
|
if (_get_desc_vs(stm))
|
|
|
|
|
param->bFormatIndex = _get_desc_vs(stm)->stm.bNumFormats;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_MIN:
|
|
|
|
|
case VIDEO_REQUEST_GET_DEF:
|
|
|
|
|
param->bFormatIndex = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
/* Set the parameters determined by the format */
|
|
|
|
@ -510,18 +563,22 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
|
|
|
|
|
case VIDEO_REQUEST_GET_MAX:
|
|
|
|
|
frmnum = fmt->bNumFrameDescriptors;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_MIN:
|
|
|
|
|
frmnum = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_DEF:
|
|
|
|
|
switch (fmt->bDescriptorSubType) {
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED:
|
|
|
|
|
frmnum = fmt->uncompressed.bDefaultFrameIndex;
|
|
|
|
|
break;
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
frmnum = fmt->mjpeg.bDefaultFrameIndex;
|
|
|
|
|
break;
|
|
|
|
|
default: return false;
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED:
|
|
|
|
|
frmnum = fmt->uncompressed.bDefaultFrameIndex;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
frmnum = fmt->mjpeg.bDefaultFrameIndex;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: return false;
|
|
|
|
@ -534,9 +591,11 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED:
|
|
|
|
|
frame_size = (uint_fast32_t)frm->wWidth * frm->wHeight * fmt->uncompressed.bBitsPerPixel / 8;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VIDEO_CS_ITF_VS_FORMAT_MJPEG:
|
|
|
|
|
frame_size = (uint_fast32_t)frm->wWidth * frm->wHeight * 16 / 8; /* YUV422 */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
param->dwMaxVideoFrameSize = frame_size;
|
|
|
|
@ -552,42 +611,43 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
|
|
|
|
|
|
|
|
|
|
uint_fast32_t interval, interval_ms;
|
|
|
|
|
switch (request) {
|
|
|
|
|
case VIDEO_REQUEST_GET_MAX:
|
|
|
|
|
{
|
|
|
|
|
uint_fast32_t min_interval, max_interval;
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
max_interval = num_intervals ? frm->uncompressed.dwFrameInterval[num_intervals - 1]: frm->uncompressed.dwFrameInterval[1];
|
|
|
|
|
min_interval = frm->uncompressed.dwFrameInterval[0];
|
|
|
|
|
interval = max_interval;
|
|
|
|
|
interval_ms = min_interval / 10000;
|
|
|
|
|
}
|
|
|
|
|
case VIDEO_REQUEST_GET_MAX: {
|
|
|
|
|
uint_fast32_t min_interval, max_interval;
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
max_interval = num_intervals ? frm->uncompressed.dwFrameInterval[num_intervals - 1]: frm->uncompressed.dwFrameInterval[1];
|
|
|
|
|
min_interval = frm->uncompressed.dwFrameInterval[0];
|
|
|
|
|
interval = max_interval;
|
|
|
|
|
interval_ms = min_interval / 10000;
|
|
|
|
|
break;
|
|
|
|
|
case VIDEO_REQUEST_GET_MIN:
|
|
|
|
|
{
|
|
|
|
|
uint_fast32_t min_interval, max_interval;
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
max_interval = num_intervals ? frm->uncompressed.dwFrameInterval[num_intervals - 1]: frm->uncompressed.dwFrameInterval[1];
|
|
|
|
|
min_interval = frm->uncompressed.dwFrameInterval[0];
|
|
|
|
|
interval = min_interval;
|
|
|
|
|
interval_ms = max_interval / 10000;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_MIN: {
|
|
|
|
|
uint_fast32_t min_interval, max_interval;
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
max_interval = num_intervals ? frm->uncompressed.dwFrameInterval[num_intervals - 1]: frm->uncompressed.dwFrameInterval[1];
|
|
|
|
|
min_interval = frm->uncompressed.dwFrameInterval[0];
|
|
|
|
|
interval = min_interval;
|
|
|
|
|
interval_ms = max_interval / 10000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_DEF:
|
|
|
|
|
interval = frm->uncompressed.dwDefaultFrameInterval;
|
|
|
|
|
interval_ms = interval / 10000;
|
|
|
|
|
break;
|
|
|
|
|
case VIDEO_REQUEST_GET_RES:
|
|
|
|
|
{
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
if (num_intervals) {
|
|
|
|
|
interval = 0;
|
|
|
|
|
interval_ms = 0;
|
|
|
|
|
} else {
|
|
|
|
|
interval = frm->uncompressed.dwFrameInterval[2];
|
|
|
|
|
interval_ms = interval / 10000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_RES: {
|
|
|
|
|
uint_fast8_t num_intervals = frm->uncompressed.bFrameIntervalType;
|
|
|
|
|
if (num_intervals) {
|
|
|
|
|
interval = 0;
|
|
|
|
|
interval_ms = 0;
|
|
|
|
|
} else {
|
|
|
|
|
interval = frm->uncompressed.dwFrameInterval[2];
|
|
|
|
|
interval_ms = interval / 10000;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
param->dwFrameInterval = interval;
|
|
|
|
@ -676,13 +736,11 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool _init_vs_configuration(videod_streaming_interface_t *stm)
|
|
|
|
|
{
|
|
|
|
|
static bool _init_vs_configuration(videod_streaming_interface_t *stm) {
|
|
|
|
|
/* initialize streaming settings */
|
|
|
|
|
stm->state = VS_STATE_PROBING;
|
|
|
|
|
stm->max_payload_transfer_size = 0;
|
|
|
|
|
video_probe_and_commit_control_t *param =
|
|
|
|
|
(video_probe_and_commit_control_t *)&stm->ep_buf;
|
|
|
|
|
video_probe_and_commit_control_t *param = &stm->probe_commit_payload;
|
|
|
|
|
tu_memclr(param, sizeof(*param));
|
|
|
|
|
return _update_streaming_parameters(stm, param);
|
|
|
|
|
}
|
|
|
|
@ -759,6 +817,7 @@ static uint_fast16_t _prepare_in_payload(videod_streaming_interface_t *stm)
|
|
|
|
|
if (hdr_len + remaining < pkt_len) {
|
|
|
|
|
pkt_len = hdr_len + remaining;
|
|
|
|
|
}
|
|
|
|
|
TU_ASSERT(pkt_len >= hdr_len);
|
|
|
|
|
uint_fast16_t data_len = pkt_len - hdr_len;
|
|
|
|
|
memcpy(&stm->ep_buf[hdr_len], stm->buffer + stm->offset, data_len);
|
|
|
|
|
stm->offset += data_len;
|
|
|
|
@ -775,6 +834,7 @@ static int handle_video_ctl_std_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
tusb_control_request_t const *request,
|
|
|
|
|
uint_fast8_t ctl_idx)
|
|
|
|
|
{
|
|
|
|
|
TU_LOG_DRV("\r\n");
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case TUSB_REQ_GET_INTERFACE:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
@ -812,7 +872,10 @@ static int handle_video_ctl_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
videod_interface_t *self = &_videod_itf[ctl_idx];
|
|
|
|
|
|
|
|
|
|
/* 4.2.1 Interface Control Request */
|
|
|
|
|
switch (TU_U16_HIGH(request->wValue)) {
|
|
|
|
|
uint8_t const ctrl_sel = TU_U16_HIGH(request->wValue);
|
|
|
|
|
TU_LOG_DRV("%s_Control(%s)\r\n", tu_str_video_vc_control_selector[ctrl_sel], tu_lookup_find(&tu_table_video_request, request->bRequest));
|
|
|
|
|
|
|
|
|
|
switch (ctrl_sel) {
|
|
|
|
|
case VIDEO_VC_CTL_VIDEO_POWER_MODE:
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case VIDEO_REQUEST_SET_CUR:
|
|
|
|
@ -876,19 +939,19 @@ static int handle_video_ctl_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
tusb_control_request_t const *request,
|
|
|
|
|
uint_fast8_t ctl_idx)
|
|
|
|
|
{
|
|
|
|
|
uint_fast8_t entity_id;
|
|
|
|
|
switch (request->bmRequestType_bit.type) {
|
|
|
|
|
case TUSB_REQ_TYPE_STANDARD:
|
|
|
|
|
return handle_video_ctl_std_req(rhport, stage, request, ctl_idx);
|
|
|
|
|
|
|
|
|
|
case TUSB_REQ_TYPE_CLASS:
|
|
|
|
|
entity_id = TU_U16_HIGH(request->wIndex);
|
|
|
|
|
case TUSB_REQ_TYPE_CLASS: {
|
|
|
|
|
uint_fast8_t entity_id = TU_U16_HIGH(request->wIndex);
|
|
|
|
|
if (!entity_id) {
|
|
|
|
|
return handle_video_ctl_cs_req(rhport, stage, request, ctl_idx);
|
|
|
|
|
} else {
|
|
|
|
|
TU_VERIFY(_find_desc_entity(_get_desc_vc(&_videod_itf[ctl_idx]), entity_id), VIDEO_ERROR_INVALID_REQUEST);
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return VIDEO_ERROR_INVALID_REQUEST;
|
|
|
|
@ -899,6 +962,7 @@ static int handle_video_stm_std_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
tusb_control_request_t const *request,
|
|
|
|
|
uint_fast8_t stm_idx)
|
|
|
|
|
{
|
|
|
|
|
TU_LOG_DRV("\r\n");
|
|
|
|
|
videod_streaming_interface_t *self = &_videod_streaming_itf[stm_idx];
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case TUSB_REQ_GET_INTERFACE:
|
|
|
|
@ -914,8 +978,7 @@ static int handle_video_stm_std_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case TUSB_REQ_SET_INTERFACE:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(_open_vs_itf(rhport, self, request->wValue), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
tud_control_status(rhport, request);
|
|
|
|
|
}
|
|
|
|
@ -929,26 +992,26 @@ static int handle_video_stm_std_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
|
|
|
|
|
static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
tusb_control_request_t const *request,
|
|
|
|
|
uint_fast8_t stm_idx)
|
|
|
|
|
{
|
|
|
|
|
uint_fast8_t stm_idx) {
|
|
|
|
|
(void)rhport;
|
|
|
|
|
videod_streaming_interface_t *self = &_videod_streaming_itf[stm_idx];
|
|
|
|
|
|
|
|
|
|
uint8_t const ctrl_sel = TU_U16_HIGH(request->wValue);
|
|
|
|
|
TU_LOG_DRV("%s_Control(%s)\r\n", tu_str_video_vs_control_selector[ctrl_sel], tu_lookup_find(&tu_table_video_request, request->bRequest));
|
|
|
|
|
|
|
|
|
|
/* 4.2.1 Interface Control Request */
|
|
|
|
|
switch (TU_U16_HIGH(request->wValue)) {
|
|
|
|
|
switch (ctrl_sel) {
|
|
|
|
|
case VIDEO_VS_CTL_STREAM_ERROR_CODE:
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case VIDEO_REQUEST_GET_CUR:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
/* TODO */
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &self->error_code, sizeof(uint8_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_INFO:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get, sizeof(_cap_get)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
@ -960,25 +1023,23 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
case VIDEO_VS_CTL_PROBE:
|
|
|
|
|
if (self->state != VS_STATE_PROBING) {
|
|
|
|
|
self->state = VS_STATE_PROBING;
|
|
|
|
|
_init_vs_configuration(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case VIDEO_REQUEST_SET_CUR:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(sizeof(video_probe_and_commit_control_t) >= request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)),
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &self->probe_commit_payload, sizeof(video_probe_and_commit_control_t)),
|
|
|
|
|
VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
} else if (stage == CONTROL_STAGE_DATA) {
|
|
|
|
|
TU_VERIFY(_update_streaming_parameters(self, (video_probe_and_commit_control_t*)self->ep_buf),
|
|
|
|
|
TU_VERIFY(_update_streaming_parameters(self, &self->probe_commit_payload),
|
|
|
|
|
VIDEO_ERROR_INVALID_VALUE_WITHIN_RANGE);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_CUR:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &self->probe_commit_payload, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
@ -986,19 +1047,16 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
case VIDEO_REQUEST_GET_MAX:
|
|
|
|
|
case VIDEO_REQUEST_GET_RES:
|
|
|
|
|
case VIDEO_REQUEST_GET_DEF:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
video_probe_and_commit_control_t tmp;
|
|
|
|
|
tmp = *(video_probe_and_commit_control_t*)&self->ep_buf;
|
|
|
|
|
video_probe_and_commit_control_t tmp = self->probe_commit_payload;
|
|
|
|
|
TU_VERIFY(_negotiate_streaming_parameters(self, request->bRequest, &tmp), VIDEO_ERROR_INVALID_VALUE_WITHIN_RANGE);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &tmp, sizeof(tmp)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_LEN:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(2 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
uint16_t len = sizeof(video_probe_and_commit_control_t);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&len, sizeof(len)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
@ -1006,8 +1064,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_INFO:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t)&_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
@ -1021,10 +1078,9 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
switch (request->bRequest) {
|
|
|
|
|
case VIDEO_REQUEST_SET_CUR:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(sizeof(video_probe_and_commit_control_t) >= request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &self->probe_commit_payload, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
} else if (stage == CONTROL_STAGE_DATA) {
|
|
|
|
|
video_probe_and_commit_control_t *param = (video_probe_and_commit_control_t*)self->ep_buf;
|
|
|
|
|
video_probe_and_commit_control_t *param = &self->probe_commit_payload;
|
|
|
|
|
TU_VERIFY(_update_streaming_parameters(self, param), VIDEO_ERROR_INVALID_VALUE_WITHIN_RANGE);
|
|
|
|
|
/* Set the negotiated value */
|
|
|
|
|
self->max_payload_transfer_size = param->dwMaxPayloadTransferSize;
|
|
|
|
@ -1046,16 +1102,14 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_CUR:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, &self->probe_commit_payload, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_LEN:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(2 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
uint16_t len = sizeof(video_probe_and_commit_control_t);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)&len, sizeof(len)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
@ -1063,8 +1117,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
|
|
|
|
|
return VIDEO_ERROR_NONE;
|
|
|
|
|
|
|
|
|
|
case VIDEO_REQUEST_GET_INFO:
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP)
|
|
|
|
|
{
|
|
|
|
|
if (stage == CONTROL_STAGE_SETUP) {
|
|
|
|
|
TU_VERIFY(1 == request->wLength, VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
TU_VERIFY(tud_control_xfer(rhport, request, (uint8_t*)(uintptr_t) &_cap_get_set, sizeof(_cap_get_set)), VIDEO_ERROR_UNKNOWN);
|
|
|
|
|
}
|
|
|
|
@ -1165,8 +1218,7 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
// USBD Driver API
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
void videod_init(void)
|
|
|
|
|
{
|
|
|
|
|
void videod_init(void) {
|
|
|
|
|
for (uint_fast8_t i = 0; i < CFG_TUD_VIDEO; ++i) {
|
|
|
|
|
videod_interface_t* ctl = &_videod_itf[i];
|
|
|
|
|
tu_memclr(ctl, sizeof(*ctl));
|
|
|
|
@ -1177,8 +1229,7 @@ void videod_init(void)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void videod_reset(uint8_t rhport)
|
|
|
|
|
{
|
|
|
|
|
void videod_reset(uint8_t rhport) {
|
|
|
|
|
(void) rhport;
|
|
|
|
|
for (uint_fast8_t i = 0; i < CFG_TUD_VIDEO; ++i) {
|
|
|
|
|
videod_interface_t* ctl = &_videod_itf[i];
|
|
|
|
@ -1190,8 +1241,7 @@ void videod_reset(uint8_t rhport)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
|
|
|
|
|
{
|
|
|
|
|
uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
|
|
|
|
|
TU_VERIFY((TUSB_CLASS_VIDEO == itf_desc->bInterfaceClass) &&
|
|
|
|
|
(VIDEO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass) &&
|
|
|
|
|
(VIDEO_ITF_PROTOCOL_15 == itf_desc->bInterfaceProtocol), 0);
|
|
|
|
@ -1250,8 +1300,7 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
|
|
|
|
|
// Invoked when a control transfer occurred on an interface of this class
|
|
|
|
|
// Driver response accordingly to the request and the transfer stage (setup/data/ack)
|
|
|
|
|
// return false to stall control endpoint (e.g unsupported request)
|
|
|
|
|
bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
|
|
|
|
|
{
|
|
|
|
|
bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) {
|
|
|
|
|
int err;
|
|
|
|
|
TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
|
|
|
|
|
uint_fast8_t itfnum = tu_u16_low(request->wIndex);
|
|
|
|
@ -1264,6 +1313,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itf < CFG_TUD_VIDEO) {
|
|
|
|
|
TU_LOG_DRV(" VC[%d]: ", itf);
|
|
|
|
|
err = handle_video_ctl_req(rhport, stage, request, itf);
|
|
|
|
|
_videod_itf[itf].error_code = (uint8_t)err;
|
|
|
|
|
if (err) return false;
|
|
|
|
@ -1279,6 +1329,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itf < CFG_TUD_VIDEO_STREAMING) {
|
|
|
|
|
TU_LOG_DRV(" VS[%d]: ", itf);
|
|
|
|
|
err = handle_video_stm_req(rhport, stage, request, itf);
|
|
|
|
|
_videod_streaming_itf[itf].error_code = (uint8_t)err;
|
|
|
|
|
if (err) return false;
|
|
|
|
@ -1287,8 +1338,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
|
|
|
|
{
|
|
|
|
|
bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
|
|
|
|
|
(void)result; (void)xferred_bytes;
|
|
|
|
|
|
|
|
|
|
/* find streaming handle */
|
|
|
|
|