boards/risc-v: ADC support on Espressif devices

Adds adc defconfig and board support for: esp32c3-generic, esp32c6-devkitc and esp32h2-devkit.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
This commit is contained in:
Filipe Cavalcanti 2025-03-26 08:14:32 -03:00 committed by Xiang Xiao
parent 643b3586c3
commit 238a5250f6
15 changed files with 848 additions and 0 deletions

View file

@ -0,0 +1,79 @@
/****************************************************************************
* boards/risc-v/esp32c3/common/include/esp_board_adc.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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_RISCV_ESP32C3_COMMON_INCLUDE_ESP32C3_BOARD_ADC_H
#define __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP32C3_BOARD_ADC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_ADC
int board_adc_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP32C3_BOARD_ADC_H */

View file

@ -22,6 +22,10 @@
ifeq ($(CONFIG_ARCH_BOARD_COMMON),y)
ifeq ($(CONFIG_ESPRESSIF_ADC),y)
CSRCS += esp_board_adc.c
endif
ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif

View file

@ -0,0 +1,138 @@
/****************************************************************************
* boards/risc-v/esp32c3/common/src/esp_board_adc.c
*
* SPDX-License-Identifier: Apache-2.0
*
* 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 <stdio.h>
#include <syslog.h>
#include <nuttx/analog/adc.h>
#include "espressif/esp_adc.h"
#include "esp_board_adc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The number of channels for each ADC */
#define ADC_MAX_CHANNELS 5
/****************************************************************************
* Private Data
****************************************************************************/
/* Select channels to be used for each ADC.
*
* GPIOs are fixed for each channel and configured in the lower-half driver.
*
* ADC 1
* Channel: 0 1 2 3 4 5
* GPIO: 0 1 2 3 4 5
*
* On the chanlist arrays below, channels are added +1. Do not change.
*/
#ifdef CONFIG_ESPRESSIF_ADC_1
static const uint8_t g_chanlist_adc1[ADC_MAX_CHANNELS] =
{
#ifdef CONFIG_ESPRESSIF_ADC_1_CH0
1,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH1
2,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH2
3,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH3
4,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH4
5,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH5
6,
#endif
};
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
int board_adc_init(void)
{
int ret;
struct adc_dev_s *adcdev;
adcdev = kmm_malloc(sizeof(struct adc_dev_s));
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to allocate adc_dev_s instance\n");
return -ENOMEM;
}
memset(adcdev, 0, sizeof(struct adc_dev_s));
adcdev = esp_adc_initialize(1, g_chanlist_adc1);
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to initialize ADC1\n");
return -ENODEV;
}
/* Register the ADC driver at "/dev/adcx" */
ret = adc_register("/dev/adc0", adcdev);
if (ret < 0)
{
kmm_free(adcdev);
syslog(LOG_ERR, "ERROR: adc_register /dev/adc0 failed: %d\n", ret);
}
return ret;
}

View file

@ -0,0 +1,48 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c3-generic"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C3_GENERIC=y
CONFIG_ARCH_CHIP="esp32c3"
CONFIG_ARCH_CHIP_ESP32C3_GENERIC=y
CONFIG_ARCH_INTERRUPTSTACK=1536
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_ESPRESSIF_ADC=y
CONFIG_EXAMPLES_ADC=y
CONFIG_EXAMPLES_ADC_SWTRIG=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y

View file

@ -41,6 +41,10 @@
#include "esp_board_i2c.h"
#include "esp_board_bmp180.h"
#ifdef CONFIG_ESPRESSIF_ADC
# include "esp_board_adc.h"
#endif
#ifdef CONFIG_WATCHDOG
# include "espressif/esp_wdt.h"
#endif
@ -399,6 +403,14 @@ int esp_bringup(void)
}
#endif
#ifdef CONFIG_ESPRESSIF_ADC
ret = board_adc_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize ADC driver: %d\n", ret);
}
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.

View file

@ -0,0 +1,79 @@
/****************************************************************************
* boards/risc-v/esp32c6/common/include/esp_board_adc.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H
#define __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_ADC
int board_adc_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H */

View file

@ -22,6 +22,10 @@
ifeq ($(CONFIG_ARCH_BOARD_COMMON),y)
ifeq ($(CONFIG_ESPRESSIF_ADC),y)
CSRCS += esp_board_adc.c
endif
ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif

View file

@ -0,0 +1,141 @@
/****************************************************************************
* boards/risc-v/esp32c6/common/src/esp_board_adc.c
*
* SPDX-License-Identifier: Apache-2.0
*
* 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 <stdio.h>
#include <syslog.h>
#include <nuttx/analog/adc.h>
#include "espressif/esp_adc.h"
#include "esp_board_adc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The number of channels for each ADC */
#define ADC_MAX_CHANNELS 7
/****************************************************************************
* Private Data
****************************************************************************/
/* Select channels to be used for each ADC.
*
* GPIOs are fixed for each channel and configured in the lower-half driver.
*
* ADC 1
* Channel: 0 1 2 3 4 5 6
* GPIO: 0 1 2 3 4 5 6
*
* On the chanlist arrays below, channels are added +1. Do not change.
*/
#ifdef CONFIG_ESPRESSIF_ADC_1
static const uint8_t g_chanlist_adc1[ADC_MAX_CHANNELS] =
{
#ifdef CONFIG_ESPRESSIF_ADC_1_CH0
1,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH1
2,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH2
3,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH3
4,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH4
5,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH5
6,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH6
7,
#endif
};
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
int board_adc_init(void)
{
int ret;
struct adc_dev_s *adcdev;
adcdev = kmm_malloc(sizeof(struct adc_dev_s));
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to allocate adc_dev_s instance\n");
return -ENOMEM;
}
memset(adcdev, 0, sizeof(struct adc_dev_s));
adcdev = esp_adc_initialize(1, g_chanlist_adc1);
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to initialize ADC1\n");
return -ENODEV;
}
/* Register the ADC driver at "/dev/adcx" */
ret = adc_register("/dev/adc0", adcdev);
if (ret < 0)
{
kmm_free(adcdev);
syslog(LOG_ERR, "ERROR: adc_register /dev/adc0 failed: %d\n", ret);
}
return ret;
}

