Added Android support
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,3 +10,6 @@ gpio/gpio
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
._.DS_Store
|
._.DS_Store
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
libs/
|
||||||
|
obj/
|
||||||
|
|||||||
86
jni/Android.mk
Normal file
86
jni/Android.mk
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_C_INCLUDES += \
|
||||||
|
$(LOCAL_PATH)/../wiringPi
|
||||||
|
|
||||||
|
LOCAL_MODULE := wiringPi
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
../wiringPi/ads1115.c \
|
||||||
|
../wiringPi/mcp23008.c \
|
||||||
|
../wiringPi/mcp4802.c \
|
||||||
|
../wiringPi/piHiPri.c \
|
||||||
|
../wiringPi/sr595.c \
|
||||||
|
../wiringPi/bmp180.c \
|
||||||
|
../wiringPi/mcp23016.c \
|
||||||
|
../wiringPi/odroidc1.c \
|
||||||
|
../wiringPi/odroidn2.c \
|
||||||
|
../wiringPi/piThread.c \
|
||||||
|
../wiringPi/wiringOdroid.c \
|
||||||
|
../wiringPi/mcp23017.c \
|
||||||
|
../wiringPi/odroidc2.c \
|
||||||
|
../wiringPi/drcSerial.c \
|
||||||
|
../wiringPi/mcp23s08.c \
|
||||||
|
../wiringPi/odroidn1.c \
|
||||||
|
../wiringPi/wiringOdroidI2C.c \
|
||||||
|
../wiringPi/ds18b20.c \
|
||||||
|
../wiringPi/mcp23s17.c \
|
||||||
|
../wiringPi/sn3218.c \
|
||||||
|
../wiringPi/wiringOdroidSPI.c \
|
||||||
|
../wiringPi/htu21d.c \
|
||||||
|
../wiringPi/mcp3002.c \
|
||||||
|
../wiringPi/odroidxu3.c \
|
||||||
|
../wiringPi/softPwm.c \
|
||||||
|
../wiringPi/wiringSerial.c \
|
||||||
|
../wiringPi/max31855.c \
|
||||||
|
../wiringPi/mcp3004.c \
|
||||||
|
../wiringPi/pcf8574.c \
|
||||||
|
../wiringPi/softServo.c \
|
||||||
|
../wiringPi/wiringShift.c \
|
||||||
|
../wiringPi/max5322.c \
|
||||||
|
../wiringPi/mcp3422.c \
|
||||||
|
../wiringPi/pcf8591.c \
|
||||||
|
../wiringPi/softTone.c \
|
||||||
|
../wiringPi/wpiExtensions.c
|
||||||
|
|
||||||
|
LOCAL_CFLAGS += -UNDEBUG -DANDROID -Wno-return-type
|
||||||
|
|
||||||
|
LOCAL_LDLIBS := -ldl -llog
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_C_INCLUDES += \
|
||||||
|
$(LOCAL_PATH)/../wiringPi
|
||||||
|
|
||||||
|
LOCAL_MODULE := wiringPiDev
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
../devLib/ds1302.c \
|
||||||
|
../devLib/maxdetect.c \
|
||||||
|
../devLib/piNes.c \
|
||||||
|
../devLib/gertboard.c \
|
||||||
|
../devLib/lcd128x64.c \
|
||||||
|
../devLib/lcd.c \
|
||||||
|
../devLib/piGlow.c \
|
||||||
|
../devLib/scrollPhat.c \
|
||||||
|
../devLib/piFace.c
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := libwiringPi
|
||||||
|
|
||||||
|
LOCAL_LDLIBS := -ldl -llog
|
||||||
|
|
||||||
|
LOCAL_CFLAGS += -UNDEBUG -DANDROID -Wno-return-type
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE := gpio
|
||||||
|
LOCAL_SRC_FILES := ../gpio/gpio.c ../gpio/readall.c ../gpio/pins.c
|
||||||
|
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../wiringPi $(LOCAL_PATH)/../devLib/
|
||||||
|
|
||||||
|
LOCAL_CFLAGS += -UNDEBUG -DANDROID -Wno-return-type
|
||||||
|
LOCAL_LDLIBS := -llog
|
||||||
|
LOCAL_SHARED_LIBRARIES := libwiringPi libwiringPiDev
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
3
jni/Application.mk
Normal file
3
jni/Application.mk
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
NDK_TOOLCHAIN_VERSION=clang
|
||||||
|
APP_ABI := armeabi-v7a arm64-v8a
|
||||||
|
APP_PLATFORM := android-21
|
||||||
@@ -116,6 +116,10 @@
|
|||||||
|
|
||||||
#define CONFIG_DEFAULT (0x8583) // From the datasheet
|
#define CONFIG_DEFAULT (0x8583) // From the datasheet
|
||||||
|
|
||||||
|
#if defined ANDROID
|
||||||
|
#define __bswap_16(x) bswap_16(x)
|
||||||
|
#define __bswap_32(x) bswap_32(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
static const uint16_t dataRates [8] =
|
static const uint16_t dataRates [8] =
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
|
|
||||||
#include "max31855.h"
|
#include "max31855.h"
|
||||||
|
|
||||||
|
#if defined ANDROID
|
||||||
|
#define __bswap_16(x) bswap_16(x)
|
||||||
|
#define __bswap_32(x) bswap_32(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
||||||
{
|
{
|
||||||
uint32_t spiData ;
|
uint32_t spiData ;
|
||||||
|
|||||||
@@ -703,7 +703,15 @@ static void init_gpio_mmap (void)
|
|||||||
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
} else {
|
} else {
|
||||||
//#define C2_GPIO_BASE 0xC8834000
|
//#define C2_GPIO_BASE 0xC8834000
|
||||||
|
#ifdef ANDROID
|
||||||
|
#if defined(__aarch64__)
|
||||||
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, C2_GPIO_BASE);
|
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, C2_GPIO_BASE);
|
||||||
|
#else
|
||||||
|
mapped = mmap64(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off64_t)C2_GPIO_BASE);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, C2_GPIO_BASE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mapped == MAP_FAILED)
|
if (mapped == MAP_FAILED)
|
||||||
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
||||||
|
|||||||
@@ -174,7 +174,15 @@ void softPwmStop (int pin)
|
|||||||
{
|
{
|
||||||
if (range [pin] != 0)
|
if (range [pin] != 0)
|
||||||
{
|
{
|
||||||
|
#ifdef ANDROID
|
||||||
|
int status;
|
||||||
|
if ( (status = pthread_kill(pin, SIGUSR1)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error cancelling thread %d", pin);
|
||||||
|
}
|
||||||
|
#else
|
||||||
pthread_cancel (threads [pin]) ;
|
pthread_cancel (threads [pin]) ;
|
||||||
|
#endif
|
||||||
pthread_join (threads [pin], NULL) ;
|
pthread_join (threads [pin], NULL) ;
|
||||||
range [pin] = 0 ;
|
range [pin] = 0 ;
|
||||||
digitalWrite (pin, LOW) ;
|
digitalWrite (pin, LOW) ;
|
||||||
|
|||||||
@@ -142,7 +142,15 @@ void softToneStop (int pin)
|
|||||||
{
|
{
|
||||||
if (threads [pin] != 0)
|
if (threads [pin] != 0)
|
||||||
{
|
{
|
||||||
pthread_cancel (threads [pin]) ;
|
#ifdef ANDROID
|
||||||
|
int status;
|
||||||
|
if ( (status = pthread_kill(pin, SIGUSR1)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error cancelling thread %d", pin);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
pthread_cancel (threads [pin]) ;
|
||||||
|
#endif
|
||||||
pthread_join (threads [pin], NULL) ;
|
pthread_join (threads [pin], NULL) ;
|
||||||
threads [pin] = 0 ;
|
threads [pin] = 0 ;
|
||||||
digitalWrite (pin, LOW) ;
|
digitalWrite (pin, LOW) ;
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ static pthread_mutex_t pinMutex ;
|
|||||||
int wiringPiDebug = FALSE ;
|
int wiringPiDebug = FALSE ;
|
||||||
int wiringPiReturnCodes = FALSE ;
|
int wiringPiReturnCodes = FALSE ;
|
||||||
|
|
||||||
|
extern void delay (unsigned int howLong) ;
|
||||||
|
|
||||||
// ODROID Wiring Library
|
// ODROID Wiring Library
|
||||||
struct libodroid libwiring;
|
struct libodroid libwiring;
|
||||||
|
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params)
|
|||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined ANDROID
|
||||||
/*
|
/*
|
||||||
* doExtensionDrcNet:
|
* doExtensionDrcNet:
|
||||||
* Interface to a DRC Network system
|
* Interface to a DRC Network system
|
||||||
@@ -802,7 +802,7 @@ static int doExtensionDrcNet (char *progName, int pinBase, char *params)
|
|||||||
return drcSetupNet (pinBase, pins, ipAddress, port, password) ;
|
return drcSetupNet (pinBase, pins, ipAddress, port, password) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function list
|
* Function list
|
||||||
@@ -820,7 +820,9 @@ static struct extensionFunctionStruct extensionFunctions [] =
|
|||||||
{ "pcf8574", &doExtensionPcf8574 },
|
{ "pcf8574", &doExtensionPcf8574 },
|
||||||
{ "pcf8591", &doExtensionPcf8591 },
|
{ "pcf8591", &doExtensionPcf8591 },
|
||||||
{ "bmp180", &doExtensionBmp180 },
|
{ "bmp180", &doExtensionBmp180 },
|
||||||
|
#if !defined ANDROID
|
||||||
{ "pseudoPins", &doExtensionPseudoPins },
|
{ "pseudoPins", &doExtensionPseudoPins },
|
||||||
|
#endif
|
||||||
{ "htu21d", &doExtensionHtu21d },
|
{ "htu21d", &doExtensionHtu21d },
|
||||||
{ "ds18b20", &doExtensionDs18b20 },
|
{ "ds18b20", &doExtensionDs18b20 },
|
||||||
{ "mcp3002", &doExtensionMcp3002 },
|
{ "mcp3002", &doExtensionMcp3002 },
|
||||||
@@ -832,7 +834,9 @@ static struct extensionFunctionStruct extensionFunctions [] =
|
|||||||
{ "max5322", &doExtensionMax5322 },
|
{ "max5322", &doExtensionMax5322 },
|
||||||
{ "sn3218", &doExtensionSn3218 },
|
{ "sn3218", &doExtensionSn3218 },
|
||||||
{ "drcs", &doExtensionDrcS },
|
{ "drcs", &doExtensionDrcS },
|
||||||
|
#if !defined ANDROID
|
||||||
{ "drcn", &doExtensionDrcNet },
|
{ "drcn", &doExtensionDrcNet },
|
||||||
|
#endif
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user