-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Camera branch #17394
Closed
Closed
Camera branch #17394
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f947d8
drivers/camera/image_sensor: Add image sensor framework
JunYangNXP 457518d
drivers/camera: Add camera framework to support camera drivers
JunYangNXP 42550ef
drivers/camera: support mt9m114 image sensor
JunYangNXP 37b136e
dts/mimxrt/csi: Support mimxrt CSI on dts
JunYangNXP 622f75a
drivers/camera: Add NXP i.MXRT CSI driver
JunYangNXP 8fe901e
samples/camera: add camera sample code
JunYangNXP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,6 @@ source "drivers/neural_net/Kconfig" | |
|
||
source "drivers/hwinfo/Kconfig" | ||
|
||
source "drivers/camera/Kconfig" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory_ifdef(CONFIG_MT9M114 mt9m114) | ||
add_subdirectory_ifdef(CONFIG_NXP_MCUX_CSI nxp_csi) | ||
|
||
zephyr_sources(camera_dev.c) | ||
zephyr_sources(image_sensor_dev.c) | ||
|
||
zephyr_sources_ifdef(CONFIG_USERSPACE camera_handlers.c) | ||
zephyr_sources_ifdef(CONFIG_USERSPACE image_sensor_handlers.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Kconfig - Camera drivers | ||
|
||
# | ||
# Copyright (c) 2019 NXP Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
menuconfig CAMERA | ||
bool "Camera Drivers" | ||
help | ||
Enable camera drivers | ||
|
||
if CAMERA | ||
|
||
module = CAMERA | ||
module-str = camera | ||
|
||
config CAMERA_DISPLAY_DEV_NAME | ||
string "Camera display device name" | ||
default "CAMERA DISPLAY" | ||
help | ||
Name of the display device to display camera. | ||
|
||
config IMAGE_SENSOR_INIT_PRIO | ||
int "Image sensor initalization priority level" | ||
default 70 | ||
range 70 80 | ||
help | ||
Image sensor initialization priority level. | ||
This number tells how early in the boot | ||
the image sensor driver and image sensor vendor | ||
driver are initialized. | ||
|
||
config CAMERA_INIT_PRIO | ||
int "Camera initalization priority level" | ||
default 81 | ||
range 81 90 | ||
help | ||
Camera initialization priority level. | ||
This number tells how early in the boot | ||
the camera vendor drivers are initialized. | ||
Camera initalization depneds on image sensors, | ||
so CAMERA_INIT_PRIO must be greater than | ||
IMAGE_SENSOR_INIT_PRIO. | ||
|
||
menuconfig NXP_MCUX_CSI | ||
bool "NXP i.MXRT cmos sensor interface" | ||
depends on HAS_MCUX_CSI | ||
help | ||
Enable NXP i.MXRT cmos sensor driver. | ||
|
||
source "drivers/camera/nxp_csi/Kconfig" | ||
|
||
menuconfig MT9M114 | ||
bool "MT9M114 image sensor" | ||
depends on I2C | ||
default y | ||
help | ||
Enable driver for the MT9M114 image sensor. | ||
|
||
source "drivers/camera/mt9m114/Kconfig" | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (c) 2019 NXP Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <drivers/camera_drv.h> | ||
#define LOG_LEVEL LOG_LEVEL_ERR | ||
#include <logging/log.h> | ||
#define CAMERA_DEV_DBG | ||
|
||
#undef LOG_ERR | ||
#define LOG_ERR printk | ||
|
||
#ifdef CAMERA_DEV_DBG | ||
#undef LOG_INF | ||
#define LOG_INF printk | ||
#endif | ||
|
||
static int z_camera_num; | ||
static struct device *z_camera_dev[CAMERA_MAX_NUMBER]; | ||
|
||
#define CAMERA_DRV_DATA_MAX_SIZE 1024 | ||
static u8_t z_camera_drv_data[CAMERA_MAX_NUMBER * | ||
CAMERA_DRV_DATA_MAX_SIZE] __aligned(64); | ||
|
||
static K_MUTEX_DEFINE(z_camera_lock); | ||
|
||
int camera_dev_get_cap(struct device *cam_dev, | ||
struct camera_capability *cap) | ||
{ | ||
struct camera_driver_data *data = cam_dev->driver_data; | ||
|
||
memcpy((char *)cap, (char *)&data->cap, | ||
sizeof(struct camera_capability)); | ||
|
||
return 0; | ||
} | ||
|
||
int camera_dev_configure(struct device *cam_dev, | ||
struct camera_fb_cfg *fb_cfg) | ||
{ | ||
struct camera_driver_data *data = cam_dev->driver_data; | ||
|
||
if (fb_cfg->cfg_mode == CAMERA_DEFAULT_CFG) { | ||
memcpy((char *)&fb_cfg->fb_attr, | ||
(char *)&data->fb_attr, | ||
sizeof(struct camera_fb_attr)); | ||
} else { | ||
memcpy((char *)&data->fb_attr, | ||
(char *)&fb_cfg->fb_attr, | ||
sizeof(struct camera_fb_attr)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int camera_dev_register(struct device *dev) | ||
{ | ||
(void)k_mutex_lock(&z_camera_lock, K_FOREVER); | ||
|
||
if (z_camera_num < CAMERA_MAX_NUMBER) { | ||
z_camera_dev[z_camera_num] = dev; | ||
z_camera_num++; | ||
|
||
k_mutex_unlock(&z_camera_lock); | ||
|
||
return 0; | ||
} | ||
|
||
k_mutex_unlock(&z_camera_lock); | ||
|
||
return -ENOSPC; | ||
} | ||
|
||
struct camera_driver_data *camera_drv_data_alloc( | ||
u32_t priv_size, enum camera_id id, bool clear) | ||
{ | ||
struct camera_driver_data *data; | ||
|
||
if ((priv_size + sizeof(struct camera_driver_data)) > | ||
CAMERA_DRV_DATA_MAX_SIZE) { | ||
|
||
LOG_ERR("Camera data alloc size %d exceeds max size\r\n", | ||
(int)(CAMERA_DRV_DATA_MAX_SIZE - | ||
sizeof(struct camera_driver_data))); | ||
return 0; | ||
} | ||
|
||
if (id != CAMERA_PRIMARY_ID && | ||
id != CAMERA_SECONDARY_ID) { | ||
|
||
LOG_ERR("Camera data alloc id %d is illegal\r\n", id); | ||
return 0; | ||
} | ||
|
||
data = (struct camera_driver_data *) | ||
&z_camera_drv_data[(id - CAMERA_PRIMARY_ID) * | ||
CAMERA_DRV_DATA_MAX_SIZE]; | ||
if (clear) { | ||
memset((char *)data, 0, sizeof(struct camera_driver_data)); | ||
} | ||
data->id = id; | ||
|
||
return data; | ||
} | ||
|
||
static struct device *camera_get_by_id(enum camera_id id) | ||
{ | ||
int i; | ||
struct device *dev; | ||
struct camera_driver_data *camera_data; | ||
|
||
(void)k_mutex_lock(&z_camera_lock, K_FOREVER); | ||
|
||
for (i = 0; i < z_camera_num; i++) { | ||
dev = z_camera_dev[i]; | ||
camera_data = dev->driver_data; | ||
if (camera_data->id == id) { | ||
|
||
k_mutex_unlock(&z_camera_lock); | ||
|
||
return dev; | ||
} | ||
} | ||
|
||
k_mutex_unlock(&z_camera_lock); | ||
|
||
return 0; | ||
} | ||
|
||
struct device *camera_get_primary(void) | ||
{ | ||
return camera_get_by_id(CAMERA_PRIMARY_ID); | ||
} | ||
|
||
struct device *camera_get_secondary(void) | ||
{ | ||
return camera_get_by_id(CAMERA_SECONDARY_ID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2019 NXP Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <drivers/camera.h> | ||
#include <drivers/display.h> | ||
#include <syscall_handler.h> | ||
|
||
Z_SYSCALL_HANDLER(camera_power, cam_dev, power) | ||
{ | ||
return z_impl_camera_power((struct device *)cam_dev, | ||
(bool)power); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_get_cap, cam_dev, cap) | ||
{ | ||
return z_impl_camera_get_cap((struct device *)cam_dev, | ||
(struct camera_capability *)cap); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_reset, cam_dev) | ||
{ | ||
return z_impl_camera_reset((struct device *)cam_dev); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_configure, cam_dev, | ||
width, height, pixformat) | ||
{ | ||
return z_impl_camera_configure((struct device *)cam_dev, | ||
(u16_t)width, (u16_t)height, | ||
(enum display_pixel_format)pixformat); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_start, cam_dev, | ||
mode, bufs, buf_num, cb) | ||
{ | ||
return z_impl_camera_start((struct device *)cam_dev, | ||
(enum camera_mode)mode, (void **)bufs, (u8_t)buf_num, | ||
(camera_capture_cb)cb); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_acquire_fb, cam_dev, | ||
fb, timeout) | ||
{ | ||
return z_impl_camera_acquire_fb((struct device *)cam_dev, | ||
(void **)fb, (s32_t)timeout); | ||
} | ||
|
||
Z_SYSCALL_HANDLER(camera_release_fb, cam_dev, | ||
fb) | ||
{ | ||
return z_impl_camera_release_fb((struct device *)cam_dev, | ||
(void *)fb); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be put under a boolean option, now it looks like a camera requires a display.
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.
this makes sense and I am trying add.