EM260 client.
[goodfet] / client / GoodFETEM260.py
1 #!/usr/bin/env python
2 # GoodFET EM260 Radio Client
3
4 # (C) 2010 Travis Goodspeed <travis at radiantmachines.com>
5 #
6 # This code is being rewritten and refactored.  You've been warned!
7
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:
11
12 # Transmit Host->Slave Data
13 # while(nHOST_INT); //Sleep until ready.
14 # Recv Dummy Byte
15 # Recv Slave->Host Data
16
17 # The delay is mandatory.
18
19 import sys, time, string, cStringIO, struct, glob, serial, os;
20
21 from GoodFETSPI import GoodFETSPI;
22
23 class GoodFETEM260(GoodFETSPI):
24     EM260APP=0x01;
25     def peek8(self,adr):
26         """Read a byte from the given address."""
27         data=self.SPItrans([0xfe,0x01,0x00,
28                             0x49,
29                             0xA7,0,0,0,0,0,0,0,0]);
30         return ord(data[7]);
31     def poke8(self,adr, byte):
32         """Poke a byte to the given address."""
33     def info(self):
34         """Read the info bytes."""
35         data=self.SPItrans([0x0B,0xA7,
36                             0xFF,
37                             0xFF,0xFF,0xFF,     #00 02 A7
38                             0,0,0,0,0,0,0,0,0,0,
39                             0,0,0,0,0,0,0,0,0,0,
40                             0,0,0,0,0,0,0,0,0,0,
41                             0,0,0,0,0,0,0,0,0,0,
42                             0,0,0,0,0,0,0,0,0,0,
43                             0,0,0,0,0,0,0,0,0,0
44                             ]); 
45         for foo in data:
46             print "%02x" % ord(foo);