Skip to content
Open
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
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
url = https://github.com/modm-ext/segger-rtt.git
[submodule "ext/vl53/vl53"]
path = ext/vl53/vl53
url = https://github.com/modm-ext/vl53-partial.git
url = https://github.com/modm-ext/vl53-partial.git
[submodule "ext/libeigen/eigen"]
path = ext/libeigen/eigen
url = https://github.com/modm-ext/eigen-partial.git
41 changes: 41 additions & 0 deletions examples/nucleo_g474re/eigen/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2025, Henrik Hose
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <Eigen/Eigen>

using namespace Board;

Eigen::IOFormat squarebrackets(5, 0, ", ", "\n", "[", "]");

int
main()
{
Board::initialize();
LedD13::setOutput();

while (1)
{
Eigen::Matrix2f mat{{1, 2}, {3, 4}};
Eigen::Vector2f u{-1, 1}, v{2, 0};
MODM_LOG_INFO << "Here is mat*mat:\n" << mat * mat << modm::endl;
MODM_LOG_INFO << "Here is mat*u:\n" << mat * u << modm::endl;
MODM_LOG_INFO << "Here is u^T*mat:\n" << u.transpose() * mat << modm::endl;
MODM_LOG_INFO << "Here is u^T*v:\n" << u.transpose() * v << modm::endl;
MODM_LOG_INFO << "Here is u*v^T:\n" << u * v.transpose() << modm::endl;
MODM_LOG_INFO << "Let's multiply mat by itself" << modm::endl;
mat = mat * mat;
MODM_LOG_INFO << "Now mat is mat:\n" << mat.format(squarebrackets)<< modm::endl;

modm::delay(1s);
}

return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_g474re/eigen/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-g474re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g474re/eigen</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:heap</module>
<module>modm:eigen</module>
</modules>
</library>
1 change: 0 additions & 1 deletion ext/gcc/assert.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <cstdint>
#include <bits/functexcept.h>
#include <modm/math/utils/bit_constants.hpp>

%% if options["assert_on_exception"]
#include <modm/architecture/interface/assert.hpp>
Expand Down
53 changes: 53 additions & 0 deletions ext/libeigen/Version.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2025, Henrik Hose
* Copyright (c) 2025, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#pragma once

#if __has_include(<modm_conf_eigen.h>)
# include <modm_conf_eigen.h>
#endif
%% if with_io
#include <modm/io.hpp>
%#
%% else
%#
#define EIGEN_NO_IO
%% endif
#define EIGEN_DONT_VECTORIZE
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
#define EIGEN_DONT_PARALLELIZE

#define EIGEN_MALLOC_ALREADY_ALIGNED 1
#ifndef EIGEN_MAX_ALIGN_BYTES
#define EIGEN_MAX_ALIGN_BYTES 0
#endif
#ifndef EIGEN_MAX_STATIC_ALIGN_BYTES
#define EIGEN_MAX_STATIC_ALIGN_BYTES 4
#endif
%#
%% if not with_heap
#define EIGEN_NO_MALLOC
%% endif
#ifndef EIGEN_STACK_ALLOCATION_LIMIT
#define EIGEN_STACK_ALLOCATION_LIMIT 1024
#endif

#ifndef MODM_DEBUG_BUILD
#define EIGEN_NO_DEBUG
#endif

#include <modm/architecture/interface/assert.hpp>

#define eigen_assert(cond) \
modm_assert(cond, "eigen", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #cond "\"")

#include "Version_orig"
1 change: 1 addition & 0 deletions ext/libeigen/eigen
Submodule eigen added at 889745
34 changes: 34 additions & 0 deletions ext/libeigen/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2025, Henrik Hose
# Copyright (c) 2025, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
module.name = ":eigen"
module.description = FileReader("module.md")


def prepare(module, options):
module.depends(":architecture:assert")
return True


def build(env):
env.outbasepath = "modm/ext/eigen"
env.collect(":build:path.include", "modm/ext/eigen")

env.substitutions = {
"with_heap": env.has_module(":platform:heap"),
"with_io": env.has_module(":io") and env.has_module(":platform:heap"),
}
env.copy("eigen/Eigen", "Eigen", ignore=env.ignore_files("Version"))
env.copy("eigen/Eigen/Version", "Eigen/Version_orig")
env.template("Version.in", "Eigen/Version")
2 changes: 2 additions & 0 deletions ext/libeigen/module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Eigen Linear Algebra Library

13 changes: 6 additions & 7 deletions src/modm/architecture/interface/assert.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#pragma once

#include "assert.h"
#include <modm/architecture/interface/register.hpp>
%% if core.startswith("avr")
#include <modm/architecture/interface/accessor_flash.hpp>
%% endif
Expand All @@ -27,13 +26,13 @@ namespace modm
enum class
Abandonment : uint8_t
{
DontCare = Bit0, ///< Do not care about failure.
Ignore = Bit1, ///< Ignore this failure.
Fail = Bit2, ///< This failure is reason for abandonment.
Debug = Bit7 ///< Only set for a debug-only failure.
DontCare = 0b001, ///< Do not care about failure.
Ignore = 0b010, ///< Ignore this failure.
Fail = 0b100, ///< This failure is reason for abandonment.
Debug = 0x80, ///< Only set for a debug-only failure.
};
using AbandonmentBehavior = Flags8<Abandonment>;
MODM_TYPE_FLAGS(AbandonmentBehavior);
/// Contains the superset of Abandonment behavior
using AbandonmentBehavior = Abandonment;

/// Contains information about the failed assertion.
struct modm_packed
Expand Down
1 change: 0 additions & 1 deletion src/modm/architecture/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Assert(Module):
default="release" if platform == "hosted" else "debug",
enumeration=["off", "debug", "release"]))

module.depends(":architecture:register")
if platform == "avr":
module.depends(":architecture:accessor")
return True
Expand Down
1 change: 1 addition & 0 deletions src/modm/driver/color/tcs3472.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <stdint.h>
#include <modm/architecture/interface/i2c_device.hpp>
#include <modm/architecture/interface/register.hpp>
#include <modm/math/utils.hpp>
#include <modm/ui/color.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/modm/driver/color/tcs3472.lb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def init(module):
def prepare(module, options):
module.depends(
":architecture:i2c.device",
":architecture:register",
":ui:color",
":math:utils")
return True
Expand Down
1 change: 1 addition & 0 deletions src/modm/driver/display/st7586s.lb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def init(module):
def prepare(module, options):
module.depends(
":architecture:fiber",
":architecture:register",
":ui:display")
return True

Expand Down
1 change: 1 addition & 0 deletions src/modm/driver/display/st7586s_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once

#include <modm/architecture/interface/register.hpp>
#include <modm/math/utils/endianness.hpp>

/// @cond
Expand Down
21 changes: 21 additions & 0 deletions src/modm/io/iostream.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ public:
vprintf(const char *fmt, va_list vlist) __attribute__((format(printf, 2, 0)));
%% endif

%% if options.with_printf
inline size_t width() const { return printf_width; }
inline void width(size_t w) {
const size_t old = printf_width;
printf_width = w;
return old;
}
inline size_t precision() const { return printf_precision; }
inline size_t precision(size_t p) {
const size_t old = printf_precision;
printf_precision = p;
return old;
}
%% endif
inline char fill() const { return ' '; }
inline char fill(char) {
return ' ';
}


protected:
template< typename T >
Expand Down Expand Up @@ -302,6 +321,8 @@ private:
static void out_char(char c, void* arg)
{ if (c) reinterpret_cast<modm::IOStream*>(arg)->write(c); }
printf_output_gadget_t output_gadget{out_char, this, NULL, 0, INT_MAX};
size_t printf_precision{};
size_t printf_width{};
%% endif
};

