skidl.mixins module¶
Mixin classes for SKiDL objects.
This module provides mixin classes that add specific functionality to SKiDL objects. The mixins are designed to be combined with base classes to provide additional capabilities without requiring deep inheritance hierarchies.
- Classes:
PinMixin: Adds pin management functionality to parts and other objects.
- class skidl.mixins.PinMixin[source]¶
Bases:
objectMixin class that adds pin-related methods and functionality to a class.
This mixin provides comprehensive pin management capabilities including: - Adding, removing, and manipulating pins - Pin selection using various criteria (names, numbers, regex patterns) - Pin connection and disconnection operations - Pin aliasing and naming utilities
The mixin maintains a list of pins and provides multiple ways to access them, including bracket notation, attribute access, and iteration.
Examples
>>> class MyPart(PinMixin): ... def __init__(self): ... super().__init__() ... # Add pins to the part ... self.add_pins(Pin(num=1, name='VCC'), Pin(num=2, name='GND')) ... >>> part = MyPart() >>> vcc_pin = part[1] # Get pin by number >>> gnd_pin = part['GND'] # Get pin by name
- add_pins(*pins)[source]¶
Add one or more pins to the part.
This method adds pins to the part and sets up proper relationships and aliases. Each pin gets a back-reference to the part, and automatic aliases are created for pin names and numbers.
- Parameters:
*pins – Variable number of Pin objects or iterables of Pin objects to add to the part.
- Returns:
The part object with pins added, enabling method chaining.
- Return type:
Self
Note
Automatic aliases are created: - Pin name becomes an alias - “p” + pin number becomes an alias (e.g., “p1” for pin 1)
Examples
>>> part.add_pins(Pin(num=1, name='VCC')) >>> part.add_pins([Pin(num=2, name='GND'), Pin(num=3, name='DATA')])
- associate_pins()[source]¶
Ensure all pins have proper back-references to this part.
This method updates each pin’s ‘part’ attribute to point back to this part object, maintaining bidirectional relationships between parts and their pins. This is typically called after pins are added or when the part structure is modified.
- create_pins(base_name, pin_count=None, connections=None)[source]¶
Create one or more pins with systematic naming and numbering.
This method creates multiple pins with names based on a common prefix and systematic numbering. Pins can optionally be connected to provided nets, buses, or other pins during creation.
- Parameters:
base_name (str) – Base name for the pins. Pin indices will be appended to this name (e.g., “DATA” becomes “DATA1”, “DATA2”, etc.).
pin_count (int, range, slice, list, tuple, or None) – Specification of how many pins to create and their numbering: - int N: Creates N pins numbered 1 to N - range or slice: Uses the range values for pin numbers - tuple or list: Uses the provided list of pin numbers - None: Creates single pin without index appended to name
connections (list or scalar, optional) – List of nets, buses, or pins to connect to each created pin. Must match the number of pins created. A scalar Net, Pin, or Bus will will be converted to a list of one item.
- Returns:
The part object with pins created, enabling method chaining.
- Return type:
Self
- Raises:
ValueError – If connections list length doesn’t match number of pins created.
Examples
>>> part.create_pins("DATA", 8) # Creates DATA1, DATA2, ..., DATA8 >>> part.create_pins("ADDR", range(0, 16)) # Creates ADDR0 to ADDR15 >>> part.create_pins("CLK", None) # Creates single pin named "CLK" >>> part.create_pins("IO", 4, [net1, net2, net3, net4]) # With connections
- disconnect()[source]¶
Disconnect all pins from their connected nets.
This method breaks all electrical connections to the part by disconnecting each pin from any nets it may be connected to. The part becomes electrically isolated after this operation.
Examples
>>> part.disconnect() # Disconnect all pins from nets
- get_pins(*pin_ids, **criteria)[source]¶
Get pins matching specified identifiers and criteria.
This is the core pin selection method that supports multiple selection modes including exact matching, regex patterns, and attribute-based filtering. It provides flexible pin selection capabilities for various use cases.
- Parameters:
*pin_ids – Pin identifiers for selection: - Integers or strings for exact pin number matches - Strings for exact pin name/alias matches - Regex patterns (when regex matching enabled) - Slices for pin number ranges - Lists/tuples of any combination above If empty, selects all pins.
- Keyword Arguments:
criteria – Attribute-based filtering criteria as key=value pairs.
silent (bool, optional) – Suppress error messages if True. Defaults to False.
only_search_numbers (bool, optional) – Restrict search to pin numbers only. Defaults to False.
only_search_names (bool, optional) – Restrict search to pin names/aliases only. Defaults to False.
match_regex (bool, optional) – Enable regex pattern matching for names. Defaults to False, or uses part’s match_pin_regex setting.
- Returns:
Single Pin object if exactly one match found
List of Pin objects if multiple matches found
None if no matches found and silent=True
- Return type:
- Raises:
ValueError – If no pins found and silent=False.
Examples
>>> pins = part.get_pins(1, 2, 3) # Get pins 1, 2, 3 >>> analog_pins = part.get_pins(func='analog') # Pins with analog function >>> power_pins = part.get_pins('VCC', 'VDD', 'GND') # Named pins >>> pattern_pins = part.get_pins('A[0-9]+', match_regex=True) # Regex
- property match_pin_regex¶
Get the enable/disable flag for pin regular-expression matching.
- Returns:
Current state of regex matching flag.
- Return type:
- property ordered_pins¶
Get the pins sorted in a consistent order.
Returns the part’s pins in sorted order, typically by pin number where possible, falling back to name-based sorting for non-numeric pins.
- Returns:
Sorted list of the part’s Pin objects.
- Return type:
Examples
>>> sorted_pins = part.ordered_pins >>> for pin in part.ordered_pins: ... print(f"Pin {pin.num}: {pin.name}")
- rename_pin(pin_id, new_pin_name)[source]¶
Change the name of a pin.
Finds the pin matching the given identifier and updates its name to the new value.
- Parameters:
pin_id – Current identifier (name or number) of the pin to rename.
new_pin_name (str) – New name to assign to the pin.
Examples
>>> part.rename_pin(1, 'POWER') # Rename pin 1 to 'POWER' >>> part.rename_pin('RESET', 'RST') # Rename RESET pin to RST
- renumber_pin(pin_id, new_pin_num)[source]¶
Change the number of a pin.
Finds the pin matching the given identifier and updates its number to the new value.
- Parameters:
pin_id – Current identifier (name or number) of the pin to renumber.
new_pin_num – New number to assign to the pin.
Examples
>>> part.renumber_pin('RESET', 100) # Change RESET pin to number 100 >>> part.renumber_pin(1, 5) # Change pin 1 to pin 5
- rmv_pins(*pin_ids)[source]¶
Remove one or more pins from the part.
Removes pins that match the given identifiers (names or numbers). The pins are permanently removed from the part’s pin list.
- Parameters:
*pin_ids – Pin identifiers (names or numbers) of pins to remove.
Examples
>>> part.rmv_pins(1, 'RESET') # Remove pin 1 and RESET pin >>> part.rmv_pins('VCC', 'GND') # Remove power pins
- split_pin_names(delimiters)[source]¶
Split pin names using delimiters and add subnames as aliases.
This method takes pin names that contain delimiter characters and splits them into component parts, adding each part as an alias to the pin. This enables more flexible pin access patterns.
- Parameters:
delimiters (str) – String containing characters to use as delimiters for splitting pin names.
Examples
>>> part.split_pin_names('_-/') # Split on underscore, dash, slash >>> # Pin named "DATA_IN" would get aliases "DATA" and "IN"
- swap_pins(pin_id1, pin_id2)[source]¶
Swap the names and numbers between two pins.
This method exchanges the name and number attributes between two pins, effectively swapping their identities while maintaining their physical connections and other properties.
- Parameters:
pin_id1 – Identifier (name or number) of the first pin.
pin_id2 – Identifier (name or number) of the second pin.
Examples
>>> part.swap_pins(1, 2) # Swap pins 1 and 2 >>> part.swap_pins('RESET', 'ENABLE') # Swap named pins
