diff --git a/examples/README.txt b/examples/README.txt index 61166c438..4460e2c66 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -46,8 +46,6 @@ examples/adc indefinitely. - 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/examples/adc/adc.h b/examples/adc/adc.h index e6d9dd7bd..901f84940 100755 --- a/examples/adc/adc.h +++ b/examples/adc/adc.h @@ -56,8 +56,6 @@ * indefinitely. * 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 @@ -72,39 +70,6 @@ # 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 @@ -129,18 +94,6 @@ * 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 ****************************************************************************/ diff --git a/examples/adc/adc_main.c b/examples/adc/adc_main.c index e85ee7653..176e7a191 100644 --- a/examples/adc/adc_main.c +++ b/examples/adc/adc_main.c @@ -94,9 +94,9 @@ int MAIN_NAME(int argc, char *argv[]) { - uint8_t sample[ADC_SAMPLE_SIZE]; + struct adc_msg_s samples[CONFIG_EXAMPLES_ADC_GROUPSIZE]; + size_t readsize; ssize_t nbytes; - FAR adc_sample_t *ptr; #if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES) long nsamples; #endif @@ -165,9 +165,10 @@ int MAIN_NAME(int argc, char *argv[]) msgflush(); - /* Read one sample of size ADC_SAMPLE_SIZE */ + /* Read CONFIG_EXAMPLES_ADC_GROUPSIZE samples */ - nbytes = read(fd, sample, ADC_SAMPLE_SIZE); + readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s); + nbytes = read(fd, sample, readsize); message("Bytes read: %d\n", nbytes); /* Handle unexpected return values */ @@ -185,10 +186,10 @@ int MAIN_NAME(int argc, char *argv[]) message(MAIN_STRING "Interrupted read...\n"); } - else if (nbytes != ADC_SAMPLE_SIZE) + else if (nbytes != readsize) { message(MAIN_STRING "Unexpected read size=%d, expected=%d, Ignoring\n", - nbytes, ADC_SAMPLE_SIZE); + nbytes, readsize); } /* Print the sample data on successful return */ @@ -196,10 +197,10 @@ int MAIN_NAME(int argc, char *argv[]) else { message("Sample :\n"); - ptr = (FAR adc_sample_t*)sample; for (i = 0; i < CONFIG_EXAMPLES_ADC_GROUPSIZE; i++) { - message("%d: " SAMPLE_FMT "\n", i, ptr[i]); + message("%d: channel: %d value: %d\n", + i, sample[i].am_channel, sample[i].am_data); } } }