3 ms·
A driver for controlling RGB LEDs using PWM, with gamma correction
- zwirbl 2y agoInteresting that this lands in the front page. Imo this really shows off the strength of embedded HAL traits when using rust for embedded
- amluto 2y agoI don’t get it. This wraps three PWM-controllable things in a struct, forcing a specific ownership model. On top of this, it seems to implement a single function to set an 8-bit sRGB color (maybe? the origin of the table is not documented at all!), and that function produces an outrageously quantized 16-bit duty cycle, with the maximum arbitrarily set to 255^2 (why?!?), and sets this value as a raw duty cycle to the underlying output. And ignores errors. Never mind that SetDutyCycle is actually supposed to be scaled to max_duty_cycle(). I would sort of understand a helper to set a color component, through a gamma curve, into a SetDutyCycle implementation, but even that seems a bit weird — sRGB is usually used for images, and you’d probably want some dithering. But even if the goal is just to use an online color picker to pick and LED color, you’d probably want to convert to a linear scale at compile time and you would absolutely want to use all available precision, which would involve doing actual math instead of using a table.
- tracyspacy 2y agoHey, first of all, thanks for having a look. Honestly, I never thought it would grab any attention, but your feedback is definitely valid. This small driver was something I quickly put together as a simple prototype, borrowing parts from Pimoroni’s C++ driver https://github.com/pimoroni/pimoroni-pico/tree/main/drivers/rgbled https://github.com/pimoroni/pimoroni-pico/tree/main/drivers/... (you probably find some answers here). I initially needed it as part of a Pimoroni GFX PACK driver concept I was working on. Now that it’s got some attention, it seems worth spending more time improving it.