/** * \brief Analog comparator interrupt callback function * * This function is called when an interrupt has occurred on a channel in analog * comparator. * * \param ac Pointer to the analog comparator (AC) base address which caused * the interrupt * \param channel The analog comparator channel that caused the interrupt * \param status Analog comparator window status given by a \ref ac_status_t * value */ static void example_aca_interrupt_callback(AC_t *ac, uint8_t channel, enum ac_status_t status) { /* * If trigger was caused by moving into above or below, switch to * trigger by being inside. If trigger was caused by moving inside the * window, switch to trigger on outside. */ if (status != AC_STATUS_INSIDE) { ac_set_interrupt_mode(&aca_config, AC_INT_MODE_INSIDE_WINDOW); } else { ac_set_interrupt_mode(&aca_config, AC_INT_MODE_OUTSIDE_WINDOW); } ac_disable(&ACA, 1); ac_disable(&ACA, 0); ac_write_config(&ACA, 0, &aca_config); ac_enable(&ACA, 0); ac_enable(&ACA, 1); example_ac_update_window_leds(status); }
/** \brief Resets and disables the Analog Comparator driver. * * Resets and disables the Analog Comparator driver, resets the internal * states and registers of the hardware module to their power-on defaults. * * \param[out] module_inst Pointer to the AC software instance struct */ enum status_code ac_reset( struct ac_module *const module_inst) { /* Sanity check arguments */ Assert(module_inst); Assert(module_inst->hw); Ac *const ac_module = module_inst->hw; /* Disable the hardware module */ ac_disable(module_inst); while (ac_is_syncing(module_inst)) { /* Wait until synchronization is complete */ } /* Software reset the module */ ac_module->CTRLA.reg |= AC_CTRLA_SWRST; return STATUS_OK; }