-
Notifications
You must be signed in to change notification settings - Fork 103
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
Added API for gpio get pin by id #159
Conversation
src/gpio.rs
Outdated
@@ -55,6 +56,15 @@ impl<'a> GpioDriver<'a> { | |||
} | |||
} | |||
|
|||
pub fn gpio_by_id(pinid:usize) -> TockResult<Gpio<'a>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why Travis didn't run (it checks formatting), but I think there should be a space between the colon and usize
here. I think the correct command to run to format the code is cargo fmt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can run ./run_all_checks.sh
to verify your formatting. Travis is triggered only when bors receives a command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the formatting, I did not know about cargo fmt.
There is a reason why a To access different GPIOs in a safe way the idea was to use the iterator Regarding the example: I do not think it is beneficial to demonstrate every possible API function in an example. In my opinion a unit test would make more sense. |
I didn't notice that, thank you.
I implemented the next_at method and a reset method. As next_at allow you to jump over pins, some pins would not be available anymore. I use an array (fixed size, not sure how to deal with this in another way) to mark the used pins. I also added a reset method to be able to reset the counter. I made a modification to the next method so that it checks if the pins had been previously exported.
How to you see the unit test implemented? I haven't seen any in the gpio.rs file or the examples, but most probably I missing something. |
self.used_pins[pin_number / 8] |= 1 << (pin_number % 8); | ||
} | ||
|
||
pub fn next_at(&mut self, pinid: usize) -> Option<Gpio<'a>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going in a good direction. However, keeping track of each GPIO pin individually will most probably add too much overhead for an embedded setup. A trade-off solution could be:
pinid < self.curr_gpio
=> returnNone
orErr(ReverseIterationError)
pinid >= self.num_gpios
=> returnNone
orErr(OutOfRangeError)
- otherwise => set
self.curr_gpio
topinid
and return theGpio
instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem that I see is that without a reset method, there is no way of getting any pins with a lower index that the requested one. As a user has no idea about what index a pin has, it depends on the mapping in the board/main.rs file, how would you solve that?
One option would be to add a function that returns the index of the pin, so that users can sort them and ask them in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I do not quite understand the scenario. Why would you randomly access pins? Wouldn't you just know beforehand which pins to use. Say, you now you need pins 7, 4 and 19, so you would call next_at(4)
, next_at(7)
, next_at(19)
?
} | ||
} | ||
|
||
pub fn reset(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this reintroduce the soundness problem mentioned before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep track of every used pin, no, otherwise yes.
We recently added some framework. You could have a look at the |
What is the status of this PR? Is there a consensus about whether or not to merging this PR? Otherwise I would like to close the PR. |
I will close the PR, as the GPIO HIL now allows None pins (tock/tock#1690). |
The API modifications and example to use tock/tock#1675.
I have not tested this yet as I don't have any of the supported boards.