<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`:
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>
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?