Open FFBoard
Open source force feedback firmware
video_device.c File Reference

Go to the source code of this file.

Classes

struct  tusb_desc_vc_itf_t
 
struct  tusb_desc_vs_itf_t
 
union  tusb_desc_video_itf_hdr_t
 
struct  TU_ATTR_PACKED
 AUDIO Channel Cluster Descriptor (4.1) More...
 
union  tusb_desc_cs_video_fmt_t
 
struct  tusb_desc_cs_video_fmt_t::TU_ATTR_PACKED
 
union  tusb_desc_cs_video_frm_t
 
struct  tusb_desc_cs_video_frm_t::TU_ATTR_PACKED
 

Typedefs

typedef struct TU_ATTR_PACKED tusb_desc_cs_video_entity_itf_t
 
typedef struct TU_ATTR_PACKED videod_streaming_interface_t
 
typedef struct TU_ATTR_PACKED videod_interface_t
 

Functions

static uint8_t _desc_itfnum (void const *desc)
 
static uint8_t _desc_ep_addr (void const *desc)
 
static videod_streaming_interface_t_get_instance_streaming (uint_fast8_t ctl_idx, uint_fast8_t stm_idx)
 
static tusb_desc_vc_itf_t const * _get_desc_vc (videod_interface_t const *self)
 
static tusb_desc_vs_itf_t const * _get_desc_vs (videod_streaming_interface_t const *self)
 
static void const * _find_desc (void const *beg, void const *end, uint_fast8_t desc_type)
 
static void const * _find_desc_2_type (void const *beg, void const *end, uint_fast8_t desc_type_0, uint_fast8_t desc_type_1)
 
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)
 
static void const * _next_desc_itf (void const *beg, void const *end)
 
static uint8_t const * _find_desc_itf (void const *beg, void const *end, uint_fast8_t itfnum, uint_fast8_t altnum)
 
static void const * _find_desc_ep (void const *beg, void const *end)
 
static void const * _end_of_control_descriptor (void const *desc)
 
static void const * _find_desc_entity (void const *desc, uint_fast8_t entityid)
 
static void const * _end_of_streaming_descriptor (void const *desc)
 
static void const * _find_desc_format (void const *beg, void const *end, uint_fast8_t fmtnum)
 
static void const * _find_desc_frame (void const *beg, void const *end, uint_fast8_t frmnum)
 
static bool _update_streaming_parameters (videod_streaming_interface_t const *stm, video_probe_and_commit_control_t *param)
 
static bool _negotiate_streaming_parameters (videod_streaming_interface_t const *stm, uint_fast8_t request, video_probe_and_commit_control_t *param)
 
static bool _close_vc_itf (uint8_t rhport, videod_interface_t *self)
 
static bool _open_vc_itf (uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum)
 
static bool _init_vs_configuration (videod_streaming_interface_t *stm)
 
static bool _open_vs_itf (uint8_t rhport, videod_streaming_interface_t *stm, uint_fast8_t altnum)
 
static uint_fast16_t _prepare_in_payload (videod_streaming_interface_t *stm)
 
static int handle_video_ctl_std_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t ctl_idx)
 
static int handle_video_ctl_cs_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t ctl_idx)
 
static int handle_video_ctl_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t ctl_idx)
 
static int handle_video_stm_std_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t stm_idx)
 
static int handle_video_stm_cs_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t stm_idx)
 
static int handle_video_stm_req (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request, uint_fast8_t stm_idx)
 
bool tud_video_n_connected (uint_fast8_t ctl_idx)
 
bool tud_video_n_streaming (uint_fast8_t ctl_idx, uint_fast8_t stm_idx)
 
bool tud_video_n_frame_xfer (uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *buffer, size_t bufsize)
 
void videod_init (void)
 
bool videod_deinit (void)
 
void videod_reset (uint8_t rhport)
 
