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
Guest7282 has left #rust-embedded [Error from remote client]
IlPalazzo-ojiisa has quit [Quit: Leaving.]
sigmaris has quit [Quit: ZNC - https://znc.in]
sigmaris has joined #rust-embedded
wllenyj[m] has quit [Quit: Idle timeout reached: 172800s]
<thejpster[m]> And of course a package can contain many binaries, and many examples (which are binaries too).
crabbedhaloablut has joined #rust-embedded
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
Guest7282 has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
maxwickhamOld[m] has quit [Quit: Idle timeout reached: 172800s]
<Ecco> Question regarding SpiDevice: as a driver writer, I understand that I should use SpiDevice if I don't need exclusive access
<Ecco> But as a *user* it's a pain in the butt to go through the whole Mutex thing if I know that the device happens to be alone on the bus
<Ecco> Question -> Is there a way to make an "exclusive" SpiDevice that doesn't bother with a mutex at all?
<Ecco> Oh it's currently being discussed
<Ecco> :)
diondokter[m] has quit [Quit: Idle timeout reached: 172800s]
<JamesMunns[m]> Instead of writing up all the ways you can accidentally do that, I'm working on a (currently pretty limited) crate to provide some alternatives: https://docs.rs/grounded
<JamesMunns[m]> But if you have something you think you need `static mut` for, I'm definitely interested to figure out what building blocks would be useful to have available.
<JamesMunns[m]> By the way, if anyone here is using `static mut` for anything, I'd be interested in hearing about it. IMO, it is *very* easy to accidentally do an undefined behavior with them.
<JamesMunns[m]> Opened up a tracking issue here, if you want to add it there instead (otherwise I'll copy over there): https://github.com/jamesmunns/grounded/issues/1
temurumaru[m] has quit [Quit: Idle timeout reached: 172800s]
<Ecco> New to rust: would those need to be wrapped in "unsafe" blocks? Or can there be UBs even in "safe" code?
<Ecco> (those = uses of "static mut")
diondokter[m] has joined #rust-embedded
<diondokter[m]> Ecco: You can only use them in unsafe blocks
<Ecco> ok :)
<Ecco> Good :)
<diondokter[m]> <JamesMunns[m]> "By the way, if anyone here is..." <- > <@jamesmunns:beeper.com> By the way, if anyone here is using `static mut` for anything, I'd be interested in hearing about it. IMO, it is *very* easy to accidentally do an undefined behavior with them.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/NMCnyBixZulyuzkeebPSPnHw>)
<diondokter[m]> * I've use them once in a while if I want to prove something to me. For example, I'm inspecting some generated assembly and I need a write to not be optimized away. A static mut is a quick way to get that in place of a let mut.
<diondokter[m]> Another thing I can imagine, but haven't done myself so far, is having to have a global variable for compat with C. Say a C lib has a global extern variable, how would you create that un Rust without static mut?
<Ecco> Very dumb question: what's the proper way to return an OutputPin from a function?
<Ecco> I'd like to get some sample code where OutputPin are passed around
<diondokter[m]> Oh I'll add it to the issue
<Ecco> The sample code in embassy is great but super simple (that's a good thing), but then as a beginner I have no idea on how to pass OutputPin (or SpiDevice or whatever) around. I just get a shitton of unfathomable errors :-/
<JamesMunns[m]> diondokter[m]: > <@diondokter:matrix.org> I've use them once in a while if I want to prove something to me. For example, I'm inspecting some generated assembly and I need a write to not be optimized away. A static mut is a quick way to get that in place of a let mut.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/pThXaVBHsIJIbeqZiwaTEzLn>)
<JamesMunns[m]> however, the `UnsafeCell<MaybeUninit<T>>` or just `UnsafeCell<T>` can also be used as a non-mut static.
<diondokter[m]> JamesMunns[m]: Ah right, you can use those because they are `#[repr(transparent)]`
<diondokter[m]> Didn't think of that
<JamesMunns[m]> IMO: basically anywhere you use `static mut` you should basically be using `UnsafeCell<T>` or `UnsafeCell<MaybeUninit<T>>`.
<Ecco> Even here, the sample code is just one big ass function https://dev.to/apollolabsbin/embedded-rust-embassy-i2c-temperature-sensing-with-bmp180-6on
<Ecco> How do I split this into smaller chunks ? :-D
<Ecco> Even dumber question: how can I return an OutputPin from a function??
hyphened[m] has joined #rust-embedded
<hyphened[m]> I'd probably wrap the I2C instance in a BMP struct and abstract the reading of registers by address
<hyphened[m]> Also I would split the initialization, configuration and loop usage of the BMP into different functions
starblue has quit [Ping timeout: 264 seconds]
starblue has joined #rust-embedded
mameluc[m] has quit [Quit: Idle timeout reached: 172800s]
mightypork has quit [Quit: ZNC - https://znc.in]
mightypork has joined #rust-embedded
mightypork has quit [Client Quit]
mightypork has joined #rust-embedded
therealprof[m] has quit [Quit: Idle timeout reached: 172800s]
badrb[m] has joined #rust-embedded
<badrb[m]> James Munns: just came across `postcard-rpc` (long-time `postcard` user!).Do you think MQTT would be a suitable option for transportation?
<badrb[m]> s/transportation/transport/
<JamesMunns[m]> Could be, it overlaps a bit, as postcard rpc provides topics/routing. You certainly could layer them, but it'd kind of be like udp over tcp :)
<badrb[m]> * James Munns: just came across `postcard-rpc` (long-time `postcard` user!). Do you think MQTT would be a suitable option for transport?
<badrb[m]> Yep, that's what I thought. I think I'll end up using postcard + MQTT.
<badrb[m]> * Yep, that's what I thought. I think I'll end up using postcard + MQTT. I don't see any obvious benefit from postcard-rpc in this case.
<adamgreig[m]> <JamesMunns[m]> "By the way, if anyone here is..." <- > <@jamesmunns:beeper.com> By the way, if anyone here is using `static mut` for anything, I'd be interested in hearing about it. IMO, it is *very* easy to accidentally do an undefined behavior with them.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/PnOfnAhQDPKvKrDwSVryjnav>)
<adamgreig[m]> it sure is convenient to be able to return a `&'static str`
<GrantM11235[m]> That's unsound, you will get UB if you call the function concurrently
<GrantM11235[m]> wait, I didn't notice the critical section
<JamesMunns[m]> It takes a critical section
<JamesMunns[m]> Yeah, that actually looks pretty reasonable to me. Scoped access of the static mut makes it much harder to accidentally UB yourself
<adamgreig[m]> yea, it rules out most shenanigans
<adamgreig[m]> and it doesn't need maybeuninit because it is always initialised
<adamgreig[m]> you could wrap it all in an unsafecell just to make it a non-mut static but i'm not sure it buys you anything? but i'm open to finding out there's some scenario where you end up violating aliasing or such
<adamgreig[m]> once you've called it once you'll have given out the shared reference, but the shared reference doesn't exist until after you've finished writing it and you won't write it again
<JamesMunns[m]> Yeah, I can't see anything wrong immediately. It's not that it's impossible to use static mut, it's just incredibly easy to misuse it
<GrantM11235[m]> Could you use static critical_section::Mutexes instead?
<adamgreig[m]> I can't do that and still return a &'static str
IlPalazzo-ojiisa has quit [Ping timeout: 240 seconds]
<GrantM11235[m]> Maybe we should have a critical_section::OnceCell 🤔
<dirbaio[m]> 💯
<dirbaio[m]> PRs welcome
starblue has quit [Ping timeout: 255 seconds]
<GrantM11235[m]> Also, I notice that there are convenience methods for `Mutex<RefCell>`, but not for `Mutex<Cell>`. Is that just because no one has asked for it yet?
<dirbaio[m]> yep
Darius has quit [Ping timeout: 256 seconds]
Darius has joined #rust-embedded
M9names[m] has quit [Quit: Idle timeout reached: 172800s]
starblue has joined #rust-embedded
crabbedhaloablut has quit []