eLua platform interface - ADC
Overview
This part of the platform interface groups functions related to the ADC interface(s) of the MCU.
Functions
int platform_adc_exists( unsigned id );
Checks if the platform has the hardware ADC specified as argument. Implemented in src/common.c, it uses the NUM_ADC macro that must be defined in the platform's platform_conf.h file (see here for details). For example:
#define NUM_ADC 1 // The platform has 1 ADC interface
Arguments: id - ADC interface ID
Returns: 1 if the ADC interface exists, 0 otherwise
u32 platform_adc_get_maxval( unsigned id );
Gets the maximum conversion value the channel may supply (based on channel resolution)
Arguments: id - ADC channel ID
Returns: the maximum possible conversion value
u32 platform_adc_set_smoothing( unsigned id, u32 length );
Sets the length of the moving average smoothing filter
Arguments:
- id - ADC channel ID
- length - the length of the moving average filter (must be a power of 2). If it is 1, the filter is disabled.
Returns: PLATFORM_OK if the operation succeeded, PLATFORM_ERR otherwise.
void platform_adc_set_blocking( unsigned id, u32 mode );
Sets whether or not sample requests should block, waiting for additional samples
Arguments:
- id - ADC channel ID
- mode - specifies whether or not sample requests block. If 1, requests will block until enough samples are available or sampling has ended. If 0, requests will return immediately with up to the number of samples requested.
Returns: nothing.
u32 platform_adc_is_done( unsigned id );
Checks whether sampling has completed
Arguments: id - ADC channel ID
Returns: 1 if sampling has completed, 0 if not
void platform_adc_set_timer( unsigned id, u32 timer );
Selects a timer to control the sampling frequency
Arguments:
- id - ADC channel ID
- timer - the ID of the timer to use to control the sampling frequency.
Returns: nothing.
u32 platform_adc_set_clock( unsigned id, u32 freq );
Set the frequency of sample acquisition
Arguments:
- id - ADC channel ID
- freq - the frequency of sample collection in Hz (number of samples per second). If 0, the timer is not used and samples are acquired as quickly as possible.
Returns: the actual sampling frequency that will be used, which might be different from the requested frequency, depending on the hardware
int platform_adc_check_timer_id( unsigned id, unsigned timer_id );
Checks whether a timer may be used with a particular ADC channel
Arguments:
- id - ADC channel ID
- timer_id - Timer ID
Returns: 1 if the timer may be used to trigger the ADC channel, 0 if not