Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 100
PointerAlignment: Left
AccessModifierOffset: -4
SortIncludes: Never
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
Cpp11BracedListStyle: true
BreakBeforeBraces: Attach
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignAfterOpenBracket: BlockIndent
37 changes: 37 additions & 0 deletions .github/workflows/format-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Format Checks

on:
workflow_dispatch:
pull_request:
paths:
- '**.cpp'
- '**.hpp'
- '**.c'
- '**.h'
- '.pre-commit-config.yaml'
- '.clang-format'
- '.github/workflows/format-checks.yml'

jobs:
format:
name: Check code format
runs-on: ubuntu-24.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install tools
run: |
python -m pip install --upgrade pip
python -m pip install pre-commit
sudo apt-get update
sudo apt-get install -y clang-format

Comment on lines +29 to +35
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI installs whatever clang-format version is provided by Ubuntu apt at the time, while local dev machines may have different versions (and the hook uses language: system). To avoid inconsistent formatting results, consider pinning clang-format via a pre-commit repo (mirrors-clang-format) or explicitly installing a specific clang-format-<version> package here and documenting the required version locally.

Copilot uses AI. Check for mistakes.
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
minimum_pre_commit_version: "3.5.0"
default_install_hook_types:
- pre-commit
- pre-push
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
files: ^(Inc/|Src/|Tests/|tools/).*
types_or:
- c
- c++
exclude: ^STM32CubeH7/.*
12 changes: 6 additions & 6 deletions Inc/C++Utilities/CppImports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include <bitset>
#include <ctype.h>
#if defined(SIM_ON)
# ifdef __APPLE__
# include <stdlib.h> // macOS
# else
# include <malloc.h> // Linux/Unix
# endif
#ifdef __APPLE__
#include <stdlib.h> // macOS
#else
# include <malloc.h>
#include <malloc.h> // Linux/Unix
#endif
#else
#include <malloc.h>
#endif
#include <math.h>
#include <deque>
Expand Down
33 changes: 16 additions & 17 deletions Inc/C++Utilities/CppUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
#include "RingBuffer.hpp"
#include "Stack.hpp"


namespace chrono = std::chrono;
namespace placeholders = std::placeholders;

using std::array;
using std::map;
using std::span;
using std::pair;
using std::function;
using std::string;
using std::to_string;
using std::reference_wrapper;
using std::set;
using std::stack;
using std::nullopt;
using std::hash;
using std::integral_constant;
using std::is_integral;
using std::is_same;
using std::make_unique;
using std::map;
using std::move;
using std::nullopt;
using std::pair;
using std::queue;
using std::reference_wrapper;
using std::remove_reference;
using std::integral_constant;
using std::set;
using std::shared_ptr;
using std::snprintf;
using std::make_unique;
using std::span;
using std::stack;
using std::string;
using std::stringstream;
using std::to_string;
using std::unique_ptr;
using std::shared_ptr;
using std::hash;
using std::unordered_map;
using std::vector;
using std::queue;
using std::stringstream;
using std::move;
26 changes: 12 additions & 14 deletions Inc/C++Utilities/RingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

#include "CppImports.hpp"

