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
haobogu[m] has quit [Quit: Idle timeout reached: 172800s]
trinhtuan[m] has quit [Quit: Idle timeout reached: 172800s]
AtleoS has quit [Ping timeout: 264 seconds]
AtleoS has joined #rust-embedded
Socke has quit [Ping timeout: 268 seconds]
AtleoS has quit [Remote host closed the connection]
AtleoS has joined #rust-embedded
Socke has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
IlPalazzo-ojiisa has quit [Ping timeout: 272 seconds]
IlPalazzo-ojiisa has joined #rust-embedded
ainedixon[m] has joined #rust-embedded
<ainedixon[m]> 👋 hi
<ainedixon[m]> I have to find how to parse arguments to an attribute macro
<ainedixon[m]> Forexample #[module("users")]
<ainedixon[m]> How can I obtain arg "users"?
<ainedixon[m]> s/to/failed/, s/find/tofind/
xiretza[cis] has joined #rust-embedded
<xiretza[cis]> it's the first argument to your proc macro
<ainedixon[m]> Yeah, but I mean, how do I parse it... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/iaNZRWGnlYuXLkElaAmRHxxR>)
<xiretza[cis]> ah you're asking about syn, honestly I might just skip it and look at the TokenStream directly for something this trivial
AdamHorden has quit [Ping timeout: 268 seconds]
AdamHorden has joined #rust-embedded
<pronvis> Hey guys, could you help me with some weird thing inside stm32_hal. To change pin type (input / output) you need to have some weird `cr: &mut <Self as HL>::Cr` which is not used inside actually, so it is just a "own marker" or smth like that
<pronvis> I have struct that speak with UART on half-duplex (using only one pin) - so I need to be able to change pin type
<pronvis> So, my struct need to have `cr: <Pin<PIN_C, PIN_N, Dynamic> as HL>::Cr,`
<pronvis> which is working fine
<pronvis> but now I found that I need several of those structures
<pronvis> so, several structures need to own `cr: <Pin<PIN_C, PIN_N, Dynamic> as HL>::Cr` which is impossible
<pronvis> what interior mutability pattern should I use here?
<pronvis> I dont want to use Mutex, cause it will use CriticalSection, which I dont actually need - because `&mut cr` is not used actually
<pronvis> here is the function from stm32f1xx_hal that using `cr`:
<pronvis> ```rust
<pronvis> fn mode<MODE: PinMode>(&mut self, cr: &mut <Self as HL>::Cr) {
<pronvis> // Input<PullUp> or Input<PullDown> mode
<pronvis> if let Some(pull) = MODE::PULL {
<pronvis> let gpio = unsafe { &(*Gpio::<P>::ptr()) };
<pronvis> if pull {
<pronvis> gpio.bsrr.write(|w| unsafe { w.bits(1 << N) });
<pronvis> } else {
<pronvis> gpio.bsrr.write(|w| unsafe { w.bits(1 << (16 + N)) });
<pronvis> }
<pronvis> }
<pronvis> let bits = (MODE::CNF << 2) | MODE::MODE;
<pronvis> self.cr_modify(cr, |r_bits| {
<pronvis> ```rust
<pronvis> #[inline(always)]
<pronvis> fn cr_modify(&mut self, _cr: &mut <Self as HL>::Cr, f: impl FnOnce(u32) -> u32) {
<pronvis> let gpio = unsafe { &(*Gpio::<P>::ptr()) };
<pronvis> match N {
<pronvis> 0..=7 => {
<pronvis> gpio.crl.modify(|r, w| unsafe { w.bits(f(r.bits())) });
<pronvis> }
<pronvis> 8..=15 => {
<pronvis> gpio.crh.modify(|r, w| unsafe { w.bits(f(r.bits())) });
<pronvis> }
<pronvis> _ => unreachable!(),
<pronvis> }
<pronvis> }
thejpster[m] has quit [Quit: Idle timeout reached: 172800s]
link445645[m] has quit [Quit: Idle timeout reached: 172800s]
ryan-summers[m] has quit [Quit: Idle timeout reached: 172800s]
<JamesMunns[m]> The reason that thing exists is that swapping the config registers for a port/pin is not necessarily atomic, depending on the config changes you are making
<pronvis> Ok, but what workaround should I implement here?
<JamesMunns[m]> it's hard to read your code, matrix split each line into a message for me, but you do probably want a critical section while modifying the configuration registers, as you could potentially corrupt it if you were to change them concurrently (two cores, or one in an interrupt, etc).
<JamesMunns[m]> I'm not sure if `embassy_stm32` handles this any better, but yeah, it's likely that the current stm32f1xx_hal doesn't handle this well. Particulary, peripherals with a lot of "type states" make it very hard to do dynamic changes like that.
<pronvis> but, I need to have several of those
<pronvis> so I cant own `cr: <Pin<PIN_C, PIN_N, Dynamic> as HL>::Cr,`
<JamesMunns[m]> yeah, I'm saying: you probably can't do that using stm32f1xx-hal.
<pronvis> O_o
<JamesMunns[m]> you could write your own unsafe GPIO drivers, use a critical section while making port changes, and do the port changes yourself using unsafe PAC operations.
<pronvis> omg, such a pain
korken89[m] has quit [Quit: Idle timeout reached: 172800s]
<pronvis> Maybe I can just wrap `cr: <Pin<PIN_C, PIN_N, Dynamic> as HL>::Cr` into some wrapper that implements interior mutability? On std I could do it with `Box<RefCell<Cr>>`, is there something similar in no_std?
dirbaio[m] has joined #rust-embedded
<dirbaio[m]> No `&mut Cr` :P
IlPalazzo-ojiisa has quit [Remote host closed the connection]
<pronvis> hmm, never use embassy_stm32 previously - is it possible to use it together with stm32f1xx_hal? Cause I dont want to rewrite my entire code
<firefrommoonligh> I use an agnostic Pin that doesn't have ownership of hardware, and/or free-standing functions to set state and clear interrupts
<firefrommoonligh> Doesn't help you here directly, but it's a pattern I like
<firefrommoonligh> s/like/use that avoids this trouble./
<pronvis> @firefrommoonligh do you have some open sourced projects where you used that pattern?
kevlan[m] has quit [Quit: Idle timeout reached: 172800s]
ninjasource[m] has quit [Quit: Idle timeout reached: 172800s]
vollbrecht[m] has quit [Quit: Idle timeout reached: 172800s]
okhsunrog[m] has quit [Quit: Idle timeout reached: 172800s]
Makarov has joined #rust-embedded
TomB[m] has quit [Quit: Idle timeout reached: 172800s]
mabez[m] has quit [Quit: Idle timeout reached: 172800s]
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
Makarov has quit [Ping timeout: 250 seconds]
BrassPin88 has joined #rust-embedded
Socke has quit [Ping timeout: 268 seconds]
Socke has joined #rust-embedded
<firefrommoonligh> No
pronvis has quit [Ping timeout: 252 seconds]
Socke has quit [Ping timeout: 240 seconds]
Socke has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
<firefrommoonligh> If your case is let several structs use a pin as you said, you would just clone the pin, or use the freestanding fn without ownership, eg:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/CaUkFeACsCIDzERkYQZBAfos>)
cr1901 has joined #rust-embedded