/**
 * @file digital_outputs_driver.h
 * @brief Simplified Driver for controlling 8 independent open-drain digital outputs on STM32F103C8T6
 * @author Embedded Systems Software Engineer
 * @date 2023
 */

#ifndef DIGITAL_OUTPUTS_DRIVER_H
#define DIGITAL_OUTPUTS_DRIVER_H

#include "main.h"
#include <stdint.h>
#include <stddef.h> // For NULL definition

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Digital output pin identifiers (Index-based)
 */
typedef enum {
    OUTPUT_PIN_0 = 0,
    OUTPUT_PIN_1,
    OUTPUT_PIN_2,
    OUTPUT_PIN_3,
    OUTPUT_PIN_4,
    OUTPUT_PIN_5,
    OUTPUT_PIN_6,
    OUTPUT_PIN_7,
    OUTPUT_PINS_COUNT
} digital_output_pin_t;

/**
 * @brief Initializes the GPIO hardware and sets initial states.
 * @retval None
 */
void digital_outputs_init(void);

/**
 * @brief Sets the state of a specific output pin (open-drain)
 * @param pin Pin identifier (0 to OUTPUT_PINS_COUNT - 1)
 * @param state Desired state (0 = LOW, 1 = HIGH)
 * @retval None
 */
void digital_outputs_set_state(digital_output_pin_t pin, uint8_t state);

/**
 * @brief Gets the current state of a specific output pin
 * @param pin Pin identifier
 * @param p_state Pointer to a variable where the state will be stored
 * @retval None
 */
void digital_outputs_get_state(digital_output_pin_t pin, uint8_t* p_state);

/**
 * @brief Toggles the state of a specific output pin
 * @param pin Pin identifier
 * @retval None
 */
void digital_outputs_toggle(digital_output_pin_t pin);

/**
 * @brief Resets all outputs to LOW (0)
 * @retval None
 */
void digital_outputs_reset_all(void);

#ifdef __cplusplus
}
#endif

#endif /* DIGITAL_OUTPUTS_DRIVER_H */