template <typename T, size_t N>
class RingBuffer {
template <typename T, size_t N> class RingBuffer {
std::array<T, N> buffer{};

size_t stored_items{0};

size_t front{0};
size_t back{0};

size_t move_forward(size_t origin, size_t amount) {
return (origin + amount) % N;
}
size_t move_forward(size_t origin, size_t amount) { return (origin + amount) % N; }

size_t move_backward(size_t origin, size_t amount) {
// N * ((amount / N) + 1) makes it so that the operation doesn't
Expand All @@ -22,11 +19,12 @@ class RingBuffer {
return ((origin + (N * ((amount / N) + 1))) - amount) % N;
}

public:
public:
RingBuffer() {}

bool push(T item) {
if (is_full()) return false;
if (is_full())
return false;

buffer[front] = item;
front = move_forward(front, 1);
Expand All @@ -36,7 +34,8 @@ class RingBuffer {
}

bool pop() {
if (is_empty()) return false;
if (is_empty())
return false;

back = move_forward(back, 1);
--stored_items;
Expand All @@ -45,7 +44,8 @@ class RingBuffer {
}

bool push_pop(T item) {
if (is_empty()) return false;
if (is_empty())
return false;

buffer[front] = item;
front = move_forward(front, 1);
Expand All @@ -54,13 +54,11 @@ class RingBuffer {
return true;
}

T &operator[](size_t index) {
return buffer[move_backward(front, index + 1)];
}
T& operator[](size_t index) { return buffer[move_backward(front, index + 1)]; }

T &last() { return buffer[back]; }
T& last() { return buffer[back]; }

T &first() { return buffer[move_backward(front, 1)]; }
T& first() { return buffer[move_backward(front, 1)]; }

constexpr size_t capacity() { return N; }
size_t size() { return stored_items; }
Expand Down
11 changes: 5 additions & 6 deletions Inc/C++Utilities/Stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
* @tparam T The type of elements stored in the stack.
* @tparam S The maximum number of elements.
*/
template<typename T, size_t S>
class Stack {
template <typename T, size_t S> class Stack {
public:
Stack() : top_idx(0) {}

bool push(const T& value) {
if (top_idx < S) {
data[top_idx++] = value;
return true;
}
return false;
}

bool pop() {
if (top_idx == 0) {
return false;
Expand All @@ -43,11 +42,11 @@ class Stack {
}
return data[top_idx - 1];
}

size_t size() const { return top_idx; }
size_t capacity() const { return S; }
bool empty() const { return top_idx == 0; }

private:
T data[S];
size_t top_idx;
Expand Down
40 changes: 17 additions & 23 deletions Inc/C++Utilities/StaticVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@
#include <array>
#include "ErrorHandler/ErrorHandler.hpp"

template <typename T, size_t Capacity>
class StaticVector {
private:
template <typename T, size_t Capacity> class StaticVector {
private:
std::array<T, Capacity> data{};
size_t size_ = 0;

public:
constexpr StaticVector() = default;

template<typename... Args>
constexpr StaticVector(Args&&... args) : data{std::forward<Args>(args)...}, size_(sizeof...(args)) {}

template <typename... Args>
constexpr StaticVector(Args&&... args)
: data{std::forward<Args>(args)...}, size_(sizeof...(args)) {}

constexpr bool operator==(const StaticVector&) const = default;

constexpr void push_back(const T& value)
{
if (size_ >= Capacity)
{
constexpr void push_back(const T& value) {
if (size_ >= Capacity) {
ErrorHandler("StaticVector capacity exceeded");
return;
}
}
data[size_] = value;
size_++;
}

constexpr auto begin() { return data.begin(); }
constexpr auto begin() const { return data.begin(); }
constexpr auto end() { return data.begin() + size_; }
constexpr auto end() const { return data.begin() + size_; }
constexpr auto end() { return data.begin() + size_; }
constexpr auto end() const { return data.begin() + size_; }

constexpr const std::array<T, Capacity>& get_array() const { return data; }
constexpr size_t size() const { return size_; }
constexpr T* get_data() { return data.data(); }
constexpr const T* get_data() const { return data.data(); }
constexpr T& operator[](size_t i) { return data[i]; }
constexpr const T& operator[](size_t i) const { return data[i]; }
constexpr bool contains(const T& value) const
{
for (size_t i = 0; i < size_; ++i)
{
if (data[i] == value)
{
constexpr T& operator[](size_t i) { return data[i]; }
constexpr const T& operator[](size_t i) const { return data[i]; }
constexpr bool contains(const T& value) const {
for (size_t i = 0; i < size_; ++i) {
if (data[i] == value) {
return true;
}
}
return false;
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#define DEMCR_TRCENA 0x01000000
#define DWT_CTRL_CYCCNTENA 0x00000001
/*
This class is designed to study the efficiency of an algorithm
by counting the number of clock cycles required for execution.
It provides a more predictable and reliable method for measuring
This class is designed to study the efficiency of an algorithm
by counting the number of clock cycles required for execution.
It provides a more predictable and reliable method for measuring
performance compared to using time-based measurements.
*/
/*
Expand All @@ -27,32 +27,32 @@
The difference will be the number of clock cycles done in the algorithm
*/
class DataWatchpointTrace {
public:
public:
static void start() {
unlock_dwt();
reset_cnt();
}
static unsigned int start_count() {
DWT->CTRL |= DWT_CTRL_CYCCNTENA; // enables the counter
DWT->CTRL |= DWT_CTRL_CYCCNTENA; // enables the counter
DWT->CYCCNT = 0;
return DWT->CYCCNT;
}
static unsigned int stop_count() {
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA; // disable the counter
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA; // disable the counter
return DWT->CYCCNT;
}
static unsigned int get_count() {
return DWT->CYCCNT; // returns the current value of the counter
return DWT->CYCCNT; // returns the current value of the counter
}

private:
private:
static void reset_cnt() {
CoreDebug->DEMCR |= DEMCR_TRCENA;
DWT->CYCCNT = 0; // reset the counter
DWT->CYCCNT = 0; // reset the counter
DWT->CTRL = 0;
}

static void unlock_dwt() { // unlock the dwt
static void unlock_dwt() { // unlock the dwt
uint32_t lsr = DWT->LSR;
if ((lsr & DWT_LSR_Present_Msk) != 0) {
if ((lsr & DWT_LSR_Access_Msk) != 0) {
Expand Down
5 changes: 2 additions & 3 deletions Inc/HALAL/HALAL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@
namespace HALAL {

#ifdef STLIB_ETH
void start(MAC mac, IPV4 ip, IPV4 subnet_mask, IPV4 gateway,
UART::Peripheral &printf_peripheral);
void start(MAC mac, IPV4 ip, IPV4 subnet_mask, IPV4 gateway, UART::Peripheral& printf_peripheral);
#else
void start(UART::Peripheral &printf_peripheral);
void start(UART::Peripheral& printf_peripheral);
#endif

} // namespace HALAL
Loading