2.88.4 PTG_EventCallbackRegister Function
C
void PTG_EventCallbackRegister(PTG_EVENTS event, PTG_EVENTS_CALLBACK callback_fn, uintptr_t context)
Summary
Registers a callback function for PTG Peripheral events.
Description
This function allows the application to register a callback function that the PLIB will call when a particular trigger event has occurred.
The function also allows the application to specify a context value (usually a pointer to a structure or data) that is passed into the callback function when it is executed. The registered callback will be invoked from the peripheral interrupt context. Therefore, the callback function should be lightweight and quick.
The callback function must be registered before initiating step sequence operation.
Precondition
The `PTG_Initialize()` function must have been called. PTG sould be enabled and configured properly using the Configurations Options GUI. The interrupts for the particular events must be enabled.
Parameters
| Param | Description |
|---|---|
| callback | A pointer to a function with a calling signature defined by the `PTG_EVENT_CALLBACK` data type. Setting this to `NULL` disables the callback feature. |
| context | A value (usually a pointer) that is passed into the callback function when it is invoked. |
Returns
None.
Example
void MyPTGEventHandler(PTG_EVENTS event, uintptr_t context) { printf("Trigger hit event detected!\n"); } int main() { PTG_Initialize(); PTG_EventCallbackRegister(PTG_EVENT_TRIGGER_HIT, MyPTGEventHandler, (uintptr_t)NULL); PTG_Enable(); PTG_StepSequenceStart(); while (1) { // Main loop tasks } return 0; }
Remarks
None.
