LibreSolar / charge-controller-firmware

Firmware for Libre Solar MPPT/PWM charge controllers
https://libre.solar/charge-controller-firmware/
Apache License 2.0
144 stars 71 forks source link

Add Clang-Format file and apply it #128

Closed martinjaeger closed 2 years ago

martinjaeger commented 2 years ago

This PR applies the suggestions by @hogthrob in PR #127.

The format definition tries to maintain the previously used Libre Solar firmware coding style as much as possible.

Setting BraceWrapping: AfterEnum: false did not have any effect, so I'm going to change the coding style such that enums and structs have the opening brace in the next line just like classes.

Also I couldn't manage to keep empty while loops (e.g. to wait for a register to be set) in a single line, so I'm just accepting that the formatter put the closing bracket in the next line.

hogthrob commented 2 years ago

@martinjaeger : I will look into the formatting changes and see if I can find any setting to make less changes, but I doubt it would reduce the amount of changes that much. A lot of the changes are caused by slightly different spacing rules etc. So, one big change, and then after that it should get much easier. Appreciate that you are willing to do this "cut"!

martinjaeger commented 2 years ago

Yep, many of the changes are because of previously often somewhat random indentation of comments, which are now aligned consistently. Also #includes are now sorted alphabetically, which is nice.

For some reason not all of the Clang options have the expected effect. Not sure if it's because of the order they are applied or if the formatter just has bugs.

In any case it's probably a good time to apply those many changes, as I've recently changed the folder structure to be more aligned with Zephyr default structure, so lots of the git blame information may be lost anyway.