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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
[submodule "ext/segger/rtt"]
path = ext/segger/rtt
url = https://github.com/modm-ext/segger-rtt.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/Dense>

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
50 changes: 50 additions & 0 deletions ext/libeigen/Version.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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(<eigen_conf_local.h>)
# include <eigen_conf_local.h>
#endif

%% if eigen_no_io
#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 eigen_no_malloc
#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 4d259c
38 changes: 38 additions & 0 deletions ext/libeigen/eigen.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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 = """
# Eigen Linear Algebra Library


"""


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 = {
"eigen_no_malloc": not env.has_module(":platform:heap"),
"eigen_no_io": not (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")
32 changes: 32 additions & 0 deletions ext/libeigen/iostream_eigen.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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
#include <Eigen/Dense>

namespace modm
{

template<typename Derived>
modm::IOStream& operator<<(modm::IOStream& s, const Eigen::MatrixBase<Derived>& m)
{
for (Eigen::Index r = 0; r < m.rows(); ++r) {
for (Eigen::Index c = 0; c < m.cols(); ++c) {
s << m(r, c);
if (c + 1 < m.cols()) s << ", ";
}
if (r + 1 < m.rows()) s << "\n";
}
return s;
}

} // namespace modm
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
19 changes: 18 additions & 1 deletion src/modm/io/iostream.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ public:
%% endif


inline size_t width() const { return 0; }
inline void width(size_t) {}
inline size_t precision() const { return fmt_precision; }
inline size_t precision(size_t p) {
size_t old = fmt_precision;
fmt_precision = p;
return old;
}
inline char fill() const { return ' '; }
inline char fill(char) {
return ' ';
}


protected:
template< typename T >
void
Expand All @@ -273,7 +287,7 @@ protected:
void writeInteger(uint64_t value);
%% endif

%% if options.with_float
%% if options.with_float and options.with_printf
inline void writeFloat(float value)
{ writeDouble(static_cast<double>(value)); }
void writeDouble(const double& value);
Expand Down Expand Up @@ -303,6 +317,9 @@ private:
{ if (c) reinterpret_cast<modm::IOStream*>(arg)->write(c); }
printf_output_gadget_t output_gadget{out_char, this, NULL, 0, INT_MAX};
%% endif
%% if options.with_float and options.with_printf
size_t fmt_precision = 0;
%% endif
};

/// @ingroup modm_io
Expand Down
2 changes: 1 addition & 1 deletion src/modm/io/iostream_printf.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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, fmt_precision, 0, 0, true);
%% else
if(!std::isfinite(value)) {
if(std::isinf(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/modm/io/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def build(env):
"is_avr": target.platform == "avr",
"with_fiber": env.has_module(":processing:fiber"),
"family": target.family,
"core": core,
"core": core
}
env.outbasepath = "modm/src/modm/io"
env.copy("iodevice.hpp")
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
1 change: 1 addition & 0 deletions src/modm/platform/timer/samg/timer_channel_base.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include "../device.hpp"
#include <modm/architecture/interface/register.hpp>

namespace modm::platform
{
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/uart/sam-sercom/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def prepare(module, options):
module.depends(
":architecture:uart",
":architecture:fiber",
":architecture:register",
":math:algorithm",
":cmsis:device",
":platform:gpio",
Expand Down
Loading