]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/i2s/pd.py
license: remove FSF postal address from boiler plate license text
[libsigrokdecode.git] / decoders / i2s / pd.py
index ee642d7dcf8aea3743ad1a4b7cbcd19868656d1a..b0b177f1f007f0687e460db06e49361121af18a3 100644 (file)
@@ -14,8 +14,7 @@
 ## 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 <http://www.gnu.org/licenses/>.
 ##
 
 import sigrokdecode as srd
@@ -37,7 +36,7 @@ class SamplerateError(Exception):
     pass
 
 class Decoder(srd.Decoder):
-    api_version = 2
+    api_version = 3
     id = 'i2s'
     name = 'I²S'
     longname = 'Integrated Interchip Sound'
@@ -59,9 +58,8 @@ class Decoder(srd.Decoder):
         ('wav', 'WAV file'),
     )
 
-    def __init__(self, **kwargs):
+    def __init__(self):
         self.samplerate = None
-        self.oldsck = 1
         self.oldws = 1
         self.bitcount = 0
         self.data = 0
@@ -73,7 +71,7 @@ class Decoder(srd.Decoder):
 
     def start(self):
         self.out_python = self.register(srd.OUTPUT_PYTHON)
-        self.out_bin = self.register(srd.OUTPUT_BINARY)
+        self.out_binary = self.register(srd.OUTPUT_BINARY)
         self.out_ann = self.register(srd.OUTPUT_ANN)
 
     def metadata(self, key, value):
@@ -84,7 +82,7 @@ class Decoder(srd.Decoder):
         self.put(self.ss_block, self.samplenum, self.out_python, data)
 
     def putbin(self, data):
-        self.put(self.ss_block, self.samplenum, self.out_bin, data)
+        self.put(self.ss_block, self.samplenum, self.out_binary, data)
 
     def putb(self, data):
         self.put(self.ss_block, self.samplenum, self.out_ann, data)
@@ -130,18 +128,12 @@ class Decoder(srd.Decoder):
         lo, hi = s & 0xff, (s >> 8) & 0xff
         return bytes([lo, hi])
 
-    def decode(self, ss, es, data):
+    def decode(self):
         if not self.samplerate:
             raise SamplerateError('Cannot decode without samplerate.')
-        for self.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
+        while True:
+            # Wait for a rising edge on the SCK pin.
+            sck, ws, sd = self.wait({0: 'r'})
 
             self.data = (self.data << 1) | sd
             self.bitcount += 1
@@ -154,7 +146,7 @@ class Decoder(srd.Decoder):
             if self.ss_block is not None:
 
                 if not self.wrote_wav_header:
-                    self.put(0, 0, self.out_bin, (0, self.wav_header()))
+                    self.put(0, 0, self.out_binary, [0, self.wav_header()])
                     self.wrote_wav_header = True
 
                 self.samplesreceived += 1
@@ -167,7 +159,7 @@ class Decoder(srd.Decoder):
                 self.putpb(['DATA', [c3, self.data]])
                 self.putb([idx, ['%s: %s' % (c1, v), '%s: %s' % (c2, v),
                                  '%s: %s' % (c3, v), c3]])
-                self.putbin((0, self.wav_sample(self.data)))
+                self.putbin([0, self.wav_sample(self.data)])
 
                 # Check that the data word was the correct length.
                 if self.wordlength != -1 and self.wordlength != self.bitcount: