[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/lynq/lib/liblynq-driver-control/MODULE_LICENSE_APACHE2 b/src/lynq/lib/liblynq-driver-control/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/MODULE_LICENSE_APACHE2
diff --git a/src/lynq/lib/liblynq-driver-control/Makefile b/src/lynq/lib/liblynq-driver-control/Makefile
new file mode 100644
index 0000000..7130bfd
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/Makefile
@@ -0,0 +1,63 @@
+PREFIX = ../install
+CROSS = arm-none-linux-
+ROOT = $(PREFIX)/$(CROSS:%-=%)
+
+#For Yocto use
+
+RFX_TEST_CLIENT = false
+RFX_TEST_AOSP = false
+
+$(warning ########## libvendor_ril BB_TELEFWK_OPTION $(BB_TELEFWK_OPTION) ##########)
+
+
+
+SUBDIRS += liblynq-driver-control
+
+
+
+
+
+$(warning ########## lynq-rilcmd SUBDIRS $(SUBDIRS) ##########)
+export SIM_COUNT?=1
+
+.PHONY: all build clean pack_rootfs
+
+all: build
+
+build: clean
+
+clean:
+ $(warning ########## clean ril ##########)
+ for i in $(SUBDIRS); do \
+ (cd $$i && make clean); \
+ if [ $$? != 0 ]; then \
+ exit 1; \
+ fi \
+ done
+
+build:
+ $(warning ########## build ril ##########)
+ for i in $(SUBDIRS); do \
+ (cd $$i && make); \
+ if [ $$? != 0 ]; then \
+ exit 1; \
+ fi \
+ done
+
+install:
+ $(warning ########## install ril ##########)
+ for i in $(SUBDIRS); do \
+ (cd $$i && make install); \
+ if [ $$? != 0 ]; then \
+ exit 1; \
+ fi \
+ done
+
+pack_rootfs:
+ $(warning ########## pack_rootfs ril ##########)
+ for i in $(SUBDIRS); do \
+ (cd $$i && make pack_rootfs); \
+ if [ $$? != 0 ]; then \
+ exit 1; \
+ fi \
+ done
diff --git a/src/lynq/lib/liblynq-driver-control/NOTICE b/src/lynq/lib/liblynq-driver-control/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/src/lynq/lib/liblynq-driver-control/README b/src/lynq/lib/liblynq-driver-control/README
new file mode 100644
index 0000000..9a7e82f
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/README
@@ -0,0 +1,13 @@
+WHAT IT DOES?
+=============
+MTK ril proxy core library
+
+HOW IT WAS BUILT?
+==================
+This module is source code released.
+
+HOW TO USE IT?
+==============
+MTK ril proxy daemon will use this library to communicate with GSM and C2K RILD.
+
+All the source code of this folder were written by MediaTek co..
diff --git a/src/lynq/lib/liblynq-driver-control/include/adc/adc.h b/src/lynq/lib/liblynq-driver-control/include/adc/adc.h
new file mode 100644
index 0000000..a119803
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/adc/adc.h
@@ -0,0 +1,5 @@
+#ifndef __ADC_H__
+#define __ADC_H__
+int lynq_set_adc_channel(unsigned char channel_val);
+float lynq_get_adc_data(void);
+#endif //__ADC_H__
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/include/i2c/i2c.h b/src/lynq/lib/liblynq-driver-control/include/i2c/i2c.h
new file mode 100644
index 0000000..881f343
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/i2c/i2c.h
@@ -0,0 +1,7 @@
+#ifndef __I2C_H__
+#define __I2C_H__
+
+int lynq_set_i2c_deplop(int set_bus_id,int set_address,int set_speedhz,unsigned int rx_length);
+int lynq_i2c_tx(int wr_len,char *wr_buf);
+int lynq_i2c_rx(int *rd_len, char *rd_buf);
+#endif
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/include/liblynq-driver-control/libdriver.h b/src/lynq/lib/liblynq-driver-control/include/liblynq-driver-control/libdriver.h
new file mode 100644
index 0000000..2cc4804
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/liblynq-driver-control/libdriver.h
@@ -0,0 +1,12 @@
+#ifndef __LYNQ_DRIVER_CONTROL_H__
+#define __LYNQ_DRIVER_CONTROL_H__
+typedef int BOOL;
+typedef void (*triggerCallback)(const char*, int);
+void disconnect_key();
+void register_key_info();
+int trigger_loop();
+//BOOL ServiceIsReady(void);
+void registerTriggerCallback(triggerCallback callback);
+int lynq_set_gpio (char * mode,int gpio_numb,int param);
+void lynq_get_gpio (int gpio_numb,char *response);
+#endif //__LOG_H__
diff --git a/src/lynq/lib/liblynq-driver-control/include/pwm/pwm.h b/src/lynq/lib/liblynq-driver-control/include/pwm/pwm.h
new file mode 100644
index 0000000..b86978f
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/pwm/pwm.h
@@ -0,0 +1,5 @@
+#ifndef __PWM_H__
+#define __PWM_H__
+
+int factory_pwm_test(void);
+#endif //__PWM_H__
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/include/spi/spi.h b/src/lynq/lib/liblynq-driver-control/include/spi/spi.h
new file mode 100644
index 0000000..d1aeb51
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/spi/spi.h
@@ -0,0 +1,8 @@
+#ifndef __SPI_H__
+#define __SPI_H__
+int lynq_spi_recv_data(char *spi_data,unsigned int spi_len);
+int lynq_spi_send_data(char *spi_data,unsigned int spi_len);
+int lynq_spi_read_state(unsigned char spi_feature,unsigned int spi_valu);
+int lynq_spi_set_state(unsigned char spi_feature,unsigned int spi_valu);
+int lynq_spi_set_channel(unsigned char spi_channel);
+#endif //__SPI_H__
diff --git a/src/lynq/lib/liblynq-driver-control/include/uart/uart.h b/src/lynq/lib/liblynq-driver-control/include/uart/uart.h
new file mode 100644
index 0000000..69998e9
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/include/uart/uart.h
@@ -0,0 +1,5 @@
+#ifndef __UART_H__
+#define __UART_H__
+
+int lynq_set_uart_param(int device_node,int nSpeed, int nBits, char nEvent, int nStop);
+#endif //__SPI_H__
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/adc/adc.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/adc/adc.c
new file mode 100644
index 0000000..36aa3c1
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/adc/adc.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <math.h>
+#include <string.h>
+#include "adc.h"
+
+char iiotype[10][64] = {
+ "in_voltage21_GPS_ANT_input",//vin6
+ "in_voltage22_MAIN_ANT_input",//vin7
+ "in_voltage23_DRX_ANT_input",//vin8
+};
+
+
+FILE *device_fp;
+int lynq_set_adc_channel(unsigned char channel_val)
+{
+ int ret = 0;
+ char filename[80];
+ sprintf(filename, "/sys/bus/iio/devices/iio:device0/%s", iiotype[channel_val]);
+ device_fp = fopen(filename, "rt" );
+ if(device_fp == NULL)
+ {
+ printf("open %s fail!\n", filename);
+ ret = -1;
+ }
+ return ret;
+}
+
+float lynq_get_adc_data(void)
+{
+ float fvoltage = 0;
+ int value = 0;
+ char buf[20];
+ int ret = 0;
+
+ ret = fread( buf, 1, sizeof(buf), device_fp);
+ fclose(device_fp);
+ if(ret == 0)
+ {
+ printf("read adc error !!!\n");
+ return -1;
+ }
+ // convert to integer
+ sscanf( buf, "%d", &value);
+ printf("value:%d\n",value);
+ fvoltage = 0.001 * value;
+ printf("fvoltage:%.3f\n",fvoltage);
+ return fvoltage;
+}
+
+
+int factory_adc_test(void)
+{
+ int ret = 0;
+ float fvalue;
+ int i = 0;
+
+ // read AIN1
+ while(1)
+ {
+ i = 0;
+ printf("-----------------------------------------\n");
+ for(i = 0;i < 3;i++)
+ {
+ ret = lynq_set_adc_channel(i);
+ if(ret < 0)
+ {
+ printf("set adc channel error\n");
+ }
+ fvalue = lynq_get_adc_data();
+ printf("vin(%d) = %.3fV\n",i+6,fvalue);
+ }
+ printf("-----------------------------------------\n");
+ sleep(5);
+ }
+
+ return ret;
+}
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/driver_control.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/driver_control.c
new file mode 100644
index 0000000..62137a5
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/driver_control.c
@@ -0,0 +1,236 @@
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <gio/gio.h>
+#include <log/log.h>
+#include <glib.h>
+#include "libdriver.h"
+#define GPIO_SERVICE "gpio.lynq" /*well-known bus name */
+#define GPIO_DATA_INTERFACE "gpio.lynq.Data" /*interface name*/
+#define GPIO_DATA_PATH "/gpio/lynq/data" /*object name*/
+#define LOG_TAG "GPIO_CONTROL"
+static GMainLoop *loop = NULL;
+static GDBusProxy *pProxy = NULL;
+triggerCallback mtriggerCallback = NULL;;
+
+void proxy_signals_on_signal (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ gint32 status;
+ RLOGD("signal_name: %s\n", signal_name);
+ g_variant_get (parameters,"(i)",&status);
+ //RLOGD("listen singal ok,%d",status);
+ if(mtriggerCallback){
+ mtriggerCallback(signal_name,status);
+ }
+ else
+ {
+ RLOGE("mbroadcastcallback NULL");
+ }
+ printf("trigger status is %d\n",status);
+}
+
+BOOL registerClientSignalHandler(GDBusProxy *proxy)
+{
+ gulong signal_handler_id;
+ signal_handler_id = g_signal_connect(proxy, "g-signal",
+ G_CALLBACK (proxy_signals_on_signal), NULL);
+ RLOGD("proxy is ready");
+ if (signal_handler_id == 0) {
+ RLOGD("listen singal fail!");
+ return FALSE;
+ }
+ return TRUE;
+}
+void registerTriggerCallback(triggerCallback callback)
+{
+ if (NULL != callback){
+ //memcpy(&mbroadcastcallback, callback, sizeof(broadcastCallback));
+ mtriggerCallback = callback;
+ }
+ else{
+ RLOGD("registerSignalCallback: parameter point is NULL");
+ }
+}
+void *run(void* arg)
+{
+
+ /** start the main event loop which manages all available sources of events */
+ g_main_loop_run(loop);
+ return ((void*)0);
+}
+
+void disconnect_key(void)
+{
+ if(pProxy != NULL) {
+ g_object_unref (pProxy);
+ }
+ if(loop != NULL) {
+ g_main_loop_unref(loop);
+ }
+}
+int thread_create(void)
+{
+ int err;
+ pthread_t thr;
+
+ err = pthread_create(&thr, NULL, run, NULL);
+ if(0 != err){
+ RLOGD("Can't create thread: %s\n", strerror(err));
+ }
+ else{
+ RLOGD("New thread created: %s\n", strerror(err));
+ }
+
+ return err;
+}
+int trigger_loop()
+{
+ g_main_loop_run(loop);
+}
+
+BOOL service_ready(void)
+{
+ gchar *owner_name = NULL;
+ owner_name = g_dbus_proxy_get_name_owner((GDBusProxy*)pProxy);
+ if(NULL != owner_name)
+ {
+ RLOGD("Owner Name: %s\n", owner_name);
+ g_free(owner_name);
+ return TRUE;
+ }
+ else
+ {
+ g_print("Owner Name is NULL.");
+ return FALSE;
+ }
+}
+
+void register_key_info(void){
+ GError *error = NULL;
+ RLOGD("go!\n");
+ loop = g_main_loop_new(NULL, FALSE);
+
+ pProxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo */
+ GPIO_SERVICE,
+ GPIO_DATA_PATH,
+ GPIO_DATA_INTERFACE,
+ NULL, /* GCancellable */
+ &error);
+ if (pProxy == NULL)
+ {
+ RLOGD ("Error creating proxy: %s\n", error->message);
+ disconnect_key();
+ }
+ if (registerClientSignalHandler(pProxy)== FALSE){
+ RLOGD ("register Error");
+ disconnect_key();
+ }
+ while(service_ready() != TRUE);
+ thread_create();
+}
+
+int lynq_set_gpio (char * mode,int gpio_numb,int param)
+{
+ GDBusConnection *c1;
+ GVariant *result;
+ GError *error;
+ GMainLoop *loop;
+ gint32 set_result = -1;
+ g_type_init();
+ loop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
+ error = NULL;
+ c1 = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ g_assert_no_error (error);
+ error = NULL;
+ g_assert (c1 != NULL);
+ g_assert (!g_dbus_connection_is_closed (c1));
+ result = g_dbus_connection_call_sync (c1,
+ GPIO_SERVICE, /* bus name */
+ GPIO_DATA_PATH, /* object path */
+ GPIO_DATA_INTERFACE, /* interface name */
+ "setGpio", /* method name */
+ g_variant_new ("(sii)", mode,gpio_numb,param), /* parameters */
+ G_VARIANT_TYPE ("(i)"), /* return type */
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (result != NULL);
+ g_variant_get(result, "(i)", &(set_result));
+ // RLOGD("%s, %s, %d,result:%d", __FILE__, __FUNCTION__, __LINE__,set_result);
+ g_variant_unref (result);
+ //g_main_loop_run (loop);
+ g_main_loop_unref (loop);
+ return set_result;
+}
+/*
+int set_gpio143(){
+ int result;
+ result = set_gpio (GPIO_MODE,WIFI_LED_CONTROL,1);
+ return result;
+ // sprintf(output, "gpio set stauts %d\n",result);
+ // printf("%s",output);
+ // emResultNotify(output);
+}*/
+void lynq_get_gpio (int gpio_numb,char *response)
+{
+ GDBusConnection *c1;
+ GError *error;
+ GMainLoop *loop;
+ //char output[2048] = {0};
+ //gchar *response;
+ GVariant *get;
+ gsize n_elts=0;
+ GVariantIter *iter;
+ //guchar *response;
+ gchar *get_res;
+// const char *p;
+ g_type_init();
+ loop = g_main_loop_new(NULL, FALSE); /** create main loop, but do not start it.*/
+ error = NULL;
+ c1 = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ g_assert_no_error (error);
+ error = NULL;
+ g_assert (c1 != NULL);
+ g_assert (!g_dbus_connection_is_closed (c1));
+ error = NULL;
+ get = g_dbus_connection_call_sync (c1,
+ GPIO_SERVICE,
+ GPIO_DATA_PATH,
+ GPIO_DATA_INTERFACE,
+ "getGpio",
+ g_variant_new ("(i)",gpio_numb),
+ G_VARIANT_TYPE ("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (get != NULL);
+ g_variant_get (get, "(s)",&get_res);
+ strcpy(response, get_res);
+ g_variant_unref (get);
+ RLOGD("get_gpio,%s",response);
+ g_main_loop_unref (loop);
+}
+/*
+void get_gpio143(){
+ char output[1024] = {0};
+ char output1[2048] = {0};
+ get_gpio (WIFI_LED_CONTROL,output);
+ printf("get_gpio143,%s\n",output);
+
+}
+*/
+
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/i2c/i2c.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/i2c/i2c.c
new file mode 100644
index 0000000..9a67ddf
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/i2c/i2c.c
@@ -0,0 +1,198 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include<fcntl.h>
+#include "i2c.h"
+
+#define I2C_SEND_DATA_LEN 1024
+#define I2C_SEND_PTR_LEN 1024
+
+static char *device = "/proc/i2c_debug"; //设备名
+static int bus_id = 0;
+static int address = 0;
+static unsigned int speedhz = 0;
+static unsigned int red_length = 0;
+static int pows(int x, int y)
+{
+ int result = 1;
+
+ while (y--)
+ result *= x;
+ return result;
+}
+
+int string2hex(const char *buffer, int cnt)
+{
+ int c = 0;
+ char t = 0;
+ int count = cnt;
+
+ while (count--) {
+ t = *(buffer + cnt - count - 1);
+ if (t >= 'A' && t <= 'F')
+ c += ((t - 'A') + 10) * pows(16, count);
+ else if (t >= 'a' && t <= 'f')
+ c += ((t - 'a') + 10) * pows(16, count);
+ else if (t >= '0' && t <= '9')
+ c += (t - '0') * pows(16, count);
+ else
+ c = -1;
+ }
+ return c;
+}
+
+int get_hexbuffer(char *data_buffer, char *hex_buffer)
+{
+ char *ptr = data_buffer;
+ int index = 0;
+ int data_offset = 0;
+
+ while (*ptr && *++ptr) {
+ *(hex_buffer + index++) = string2hex(ptr - 1, 2);
+ ptr++;
+ data_offset++;
+ }
+ *(hex_buffer + index) = 0;
+ return data_offset;
+}
+
+static void hex2string(unsigned char *in, unsigned char *out, int length)
+{
+ unsigned char *ptr = in;
+ unsigned char *ptrout = out;
+ unsigned char t;
+
+ while (length--) {
+ t = (*ptr & 0xF0) >> 4;
+ if (t < 10)
+ *ptrout = t + '0';
+ else
+ *ptrout = t + 'A' - 10;
+
+ ptrout++;
+
+ t = (*ptr & 0x0F);
+ if (t < 10)
+ *ptrout = t + '0';
+ else
+ *ptrout = t + 'A' - 10;
+
+ ptr++;
+ ptrout++;
+ }
+ *ptrout = 0;
+}
+
+int lynq_set_i2c_deplop(int set_bus_id,int set_address,int set_speedhz,unsigned int rx_length)
+{
+ bus_id = set_bus_id;
+ address = set_address;
+ speedhz = set_speedhz;
+ red_length = rx_length;
+ return 1;
+}
+
+int lynq_i2c_tx(int wr_len,char *wr_buf)
+{
+ int fd;
+ int ret = 0;
+ char str[I2C_SEND_DATA_LEN + 64];
+ char *ptr_buf = NULL;
+
+ if((wr_len > (I2C_SEND_DATA_LEN / 2)) || (wr_buf == NULL))
+ {
+ return -1;
+ }
+ fd = open(device, O_RDWR); //打开"/dev/i2c_debug"
+
+ if (fd < 0)
+ {
+ printf("can't open device");
+ ret = -1;
+ return ret;
+ }
+
+ ptr_buf = malloc(I2C_SEND_PTR_LEN);
+ if(ptr_buf == NULL)
+ {
+ close(fd);
+ return -1;
+ }
+ hex2string(wr_buf,ptr_buf,wr_len);
+
+ sprintf(str,"%d %x %d %d %d %d %s",bus_id,address,2,wr_len*2,red_length,speedhz,ptr_buf);
+ printf("%s\n",str);
+ write(fd,str,strlen(str));
+
+ close(fd);
+ free(ptr_buf);
+ ptr_buf = NULL;
+ return ret;
+}
+
+int lynq_i2c_rx(int *rd_len, char *rd_buf)
+{
+ int fd;
+ int ret = 0;
+ char *ptr_buf = NULL;
+
+ if(red_length > (I2C_SEND_DATA_LEN / 2))
+ {
+ return -1;
+ }
+ fd = open(device, O_RDWR); //打开"/dev/i2c_debug"
+
+ if (fd < 0)
+ {
+ printf("can't open device");
+ ret = -1;
+ return ret;
+ }
+
+ ptr_buf = malloc(I2C_SEND_PTR_LEN);
+ if(ptr_buf == NULL)
+ {
+ close(fd);
+ return -1;
+ }
+ *rd_len = read(fd,ptr_buf,I2C_SEND_PTR_LEN);
+
+ printf("rx:%s\n",ptr_buf);
+ if(ptr_buf[0] == 0x31) //字符串1
+ {
+ *rd_len = get_hexbuffer(&ptr_buf[2],rd_buf);
+ printf("rd_len1:%d\n", *rd_len);
+ }
+ else
+ {
+ ret = -1;
+ printf("read error!!!\n");
+ }
+ close(fd);
+ free(ptr_buf);
+ ptr_buf = NULL;
+ return ret;
+}
+
+int factory_i2c_test(void)
+{
+ printf("i2c test start \n");
+ char rd_buf[1024] = {0};
+ int rd_len = 0;
+ char buf[10] = {1,2,3,4,5,6,7,8,9,128};
+ lynq_set_i2c_deplop(1,12,100000,20);
+ lynq_i2c_tx(sizeof(buf),buf);
+ lynq_i2c_rx(&rd_len,rd_buf);
+ printf("rd_len:%d\n",rd_len);
+ if(rd_len > 0)
+ {
+ printf("I2C_data:");
+ for(int i = 0; i < rd_len; i++)
+ {
+ printf("%02x ",rd_buf[i]);
+ }
+ printf("\n");
+ }
+
+ return 1;
+}
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/makefile b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/makefile
new file mode 100644
index 0000000..87afee6
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/makefile
@@ -0,0 +1,113 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+ -g -Os \
+ -flto \
+ -DRIL_SHLIB \
+ -DATCI_PARSE \
+ -DKEEP_ALIVE \
+ -DECALL_SUPPORT \
+
+$(warning ################# C2K support: $(RAT_CONFIG_C2K_SUPPORT))
+ifeq ($(strip $(RAT_CONFIG_C2K_SUPPORT)), yes)
+ LOCAL_CFLAGS += -DC2K_SUPPORT
+
+endif
+
+ifeq ($(strip $(MTK_MULTI_SIM_SUPPORT)), dsds)
+ LOCAL_CFLAGS += -DANDROID_SIM_COUNT_2 \
+ -DANDROID_MULTI_SIM \
+ -DMODE_DSDS
+endif
+
+ifeq ($(strip $(MTK_MULTI_SIM_SUPPORT)), dsss)
+ LOCAL_CFLAGS += -DMODE_DSSS
+endif
+
+$(warning ################# TARGET_PLATFORM: $(TARGET_PLATFORM))
+ifeq ($(strip $(TARGET_PLATFORM)), mt2731)
+#$(warning #################add for debug $(ROOT), $(includedir))
+$(warning ################# TARGET_PLATFORM_MT2731)
+ LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2731 \
+ -DMD_93_SUPPORT
+else ifeq ($(strip $(TARGET_PLATFORM)), mt2635)
+$(warning ################# TARGET_PLATFORM_MT2635)
+ LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2635 \
+ -DMD_90_SUPPORT
+endif
+
+$(warning ################# RITA ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH = .
+
+LOCAL_C_INCLUDES = \
+ -I. \
+ -I$(LOCAL_PATH)/../include/liblynq-driver-control \
+ -I$(LOCAL_PATH)/../include/adc \
+ -I$(LOCAL_PATH)/../include/i2c \
+ -I$(LOCAL_PATH)/../include/pwm \
+ -I$(LOCAL_PATH)/../include/spi \
+ -I$(LOCAL_PATH)/../include/uart \
+ -I$(ROOT)$(includedir)/logger \
+ -I$(ROOT)$(includedir)/gstreamer-1.0 \
+ -I$(ROOT)$(includedir)/glib-2.0 \
+ -I$(ROOT)$(libdir)/glib-2.0/include \
+ -I$(ROOT)$(libdir)/gstreamer-1.0/include\
+ -I$(ROOT)$(includedir)/dbus-1.0 \
+ -I$(ROOT)$(libdir)/dbus-1.0/include \
+
+
+LOCAL_LIBS := \
+ -L. \
+ -ldl \
+ -lstdc++ \
+ -llog \
+ -lcutils \
+ -lutils \
+ -lpower \
+ -lbinder \
+ -lpthread \
+ -lpal \
+ -lgstreamer-1.0 \
+ -lglib-2.0 \
+ -lgstbase-1.0 \
+ -lgstreamer-1.0 \
+ -lgobject-2.0 \
+ -lgio-2.0 \
+ -ldtmf \
+ -ldbus-1 \
+
+SOURCES = $(wildcard *.c wildcard *.h lynq_mqtt/*.c adc/*.c i2c/*.c pwm/*.c spi/*.c uart/*.c)
+
+EXECUTABLE = liblynq-driver-control.so
+
+OBJECTS=$(SOURCES:.c=.o)
+
+
+.PHONY: build clean install pack_rootfs
+
+all: build
+$(EXECUTABLE): $(OBJECTS)
+ $(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+ $(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+build: $(EXECUTABLE)
+ $(warning ########## build $(EXECUTABLE) ##########)
+
+install:
+ mkdir -p $(ROOT)$(base_libdir)/
+ install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+ mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
+
+pack_rootfs:
+ mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
+ cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/
+ $(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)
+ mkdir -p $(PACK_TO)$(base_libdir)/
+ cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/
+ $(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)
+.PHONY: clean
+clean:
+ $(RM) $(OBJECTS) $(EXECUTABLE)
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/pwm/pwm.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/pwm/pwm.c
new file mode 100644
index 0000000..94c974b
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/pwm/pwm.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include<stdlib.h>
+#include <string.h>
+#include "pwm.h"
+
+void lynq_enable_pwm0_parameterize(unsigned int pwm_units,unsigned int duty_cycle)
+{
+ char *open_pwm0 = "echo 0 > /sys/class/pwm/pwmchip0/export";
+ char *enable_pwm0 = "echo 1 >/sys/class/pwm/pwmchip0/pwm0/enable";
+ char pwm_units_buff[128] = {0};
+ char duty_cycle_buff[128] ={0};
+
+ system(open_pwm0);
+
+ sprintf(pwm_units_buff,"echo %d >/sys/class/pwm/pwmchip0/pwm0/period",pwm_units);
+ printf("%s\n",pwm_units_buff);
+ system(pwm_units_buff);
+
+ sprintf(duty_cycle_buff,"echo %d >/sys/class/pwm/pwmchip0/pwm0/period",duty_cycle);
+ printf("%s\n",duty_cycle_buff);
+ system(duty_cycle_buff);
+
+ system(enable_pwm0);
+}
+
+int factory_pwm_test(void) //gpio89做测试
+{
+ system("echo mode 89 1 > /sys/devices/platform/10005000.pinctrl/mt_gpio");
+ lynq_enable_pwm0_parameterize(1000000,500000);
+}
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/spi/spi.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/spi/spi.c
new file mode 100644
index 0000000..ebf4c6a
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/spi/spi.c
@@ -0,0 +1,382 @@
+#include <stdint.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/types.h>
+#include <linux/spi/spidev.h>
+#include "spi.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+static void pabort(const char *s)
+
+{
+
+ perror(s);
+
+ abort();
+
+}
+
+static char *device = "/dev/spidev2.0"; //设备名
+
+static uint8_t mode;
+
+static uint8_t bits = 8;
+
+static uint32_t speed = 500000;
+
+static uint16_t delay;
+
+static void transfer(int fd)
+
+{
+
+ int ret;
+
+ uint8_t tx[] = { //定义待发送的数据
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
+
+ 0xF0, 0x0D,
+
+ };
+
+ uint8_t rx[ARRAY_SIZE(tx)] = {0, };
+
+ struct spi_ioc_transfer tr = {
+ .tx_buf = (unsigned long)tx, //定义发送缓冲区指针
+
+ .rx_buf = (unsigned long)rx, //定义接收缓冲区指针
+
+ .len = ARRAY_SIZE(tx),
+
+ .delay_usecs = delay,
+
+ .speed_hz = speed,
+
+ .bits_per_word = bits,
+
+ };
+
+ ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);//执行spidev.c中ioctl的default进行数据传输
+
+ if (ret == 1)
+
+ pabort("can't send spi message");
+
+ for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
+ if (!(ret % 6))
+
+ puts("");
+
+ printf("%.2X ", rx[ret]); //打印接收到的数据
+
+ }
+
+ puts("");
+
+}
+
+int lynq_spi_set_channel(unsigned char spi_channel)
+{
+ int ret = 0;
+ switch(spi_channel){
+ case 0:{
+ device = "/dev/spidev0.0";
+ break;
+ }
+ case 1:{
+ device = "/dev/spidev1.0";
+ break;
+ }
+ case 2:{
+ device = "/dev/spidev2.0";
+ break;
+ }
+ case 3:{
+ device = "/dev/spidev3.0";
+ break;
+ }
+ default:{
+ printf("spi%d channel not exist\n",spi_channel);
+ ret = -1;
+ break;
+ }
+ }
+ printf("open %s\n",device);
+ return ret;
+}
+
+
+int lynq_spi_set_state(unsigned char spi_feature,unsigned int spi_valu)
+{
+ int ret = 0;
+ int fd;
+
+ fd = open(device, O_RDWR); //打开"/dev/spidev1.0"
+ if (fd < 0)
+ {
+ pabort("can't open device");
+ ret = -1;
+ }
+
+ switch(spi_feature)
+ {
+ case 1:{
+ ret = ioctl(fd, SPI_IOC_WR_MODE, &spi_valu); //SPI模式设置可写
+ if (ret == -1){
+ pabort("can't set spi mode");
+ }
+ break;
+ }
+
+ case 2:{
+ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi_valu); //SPI的bit/word设置可写
+ if (ret == -1){
+ pabort("can't set bits per word");
+ }
+ break;
+ }
+ case 3:{
+ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_valu); //SPI的波特率设置可写
+ if (ret == -1){
+ pabort("can't set max speed hz");
+ }
+ break;
+ }
+ default:
+ {
+ printf("can not spi feature\n");
+ break;
+ }
+ }
+ close(fd);
+ return ret;
+}
+
+int lynq_spi_read_state(unsigned char spi_feature,unsigned int spi_valu)
+{
+ int ret = 0;
+ int fd;
+ fd = open(device, O_RDWR); //打开"/dev/spidev1.0"
+ if (fd < 0)
+ {
+ pabort("can't open device");
+ ret = -1;
+ }
+ switch(spi_feature)
+ {
+ case 1:{
+ ret = ioctl(fd, SPI_IOC_RD_MODE, &spi_valu); //SPI模式设置可写
+ if (ret == -1){
+ pabort("can't set spi mode");
+ }
+ break;
+ }
+
+ case 2:{
+ ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &spi_valu); //SPI的bit/word设置可写
+ if (ret == -1){
+ pabort("can't set bits per word");
+ }
+ break;
+ }
+ case 3:{
+ ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_valu); //SPI的波特率设置可写
+ if (ret == -1){
+ pabort("can't set max speed hz");
+ }
+ break;
+ }
+ default:
+ {
+ printf("can not spi feature\n");
+ break;
+ }
+ }
+ close(fd);
+ return ret;
+}
+
+int lynq_spi_send_data(char *spi_data,unsigned int spi_len)
+{
+
+ int ret;
+ int fd;
+ fd = open(device, O_RDWR); //打开"/dev/spidev1.0"
+ if (fd < 0)
+ {
+ pabort("can't open device");
+ ret = -1;
+ }
+
+ ret = write(fd,spi_data,spi_len);
+ close(fd);
+ return ret;
+
+}
+
+int lynq_spi_recv_data(char *spi_data,unsigned int spi_len)
+{
+
+ int ret;
+ int fd;
+ fd = open(device, O_RDWR); //打开"/dev/spidev1.0"
+ if (fd < 0)
+ {
+ pabort("can't open device");
+ ret = -1;
+ }
+
+ ret = read(fd,spi_data,spi_len);
+ close(fd);
+ return ret;
+
+}
+
+#if 0
+int factory_spi_test(void)
+{
+
+ int ret = 0;
+
+ int fd;
+
+ mode |= SPI_CPHA;
+
+ mode |= SPI_CPOL;
+
+ mode &= ~SPI_CS_HIGH;
+
+ fd = open(device, O_RDWR); //打开"/dev/spidev1.0"
+
+ if (fd < 0)
+
+ pabort("can't open device");
+
+ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); //SPI模式设置可写
+
+ if (ret == -1)
+
+ pabort("can't set spi mode");
+
+ ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); //SPI模式设置可读
+
+ if (ret == -1)
+
+ pabort("can't get spi mode");
+
+ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); //SPI的bit/word设置可写
+
+ if (ret == -1)
+
+ pabort("can't set bits per word");
+
+ ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); //SPI的bit/word设置可读
+
+ if (ret == -1)
+
+ pabort("can't get bits per word");
+
+ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); //SPI的波特率设置可写
+
+ if (ret == -1)
+
+ pabort("can't set max speed hz");
+
+ ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); //SPI的波特率设置可读
+
+ if (ret == -1)
+
+ pabort("can't get max speed hz");
+
+ printf("spi mode: %d\n", mode);
+
+ printf("bits per word: %d\n", bits);
+
+ printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
+
+ transfer(fd); //数据传输
+
+ close(fd);
+
+ return ret;
+
+}
+#else
+int factory_spi_test(void)
+{
+ int tx_re_st = 0;
+ int rx_re_st = 0;
+ uint8_t tx[] = {0};
+ /*
+ uint8_t tx[] = { //定义待发送的数据
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
+
+ 0xF0, 0x0D,
+
+ };*/
+ uint8_t rx[100] = {};
+
+ mode |= SPI_CPHA;
+
+ mode |= SPI_CPOL;
+
+ mode &= ~SPI_CS_HIGH;
+
+ lynq_spi_set_channel(2); //打开"/dev/spidev2.0"
+
+ lynq_spi_set_state(1,mode);
+ lynq_spi_set_state(2,bits);
+ lynq_spi_set_state(3,speed);
+
+ lynq_spi_read_state(1,&mode);
+ lynq_spi_read_state(2,&bits);
+ lynq_spi_read_state(3,&speed);
+
+ printf("spi mode: %d\n", mode);
+
+ printf("bits per word: %d\n", bits);
+
+ printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
+
+ tx_re_st = lynq_spi_send_data(tx,sizeof(tx));
+
+ rx_re_st = lynq_spi_recv_data(rx,sizeof(tx));
+
+ printf("tx_re_st:%d---rx_re_st:%d\n",tx_re_st,rx_re_st);
+ for (int ret = 0; ret < sizeof(tx); ret++) {
+ if (!(ret % 6))
+ puts("");
+ printf("%.2X ", rx[ret]); //打印接收到的数据
+
+ }
+
+ puts("");
+}
+#endif
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/uart/uart.c b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/uart/uart.c
new file mode 100644
index 0000000..7f6b438
--- /dev/null
+++ b/src/lynq/lib/liblynq-driver-control/liblynq-driver-control/uart/uart.c
@@ -0,0 +1,335 @@
+#include "uart.h"
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+#include <stdlib.h>
+
+int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
+{
+ struct termios newtio,oldtio;
+ if ( tcgetattr( fd,&oldtio) != 0)
+ {
+ perror("SetupSerial 1");
+ return -1;
+ }
+ bzero( &newtio, sizeof( newtio ) );
+ newtio.c_cflag |= CLOCAL | CREAD;
+ newtio.c_cflag &= ~CSIZE;
+
+ switch( nBits )
+ {
+ case 5:
+ newtio.c_cflag |= CS5;
+ break;
+ case 6:
+ newtio.c_cflag |= CS6;
+ break;
+ case 7:
+ newtio.c_cflag |= CS7;
+ break;
+ case 8:
+ newtio.c_cflag |= CS8;
+ break;
+ default:
+ newtio.c_cflag |= CS8;
+ break;
+ }
+
+ switch( nEvent )
+ {
+ case 'O': //奇校验
+ newtio.c_cflag |= PARENB;
+ newtio.c_cflag |= PARODD;
+ newtio.c_iflag |= (INPCK | ISTRIP);
+ break;
+ case 'E': //偶校验
+ newtio.c_iflag |= (INPCK | ISTRIP);
+ newtio.c_cflag |= PARENB;
+ newtio.c_cflag &= ~PARODD;
+ break;
+ case 'N': //无校验
+ newtio.c_cflag &= ~PARENB;
+ break;
+ default: //无校验
+ newtio.c_cflag &= ~PARENB;
+ break;
+ }
+
+switch( nSpeed )
+ {
+ case 2400:
+ cfsetispeed(&newtio, B2400);
+ cfsetospeed(&newtio, B2400);
+ break;
+ case 4800:
+ cfsetispeed(&newtio, B4800);
+ cfsetospeed(&newtio, B4800);
+ break;
+ case 9600:
+ cfsetispeed(&newtio, B9600);
+ cfsetospeed(&newtio, B9600);
+ break;
+ case 115200:
+ cfsetispeed(&newtio, B115200);
+ cfsetospeed(&newtio, B115200);
+ break;
+ default:
+ cfsetispeed(&newtio, B9600);
+ cfsetospeed(&newtio, B9600);
+ break;
+ }
+ if( nStop == 1 )
+ {
+ newtio.c_cflag &= ~CSTOPB;
+ }
+ else if ( nStop == 2 )
+ {
+ newtio.c_cflag |= CSTOPB;
+ }
+ else
+ {
+ newtio.c_cflag &= ~CSTOPB;
+ }
+ newtio.c_cc[VTIME] = 0;
+ newtio.c_cc[VMIN] = 0;
+ tcflush(fd,TCIFLUSH);
+ if((tcsetattr(fd,TCSANOW,&newtio))!=0)
+ {
+ perror("com set error");
+ return -1;
+ }
+ printf("set done!\n");
+ return 0;
+}
+
+int open_port(int fd,int comport)
+{
+ // char *dev[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2"};
+ long vdisable;
+ if (comport==1)
+ { fd = open( "/dev/ttyS0", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS0 .....\n");
+ }
+ }
+ else if(comport==2)
+ { fd = open( "/dev/ttyS1", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS1 .....\n");
+ }
+ }
+ else if (comport==3)
+ {
+ fd = open( "/dev/ttyS2", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS2 .....\n");
+ }
+ }
+ if(fcntl(fd, F_SETFL, 0)<0)
+ {
+ printf("fcntl failed!\n");
+ }
+ else
+ {
+ printf("fcntl=%d\n",fcntl(fd, F_SETFL,0));
+ }
+ if(isatty(STDIN_FILENO)==0)
+ {
+ printf("standard input is not a terminal device\n");
+ }
+ else
+ {
+ printf("isatty success!\n");
+ }
+ printf("fd-open=%d\n",fd);
+ return fd;
+}
+
+int lynq_set_uart_param(int device_node,int nSpeed, int nBits, char nEvent, int nStop)
+{
+ int fd;
+ switch(device_node)
+ {
+ case 0:
+ fd = open( "/dev/ttyS0", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS0 .....\n");
+ }
+ break;
+ case 1:
+ fd = open( "/dev/ttyS1", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS1 .....\n");
+ }
+ break;
+ case 2:
+ fd = open( "/dev/ttyS2", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS2 .....\n");
+ }
+ break;
+ case 3:
+ fd = open( "/dev/ttyS3", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS3 .....\n");
+ }
+ break;
+ case 4:
+ fd = open( "/dev/ttyS4", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS4 .....\n");
+ }
+ break;
+ case 5:
+ fd = open( "/dev/ttyS5", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS5 .....\n");
+ }
+ break;
+ case 6:
+ fd = open( "/dev/ttyS6", O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if (-1 == fd)
+ {
+ perror("Can't Open Serial Port");
+ return(-1);
+ }
+ else
+ {
+ printf("open ttyS6 .....\n");
+ }
+ break;
+ default:
+ fd = -1;
+ break;
+ }
+
+ printf("fd-open=%d\n",fd);
+
+ if(set_opt(fd,nSpeed,nBits,nEvent,nStop) == -1)
+ {
+ fd = -1;
+ printf("set uart speed,nbits,nevent,stop,error!!!\n");
+ }
+ return fd;
+}
+
+#if 0
+int factory_uart_test(void)
+{
+ int fd;
+ int nread,i,wread;
+ char wr_buf[] = "Hello";
+ char rx_buff[128]= {};
+
+ if((fd=open_port(fd,3))<0)
+ {
+ perror("open_port error");
+ return;
+ }
+ if((i=set_opt(fd,9600,8,'N',1))<0)
+ {
+ perror("set_opt error");
+ return -1;
+ }
+
+ printf("fd=%d\n",fd);
+
+ while(1)
+ {
+ sleep(2);
+ memset(rx_buff,0,128);
+ nread=read(fd,rx_buff,128);
+ printf("nread=%d,%s\n",nread,rx_buff);
+ sleep(1);
+ wread = write(fd,wr_buf,strlen(wr_buf));
+ }
+ close(fd);
+ return 1;
+}
+#else
+int factory_uart_test(void)
+{
+ int fd;
+ int nread,i,wread;
+ char wr_buf[] = "Hello";
+ char rx_buff[128]= {};
+
+ if((fd = lynq_set_uart_param(2,9600,8,'N',1))<0)
+ {
+ perror("open_port-set_opt error");
+ }
+
+ printf("fd=%d\n",fd);
+
+ while(1)
+ {
+ sleep(2);
+ memset(rx_buff,0,128);
+ nread=read(fd,rx_buff,128);
+ printf("nread=%d,%s\n",nread,rx_buff);
+ sleep(1);
+ wread = write(fd,wr_buf,strlen(wr_buf));
+ }
+ close(fd);
+ return 1;
+}
+#endif
\ No newline at end of file