Skip to content

Commit 3e70a7e

Browse files
nmaggionixiaoxiang781216
authored andcommitted
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>
1 parent 7a2343f commit 3e70a7e

6 files changed

Lines changed: 309 additions & 4 deletions

File tree

Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ the ``nuttx`` directory (again, consult the main :doc:`RP2040 documentation
133133
134134
$ ./tools/configure.sh raspberrypi-pico:<configname>
135135
136+
ads7046
137+
-------
138+
139+
NuttShell configuration (console enabled in USB Port, at 115200 bps) with support for Texas Instruments ADS7046 ADC:
140+
141+
.. list-table:: ADS7046 connections
142+
:widths: auto
143+
:header-rows: 1
144+
145+
* - ADS7046
146+
- Raspberry Pi Pico
147+
* - GND
148+
- GND (Pin 3 or 38 or ...)
149+
* - DVDD
150+
- 3V3 OUT (Pin 36)
151+
* - SCLK
152+
- GP10 (SPI1 SCK) (Pin 14)
153+
* - CS
154+
- GP13 (SPI1 CSn) (Pin 17)
155+
* - SDO
156+
- GP12 (SPI1 RX) (Pin 16)
157+
158+
.. code-block:: console
159+
160+
nsh> ads7046
161+
ADS7046: hex=106, dec=262, adc_percentage=6%
162+
nsh>
163+
136164
audiopack
137165
---------
138166

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/****************************************************************************
2+
* boards/arm/rp2040/common/include/rp2040_ads7046.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H
24+
#define __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
#include <nuttx/spi/spi.h>
32+
33+
/****************************************************************************
34+
* Pre-processor Definitions
35+
****************************************************************************/
36+
37+
/****************************************************************************
38+
* Type Definitions
39+
****************************************************************************/
40+
41+
/****************************************************************************
42+
* Public Types
43+
****************************************************************************/
44+
45+
/****************************************************************************
46+
* Public Data
47+
****************************************************************************/
48+
49+
#ifdef __cplusplus
50+
#define EXTERN extern "C"
51+
extern "C"
52+
{
53+
#else
54+
#define EXTERN extern
55+
#endif
56+
57+
/****************************************************************************
58+
* Inline Functions
59+
****************************************************************************/
60+
61+
/****************************************************************************
62+
* Public Function Prototypes
63+
****************************************************************************/
64+
65+
/****************************************************************************
66+
* Name: board_ads7046_initialize
67+
*
68+
* Description:
69+
* Initialize and register the ADS7046 ADC driver.
70+
*
71+
* Input Parameters:
72+
* spi - An instance of the SPI interface to use.
73+
* devno - The device number, used to build the device path as /dev/adcN.
74+
*
75+
* Returned Value:
76+
* Zero (OK) on success; a negated errno value on failure.
77+
*
78+
****************************************************************************/
79+
80+
int board_ads7046_initialize(FAR struct spi_dev_s *spi, int devno);
81+
82+
#undef EXTERN
83+
#ifdef __cplusplus
84+
}
85+
#endif
86+
87+
#endif /* __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_ADS7046_H */

boards/arm/rp2040/common/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ ifeq ($(CONFIG_SENSORS_TMP112),y)
113113
CSRCS += rp2040_tmp112.c
114114
endif
115115

116+
ifeq ($(CONFIG_ADC_ADS7046),y)
117+
CSRCS += rp2040_ads7046.c
118+
endif
119+
116120
DEPPATH += --dep-path src
117121
VPATH += :src
118122
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/****************************************************************************
2+
* boards/arm/rp2040/common/src/rp2040_ads7046.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdio.h>
30+
#include <debug.h>
31+
32+
#include <nuttx/arch.h>
33+
#include <nuttx/analog/ads7046.h>
34+
35+
#include "rp2040_spi.h"
36+
#include "rp2040_ads7046.h"
37+
38+
/****************************************************************************
39+
* Pre-processor Definitions
40+
****************************************************************************/
41+
42+
/****************************************************************************
43+
* Private Types
44+
****************************************************************************/
45+
46+
/****************************************************************************
47+
* Private Function Prototypes
48+
****************************************************************************/
49+
50+
/****************************************************************************
51+
* Private Data
52+
****************************************************************************/
53+
54+
/****************************************************************************
55+
* Public Data
56+
****************************************************************************/
57+
58+
/****************************************************************************
59+
* Private Functions
60+
****************************************************************************/
61+
62+
/****************************************************************************
63+
* Public Functions
64+
****************************************************************************/
65+
66+
/****************************************************************************
67+
* Name: board_ads7046_initialize
68+
*
69+
* Description:
70+
* Initialize and register the ADS7046 ADC driver.
71+
*
72+
* Input Parameters:
73+
* spi - An instance of the SPI interface to use.
74+
* devno - The device number, used to build the device path as /dev/adcN.
75+
*
76+
* Returned Value:
77+
* Zero (OK) on success; a negated errno value on failure.
78+
*
79+
****************************************************************************/
80+
81+
int board_ads7046_initialize(FAR struct spi_dev_s *spi, int devno)
82+
{
83+
char devpath[10];
84+
int ret;
85+
86+
ainfo("Initializing ADS7046 #%d\n", devno);
87+
88+
if (spi)
89+
{
90+
snprintf(devpath, sizeof(devpath), "/dev/adc%d", devno);
91+
ret = ads7046_register(devpath, spi, devno);
92+
if (ret < 0)
93+
{
94+
snerr("ERROR: Error registering ADS7046 at /dev/adc%d\n", devno);
95+
}
96+
}
97+
else
98+
{
99+
ret = -ENODEV;
100+
}
101+
102+
return ret;
103+
}

boards/arm/rp2040/common/src/rp2040_common_bringup.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@
111111
#include "rp2040_spi.h"
112112
#endif
113113

114+
#if defined(CONFIG_ADC) && defined(CONFIG_ADC_ADS7046)
115+
#include <nuttx/analog/ads7046.h>
116+
#include <nuttx/analog/adc.h>
117+
#include "rp2040_spi.h"
118+
#include "rp2040_ads7046.h"
119+
#endif
120+
114121
#if defined(CONFIG_RP2040_BOARD_HAS_WS2812) && defined(CONFIG_WS2812)
115122
#include "rp2040_ws2812.h"
116123
#endif
@@ -471,15 +478,15 @@ int rp2040_common_bringup(void)
471478
#endif
472479

473480
#ifdef CONFIG_ADC_MCP3008
474-
/* Register MCP3008 ADC. */
481+
/* Register the MCP3008 ADC. */
475482

476-
struct spi_dev_s *spi = rp2040_spibus_initialize(0);
477-
if (spi == NULL)
483+
struct spi_dev_s *mcp3008_spi = rp2040_spibus_initialize(0);
484+
if (mcp3008_spi == NULL)
478485
{
479486
syslog(LOG_ERR, "Failed to initialize SPI bus 0\n");
480487
}
481488

482-
struct adc_dev_s *mcp3008 = mcp3008_initialize(spi);
489+
struct adc_dev_s *mcp3008 = mcp3008_initialize(mcp3008_spi);
483490
if (mcp3008 == NULL)
484491
{
485492
syslog(LOG_ERR, "Failed to initialize MCP3008\n");
@@ -492,6 +499,22 @@ int rp2040_common_bringup(void)
492499
}
493500
#endif
494501

502+
#ifdef CONFIG_ADC_ADS7046
503+
/* Register the ADS7046 ADC. */
504+
505+
struct spi_dev_s *ads7046_spi = rp2040_spibus_initialize(1);
506+
if (ads7046_spi == NULL)
507+
{
508+
syslog(LOG_ERR, "Failed to initialize SPI bus 1\n");
509+
}
510+
511+
ret = board_ads7046_initialize(ads7046_spi, 0);
512+
if (ret < 0)
513+
{
514+
syslog(LOG_ERR, "Failed to initialize ADS7046 driver: %d\n", ret);
515+
}
516+
#endif
517+
495518
#ifdef CONFIG_FS_PROCFS
496519
/* Mount the procfs file system */
497520

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# This file is autogenerated: PLEASE DO NOT EDIT IT.
3+
#
4+
# You can use "make menuconfig" to make any modifications to the installed .config file.
5+
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
6+
# modifications.
7+
#
8+
# CONFIG_DEV_CONSOLE is not set
9+
# CONFIG_LIBC_LONG_LONG is not set
10+
# CONFIG_NSH_ARGCAT is not set
11+
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
12+
# CONFIG_NSH_DISABLE_DATE is not set
13+
# CONFIG_NSH_DISABLE_LOSMART is not set
14+
# CONFIG_RP2040_UART0 is not set
15+
CONFIG_ADC=y
16+
CONFIG_ADC_ADS7046=y
17+
CONFIG_ANALOG=y
18+
CONFIG_ARCH="arm"
19+
CONFIG_ARCH_BOARD="raspberrypi-pico"
20+
CONFIG_ARCH_BOARD_COMMON=y
21+
CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y
22+
CONFIG_ARCH_CHIP="rp2040"
23+
CONFIG_ARCH_CHIP_RP2040=y
24+
CONFIG_ARCH_RAMVECTORS=y
25+
CONFIG_ARCH_STACKDUMP=y
26+
CONFIG_BOARDCTL_RESET=y
27+
CONFIG_BOARD_LOOPSPERMSEC=10450
28+
CONFIG_BUILTIN=y
29+
CONFIG_CDCACM=y
30+
CONFIG_CDCACM_CONSOLE=y
31+
CONFIG_DEBUG_FULLOPT=y
32+
CONFIG_DEBUG_SYMBOLS=y
33+
CONFIG_DISABLE_POSIX_TIMERS=y
34+
CONFIG_EXAMPLES_ADS7046=y
35+
CONFIG_EXAMPLES_HELLO=y
36+
CONFIG_FS_PROCFS=y
37+
CONFIG_FS_PROCFS_REGISTER=y
38+
CONFIG_INIT_ENTRYPOINT="nsh_main"
39+
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
40+
CONFIG_NSH_ARCHINIT=y
41+
CONFIG_NSH_BUILTIN_APPS=y
42+
CONFIG_NSH_READLINE=y
43+
CONFIG_NSH_USBCONSOLE=y
44+
CONFIG_RAM_SIZE=270336
45+
CONFIG_RAM_START=0x20000000
46+
CONFIG_READLINE_CMD_HISTORY=y
47+
CONFIG_RP2040_SPI1=y
48+
CONFIG_RP2040_SPI1_CS_GPIO=13
49+
CONFIG_RP2040_SPI1_RX_GPIO=12
50+
CONFIG_RP2040_SPI=y
51+
CONFIG_RR_INTERVAL=200
52+
CONFIG_SCHED_WAITPID=y
53+
CONFIG_START_DAY=9
54+
CONFIG_START_MONTH=2
55+
CONFIG_START_YEAR=2021
56+
CONFIG_SYSTEM_NSH=y
57+
CONFIG_TESTING_GETPRIME=y
58+
CONFIG_TESTING_OSTEST=y
59+
CONFIG_USBDEV=y
60+
CONFIG_USBDEV_BUSPOWERED=y

0 commit comments

Comments
 (0)