Tizen Native API  10.0

The ADC API provides functions to control ADC peripherals connected to the IoT device.

The ADC API can be used to control analog-to-digital converters (ADC).

Required Header

#include <peripheral_io.h>

Overview

This ADC API provides support for reading the values of analog-to-digital converters (ADC). These measure the voltage and output the result as a number.

Related Features

This API is related with the following feature:

  • http://tizen.org/feature/peripheral_io.adc

It is recommended to use features in your application for reliability.

You can check if a IoT device supports the related features for this API
by using System Information, and control your application's actions accordingly.

To ensure your application is only running on the IoT device with specific features,
please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from Feature Element.

Functions

int peripheral_adc_open (int device, int channel, peripheral_adc_h *adc)
 Opens the ADC pin and returns a handle representing it.
int peripheral_adc_close (peripheral_adc_h adc)
 Closes the ADC pin and frees the resources associated with it.
int peripheral_adc_read (peripheral_adc_h adc, uint32_t *value)
 Gets the current value of the ADC peripherals pin.

Typedefs

typedef struct _peripheral_adc_s * peripheral_adc_h
 An opaque handle representing an ADC peripherals pin.

Typedef Documentation

typedef struct _peripheral_adc_s* peripheral_adc_h

An opaque handle representing an ADC peripherals pin.

A handle to a single ADC pin, for use with most ADC interfaces

Since :
5.0

Function Documentation

Closes the ADC pin and frees the resources associated with it.

Warning:
This is not for use by third-party applications.

This function should be called at the end of the object's lifetime to avoid a memory leak.

Since :
5.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]adcThe ADC handle
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Precondition:
peripheral_adc_open()
#include <peripheral_io.h>

#define ADC_DEVICE 0
#define ADC_CHANNEL 1

int main(void)
{
    int ret;
    peripheral_adc_h adc;

    ret = peripheral_adc_open(ADC_DEVICE, ADC_CHANNEL, &adc);
    if (ret != PERIPHERAL_ERROR_NONE)
        handle_error(ret);

    // Use the connection here

    ret = peripheral_adc_close(adc);
    if (ret != PERIPHERAL_ERROR_NONE)
        handle_error(ret);
}
int peripheral_adc_open ( int  device,
int  channel,
peripheral_adc_h adc 
)

Opens the ADC pin and returns a handle representing it.

Warning:
This is not for use by third-party applications.

Starts the lifetime of the handle and allocates its needed resources.

Since :
5.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Remarks:
adc should be released with peripheral_adc_close()
Parameters:
[in]deviceThe ADC device number
[in]channelThe ADC channel number to control
[out]adcThe ADC handle is created on success
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_OUT_OF_MEMORYMemory allocation failed
PERIPHERAL_ERROR_RESOURCE_BUSYDevice is in use
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Postcondition:
peripheral_adc_close()
#include <peripheral_io.h>

#define ADC_DEVICE 0
#define ADC_CHANNEL 1

int main(void)
{
    int ret;
    peripheral_adc_h adc;

    ret = peripheral_adc_open(ADC_DEVICE, ADC_CHANNEL, &adc);
    if (ret != PERIPHERAL_ERROR_NONE)
        handle_error(ret);

    // Use the connection here

    ret = peripheral_adc_close(adc);
    if (ret != PERIPHERAL_ERROR_NONE)
        handle_error(ret);
}
int peripheral_adc_read ( peripheral_adc_h  adc,
uint32_t *  value 
)

Gets the current value of the ADC peripherals pin.

Warning:
This is not for use by third-party applications.

Reads the pin value into the provided pointer parameter.

Since :
5.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Remarks:
The value is returned in arbitrary units. It should be interpreted either experimentally, or by investigating the multiplier provided inside kernel's sys tree.
Parameters:
[in]adcThe ADC handle
[out]valueThe value to get
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
#include <peripheral_io.h>
#include <glib.h>
#include <stdio.h>

gboolean loop_iteration(gpointer user_data)
{
    peripheral_adc_h adc = user_data;
    int ret;
    uint32_t data;

    ret = peripheral_adc_read(adc, &data);
    if (ret != PERIPHERAL_ERROR_NONE)
        handle_error(ret);

    printf("Current ADC pin value: %d\n", (int)data);

    return G_SOURCE_CONTINUE;
}

guint read_in_a_loop(peripheral_adc_h adc)
{
    return g_timeout_add_seconds(1, loop_iteration, adc);
}