uint16_t videod_open (uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
 
bool videod_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
 
bool videod_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
 

Variables

CFG_TUD_MEM_SECTION tu_static videod_interface_t _videod_itf [CFG_TUD_VIDEO]
 
CFG_TUD_MEM_SECTION tu_static videod_streaming_interface_t _videod_streaming_itf [CFG_TUD_VIDEO_STREAMING]
 
tu_static uint8_t const _cap_get = 0x1u
 
tu_static uint8_t const _cap_get_set = 0x3u
 
static tu_lookup_entry_t const tu_lookup_video_request []
 
static tu_lookup_table_t const tu_table_video_request
 
static char const *const tu_str_video_vc_control_selector []
 
static char const *const tu_str_video_vs_control_selector []
 

Typedef Documentation

◆ tusb_desc_cs_video_entity_itf_t

◆ videod_interface_t

◆ videod_streaming_interface_t

Function Documentation

◆ _close_vc_itf()

static bool _close_vc_itf ( uint8_t  rhport,
videod_interface_t self 
)
static

Close current video control interface.

Parameters
[in,out]selfVideo control interface context.
[in]altnumThe target alternate setting number.

Definition at line 678 of file video_device.c.

◆ _desc_ep_addr()

static uint8_t _desc_ep_addr ( void const *  desc)
inlinestatic

Get endpoint address from the endpoint descriptor

Parameters
[in]descendpoint descriptor
Returns
bEndpointAddress

Definition at line 215 of file video_device.c.

◆ _desc_itfnum()

static uint8_t _desc_itfnum ( void const *  desc)
inlinestatic

Get interface number from the interface descriptor

Parameters
[in]descinterface descriptor
Returns
bInterfaceNumber

Definition at line 206 of file video_device.c.

◆ _end_of_control_descriptor()

static void const * _end_of_control_descriptor ( void const *  desc)
inlinestatic

Return the end of the video control descriptor.

Definition at line 356 of file video_device.c.

◆ _end_of_streaming_descriptor()

static void const * _end_of_streaming_descriptor ( void const *  desc)
inlinestatic

Return the end of the video streaming descriptor.

Definition at line 386 of file video_device.c.

◆ _find_desc()

static void const * _find_desc ( void const *  beg,
void const *  end,
uint_fast8_t  desc_type 
)
static

Find the first descriptor of a given type

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
[in]desc_typeThe target descriptor type.
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 251 of file video_device.c.

◆ _find_desc_2_type()

static void const * _find_desc_2_type ( void const *  beg,
void const *  end,
uint_fast8_t  desc_type_0,
uint_fast8_t  desc_type_1 
)
static

Find the first descriptor of two given types

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
[in]desc_type_0The first target descriptor type.
[in]desc_type_1The second target descriptor type.
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 268 of file video_device.c.

◆ _find_desc_3()

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 
)
static

Find the first descriptor specified by the arguments

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
[in]desc_typeThe target descriptor type
[in]element_0The target element following the desc_type
[in]element_1The target element following the element_0
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 287 of file video_device.c.

◆ _find_desc_entity()

static void const * _find_desc_entity ( void const *  desc,
uint_fast8_t  entityid 
)
static

Find the first entity descriptor with the entity ID specified by the argument belonging to the current video control descriptor.

Parameters
[in]descThe video control interface descriptor.
[in]entityidThe target entity id.
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 370 of file video_device.c.

◆ _find_desc_ep()

static void const * _find_desc_ep ( void const *  beg,
void const *  end 
)
static

Find the first endpoint descriptor belonging to the current interface descriptor.

The search range is from beg to end or the next interface descriptor.

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
Returns
The pointer for endpoint descriptor.
Return values
enddid not found endpoint descriptor

Definition at line 345 of file video_device.c.

◆ _find_desc_format()

static void const * _find_desc_format ( void const *  beg,
void const *  end,
uint_fast8_t  fmtnum 
)
inlinestatic

Find the first format descriptor with the specified format number.

Definition at line 393 of file video_device.c.

◆ _find_desc_frame()

static void const * _find_desc_frame ( void const *  beg,
void const *  end,
uint_fast8_t  frmnum 
)
inlinestatic

Find the first frame descriptor with the specified format number.

Definition at line 411 of file video_device.c.

◆ _find_desc_itf()

static uint8_t const * _find_desc_itf ( void const *  beg,
void const *  end,
uint_fast8_t  itfnum,
uint_fast8_t  altnum 
)
inlinestatic

Find the first interface descriptor with the specified interface number and alternate setting number.

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
[in]itfnumThe target interface number.
[in]altnumThe target alternate setting number.
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 331 of file video_device.c.

◆ _get_desc_vc()

static tusb_desc_vc_itf_t const * _get_desc_vc ( videod_interface_t const *  self)
static

Definition at line 233 of file video_device.c.

◆ _get_desc_vs()

static tusb_desc_vs_itf_t const * _get_desc_vs ( videod_streaming_interface_t const *  self)
static

