leds-class-multicolor.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====================================
  3. Multicolor LED handling under Linux
  4. ====================================
  5. Description
  6. ===========
  7. The multicolor class groups monochrome LEDs and allows controlling two
  8. aspects of the final combined color: hue and lightness. The former is
  9. controlled via the multi_intensity array file and the latter is controlled
  10. via brightness file.
  11. Multicolor Class Control
  12. ========================
  13. The multicolor class presents files that groups the colors as indexes in an
  14. array. These files are children under the LED parent node created by the
  15. led_class framework. The led_class framework is documented in led-class.rst
  16. within this documentation directory.
  17. Each colored LED will be indexed under the multi_* files. The order of the
  18. colors will be arbitrary. The multi_index file can be read to determine the
  19. color name to indexed value.
  20. The multi_index file is an array that contains the string list of the colors as
  21. they are defined in each multi_* array file.
  22. The multi_intensity is an array that can be read or written to for the
  23. individual color intensities. All elements within this array must be written in
  24. order for the color LED intensities to be updated.
  25. Directory Layout Example
  26. ========================
  27. root:/sys/class/leds/multicolor:status# ls -lR
  28. -rw-r--r-- 1 root root 4096 Oct 19 16:16 brightness
  29. -r--r--r-- 1 root root 4096 Oct 19 16:16 max_brightness
  30. -r--r--r-- 1 root root 4096 Oct 19 16:16 multi_index
  31. -rw-r--r-- 1 root root 4096 Oct 19 16:16 multi_intensity
  32. Multicolor Class Brightness Control
  33. ===================================
  34. The brightness level for each LED is calculated based on the color LED
  35. intensity setting divided by the global max_brightness setting multiplied by
  36. the requested brightness.
  37. led_brightness = brightness * multi_intensity/max_brightness
  38. Example:
  39. A user first writes the multi_intensity file with the brightness levels
  40. for each LED that are necessary to achieve a certain color output from a
  41. multicolor LED group.
  42. cat /sys/class/leds/multicolor:status/multi_index
  43. green blue red
  44. echo 43 226 138 > /sys/class/leds/multicolor:status/multi_intensity
  45. red -
  46. intensity = 138
  47. max_brightness = 255
  48. green -
  49. intensity = 43
  50. max_brightness = 255
  51. blue -
  52. intensity = 226
  53. max_brightness = 255
  54. The user can control the brightness of that multicolor LED group by writing the
  55. global 'brightness' control. Assuming a max_brightness of 255 the user
  56. may want to dim the LED color group to half. The user would write a value of
  57. 128 to the global brightness file then the values written to each LED will be
  58. adjusted base on this value.
  59. cat /sys/class/leds/multicolor:status/max_brightness
  60. 255
  61. echo 128 > /sys/class/leds/multicolor:status/brightness
  62. adjusted_red_value = 128 * 138/255 = 69
  63. adjusted_green_value = 128 * 43/255 = 21
  64. adjusted_blue_value = 128 * 226/255 = 113
  65. Reading the global brightness file will return the current brightness value of
  66. the color LED group.
  67. cat /sys/class/leds/multicolor:status/brightness
  68. 128