#include#include #include #include #include #include #include #include #include #include #include //#include #include #include #include #include #define COLS 320 #define ROWS 240 #define V4L2_DEV_NODE "/dev/video13" #define FB_DEV_NODE "/dev/fb0" #define CLEAR(x) memset(&(x),0,sizeof(x)) typedef struct v4l2_format V_FORMAT; typedef struct fb_var_screeninfo F_VINFO; struct fb_var_screeninfo fb_var; struct fb_fix_screeninfo fb_fix; char * fb_base_addr = NULL; static void show_rgb565_img(void *scr, __u16 *data_buf) { __u16 x, y; __u16 *fb_buf = (__u16 *)scr; fb_buf += (320); for (y = 0; y < ROWS; y++) { for (x = 0; x < COLS; x++) { fb_buf[x] = *data_buf++ ; } fb_buf += 320; } } int main(void) { int v4l2_fd = -1; int fb_fd = -1; int n=0; __u8 *fb_buf; __u8 *buf; __u32 screensize; //unsigned int width = 0; //unsigned int height = 0; //unsigned int bpp = 0; V_FORMAT fmt; enum v4l2_buf_type type; type = V4L2_BUF_TYPE_VIDEO_CAPTURE; printf("Start Main \n"); printf("Before openning video \n"); v4l2_fd = open(V4L2_DEV_NODE, O_RDWR | O_NONBLOCK, 0); if (v4l2_fd < 0) { printf(" open video ERR\n"); return 0; } printf("Before openning FB \n"); fb_fd = open(FB_DEV_NODE, O_RDWR); if (fb_fd < 0) { printf("error open fb_fd\n"); exit(1); } /* Get fixed screen information */ if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_fix)) { printf("Error reading fb fixed information.\n"); exit(1); } /* Get variable screen information */ if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_var)) { printf("Error reading fb variable information.\n"); exit(1); } screensize = fb_var.xres * fb_var.yres * fb_var.bits_per_pixel / 8; //screensize = 480 * 272 * 16 / 8; fb_buf = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); if ((int)fb_buf == -1) { printf("Error: failed to map framebuffer device to memory.\n"); close(fb_fd); return -1; } CLEAR (fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 320; fmt.fmt.pix.height = 240; //fmt.fmt.pix.depth = 16; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565; //printf("VIDIOC_S_FMT is %x\n",VIDIOC_S_FMT); if ((ioctl(v4l2_fd, VIDIOC_S_FMT, &fmt)) < 0) { printf("Error: failed to set video format.\n"); return 0; } buf = malloc(320 * 240 * 3); //printf("VIDIOC_STREAMON is %x\n",VIDIOC_STREAMON); if ((ioctl(v4l2_fd, VIDIOC_STREAMON, &type)) < 0) { printf("error ioctl streamon\n"); return 0; } printf("start to get pic %d\n",(int)fmt.fmt.pix.sizeimage); while(1) { n=read(v4l2_fd, buf, 320*240*2); printf("display %d\n",n); show_rgb565_img(fb_buf,buf); } }
Previous article:How to use STM32's on-chip Flash to store Chinese character library
Next article:Mini2440 NRF24L01 wireless module driver
Recommended ReadingLatest update time:2024-11-16 16:44
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [EEWorld invites you to play disassembly] PISEN fast charging power bank 10500mAh 22.5W
- Application of Single Chip Microcomputer in Inverted Pendulum Control System
- 【XMC4800 Relax EtherCAT Kit Review】+ Getting Started with DAVE, Timer Interrupt and UART Simple Application
- Share: In actual project, the average load was too high, and finally found that it was this that was causing the problem
- The problem of MCLK frequency of LIS25BA
- 【GD32307E-START】Development practice->UART sends HELLOWORD to the world
- Electromagnetic waves and antennas
- The voltage difference of bq4050 with load is very high, almost 1V. How to solve this problem? It is two strings of batteries.
- 2.4 GHz CDMA Radio Transceiver CYWUSB6934 Application Circuit
- It feels like USB3 isn't popular yet, and USB4 is here!