error handling and cleanup
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
/**
|
||||
* @file outputs.c
|
||||
* @brief Implementation of output control module.
|
||||
*/
|
||||
|
||||
#include "outputs.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
@ -6,69 +11,76 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-outputs";
|
||||
const uint8_t uCirculationPumpGpioPin = CONFIG_GPIO_CIRCULATION_PUMP;
|
||||
const uint8_t uBurnerGpioPin = CONFIG_GPIO_BURNER;
|
||||
const uint8_t uSafetyContactGpioPin = CONFIG_GPIO_SAFETY_CONTACT;
|
||||
static const char *TAG = "outputs";
|
||||
|
||||
/** @brief Circulation pump GPIO pin (from Kconfig). */
|
||||
static const uint8_t uCirculationPumpGpioPin = CONFIG_GPIO_CIRCULATION_PUMP;
|
||||
|
||||
/** @brief Burner control GPIO pin (from Kconfig). */
|
||||
static const uint8_t uBurnerGpioPin = CONFIG_GPIO_BURNER;
|
||||
|
||||
/** @brief Safety contact GPIO pin (from Kconfig). */
|
||||
static const uint8_t uSafetyContactGpioPin = CONFIG_GPIO_SAFETY_CONTACT;
|
||||
|
||||
static SemaphoreHandle_t xMutexAccessOutputs = NULL;
|
||||
static eOutput sCirculationPumpState;
|
||||
static eOutput sBurnerState;
|
||||
static eOutput sSafetyContactState;
|
||||
|
||||
void initOutputs(void)
|
||||
esp_err_t initOutputs(void)
|
||||
{
|
||||
gpio_config_t ioConfCirculationPump = {
|
||||
.pin_bit_mask = (1ULL << uCirculationPumpGpioPin), // Pin mask
|
||||
.mode = GPIO_MODE_OUTPUT, // Set as output
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE, // Disable pull-up
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down
|
||||
.intr_type = GPIO_INTR_DISABLE // Disable interrupts
|
||||
};
|
||||
.pin_bit_mask = (1ULL << uCirculationPumpGpioPin),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE};
|
||||
|
||||
gpio_config_t ioConfBurner = {
|
||||
.pin_bit_mask = (1ULL << uBurnerGpioPin), // Pin mask
|
||||
.mode = GPIO_MODE_OUTPUT, // Set as output
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE, // Disable pull-up
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down
|
||||
.intr_type = GPIO_INTR_DISABLE // Disable interrupts
|
||||
};
|
||||
.pin_bit_mask = (1ULL << uBurnerGpioPin),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE};
|
||||
|
||||
gpio_config_t ioConfSafetyContact = {
|
||||
.pin_bit_mask = (1ULL << uSafetyContactGpioPin), // Pin mask
|
||||
.mode = GPIO_MODE_OUTPUT, // Set as output
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE, // Disable pull-up
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down
|
||||
.intr_type = GPIO_INTR_DISABLE // Disable interrupts
|
||||
};
|
||||
.pin_bit_mask = (1ULL << uSafetyContactGpioPin),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE};
|
||||
|
||||
esp_err_t ret = gpio_config(&ioConfCirculationPump);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "GPIO config failed: %s", esp_err_to_name(ret));
|
||||
return;
|
||||
ESP_LOGE(TAG, "GPIO config failed for circulation pump: %s", esp_err_to_name(ret));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ret = gpio_config(&ioConfBurner);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "GPIO config failed: %s", esp_err_to_name(ret));
|
||||
return;
|
||||
ESP_LOGE(TAG, "GPIO config failed for burner: %s", esp_err_to_name(ret));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ret = gpio_config(&ioConfSafetyContact);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "GPIO config failed: %s", esp_err_to_name(ret));
|
||||
return;
|
||||
ESP_LOGE(TAG, "GPIO config failed for safety contact: %s", esp_err_to_name(ret));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
xMutexAccessOutputs = xSemaphoreCreateRecursiveMutex();
|
||||
if (xMutexAccessOutputs == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to create mutex");
|
||||
ESP_LOGE(TAG, "Failed to create mutex");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
xSemaphoreGiveRecursive(xMutexAccessOutputs);
|
||||
|
||||
ESP_LOGI(TAG, "Initialized successfully");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
eOutput getCirculationPumpState(void)
|
||||
|
||||
Reference in New Issue
Block a user