OpenCores
URL https://opencores.org/ocsvn/csa/csa/trunk

Subversion Repositories csa

[/] [csa/] [trunk/] [pc/] [imgdev.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 simon111
 
2
 
3
// this file implements some function to access image device
4
 
5
 
6
#include <usb.h>
7
#include <stdio.h>
8
 
9
#include "misc.h"
10
 
11
 
12
#define IMG_DEV_VID 0x0547
13
#define IMG_DEV_PID 0x1002
14
//#define IMG_DEV_VID 0x0a82 
15
//#define IMG_DEV_PID 0x0603
16
 
17
static usb_dev_handle* img_dev_handle=NULL;
18
 
19
int img_dev_open()
20
{
21
        struct usb_bus *bus;
22
        if(img_dev_handle)
23
                return -1;
24
        usb_set_debug(14);
25
        usb_init();
26
        usb_find_busses();
27
        usb_find_devices();
28
 
29
        for (bus = usb_get_busses(); bus; bus = bus->next)
30
        {
31
                struct usb_device *dev;
32
                for (dev = bus->devices; dev; dev = dev->next)
33
                {
34
                        if(      dev->descriptor.idVendor  == IMG_DEV_VID
35
                             &&  dev->descriptor.idProduct == IMG_DEV_PID )
36
                        {
37
                                        img_dev_handle = usb_open(dev);
38
                                        usb_set_configuration ( img_dev_handle, 1);
39
                                        usb_claim_interface   ( img_dev_handle, 0);
40
                                        usb_set_altinterface  ( img_dev_handle, 0);
41
                                        return 0;
42
                        }
43
                }
44
        }
45
        return -1;
46
}
47
 
48
void img_dev_close()
49
{
50
        if(img_dev_handle)
51
        {
52
                usb_close(img_dev_handle);
53
                img_dev_handle=NULL;
54
        }
55
 
56
}
57
 
58
int img_read_img(unsigned char* buf, int len)
59
{
60
        int i;
61
        if(!img_dev_handle)
62
                return -2;
63
        i=usb_bulk_read(img_dev_handle, 0x82, (char*)buf,  len, 200);
64
        if(i!=len)
65
                DEBUG_LINE("read data error");
66
        return i;
67
}
68
 
69
int img_write_data(unsigned char* buf, int len,int addr)
70
{
71
        int i;
72
        if(!img_dev_handle)
73
                return -2;
74
        if(addr != 0x08 && addr != 0x6 )
75
                return -3;
76
        i=usb_bulk_write(img_dev_handle, addr, (char*)buf,  len, 500);
77
        if(i!=len)
78
                DEBUG_LINE("write data have some error i= %d",i);
79
        return i;
80
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.