Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Tools: Add lcsc & mfr flag to libadd for auto-module #45

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

iopapamanoglou
Copy link
Contributor

@iopapamanoglou iopapamanoglou commented Sep 9, 2024

Tools: Add lcsc & mfr flag to libadd for auto-module

Description

Adding --mfr or --lcsc to libadd will now result in automatically adding
datasheets, designator, name, descriptive_properties, interfaces & pin
heuristics to the module.

❯ faebryk libadd STM32G030K6T6 module --mfr
image

# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging

import faebryk.library._F as F  # noqa: F401
from faebryk.core.module import Module
from faebryk.libs.library import L  # noqa: F401
from faebryk.libs.picker.picker import DescriptiveProperties
from faebryk.libs.units import P  # noqa: F401

logger = logging.getLogger(__name__)


class STMicroelectronics_STM32G030K6T6(Module):
    """
    TODO: Docstring describing your module

    32KB 2V~3.6V ARM-M0 8KB 64MHz FLASH 30 LQFP-32(7x7)
    Microcontrollers (MCU/MPU/SOC) ROHS
    """

    # ----------------------------------------
    #     modules, interfaces, parameters
    # ----------------------------------------
    # TODO: Change auto-generated interface types to actual high level types
    NRST: F.Electrical
    PA0: F.Electrical
    PA1: F.Electrical
    PA10: F.Electrical
    PA11PA9: F.Electrical
    PA12PA10: F.Electrical
    PA13: F.Electrical
    PA14_BOOT0: F.Electrical
    PA15: F.Electrical
    PA2: F.Electrical
    PA3: F.Electrical
    PA4: F.Electrical
    PA5: F.Electrical
    PA6: F.Electrical
    PA7: F.Electrical
    PA8: F.Electrical
    PA9: F.Electrical
    PB0: F.Electrical
    PB1: F.Electrical
    PB2: F.Electrical
    PB3: F.Electrical
    PB4: F.Electrical
    PB5: F.Electrical
    PB6: F.Electrical
    PB7: F.Electrical
    PB8: F.Electrical
    PB9: F.Electrical
    PC14_OSC32IN: F.Electrical
    PC15_OSC32OUT: F.Electrical
    PC6: F.Electrical
    VDD_VDDA: F.Electrical
    VSS_VSSA: F.Electrical

    # ----------------------------------------
    #                 traits
    # ----------------------------------------
    designator_prefix = L.f_field(F.has_designator_prefix_defined)("U")
    descriptive_properties = L.f_field(F.has_descriptive_properties_defined)(
        {
            DescriptiveProperties.manufacturer: "STMicroelectronics",
            DescriptiveProperties.partno: "STM32G030K6T6",
        }
    )
    datasheet = L.f_field(F.has_datasheet_defined)(
        "https://wmsc.lcsc.com/wmsc/upload/file/pdf/v2/lcsc/2304140030_STMicroelectronics-STM32G030K6T6_C529331.pdf"
    )

    @L.rt_field
    def pin_association_heuristic(self):
        return F.has_pin_association_heuristic_lookup_table(
            mapping={
                self.PB9: ["PB9"],
                self.PA3: ["PA3"],
                self.PA4: ["PA4"],
                self.PA5: ["PA5"],
                self.PA6: ["PA6"],
                self.PA7: ["PA7"],
                self.PB0: ["PB0"],
                self.PB1: ["PB1"],
                self.PB2: ["PB2"],
                self.PA8: ["PA8"],
                self.PA9: ["PA9"],
                self.PC14_OSC32IN: ["PC14-OSC32IN"],
                self.PC6: ["PC6"],
                self.PA10: ["PA10"],
                self.PA11PA9: ["PA11[PA9]"],
                self.PA12PA10: ["PA12[PA10]"],
                self.PA13: ["PA13"],
                self.PA14_BOOT0: ["PA14-BOOT0"],
                self.PA15: ["PA15"],
                self.PB3: ["PB3"],
                self.PB4: ["PB4"],
                self.PB5: ["PB5"],
                self.PC15_OSC32OUT: ["PC15-OSC32OUT"],
                self.PB6: ["PB6"],
                self.PB7: ["PB7"],
                self.PB8: ["PB8"],
                self.VDD_VDDA: ["VDD/VDDA"],
                self.VSS_VSSA: ["VSS/VSSA"],
                self.NRST: ["NRST"],
                self.PA0: ["PA0"],
                self.PA1: ["PA1"],
                self.PA2: ["PA2"],
            },
            accept_prefix=False,
            case_sensitive=False,
        )

    def __preinit__(self):
        # ------------------------------------
        #           connections
        # ------------------------------------

        # ------------------------------------
        #          parametrization
        # ------------------------------------
        pass

❯ faebryk libadd WJ2EDGK-5.08-3 module --mfr
image

# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging

import faebryk.library._F as F  # noqa: F401
from faebryk.core.module import Module
from faebryk.libs.library import L  # noqa: F401
from faebryk.libs.picker.picker import DescriptiveProperties
from faebryk.libs.units import P  # noqa: F401

logger = logging.getLogger(__name__)


class Ningbo_Kangnex_Elec_WJ2EDGK_5_08_3P(Module):
    """
    TODO: Docstring describing your module

    3 1 5.08mm 1x3P Green Plug P=5.08mm
    Pluggable System Terminal Block ROHS
    """

    # ----------------------------------------
    #     modules, interfaces, parameters
    # ----------------------------------------
    # TODO: Change auto-generated interface types to actual high level types
    unnamed = L.list_field(3, F.Electrical)

    # ----------------------------------------
    #                 traits
    # ----------------------------------------
    designator_prefix = L.f_field(F.has_designator_prefix_defined)("P")
    descriptive_properties = L.f_field(F.has_descriptive_properties_defined)(
        {
            DescriptiveProperties.manufacturer: "Ningbo Kangnex Elec",
            DescriptiveProperties.partno: "WJ2EDGK-5.08-3P",
        }
    )
    datasheet = L.f_field(F.has_datasheet_defined)(
        "https://wmsc.lcsc.com/wmsc/upload/file/pdf/v2/lcsc/1912251642_Ningbo-Kangnex-Elec-WJ2EDGK-5-08-3P_C71371.pdf"
    )

    @L.rt_field
    def pin_association_heuristic(self):
        return F.has_pin_association_heuristic_lookup_table(
            mapping={
                self.unnamed[0]: ["1"],
                self.unnamed[1]: ["2"],
                self.unnamed[2]: ["3"],
            },
            accept_prefix=False,
            case_sensitive=False,
        )

    def __preinit__(self):
        # ------------------------------------
        #           connections
        # ------------------------------------

        # ------------------------------------
        #          parametrization
        # ------------------------------------
        pass

Checklist

Please read and execute the following:

  • My code follows the coding guidelines of this project
  • My PR title is following the contribution guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I ran Black to format my code

Code of Conduct

By submitting this issue, you agree to follow our Code of Conduct:

Adding --mfr or --lcsc to libadd will now result in automatically adding
datasheets, designator, name, descriptive_properties, interfaces & pin
heuristics to the module.
@iopapamanoglou iopapamanoglou merged commit 6cf4dc7 into main Sep 9, 2024
1 check passed
@iopapamanoglou iopapamanoglou deleted the feature/libadd_mfr_lcsc branch September 9, 2024 09:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant