esp32: Add PWM support using the LEDC peripheral

Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Alan C. Assis
2022-01-06 14:12:55 -03:00
committed by Petro Karashchenko
parent e7f9c7af21
commit 4ca38c6c50
5 changed files with 5149 additions and 3 deletions
+89 -3
View File
@@ -324,11 +324,12 @@ config ESP32_I2S1
No yet implemented
config ESP32_LEDC
bool "LED PWM (LEDC)"
bool "LEDC (PWM)"
default n
depends on EXPERIMENTAL
select PWM
select ARCH_HAVE_PWM_MULTICHAN
---help---
No yet implemented
Enable support to PWM on ESP32 using LEDC peripheral.
config ESP32_PCNT
bool "Pulse Count Module (PCNT)"
@@ -1282,6 +1283,91 @@ config ESP32_FREERUN
endmenu # Timer/counter Configuration
endif # ESP32_TIMER
menu "LEDC configuration"
depends on ESP32_LEDC
menuconfig ESP32_LEDC_TIM0
bool "Timer 0"
default n
if ESP32_LEDC_TIM0
config ESP32_LEDC_TIM0_CHANNELS
int "Number of Timer 0 channels"
default 2
endif # ESP32_LEDC_TIM0
menuconfig ESP32_LEDC_TIM1
bool "Timer 1"
default n
if ESP32_LEDC_TIM1
config ESP32_LEDC_TIM1_CHANNELS
int "Number of Timer 1 channels"
default 2
endif # ESP32_LEDC_TIM1
menuconfig ESP32_LEDC_TIM2
bool "Timer 2"
default n
if ESP32_LEDC_TIM2
config ESP32_LEDC_TIM2_CHANNELS
int "Number of Timer 2 channels"
default 2
endif # ESP32_LEDC_TIM2
menuconfig ESP32_LEDC_TIM3
bool "Timer 3"
default n
if ESP32_LEDC_TIM3
config ESP32_LEDC_TIM3_CHANNELS
int "Number of Timer 3 channels"
default 2
endif # ESP32_LEDC_TIM2
config ESP32_LEDC_CHANNEL0_PIN
int "Channel 0 pin"
default 2
config ESP32_LEDC_CHANNEL1_PIN
int "Channel 1 pin"
default 3
config ESP32_LEDC_CHANNEL2_PIN
int "Channel 2 pin"
default 4
config ESP32_LEDC_CHANNEL3_PIN
int "Channel 3 pin"
default 5
config ESP32_LEDC_CHANNEL4_PIN
int "Channel 4 pin"
default 6
config ESP32_LEDC_CHANNEL5_PIN
int "Channel 5 pin"
default 7
config ESP32_LEDC_CHANNEL6_PIN
int "Channel 6 pin"
default 8
config ESP32_LEDC_CHANNEL7_PIN
int "Channel 7 pin"
default 9
endmenu # LEDC configuration
config ESP32_HAVE_OTA_PARTITION
bool
default n
+4
View File
@@ -95,6 +95,10 @@ ifeq ($(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP),y)
CHIP_CSRCS += esp32_imm.c
endif
ifeq ($(CONFIG_ESP32_LEDC),y)
CHIP_CSRCS += esp32_ledc.c
endif
ifeq ($(CONFIG_ESP32_I2C),y)
CHIP_CSRCS += esp32_i2c.c
endif
File diff suppressed because it is too large Load Diff
+52
View File
@@ -0,0 +1,52 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_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_XTENSA_SRC_ESP32_ESP32_LEDC_H
#define __ARCH_XTENSA_SRC_ESP32_ESP32_LEDC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/timers/pwm.h>
/****************************************************************************
* Public functions
****************************************************************************/
/****************************************************************************
* Name: esp32_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 *esp32_ledc_init(int timer);
#endif /* __ARCH_RISCV_SRC_ESP32_ESP32_LEDC_H */
File diff suppressed because it is too large Load Diff