Thread 中讨论的其他器件:AM67、AM67A 、 ALP
工具/软件:
尊敬的 TI:
我们有 TDA4VEN - DS90UB960 - IMX390 (内置 DS90UB953)、并设置器件树继电器。 现在、我们要使用以下代码测试传感器的通电和工作是否正常:
# after boot and login, config code provided by manutacturer $ i2cset -y 7 0x3d 0x4c 0x01 $ i2cset -y 7 0x3d 0x58 0x5e $ i2cset -y 7 0x3d 0x1f 0x02 $ i2cset -y 7 0x3d 0x20 0x20 $ i2cset -y 7 0x3d 0x33 0x03
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <string.h>
#include <errno.h>
#define DEVICE "/dev/video4"
#define WIDTH  1936
#define HEIGHT 1100
int main() {
	int fd = open(DEVICE, O_RDWR);
	if (fd == -1) {
    	perror("Error opening video device");
    	return 1;
	}
	// Set video format
	struct v4l2_format fmt;
	memset(&fmt, 0, sizeof(fmt));
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width = WIDTH;
	fmt.fmt.pix.height = HEIGHT;
	fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SRGGB12;  // 10-bit Bayer Packed
	fmt.fmt.pix.field = V4L2_FIELD_NONE;
	if (ioctl(fd, VIDIOC_S_FMT, &fmt) == -1) {
    	perror("VIDIOC_S_FMT failed");
    	printf("Error: %d\n", errno);
    	close(fd);
    	return 1;
	}
	// Request buffers
	struct v4l2_requestbuffers req;
	memset(&req, 0, sizeof(req));
	req.count = 1;  // Request 1 buffer
	req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	req.memory = V4L2_MEMORY_MMAP;
	if (ioctl(fd, VIDIOC_REQBUFS, &req) == -1) {
    	perror("VIDIOC_REQBUFS failed");
    	close(fd);
    	return 1;
	}
	// Query buffer
	struct v4l2_buffer buf;
	memset(&buf, 0, sizeof(buf));
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;
	buf.index = 0;
	if (ioctl(fd, VIDIOC_QUERYBUF, &buf) == -1) {
    	perror("VIDIOC_QUERYBUF failed");
    	close(fd);
    	return 1;
	}
   // Map buffer to user space             	 
	void* buffer = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset);
	if (buffer == MAP_FAILED) {                                                            	 
    	perror("Memory mapping failed");                                                   	 
    	close(fd);                                                                         	 
    	return 1;                                                                          	 
	}                                                                                      	 
                                                                                           	 
	// Queue buffer                                                                        	 
	if (ioctl(fd, VIDIOC_QBUF, &buf) == -1) {                                              	 
    	perror("VIDIOC_QBUF failed");                                                      	 
    	close(fd);                                                                         	 
    	return 1;                                                                          	 
	}                                                                                      	 
                                                                                           	 
	// Start streaming                                                                     	 
	int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;                                                	 
	if (ioctl(fd, VIDIOC_STREAMON, &type) == -1) {                                         	 
    	perror("VIDIOC_STREAMON failed");                                                  	 
    	close(fd);                                                                         	 
    	return 1;                                                                          	 
	}                                                                                      	 
                                                                      	 
	// Dequeue buffer (capture frame)        	 
	if (ioctl(fd, VIDIOC_DQBUF, &buf) == -1) {    
    	perror("VIDIOC_DQBUF failed");       	 
    	close(fd);                                                                         	 
    	return 1;                                                                          	 
	}                                                                                      	 
                                                                                           	 
	// Save raw Bayer frame                  	 
	FILE* file = fopen("frame.raw", "wb");                                                 	 
	if (file) {                              	 
    	fwrite(buffer, buf.length, 1, file);    
    	fclose(file);                       	 
    	printf("Frame captured and saved as frame.raw\n");
	} else {                                         	 
    	perror("Error saving frame");                	 
	}                                                	 
                                                     	 
	// Stop streaming                                                                      	 
	if (ioctl(fd, VIDIOC_STREAMOFF, &type) == -1) {  	 
    	perror("VIDIOC_STREAMOFF failed");           	 
	}                                                	 
                                                     	 
	// Cleanup                                       	 
	munmap(buffer, buf.length);                      	 
	close(fd);                                       	 
	return 0;                                        	 
}
执行在第88行挂起、如果我们使用 ctrl + c 中断并检查954的0x20和0x33寄存器、则该值分别修改回0xf0和0x02。 在执行第81行之后、这些值似乎被修改了。
我们还尝试了`v4l2-ctl --device /dev/video4 --stream-mmap --stream-count=1 --stream-to=frame.raw`并将其挂起。
此致
 
				 
		 
					 
				
