[Feature][T106][task-view-1364][ADC] add qser_adc_show underlying query only once
Only Configure:No
Affected branch:master
Affected module:ADC
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Change-Id: I84161617342580e132cf948bd2ac45356e7ec7ee
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp
index a465ae3..1286d7d 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-adc/lynq-adc.cpp
@@ -3,6 +3,8 @@
#include <string.h>
#include <sc_bsp.h>
#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "lynq-adc.h"
#include "liblog/lynq_deflog.h"
@@ -14,6 +16,8 @@
#define ADC1_NODES "/sys/kernel/debug/pmu_zx29/adc1"
#define ADC2_NODES "/sys/kernel/debug/pmu_zx29/adc2"
+static int adc_count_initialized = 0;
+
/********************************************************************
* @brief: qser_adc_show, function to read ADC value from specific channel
* @param qadc [IN]: ADC_CHANNEL_E, the ADC channel to read from
@@ -27,6 +31,19 @@
int adc_value;
char cmd_ret[1024]={0};
FILE *fd;
+
+ if (!adc_count_initialized) {
+ int fd_init;
+ if ((fd_init = open("/sys/kernel/debug/pmu_zx29/set_adc_count", O_WRONLY)) != -1) {
+ ssize_t ret = write(fd_init, "1", 1);
+ close(fd_init);
+ adc_count_initialized = 1;
+ LYDBGLOG("ADC count initialized, write returned: %zd bytes\n", ret);
+ } else {
+ LYERRLOG("Failed to initialize ADC count: %s\n", strerror(errno));
+ }
+ }
+
switch(qadc)
{
case QADC_NONE: