[Armadeus-commitlog] armadeus branch, buildroot-update, updated. armadeus-6.0-146-g1f14c01
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2016-10-31 11:52:00
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, buildroot-update has been updated
via 1f14c01b8c3fc4d4fb6054d547fbecb43746ea1c (commit)
via d8a4bd3c3a587e72b2d6d9251a3a8293b457edcd (commit)
from fd9c1f676e700128a8a16ee247b0e6630274b349 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1f14c01b8c3fc4d4fb6054d547fbecb43746ea1c
Author: Julien BOIBESSOT <jul...@ar...>
Date: Mon Oct 31 12:45:51 2016 +0100
[BUILDROOT] 2016.08: add a simple LoRa gateway (packet forwarder)
commit d8a4bd3c3a587e72b2d6d9251a3a8293b457edcd
Author: Julien BOIBESSOT <jul...@ar...>
Date: Mon Oct 31 12:40:34 2016 +0100
[AS_DEVICES] add wiringPi compatibility layer
-----------------------------------------------------------------------
Summary of changes:
.../package/armadeus/as_devices/as_devices.mk | 2 +-
.../029-armadeus-lora-forwarder-add-package.patch | 92 +++++
patches/buildroot/2016.08/cleanup_buildroot.sh | 3 +
target/packages/as_devices/Makefile | 1 +
target/packages/as_devices/c/Makefile | 9 +-
.../packages/as_devices/c/wiringPi/COPYING.LESSER | 165 ++++++++
target/packages/as_devices/c/wiringPi/wiringPi.c | 405 ++++++++++++++++++++
target/packages/as_devices/c/wiringPi/wiringPi.h | 181 +++++++++
.../packages/as_devices/c/wiringPi/wiringPiI2C.c | 232 +++++++++++
.../packages/as_devices/c/wiringPi/wiringPiI2C.h | 42 ++
.../packages/as_devices/c/wiringPi/wiringPiSPI.c | 136 +++++++
.../packages/as_devices/c/wiringPi/wiringPiSPI.h | 36 ++
.../packages/as_devices/c/wiringPi/wiringSerial.c | 213 ++++++++++
.../packages/as_devices/c/wiringPi/wiringSerial.h | 38 ++
14 files changed, 1552 insertions(+), 3 deletions(-)
create mode 100644 patches/buildroot/2016.08/029-armadeus-lora-forwarder-add-package.patch
create mode 100644 target/packages/as_devices/c/wiringPi/COPYING.LESSER
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPi.c
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPi.h
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPiI2C.c
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPiI2C.h
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPiSPI.c
create mode 100644 target/packages/as_devices/c/wiringPi/wiringPiSPI.h
create mode 100644 target/packages/as_devices/c/wiringPi/wiringSerial.c
create mode 100644 target/packages/as_devices/c/wiringPi/wiringSerial.h
diff --git a/buildroot/package/armadeus/as_devices/as_devices.mk b/buildroot/package/armadeus/as_devices/as_devices.mk
index f6a3c6b..a3d4d97 100644
--- a/buildroot/package/armadeus/as_devices/as_devices.mk
+++ b/buildroot/package/armadeus/as_devices/as_devices.mk
@@ -4,7 +4,7 @@
#
################################################################################
-AS_DEVICES_VERSION = 0.17
+AS_DEVICES_VERSION = 0.18
AS_DEVICES_SITE = $(TOPDIR)/../target/packages/as_devices
ifeq ($(generic-package), )
AS_DEVICES_SITE_METHOD = copy
diff --git a/patches/buildroot/2016.08/029-armadeus-lora-forwarder-add-package.patch b/patches/buildroot/2016.08/029-armadeus-lora-forwarder-add-package.patch
new file mode 100644
index 0000000..65600eb
--- /dev/null
+++ b/patches/buildroot/2016.08/029-armadeus-lora-forwarder-add-package.patch
@@ -0,0 +1,92 @@
+Signed-off-by: Julien Boibessot <jul...@ar...>
+
+Index: buildroot/package/lora-forwarder/lora-forwarder.mk
+===================================================================
+--- /dev/null
++++ buildroot/package/lora-forwarder/lora-forwarder.mk
+@@ -0,0 +1,27 @@
++################################################################################
++#
++# lora-forwarder
++#
++################################################################################
++
++LORA_FORWARDER_VERSION = a29921789bc5b63d6a7c51e46dd6314aca06b99e
++LORA_FORWARDER_SITE = $(call github,tftelkamp,single_chan_pkt_fwd,$(LORA_FORWARDER_VERSION))
++LORA_FORWARDER_LICENSE = Eclipse Public License v1.0 + Semtech
++LORA_FORWARDER_LICENSE_FILES = main.cpp LICENSE
++# as_devices provides wiringPi interface:
++LORA_FORWARDER_DEPENDENCIES = as_devices
++
++define LORA_FORWARDER_BUILD_CMDS
++ $(TARGET_MAKE_ENV) $(MAKE) \
++ CC="$(TARGET_CXX)" \
++ CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include/as_devices/" \
++ LD="$(TARGET_LD)" \
++ LIBS="-L$(STAGING_DIR)/usr/lib/ -las_devices" \
++ -C $(@D)
++endef
++
++define LORA_FORWARDER_INSTALL_TARGET_CMDS
++ $(INSTALL) -D -m 755 $(@D)/single_chan_pkt_fwd $(TARGET_DIR)/usr/bin/
++endef
++
++$(eval $(generic-package))
+Index: buildroot/package/lora-forwarder/Config.in
+===================================================================
+--- /dev/null
++++ buildroot/package/lora-forwarder/Config.in
+@@ -0,0 +1,7 @@
++config BR2_PACKAGE_LORA_FORWARDER
++ bool "LoRa packet forwarder"
++ help
++ Forward LoRa packets received from SX1276/RFM95W transceivers to a
++ fixed IP network server.
++
++ https://github.com/tftelkamp/single_chan_pkt_fwd
+Index: buildroot/package/Config.in
+===================================================================
+--- buildroot.orig/package/Config.in
++++ buildroot/package/Config.in
+@@ -1524,6 +1524,7 @@ menu "Networking applications"
+ source "package/linphone/Config.in"
+ source "package/linux-zigbee/Config.in"
+ source "package/lldpd/Config.in"
++ source "package/lora-forwarder/Config.in"
+ source "package/lrzsz/Config.in"
+ source "package/macchanger/Config.in"
+ source "package/memcached/Config.in"
+Index: buildroot/package/lora-forwarder/0001-fix-cross-compiling.patch
+===================================================================
+--- /dev/null
++++ buildroot/package/lora-forwarder/0001-fix-cross-compiling.patch
+@@ -0,0 +1,29 @@
++Signed-off-by: Julien Boibessot <jul...@ar...>
++
++diff -urN lora-forwarder-a29921789bc5b63d6a7c51e46dd6314aca06b99e/Makefile lora-forwarder-a29921789bc5b63d6a7c51e46dd6314aca06b99e.mod/Makefile
++--- lora-forwarder-a29921789bc5b63d6a7c51e46dd6314aca06b99e/Makefile 2016-01-06 12:06:08.000000000 +0100
+++++ lora-forwarder-a29921789bc5b63d6a7c51e46dd6314aca06b99e.mod/Makefile 2016-10-28 18:38:25.527840090 +0200
++@@ -7,14 +7,14 @@
++
++ all: single_chan_pkt_fwd
++
++-single_chan_pkt_fwd: base64.o main.o
++- $(CC) main.o base64.o $(LIBS) -o single_chan_pkt_fwd
+++single_chan_pkt_fwd: base64.c main.cpp
+++ $(CC) $(CFLAGS) main.cpp base64.c $(LIBS) -o single_chan_pkt_fwd
++
++-main.o: main.cpp
++- $(CC) $(CFLAGS) main.cpp
++-
++-base64.o: base64.c
++- $(CC) $(CFLAGS) base64.c
+++#main.o: main.cpp
+++# $(CC) $(CFLAGS) main.cpp
+++#
+++#base64.o: base64.c
+++# $(CC) $(CFLAGS) base64.c
++
++ clean:
++- rm *.o single_chan_pkt_fwd
++\ Pas de fin de ligne à la fin du fichier
+++ rm -f *.o single_chan_pkt_fwd
diff --git a/patches/buildroot/2016.08/cleanup_buildroot.sh b/patches/buildroot/2016.08/cleanup_buildroot.sh
index fd36984..0bc616f 100755
--- a/patches/buildroot/2016.08/cleanup_buildroot.sh
+++ b/patches/buildroot/2016.08/cleanup_buildroot.sh
@@ -64,6 +64,9 @@ rm -rf buildroot/package/linux-firmware/linux-firmware.mk
rm -rf buildroot/package/linux-headers/2.6.29.6/0001-net-Support-inclusion-of-linux-socket.h-before-sys-s.patch
rm -rf buildroot/package/linux-headers/2.6.29.6/368-redhat-types_h-define-__aligned_u64-and-expose-to-userspace.patch
rm -rf buildroot/package/linux-headers/2.6.35.3/368-redhat-types_h-define-__aligned_u64-and-expose-to-userspace.patch
+rm -rf buildroot/package/lora-forwarder/0001-fix-cross-compiling.patch
+rm -rf buildroot/package/lora-forwarder/Config.in
+rm -rf buildroot/package/lora-forwarder/lora-forwarder.mk
rm -rf buildroot/package/ltrace/Config.in
rm -rf buildroot/package/marble/Config.in
rm -rf buildroot/package/marble/marble.mk
diff --git a/target/packages/as_devices/Makefile b/target/packages/as_devices/Makefile
index f4248d1..22e5a7b 100644
--- a/target/packages/as_devices/Makefile
+++ b/target/packages/as_devices/Makefile
@@ -51,6 +51,7 @@ install:
install -D $(C_LIB) $(INSTALL_DIR)/usr/lib/$(C_LIBNAME)
mkdir -p $(INSTALL_DIR)/usr/include/as_devices/
cp $(C_INCLUDE)/*.h $(INSTALL_DIR)/usr/include/as_devices/
+ cp $(C_INCLUDE)/wiringPi/*.h $(INSTALL_DIR)/usr/include/as_devices/
install-exe:
install -D $(C_LIB) $(INSTALL_DIR)/usr/lib/$(C_LIBNAME)
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 2e373d3..ebaa128 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -28,6 +28,11 @@ OBJ += as_helpers.o
OBJ += as_power_supply.o
OBJ += as_tcs3472.o
+OBJ += wiringPi/wiringPi.o
+OBJ += wiringPi/wiringPiI2C.o
+OBJ += wiringPi/wiringPiSPI.o
+OBJ += wiringPi/wiringSerial.o
+
LIBRARY = as_devices
LIB_VERS = 1
STAT_LIB = $(LIBRARY).a
@@ -37,16 +42,16 @@ ARCHIVE_CMD = ar
ARCHIVE_OPTS = -cvq
$(LIBNAME): $(OBJ)
+ @echo " LNK $@"
@$(CC) -shared -Wl,-soname,$(SONAME) -o $(SONAME) $(OBJ)
@ln -sf $(SONAME) $(LIBNAME)
- @echo " LNK $@"
$(STAT_LIB): $(OBJ)
$(ARCHIVE_CMD) $(ARCHIVE_OPTS) $(STAT_LIB) $(OBJ)
%.o: %.c
- @$(CC) -fPIC -o $@ -c $< $(CFLAGS)
@echo " CC $@"
+ @$(CC) -fPIC -o $@ -c $< $(CFLAGS) -I./wiringPi/
clean:
rm -f $(OBJ) $(BINARY) $(LIBNAME) $(SONAME)
diff --git a/target/packages/as_devices/c/wiringPi/COPYING.LESSER b/target/packages/as_devices/c/wiringPi/COPYING.LESSER
new file mode 100644
index 0000000..65c5ca8
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/COPYING.LESSER
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/target/packages/as_devices/c/wiringPi/wiringPi.c b/target/packages/as_devices/c/wiringPi/wiringPi.c
new file mode 100644
index 0000000..a24baaf
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPi.c
@@ -0,0 +1,405 @@
+/*
+ * wiringPi:
+ * Arduino look-a-like Wiring library for the Raspberry Pi
+ * Copyright (c) 2012-2015 Gordon Henderson
+ * Additional code for pwmSetClock by Chris Hall <ch...@kc...>
+ *
+ * Thanks to code samples from Gert Jan van Loo and the
+ * BCM2835 ARM Peripherals manual, however it's missing
+ * the clock section /grr/mutter/
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h> /* lseek() */
+#include <poll.h> /* poll() */
+#include <sys/time.h> /* gettimeofday() */
+#include <time.h> /* nanosleep() */
+#include <fcntl.h> /* open() */
+
+#include "wiringPi.h"
+
+// Environment Variables
+
+#define ENV_DEBUG "WIRINGPI_DEBUG"
+#define ENV_CODES "WIRINGPI_CODES"
+#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
+
+
+static uint64_t epochMilli, epochMicro ;
+
+static int wiringPiMode = WPI_MODE_UNINITIALISED ;
+// Debugging & Return codes
+
+int wiringPiDebug = FALSE ;
+int wiringPiReturnCodes = FALSE ;
+
+#define GPIO_NUMBER 128
+
+static int sysFds [GPIO_NUMBER] =
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+} ;
+
+static int pinToGpio [] =
+{
+ 24, -1, -1, -1, -1, -1, 97, 10,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+// Padding:
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 31
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
+} ;
+
+/*
+ * wiringPiFailure:
+ * Fail. Or not.
+ *********************************************************************************
+ */
+
+int wiringPiFailure (int fatal, const char *message, ...)
+{
+ va_list argp ;
+ char buffer [1024] ;
+
+ if (!fatal && wiringPiReturnCodes)
+ return -1 ;
+
+ va_start (argp, message) ;
+ vsnprintf (buffer, 1023, message, argp) ;
+ va_end (argp) ;
+
+ fprintf (stderr, "%s", buffer) ;
+ exit (EXIT_FAILURE) ;
+
+ return 0 ;
+}
+
+
+/*
+ * wpiPinToGpio:
+ * Translate a wiringPi Pin number to native GPIO pin number.
+ * Provided for external support.
+ *********************************************************************************
+ */
+
+int wpiPinToGpio (int wpiPin)
+{
+ return pinToGpio [wpiPin & 63] ;
+}
+
+/*
+ * pinMode:
+ * Sets the mode of a pin to be input, output or PWM output
+ *********************************************************************************
+ */
+
+void pinMode (int pin, int mode)
+{
+ fprintf(stderr, "wiringPi emulation in as_devices: your software is calling pinMode(%d, %d) which is not implemented. \n"
+ "I hope you did the corresponding echo %d > /sys/class/gpio/export + echo in/out > /sys/class/gpio/gpio%d/direction !\n",
+ pin, mode, wpiPinToGpio(pin), wpiPinToGpio(pin));
+}
+
+
+/*
+ * digitalRead:
+ * Read the value of a given Pin, returning HIGH or LOW
+ *********************************************************************************
+ */
+
+int digitalRead (int pin)
+{
+ char c ;
+
+ // WiringPi N° -> Linux GPIO N°
+ if (wiringPiMode == WPI_MODE_PINS)
+ pin = wpiPinToGpio(pin);
+
+ //printf("%s(%d)\n", __func__, pin);
+
+ if (sysFds [pin] == -1) {
+ fprintf(stderr, "%s: gpio%d not exported !\n", __func__ ,pin);
+ return LOW ;
+ }
+
+ lseek (sysFds [pin], 0L, SEEK_SET) ;
+ read (sysFds [pin], &c, 1) ;
+ return (c == '0') ? LOW : HIGH ;
+}
+
+
+/*
+ * digitalWrite:
+ * Set an output bit
+ *********************************************************************************
+ */
+
+void digitalWrite (int pin, int value)
+{
+ // WiringPi N° -> Linux GPIO N°
+ if (wiringPiMode == WPI_MODE_PINS)
+ pin = wpiPinToGpio(pin);
+
+ //printf("%s(%d, %d)\n", __func__, pin, value);
+ if (sysFds [pin] != -1)
+ {
+ if (value == LOW)
+ write (sysFds [pin], "0\n", 2) ;
+ else
+ write (sysFds [pin], "1\n", 2) ;
+ } else {
+ fprintf(stderr, "%s: gpio%d not exported !\n", __func__ ,pin);
+ }
+
+ return ;
+}
+
+
+/*
+ * waitForInterrupt:
+ * Pi Specific.
+ * Wait for Interrupt on a GPIO pin.
+ * This is actually done via the /sys/class/gpio interface regardless of
+ * the wiringPi access mode in-use. Maybe sometime it might get a better
+ * way for a bit more efficiency.
+ *********************************************************************************
+ */
+
+int waitForInterrupt (int pin, int mS)
+{
+ int fd, x ;
+ uint8_t c ;
+ struct pollfd polls ;
+
+ if ((fd = sysFds [pin]) == -1)
+ return -2 ;
+
+// Setup poll structure
+
+ polls.fd = fd ;
+ polls.events = POLLPRI ; // Urgent data!
+
+// Wait for it ...
+
+ x = poll (&polls, 1, mS) ;
+
+// Do a dummy read to clear the interrupt
+// A one character read appars to be enough.
+// Followed by a seek to reset it.
+
+ (void)read (fd, &c, 1) ;
+ lseek (fd, 0, SEEK_SET) ;
+
+ return x ;
+}
+
+
+/*
+ * initialiseEpoch:
+ * Initialise our start-of-time variable to be the current unix
+ * time in milliseconds and microseconds.
+ *********************************************************************************
+ */
+
+static void initialiseEpoch (void)
+{
+ struct timeval tv ;
+
+ gettimeofday (&tv, NULL) ;
+ epochMilli = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ;
+ epochMicro = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)(tv.tv_usec) ;
+}
+
+
+/*
+ * delay:
+ * Wait for some number of milliseconds
+ *********************************************************************************
+ */
+
+void delay (unsigned int howLong)
+{
+ struct timespec sleeper, dummy ;
+
+ sleeper.tv_sec = (time_t)(howLong / 1000) ;
+ sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
+
+ nanosleep (&sleeper, &dummy) ;
+}
+
+
+/*
+ * delayMicroseconds:
+ * This is somewhat intersting. It seems that on the Pi, a single call
+ * to nanosleep takes some 80 to 130 microseconds anyway, so while
+ * obeying the standards (may take longer), it's not always what we
+ * want!
+ *
+ * So what I'll do now is if the delay is less than 100uS we'll do it
+ * in a hard loop, watching a built-in counter on the ARM chip. This is
+ * somewhat sub-optimal in that it uses 100% CPU, something not an issue
+ * in a microcontroller, but under a multi-tasking, multi-user OS, it's
+ * wastefull, however we've no real choice )-:
+ *
+ * Plan B: It seems all might not be well with that plan, so changing it
+ * to use gettimeofday () and poll on that instead...
+ *********************************************************************************
+ */
+
+void delayMicrosecondsHard (unsigned int howLong)
+{
+ struct timeval tNow, tLong, tEnd ;
+
+ gettimeofday (&tNow, NULL) ;
+ tLong.tv_sec = howLong / 1000000 ;
+ tLong.tv_usec = howLong % 1000000 ;
+ timeradd (&tNow, &tLong, &tEnd) ;
+
+ while (timercmp (&tNow, &tEnd, <))
+ gettimeofday (&tNow, NULL) ;
+}
+
+void delayMicroseconds (unsigned int howLong)
+{
+ struct timespec sleeper ;
+ unsigned int uSecs = howLong % 1000000 ;
+ unsigned int wSecs = howLong / 1000000 ;
+
+ /**/ if (howLong == 0)
+ return ;
+ else if (howLong < 100)
+ delayMicrosecondsHard (howLong) ;
+ else
+ {
+ sleeper.tv_sec = wSecs ;
+ sleeper.tv_nsec = (long)(uSecs * 1000L) ;
+ nanosleep (&sleeper, NULL) ;
+ }
+}
+
+
+/*
+ * millis:
+ * Return a number of milliseconds as an unsigned int.
+ *********************************************************************************
+ */
+
+unsigned int millis (void)
+{
+ struct timeval tv ;
+ uint64_t now ;
+
+ gettimeofday (&tv, NULL) ;
+ now = (uint64_t)tv.tv_sec * (uint64_t)1000 + (uint64_t)(tv.tv_usec / 1000) ;
+
+ return (uint32_t)(now - epochMilli) ;
+}
+
+
+/*
+ * micros:
+ * Return a number of microseconds as an unsigned int.
+ *********************************************************************************
+ */
+
+unsigned int micros (void)
+{
+ struct timeval tv ;
+ uint64_t now ;
+
+ gettimeofday (&tv, NULL) ;
+ now = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec ;
+
+ return (uint32_t)(now - epochMicro) ;
+}
+
+
+/*
+ * wiringPiSetupSys:
+ * Must be called once at the start of your program execution.
+ *
+ * Initialisation (again), however this time we are using the /sys/class/gpio
+ * interface to the GPIO systems - slightly slower, but always usable as
+ * a non-root user, assuming the devices are already exported and setup correctly.
+ */
+
+int wiringPiSetupSys (void)
+{
+// int boardRev ;
+ int pin ;
+ char fName [128] ;
+ static int alreadyCalled = FALSE ;
+
+// This is here to trap the unwary - those who's program appears to work then fails some
+// time later with a weird error message because you run out of file-handles.
+
+ if (alreadyCalled)
+ (void)wiringPiFailure (WPI_FATAL, "wiringPiSetupSys: You must only call this once per program run. This is a fatal error. Please fix your code.\n") ;
+
+ alreadyCalled = TRUE ;
+
+ if (getenv (ENV_DEBUG) != NULL)
+ wiringPiDebug = TRUE ;
+
+ if (getenv (ENV_CODES) != NULL)
+ wiringPiReturnCodes = TRUE ;
+
+ if (wiringPiDebug)
+ printf ("wiringPi: wiringPiSetupSys called\n") ;
+
+// Open and scan the directory, looking for exported GPIOs, and pre-open
+// the 'value' interface to speed things up for later
+
+ for (pin = 0 ; pin < GPIO_NUMBER ; ++pin)
+ {
+ sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
+ sysFds [pin] = open (fName, O_RDWR) ;
+ }
+
+ initialiseEpoch () ;
+
+ wiringPiMode = WPI_MODE_GPIO_SYS ;
+
+ return 0 ;
+}
+
+
+int wiringPiSetup(void)
+{
+ int res;
+
+ // On Armadeus we always use /sys/class/gpio interface
+ res = wiringPiSetupSys();
+ wiringPiMode = WPI_MODE_PINS;
+ return res;
+}
diff --git a/target/packages/as_devices/c/wiringPi/wiringPi.h b/target/packages/as_devices/c/wiringPi/wiringPi.h
new file mode 100644
index 0000000..e51e397
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPi.h
@@ -0,0 +1,181 @@
+/*
+ * wiringPi.h:
+ * Arduino like Wiring library for the Raspberry Pi.
+ * Copyright (c) 2012-2016 Gordon Henderson
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#ifndef __WIRING_PI_H__
+#define __WIRING_PI_H__
+
+// C doesn't have true/false by default and I can never remember which
+// way round they are, so ...
+
+#ifndef TRUE
+# define TRUE (1==1)
+# define FALSE (!TRUE)
+#endif
+
+// Handy defines
+
+// wiringPi modes
+
+#define WPI_MODE_PINS 0
+//#define WPI_MODE_GPIO 1
+#define WPI_MODE_GPIO_SYS 2
+//#define WPI_MODE_PHYS 3
+//#define WPI_MODE_PIFACE 4
+#define WPI_MODE_UNINITIALISED -1
+
+// Pin modes
+
+#define INPUT 0
+#define OUTPUT 1
+/*
+#define PWM_OUTPUT 2
+#define GPIO_CLOCK 3
+#define SOFT_PWM_OUTPUT 4
+#define SOFT_TONE_OUTPUT 5
+#define PWM_TONE_OUTPUT 6
+*/
+#define LOW 0
+#define HIGH 1
+/*
+// Pull up/down/none
+
+#define PUD_OFF 0
+#define PUD_DOWN 1
+#define PUD_UP 2
+
+// PWM
+
+#define PWM_MODE_MS 0
+#define PWM_MODE_BAL 1
+
+// Interrupt levels
+
+#define INT_EDGE_SETUP 0
+#define INT_EDGE_FALLING 1
+#define INT_EDGE_RISING 2
+#define INT_EDGE_BOTH 3
+
+// Pi model types and version numbers
+// Intended for the GPIO program Use at your own risk.
+
+#define PI_MODEL_A 0
+#define PI_MODEL_B 1
+#define PI_MODEL_AP 2
+#define PI_MODEL_BP 3
+#define PI_MODEL_2 4
+#define PI_ALPHA 5
+#define PI_MODEL_CM 6
+#define PI_MODEL_07 7
+#define PI_MODEL_3 8
+#define PI_MODEL_ZERO 9
+
+#define PI_VERSION_1 0
+#define PI_VERSION_1_1 1
+#define PI_VERSION_1_2 2
+#define PI_VERSION_2 3
+
+#define PI_MAKER_SONY 0
+#define PI_MAKER_EGOMAN 1
+#define PI_MAKER_MBEST 2
+#define PI_MAKER_UNKNOWN 3
+
+extern const char *piModelNames [16] ;
+extern const char *piRevisionNames [16] ;
+extern const char *piMakerNames [16] ;
+extern const int piMemorySize [ 8] ;
+
+
+// Intended for the GPIO program Use at your own risk.
+
+// Threads
+
+#define PI_THREAD(X) void *X (void *dummy)
+*/
+// Failure modes
+
+#define WPI_FATAL (1==1)
+#define WPI_ALMOST (1==2)
+
+// Function prototypes
+// c++ wrappers thanks to a comment by Nick Lott
+// (and others on the Raspberry Pi forums)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Data
+
+// Internal
+
+extern int wiringPiFailure (int fatal, const char *message, ...) ;
+
+// Core wiringPi functions
+
+extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
+extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
+
+extern int wiringPiSetup (void) ;
+extern int wiringPiSetupSys (void) ;
+
+//extern void pinModeAlt (int pin, int mode) ;
+extern void pinMode (int pin, int mode) ;
+//extern void pullUpDnControl (int pin, int pud) ;
+extern int digitalRead (int pin) ;
+extern void digitalWrite (int pin, int value) ;
+//extern void pwmWrite (int pin, int value) ;
+//extern int analogRead (int pin) ;
+//extern void analogWrite (int pin, int value) ;
+
+// On-Board Raspberry Pi hardware specific stuff
+
+extern int wpiPinToGpio (int wpiPin) ;
+
+// Interrupts
+// (Also Pi hardware specific)
+
+extern int waitForInterrupt (int pin, int mS) ;
+extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
+
+// Threads
+
+extern int piThreadCreate (void *(*fn)(void *)) ;
+extern void piLock (int key) ;
+extern void piUnlock (int key) ;
+
+// Schedulling priority
+
+extern int piHiPri (const int pri) ;
+
+// Extras from arduino land
+
+extern void delay (unsigned int howLong) ;
+extern void delayMicroseconds (unsigned int howLong) ;
+extern unsigned int millis (void) ;
+extern unsigned int micros (void) ;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/target/packages/as_devices/c/wiringPi/wiringPiI2C.c b/target/packages/as_devices/c/wiringPi/wiringPiI2C.c
new file mode 100644
index 0000000..92f570f
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPiI2C.c
@@ -0,0 +1,232 @@
+/*
+ * wiringPiI2C.c:
+ * Simplified I2C access routines
+ * Copyright (c) 2013 Gordon Henderson
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+/*
+ * Notes:
+ * The Linux I2C code is actually the same (almost) as the SMBus code.
+ * SMBus is System Management Bus - and in essentially I2C with some
+ * additional functionality added, and stricter controls on the electrical
+ * specifications, etc. however I2C does work well with it and the
+ * protocols work over both.
+ *
+ * I'm directly including the SMBus functions here as some Linux distros
+ * lack the correct header files, and also some header files are GPLv2
+ * rather than the LGPL that wiringPi is released under - presumably because
+ * originally no-one expected I2C/SMBus to be used outside the kernel -
+ * however enter the Raspberry Pi with people now taking directly to I2C
+ * devices without going via the kernel...
+ *
+ * This may ultimately reduce the flexibility of this code, but it won't be
+ * hard to maintain it and keep it current, should things change.
+ *
+ * Information here gained from: kernel/Documentation/i2c/dev-interface
+ * as well as other online resources.
+ *********************************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "wiringPi.h"
+#include "wiringPiI2C.h"
+
+// I2C definitions
+
+#define I2C_SLAVE 0x0703
+#define I2C_SMBUS 0x0720 /* SMBus-level access */
+
+#define I2C_SMBUS_READ 1
+#define I2C_SMBUS_WRITE 0
+
+// SMBus transaction types
+
+#define I2C_SMBUS_QUICK 0
+#define I2C_SMBUS_BYTE 1
+#define I2C_SMBUS_BYTE_DATA 2
+#define I2C_SMBUS_WORD_DATA 3
+#define I2C_SMBUS_PROC_CALL 4
+#define I2C_SMBUS_BLOCK_DATA 5
+#define I2C_SMBUS_I2C_BLOCK_BROKEN 6
+#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
+#define I2C_SMBUS_I2C_BLOCK_DATA 8
+
+// SMBus messages
+
+#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
+#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
+
+// Structures used in the ioctl() calls
+
+union i2c_smbus_data
+{
+ uint8_t byte ;
+ uint16_t word ;
+ uint8_t block [I2C_SMBUS_BLOCK_MAX + 2] ; // block [0] is used for length + one more for PEC
+} ;
+
+struct i2c_smbus_ioctl_data
+{
+ char read_write ;
+ uint8_t command ;
+ int size ;
+ union i2c_smbus_data *data ;
+} ;
+
+static inline int i2c_smbus_access (int fd, char rw, uint8_t command, int size, union i2c_smbus_data *data)
+{
+ struct i2c_smbus_ioctl_data args ;
+
+ args.read_write = rw ;
+ args.command = command ;
+ args.size = size ;
+ args.data = data ;
+ return ioctl (fd, I2C_SMBUS, &args) ;
+}
+
+
+/*
+ * wiringPiI2CRead:
+ * Simple device read
+ *********************************************************************************
+ */
+
+int wiringPiI2CRead (int fd)
+{
+ union i2c_smbus_data data ;
+
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
+ return -1 ;
+ else
+ return data.byte & 0xFF ;
+}
+
+
+/*
+ * wiringPiI2CReadReg8: wiringPiI2CReadReg16:
+ * Read an 8 or 16-bit value from a regsiter on the device
+ *********************************************************************************
+ */
+
+int wiringPiI2CReadReg8 (int fd, int reg)
+{
+ union i2c_smbus_data data;
+
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, &data))
+ return -1 ;
+ else
+ return data.byte & 0xFF ;
+}
+
+int wiringPiI2CReadReg16 (int fd, int reg)
+{
+ union i2c_smbus_data data;
+
+ if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, &data))
+ return -1 ;
+ else
+ return data.word & 0xFFFF ;
+}
+
+
+/*
+ * wiringPiI2CWrite:
+ * Simple device write
+ *********************************************************************************
+ */
+
+int wiringPiI2CWrite (int fd, int data)
+{
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) ;
+}
+
+
+/*
+ * wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
+ * Write an 8 or 16-bit value to the given register
+ *********************************************************************************
+ */
+
+int wiringPiI2CWriteReg8 (int fd, int reg, int value)
+{
+ union i2c_smbus_data data ;
+
+ data.byte = value ;
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, &data) ;
+}
+
+int wiringPiI2CWriteReg16 (int fd, int reg, int value)
+{
+ union i2c_smbus_data data ;
+
+ data.word = value ;
+ return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, &data) ;
+}
+
+
+/*
+ * wiringPiI2CSetupInterface:
+ * Undocumented access to set the interface explicitly - might be used
+ * for the Pi's 2nd I2C interface...
+ *********************************************************************************
+ */
+
+int wiringPiI2CSetupInterface (const char *device, int devId)
+{
+ int fd ;
+
+ if ((fd = open (device, O_RDWR)) < 0)
+ return wiringPiFailure (WPI_ALMOST, "Unable to open I2C device: %s\n", strerror (errno)) ;
+
+ if (ioctl (fd, I2C_SLAVE, devId) < 0)
+ return wiringPiFailure (WPI_ALMOST, "Unable to select I2C device: %s\n", strerror (errno)) ;
+
+ return fd ;
+}
+
+
+/*
+ * wiringPiI2CSetup:
+ * Open the I2C device, and register the target device
+ *********************************************************************************
+ */
+
+int wiringPiI2CSetup (const int devId)
+{
+// int rev ;
+ const char *device ;
+
+/* rev = piBoardRev () ;
+
+ if (rev == 1)
+ device = "/dev/i2c-0" ;
+ else */
+ device = "/dev/i2c-1" ;
+
+ return wiringPiI2CSetupInterface (device, devId) ;
+}
diff --git a/target/packages/as_devices/c/wiringPi/wiringPiI2C.h b/target/packages/as_devices/c/wiringPi/wiringPiI2C.h
new file mode 100644
index 0000000..11cbee4
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPiI2C.h
@@ -0,0 +1,42 @@
+/*
+ * wiringPiI2C.h:
+ * Simplified I2C access routines
+ * Copyright (c) 2013 Gordon Henderson
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int wiringPiI2CRead (int fd) ;
+extern int wiringPiI2CReadReg8 (int fd, int reg) ;
+extern int wiringPiI2CReadReg16 (int fd, int reg) ;
+
+extern int wiringPiI2CWrite (int fd, int data) ;
+extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
+extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
+
+extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
+extern int wiringPiI2CSetup (const int devId) ;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/target/packages/as_devices/c/wiringPi/wiringPiSPI.c b/target/packages/as_devices/c/wiringPi/wiringPiSPI.c
new file mode 100644
index 0000000..94539c1
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPiSPI.c
@@ -0,0 +1,136 @@
+/*
+ * wiringPiSPI.c:
+ * Simplified SPI access routines
+ * Copyright (c) 2012-2015 Gordon Henderson
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+
+#include <stdint.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <linux/spi/spidev.h>
+
+#include "wiringPi.h"
+
+#include "wiringPiSPI.h"
+
+
+// The SPI bus parameters
+// Variables as they need to be passed as pointers later on
+
+const static char *spiDev0 = "/dev/spidev3.0" ; // OPOS6ULDev
+const static char *spiDev1 = "/dev/spidev3.1" ; // OPOS6ULDev
+const static uint8_t spiBPW = 8 ;
+const static uint16_t spiDelay = 0 ;
+
+static uint32_t spiSpeeds [2] ;
+static int spiFds [2] ;
+
+
+/*
+ * wiringPiSPIGetFd:
+ * Return the file-descriptor for the given channel
+ *********************************************************************************
+ */
+
+int wiringPiSPIGetFd (int channel)
+{
+ return spiFds [channel & 1] ;
+}
+
+
+/*
+ * wiringPiSPIDataRW:
+ * Write and Read a block of data over the SPI bus.
+ * Note the data ia being read into the transmit buffer, so will
+ * overwrite it!
+ * This is also a full-duplex operation.
+ *********************************************************************************
+ */
+
+int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
+{
+ struct spi_ioc_transfer spi ;
+
+ channel &= 1 ;
+
+// Mentioned in spidev.h but not used in the original kernel documentation
+// test program )-:
+
+ memset (&spi, 0, sizeof (spi)) ;
+
+ spi.tx_buf = (unsigned long)data ;
+ spi.rx_buf = (unsigned long)data ;
+ spi.len = len ;
+ spi.delay_usecs = spiDelay ;
+ spi.speed_hz = spiSpeeds [channel] ;
+ spi.bits_per_word = spiBPW ;
+
+ return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &spi) ;
+}
+
+
+/*
+ * wiringPiSPISetupMode:
+ * Open the SPI device, and set it up, with the mode, etc.
+ *********************************************************************************
+ */
+
+int wiringPiSPISetupMode (int channel, int speed, int mode)
+{
+ int fd ;
+
+ mode &= 3 ; // Mode is 0, 1, 2 or 3
+ channel &= 1 ; // Channel is 0 or 1
+
+ if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
+ return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s (forgot to modprobe spidev ?)\n", strerror (errno)) ;
+
+ spiSpeeds [channel] = speed ;
+ spiFds [channel] = fd ;
+
+// Set SPI parameters.
+
+ if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0)
+ return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
+
+ if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
+ return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;
+
+ if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
+ return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;
+
+ return fd ;
+}
+
+
+/*
+ * wiringPiSPISetup:
+ * Open the SPI device, and set it up, etc. in the default MODE 0
+ *********************************************************************************
+ */
+
+int wiringPiSPISetup (int channel, int speed)
+{
+ return wiringPiSPISetupMode (channel, speed, 0) ;
+}
diff --git a/target/packages/as_devices/c/wiringPi/wiringPiSPI.h b/target/packages/as_devices/c/wiringPi/wiringPiSPI.h
new file mode 100644
index 0000000..4d2e16b
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringPiSPI.h
@@ -0,0 +1,36 @@
+/*
+ * wiringPiSPI.h:
+ * Simplified SPI access routines
+ * Copyright (c) 2012-2015 Gordon Henderson
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int wiringPiSPIGetFd (int channel) ;
+int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
+int wiringPiSPISetupMode (int channel, int speed, int mode) ;
+int wiringPiSPISetup (int channel, int speed) ;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/target/packages/as_devices/c/wiringPi/wiringSerial.c b/target/packages/as_devices/c/wiringPi/wiringSerial.c
new file mode 100644
index 0000000..410f42e
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringSerial.c
@@ -0,0 +1,213 @@
+/*
+ * wiringSerial.c:
+ * Handle a serial port
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "wiringSerial.h"
+
+/*
+ * serialOpen:
+ * Open and initialise the serial port, setting all the right
+ * port parameters - or as many as are required - hopefully!
+ *********************************************************************************
+ */
+
+int serialOpen (const char *device, const int baud)
+{
+ struct termios options ;
+ speed_t myBaud ;
+ int status, fd ;
+
+ switch (baud)
+ {
+ case 50: myBaud = B50 ; break ;
+ case 75: myBaud = B75 ; break ;
+ case 110: myBaud = B110 ; break ;
+ case 134: myBaud = B134 ; break ;
+ case 150: myBaud = B150 ; break ;
+ case 200: myBaud = B200 ; break ;
+ case 300: myBaud = B300 ; break ;
+ case 600: myBaud = B600 ; break ;
+ case 1200: myBaud = B1200 ; break ;
+ case 1800: myBaud = B1800 ; break ;
+ case 2400: myBaud = B2400 ; break ;
+ case 4800: myBaud = B4800 ; break ;
+ case 9600: myBaud = B9600 ; break ;
+ case 19200: myBaud = B19200 ; break ;
+ case 38400: myBaud = B38400 ; break ;
+ case 57600: myBaud = B57600 ; break ;
+ case 115200: myBaud = B115200 ; break ;
+ case 230400: myBaud = B230400 ; break ;
+
+ default:
+ return -2 ;
+ }
+
+ if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
+ return -1 ;
+
+ fcntl (fd, F_SETFL, O_RDWR) ;
+
+// Get and modify current options:
+
+ tcgetattr (fd, &options) ;
+
+ cfmakeraw (&options) ;
+ cfsetispeed (&options, myBaud) ;
+ cfsetospeed (&options, myBaud) ;
+
+ options.c_cflag |= (CLOCAL | CREAD) ;
+ options.c_cflag &= ~PARENB ;
+ options.c_cflag &= ~CSTOPB ;
+ options.c_cflag &= ~CSIZE ;
+ options.c_cflag |= CS8 ;
+ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
+ options.c_oflag &= ~OPOST ;
+
+ options.c_cc [VMIN] = 0 ;
+ options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
+
+ tcsetattr (fd, TCSANOW | TCSAFLUSH, &options) ;
+
+ ioctl (fd, TIOCMGET, &status);
+
+ status |= TIOCM_DTR ;
+ status |= TIOCM_RTS ;
+
+ ioctl (fd, TIOCMSET, &status);
+
+ usleep (10000) ; // 10mS
+
+ return fd ;
+}
+
+
+/*
+ * serialFlush:
+ * Flush the serial buffers (both tx & rx)
+ *********************************************************************************
+ */
+
+void serialFlush (const int fd)
+{
+ tcflush (fd, TCIOFLUSH) ;
+}
+
+
+/*
+ * serialClose:
+ * Release the serial port
+ *********************************************************************************
+ */
+
+void serialClose (const int fd)
+{
+ close (fd) ;
+}
+
+
+/*
+ * serialPutchar:
+ * Send a single character to the serial port
+ *********************************************************************************
+ */
+
+void serialPutchar (const int fd, const unsigned char c)
+{
+ write (fd, &c, 1) ;
+}
+
+
+/*
+ * serialPuts:
+ * Send a string to the serial port
+ *********************************************************************************
+ */
+
+void serialPuts (const int fd, const char *s)
+{
+ write (fd, s, strlen (s)) ;
+}
+
+/*
+ * serialPrintf:
+ * Printf over Serial
+ *********************************************************************************
+ */
+
+void serialPrintf (const int fd, const char *message, ...)
+{
+ va_list argp ;
+ char buffer [1024] ;
+
+ va_start (argp, message) ;
+ vsnprintf (buffer, 1023, message, argp) ;
+ va_end (argp) ;
+
+ serialPuts (fd, buffer) ;
+}
+
+
+/*
+ * serialDataAvail:
+ * Return the number of bytes of data avalable to be read in the serial port
+ *********************************************************************************
+ */
+
+int serialDataAvail (const int fd)
+{
+ int result ;
+
+ if (ioctl (fd, FIONREAD, &result) == -1)
+ return -1 ;
+
+ return result ;
+}
+
+
+/*
+ * serialGetchar:
+ * Get a single character from the serial device.
+ * Note: Zero is a valid character and this function will time-out after
+ * 10 seconds.
+ *********************************************************************************
+ */
+
+int serialGetchar (const int fd)
+{
+ uint8_t x ;
+
+ if (read (fd, &x, 1) != 1)
+ return -1 ;
+
+ return ((int)x) & 0xFF ;
+}
diff --git a/target/packages/as_devices/c/wiringPi/wiringSerial.h b/target/packages/as_devices/c/wiringPi/wiringSerial.h
new file mode 100644
index 0000000..09efe27
--- /dev/null
+++ b/target/packages/as_devices/c/wiringPi/wiringSerial.h
@@ -0,0 +1,38 @@
+/*
+ * wiringSerial.h:
+ * Handle a serial port
+ ***********************************************************************
+ * This file is an adaptation to Armadeus SOM of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int serialOpen (const char *device, const int baud) ;
+extern void serialClose (const int fd) ;
+extern void serialFlush (const int fd) ;
+extern void serialPutchar (const int fd, const unsigned char c) ;
+extern void serialPuts (const int fd, const char *s) ;
+extern void serialPrintf (const int fd, const char *message, ...) ;
+extern int serialDataAvail (const int fd) ;
+extern int serialGetchar (const int fd) ;
+
+#ifdef __cplusplus
+}
+#endif
hooks/post-receive
--
armadeus
|