Skip to content

052 GPIO Expander Pins ​

052-gpio-expander-pins.mc always declares eight GPIO signals plus power and ground. When partno equals "GPIO16", this block appends eight more pins:

text
pins += [
    io [11:18] = GPIO[8:15]
]

+= extends the existing pins list instead of replacing it. Square-bracketed [11:18] is a physical-pin range, while GPIO[8:15] expands indexed signal names from GPIO8 through GPIO15. Here, partno::STRING = "GPIO8" introduces a default parameter value. U_SMALL omits the argument and resolves to 10 pins total; U_LARGE passes "GPIO16" and resolves to 18. Both variants have VCC, GND, and GPIO0 connected, so the shared base pins can be compared. LARGE_GPIO8 -> U_LARGE.GPIO8 then accesses one of the names added by pins +=; the smaller variant has no GPIO8 member.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 05-dynamic-pins-and-conditions/052-gpio-expander-pins.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 05-dynamic-pins-and-conditions/052-gpio-expander-pins.mc --lib mcode --viz -o 05-dynamic-pins-and-conditions/052-gpio-expander-pins.html

Source ​

text
// Example: GPIO Expander Pins
// Goal: Add more pins for a larger device variant.
// Language focus: if, pins +=, pin ranges.

component GPIO_EXPANDER(partno::STRING = "GPIO8")
{
    name = "GPIO Expander"
    pins = [
        io [1:8] = GPIO[0:7]
        psnk [9,10] = [VCC, GND]
    ]

    if (partno == "GPIO16")
    {
        pins += [
            io [11:18] = GPIO[8:15]
        ]
    }
}

module main
{
    io GND
    io LARGE_GPIO0
    io LARGE_GPIO8
    io SMALL_GPIO0
    io V3V3

    DC.SRC PWR(3.3V, 100mA)
    GPIO_EXPANDER            U_SMALL
    GPIO_EXPANDER("GPIO16") U_LARGE

    PWR.1 -> V3V3
    PWR.2 -> GND

    V3V3 -> U_SMALL.VCC
    U_SMALL.GND -> GND
    SMALL_GPIO0 -> U_SMALL.GPIO0

    V3V3 -> U_LARGE.VCC
    U_LARGE.GND -> GND
    LARGE_GPIO0 -> U_LARGE.GPIO0
    // GPIO8 exists only on the GPIO16 variant.
    LARGE_GPIO8 -> U_LARGE.GPIO8
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.