Functions for using analog-to-digital (ADC) conversion peripheral. More...

Modules

Types
Hardware ADC data types.
 

Functions

zos_result_t zn_adc_init (zos_gpio_t gpio)
 Initialize GPIO's ADC function. More...
 
zos_result_t zn_adc_sample (zos_gpio_t gpio, uint16_t *value_ptr, zos_adc_sample_t type)
 Take an ADC sample from the specified GPIO. More...
 
zos_result_t zn_adc_direct_init (zos_adc_t adc, const zos_adc_config_t *config)
 Initialize the ADC peripheral. More...
 
zos_result_t zn_adc_direct_sample (zos_adc_t adc, uint16_t *value_ptr)
 Take single 16bit ADC reading and store to given pointer. More...
 
zos_result_t zn_adc_sample_stream (zos_adc_t adc, uint16_t *buffer, uint16_t sample_count)
 Take multiple 16bit ADC readings and store to given buffer. More...
 
zos_result_t zn_adc_gpio_to_peripheral (zos_gpio_t gpio, zos_adc_t *adc_peripheral)
 Attempt to retrieve the ADC peripheral value from GPIO. More...
 
zos_result_t zn_adc_safe_sample (zos_adc_t adc, uint8_t gain, uint32_t *value)
 Safely take a 16bit ADC reading and store to given buffer. More...
 
zos_result_t zn_adc_add_lut (uint32_t adc_mask, const char *filename, zos_adc_lut_t *lut_ptr)
 Add Lookup Table (LUT) to ADC. More...
 
zos_result_t zn_adc_remove_lut (zos_adc_lut_t *lut)
 Cleanup the memory used by a Lookup Table (LUT) More...
 
zos_result_t zn_adc_sample_and_convert (zos_adc_t adc, uint8_t gain, fpi_word_t *conv_value)
 Table ADC sample and convert to corresponding value in Lookup Table. More...
 

Detailed Description

Functions for using analog-to-digital (ADC) conversion peripheral.

Function Documentation

zos_result_t zn_adc_add_lut ( uint32_t  adc_mask,
const char *  filename,
zos_adc_lut_t lut_ptr 
)

Add Lookup Table (LUT) to ADC.

This reads a LUT file and prepares a table to be used to convert raw ADC readings into a corresponding value.

Use zn_adc_sample_and_convert() to get a converted value. Use zn_adc_remove_lut() to cleanup the LUT from memory.

Parameters
[in]adc_maskBitmask corresponding to the ADCs to associate with LUT
filenamethe filename of the LUT
lut_ptrPointer to allocated lut
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, cloud/bluemix/bluemix.c, and cloud/s2cdemo/zentri_platform_streams.c.
zos_result_t zn_adc_direct_init ( zos_adc_t  adc,
const zos_adc_config_t config 
)

Initialize the ADC peripheral.

This bypasses ZentriOS and directly initializes the ADC peripheral.

Parameters
[in]adcThe ADC to initialize
[in]configADC peripheral configuration, zos_adc_config_t
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, cloud/bluemix/bluemix.c, and cloud/s2cdemo/zentri_platform_streams.c.
zos_result_t zn_adc_direct_sample ( zos_adc_t  adc,
uint16_t *  value_ptr 
)

Take single 16bit ADC reading and store to given pointer.

This bypasses ZentriOS and directly samples the ADC peripheral.

Note
zn_adc_init() or zn_adc_init_with_config() MUST be called first.
Parameters
[in]adcThe ADC to read
[out]value_ptrPointer to hold 16bit raw ADC reading
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, and cloud/s2cdemo/zentri_platform_streams.c.
zos_result_t zn_adc_gpio_to_peripheral ( zos_gpio_t  gpio,
zos_adc_t *  adc_peripheral 
)

Attempt to retrieve the ADC peripheral value from GPIO.

Parameters
[in]gpioGPIO of corresponding ADC
[out]adc_peripheralPointer to hold ADC number of corresponding GPIO
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, cloud/bluemix/bluemix.c, and cloud/s2cdemo/zentri_platform_streams.c.
zos_result_t zn_adc_init ( zos_gpio_t  gpio)

Initialize GPIO's ADC function.

See ZentriOS Command API documentation: adc_take_sample

Note
This does not support the Lookup Table (LUT) feature. Refer to zn_adc_add_lut() for this functionality.
Parameters
[in]gpioThe GPIO to initialize for ADC
Returns
zos_result_t result of api call
zos_result_t zn_adc_remove_lut ( zos_adc_lut_t lut)

Cleanup the memory used by a Lookup Table (LUT)

Parameters
lutLookup Table reference
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, and cloud/bluemix/bluemix.c.
zos_result_t zn_adc_safe_sample ( zos_adc_t  adc,
uint8_t  gain,
uint32_t *  value 
)

Safely take a 16bit ADC reading and store to given buffer.

This ensures the ADC can safely be read without interfering with other GPIO operations.

Note
This is mainly a concern on the AMx06 boards which share the serial flash SPI signals with the ADC GPIOs.

It also automatically initializes the ADC peripheral.

Parameters
[in]adcThe ADC to read sample
[in]gainThe gain of ADC hardware (only used for AMW004 boards)
[out]valuePointer to hold ADC reading
Returns
zos_result_t result of api call
zos_result_t zn_adc_sample ( zos_gpio_t  gpio,
uint16_t *  value_ptr,
zos_adc_sample_t  type 
)

Take an ADC sample from the specified GPIO.

See ZentriOS Command API documentation: adc_take_sample

Note
This does not support the Lookup Table (LUT) feature. Refer to zn_adc_add_lut() for this functionality.
Parameters
[in]gpioThe GPIO to take reading
[out]value_ptrHolds ADC reading value
[in]typeThe type of ADC reading, zos_adc_sample_t
Returns
zos_result_t result of api call
zos_result_t zn_adc_sample_and_convert ( zos_adc_t  adc,
uint8_t  gain,
fpi_word_t conv_value 
)

Table ADC sample and convert to corresponding value in Lookup Table.

Call zn_adc_add_lut() first to associate a LUT with the ADC.

The returned value is a Fixed Point Integer (FPI), refer to fpi_to_str_with_padding() for printing this value.

Parameters
[in]adcThe ADC to sample
[in]gainThe gain of ADC hardware (only used for AMW004 boards)
[out]conv_valueThe converted ADC sample as a Fixed Point Integer (FPI)
Returns
zos_result_t result of api call
Examples:
basic/adc/adc.c, cloud/bluemix/bluemix.c, and cloud/s2cdemo/zentri_platform_streams.c.
zos_result_t zn_adc_sample_stream ( zos_adc_t  adc,
uint16_t *  buffer,
uint16_t  sample_count 
)

Take multiple 16bit ADC readings and store to given buffer.

Note
zn_adc_init() or zn_adc_init_with_config() MUST be called first.
Parameters
[in]adcThe ADC to read samples
[out]bufferBuffer to hold sample_count 16bit raw ADC readings
[in]sample_countNumber of ADC samples to take
Returns
zos_result_t result of api call