mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
esp32-devkitc: Add board support to Rotary Encoder
Reviewed-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
committed by
Petro Karashchenko
parent
655faa33d4
commit
0dfd1f004d
@@ -0,0 +1,73 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32/common/include/board_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 __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_QENCODER_H
|
||||||
|
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_QENCODER_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_qencoder_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the quadrature encoder driver for the given timer
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_qencoder_initialize(int devno, int timerno);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_QENCODER_H */
|
||||||
@@ -36,6 +36,10 @@ ifeq ($(CONFIG_ESP32_I2S),y)
|
|||||||
CSRCS += esp32_board_i2sdev.c
|
CSRCS += esp32_board_i2sdev.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32_PCNT_AS_QE),y)
|
||||||
|
CSRCS += esp32_qencoder.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_AUDIO_CS4344),y)
|
ifeq ($(CONFIG_AUDIO_CS4344),y)
|
||||||
CSRCS += esp32_cs4344.c
|
CSRCS += esp32_cs4344.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32/common/src/esp32_qencoder.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 <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/sensors/qencoder.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "esp32_qencoder.h"
|
||||||
|
#include "chip.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_qencoder_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the quadrature encoder driver for the given timer
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_qencoder_initialize(int devno, int pcntno)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char devpath[12];
|
||||||
|
|
||||||
|
/* Initialize a quadrature encoder interface. */
|
||||||
|
|
||||||
|
sninfo("Initializing the quadrature encoder using PCNT%d\n", pcntno);
|
||||||
|
snprintf(devpath, sizeof(devpath), "/dev/qe%d", devno);
|
||||||
|
ret = esp32_qeinitialize(devpath, pcntno);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
snerr("ERROR: esp32_qeinitialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -46,6 +46,10 @@
|
|||||||
|
|
||||||
#define GPIO_LED1 2
|
#define GPIO_LED1 2
|
||||||
|
|
||||||
|
/* PCNT Quadrature Encoder IDs */
|
||||||
|
|
||||||
|
#define PCNT_QE0_ID 0
|
||||||
|
|
||||||
/* MCP2515 Interrupt pin */
|
/* MCP2515 Interrupt pin */
|
||||||
|
|
||||||
#define GPIO_MCP2515_IRQ 22
|
#define GPIO_MCP2515_IRQ 22
|
||||||
|
|||||||
@@ -91,6 +91,10 @@
|
|||||||
# include "esp32_i2s.h"
|
# include "esp32_i2s.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_PCNT_AS_QE
|
||||||
|
# include "board_qencoder.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_I2CMULTIPLEXER_TCA9548A
|
#ifdef CONFIG_I2CMULTIPLEXER_TCA9548A
|
||||||
# include "esp32_tca9548a.h"
|
# include "esp32_tca9548a.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -398,6 +402,19 @@ int esp32_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SENSORS_QENCODER
|
||||||
|
/* Initialize and register the qencoder driver */
|
||||||
|
|
||||||
|
ret = board_qencoder_initialize(0, PCNT_QE0_ID);
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to register the qencoder: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Register the TCA9548A Multiplexer before others I2C drivers to allow it
|
/* Register the TCA9548A Multiplexer before others I2C drivers to allow it
|
||||||
* be used by other drivers. Look at esp32_ms5611.c how to use it.
|
* be used by other drivers. Look at esp32_ms5611.c how to use it.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user