2 # GoodFET EM260 Radio Client
4 # (C) 2010 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
8 # The EM260 is almost textbook SPI, except that the response cannot be
9 # read until after the nHOST_INT pin of the EM260 drops low and a dummy
10 # byte is read. That is, the sequence will look like the following:
12 # Transmit Host->Slave Data
13 # while(nHOST_INT); //Sleep until ready.
15 # Recv Slave->Host Data
17 # The delay is mandatory.
19 import sys, time, string, cStringIO, struct, glob, serial, os;
21 from GoodFETSPI import GoodFETSPI;
23 class GoodFETEM260(GoodFETSPI):
26 def EM260trans(self,data):
27 """Exchange data by EM260 SPI. (Slightly nonstandard.)"""
29 self.writecmd(0x01,0x82,len(data),data);
32 reply=ord(self.data[0]);
34 print "Warning: EM260 rebooted.";
35 return self.EM260trans(data);
37 print "Error: Aborted Transaction.";
38 #return self.EM260trans(data);
40 print "Error: Missing Frame Terminator.";
43 print "Error in EM260trans.";
48 """Read a byte from the given address."""
49 data=self.EM260trans([0xfe,0x01,self.seq,0x00,
54 s=s+"%02x " % ord(foo);
59 """Read the info bytes."""
60 version=self.EM260spiversion();
61 print "Version %2i" % (version &0x7F);
62 def EM260spiversion(self):
63 """Read the SPI version number from EM260."""
64 data=self.EM260trans([0x0A,0xA7]);
68 return self.EM260spiversion();
70 return self.EM260spiversion();
72 print "Version misread.";
76 def EM260spistatus(self):
77 """Read the info bytes."""
78 data=self.EM260trans([0x0B,0xA7]);
81 s=s+"%02x " % ord(foo);