Closed icanwalkonwater closed 1 year ago
The same would make sense for arduino-hal
in my opinion.
Yesterday I wrote a struct for handling a seven segment led. This element is used to display a single digit and has segments named A
through G
. With arduino_hal
it looks a little something like this
struct SevenSegmentLed<A, B, C, D, E, F, G>
where
A: PinOps,
// Shortened for brevity.
{
segment_a: Pin<Output, A>,
// Shortened for brevity.
}
The problem is, that the Trait bound PinOps can only be found in avr-hal-generic
.
Reexport avr-hal-generic's
prelude
:+1: from me. I'm actually surprised this isn't the case already... It probably got lost at some point during the refactoring.
Reexport
avr-hal-generic
Hm, I'd rather see the pieces from avr-hal-generic
re-exported in the appropriate locations. To some degree, this is already happening: For example in the adc
module or in the i2c
module:
I think it is more sensible to add the missing re-exports in this way than to expose the entire avr-hal-generic
crate's structure to the outside. It will make downstream code much more ugly if they have to pull in imports from all over the place rather than a single import for all i2c
related items, for example.
From a quick glance, it does seem that these re-exports are missing in places, though. To begin, PinOps
isn't re-exported in the port
module in either atmega-hal
nor the BSP arduino-hal
crate. I think the end-goal should be having all items from avr-hal-generic
re-exported somewhere appropriate in the HAL crates.
I think it is more sensible to add the missing re-exports in this way than to expose the entire
avr-hal-generic
crate's structure to the outside.
I agree, seems like more work but if well done would be the better solution.
I started with fixing the prelude and PinOps
in #350. If you stumble over any other missing re-exports, please either report them here or, even better, send a PR :)
I think this is all solved now, if not, let me know!
Why ?
Currently, when working with the crates of this repository, doing anything more than a blinky requires adding a bunch of dependencies that are already present in the upstream crates, just hidden.
For example, in a very basic app that uses only the serial and logs panics to it, I need all of these:
Each one of these crates is already in the dependency tree of
atmega-hal
and is thus prone to version conflicts. The goal of this issue is to propose a solution for this.Reexport
avr-hal-generic
's preludeThe prelude of
avr-hal-generic
currently reexports traits fromembedded-hal
,ufmt
andvoid
, which are compiled either way and are useful to have in downstream crates.The proposal is to create a prelude for the
mcu/*-hal
which reexportsavr-hal-generic::prelude::*
. Something likeAnd maybe the same things in further downstream crates like
arduino-hal
.This will also prevent version conflicts related issues as well. #303 #282
Reexport
avr-hal-generic
In addition to that, reexporting the whole
avr-hal-generic
crates will be great, this was discarded as useless #98 but I'd argue that this is a similar case to thepac
reexport in mcu crates and thehal
one inarduino-hal
, it allows users to drop down a level (or up in this case) and get access to all the traits and reexports of this crate to write more generic code.This is similar to what they do on the
stm32-rs
project, for example instm32f3xx-hal
, thenb
crate traits are implemented a bit everywhere and reexported at the root.