drivers icon indicating copy to clipboard operation
drivers copied to clipboard

Allow for backlight dimming on supported displays

Open ysmilda opened this issue 2 months ago • 6 comments

The backlight on most LCD screens (including the one on the Gopherbadge) is based on some form of LED control. The current support for this in the tinygo drivers is limited to turning the backlight on and off which is implemented for three screens in the repo.

When the pin connected to the backlight also has a PWM peripheral connected to it we could expand this functionality. My proposal would be to extend the API for these screens to allow for passing in a PWM interface similar to the tone driver and use that to set the display backlight to a certain value/percentage.

From my experiments of enabling this on the users side we would need the following interface for the PWM:

type PWM interface {
	Configure(config machine.PWMConfig) error
	Channel(pin machine.Pin) (channel uint8, err error)
	Top() uint32
	Set(channel uint8, value uint32)
}

Adding this to the existing API is a bit more difficult as I'm not sure what the guidelines are on breaking changes. One thing that could be done would be to have a separate initialisation call in the lines of NewWithBacklightDimming and make the functions that handle the backlight a noop when the PWM interface has not been set. Optional names for these functions could be SetBacklight(percentage int8) or DimBacklight(percentage int8).

I'm not quite happy yet with how the above solution integrates with the current implementation. But I do think that this can add a valuable way to interact with these screens for users.

ysmilda avatar Jun 20 '24 09:06 ysmilda