-
Notifications
You must be signed in to change notification settings - Fork 143
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
[gpio] Refactor SAM signals API #482
Conversation
This looks great on first viewing! The STM32 API was still C++11 based, which didn't have variadic templates, so we generated everything with Python. I've always been busy fixing lbuild/modm-devices/tooling stuff that I don't have enough time to properly engage on the C++17 API front. There's a lot more to improve. I'm still busy with TinyUSB and then I'd like to review/merge your OTA code, so I'll check this out, but probably not fast. PS: Please fix your formatting style, or I'm going to have a hard time reviewing this. |
c61f5f9
to
c9de7d1
Compare
Yeah I learned a lot about C++17 while doing this, which was my main motivation. It believe it should be fairly straight-forward to make the STM32 API follow the pattern, but I'd like to make that a separate PR. The OTA code is still WIP and not ready to merge, I would recommend you start here and then look at the fiber PR.
Fixed, I also added the .clang-format file which I used so that I can stay more consistent in the future. PS: How I dislike those hard tabs... |
c9de7d1
to
a63aa57
Compare
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 like this very, very much! It's so much cleaner and much faster to generate/compile than the STM32 solution, which generates 200+ files just for the GPIOs, which is just dumb.
I added a closer-to-modm-style clang format, but I guess we're going to have to use // clang-format off
for some of the short function stuff. You still have to set hardtabs in your editor for the template stuff. Theres a .editorconfig
for that purpose, it's supposed to be editor independent.
I would still like to see an alias for using GpioA00 = Gpio<A00>;
for backwards compatiblity? Or perhaps just for STM32? I'm not sure I like having a A00
type floating around globally (due to using namespace modm::platform;
), so perhaps it should be using GpioA00 = Gpio<GpioConfigA00>;
?
using LoggerDevice = modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull >; | ||
using Leds = SoftwareGpioPort< Led >; | ||
using LoggerDevice = modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull>; | ||
using Leds = Led; |
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 does not have the same semantics. Leds::write(uint32_t)
accepts a bit vector, Led::write(bool)
only accepts a single bit.
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.
Yes, but a bit vector is implicitly convertible to a bool, so it should be ok in all cases.
Here is the line I am trying to make it work with:
modm/src/modm/board/board.cpp.in
Line 50 in 3072005
Board::Leds::write(1); |
Is it expected that it only will blink the first led?
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 is the benefit of removing the SoftwareGpioPort<>
here?
I would like to keep it in order to have the same board.hpp
files for further automation and testing in the future (#359).
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.
It wasn't implemented on SAM properly and the new Gpio<>
is drop-in compatible with a SoftwareGpioPort<>
that only contains one port (which is the case for all SAM boards at the moment).
Maybe we can move the SoftwareGpioPort<>
to a common library after stm32/avr supports the same signals API?
a63aa57
to
c9de7d1
Compare
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 like this very, very much! It's so much cleaner and much faster to generate/compile than the STM32 solution, which generates 200+ files just for the GPIOs, which is just dumb.
Thanks for the review!
I added a closer-to-modm-style clang format, but I guess we're going to have to use
// clang-format off
for some of the short function stuff. You still have to set hardtabs in your editor for the template stuff. Theres a.editorconfig
for that purpose, it's supposed to be editor independent.
I disagree your clang-format is substantially closer to modm-style than the one I added. I force-pushed the branch back to where it originally was, in the future, please make changes in commits so that we can review the differences. I spent multiple hours aligning it with the modm style so it would be good to compare our efforts...
Also feel free to comment on the style in this PR, then we can see how we can fix that in the clang-format file.
I used this command to assess quality of the clang-format file: find src/modm | grep -e "\.\(c\|h\|hpp\|cpp\)\$" | xargs clang-format -n 2>&1 | wc -l
(lower is better)
Your config: 143759
My config: 143800
Note that my config does allow the short functions, so no need for the // clang-format off
.
I would still like to see an alias for
using GpioA00 = Gpio<A00>;
for backwards compatiblity? Or perhaps just for STM32?
I'm fine with adding the using declarations, but it should be a separate templated header file (which we could probably share between the platforms).
I'm not sure I like having a
A00
type floating around globally (due tousing namespace modm::platform;
), so perhaps it should beusing GpioA00 = Gpio<GpioConfigA00>;
How about PinA01
then? GpioConfigA00
is too long for my taste.
|
||
%% endfor | ||
|
||
} // namespace modm::platform |
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 file needs to be converted to tabs and the { put on a newline.
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.
Braces done, I still need to figure out how to configure my editor (VSCode) for properly emitting tabs
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've added a .editorconfig
to make GitHub render tabs as 4 spaces. Perhaps you can use the same mechanism. Something like this perhaps:
https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
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 tried it but it makes it impossible to edit the python files, as there we use spaces and python considers the difference important
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.
Then we need to add a filter for python files to the config.
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.
Try adding this to .editorconfig
, that should make the tabs go away for the Python files.
[*.{lb,py}]
indent_style = space
indent_size = 4
I'm currently super busy with manufacturing 100 railway signals, so I'm AFK for a few weeks. |
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.
Need to make the CI pass and rebase and squash onto develop please.
Perhaps using clang format is ok on new files, but we're not reformatting entire swathes of modm, just because one line changes. I'm not wasting my free time fighting an autoformatter. |
I'm sorry I'm exploding at you, but these are exactly the same issues that I first encountered ~3 years ago when investigating using clang format for modm (during the porting from xpcc) and it's very frustating to see all the failing corner cases. I like the idea, but I'm going to have to deal with the fallout of this decision for many, many years going forward and I don't want to burn out on this project from preventable causes. |
And why did the STM32 CMSIS header and FreeRTOS submodules change? |
*challening the inner grumpy old maintainer* get off my lawn!1!! |
8003b41
to
44eed30
Compare
Rebased + fixed CI |
If I look at the changes, there are more cases where the existing style is inconsistent with the modm style than there are cases where clang-format IMO is wrong. For example, the contribution guide specifies no space after template keyword, yet that is the case in all of the bitbang implementations. Also, brace wrapping of if/else conditions is done very inconsistently (and this one isn't well defined in the style guide). At some point, you need to bite the apple and decide which one is actually correct. Obviously, if the goal is to have inconsistent style everywhere, then we should not use clang format [grumpy new contributor mode on] but then I expect no more comments on the style of my commits... [/grumpy] |
44eed30
to
e382657
Compare
The goals are in order:
All are pretty subjective, but forcing me to search the diff in a reformatted file is not acceptable. I also contribute to other projects and I don't reformat entirely unrelated lines of code because I want my changes merged and not bikeshed about code formatting. Our formatting guide is basically about quickly grokking code, by visually matching vertically scoped code elements, like most control structured and function declarations.
This is a cooperation between you and me, not a negotiation. You adapt your style a little and I look the other way and then we can both be maximize our happiness. This has worked quite well for most contributors and it can work well for us too.
The bit-bang implementation is adapted from code from 2006 I believe. Much modm code is over a decade old. When we ported xpcc to modm, we experimented with clang-format to change the tabs to spaces, but it was just too many changes it would have double the repository size and made it impossible to use git blame for anything anymore. Which is why using clang-format on purely added files is very acceptable to me, but let's not plough over the entire repo on principle. |
b44c26d
to
6382b44
Compare
I reverted the style changes to the bitbang* files and rebased/squashed against develop. |
6382b44
to
4b1cd6d
Compare
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.
Excellent.
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.
Nice work! 👍
I have commented a few remarks and questions inline.
using LoggerDevice = modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull >; | ||
using Leds = SoftwareGpioPort< Led >; | ||
using LoggerDevice = modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull>; | ||
using Leds = Led; |
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 is the benefit of removing the SoftwareGpioPort<>
here?
I would like to keep it in order to have the same board.hpp
files for further automation and testing in the future (#359).
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.
Thanks for the review!
using LoggerDevice = modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull >; | ||
using Leds = SoftwareGpioPort< Led >; | ||
using LoggerDevice = modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull>; | ||
using Leds = Led; |
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.
It wasn't implemented on SAM properly and the new Gpio<>
is drop-in compatible with a SoftwareGpioPort<>
that only contains one port (which is the case for all SAM boards at the moment).
Maybe we can move the SoftwareGpioPort<>
to a common library after stm32/avr supports the same signals API?
Merge @salkinium? |
32e15b6
to
debb430
Compare
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.
Squashed and rebased, I'll merge once the CI passes.
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
#---------------------------------------------------------------------------- | ||
|
||
git diff --name-only --diff-filter=A -C -M develop | grep -e "\.\(c\|h\|hpp\|cpp\)\$" | xargs clang-format -i "$@" |
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.
Added a filter so that only newly added files get formatted, otherwise I go crazy as discussed ;-P
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.
Thanks! I realized this command is even better, as it reformats only changed lines: git clang-format upstream/develop
Goals:
Fixes #481.