Expand Down
15 changes: 8 additions & 7 deletions src/modm/io/iostream_printf.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ IOStream::writeInteger(int16_t value)
{
%% if options.with_printf
print_integer(&output_gadget, uint16_t(value < 0 ? -value : value),
value < 0, 10, 0, 0, FLAGS_SHORT);
value < 0, 10, printf_precision, printf_width, FLAGS_SHORT);
%% else
// hard coded for -32'768
char str[7 + 1]; // +1 for '\0'
Expand All @@ -91,7 +91,8 @@ void
IOStream::writeInteger(uint16_t value)
{
%% if options.with_printf
print_integer(&output_gadget, value, false, 10, 0, 0, FLAGS_SHORT);
print_integer(&output_gadget, value, false, 10,
printf_precision, printf_width, FLAGS_SHORT);
%% else
// hard coded for 32'768
char str[6 + 1]; // +1 for '\0'
Expand All @@ -105,7 +106,7 @@ IOStream::writeInteger(int32_t value)
{
%% if options.with_printf
print_integer(&output_gadget, uint32_t(value < 0 ? -value : value),
value < 0, 10, 0, 0, FLAGS_LONG);
value < 0, 10, printf_precision, printf_width, FLAGS_LONG);
%% else
// hard coded for -2147483648
char str[11 + 1]; // +1 for '\0'
Expand All @@ -118,7 +119,7 @@ void
IOStream::writeInteger(uint32_t value)
{
%% if options.with_printf
print_integer(&output_gadget, value, false, 10, 0, 0, FLAGS_LONG);
print_integer(&output_gadget, value, false, 10, printf_precision, printf_width, FLAGS_LONG);
%% else
// hard coded for 4294967295
char str[10 + 1]; // +1 for '\0'
Expand All @@ -132,13 +133,13 @@ void
IOStream::writeInteger(int64_t value)
{
print_integer(&output_gadget, uint64_t(value < 0 ? -value : value),
value < 0, 10, 0, 0, FLAGS_LONG_LONG);
value < 0, 10, printf_precision, printf_width, FLAGS_LONG_LONG);
}

void
IOStream::writeInteger(uint64_t value)
{
print_integer(&output_gadget, value, false, 10, 0, 0, FLAGS_LONG_LONG);
print_integer(&output_gadget, value, false, 10, printf_precision, printf_width, FLAGS_LONG_LONG);
}
%% endif

Expand All @@ -147,7 +148,7 @@ void
IOStream::writeDouble(const double& value)
{
%% if options.with_printf
print_floating_point(&output_gadget, value, 0, 0, 0, true);
print_floating_point(&output_gadget, value, printf_precision, printf_width, 0, true);
%% else
if(!std::isfinite(value)) {
if(std::isinf(value)) {
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/adc/at90_tiny_mega/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def prepare(module, options):

module.depends(
":architecture:adc",
":architecture:register",
":architecture:interrupt",
":platform:gpio",
":math:algorithm")
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/can/common/fdcan/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def prepare(module, options):

module.depends(
":architecture:assert",
":architecture:register",
":architecture:can",
":architecture:clock")
return True
Expand Down
14 changes: 7 additions & 7 deletions src/modm/platform/core/cortex/assert.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ void
modm_assert_report(_modm_assertion_info *cinfo)
{
auto info = reinterpret_cast<modm::AssertionInfo *>(cinfo);
AbandonmentBehavior behavior(info->behavior);
uint8_t behavior(uint8_t(info->behavior));

for (const AssertionHandler *handler = &__assertion_table_start;
handler < &__assertion_table_end; handler++)
{
%% if core.startswith("avr")
behavior |= ((AssertionHandler)pgm_read_ptr(handler))(*info);
behavior |= (uint8_t)((AssertionHandler)pgm_read_ptr(handler))(*info);
%% else
behavior |= (*handler)(*info);
behavior |= (uint8_t)(*handler)(*info);
%% endif
}

info->behavior = behavior;
behavior.reset(Abandonment::Debug);
if ((behavior == Abandonment::DontCare) or
(behavior & Abandonment::Fail))
info->behavior = AbandonmentBehavior(behavior);
behavior &= ~uint8_t(Abandonment::Debug);
if ((behavior == uint8_t(Abandonment::DontCare)) or
(behavior & uint8_t(Abandonment::Fail)))
{
modm_abandon(*info);
%% if core.startswith("cortex-m")
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/pwm/sam_x7x/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def prepare(module, options):
return False

module.depends(
":architecture:register",
":cmsis:device",
":platform:clock",
":platform:gpio")
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/timer/samg/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def prepare(module, options):
return False

module.depends(
":architecture:register",
":cmsis:device",
":platform:gpio")

Expand Down
Loading
Loading