//! [setup_14] void configure_ac_callback(void) { //! [setup_15] ac_register_callback(&ac_instance, callback_function_ac, AC_CALLBACK_COMPARATOR_0); //! [setup_15] //! [setup_16] ac_enable_callback(&ac_instance, AC_CALLBACK_COMPARATOR_0); //! [setup_16] }
/** * \internal * \brief Setup Function: AC callback mode test. * * This function initializes the AC to generate interrupt when the AC * output toggles. * * \param test Current test case. */ static void setup_ac_callback_mode_test(const struct test_case *test) { enum status_code status = STATUS_ERR_IO; /* Structure for AC configuration */ struct ac_config config; struct ac_chan_config channel_config; /* Set the flag to false */ ac_init_success = false; ac_reset(&ac_inst); ac_get_config_defaults(&config); /* Initialize the AC */ status = ac_init(&ac_inst, AC, &config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC initialization failed"); /* Configure the AC input pin */ struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PA04B_AC_AIN0; system_pinmux_pin_set_config(PIN_PA04B_AC_AIN0, &ac0_pin_conf); /* Channel configuration */ status = STATUS_ERR_IO; ac_chan_get_config_defaults(&channel_config); channel_config.sample_mode = AC_CHAN_MODE_CONTINUOUS; channel_config.positive_input = AC_CHAN_POS_MUX_PIN0; channel_config.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; channel_config.vcc_scale_factor = AC_SCALER_0_50_VOLT; status = ac_chan_set_config(&ac_inst, AC_CHAN_CHANNEL_0, &channel_config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC channel initialization failed"); /* Callback configuration */ status = ac_register_callback(&ac_inst, ac_user_callback, AC_CALLBACK_COMPARATOR_0); test_assert_true(test, status == STATUS_OK, "AC callback registration failed"); /* Enable the AC channel & the module */ ac_chan_enable(&ac_inst, AC_CHAN_CHANNEL_0); ac_enable(&ac_inst); ac_enable_callback(&ac_inst, AC_CALLBACK_COMPARATOR_0); if (status == STATUS_OK) { ac_init_success = true; } }