145 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			145 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#ifndef IOT_ADC_API_H
 | 
						|
#define IOT_ADC_API_H
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#include "iot_errno_api.h"
 | 
						|
 | 
						|
/** \defgroup MISC_APIs MISC APIs
 | 
						|
 *  @brief MISC APIs
 | 
						|
 *
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
/** @addtogroup MISC_APIs
 | 
						|
 * @{
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
/**
 | 
						|
  * @brief ADC channel.
 | 
						|
  */
 | 
						|
typedef enum {
 | 
						|
    ADC_CHANNEL0 = 0,
 | 
						|
    ADC_CHANNEL1 = 1,
 | 
						|
    ADC_CHANNEL2 = 2,
 | 
						|
    ADC_CHANNEL3 = 3,
 | 
						|
    ADC_CHANNEL4 = 4,
 | 
						|
    ADC_CHANNEL5 = 5,
 | 
						|
    ADC_CHANNEL2_3 = 6,
 | 
						|
    ADC_CHANNEL0_1 = 7,
 | 
						|
    ADC_CHANNEL6 = 8,
 | 
						|
    ADC_CHANNEL7 = 9,
 | 
						|
    ADC_CHANNEL4_5 = 10,
 | 
						|
    ADC_CHANNEL6_7 = 11,
 | 
						|
    ADC1_CHANNEL0 = 12,
 | 
						|
    ADC1_CHANNEL1 = 13,
 | 
						|
    ADC1_CHANNEL2 = 14,
 | 
						|
    ADC1_CHANNEL3 = 15,
 | 
						|
    ADC1_CHANNEL4 = 16,
 | 
						|
    ADC1_CHANNEL5 = 17,
 | 
						|
    ADC1_CHANNEL0_1 = 18,
 | 
						|
    ADC1_CHANNEL2_3 = 19,
 | 
						|
    ADC1_CHANNEL4_5 = 20,
 | 
						|
    ADC_CHANNEL_INVALID = 0xff,
 | 
						|
} ADC_CHANNEL;
 | 
						|
 | 
						|
/**
 | 
						|
  * @brief ADC ACC, the num(1<<ADC_ACC_X) adc data will accumulate.
 | 
						|
  */
 | 
						|
typedef enum {
 | 
						|
    ADC_ACC16 = 4,
 | 
						|
    ADC_ACC64 = 6,
 | 
						|
} ADC_ACC;
 | 
						|
 | 
						|
/**
 | 
						|
  * @brief ADC GAIN.
 | 
						|
  */
 | 
						|
typedef enum {
 | 
						|
    ADC_GAIN_1V = 11,
 | 
						|
    ADC_GAIN_3V = 15,
 | 
						|
} ADC_GAIN;
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_adc_init() - init adc sub system
 | 
						|
 *
 | 
						|
 */
 | 
						|
void iot_adc_init();
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_adc_poll_done() - poll adc's output code which is calibrated.
 | 
						|
 *          Notice: this api is unsupported on KL3.
 | 
						|
 * @param ch:  adc channel.
 | 
						|
 * @param acc:  enum ADC_ACC
 | 
						|
 * @param gain: enum ADC_GAIN
 | 
						|
 * @param err_num: err_num return value:
 | 
						|
                   0 - normal. data is OK;
 | 
						|
                   1 - abnormal, data is not OK;
 | 
						|
                   2 - device in use;
 | 
						|
 * @return        adc code value, which can be converted to mV voltage value by
 | 
						|
                    following formula:
 | 
						|
                    on KL1, gain = ADC_GAIN_3V: voltage = code * 3200 / 511
 | 
						|
                    on KL1, gain = ADC_GAIN_1V: voltage = code * 1280 / 511
 | 
						|
                    on KL2: voltage = code * 350 / 2360
 | 
						|
                    on KL3: code value is invalid
 | 
						|
 */
 | 
						|
int32_t iot_adc_poll_done(uint32_t ch, uint8_t acc, uint8_t gain,
 | 
						|
    uint8_t *err_num);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_adc_poll_get_volt() - poll adc's output voltage which is calibrated.
 | 
						|
 * @param ch:  adc channel.
 | 
						|
 * @param gain: enum ADC_GAIN
 | 
						|
 * @param err_num: err_num return value:
 | 
						|
                   0 - normal. data is OK;
 | 
						|
                   1 - abnormal, data is not OK;
 | 
						|
                   2 - device in use;
 | 
						|
 *
 | 
						|
 * @return        adc voltage value, unit mV.
 | 
						|
 */
 | 
						|
int32_t iot_adc_poll_get_volt(uint32_t ch, uint8_t gain, uint8_t *err_num);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_adc_poll_forever_done() - poll adc's output until poll available
 | 
						|
 *          Notice: this api is unsupported on KL3.
 | 
						|
 * @param ch:  adc channel.
 | 
						|
 * @param acc:  enum ADC_ACC
 | 
						|
 * @param gain: enum ADC_GAIN
 | 
						|
 * @param err_num: err_num return value;
 | 
						|
                   0 - normal. data is OK
 | 
						|
                   1 - abnormal, data is not OK.
 | 
						|
 * @return        adc value
 | 
						|
 */
 | 
						|
int32_t iot_adc_poll_forever_done(uint32_t ch, uint8_t acc,
 | 
						|
    uint8_t gain, uint8_t *err_num);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_adc_get_core_temperature(uint8_t type) - get core temperature
 | 
						|
 * @return:  core temperature, unit: degrees centigrade.
 | 
						|
 * @param type: temperature type: 0 rawdata  1 Calibrated data
 | 
						|
 */
 | 
						|
float iot_adc_get_core_temperature(uint8_t type);
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif //IOT_ADC_API_H
 |