/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#ifndef RX_ENCODER_H
#define RX_ENCODER_H

#include <stdint.h>

typedef enum
{
    RX_ENCODER_DIR_CW = 1,
    RX_ENCODER_DIR_CCW = -1,
} rx_encoder_dir_t;

/**
 * @brief Structure representing the NEO Encoder.
 */
typedef struct
{
    uint32_t count;                             /**< Current count of the NEO Encoder. */
    uint32_t direction;                         /**< Current count of the NEO Encoder. */
    rx_encoder_dir_t polarity;                  /**< Polarity of the encoder. */
    char name[32];                           /**< Name of the encoder object. */
    void (*clear_sync)();                       /**< Callback function to clear count syncronously*/
    void (*clear_async)();                      /**< Callback function to clear count syncronously*/
    void (*set_polarity)(rx_encoder_dir_t dir); /**< Callback function to set the polarity of the encoder. */
    struct k_work work;                         /**< Work item for the encoder. */
} rx_encoder_t;

/**
 * @brief Initializes the NEO Encoder module.
 *
 * This function initializes the NEO Encoder module by configuring the GPIO pins
 * for the encoder channels.
 *
 * @param dose_enc_a The GPIO specification for the encoder channel A.
 * @param dose_enc_b The GPIO specification for the encoder channel B.
 */
void rx_encoder_init(rx_encoder_t *en, const struct gpio_dt_spec *dose_enc_a, const struct gpio_dt_spec *dose_enc_b);

#endif
