-
-
Notifications
You must be signed in to change notification settings - Fork 34
Harden LED configuration and color packing #94
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
Open
mjc
wants to merge
2
commits into
lukash:main
Choose a base branch
from
mjc:refloat-fix-led-driver-encoding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2026 Michael Conrad | ||
| // | ||
| // This file is part of the Refloat VESC package. | ||
| // | ||
| // Refloat VESC package is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by the | ||
| // Free Software Foundation, either version 3 of the License, or (at your | ||
| // option) any later version. | ||
| // | ||
| // Refloat VESC package is distributed in the hope that it will be useful, but | ||
| // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along with | ||
| // this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| #include "led_color_order.h" | ||
|
|
||
| static uint32_t color_grb(uint8_t w, uint8_t r, uint8_t g, uint8_t b) { | ||
| (void) w; | ||
| return ((uint32_t) g << 16) | ((uint32_t) r << 8) | b; | ||
| } | ||
|
|
||
| static uint32_t color_grbw(uint8_t w, uint8_t r, uint8_t g, uint8_t b) { | ||
| return ((uint32_t) g << 24) | ((uint32_t) r << 16) | ((uint32_t) b << 8) | w; | ||
| } | ||
|
|
||
| static uint32_t color_rgb(uint8_t w, uint8_t r, uint8_t g, uint8_t b) { | ||
| (void) w; | ||
| return ((uint32_t) r << 16) | ((uint32_t) g << 8) | b; | ||
| } | ||
|
|
||
| static uint32_t color_wrgb(uint8_t w, uint8_t r, uint8_t g, uint8_t b) { | ||
| return ((uint32_t) w << 24) | ((uint32_t) r << 16) | ((uint32_t) g << 8) | b; | ||
| } | ||
|
|
||
| bool led_color_order_resolve(LedColorOrder order, uint8_t *bits, LedColorConverter *converter) { | ||
| switch (order) { | ||
| case LED_COLOR_GRB: | ||
| *bits = 24; | ||
| *converter = color_grb; | ||
| return true; | ||
| case LED_COLOR_GRBW: | ||
| *bits = 32; | ||
| *converter = color_grbw; | ||
| return true; | ||
| case LED_COLOR_RGB: | ||
| *bits = 24; | ||
| *converter = color_rgb; | ||
| return true; | ||
| case LED_COLOR_WRGB: | ||
| *bits = 32; | ||
| *converter = color_wrgb; | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright 2026 Michael Conrad | ||
| // | ||
| // This file is part of the Refloat VESC package. | ||
| // | ||
| // Refloat VESC package is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by the | ||
| // Free Software Foundation, either version 3 of the License, or (at your | ||
| // option) any later version. | ||
| // | ||
| // Refloat VESC package is distributed in the hope that it will be useful, but | ||
| // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| // more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License along with | ||
| // this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "conf/datatypes.h" | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| typedef uint32_t (*LedColorConverter)(uint8_t w, uint8_t r, uint8_t g, uint8_t b); | ||
|
|
||
| bool led_color_order_resolve(LedColorOrder order, uint8_t *bits, LedColorConverter *converter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 duplication is not good. It's about architecturally putting the code to the correct place. Looks like the whole color_order handling could be moved into the led_strip module, storing the bit number and the converter in the LedStrip struct. They are not really LedStrip related by nature, they should probably technically go into their own module (e.g. led_color_order.{c,h} or just make a directory for the led code at this stage). But I'd accept it if the functions were cleanly placed into led_strip.c too. More structural work and I don't really wanna spend the time iterating on this (so to be blunt if you can do it right please do, if not, let's not spend the time 😅 ).
A straightforward fix of the uninitialized pointer dereference would be to initialize it and early-return if it's NULL.