X-Git-Url: http://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Ftlc5620%2Fpd.py;h=2a407d1687cc288a15349544a94107af5f1518fe;hp=df42bfbe10613c786c98108adb805cdb82e80155;hb=HEAD;hpb=04c310c8d90a29dc4125ad2b707d08ed4fe15c52 diff --git a/decoders/tlc5620/pd.py b/decoders/tlc5620/pd.py index df42bfb..8ff30d7 100644 --- a/decoders/tlc5620/pd.py +++ b/decoders/tlc5620/pd.py @@ -14,11 +14,13 @@ ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## import sigrokdecode as srd +from common.srdhelper import SrdIntEnum + +Pin = SrdIntEnum.from_str('Pin', 'CLK DATA LOAD LDAC') dacs = { 0: 'DACA', @@ -28,14 +30,15 @@ dacs = { } class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'tlc5620' name = 'TI TLC5620' longname = 'Texas Instruments TLC5620' desc = 'Texas Instruments TLC5620 8-bit quad DAC.' license = 'gplv2+' inputs = ['logic'] - outputs = ['tlc5620'] + outputs = [] + tags = ['IC', 'Analog/digital'] channels = ( {'id': 'clk', 'name': 'CLK', 'desc': 'Serial interface clock'}, {'id': 'data', 'name': 'DATA', 'desc': 'Serial interface data'}, @@ -71,8 +74,10 @@ class Decoder(srd.Decoder): ('errors', 'Errors', (9,)), ) - def __init__(self, **kwargs): - self.oldpins = self.oldclk = self.oldload = self.oldldac = None + def __init__(self): + self.reset() + + def reset(self): self.bits = [] self.ss_dac_first = None self.ss_dac = self.es_dac = 0 @@ -183,28 +188,25 @@ class Decoder(srd.Decoder): [8, ['Updating voltages: %s' % s, s, s.replace('DAC', '')]]) self.ss_dac_first = None - def handle_new_dac_bit(self): - self.bits.append([self.datapin, self.samplenum]) - - def decode(self, ss, es, data): - for (self.samplenum, pins) in data: - - # Ignore identical samples early on (for performance reasons). - if self.oldpins == pins: - continue - self.oldpins, (clk, self.datapin, load, ldac) = pins, pins - self.ldac = ldac + def handle_new_dac_bit(self, datapin): + self.bits.append([datapin, self.samplenum]) + def decode(self): + while True: # DATA is shifted in the DAC on the falling CLK edge (MSB-first). # A falling edge of LOAD will latch the data. - if self.oldload == 1 and load == 0: + # Wait for one (or multiple) of the following conditions: + # a) Falling edge on CLK, and/or + # b) Falling edge on LOAD, and/or + # b) Falling edge on LDAC + pins = self.wait([{Pin.CLK: 'f'}, {Pin.LOAD: 'f'}, {Pin.LDAC: 'f'}]) + self.ldac = pins[3] + + # Handle those conditions (one or more) that matched this time. + if self.matched[0]: + self.handle_new_dac_bit(pins[1]) + if self.matched[1]: self.handle_falling_edge_load() - if self.oldldac == 1 and ldac == 0: + if self.matched[2]: self.handle_falling_edge_ldac() - if self.oldclk == 1 and clk == 0: - self.handle_new_dac_bit() - - self.oldclk = clk - self.oldload = load - self.oldldac = ldac