[driver] rewrite adns9800#1193
Conversation
f1db304 to
6748582
Compare
| template<int Cpi> | ||
| requires (Cpi >= 200) and (Cpi % 200 == 0) and (Cpi <= 8200) | ||
| struct Resolution: public modm::Register8 { | ||
| Resolution() : modm::Register8(Cpi / 200) {}; | ||
| }; | ||
| using Resolution_t = modm::Register8; |
There was a problem hiding this comment.
Instead of writing all the options from 200, 400, 600, 800, ... , 8200 i came up with this.
It constraints allowed values without overloading the corresponding Adns9800::set(...).
Alternatively, something with constexpr would allow both, compile time and runtime scaling by 1/200 of the argument. let's see...
|
|
||
| return D(buffer); |
There was a problem hiding this comment.
EDITED AGAIN:
I've crossed modm's default here to add support for multiple Data types.
Problem is, the binding of Data& to the driver class limits the programmer to one type or multiple, symmetric driver instances 😖. (Is this some kind of RF relict?)
Handling Data exclusively via the emitting method Device::read(...) feels better:
Either a fresh constructed Data is returned from Device::read(...) or - as a compromise to the current default - a Data& is passed to Device::read(...).
With the "Data& in Driver"-design, responsibility for the integrity of Driver::Data&s is on Driver due to encapsulation principles -> A mutex on Driver::Data& data within Driver::read(...) might become fundamentally at some point!?
In contrast, when returning newly constructed Data, the API user could take appropriate measures. Returning Data also facilitates RVO / Copy Elision in typical situations, f.e. when forwarding Data samples from Driver::read(...) into a Container for further processing.
There was a problem hiding this comment.
Historically, this was optimizaed for placing all data objects into a big struct that was then serialized directly over a comms network. However this is not how you would do it today anymoe.
Feel free to completely refactor it to your liking.
|
Not intended to be a dizz, but i've stroken Sascha Schade from the copyright: There's nothing left from the previous driver-port but the lbuild firmware select option. |
salkinium
left a comment
There was a problem hiding this comment.
I'll review some more next week.
| powerUp() { | ||
| /// @see power-up sequence, datasheet page 20 | ||
| Cs::reset(); | ||
| modm::this_fiber::sleep_for(10ns); |
There was a problem hiding this comment.
Use modm::delay(10ns). The fiber sleep is only implemented for microseconds, since a context switch takes around 1us. (for comparison one cycle at 100MHz = 10ns-1.) (even on 550MHz STM32H7 it takes ~250ns).
There was a problem hiding this comment.
Thought of just some registers to rotate on context switches but 1us(!) sounds like there's more 😅. Assembler is not (yet) in my repertoire but now I feel the need to digg deeper into fibers gearwork.
To fix this pitfall sleep_for(...) could branch to delay(...) for durations below an appropriate threshold. With the MCUs clock by hand, this could even be scaled as needed.
There was a problem hiding this comment.
Yes, I agree those details should be all taken care of by the function itself.
Have to think about this some more, for example, on AVRs, a context switch takes 10us, so if you sleep for just 1us in a loop, it'll never yield…
(The context switch code is here btw)
| while(not this->acquireMaster()) modm::this_fiber::yield(); | ||
| Cs::reset(); | ||
|
|
||
| closure(); |
There was a problem hiding this comment.
| closure(); | |
| std::forward<Closure>(closure)(); |
#CosCppBullshitAboutPerfectForwarding
15c1a45 to
f08654c
Compare
|
Just wanna tell: I'll finish this in the beginning of September. |
The Adns9800-driver was made of pure blocking SPI calls - fixed that, added some features and eventually were directed to some clean, fibers-only implementation.
Writing a driver without the RF limitations was a pleasure!
By this chance I wanna ask, if there's a (solid) concept/thoughts how we transition drivers to fibers?Adns9800::captureFrame()in hardwareexamples/blue_pill_f103/adns9800adns9800_data.hpp