Common mistakes
Informative
Pitfalls when using the Port driver, and how to avoid them. Each maps to a rule in Port — Requirements or an error in Errors.
Passing a real pointer to
Port_Init.configPtrMUST beNULL_PTR— a non-null pointer raisesPORT_DEVERR_PARAM_POINTER(CHI-PORT-MUST-02). The configuration is selected at build time.Expecting to reconfigure a pin at runtime. A pin’s function
modeanddirectionare fixed byPort_Init; there is no API to change them later. Only edge detection is runtime-settable (CHI-PORT-MUST-01).Using raw pin/port numbers. Address pins and ports through the generated symbols (
PORT_PIN_<...>/PORT_PORT_<...>); a pin id is(portId << 8) | pinIndexand an unconfigured pin raisesPORT_DEVERR_PARAM_PIN(CHI-PORT-MUST-11).Rewriting a whole port to change one pin. Use
Port_SetMaskedPortValuewith a mask so only the intended pins change and the update is atomic; a plain full-port write clobbers the others (CHI-PORT-MUST-06).Assuming defined behavior when writing an input pin.
Port_SetPinValueon an input pin is implementation-defined — don’t rely on it to steer pull-ups/downs portably (CHI-PORT-MUST-04).Forgetting edge detection starts disabled.
Port_Initdisables detection on every pin; callPort_SetEdgeDetectionto enable it before expectingPort_Callout_OnEdgeDetection(CHI-PORT-MUST-07).Not servicing polled pins. A pin configured for
PollingneedsPort_PollFunctioncalled cyclically, or its edge events never fire (CHI-PORT-MUST-09).Treating a read error as a valid LOW. On error the Get APIs return
PORT_PIN_VALUE_LOW(or all-LOW for a port) — indistinguishable from a genuine low, so validate the pin id first (CHI-PORT-MUST-03).