032 Pin Directions And Ranges
032-pin-directions-and-ranges.mc adds meaning to the named pins from 031 without introducing interfaces yet:
text
pins = [
in 1 = ENABLE
out 2 = READY
io [3:4] = GPIO[1:2]
psnk [5,6] = [VCC, GND]
]inmarks a signal received by the device, whileoutmarks a signal driven by the device. These keywords document the component pin's electrical role; connections still use the same->syntax learned earlier.iomarks a bidirectional signal, andpsnkmarks a power-supply pin that draws current.psnk [5,6] = [VCC, GND]pairs the hot terminal with the return it closes over: the return is named, but carries no direction word of its own — the direction belongs to the power pin the row heads.[3:4]is an inclusive physical-pin range, so it covers pins 3 and 4.GPIO[1:2]expands to two indexed names,GPIO1andGPIO2. The physical range and name range contain the same number of entries, so they pair in order: pin 3 isGPIO1, and pin 4 isGPIO2.U_IO.GPIO1still uses the ordinaryinstance.memberaccess introduced in031; no nested interface path is involved.
The four signal connections also make the directions readable in context: ENABLE enters the device, READY leaves it, and the two GPIO pins may be used in either direction.
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/032-pin-directions-and-ranges.mc --lib mcode --pass1 --pass2
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 03-define-components-and-interfaces/032-pin-directions-and-ranges.mc --lib mcode --viz -o 03-define-components-and-interfaces/032-pin-directions-and-ranges.htmlSource
text
// Example: Pin Directions And Ranges
// Goal: Describe simple input, output, bidirectional, and power pins.
// Language focus: in, out, io, psnk, physical pin ranges, indexed pin names.
component SIMPLE_IO_DEVICE
{
name = "Simple I/O Device"
pins = [
in 1 = ENABLE
out 2 = READY
io [3:4] = GPIO[1:2]
psnk [5,6] = [VCC, GND]
]
}
module main
{
io ENABLE
io GND
io GPIO1
io GPIO2
io READY
io V3V3
DC.SRC PWR(3.3V, 20mA)
SIMPLE_IO_DEVICE U_IO
PWR.1 -> V3V3
PWR.2 -> GND
V3V3 -> U_IO.VCC
U_IO.GND -> GND
ENABLE -> U_IO.ENABLE
U_IO.READY -> READY
GPIO1 -> U_IO.GPIO1
U_IO.GPIO2 -> GPIO2
}