esp32/rmt: Use the Espressif`s common RMT driver.
This commit implements the common RMT driver (already available for the other Espressif's xtensa-based devices) for ESP32. This allows us to have a proper separation between the lower and upper-half drivers and use the 'ws2812' example to drive WS2812 RGB LEDs.
This commit is contained in:
parent
6b73782c27
commit
5ba40d083a
@ -213,6 +213,8 @@ config ESP32_EXCEPTION_ENABLE_CACHE
|
||||
|
||||
menu "ESP32 Peripheral Selection"
|
||||
|
||||
source "arch/xtensa/src/common/espressif/Kconfig"
|
||||
|
||||
config ESP32_UART
|
||||
bool
|
||||
default n
|
||||
|
@ -35,6 +35,8 @@
|
||||
|
||||
#include "xtensa.h"
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#include "hardware/esp32_iomux.h"
|
||||
#include "hardware/esp32_gpio.h"
|
||||
|
||||
|
@ -102,6 +102,24 @@
|
||||
#define ONLOW_WE 0x0c
|
||||
#define ONHIGH_WE 0x0d
|
||||
|
||||
/* Check whether it is a valid GPIO number */
|
||||
|
||||
#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \
|
||||
(((1ULL << (gpio_num)) & \
|
||||
SOC_GPIO_VALID_GPIO_MASK) != 0))
|
||||
|
||||
/* Check whether it can be a valid GPIO number of output mode */
|
||||
|
||||
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) \
|
||||
((gpio_num >= 0) && \
|
||||
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0))
|
||||
|
||||
/* Check whether it can be a valid digital I/O pad */
|
||||
|
||||
#define GPIO_IS_VALID_DIGITAL_IO_PAD(gpio_num) \
|
||||
((gpio_num >= 0) && \
|
||||
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK) != 0))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
97
boards/xtensa/esp32/common/include/esp32_board_rmt.h
Normal file
97
boards/xtensa/esp32/common/include/esp32_board_rmt.h
Normal file
@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
* boards/xtensa/esp32/common/include/esp32_board_rmt.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_BOARD_RMT_H
|
||||
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_RMT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP_RMT
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_rmt_rxinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the RMT peripheral and register a RX device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ch - the RMT's channel that will be used
|
||||
* pin - The pin used for the RX channel
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_rmt_rxinitialize(int ch, int pin);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_rmt_txinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the RMT peripheral and register a TX device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ch - the RMT's channel that will be used
|
||||
* pin - The pin used for the TX channel
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_rmt_txinitialize(int ch, int pin);
|
||||
|
||||
#endif /* CONFIG_ESP_RMT */
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_RMT_H */
|
@ -140,8 +140,8 @@ ifeq ($(CONFIG_RGBLED),y)
|
||||
CSRCS += esp32_rgbled.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ESP32_RMT),y)
|
||||
CSRCS += esp32_rmt.c
|
||||
ifeq ($(CONFIG_ESP_RMT),y)
|
||||
CSRCS += esp32_board_rmt.c
|
||||
endif
|
||||
|
||||
#ifeq ($(CONFIG_DAC),y)
|
||||
|
155
boards/xtensa/esp32/common/src/esp32_board_rmt.c
Normal file
155
boards/xtensa/esp32/common/src/esp32_board_rmt.c
Normal file
@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
* boards/xtensa/esp32/common/src/esp32_board_rmt.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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xtensa.h"
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/rmt/rmtchar.h>
|
||||
#ifdef CONFIG_WS2812_NON_SPI_DRIVER
|
||||
#include <nuttx/leds/ws2812.h>
|
||||
|
||||
#include "espressif/esp_ws2812.h"
|
||||
#endif
|
||||
|
||||
#include "espressif/esp_rmt.h"
|
||||
|
||||
#ifdef CONFIG_ESP_RMT
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_rmt_rxinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the RMT peripheral and register a RX device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ch - the RMT's channel that will be used
|
||||
* pin - The pin used for the RX channel
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_rmt_rxinitialize(int ch, int pin)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct rmt_dev_s *rmt = esp_rmt_rx_init(ch, pin);
|
||||
|
||||
ret = rmtchar_register(rmt);
|
||||
if (ret < 0)
|
||||
{
|
||||
rmterr("ERROR: rmtchar_register failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_rmt_txinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the RMT peripheral and register a TX device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ch - the RMT's channel that will be used
|
||||
* pin - The pin used for the TX channel
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_rmt_txinitialize(int ch, int pin)
|
||||
{
|
||||
int ret;
|
||||
struct rmt_dev_s *rmt;
|
||||
#ifdef CONFIG_WS2812_NON_SPI_DRIVER
|
||||
struct ws2812_dev_s *led;
|
||||
#endif
|
||||
|
||||
rmt = esp_rmt_tx_init(ch, pin);
|
||||
|
||||
if (rmt == NULL)
|
||||
{
|
||||
rmterr("ERROR: esp_rmt_tx_init failed\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = rmtchar_register(rmt);
|
||||
if (ret < 0)
|
||||
{
|
||||
rmterr("ERROR: rmtchar_register failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_WS2812_NON_SPI_DRIVER
|
||||
led = esp_ws2812_setup("/dev/leds0", rmt,
|
||||
CONFIG_WS2812_LED_COUNT, false);
|
||||
|
||||
if (led == NULL)
|
||||
{
|
||||
rmterr("ERROR: esp_ws2812_setup failed\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
57
boards/xtensa/esp32/esp32-devkitc/configs/rmt/defconfig
Normal file
57
boards/xtensa/esp32/esp32-devkitc/configs/rmt/defconfig
Normal file
@ -0,0 +1,57 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_ARCH_LEDS is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-devkitc"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_ESP_RMT=y
|
||||
CONFIG_EXAMPLES_RMTCHAR=y
|
||||
CONFIG_EXAMPLES_RMTCHAR_RX=y
|
||||
CONFIG_EXAMPLES_RMTCHAR_TX=y
|
||||
CONFIG_EXAMPLES_WS2812=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RMT=y
|
||||
CONFIG_RMTCHAR=y
|
||||
CONFIG_RMT_DEFAULT_RX_BUFFER_SIZE=256
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSLOG_BUFFER=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_WS2812=y
|
||||
CONFIG_WS2812_LED_COUNT=100
|
||||
CONFIG_WS2812_NON_SPI_DRIVER=y
|
@ -68,8 +68,16 @@
|
||||
|
||||
/* RMT gpio */
|
||||
|
||||
#define RMT_OUTPUT_PIN 4
|
||||
#define RMT_CHANNEL 0
|
||||
#define RMT_RXCHANNEL 1
|
||||
#define RMT_TXCHANNEL 0
|
||||
|
||||
#ifdef CONFIG_RMT_LOOP_TEST_MODE
|
||||
# define RMT_INPUT_PIN 0
|
||||
# define RMT_OUTPUT_PIN 0
|
||||
#else
|
||||
# define RMT_INPUT_PIN 2
|
||||
# define RMT_OUTPUT_PIN 4
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
|
@ -165,6 +165,10 @@
|
||||
# include "esp32_board_dac.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_RMT
|
||||
# include "esp32_board_rmt.h"
|
||||
#endif
|
||||
|
||||
#include "esp32-devkitc.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -653,6 +657,20 @@ int esp32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_RMT
|
||||
ret = board_rmt_txinitialize(RMT_TXCHANNEL, RMT_OUTPUT_PIN);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: board_rmt_txinitialize() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
ret = board_rmt_rxinitialize(RMT_RXCHANNEL, RMT_INPUT_PIN);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: board_rmt_txinitialize() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTC_DRIVER
|
||||
/* Instantiate the ESP32 RTC driver */
|
||||
|
||||
@ -676,7 +694,7 @@ int esp32_bringup(void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WS2812
|
||||
# ifndef CONFIG_WS2812_NON_SPI_DRIVER
|
||||
# ifndef CONFIG_WS2812_NON_SPI_DRIVER
|
||||
ret = board_ws2812_initialize(0, ESP32_SPI3, CONFIG_WS2812_LED_COUNT);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user