mirror of
https://github.com/apache/nuttx.git
synced 2026-10-03 04:07:55 +00:00
boards/thingy53: add ADC support
add ADC support for thingy53 Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
parent
dff3977d4c
commit
be46d87e1a
5 changed files with 179 additions and 0 deletions
|
|
@ -50,6 +50,10 @@ if(CONFIG_RGBLED)
|
|||
list(APPEND SRCS nrf53_rgbled.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ADC)
|
||||
list(APPEND SRCS nrf53_adc.c)
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
if(CONFIG_ARCH_BOARD_COMMON)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ ifeq ($(CONFIG_RGBLED),y)
|
|||
CSRCS += nrf53_rgbled.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADC),y)
|
||||
CSRCS += nrf53_adc.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path board
|
||||
VPATH += :board
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
|
||||
|
|
|
|||
146
boards/arm/nrf53/thingy53/src/nrf53_adc.c
Normal file
146
boards/arm/nrf53/thingy53/src/nrf53_adc.c
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/****************************************************************************
|
||||
* boards/arm/nrf53/thingy53/src/nrf53_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 <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/analog/adc.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "nrf53_gpio.h"
|
||||
#include "nrf53_adc.h"
|
||||
|
||||
#include "thingy53.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Only one channel supported if TIMER trigger enabled */
|
||||
|
||||
#define ADC_NCHANNELS (1)
|
||||
|
||||
/****************************************************************************
|
||||
* Private data
|
||||
****************************************************************************/
|
||||
|
||||
/* ADC pins configuration */
|
||||
|
||||
static uint32_t g_adc_pins[ADC_NCHANNELS] =
|
||||
{
|
||||
NRF53_ADC_CH0_PIN, /* AIN2 */
|
||||
};
|
||||
|
||||
/* ADC channels configuration */
|
||||
|
||||
static struct nrf53_adc_channel_s g_adc_chanlist[ADC_NCHANNELS] =
|
||||
{
|
||||
/* Channel 0 */
|
||||
|
||||
{
|
||||
.p_psel = NRF53_ADC_IN_IN2, /* AIN2 / P0.06 - BAT_MEAS */
|
||||
.n_psel = 0,
|
||||
#ifdef CONFIG_NRF53_SAADC_LIMITS
|
||||
.limith = 0,
|
||||
.limitl = 0,
|
||||
#endif
|
||||
.resp = NRF53_ADC_RES_BYPASS,
|
||||
.resn = NRF53_ADC_RES_BYPASS,
|
||||
.gain = NRF53_ADC_GAIN_1,
|
||||
.refsel = NRF53_ADC_REFSEL_INTERNAL,
|
||||
.tacq = NRF53_ADC_TACQ_40US,
|
||||
.mode = NRF53_ADC_MODE_SE,
|
||||
.burst = NRF53_ADC_BURST_DISABLE,
|
||||
},
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nrf53_adc_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize ADC and register the ADC device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nrf53_adc_setup(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
struct adc_dev_s *adc = NULL;
|
||||
int ret = OK;
|
||||
int i = 0;
|
||||
|
||||
/* Enable battery measurement.
|
||||
* TODO: this should be controlled by power management logic
|
||||
*/
|
||||
|
||||
nrf53_gpio_config(GPIO_BATT_EN);
|
||||
nrf53_gpio_write(GPIO_BATT_EN, true);
|
||||
|
||||
/* Have we already initialized? */
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
/* Configure ADC pins */
|
||||
|
||||
for (i = 0; i < ADC_NCHANNELS; i += 1)
|
||||
{
|
||||
nrf53_gpio_config(g_adc_pins[i]);
|
||||
}
|
||||
|
||||
/* Call nrf53_adcinitialize() to get an instance of the ADC interface */
|
||||
|
||||
adc = nrf53_adcinitialize(g_adc_chanlist, ADC_NCHANNELS);
|
||||
if (!adc)
|
||||
{
|
||||
aerr("ERROR: Failed to get the NRF53 ADC lower half\n");
|
||||
ret = -ENODEV;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Register the ADC driver at "/dev/adc0" */
|
||||
|
||||
ret = adc_register("/dev/adc0", adc);
|
||||
if (ret < 0)
|
||||
{
|
||||
aerr("ERROR: adc_register failed: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -211,6 +211,7 @@ int nrf53_bringup(void)
|
|||
|
||||
#if defined(CONFIG_RNDIS) && !defined(CONFIG_RNDIS_COMPOSITE)
|
||||
uint8_t mac[6];
|
||||
|
||||
mac[0] = 0xa0; /* TODO */
|
||||
mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff;
|
||||
mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff;
|
||||
|
|
@ -248,6 +249,18 @@ int nrf53_bringup(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ADC
|
||||
/* Configure ADC driver */
|
||||
|
||||
ret = nrf53_adc_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to initialize ADC driver: %d\n",
|
||||
ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize on-board sensors */
|
||||
|
||||
ret = nrf53_sensors_init();
|
||||
|
|
|
|||
|
|
@ -217,5 +217,17 @@ int nrf53_i2ctool(void);
|
|||
void nrf53_spidev_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nrf53_adc_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize ADC driver.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADC
|
||||
int nrf53_adc_setup(void);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_ARM_NRF53_THINGY53_SRC_THINGY53_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue