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:
@@ -0,0 +1,103 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file ISerialBus.h
|
||||
/// \brief File description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef MAIN_HAL_INC_ISERIALBUS_H_
|
||||
#define MAIN_HAL_INC_ISERIALBUS_H_
|
||||
|
||||
/**
|
||||
* ISerialBus implementation
|
||||
* \defgroup ISerialBus
|
||||
* \brief {group_description}
|
||||
* \addtogroup {Layer}
|
||||
*
|
||||
* Detailed description
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// CompilerIncludes
|
||||
// All include files that are provided by the compiler directly
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// ProjectIncludes
|
||||
// All include files that are provided by the project
|
||||
#include "FunctionStatus.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
class ISerialBus
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
public:
|
||||
// Virtual Class Destructor (required for absolute virtual classes)
|
||||
virtual ~ISerialBus() {}
|
||||
|
||||
FunctionStatus open() {status = OPEN; return FUNCTION_STATUS_OK;}
|
||||
|
||||
FunctionStatus close() {status = CLOSED; return FUNCTION_STATUS_OK;}
|
||||
|
||||
virtual FunctionStatus read(T* buffer, uint32_t length, uint32_t* actualLength) = 0;
|
||||
|
||||
virtual FunctionStatus write(T* buffer, uint32_t length) = 0;
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Protected Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
protected:
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CLOSED = 0,
|
||||
OPEN
|
||||
} Status_t;
|
||||
|
||||
// The current open/close status of the interface
|
||||
Status_t status;
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#endif /* MAIN_HAL_INC_ISERIALBUS_H_ */
|
||||
@@ -0,0 +1,122 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file gpio.h
|
||||
/// \brief File description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef MAIN_HAL_INC_GPIO_H_
|
||||
#define MAIN_HAL_INC_GPIO_H_
|
||||
|
||||
/**
|
||||
* gpio implementation
|
||||
* \defgroup gpio
|
||||
* \brief {group_description}
|
||||
* \addtogroup {Layer}
|
||||
*
|
||||
* Detailed description
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// CompilerIncludes
|
||||
// All include files that are provided by the compiler directly
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// ProjectIncludes
|
||||
// All include files that are provided by the project
|
||||
#include "FunctionStatus.h" //!< Include to use the generic function status enumeration type
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class gpio
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
public:
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GPIO_DIRECTION_INPUT = 0,
|
||||
GPIO_DIRECTION_OUTPUT = 1
|
||||
} Direction_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GPIO_VALUE_LOW = 0,
|
||||
GPIO_VALUE_HIGH = 1
|
||||
} Value_t;
|
||||
|
||||
/** -------------------------------------------------------------------------------------------------------------
|
||||
* GPIO
|
||||
* \brief Constructs a new instance of GPIO
|
||||
*
|
||||
*
|
||||
* @param number The IO instance given in as its unique GPIO number
|
||||
* @param direction Direction of the GPIO.
|
||||
* Default value: @arg GPIO_DIRECTION_INPUT
|
||||
* @arg GPIO_DIRECTION_INPUT for incoming signal
|
||||
* @arg GPIO_DIRECTION_OUTPUT for outgoing signal
|
||||
* @param initialValue The initial value for this GPIO. For outputs the given value will be
|
||||
* applied immediately after initialization. For inputs this value is only
|
||||
* initial and is not the real representation of the input.
|
||||
* Default value: @arg GPIO_VALUE_LOW
|
||||
* @arg GPIO_VALUE_LOW the signal at the GPIO is equal to GND
|
||||
* @arg GPIO_VALUE_HIGH the signal at the GPIO is equal to VCC
|
||||
* --------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
gpio(uint32_t number, Direction_t direction = GPIO_DIRECTION_INPUT, Value_t initialValue = GPIO_VALUE_LOW);
|
||||
|
||||
FunctionStatus set(Value_t value);
|
||||
FunctionStatus get(Value_t* const value);
|
||||
FunctionStatus toogle();
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Protected Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
protected:
|
||||
uint32_t number;
|
||||
Direction_t direction;
|
||||
Value_t currentState;
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#endif /* MAIN_HAL_INC_GPIO_H_ */
|
||||
@@ -0,0 +1,91 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file uart.h
|
||||
/// \brief File description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef MAIN_HAL_INC_UART_H_
|
||||
#define MAIN_HAL_INC_UART_H_
|
||||
|
||||
/**
|
||||
* uart implementation
|
||||
* \defgroup uart
|
||||
* \brief {group_description}
|
||||
* \addtogroup {Layer}
|
||||
*
|
||||
* Detailed description
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// CompilerIncludes
|
||||
// All include files that are provided by the compiler directly
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// ProjectIncludes
|
||||
// All include files that are provided by the project
|
||||
#include "ISerialBus.h"
|
||||
#include "driver/uart.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class uart : public ISerialBus<uint8_t>
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
public:
|
||||
// Class Constructor
|
||||
uart(uart_port_t* uartPort);
|
||||
~uart();
|
||||
|
||||
FunctionStatus read(uint8_t* buffer, uint32_t length, uint32_t* actualLength);
|
||||
|
||||
FunctionStatus write(uint8_t* buffer, uint32_t length);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Protected Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
protected:
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
private:
|
||||
uart_port_t* port;
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#endif /* MAIN_HAL_INC_UART_H_ */
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file uart.cpp
|
||||
/// \brief Description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
uart::uart(uart_port_t* uartPort)
|
||||
{
|
||||
this->port = uartPort;
|
||||
this->status = CLOSED;
|
||||
}
|
||||
|
||||
uart::~uart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FunctionStatus uart::write(uint8_t* buffer, uint32_t length)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
|
||||
if (status == OPEN)
|
||||
{
|
||||
uart_write_bytes(*this->port, (const void*)buffer, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_OPEN;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
FunctionStatus uart::read(uint8_t* buffer, uint32_t length, uint32_t* actualLength)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
|
||||
if (status == OPEN)
|
||||
{
|
||||
// Do Stuff
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_OPEN;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
Reference in New Issue
Block a user