Skip to content
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

apa102: fix end frame #76533

Merged

Conversation

fouge
Copy link
Contributor

@fouge fouge commented Jul 31, 2024

end frame is used to supply clock pulses so that data goes to next led.
It depends on the number of LEDs in the chain.

Previously, the number of ones sent into the end frame was hard-coded and limited the usage of the driver to 64 LEDs in the strip.
This PR fixes that issues by computing the number of bits to send in the end frame

@fouge fouge requested a review from mbolivar-ampere as a code owner July 31, 2024 08:15
@zephyrbot zephyrbot added the area: LED Label to identify LED subsystem label Jul 31, 2024
@fouge fouge force-pushed the worldcoin/apa102-end-frame branch 2 times, most recently from 6954d01 to 3527c83 Compare July 31, 2024 08:44
thedjnK
thedjnK previously approved these changes Aug 5, 2024
soburi
soburi previously approved these changes Aug 5, 2024
Copy link
Collaborator

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fouge,

Thanks for this patch. Please see my comments below.

Additionally, can you please improve the commit description message ? The PR description message you wrote is more detailed and understandable. You could use it.

drivers/led_strip/apa102.c Outdated Show resolved Hide resolved
drivers/led_strip/apa102.c Outdated Show resolved Hide resolved
drivers/led_strip/apa102.c Outdated Show resolved Hide resolved
@simonguinot
Copy link
Collaborator

ping @fouge :)

Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@fouge
Copy link
Contributor Author

fouge commented Nov 6, 2024

@simonguinot sorry for the very late reply, & thank you for the review.
i addressed all your comments.

@fouge fouge force-pushed the worldcoin/apa102-end-frame branch 3 times, most recently from 6d68ba3 to 9c628d8 Compare November 6, 2024 13:05
@simonguinot
Copy link
Collaborator

simonguinot commented Nov 7, 2024

@simonguinot sorry for the very late reply, & thank you for the review. i addressed all your comments.

No problem @fouge. Thanks for the update. It looks good. Please see above for one last question.

@simonguinot simonguinot self-requested a review November 8, 2024 09:15
simonguinot
simonguinot previously approved these changes Nov 8, 2024
Copy link
Collaborator

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fouge for this bug fix !

@simonguinot
Copy link
Collaborator

@thedjnK @soburi Please have a look

@fouge fouge requested review from thedjnK and soburi November 8, 2024 16:05
Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment on the allocation. Also the commit message can be 72 columns long, no need to make it look like a haiku :-)

* number of clock pulses required is exactly half the total number
* of LEDs in the string
*/
uint8_t ones[((size / sizeof(struct led_rgb)) / 2) + 1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it is really a good idea to allocate a dynamically sized array on the stack, especially since it's just filled with 0xff, this could waste an awful lot of RAM on a long strip.

How about allocating an 0xff array statically up to a certain configurable size? The drawback is then that the maximum strip length would have to be configured at build time but imo that's way better than changing this as potentially blowing up the stack

Copy link
Collaborator

@simonguinot simonguinot Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fabiobaltieri. Thanks for spotting this.

@fouge Please can you statically initialize the ones array (with the half the strip length) and pass it via the dev->data pointer ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointers can and should go in the config structure btw, even pointers of non constant data, the pointer itself is going to be constant

SRAM is expensive :-)

Copy link
Collaborator

@simonguinot simonguinot Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiobaltieri Thanks again. It is confusing and counterintuitive to not put a data buffer in the data structure but in the config structure because the pointer is constant. I think we have made this mistake in the lp50xx and tlc5971 LED and strip drivers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I haven't done it myself. :-)

Copy link
Contributor Author

@fouge fouge Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonguinot @fabiobaltieri I like that approach a lot

I could make the array const with some macro that are available with GNU extension
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html#Designated-Initializers

uint8_t apa102_end_frame_##idx[] = { [0 ... LENGTH] = 0xFF };

not sure we want a specific implementation for GNU though, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't risk it, the project as a whole aims to be compatible with other compilers that we don't have access to in CI, not a fan of that myself but that's unfortunately something we have to deal with

@simonguinot simonguinot self-requested a review November 25, 2024 22:11
@fouge fouge force-pushed the worldcoin/apa102-end-frame branch from fe60f34 to 2e3f7a0 Compare January 9, 2025 17:35
@fouge fouge force-pushed the worldcoin/apa102-end-frame branch 2 times, most recently from 8faaa30 to d4e8f07 Compare January 10, 2025 08:42
end frame is used to supply clock pulses so that data goes to last
LED in the chain. Thus, it depends on the number of LEDs in the chain.
Previously, the number of ones sent into the end frame was
hard-coded and limited the usage of the driver to 64 LEDs in the
strip.

Signed-off-by: Cyril Fougeray <cyril.fougeray@toolsforhumanity.com>
@fouge fouge force-pushed the worldcoin/apa102-end-frame branch from d4e8f07 to d690b3e Compare January 10, 2025 08:51
@fouge fouge requested a review from fabiobaltieri January 10, 2025 08:58
Copy link
Collaborator

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done !

@kartben kartben merged commit 89594e3 into zephyrproject-rtos:main Jan 14, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: LED Label to identify LED subsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants