Code Monkey home page Code Monkey logo

ledhidl's Introduction

hidl demo
1. 以控制LED为例进行demo的编写
1.1 编写led.hal 和types.hal
1.2 执行update-makefiles.sh 编译文件
	新建defalut文件夹
	
1.3 实现[email protected][email protected]
	编写android.bp
		cc_library_shared {
			name: "[email protected]",
			defaults: ["hidl_defaults"],
			relative_install_path: "hw",
			proprietary: true,
			srcs: ["Consumerled.cpp"],
			shared_libs: [
				"libhidlbase",
				"libhidltransport",
				"libhardware",
				"liblog",
				"libutils",
				"[email protected]",
			],
		}

		cc_binary {
			relative_install_path: "hw",
			defaults: ["hidl_defaults"],
			name: "[email protected]",
			proprietary: true,
			init_rc: ["[email protected]"],
			srcs: ["service.cpp"],

			shared_libs: [
				"liblog",
				"libhardware",
				"libhidlbase",
				"libhidltransport",
				"libutils",
				"[email protected]",
			],

		}
	
		接下来,使用相应功能填写存根并设置守护进程。守护进程代码(支持直通)示例:

		#include <hidl/LegacySupport.h>

		int main(int /* argc */, char* /* argv */ []) {
			return defaultPassthroughServiceImplementation<INfc>("nfc");
		}
		defaultPassthroughServiceImplementation 将对提供的 -impl 库执行 dlopen() 操作,并将其作为绑定式服务提供。守护进程代码(对于纯绑定式服务)示例:

		int main(int /* argc */, char* /* argv */ []) {
			sp nfc = new Nfc();
			const status_t status = nfc->registerAsService();
			if (status != ::android::OK) {
				return 1; // or handle error
			}
			// join pool or do other things
		}

		
		add the code to the manifest.xm 以至于hwservicemanager 查找到指定的hidl service
			About HIDL configures
			device/linaro/hikey/manifest.xml
			<hal format="hidl">
				<name>android.hardware.led</name>
				<transport>hwbinder</transport>
				<version>1.0</version>
				<interface>
					<name>ILed</name>
					<instance>default</instance>
				</interface>
			</hal>
		
		
2. 实现java调用hidl service的例子
	2.1 添加库:
		将以下内容添加到 Android.mk 中:
		LOCAL_JAVA_LIBRARIES += android.hardware.foo-V1.0-java
		或
		将以下内容添加到 Android.bp 中:
		shared_libs: [
			/* … */
			"android.hardware.foo-V1.0-java",
		],
		该库还存在静态版:android.hardware.foo-V1.0-java-static。
	2.2 将以下内容添加到您的 Java 文件中:
		import android.hardware.foo.V1_0.IFoo;
		...
		// retry to wait until the service starts up if it is in the manifest
		IFoo server = IFoo.getService(true /* retry */); // throws NoSuchElementException if not available
		IFoo anotherServer = IFoo.getService("second_impl", true /* retry */);
		server.doSomething(…);
		

3. 实现C++ 调用hidl service的例子
	首先将 HAL 库添加到 makefile 中:
		Make:LOCAL_SHARED_LIBRARIES += [email protected]
		Soong:shared_libs: [ …, [email protected] ]
	接下来,添加 HAL 头文件:
		#include <android/hardware/nfc/1.0/IFoo.h>
		…
		// in code:
		sp<IFoo> client = IFoo::getService();
		client->doThing();


4. 编写LED驱动


ledhidl's People

Contributors

anlory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ledhidl's Issues

绑定式HAL,java客户端能传对象吗?

绑定式HAL,java客户端调用Service和C++调用能传对象吗?

  1. 实现java调用hidl service的例子
    2.1 添加库:
    将以下内容添加到 Android.mk 中:
    LOCAL_JAVA_LIBRARIES += android.hardware.foo-V1.0-java

    将以下内容添加到 Android.bp 中:
    shared_libs: [
    /* … /
    "android.hardware.foo-V1.0-java",
    ],
    该库还存在静态版:android.hardware.foo-V1.0-java-static。
    2.2 将以下内容添加到您的 Java 文件中:
    import android.hardware.foo.V1_0.IFoo;
    ...
    // retry to wait until the service starts up if it is in the manifest
    IFoo server = IFoo.getService(true /
    retry /); // throws NoSuchElementException if not available
    IFoo anotherServer = IFoo.getService("second_impl", true /
    retry */);
    server.doSomething(…);

  2. 实现C++ 调用hidl service的例子
    首先将 HAL 库添加到 makefile 中:
    Make:LOCAL_SHARED_LIBRARIES += [email protected]
    Soong:shared_libs: [ …, [email protected] ]
    接下来,添加 HAL 头文件:
    #include <android/hardware/nfc/1.0/IFoo.h>

    // in code:
    sp client = IFoo::getService();
    client->doThing();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.