c++ - trouble with Open Cv and GPIO on mini6410 -
i doing simple project on arm based mini6410. have debian package installed on mini. project interface 1 ir motion sensor , usb webcam mini6410. working simple, whenever there motion detected ir sensor, webcam on 30 seconds save images (over write previous) , off. have cross comiled open cv code using arm-linux-gcc
for ir using gpe register.
here stuck issue unable resolve. , dont know how resolve. opencv code cpp file camera.cpp , file deals i/o ports c file named sensor.c. in c file polling or whatever mechanism check if gpe register 1 or not. if one, should start open cv code start capture images. further more sensor.c file not compiled rather made module , insmod on mini6410.
however dont know how write c++ code in c file. can dont know how call opencv thing c file. module , within cant write cpp code using namespace std , using namespace cv doesnot work.
i new embedded stuff , linux self. wanted know there possible solutions. attaching codes of both files.
this sensor.c
#include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/serio.h> #include <linux/delay.h> #include <linux/clk.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/cdev.h> #include <linux/miscdevice.h> #include <asm/io.h> #include <asm/irq.h> #include <asm/uaccess.h> #include <mach/map.h> #include <mach/regs-clock.h> #include <mach/regs-gpio.h> #include <plat/gpio-cfg.h> #include <mach/gpio-bank-q.h> #include <mach/gpio-bank-e.h> #include <mach/map.h> #include <plat/regs-timer.h> #include <mach/hardware.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h> #include <linux/types.h> #include <linux/moduleparam.h> #include <linux/ioctl.h> #include <linux/cdev.h> #include <linux/string.h> #include <linux/list.h> #include <linux/pci.h> #include <asm/uaccess.h> #include <asm/atomic.h> #include <asm/unistd.h> #include <mach/gpio-bank-k.h> #define rlv 0x0fff unsigned gpe; unsigned sensor_value; typedef struct { int delay; } tim_dev; static tim_dev timdev; static irqreturn_t inthandler(int irq,void *timdev) { gpe = readl(s3c64xx_gpedat); gpe &= ~(0xf<<1); readl(sensor_value, s3c64xx_gpedat); while (sensor_value == 1) {//1 means ir sensor has detected motion , given value of +5 v (i = 0; < 30; i++){ //cv_function(); // delay here such delay(1 s) * 30 = 30 seconds } } return irq_handled; } static struct file_operations dev_fops = { .owner = this_module, .write = mywrite, }; static struct miscdevice misc = { .minor = misc_dynamic_minor, .name = device_name, .fops = &dev_fops, }; static int __init dev_init(void) { int ret; unsigned timercontrol; unsigned timerintcontrol; unsigned timercntb; unsigned timercmpb; unsigned timercfg1; unsigned ge; timercontrol = readl(s3c_tcon); timerintcontrol = readl(s3c_tint_cstat); timercntb = readl(s3c_tcntb(0)); timercmpb = readl(s3c_tcmpb(0)); timercfg1 = readl(s3c_tcfg1); timercfg1 &= ~(s3c_tcfg1_mux0_mask); timercntb = rlv; timercmpb = 0; writel(timercntb, s3c_tcntb(0)); writel(timercmpb, s3c_tcmpb(0)); writel(timercfg1, s3c_tcfg1); timercontrol |= s3c_tcon_t0manualupd; timerintcontrol |= s3c_tint_cstat_t0inten; writel(timercontrol, s3c_tcon); writel(timerintcontrol, s3c_tint_cstat); timercontrol = readl(s3c_tcon); timercontrol |= s3c_tcon_t0reload; timercontrol &= ~s3c_tcon_t0manualupd; timercontrol |= s3c_tcon_t0start; writel(timercontrol, s3c_tcon); //////////////here configuring gpe input///////////// ge = readl(s3c64xx_gpecon); ge &= ~(0xffff<<4); ge |= (0x0000<<4); writel(ge, s3c64xx_gpecon); ///////////// misc_register(&misc); ret = request_irq(irq_timer0, inthandler, irqf_shared, device_name, &timdev); if (ret) { return ret; } return ret; } static void __exit dev_exit(void) { free_irq(irq_timer0, &timdev); misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); module_license("gpl"); module_author("xyz");
this camera.cpp
#include <opencv2/objdetect/objdetect.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main( int argc, const char** argv ) {cvcapture* capture = 0; mat frame, framecopy, image; capture = cvcapturefromcam( 2 ); if( !capture ) { cout << "no camera detected" << endl; } if( capture ) { cout << "in capture ..." << endl; iplimage* iplimg = cvqueryframe( capture ); frame = iplimg; if( frame.empty() ) break; if( iplimg->origin == ipl_origin_tl ) frame.copyto( framecopy ); else flip( frame, framecopy, 0 ); cvsaveimage("image.jpg" ,iplimg); } cvreleasecapture( &capture ); return 0; }
the loop in sensor.c file should have above code means
i hope idea, thanks
the missing link in code shown mechanism user-space code shown above can notification of change in gpio pin detected device driver.
there 2 obvious ways achieve this:
- integrate gpio pin platform's gpio resources , use generic
sysfs
mechanism user-space. linux kernel gpio documentation describes both kernel , user-space side of this. - have driver expose
sysfs
node gpio line.sysfs
fundamental linux driver model. suggest thorough read of linux device drivers 3rd edition.
the user-space side of either method similar: open sysfs
resource exported module , use either poll()
or select()
block until event occurs.
Comments
Post a Comment