diff --git a/04_day.pptx b/04_day.pptx index 726f2fa..d2c3fcd 100644 Binary files a/04_day.pptx and b/04_day.pptx differ diff --git a/04_day/hal/a.out b/04_day/hal/a.out new file mode 100644 index 0000000..9553a8c Binary files /dev/null and b/04_day/hal/a.out differ diff --git a/04_day/hal/led.c b/04_day/hal/led.c new file mode 100644 index 0000000..852de7f --- /dev/null +++ b/04_day/hal/led.c @@ -0,0 +1,19 @@ +#include + +typedef struct module +{ + void (*on)(); + void (*off)(); +} module_t; + +void ledOn() +{ + printf("ledOn()\n"); +} + +void ledOff() +{ + printf("ledOff()\n"); +} + +module_t HMI = { ledOn, ledOff }; diff --git a/04_day/hal/led.o b/04_day/hal/led.o new file mode 100644 index 0000000..f862ed8 Binary files /dev/null and b/04_day/hal/led.o differ diff --git a/04_day/hal/libled.a b/04_day/hal/libled.a new file mode 100644 index 0000000..e7c8273 Binary files /dev/null and b/04_day/hal/libled.a differ diff --git a/04_day/hal/libled.so b/04_day/hal/libled.so new file mode 100644 index 0000000..cf7d7a6 Binary files /dev/null and b/04_day/hal/libled.so differ diff --git a/04_day/hal/main.c b/04_day/hal/main.c new file mode 100644 index 0000000..60ba085 --- /dev/null +++ b/04_day/hal/main.c @@ -0,0 +1,19 @@ +#include + +typedef struct module +{ + void (*on)(); + void (*off)(); +} module_t; + +int main() +{ + void *handle; + module_t *module; + handle = dlopen("libled.so", RTLD_NOW); + module = dlsym( handle, "HMI" ); + module->on(); + module->off(); + dlclose(handle); + return 0; +} diff --git a/04_day/hidl/Android.bp b/04_day/hidl/Android.bp new file mode 100644 index 0000000..aac1663 --- /dev/null +++ b/04_day/hidl/Android.bp @@ -0,0 +1,7 @@ +subdirs = [ + "server", +] + + + + diff --git a/04_day/hidl/client/Android.mk b/04_day/hidl/client/Android.mk new file mode 100644 index 0000000..36f52a0 --- /dev/null +++ b/04_day/hidl/client/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES = liblog libutils libhidlbase android.hardware.samples@1.0 +LOCAL_SRC_FILES := client.cpp +LOCAL_MODULE := my_client +include $(BUILD_EXECUTABLE) diff --git a/04_day/hidl/client/client.cpp b/04_day/hidl/client/client.cpp new file mode 100644 index 0000000..6da9226 --- /dev/null +++ b/04_day/hidl/client/client.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +using ::android::hardware::samples::V1_0::IFoo; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + + +int main() +{ + sp foo; + foo = IFoo::getService(); + foo->foo(); + return 0; +} + diff --git a/04_day/hidl/client_light/Android.mk b/04_day/hidl/client_light/Android.mk new file mode 100644 index 0000000..0230931 --- /dev/null +++ b/04_day/hidl/client_light/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES = liblog libutils libhidlbase android.hardware.light@2.0 +LOCAL_SRC_FILES := light_client.cpp +LOCAL_MODULE := light_client +include $(BUILD_EXECUTABLE) diff --git a/04_day/hidl/client_light/light_client.cpp b/04_day/hidl/client_light/light_client.cpp new file mode 100644 index 0000000..8c1fead --- /dev/null +++ b/04_day/hidl/client_light/light_client.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +using ::android::hardware::light::V2_0::Brightness; +using ::android::hardware::light::V2_0::Flash; +using ::android::hardware::light::V2_0::ILight; +using ::android::hardware::light::V2_0::LightState; +using ::android::hardware::light::V2_0::Status; +using ::android::hardware::light::V2_0::Type; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + + +const static LightState kWhite = { + .color = 0xFFFFFFFF, + .flashMode = Flash::TIMED, + .flashOnMs = 100, + .flashOffMs = 50, + .brightnessMode = Brightness::USER, +}; + +int main() +{ + sp light; + light = ILight::getService(); + Return ret = light->setLight( Type::BACKLIGHT, kWhite); + //if( ret.isOk() == false ) + // return -1; + //if( Status::SUCCESS == static_cast(ret) ) + // return 0; + return 0; +} + diff --git a/04_day/hidl/server/.hardware/interfaces/samples/1.0/Android.bp b/04_day/hidl/server/.hardware/interfaces/samples/1.0/Android.bp new file mode 100644 index 0000000..abbcb74 --- /dev/null +++ b/04_day/hidl/server/.hardware/interfaces/samples/1.0/Android.bp @@ -0,0 +1,66 @@ +// This file is autogenerated by hidl-gen. Do not edit manually. + +filegroup { + name: "android.hardware.samples@1.0_hal", + srcs: [ + "types.hal", + "IFoo.hal", + ], +} + +genrule { + name: "android.hardware.samples@1.0_genc++", + tools: ["hidl-gen"], + cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.samples@1.0", + srcs: [ + ":android.hardware.samples@1.0_hal", + ], + out: [ + "android/hardware/samples/1.0/types.cpp", + "android/hardware/samples/1.0/FooAll.cpp", + ], +} + +genrule { + name: "android.hardware.samples@1.0_genc++_headers", + tools: ["hidl-gen"], + cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.samples@1.0", + srcs: [ + ":android.hardware.samples@1.0_hal", + ], + out: [ + "android/hardware/samples/1.0/types.h", + "android/hardware/samples/1.0/hwtypes.h", + "android/hardware/samples/1.0/IFoo.h", + "android/hardware/samples/1.0/IHwFoo.h", + "android/hardware/samples/1.0/BnHwFoo.h", + "android/hardware/samples/1.0/BpHwFoo.h", + "android/hardware/samples/1.0/BsFoo.h", + ], +} + +cc_library { + name: "android.hardware.samples@1.0", + defaults: ["hidl-module-defaults"], + generated_sources: ["android.hardware.samples@1.0_genc++"], + generated_headers: ["android.hardware.samples@1.0_genc++_headers"], + export_generated_headers: ["android.hardware.samples@1.0_genc++_headers"], + vendor_available: true, + vndk: { + enabled: true, + }, + shared_libs: [ + "libhidlbase", + "libhidltransport", + "libhwbinder", + "liblog", + "libutils", + "libcutils", + ], + export_shared_lib_headers: [ + "libhidlbase", + "libhidltransport", + "libhwbinder", + "libutils", + ], +} diff --git a/04_day/hidl/server/Android.bp b/04_day/hidl/server/Android.bp new file mode 100644 index 0000000..3add764 --- /dev/null +++ b/04_day/hidl/server/Android.bp @@ -0,0 +1,15 @@ +cc_binary { + name: "android.hardware.samples@1.0-service", + relative_install_path: "hw", + proprietary: true, + srcs: [ + "Foo.cpp", + "service.cpp", + ], + shared_libs: [ + "libhidlbase", + "libhidltransport", + "libutils", + "android.hardware.samples@1.0", + ], +} diff --git a/04_day/hidl/server/Foo.cpp b/04_day/hidl/server/Foo.cpp new file mode 100644 index 0000000..70c51ec --- /dev/null +++ b/04_day/hidl/server/Foo.cpp @@ -0,0 +1,27 @@ +#include +#include "Foo.h" + +namespace android { +namespace hardware { +namespace samples { +namespace V1_0 { +namespace implementation { + +// Methods from IFoo follow. +Return Foo::foo() { + std::cout << "Foo::foo()" < +#include +#include + +namespace android { +namespace hardware { +namespace samples { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +struct Foo : public IFoo { + // Methods from IFoo follow. + Return foo() override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. + +}; + +// FIXME: most likely delete, this is only for passthrough implementations +// extern "C" IFoo* HIDL_FETCH_IFoo(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace samples +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_SAMPLES_V1_0_FOO_H diff --git a/04_day/hidl/server/service.cpp b/04_day/hidl/server/service.cpp new file mode 100644 index 0000000..7ca1c5d --- /dev/null +++ b/04_day/hidl/server/service.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include "Foo.h" + +using android::sp; +using android::status_t; +using android::OK; + +// libhwbinder: +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +// Generated HIDL files +using android::hardware::samples::V1_0::IFoo; +using android::hardware::samples::V1_0::implementation::Foo; + +int main() { + status_t status; + android::sp service = nullptr; + + service = new Foo(); + + configureRpcThreadpool(1, true); + service->registerAsService(); + std::cout << "Foo HAL Service is ready." << std::endl; + joinRpcThreadpool(); + return 0; +} +