Support to generic GPIOs class path names#523
Support to generic GPIOs class path names#523bmeneg wants to merge 1 commit intoeclipse-mraa:masterfrom bmeneg:feature-gpio-class-#520
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 =). |
|
|
||
| dev->advance_func = func_table; | ||
| dev->pin = pin; | ||
| dev->gpio_path = (char*) calloc(MAX_SIZE, sizeof(char)); |
There was a problem hiding this comment.
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
| 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.
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? |
| syslog(LOG_ERR, "gpio%i: init: platform not initialised", pin); | ||
| return NULL; | ||
| } | ||
|
|
|
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.
I'd suggest to add "or NULL if error", to make it clear.
There was a problem hiding this comment.
but it already has "invalid will return NULL" in the same way other functions mention.
There was a problem hiding this comment.
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.
Oh yeah, I understand and agree. =)
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.