@@ -1023,7 +1023,7 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
1023
1023
struct video_format * fmt )
1024
1024
{
1025
1025
struct gc2145_data * drv_data = dev -> data ;
1026
- uint16_t width , height ;
1026
+ enum resolutions res = RESOLUTIONS_MAX ;
1027
1027
int ret ;
1028
1028
1029
1029
/* We only support RGB565 formats */
@@ -1032,40 +1032,41 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
1032
1032
return - ENOTSUP ;
1033
1033
}
1034
1034
1035
- width = fmt -> width ;
1036
- height = fmt -> height ;
1037
-
1038
1035
if (memcmp (& drv_data -> fmt , fmt , sizeof (drv_data -> fmt )) == 0 ) {
1039
1036
/* nothing to do */
1040
1037
return 0 ;
1041
1038
}
1042
1039
1043
1040
/* Check if camera is capable of handling given format */
1044
- for (int i = 0 ; i < ARRAY_SIZE (fmts ); i ++ ) {
1045
- if (fmts [i ].width_min == width && fmts [i ].height_min == height &&
1041
+ for (int i = 0 ; i == ARRAY_SIZE (fmts ); i ++ ) {
1042
+ if (fmts [i ].width_min == fmt -> width && fmts [i ].height_min == fmt -> height &&
1046
1043
fmts [i ].pixelformat == fmt -> pixelformat ) {
1047
- drv_data -> fmt = * fmt ;
1044
+ res = (enum resolutions )i ;
1045
+ break ;
1046
+ }
1047
+ }
1048
+ if (res == RESOLUTIONS_MAX ) {
1049
+ LOG_ERR ("Image format not supported" );
1050
+ return - ENOTSUP ;
1051
+ }
1048
1052
1049
- /* Set output format */
1050
- ret = gc2145_set_output_format (dev , fmt -> pixelformat );
1051
- if (ret < 0 ) {
1052
- LOG_ERR ("Failed to set the output format" );
1053
- return ret ;
1054
- }
1053
+ drv_data -> fmt = * fmt ;
1055
1054
1056
- /* Set window size */
1057
- ret = gc2145_set_resolution (dev , (enum resolutions )i );
1058
- if (ret < 0 ) {
1059
- LOG_ERR ("Failed to set the resolution" );
1060
- }
1055
+ /* Set output format */
1056
+ ret = gc2145_set_output_format (dev , fmt -> pixelformat );
1057
+ if (ret < 0 ) {
1058
+ LOG_ERR ("Failed to set the output format" );
1059
+ return ret ;
1060
+ }
1061
1061
1062
- return ret ;
1063
- }
1062
+ /* Set window size */
1063
+ ret = gc2145_set_resolution (dev , res );
1064
+ if (ret < 0 ) {
1065
+ LOG_ERR ("Failed to set the resolution" );
1066
+ return ret ;
1064
1067
}
1065
1068
1066
- /* Camera is not capable of handling given format */
1067
- LOG_ERR ("Image format not supported\n" );
1068
- return - ENOTSUP ;
1069
+ return 0 ;
1069
1070
}
1070
1071
1071
1072
static int gc2145_get_fmt (const struct device * dev , enum video_endpoint_id ep ,
0 commit comments