Skip to content

Commit 0c1e2c9

Browse files
ngphibangkartben
authored andcommitted
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 0b090fa commit 0c1e2c9

File tree

17 files changed

+39
-31
lines changed

17 files changed

+39
-31
lines changed

drivers/video/gc2145.c

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

11881187
ret = gc2145_set_fmt(dev, &fmt);
11891188
if (ret) {

drivers/video/mt9m114.c

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

569568
ret = mt9m114_set_fmt(dev, &fmt);
570569
if (ret) {

drivers/video/ov2640.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,6 @@ static int ov2640_init(const struct device *dev)
10321032
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
10331033
fmt.width = SVGA_HSIZE;
10341034
fmt.height = SVGA_VSIZE;
1035-
fmt.pitch = SVGA_HSIZE * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
10361035
ret = ov2640_set_fmt(dev, &fmt);
10371036
if (ret) {
10381037
LOG_ERR("Unable to configure default format");

drivers/video/ov5640.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,6 @@ static int ov5640_init(const struct device *dev)
14331433
fmt.width = 1280;
14341434
fmt.height = 720;
14351435
}
1436-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
14371436
ret = ov5640_set_fmt(dev, &fmt);
14381437
if (ret) {
14391438
LOG_ERR("Unable to configure default format");

drivers/video/ov7670.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ static int ov7670_init(const struct device *dev)
554554
fmt.pixelformat = VIDEO_PIX_FMT_YUYV;
555555
fmt.width = 640;
556556
fmt.height = 480;
557-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
558557
ret = ov7670_set_fmt(dev, &fmt);
559558
if (ret < 0) {
560559
return ret;

drivers/video/ov7725.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ static int ov7725_init(const struct device *dev)
592592
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
593593
fmt.width = 640;
594594
fmt.height = 480;
595-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
596595
ret = ov7725_set_fmt(dev, &fmt);
597596
if (ret) {
598597
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
@@ -368,7 +368,6 @@ int emul_imager_init(const struct device *dev)
368368
fmt.pixelformat = fmts[0].pixelformat;
369369
fmt.width = fmts[0].width_min;
370370
fmt.height = fmts[0].height_min;
371-
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
372371

373372
ret = emul_imager_set_fmt(dev, &fmt);
374373
if (ret < 0) {

drivers/video/video_emul_rx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ static int emul_rx_set_fmt(const struct device *const dev, struct video_format *
6767
}
6868

6969
/* Cache the format selected locally to use it for getting the size of the buffer */
70+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
7071
data->fmt = *fmt;
72+
7173
return 0;
7274
}
7375

@@ -216,6 +218,9 @@ int emul_rx_init(const struct device *dev)
216218
return ret;
217219
}
218220

221+
data->fmt.pitch =
222+
data->fmt.width * video_bits_per_pixel(data->fmt.pixelformat) / BITS_PER_BYTE;
223+
219224
k_fifo_init(&data->fifo_in);
220225
k_fifo_init(&data->fifo_out);
221226
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
@@ -269,21 +269,31 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
269269
return ret;
270270
}
271271

272+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
273+
272274
return 0;
273275
}
274276

275277
static int video_esp32_set_fmt(const struct device *dev, struct video_format *fmt)
276278
{
277279
const struct video_esp32_config *cfg = dev->config;
278280
struct video_esp32_data *data = dev->data;
281+
int ret;
279282

280283
if (fmt == NULL) {
281284
return -EINVAL;
282285
}
283286

287+
ret = video_set_format(cfg->source_dev, fmt);
288+
if (ret < 0) {
289+
return ret;
290+
}
291+
292+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
293+
284294
data->video_format = *fmt;
285295

286-
return video_set_format(cfg->source_dev, fmt);
296+
return 0;
287297
}
288298

289299
static int video_esp32_enqueue(const struct device *dev, struct video_buffer *vbuf)

drivers/video/video_mcux_csi.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,11 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
133133
{
134134
const struct video_mcux_csi_config *config = dev->config;
135135
struct video_mcux_csi_data *data = dev->data;
136-
unsigned int bpp = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
137136
status_t ret;
138137
struct video_format format = *fmt;
139138

140-
if (bpp == 0) {
141-
return -EINVAL;
142-
}
143-
144-
data->csi_config.bytesPerPixel = bpp;
145-
data->csi_config.linePitch_Bytes = fmt->pitch;
139+
data->csi_config.bytesPerPixel = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
140+
data->csi_config.linePitch_Bytes = fmt->width * data->csi_config.bytesPerPixel;
146141
#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX)
147142
if (fmt->pixelformat != VIDEO_PIX_FMT_XRGB32 && fmt->pixelformat != VIDEO_PIX_FMT_XYUV32) {
148143
return -ENOTSUP;
@@ -172,6 +167,8 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
172167
return -EIO;
173168
}
174169

170+
fmt->pitch = data->csi_config.linePitch_Bytes;
171+
175172
return 0;
176173
}
177174

0 commit comments

Comments
 (0)