2016-02-06 06:12:40 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief ADC public API header file.
|
|
|
|
*/
|
2015-10-03 04:16:31 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-10-03 04:16:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __INCLUDE_ADC_H__
|
|
|
|
#define __INCLUDE_ADC_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <device.h>
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-10-26 18:18:44 +08:00
|
|
|
/**
|
2016-02-06 06:12:40 +08:00
|
|
|
* @brief ADC driver APIs
|
|
|
|
* @defgroup adc_interface ADC driver APIs
|
2015-10-26 18:18:44 +08:00
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
2015-10-03 04:16:31 +08:00
|
|
|
|
|
|
|
/**
|
2016-02-06 06:12:40 +08:00
|
|
|
* @brief ADC driver Sequence entry
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* This structure defines a sequence entry used
|
2015-10-03 04:16:31 +08:00
|
|
|
* to define a sample from a specific channel.
|
|
|
|
*/
|
|
|
|
struct adc_seq_entry {
|
2016-02-06 06:12:40 +08:00
|
|
|
/** Clock ticks delay before sampling the ADC. */
|
2015-10-03 04:16:31 +08:00
|
|
|
int32_t sampling_delay;
|
2016-02-06 06:12:40 +08:00
|
|
|
|
|
|
|
/** Buffer pointer where the sample is written.*/
|
2015-10-03 04:16:31 +08:00
|
|
|
uint8_t *buffer;
|
2016-02-06 06:12:40 +08:00
|
|
|
|
|
|
|
/** Length of the sampling buffer.*/
|
2015-10-03 04:16:31 +08:00
|
|
|
uint32_t buffer_length;
|
2016-01-29 04:53:34 +08:00
|
|
|
|
|
|
|
/** Channel ID that should be sampled from the ADC */
|
|
|
|
uint8_t channel_id;
|
|
|
|
|
|
|
|
uint8_t stride[3];
|
2015-10-03 04:16:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-06 06:12:40 +08:00
|
|
|
* @brief ADC driver Sequence table
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* This structure defines a list of sequence entries
|
|
|
|
* used to execute a sequence of samplings.
|
2015-10-03 04:16:31 +08:00
|
|
|
*/
|
|
|
|
struct adc_seq_table {
|
2016-02-06 06:12:40 +08:00
|
|
|
/* Pointer to a sequence entry array. */
|
2015-10-03 04:16:31 +08:00
|
|
|
struct adc_seq_entry *entries;
|
2016-02-06 06:12:40 +08:00
|
|
|
|
|
|
|
/* Number of entries in the sequence entry array. */
|
2015-10-03 04:16:31 +08:00
|
|
|
uint8_t num_entries;
|
2016-01-29 04:53:34 +08:00
|
|
|
uint8_t stride[3];
|
2015-10-03 04:16:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ADC driver API
|
|
|
|
*
|
|
|
|
* This structure holds all API function pointers.
|
|
|
|
*/
|
|
|
|
struct adc_driver_api {
|
2016-02-06 06:12:40 +08:00
|
|
|
/** Pointer to the enable routine. */
|
2015-10-03 04:16:31 +08:00
|
|
|
void (*enable)(struct device *dev);
|
2016-02-06 06:12:40 +08:00
|
|
|
|
|
|
|
/** Pointer to the disable routine. */
|
2015-10-03 04:16:31 +08:00
|
|
|
void (*disable)(struct device *dev);
|
2016-02-06 06:12:40 +08:00
|
|
|
|
|
|
|
/** Pointer to the read routine. */
|
2015-10-03 04:16:31 +08:00
|
|
|
int (*read)(struct device *dev, struct adc_seq_table *seq_table);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable ADC hardware
|
|
|
|
*
|
|
|
|
* This routine enables the ADC hardware block for data sampling for the
|
|
|
|
* specified device.
|
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
static inline void adc_enable(struct device *dev)
|
|
|
|
{
|
2016-10-22 16:55:47 +08:00
|
|
|
const struct adc_driver_api *api = dev->driver_api;
|
2015-10-03 04:16:31 +08:00
|
|
|
|
|
|
|
api->enable(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable ADC hardware
|
|
|
|
*
|
|
|
|
* This routine disables the ADC hardware block for data sampling for the
|
|
|
|
* specified device.
|
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
static inline void adc_disable(struct device *dev)
|
|
|
|
{
|
2016-10-22 16:55:47 +08:00
|
|
|
const struct adc_driver_api *api = dev->driver_api;
|
2015-10-03 04:16:31 +08:00
|
|
|
|
|
|
|
api->disable(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set a read request.
|
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* This routine sends a read or sampling request to the ADC hardware block.
|
|
|
|
* A sequence table describes the read request.
|
|
|
|
* The routine returns once the ADC completes the read sequence.
|
2016-01-29 00:42:47 +08:00
|
|
|
* The sample data can be retrieved from the memory buffers in
|
|
|
|
* the sequence table structure.
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2016-02-06 06:12:40 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance.
|
|
|
|
* @param seq_table Pointer to the structure representing the sequence table.
|
2015-10-03 04:16:31 +08:00
|
|
|
*
|
2016-03-10 01:01:20 +08:00
|
|
|
* @retval 0 On success
|
2016-02-06 06:12:40 +08:00
|
|
|
* @retval else Otherwise.
|
2015-10-03 04:16:31 +08:00
|
|
|
*/
|
|
|
|
static inline int adc_read(struct device *dev, struct adc_seq_table *seq_table)
|
|
|
|
{
|
2016-10-22 16:55:47 +08:00
|
|
|
const struct adc_driver_api *api = dev->driver_api;
|
2015-10-03 04:16:31 +08:00
|
|
|
|
|
|
|
return api->read(dev, seq_table);
|
|
|
|
}
|
|
|
|
|
2015-10-26 18:18:44 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 04:16:31 +08:00
|
|
|
#endif /* __INCLUDE_ADC_H__ */
|