-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpiod: first initialized without readme file
Tested on android-studio bumblebee including kotlin base activity, and c++ base JNI layer api using libgpiod static libraries. Support platform: - arm64-v8 - armeabi-v7a Signed-off-by: Wig Cheng <[email protected]>
- Loading branch information
0 parents
commit 184451a
Showing
48 changed files
with
4,092 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdk 31 | ||
|
||
defaultConfig { | ||
applicationId "com.example.gpiod" | ||
minSdk 28 | ||
targetSdk 31 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary true | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
cppFlags '' | ||
abiFilters 'armeabi-v7a', 'arm64-v8a' | ||
} | ||
ndk { | ||
// Specifies the ABI configurations of your native | ||
// libraries Gradle should build and package with your app. | ||
abiFilters 'armeabi-v7a', 'arm64-v8a' | ||
} | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion compose_version | ||
} | ||
packagingOptions { | ||
resources { | ||
excludes += '/META-INF/{AL2.0,LGPL2.1}' | ||
} | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path file('src/main/cpp/CMakeLists.txt') | ||
version '3.18.1' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation "androidx.compose.ui:ui:$compose_version" | ||
implementation "androidx.compose.material:material:$compose_version" | ||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' | ||
implementation 'androidx.activity:activity-compose:1.3.1' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" | ||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/example/gpiod/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.gpiod | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.gpiod", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.gpiod"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Gpiod"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.Gpiod"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.18.1) | ||
|
||
# Declares and names the project. | ||
|
||
project("JNIGpiod") | ||
|
||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
add_library( # Sets the name of the library. | ||
JNIGpiod | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
JNIGpiod.cpp ) | ||
|
||
# Searches for a specified prebuilt library and stores the path as a | ||
# variable. Because CMake includes system libraries in the search path by | ||
# default, you only need to specify the name of the public NDK library | ||
# you want to add. CMake verifies that the library exists before | ||
# completing its build. | ||
|
||
find_library( # Sets the name of the path variable. | ||
log-lib | ||
|
||
# Specifies the name of the NDK library that | ||
# you want CMake to locate. | ||
log ) | ||
|
||
# Specifies libraries CMake should link to your target library. You | ||
# can link multiple libraries, such as libraries you define in this | ||
# build script, prebuilt third-party libraries, or system libraries. | ||
|
||
include_directories(${ANDROID_ABI}/) | ||
add_library(gpiod STATIC IMPORTED) | ||
set_target_properties(gpiod PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_ABI}/libgpiod.a) | ||
|
||
|
||
target_link_libraries( # Specifies the target library. | ||
JNIGpiod | ||
gpiod | ||
# Links the target library to the log library | ||
# included in the NDK. | ||
${log-lib} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Write C++ code here. | ||
// | ||
// Do not forget to dynamically load the C++ library into your application. | ||
// | ||
// For instance, | ||
// | ||
// In MainActivity.java: | ||
// static { | ||
// System.loadLibrary("gpiod"); | ||
// } | ||
// | ||
// Or, in MainActivity.kt: | ||
// companion object { | ||
// init { | ||
// System.loadLibrary("gpiod") | ||
// } | ||
// } | ||
|
||
#define LOG_TAG "gpiod-lib_JNI" | ||
#include <cstring> | ||
#include <jni.h> | ||
#include <cinttypes> | ||
#include <string> | ||
#include <gpiod.h> | ||
#include <android/log.h> | ||
|
||
extern "C" | ||
JNIEXPORT jint JNICALL | ||
Java_com_example_gpiod_MainActivity_getGpioTotalBank(JNIEnv *env, jobject thiz) { | ||
std::ignore = thiz; | ||
struct gpiod_chip_iter *iter; | ||
struct gpiod_chip *chip; | ||
unsigned int total_bank = 0; | ||
|
||
iter = gpiod_chip_iter_new(); | ||
gpiod_foreach_chip(iter, chip) { | ||
total_bank += 1; | ||
} | ||
|
||
gpiod_chip_iter_free(iter); | ||
|
||
return total_bank; | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jstring JNICALL | ||
Java_com_example_gpiod_MainActivity_getGpioInfo(JNIEnv *env, jobject thiz, jint gpiobank, jint gpioline) { | ||
std::ignore = thiz; | ||
|
||
char bank[32] = {0}, ret[4] = {0}; | ||
sprintf(bank, "gpiochip%d", gpiobank); | ||
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "GPIO gpiobank is %d", gpiobank); | ||
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "GPIO gpioline is %d", gpioline); | ||
|
||
jint value = gpiod_ctxless_get_value((char *)bank, gpioline, 0, "gpioget"); | ||
|
||
sprintf(ret, "%d", value); | ||
|
||
return env->NewStringUTF(ret); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jstring JNICALL | ||
Java_com_example_gpiod_MainActivity_setGpioInfo(JNIEnv *env, jobject thiz, jint gpiobank, jint gpioline, jint gpio_value) { | ||
|
||
std::ignore = thiz; | ||
|
||
char bank[32] = {0}, ret_str[32] = {0}; | ||
sprintf(bank, "/dev/gpiochip%d", gpiobank); | ||
|
||
int ret = gpiod_ctxless_set_value(bank, gpioline, gpio_value, 0, "gpioset", NULL, NULL); | ||
|
||
if(ret) | ||
sprintf(ret_str, "Set Failed !"); | ||
else | ||
sprintf(ret_str, "Set Successed !"); | ||
|
||
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "set gpio ret = %d", ret); | ||
return env->NewStringUTF(ret_str); | ||
} | ||
|
||
|
||
extern "C" | ||
JNIEXPORT jstring JNICALL | ||
Java_com_example_gpiod_MainActivity_stringFromJNI(JNIEnv *env, jobject thiz) { | ||
// TODO: implement stringFromJNI() | ||
return env->NewStringUTF("Test"); | ||
} |
Oops, something went wrong.