|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, tinyVision.ai Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_VIDEO_COMMON_H |
| 8 | +#define ZEPHYR_INCLUDE_VIDEO_COMMON_H |
| 9 | + |
| 10 | +/** |
| 11 | + * @brief Provide the minimum/maximum/default integer value depending on the CID. |
| 12 | + * |
| 13 | + * Video CIDs can contain sub-operations. This function facilitates |
| 14 | + * implementation of video controls in the drivers by handling these |
| 15 | + * the range-related CIDs. |
| 16 | + * |
| 17 | + * @param cid The Video Control ID which contains the operation. |
| 18 | + * @param value The value, selected among @p min, @p max and @p def. |
| 19 | + * @param min The minimum value returned if the CID requested it. |
| 20 | + * @param max The maximum value returned if the CID requested it. |
| 21 | + * @param def The default value returned if the CID requested it. |
| 22 | + * |
| 23 | + * @return 0 if the operation was regarding a range CID and the value could |
| 24 | + * be set. In which case, there is nothing else to do than returning 0. |
| 25 | + * @return 1 if the operation is not for the range, but the current value, |
| 26 | + * in which case it is the duty of the driver to query the current |
| 27 | + * value to the hardware |
| 28 | + * @return A negative error code if an error occurred. |
| 29 | + * |
| 30 | + * @{ |
| 31 | + */ |
| 32 | + |
| 33 | +/** Signed integer version */ |
| 34 | +int video_get_range_int(unsigned int cid, int *value, int min, int max, int def); |
| 35 | + |
| 36 | +/** Signed 64-bit version */ |
| 37 | +int video_get_range_int64(unsigned int cid, int64_t *value, int64_t min, int64_t max, int64_t def); |
| 38 | + |
| 39 | +/** |
| 40 | + * @} |
| 41 | + */ |
| 42 | + |
| 43 | +/** |
| 44 | + * @brief Check if the integer value is within range for this CID. |
| 45 | + * |
| 46 | + * Before setting a video control, a driver might be interested in checking |
| 47 | + * if it is within a valid range. This function facilitates it by reusing the |
| 48 | + * video_get_ctrl() API using @c VIDEO_CTRL_GET_MIN and @c VIDEO_CTRL_GET_MAX |
| 49 | + * to validate the input. |
| 50 | + * |
| 51 | + * @param dev The video device to query to learn about the min and max. |
| 52 | + * @param cid The CID for which to check the range. |
| 53 | + * @param value The integer value that must be matched against the range. |
| 54 | + * |
| 55 | + * @{ |
| 56 | + */ |
| 57 | + |
| 58 | +/** Signed integer version */ |
| 59 | +int video_check_range_int(const struct device *dev, unsigned int cid, int value); |
| 60 | + |
| 61 | +/** Signed 64-bit version */ |
| 62 | +int video_check_range_int64(const struct device *dev, unsigned int cid, int64_t value); |
| 63 | + |
| 64 | +/** |
| 65 | + * @} |
| 66 | + */ |
| 67 | + |
| 68 | +#endif /* ZEPHYR_INCLUDE_VIDEO_COMMON_H */ |
0 commit comments