In the Analog Comparator (AC) asynchronous driver, a callback function can be registered in the driver by the application and triggered when comparison is done to let the application know the comparison result.
Initialize and deinitialize the driver and associated hardware
Hookup callback handlers on comparison done
Enable or disable AC comparator
Start single-short comparison if signal-shot mode is enabled (no need to start for continuous mode)
Select positive and negative input for AC comparator
Select single shot or continuous measurement mode
Filter length and hysteresis setting, etc.
Run in Standby or Debug mode
Various aspects of Event control
After the AC hardware initialization, the application can register the callback function for comparison done by ac_async_register_callback.
The following shows a simple example of using the AC. The AC must have been initialized by ac_async_init. This initialization will configure the operation of the AC, such as input pins, single-shot, or continuous measurement mode, etc.
The example registers a callback function for comparison ready and enables comparator 0 of AC, and then finally starts a voltage comparison on this comparator.
static void ready_cb_AC_0(struct ac_async_descriptor *const descr, const uint8_t comp, const uint8_t result) { /* Handle date here */ } /** * Example of using AC_0 to compare the voltage level. */ void AC_0_example(void) { ac_async_register_callback(&AC_0, AC_COMPARISON_READY_CB, (ac_cb_t)ready_cb_AC_0); ac_async_enable(&AC_0); ac_async_start_comparison(&AC_0, 0); }
The AC peripheral and its related I/O lines and clocks
The NVIC must be configured so that AC interrupt requests are periodically serviced