FreeRTOS: Common I/O
AWS IoT Common I/O library
Return to main page ↑
iot_adc.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS Common IO V1.0.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
30 #ifndef _IOT_ADC_H_
31 #define _IOT_ADC_H_
32 
36 #define IOT_ADC_SUCCESS ( 0 )
37 #define IOT_ADC_FAILED ( 1 )
38 #define IOT_ADC_INVALID_VALUE ( 2 )
39 #define IOT_ADC_NOT_OPEN ( 3 )
40 #define IOT_ADC_FUNCTION_NOT_SUPPORTED ( 4 )
41 #define IOT_ADC_CH_BUSY ( 5 )
47 struct IotAdcDescriptor;
48 
54 typedef struct IotAdcDescriptor * IotAdcHandle_t;
55 
65 typedef void ( * IotAdcCallback_t )( uint16_t * pusConvertedData,
66  void * pvUserContext );
67 
85 IotAdcHandle_t iot_adc_open( int32_t lAdc );
86 
99 int32_t iot_adc_close( IotAdcHandle_t const pxAdc );
100 
129 void iot_adc_set_callback( IotAdcHandle_t const pxAdc,
130  uint8_t ucAdcChannel,
131  IotAdcCallback_t xAdcCallback,
132  void * pvUserContext );
133 
193 int32_t iot_adc_start( IotAdcHandle_t const pxAdc,
194  uint8_t ucAdcChannel );
195 
207 int32_t iot_adc_stop( IotAdcHandle_t const pxAdc,
208  uint8_t ucAdcChannel );
209 
253 int32_t iot_adc_read_sample( IotAdcHandle_t const pxAdc,
254  uint8_t ucAdcChannel,
255  uint16_t * pusAdcSample );
256 
264 typedef struct IotAdcConfig_s
265 {
266  uint32_t ulAdcSampleTime;
269  uint8_t ucAdcResolution;
271 
272 typedef enum
273 {
277 
281 typedef struct IotAdcChStatus_s
282 {
283  uint8_t ucAdcChannel;
286 
298 typedef struct IotAdcChBuffer_s
299 {
300  uint8_t ucAdcChannel;
301  void * pvBuffer;
302  uint8_t ucBufLen;
304 
313 typedef struct IoTAdcChain_s
314 {
315  uint8_t ucAdcChannel;
318  void * pvBuffer;
320  uint8_t ucBufLen;
321  uint16_t usChainMask;
324 } IotAdcChain_t;
325 
329 typedef enum IotAdcIoctlRequest_s
330 {
337 
354 int32_t iot_adc_ioctl( IotAdcHandle_t const pxAdc,
355  IotAdcIoctlRequest_t xRequest,
356  void * const pvBuffer );
357 
358 #endif /* _IOT_ADC_H_ */
uint8_t ucAdcResolution
Definition: iot_adc.h:269
Definition: iot_adc.h:334
uint8_t ucAdcChannel
Definition: iot_adc.h:300
data structure for ioctl GetChStatus
Definition: iot_adc.h:281
Definition: iot_adc.h:335
Definition: iot_adc.h:331
uint8_t ucBufLen
Definition: iot_adc.h:302
void iot_adc_set_callback(IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel, IotAdcCallback_t xAdcCallback, void *pvUserContext)
Sets channel callback on availability of channel scan data. On availability of ADC scan data...
struct IotAdcDescriptor * IotAdcHandle_t
IotAdcHandle_t is the handle type returned by calling iot_adc_open(). This is initialized in open and...
Definition: iot_adc.h:54
data structures for ioctl request
Definition: iot_adc.h:264
void(* IotAdcCallback_t)(uint16_t *pusConvertedData, void *pvUserContext)
adc notification callback type
Definition: iot_adc.h:65
int32_t iot_adc_close(IotAdcHandle_t const pxAdc)
Close ADC controller. All pending operation will be cancelled, put ADC module in reset state or low p...
Definition: iot_adc.h:333
int32_t iot_adc_stop(IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel)
Stop data acquisition for ADC channel.
int32_t iot_adc_read_sample(IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel, uint16_t *pusAdcSample)
read one ADC data sample. This API will return one ADC sample.
IotAdcHandle_t iot_adc_open(int32_t lAdc)
Initializes ADC controller with default configuration. init ADC controller, enable ADC clock...
uint16_t usChainMask
Definition: iot_adc.h:321
uint8_t ucAdcChannel
Definition: iot_adc.h:283
IotAdcChState_t xAdcChState
Definition: iot_adc.h:284
IotAdcChState_t
Definition: iot_adc.h:272
Definition: iot_adc.h:332
uint32_t ulAdcSampleTime
Definition: iot_adc.h:266
IotAdcIoctlRequest_t
adc ioctl request types.
Definition: iot_adc.h:329
Definition: iot_adc.h:274
int32_t iot_adc_ioctl(IotAdcHandle_t const pxAdc, IotAdcIoctlRequest_t xRequest, void *const pvBuffer)
Used for various ADC control functions.
uint8_t ucBufLen
Definition: iot_adc.h:320
Definition: iot_adc.h:275
void * pvBuffer
Definition: iot_adc.h:301
void * pvBuffer
Definition: iot_adc.h:318
uint8_t ucAdcChannel
Definition: iot_adc.h:315
data structure for ioctl SetChBuffer setting channel data buffer is optional using this ioctl if clie...
Definition: iot_adc.h:298
Some ADC host controller supports grouping multiple ADC channels into a chain. When the chain is trig...
Definition: iot_adc.h:313
int32_t iot_adc_start(IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel)
Start data acquisition for ADC channel until iot_adc_stop API is called. data will be passed back to ...