# Path: ripyl/sigproc.py
# def remove_excess_edges(edges):
#     '''Remove incorrect edge transitions from an edge stream
#     
#     This is a generator function.
#     
#     This function is most useful for conditioning the outputs of the protocol
#     synthesizers. For those protocols with multiple signals, the synthesizers
#     myst yield a new output set for *all* signals when any *one* of them changes.
#     This results in non-conforming edge streams that contain multiple consecutive
#     pairs with a non-changing value.
#     
#     edges (iterable of (float, int) tuples)
#         An edge stream to filter for extraneous non-edges
#         
#     Yields an edge stream.
#     '''
#     prev_state = None
#     last_e = None
#     for e in edges:
#         if prev_state is None:
#             prev_state = e[1]
#             yield e
#         else:
#             if e[1] != prev_state:
#                 prev_state = e[1]
#                 last_e = None
#                 yield e
#             else: # Save last edge so we can yield it at the end
#                 last_e = e
#         
#     if last_e is not None:
#         yield last_e


import itertools
import ripyl.streaming as stream
from ripyl.decode import *
from ripyl.util.bitops import *
from ripyl.sigproc import remove_excess_edges
    
    cpol (int)
        Clock polarity: 0 or 1
    
    cpha (int)
        Clock phase: 0 or 1
    
    lsb_first (bool)
        Flag indicating whether the Least Significant Bit is transmitted first.
    
    idle_start (float)
        The amount of idle time before the transmission of data begins
    
    word_interval (float)
        The amount of time between data words

    idle_end (float)
        The amount of idle time after the last transmission

    Yields a triplet of pairs representing the three edge streams for clk, data_io, and cs
      respectively. Each edge stream pair is in (time, value) format representing the
      time and logic value (0 or 1) for each edge transition. The first set of pairs
      yielded is the initial state of the waveforms.
    '''
    # This is a wrapper around the actual synthesis code in _spi_synth()
    # It unzips the yielded tuple and removes unwanted artifact edges
    clk, data_io, cs = itertools.izip(*_spi_synth(data, word_size, clock_freq, cpol, cpha, \
        lsb_first, idle_start, word_interval, idle_end))
    clk = remove_excess_edges(clk)
    data_io = remove_excess_edges(data_io)

# Path: ripyl/sigproc.py
# def remove_excess_edges(edges):
#     '''Remove incorrect edge transitions from an edge stream
#     
#     This is a generator function.
#     
#     This function is most useful for conditioning the outputs of the protocol
#     synthesizers. For those protocols with multiple signals, the synthesizers
#     myst yield a new output set for *all* signals when any *one* of them changes.
#     This results in non-conforming edge streams that contain multiple consecutive
#     pairs with a non-changing value.
#     
#     edges (iterable of (float, int) tuples)
#         An edge stream to filter for extraneous non-edges
#         
#     Yields an edge stream.
#     '''
#     prev_state = None
#     last_e = None
#     for e in edges:
#         if prev_state is None:
#             prev_state = e[1]
#             yield e
#         else:
#             if e[1] != prev_state:
#                 prev_state = e[1]
#                 last_e = None
#                 yield e
#             else: # Save last edge so we can yield it at the end
#                 last_e = e
#         
#     if last_e is not None:
#         yield last_e


# Path: ripyl/protocol/spi.py
import itertools
import ripyl.streaming as stream
from ripyl.decode import *
from ripyl.util.bitops import *
from ripyl.sigproc import remove_excess_edges

    
    cpol (int)
        Clock polarity: 0 or 1
    
    cpha (int)
        Clock phase: 0 or 1
    
    lsb_first (bool)
        Flag indicating whether the Least Significant Bit is transmitted first.
    
    idle_start (float)
        The amount of idle time before the transmission of data begins
    
    word_interval (float)
        The amount of time between data words

    idle_end (float)
        The amount of idle time after the last transmission

    Yields a triplet of pairs representing the three edge streams for clk, data_io, and cs
      respectively. Each edge stream pair is in (time, value) format representing the
      time and logic value (0 or 1) for each edge transition. The first set of pairs
      yielded is the initial state of the waveforms.
    '''
    # This is a wrapper around the actual synthesis code in _spi_synth()
    # It unzips the yielded tuple and removes unwanted artifact edges
    clk, data_io, cs = itertools.izip(*_spi_synth(data, word_size, clock_freq, cpol, cpha, \
        lsb_first, idle_start, word_interval, idle_end))
    clk = remove_excess_edges(clk)
    data_io = remove_excess_edges(data_io)

    cs = remove_excess_edges(cs)