ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
cr1901_ is now known as cr1901
IlPalazzo-ojiisa has quit [Quit: Leaving.]
Alistair[m]1 has quit [Quit: Idle timeout reached: 172800s]
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
M-[m] has joined #rust-embedded
<M-[m]> Please I m new here I started practicing this language newly coming from c background I wanna ask can rust be use to develop operating system kernel, device driver's and embedded system like c programming.
K900 has joined #rust-embedded
<K900> You've literally just asked that in the other room
<K900> And got an answer
<K900> Multiple answers, even
korken89[m] has quit [Quit: Idle timeout reached: 172800s]
IlPalazzo-ojiisa has joined #rust-embedded
Ralph[m] has joined #rust-embedded
<Ralph[m]> <thejpster[m]> "The nice thing about them..." <- it'd be great to have more public support for (embedded) rust from big company names - the universities i know (in Switzerland) still teach C/C++ (and sometimes with basic memory safety issues in their example code 🤦) and state "nobody is using rust and the industry just asks us for C/C++ embedded devs". at least i just read that there's now an ASIL-D & SIL4 certified toolchain
<Ralph[m]> (nice blog post, btw: https://ferrous-systems.com/blog/new-safety-critical-rust-consortium/), so that takes one of their reasons away which they so far used against it (though they'll stick to the "nobody is using it, it'd be useless if we teach it" reason 🙄).
ilpalazzo-ojiis4 has joined #rust-embedded
<ilpalazzo-ojiis4> Personally? Even as a Rust fanatic, I'm not sure I'd directly teach Rust either.
<ilpalazzo-ojiis4> It is possible, however to teach rust indirectly!
<ilpalazzo-ojiis4> 1) While teaching C/C++, make a mention of the safety guarantees that need to be upheld when using pointers;
<ilpalazzo-ojiis4> 2) At some point teach students functional programming;
<ilpalazzo-ojiis4> …and after those two, learning Rust ought to be piss-easy.
<thejpster[m]> University Polytehnica Bucharest teach embedded using Rust, to students who don’t know C
<diondokter[m]> The university of Delft also has some Rust in some of their courses
<thejpster[m]> Do they do embedded in Rust?
<thejpster[m]> Don’t forget that although Rust is complicated, there’s definitely a perfectly usable subset you can learn as a first language v
<thejpster[m]> * first language.
<diondokter[m]> thejpster[m]: IIRC yes with some robotics? But it's been a while since I heard it.
<diondokter[m]> Students can pick any language really, but lots of them use Rust since they've used it in other projects
<thejpster[m]> Hell, even I don’t know the deep type theory. I have no need to know it.
<Ralph[m]> i know that per.lindgren teaches embedded rust at Luleå university in sweden.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/ysTSciSDtMSZLLNSRljGdNRk>)
AtleoS has quit [Ping timeout: 252 seconds]
ijager[m] has quit [Quit: Idle timeout reached: 172800s]
FreeKill[m] has quit [Quit: Idle timeout reached: 172800s]
<FrreJacques[m]> I hope it's okay to ask here some noob questions. I was thinking that giving a timer into a driver might be a bad idea, because it probably binds it forever and can't be used outside. So I thought I try out whether it's true or not. And created a quite useless struct that has one field that implements the... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/dHpFWSKheJpsmiqsUrPPSmNN>)
<ryan-summers[m]> Only tangentially rust-related, but I'm going to stick some sensors right next to my plants in probably high humidity/moisture and want them to be protected during watering as well. Anyone know of any quick tips to environment proof a small PCBA? Could probably epoxy it, but I'll need to leave a humidity sensor exposed (it has an IP67 cover on the actual sensor portion though)
<FrreJacques[m]> Plastik70
<FrreJacques[m]> You can get it in a spray can and it creates a coating that would probably fine even on sea.
<ryan-summers[m]> Hmm conformal coating is indeed not a bad idea. I was under the impression it didn't fully waterproof though?
<FrreJacques[m]> I don't know. I guess it depends on how good the coating is.
<ryan-summers[m]> I actually think just dumping the thing in epoxy might be the simplest approach. It's only going to be a couple I2C sensors
<ryan-summers[m]> But re: your timer question, I imagine your issues are related to ownership semantics. Hard to say for sure without the full code or compiler output
<FrreJacques[m]> Yeah, it says when I run my_delay I do a mutable borrow. And if I run it a second time, I do a second mutable borrow, which isn't allowed. It looks like the function that borrows the self doesn't return it.
<ryan-summers[m]> I think you need to remove the `&'a mut self` and make it just `&mut self`
<ryan-summers[m]> Your lifetime is incorrect in the definition which is throwing off the borrow checker
<ryan-summers[m]> Because you're borrowing the actual timer in the struct for 'a, aka 'a is the whole lifetime that TinyTimer exists for. So if you borrow it out in my_delay for 'a, you're borrowing it out for the entire lifetime of the timer
<ryan-summers[m]> * Because you're borrowing the actual timer in the struct for `'a`, aka `'a` is the whole lifetime that `TinyTimer` exists for. So if you borrow it out in `my_delay` for `'a`, you're borrowing it out for the entire lifetime of the timer, and thus it's borrowed out for more than just the call of `my_delay`. If you omit the lifetime, rust will figure out the appropriate `&mut self` lifetime to use automatically
<FrreJacques[m]> hundred percent right :)
<FrreJacques[m]> now it compiles
<ryan-summers[m]> Yeah it's easy to footgun yourself with lifetimes like that. When possible, don't specify any lifetime unless you know why you're specifying it
<FrreJacques[m]> It didn't came to my mind writing it with lifetimes. But I struggled to figure out how to define a generic stuct field by defining a trait it needs to implement. I found that I either have to use &Trait with lifetimes or I would need to make a Box.
<ryan-summers[m]> Yeah generic timers are not idea
<ryan-summers[m]> s/Yeah/lYeah/
<ryan-summers[m]> Generally, instead of a borrow, I use a proxy structure similar to shared-bus
<ryan-summers[m]> For example, this is such a proxy structure for the embedded-nal TCP/UDP stack traits: https://github.com/quartiq/smoltcp-nal/blob/main/src/shared.rs
<FrreJacques[m]> Cool thing is. It is working now to delay via the t3 or via tiny, as I like. So I could hand over the timer as &mut and use it for other stuff too.
<ryan-summers[m]> I think it may break when you try handing things around though
<ryan-summers[m]> Borrows like that tend to be quite fragile, which is why I reference proxy structures to handle it instead. Proxy structures also have the benefit of not having generic lifetimes
<ryan-summers[m]> The general idea of a proxy structure is to move the actual timer into some 'static memory location and then make new, owned structs with cell references to it. Then you provide some synchronization API (i.e. critical sections, atomic bools, whatnot) to handle concurrent access
<ryan-summers[m]> So you'd have `&'static MyTimer` and then some `ProxyTimer` where `ProxyTimer: DelayUs`
<ryan-summers[m]> * some `ProxyTimer { _ref: Mutex<&MyTimer> }` where
<FrreJacques[m]> Okay. That is interesting. Some days ago I started my first embedded rust journey with a problem which I tried to solve with something like a proxy. But I didn't get it running. I wanted to make create a struct that holds a countdown with fugit duration and behaves like a countdown with core duration.
<FrreJacques[m]> But as far as I understand that is something which is more relevant for the main application as for the driver.
<FrreJacques[m]> And having the struct taking a timer that implements the delay and a function that use it, is like the first starting point to get my driver project started :)
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
dirbaio[m] has quit [Quit: Idle timeout reached: 172800s]
embassy-learner[ has quit [Quit: Idle timeout reached: 172800s]
crabbedhaloablut has quit [Ping timeout: 255 seconds]
crabbedhaloablut has joined #rust-embedded
GrantM11235[m] has joined #rust-embedded
<GrantM11235[m]> By the way, embedded_hal 1.0 solves this problem with this blanket impl https://docs.rs/embedded-hal/latest/embedded_hal/delay/trait.DelayNs.html#impl-DelayNs-for-%26mut+T
<GrantM11235[m]> It means that `&mut MyTimer` will always impl delay as long as the non-reference `MyTimer` does
<FrreJacques[m]> I had it first without dyn. But the compiler says Trait objects must include the dyn keyword.
<GrantM11235[m]> The thing I posted uses generics instead of a trait object
<FrreJacques[m]> Ah okay. So it's not a different way to express it, it's a different thing with the where.
<FrreJacques[m]> I should reread those sections in the rust book. But those things are stretched over different chapters,which is a bit like a maze hunt.
<GrantM11235[m]> Chapter 10 covers generics, but I don't think it explains trait objects/dyn, or how they are different
<FrreJacques[m]> Do you have a good ressource for that?
<GrantM11235[m]> Ah, here is the section on trait objects https://doc.rust-lang.org/book/ch17-02-trait-objects.html
<FrreJacques[m]> But what you did in your example is creating a struct and implementing the two Delay traits for it. In the end this is not what I want. I want to have a struct that takes a type that already implements those traits.
<FrreJacques[m]> Because I want to create a struct that takes different pins and a timer and than communicates with another device.
<GrantM11235[m]> Ah, I didn't realize you were writing your own driver, I thought you were trying to use an existing driver
<FrreJacques[m]> Thats how I started. And then I saw that the existing is outdated and doesn't have full feature set and I thought it would be a nice project.
<FrreJacques[m]> And to have it quite generic I want to specify only that the fields have the needed embedded-hal 1 traits.
<GrantM11235[m]> If you hold the delay in your driver struct, you won't be able to use the delay for anything else for the lifetime of your driver, unless you use some sort of mutex
<FrreJacques[m]> Hmm, but this works. After creating an instance of the struct I still can call the delay on the Delay I put into the struct.
<GrantM11235[m]> One option is to not hold the delay in the struct and to just pass it in whenever you need it. Compare these two examples https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b98f03126c82d69b064f0beb0453a520
<GrantM11235[m]> FrreJacques[m]: That's because the struct is being dropped when you use the delay again. If you create the struct, use the delay, then use the struct, you will get a borrow checker error
<FrreJacques[m]> Yeah that was my other idea. To initialize it with only the pins that really can't be used for anything else and then reach in a delay for each function call.
<FrreJacques[m]> GrantM11235[m]: Ah you are right.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/evBjxVSmoiRHyPHbAwzRJNIi>)
IlPalazzo-ojiisa has quit [Quit: Leaving.]
inara has quit [Quit: Leaving]
inara has joined #rust-embedded