void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh) { if (hw == NULL) { // we can get NULL driver if user somehow has invalid pin in his configuration warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "s_not input pin"); return; } hw->isActiveHigh = isActiveHigh; if (hw->isActiveHigh) { wave_icucfg.mode = ICU_INPUT_ACTIVE_HIGH; } else { wave_icucfg.mode = ICU_INPUT_ACTIVE_LOW; } ICUDriver *driver = hw->driver; if (driver != NULL) { if (hw->started) { icuDisableNotificationsI(driver); icuStopCapture(driver); icuStop(driver); } wave_icucfg.channel = getInputCaptureChannel(hw->brainPin); efiIcuStart(msg, driver, &wave_icucfg); efiAssertVoid(CUSTOM_ERR_6672, driver != NULL, "di: driver is NULL"); efiAssertVoid(CUSTOM_ERR_6673, driver->state == ICU_READY, "di: driver not ready"); icuStartCapture(driver); // this would change state from READY to WAITING icuEnableNotifications(driver); } hw->started = true; }
static ICUDriver *turnOnTriggerInputPin(brain_pin_e hwPin) { // configure pin turnOnCapturePin(hwPin); shaft_icucfg.channel = ICU_CHANNEL_1; ICUDriver *driver = getInputCaptureDriver(hwPin); scheduleMsg(logger, "turnOnTriggerInputPin %s", hwPortname(hwPin)); // todo: reuse 'setWaveReaderMode' method here? if (driver != NULL) { bool_t needWidthCallback = !CONFIG(useOnlyFrontForTrigger) || TRIGGER_SHAPE(useRiseEdge); shaft_icucfg.width_cb = needWidthCallback ? shaft_icu_width_callback : NULL; bool_t needPeriodCallback = !CONFIG(useOnlyFrontForTrigger) || !TRIGGER_SHAPE(useRiseEdge); shaft_icucfg.period_cb = needPeriodCallback ? shaft_icu_period_callback : NULL; efiIcuStart(driver, &shaft_icucfg); icuEnable(driver); } return driver; }