2d36a4434787235ec2c62fde297850909798efe7
[goodfet] / client / GoodFETAVR.py
1 #!/usr/bin/env python
2 # GoodFET SPI and SPIFlash Client Library
3
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
5 #
6 # This code is being rewritten and refactored.  You've been warned!
7
8 import sys, time, string, cStringIO, struct, glob, serial, os;
9
10 from GoodFET import GoodFET;
11
12 class GoodFETAVR(GoodFET):
13     AVRAPP=0x32;
14     
15     def setup(self):
16         """Move the FET into the SPI application."""
17         self.writecmd(self.AVRAPP,0x10,0,self.data); #SPI/SETUP
18     
19     def trans(self,data):
20         """Exchange data by AVR.
21         Input should probably be 4 bytes."""
22         self.data=data;
23         self.writecmd(self.AVRAPP,0x00,len(data),data);
24         return self.data;
25
26     def start(self):
27         """Start the connection."""
28         self.writecmd(self.AVRAPP,0x20,0,None);
29
30     def identstr(self):
31         """Return an identifying string."""
32         self.writecmd(self.AVRAPP,0x83,0,None);
33         return "AVR(%02x)" % ord(self.data[0]);