Definition at line 237 of file video_device.c.

◆ _get_instance_streaming()

static videod_streaming_interface_t * _get_instance_streaming ( uint_fast8_t  ctl_idx,
uint_fast8_t  stm_idx 
)
static

Get instance of streaming interface

Parameters
[in]ctl_idxinstance number of video control
[in]stm_idxindex number of streaming interface
Returns
instance

Definition at line 225 of file video_device.c.

◆ _init_vs_configuration()

static bool _init_vs_configuration ( videod_streaming_interface_t stm)
static

Definition at line 739 of file video_device.c.

◆ _negotiate_streaming_parameters()

static bool _negotiate_streaming_parameters ( videod_streaming_interface_t const *  stm,
uint_fast8_t  request,
video_probe_and_commit_control_t param 
)
static

Set the minimum, maximum, default values or resolutions to variables which need to negotiate with the host

Parameters
[in]requestGET_MAX, GET_MIN, GET_RES or GET_DEF
[in,out]paramTarget

Definition at line 522 of file video_device.c.

◆ _next_desc_itf()

static void const * _next_desc_itf ( void const *  beg,
void const *  end 
)
static

Return the next interface descriptor which has another interface number. If there are multiple VC interfaces, there will be an IAD descriptor before the next interface descriptor. Check both the IAD descriptor and the interface descriptor. 3.1 Descriptor Layout Overview

Parameters
[in]begThe head of descriptor byte array.
[in]endThe tail of descriptor byte array.
Returns
The pointer for interface descriptor.
Return values
enddid not found interface descriptor

Definition at line 312 of file video_device.c.

◆ _open_vc_itf()

static bool _open_vc_itf ( uint8_t  rhport,
videod_interface_t self,
uint_fast8_t  altnum 
)
static

Set the alternate setting to own video control interface.

Parameters
[in,out]selfVideo control interface context.
[in]altnumThe target alternate setting number.

Definition at line 702 of file video_device.c.

◆ _open_vs_itf()

static bool _open_vs_itf ( uint8_t  rhport,
videod_streaming_interface_t stm,
uint_fast8_t  altnum 
)
static

Set the alternate setting to own video streaming interface.

Parameters
[in,out]stmStreaming interface context.
[in]altnumThe target alternate setting number.

Definition at line 752 of file video_device.c.

◆ _prepare_in_payload()

static uint_fast16_t _prepare_in_payload ( videod_streaming_interface_t stm)
static

Prepare the next packet payload.

Definition at line 819 of file video_device.c.

◆ _update_streaming_parameters()

static bool _update_streaming_parameters ( videod_streaming_interface_t const *  stm,
video_probe_and_commit_control_t param 
)
static

Set uniquely determined values to variables that have not been set

Parameters
[in,out]paramTarget

Definition at line 430 of file video_device.c.

◆ handle_video_ctl_cs_req()

static int handle_video_ctl_cs_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  ctl_idx 
)
static

Definition at line 875 of file video_device.c.

◆ handle_video_ctl_req()

static int handle_video_ctl_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  ctl_idx 
)
static

Definition at line 945 of file video_device.c.

◆ handle_video_ctl_std_req()

static int handle_video_ctl_std_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  ctl_idx 
)
static

Handle a standard request to the video control interface.

Definition at line 840 of file video_device.c.

◆ handle_video_stm_cs_req()

static int handle_video_stm_cs_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  stm_idx 
)
static

Definition at line 1000 of file video_device.c.

◆ handle_video_stm_req()

static int handle_video_stm_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  stm_idx 
)
static

Definition at line 1154 of file video_device.c.

◆ handle_video_stm_std_req()

static int handle_video_stm_std_req ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request,
uint_fast8_t  stm_idx 
)
static

Definition at line 968 of file video_device.c.

◆ tud_video_n_connected()

bool tud_video_n_connected ( uint_fast8_t  ctl_idx)

Definition at line 1174 of file video_device.c.

◆ tud_video_n_frame_xfer()

bool tud_video_n_frame_xfer ( uint_fast8_t  ctl_idx,
uint_fast8_t  stm_idx,
void *  buffer,
size_t  bufsize 
)

Transfer a frame

Parameters
[in]ctl_idxDestination control interface index
[in]stm_idxDestination streaming interface index
[in]bufferFrame buffer. The caller must not use this buffer until the operation is completed.
[in]bufsizeByte size of the frame buffer

Definition at line 1202 of file video_device.c.

