MTK功能机获取ADC电压

jues 提交于 2019/07/24 - 12:57 周三

标签

内容

文件:<PROJECT>\interface\hal\peripheral\dcl_adc.h


//ADC_CMD_GET_CHANNEL
typedef enum {
   DCL_VBAT_ADC_CHANNEL = 0,
   DCL_VISENSE_ADC_CHANNEL,
   DCL_VBATTMP_ADC_CHANNEL,
   DCL_BATTYPE_ADC_CHANNEL,
   DCL_VCHARGER_ADC_CHANNEL,
   DCL_PCBTMP_ADC_CHANNEL,
   DCL_AUX_ADC_CHANNEL,
   DCL_CHR_USB_ADC_CHANNEL,
   DCL_OTG_VBUS_ADC_CHANNEL,
   DCL_RFTMP_ADC_CHANNEL,
   DCL_XP_ADC_CHANNEL,
   DCL_YP_ADC_CHANNEL,
   DCL_YM_ADC_CHANNEL,
   DCL_XM_ADC_CHANNEL, 
   DCL_MAX_ADC_CHANNEL
} DCL_ADC_CHANNEL_TYPE_ENUM;

 

文件:<PROJECT>\hal\peripheral\src\bmt_utility.c

kal_bool bmt_get_adc_channel_voltage(DCL_ADC_CHANNEL_TYPE_ENUM ch, kal_uint32 *voltage)
{

 

例:DCL_AUX_ADC_CHANNEL

文件:<PROJECT>\custom\drv\Drv_Tool\ADC.cmp

确认文件中有ADC_ACCESSORYID

[ADC_variables]
ADC_VBAT
ADC_VISENSE
ADC_VBATTMP
ADC_VCHARGER
ADC_ACCESSORYID
ADC_PCBTMP
ADC_CHR_USB
ADC_OTG_VBUS
ADC_RFTMP
ADC_JACK_TYPE
[adc_var.c_HEADER]

#ifdef __CUST_NEW__
#include "kal_release.h"
#include "dcl.h"
[adc_var.c_TAILER]

#endif /*__CUST_NEW__ */

配置dws

MTK功能机获取ADC电压

对应配置代码:

文件:<PROJECT>\hal\peripheral\src\adcsche.c

kal_uint8 adc_sche_get_channel(adc_channel_type type)
{
   kal_uint8 VBAT, VISENSE, VCHARGER, VBATTEMP;
   
#if defined(PMIC_FIXED_3_ADC_CH)
   VBAT = PMIC_ADC_VBAT_CH_NUM;
   VISENSE = PMIC_ADC_VISENSE_CH_NUM;
   VCHARGER = PMIC_ADC_VCHARGER_CH_NUM;
#if defined(PMIC_FIXED_4_ADC_CH)   
   VBATTEMP = PMU_ADC_VBATTEMP_CH_NUM;
#else
   VBATTEMP = ADC_VBATTMP;
#endif
#else
   VBAT = ADC_VBAT;
   VISENSE = ADC_VISENSE;
   VCHARGER = ADC_VCHARGER;
   VBATTEMP = ADC_VBATTMP;
#endif //#if defined(PMIC_FIXED_3_ADC_CH)

   switch(type)
   {
      case vbat_adc_channel:
         return ((kal_uint8)VBAT);
      case visense_adc_channel:
         return ((kal_uint8)VISENSE);
      case vbattmp_adc_channel:
         return ((kal_uint8)VBATTEMP);
      case aux_adc_channel:
         return ((kal_uint8)ADC_ACCESSORYID);
      case vcharger_adc_channel:
         return ((kal_uint8)VCHARGER);     
      case pcbtmp_adc_channel:
         return ((kal_uint8)ADC_PCBTMP);
      case chr_usb_adc_channel:
         return ((kal_uint8)ADC_CHR_USB);        
      case otg_vbus_adc_channel:
         return ((kal_uint8)ADC_OTG_VBUS);	
      case rftmp_adc_channel:
         return ((kal_uint8)ADC_RFTMP);
      default:
         ASSERT(0);         
         return 100;
   }
}

 

 

 

实现代码:

kal_bool ret;
kal_uint32 voltage;

ret = bmt_get_adc_channel_voltage(DCL_AUX_ADC_CHANNEL,&voltage);

 

注意事项

文件:\hal\peripheral\src\bmt_utility.c

kal_bool bmt_get_adc_channel_voltage(DCL_ADC_CHANNEL_TYPE_ENUM ch, kal_uint32 *voltage)
{
	DCL_HANDLE adc_handle;
   	ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_get_channel;
	ADC_CTRL_GET_DATA_T adc_data;
	ADC_CTRL_TRANSFORM_INTO_VOLT_T adcTransV;


    // 注意如果你需要使用的channel大于DCL_VCHARGER_ADC_CHANNEL,请更改此处。
	if(ch > DCL_VCHARGER_ADC_CHANNEL)
		return KAL_FALSE;  

 

添加新评论

此字段内容将保密,不会被其他人看见。