From: Joel Holdsworth Date: Fri, 6 Apr 2012 19:01:02 +0000 (+0100) Subject: srd/i2s: Initial implementation X-Git-Tag: libsigrokdecode-0.1.0~8 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=2ab416c214e248be8ece49bab2cabf2b28954cca srd/i2s: Initial implementation --- diff --git a/configure.ac b/configure.ac index 4f7bcdd..0ee981e 100644 --- a/configure.ac +++ b/configure.ac @@ -152,6 +152,7 @@ AC_CONFIG_FILES([Makefile decoders/i2c/Makefile decoders/i2cdemux/Makefile decoders/i2cfilter/Makefile + decoders/i2s/Makefile decoders/mlx90614/Makefile decoders/mx25lxx05d/Makefile decoders/pan1321/Makefile diff --git a/decoders/Makefile.am b/decoders/Makefile.am index 4fcd83f..b134953 100644 --- a/decoders/Makefile.am +++ b/decoders/Makefile.am @@ -25,6 +25,7 @@ SUBDIRS = \ i2c \ i2cdemux \ i2cfilter \ + i2s \ mlx90614 \ mx25lxx05d \ pan1321 \ diff --git a/decoders/i2s/Makefile.am b/decoders/i2s/Makefile.am new file mode 100644 index 0000000..ff66902 --- /dev/null +++ b/decoders/i2s/Makefile.am @@ -0,0 +1,26 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Joel Holdsworth +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## 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 +## + +pkgdatadir = $(DECODERS_DIR)/i2s + +dist_pkgdata_DATA = __init__.py i2s.py + +CLEANFILES = *.pyc + diff --git a/decoders/i2s/__init__.py b/decoders/i2s/__init__.py new file mode 100644 index 0000000..e52d5b2 --- /dev/null +++ b/decoders/i2s/__init__.py @@ -0,0 +1,29 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Joel Holdsworth +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## 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 +## + +''' +I2S protocol decoder. + +Details: +TODO +''' + +from .i2s import * + diff --git a/decoders/i2s/i2s.py b/decoders/i2s/i2s.py new file mode 100644 index 0000000..30497b3 --- /dev/null +++ b/decoders/i2s/i2s.py @@ -0,0 +1,96 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Joel Holdsworth +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## 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 +## + +# I2S protocol decoder + +import sigrokdecode as srd + +# Annotation formats +ANN_HEX = 0 + +class Decoder(srd.Decoder): + api_version = 1 + id = 'i2s' + name = 'I2S' + longname = 'Integrated Interchip Sound' + desc = 'I2S is an electrical serial bus interface standard used ' \ + 'for connecting digital audio devices together.' + license = 'gplv2+' + inputs = ['logic'] + outputs = ['i2s'] + probes = [ + {'id': 'sck', 'name': 'SCK', 'desc': 'Bit clock line'}, + {'id': 'ws', 'name': 'WS', 'desc': 'Word select line'}, + {'id': 'sd', 'name': 'SD', 'desc': 'Serial Data line'}, + ] + annotations = [ + ['ASCII', 'Annotations in ASCII format'], + ] + + def __init__(self, **kwargs): + self.oldsck = 1 + self.oldws = 1 + self.bitcount = 0 + self.data = 0 + self.samplesreceived = 0 + self.start_sample = None + self.samplenum = -1 + + def start(self, metadata): + self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2s') + self.out_ann = self.add(srd.OUTPUT_ANN, 'i2s') + + def report(self): + return 'I2S: %d samples received' % self.samplesreceived + + def decode(self, ss, es, data): + for samplenum, (sck, ws, sd) in data: + + # Ignore sample if the bit clock hasn't changed. + if sck == self.oldsck: + continue + + self.oldsck = sck + if sck == 0: # Ignore the falling clock edge + continue + + self.data = (self.data << 1) | sd + self.bitcount += 1 + + # This was not the LSB unless WS has flipped + if ws == self.oldws: + continue + + # Only submit the sample, if we received the beginning of it + if self.start_sample != None: + self.samplesreceived += 1 + self.put(self.start_sample, self.samplenum, self.out_proto, + ['data', self.data]) + self.put(self.start_sample, self.samplenum, self.out_ann, + [ANN_HEX, ['%s %d-bits: 0x%08x' % ('L' if self.oldws else 'R', + self.bitcount, self.data)]]) + + # Reset decoder state. + self.data = 0 + self.bitcount = 0 + self.start_sample = self.samplenum + + self.oldws = ws + \ No newline at end of file