Here are the files:
vendor/hardkernel/interfaces/Android.bp
Code: Select all
hidl_package_root {
name: "vendor.hardkernel.hardware",
path: "vendor/hardkernel/interfaces",
}
vendor/hardkernel/interfaces/update-makefiles.sh
Code: Select all
#!/bin/bash
source $ANDROID_BUILD_TOP/system/tools/hidl/update-makefiles-helper.sh
do_makefiles_update \
"vendor.hardkernel.hardware:vendor/hardkernel/interfaces" \
"android.hidl:system/libhidl/transport" \
"android.hardware:hardware/interfaces"
vendor/hardkernel/interfaces/gpio/1.0/Android.bp
Code: Select all
// This file is autogenerated by hidl-gen -Landroidbp.
hidl_interface {
name: "vendor.hardkernel.hardware.gpio@1.0",
root: "vendor.hardkernel.hardware",
system_ext_specific: true,
srcs: [
"IGpio.hal",
],
interfaces: [
"android.hidl.base@1.0",
],
gen_java: true,
}
vendor/hardkernel/interfaces/gpio/1.0/IGpio.hal
Code: Select all
package vendor.hardkernel.hardware.gpio@1.0;
interface IGpio {
gpio(int32_t valueIn) generates (int32_t valueRet);
setup_wiringPi() generates (int32_t status);
pin_mode(int32_t pin, int32_t mode);
digital_read(int32_t pin) generates (int32_t status);
digital_write(int32_t pin, int32_t value);
pullupdn_control(int32_t pin, int32_t mode);
get_alt(int32_t pin) generates (int32_t status);
};
vendor/hardkernel/interfaces/gpio/1.0/default/Android.bp
Code: Select all
cc_library_shared {
name: "vendor.hardkernel.hardware.gpio@1.0-impl",
vendor: true,
relative_install_path: "hw",
srcs: [
"Gpio.cpp",
],
shared_libs: [
"libhidlbase",
"libutils",
"liblog",
"vendor.hardkernel.hardware.gpio@1.0",
"libwiringPi",
],
include_dirs: [ "vendor/hardkernel/external/wiringPi/wiringPi" ],
}
cc_binary {
name: "vendor.hardkernel.hardware.gpio@1.0-service",
defaults: ["hidl_defaults"],
vendor: true,
relative_install_path: "hw",
init_rc: ["vendor.hardkernel.hardware.gpio@1.0-service.rc"],
vintf_fragments: ["vendor.hardkernel.hardware.gpio@1.0-service.xml"],
srcs: ["service.cpp"],
shared_libs: [
"vendor.hardkernel.hardware.gpio@1.0",
"vendor.hardkernel.hardware.gpio@1.0-impl",
"libhidlbase",
"liblog",
"libbase",
"libdl",
"libhidlbase",
"libutils",
],
}
cc_binary {
name: "gpioclient",
defaults: ["hidl_defaults"],
vendor: true,
srcs: ["gpioclient.cpp"],
shared_libs: [
"vendor.hardkernel.hardware.gpio@1.0",
"vendor.hardkernel.hardware.gpio@1.0-impl",
"libhidlbase",
"liblog",
"libbase",
"libdl",
"libhidlbase",
"libutils",
],
}
vendor/hardkernel/interfaces/gpio/1.0/default/Gpio.cpp
Code: Select all
#include <android-base/logging.h>
#include <log/log.h>
#include "Gpio.h"
#include <wiringPi.h>
namespace vendor::hardkernel::hardware::gpio::V1_0::implementation {
Gpio::Gpio(){
}
Gpio::~Gpio(){
}
// Methods from ::android::hardware::gpio::V1_0::IGpio follow.
Return<int32_t> Gpio::gpio(int32_t valueIn) {
return valueIn+100;
}
Return<int32_t> Gpio::setup_wiringPi() {
int32_t status = wiringPiSetup();
return status;
}
Return<void> Gpio::pin_mode(int32_t pin, int32_t mode) {
pinMode(pin, mode);
return Void();
}
Return<int32_t> Gpio::digital_read(int32_t pin) {
int32_t status = digitalRead(pin);
return status;
}
Return<void> Gpio::digital_write(int32_t pin, int32_t value) {
digitalWrite(pin, value);
return Void();
}
Return<void> Gpio::pullupdn_control(int32_t pin, int32_t mode) {
pullUpDnControl(pin, mode);
return Void();
}
Return<int32_t> Gpio::get_alt(int32_t pin) {
int32_t status = getAlt(pin);
return status;
}
// Methods from ::android::hidl::base::V1_0::IBase follow.
//IGpio* HIDL_FETCH_IGpio(const char* /* name */) {
//return new Gpio();
//}
//
} // namespace vendor::hardkernel::hardware::gpio::implementation
vendor/hardkernel/interfaces/gpio/1.0/default/Gpio.h
Code: Select all
#pragma once
#include <vendor/hardkernel/hardware/gpio/1.0/IGpio.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
namespace vendor::hardkernel::hardware::gpio::V1_0::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;
class Gpio : public IGpio {
public:
Gpio();
// Methods from ::android::hardware::gpio::V1_0::IGpio follow.
Return<int32_t> gpio(int32_t valueIn) override;
Return<int32_t> setup_wiringPi() override;
Return<void> pin_mode(int32_t pin, int32_t mode) override;
Return<int32_t> digital_read(int32_t pin) override;
Return<void> digital_write(int32_t pin, int32_t value) override;
Return<void> pullupdn_control(int32_t pin, int32_t mode) override;
Return<int32_t> get_alt(int32_t pin) override;
private:
virtual ~Gpio();
};
// FIXME: most likely delete, this is only for passthrough implementations
// extern "C" IGpio* HIDL_FETCH_IGpio(const char* name);
} // namespace vendor::hardkernel::hardware::gpio::implementation
vendor/hardkernel/interfaces/gpio/1.0/default/service.cpp
Code: Select all
#define LOG_TAG "vendor.hardkernel.hardware.gpio@1.0-service"
#include <hidl/LegacySupport.h>
#include "Gpio.h"
using vendor::hardkernel::hardware::gpio::V1_0::IGpio;
using vendor::hardkernel::hardware::gpio::V1_0::implementation::Gpio;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;
int main() {
int res;
android::sp<IGpio> ser = new Gpio();
ALOGD("gpio main service");
configureRpcThreadpool(1, true /*callerWillJoin*/);
if (ser != nullptr) {
res = ser->registerAsService();
if(res != 0)
ALOGE("Can't register instance of GpioHardware, nullptr");
} else {
ALOGE("Can't create instance of GpioHardware, nullptr");
}
joinRpcThreadpool();
return 0; // should never get here
}
vendor/hardkernel/interfaces/gpio/1.0/default/vendor.hardkernel.hardware.gpio@1.0-service.rc
Code: Select all
service gpio_service /vendor/bin/hw/vendor.hardkernel.hardware.gpio@1.0-service
class hal
user root
group root
seclabel u:r:su:s0
vendor/hardkernel/interfaces/gpio/1.0/default/vendor.hardkernel.hardware.gpio@1.0-service.xml
Code: Select all
<manifest version="1.0" type="device">
<hal format="hidl">
<name>vendor.hardkernel.hardware.gpio</name>
<transport>hwbinder</transport>
<fqname>@1.0::IGpio/default</fqname>
</hal>
</manifest>
device/hardkernel/common/manifests/frameworks/vendor.hardkernel.hardware.gpio@1.0-service.xml
Code: Select all
<compatibility-matrix version="1.0" type="framework">
<hal format="hidl" optional="true">
<name>vendor.hardkernel.hardware.gpio</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IGpio</name>
<instance>default</instance>
</interface>
</hal>
</compatibility-matrix>
Code: Select all
DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE += device/hardkernel/common/manifests/frameworks/vendor.hardkernel.hardware.gpio@1.0-service.xml
Code: Select all
PRODUCT_PACKAGES += \
vendor.hardkernel.hardware.gpio@1.0-impl \
vendor.hardkernel.hardware.gpio@1.0-service \
Code: Select all
vendor: true,
Code: Select all
$lshal
X ? vendor.hardkernel.hardware.gpio@1.0::I*/* (/vendor/lib/hw/) N/A N/A
X ? vendor.hardkernel.hardware.gpio@1.0::I*/* (/vendor/lib64/hw/) N/A N/A 4993
Code: Select all
$ps -A|grep gpio
root 4993 1 10775224 4776 binder_thread_read 0 S vendor.hardkernel.hardware.gpio@1.0-service
app/libs
:out/soong/.intermediates/frameworks/base/framework.jar
out/soong/.intermediates/vendor/hardkernel/interfaces/gpio/1.0/vendor.hardkernel.hardware.gpio-V1.0-java/android_common/combined/vendor.hardkernel.hardware.gpio-V1.0-java.jar
In build.gradle(app) is to add:
Code: Select all
implementation fileTree(dir: 'libs', include: ['vendor.hardkernel.hardware.gpio*.jar'])
dependencies {
compileOnly files('libs/framework.jar')
}
Code: Select all
import vendor.hardkernel.hardware.gpio.V1_0.IGpio;
public class wiring {
private static IGpio gpio = null;
static {
try {
gpio = IGpio.getService(true);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public static int wiringPiSetup() {
try {
return gpio.setup_wiringPi();
} catch (RemoteException e) {
e.printStackTrace();
return -1;
}
}
public static int digitalRead(int iGpio) {
int value = 0;
if (gpio != null) {
try {
value = gpio.digital_read(iGpio);
return value;
} catch (RemoteException e) {
e.printStackTrace();
return -1;
}
}
}
}
