forked from nuttx/nuttx-update
esp32/common: Added support for rgb led driver on esp32
Signed-off-by: simonatoaca <simona.alexandra2000@gmail.com> esp32-sparrow-kit: Added rgb led driver to bringup and to defconfig Signed-off-by: simonatoaca <simona.alexandra2000@gmail.com> Fixed checkstyle Signed-off-by: simonatoaca <simona.alexandra2000@gmail.com> Update esp32_rgbled.h Update boards/xtensa/esp32/common/src/esp32_rgbled.c Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com> Update boards/xtensa/esp32/common/src/esp32_rgbled.c Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com> Update boards/xtensa/esp32/common/src/esp32_rgbled.c Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com> Update boards/xtensa/esp32/common/src/esp32_rgbled.c Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com> Removed ret 0 as an error in the case of nx_write()
This commit is contained in:
parent
c3576d79d9
commit
a4708d217a
5 changed files with 274 additions and 0 deletions
89
boards/xtensa/esp32/common/include/esp32_rgbled.h
Normal file
89
boards/xtensa/esp32/common/include/esp32_rgbled.h
Normal file
|
@ -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_RGBLED_H */
|
|
@ -120,6 +120,10 @@ ifeq ($(CONFIG_LCD_SSD1680),y)
|
|||
CSRCS += esp32_ssd1680.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RGBLED),y)
|
||||
CSRCS += esp32_rgbled.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path src
|
||||
VPATH += :src
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||
|
|
152
boards/xtensa/esp32/common/src/esp32_rgbled.c
Normal file
152
boards/xtensa/esp32/common/src/esp32_rgbled.c
Normal file
|
@ -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)
|
||||
{
|
||||
lederr("ERROR: rgbled_write failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#else
|
||||
# error "RGB LED bad configuration"
|
||||
#endif
|
||||
|
|
@ -27,11 +27,18 @@ CONFIG_BUILTIN=y
|
|||
CONFIG_DRIVERS_VIDEO=y
|
||||
CONFIG_ESP32_I2C0=y
|
||||
CONFIG_ESP32_I2C0_SDAPIN=21
|
||||
CONFIG_ESP32_LEDC=y
|
||||
CONFIG_ESP32_LEDC_CHANNEL0_PIN=14
|
||||
CONFIG_ESP32_LEDC_CHANNEL1_PIN=13
|
||||
CONFIG_ESP32_LEDC_CHANNEL2_PIN=15
|
||||
CONFIG_ESP32_LEDC_TIM0=y
|
||||
CONFIG_ESP32_LEDC_TIM0_CHANNELS=3
|
||||
CONFIG_ESP32_SPI2=y
|
||||
CONFIG_ESP32_SPI2_CLKPIN=18
|
||||
CONFIG_ESP32_SPI2_CSPIN=5
|
||||
CONFIG_ESP32_SPI2_MISOPIN=19
|
||||
CONFIG_ESP32_SPI2_MOSIPIN=23
|
||||
CONFIG_ESP32_TIMER0=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_FAT_LCNAMES=y
|
||||
CONFIG_FAT_LFN=y
|
||||
|
@ -58,8 +65,14 @@ CONFIG_NSH_LINELEN=64
|
|||
CONFIG_NSH_MMCSDSPIPORTNO=2
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PWM_MULTICHAN=y
|
||||
CONFIG_PWM_NCHANNELS=3
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RGBLED=y
|
||||
CONFIG_RGBLED_INVERT=y
|
||||
CONFIG_RGBLED_LIGHTNESS_CORRECTION=y
|
||||
CONFIG_RGBLED_PWM_FREQ=200
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SENSORS=y
|
||||
|
@ -69,5 +82,7 @@ CONFIG_START_MONTH=12
|
|||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSLOG_BUFFER=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TIMER=y
|
||||
CONFIG_TIMER_ARCH=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_VIDEO_FB=y
|
||||
|
|
|
@ -48,6 +48,10 @@
|
|||
# include <nuttx/leds/userled.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RGBLED
|
||||
# include "esp32_rgbled.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TIMER
|
||||
#include <esp32_tim_lowerhalf.h>
|
||||
#endif
|
||||
|
@ -400,6 +404,16 @@ int esp32_bringup(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RGBLED
|
||||
/* Register RGB Driver */
|
||||
|
||||
ret = esp32_rgbled_initialize("/dev/rgbled0");
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: esp32_rgbled_initialize() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we got here then perhaps not all initialization was successful, but
|
||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||
* capabilities.
|
||||
|
|
Loading…
Reference in a new issue