logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

snled27351.md (8286B)


  1. # SNLED27351 Driver {#snled27351-driver}
  2. I²C 16x12 LED matrix driver by Sonix. Supports a maximum of four drivers, each controlling up to 192 single-color LEDs, or 64 RGB LEDs.
  3. A slightly modified version of this IC is also known as "CKLED2001".
  4. [SNLED27351 Datasheet](https://www.sonix.com.tw/files/1/D235860C0C037C28E050007F01001CBE)
  5. ## Usage {#usage}
  6. The SNLED27351 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `snled27351` driver set, and you would use those APIs instead.
  7. However, if you need to use the driver standalone, add this to your `rules.mk`:
  8. ```make
  9. COMMON_VPATH += $(DRIVER_PATH)/led
  10. SRC += snled27351-mono.c # For single-color
  11. SRC += snled27351.c # For RGB
  12. I2C_DRIVER_REQUIRED = yes
  13. ```
  14. ## Basic Configuration {#basic-configuration}
  15. Add the following to your `config.h`:
  16. |Define |Default |Description |
  17. |----------------------------|-------------|----------------------------------------------------|
  18. |`SNLED27351_SDB_PIN` |*Not defined*|The GPIO pin connected to the drivers' shutdown pins|
  19. |`SNLED27351_I2C_TIMEOUT` |`100` |The I²C timeout in milliseconds |
  20. |`SNLED27351_I2C_PERSISTENCE`|`0` |The number of times to retry I²C transmissions |
  21. |`SNLED27351_I2C_ADDRESS_1` |*Not defined*|The I²C address of driver 0 |
  22. |`SNLED27351_I2C_ADDRESS_2` |*Not defined*|The I²C address of driver 1 |
  23. |`SNLED27351_I2C_ADDRESS_3` |*Not defined*|The I²C address of driver 2 |
  24. |`SNLED27351_I2C_ADDRESS_4` |*Not defined*|The I²C address of driver 3 |
  25. ### I²C Addressing {#i2c-addressing}
  26. The SNLED27351 has four possible 7-bit I²C addresses, depending on how the `ADDR` pin is connected.
  27. To configure this, set the `SNLED27351_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:
  28. |Define |Value |
  29. |------------------------------|------|
  30. |`SNLED27351_I2C_ADDRESS_GND` |`0x74`|
  31. |`SNLED27351_I2C_ADDRESS_SCL` |`0x75`|
  32. |`SNLED27351_I2C_ADDRESS_SDA` |`0x76`|
  33. |`SNLED27351_I2C_ADDRESS_VDDIO`|`0x77`|
  34. ## ARM/ChibiOS Configuration {#arm-configuration}
  35. Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.
  36. ## LED Mapping {#led-mapping}
  37. In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
  38. ```c
  39. const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
  40. /* Driver
  41. * | R G B */
  42. {0, CB1_CA1, CB1_CA2, CB1_CA3},
  43. // etc...
  44. };
  45. ```
  46. In this example, the red, green and blue channels for the first LED index on driver 0 all have their cathodes connected to the `CB1` pin, and their anodes on the `CA1`, `CA2` and `CA3` pins respectively.
  47. For the single-color driver, the principle is the same, but there is only one channel:
  48. ```c
  49. const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
  50. /* Driver
  51. * | V */
  52. {0, CB1_CA1},
  53. // etc...
  54. };
  55. ```
  56. These values correspond to the register indices as shown in the datasheet on page 13.
  57. ## API {#api}
  58. ### `struct snled27351_led_t` {#api-snled27351-led-t}
  59. Contains the PWM register addresses for a single RGB LED.
  60. #### Members {#api-snled27351-led-t-members}
  61. - `uint8_t driver`
  62. The driver index of the LED, from 0 to 3.
  63. - `uint8_t r`
  64. The output PWM register address for the LED's red channel (RGB driver only).
  65. - `uint8_t g`
  66. The output PWM register address for the LED's green channel (RGB driver only).
  67. - `uint8_t b`
  68. The output PWM register address for the LED's blue channel (RGB driver only).
  69. - `uint8_t v`
  70. The output PWM register address for the LED (single-color driver only).
  71. ---
  72. ### `void snled27351_init(uint8_t index)` {#api-snled27351-init}
  73. Initialize the LED driver. This function should be called first.
  74. #### Arguments {#api-snled27351-init-arguments}
  75. - `uint8_t index`
  76. The driver index.
  77. ---
  78. ### `void snled27351_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-snled27351-write-register}
  79. Set the value of the given register.
  80. #### Arguments {#api-snled27351-write-register-arguments}
  81. - `uint8_t index`
  82. The driver index.
  83. - `uint8_t reg`
  84. The register address.
  85. - `uint8_t data`
  86. The value to set.
  87. ---
  88. ### `void snled27351_select_page(uint8_t index, uint8_t page)` {#api-snled27351-select-page}
  89. Change the current page for configuring the LED driver.
  90. #### Arguments {#api-snled27351-select-page-arguments}
  91. - `uint8_t index`
  92. The driver index.
  93. - `uint8_t page`
  94. The page number to select.
  95. ---
  96. ### `void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-snled27351-set-color}
  97. Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `snled27351_update_pwm_buffers()` after you are finished.
  98. #### Arguments {#api-snled27351-set-color-arguments}
  99. - `int index`
  100. The LED index (ie. the index into the `g_snled27351_leds` array).
  101. - `uint8_t red`
  102. The red value to set.
  103. - `uint8_t green`
  104. The green value to set.
  105. - `uint8_t blue`
  106. The blue value to set.
  107. ---
  108. ### `void snled27351_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-snled27351-set-color-all}
  109. Set the color of all LEDs (RGB driver only).
  110. #### Arguments {#api-snled27351-set-color-all-arguments}
  111. - `uint8_t red`
  112. The red value to set.
  113. - `uint8_t green`
  114. The green value to set.
  115. - `uint8_t blue`
  116. The blue value to set.
  117. ---
  118. ### `void snled27351_set_value(int index, uint8_t value)` {#api-snled27351-set-value}
  119. Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `snled27351_update_pwm_buffers()` after you are finished.
  120. #### Arguments {#api-snled27351-set-value-arguments}
  121. - `int index`
  122. The LED index (ie. the index into the `g_snled27351_leds` array).
  123. - `uint8_t value`
  124. The brightness value to set.
  125. ---
  126. ### `void snled27351_set_value_all(uint8_t value)` {#api-snled27351-set-value-all}
  127. Set the brightness of all LEDs (single-color driver only).
  128. #### Arguments {#api-snled27351-set-value-all-arguments}
  129. - `uint8_t value`
  130. The brightness value to set.
  131. ---
  132. ### `void snled27351_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-snled27351-set-led-control-register-rgb}
  133. Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `snled27351_update_led_control_registers()` after you are finished.
  134. #### Arguments {#api-snled27351-set-led-control-register-rgb-arguments}
  135. - `uint8_t index`
  136. The LED index (ie. the index into the `g_snled27351_leds` array).
  137. - `bool red`
  138. Enable or disable the red channel.
  139. - `bool green`
  140. Enable or disable the green channel.
  141. - `bool blue`
  142. Enable or disable the blue channel.
  143. ---
  144. ### `void snled27351_set_led_control_register(uint8_t index, bool value)` {#api-snled27351-set-led-control-register-mono}
  145. Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `snled27351_update_led_control_registers()` after you are finished.
  146. #### Arguments {#api-snled27351-set-led-control-register-mono-arguments}
  147. - `uint8_t index`
  148. The LED index (ie. the index into the `g_snled27351_leds` array).
  149. - `bool value`
  150. Enable or disable the LED.
  151. ---
  152. ### `void snled27351_update_pwm_buffers(uint8_t index)` {#api-snled27351-update-pwm-buffers}
  153. Flush the PWM values to the LED driver.
  154. #### Arguments {#api-snled27351-update-pwm-buffers-arguments}
  155. - `uint8_t index`
  156. The driver index.
  157. ---
  158. ### `void snled27351_update_led_control_registers(uint8_t index)` {#api-snled27351-update-led-control-registers}
  159. Flush the LED control register values to the LED driver.
  160. #### Arguments {#api-snled27351-update-led-control-registers-arguments}
  161. - `uint8_t index`
  162. The driver index.