@@ -108,7 +108,7 @@ typedef struct TU_ATTR_PACKED {
108
108
109
109
/* video control interface */
110
110
typedef 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 */
112
112
uint16_t len ; /* Byte length of the descriptors */
113
113
uint16_t cur ; /* offset for current video control interface */
114
114
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)
174
174
static tusb_desc_vs_itf_t const * _get_desc_vs (videod_streaming_interface_t const * self )
175
175
{
176
176
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 ;
178
178
return (tusb_desc_vs_itf_t const * )(desc + self -> desc .cur );
179
179
}
180
180
@@ -247,9 +247,9 @@ static void const* _next_desc_itf(void const *beg, void const *end)
247
247
*
248
248
* @return The pointer for interface descriptor.
249
249
* @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 )
251
251
{
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 );
253
253
}
254
254
255
255
/** 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)
275
275
static inline void const * _end_of_control_descriptor (void const * desc )
276
276
{
277
277
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 ) ;
279
279
}
280
280
281
281
/** 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)
305
305
static inline void const * _end_of_streaming_descriptor (void const * desc )
306
306
{
307
307
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 ) ;
309
309
}
310
310
311
311
/** Find the first format descriptor with the specified format number. */
@@ -581,8 +581,10 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
581
581
static bool _close_vc_itf (uint8_t rhport , videod_interface_t * self )
582
582
{
583
583
tusb_desc_vc_itf_t const * vc = _get_desc_vc (self );
584
+
584
585
/* 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
+
586
588
/* The end of the video control interface descriptor. */
587
589
void const * end = _end_of_control_descriptor (vc );
588
590
if (vc -> std .bNumEndpoints ) {
@@ -603,10 +605,11 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
603
605
static bool _open_vc_itf (uint8_t rhport , videod_interface_t * self , uint_fast8_t altnum )
604
606
{
605
607
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
+
608
611
/* 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 );
610
613
TU_LOG2 (" cur %d\n" , cur - beg );
611
614
TU_VERIFY (cur < end );
612
615
@@ -616,7 +619,8 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
616
619
TU_ASSERT (vc -> ctl .bInCollection <= CFG_TUD_VIDEO_STREAMING );
617
620
618
621
/* 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
+
620
624
/* Advance to the next descriptor after the class-specific VC interface header descriptor. */
621
625
cur += vc -> std .bLength + vc -> ctl .bLength ;
622
626
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
631
635
/* Open the notification endpoint */
632
636
TU_ASSERT (usbd_edpt_open (rhport , notif ));
633
637
}
634
- self -> cur = (uint16_t ) ((void const * )vc - beg );
638
+ self -> cur = (uint16_t ) ((uint8_t const * )vc - beg );
635
639
return true;
636
640
}
637
641
@@ -643,7 +647,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
643
647
{
644
648
uint_fast8_t i ;
645
649
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 ;
647
651
648
652
/* Close endpoints of previous settings. */
649
653
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
654
658
stm -> desc .ep [i ] = 0 ;
655
659
TU_LOG2 (" close EP%02x\n" , ep_adr );
656
660
}
661
+
657
662
/* clear transfer management information */
658
663
stm -> buffer = NULL ;
659
664
stm -> bufsize = 0 ;
660
665
stm -> offset = 0 ;
661
666
662
667
/* 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 );
666
671
TU_VERIFY (cur < end );
672
+
667
673
uint_fast8_t numeps = ((tusb_desc_interface_t const * )cur )-> bNumEndpoints ;
668
674
TU_ASSERT (numeps <= TU_ARRAY_SIZE (stm -> desc .ep ));
669
675
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,
917
923
switch (request -> bRequest ) {
918
924
case VIDEO_REQUEST_SET_CUR :
919
925
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 );
921
927
TU_VERIFY (tud_control_xfer (rhport , request , self -> ep_buf , sizeof (video_probe_and_commit_control_t )),
922
928
VIDEO_ERROR_UNKNOWN );
923
929
} else if (stage == CONTROL_STAGE_DATA ) {
@@ -973,7 +979,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
973
979
switch (request -> bRequest ) {
974
980
case VIDEO_REQUEST_SET_CUR :
975
981
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 );
977
983
TU_VERIFY (tud_control_xfer (rhport , request , self -> ep_buf , sizeof (video_probe_and_commit_control_t )), VIDEO_ERROR_UNKNOWN );
978
984
} else if (stage == CONTROL_STAGE_DATA ) {
979
985
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,
1043
1049
1044
1050
default : return VIDEO_ERROR_INVALID_REQUEST ;
1045
1051
}
1046
- return VIDEO_ERROR_UNKNOWN ;
1047
1052
}
1048
1053
1049
1054
//--------------------------------------------------------------------+
@@ -1076,7 +1081,7 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu
1076
1081
if (!stm || !stm -> desc .ep [0 ] || stm -> buffer ) return false;
1077
1082
1078
1083
/* Find EP address */
1079
- void const * desc = _videod_itf [stm -> index_vc ].beg ;
1084
+ uint8_t const * desc = _videod_itf [stm -> index_vc ].beg ;
1080
1085
uint8_t ep_addr = 0 ;
1081
1086
for (uint_fast8_t i = 0 ; i < CFG_TUD_VIDEO_STREAMING ; ++ i ) {
1082
1087
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
1143
1148
}
1144
1149
TU_ASSERT (ctl_idx < CFG_TUD_VIDEO , 0 );
1145
1150
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 ;
1148
1153
self -> len = max_len ;
1154
+
1149
1155
/*------------- Video Control Interface -------------*/
1150
1156
TU_VERIFY (_open_vc_itf (rhport , self , 0 ), 0 );
1151
1157
tusb_desc_vc_itf_t const * vc = _get_desc_vc (self );
1152
1158
uint_fast8_t bInCollection = vc -> ctl .bInCollection ;
1159
+
1153
1160
/* Find the end of the video interface descriptor */
1154
1161
void const * cur = _next_desc_itf (itf_desc , end );
1155
1162
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_
1200
1207
for (itf = 0 ; itf < CFG_TUD_VIDEO_STREAMING ; ++ itf ) {
1201
1208
videod_streaming_interface_t * stm = & _videod_streaming_itf [itf ];
1202
1209
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 ;
1204
1211
if (itfnum == _desc_itfnum (desc + stm -> desc .beg )) break ;
1205
1212
}
1206
1213
@@ -1226,7 +1233,7 @@ bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint3
1226
1233
uint_fast16_t const ep_ofs = stm -> desc .ep [0 ];
1227
1234
if (!ep_ofs ) continue ;
1228
1235
ctl = & _videod_itf [stm -> index_vc ];
1229
- void const * desc = ctl -> beg ;
1236
+ uint8_t const * desc = ctl -> beg ;
1230
1237
if (ep_addr == _desc_ep_addr (desc + ep_ofs )) break ;
1231
1238
}
1232
1239
0 commit comments