static int stm32_lptim_cnt_action_read()

in stm32-lptimer-cnt.c [274:316]


static int stm32_lptim_cnt_action_read(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;

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

	switch (function) {
	case COUNTER_FUNCTION_INCREASE:
		/* LP Timer acts as up-counter on input 1 */
		if (synapse->signal->id != count->synapses[0].signal->id) {
			*action = COUNTER_SYNAPSE_ACTION_NONE;
			return 0;
		}

		switch (priv->polarity) {
		case STM32_LPTIM_CKPOL_RISING_EDGE:
			*action = COUNTER_SYNAPSE_ACTION_RISING_EDGE;
			return 0;
		case STM32_LPTIM_CKPOL_FALLING_EDGE:
			*action = COUNTER_SYNAPSE_ACTION_FALLING_EDGE;
			return 0;
		case STM32_LPTIM_CKPOL_BOTH_EDGES:
			*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
			return 0;
		default:
			/* should never reach this path */
			return -EINVAL;
		}
	case COUNTER_FUNCTION_QUADRATURE_X4:
		*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
		return 0;
	default:
		/* should never reach this path */
		return -EINVAL;
	}
}