riscv/esp32c3: Add ESP32-C3 LEDC(PWM) driver

This commit is contained in:
Dong Heng
2021-05-03 13:52:39 +08:00
committed by Alan Carvalho de Assis
parent b5ee9b673c
commit beed26b6bf
10 changed files with 3831 additions and 0 deletions
+70
View File
@@ -178,6 +178,11 @@ config ESP32C3_SPI
bool
default n
config ESP32C3_LEDC
bool "LEDC (PWM)"
default n
select PWM
config ESP32C3_GPIO_IRQ
bool "GPIO pin interrupts"
default n
@@ -418,6 +423,71 @@ config ESP32C3_FREERUN
endmenu # Timer/counter Configuration
endif # ESP32C3_TIMER
menu "LEDC configuration"
depends on ESP32C3_LEDC
menuconfig ESP32C3_LEDC_TIM0
bool "Timer 0"
default n
if ESP32C3_LEDC_TIM0
config ESP32C3_LEDC_TIM0_CHANNELS
int "Number of Timer 0 channels"
default 2
endif # ESP32C3_LEDC_TIM0
menuconfig ESP32C3_LEDC_TIM1
bool "Timer 1"
default n
if ESP32C3_LEDC_TIM1
config ESP32C3_LEDC_TIM1_CHANNELS
int "Number of Timer 1 channels"
default 2
endif # ESP32C3_LEDC_TIM1
menuconfig ESP32C3_LEDC_TIM2
bool "Timer 2"
default n
if ESP32C3_LEDC_TIM2
config ESP32C3_LEDC_TIM2_CHANNELS
int "Number of Timer 2 channels"
default 2
endif # ESP32C3_LEDC_TIM2
config ESP32C3_LEDC_CHANNEL0_PIN
int "Channel 0 pin"
default 2
config ESP32C3_LEDC_CHANNEL1_PIN
int "Channel 1 pin"
default 3
config ESP32C3_LEDC_CHANNEL2_PIN
int "Channel 2 pin"
default 4
config ESP32C3_LEDC_CHANNEL3_PIN
int "Channel 3 pin"
default 5
config ESP32C3_LEDC_CHANNEL4_PIN
int "Channel 4 pin"
default 6
config ESP32C3_LEDC_CHANNEL5_PIN
int "Channel 5 pin"
default 7
endmenu # LEDC configuration
menu "Wi-Fi configuration"
depends on ESP32C3_WIRELESS
+4
View File
@@ -121,6 +121,10 @@ endif
CHIP_CSRCS += esp32c3_rtc.c
ifeq ($(CONFIG_ESP32C3_LEDC),y)
CHIP_CSRCS += esp32c3_ledc.c
endif
ifeq ($(CONFIG_ESP32C3_WIRELESS),y)
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty
WIRELESS_DRV_ID = 2b53111
File diff suppressed because it is too large Load Diff
+52
View File
@@ -0,0 +1,52 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_ledc.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_RISCV_SRC_ESP32C3_ESP32C3_LEDC_H
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_LEDC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/timers/pwm.h>
/****************************************************************************
* Public functions
****************************************************************************/
/****************************************************************************
* Name: esp32c3_ledc_init
*
* Description:
* Initialize one LEDC timer for use with the upper_level PWM driver.
*
* Input Parameters:
* timer - A number identifying the timer use.
*
* Returned Value:
* On success, a pointer to the ESP32-C3 LEDC lower half PWM driver is
* returned. NULL is returned on any failure.
*
****************************************************************************/
struct pwm_lowerhalf_s *esp32c3_ledc_init(int timer);
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_LEDC_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,47 @@
#
# 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_NSH_CMDPARMS is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c3-devkit"
CONFIG_ARCH_BOARD_ESP32C3_DEVKIT=y
CONFIG_ARCH_CHIP="esp32c3"
CONFIG_ARCH_CHIP_ESP32C3=y
CONFIG_ARCH_CHIP_ESP32C3WROOM02=y
CONFIG_ARCH_INTERRUPTSTACK=1536
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DEV_ZERO=y
CONFIG_ESP32C3_LEDC=y
CONFIG_ESP32C3_LEDC_TIM0=y
CONFIG_EXAMPLES_PWM=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_MAX_TASKS=8
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_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"
@@ -66,6 +66,10 @@ ifeq ($(CONFIG_ONESHOT),y)
CSRCS += esp32c3_oneshot.c
endif
ifeq ($(CONFIG_PWM),y)
CSRCS += esp32c3_ledc.c
endif
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32c3.template.ld
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32c3_out.ld
@@ -181,5 +181,17 @@ int board_bmp180_initialize(int devno, int busno);
int esp32c3_spiflash_init(void);
#endif
/****************************************************************************
* Name: esp32c3_ledc_setup
*
* Description:
* Initialize LEDC PWM and register the PWM device.
*
****************************************************************************/
#ifdef CONFIG_ESP32C3_LEDC
int esp32c3_pwm_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C3_ESP32C3_DEVKIT_SRC_ESP32C3_DEVKIT_H */
@@ -283,6 +283,14 @@ int esp32c3_bringup(void)
#endif
#ifdef CONFIG_ESP32C3_LEDC
ret = esp32c3_pwm_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: esp32c3_pwm_setup() failed: %d\n", ret);
}
#endif /* CONFIG_ESP32C3_LEDC */
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.
@@ -0,0 +1,116 @@
/****************************************************************************
* boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_ledc.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 <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/timers/pwm.h>
#include <arch/board/board.h>
#include "chip.h"
#include "esp32c3_ledc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32c3_pwm_setup
*
* Description:
* Initialize LEDC PWM and register the PWM device.
*
****************************************************************************/
int esp32c3_pwm_setup(void)
{
int ret;
struct pwm_lowerhalf_s *pwm;
#ifdef CONFIG_ESP32C3_LEDC_TIM0
pwm = esp32c3_ledc_init(0);
if (!pwm)
{
syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 0 lower half\n");
return -ENODEV;
}
/* Register the PWM driver at "/dev/pwm0" */
ret = pwm_register("/dev/pwm0", pwm);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_ESP32C3_LEDC_TIM1
pwm = esp32c3_ledc_init(1);
if (!pwm)
{
syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 1 lower half\n");
return -ENODEV;
}
/* Register the PWM driver at "/dev/pwm1" */
ret = pwm_register("/dev/pwm1", pwm);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_ESP32C3_LEDC_TIM2
pwm = esp32c3_ledc_init(2);
if (!pwm)
{
syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 2 lower half\n");
return -ENODEV;
}
/* Register the PWM driver at "/dev/pwm2" */
ret = pwm_register("/dev/pwm2", pwm);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
return ret;
}
#endif
return OK;
}