Update to STM32 DAC and ADC drivers

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4185 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2011-12-15 13:33:15 +00:00
parent 59712fdeef
commit 18d89455ad
6 changed files with 125 additions and 28 deletions
+10 -9
View File
@@ -510,23 +510,23 @@ static void adc_reset(FAR struct adc_dev_s *dev)
/* Configuration of the channels conversions */ /* Configuration of the channels conversions */
regval = adc_getreg(priv, STM32_ADC_SQR3_OFFSET) & ~ADC_SQR3_RESERVED; regval = adc_getreg(priv, STM32_ADC_SQR3_OFFSET) & ~ADC_SQR3_RESERVED;
for (i = 1, offset = 0; i <= priv->nchannels && i <= 6; i++, offset += 5) for (i = 0, offset = 0; i < priv->nchannels && i < 6; i++, offset += 5)
{ {
regval |= (uint32_t)priv->chanlist[i-1] << offset; regval |= (uint32_t)priv->chanlist[i] << offset;
} }
adc_putreg(priv, STM32_ADC_SQR3_OFFSET, regval); adc_putreg(priv, STM32_ADC_SQR3_OFFSET, regval);
regval = adc_getreg(priv, STM32_ADC_SQR2_OFFSET) & ~ADC_SQR2_RESERVED; regval = adc_getreg(priv, STM32_ADC_SQR2_OFFSET) & ~ADC_SQR2_RESERVED;
for (i = 7, offset = 0; i <= priv->nchannels && i <= 12; i++, offset += 5) for (i = 6, offset = 0; i < priv->nchannels && i < 12; i++, offset += 5)
{ {
regval |= (uint32_t)priv->chanlist[i-1] << offset; regval |= (uint32_t)priv->chanlist[i] << offset;
} }
adc_putreg(priv, STM32_ADC_SQR2_OFFSET, regval); adc_putreg(priv, STM32_ADC_SQR2_OFFSET, regval);
regval = adc_getreg(priv, STM32_ADC_SQR1_OFFSET) & ~(ADC_SQR1_RESERVED|ADC_SQR1_L_MASK); regval = adc_getreg(priv, STM32_ADC_SQR1_OFFSET) & ~(ADC_SQR1_RESERVED|ADC_SQR1_L_MASK);
for (i = 13, offset = 0; i <= priv->nchannels && i <= 16; i++, offset += 5) for (i = 12, offset = 0; i < priv->nchannels && i < 16; i++, offset += 5)
{ {
regval |= (uint32_t)priv->chanlist[i-1] << offset; regval |= (uint32_t)priv->chanlist[i] << offset;
} }
adc_putreg(priv, STM32_ADC_SQR1_OFFSET, regval); adc_putreg(priv, STM32_ADC_SQR1_OFFSET, regval);
@@ -842,8 +842,9 @@ static int adc123_interrupt(int irq, void *context)
* Name: stm32_adcinitialize * Name: stm32_adcinitialize
* *
* Description: * Description:
* Initialize the ADC. The logic is, save nchannels : # of channels * Initialize the ADC.
* (conversions) in ADC_SQR1_L *
* The logic is, save nchannels : # of channels (conversions) in ADC_SQR1_L
* Then, take the chanlist array and store it in the SQR Regs, * Then, take the chanlist array and store it in the SQR Regs,
* chanlist[0] -> ADC_SQR3_SQ1 * chanlist[0] -> ADC_SQR3_SQ1
* chanlist[1] -> ADC_SQR3_SQ2 * chanlist[1] -> ADC_SQR3_SQ2
@@ -863,7 +864,7 @@ static int adc123_interrupt(int irq, void *context)
* nchannels - Number of channels * nchannels - Number of channels
* *
* Returned Value: * Returned Value:
* Valid can device structure reference on succcess; a NULL on failure * Valid ADC device structure reference on succcess; a NULL on failure
* *
****************************************************************************/ ****************************************************************************/
+38
View File
@@ -47,5 +47,43 @@
#include <nuttx/analog/adc.h> #include <nuttx/analog/adc.h>
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_adcinitialize
*
* Description:
* Initialize the ADC.
*
* Input Parameters:
* intf - Could be {1,2,3} for ADC1, ADC2, or ADC3
* chanlist - The list of channels
* nchannels - Number of channels
*
* Returned Value:
* Valid can device structure reference on succcess; a NULL on failure
*
****************************************************************************/
struct adc_dev_s;
EXTERN struct adc_dev_s *stm32_adcinitialize(int intf, uint8_t *chanlist,
int nchannels);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_STM32_STM32_ADC_H */ #endif /* __ARCH_ARM_SRC_STM32_STM32_ADC_H */
+27 -6
View File
@@ -58,18 +58,33 @@
#include "stm32_internal.h" #include "stm32_internal.h"
#include "stm32_dac.h" #include "stm32_dac.h"
#if defined(CONFIG_DAC) && defined(CONFIG_STM32_DAC) #ifdef CONFIG_DAC
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/
/* Up to 2 DAC interfaces are supported */
#if STM32_NDAC < 2
# undef CONFIG_STM32_DAC2
#endif
#if STM32_NDAC < 1
# undef CONFIG_STM32_DAC1
#endif
#if defined(CONFIG_STM32_DAC1) || defined(CONFIG_STM32_DAC2)
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* Interrupt handler */ /* Interrupt handler */
#ifdef CONFIG_STM32_STM32F40XX
static int dac_interrupt(int irq, void *context); static int dac_interrupt(int irq, void *context);
#endif
/* DAC methods */ /* DAC methods */
@@ -108,7 +123,8 @@ static struct dac_dev_s g_dacdev =
* Name: dac_interrupt * Name: dac_interrupt
* *
* Description: * Description:
* DAC interrupt handler. * DAC interrupt handler. The STM32 F4 family supports a only a DAC
* underrun interrupt.
* *
* Input Parameters: * Input Parameters:
* *
@@ -116,10 +132,12 @@ static struct dac_dev_s g_dacdev =
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_STM32_STM32F40XX
static int dac_interrupt(int irq, void *context) static int dac_interrupt(int irq, void *context)
{ {
return OK; return OK;
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: dac_reset * Name: dac_reset
@@ -242,20 +260,23 @@ static int dac_ioctl(FAR struct dac_dev_s *dev, int cmd, unsigned long arg)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_dacinitialize * Name: stm32_dacinitialize
* *
* Description: * Description:
* Initialize the DAC * Initialize the DAC
* *
* Input Parameters:
* intf - The DAC interface number.
*
* Returned Value: * Returned Value:
* Valid dac device structure reference on succcess; a NULL on failure * Valid dac device structure reference on succcess; a NULL on failure
* *
****************************************************************************/ ****************************************************************************/
FAR struct dac_dev_s *up_dacinitialize(int channel) FAR struct dac_dev_s *stm32_dacinitialize(int intf)
{ {
return &g_dacdev; return &g_dacdev;
} }
#endif /* CONFIG_DAC && CONFIG_STM32_DAC */ #endif /* CONFIG_STM32_DAC1 || CONFIG_STM32_DAC2 */
#endif /* CONFIG_DAC */
+35
View File
@@ -47,5 +47,40 @@
#include <nuttx/analog/dac.h> #include <nuttx/analog/dac.h>
/************************************************************************************
* Public Function Prototypes
************************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_dacinitialize
*
* Description:
* Initialize the DAC
*
* Input Parameters:
* intf - The DAC interface number.
*
* Returned Value:
* Valid dac device structure reference on succcess; a NULL on failure
*
****************************************************************************/
struct dac_dev_s;
EXTERN FAR struct dac_dev_s *stm32_dacinitialize(int intf);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_STM32_STM32_DAC_H */ #endif /* __ARCH_ARM_SRC_STM32_STM32_DAC_H */
+2 -1
View File
@@ -461,7 +461,8 @@ STM3210E-EVAL-specific Configuration Options
CONFIG_STM32_CAN CONFIG_STM32_CAN
CONFIG_STM32_BKP CONFIG_STM32_BKP
CONFIG_STM32_PWR CONFIG_STM32_PWR
CONFIG_STM32_DAC CONFIG_STM32_DAC1
CONFIG_STM32_DAC2
CONFIG_STM32_USB CONFIG_STM32_USB
APB2 APB2
+2 -1
View File
@@ -334,7 +334,8 @@ STM3240G-EVAL-specific Configuration Options
CONFIG_STM32_I2C3 CONFIG_STM32_I2C3
CONFIG_STM32_CAN1 CONFIG_STM32_CAN1
CONFIG_STM32_CAN2 CONFIG_STM32_CAN2
CONFIG_STM32_DAC CONFIG_STM32_DAC1
CONFIG_STM32_DAC2
CONFIG_STM32_PWR -- Required for RTC CONFIG_STM32_PWR -- Required for RTC
APB2 APB2