@@ -135,4 +135,126 @@ int video_read_cci_reg(const struct i2c_dt_spec *i2c, uint32_t reg_addr, uint32_
135135 */
136136int video_write_cci_multi (const struct i2c_dt_spec * i2c , const struct video_reg * regs );
137137
138+ /** @} */
139+
140+ /**
141+ * @defgroup video_imager Video Imager (image sensor) shared implementation
142+ *
143+ * This API is targeting image sensor driver developers.
144+ *
145+ * It provides a common implementation that only requires implementing a table of
146+ * @ref video_imager_mode that lists the various resolution, frame rates and associated I2C
147+ * configuration registers.
148+ *
149+ * The @c video_imager_... functions can be submitted directly to the @rev video_api.
150+ * If a driver also needs to do extra work before or after applying a mode, it is possible
151+ * to provide a custom wrapper or skip these default implementation altogether.
152+ *
153+ * @{
154+ */
155+
156+ /**
157+ * @brief Table entry for an imaging mode of the sensor device.
158+ *
159+ * AA mode can be applied to an imager to configure a particular framerate, resolution, and pixel
160+ * format. The index of the table of modes is meant to match the index of the table of formats.
161+ */
162+ struct video_imager_mode {
163+ /* FPS for this mode */
164+ uint16_t fps ;
165+ /* Multiple lists of registers to allow sharing common sets of registers across modes. */
166+ const struct video_reg * regs [3 ];
167+ };
168+
169+ /**
170+ * @brief A video imager device is expected to have dev->data point to this structure.
171+ *
172+ * In order to support custom data structure, it is possible to store an extra pointer
173+ * in the dev->config struct. See existing drivers for an example.
174+ */
175+ struct video_imager_config {
176+ /** List of all formats supported by this sensor */
177+ const struct video_format_cap * fmts ;
178+ /** Array of modes tables, one table per format cap lislted by "fmts" */
179+ const struct video_imager_mode * * modes ;
180+ /** I2C device to write the registers to */
181+ struct i2c_dt_spec i2c ;
182+ /** Write a table of registers onto the device */
183+ int (* write_multi )(const struct i2c_dt_spec * i2c , const struct video_reg * regs );
184+ /** Reference to a ; */
185+ struct video_imager_data * data ;
186+ };
187+
188+ /**
189+ * @brief A video imager device is expected to have dev->data point to this structure.
190+ *
191+ * In order to support custom data structure, it is possible to store an extra pointer
192+ * in the dev->config struct. See existing drivers for an example.
193+ */
194+ struct video_imager_data {
195+ /** Index of the currently active format in both modes[] and fmts[] */
196+ int fmt_id ;
197+ /** Currently active video format */
198+ struct video_format fmt ;
199+ /** Currently active operating mode as defined above */
200+ const struct video_imager_mode * mode ;
201+ };
202+
203+ /**
204+ * @brief Initialize one row of a @struct video_format_cap with fixed width and height.
205+ *
206+ * The minimum and maximum are the same for both width and height fields.
207+ * @param
208+ */
209+ #define VIDEO_IMAGER_FORMAT_CAP (pixfmt , width , height ) \
210+ { \
211+ .width_min = (width), .width_max = (width), .width_step = 0, \
212+ .height_min = (height), .height_max = (height), .height_step = 0, \
213+ .pixelformat = (pixfmt), \
214+ }
215+
216+ /**
217+ * @brief Set the operating mode of the imager as defined in @ref video_imager_mode.
218+ *
219+ * If the default immplementation for the video API are used, there is no need to explicitly call
220+ * this function in the image sensor driver.
221+ *
222+ * @param dev Device that has a struct video_imager in @c dev->data.
223+ * @param mode The mode to apply to the image sensor.
224+ * @return 0 if successful, or negative error number otherwise.
225+ */
226+ int video_imager_set_mode (const struct device * dev , const struct video_imager_mode * mode );
227+
228+ /** @brief Default implementation for image drivers frame interval selection */
229+ int video_imager_set_frmival (const struct device * dev , enum video_endpoint_id ep ,
230+ struct video_frmival * frmival );
231+ /** @brief Default implementation for image drivers frame interval query */
232+ int video_imager_get_frmival (const struct device * dev , enum video_endpoint_id ep ,
233+ struct video_frmival * frmival );
234+ /** @brief Default implementation for image drivers frame interval enumeration */
235+ int video_imager_enum_frmival (const struct device * dev , enum video_endpoint_id ep ,
236+ struct video_frmival_enum * fie );
237+ /** @brief Default implementation for image drivers format selection */
238+ int video_imager_set_fmt (const struct device * const dev , enum video_endpoint_id ep ,
239+ struct video_format * fmt );
240+ /** @brief Default implementation for image drivers format query */
241+ int video_imager_get_fmt (const struct device * dev , enum video_endpoint_id ep ,
242+ struct video_format * fmt );
243+ /** @brief Default implementation for image drivers format capabilities */
244+ int video_imager_get_caps (const struct device * dev , enum video_endpoint_id ep ,
245+ struct video_caps * caps );
246+
247+ /**
248+ * Initialize an imager by loading init_regs onto the device, and setting the default format.
249+ *
250+ * @param dev Device that has a struct video_imager in @c dev->data.
251+ * @param init_regs If non-NULL, table of registers to configure at init.
252+ * @param default_fmt_idx Default format index to apply at init.
253+ * @return 0 if successful, or negative error number otherwise.
254+ */
255+ int video_imager_init (const struct device * dev , const struct video_reg * init_regs ,
256+ int default_fmt_idx );
257+
258+ /** @} */
259+
138260#endif /* ZEPHYR_DRIVERS_VIDEO_COMMON_H_ */
0 commit comments