You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "simonatoaca (via GitHub)" <gi...@apache.org> on 2023/07/05 10:25:18 UTC
[GitHub] [nuttx] simonatoaca opened a new pull request, #9707: esp32/common: RGB LED support
simonatoaca opened a new pull request, #9707:
URL: https://github.com/apache/nuttx/pull/9707
## Summary
Added RGB LED support for esp32, using the existing pwm code for esp32. The 3 leds are linked to the same timer (timer0) and pwm multichannel is enabled for controlling each led independently.
The code is based on the already existing implementation for stm32.
Testing was done on the esp32-sparrow board.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1252916466
##########
boards/xtensa/esp32/common/include/esp32_rgbled.h:
##########
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/include/esp32_rgbled.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_RGBLED_H
+#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_RGBLED_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define RGB_LED_TIMER TIMER0
+
+#define RGB_R_CHANN 0
+#define RGB_G_CHANN 1
+#define RGB_B_CHANN 2
+
+/****************************************************************************
+ * Type Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ *
+ *
+ * Input Parameters:
+ * devname - The name under which the RGB led will be registered
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_LTR308_H */
Review Comment:
```suggestion
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_LTR308_H */
```
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = write(fd, "#000000", 8);
Review Comment:
```suggestion
ret = nx_write(fd, "#000000", 8);
```
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = write(fd, "#000000", 8);
+
+ if (ret <= 0)
+ {
+ lederr("ERROR: rgbled_write failed: %d\n", ret);
+ close(fd);
+ return ret;
+ }
+
+ close(fd);
+
+ /* Now we are initialized */
+
+ initialized = true;
+ }
+
+ return OK;
+}
+
+#else
+# error "RGB LED bad configuration"
Review Comment:
```suggestion
# error "RGB LED bad configuration"
```
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = open(devname, O_WRONLY);
Review Comment:
```suggestion
int fd = nx_open(devname, O_WRONLY);
```
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = write(fd, "#000000", 8);
+
+ if (ret <= 0)
+ {
+ lederr("ERROR: rgbled_write failed: %d\n", ret);
+ close(fd);
+ return ret;
+ }
+
+ close(fd);
Review Comment:
```suggestion
nx_close(fd);
if (ret <= 0)
{
lederr("ERROR: rgbled_write failed: %d\n", ret);
return ret;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253100856
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
Maybe `return -EIO;`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on pull request #9707: esp32/common: RGB LED support
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#issuecomment-1621860470
Thank you very much @simonatoaca !
Please squash these commits in a single commit. You can consult the instructions here:
https://nuttx.apache.org/docs/latest/contributing/making-changes.html#submitting-your-changes-to-nuttx
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] simonatoaca commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "simonatoaca (via GitHub)" <gi...@apache.org>.
simonatoaca commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253056828
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
Do you have any suggestions on how I could fix this? Should I remove the 0 or return an error code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] simonatoaca commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "simonatoaca (via GitHub)" <gi...@apache.org>.
simonatoaca commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253112819
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
I read on nx_write and it says that it returns a negated errno value on any failure, so if indeed nothing is written, it won't return 0, but the errno value. I will remove the 0, since returning -EIO would mask the real error in some cases. Thank you for your response!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis merged pull request #9707: esp32/common: RGB LED support
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #9707:
URL: https://github.com/apache/nuttx/pull/9707
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253052084
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
Here `0` is an error, but upper layer will think that it is success.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] simonatoaca commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "simonatoaca (via GitHub)" <gi...@apache.org>.
simonatoaca commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253056828
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
Do you have any suggestions on how I could fix this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] simonatoaca commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "simonatoaca (via GitHub)" <gi...@apache.org>.
simonatoaca commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1253112819
##########
boards/xtensa/esp32/common/src/esp32_rgbled.c:
##########
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_rgbled.c
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/timers/pwm.h>
+#include <nuttx/leds/rgbled.h>
+
+#include "esp32-sparrow-kit.h"
+#include "esp32_gpio.h"
+#include "esp32_ledc.h"
+#include "esp32_rgbled.h"
+
+#if defined(CONFIG_ESP32_TIMER0) && \
+ defined(CONFIG_ESP32_LEDC) && \
+ defined(CONFIG_ESP32_LEDC_TIM0) && \
+ (CONFIG_ESP32_LEDC_TIM0_CHANNELS >= 3) && \
+ defined(CONFIG_PWM_MULTICHAN) && (CONFIG_PWM_NCHANNELS >= 3)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ * Initialize support for RGB LED using PWM.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname)
+{
+ static bool initialized = false;
+ FAR struct pwm_lowerhalf_s *ledr;
+ FAR struct pwm_lowerhalf_s *ledg;
+ FAR struct pwm_lowerhalf_s *ledb;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ ledr = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledr)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDR\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED R */
+
+ ledr->ops->setup(ledr);
+
+ ledg = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledg)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDG\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED G */
+
+ ledg->ops->setup(ledg);
+
+ ledb = esp32_ledc_init(RGB_LED_TIMER);
+ if (!ledb)
+ {
+ lederr("ERROR: Failed to get the ESP32 PWM lower half to LEDB\n");
+ return -ENODEV;
+ }
+
+ /* Initialize LED B */
+
+ ledb->ops->setup(ledb);
+
+ /* Register the RGB LED diver at <devname> */
+
+ ret = rgbled_register(devname, ledr, ledg, ledb, RGB_R_CHANN,
+ RGB_G_CHANN,
+ RGB_B_CHANN);
+ if (ret < 0)
+ {
+ lederr("ERROR: rgbled_register failed: %d\n", ret);
+ return ret;
+ }
+
+ int fd = nx_open(devname, O_WRONLY);
+
+ if (fd < 0)
+ {
+ lederr("ERROR: rgbled_open failed\n");
+ return fd;
+ }
+
+ /* Turn OFF the LED */
+
+ ret = nx_write(fd, "#000000", 8);
+ nx_close(fd);
+
+ if (ret <= 0)
Review Comment:
I read on nx_write and it says that it returns a negated errno value on any failure, so if indeed nothing is written, it won't return 0, but the errno value. I will remove the 0. Thank you for your response!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] simonatoaca commented on a diff in pull request #9707: esp32/common: RGB LED support
Posted by "simonatoaca (via GitHub)" <gi...@apache.org>.
simonatoaca commented on code in PR #9707:
URL: https://github.com/apache/nuttx/pull/9707#discussion_r1252933768
##########
boards/xtensa/esp32/common/include/esp32_rgbled.h:
##########
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/include/esp32_rgbled.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_RGBLED_H
+#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_RGBLED_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define RGB_LED_TIMER TIMER0
+
+#define RGB_R_CHANN 0
+#define RGB_G_CHANN 1
+#define RGB_B_CHANN 2
+
+/****************************************************************************
+ * Type Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_rgbled_initialize
+ *
+ * Description:
+ *
+ *
+ * Input Parameters:
+ * devname - The name under which the RGB led will be registered
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int esp32_rgbled_initialize(const char *devname);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_LTR308_H */
Review Comment:
Thank you, I modified it to say rgbled instead of ltr308 :))
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org