mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 10:32:47 +08:00
arch/arm/src/samv7: add support for AFEC (ADC) driver
This commit adds microcontroller support for Analog Front End driver to samv7 MCUs. Only software trigger via IOCTL is currently supported, averaging can be set by configuration option CONFIG_SAMV7_AFECn_RES. Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
@@ -196,6 +196,10 @@ config SAMV7_HAVE_MCAN1
|
||||
bool
|
||||
default n
|
||||
|
||||
config SAMV7_AFEC
|
||||
bool
|
||||
default n
|
||||
|
||||
config SAMV7_DAC
|
||||
bool
|
||||
default n
|
||||
@@ -313,10 +317,42 @@ config SAMV7_ADC
|
||||
config SAMV7_AFEC0
|
||||
bool "Analog Front End 0 (AFEC0)"
|
||||
default n
|
||||
select SAMV7_AFEC
|
||||
|
||||
if SAMV7_AFEC0
|
||||
|
||||
config SAMV7_AFEC0_RES
|
||||
int "AFEC0 Resolution"
|
||||
default 0
|
||||
range 0 5
|
||||
---help---
|
||||
0 no average
|
||||
1 low resolution
|
||||
2 OSR4
|
||||
3 OSR16
|
||||
4 OSR64
|
||||
5 OSR256
|
||||
endif
|
||||
|
||||
config SAMV7_AFEC1
|
||||
bool "Analog Front End 1 (AFEC1)"
|
||||
default n
|
||||
select SAMV7_AFEC
|
||||
|
||||
if SAMV7_AFEC1
|
||||
|
||||
config SAMV7_AFEC1_RES
|
||||
int "AFEC1 Resolution"
|
||||
default 0
|
||||
range 0 5
|
||||
---help---
|
||||
0 no average
|
||||
1 low resolution
|
||||
2 OSR4
|
||||
3 OSR16
|
||||
4 OSR64
|
||||
5 OSR256
|
||||
endif
|
||||
|
||||
config SAMV7_MCAN0
|
||||
bool "CAN controller 0 (MCAN0)"
|
||||
|
||||
@@ -166,6 +166,10 @@ ifeq ($(CONFIG_SAMV7_MCAN),y)
|
||||
CHIP_CSRCS += sam_mcan.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SAMV7_AFEC),y)
|
||||
CHIP_CSRCS += sam_afec.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SAMV7_USBDEVHS),y)
|
||||
CHIP_CSRCS += sam_usbdevhs.c
|
||||
endif
|
||||
|
||||
@@ -222,7 +222,9 @@
|
||||
# define AFEC_EMR_CMPFILTER(n) ((uint32_t)(n) << AFEC_EMR_CMPFILTER_SHIFT)
|
||||
#define AFEC_EMR_RES_SHIFT (16) /* Bits 16-18: Resolution */
|
||||
#define AFEC_EMR_RES_MASK (7 << AFEC_EMR_RES_SHIFT)
|
||||
#define AFEC_EMR_RES(n) ((uint32_t)(n) << AFEC_EMR_RES_SHIFT)
|
||||
# define AFEC_EMR_RES_NOAVG (0 << AFEC_EMR_RES_SHIFT) /* 12-bit resolution, AFEC sample rate is maximum (no averaging) */
|
||||
# define AFEC_EMR_RES_LOWRES (1 << AFEC_EMR_RES_SHIFT) /* 10-bit resolution, AFEC sample rate is maximum (no averaging) */
|
||||
# define AFEC_EMR_RES_OSR4 (2 << AFEC_EMR_RES_SHIFT) /* 13-bit resolution, AFEC sample rate divided by 4 (averaging) */
|
||||
# define AFEC_EMR_RES_OSR16 (3 << AFEC_EMR_RES_SHIFT) /* 14-bit resolution, AFEC sample rate divided by 16 (averaging) */
|
||||
# define AFEC_EMR_RES_OSR64 (4 << AFEC_EMR_RES_SHIFT) /* 15-bit resolution, AFEC sample rate divided by 64 (averaging) */
|
||||
@@ -368,10 +370,10 @@
|
||||
/* Compare Window Register */
|
||||
|
||||
#define AFEC_CWR_LOWTHRES_SHIFT (0) /* Bits 0-11: Low Threshold */
|
||||
#define AFEC_CWR_LOWTHRES_MASK (0xfff << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
#define AFEC_CWR_LOWTHRES_MASK (0xffff << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
# define AFEC_CWR_LOWTHRES(n) ((uint32_t)(n) << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
#define AFEC_CWR_HIGHTHRES_SHIFT (16) /* Bits 16-27: High Threshold */
|
||||
#define AFEC_CWR_HIGHTHRES_MASK (0xfff << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
#define AFEC_CWR_HIGHTHRES_MASK (0xffff << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
# define AFEC_CWR_HIGHTHRES(n)K ((uint32_t)(n) << AFEC_CWR_LOWTHRES_SHIFT)
|
||||
|
||||
/* Channel Gain Register */
|
||||
@@ -453,7 +455,7 @@
|
||||
/* Channel Selection Register */
|
||||
|
||||
#define AFEC_CSELR_CSEL_SHIFT (0) /* Bits 0-3: Channel Selection */
|
||||
#define AFEC_CSELR_CSEL_MASK (15 << AFEC_CSELR_CSEL_SHIFT)
|
||||
#define AFEC_CSELR_CSEL_MASK (0xf << AFEC_CSELR_CSEL_SHIFT)
|
||||
# define AFEC_CSELR_CSEL(n) ((uint32_t)(n) << AFEC_CSELR_CSEL_SHIFT)
|
||||
|
||||
/* Channel Data Register */
|
||||
@@ -462,7 +464,7 @@
|
||||
|
||||
/* Channel Offset Compensation Register */
|
||||
|
||||
#define AFEC_COCR_MASK (0x00000fff) /* Bits 0-12: Analog Offset */
|
||||
#define AFEC_COCR_MASK (0x000003ff) /* Bits 0-9: Analog Offset */
|
||||
|
||||
/* Temperature Sensor Mode Register */
|
||||
|
||||
@@ -487,7 +489,7 @@
|
||||
|
||||
#define AFEC_ACR_PGA0EN (1 << 2) /* Bit 2: PGA0 Enable */
|
||||
#define AFEC_ACR_PGA1EN (1 << 3) /* Bit 3: PGA1 Enable */
|
||||
#define AFEC_ACR_IBCTL_SHIFT (9) /* Bits 8-9: AFEC Bias Current Control */
|
||||
#define AFEC_ACR_IBCTL_SHIFT (8) /* Bits 8-9: AFEC Bias Current Control */
|
||||
#define AFEC_ACR_IBCTL_MASK (3 << AFEC_ACR_IBCTL_SHIFT)
|
||||
# define AFEC_ACR_IBCTL(n) ((uint32_t)(n) << AFEC_ACR_IBCTL_SHIFT)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/samv7/sam_afec.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 __ARCH_ARM_SRC_SAMV7_SAM_AFEC_H
|
||||
#define __ARCH_ARM_SRC_SAMV7_SAM_AFEC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "chip.h"
|
||||
#include "hardware/sam_afec.h"
|
||||
|
||||
#if defined(CONFIG_ADC) && (defined(CONFIG_SAMV7_AFEC0) || \
|
||||
defined(CONFIG_SAMV7_AFEC1))
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Port numbers for use with sam_mcan_initialize() */
|
||||
|
||||
#define AFEC0 0
|
||||
#define AFEC1 1
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_afec_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the adc
|
||||
*
|
||||
* Input Parameters:
|
||||
* intf - ADC number (1 or 2)
|
||||
* chanlist - The list of channels
|
||||
* nchannels - Number of channels
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid can device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct adc_dev_s *sam_afec_initialize(int intf,
|
||||
FAR const uint8_t *chanlist,
|
||||
int nchannels);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* CONFIG_ADC && (CONFIG_SAMV7_AFEC0 || CONFIG_SAMV7_AFEC1) */
|
||||
#endif /* __ARCH_ARM_SRC_SAMV7_SAM_AFEC_H */
|
||||
Reference in New Issue
Block a user