adc: improvements to the adc sample code.
- Sample application now pulls data continuously. - Adds information on the arduino analog input pins and ADC channels. - CHANNEL is defined as a macro. - BUFFER_SIZE is defined as a macro. - Sets the sample to run on repetitive mode on ARC architectures (applies to Arduino 101 ADC). Change-Id: I6201fea3a98b5394c05eb3ac570793629431ac02 Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@linux.intel.com>
This commit is contained in:
parent
87aa20ebad
commit
fed390316f
2 changed files with 36 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
||||||
CONFIG_ADC=y
|
CONFIG_ADC=y
|
||||||
CONFIG_ADC_DW=y
|
CONFIG_ADC_DW=y
|
||||||
CONFIG_ADC_DW_0=y
|
CONFIG_ADC_DW_0=y
|
||||||
|
CONFIG_ADC_DW_REPETITIVE=y
|
||||||
CONFIG_NUM_IRQS=20
|
CONFIG_NUM_IRQS=20
|
||||||
|
|
|
@ -30,18 +30,34 @@
|
||||||
#define DBG printk
|
#define DBG printk
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SLEEPTIME 2
|
||||||
|
#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec)
|
||||||
|
|
||||||
#ifdef CONFIG_SOC_QUARK_SE_SS
|
#ifdef CONFIG_SOC_QUARK_SE_SS
|
||||||
#define ADC_DEVICE_NAME CONFIG_ADC_DW_NAME_0
|
#define ADC_DEVICE_NAME CONFIG_ADC_DW_NAME_0
|
||||||
#elif CONFIG_BOARD_GALILEO
|
#elif CONFIG_BOARD_GALILEO
|
||||||
#define ADC_DEVICE_NAME CONFIG_ADC_TI_ADC108S102_0_DRV_NAME
|
#define ADC_DEVICE_NAME CONFIG_ADC_TI_ADC108S102_0_DRV_NAME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t seq_buffer[100];
|
/*
|
||||||
|
* The analog input pin and channel number mapping
|
||||||
|
* for Arduino 101 board.
|
||||||
|
* A0 Channel 10
|
||||||
|
* A1 Channel 11
|
||||||
|
* A2 Channel 12
|
||||||
|
* A3 Channel 13
|
||||||
|
* A4 Channel 14
|
||||||
|
*/
|
||||||
|
#define CHANNEL 10
|
||||||
|
#define BUFFER_SIZE 40
|
||||||
|
|
||||||
|
static uint8_t seq_buffer[BUFFER_SIZE];
|
||||||
|
|
||||||
static struct adc_seq_entry sample = {
|
static struct adc_seq_entry sample = {
|
||||||
.sampling_delay = 1,
|
.sampling_delay = 12,
|
||||||
.channel_id = 0,
|
.channel_id = CHANNEL,
|
||||||
.buffer = seq_buffer,
|
.buffer = seq_buffer,
|
||||||
.buffer_length = 100,
|
.buffer_length = BUFFER_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct adc_seq_table table = {
|
static struct adc_seq_table table = {
|
||||||
|
@ -52,14 +68,17 @@ static struct adc_seq_table table = {
|
||||||
static void _print_sample_in_hex(uint8_t *buf, uint32_t length)
|
static void _print_sample_in_hex(uint8_t *buf, uint32_t length)
|
||||||
{
|
{
|
||||||
DBG("Buffer content:\n");
|
DBG("Buffer content:\n");
|
||||||
for (; length > 0; length -= 2, buf += 2) {
|
for (; length > 0; length -= 4, buf += 4) {
|
||||||
DBG("0x%x ", *((uint16_t *)buf));
|
DBG("0x%x ", *((uint32_t *)buf));
|
||||||
}
|
}
|
||||||
|
DBG("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
struct device *adc;
|
struct device *adc;
|
||||||
|
struct nano_timer timer;
|
||||||
|
uint32_t data[2] = {0, 0};
|
||||||
|
|
||||||
DBG("ADC sample started on %s\n", ADC_DEVICE_NAME);
|
DBG("ADC sample started on %s\n", ADC_DEVICE_NAME);
|
||||||
|
|
||||||
|
@ -69,14 +88,17 @@ void main(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nano_timer_init(&timer, data);
|
||||||
adc_enable(adc);
|
adc_enable(adc);
|
||||||
|
while (1) {
|
||||||
if (adc_read(adc, &table) != DEV_OK) {
|
if (adc_read(adc, &table) != DEV_OK) {
|
||||||
DBG("Sampling could not proceed, an error occurred\n");
|
DBG("Sampling could not proceed, an error occurred\n");
|
||||||
} else {
|
} else {
|
||||||
DBG("Sampling is done\n");
|
DBG("Sampling is done\n");
|
||||||
_print_sample_in_hex(seq_buffer, 100);
|
_print_sample_in_hex(seq_buffer, BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
nano_timer_start(&timer, SLEEPTICKS);
|
||||||
|
nano_timer_test(&timer, TICKS_UNLIMITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
adc_disable(adc);
|
adc_disable(adc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue