Add camera driver and examples for edu-riscv64 from Wu_zheng

it is OK
This commit is contained in:
xuedongliang
2022-11-25 10:25:38 +08:00
51 changed files with 2594 additions and 270 deletions
+6
View File
@@ -163,3 +163,9 @@ if BSP_USING_DAC
bool "Using DAC bus drivers"
default n
endif
if BSP_USING_CAMERA
config RESOURCES_CAMERA
bool "Using Camera bus drivers"
default n
endif
+4
View File
@@ -65,4 +65,8 @@ ifeq ($(CONFIG_RESOURCES_DAC),y)
SRC_DIR += dac
endif
ifeq ($(CONFIG_RESOURCES_CAMERA),y)
SRC_DIR += camera
endif
include $(KERNEL_ROOT)/compiler.mk
@@ -0,0 +1,5 @@
SRC_FILES += dev_camera.c drv_camera.c bus_camera.c
include $(KERNEL_ROOT)/compiler.mk
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file bus_camera.c
* @brief register camera bus function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#include <bus_camera.h>
#include <dev_camera.h>
/*Register the CAMERA BUS*/
int CameraBusInit(struct CameraBus *camera_bus, const char *bus_name)
{
NULL_PARAM_CHECK(camera_bus);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
if (BUS_INSTALL != camera_bus->bus.bus_state) {
strncpy(camera_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
camera_bus->bus.bus_type = TYPE_CAMERA_BUS;
camera_bus->bus.bus_state = BUS_INSTALL;
camera_bus->bus.private_data = camera_bus->private_data;
ret = BusRegister(&camera_bus->bus);
if (EOK != ret) {
KPrintf("CameraBusInit BusRegister error %u\n", ret);
return ret;
}
} else {
KPrintf("CameraBusInit BusRegister bus has been register state%u\n", camera_bus->bus.bus_state);
}
return ret;
}
/*Register the CAMERA Driver*/
int CameraDriverInit(struct CameraDriver *camera_driver, const char *driver_name)
{
NULL_PARAM_CHECK(camera_driver);
NULL_PARAM_CHECK(driver_name);
x_err_t ret = EOK;
if (DRV_INSTALL != camera_driver->driver.driver_state) {
camera_driver->driver.driver_type = TYPE_CAMERA_DRV;
camera_driver->driver.driver_state = DRV_INSTALL;
strncpy(camera_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
camera_driver->driver.private_data = camera_driver->private_data;
camera_driver->driver.configure = camera_driver->configure;
ret = CameraDriverRegister(&camera_driver->driver);
if (EOK != ret) {
KPrintf("CameraDriverInit DriverRegister error %u\n", ret);
return ret;
}
} else {
KPrintf("CameraDriverInit DriverRegister driver has been register state%u\n", camera_driver->driver.driver_state);
}
return ret;
}
/*Release the CAMERA device*/
int CameraReleaseBus(struct CameraBus *camera_bus)
{
NULL_PARAM_CHECK(camera_bus);
return BusRelease(&camera_bus->bus);
}
/*Register the CAMERA Driver to the CAMERA BUS*/
int CameraDriverAttachToBus(const char *drv_name, const char *bus_name)
{
NULL_PARAM_CHECK(drv_name);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
struct Bus *bus;
struct Driver *driver;
bus = BusFind(bus_name);
if (NONE == bus) {
KPrintf("CameraDriverAttachToBus find camera bus error!name %s\n", bus_name);
return ERROR;
}
if (TYPE_CAMERA_BUS == bus->bus_type) {
driver = CameraDriverFind(drv_name, TYPE_CAMERA_DRV);
if (NONE == driver) {
KPrintf("CameraDriverAttachToBus find camera driver error!name %s\n", drv_name);
return ERROR;
}
if (TYPE_CAMERA_DRV == driver->driver_type) {
ret = DriverRegisterToBus(bus, driver);
if (EOK != ret) {
KPrintf("CameraDriverAttachToBus DriverRegisterToBus error %u\n", ret);
return ERROR;
}
}
}
return ret;
}
@@ -0,0 +1,200 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2006-03-13 bernard first version
* 2012-05-15 lgnq modified according bernard's implementation.
* 2012-05-28 bernard code cleanup
* 2012-11-23 bernard fix compiler warning.
* 2013-02-20 bernard use RT_CAMERA_RB_BUFSZ to define
* the size of ring buffer.
* 2014-07-10 bernard rewrite camera framework
* 2014-12-31 bernard use open_flag for poll_tx stream mode.
* 2015-05-19 Quintin fix DMA tx mod tx_dma->activated flag !=RT_FALSE BUG
* in open function.
* 2015-11-10 bernard fix the poll rx issue when there is no data.
* 2016-05-10 armink add fifo mode to DMA rx when camera->config.bufsz != 0.
* 2017-01-19 aubr.cool prevent change camera rx bufsz when camera is opened.
* 2017-11-07 JasonJia fix data bits error issue when using tcsetattr.
* 2017-11-15 JasonJia fix poll rx issue when data is full.
* add TCFLSH and FIONREAD support.
* 2018-12-08 Ernest Chen add DMA choice
* 2020-09-14 WillianChan add a line feed to the carriage return character
* when using interrupt tx
*/
/**
* @file dev_camera.c
* @brief register camera dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
/*************************************************
File name: dev_camera.c
Description: support camera dev INT and DMA configure、transfer data
Others: take RT-Thread v4.0.2/components/driver/camera/camera.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-24
Author: AIIT XUOS Lab
Modification:
1. support camera dev register, configure, write and read
2. add bus driver framework support, include INT and DMA mode
*************************************************/
#include <bus_camera.h>
#include <dev_camera.h>
static DoubleLinklistType cameradev_linklist;
static uint32 CameraDevOpen(void *dev)
{
NULL_PARAM_CHECK(dev);
x_err_t ret = EOK;
struct CameraHardwareDevice *camera_dev = (struct CameraHardwareDevice *)dev;
ret = camera_dev->camera_dev_done->dev_open(dev);
return EOK;
}
static uint32 CameraDevClose(void *dev)
{
NULL_PARAM_CHECK(dev);
x_err_t ret = EOK;
struct CameraHardwareDevice *camera_dev = (struct CameraHardwareDevice *)dev;
ret = camera_dev->camera_dev_done->dev_close(dev);
return EOK;
}
static uint32 CameraDevWrite(void *dev, struct BusBlockWriteParam *write_param)
{
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(write_param);
x_err_t ret = EOK;
struct CameraHardwareDevice *camera_dev = (struct CameraHardwareDevice *)dev;
ret = camera_dev->camera_dev_done->dev_write(dev,write_param);
return ret;
}
static uint32 CameraDevRead(void *dev, struct BusBlockReadParam *read_param)
{
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param);
x_err_t ret = EOK;
struct CameraHardwareDevice *camera_dev = (struct CameraHardwareDevice *)dev;
ret = camera_dev->camera_dev_done->dev_read(dev,read_param);
return EOK;
}
static const struct HalDevDone dev_done =
{
.open = CameraDevOpen,
.close = CameraDevClose,
.write = CameraDevWrite,
.read = CameraDevRead,
};
/*Create the camera device linklist*/
static void CameraDeviceLinkInit()
{
InitDoubleLinkList(&cameradev_linklist);
}
HardwareDevType CameraDeviceFind(const char *dev_name, enum DevType dev_type)
{
NULL_PARAM_CHECK(dev_name);
struct HardwareDev *device = NONE;
DoubleLinklistType *node = NONE;
DoubleLinklistType *head = &cameradev_linklist;
for (node = head->node_next; node != head; node = node->node_next) {
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
if ((!strcmp(device->dev_name, dev_name)) && (dev_type == device->dev_type)) {
return device;
}
}
KPrintf("CameraDeviceFind cannot find the %s device.return NULL\n", dev_name);
return NONE;
}
int CameraDeviceRegister(struct CameraHardwareDevice *camera_device, void *camera_param, const char *device_name)
{
NULL_PARAM_CHECK(camera_device);
NULL_PARAM_CHECK(device_name);
x_err_t ret = EOK;
static x_bool dev_link_flag = RET_FALSE;
if (!dev_link_flag) {
CameraDeviceLinkInit();
dev_link_flag = RET_TRUE;
}
if (DEV_INSTALL != camera_device->haldev.dev_state) {
strncpy(camera_device->haldev.dev_name, device_name, NAME_NUM_MAX);
camera_device->haldev.dev_type = TYPE_CAMERA_DEV;
camera_device->haldev.dev_state = DEV_INSTALL;
camera_device->haldev.dev_done = (struct HalDevDone *)&dev_done;
DoubleLinkListInsertNodeAfter(&cameradev_linklist, &(camera_device->haldev.dev_link));
} else {
KPrintf("CameraDeviceRegister device has been register state%u\n", camera_device->haldev.dev_state);
}
return ret;
}
int CameraDeviceAttachToBus(const char *dev_name, const char *bus_name)
{
NULL_PARAM_CHECK(dev_name);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
struct Bus *bus;
struct HardwareDev *device;
bus = BusFind(bus_name);
if (NONE == bus) {
KPrintf("CameraDeviceAttachToBus find camera bus error!name %s\n", bus_name);
return ERROR;
}
if (TYPE_CAMERA_BUS == bus->bus_type) {
device = CameraDeviceFind(dev_name, TYPE_CAMERA_DEV);
if (NONE == device) {
KPrintf("CameraDeviceAttachToBus find camera device error!name %s\n", dev_name);
return ERROR;
}
if (TYPE_CAMERA_DEV == device->dev_type) {
ret = DeviceRegisterToBus(bus, device);
if (EOK != ret) {
KPrintf("CameraDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
return ERROR;
}
}
}
return EOK;
}
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file drv_camera.c
* @brief register camera drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#include <bus_camera.h>
#include <dev_camera.h>
static DoubleLinklistType camera_drv_linklist;
/*Create the driver linklist*/
static void CameraDrvLinkInit()
{
InitDoubleLinkList(&camera_drv_linklist);
}
DriverType CameraDriverFind(const char *drv_name, enum DriverType_e drv_type)
{
NULL_PARAM_CHECK(drv_name);
struct Driver *driver = NONE;
DoubleLinklistType *node = NONE;
DoubleLinklistType *head = &camera_drv_linklist;
for (node = head->node_next; node != head; node = node->node_next) {
driver = SYS_DOUBLE_LINKLIST_ENTRY(node, struct Driver, driver_link);
if ((!strcmp(driver->drv_name, drv_name)) && (drv_type == driver->driver_type)) {
return driver;
}
}
KPrintf("CameraDriverFind cannot find the %s driver.return NULL\n", drv_name);
return NONE;
}
int CameraDriverRegister(struct Driver *driver)
{
NULL_PARAM_CHECK(driver);
x_err_t ret = EOK;
static x_bool driver_link_flag = RET_FALSE;
if (!driver_link_flag) {
CameraDrvLinkInit();
driver_link_flag = RET_TRUE;
}
DoubleLinkListInsertNodeAfter(&camera_drv_linklist, &(driver->driver_link));
return ret;
}
@@ -54,6 +54,7 @@ enum BusType_e
TYPE_SERIAL_BUS,
TYPE_ADC_BUS,
TYPE_DAC_BUS,
TYPE_CAMERA_BUS,
TYPE_BUS_END,
};
@@ -80,6 +81,7 @@ enum DevType
TYPE_SERIAL_DEV,
TYPE_ADC_DEV,
TYPE_DAC_DEV,
TYPE_CAMERA_DEV,
TYPE_DEV_END,
};
@@ -106,6 +108,7 @@ enum DriverType_e
TYPE_SERIAL_DRV,
TYPE_ADC_DRV,
TYPE_DAC_DRV,
TYPE_CAMERA_DRV,
TYPE_DRV_END,
};
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file bus_camera.h
* @brief define camera bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-11-15
*/
#ifndef BUS_CAMERA_H
#define BUS_CAMERA_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct CameraDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
void *private_data;
};
struct CameraBus
{
struct Bus bus;
void *private_data;
};
/*Register the CAMERA bus*/
int CameraBusInit(struct CameraBus *camera_bus, const char *bus_name);
/*Register the CAMERA driver*/
int CameraDriverInit(struct CameraDriver *camera_driver, const char *driver_name);
/*Release the CAMERA device*/
int CameraReleaseBus(struct CameraBus *camera_bus);
/*Register the CAMERA driver to the CAMERA bus*/
int CameraDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int CameraDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType CameraDriverFind(const char *drv_name, enum DriverType_e drv_type);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file dev_camera.h
* @brief define camera dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-11-15
*/
#ifndef DEV_CAMERA_H
#define DEV_CAMERA_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct CameraDataStandard
{
uint16 addr;
uint16 flags;
uint16 len;
uint16 retries;
uint8 *buf;
struct CameraDataStandard *next;
};
struct CameraDevDone
{
uint32 (*dev_open) (void *camera_device);
uint32 (*dev_close) (void *camera_device);
uint32 (*dev_write) (void *camera_device, struct BusBlockWriteParam *msg);
uint32 (*dev_read) (void *camera_device, struct BusBlockReadParam *msg);
};
struct CameraHardwareDevice
{
struct HardwareDev haldev;
const struct CameraDevDone *camera_dev_done;
};
/*Register the CAMERA device*/
int CameraDeviceRegister(struct CameraHardwareDevice *camera_device, void *camera_param, const char *device_name);
/*Register the CAMERA device to the CAMERA bus*/
int CameraDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register CAMERA device*/
HardwareDevType CameraDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
@@ -106,4 +106,9 @@ HardwareDevType ObtainConsole(void);
#include <dev_dac.h>
#endif
#ifdef RESOURCES_CAMERA
#include <bus_camera.h>
#include <dev_camera.h>
#endif
#endif