From 37e3f9ce2696bb70fad20762e3860fd2a3d46dd1 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 15 Dec 2011 13:33:15 +0000 Subject: [PATCH] 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 --- arch/arm/src/stm32/stm32_adc.c | 41 +++++++++++++++++----------------- arch/arm/src/stm32/stm32_adc.h | 38 +++++++++++++++++++++++++++++++ arch/arm/src/stm32/stm32_dac.c | 33 ++++++++++++++++++++++----- arch/arm/src/stm32/stm32_dac.h | 35 +++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 26 deletions(-) diff --git a/arch/arm/src/stm32/stm32_adc.c b/arch/arm/src/stm32/stm32_adc.c index f4363ba6a3..88f117b6e2 100644 --- a/arch/arm/src/stm32/stm32_adc.c +++ b/arch/arm/src/stm32/stm32_adc.c @@ -510,23 +510,23 @@ static void adc_reset(FAR struct adc_dev_s *dev) /* Configuration of the channels conversions */ 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); 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); 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); @@ -842,20 +842,21 @@ static int adc123_interrupt(int irq, void *context) * Name: stm32_adcinitialize * * Description: - * Initialize the ADC. The logic is, save nchannels : # of channels - * (conversions) in ADC_SQR1_L - * Then, take the chanlist array and store it in the SQR Regs, - * chanlist[0] -> ADC_SQR3_SQ1 - * chanlist[1] -> ADC_SQR3_SQ2 - * chanlist[2] -> ADC_SQR3_SQ3 - * chanlist[3] -> ADC_SQR3_SQ4 - * chanlist[4] -> ADC_SQR3_SQ5 - * chanlist[5] -> ADC_SQR3_SQ6 - * ... - * chanlist[15]-> ADC_SQR1_SQ16 + * Initialize the ADC. * - * up to - * chanlist[nchannels] + * The logic is, save nchannels : # of channels (conversions) in ADC_SQR1_L + * Then, take the chanlist array and store it in the SQR Regs, + * chanlist[0] -> ADC_SQR3_SQ1 + * chanlist[1] -> ADC_SQR3_SQ2 + * chanlist[2] -> ADC_SQR3_SQ3 + * chanlist[3] -> ADC_SQR3_SQ4 + * chanlist[4] -> ADC_SQR3_SQ5 + * chanlist[5] -> ADC_SQR3_SQ6 + * ... + * chanlist[15]-> ADC_SQR1_SQ16 + * + * up to + * chanlist[nchannels] * * Input Parameters: * intf - Could be {1,2,3} for ADC1, ADC2, or ADC3 @@ -863,7 +864,7 @@ static int adc123_interrupt(int irq, void *context) * nchannels - Number of channels * * Returned Value: - * Valid can device structure reference on succcess; a NULL on failure + * Valid ADC device structure reference on succcess; a NULL on failure * ****************************************************************************/ diff --git a/arch/arm/src/stm32/stm32_adc.h b/arch/arm/src/stm32/stm32_adc.h index 6089217fed..508813bd14 100644 --- a/arch/arm/src/stm32/stm32_adc.h +++ b/arch/arm/src/stm32/stm32_adc.h @@ -47,5 +47,43 @@ #include +/************************************************************************************ + * 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 */ diff --git a/arch/arm/src/stm32/stm32_dac.c b/arch/arm/src/stm32/stm32_dac.c index 79a8178dac..a7d46707c4 100644 --- a/arch/arm/src/stm32/stm32_dac.c +++ b/arch/arm/src/stm32/stm32_dac.c @@ -58,18 +58,33 @@ #include "stm32_internal.h" #include "stm32_dac.h" -#if defined(CONFIG_DAC) && defined(CONFIG_STM32_DAC) +#ifdef CONFIG_DAC /**************************************************************************** * 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 ****************************************************************************/ /* Interrupt handler */ +#ifdef CONFIG_STM32_STM32F40XX static int dac_interrupt(int irq, void *context); +#endif /* DAC methods */ @@ -108,7 +123,8 @@ static struct dac_dev_s g_dacdev = * Name: dac_interrupt * * Description: - * DAC interrupt handler. + * DAC interrupt handler. The STM32 F4 family supports a only a DAC + * underrun interrupt. * * 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) { return OK; } +#endif /**************************************************************************** * 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: * Initialize the DAC * + * Input Parameters: + * intf - The DAC interface number. + * * Returned Value: * 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; } -#endif /* CONFIG_DAC && CONFIG_STM32_DAC */ - +#endif /* CONFIG_STM32_DAC1 || CONFIG_STM32_DAC2 */ +#endif /* CONFIG_DAC */ diff --git a/arch/arm/src/stm32/stm32_dac.h b/arch/arm/src/stm32/stm32_dac.h index 64942b05e7..41d681ee76 100644 --- a/arch/arm/src/stm32/stm32_dac.h +++ b/arch/arm/src/stm32/stm32_dac.h @@ -47,5 +47,40 @@ #include +/************************************************************************************ + * 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 */