Started with a blank main file

- Added GPIO handling
- Added a logger class with additional static debug log handling

Tested, functional
This commit is contained in:
Matthias Mitscherlich
2024-03-11 15:45:48 +01:00
parent 4b31b6c618
commit a0d13f08c1
10 changed files with 1067 additions and 4 deletions
+127
View File
@@ -0,0 +1,127 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file gpio.c
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <gpio.h>
#include "driver/gpio.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
gpio::gpio(uint32_t number, Direction_t direction, Value_t initialValue)
{
this->number = number;
this->direction = direction;
//zero-initialize the config structure.
gpio_config_t io_conf = {};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = (this->direction == GPIO_DIRECTION_OUTPUT) ? GPIO_MODE_OUTPUT : GPIO_MODE_INPUT;
//bit mask of the pins that you want to set
io_conf.pin_bit_mask = (1ULL << this->number);
//disable pull-down mode
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
//disable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
//configure GPIO with the given settings
ESP_ERROR_CHECK(gpio_config(&io_conf));
this->currentState = GPIO_VALUE_LOW;
set(initialValue);
}
FunctionStatus gpio::set(Value_t value)
{
FunctionStatus returnValue = FUNCTION_STATUS_ERROR;
if (this->direction == GPIO_DIRECTION_OUTPUT)
{
ESP_ERROR_CHECK(gpio_set_level((gpio_num_t)this->number, (uint32_t)value));
this->currentState = value;
returnValue = FUNCTION_STATUS_OK;
}
return returnValue;
}
FunctionStatus gpio::get(Value_t* value)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
if (gpio_get_level((gpio_num_t)this->number))
{
this->currentState = GPIO_VALUE_HIGH;
}
else
{
this->currentState = GPIO_VALUE_LOW;
}
*value = this->currentState;
return returnValue;
}
FunctionStatus gpio::toogle()
{
FunctionStatus returnValue = FUNCTION_STATUS_ERROR;
if (this->currentState == GPIO_VALUE_LOW)
{
// Going to HIGH
set(GPIO_VALUE_HIGH);
}
else
{
// Going to LOW
set(GPIO_VALUE_LOW);
}
return returnValue;
}