<re_irc>
<@therealprof:matrix.org> burrbull: `char` seems like a good fit.
<re_irc>
<@therealprof:matrix.org> burrbull: I'm not quite sure what the external use of those `P` types is, aren't they degraded into an implementation detail? Do we actually need to publicly expose them?
<re_irc>
<@burrbull:matrix.org> They can be usefull if you want to write generic implementation of something across all or part of pins. On the other hand you can't construct incorrect pin as fields and construction methods are private.
starblue has quit [Quit: WeeChat 2.3]
<re_irc>
<@therealprof:matrix.org> So I'm hearing we want/need them? 😉
<re_irc>
<@burrbull:matrix.org> I just saying it makes no sense to hide them.
<re_irc>
<@therealprof:matrix.org> Fair enough. I don't have actual naming ideas. Maybe if they're only useful for very special applications the current names are good enough.
<re_irc>
<@burrbull:matrix.org> Let's merge this then. I have several other improvements based on this.
<re_irc>
<@therealprof:matrix.org> I take it you're happy with the current run of commits on the PR?
<re_irc>
<@adamgreig:matrix.org> oh man, `into_alternate()` and then the compiler completes the type based on the driver you pass it into is great
<re_irc>
<@therealprof:matrix.org> Hell yes! 😀
<re_irc>
<@therealprof:matrix.org> burrbull: Can I leave the computer now or is more coming my way? 😀
<re_irc>
<@firefrommoonlight:matrix.org> Yea - that's a great idea a, given there's 0 degrees of freedom of which alternate to use, if you've paired the pin to a periphi. I've gone with a more explicit approach since I don't do the pairing in software
<re_irc>
<@firefrommoonlight:matrix.org> I also like how the example in that PR (Based on code in an earlier one?) doesn't rely on the fallible EH GPIO traits
<re_irc>
<@jamesmunns:matrix.org> How does it look inside of an rtic resource?
<re_irc>
<@jamesmunns:matrix.org> Something like `Pin<Alternate<4>>`?
<re_irc>
<@jamesmunns:matrix.org> (just asking, as sometimes things that lean too hard on type inference can look... funky, when you have to actually name their type, which is typically for statics and rtic resources)
<re_irc>
<@therealprof:matrix.org> jamesmunns: I think that's correct. We don't have an example using `Alternate` pins as a ressource at the moment.
<re_irc>
<@jamesmunns:matrix.org> (I'm thinking more like `Spi4<Pin<AF<4>>, Pin<AF<4>>, Pin<AF<4>>, Pin<AF<4>>>` or something, which is usually what gets put in Resources)
<re_irc>
<@therealprof:matrix.org> Is passing a initialized AF pin common? Wouldn't you pass around a fully initialized peripheral handle in most cases?
<re_irc>
<@jamesmunns:matrix.org> I mean for SPI ports that are generic over the pins they take
<re_irc>
<@firefrommoonlight:matrix.org> IMO sigs like that needs to be in the Readme, and examples. Ie include use as a global, struct field, or fn argument
<re_irc>
<@jamesmunns:matrix.org> But I guess if you've type erased, maybe not?
<re_irc>
<@jamesmunns:matrix.org> But I guess you could also have `Spi4<Pin<AF<4>>, Pin<AF<6>>, Pin<AF<4>>, Pin<AF<2>>>` or something if you use alt pins
<re_irc>
<@jamesmunns:matrix.org> (this is not a criticism of this change, by the way! This is no better or worse than the verbose types we had before)
<re_irc>
<@jamesmunns:matrix.org> and can be fixed by the same techniques, e.g.:
<re_irc>
<@jamesmunns:matrix.org> type MainSpi = Spi4<Pin<AF<4>>, Pin<AF<6>>, Pin<AF<4>>, Pin<AF<2>>>;
<re_irc>
<@jamesmunns:matrix.org> ```rust
<re_irc>
<@jamesmunns:matrix.org> once at the top of your program
<re_irc>
<@jamesmunns:matrix.org> newam: that pin is sck af!
<re_irc>
<@therealprof:matrix.org> jamesmunns: Not seeing this criticism at all. I'm thinking of other ways we can use this vastly improved method to improve even further.
<re_irc>
<@newam:matrix.org> Source here if you want to take a look - I am still tweaking it, I need to remove some more of that boilerplate
<re_irc>
<@therealprof:matrix.org> Interestingly this change bloats no-opt binaries even more. Oh rustc...
<re_irc>
<@burrbull:matrix.org> sorry i was offline myself
<re_irc>
<@burrbull:matrix.org> jamesmunns: I'll see what I can do about it
<re_irc>
<@therealprof:matrix.org> jamesmunns: Type syntax is `PD11<Alternate<AF4>>` or `Pin<Alternate<AF4>>` for a fully erased Pin.
<re_irc>
<@therealprof:matrix.org> Very little (if anything) has changed in the usage itself, just needed to doublecheck whether that's actually true for RTIC, too. 😅
<re_irc>
<@burrbull:matrix.org> Mayby we can make `PD11<Alternate<4>>`
<re_irc>
<@firefrommoonlight:matrix.org> Someone proposed using the type checks in constructors only. Then you could ditch the args from the Spi struct
<re_irc>
<@firefrommoonlight:matrix.org> `Spi`, or `Spi<SPI1>` if it's generic over Deref regblocks
<re_irc>
<@firefrommoonlight:matrix.org> I use the syntax above, but that's unchecked
<re_irc>
<@firefrommoonlight:matrix.org> Feels wrong, since that struct is responsible for setting up and configuring the Spi peripheral, primary with reg reads and writes to the `SPI4` etc reg block. It has no interactions with pin configs. That type signature is a byproduct of ensuring the correct pin is used and configured properly, but it...
<re_irc>
... should end there
<re_irc>
<@firefrommoonlight:matrix.org> This causes #1: Code that's more difficult to read and write, and extraneous data that implies use where there is none
<re_irc>
<@burrbull:matrix.org> This is draft PR. It let's you pass pin in any mode to Serial. It will be transformed to Alternate internally after serial initialization.
<re_irc>
<@adamgreig:matrix.org> firefrommoonlight: the main tradeoff here is you can't then return the pins in a `free` sort of method, since you don't know what they are any more
<re_irc>
<@firefrommoonlight:matrix.org> Maybe this is something that could be resolved by a Rust language update... It would be nice to have the compile checks without the added code complexity
<re_irc>
<@firefrommoonlight:matrix.org> I don't have an idea of what that would look like
<re_irc>
<@firefrommoonlight:matrix.org> You could have the struct take the pin as a borrow. This wouldn't be as strong of a guarantee the pin's set up correctly though
<re_irc>
<@firefrommoonlight:matrix.org> I think the crux of this is "what is the intended use case of the pin checks", and validating the model of situations where someone misconfigures a pin
<re_irc>
<@firefrommoonlight:matrix.org> Ie, the questions to ask: "Is this a new user who's never programmed in embedded and doesn't know how to configure a pin?" "Is this for a complex project worked on by multiple teams, and we need to catch cross-team errors between iterations?" etc
<re_irc>
<@firefrommoonlight:matrix.org> Then you can figure out which approach to take, given the tradeoffs
<re_irc>
<@newam:matrix.org> firefrommoonlight: There was a post on reddit showing crates that were downloaded the most during weekdays/weekends.
<re_irc>
<@newam:matrix.org> At the moment the embedded rust crates have many more downloads on weekends than weekdays, I think there's a lot of hobbiests here.
<re_irc>
<@firefrommoonlight:matrix.org> And consider teh consequences of a misconfigured pin: "Is this a sublte error that will waste people's time and be tough to find?" "Will the first step when button 1 isn't working is to check the wiring and config for PA5 it's connected to?" "Will the product short out and break?"
<re_irc>
<@firefrommoonlight:matrix.org> newam: That's a neat inference
<re_irc>
<@firefrommoonlight:matrix.org> Overall, I think a lot could be done in these packages by describing who they're for, what the intent is. Your classic "Requiremetns and Specifications"
<re_irc>
<@firefrommoonlight:matrix.org> In my projects, the type checks make no sense because they make parts of the code messy, and a misconfigured pin will be obvious. But maybe that's not the intent here
<re_irc>
<@firefrommoonlight:matrix.org> I wonder if it's arduino spillover? Or Raspberry Pi? (Implied by i2cdev?)
<re_irc>
<@firefrommoonlight:matrix.org> It fits with the F1 and F4 being the most stalked about STM32s here, due to the cheap dev boards
<re_irc>
<@newam:matrix.org> Maybe? I am curious too, but only have theories.
<re_irc>
<@newam:matrix.org> I think there is also a lot of embedded developers doing rust on weekends for projects; we never touch rust at my workplace, but there are quite a few of us who use it for personal projects.
<re_irc>
<@firefrommoonlight:matrix.org> That's where I fit
<re_irc>
<@firefrommoonlight:matrix.org> Well, non-coding day job, and have a side-hustle selling electronics
<re_irc>
<@firefrommoonlight:matrix.org> I'm suspicious there's a larger contingent of embedded Rust users that dont' get involved with the OSS community
tokomak has quit [Read error: Connection reset by peer]
<re_irc>
<@newam:matrix.org> firefrommoonlight: That could also be true. There is a tonnnn of red tape at my work to get involved in any OSS project; you have to schedule a meeting with the OSS team, give an hour-long presentation about what/why you want to contribute, no exceptions (even if you are just fixing a typo in the docs).
<re_irc>
<@dirbaio:matrix.org> Hahaha embedded-hal and nb are there in the top unprofessional 🤣
<re_irc>
<@lachlansneff:matrix.org> burrbull: You're right, looking at it again, this is sick
<re_irc>
<@lachlansneff:matrix.org> I don't think I saw it in the diff, but might have missed it, are the Pins still different types, or do they use const generics to differentiate?
<re_irc>
<@lachlansneff:matrix.org> e.g. `Pin<'A', 5, AF5>`
<re_irc>
<@burrbull:matrix.org> We have 3 type of pins. Basic are different types
<re_irc>
<@burrbull:matrix.org> You can take erased and partially erased pins by `downgrade` and `downgrade2` from basic
<re_irc>
<@firefrommoonlight:matrix.org> dirbaio: I'd considered automatic pin config by periph. Ultimately, I think this is a bad plan for most uses, since it hides config that can be tough to troubleshoot, and there are edge cases where the standard pin config isn't suitable
<re_irc>
<@adamgreig:matrix.org> why not have SckPin::into_af that configures the pin when impl for a legit pin and nops when impld for NoPin?
<re_irc>
<@dirbaio:matrix.org> > tough to troubleshoot
<re_irc>
<@dirbaio:matrix.org> tough if the type system enforces you can only pass the right pins?
<re_irc>
<@adamgreig:matrix.org> anyway yea fair enough having the SckPin trait resolve it for you, makes sense
<re_irc>
<@adamgreig:matrix.org> shame the AF number can't always be the same for any given peripheral
<re_irc>
<@adamgreig:matrix.org> at least when you can pass in NoSck etc it means in those edge cases you can take care of the config yourself
<re_irc>
<@thalesfragoso:matrix.org> adamgreig: At least we just scrape them from ST's files
<re_irc>
<@firefrommoonlight:matrix.org> dirbaio: Maybe your I2C line isn't open drain. Or you're checking why a certain pin isn't working right but can't find where you set it up. I think it's best to be explicit with how the pins are set up
<re_irc>
<@therealprof:matrix.org> burrbull: I'm not totally convinced by this change. It might be necessary to useful to use a custom configuration without the `into` implementation magically changing it behind the users back. Or would this automagically turn into a no-op if the user already provided a pin in the correct mode?
<re_irc>
<@dirbaio:matrix.org> adamgreig: that'd work too, but it's more stuff in the macro'd impls
<re_irc>
<@firefrommoonlight:matrix.org> I really think you need to write down reasoning of why you're doing the type states before continuing work on this
<re_irc>
<@firefrommoonlight:matrix.org> And what the intended problem they solve is
<re_irc>
<@firefrommoonlight:matrix.org> But Dead horse is dead. Sorry
<re_irc>
<@firefrommoonlight:matrix.org> Agree to disagree
<re_irc>
<@burrbull:matrix.org> therealprof: It does nothing if pin in correct mode
<re_irc>
<@firefrommoonlight:matrix.org> The complexity they hide isn't trivial. And not providing examples or docs of this complexity is a mistake.
<re_irc>
<@therealprof:matrix.org> Interesting. Is this guaranteed by Rust?
<re_irc>
<@burrbull:matrix.org> Of cource. It uses common `From` which is autoimplemented for Self
<re_irc>
<@therealprof:matrix.org> Right, but I wasn't sure whether that is still the case for specialised implementations.
<re_irc>
<@burrbull:matrix.org> But you are rigth. `release` returns pins in alternate mode.
<re_irc>
<@adamgreig:matrix.org> I was thinking of asm::delay
<re_irc>
<@adamgreig:matrix.org> but the Delay impl using systick is fine
<re_irc>
<@firefrommoonlight:matrix.org> Yea. Adding an ASM::delay is always an option
<re_irc>
<@firefrommoonlight:matrix.org> I tried at one pt; don't remember why I abandoned it
<re_irc>
<@adamgreig:matrix.org> it doesn't guarantee accuracy, it will delay "at least" the number of cycles
<re_irc>
<@adamgreig:matrix.org> but it can be (many) more
<re_irc>
<@firefrommoonlight:matrix.org> That might be why!
<re_irc>
<@firefrommoonlight:matrix.org> Anecdotally the systick delay feels accurate to the second
<re_irc>
<@firefrommoonlight:matrix.org> Probably far better (?)
<re_irc>
<@firefrommoonlight:matrix.org> I guess it depends on your oscillator
<re_irc>
<@adamgreig:matrix.org> yes
<re_irc>
<@adamgreig:matrix.org> but pretty much anything you use should feel totally accurate to a human
<re_irc>
<@adamgreig:matrix.org> anyway it counts clock cycles so (except for the small number of extra cycles due to it doing some maths and entering/leaving the method) it should be exactly as good as your oscillator
starblue has quit [Quit: WeeChat 2.3]
<re_irc>
<@sympatron:matrix.org> It's not accurate if it's interrupted by interrupts. Then the asm::delay could be much longer and a systick delay would be much more accurate.
<re_irc>
<@adamgreig:matrix.org> that too, yea
<re_irc>
<@firefrommoonlight:matrix.org> Another thought on HAL design, after a discussion with newam : I've just followed his example, and featured-gated the EH trait implementations
neceve has quit [Ping timeout: 240 seconds]
<re_irc>
<@firefrommoonlight:matrix.org> adamgreig: Regarding `stm32-ral` - I just looked at this again. Compared to PACs, is this intended to be a nicer user-facing API, for writing code at a lower-level than HAL? Eg, PACs for building HALs on top of, and RAL for writing project code, with a nicer API?
<re_irc>
<@adamgreig:matrix.org> why feature-gate the EH traits?
<re_irc>
<@adamgreig:matrix.org> re RAL, I guess both, but I wrote it originally with application code in mind
<re_irc>
<@newam:matrix.org> I did it for a W5500 crate. I made the device a trait that people could implement by providing read_reg/write_reg.
<re_irc>
<@newam:matrix.org> There's a number of things that can't be done with EH (at the moment); so makes sense to have it optional with default EH implementations provided if desired.
<re_irc>
<@newam:matrix.org> Brings the dependencies down to zero by default which is nice.
<re_irc>
<@adamgreig:matrix.org> but in principle no issue beyond pulling in an extra dependency? do you have it as a default dependency?
<re_irc>
<@newam:matrix.org> it isn't a default, but that's just preference.
<re_irc>
<@newam:matrix.org> No issues in principle; I just like to give options for other use-cases that are difficult to capture with the EH (e.g. a share SPI bus)
<re_irc>
<@adamgreig:matrix.org> sure, makes sense, was just curious if there was a particular problem always providing the e-h impl too
<re_irc>
<@firefrommoonlight:matrix.org> Feature-gate the EH traits so you don't need the dependency unless you need the traits; it's more of a philosophical decision be clear they're not the primary API; they're opt-in. I'm not sold 100% on it, but leaning that way, and have already made the code change.
<re_irc>
<@dirbaio:matrix.org> feature-gating only makes sense if the dep is fat imo
<re_irc>
<@dirbaio:matrix.org> and e-h is not fat
<re_irc>
<@firefrommoonlight:matrix.org> That's a good point
<re_irc>
<@firefrommoonlight:matrix.org> And was my initial reaction
<re_irc>
<@firefrommoonlight:matrix.org> I'm leaning 60% on this being the right approach
<re_irc>
<@adamgreig:matrix.org> it does also make sense if you are releasing a 1.0 crate and don't want a <1.0 dependency
<re_irc>
<@adamgreig:matrix.org> but in general it seems like a pretty slim dependency
<re_irc>
<@firefrommoonlight:matrix.org> Re RAL: if used as an underlying layer, what are your thoughts on RAL vs SVD-generated PACs?
<re_irc>
<@firefrommoonlight:matrix.org> For application-layer, RAL seems like the winner
<re_irc>
<@adamgreig:matrix.org> I'd be interested in seeing how well it worked, I think the current inability to abstract over registers might make some HAL operations more annoying than they could otherwise be
<re_irc>
<@adamgreig:matrix.org> I'd like to revisit the concept at some point for sure but there's a lot of other experimentation in this space now anyway I guess, like the various svd2rust mods and also the metapac stuff the embassy folks are working on
<re_irc>
<@firefrommoonlight:matrix.org> I have `eh` as an optional dependency, that's only pulled in if you use the `embedded-hal` feature
<re_irc>
<@firefrommoonlight:matrix.org> But as you and dirbaio said, it's a very light dep
<re_irc>
<@firefrommoonlight:matrix.org> So not a big deal
<re_irc>
<@adamgreig:matrix.org> in principle I don't see why it couldn't work and indeed my own per-project small HALs use it
<re_irc>
<@firefrommoonlight:matrix.org> To avoid a conflation: You can actually use EH SPI etc traits without worrying about bus sharing; that's more an issue of regblock owning than traits-vs-native. Ie, you can easily take `&mut S`, where S is the EH trait
<re_irc>
<@newam:matrix.org> firefrommoonlight: Yeah, I made it optional on a peripheral crate, it is difficult to make a concrete type that accounts for shared SPI bus'; no problem there for the HAL crates.
<re_irc>
<@newam:matrix.org> Also feature gating becomes a lot less painful for users with the docs.rs features to highlight what features are required to enable what code; e.g.
<re_irc>
<@firefrommoonlight:matrix.org> In the past, I've forked EH drivers to borrow SPI etc instead of own. In some cases, got PRs merged; in other cases didn't and used forks. Currently, I do the SPI etc writes directly in my application code, to make it easier to troubleshoot, and ensure the functionality I need is there. Ie simpler, and...
<re_irc>
... more functional, but I had to spellunk the datasheets myself
<re_irc>
<@firefrommoonlight:matrix.org> Rahix's shared-bus is nice too, but IMO there's a smell when a bus is being owned, since buses are by nature multi-device
<re_irc>
<@firefrommoonlight:matrix.org> While owning a timer reg block for example, doesn't seem wrong
<re_irc>
<@firefrommoonlight:matrix.org> newam: I agree on the docs. And in general, Trait-first APIs can make the docs tough to read
<re_irc>
<@firefrommoonlight:matrix.org> Doesn't really show you how to use SPI
<re_irc>
<@newam:matrix.org> firefrommoonlight: Eh, I would disagree with this one; you need some sort of ownership to track who is using the bus at the very least.