-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/ws281x: Add saul support #20562
Conversation
I haven't tested yet but will do it tomorrow then make it a real PR |
247dddb
to
87f75a5
Compare
There were a few bumps along the way... Since we have a whole bunch of backends in submodules we could not use the Also, it seems there were some issues with the dep modelling, since xtimer is used in the header it should be mandatory for all backends... I didn't see this until I added the I also accounted for the amount of LEDs a bit better... SAUL will only apply color to all LEDs and individual LEDs are not exposed. |
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.
Thx :)
IMHO this is not scary and could be merged during soft feature freeze. But let's give @teufelchen a chance to veto.
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.
Approve, just a nit pick.
Oh and murdock spotted a little type issue!
I also don't mind waiting until the head freeze... Not so critical, just nice. |
Please squash at will. |
361455a
to
8a15b8c
Compare
}; | ||
for (unsigned idx = 0; idx < ws281x->params.numof; idx++) { | ||
puts("Setting LED"); | ||
ws281x_set(ws281x, idx, color); |
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.
Just from a perspective of practicality: Would it make sense to set the idx
as an additional vector component (or address each LED as their own SAUL device)? It seems to me very restrictive that only one color can be set for a whole LED strip using SAUL.
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 think an extra vector component would be weird; strand-as-a-whole is at least consistent with the data types and write mode.
A per-LED mode would make sense, possibly also a group-of-LEDs mode – but maybe that can grow from this as a starting point?
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 maybe that can grow from this as a starting point?
Fine by me, just wanted to give a possible discussion starter.
Maybe we should even distinguish from a single RGB LED and a LED strip in SAUL type. In any way it should be clarified (in the documentation) and unify that at the moment SAUL_ACT_LED_RGB
sets just everything in the SAUL device to one color. Currently, it seems to be used for PWM-based RGB LEDs (where it is used to set the color of a single LED associated to a single PWM device) and by the Grove LED bar, that currently just seems to set the red compontent.
Lines 102 to 123 in 680c5aa
static int write_rgb(const void *dev, const phydat_t *state) | |
{ | |
const saul_pwm_rgb_params_t *p = dev; | |
int factor, shiftback, max; | |
int err = extract_scaling(state, &factor, &shiftback, &max); | |
if (err < 0) { | |
return err; | |
} | |
for (int i = 0; i < 3; ++i) { | |
if (state->val[i] < 0 || state->val[i] > max) { | |
return -ECANCELED; | |
} | |
} | |
for (int i = 0; i < 3; ++i) { | |
setchan(&p->channels[i], (state->val[i] * factor) >> shiftback); | |
} | |
return 3; | |
} |
RIOT/drivers/grove_ledbar/grove_ledbar_saul.c
Lines 27 to 32 in 680c5aa
static int set_ledbar(const void *dev, const phydat_t *res) | |
{ | |
uint8_t lvl = (uint8_t)res->val[0]; | |
grove_ledbar_set((grove_ledbar_t *)dev, lvl); | |
return 1; | |
} |
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.
And a good starter it is indeed.
I don't think the SAUL type is the right place, [edit, added:] if visible the distinction belongs in the descriptive text. Single LED, LED strip or group of LEDs are just what RIOT sees, and may not correspond to the physical reality. (For example, on a PWM port there could be a strip of non-addressable LEDs, or all the many LEDs of a WS281x may be hidden behind a larger diffusor).
It is weird that in the Grove bar it uses one component -- anything monochromatic should be SAUL_ACT_DIMMER (and read one channel), and anything RGBish should be SAUL_ACT_LED_RGB and read the 3 components. (And I do not yet know how to best work with RGBW or RGBA LEDs in SAUL, but one step at a time).
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.
Can we say this is for a different PR? This issues is already documented in the PR description.
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 think yes.
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!
Build tests are blocked by the previously 3-year-dormant ws281x module coming back to life, as in this build failure -- apparently there was one of the non-inline-to-inline API changes that are nonbreaking for C but breaking for Rust. Looking into a quick fix. |
This pulls in [88], and thus fixes building of Rust modules when the wS281x module is enabled. [88]: RIOT-OS/rust-riot-wrappers#88
I have pushed a commit that updates the riot-wrappers version to include RIOT-OS/rust-riot-wrappers#88 which fixes building when combining WS281x and Rust. |
Contribution description
Support the ws281x driver on saul... starting with 🥁 the
feather-nrf52840-sense
.Note that this only allows control of all LEDs at once since saul does not really have a way to handle subindex or array control (for example LED array). For our use case we would like to keep it simple now but if we did want to allow saul to control individual LEDs in the future here are some considerations:
saul_entries
would be of sizeWS281X_NUM * WS281X_PARAM_NUMOF
and one could iterate over this matrix, though there would still be no mechanism to address each one...ws281x_t
should change to be for each LED and not an array (likely a bit of rework) but then eachdev
could be for each LEDAll of this is out of scope of this PR, but if people need individual control with saul, these issues must be considered.
Testing procedure
Play around with:
Issues/PRs references