risc-v/esp_<rmt|ws2812>: Implement the RMT peripheral for ESP32 RVs

This commit implements the RMT peripheral for all the supported
Espressif's RISC-V devices. It also implements the support for the
WS2812 addressable RGB LED using the RMT peripheral.
This commit is contained in:
Tiago Medicci Serrano 2024-01-31 16:07:58 -03:00 committed by Xiang Xiao
parent c5358d6365
commit e49684d781
29 changed files with 3885 additions and 0 deletions

View File

@ -130,6 +130,7 @@ endif
VPATH += chip
VPATH += common
VPATH += common/espressif
VPATH += $(SBI_DIR)
VPATH += $(ARCH_SUBDIR)
VPATH += $(CHIP_DIR)

View File

@ -298,6 +298,16 @@ config ESPRESSIF_BROWNOUT_DET
than a specific value. If this happens, it will reset the chip in
order to prevent unintended behaviour.
config ESP_RMT
bool "Remote Control Module (RMT)"
default n
depends on RMT
---help---
The RMT (Remote Control Transceiver) peripheral was designed to act as
an infrared transceiver. However, due to the flexibility of its data
format, RMT can be extended to a versatile and general-purpose
transceiver, transmitting or receiving many other types of signals.
endmenu # Peripheral Support
menu "UART Configuration"

View File

@ -73,6 +73,13 @@ ifeq ($(CONFIG_ESPRESSIF_USBSERIAL),y)
CHIP_CSRCS += esp_usbserial.c
endif
ifeq ($(CONFIG_ESP_RMT),y)
CHIP_CSRCS += esp_rmt.c
ifeq ($(CONFIG_WS2812_NON_SPI_DRIVER),y)
CHIP_CSRCS += esp_ws2812.c
endif
endif
#############################################################################
# Espressif HAL for 3rd Party Platforms
#############################################################################

View File

@ -98,6 +98,24 @@
#define ONLOW 0x04
#define ONHIGH 0x05
/* 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
****************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,109 @@
/****************************************************************************
* arch/risc-v/src/common/espressif/esp_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 __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_RMT_H
#define __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_RMT_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <semaphore.h>
#include <nuttx/spinlock.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define RMT_MEM_ITEM_NUM SOC_RMT_MEM_WORDS_PER_CHANNEL
#define RMT_DEFAULT_CLK_DIV 1
/* Channel can work during APB clock scaling */
#define RMT_CHANNEL_FLAGS_AWARE_DFS (1 << 0)
/* Invert RMT signal */
#define RMT_CHANNEL_FLAGS_INVERT_SIG (1 << 1)
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
extern "C"
{
#endif
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
#if defined(CONFIG_ESP_RMT)
/****************************************************************************
* Name: esp_rmt_tx_init
*
* Description:
* Initialize the selected RMT device in TX mode
*
* Input Parameters:
* ch - the RMT's channel that will be used
* pin - The pin used for the TX channel
*
* Returned Value:
* Valid RMT device structure reference on success; NULL, otherwise.
*
****************************************************************************/
struct rmt_dev_s *esp_rmt_tx_init(int ch, int pin);
/****************************************************************************
* Name: esp_rmt_rx_init
*
* Description:
* Initialize the selected RMT device in RC mode
*
* Input Parameters:
* ch - the RMT's channel that will be used
* pin - The pin used for the RX channel
*
* Returned Value:
* Valid RMT device structure reference on success; NULL, otherwise.
*
****************************************************************************/
struct rmt_dev_s *esp_rmt_rx_init(int ch, int pin);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_RMT_H */

View File

@ -0,0 +1,667 @@
/****************************************************************************
* arch/risc-v/src/common/espressif/esp_ws2812.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 <stdlib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>
#include <nuttx/leds/ws2812.h>
#include <nuttx/rmt/rmt.h>
#include "hal/rmt_types.h"
#include "soc/soc.h"
#include "esp_rmt.h"
#include "esp_ws2812.h"
#ifdef CONFIG_WS2812
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define rmt_item32_t rmt_symbol_word_t
/****************************************************************************
* Private Type
****************************************************************************/
struct rgbw_led_s
{
union
{
struct
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t w;
};
uint32_t val;
};
};
struct esp_ws2812_dev_s
{
struct rmt_dev_s *rmt;
uint8_t *buf;
size_t buflen;
size_t open_count; /* Number of opens on this instance. */
};
/* RMT channel ID */
enum rmt_channel_e
{
RMT_CHANNEL_0, /* RMT channel number 0 */
RMT_CHANNEL_1, /* RMT channel number 1 */
RMT_CHANNEL_2, /* RMT channel number 2 */
RMT_CHANNEL_3, /* RMT channel number 3 */
#if SOC_RMT_CHANNELS_PER_GROUP > 4
RMT_CHANNEL_4, /* RMT channel number 4 */
RMT_CHANNEL_5, /* RMT channel number 5 */
RMT_CHANNEL_6, /* RMT channel number 6 */
RMT_CHANNEL_7, /* RMT channel number 7 */
#endif
RMT_CHANNEL_MAX /* Number of RMT channels */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static uint32_t map_byte_to_words(struct esp_ws2812_dev_s *dev,
uint8_t byte,
uint32_t *dst);
static int map_leds_to_words(struct esp_ws2812_dev_s *dev,
struct rgbw_led_s *leds,
uint32_t n_leds,
uint32_t *dst,
bool has_white);
static int esp_open(struct file *filep);
static int esp_close(struct file *filep);
static int esp_write(struct file *filep, const char *data, size_t len);
/****************************************************************************
* Private Data
****************************************************************************/
#if SOC_RMT_CHANNEL_CLK_INDEPENDENT
extern uint32_t g_rmt_source_clock_hz[RMT_CHANNEL_MAX];
#else
extern uint32_t g_rmt_source_clock_hz;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: map_byte_to_words
*
* Description:
* Maps a byte to a sequence of RMT items. Each bit in the byte is
* represented by an RMT item (32-bit value). Iterates over each bit in
* the byte, creating an RMT item for each bit, set or not. The created
* RMT items are stored in the destination array.
*
* Input Parameters:
* dev - Pointer to the RMT-based WS2812 device structure.
* byte - The byte to be mapped.
* dst - Destination array for the RMT items.
*
* Returned Value:
* Number of RMT items mapped.
*
****************************************************************************/
static uint32_t map_byte_to_words(struct esp_ws2812_dev_s *dev,
uint8_t byte,
uint32_t *dst)
{
uint32_t mapped;
uint8_t mask;
uint16_t t0h;
uint16_t t0l;
uint16_t t1h;
uint16_t t1l;
uint32_t clock_period_ps;
uint32_t rmt_period_ps;
#if SOC_RMT_CHANNEL_CLK_INDEPENDENT
clock_period_ps = 1000000000000 / g_rmt_source_clock_hz[dev->rmt->minor];
#else
clock_period_ps = 1000000000000 / g_rmt_source_clock_hz;
#endif
rmt_period_ps = clock_period_ps / RMT_DEFAULT_CLK_DIV;
/* Calculate the RMT period to encode WS2812 frames */
t0h = ((uint16_t)(350000 / rmt_period_ps));
t0l = ((uint16_t)(900000 / rmt_period_ps));
t1h = ((uint16_t)(900000 / rmt_period_ps));
t1l = ((uint16_t)(350000 / rmt_period_ps));
mapped = 0;
mask = 0x80;
for (int i = 0; i < 8; i++)
{
uint32_t word;
uint8_t bit = (byte & mask);
mask >>= 1;
if (bit)
{
word = (t1l << 16) | (0x8000 | t1h);
}
else
{
word = (t0l << 16) | (0x8000 | t0h);
}
*dst = word;
dst++;
mapped++;
}
return mapped;
}
/****************************************************************************
* Name: map_leds_to_words
*
* Description:
* Maps an array of LEDs to a sequence of RMT items. Each LED in the array
* is represented by a sequence of RMT items, one for each bit in the RGB
* (and optionally white) values. Iterates over each LED in the array,
* mapping the RGB (and optionally white) values to RMT items using the
* map_byte_to_words function. The RMT items are stored in the destination
* array.
*
* Input Parameters:
* dev - Pointer to the RMT-based WS2812 device structure.
* leds - Pointer to the array of LEDs.
* n_leds - Number of LEDs in the array.
* dst - Destination array for the RMT items.
* has_white - Flag indicating if the LEDs include a white component.
*
* Returned Value:
* Number of RMT items mapped; a negated errno value is returned on
* failure.
*
****************************************************************************/
static int map_leds_to_words(struct esp_ws2812_dev_s *dev,
struct rgbw_led_s *leds,
uint32_t n_leds,
uint32_t *dst,
bool has_white)
{
uint32_t dst_offset;
if (!dst || !leds)
{
return -EINVAL;
}
dst_offset = 0;
for (uint32_t led_idx = 0; led_idx < n_leds; led_idx++)
{
dst_offset += map_byte_to_words(dev,
leds[led_idx].g,
dst + dst_offset);
dst_offset += map_byte_to_words(dev,
leds[led_idx].r,
dst + dst_offset);
dst_offset += map_byte_to_words(dev,
leds[led_idx].b,
dst + dst_offset);
if (has_white)
{
dst_offset += map_byte_to_words(dev,
leds[led_idx].w,
dst + dst_offset);
}
}
return dst_offset;
}
/****************************************************************************
* Name: esp_open
*
* Description:
* This function opens a WS2812 device instance. It locks the device,
* checks if the device has already been initialized, and if not, it
* allocates and initializes the pixel buffer. It then increases the open
* count and unlocks the device.
*
* Input Parameters:
* filep - Pointer to the file structure.
*
* Returned Value:
* Returns OK on successful open of the device; a negated errno value
* is returned on any failure.
*
****************************************************************************/
static int esp_open(struct file *filep)
{
struct inode *inode = filep->f_inode;
struct ws2812_dev_s *dev_data = inode->i_private;
struct esp_ws2812_dev_s *priv;
uint8_t colors;
irqstate_t flags;
size_t buflen;
int i;
int ret;
priv = (struct esp_ws2812_dev_s *)dev_data->private;
flags = enter_critical_section();
if (priv->buf != NULL)
{
/* We've already been initialized. Keep on truckin' */
ledinfo("esp_ws2812 re-open dev: 0x%p\n", dev_data);
ret = OK;
goto post_and_return;
}
ledinfo("esp_ws2812 open dev: 0x%p\n", dev_data);
/* Allocate the pixel buffer */
if (priv->open_count == 0)
{
struct rgbw_led_s *led;
/* Number of colors of each LED */
colors = (dev_data->has_white ? 4 : 3);
/* Each LED color is represented by 8 RMT items + 1 last item. Each RMT
* item is 32-bit long.
*/
buflen = (dev_data->nleds * colors * 8 + 1) * sizeof(rmt_item32_t);
priv->buf = kmm_zalloc(buflen);
if (priv->buf == NULL)
{
lederr("esp_ws2812 open: out of memory\n");
ret = -ENOMEM;
goto post_and_return;
}
priv->buflen = buflen;
/* Clear all LEDs in the LED strip */
led = kmm_zalloc(sizeof(struct rgbw_led_s));
if (led == NULL)
{
lederr("esp_ws2812 open: out of memory\n");
ret = -ENOMEM;
goto post_and_return;
}
for (i = 0; i < dev_data->nleds; i++)
{
map_leds_to_words(priv,
led,
1,
((uint32_t *)priv->buf + i * colors * 8),
dev_data->has_white);
}
kmm_free(led);
}
else
{
ledwarn("esp_ws2812 open: already open\n");
}
priv->open_count += 1;
ret = OK;
post_and_return:
leave_critical_section(flags);
return ret;
}
/****************************************************************************
* Name: esp_close
*
* Description:
* This function closes a previously opened WS2812 device instance. It
* locks the device, decreases the open count, and if no other instances
* are open, it frees the buffer associated with the device. It then
* unlocks the device and returns OK.
*
* Input Parameters:
* filep - Pointer to the file structure.
*
* Returned Value:
* Returns OK on successful close of the device; a negated errno value
* is returned on any failure.
*
****************************************************************************/
static int esp_close(struct file *filep)
{
struct inode *inode = filep->f_inode;
struct ws2812_dev_s *dev_data = inode->i_private;
struct esp_ws2812_dev_s *priv;
priv = (struct esp_ws2812_dev_s *)dev_data->private;
nxmutex_lock(&dev_data->lock);
ledinfo("esp_ws2812 close dev: 0x%p\n", dev_data);
priv->open_count -= 1;
if (priv->open_count == 0)
{
kmm_free(priv->buf);
priv->buf = NULL;
}
nxmutex_unlock(&dev_data->lock);
return OK;
}
/****************************************************************************
* Name: esp_write
*
* Description:
* This function writes the LED data to the WS2812 device. It checks if the
* data and length are valid, locks the device, maps the LED data to the
* buffer, updates the file position, writes the buffer to the RMT device,
* and unlocks the device. It returns the number of LED pixels that had
* their values changed.
*
* Input Parameters:
* filep - Pointer to the file structure.
* data - Pointer to the LED data to be written.
* len - The length of the data to be written.
*
* Returned Value:
* Returns the number of LED pixels that had their values changed on
* successful write; a negated errno value is returned on any failure.
*
****************************************************************************/
static ssize_t esp_write(struct file *filep, const char *data, size_t len)
{
struct inode *inode = filep->f_inode;
struct ws2812_dev_s *dev = inode->i_private;
struct esp_ws2812_dev_s *priv =
(struct esp_ws2812_dev_s *)dev->private;
int position = filep->f_pos;
uint32_t n_leds = len / WS2812_RW_PIXEL_SIZE;
uint8_t colors = (dev->has_white ? 4 : 3);
uint8_t *bp = priv->buf + position;
int rmt_bytes;
int n_leds_written;
int ret;
/* Check if LED data isn't NULL */
if (data == NULL)
{
lederr("esp_ws2812 write failed: NULL data\n");
set_errno(EINVAL);
return 0;
}
/* Check if the number of LEDs to be updated is valid */
if (n_leds > dev->nleds)
{
lederr("esp_ws2812 write failed: invalid len for the LEDs buffer\n");
set_errno(EINVAL);
return 0;
}
nxmutex_lock(&dev->lock);
if (len > 0)
{
/* Check if the lenght to be updated, considering the current position,
* is valid. The number of LEDs to be updated should, starting from the
* current offset should be less than the LED strip total length.
*/
if (((position + len) / WS2812_RW_PIXEL_SIZE) > dev->nleds)
{
ledwarn("esp_ws2812 write truncated:\n\t\tLED position: %d\n"
"\t\tLED requested to be written: %ld\n"
"\t\tLED strip LED count: %d\n"
"\t\tLED being written: %d\n",
position / WS2812_RW_PIXEL_SIZE,
n_leds,
dev->nleds,
dev->nleds - (position / WS2812_RW_PIXEL_SIZE));
n_leds = dev->nleds - (position / WS2812_RW_PIXEL_SIZE);
}
ret = map_leds_to_words(priv,
(struct rgbw_led_s *)data,
n_leds,
(uint32_t *)bp,
dev->has_white);
if (ret < 0)
{
lederr("esp_ws2812 write failed: %d\n", ret);
nxmutex_unlock(&dev->lock);
set_errno(-ret);
return ret;
}
/* Update the file position: each LED color is represented by 8 RMT
* items. The position is, then, the number of LEDs to be update times
* the size of a LED color in bytes.
*/
position += n_leds * WS2812_RW_PIXEL_SIZE;
filep->f_pos = position;
}
/* Write the buffer to the RMT device */
rmt_bytes = priv->rmt->ops->write(priv->rmt,
(const char *)priv->buf,
priv->buflen);
/* n_leds_written is the number of LEDs that had their values changed:
* Each LED color is represented by 8 RMT items. We also added a last
* RMT item to the buffer, so we need to subtract 1 from the total number.
* Finally, we divide by the number of colors to get the number of LEDs.
*/
n_leds_written = ((rmt_bytes / sizeof(rmt_item32_t)) - 1) / (colors * 8);
/* Compare n_leds_written with the value representing the full LED strip */
if (n_leds_written < dev->nleds)
{
lederr("esp_ws2812 write failed: %d\n", n_leds_written);
nxmutex_unlock(&dev->lock);
set_errno(-EIO);
return -EIO;
}
nxmutex_unlock(&dev->lock);
/* Return the number of LEDs pixels that had their values changed */
return n_leds * WS2812_RW_PIXEL_SIZE;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp_ws2812_setup
*
* Description:
* This function sets up a WS2812 device instance. It allocates memory for
* the device structures, initializes the device with the provided
* parameters, and registers the device with the system.
*
* Input Parameters:
* path - The device path.
* rmt - Pointer to the RMT device structure.
* pixel_count - The number of pixels in the WS2812 strip.
* has_white - Flag indicating if the WS2812 strip includes a white LED.
*
* Returned Value:
* Returns a pointer to the WS2812 device structure on successful setup;
* NULL is returned on any failure, with errno set appropriately.
*
****************************************************************************/
struct ws2812_dev_s *esp_ws2812_setup(const char *path,
struct rmt_dev_s *rmt,
uint16_t pixel_count,
bool has_white)
{
struct ws2812_dev_s *dev;
struct esp_ws2812_dev_s *priv;
int err;
/* Allocate struct holding generic WS2812 device data */
dev = kmm_zalloc(sizeof(struct ws2812_dev_s));
if (dev == NULL)
{
lederr("esp_ws2812 setup: out of memory\n");
set_errno(ENOMEM);
return NULL;
}
/* Allocate struct holding Espressif's WS2812 (RMT-enabled) device data */
priv = kmm_zalloc(sizeof(struct esp_ws2812_dev_s));
if (priv == NULL)
{
lederr("esp_ws2812 open: out of memory\n");
kmm_free(dev);
set_errno(ENOMEM);
return NULL;
}
priv->rmt = rmt;
dev->open = esp_open;
dev->close = esp_close;
dev->write = esp_write;
dev->private = priv;
dev->clock = CONFIG_WS2812_FREQUENCY;
dev->port = priv->rmt->minor;
dev->nleds = pixel_count;
dev->has_white = has_white;
nxmutex_init(&dev->lock);
ledinfo("register dev: 0x%p\n", dev);
/* Register the WS2812 RGB addressable LED strip device */
err = ws2812_register(path, dev);
if (err != OK)
{
set_errno(err);
return NULL;
}
return (void *)dev;
}
/****************************************************************************
* Name: esp_ws2812_release
*
* Description:
* This function releases a previously opened WS2812 device instance. It
* checks if the device is currently open, and if not, it frees the private
* data structure and sets the private field of the device to NULL. If the
* device is still open, it returns an error.
*
* Input Parameters:
* driver - Pointer to the instance of the WS2812 device driver to be
* released.
*
* Returned Value:
* Returns OK on successful release of the device; a negated errno value
* is returned on any failure.
*
****************************************************************************/
int esp_ws2812_release(void * driver)
{
struct ws2812_dev_s *dev = driver;
struct esp_ws2812_dev_s *priv;
int ret = OK;
priv = (struct esp_ws2812_dev_s *)dev->private;
nxmutex_lock(&dev->lock);
if (priv->open_count == 0)
{
dev->private = NULL;
nxmutex_unlock(&dev->lock);
kmm_free(priv);
}
else
{
ret = -EBUSY;
nxmutex_unlock(&dev->lock);
}
return ret;
}
#endif /* CONFIG_WS2812 */

View File

@ -0,0 +1,100 @@
/****************************************************************************
* arch/risc-v/src/common/espressif/esp_ws2812.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 __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_WS2812_H
#define __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_WS2812_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <stdbool.h>
#ifndef __ASSEMBLY__
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifdef CONFIG_WS2812
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp_ws2812_setup
*
* Description:
* This function sets up a WS2812 device instance. It allocates memory for
* the device structures, initializes the device with the provided
* parameters, and registers the device with the system.
*
* Input Parameters:
* path - The device path.
* rmt - Pointer to the RMT device structure.
* pixel_count - The number of pixels in the WS2812 strip.
* has_white - Flag indicating if the WS2812 strip includes a white LED.
*
* Returned Value:
* Returns a pointer to the WS2812 device structure on successful setup;
* NULL is returned on any failure, with errno set appropriately.
*
****************************************************************************/
struct ws2812_dev_s *esp_ws2812_setup(const char *path,
struct rmt_dev_s *rmt,
uint16_t pixel_count,
bool has_white);
/****************************************************************************
* Name: esp_ws2812_release
*
* Description:
* This function releases a previously opened WS2812 device instance. It
* checks if the device is currently open, and if not, it frees the private
* data structure and sets the private field of the device to NULL. If the
* device is still open, it returns an error.
*
* Input Parameters:
* driver - Pointer to the instance of the WS2812 device driver to be
* released.
*
* Returned Value:
* Returns OK on successful release of the device; a negated errno value
* is returned on any failure.
*
****************************************************************************/
int esp_ws2812_release(void * driver);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISC_V_SRC_COMMON_ESPRESSIF_ESP_WS2812_H */

View File

@ -105,6 +105,7 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/timer_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/cache_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/mpu_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/mmu_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/rmt_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/uart_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/uart_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/wdt_hal_iram.c
@ -115,6 +116,7 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/log/log_noos.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/riscv/interrupt.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/gpio_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/ledc_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/rmt_periph.c
ifeq ($(CONFIG_ESPRESSIF_SIMPLE_BOOT),y)
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/nuttx/src/bootloader_banner_wrap.c

View File

@ -97,6 +97,7 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/gpio_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/ledc_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/ledc_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/lp_timer_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/rmt_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/timer_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/timer_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/uart_hal.c
@ -109,3 +110,4 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/log/log_noos.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/riscv/interrupt.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/gpio_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/ledc_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/rmt_periph.c

View File

@ -96,6 +96,7 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/gpio_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/ledc_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/ledc_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/lp_timer_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/rmt_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/timer_hal.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/timer_hal_iram.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/hal/uart_hal.c
@ -108,3 +109,4 @@ CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/log/log_noos.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/riscv/interrupt.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/gpio_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/ledc_periph.c
CHIP_CSRCS += chip/$(ESP_HAL_3RDPARTY_REPO)/components/soc/$(CHIP_SERIES)/rmt_periph.c

View File

@ -0,0 +1,97 @@
/****************************************************************************
* boards/risc-v/esp32c3/common/include/esp_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_RISC_V_ESP32C3_COMMON_INCLUDE_ESP_BOARD_RMT_H
#define __BOARDS_RISC_V_ESP32C3_COMMON_INCLUDE_ESP_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_RISC_V_ESP32C3_COMMON_INCLUDE_ESP_BOARD_RMT_H */

View File

@ -24,6 +24,10 @@ ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif
ifeq ($(CONFIG_ESP_RMT),y)
CSRCS += esp_board_rmt.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

View File

@ -0,0 +1,150 @@
/****************************************************************************
* boards/risc-v/esp32c3/common/src/esp_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 <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

View File

@ -0,0 +1,59 @@
#
# 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_NDEBUG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c3-generic"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C3_GENERIC=y
CONFIG_ARCH_CHIP="esp32c3"
CONFIG_ARCH_CHIP_ESP32C3_GENERIC=y
CONFIG_ARCH_INTERRUPTSTACK=1536
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DEV_ZERO=y
CONFIG_ESP_RMT=y
CONFIG_EXAMPLES_RMTCHAR=y
CONFIG_EXAMPLES_RMTCHAR_RX=y
CONFIG_EXAMPLES_RMTCHAR_RX_DEVPATH="/dev/rmt2"
CONFIG_EXAMPLES_RMTCHAR_TX=y
CONFIG_EXAMPLES_WS2812=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RMT=y
CONFIG_RMTCHAR=y
CONFIG_RMT_DEFAULT_RX_BUFFER_SIZE=512
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_WS2812=y
CONFIG_WS2812_LED_COUNT=100
CONFIG_WS2812_NON_SPI_DRIVER=y

View File

@ -31,6 +31,19 @@
* Pre-processor Definitions
****************************************************************************/
/* RMT gpio */
#define RMT_RXCHANNEL 2
#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 8
#endif
/****************************************************************************
* Public Types
****************************************************************************/

View File

@ -60,6 +60,10 @@
# include <nuttx/input/buttons.h>
#endif
#ifdef CONFIG_ESP_RMT
# include "esp_board_rmt.h"
#endif
#include "esp32c3-generic.h"
/****************************************************************************
@ -147,6 +151,20 @@ int esp_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
/* Initialize the RTC driver */

View File

@ -0,0 +1,97 @@
/****************************************************************************
* boards/risc-v/esp32c6/common/include/esp_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_RISC_V_ESP32C6_COMMON_INCLUDE_ESP_BOARD_RMT_H
#define __BOARDS_RISC_V_ESP32C6_COMMON_INCLUDE_ESP_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_RISC_V_ESP32C6_COMMON_INCLUDE_ESP_BOARD_RMT_H */

View File

@ -24,6 +24,10 @@ ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif
ifeq ($(CONFIG_ESP_RMT),y)
CSRCS += esp_board_rmt.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

View File

@ -0,0 +1,150 @@
/****************************************************************************
* boards/risc-v/esp32c6/common/src/esp_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 <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

View File

@ -0,0 +1,59 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c6-devkit"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C6_DEVKIT=y
CONFIG_ARCH_CHIP="esp32c6"
CONFIG_ARCH_CHIP_ESP32C6=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DEV_ZERO=y
CONFIG_ESPRESSIF_ESP32C6=y
CONFIG_ESP_RMT=y
CONFIG_EXAMPLES_RMTCHAR=y
CONFIG_EXAMPLES_RMTCHAR_RX=y
CONFIG_EXAMPLES_RMTCHAR_RX_DEVPATH="/dev/rmt2"
CONFIG_EXAMPLES_RMTCHAR_TX=y
CONFIG_EXAMPLES_WS2812=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RMT=y
CONFIG_RMTCHAR=y
CONFIG_RMT_DEFAULT_RX_BUFFER_SIZE=512
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_WS2812=y
CONFIG_WS2812_LED_COUNT=100
CONFIG_WS2812_NON_SPI_DRIVER=y

View File

@ -31,6 +31,19 @@
* Pre-processor Definitions
****************************************************************************/
/* RMT gpio */
#define RMT_RXCHANNEL 2
#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 8
#endif
/****************************************************************************
* Public Types
****************************************************************************/

View File

@ -60,6 +60,10 @@
# include <nuttx/input/buttons.h>
#endif
#ifdef CONFIG_ESP_RMT
# include "esp_board_rmt.h"
#endif
#include "esp32c6-devkit.h"
/****************************************************************************
@ -147,6 +151,20 @@ int esp_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
/* Initialize the RTC driver */

View File

@ -0,0 +1,97 @@
/****************************************************************************
* boards/risc-v/esp32h2/common/include/esp_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_RISC_V_ESP32H2_COMMON_INCLUDE_ESP_BOARD_RMT_H
#define __BOARDS_RISC_V_ESP32H2_COMMON_INCLUDE_ESP_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_RISC_V_ESP32H2_COMMON_INCLUDE_ESP_BOARD_RMT_H */

View File

@ -24,6 +24,10 @@ ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif
ifeq ($(CONFIG_ESP_RMT),y)
CSRCS += esp_board_rmt.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

View File

@ -0,0 +1,150 @@
/****************************************************************************
* boards/risc-v/esp32h2/common/src/esp_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 <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

View File

@ -0,0 +1,59 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32h2-devkit"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32H2_DEVKIT=y
CONFIG_ARCH_CHIP="esp32h2"
CONFIG_ARCH_CHIP_ESP32H2=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DEV_ZERO=y
CONFIG_ESPRESSIF_ESP32H2=y
CONFIG_ESP_RMT=y
CONFIG_EXAMPLES_RMTCHAR=y
CONFIG_EXAMPLES_RMTCHAR_RX=y
CONFIG_EXAMPLES_RMTCHAR_RX_DEVPATH="/dev/rmt2"
CONFIG_EXAMPLES_RMTCHAR_TX=y
CONFIG_EXAMPLES_WS2812=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RMT=y
CONFIG_RMTCHAR=y
CONFIG_RMT_DEFAULT_RX_BUFFER_SIZE=512
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_WS2812=y
CONFIG_WS2812_LED_COUNT=100
CONFIG_WS2812_NON_SPI_DRIVER=y

View File

@ -31,6 +31,19 @@
* Pre-processor Definitions
****************************************************************************/
/* RMT gpio */
#define RMT_RXCHANNEL 2
#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 8
#endif
/****************************************************************************
* Public Types
****************************************************************************/

View File

@ -60,6 +60,10 @@
# include <nuttx/input/buttons.h>
#endif
#ifdef CONFIG_ESP_RMT
# include "esp_board_rmt.h"
#endif
#include "esp32h2-devkit.h"
/****************************************************************************
@ -147,6 +151,20 @@ int esp_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
/* Initialize the RTC driver */