Skip to content

Commit 8060a59

Browse files
committed
leds: add arduino,modulino-buttons-leds
Add an LED driver for the modulino buttons module, this has three LEDs that are controllable independently of the buttons. Link: https://github.com/arduino/node_modulino_firmware Link: https://github.com/arduino-libraries/Modulino Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 82509f7 commit 8060a59

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

drivers/led/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ zephyr_library_sources_ifdef(CONFIG_LP3943 lp3943.c)
1919
zephyr_library_sources_ifdef(CONFIG_LP50XX lp50xx.c)
2020
zephyr_library_sources_ifdef(CONFIG_LP5562 lp5562.c)
2121
zephyr_library_sources_ifdef(CONFIG_LP5569 lp5569.c)
22+
zephyr_library_sources_ifdef(CONFIG_MODULINO_BUTTONS_LEDS modulino_buttons_leds.c)
2223
zephyr_library_sources_ifdef(CONFIG_NCP5623 ncp5623.c)
2324
zephyr_library_sources_ifdef(CONFIG_PCA9633 pca9633.c)
2425
zephyr_library_sources_ifdef(CONFIG_TLC59108 tlc59108.c)

drivers/led/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ source "drivers/led/Kconfig.lp3943"
3838
source "drivers/led/Kconfig.lp50xx"
3939
source "drivers/led/Kconfig.lp5562"
4040
source "drivers/led/Kconfig.lp5569"
41+
source "drivers/led/Kconfig.modulino"
4142
source "drivers/led/Kconfig.ncp5623"
4243
source "drivers/led/Kconfig.npm1300"
4344
source "drivers/led/Kconfig.pca9633"

drivers/led/Kconfig.modulino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 Google, LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config MODULINO_BUTTONS_LEDS
5+
bool "Arduino Modulino buttons LEDs"
6+
default y
7+
depends on DT_HAS_ARDUINO_MODULINO_BUTTONS_LEDS_ENABLED
8+
select I2C
9+
help
10+
Enable driver Arduino Modulino Buttons LEDs.

drivers/led/modulino_buttons_leds.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT arduino_modulino_buttons_leds
8+
9+
#include <zephyr/device.h>
10+
#include <zephyr/drivers/i2c.h>
11+
#include <zephyr/drivers/led.h>
12+
#include <zephyr/kernel.h>
13+
#include <zephyr/logging/log.h>
14+
15+
LOG_MODULE_REGISTER(modulino_buttons_leds, CONFIG_LED_LOG_LEVEL);
16+
17+
#define MODULINO_BUTTONS_NUM_LEDS 3
18+
19+
struct modulino_buttons_leds_config {
20+
struct i2c_dt_spec bus;
21+
};
22+
23+
struct modulino_buttons_leds_data {
24+
uint8_t buf[MODULINO_BUTTONS_NUM_LEDS];
25+
};
26+
27+
static int modulino_buttons_leds_set(const struct device *dev,
28+
uint32_t led, bool value)
29+
{
30+
const struct modulino_buttons_leds_config *cfg = dev->config;
31+
struct modulino_buttons_leds_data *data = dev->data;
32+
int ret;
33+
34+
if (led >= MODULINO_BUTTONS_NUM_LEDS) {
35+
return -EINVAL;
36+
}
37+
38+
data->buf[led] = value ? 1 : 0;
39+
40+
ret = i2c_write_dt(&cfg->bus, data->buf, sizeof(data->buf));
41+
if (ret < 0) {
42+
LOG_ERR("i2c write error: %d", ret);
43+
return ret;
44+
}
45+
46+
return 0;
47+
}
48+
49+
static int modulino_buttons_leds_on(const struct device *dev, uint32_t led)
50+
{
51+
return modulino_buttons_leds_set(dev, led, true);
52+
}
53+
54+
static int modulino_buttons_leds_off(const struct device *dev, uint32_t led)
55+
{
56+
return modulino_buttons_leds_set(dev, led, false);
57+
}
58+
59+
static int modulino_buttons_leds_set_brightness(const struct device *dev,
60+
uint32_t led, uint8_t value)
61+
{
62+
return modulino_buttons_leds_set(dev, led, value > 0);
63+
}
64+
65+
static int modulino_buttons_leds_init(const struct device *dev)
66+
{
67+
const struct modulino_buttons_leds_config *cfg = dev->config;
68+
struct modulino_buttons_leds_data *data = dev->data;
69+
int ret;
70+
71+
if (!i2c_is_ready_dt(&cfg->bus)) {
72+
LOG_ERR("Bus device is not ready");
73+
return -ENODEV;
74+
}
75+
76+
/* Reset to all LEDs off */
77+
ret = i2c_write_dt(&cfg->bus, data->buf, sizeof(data->buf));
78+
if (ret < 0) {
79+
LOG_ERR("i2c write error: %d", ret);
80+
return ret;
81+
}
82+
83+
return 0;
84+
}
85+
86+
static DEVICE_API(led, modulino_buttons_leds_api) = {
87+
.on = modulino_buttons_leds_on,
88+
.off = modulino_buttons_leds_off,
89+
.set_brightness = modulino_buttons_leds_set_brightness,
90+
};
91+
92+
#define MODULINO_BUTTONS_INIT(inst) \
93+
static const struct modulino_buttons_leds_config \
94+
modulino_buttons_leds_cfg_##inst = { \
95+
.bus = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
96+
}; \
97+
\
98+
static struct modulino_buttons_leds_data modulino_buttons_leds_data_##inst; \
99+
\
100+
DEVICE_DT_INST_DEFINE(inst, modulino_buttons_leds_init, NULL, \
101+
&modulino_buttons_leds_data_##inst, \
102+
&modulino_buttons_leds_cfg_##inst, \
103+
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
104+
&modulino_buttons_leds_api);
105+
106+
107+
DT_INST_FOREACH_STATUS_OKAY(MODULINO_BUTTONS_INIT)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Google, LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Arduino Modulino buttons LEDs
5+
6+
compatible: "arduino,modulino-buttons-leds"

0 commit comments

Comments
 (0)