Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splitting app source code in multiple files #639

Closed
lelongg opened this issue May 11, 2022 · 5 comments
Closed

splitting app source code in multiple files #639

lelongg opened this issue May 11, 2022 · 5 comments

Comments

@lelongg
Copy link

lelongg commented May 11, 2022

Is there a way to split the app module source code into different files ? Each of my attempts feels like hitting some wall. The main issue seems to be that having a non-inline module inside a macro is currently unstable. Is everybody else keeping the whole app in a single file ?

@perlindgren
Copy link
Collaborator

perlindgren commented May 11, 2022

You can implement tasks external to the app macro. (I think for now init/idle needs to be internal in the app, eventually we will support all task types, there is a PR on the way, but some implementation work remains...)

For a small example see:
https://github.com/rtic-rs/cortex-m-rtic/blob/master/examples/extern_binds.rs

/Per

@lelongg
Copy link
Author

lelongg commented May 11, 2022

Ok thanks for the tip

@lelongg lelongg closed this as completed May 11, 2022
@eflukx
Copy link

eflukx commented Jul 18, 2022

Hmm.. been fighting with this for some time.. but I really don't seem to be able to access the RTIC main app module, which is defined in main.rs (or in my case an example.rs) main binary, from outside of the app module.

The extern_spawn.rs does show an external spawn for a task function, but the code is still within the same file. It is probably something trivial, but how make the 'main' app module pub to allow it to be used somewhere else?

@sakian
Copy link

sakian commented Jul 18, 2022

In my secondary file I have use crate::app;. I can then spawn tasks within my extern function using app::<task_name>::spawn().unwrap();.

@eflukx
Copy link

eflukx commented Jul 19, 2022

Hi @sakian thanks for your response on this (long dead) topic!

I got things working (more or less) the way I desire. In my app I have main.rs and a lib.rs, where the latter is referencing most of the app's modules. Apparently rust/cargo compiles main.rs and lib.rs a separate crates. Up until now stuff like modules and use-ing code (from internal and external sources), just worked™️, but RTIC with external binding does not seem to fit this nicely. (as the app 'root' needs to be in the 'executable' crate and can not be in the 'lib part').

When I chuck all the pub mod xxx from lib.rs into the main.rs things start working as expected. It's just not possible (or at least I don't know how) to use (reference) the main crate from the lib crate. Currently I placed all the mods that have to do with the RITC app in the main.rs file and that's fine for now.

Another thing I noticed is that having a qualified/mod name in the extern block's function name, seems to break things. This does not work: ( One has to use mymod::foo and use the short name)

    extern "Rust" {
        #[task()]
        fn mymod::foo(_c: foo::Context, _x: i32, _y: u32);
    }

All in all I got working what was needed, so that's good. Some more elaborate (multi file) examples resembling a "real" application would be a welcome addition for RTIC imho..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants