This is an automated email from the ASF dual-hosted git repository.

michallenc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 9eb6969843f boards/thingy91: add rgb led support
9eb6969843f is described below

commit 9eb6969843f3c371a3e527ad34b961dfb931d260
Author: raiden00pl <[email protected]>
AuthorDate: Thu Jun 11 11:35:42 2026 +0200

    boards/thingy91: add rgb led support
    
    add rgb led support for thingy91
    
    Signed-off-by: raiden00pl <[email protected]>
---
 boards/arm/nrf91/thingy91/include/board.h     |  25 +++++
 boards/arm/nrf91/thingy91/src/CMakeLists.txt  |   4 +
 boards/arm/nrf91/thingy91/src/Make.defs       |   4 +
 boards/arm/nrf91/thingy91/src/nrf91_bringup.c |  13 +++
 boards/arm/nrf91/thingy91/src/nrf91_rgbled.c  | 144 ++++++++++++++++++++++++++
 boards/arm/nrf91/thingy91/src/thingy91.h      |  13 +++
 6 files changed, 203 insertions(+)

diff --git a/boards/arm/nrf91/thingy91/include/board.h 
b/boards/arm/nrf91/thingy91/include/board.h
index 96552283855..582d442d1cf 100644
--- a/boards/arm/nrf91/thingy91/include/board.h
+++ b/boards/arm/nrf91/thingy91/include/board.h
@@ -83,4 +83,29 @@
 #define BOARD_I2C2_SCL_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(12))
 #define BOARD_I2C2_SDA_PIN (GPIO_INPUT  | GPIO_PORT0 | GPIO_PIN(11))
 
+/* PWM Pins *****************************************************************/
+
+/* The Thingy:91 has two RGB LEDs, both on the 3.3 V rail controlled by the
+ * ADP5360 PMIC:
+ *
+ * PWM0 drives the "lightwell" RGB LED (large LED in the enclosure light
+ * pipe):
+ *   RED   - P0.29
+ *   GREEN - P0.30
+ *   BLUE  - P0.31
+ *
+ * PWM1 drives the "sense" RGB LED (next to the environmental/light sensors):
+ *   RED   - P0.00
+ *   GREEN - P0.01
+ *   BLUE  - P0.02
+ */
+
+#define NRF91_PWM0_CH0_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(29))
+#define NRF91_PWM0_CH1_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(30))
+#define NRF91_PWM0_CH2_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(31))
+
+#define NRF91_PWM1_CH0_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(0))
+#define NRF91_PWM1_CH1_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(1))
+#define NRF91_PWM1_CH2_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | 
GPIO_PIN(2))
+
 #endif /* __BOARDS_ARM_NRF91_THINGY91_INCLUDE_BOARD_H */
diff --git a/boards/arm/nrf91/thingy91/src/CMakeLists.txt 
b/boards/arm/nrf91/thingy91/src/CMakeLists.txt
index b3ec909aaf5..18a93f7c21b 100644
--- a/boards/arm/nrf91/thingy91/src/CMakeLists.txt
+++ b/boards/arm/nrf91/thingy91/src/CMakeLists.txt
@@ -38,6 +38,10 @@ if(CONFIG_NRF91_MODEM)
   list(APPEND SRCS nrf91_modem.c)
 endif()
 
+if(CONFIG_RGBLED)
+  list(APPEND SRCS nrf91_rgbled.c)
+endif()
+
 target_sources(board PRIVATE ${SRCS})
 
 if(CONFIG_ARCH_BOARD_COMMON)
diff --git a/boards/arm/nrf91/thingy91/src/Make.defs 
b/boards/arm/nrf91/thingy91/src/Make.defs
index d68245956ef..be080aace4c 100644
--- a/boards/arm/nrf91/thingy91/src/Make.defs
+++ b/boards/arm/nrf91/thingy91/src/Make.defs
@@ -40,6 +40,10 @@ ifeq ($(CONFIG_I2C),y)
 CSRCS += nrf91_i2c.c
 endif
 
+ifeq ($(CONFIG_RGBLED),y)
+CSRCS += nrf91_rgbled.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
diff --git a/boards/arm/nrf91/thingy91/src/nrf91_bringup.c 
b/boards/arm/nrf91/thingy91/src/nrf91_bringup.c
index 4d52425598d..aa09d56781b 100644
--- a/boards/arm/nrf91/thingy91/src/nrf91_bringup.c
+++ b/boards/arm/nrf91/thingy91/src/nrf91_bringup.c
@@ -164,6 +164,19 @@ int nrf91_bringup(void)
     }
 #endif /* CONFIG_MTD */
 
+#ifdef CONFIG_RGBLED
+  /* Register the RGB LED (PWM0). Note: the LED is on the 3.3 V rail, which
+   * is controlled by the ADP5360 PMIC and must be enabled for the LED
+   * to light.
+   */
+
+  ret = nrf91_rgbled_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize RGB LED: %d\n", ret);
+    }
+#endif
+
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/nrf91/thingy91/src/nrf91_rgbled.c 
b/boards/arm/nrf91/thingy91/src/nrf91_rgbled.c
new file mode 100644
index 00000000000..9715b8c73be
--- /dev/null
+++ b/boards/arm/nrf91/thingy91/src/nrf91_rgbled.c
@@ -0,0 +1,144 @@
+/****************************************************************************
+ * boards/arm/nrf91/thingy91/src/nrf91_rgbled.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+#include <arch/board/board.h>
+
+#include "nrf91_pwm.h"
+#include "thingy91.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf91_rgbled_register
+ *
+ * Description:
+ *   Bring up one PWM instance (channels 0-2) and register it as an RGB LED
+ *   device at 'path'.
+ *
+ ****************************************************************************/
+
+static int nrf91_rgbled_register(int pwm, const char *path)
+{
+  struct pwm_lowerhalf_s *led = NULL;
+  struct pwm_info_s       info;
+  int                     ret;
+
+  led = nrf91_pwminitialize(pwm);
+  if (!led)
+    {
+      lederr("ERROR: Failed to get PWM%d lower half\n", pwm);
+      return -ENODEV;
+    }
+
+  /* A single PWM instance drives all three colour channels */
+
+  memset(&info, 0, sizeof(info));
+  info.frequency = 100;
+  info.channels[0].duty = 0;
+  info.channels[0].channel = 1;
+  info.channels[1].duty = 0;
+  info.channels[1].channel = 2;
+  info.channels[2].duty = 0;
+  info.channels[2].channel = 3;
+
+  led->ops->setup(led);
+  led->ops->start(led, &info);
+
+  ret = rgbled_register(path, led, led, led, 1, 2, 3);
+  if (ret < 0)
+    {
+      lederr("ERROR: rgbled_register(%s) failed: %d\n", path, ret);
+      return ret;
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf91_rgbled_initialize
+ *
+ * Description:
+ *   Register the on-board RGB LEDs: the lightwell LED (PWM0, P0.29/30/31) as
+ *   /dev/rgbled0 and, when PWM1 is enabled, the sense LED (PWM1, P0.0/1/2)
+ *   as /dev/rgbled1.
+ *
+ ****************************************************************************/
+
+int nrf91_rgbled_initialize(void)
+{
+  static bool initialized = false;
+  int         ret;
+
+  if (initialized)
+    {
+      return OK;
+    }
+
+  /* The Thingy:91 has two RGB LEDs, each driven by one PWM instance using
+   * its channels 0-2: PWM0 -> lightwell LED (/dev/rgbled0),
+   * PWM1 -> sense LED (/dev/rgbled1).
+   */
+
+#if defined(CONFIG_NRF91_PWM0_CH0) && defined(CONFIG_NRF91_PWM0_CH1) && \
+    defined(CONFIG_NRF91_PWM0_CH2)
+  /* Lightwell RGB LED */
+
+  ret = nrf91_rgbled_register(0, "/dev/rgbled0");
+  if (ret < 0)
+    {
+      return ret;
+    }
+#endif
+
+#if defined(CONFIG_NRF91_PWM1_CH0) && defined(CONFIG_NRF91_PWM1_CH1) && \
+    defined(CONFIG_NRF91_PWM1_CH2)
+  /* Sense RGB LED */
+
+  ret = nrf91_rgbled_register(1, "/dev/rgbled1");
+  if (ret < 0)
+    {
+      return ret;
+    }
+#endif
+
+  initialized = true;
+  return OK;
+}
diff --git a/boards/arm/nrf91/thingy91/src/thingy91.h 
b/boards/arm/nrf91/thingy91/src/thingy91.h
index 26cef5ca962..50b8d605ce5 100644
--- a/boards/arm/nrf91/thingy91/src/thingy91.h
+++ b/boards/arm/nrf91/thingy91/src/thingy91.h
@@ -170,5 +170,18 @@ int nrf91_i2ctool(void);
 void nrf91_spidev_initialize(void);
 #endif
 
+/****************************************************************************
+ * Name: nrf91_rgbled_initialize
+ *
+ * Description:
+ *   Register the on-board RGB LED (PWM0 channels 0-2, P0.29/30/31) as
+ *   /dev/rgbled0.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RGBLED
+int nrf91_rgbled_initialize(void);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_ARM_NRF91_THINGY91_SRC_THINGY91_H */

Reply via email to