How to use the skidl.Pin.Pin function in skidl

To help you get started, we’ve selected a few skidl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xesscorp / skidl / skidl / Part.py View on Github external
ios = ",".join(io).split(INDEX_SEPARATOR)

        # Add a pin to the part for each pin name.
        for i, arg in enumerate(ios):
            arg = arg.strip()  # Strip any spaces that may have been between pin names.

            # If [pin_name] or pin_name[], then add a PinList to the part. Don't use
            # part.add_pins() because it will flatten the PinList and add nothing since
            # the PinList is empty.
            if arg[0] + arg[-1] == "[]":
                self.pins.append(PinList(num=i, name=arg[1:-1], part=self))
            elif arg[-2:] == "[]":
                self.pins.append(PinList(num=i, name=arg[0:-2], part=self))
            else:
                # Add a simple, non-vector pin.
                self.add_pins(Pin(num=i, name=arg))
github xesscorp / skidl / skidl / skidl.py View on Github external
builtins.default_circuit = Circuit()
# NOCONNECT net for attaching pins that are intentionally left open.
builtins.NC = default_circuit.NC  # pylint: disable=undefined-variable

# Create calls to functions on whichever Circuit object is the current default.
ERC = default_circuit.ERC  # pylint: disable=undefined-variable
generate_netlist = (
    default_circuit.generate_netlist
)  # pylint: disable=undefined-variable
generate_xml = default_circuit.generate_xml  # pylint: disable=undefined-variable
generate_graph = default_circuit.generate_graph  # pylint: disable=undefined-variable
reset = default_circuit.reset  # pylint: disable=undefined-variable
backup_parts = default_circuit.backup_parts  # pylint: disable=undefined-variable

# Define a tag for nets that convey power (e.g., VCC or GND).
POWER = Pin.drives.POWER


def no_files(circuit=default_circuit):
    """Prevent creation of output files (netlists, ERC, logs) by this Circuit object."""
    circuit.no_files = True
    erc_logger.stop_file_output()
    logger.stop_file_output()
github xesscorp / skidl / skidl / Net.py View on Github external
def __init__(self, name=None, circuit=None, *pins_nets_buses, **attribs):
        from .Pin import Pin

        super().__init__()

        self._valid = True  # Make net valid before doing anything else.
        self.do_erc = True
        self._drive = Pin.drives.NONE
        self.pins = []
        self.circuit = None
        self.code = None  # This is the net number used in a KiCad netlist file.

        # Set the net name directly to the passed-in name without any adjustment.
        # The net name will be adjusted when it is added to the circuit which
        # may already have a net with the same name.
        self._name = name

        # Add the net to the passed-in circuit or to the default circuit.
        if circuit is None:
            circuit = builtins.default_circuit
        circuit += self

        # Attach whatever pins were given.
        self.connect(pins_nets_buses)
github xesscorp / skidl / skidl / tools / kicad.py View on Github external
# Replicate the KiCad pin fields as attributes in the Pin object.
        # Note that this update will not give the pins valid references
        # to the current part, but we'll fix that soon.
        p.__dict__.update(kicad_pin)

        pin_type_translation = {
            "I": Pin.types.INPUT,
            "O": Pin.types.OUTPUT,
            "B": Pin.types.BIDIR,
            "T": Pin.types.TRISTATE,
            "P": Pin.types.PASSIVE,
            "U": Pin.types.UNSPEC,
            "W": Pin.types.PWRIN,
            "w": Pin.types.PWROUT,
            "C": Pin.types.OPENCOLL,
            "E": Pin.types.OPENEMIT,
            "N": Pin.types.NOCONNECT,
        }
        p.func = pin_type_translation[
            p.electrical_type
        ]  # pylint: disable=no-member, attribute-defined-outside-init

        return p
github xesscorp / skidl / skidl / Pin.py View on Github external
try:
            del self._drive
        except AttributeError:
            pass

    def __bool__(self):
        """Any valid Pin is True."""
        return True

    __nonzero__ = __bool__  # Python 2 compatibility.


