summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-12-16 00:32:11 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-12-16 00:32:11 +0000
commitdf5aca04bdf127475b90bf6fdc246f402f039649 (patch)
treefa8d7ebc153e98273b925eb661c86da5c96e9519 /apps
parentfdaf3f62925632d5c98d019511acd22934653b0c (diff)
downloadnuttx-df5aca04bdf127475b90bf6fdc246f402f039649.tar.gz
nuttx-df5aca04bdf127475b90bf6fdc246f402f039649.tar.bz2
nuttx-df5aca04bdf127475b90bf6fdc246f402f039649.zip
Updated STM32 ADC driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4189 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/README.txt6
-rwxr-xr-xapps/examples/adc/adc.h57
-rw-r--r--apps/examples/adc/adc_main.c23
3 files changed, 70 insertions, 16 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 63b0a0223..61166c438 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -44,8 +44,10 @@ examples/adc
and this value is ignored. Otherwise, this number of samples is
collected and the program terminates. Default: Samples are collected
indefinitely.
- - CONFIG_EXAMPLES_ADC_SAMPLESIZE - The number of bytes to read in one sample.
- Default: 8
+ - CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once.
+ Default: 4
+ - CONFIG_EXAMPLES_ADC_SAMPLEWIDTH - The width (in bits) of the on ADC sample.
+ Default: 16
examples/buttons
^^^^^^^^^^^^^^^^
diff --git a/apps/examples/adc/adc.h b/apps/examples/adc/adc.h
index a8f225532..e6d9dd7bd 100755
--- a/apps/examples/adc/adc.h
+++ b/apps/examples/adc/adc.h
@@ -54,8 +54,10 @@
* and this value is ignored. Otherwise, this number of samples is
* collected and the program terminates. Default: Samples are collected
* indefinitely.
- * CONFIG_EXAMPLES_ADC_SAMPLESIZE - The number of bytes to read in one sample.
- * Default: 8
+ * CONFIG_EXAMPLES_ADC_GROUPSIZE - The number of samples to read at once.
+ * Default: 4
+ * CONFIG_EXAMPLES_ADC_SAMPLEWIDTH - The width (in bits) of the on ADC sample.
+ * Default: 16
*/
#ifndef CONFIG_ADC
@@ -66,10 +68,43 @@
# define CONFIG_EXAMPLES_ADC_DEVPATH "/dev/adc0"
#endif
-#ifndef CONFIG_EXAMPLES_ADC_SAMPLESIZE
-# define CONFIG_EXAMPLES_ADC_SAMPLESIZE 8
+#ifndef CONFIG_EXAMPLES_ADC_GROUPSIZE
+# define CONFIG_EXAMPLES_ADC_GROUPSIZE 4
#endif
+#ifndef CONFIG_EXAMPLES_ADC_SAMPLEWIDTH
+# define CONFIG_EXAMPLES_ADC_SAMPLEWIDTH 16
+#endif
+
+/* Sample characteristics ***************************************************/
+
+#undef ADC_SAMPLE_BYTEWIDTH
+#if CONFIG_EXAMPLES_ADC_SAMPLEWIDTH <= 8
+# undef CONFIG_EXAMPLES_ADC_SAMPLEWIDTH
+# define CONFIG_EXAMPLES_ADC_SAMPLEWIDTH 8
+# define ADC_SAMPLE_BYTEWIDTH 1
+# define SAMPLE_FMT "%02x"
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH <= 16
+# undef CONFIG_EXAMPLES_ADC_SAMPLEWIDTH
+# define CONFIG_EXAMPLES_ADC_SAMPLEWIDTH 16
+# define ADC_SAMPLE_BYTEWIDTH 2
+# define SAMPLE_FMT "%04x"
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH <= 24
+# undef CONFIG_EXAMPLES_ADC_SAMPLEWIDTH
+# define CONFIG_EXAMPLES_ADC_SAMPLEWIDTH 24
+# define ADC_SAMPLE_BYTEWIDTH 3
+# define SAMPLE_FMT "%06x"
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH <= 32
+# undef CONFIG_EXAMPLES_ADC_SAMPLEWIDTH
+# define CONFIG_EXAMPLES_ADC_SAMPLEWIDTH 32
+# define ADC_SAMPLE_BYTEWIDTH 4
+# define SAMPLE_FMT "%08x"
+#else
+# error "Unsupported sample width"
+#endif
+
+#undef ADC_SAMPLE_SIZE (CONFIG_EXAMPLES_ADC_GROUPSIZE * ADC_SAMPLE_BYTEWIDTH)
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
@@ -94,6 +129,18 @@
* Public Types
****************************************************************************/
+#if CONFIG_EXAMPLES_ADC_SAMPLEWIDTH == 8
+typedef uint8_t adc_sample_t;
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH == 16
+typedef uint16_t adc_sample_t;
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH == 24
+typedef uint32_t adc_sample_t;
+#elif CONFIG_EXAMPLES_ADC_SAMPLEWIDTH == 32
+typedef uint32_t adc_sample_t;
+#else
+# error "Unsupported sample width"
+#endif
+
/****************************************************************************
* Public Variables
****************************************************************************/
@@ -111,6 +158,6 @@
*
****************************************************************************/
-void adc_devinit(void);
+int adc_devinit(void);
#endif /* __APPS_EXAMPLES_ADC_ADC_H */
diff --git a/apps/examples/adc/adc_main.c b/apps/examples/adc/adc_main.c
index 3a1a1be44..e85ee7653 100644
--- a/apps/examples/adc/adc_main.c
+++ b/apps/examples/adc/adc_main.c
@@ -94,8 +94,9 @@
int MAIN_NAME(int argc, char *argv[])
{
- uintt_t sample[CONFIG_EXAMPLES_ADC_SAMPLESIZE];
+ uint8_t sample[ADC_SAMPLE_SIZE];
ssize_t nbytes;
+ FAR adc_sample_t *ptr;
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
long nsamples;
#endif
@@ -131,6 +132,7 @@ int MAIN_NAME(int argc, char *argv[])
errval = 1;
goto errout;
}
+ message(MAIN_STRING "Hardware initialized. Opening the ADC device\n");
/* Open the ADC device for reading */
@@ -147,6 +149,8 @@ int MAIN_NAME(int argc, char *argv[])
* ADC samples.
*/
+ message(MAIN_STRING "Entering the main loop\n");
+
#if defined(CONFIG_NSH_BUILTIN_APPS)
for (; nsamples > 0; nsamples--)
#elif defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
@@ -161,10 +165,10 @@ int MAIN_NAME(int argc, char *argv[])
msgflush();
- /* Read one sample */
+ /* Read one sample of size ADC_SAMPLE_SIZE */
- nbytes = read(fd, sample,CONFIG_EXAMPLES_ADC_SAMPLESIZE ));
- ivdbg("Bytes read: %d\n", nbytes);
+ nbytes = read(fd, sample, ADC_SAMPLE_SIZE);
+ message("Bytes read: %d\n", nbytes);
/* Handle unexpected return values */
@@ -181,10 +185,10 @@ int MAIN_NAME(int argc, char *argv[])
message(MAIN_STRING "Interrupted read...\n");
}
- else if (nbytes != CONFIG_EXAMPLES_ADC_SAMPLESIZE)
+ else if (nbytes != ADC_SAMPLE_SIZE)
{
message(MAIN_STRING "Unexpected read size=%d, expected=%d, Ignoring\n",
- nbytes, CONFIG_EXAMPLES_ADC_SAMPLESIZE);
+ nbytes, ADC_SAMPLE_SIZE);
}
/* Print the sample data on successful return */
@@ -192,16 +196,17 @@ int MAIN_NAME(int argc, char *argv[])
else
{
message("Sample :\n");
- for (i = 0; i < CONFIG_EXAMPLES_ADC_SAMPLESIZE; i++)
+ ptr = (FAR adc_sample_t*)sample;
+ for (i = 0; i < CONFIG_EXAMPLES_ADC_GROUPSIZE; i++)
{
- message("%d: %02x\n", i, sample[i]);
+ message("%d: " SAMPLE_FMT "\n", i, ptr[i]);
}
}
}
errout_with_dev:
close(fd);
-errout_with_dev:
+
errout:
message("Terminating!\n");
msgflush();