Files
esp32-bmc/main/gpio_controller.h
Valentin Haudiquet ccf4569969
All checks were successful
Build ESP32 BMC Firmware / build (push) Successful in 59s
gpio: update config to use only one gpio for ATX PSU
2026-03-12 15:28:20 +01:00

141 lines
3.2 KiB
C

#ifndef GPIO_CONTROLLER_H
#define GPIO_CONTROLLER_H
#include "driver/gpio.h"
#include "esp_err.h"
#include "config.h"
// ============================================================================
// GPIO State Structure
// ============================================================================
typedef struct {
gpio_num_t pin;
const char *name;
gpio_mode_t mode;
int value;
bool inverted;
bool is_input_only;
} bmc_gpio_state_t;
// ============================================================================
// Function Declarations
// ============================================================================
/**
* @brief Initialize the GPIO controller
*
* Sets up all GPIOs according to the default configuration.
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_controller_init(void);
/**
* @brief Get the current state of all GPIOs
*
* @param states Array to store GPIO states (must be BMC_GPIO_COUNT size)
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_get_all_states(bmc_gpio_state_t *states);
/**
* @brief Get the state of a specific GPIO
*
* @param pin GPIO pin number
* @param state Pointer to store the GPIO state
* @return ESP_OK on success, ESP_ERR_NOT_FOUND if pin not in config
*/
esp_err_t gpio_get_state(gpio_num_t pin, bmc_gpio_state_t *state);
/**
* @brief Read the value of a GPIO
*
* @param pin GPIO pin number
* @return GPIO level (0 or 1), -1 on error
*/
int gpio_read(gpio_num_t pin);
/**
* @brief Write a value to a GPIO
*
* Handles inverted logic automatically.
*
* @param pin GPIO pin number
* @param value Value to write (0 or 1)
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_write(gpio_num_t pin, int value);
/**
* @brief Configure a GPIO mode
*
* @param pin GPIO pin number
* @param mode GPIO mode (INPUT, OUTPUT, etc.)
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_configure(gpio_num_t pin, gpio_mode_t mode);
/**
* @brief Toggle a GPIO output
*
* @param pin GPIO pin number
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_toggle(gpio_num_t pin);
/**
* @brief Find GPIO index by pin number
*
* @param pin GPIO pin number
* @return Index in the GPIO array, or -1 if not found
*/
int gpio_find_index(gpio_num_t pin);
/**
* @brief Get GPIO name by pin number
*
* @param pin GPIO pin number
* @return GPIO name string, or NULL if not found
*/
const char *gpio_get_name(gpio_num_t pin);
// ============================================================================
// Power Control Functions
// ============================================================================
/**
* @brief Turn board power on
*
* Pulses the POWER_ON GPIO.
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_power_on(void);
/**
* @brief Turn board power off
*
* Pulses the POWER_OFF GPIO.
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_power_off(void);
/**
* @brief Reset the board
*
* Pulses the RESET GPIO (active-low).
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gpio_reset(void);
/**
* @brief Check if power is on or off
*
* @return true if power signal is high, false otherwise
*/
bool gpio_power_status(void);
#endif // GPIO_CONTROLLER_H