static int stm32_lptim_cnt_action_write()

in stm32-lptimer-cnt.c [318:352]


static int stm32_lptim_cnt_action_write(struct counter_device *counter,
					struct counter_count *count,
					struct counter_synapse *synapse,
					enum counter_synapse_action action)
{
	struct stm32_lptim_cnt *const priv = counter_priv(counter);
	enum counter_function function;
	int err;

	if (stm32_lptim_is_enabled(priv))
		return -EBUSY;

	err = stm32_lptim_cnt_function_read(counter, count, &function);
	if (err)
		return err;

	/* only set polarity when in counter mode (on input 1) */
	if (function != COUNTER_FUNCTION_INCREASE
	    || synapse->signal->id != count->synapses[0].signal->id)
		return -EINVAL;

	switch (action) {
	case COUNTER_SYNAPSE_ACTION_RISING_EDGE:
		priv->polarity = STM32_LPTIM_CKPOL_RISING_EDGE;
		return 0;
	case COUNTER_SYNAPSE_ACTION_FALLING_EDGE:
		priv->polarity = STM32_LPTIM_CKPOL_FALLING_EDGE;
		return 0;
	case COUNTER_SYNAPSE_ACTION_BOTH_EDGES:
		priv->polarity = STM32_LPTIM_CKPOL_BOTH_EDGES;
		return 0;
	default:
		return -EINVAL;
	}
}