arch/xtensa: add support for capture driver on ESP32 and ESP32|S3|

Squashed:
Initial settings for MCPWM Capture on board level
Created lower half files - compilation ok
Using capture debug features. Simple example on fops works
Successful duty and freq calculation
Documentation update
Fixed and added interupt capabilities for all 3 capture channels
Cleaned defconfig
Renamed macros, added S3 options and moved arch source to common dir
Added support for ESP32S3
Added capture example to defconfig and renamed
This commit is contained in:
Filipe Cavalcanti
2024-06-12 11:41:00 -03:00
committed by Xiang Xiao
parent 92747b7529
commit 365e9e967c
22 changed files with 1453 additions and 2 deletions
@@ -0,0 +1,70 @@
/****************************************************************************
* boards/xtensa/esp32/common/include/esp32_board_mcpwm.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_MCPWM_H
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_MCPWM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef CONFIG_ESP_MCPWM_CAPTURE
/****************************************************************************
* Name: esp32_capture_initialize
*
* Description:
* Initialize and register the capture driver using the MCPWM peripheral.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_capture_initialize(void);
#endif /* CONFIG_ESP_MCPWM_CAPTURE */
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_MCPWM_H */
+4
View File
@@ -152,6 +152,10 @@ ifeq ($(CONFIG_SENSORS_ZEROCROSS),y)
CSRCS += esp32_zerocross.c
endif
ifeq ($(CONFIG_ESP_MCPWM),y)
CSRCS += esp32_board_mcpwm.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
@@ -0,0 +1,120 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_board_mcpwm.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/capture.h>
#include <arch/board/board.h>
#include "espressif/esp_mcpwm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_capture_initialize
*
* Description:
* Initialize MCPWM Capture submodule and register the capture device.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP_MCPWM_CAPTURE
int board_capture_initialize(void)
{
int ret;
struct cap_lowerhalf_s *cap;
#ifdef CONFIG_ESP_MCPWM_CAPTURE_CH0
cap = esp_mcpwm_capture_initialize(0,
CONFIG_ESP_MCPWM_CAPTURE_CH0_GPIO);
if (!cap)
{
syslog(LOG_ERR, "ERROR: Failed to start MCPWM Capture: CH0\n");
return -ENODEV;
}
ret = cap_register("/dev/capture0", cap);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: cap_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_ESP_MCPWM_CAPTURE_CH1
cap = esp_mcpwm_capture_initialize(1,
CONFIG_ESP_MCPWM_CAPTURE_CH1_GPIO);
if (!cap)
{
syslog(LOG_ERR, "ERROR: Failed to start MCPWM Capture: CH1\n");
return -ENODEV;
}
ret = cap_register("/dev/capture1", cap);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: cap_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_ESP_MCPWM_CAPTURE_CH2
cap = esp_mcpwm_capture_initialize(2,
CONFIG_ESP_MCPWM_CAPTURE_CH2_GPIO);
if (!cap)
{
syslog(LOG_ERR, "ERROR: Failed to start MCPWM Capture: CH2\n");
return -ENODEV;
}
ret = cap_register("/dev/capture2", cap);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: cap_register failed: %d\n", ret);
return ret;
}
#endif
return OK;
}
#endif
@@ -0,0 +1,50 @@
#
# 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_MCPWM=y
CONFIG_ESP_MCPWM_CAPTURE=y
CONFIG_ESP_MCPWM_CAPTURE_CH0=y
CONFIG_EXAMPLES_CAPTURE=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_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
@@ -169,6 +169,10 @@
# include "esp32_board_rmt.h"
#endif
#ifdef CONFIG_ESP_MCPWM
# include "esp32_board_mcpwm.h"
#endif
#include "esp32-devkitc.h"
/****************************************************************************
@@ -283,6 +287,14 @@ int esp32_bringup(void)
}
#endif /* CONFIG_ESP32_LEDC */
#ifdef CONFIG_ESP_MCPWM_CAPTURE
ret = board_capture_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_capture_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_SENSORS_MAX6675
ret = board_max6675_initialize(0, 2);
if (ret < 0)