Skip to content

Commit d5eda10

Browse files
Joshua LangeAlan C. Assis
authored andcommitted
drivers/leds: Add support for KTD2052
This commit adds support for the KTD2052 LED driver chip. Signed-off-by: Tyler Bennett <[email protected]>
1 parent e5b138d commit d5eda10

File tree

6 files changed

+1032
-0
lines changed

6 files changed

+1032
-0
lines changed

Documentation/components/drivers/character/leds/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ LEDS
77

88
userled.rst
99
ws2812.rst
10+
ktd2052.rst
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
=======
2+
KTD2052
3+
=======
4+
5+
This is a driver for the Kinetic Technologies KTD2052, a 4-module (12-channel)
6+
RGB LED driver with an I2C interface. This driver exposes the KTD2052's
7+
functionality as a standard NuttX character device.
8+
9+
Driver Configuration
10+
====================
11+
12+
This driver depends on I2C being enabled and configured for your board.
13+
To use the driver, enable the following option in menuconfig:
14+
15+
- ``Device Drivers -> LED Support -> KTD2052 I2C LED Driver``
16+
(``CONFIG_KTD2052``)
17+
18+
Driver Usage
19+
============
20+
21+
The driver is registered as a character device, typically at a path like
22+
``/dev/leds0``.
23+
24+
Initialization
25+
--------------
26+
27+
To use the driver, board-specific logic must call ``ktd2052_register``
28+
during the board initialization sequence. This function takes the device path,
29+
an I2C master instance, the I2C address of the device, and the I2C frequency.
30+
31+
.. code-block:: c
32+
33+
#include <nuttx/leds/ktd2052.h>
34+
35+
/* In your board's initialization logic */
36+
FAR struct i2c_master_s *i2c; /* I2C bus instance */
37+
/* ... */
38+
ktd2052_register("/dev/leds0", i2c, 0x74, 400000);
39+
40+
41+
Application Interface
42+
---------------------
43+
44+
An application can interact with the device by opening the device path and
45+
using standard ``read()``, ``write()``, and ``ioctl()`` calls. The device will
46+
automatically be taken out of shutdown mode as soon as it is opened.
47+
48+
**write()**
49+
50+
The ``write()`` call provides a simple way to set the raw current
51+
values for one or more connected RGB modules. The buffer should contain a
52+
sequence of Red, Green, and Blue current values for each module, starting with
53+
module 1. The device's output current is linear between values of 0 (no current)
54+
and 192 (full scale current). Setting a value above 192 will result in full
55+
scale current output. Full scale current is either 24mA in normal mode or 1.5mA
56+
in night mode. Writes to the device using the ``write()`` call will always start
57+
at module 1. The entire string can be updated by repeatedly calling ``write()``
58+
without needing to first seek back to 0. Partial writes are supported.
59+
60+
- **Buffer Format**: ``[R1, G1, B1, R2, G2, B2, R3, G3, B3, R4, G4, B4]``
61+
- **Buffer Length**: 1 to 12 bytes.
62+
63+
.. code-block:: c
64+
65+
/* Example: Set module 1 to red and module 2 to blue */
66+
uint8_t colors[6] = { 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0 };
67+
int fd = open("/dev/leds0", O_WRONLY);
68+
write(fd, colors, sizeof(colors));
69+
close(fd);
70+
71+
**read()**
72+
73+
The ``read()`` call retrieves status information from the device.
74+
75+
- Reading 1 byte returns the contents of the MONITOR Register.
76+
- Reading 2 bytes returns the MONITOR Register followed by the CONTROL Register.
77+
78+
The MONITOR register bits are defined in ``nuttx/leds/ktd2052.h``.
79+
80+
**ioctl()**
81+
82+
For more advanced control, the driver implements several ``ioctl`` commands,
83+
defined in ``nuttx/leds/ktd2052.h``.
84+
85+
- ``KTDIOSETRGB``
86+
Set the color for a single RGB module.
87+
88+
- **Argument**: A pointer to a ``uint8_t[4]`` array:
89+
``{module number [1-4], r, g, b}``.
90+
91+
- ``KTDIOSETMODE``
92+
Configure the operating mode of the device. See the CONTROL register in the
93+
device datasheet for additional information on available modes.
94+
95+
- **Argument**: A pointer to a ``struct ktd2052_mode_s``.
96+
97+
- ``KTDIOSETPATTERN``
98+
Configure the hardware pattern generator. See the device datasheet for
99+
additional information on using the hardware pattern generator.
100+
101+
- **Argument**: A pointer to a ``struct ktd2052_pattern_s``.
102+
103+
- ``KTDIOSETSLOTS``
104+
Configure which RGB modules are active in each pattern slot.
105+
106+
- **Argument**: A pointer to a ``struct ktd2052_slots_s``.
107+
108+
- ``KTDIOGETMONITOR``
109+
Read the MONITOR register.
110+
111+
- **Argument**: A pointer to a ``uint8_t`` to store the result.
112+
113+
- ``KTDIOSETWDOG``
114+
Feed the pattern generator watchdog timer.
115+
116+
- **Argument**: A ``uint8_t`` value for the watchdog cycle count to set.

drivers/leds/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ config LEDS_APA102
5757
---help---
5858
Enable support for the APA102 LED Strip driver.
5959

60+
config KTD2052
61+
bool "KTD2052 I2C LED Driver"
62+
default n
63+
select I2C
64+
---help---
65+
Enable support for the KTD2052 LED driver
66+
6067
config LEDS_MAX7219
6168
bool "MAX7219 Numeric Display"
6269
default n

drivers/leds/Make.defs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ ifeq ($(CONFIG_LEDS_APA102),y)
3737
LEDVPATH = :leds
3838
endif
3939

40+
ifeq ($(CONFIG_KTD2052),y)
41+
CSRCS += ktd2052.c
42+
LEDDEPATH = --dep-path leds
43+
LEDVPATH = :leds
44+
endif
45+
4046
ifeq ($(CONFIG_LEDS_MAX7219),y)
4147
CSRCS += max7219.c
4248
LEDDEPATH = --dep-path leds

0 commit comments

Comments
 (0)