2 ## This file is part of the sigrok project.
4 ## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 # TrekStor EBR30-a I2C demux protocol decoder
23 import sigrokdecode as srd
30 class Decoder(srd.Decoder):
32 id = 'ebr30a_i2c_demux'
33 name = 'EBR30-a I2C demux'
34 longname = 'TrekStor EBR30-a I2C demux'
39 outputs = ['i2c-axp199', 'i2c-h8563s', 'i2c-accel'] # TODO: type vs. inst.
45 def __init__(self, **kwargs):
49 def start(self, metadata):
51 self.out_proto.append(self.add(srd.OUTPUT_PROTO, 'i2c-axp199'))
52 self.out_proto.append(self.add(srd.OUTPUT_PROTO, 'i2c-h8563s'))
53 self.out_proto.append(self.add(srd.OUTPUT_PROTO, 'i2c-accel'))
59 # Grab I2C packets into a local cache, until an I2C STOP condition
60 # packet comes along. At some point before that STOP condition, there
61 # will have been an ADDRESS READ or ADDRESS WRITE which contains the
62 # I2C address of the slave that the master wants to talk to.
63 # We use this slave address to figure out which output stream should
64 # get the whole chunk of packets (from START to STOP).
65 def decode(self, ss, es, data):
67 cmd, databyte, ack_bit = data
69 # Add the I2C packet to our local cache.
70 self.packets += [[ss, es, data]]
72 if cmd in ('ADDRESS READ', 'ADDRESS WRITE'):
73 # print(hex(databyte))
76 elif databyte == 0x51:
78 elif databyte == 0x15:
82 # TODO: Can there be two ADDRESS READ/WRITE with two different
83 # slave addresses before any STOP occurs?
86 # Send the whole chunk of I2C packets to the correct stream.
87 for p in self.packets:
88 # print(self.out_proto[self.stream], p)
89 self.put(p[0], p[1], self.out_proto[self.stream], p[2])
91 print('Error: Could not determine correct stream!') # FIXME
95 pass # Do nothing, only add the I2C packet to our cache.