Giter Club home page Giter Club logo

Comments (8)

Balint134 avatar Balint134 commented on May 28, 2024 1

Thanks for the response, yes something like that but in my case the number of combinations are close to 80 and I have at least 5-6 peripherals so the total number of permutations are very high. I was thinking more like

auto config = ConfigResolver::load()
auto spi = Spi::create(config.spi.interface, config.spi.mosi, config.spi.miso, config.spi.sck)

Apparently all the pin assignments are passed as template variables which is compile time only rather than runtime and I don't know if there's any way to get around this 🤔

from modm.

salkinium avatar salkinium commented on May 28, 2024

You mean something like this?

if (board_A) {
    SpiMaster5::connect<GpioA5::Mosi, GpioA6::Miso, GpioA7::Sck>();
    SpiMaster5::initialize<BoardA::SystemClock, 5_MHz>();
}
else if (board_B) {
    SpiMaster5::connect<GpioB5::Mosi, GpioB6::Miso, GpioB7::Sck>();
    SpiMaster5::initialize<BoardB::SystemClock, 1_MHz>();
}
else if (board_C) {
    SpiMaster3::connect<GpioC5::Mosi, GpioC6::Miso, GpioC7::Sck>();
    SpiMaster3::initialize<BoardC::SystemClock, 20_MHz>();
}

The connect methods compile into very compact code (just constants basically), including a few different configurations like this will probably still be less code than a fully dynamic computation.

from modm.

salkinium avatar salkinium commented on May 28, 2024

You can of course just call GpioA5::setAlternateFunction(id);, which is what the connect function compiles down to, but you loose all of the compile-time sanity checks. The AF mapping is pretty random too for STM32.

from modm.

salkinium avatar salkinium commented on May 28, 2024

There’s no runtime API for this I’m afraid. I believe mbed has such an API, but it’s completeness may be lacking.

However, you can take a look at the modm:platform:gpio module to see how we transform the data from modm-devices into compile time structures, and perhaps transform it into a runtime friendly format instead. Or just generate one massive switch case with all permutations ;-p

from modm.

salkinium avatar salkinium commented on May 28, 2024

You can even use modm-devices on it’s own and extend another HAL with that data. That was the whole point of separating modm (the C++ library) from modm-devices after all.

from modm.

Balint134 avatar Balint134 commented on May 28, 2024

Thanks for the tips, I'll take a look and see what can I do. Extending from modm-devices sounds interesting, wonder how complicated would that be 🤔

from modm.

salkinium avatar salkinium commented on May 28, 2024

Here’s an introductory blog post: https://blog.salkinium.com/modm-devices/#using-device-files
Haven’t gotten around to writing more though.

from modm.

salkinium avatar salkinium commented on May 28, 2024

I'm closing this since its out-of-scope for modm, but feel free to continue posting questions/issues here about using modm-devices.

from modm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.