-
Notifications
You must be signed in to change notification settings - Fork 234
Names "is_high", "is_low" is confusing. #71
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
Comments
is_high
, is_low
is confusing.
is_set(), is_clear(), set(), clear()? |
set/clear are nice verbs for output pins but it seems a bit unusual to talk about In other words |
@Fulkerson It's specifically the job of a hal implementation to ensure that |
@therealprof Lets say you have something shifting in bytes on a port. Some of the pins, for whatever reason, is inverted. Instead of adding instructions to flip some of the bits you just set the inverting register and read the bytes from the port directly. |
I could not disagree more. That is exactly what you want. The HAL is meant to abstract the hardware so that there is a common interface translating between generic drivers and hardware. If a driver needs to know whether the voltage level on a pin is high or low it would ask for that information using the
As I said: if the MCU knows that the result is inverted it's the implementations job to abstract it. If this is hardware choice (i.e. GPIO pin is inverted via external hardware) then it's the job of the application to make sure the inversion is properly accounted for. If you really wanted to support that inversion in an hal implementation for the LPC810 (and others) you can also implement a separate |
@adamgreig Fair enough. I usually work higher up in the stack and not a lot with microcontrollers. On Linux embedded systems it is common to specify whether something is active high or active low and configure the port so that when the peripheral (be it a button or amplifier or whatever) is considered active (button is pressed, amplifier is powered on etc) it corresponds to a digital one. In the long run I think it is important that the HAL clearly states what the methods are. I.e. is |
We're doing that, too. ;) But the interpretation of what is active or inactive is left to a specific driver or the application and not handled by the lower layers.
Yes, that situation is actually a bit more complex than it may sound on first glance. There's plenty of discussion about the details in #29 and at least another one I can't find right now. |
I have a hard time thinking of a driver that needs to know what the actual voltage on a digital pin is. Usually a driver only care about the peripheral on the other end of the line and not what components are in the way. There are many times the electrical signal may be inverted on the way to the destination. Many times the protocol dictates how the electrical connection should look like, but it is far from always the case.
That is sort of my point! I envision myself adding a mode for
That is perfectly fine for simple things like LEDs (is it active low or high?) but driver code quickly becomes very complex when adding interrupt pins to an ethernet driver or whatever, and you have to specify for each raw GPIO the driver is using if it is active high or not. Better put it in the gpio interface like with pullups and similar in my opinion. I believe we are of the same opinion the matter. Whether a pin should invert its logic or not should be a configuration of the pin. If it is configured to be non inverting, low should be grounded. If it is configured to be inverting high should be grounded. My main argument is that I think using high and low is confusing when introducing inversion to pins. |
The real voltage is irrelevant. The only question is: Is it considered a high level or a low level (or is it floating/in between). There're very clear definitions for that.
Exactly.
And this goes hand in hand with what the HAL does.
Not sure what's preventing you from doing that. That's exactly how it's supposed to work: The application sets up the peripherals using the hal implementation according to the schematics and then uses them (either directly or by handing them off to some driver).
How so? The whole point of the abstraction is to keep the drivers simple and generic.
And I still don't get why. Can you link any datasheet of any active component that does not mention high or low? Any digital signal consists of high/low levels/edges so it is important to know what the current state directly at the pin is if you want to use it to work with an external component. If you have an external inversion somewhere then you'll obviously need to account for that fact in your setup but it doesn't change anything about the level directly at the pin. An Most likely I would even argue against supporting that inversion flag on the GPIO. I can see why it exists for other languages where software signal inversion might cost instruction cycles, but in Rust any level-inverting adapter on a regular pin (which will work with any MCU) shouldn't require any additional instructions. |
I think I see what you mean. I can implement the InputPin trait on top of an Input and invert it there. I did not think about that! |
71: WIP: Update embedded-hal to version 1.0.0-alpha.6 r=eldruin a=caemor The delay update is pretty straightforward. The error update is more difficult: The current implementation creates a new struct including a single element: the upstream linux error, and implement the e-h error trait for it. I've got two issues with this. Is creating a new struct the best way to do this? For matching the e-h trait kind: Currently I just matched everything to `Other` because I couldn't find any good matches when taking a quick glance. Is there something that should be matched? The creation of a central error enum for linux e-h would be an other alternative way to solve this. Co-authored-by: Caemor <[email protected]> Co-authored-by: Chris <[email protected]>
The function names for at
InputPin
andOutputPin
(is_high
,is_low
) can be a bit confusing for MCUs with inverting logic. At least some (I would imagine most?) NXP LPC microcontrollers have a register for inverting the value of the GPIO register. If the invert bit is set, a high voltage at the pin will result in a 0 in the register. The nameis_low
suggests the voltage is low.I don't know if there's a better name though.
is_active
?See for example page 76 in the User Manual for the LPC81x series
The text was updated successfully, but these errors were encountered: