esp32-devkitc: Add support to PWM

This commit is contained in:
Alan C. Assis 2022-01-06 14:13:58 -03:00 committed by Petro Karashchenko
parent 4ca38c6c50
commit d7ec3e30ae
5 changed files with 213 additions and 0 deletions

View File

@ -0,0 +1,55 @@
#
# 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_NSH_CMDPARMS is not set
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD="esp32-devkitc"
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_LEDC=y
CONFIG_ESP32_LEDC_CHANNEL0_PIN=12
CONFIG_ESP32_LEDC_CHANNEL1_PIN=13
CONFIG_ESP32_LEDC_CHANNEL2_PIN=14
CONFIG_ESP32_LEDC_CHANNEL3_PIN=15
CONFIG_ESP32_LEDC_TIM0=y
CONFIG_ESP32_LEDC_TIM1=y
CONFIG_ESP32_UART0=y
CONFIG_EXAMPLES_PWM=y
CONFIG_EXAMPLES_PWM_FREQUENCY=10000
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INIT_ENTRYPOINT="nsh_main"
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_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -39,6 +39,10 @@ ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += esp32_gpio.c
endif
ifeq ($(CONFIG_PWM),y)
CSRCS += esp32_ledc.c
endif
ifeq ($(CONFIG_USERLED),y)
CSRCS += esp32_userleds.c
endif

View File

@ -109,6 +109,18 @@ int esp32_mmcsd_initialize(int minor);
int esp32_gpio_init(void);
#endif
/****************************************************************************
* Name: esp32_ledc_setup
*
* Description:
* Initialize LEDC PWM and register the PWM device.
*
****************************************************************************/
#ifdef CONFIG_ESP32_LEDC
int esp32_pwm_setup(void);
#endif
/****************************************************************************
* Name: board_spidev_initialize
*

View File

@ -223,6 +223,14 @@ int esp32_bringup(void)
}
#endif
#ifdef CONFIG_ESP32_LEDC
ret = esp32_pwm_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: esp32_pwm_setup() failed: %d\n", ret);
}
#endif /* CONFIG_ESP32_LEDC */
#ifdef CONFIG_ESP32_RT_TIMER
ret = esp32_rt_timer_init();
if (ret < 0)

View File

@ -0,0 +1,134 @@
/****************************************************************************
* boards/xtensa/esp32/esp32-devkitc/src/esp32_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 "esp32_ledc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_pwm_setup
*
* Description:
* Initialize LEDC PWM and register the PWM device.
*
****************************************************************************/
int esp32_pwm_setup(void)
{
int ret;
struct pwm_lowerhalf_s *pwm;
#ifdef CONFIG_ESP32_LEDC_TIM0
pwm = esp32_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_ESP32_LEDC_TIM1
pwm = esp32_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_ESP32_LEDC_TIM2
pwm = esp32_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
#ifdef CONFIG_ESP32_LEDC_TIM3
pwm = esp32_ledc_init(3);
if (!pwm)
{
syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 3 lower half\n");
return -ENODEV;
}
/* Register the PWM driver at "/dev/pwm3" */
ret = pwm_register("/dev/pwm3", pwm);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
return ret;
}
#endif
return OK;
}