[Feature][ZXW-163][ADC]Add Get ADC Voltage API
Only Configure:No
Affected branch:master
Affected module:ADC
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Yes
Change-Id: Icd1778a0782227379f497a5e573121f9db698098
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp
new file mode 100755
index 0000000..b392fca
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sc_bsp.h>
+#include <errno.h>
+#include "lynq-adc.h"
+#include "liblog/lynq_deflog.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ADC0_NODES "/sys/kernel/debug/pmu_zx29/adc0"
+#define ADC1_NODES "/sys/kernel/debug/pmu_zx29/adc1"
+#define ADC2_NODES "/sys/kernel/debug/pmu_zx29/adc2"
+
+/********************************************************************
+* @brief: qser_adc_show, function to read ADC value from specific channel
+* @param qadc [IN]: ADC_CHANNEL_E, the ADC channel to read from
+* @return : int, the read ADC value, or error code if failed
+* @todo: NA
+* @see: NA
+* @warning: NA
+*********************************************************************/
+int qser_adc_show(ADC_CHANNEL_E qadc)
+{
+ int adc_value;
+ char cmd[1024];
+ char cmd_ret[1024];
+ FILE *fp;
+ switch(qadc)
+ {
+ case QADC_NONE:
+ {
+ LYERRLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ return 0;
+ }
+ case ADC0:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd, "cat %s", ADC0_NODES);
+ break;
+ }
+ case ADC1:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd, "cat %s", ADC1_NODES);
+ break;
+ }
+ case ADC2:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd, "cat %s", ADC2_NODES);
+ break;
+ }
+ default:
+ {
+ LYERRLOG("input error\n");
+ return -1;
+ }
+ }
+ if((fp = popen(cmd,"r")) == NULL)
+ {
+ LYERRLOG("popen error: %s", strerror(errno));
+ return -1;
+ }
+ if((fread(cmd_ret,sizeof(cmd_ret),1,fp))<0)
+ {
+ LYERRLOG("fread fail: %s", strerror(errno));
+ fclose(fp);
+ return -1;
+ }
+ fclose(fp);
+ adc_value = atoi(cmd_ret);
+ if (adc_value < 0 || adc_value > 12000)
+ {
+ LYERRLOG("bad adc value %s!", cmd_ret);
+ return -1;
+ }
+ return adc_value;
+}
+
+DEFINE_LYNQ_LIB_LOG(LYNQ_ADC)
+
+#ifdef __cplusplus
+}
+#endif
+