]>
Commit | Line | Data |
---|---|---|
3608c106 UH |
1 | # Copyright (C) 2009 Ubixum, Inc. |
2 | # | |
3 | # This library is free software; you can redistribute it and/or | |
4 | # | |
5 | # modify it under the terms of the GNU Lesser General Public | |
6 | # License as published by the Free Software Foundation; either | |
7 | # version 2.1 of the License, or (at your option) any later version. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | # Lesser General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public | |
15 | # License along with this library; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | ||
18 | from time import sleep | |
19 | from fx2 import fx2 | |
20 | ||
21 | f=fx2.fx2() | |
22 | ||
23 | # use this functions 1st | |
24 | ||
25 | def openfx2(vid=0x04b4,pid=0x0082,idx=0): | |
26 | f.open(vid,pid,idx) | |
27 | ||
28 | def reset_device(reset): | |
29 | print reset and "Put device in reset" or "Set device to run" | |
30 | write_ram (0xe600,reset and '\x01' or '\x00', 1) | |
31 | ||
32 | def write_ram(addr,data,length): | |
33 | transferred=0 | |
34 | while(transferred<length): | |
35 | this_transfer_size=length-transferred>1024 and 1024 or length-transferred | |
36 | buf=data[transferred:] | |
37 | ret=f.do_usb_command( buf, | |
38 | 0x40, | |
39 | 0xa0, | |
40 | addr+transferred, 0, | |
41 | this_transfer_size ) | |
42 | if (ret>0): | |
43 | print "wrote %d bytes" % ret | |
44 | transferred+=ret | |
45 | else: | |
46 | print "Error: %d" % ret | |
47 | return | |
48 | ||
49 | def reset_bix(filename): | |
50 | """ | |
51 | Use this function to reset your firmware. You'll need to reopen the device afterward. | |
52 | """ | |
53 | reset_device(True) | |
54 | bix=open(filename).read() | |
55 | print "loading bix file of length: %d" % len(bix) | |
56 | write_ram( 0, bix,len(bix) ); | |
57 | reset_device(False) | |
58 | f.close() | |
59 |