Edge detection
Informative
How to detect pin edges and handle the events. Binding rules: CHI-PORT-MUST-07, CHI-PORT-MUST-08, and CHI-PORT-MUST-09 in Port — Requirements.
Enable edge detection
Port_Init leaves edge detection off on every pin. Enable it per pin with the edge type you want:
Port_SetEdgeDetection(PORT_PIN_BUTTON, PORT_EDGE_CONFIG_RISING); /* NONE/RISING/FALLING/BOTH */
To turn detection back off, set PORT_EDGE_CONFIG_NONE.
Handle the event
When a configured edge occurs, the driver calls the Port_Callout_OnEdgeDetection callout with
the pin id. Fill in its user code block in Port_Callout_Stubs.c
(see The Callout Stub File):
void Port_Callout_OnEdgeDetection(uint16 pinId)
{
if (pinId == PORT_PIN_BUTTON) {
/* the button edge fired */
}
}
The callout runs from whichever service handles the event for that pin:
Interrupt pins — the event is serviced in
Port_Interrupt(define it with theISR()macro; see the general reference).Polling pins — call
Port_PollFunctioncyclically; it services the same events.
Note
The event-handling mode is set per pin in the configuration
(event_handling_mode: Interrupt | Polling). A PORT_EDGE_CONFIG_* value the hardware does
not support raises PORT_DEVERR_PARAM_EDGE_CONFIG (Errors).