Closed stabler closed 1 month ago
Turns out I didn't need the unwrap after all (ff07d75)
I'm just a user, but from what I have seen so far this looks great. I really like not having 6 different modules with their own types. I also like not having to use the Option
's for the output :)
Awesome :)
For those interested, here's a branch where I'm working on adding the remaining Pga modes: https://github.com/stabler/stm32g4xx-hal/commit/861a3e77aae5c4d2330a31c1ed80200d956e42cd
It's a bit heavy handed right now (separate structs for each Pga variant), so I'm going to see if I can consolidate a bit (and test it!) before I put a PR up
Ok I cleaned up the Pga implementation (a lot!), so I pulled it into this PR. I haven't tested all of this code on hardware yet (hoping to do that this weekend), but I'm feeling pretty good about the Pga implementation.
Nice compile-time error if you use the wrong input pin in the more complex Pga modes:
Here's an attempt to improve the ergonomics of the opamp API. This PR also adds the remaining PGA modes.
Key changes:
Option<>
from the output interface, and instead implemented traits on the output pin directly, or a new typeInternalOutput
that represents the case where the opamp is directly connected to the ADC.Locked<_>
struct. Opamps can be moved from any of the implemented modes (Pga
,OpenLoop
,Follower
) into theLocked
state, at which point the lock bit is set and you cannot modify or disable the opamp (but you can pass it into the ADC, if appropriately configured)adc_op_pga
andadc_op_follower
were intended to work around limitations of the opamp (certain opamps can only operate in certain modes), but I can't see anything about that in the datasheet or reference manual. Maybe this is an artifact from copy-paste from another chip?Things I think are good:
Things I don't love
disable()
and alldisable_output()
functions. This is safe because those functions are only implemented on opamps that contain an output pin, but it relies on the module being implemented correctly.~Let me know what you think! @usbalbin I know you worked on this code recently, so you may have opinions!