-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement video control framework #82158
base: main
Are you sure you want to change the base?
Changes from 1 commit
6fc1d3e
8b3c3c5
b98753e
4080680
0fe00c7
a7ea463
81be3e1
356e98b
1583d64
62695e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2024 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "video_device.h" | ||
|
||
#include <zephyr/logging/log.h> | ||
|
||
LOG_MODULE_REGISTER(video_device, CONFIG_VIDEO_LOG_LEVEL); | ||
|
||
#define VIDEO_NUM_DEVICES 256 | ||
|
||
static struct video_device *video_devices[VIDEO_NUM_DEVICES]; | ||
|
||
static bool video_is_vdev_registered(struct video_device *vdev) | ||
{ | ||
for (uint8_t i = 0; i < VIDEO_NUM_DEVICES; ++i) { | ||
if (!video_devices[i] && video_devices[i] == vdev) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
int video_register_vdev(struct video_device *vdev, const struct device *dev) | ||
{ | ||
uint8_t i; | ||
|
||
if (!vdev) { | ||
return -EINVAL; | ||
} | ||
|
||
if (video_is_vdev_registered(vdev)) { | ||
LOG_ERR("Video device %s is already registered at index %d", vdev->dev->name, | ||
vdev->ind); | ||
return -EALREADY; | ||
} | ||
|
||
vdev->dev = dev; | ||
|
||
for (i = 0; i < VIDEO_NUM_DEVICES; ++i) { | ||
if (!video_devices[i]) { | ||
video_devices[i] = vdev; | ||
vdev->ind = i; | ||
break; | ||
} | ||
} | ||
|
||
if (i == VIDEO_NUM_DEVICES) { | ||
LOG_ERR("No space left to register a new video device"); | ||
vdev->ind = -1; | ||
return -ENOSPC; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void video_unregister_vdev(struct video_device *vdev) | ||
{ | ||
if (!video_is_vdev_registered(vdev)) { | ||
LOG_ERR("Video device %s, index = %d is not registered", vdev->dev->name, | ||
vdev->ind); | ||
return; | ||
} | ||
|
||
video_devices[vdev->ind] = NULL; | ||
vdev->ind = -1; | ||
} | ||
|
||
struct video_device *video_find_vdev(const struct device *dev) | ||
{ | ||
for (uint8_t i = 0; i < VIDEO_NUM_DEVICES; ++i) { | ||
if (video_devices[i] != NULL && video_devices[i]->dev == dev) { | ||
return video_devices[i]; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef ZEPHYR_INCLUDE_VIDEO_DEVICE_H_ | ||
#define ZEPHYR_INCLUDE_VIDEO_DEVICE_H_ | ||
|
||
#include <zephyr/device.h> | ||
|
||
struct video_device { | ||
int ind; | ||
const struct device *dev; | ||
}; | ||
|
||
int video_register_vdev(struct video_device *vdev, const struct device *dev); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could it simply be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the naming pattern with the prefix |
||
|
||
void video_unregister_vdev(struct video_device *vdev); | ||
|
||
struct video_device *video_find_vdev(const struct device *dev); | ||
|
||
#endif /* ZEPHYR_INCLUDE_VIDEO_DEVICE_H_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as here, I think this can be removed altogether if it is possible to have a
vdata = dev->data
pointer.