aio: added configuration within platform data.
* Allows for different bit shifting for each platform. * New functions added for obtaining this information * mraa_adc_raw_bits * mraa_adc_supported_bits * Update board information to include this. AIO module changed to allow * use of the new board data Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -34,6 +34,9 @@ struct _aio {
|
||||
int adc_in_fp;
|
||||
};
|
||||
|
||||
static int raw_bits;
|
||||
static int sup_bits;
|
||||
|
||||
static mraa_result_t aio_get_valid_fp(mraa_aio_context dev)
|
||||
{
|
||||
char file_path[64]= "";
|
||||
@@ -92,6 +95,8 @@ mraa_aio_context mraa_aio_init(unsigned int aio_channel)
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
raw_bits = mraa_adc_raw_bits();
|
||||
sup_bits = mraa_adc_supported_bits();
|
||||
|
||||
return dev;
|
||||
}
|
||||
@@ -132,12 +137,14 @@ uint16_t mraa_aio_read(mraa_aio_context dev)
|
||||
}
|
||||
|
||||
/* Adjust the raw analog input reading to supported resolution value*/
|
||||
if (ADC_RAW_RESOLUTION_BITS > ADC_SUPPORTED_RESOLUTION_BITS) {
|
||||
shifter_value = ADC_RAW_RESOLUTION_BITS - ADC_SUPPORTED_RESOLUTION_BITS;
|
||||
analog_value = analog_value >> shifter_value;
|
||||
} else {
|
||||
shifter_value = ADC_SUPPORTED_RESOLUTION_BITS - ADC_RAW_RESOLUTION_BITS;
|
||||
analog_value = analog_value << shifter_value;
|
||||
if (raw_bits =! sup_bits) {
|
||||
if (raw_bits > sup_bits) {
|
||||
shifter_value = raw_bits - sup_bits;
|
||||
analog_value = analog_value >> shifter_value;
|
||||
} else {
|
||||
shifter_value = sup_bits - raw_bits;
|
||||
analog_value = analog_value << shifter_value;
|
||||
}
|
||||
}
|
||||
|
||||
return analog_value;
|
||||
|
||||
@@ -38,6 +38,8 @@ mraa_intel_galileo_rev_d()
|
||||
b->phy_pin_count = 20;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
b->adc_raw = 12;
|
||||
b->adc_supported = 10;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_GALILEO_REV_D_PINCOUNT);
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ mraa_intel_galileo_gen2()
|
||||
b->phy_pin_count = 20;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
b->adc_raw = 12;
|
||||
b->adc_supported = 10;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_GALILEO_GEN_2_PINCOUNT);
|
||||
|
||||
|
||||
24
src/mraa.c
24
src/mraa.c
@@ -419,3 +419,27 @@ mraa_platform_t mraa_get_platform_type()
|
||||
{
|
||||
return platform_type;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mraa_adc_raw_bits()
|
||||
{
|
||||
if (plat == NULL)
|
||||
return 0;
|
||||
|
||||
if (plat->aio_count == 0)
|
||||
return 0;
|
||||
|
||||
return plat->adc_raw;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mraa_adc_supported_bits()
|
||||
{
|
||||
if (plat == NULL)
|
||||
return 0;
|
||||
|
||||
if (plat->aio_count == 0)
|
||||
return 0;
|
||||
|
||||
return plat->adc_supported;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user