2 def __init__(self, data):
4 def probe(self, probe):
5 s = ord(self.data[probe / 8]) & (1 << (probe % 8))
6 return True if s else False
8 def sampleiter(data, unitsize):
9 for i in range(0, len(data), unitsize):
10 yield(Sample(data[i:i+unitsize]))
13 # Probe names with a set of defaults
14 probes = {'sdata':0, 'sck':1}
16 def __init__(self, unitsize, **kwargs):
17 # Metadata comes in here, we don't care for now
19 self.unitsize = unitsize
21 self.probes = Decoder.probes
25 self.bytesreceived = 0
28 return "SPI: %d bytes received" % self.bytesreceived
30 def decode(self, data):
31 # We should accept a list of samples and iterate...
32 for sample in sampleiter(data["data"], self.unitsize):
34 sck = sample.probe(self.probes["sck"])
35 # Sample SDATA on rising SCK
36 if sck == self.oldsck:
42 # If this is first bit, save timestamp
44 self.time = data["time"]
45 # Receive bit into our shift register
46 sdata = sample.probe(self.probes["sdata"])
48 self.rxdata |= 1 << (7 - self.rxcount)
50 # Continue to receive if not a byte yet
53 # Received a byte, pass up to sigrok
54 outdata = {"time":self.time,
55 "duration":data["time"] + data["duration"] - self.time,
57 "display":("%02X" % self.rxdata),
65 # Keep stats for summary
66 self.bytesreceived += 1
71 'name': 'SPI Decoder',
73 'desc': 'Decodes SPI frames',
75 'author': 'Gareth McMullin',
76 'email': 'gareth@blacksphere.co.nz',
90 if __name__ == "__main__":
91 data = open("spi_dump.bin").read()
93 # dummy class to keep Decoder happy for test
99 dec = Decoder(driver='ols', unitsize=1, starttime=0)
100 dec.decode({"time":0, "duration":len(data), "data":data, "type":"logic"})
107 # sigrok-cli -d 0:samplerate=1000000:rle=on --time=1s -p 1,2 -a spidec