-
Notifications
You must be signed in to change notification settings - Fork 614
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
Support to generic GPIOs class path names #523
base: master
Are you sure you want to change the base?
Conversation
Haven't had a chance to analyze it in full yet, but what's immediately apparent is that it makes sense to squash both commits into one. And looks like you've removed a couple of "not owner" comments, which IMHO were helpful. |
@alext-mkrs done, squashed both commits. But about the comments I removed: I added new comments a little bit more generic just before the 'if' block about this 'ownership', do you think would be better to revert it? Now, about the Trevis CI failure state: I saw that on Travis CI the commits failed, but the failure report shows a problem to the test script itself:
I will commit the tests modification we discussed on Issue #520, I hope the CI passes then =). |
@@ -72,6 +78,7 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin) | |||
|
|||
dev->advance_func = func_table; | |||
dev->pin = pin; | |||
dev->gpio_path = (char*) calloc(MAX_SIZE, sizeof(char)); |
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.
Won't this need to be freed in mraa deinit
Thanks for squashing, but now you have duplicated Signed-off-by line and two commit messages in one, I'd suggest just rephrase and merge them. As for the comment - let me take a closer look on a computer in a day or two, as phone is not an ideal tool 😃 |
@Hbrinj well pointed. Indeed it's also needed to check its state after allocation and freed in case of error (goto init_internal_cleanup). Now it's done. @alext-mkrs sorry for these wrong commits =), but now it's done, I squashed all commits together because all are related to the same thing. And don't worry, take a look when you have some time, phones isn't the better tool for sure. |
include/mraa_internal_types.h
Outdated
@@ -215,7 +216,7 @@ typedef struct { | |||
/*@{*/ | |||
unsigned int pinmap; /**< sysfs pin */ | |||
unsigned int parent_id; /** parent chip id */ | |||
unsigned int mux_total; /** Numfer of muxes needed for operation of pin */ | |||
unsigned int mux_total; /** Number of muxes needed for operation of pin */ |
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.
Styling/typo fixes not directly related to the change at hand should better be split out into separate commits.
Othserwise they pollute git history and make it harder to git bisect/blame
Indeed, before we continue, I'll edit the Pull Request title, because I made a terrible mistake using the sentence "old kernel version", because this different GPIO class path name might be particularity to old kernel versions adopted by the Allwinner SoC vendor, which has its own internal things inside kernel translating the gpios to these schema. I'll change some things and come back later just with the dev->gpio_path generic attribute part, the path schema itself (gpio<pin_number>_<pin_name>) I'll handle inside Cubietruck's code, with gpio_init_internal_replace(dev, pin), and other platforms based on Allwinner might handle the same way. It's a better way, right? |
@@ -136,7 +176,6 @@ mraa_gpio_init(int pin) | |||
syslog(LOG_ERR, "gpio%i: init: platform not initialised", pin); | |||
return NULL; | |||
} | |||
|
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.
Surplus styling fix
FWIW aside from those line comments I've added it looks ok to me by inspection. Haven't tried to run or explore it in runtime though. |
Yes, I think so. That indeed changes the angle a bit 😃 If that's more of a platform-specific quirk, replace functions are there to help that.
I wonder if in this case this infrastructure is going to be useful anywhere else and if not - wouldn't using replace functions across the board for other GPIO functionalities (and adding the pin name part in those) be a better solution. Do you think that's feasible? |
Initially I thought it would be the solution, but there are hard coded path names are all around GPIO internal functions that doesn't have replaces. Then I though that the gpio_path attribute on gpio_context_t would help. |
I'll try to use the gpio_path first, it's almost done :D, just change little things to clear the "Allwinner" specific parts. But if @arfoll prefers the replace functions, won't be a problem too. But thank you very much @alext-mkrs .. I'll be back soon. |
I think that by just concatenating either the pin num or the pin path we should be able to get both working relatively easily. I can't review well on my phone but I'll be back next week with a closer look :) |
Well, I'm back with new changes, but now I didn't do any style fixes and everything specific to the gpio<pin_number>_<pin_name> were removed, because as I said before it was a specific case to Allwinner SoC based platforms using old kernel versions. The only thing I made in this commit was to add the gpio_path attribute to struct _gpio and handled it on gpio.c/.h and on the APIs to other languages. Everything specific to Allwinner SoC must be handled in _replace functions on each platform support, as it's being made in the new support to Cubietruck I'm developing. |
api/mraa/gpio.h
Outdated
* Get the SYSFS pin path, invalid will return NULL | ||
* | ||
* @param dev The Gpio context | ||
* @return Gpio pin sysfs path |
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'd suggest to add "or NULL if error", to make it clear.
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.
but it already has "invalid will return NULL" in the same way other functions mention.
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 refer to the comment line and I refer to the @return
one. Adding it to @return
will have it fully picked up by doxygen, meaning proper/better documenting.
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.
Oh yeah, I understand and agree. =)
src/gpio/gpio.c
Outdated
// GPIO sysfs path may store the default path names schema or any other specific to vendor | ||
dev->gpio_path = (char*) calloc(MAX_SIZE, sizeof(char)); | ||
if (dev->gpio_path == NULL) { | ||
syslog(LOG_CRIT, "gpio%i: Failed to allocate memory for context's attribute", pin); |
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'd still recommend to elaborate on "context's attribute" and just state directly it's the gpio_path we are talking about.
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 didn't understand exactly what you mean by "context's attribute", could you give me an example?
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.
What I mean is that instead of "gpio%i: Failed to allocate memory for context's attribute"
make it a "gpio%i: Failed to allocate memory for gpio_path attribute"
to make it clear, which exact piece were we not able to initialize.
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.
Wow... I'm so bad on this xD. I'm sorry, you are completely right!
In addition to those inline comments - what's your idea about |
* @return Pin path string | ||
*/ | ||
char* | ||
getPath() |
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.
in C++ this should return a std::string and throw exception if error
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.
well pointed.
@bmeneguele can you push an example of a platform that works with this stuff as well? this seems to require a mix of _replace and gpio_path rather than just all moving to gpio_path. I'd much rather simply use gpio_path everywhere and have a small replace in the _init() that just sets gpio_path differently for platforms with names and by default set it to "gpio+dev->pin". Does that makes sense? |
@alext-mkrs You are right.. I just forgot that peace, there should have the gpio_path as well. @arfoll Yeah, I will open an PR to the cubietruck support I am working on. It isn't complete yet, I'm facing some SPI problems, but GPIO is working correctly. But as you can see on lines 108 and 109:
the gpio_path is being set to gpio+dev->pin by default if there isn't any init_internal_replace() function on platform's _init() code. |
@arfoll take a look at https://github.com/bmeneguele/mraa/commit/e93e261285586d4ec04c4758c541e93760cf8a7d this is the initial support to the Cubietruck board I'm working on right now. I won't pull request yet because I need to change the coding style to the standard of the project, but take a look at line 139 on src/arm/cubietruck.c, that is the _replace function to the gpio_init_internal function that handles the dev->gpio_path. |
In some platforms using old Kernel versions uses different gpio class path names, like in all Allwinner SoC based boards before Kernel 4.0 device trees weren't used, and therefore gpio paths in sysfs were different from the actual standard. Libmraa doesn't supports this kind of paths because all gpio operations were done with hard coded path names following the gpios<pin_number> standard. With this commit it's possible to run libmraa either on newer kernel version and older ones, with any formats of gpio sysfs paths, anyone can specify an specific path standard. Also, the API to other languages was modified to support the new getPath() method which returns the current path being used. Signed-off-by: Bruno E. O. Meneguele <[email protected]>
Older kernel versions might use gpio paths in the format of gpio<pin_number>_<pin_name> or any other way, as before device trees were supported proprietary hardware description files were passed from bootloader to kernel and hence leading to different naming convetions. For instance, on Allwinner platforms a specific .fex file was passed instead of the "Device Tree Binary" (.dtb).
Libmraa didn't support this kind of paths because all gpio operations were done with hard coded path names. With this commit it's possible to run libmraa either on newer kernel version and older ones, with both formats of gpio sysfs paths.
This PR also guarantees the kernel version discovery either when the gpio was already exported by any other process or when it is the first time used.