Adding NVS to project

This commit is contained in:
2025-01-01 21:15:01 +01:00
parent dd9f59e418
commit 968d078c07
19 changed files with 812 additions and 28 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
idf_component_register(
SRC_DIRS "src"
INCLUDE_DIRS "include"
INCLUDE_DIRS "include" "defines"
)
@@ -0,0 +1,43 @@
/**
* @file utils.hpp
* @author Gustice
* @brief Template
*
* @copyright Copyright (c) 2024
*/
#pragma once
#include <cassert>
#include <exception>
#include <cstdint>
/**
* @brief Base for constructs that allow only one concurrently active instance
*
* @tparam T
* @note needs a `T * T::SingleActive<T>::active{};` definition in source
*/
template <typename T>
class SingleActive {
static bool active;
public:
/// @brief Constructor, memorizes if already on instance was successfully build
SingleActive() {
if (active) {
throw "Instance already active";
}
assert(active == false && "Constructor my only be run if no instance active");
active = true;
}
/// @brief Destructor, clears memory of existing instance
~SingleActive() {
assert(active == true && "Destructor my only be run on active instance");
active = false;
}
// Disable move and assignment
SingleActive(SingleActive &other) = delete;
void operator=(const SingleActive &) = delete;
};
@@ -0,0 +1,25 @@
/**
* @file coreExcept.hpp
* @author Gustice
* @brief Template
*
* @copyright Copyright (c) 2024
*/
#pragma once
#include <exception>
/**
* @brief Simple exception
*/
class CoreException : public std::exception {
char const *Text;
public:
/// @brief Constructor with simple pointer to text
CoreException(char const *text) : Text(text) {
}
/// @brief error message getter
char const *what() const throw() override { return Text; }
};
@@ -1,36 +0,0 @@
/**
* @file countDown.hpp
* @author Gustice
* @brief Classes for typical index manipulation
*
* @copyright Copyright (c) 2020
*/
#pragma once
class CountDown {
public:
CountDown(unsigned max) : Max(max) {}
void Tick() {
_cnt++;
if (_cnt >= Max) {
_cnt = 0;
_pFlag = true;
}
}
bool GetVolatileFlag() {
if (!_pFlag)
return false;
// Reset _pFlag in any case, so it only be consumed once
// hence volatile
_pFlag = false;
return true;
}
private:
const unsigned Max;
unsigned _cnt;
bool _pFlag;
};
@@ -1,58 +0,0 @@
/**
* @file rotatingIndex.hpp
* @author Gustice
* @brief Classes for typical index manipulation
*
* @copyright Copyright (c) 2020
*/
#pragma once
#include <cstdint>
/**
* @brief Index with automatic revolution back to start position
* @details Useful for Buffer-Pointer, or similar tasks
*/
class RotatingIndex {
public:
/// @brief Value at witch the index rotates back to beginning
const uint16_t MaxIndex;
/// @brief Constructor for rotating index
/// @brief output index will be set to 0 if incremented value reaches Maximum
/// @param max Maximum index for overflow-condition
RotatingIndex(uint16_t max) : MaxIndex(max) { _index = 0; }
/// @brief Get the current index and inkrement index afterwards
/// @return uint16_t current index
uint16_t getIndexAndIncrement(void) {
auto retVal = _index;
_index++;
if (_index >= MaxIndex) {
_index = 0;
}
return retVal;
};
/// @brief Get the current index without incrementing the index
/// @return uint16_t current index
uint16_t getIndex(void) { return _index; }
/// @brief Check if next get will lead to overflow condition
bool peekRevolution(void) {
if (MaxIndex == 0)
return true;
if (_index >= MaxIndex - 1) {
return true;
}
return false;
}
/// @brief Reset Index to 0
void resetIndex(void) { _index = 0; }
private:
/// Current Index
uint16_t _index;
};
@@ -13,21 +13,6 @@
#include <vector>
#include <cstdint>
/**
* @brief Simple exception
*/
class CoreException : public std::exception {
char const *Text;
public:
/// @brief Constructor with simple pointer to text
CoreException(char const *text) : Text(text) {
}
/// @brief error message getter
char const *what() const throw() override { return Text; }
};
/**
* @brief Common interface for character streams
*/
+9
View File
@@ -0,0 +1,9 @@
/**
* @file dummy.cpp
* @author Gustice
* @brief Silence toolchain
*
* @copyright Copyright (c) 2024
*/
#include "portBase.hpp"
-9
View File
@@ -1,9 +0,0 @@
/**
* @file utils.cpp
* @author Gustice
* @brief Implementation of utilities
*
* @copyright Copyright (c) 2024
*/
#include "utils.hpp"