mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 20:44:39 +08:00
ESP32: Add support to Quadrature Encoder
Reviewed-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
committed by
Petro Karashchenko
parent
947e771c41
commit
655faa33d4
@@ -285,9 +285,8 @@ config ESP32_LEDC
|
||||
Enable support to PWM on ESP32 using LEDC peripheral.
|
||||
|
||||
config ESP32_PCNT
|
||||
bool "Pulse Count Module (PCNT)"
|
||||
bool "Pulse Counter (PCNT / QE) Module"
|
||||
default n
|
||||
depends on EXPERIMENTAL
|
||||
---help---
|
||||
No yet implemented
|
||||
|
||||
@@ -1228,6 +1227,415 @@ endif # ESP32_SPI3
|
||||
|
||||
endmenu # ESP32_SPI
|
||||
|
||||
menu "Pulse Counter (PCNT) Configuration"
|
||||
depends on ESP32_PCNT
|
||||
|
||||
config ESP32_PCNT_AS_QE
|
||||
bool
|
||||
default n
|
||||
|
||||
config ESP32_PCNT_U0
|
||||
bool "Enable PCNT Unit 0"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U0
|
||||
|
||||
config ESP32_PCNT_U0_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U0_CH0_EDGE_PIN
|
||||
int "PCNT_U0 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U0_CH0_LEVEL_PIN
|
||||
int "PCNT_U0 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U0_QE
|
||||
|
||||
config ESP32_PCNT_U0_CH1_EDGE_PIN
|
||||
int "PCNT_U0 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U0_QE
|
||||
|
||||
config ESP32_PCNT_U0_CH1_LEVEL_PIN
|
||||
int "PCNT_U0 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U0_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U0_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U0_FILTER_THRES
|
||||
int "PCNT_U0 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U0_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U0
|
||||
|
||||
config ESP32_PCNT_U1
|
||||
bool "Enable PCNT Unit 1"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U1
|
||||
|
||||
config ESP32_PCNT_U1_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U1_CH0_EDGE_PIN
|
||||
int "PCNT_U1 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U1_CH0_LEVEL_PIN
|
||||
int "PCNT_U1 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U1_QE
|
||||
|
||||
config ESP32_PCNT_U1_CH1_EDGE_PIN
|
||||
int "PCNT_U1 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U1_QE
|
||||
|
||||
config ESP32_PCNT_U1_CH1_LEVEL_PIN
|
||||
int "PCNT_U1 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U1_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U1_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U1_FILTER_THRES
|
||||
int "PCNT_U1 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U1_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U1
|
||||
|
||||
config ESP32_PCNT_U2
|
||||
bool "Enable PCNT Unit 2"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U2
|
||||
|
||||
config ESP32_PCNT_U2_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U2_CH0_EDGE_PIN
|
||||
int "PCNT_U2 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U2_CH0_LEVEL_PIN
|
||||
int "PCNT_U2 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U2_QE
|
||||
|
||||
config ESP32_PCNT_U2_CH1_EDGE_PIN
|
||||
int "PCNT_U2 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U2_QE
|
||||
|
||||
config ESP32_PCNT_U2_CH1_LEVEL_PIN
|
||||
int "PCNT_U2 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U2_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U2_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U2_FILTER_THRES
|
||||
int "PCNT_U2 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U2_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U2
|
||||
|
||||
config ESP32_PCNT_U3
|
||||
bool "Enable PCNT Unit 3"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U3
|
||||
|
||||
config ESP32_PCNT_U3_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U3_CH0_EDGE_PIN
|
||||
int "PCNT_U3 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U3_CH0_LEVEL_PIN
|
||||
int "PCNT_U3 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U3_QE
|
||||
|
||||
config ESP32_PCNT_U3_CH1_EDGE_PIN
|
||||
int "PCNT_U3 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U3_QE
|
||||
|
||||
config ESP32_PCNT_U3_CH1_LEVEL_PIN
|
||||
int "PCNT_U3 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U3_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U3_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U3_FILTER_THRES
|
||||
int "PCNT_U3 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U3_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U3
|
||||
|
||||
config ESP32_PCNT_U4
|
||||
bool "Enable PCNT Unit 4"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U4
|
||||
|
||||
config ESP32_PCNT_U4_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U4_CH0_EDGE_PIN
|
||||
int "PCNT_U4 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U4_CH0_LEVEL_PIN
|
||||
int "PCNT_U4 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U4_QE
|
||||
|
||||
config ESP32_PCNT_U4_CH1_EDGE_PIN
|
||||
int "PCNT_U4 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U4_QE
|
||||
|
||||
config ESP32_PCNT_U4_CH1_LEVEL_PIN
|
||||
int "PCNT_U4 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U4_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U4_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U4_FILTER_THRES
|
||||
int "PCNT_U4 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U4_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U4
|
||||
|
||||
config ESP32_PCNT_U5
|
||||
bool "Enable PCNT Unit 5"
|
||||
default n
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
if ESP32_PCNT_U5
|
||||
|
||||
config ESP32_PCNT_U5_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
|
||||
config ESP32_PCNT_U5_CH0_EDGE_PIN
|
||||
int "PCNT_U5 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U5_CH0_LEVEL_PIN
|
||||
int "PCNT_U5 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U5_QE
|
||||
|
||||
config ESP32_PCNT_U5_CH1_EDGE_PIN
|
||||
int "PCNT_U5 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U5_QE
|
||||
|
||||
config ESP32_PCNT_U5_CH1_LEVEL_PIN
|
||||
int "PCNT_U5 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U5_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U5_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U5_FILTER_THRES
|
||||
int "PCNT_U5 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U5_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U5
|
||||
|
||||
config ESP32_PCNT_U6
|
||||
bool "Enable PCNT Unit 6"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U6
|
||||
|
||||
config ESP32_PCNT_U6_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U6_CH0_EDGE_PIN
|
||||
int "PCNT_U6 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U6_CH0_LEVEL_PIN
|
||||
int "PCNT_U6 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U6_QE
|
||||
|
||||
config ESP32_PCNT_U6_CH1_EDGE_PIN
|
||||
int "PCNT_U6 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U6_QE
|
||||
|
||||
config ESP32_PCNT_U6_CH1_LEVEL_PIN
|
||||
int "PCNT_U6 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U6_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U6_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U6_FILTER_THRES
|
||||
int "PCNT_U6 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U6_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U6
|
||||
|
||||
config ESP32_PCNT_U7
|
||||
bool "Enable PCNT Unit 7"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U7
|
||||
|
||||
config ESP32_PCNT_U7_QE
|
||||
bool "Use this PCNT Unit as Quadrature Encoder"
|
||||
default y
|
||||
select ESP32_PCNT_AS_QE
|
||||
|
||||
config ESP32_PCNT_U7_CH0_EDGE_PIN
|
||||
int "PCNT_U7 CH0 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U7_CH0_LEVEL_PIN
|
||||
int "PCNT_U7 CH0 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U7_QE
|
||||
|
||||
config ESP32_PCNT_U7_CH1_EDGE_PIN
|
||||
int "PCNT_U7 CH1 Edge/Pulse Pin Number"
|
||||
default 0
|
||||
range -1 39
|
||||
depends on !ESP32_PCNT_U7_QE
|
||||
|
||||
config ESP32_PCNT_U7_CH1_LEVEL_PIN
|
||||
int "PCNT_U7 CH1 Level/Control Pin Number"
|
||||
default 4
|
||||
range -1 39
|
||||
|
||||
config ESP32_PCNT_U7_FILTER_EN
|
||||
bool "Enable Glitch Filter for this PCNT Unit"
|
||||
default n
|
||||
|
||||
if ESP32_PCNT_U7_FILTER_EN
|
||||
|
||||
config ESP32_PCNT_U7_FILTER_THRES
|
||||
int "PCNT_U7 Filter Threshold value"
|
||||
default 5
|
||||
---help---
|
||||
If a pulse is shorter than this number of APB_CLK clock cycles
|
||||
then it will not be considered as a valid pulse.
|
||||
|
||||
endif # ESP32_PCNT_U7_FILTER_EN
|
||||
|
||||
endif # ESP32_PCNT_U7
|
||||
|
||||
endmenu # ESP32_PCNT
|
||||
|
||||
menu "SPI Flash configuration"
|
||||
depends on ESP32_SPIFLASH
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ ifeq ($(CONFIG_ESP32_TWAI),y)
|
||||
CHIP_CSRCS += esp32_twai.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ESP32_PCNT_AS_QE),y)
|
||||
CHIP_CSRCS += esp32_qencoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ESP32_SPI),y)
|
||||
CHIP_CSRCS += esp32_spi.c
|
||||
ifeq ($(CONFIG_SPI_SLAVE),y)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
* arch/xtensa/src/esp32/esp32_qencoder.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_QENCODER_H
|
||||
#define __ARCH_XTENSA_SRC_ESP32_ESP32_QENCODER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Timer devices may be used for different purposes. One special purpose is
|
||||
* as a quadrature encoder input device. If CONFIG_ESP32_PCNT_Un is defined
|
||||
* then the CONFIG_ESP32_PCNT_Un_QE must also be defined to indicate that
|
||||
* pcnt "n" is intended to be used for as a quadrature encoder.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_ESP32_PCNT_U0
|
||||
# undef CONFIG_ESP32_PCNT_U0_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U1
|
||||
# undef CONFIG_ESP32_PCNT_U1_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U2
|
||||
# undef CONFIG_ESP32_PCNT_U2_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U3
|
||||
# undef CONFIG_ESP32_PCNT_U3_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U4
|
||||
# undef CONFIG_ESP32_PCNT_U4_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U5
|
||||
# undef CONFIG_ESP32_PCNT_U5_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U6
|
||||
# undef CONFIG_ESP32_PCNT_U6_QE
|
||||
#endif
|
||||
#ifndef CONFIG_ESP32_PCNT_U7
|
||||
# undef CONFIG_ESP32_PCNT_U7_QE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_qeinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize a quadrature encoder interface. This function must be called
|
||||
* from board-specific logic..
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/qe0"
|
||||
* pcnt - The PCNT number to used. 'tim' must be an element of
|
||||
* {0,1,2,3,4,5,6,7}
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; A negated errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_qeinitialize(const char *devpath, int pcnt);
|
||||
|
||||
#ifdef CONFIG_ESP32_QENCODER_INDEX_PIN
|
||||
/****************************************************************************
|
||||
* Name: esp32_qe_index_init
|
||||
*
|
||||
* Description:
|
||||
* Register the encoder index pin to a given Qencoder timer
|
||||
*
|
||||
* Input Parameters:
|
||||
* pcnt - The qencoder PCNT number
|
||||
* gpio - gpio pin configuration
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; A negated errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_qe_index_init(int pcnt, uint32_t gpio);
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SENSORS_QENCODER */
|
||||
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_QENCODER_H */
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user