boards/arm/rp2040: Add ADS7046 example config

Add a new defconfig that includes support for an ADS7046 sensor
and extend the existing documentation to include its description.

Signed-off-by: Niccolò Maggioni <nicco.maggioni+nuttx@gmail.com>
This commit is contained in:
Niccolò Maggioni
2025-08-19 17:28:44 +02:00
committed by Xiang Xiao
parent 7a2343f1be
commit 3e70a7edc7
6 changed files with 309 additions and 4 deletions

View File

@@ -133,6 +133,34 @@ the ``nuttx`` directory (again, consult the main :doc:`RP2040 documentation
$ ./tools/configure.sh raspberrypi-pico:<configname>
ads7046
-------
NuttShell configuration (console enabled in USB Port, at 115200 bps) with support for Texas Instruments ADS7046 ADC:
.. list-table:: ADS7046 connections
:widths: auto
:header-rows: 1
* - ADS7046
- Raspberry Pi Pico
* - GND
- GND (Pin 3 or 38 or ...)
* - DVDD
- 3V3 OUT (Pin 36)
* - SCLK
- GP10 (SPI1 SCK) (Pin 14)
* - CS
- GP13 (SPI1 CSn) (Pin 17)
* - SDO
- GP12 (SPI1 RX) (Pin 16)
.. code-block:: console
nsh> ads7046
ADS7046: hex=106, dec=262, adc_percentage=6%
nsh>
audiopack
---------

View File

@@ -0,0 +1,87 @@
/****************************************************************************
* boards/arm/rp2040/common/include/rp2040_ads7046.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_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H
#define __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spi/spi.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Type 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_ads7046_initialize
*
* Description:
* Initialize and register the ADS7046 ADC driver.
*
* Input Parameters:
* spi - An instance of the SPI interface to use.
* devno - The device number, used to build the device path as /dev/adcN.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_ads7046_initialize(FAR struct spi_dev_s *spi, int devno);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H */

View File

@@ -113,6 +113,10 @@ ifeq ($(CONFIG_SENSORS_TMP112),y)
CSRCS += rp2040_tmp112.c
endif
ifeq ($(CONFIG_ADC_ADS7046),y)
CSRCS += rp2040_ads7046.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

View File

@@ -0,0 +1,103 @@
/****************************************************************************
* boards/arm/rp2040/common/src/rp2040_ads7046.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 <debug.h>
#include <nuttx/arch.h>
#include <nuttx/analog/ads7046.h>
#include "rp2040_spi.h"
#include "rp2040_ads7046.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_ads7046_initialize
*
* Description:
* Initialize and register the ADS7046 ADC driver.
*
* Input Parameters:
* spi - An instance of the SPI interface to use.
* devno - The device number, used to build the device path as /dev/adcN.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_ads7046_initialize(FAR struct spi_dev_s *spi, int devno)
{
char devpath[10];
int ret;
ainfo("Initializing ADS7046 #%d\n", devno);
if (spi)
{
snprintf(devpath, sizeof(devpath), "/dev/adc%d", devno);
ret = ads7046_register(devpath, spi, devno);
if (ret < 0)
{
snerr("ERROR: Error registering ADS7046 at /dev/adc%d\n", devno);
}
}
else
{
ret = -ENODEV;
}
return ret;
}

View File

@@ -111,6 +111,13 @@
#include "rp2040_spi.h"
#endif
#if defined(CONFIG_ADC) && defined(CONFIG_ADC_ADS7046)
#include <nuttx/analog/ads7046.h>
#include <nuttx/analog/adc.h>
#include "rp2040_spi.h"
#include "rp2040_ads7046.h"
#endif
#if defined(CONFIG_RP2040_BOARD_HAS_WS2812) && defined(CONFIG_WS2812)
#include "rp2040_ws2812.h"
#endif
@@ -471,15 +478,15 @@ int rp2040_common_bringup(void)
#endif
#ifdef CONFIG_ADC_MCP3008
/* Register MCP3008 ADC. */
/* Register the MCP3008 ADC. */
struct spi_dev_s *spi = rp2040_spibus_initialize(0);
if (spi == NULL)
struct spi_dev_s *mcp3008_spi = rp2040_spibus_initialize(0);
if (mcp3008_spi == NULL)
{
syslog(LOG_ERR, "Failed to initialize SPI bus 0\n");
}
struct adc_dev_s *mcp3008 = mcp3008_initialize(spi);
struct adc_dev_s *mcp3008 = mcp3008_initialize(mcp3008_spi);
if (mcp3008 == NULL)
{
syslog(LOG_ERR, "Failed to initialize MCP3008\n");
@@ -492,6 +499,22 @@ int rp2040_common_bringup(void)
}
#endif
#ifdef CONFIG_ADC_ADS7046
/* Register the ADS7046 ADC. */
struct spi_dev_s *ads7046_spi = rp2040_spibus_initialize(1);
if (ads7046_spi == NULL)
{
syslog(LOG_ERR, "Failed to initialize SPI bus 1\n");
}
ret = board_ads7046_initialize(ads7046_spi, 0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize ADS7046 driver: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */

View File

@@ -0,0 +1,60 @@
#
# 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_DEV_CONSOLE is not set
# CONFIG_LIBC_LONG_LONG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_DATE is not set
# CONFIG_NSH_DISABLE_LOSMART is not set
# CONFIG_RP2040_UART0 is not set
CONFIG_ADC=y
CONFIG_ADC_ADS7046=y
CONFIG_ANALOG=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="raspberrypi-pico"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y
CONFIG_ARCH_CHIP="rp2040"
CONFIG_ARCH_CHIP_RP2040=y
CONFIG_ARCH_RAMVECTORS=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=10450
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_EXAMPLES_ADS7046=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_READLINE=y
CONFIG_NSH_USBCONSOLE=y
CONFIG_RAM_SIZE=270336
CONFIG_RAM_START=0x20000000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RP2040_SPI1=y
CONFIG_RP2040_SPI1_CS_GPIO=13
CONFIG_RP2040_SPI1_RX_GPIO=12
CONFIG_RP2040_SPI=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=9
CONFIG_START_MONTH=2
CONFIG_START_YEAR=2021
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_USBDEV=y
CONFIG_USBDEV_BUSPOWERED=y