123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- #ifndef ZEPHYR_INCLUDE_VIDEO_H_
- #define ZEPHYR_INCLUDE_VIDEO_H_
- #include <device.h>
- #include <stddef.h>
- #include <zephyr.h>
- #include <zephyr/types.h>
- #include <drivers/video-controls.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct video_format {
- uint32_t pixelformat;
- uint32_t width;
- uint32_t height;
- uint32_t pitch;
- };
- struct video_format_cap {
- uint32_t pixelformat;
- uint32_t width_min;
- uint32_t width_max;
- uint32_t height_min;
- uint32_t height_max;
- uint16_t width_step;
- uint16_t height_step;
- };
- struct video_caps {
- const struct video_format_cap *format_caps;
- uint8_t min_vbuf_count;
- };
- struct video_buffer {
- void *driver_data;
- uint8_t *buffer;
- uint32_t size;
- uint32_t bytesused;
- uint32_t timestamp;
- };
- enum video_endpoint_id {
- VIDEO_EP_NONE,
- VIDEO_EP_ANY,
- VIDEO_EP_IN,
- VIDEO_EP_OUT,
- };
- enum video_signal_result {
- VIDEO_BUF_DONE,
- VIDEO_BUF_ABORTED,
- VIDEO_BUF_ERROR,
- };
- typedef int (*video_api_set_format_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_format *fmt);
- typedef int (*video_api_get_format_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_format *fmt);
- typedef int (*video_api_enqueue_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_buffer *buf);
- typedef int (*video_api_dequeue_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_buffer **buf,
- k_timeout_t timeout);
- typedef int (*video_api_flush_t)(const struct device *dev,
- enum video_endpoint_id ep,
- bool cancel);
- typedef int (*video_api_stream_start_t)(const struct device *dev);
- typedef int (*video_api_stream_stop_t)(const struct device *dev);
- typedef int (*video_api_set_ctrl_t)(const struct device *dev,
- unsigned int cid,
- void *value);
- typedef int (*video_api_get_ctrl_t)(const struct device *dev,
- unsigned int cid,
- void *value);
- typedef int (*video_api_get_caps_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_caps *caps);
- typedef int (*video_api_set_signal_t)(const struct device *dev,
- enum video_endpoint_id ep,
- struct k_poll_signal *signal);
- struct video_driver_api {
-
- video_api_set_format_t set_format;
- video_api_get_format_t get_format;
- video_api_stream_start_t stream_start;
- video_api_stream_stop_t stream_stop;
- video_api_get_caps_t get_caps;
-
- video_api_enqueue_t enqueue;
- video_api_dequeue_t dequeue;
- video_api_flush_t flush;
- video_api_set_ctrl_t set_ctrl;
- video_api_set_ctrl_t get_ctrl;
- video_api_set_signal_t set_signal;
- };
- static inline int video_set_format(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_format *fmt)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->set_format == NULL) {
- return -ENOSYS;
- }
- return api->set_format(dev, ep, fmt);
- }
- static inline int video_get_format(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_format *fmt)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->get_format == NULL) {
- return -ENOSYS;
- }
- return api->get_format(dev, ep, fmt);
- }
- static inline int video_enqueue(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_buffer *buf)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->enqueue == NULL) {
- return -ENOSYS;
- }
- return api->enqueue(dev, ep, buf);
- }
- static inline int video_dequeue(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_buffer **buf,
- k_timeout_t timeout)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->dequeue == NULL) {
- return -ENOSYS;
- }
- return api->dequeue(dev, ep, buf, timeout);
- }
- static inline int video_flush(const struct device *dev,
- enum video_endpoint_id ep,
- bool cancel)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->flush == NULL) {
- return -ENOSYS;
- }
- return api->flush(dev, ep, cancel);
- }
- static inline int video_stream_start(const struct device *dev)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->stream_start == NULL) {
- return -ENOSYS;
- }
- return api->stream_start(dev);
- }
- static inline int video_stream_stop(const struct device *dev)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- int ret;
- if (api->stream_stop) {
- return -ENOSYS;
- }
- ret = api->stream_stop(dev);
- video_flush(dev, VIDEO_EP_ANY, true);
- return ret;
- }
- static inline int video_get_caps(const struct device *dev,
- enum video_endpoint_id ep,
- struct video_caps *caps)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->get_caps == NULL) {
- return -ENOSYS;
- }
- return api->get_caps(dev, ep, caps);
- }
- static inline int video_set_ctrl(const struct device *dev, unsigned int cid,
- void *value)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->set_ctrl == NULL) {
- return -ENOSYS;
- }
- return api->set_ctrl(dev, cid, value);
- }
- static inline int video_get_ctrl(const struct device *dev, unsigned int cid,
- void *value)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->get_ctrl == NULL) {
- return -ENOSYS;
- }
- return api->get_ctrl(dev, cid, value);
- }
- static inline int video_set_signal(const struct device *dev,
- enum video_endpoint_id ep,
- struct k_poll_signal *signal)
- {
- const struct video_driver_api *api =
- (const struct video_driver_api *)dev->api;
- if (api->set_signal == NULL) {
- return -ENOSYS;
- }
- return api->set_signal(dev, ep, signal);
- }
- struct video_buffer *video_buffer_alloc(size_t size);
- void video_buffer_release(struct video_buffer *buf);
- #define video_fourcc(a, b, c, d)\
- ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
- #define VIDEO_PIX_FMT_BGGR8 video_fourcc('B', 'G', 'G', 'R')
- #define VIDEO_PIX_FMT_GBRG8 video_fourcc('G', 'B', 'R', 'G')
- #define VIDEO_PIX_FMT_GRBG8 video_fourcc('G', 'R', 'B', 'G')
- #define VIDEO_PIX_FMT_RGGB8 video_fourcc('R', 'G', 'G', 'B')
- #define VIDEO_PIX_FMT_RGB565 video_fourcc('R', 'G', 'B', 'P')
- #define VIDEO_PIX_FMT_JPEG video_fourcc('J', 'P', 'E', 'G')
- #ifdef __cplusplus
- }
- #endif
- #endif
|