◆ tud_video_n_streaming()

bool tud_video_n_streaming ( uint_fast8_t  ctl_idx,
uint_fast8_t  stm_idx 
)

Return true if streaming

Parameters
[in]ctl_idxDestination control interface index
[in]stm_idxDestination streaming interface index

Definition at line 1182 of file video_device.c.

◆ videod_control_xfer_cb()

bool videod_control_xfer_cb ( uint8_t  rhport,
uint8_t  stage,
tusb_control_request_t const *  request 
)

Definition at line 1342 of file video_device.c.

◆ videod_deinit()

bool videod_deinit ( void  )

Definition at line 1249 of file video_device.c.

◆ videod_init()

void videod_init ( void  )

Definition at line 1238 of file video_device.c.

◆ videod_open()

uint16_t videod_open ( uint8_t  rhport,
tusb_desc_interface_t const *  itf_desc,
uint16_t  max_len 
)

Definition at line 1265 of file video_device.c.

◆ videod_reset()

void videod_reset ( uint8_t  rhport)

Definition at line 1253 of file video_device.c.

◆ videod_xfer_cb()

bool videod_xfer_cb ( uint8_t  rhport,
uint8_t  ep_addr,
xfer_result_t  result,
uint32_t  xferred_bytes 
)

Definition at line 1380 of file video_device.c.

Variable Documentation

◆ _cap_get

tu_static uint8_t const _cap_get = 0x1u

Definition at line 145 of file video_device.c.

◆ _cap_get_set

tu_static uint8_t const _cap_get_set = 0x3u

Definition at line 146 of file video_device.c.

◆ _videod_itf

CFG_TUD_MEM_SECTION tu_static videod_interface_t _videod_itf[CFG_TUD_VIDEO]

Definition at line 142 of file video_device.c.

◆ _videod_streaming_itf

CFG_TUD_MEM_SECTION tu_static videod_streaming_interface_t _videod_streaming_itf[CFG_TUD_VIDEO_STREAMING]

Definition at line 143 of file video_device.c.

◆ tu_lookup_video_request

tu_lookup_entry_t const tu_lookup_video_request[]
static
Initial value:
= {
{.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"},
}
@ VIDEO_REQUEST_SET_CUR_ALL
Definition: video.h:145
@ VIDEO_REQUEST_GET_INFO
Definition: video.h:151
@ VIDEO_REQUEST_GET_DEF_ALL
Definition: video.h:157
@ VIDEO_REQUEST_UNDEFINED
Definition: video.h:143
@ VIDEO_REQUEST_GET_LEN
Definition: video.h:150
@ VIDEO_REQUEST_GET_DEF
Definition: video.h:152
@ VIDEO_REQUEST_GET_CUR_ALL
Definition: video.h:153
@ VIDEO_REQUEST_GET_MIN
Definition: video.h:147
@ VIDEO_REQUEST_GET_RES
Definition: video.h:149
@ VIDEO_REQUEST_GET_MIN_ALL
Definition: video.h:154
@ VIDEO_REQUEST_SET_CUR
Definition: video.h:144
@ VIDEO_REQUEST_GET_CUR
Definition: video.h:146
@ VIDEO_REQUEST_GET_MAX
Definition: video.h:148
@ VIDEO_REQUEST_GET_RES_ALL
Definition: video.h:156
@ VIDEO_REQUEST_GET_MAX_ALL
Definition: video.h:155

Definition at line 153 of file video_device.c.

◆ tu_str_video_vc_control_selector

char const* const tu_str_video_vc_control_selector[]
static
Initial value:
= {
"Undefined",
"Video Power Mode",
"Request Error Code",
}

Definition at line 176 of file video_device.c.

◆ tu_str_video_vs_control_selector

char const* const tu_str_video_vs_control_selector[]
static
Initial value:
= {
"Undefined",
"Probe",
"Commit",
"Still Probe",
"Still Commit",
"Still Image Trigger",
"Stream Error Code",
"Generate Key Frame",
"Update Frame Segment",
"Sync Delay",
}

Definition at line 182 of file video_device.c.

◆ tu_table_video_request

tu_lookup_table_t const tu_table_video_request
static
Initial value:
= {
.count = TU_ARRAY_SIZE(tu_lookup_video_request),
}
static tu_lookup_entry_t const tu_lookup_video_request[]
Definition: video_device.c:153

Definition at line 171 of file video_device.c.