View file

@ -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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c6-devkitc"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C6_DEVKITC=y
CONFIG_ARCH_CHIP="esp32c6"
CONFIG_ARCH_CHIP_ESP32C6=y
CONFIG_ARCH_CHIP_ESP32C6WROOM1=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_ESPRESSIF_ADC=y
CONFIG_ESPRESSIF_ESP32C6=y
CONFIG_EXAMPLES_ADC=y
CONFIG_EXAMPLES_ADC_SWTRIG=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y

View file

@ -41,6 +41,10 @@
#include "esp_board_i2c.h"
#include "esp_board_bmp180.h"
#ifdef CONFIG_ESPRESSIF_ADC
# include "esp_board_adc.h"
#endif
#ifdef CONFIG_WATCHDOG
# include "espressif/esp_wdt.h"
#endif
@ -422,6 +426,16 @@ int esp_bringup(void)
}
#endif
#ifdef CONFIG_ESPRESSIF_ADC
/* Initialize and register the pcnt/qencoder driver */
ret = board_adc_init();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_adc_init failed: %d\n", ret);
}
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.

View file

@ -0,0 +1,79 @@
/****************************************************************************
* boards/risc-v/esp32h2/common/include/esp_board_adc.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H
#define __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_ADC
int board_adc_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP32C6_BOARD_ADC_H */

View file

@ -22,6 +22,10 @@
ifeq ($(CONFIG_ARCH_BOARD_COMMON),y)
ifeq ($(CONFIG_ESPRESSIF_ADC),y)
CSRCS += esp_board_adc.c
endif
ifeq ($(CONFIG_ESPRESSIF_LEDC),y)
CSRCS += esp_board_ledc.c
endif

View file

@ -0,0 +1,135 @@
/****************************************************************************
* boards/risc-v/esp32h2/common/src/esp_board_adc.c
*
* SPDX-License-Identifier: Apache-2.0
*
* 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 <stdio.h>
#include <syslog.h>
#include <nuttx/analog/adc.h>
#include "espressif/esp_adc.h"
#include "esp_board_adc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The number of channels for each ADC */
#define ADC_MAX_CHANNELS 7
/****************************************************************************
* Private Data
****************************************************************************/
/* Select channels to be used for each ADC.
*
* GPIOs are fixed for each channel and configured in the lower-half driver.
*
* ADC 1
* Channel: 0 1 2 3 4
* GPIO: 1 2 3 4 5
*
* On the chanlist arrays below, channels are added +1. Do not change.
*/
#ifdef CONFIG_ESPRESSIF_ADC_1
static const uint8_t g_chanlist_adc1[ADC_MAX_CHANNELS] =
{
#ifdef CONFIG_ESPRESSIF_ADC_1_CH0
1,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH1
2,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH2
3,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH3
4,
#endif
#ifdef CONFIG_ESPRESSIF_ADC_1_CH4
5,
#endif
};
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_adc_init
*
* Description:
* This function configures and initializes the ADC driver for the board.
* It allocates memory for the ADC device structure, sets up the ADC
* hardware, and registers the ADC device with the system.
*
* Input Parameters:
* None.
*
* Returned Value:
* Returns zero (OK) on successful initialization and registration of the
* ADC device; a negated errno value is returned to indicate the nature
* of any failure.
*
****************************************************************************/
int board_adc_init(void)
{
int ret;
struct adc_dev_s *adcdev;
adcdev = kmm_malloc(sizeof(struct adc_dev_s));
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to allocate adc_dev_s instance\n");
return -ENOMEM;
}
memset(adcdev, 0, sizeof(struct adc_dev_s));
adcdev = esp_adc_initialize(1, g_chanlist_adc1);
if (adcdev == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to initialize ADC1\n");
return -ENODEV;
}
/* Register the ADC driver at "/dev/adcx" */
ret = adc_register("/dev/adc0", adcdev);
if (ret < 0)
{
kmm_free(adcdev);
syslog(LOG_ERR, "ERROR: adc_register /dev/adc0 failed: %d\n", ret);
}
return ret;
}

View file

@ -0,0 +1,49 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32h2-devkit"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32H2_DEVKIT=y
CONFIG_ARCH_CHIP="esp32h2"
CONFIG_ARCH_CHIP_ESP32H2=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_ESPRESSIF_ADC=y
CONFIG_ESPRESSIF_ESP32H2=y
CONFIG_EXAMPLES_ADC=y
CONFIG_EXAMPLES_ADC_SWTRIG=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y

View file

@ -103,6 +103,10 @@
# include "esp_board_pcnt.h"
#endif
#ifdef CONFIG_ESPRESSIF_ADC
# include "esp_board_adc.h"
#endif
#ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL
# include "espressif/esp_nxdiag.h"
#endif
@ -389,6 +393,14 @@ int esp_bringup(void)
}
#endif
#ifdef CONFIG_ESPRESSIF_ADC
ret = board_adc_init();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_adc_init failed: %d\n", ret);
}
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.