Skip to content

Commit 78e6214

Browse files
committed
drivers: video: Move format pitch setting to bridge drivers
The format pitch (bytesperline) field is typically set by the bridge drivers, i.e. DMA, ISP drivers who actually handle the memory as they know exactly the memory layout constraints. Application just set the pixel format and resolution and must always read back this field to see what the driver actually sets (to allocate buffers for example). Also, drop format pitch setting in sensor drivers as this is not needed. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 4ad088e commit 78e6214

File tree

17 files changed

+44
-28
lines changed

17 files changed

+44
-28
lines changed

drivers/video/gc2145.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,6 @@ static int gc2145_init(const struct device *dev)
11861186
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
11871187
fmt.width = RESOLUTION_QVGA_W;
11881188
fmt.height = RESOLUTION_QVGA_H;
1189-
fmt.pitch = RESOLUTION_QVGA_W * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
11901189

11911190
ret = gc2145_set_fmt(dev, VIDEO_EP_OUT, &fmt);
11921191
if (ret) {

drivers/video/mt9m114.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ static int mt9m114_init(const struct device *dev)
567567
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
568568
fmt.width = 480;
569569
fmt.height = 272;
570-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
571570

572571
ret = mt9m114_set_fmt(dev, VIDEO_EP_OUT, &fmt);
573572
if (ret) {

drivers/video/ov2640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static int ov2640_init(const struct device *dev)
10361036
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
10371037
fmt.width = SVGA_HSIZE;
10381038
fmt.height = SVGA_VSIZE;
1039-
fmt.pitch = SVGA_HSIZE * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
1039+
10401040
ret = ov2640_set_fmt(dev, VIDEO_EP_OUT, &fmt);
10411041
if (ret) {
10421042
LOG_ERR("Unable to configure default format");

drivers/video/ov5640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ static int ov5640_init(const struct device *dev)
14391439
fmt.width = 1280;
14401440
fmt.height = 720;
14411441
}
1442-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
1442+
14431443
ret = ov5640_set_fmt(dev, VIDEO_EP_OUT, &fmt);
14441444
if (ret) {
14451445
LOG_ERR("Unable to configure default format");

drivers/video/ov7670.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int ov7670_init(const struct device *dev)
557557
fmt.pixelformat = VIDEO_PIX_FMT_YUYV;
558558
fmt.width = 640;
559559
fmt.height = 480;
560-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
560+
561561
ret = ov7670_set_fmt(dev, VIDEO_EP_OUT, &fmt);
562562
if (ret < 0) {
563563
return ret;

drivers/video/ov7725.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static int ov7725_init(const struct device *dev)
598598
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
599599
fmt.width = 640;
600600
fmt.height = 480;
601-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
601+
602602
ret = ov7725_set_fmt(dev, VIDEO_EP_OUT, &fmt);
603603
if (ret) {
604604
LOG_ERR("Unable to configure default format");

drivers/video/video_emul_imager.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ int emul_imager_init(const struct device *dev)
398398
fmt.pixelformat = fmts[0].pixelformat;
399399
fmt.width = fmts[0].width_min;
400400
fmt.height = fmts[0].height_min;
401-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
402401

403402
ret = emul_imager_set_fmt(dev, VIDEO_EP_OUT, &fmt);
404403
if (ret < 0) {

drivers/video/video_emul_rx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ static int emul_rx_set_fmt(const struct device *const dev, enum video_endpoint_i
8888
}
8989

9090
/* Cache the format selected locally to use it for getting the size of the buffer */
91+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
9192
data->fmt = *fmt;
93+
9294
return 0;
9395
}
9496

@@ -262,6 +264,9 @@ int emul_rx_init(const struct device *dev)
262264
return ret;
263265
}
264266

267+
data->fmt.pitch =
268+
data->fmt.width * video_bits_per_pixel(data->fmt.pixelformat) / BITS_PER_BYTE;
269+
265270
k_fifo_init(&data->fifo_in);
266271
k_fifo_init(&data->fifo_out);
267272
k_work_init(&data->work, &emul_rx_worker);

drivers/video/video_esp32_dvp.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ static int video_esp32_get_fmt(const struct device *dev, enum video_endpoint_id
275275
return ret;
276276
}
277277

278+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
279+
278280
return 0;
279281
}
280282

@@ -283,14 +285,22 @@ static int video_esp32_set_fmt(const struct device *dev, enum video_endpoint_id
283285
{
284286
const struct video_esp32_config *cfg = dev->config;
285287
struct video_esp32_data *data = dev->data;
288+
int ret;
286289

287290
if (fmt == NULL || ep != VIDEO_EP_OUT) {
288291
return -EINVAL;
289292
}
290293

294+
ret = video_set_format(cfg->source_dev, ep, fmt);
295+
if (ret) {
296+
return ret;
297+
}
298+
299+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
300+
291301
data->video_format = *fmt;
292302

293-
return video_set_format(cfg->source_dev, ep, fmt);
303+
return 0;
294304
}
295305

296306
static int video_esp32_enqueue(const struct device *dev, enum video_endpoint_id ep,

drivers/video/video_mcux_csi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,15 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_
134134
{
135135
const struct video_mcux_csi_config *config = dev->config;
136136
struct video_mcux_csi_data *data = dev->data;
137-
unsigned int bpp = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
138137
status_t ret;
139138
struct video_format format = *fmt;
140139

141-
if (bpp == 0 || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) {
140+
if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) {
142141
return -EINVAL;
143142
}
144143

145-
data->csi_config.bytesPerPixel = bpp;
146-
data->csi_config.linePitch_Bytes = fmt->pitch;
144+
data->csi_config.bytesPerPixel = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
145+
data->csi_config.linePitch_Bytes = fmt->width * data->csi_config.bytesPerPixel;
147146
#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX)
148147
if (fmt->pixelformat != VIDEO_PIX_FMT_XRGB32 && fmt->pixelformat != VIDEO_PIX_FMT_XYUV32) {
149148
return -ENOTSUP;
@@ -173,6 +172,8 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_
173172
return -EIO;
174173
}
175174

175+
fmt->pitch = data->csi_config.linePitch_Bytes;
176+
176177
return 0;
177178
}
178179

0 commit comments

Comments
 (0)