@@ -108,7 +108,7 @@ typedef struct TU_ATTR_PACKED {
108108
109109/* video control interface */
110110typedef struct TU_ATTR_PACKED {
111- void const * beg ; /* The head of the first video control interface descriptor */
111+ uint8_t const * beg ; /* The head of the first video control interface descriptor */
112112 uint16_t len ; /* Byte length of the descriptors */
113113 uint16_t cur ; /* offset for current video control interface */
114114 uint8_t stm [CFG_TUD_VIDEO_STREAMING ]; /* Indices of streaming interface */
@@ -174,7 +174,7 @@ static tusb_desc_vc_itf_t const* _get_desc_vc(videod_interface_t const *self)
174174static tusb_desc_vs_itf_t const * _get_desc_vs (videod_streaming_interface_t const * self )
175175{
176176 if (!self -> desc .cur ) return NULL ;
177- void const * desc = _videod_itf [self -> index_vc ].beg ;
177+ uint8_t const * desc = _videod_itf [self -> index_vc ].beg ;
178178 return (tusb_desc_vs_itf_t const * )(desc + self -> desc .cur );
179179}
180180
@@ -247,9 +247,9 @@ static void const* _next_desc_itf(void const *beg, void const *end)
247247 *
248248 * @return The pointer for interface descriptor.
249249 * @retval end did not found interface descriptor */
250- static inline void const * _find_desc_itf (void const * beg , void const * end , uint_fast8_t itfnum , uint_fast8_t altnum )
250+ static inline uint8_t const * _find_desc_itf (void const * beg , void const * end , uint_fast8_t itfnum , uint_fast8_t altnum )
251251{
252- return _find_desc_3 (beg , end , TUSB_DESC_INTERFACE , itfnum , altnum );
252+ return ( uint8_t const * ) _find_desc_3 (beg , end , TUSB_DESC_INTERFACE , itfnum , altnum );
253253}
254254
255255/** Find the first endpoint descriptor belonging to the current interface descriptor.
@@ -275,7 +275,7 @@ static void const* _find_desc_ep(void const *beg, void const *end)
275275static inline void const * _end_of_control_descriptor (void const * desc )
276276{
277277 tusb_desc_vc_itf_t const * vc = (tusb_desc_vc_itf_t const * )desc ;
278- return desc + vc -> std .bLength + vc -> ctl .wTotalLength ;
278+ return (( uint8_t const * ) desc ) + vc -> std .bLength + tu_le16toh ( vc -> ctl .wTotalLength ) ;
279279}
280280
281281/** Find the first entity descriptor with the entity ID
@@ -305,7 +305,7 @@ static void const* _find_desc_entity(void const *desc, uint_fast8_t entityid)
305305static inline void const * _end_of_streaming_descriptor (void const * desc )
306306{
307307 tusb_desc_vs_itf_t const * vs = (tusb_desc_vs_itf_t const * )desc ;
308- return desc + vs -> std .bLength + vs -> stm .wTotalLength ;
308+ return (( uint8_t const * ) desc ) + vs -> std .bLength + tu_le16toh ( vs -> stm .wTotalLength ) ;
309309}
310310
311311/** Find the first format descriptor with the specified format number. */
@@ -581,8 +581,10 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
581581static bool _close_vc_itf (uint8_t rhport , videod_interface_t * self )
582582{
583583 tusb_desc_vc_itf_t const * vc = _get_desc_vc (self );
584+
584585 /* The next descriptor after the class-specific VC interface header descriptor. */
585- void const * cur = (void const * )vc + vc -> std .bLength + vc -> ctl .bLength ;
586+ void const * cur = (uint8_t const * )vc + vc -> std .bLength + vc -> ctl .bLength ;
587+
586588 /* The end of the video control interface descriptor. */
587589 void const * end = _end_of_control_descriptor (vc );
588590 if (vc -> std .bNumEndpoints ) {
@@ -603,10 +605,11 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
603605static bool _open_vc_itf (uint8_t rhport , videod_interface_t * self , uint_fast8_t altnum )
604606{
605607 TU_LOG2 (" open VC %d\n" , altnum );
606- void const * beg = self -> beg ;
607- void const * end = beg + self -> len ;
608+ uint8_t const * beg = self -> beg ;
609+ uint8_t const * end = beg + self -> len ;
610+
608611 /* The first descriptor is a video control interface descriptor. */
609- void const * cur = _find_desc_itf (beg , end , _desc_itfnum (beg ), altnum );
612+ uint8_t const * cur = _find_desc_itf (beg , end , _desc_itfnum (beg ), altnum );
610613 TU_LOG2 (" cur %d\n" , cur - beg );
611614 TU_VERIFY (cur < end );
612615
@@ -616,7 +619,8 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
616619 TU_ASSERT (vc -> ctl .bInCollection <= CFG_TUD_VIDEO_STREAMING );
617620
618621 /* Update to point the end of the video control interface descriptor. */
619- end = _end_of_control_descriptor (cur );
622+ end = _end_of_control_descriptor (cur );
623+
620624 /* Advance to the next descriptor after the class-specific VC interface header descriptor. */
621625 cur += vc -> std .bLength + vc -> ctl .bLength ;
622626 TU_LOG2 (" bNumEndpoints %d\n" , vc -> std .bNumEndpoints );
@@ -631,7 +635,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
631635 /* Open the notification endpoint */
632636 TU_ASSERT (usbd_edpt_open (rhport , notif ));
633637 }
634- self -> cur = (uint16_t ) ((void const * )vc - beg );
638+ self -> cur = (uint16_t ) ((uint8_t const * )vc - beg );
635639 return true;
636640}
637641
@@ -643,7 +647,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
643647{
644648 uint_fast8_t i ;
645649 TU_LOG2 (" reopen VS %d\n" , altnum );
646- void const * desc = _videod_itf [stm -> index_vc ].beg ;
650+ uint8_t const * desc = _videod_itf [stm -> index_vc ].beg ;
647651
648652 /* Close endpoints of previous settings. */
649653 for (i = 0 ; i < TU_ARRAY_SIZE (stm -> desc .ep ); ++ i ) {
@@ -654,16 +658,18 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
654658 stm -> desc .ep [i ] = 0 ;
655659 TU_LOG2 (" close EP%02x\n" , ep_adr );
656660 }
661+
657662 /* clear transfer management information */
658663 stm -> buffer = NULL ;
659664 stm -> bufsize = 0 ;
660665 stm -> offset = 0 ;
661666
662667 /* Find a alternate interface */
663- void const * beg = desc + stm -> desc .beg ;
664- void const * end = desc + stm -> desc .end ;
665- void const * cur = _find_desc_itf (beg , end , _desc_itfnum (beg ), altnum );
668+ uint8_t const * beg = desc + stm -> desc .beg ;
669+ uint8_t const * end = desc + stm -> desc .end ;
670+ uint8_t const * cur = _find_desc_itf (beg , end , _desc_itfnum (beg ), altnum );
666671 TU_VERIFY (cur < end );
672+
667673 uint_fast8_t numeps = ((tusb_desc_interface_t const * )cur )-> bNumEndpoints ;
668674 TU_ASSERT (numeps <= TU_ARRAY_SIZE (stm -> desc .ep ));
669675 stm -> desc .cur = (uint16_t ) (cur - desc ); /* Save the offset of the new settings */
@@ -917,7 +923,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
917923 switch (request -> bRequest ) {
918924 case VIDEO_REQUEST_SET_CUR :
919925 if (stage == CONTROL_STAGE_SETUP ) {
920- TU_VERIFY (sizeof (video_probe_and_commit_control_t ) = = request -> wLength , VIDEO_ERROR_UNKNOWN );
926+ TU_VERIFY (sizeof (video_probe_and_commit_control_t ) > = request -> wLength , VIDEO_ERROR_UNKNOWN );
921927 TU_VERIFY (tud_control_xfer (rhport , request , self -> ep_buf , sizeof (video_probe_and_commit_control_t )),
922928 VIDEO_ERROR_UNKNOWN );
923929 } else if (stage == CONTROL_STAGE_DATA ) {
@@ -973,7 +979,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
973979 switch (request -> bRequest ) {
974980 case VIDEO_REQUEST_SET_CUR :
975981 if (stage == CONTROL_STAGE_SETUP ) {
976- TU_VERIFY (sizeof (video_probe_and_commit_control_t ) = = request -> wLength , VIDEO_ERROR_UNKNOWN );
982+ TU_VERIFY (sizeof (video_probe_and_commit_control_t ) > = request -> wLength , VIDEO_ERROR_UNKNOWN );
977983 TU_VERIFY (tud_control_xfer (rhport , request , self -> ep_buf , sizeof (video_probe_and_commit_control_t )), VIDEO_ERROR_UNKNOWN );
978984 } else if (stage == CONTROL_STAGE_DATA ) {
979985 TU_VERIFY (_update_streaming_parameters (self , (video_probe_and_commit_control_t * )self -> ep_buf ), VIDEO_ERROR_INVALID_VALUE_WITHIN_RANGE );
@@ -1043,7 +1049,6 @@ static int handle_video_stm_req(uint8_t rhport, uint8_t stage,
10431049
10441050 default : return VIDEO_ERROR_INVALID_REQUEST ;
10451051 }
1046- return VIDEO_ERROR_UNKNOWN ;
10471052}
10481053
10491054//--------------------------------------------------------------------+
@@ -1076,7 +1081,7 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu
10761081 if (!stm || !stm -> desc .ep [0 ] || stm -> buffer ) return false;
10771082
10781083 /* Find EP address */
1079- void const * desc = _videod_itf [stm -> index_vc ].beg ;
1084+ uint8_t const * desc = _videod_itf [stm -> index_vc ].beg ;
10801085 uint8_t ep_addr = 0 ;
10811086 for (uint_fast8_t i = 0 ; i < CFG_TUD_VIDEO_STREAMING ; ++ i ) {
10821087 uint_fast16_t ofs_ep = stm -> desc .ep [i ];
@@ -1143,13 +1148,15 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
11431148 }
11441149 TU_ASSERT (ctl_idx < CFG_TUD_VIDEO , 0 );
11451150
1146- void const * end = (void const * )itf_desc + max_len ;
1147- self -> beg = itf_desc ;
1151+ uint8_t const * end = (uint8_t const * )itf_desc + max_len ;
1152+ self -> beg = ( uint8_t const * ) itf_desc ;
11481153 self -> len = max_len ;
1154+
11491155 /*------------- Video Control Interface -------------*/
11501156 TU_VERIFY (_open_vc_itf (rhport , self , 0 ), 0 );
11511157 tusb_desc_vc_itf_t const * vc = _get_desc_vc (self );
11521158 uint_fast8_t bInCollection = vc -> ctl .bInCollection ;
1159+
11531160 /* Find the end of the video interface descriptor */
11541161 void const * cur = _next_desc_itf (itf_desc , end );
11551162 for (uint8_t stm_idx = 0 ; stm_idx < bInCollection ; ++ stm_idx ) {
@@ -1200,7 +1207,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_
12001207 for (itf = 0 ; itf < CFG_TUD_VIDEO_STREAMING ; ++ itf ) {
12011208 videod_streaming_interface_t * stm = & _videod_streaming_itf [itf ];
12021209 if (!stm -> desc .beg ) continue ;
1203- void const * desc = _videod_itf [stm -> index_vc ].beg ;
1210+ uint8_t const * desc = _videod_itf [stm -> index_vc ].beg ;
12041211 if (itfnum == _desc_itfnum (desc + stm -> desc .beg )) break ;
12051212 }
12061213
@@ -1226,7 +1233,7 @@ bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint3
12261233 uint_fast16_t const ep_ofs = stm -> desc .ep [0 ];
12271234 if (!ep_ofs ) continue ;
12281235 ctl = & _videod_itf [stm -> index_vc ];
1229- void const * desc = ctl -> beg ;
1236+ uint8_t const * desc = ctl -> beg ;
12301237 if (ep_addr == _desc_ep_addr (desc + ep_ofs )) break ;
12311238 }
12321239
0 commit comments