##############################################################################


class PhantomPin(Pin):
    """
    A pin type that exists solely to tie two pinless nets together.
    It will not participate in generating any netlists.
    """

    def __init__(self, **attribs):
        super().__init__(**attribs)
        self.nets = []
        self.part = None
        self.do_erc = False


##############################################################################


class PinList(list):
github xesscorp / skidl / skidl / Pin.py View on Github external
# This will make all the Pin.drive members into attributes of the Pin class
# so things like Pin.INPUT will work as well as Pin.types.INPUT.
Pin.add_type()

# Create the pin conflict matrix as a defaultdict of defaultdicts which
# returns OK if the given element is not in the matrix. This would indicate
# the pin types used to index that element have no contention if connected.
conflict_matrix = defaultdict(lambda: defaultdict(lambda: [OK, ""]))

# Add the non-OK pin connections to the matrix.
conflict_matrix[Pin.types.OUTPUT][Pin.types.OUTPUT] = [ERROR, ""]
conflict_matrix[Pin.types.TRISTATE][Pin.types.OUTPUT] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.INPUT] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.OUTPUT] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.BIDIR] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.TRISTATE] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.PASSIVE] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.PULLUP] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.PULLDN] = [WARNING, ""]
conflict_matrix[Pin.types.UNSPEC][Pin.types.UNSPEC] = [WARNING, ""]
conflict_matrix[Pin.types.PWRIN][Pin.types.TRISTATE] = [WARNING, ""]
conflict_matrix[Pin.types.PWRIN][Pin.types.UNSPEC] = [WARNING, ""]
conflict_matrix[Pin.types.PWROUT][Pin.types.OUTPUT] = [ERROR, ""]
conflict_matrix[Pin.types.PWROUT][Pin.types.BIDIR] = [WARNING, ""]
conflict_matrix[Pin.types.PWROUT][Pin.types.TRISTATE] = [ERROR, ""]
conflict_matrix[Pin.types.PWROUT][Pin.types.UNSPEC] = [WARNING, ""]
conflict_matrix[Pin.types.PWROUT][Pin.types.PWROUT] = [ERROR, ""]
conflict_matrix[Pin.types.OPENCOLL][Pin.types.OUTPUT] = [ERROR, ""]
conflict_matrix[Pin.types.OPENCOLL][Pin.types.TRISTATE] = [ERROR, ""]
conflict_matrix[Pin.types.OPENCOLL][Pin.types.UNSPEC] = [WARNING, ""]
conflict_matrix[Pin.types.OPENCOLL][Pin.types.PWROUT] = [ERROR, ""]
github xesscorp / skidl / skidl / Net.py View on Github external
def __init__(self, name=None, circuit=None, *pins_nets_buses, **attribs):
        from .Pin import Pin

        super().__init__(name=name, circuit=circuit, *pins_nets_buses, **attribs)
        self._drive = Pin.drives.NOCONNECT
        self.do_erc = False  # No need to do ERC on no-connect nets.
github xesscorp / skidl / skidl / Net.py View on Github external
# Go through all the pins and/or nets and connect them to this net.
        for pn in expand_buses(flatten(pins_nets_buses)):
            if isinstance(pn, ProtoNet):
                pn += self
            elif isinstance(pn, Net):
                if pn.circuit == self.circuit:
                    merge(pn)
                else:
                    log_and_raise(
                        logger,
                        ValueError,
                        "Can't attach nets in different circuits ({}, {})!".format(
                            pn.circuit.name, self.circuit.name
                        ),
                    )
            elif isinstance(pn, Pin):
                if not pn.part or pn.part.circuit == self.circuit:
                    if not pn.part:
                        logger.warning(
                            "Attaching non-part Pin {} to a Net {}.".format(
                                pn.name, self.name
                            )
                        )
                    connect_pin(pn)
                else:
                    log_and_raise(
                        logger,
                        ValueError,
                        "Can't attach a part to a net in different circuits ({}, {})!".format(
                            pn.part.circuit.name, self.circuit.name
                        ),
                    )