## 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
pass
class Decoder(srd.Decoder):
- api_version = 2
+ api_version = 3
id = 'i2s'
name = 'I²S'
longname = 'Integrated Interchip Sound'
('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
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):
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)
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
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
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: