-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General feedback #2
Comments
One thing I was wondering if it makes sense to further splits traits like |
My other question is where generic higher level abstractions like these should live? I would prefer to keep them in a different repository to keep the dependency count of this repo low. (I certainly don't want to make this crate depend on the futures crate.) |
One quick thought, looking at how I'm currently doing serial/SPI and how I'd do it with this crate, is that in my applications almost all peripheral IO happens through DMA to large buffers, and almost none of it is word-at-a-time. How could the current traits be extended to support that sort of thing? DMA fits very nicely into a variety of async patterns (since you start it, and then get an interrupt or can check a flag to see if it's done yet), and is generally faster and lower overhead. If I'm writing a high-level abstract library, say something to communicate packets over a UART with framing (so COBS or PPP style escapes), I'll want to tell the underlying hardware, via the HAL, to send/receive a whole &[Word] (or u8 for Serial but that should probably be Word too to handle 9-bit serial), and to tell me when it's done. Does that live as some new traits? Should the current traits have Edit: Ok, I found and read the section on higher level abstractions that touches on this -- that's an option, but I think "transfer a whole block" is both so commonly used by higher levels, and so commonly doable better with DMA, that it makes sense for the device HAL implementations to provide for it natively, rather than it being done generically as a word-by-word loop, even with async. |
I agree with @adamgreig. Writing more bytes is a common thing. Maybe use something like genio would help. I think splitting |
@adamgreig Yes, that would be in a different trait: So, yeah I think stuff that uses the DMA will require different signatures / traits to actually be memory safe.
That makes sense.
That seems to be a blocking API. We probably will want two APIs: a blocking way and a non blocking one. |
As far as I understand, the only difference is Maybe add some convenience traits or just duplicate those with slightly modified return types. |
No, that wouldn't work for |
I've opened PR #13, as I don't think we should use th However, I think @adamgreig touches on a very important issue which is that we need ways to indicate that a whole buffer of data is ready. In In REQ-std I state that one core data type must be "buffering: creating global buffers and sharing them with functions and between threads". We must have core data types that enable sharing and returning of owned global buffers, as these kind of objects are extremely core to the operation of most embedded systems. Then most of these IO features could be built on top of these buffers. |
@japaric well, That being said, I believe such trait should look like this: trait AsyncRead {
type ReadError;
// Maybe some kind of buffer with possibly uninitialized memoy instead of [u8]?
fn read(&mut [u8]) -> Result<usize, nb::Error<Self::ReadError>>;
} Similar in case of |
Another thing to consider is where you would want to host libraries that are implemented using this hal. If I write say a stepper driver using the gpio hal, it would be nice if other people could easily find and use it. It could just be an index that someone maintains like the awesome rust page, or maybe something more involved like platformio |
How will pin selection be handled? If there is overlap between, say, a GPIO line and a PWM channel line, will the HAL provide an error mechanism if one attempts to use both at the same time? Or is it possible that the svd2rust output already accounts for this (I haven't read into svd2rust thoroughly)? I can imagine one way to do this would be to make some sort of Pin struct that acts as a lock that a peripheral must acquire in order to work. My apologies if this is a non-issue because of some implementation details I'm unaware of :) |
Also a few other API's you may want to consider adding are RTC, Clock speed selection (I know you've mentioned in the past leaving this up to the board support crates, but I think it's pretty common), power saving (setting sleep/stop/standby), attaching an interrupt to a pin (may be out of scope), and DAC. |
I think we're mixing up what's wanted from a HAL. Where they would be really nice is microcontroller-specific HALs that make configuring that microcontroller easier, and there you could totally imagine having something that checked that your pin selections made sense, etc. But I think that's a lot of work and by its nature can't be very cross-device without losing a lot of utility, just because so many features are so device-specific. |
@adamgreig you're right, I was looking at this more as a platform (the hal being more generic than just for writing libraries). It does make sense for device specific settings to be in separate crates, I was just looking at this crate to be where the API for those interactions would be defined. It does make sense if that's out of scope for this crate, but I do think it should be considered in the early stages of design. |
From the documentation
Now I think that that ^ is a useful thing to have but it doesn't belong to this crate, to this set of traits. This set of traits has constraits around zero cost-ness and async model agnostic-ness that don't make sense for a configuration layer. I have written my thoughts on configuration at the end of this comment. I'll eventually open an issue about configuration on the rust-embedded/rfcs so let's keep this thread on topic please. |
No problem, I believe having a DAC API would still be in scope then, and is available on several of the stm32 chips. |
We (https://github.com/embed-rs/) cannot use the APIs as suggested here, since the APIs take I think changing the appropriate methods to |
@oli-obk good observation. |
@oli-obk Sounds good to me. |
@oli-obk For the record, there might be some downsides in using unique |
@Protagores I don't think your and our method are in conflict. Inside the |
It is mostly a matter how we want different people to cooperate. repository type a: RTFM core developers It is worth do have a look in TockOS. They differentiate between "chips" and "boards" and have a "capsule" API for drivers. |
I think this issue has served its purpose. The signature of the methods has changed from |
disable the default features of the cast dependency None
You can leave general feedback about the HAL here.
The text was updated successfully, but these errors were encountered: