Compare commits

...

50 Commits

Author SHA1 Message Date
Stefan Andritoiu
8ce214ae86 java: Added version information & checks to ensure Java version matches Native version
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:30:08 +01:00
Houman brinjcargorabi
8329bcab62 intel_edison_fab_c.c: fixed the pins not being freed in the event of a tristate read failing
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:29:17 +01:00
Houman brinjcargorabi
e8d6f38ee0 intel_nuc5.c: Fixed incorrect I2C numbering, effectively not shifting the pin number correctly
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:29:15 +01:00
Brendan Le Foll
a177a3f729 cmake: Fix tests with multiple python bindings being built
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:21:20 +01:00
Brendan Le Foll
99841419ab python: Support building of both python2 & python3 bindings
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-26 14:51:34 +01:00
David Antler
1cfdfcddc6 Add JavaScript mraaStub project
Signed-off-by: David Antler <david.a.antler@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:28:04 +01:00
Houman brinjcargorabi
a321d6707f mraa.i: Swig interface options to ignore the void* IO constructors and pre-initialise the c++ template functions
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
b6e6374370 c++: Added the ability to initialise a class using a context struct
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
bcf1584fbe mraa.c: Added common function to init io from a description
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
a9de84b74a intel_galileo_rev_g.c: Corrected typo in mapping re setting the pincmd for GPIO2
Fixes typo in 95c259f6b2

Acked-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-20 11:26:59 +01:00
Alex Tereschenko
0ee25fbd4d pwm.hpp: fixed some typos and styling in comments
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:52:16 +01:00
Bruno Meneguele
4fc3e7a73f banana_pi.md: fixed header table layout
In the second table (second 8-pin connector) wasn't present the table header and
because of that the layout was broken.

Signed-off-by: Bruno Eduardo de Oliveira Meneguele <bmeneguele@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:51:52 +01:00
Brendan Le Foll
88d878648b beaglebone.c: Remove unused variables
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:51:07 +01:00
Alexandru Timohi
828338a69a libmraa: Fix compilation warnings about unsigned ints
Make better use of unsigned/signed ints, signed ints are preffered unless there
is a good reason not to.

Signed-off-by: Alexandru Timohi <alexandru.timohi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:50:33 +01:00
Brendan Le Foll
022b36355f x86: Fix capabilities being initialised with only 7 bits
This whilst ugly should not cause an issue because of our use of calloc.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 10:23:10 +01:00
Brendan Le Foll
3969af2b24 iio.c: Fix the location mapping in iio
Go through channel array after getting byte mapping to correctly map channel
location. Doing it at the same time as mapping the indexes is unreliable
depending on filename etc...

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 12:31:47 +01:00
Stefan Andritoiu
b15ab84f61 README.md: Added java bindings to README
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 09:05:39 +01:00
Michael Kellner
d3a220479d beaglebone.c: fix beaglebone i2c bus 2 not existing
Signed-off-by: Michael Kellner mkellner@intlweb.com
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 09:02:21 +01:00
Noel Eck
905abdec7c travis-ci: Updates to ensure MRAA builds with clang.
The MRAA clang build was getting overridden with gcc.
This commit allows MRAA to build with clang and adds nodejs
0.10 to the build matrix.  Note, this means 8 builds
(2 compilers x 4 versions of nodejs).

    * Added compiler directive for clang/gcc.

    * Added build for node010.

    * Added make install to cover the MRAA install.

Signed-off-by: Noel Eck <noel.eck@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 08:59:19 +01:00
Brendan Le Foll
db546456d2 building.md: Fix typos in INSTALL_PREFIX
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 17:26:02 +01:00
Jon Trulson
f6d9cf57c9 uart_ow: add ow specific context and store search state there
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:50:02 +01:00
Mihai Tudor Panu
a702cdf4d5 ft4222: fixed pca9555 expander detection
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:48:40 +01:00
Evgen48
800c89bfa4 examples/java: input pin number should be parsed in base 10, not in base 8, similar to c++ sample
Signed-off-by: Eugene Smirnov <o1o2o3o4o5@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:46:16 +01:00
Brendan Le Foll
887acf54e1 mraa: Update to v1.0.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-28 15:59:40 +01:00
Brendan Le Foll
3a88c44620 i2c.c: rollback change to mraa_i2c_init that stopped default bus being used
Partly rollsback f2c4d95c15 which stopped
mraa_i2c_init from switching i2c bus silently. If you don't want this to
happen, you need to use mraa_i2c_init_raw. Closes #497.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-26 10:59:59 +01:00
Brendan Le Foll
5e867419bc spi.hpp: rename Spi::write_word to Spi::WriteWord
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:38:21 +01:00
Brendan Le Foll
4195a61e52 pwm: remove pwm config_* apis as unused
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:37:50 +01:00
Brendan Le Foll
c524c3d372 spi: mraa_spi_write_word can now return -1 in error cases
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:11:08 +01:00
Brendan Le Foll
b258867c37 aio.c: pass channel to mraa_aio_init_internal
This fixes previous broken commit because dev is not defined before
_internal_init but since fp is taken during internal init we need to know the
channel number. This does not affect the internal override API.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 12:17:32 +01:00
Brendan Le Foll
56e45f6de5 aio.c: Set channel number before grabbing filepointer
Fixes #495

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 11:53:49 +01:00
Robert Chiras
cdfdd2b9e3 Add support for android build
Using NPM, this module can be cross-compiled for Android using NDK.
But, when compiling for Android, we need to add glob.c to source files
(as in Android.mk).
Also, re-arranged the layout in binding.gyp for better readability.

Signed-off-by: Robert Chiras <robert.chiras@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 11:48:38 +01:00
Brendan Le Foll
c1465bd694 i2c: Make i2c advance function match new prototypes
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:59:17 +01:00
Brendan Le Foll
1e4516d026 i2c: Add exceptions for C++ i2c errors
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:58:57 +01:00
Brendan Le Foll
0b74aa68ab aio: Change mraa_aio_read to use int and return -1
This commit changes also the _replace function and adds exceptions to the C++
API for errors in AIO read

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:57:26 +01:00
Brendan Le Foll
e961558fd2 mraa: add mraa_remove_subplatform call
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 09:38:30 +01:00
Eugene Bolshakov
6d8ec87e0e edison: change pin initialization by adding pin commands
Pullup/pulldown resistors are disabled during GPIO initialization.

Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-19 18:39:11 +01:00
Brendan Le Foll
acf90073a8 types: Remove MRAA_ERROR_PLATFORM_ALREADY_INITIALISED
Enum was deprecated in 0.10.x and causes issues with strict C89 compliance so
is now removed

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:51:44 +01:00
wda2945
2404b0a683 pwm.c: Improve pwm error handling
Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
0da3d35a8f i2c.c: Fix typo in syslog message
Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
1ebe377487 uart.c: Improve error handling
Changed syslog messages and some error returns.

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
e757844a3d gpio.c: Improve gpio error handling
Changed syslog messages and some error returns.

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 13:46:25 +01:00
wda2945
f2c4d95c15 i2c: Improve i2c Error Handling
Edited syslog messages. Changed some return types to used signed and using -1
to indicate errors

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 13:46:25 +01:00
Brendan Le Foll
c41c3b41d5 uart_ow: Better error handling in corner cases
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 12:03:32 +01:00
Brendan Le Foll
4a52ad6c4f uart_ow: Make onewire functionality optional but on by default
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-14 13:52:09 +01:00
Jon Trulson
a379eb7bf6 uart_ow: Initial support for Dallas 1-wire over UART support for MRAA
This commit introduces support for Dallas Semiconductor (DS) 1-wire
compliant device support using an available UART device.

The principle of operation is described in the following Application
note by Maxim Electronics:

https://www.maximintegrated.com/en/app-notes/index.mvp/id/214

with help (1-wire search) from:
https://www.maximintegrated.com/en/app-notes/index.mvp/id/187

It has been tested on Galileo 2 and Edison, with 2 DS 1-wire devices,
the DS18B20 and DS2413 connected to the bus.  A UPM driver for the
DS2413 is already complete and a PR will be submitted after this one.

It is important that you use a UART with CMOS/TTL level voltages
(3.3v/5v) RX and TX lines.  DO NOT use standard RS232 level voltages
or you are going to have a bad day.

In order for this to work, a simple interface circuit, using a single
diode must be constructed:

(forgive my "Asciihematic" :)

-|
U|
A| TX---|<--+
R|          |
T| RX-------o--------o 1-wire data bus
-|

The diode on TX is a 1N4148 (cheap and common), with the cathode
connected to TX, and the anode connected to RX and the 1-wire data
line.

The 1-wire data line requires a pull-up resistor, as the DS 1-wire
spec requires. 4.7-5K is typical for DS 1-wire buses.

NOTE: DHT-type (temp/humidity sensor) 1-wire devices ARE NOT DS 1-wire
compliant, and will not work with this code/circuit unfortunately.

Also note, this will use up one of your UARTs, which cannot be used
for any other purpose (ie: to access true UART-type serial devices).

You can however, connect as many DS 1-wire devices as feasible to this
UART, as it will function as a DS 1-wire bus master.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-14 13:41:31 +01:00
Noel Eck
69d9c26e6e pkg_config: Update mraa.pc.cmake to use new install dir
LIB_SUFFIX is no longer used.  Replaced with LIB_INSTALL_DIR
which provides the correct lib dir with arch suffix.

Moved the call to include(GNUInstallDirs) prior to checking the
CMAKE_INSTALL_LIBDIR - which is set by include(GNUInstallDirs).

Tested with cmake 2.8 and cmake 3.5.

Signed-off-by: Noel Eck <noel.eck@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-12 14:18:19 +01:00
Mihai Tudor Panu
62e113ed3f cmake: use LIB_INSTALL_DIR throughout instead of CMAKE_INSTALL_LIBDIR
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-12 14:18:19 +01:00
Alex Tereschenko
00a0abd030 isr.js: updated JS ISR example to avoid GPIO context being destroyed
Closes #403.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:28:22 +01:00
Alex Tereschenko
ecf049eccd spi.c: removed hard frequency cap in mraa_spi_init_raw()
We rely on driver-supplied information in mraa_spi_frequency(),
so let's be consistent.

Closes #132.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:27:34 +01:00
Fathi Boudra
e1c500414b docs: fix spelling errors
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:13:06 +01:00
78 changed files with 3030 additions and 661 deletions

View File

@@ -1,10 +1,12 @@
language: cpp
env:
- CC=gcc CXX=gcc
- CC=clang CXX=clang++
- NODE010=true
- NODE012=true
- NODE4=true
- NODE5=true
- NODE012=true
compiler:
- clang
- gcc
install:
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
- sudo add-apt-repository --yes ppa:kalakris/cmake
@@ -14,19 +16,19 @@ install:
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
- sudo update-java-alternatives -s java-8-oracle
before_script:
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
- if [ "${NODE012}" ]; then nvm install 0.12; fi
- if [ "${NODE4}" ]; then nvm install 4.1; fi
- if [ "${NODE5}" ]; then nvm install 5; fi
# Handle 0.10 NODE_ROOT_DIR differently than other versions
- if [ -z ${NODE010} ]; then export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; else export NODE_ROOT_DIR=/home/travis/.nvm/v0.10.36; fi
script:
- mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" .. && make && make test
- echo "CC=$CC BUILDJAVA=$BUILDJAVA NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
- mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DCMAKE_INSTALL_PREFIX:PATH=../install .. && make install && make test
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- clang-3.6
- g++-4.8

View File

@@ -5,11 +5,17 @@ FIND_PACKAGE (Threads REQUIRED)
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer ")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
# Set CMAKE_LIB_INSTALL_DIR if not defined
# Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)
# Older cmake might not pick CMAKE_INSTALL_LIBDIR right
if (CMAKE_INSTALL_LIBDIR)
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
else ()
set (LIB_INSTALL_DIR "lib" CACHE PATH "Installation path for libraries")
endif ()
# By default, build shared object libraries on linux
if (UNIX AND NOT APPLE)
if (NOT DEFINED BUILD_SHARED_LIBS)
@@ -25,7 +31,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
message (WARNING " - Install git to compile a production libmraa!")
set (VERSION "v0.10.1-dirty")
set (VERSION "v1.0.0-dirty")
endif ()
message (STATUS "INFO - libmraa Version ${VERSION}")
@@ -64,11 +70,11 @@ option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDSWIGJAVA "Build Java API." OFF)
option (USBPLAT "Detection USB platform." OFF)
option (FIRMATA "Add Firmata support to mraa." OFF)
option (ONEWIRE "Add Onewire support to mraa." ON)
option (IMRAA "Add Imraa support to mraa." OFF)
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (ENABLEEXAMPLES "Disable building of examples" ON)
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
option (INSTALLTOOLS "Install all tools" OFF)
@@ -102,12 +108,7 @@ else ()
endif()
if (BUILDSWIGPYTHON OR BUILDTESTS)
if (BUILDPYTHON3)
set (PYTHONBUILD_VERSION 3)
else ()
set (PYTHONBUILD_VERSION 2.7)
endif ()
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
include (cmake/modules/OpenCVDetectPython.cmake)
endif ()
if (BUILDDOC)
@@ -195,9 +196,7 @@ if (IMRAA)
add_subdirectory (imraa)
endif ()
if (BUILDTESTS)
if (${PYTHONINTERP_FOUND})
enable_testing ()
add_subdirectory (tests)
endif ()
if (BUILDTESTS AND PYTHON_DEFAULT_EXECUTABLE)
enable_testing ()
add_subdirectory (tests)
endif ()

View File

@@ -4,10 +4,10 @@
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
==============
Libmraa is a C/C++ library with bindings to javascript & python to interface
with the IO on Galileo, Edison & other platforms, with a structured and sane
API where port names/numbering matches the board that you are on. Use of
libmraa does not tie you to specific hardware with board detection done at
Libmraa is a C/C++ library with bindings to Java, Python and JavaScript to
interface with the IO on Galileo, Edison & other platforms, with a structured
and sane API where port names/numbering matches the board that you are on. Use
of libmraa does not tie you to specific hardware with board detection done at
runtime you can create portable code that will work across the supported
platforms.

View File

@@ -33,6 +33,7 @@ extern "C" {
#include "mraa/spi.h"
#include "mraa/i2c.h"
#include "mraa/uart.h"
#include "mraa/uart_ow.h"
#ifdef __cplusplus
}

View File

@@ -59,19 +59,20 @@ typedef struct _aio* mraa_aio_context;
mraa_aio_context mraa_aio_init(unsigned int pin);
/**
* Read the input voltage. By default mraa will shift
* the raw value up or down to a 10 bit value.
* Read the input voltage. By default mraa will shift the raw value up or down
* to a 10 bit value.
*
* @param dev The AIO context
* @returns The current input voltage.
* @returns The current input voltage or -1 for error
*/
unsigned int mraa_aio_read(mraa_aio_context dev);
int mraa_aio_read(mraa_aio_context dev);
/**
* Read the input voltage and return it as a normalized float (0.0f-1.0f).
*
* @param dev The AIO context
* @returns The current input voltage as a normalized float (0.0f-1.0f)
* @returns The current input voltage as a normalized float (0.0f-1.0f), error
* will be signaled by -1.0f
*/
float mraa_aio_read_float(mraa_aio_context dev);

View File

@@ -47,13 +47,26 @@ class Aio
*
* @param pin channel number to read ADC inputs
*/
Aio(unsigned int pin)
Aio(int pin)
{
m_aio = mraa_aio_init(pin);
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
}
}
/**
* Aio Constructor, takes a pointer to the AIO context and initialises
* the AIO class
*
* @param void * to an AIO context
*/
Aio(void* aio_context)
{
m_aio = (mraa_aio_context) aio_context;
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO context");
}
}
/**
* Aio destructor
*/
@@ -65,22 +78,32 @@ class Aio
* Read a value from the AIO pin. By default mraa will shift
* the raw value up or down to a 10 bit value.
*
* @throws std::invalid_argument in case of error
* @returns The current input voltage. By default, a 10bit value
*/
int
unsigned int
read()
{
return mraa_aio_read(m_aio);
int x = mraa_aio_read(m_aio);
if (x == -1) {
throw std::invalid_argument("Unknown error in Aio::read()");
}
return (unsigned int) x;
}
/**
* Read a value from the AIO pin and return it as a normalized float.
*
* @throws std::invalid_argument in case of error
* @returns The current input voltage as a normalized float (0.0f-1.0f)
*/
float
readFloat()
{
return mraa_aio_read_float(m_aio);
float x = mraa_aio_read_float(m_aio);
if (x == -1.0f) {
throw std::invalid_argument("Unknown error in Aio::readFloat()");
}
return x;
}
/**
* Set the bit value which mraa will shift the raw reading

View File

@@ -159,7 +159,7 @@ const char* mraa_get_platform_version(int platform_offset);
* @param priority Value from typically 0 to 99
* @return The priority value set
*/
int mraa_set_priority(const unsigned int priority);
int mraa_set_priority(const int priority);
/** Get the version string of mraa autogenerated from git tag
*
@@ -214,7 +214,7 @@ int mraa_get_i2c_bus_count();
* @param i2c_bus the logical I2C bus number
* @return I2C adapter number in sysfs. Function will return -1 on failure
*/
int mraa_get_i2c_bus_id(unsigned int i2c_bus);
int mraa_get_i2c_bus_id(int i2c_bus);
/**
* Get specified platform pincount, board must be initialised.
@@ -284,6 +284,28 @@ int mraa_get_sub_platform_index(int pin_or_bus_id);
*/
mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev);
/**
* Remove a mraa subplatform
*
* @param subplatform type
*
* @return mraa_result indicating success
*/
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype);
/**
* Create IO using a description in the format:
* [io]-[pin]
* [io]-[raw]-[pin]
* [io]-[raw]-[id]-[pin]
* [io]-[raw]-[path]
*
* @param IO description
*
* @return void* to IO context or NULL
*/
void* mraa_init_io(const char* desc);
#ifdef __cplusplus
}
#endif

View File

@@ -78,7 +78,7 @@ getVersion()
* @return The priority value set
*/
inline int
setPriority(const unsigned int priority)
setPriority(const int priority)
{
return mraa_set_priority(priority);
}
@@ -195,7 +195,7 @@ getI2cBusCount()
* @return I2C adapter number in sysfs. Function will return -1 on failure
*/
inline int
getI2cBusId(unsigned int i2c_bus)
getI2cBusId(int i2c_bus)
{
return mraa_get_i2c_bus_id(i2c_bus);
}
@@ -303,4 +303,28 @@ addSubplatform(Platform subplatformtype, std::string uart_dev)
return (Result) mraa_add_subplatform((mraa_platform_t) subplatformtype, uart_dev.c_str());
}
inline Result
removeSubplatform(Platform subplatformtype)
{
return (Result) mraa_remove_subplatform((mraa_platform_t) subplatformtype);
}
/**
* Create IO using a description in the format:
* [io]-[pin]
* [io]-[raw]-[pin]
* [io]-[raw]-[id]-[pin]
* [io]-[raw]-[path]
*
* @param IO description
*
* @return class T initialised using pointer to IO or NULL
*/
template <class T>
inline T*
initIo(std::string desc)
{
return new T(mraa_init_io(desc.c_str()));
}
}

View File

@@ -71,7 +71,7 @@ mraa_result_t mraa_firmata_write_sysex(mraa_firmata_context dev, char* msg, int
* calling it need to make sure they are the only thread calling this.
*
* @param dev The Firmata context
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered, the returned buffer and length are the arguments.
* @return Result of operation
*/

View File

@@ -77,13 +77,13 @@ typedef enum {
} mraa_gpio_dir_t;
/**
* Gpio Edge types for interupts
* Gpio Edge types for interrupts
*/
typedef enum {
MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interrupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interrupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interrupt on falling only */
} mraa_gpio_edge_t;
/**
@@ -112,11 +112,11 @@ mraa_gpio_context mraa_gpio_init_raw(int gpiopin);
mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
/**
* Set an interupt on pin
* Set an interrupt on pin
*
* @param dev The Gpio context
* @param edge The edge mode to set the gpio into
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
@@ -124,7 +124,7 @@ mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (*fptr)(void*), void* args);
/**
* Stop the current interupt watcher on this Gpio, and set the Gpio edge mode
* Stop the current interrupt watcher on this Gpio, and set the Gpio edge mode
* to MRAA_GPIO_EDGE_NONE
*
* @param dev The Gpio context

View File

@@ -60,13 +60,13 @@ typedef enum {
} Dir;
/**
* Gpio Edge types for interupts
* Gpio Edge types for interrupts
*/
typedef enum {
EDGE_NONE = 0, /**< No interrupt on Gpio */
EDGE_BOTH = 1, /**< Interupt on rising & falling */
EDGE_RISING = 2, /**< Interupt on rising only */
EDGE_FALLING = 3 /**< Interupt on falling only */
EDGE_BOTH = 1, /**< Interrupt on rising & falling */
EDGE_RISING = 2, /**< Interrupt on rising only */
EDGE_FALLING = 3 /**< Interrupt on falling only */
} Edge;
/**
@@ -80,7 +80,7 @@ class Gpio
{
public:
/**
* Instanciates a Gpio object
* Instantiates a Gpio object
*
* @param pin pin number to use
* @param owner (optional) Set pin owner, default behaviour is to 'own'
@@ -107,6 +107,19 @@ class Gpio
mraa_gpio_owner(m_gpio, 0);
}
}
/**
* Gpio Constructor, takes a pointer to the GPIO context and initialises
* the GPIO class
*
* @param void * to GPIO context
*/
Gpio(void* gpio_context)
{
m_gpio = (mraa_gpio_context) gpio_context;
if (m_gpio == NULL) {
throw std::invalid_argument("Invalid GPIO context");
}
}
/**
* Gpio object destructor, this will only unexport the gpio if we where
* the owner
@@ -186,7 +199,7 @@ class Gpio
* Sets a callback to be called when pin value changes
*
* @param mode The edge mode to set
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
@@ -198,7 +211,7 @@ class Gpio
}
/**
* Exits callback - this call will not kill the isr thread immediatly
* Exits callback - this call will not kill the isr thread immediately
* but only when it is out of it's critical section
*
* @return Result of operation

View File

@@ -78,42 +78,40 @@ mraa_i2c_context mraa_i2c_init_raw(unsigned int bus);
mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode);
/**
* Simple bulk read from an i2c context, this will always begin with the i2c
* offset 0x0
* Simple bulk read from an i2c context
*
* @param dev The i2c context
* @param data pointer to the byte array to read data in to
* @param length max number of bytes to read
* @return length of the read in bytes or 0
* @return length of the read in bytes or -1
*/
int mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length);
/**
* Simple read for a single byte from the i2c context, this will always begin
* with the i2c offset 0x0
* Simple read for a single byte from the i2c context
*
* @param dev The i2c context
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
int mraa_i2c_read_byte(mraa_i2c_context dev);
/**
* Read a single byte from i2c context, from designated register
*
* @param dev The i2c context
* @param command The register
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
int mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
/**
* Read a single word from i2c context, from designated register
*
* @param dev The i2c context
* @param command The register
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
int mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
/**
* Bulk read from i2c context, starting from designated register
@@ -138,7 +136,7 @@ int mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* dat
mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length);
/**
* Write a single byte to an i2c context, always at offset 0x0
* Write a single byte to an i2c context
*
* @param dev The i2c context
* @param data The byte to write
@@ -167,12 +165,10 @@ mraa_result_t mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data,
mraa_result_t mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
/**
* Sets the i2c context address.
* Sets the i2c slave address.
*
* @param dev The i2c context
* @param address The address to set for the slave (ignoring the least
* signifcant bit). If set to 0, the slave will only respond to the
* general call address.
* @param address The address to set for the slave (7-bit address)
* @return Result of operation
*/
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, uint8_t address);

View File

@@ -62,6 +62,18 @@ class I2c
throw std::invalid_argument("Invalid i2c bus");
}
}
/**
* I2C constructor, takes a pointer to a I2C context and initialises the I2C class
*
* @param void * to an I2C context
*/
I2c(void* i2c_context)
{
m_i2c = (mraa_i2c_context) i2c_context;
if (m_i2c == NULL) {
throw std::invalid_argument("Invalid I2C context");
}
}
/**
* Closes the I2c Bus used. This does not guarrantee the bus will not
@@ -103,12 +115,17 @@ class I2c
/**
* Read exactly one byte from the bus
*
* @throws std::invalid_argument in case of error
* @return char read from the bus
*/
uint8_t
readByte()
{
return (uint8_t) mraa_i2c_read_byte(m_i2c);
int x = mraa_i2c_read_byte(m_i2c);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readByte()");
}
return (uint8_t) x;
}
/**
@@ -128,24 +145,36 @@ class I2c
* Read byte from an i2c register
*
* @param reg Register to read from
*
* @throws std::invalid_argument in case of error
* @return char read from register
*/
uint8_t
readReg(uint8_t reg)
{
return mraa_i2c_read_byte_data(m_i2c, reg);
int x = mraa_i2c_read_byte_data(m_i2c, reg);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readReg()");
}
return (uint8_t) x;
}
/**
* Read word from an i2c register
*
* @param reg Register to read from
*
* @throws std::invalid_argument in case of error
* @return char read from register
*/
uint16_t
readWordReg(uint8_t reg)
{
return mraa_i2c_read_word_data(m_i2c, reg);
int x = mraa_i2c_read_word_data(m_i2c, reg);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readReg()");
}
return (uint16_t) x;
}
/**

View File

@@ -65,7 +65,7 @@ mraa_pwm_context mraa_pwm_init(int pin);
mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
/**
* Set the ouput duty-cycle percentage, as a float
* Set the output duty-cycle percentage, as a float
*
* @param dev The Pwm context to use
* @param percentage A floating-point value representing percentage of output.
@@ -76,7 +76,7 @@ mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
mraa_result_t mraa_pwm_write(mraa_pwm_context dev, float percentage);
/**
* Read the ouput duty-cycle percentage, as a float
* Read the output duty-cycle percentage, as a float
*
* @param dev The Pwm context to use
* @return percentage A floating-point value representing percentage of output.
@@ -166,26 +166,6 @@ mraa_result_t mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner);
*/
mraa_result_t mraa_pwm_close(mraa_pwm_context dev);
/**
* Set Both Period and DutyCycle on a PWM context
*
* @param dev The pwm context to use
* @param period represented in ms.
* @param duty dutycycle of the pwm signal.
* @return Result of operation
*/
mraa_result_t mraa_pwm_config_ms(mraa_pwm_context dev, int period, float duty);
/**
* Set Both Period and DutyCycle on a PWM context. Duty represented as percentage.
*
* @param dev The pwm context to use
* @param period represented in ms.
* @param duty duty percantage. i.e. 50% = 0.5f
* @return Result of operation
*/
mraa_result_t mraa_pwm_config_percent(mraa_pwm_context dev, int period, float duty);
/**
* Get the maximum pwm period in us
*

View File

@@ -46,9 +46,9 @@ class Pwm
*
* @param pin the pin number used on your board
* @param owner if you are the owner of the pin the destructor will
* @param chipid the pwmchip to use, use only in raw mode
* unexport the pin from sysfs, default behaviour is you are the owner
* if the pinmapper exported it
* @param chipid the pwmchip to use, use only in raw mode
*/
Pwm(int pin, bool owner = true, int chipid = -1)
{
@@ -66,6 +66,20 @@ class Pwm
mraa_pwm_owner(m_pwm, 0);
}
}
/**
* Pwm constructor, takes a pointer to the PWM context and
* initialises the class
*
* @param void * to a PWM context
*/
Pwm(void* pwm_context)
{
m_pwm = (mraa_pwm_context) pwm_context;
if (m_pwm == NULL) {
throw std::invalid_argument("Invalid PWM context");
}
}
/**
* Pwm destructor
*/
@@ -77,7 +91,7 @@ class Pwm
* Set the output duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* output. The value should lie between 0.0f (representing 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
* @return Result of operation
@@ -88,10 +102,10 @@ class Pwm
return (Result) mraa_pwm_write(m_pwm, percentage);
}
/**
* Read the ouput duty-cycle percentage, as a float
* Read the output duty-cycle percentage, as a float
*
* @return A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* output. The value should lie between 0.0f (representing 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
*/
@@ -134,7 +148,7 @@ class Pwm
return (Result) mraa_pwm_period_us(m_pwm, us);
}
/**
* Set pulsewidth, As represnted by seconds in a (float)
* Set pulsewidth, as represented by seconds in a float
*
* @param seconds The duration of a pulse
* @return Result of operation
@@ -179,33 +193,9 @@ class Pwm
return (Result) mraa_pwm_enable(m_pwm, enable);
}
/**
* Set the period and duty of a PWM object.
* Get the maximum PWM period in us
*
* @param period represented in ms.
* @param duty represnted in ms as float.
* @return Result of operation
*/
Result
config_ms(int period, float duty)
{
return (Result) mraa_pwm_config_ms(m_pwm, period, duty);
}
/**
* Set the period and duty (percent) of a PWM object.
*
* @param period as represented in ms.
* @param duty percentage i.e. 50% = 0.5f
* @return Result of operation
*/
Result
config_percent(int period, float duty)
{
return (Result) mraa_pwm_config_percent(m_pwm, period, duty);
}
/**
* Get the maximum pwm period in us
*
* @return max pwm in us
* @return max PWM period in us
*/
int
max_period()
@@ -213,9 +203,9 @@ class Pwm
return mraa_pwm_get_max_period(m_pwm);
}
/**
* Get the minimum pwm period in us
* Get the minimum PWM period in us
*
* @return min pwm in us
* @return min PWM period in us
*/
int
min_period()

View File

@@ -111,13 +111,13 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
int mraa_spi_write(mraa_spi_context dev, uint8_t data);
/**
*Write Two Bytes to the SPI device.
* Write Two Bytes to the SPI device.
*
* @param dev The Spi context
* @param data Data to send
* @return Data received on the miso line
*/
uint16_t mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
int mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
/**
* Write Buffer of bytes to the SPI device. The pointer return has to be

View File

@@ -79,6 +79,20 @@ class Spi
}
}
/**
* Spi Constructor, takes a pointer to a SPI context and initialises
* the SPI class
*
* @param void * to SPI context
*/
Spi(void* spi_context)
{
m_spi = (mraa_spi_context) spi_context;
if (m_spi == NULL) {
throw std::invalid_argument("Invalid SPI context");
}
}
/**
* Closes spi bus
*/
@@ -127,10 +141,10 @@ class Spi
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line
* @return data received on the miso line or -1 in case of error
*/
uint16_t
write_word(uint16_t data)
int
writeWord(uint16_t data)
{
return mraa_spi_write_word(m_spi, (uint16_t) data);
}
@@ -161,7 +175,7 @@ class Spi
* @return uint8_t* data received on the miso line. Same length as passed in
*/
uint16_t*
write_word(uint16_t* txBuf, int length)
writeWord(uint16_t* txBuf, int length)
{
return mraa_spi_write_buf_word(m_spi, txBuf, length);
}

View File

@@ -206,7 +206,9 @@ typedef enum {
MRAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
MRAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
MRAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
MRAA_ERROR_PLATFORM_ALREADY_INITIALISED = 0, /**< Board is already initialised, same as MRAA_SUCESS */
MRAA_ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
MRAA_ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
MRAA_ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
MRAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} mraa_result_t;

View File

@@ -204,7 +204,9 @@ typedef enum {
ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
ERROR_PLATFORM_ALREADY_INITIALISED = 0, /**< Board is already initialised, same as SUCCESS */
ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} Result;

View File

@@ -75,6 +75,20 @@ class Uart
}
}
/**
* Uart Constructor, takes a pointer to the UART context and initialises
* the UART class
*
* @param void * to a UART context
*/
Uart(void* uart_context)
{
m_uart = (mraa_uart_context) uart_context;
if (m_uart == NULL) {
throw std::invalid_argument("Invalid UART context");
}
}
/**
* Uart destructor
*/

197
api/mraa/uart_ow.h Normal file
View File

@@ -0,0 +1,197 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
/**
* @file
* @brief UART OW module
*
* This module allows one to use MRAA's UART support in order to
* interact with Dallas 1-wire compliant devices on a 1-wire bus. It
* makes use of the UART for timing purposes. The principle of
* operation is described here:
* https://www.maximintegrated.com/en/app-notes/index.mvp/id/214
*
* It is important the you use a UART with CMOS/TTL level voltages
* (3.3v/5v) RX and TX lines. DO NOT use standard RS232 level
* voltages, or you are going to have a bad day.
*
* In addition, a diode should be placed across the RX and
* TX lines like so:
*
* -|
* U|
* A| TX---|<--+
* R| |
* T| RX-------o--------o 1-wire data bus
* -|
*
* The diode on TX is a 1N4148 (cheap and common), with the cathode
* connected to TX, and the anode connected to RX and the rest of the
* 1-wire data line.
*
* @snippet uart_ow.c Interesting
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "common.h"
#include "uart.h"
/* for now, we simply use the normal MRAA UART context */
typedef struct _mraa_uart_ow {
mraa_uart_context uart;
/* search state */
unsigned char ROM_NO[8]; /* 8 byte (64b) rom code */
int LastDiscrepancy;
int LastFamilyDiscrepancy;
mraa_boolean_t LastDeviceFlag;
} *mraa_uart_ow_context;
/* 8 bytes (64 bits) for a device rom code */
static const int MRAA_UART_OW_ROMCODE_SIZE = 8;
/**
* UART One Wire ROM related Command bytes
*/
typedef enum {
MRAA_UART_OW_CMD_READ_ROM = 0x33, /**< read rom, when only one device on bus */
MRAA_UART_OW_CMD_MATCH_ROM = 0x55, /**< match a specific rom code */
MRAA_UART_OW_CMD_SKIP_ROM = 0xcc, /**< skip match/search rom */
MRAA_UART_OW_CMD_SEARCH_ROM_ALARM = 0xec, /**< search all roms in alarm state */
MRAA_UART_OW_CMD_SEARCH_ROM = 0xf0 /**< search all rom codes */
} mraa_uart_ow_rom_cmd_t;
/**
* Initialise uart_ow_context, uses UART board mapping
*
* @param uart the index of the uart set to use
* @return uart_ow context or NULL
*/
mraa_uart_ow_context mraa_uart_ow_init(int uart);
/**
* Initialise a raw uart_ow_context. No board setup.
*
* @param path for example "/dev/ttyS0"
* @return uart_ow context or NULL
*/
mraa_uart_ow_context mraa_uart_ow_init_raw(const char* path);
/**
* Get char pointer with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @param dev uart_ow context
* @return char pointer of device path
*/
const char* mraa_uart_ow_get_dev_path(mraa_uart_ow_context dev);
/**
* Destroy a mraa_uart_ow_context
*
* @param dev uart_ow context
* @return mraa_result_t
*/
mraa_result_t mraa_uart_ow_stop(mraa_uart_ow_context dev);
/**
* Read a byte from the 1-wire bus
*
* @param dev uart_ow context
* @return the byte read or -1 for error
*/
int mraa_uart_ow_read_byte(mraa_uart_ow_context dev);
/**
* Write a byte to a 1-wire bus
*
* @param dev uart_ow context
* @param byte the byte to write to the bus
* @return the byte read back during the time slot or -1 for error
*/
int mraa_uart_ow_write_byte(mraa_uart_ow_context dev, uint8_t byte);
/**
* Write a bit to a 1-wire bus and read a bit corresponding to the
* time slot back. This is possible due to the way we wired the TX
* and RX together with a diode, forming a loopback.
*
* @param dev uart_ow context
* @param bit the bit to write to the bus
* @return the bit read back during the time slot or -1 for error
*/
int mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t bit);
/**
* Send a reset pulse to the 1-wire bus and test for device presence
*
* @param dev uart_ow context
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_reset(mraa_uart_ow_context dev);
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the uart_ow.c example
* for an idea on how to use this function to identify all devices
* present on the bus.
*
* @param dev uart_ow context
* @param start true to start a new search from scratch, false to
* continue an existing search
* @param id the 8-byte rom code id of the current matched device when
* a device is found
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_rom_search(mraa_uart_ow_context dev, mraa_boolean_t start, uint8_t* id);
/**
* Send a command byte to a device on the 1-wire bus
*
* @param dev uart_ow context
* @param command the command byte to send
* @param id the rom code id of the device to receive the command,
* NULL for all devices on the bus
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_command(mraa_uart_ow_context dev, uint8_t command, uint8_t* id);
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
*
* @param buffer the buffer containing the data
* @param length the length of the buffer
* @return the computed CRC
*/
uint8_t mraa_uart_ow_crc8(uint8_t* buffer, uint16_t length);
#ifdef __cplusplus
}
#endif

277
api/mraa/uart_ow.hpp Normal file
View File

@@ -0,0 +1,277 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "uart_ow.h"
#include "types.hpp"
#include <stdexcept>
#include <cstring>
namespace mraa
{
/**
* @brief API for UART One Wire
*
* This file defines the UartOW (UART to Dallas 1-wire) interface for libmraa
*
* @snippet UartOW.cpp Interesting
*/
class UartOW
{
public:
/**
* UartOW Constructor, takes a pin number which will map directly to the
* linux uart number, this 'enables' the uart, nothing more
*
* @throws std::invalid_argument in case of error
* @param uart the index of the uart to use
*/
UartOW(int uart)
{
m_uart = mraa_uart_ow_init(uart);
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART_OW");
}
}
/**
* UartOW Constructor, takes a string to the path of the serial
* interface that is needed.
*
* @throws std::invalid_argument in case of error
* @param path the file path for the UART to use
*/
UartOW(std::string path)
{
m_uart = mraa_uart_ow_init_raw(path.c_str());
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART");
}
}
/**
* Uart destructor
*/
~UartOW()
{
mraa_uart_ow_stop(m_uart);
}
/**
* Get string with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @return char pointer of device path
*/
std::string
getDevicePath()
{
std::string ret_val(mraa_uart_ow_get_dev_path(m_uart));
return ret_val;
}
/**
* Read a byte from the 1-wire bus
*
* @throws std::invalid_argument in case of error
* @return the byte read
*/
uint8_t
readByte()
{
int res = mraa_uart_ow_read_byte(m_uart);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return (uint8_t) res;
}
/**
* Write a byte to a 1-wire bus
*
* @param byte the byte to write to the bus
*
* @throws std::invalid_argument in case of error
* @return the byte read back during the time slot
*/
uint8_t
writeByte(uint8_t byte)
{
int res = mraa_uart_ow_write_byte(m_uart, byte);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return (uint8_t) res;
}
/**
* Write a bit to a 1-wire bus and read a bit corresponding to the
* time slot back. This is possible due to the way we wired the TX
* and RX together with a diode, forming a loopback.
*
* @param bit the bit to write to the bus
* @throws std::invalid_argument in case of error
* @return the bit read back during the time slot
*/
bool
writeBit(bool bit)
{
int res = mraa_uart_ow_bit(m_uart, (bit) ? 1 : 0);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return ((res) ? true : false);
}
/**
* Send a reset pulse to the 1-wire bus and test for device presence
*
* @return one of the mraa::Result values
*/
mraa::Result
reset()
{
return (mraa::Result) mraa_uart_ow_reset(m_uart);
}
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the uart_ow.c example
* for an idea on how to use this function to identify all devices
* present on the bus.
*
* @param start true to start a search from scratch, false to
* continue a previously started search
* @param id the 8-byte rom code id of the current matched device when a
* device is found
* @return one of the mraa::Result values
*/
mraa::Result
search(bool start, uint8_t* id)
{
return (mraa::Result) mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
}
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the UartOW.cpp
* example for an idea on how to use this function to identify all
* devices present on the bus.
*
* @param start true to start a search from scratch, false to
* continue a previously started search
* @return an empty string if no [more] devices are found, or a
* string containing the 8-byte romcode of a detected device.
*/
std::string
search(bool start)
{
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
mraa_result_t rv;
rv = mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
if (rv == MRAA_SUCCESS) {
// we found one
std::string idStr((char*) id, MRAA_UART_OW_ROMCODE_SIZE);
return idStr;
} else {
// failure, or end of search
return "";
}
}
/**
* Send a command byte to a device on the 1-wire bus
*
* @param command the command byte to send
* @param id the rom code id of the device to receive the command,
* NULL for all devices on the bus
* @return one of the mraa::Result values
*/
mraa::Result
command(uint8_t command, uint8_t* id)
{
return (mraa::Result) mraa_uart_ow_command(m_uart, command, id);
}
/**
* Send a command byte to a device on the 1-wire bus, supplying
* the id as a std::string
*
* @param command the command byte to send
* @param id std::string representing the code id of the device to
* receive the command, or an empty string for all devices on the
* bus. This string should be 8 bytes in size.
* @return one of the mraa::Result values
*/
mraa::Result
command(uint8_t command, std::string id)
{
if (id.empty() == 0)
return (mraa::Result) mraa_uart_ow_command(m_uart, command, NULL);
else {
if (id.size() != 8) {
// Only 8 byte romcodes are legal.
throw std::invalid_argument(std::string(__FUNCTION__) +
": id must be 8 bytes only");
}
return (mraa::Result) mraa_uart_ow_command(m_uart, command, (uint8_t*) id.c_str());
}
}
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
*
* @param buffer the buffer containing the data
* @param length the length of the buffer
* @return the computed CRC
*/
uint8_t
crc8(uint8_t* buffer, uint16_t length)
{
return mraa_uart_ow_crc8(buffer, length);
}
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a
* std::string based buffer
*
* @param buffer std::string buffer containing the data
* @return the computed CRC
*/
uint8_t
crc8(std::string buffer)
{
return mraa_uart_ow_crc8((uint8_t*) buffer.c_str(), buffer.size());
}
private:
mraa_uart_ow_context m_uart;
};
}

View File

@@ -0,0 +1,158 @@
# Find specified Python version
# Arguments:
# preferred_version (value): Version to check for first
# min_version (value): Minimum supported version
# library_env (value): Name of Python library ENV variable to check
# include_dir_env (value): Name of Python include directory ENV variable to check
# found (variable): Set if interpreter found
# executable (variable): Output of executable found
# version_string (variable): Output of found version
# version_major (variable): Output of found major version
# version_minor (variable): Output of found minor version
# libs_found (variable): Set if libs found
# libs_version_string (variable): Output of found libs version
# libraries (variable): Output of found Python libraries
# library (variable): Output of found Python library
# debug_libraries (variable): Output of found Python debug libraries
# debug_library (variable): Output of found Python debug library
# include_path (variable): Output of found Python include path
# include_dir (variable): Output of found Python include dir
# include_dir2 (variable): Output of found Python include dir2
# packages_path (variable): Output of found Python packages path
function(find_python preferred_version min_version library_env include_dir_env
found executable version_string version_major version_minor
libs_found libs_version_string libraries library debug_libraries
debug_library include_path include_dir include_dir2 packages_path)
if(NOT ${found})
if(${executable})
set(PYTHON_EXECUTABLE "${${executable}}")
endif()
find_package(PythonInterp "${preferred_version}")
if(NOT PYTHONINTERP_FOUND)
find_package(PythonInterp "${min_version}")
endif()
if(PYTHONINTERP_FOUND)
# Copy outputs
set(_found ${PYTHONINTERP_FOUND})
set(_executable ${PYTHON_EXECUTABLE})
set(_version_string ${PYTHON_VERSION_STRING})
set(_version_major ${PYTHON_VERSION_MAJOR})
set(_version_minor ${PYTHON_VERSION_MINOR})
set(_version_patch ${PYTHON_VERSION_PATCH})
# Clear find_host_package side effects
unset(PYTHONINTERP_FOUND)
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON_VERSION_STRING)
unset(PYTHON_VERSION_MAJOR)
unset(PYTHON_VERSION_MINOR)
unset(PYTHON_VERSION_PATCH)
endif()
if(_found)
set(_version_major_minor "${_version_major}.${_version_minor}")
if(NOT ANDROID AND NOT APPLE_FRAMEWORK)
# not using _version_string here, because it might not conform to the CMake version format
if(CMAKE_CROSSCOMPILING)
# builder version can differ from target, matching base version (e.g. 2.7)
find_package(PythonLibs "${_version_major_minor}")
else()
find_package(PythonLibs "${_version_major_minor}.${_version_patch}" EXACT)
endif()
if(PYTHONLIBS_FOUND)
# Copy outputs
set(_libs_found ${PYTHONLIBS_FOUND})
set(_libraries ${PYTHON_LIBRARIES})
set(_include_path ${PYTHON_INCLUDE_PATH})
set(_include_dirs ${PYTHON_INCLUDE_DIRS})
set(_debug_libraries ${PYTHON_DEBUG_LIBRARIES})
set(_libs_version_string ${PYTHONLIBS_VERSION_STRING})
set(_debug_library ${PYTHON_DEBUG_LIBRARY})
set(_library ${PYTHON_LIBRARY})
set(_library_debug ${PYTHON_LIBRARY_DEBUG})
set(_library_release ${PYTHON_LIBRARY_RELEASE})
set(_include_dir ${PYTHON_INCLUDE_DIR})
set(_include_dir2 ${PYTHON_INCLUDE_DIR2})
# Clear find_package side effects
unset(PYTHONLIBS_FOUND)
unset(PYTHON_LIBRARIES)
unset(PYTHON_INCLUDE_PATH)
unset(PYTHON_INCLUDE_DIRS)
unset(PYTHON_DEBUG_LIBRARIES)
unset(PYTHONLIBS_VERSION_STRING)
unset(PYTHON_DEBUG_LIBRARY CACHE)
unset(PYTHON_LIBRARY)
unset(PYTHON_LIBRARY_DEBUG)
unset(PYTHON_LIBRARY_RELEASE)
unset(PYTHON_LIBRARY CACHE)
unset(PYTHON_LIBRARY_DEBUG CACHE)
unset(PYTHON_LIBRARY_RELEASE CACHE)
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_INCLUDE_DIR2 CACHE)
endif()
endif()
execute_process(COMMAND ${_executable} -c "from distutils.sysconfig import *; print(get_python_lib())"
RESULT_VARIABLE _cvpy_process
OUTPUT_VARIABLE _std_packages_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${_std_packages_path}" MATCHES "site-packages")
set(_packages_path "python${_version_major_minor}/site-packages")
else() #debian based assumed, install to the dist-packages.
set(_packages_path "python${_version_major_minor}/dist-packages")
endif()
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${${packages_path}}")
set(_packages_path "lib${LIB_SUFFIX}/${_packages_path}")
else()
set(_packages_path "lib/${_packages_path}")
endif()
endif()
# Export return values
set(${found} "${_found}" CACHE INTERNAL "")
set(${executable} "${_executable}" CACHE FILEPATH "Path to Python interpretor")
set(${version_string} "${_version_string}" CACHE INTERNAL "")
set(${version_major} "${_version_major}" CACHE INTERNAL "")
set(${version_minor} "${_version_minor}" CACHE INTERNAL "")
set(${libs_found} "${_libs_found}" CACHE INTERNAL "")
set(${libs_version_string} "${_libs_version_string}" CACHE INTERNAL "")
set(${libraries} "${_libraries}" CACHE INTERNAL "Python libraries")
set(${library} "${_library}" CACHE FILEPATH "Path to Python library")
set(${debug_libraries} "${_debug_libraries}" CACHE INTERNAL "")
set(${debug_library} "${_debug_library}" CACHE FILEPATH "Path to Python debug")
set(${include_path} "${_include_path}" CACHE INTERNAL "")
set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
endif()
endfunction(find_python)
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
if(PYTHON_DEFAULT_EXECUTABLE)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
endif()

View File

@@ -75,6 +75,8 @@ style numbers.
There is also a second 8-pin connector on the Banana Pi, the pins are as follows:
| MRAA Number | Physical Pin | Function |
|-------------|--------------|-----------|
| 27 | P1-19 | 5V VCC |
| 28 | P1-20 | 3V3 VCC |
| 29 | P1-21 | GPIO(PH5) |

View File

@@ -92,10 +92,6 @@ Building doc, this will require [SPHINX](http://sphinx-doc.org) &
[Doxygen](http://doxygen.org):
`-DBUILDDOC=ON`
Building with Python 3 (careful you need to clear CMake cache between Python
version switches!)
`-DBUILDPYTHON3=ON`
Override build architecture (this is useful because on x86 ARM code is not
compiled so use this flag to force the target arch)
`-DBUILDARCH=arm`
@@ -172,7 +168,7 @@ You can get `cpack` to generate an IPK or RPM package fairly easily if you have
the correct packaging tools
~~~~~~~~~~~~~{.sh}
cmake -DIPK=ON -DCMAKE_INSTAL_PREFIX=/usr ..
cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make package
~~~~~~~~~~~~~
@@ -180,5 +176,5 @@ To use RPM simply enable the RPM option. You'll need `rpmbuild` installed on you
build machine.
~~~~~~~~~~~~~{.sh}
cmake -DRPM=ON -DCMAKE_INSTAL_PREFIX=/usr ..
cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
~~~~~~~~~~~~~

View File

@@ -5,6 +5,21 @@ This changelog is meant as a quick & rough guide to what has changed between
versions. The API is now fairly stable but when new calls/features are added
they are listed here. Anything pre 0.2.x is ignored.
**1.0.0**
* Change API to enhance error checking in C. Changes include:
- mraa_aio_read
- mraa_i2c_read_byte
- mraa_i2c_read
- mraa_i2c_read_byte_data
- mraa_i2c_read_word_data
- mraa_spi_write_word
- mraa::Spi:write_word becomes mraa::Spi::writeWord
* Remove MRAA_ERROR_PLATFORM_ALREADY_INITIALISED which was deprecated for C89 compatibility
* Remove pwm config_* apis as unused
* Add mraa_remove_subplatform
* Support NPM for android
* Fix AIO always returning channel 0 with firmata support
**0.10.1**
* Remove imraa from node package
@@ -35,7 +50,7 @@ they are listed here. Anything pre 0.2.x is ignored.
**0.9.3**
* Intel edison detection much improved
* ftdi ft4222 interupt improvement
* ftdi ft4222 interrupt improvement
* small fixes to java lib
**0.9.2**

View File

@@ -8,7 +8,7 @@ The rev D board has the following limitations in libmraa:
- gpio 13 will not switch the LED as it's a different Gpio, use raw gpio '3' to do this
- gpio register access via /dev/uio is limited to pin2 and 3
- gpio interupts will only work on GPIO_EDGE_BOTH
- gpio interrupts will only work on GPIO_EDGE_BOTH
- adc kernel module will return 12bit number. MRAA defaults shift this to 10bits
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio

View File

@@ -35,6 +35,11 @@ target_link_libraries (mraa-i2c mraa)
target_link_libraries (spi_max7219 mraa)
target_link_libraries (iio_driver mraa)
if (ONEWIRE)
add_executable (uart_ow uart_ow.c)
target_link_libraries (uart_ow mraa)
endif ()
if (FIRMATA)
add_executable (firmata_curie_imu firmata_curie_imu.c)
add_executable (i2c_firmata i2c_firmata.c)

View File

@@ -19,3 +19,8 @@ target_link_libraries (Spi-pot mraa stdc++)
target_link_libraries (Uart mraa stdc++)
target_link_libraries (Isr-pin6 mraa stdc++)
target_link_libraries (Iio-dummy mraa stdc++)
if (ONEWIRE)
add_executable (UartOW UartOW.cpp)
target_link_libraries (UartOW mraa stdc++)
endif ()

82
examples/c++/UartOW.cpp Normal file
View File

@@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "stdio.h"
#include "iostream"
//! [Interesting]
#include "uart_ow.hpp"
using namespace std;
int
main(int argc, char** argv)
{
mraa::UartOW* uart = new mraa::UartOW(0);
// Reset the ow bus and see if anything is present
mraa::Result rv;
if ((rv = uart->reset()) == mraa::SUCCESS) {
cout << "Reset succeeded, device(s) detected!" << endl;
} else {
cout << "Reset failed, returned " << int(rv) << ". No devices on bus?" << endl;
return 1;
}
cout << "Looking for devices..." << endl;
;
uint8_t count = 0;
// start the search from scratch
string id = uart->search(true);
if (id.empty()) {
cout << "No devices detected." << endl;
return 1;
}
while (!id.empty()) {
// hack so we don't need to cast each element of the romcode
// for printf purposes
uint8_t* ptr = (uint8_t*) id.c_str();
// The first byte (0) is the device type (family) code.
// The last byte (7) is the rom code CRC value. The
// intervening bytes are the unique 48 bit device ID.
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, ptr[0],
ptr[6], ptr[5], ptr[4], ptr[3], ptr[2], ptr[1], ptr[7]);
count++;
// continue the search with start argument set to false
id = uart->search(false);
}
cout << "Exiting..." << endl;
delete uart;
return 0;
}
//! [Interesting]

View File

@@ -50,7 +50,7 @@ public class BlinkIO {
if (argv.length == 0) {
System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN);
} else {
iopin = Integer.valueOf(argv[0], DEFAULT_IOPIN);
iopin = Integer.valueOf(argv[0]);
}
//! [Interesting]

View File

@@ -8,3 +8,9 @@ function h() {
x = new m.Gpio(14)
x.isr(m.EDGE_BOTH, h)
setInterval(function() {
// It's important to refer to our GPIO context here,
// otherwise it will be garbage-collected
console.log("Waiting for an interrupt at GPIO pin " + x.getPin() + "...")
}, 10000)

View File

@@ -31,7 +31,7 @@ class Counter:
c = Counter()
# inside a python interupt you cannot use 'basic' types so you'll need to use
# inside a python interrupt you cannot use 'basic' types so you'll need to use
# objects
def test(gpio):
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))

92
examples/uart_ow.c Normal file
View File

@@ -0,0 +1,92 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "stdio.h"
//! [Interesting]
#include "mraa.h"
int
main(int argc, char** argv)
{
mraa_uart_ow_context uart;
uart = mraa_uart_ow_init(0);
if (!uart) {
printf("mraa_uart_ow_init() failed\n");
return 1;
}
// Reset the ow bus and see if anything is present
mraa_result_t rv;
if ((rv = mraa_uart_ow_reset(uart)) == MRAA_SUCCESS) {
printf("Reset succeeded, device(s) detected!\n");
} else {
printf("Reset failed, returned %d. No devices on bus?\n", rv);
return 1;
}
printf("Looking for devices...\n");
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
/* we are essentially doing a binary tree search through the 64
* bit address space. id is modified during this search, and will
* be set to the valid rom code for each device found.
*/
uint8_t count = 0;
// start the search from scratch
mraa_result_t result = mraa_uart_ow_rom_search(uart, 1, id);
if (result == MRAA_ERROR_UART_OW_NO_DEVICES) {
printf("No devices detected.\n");
return 1;
}
if (result == MRAA_ERROR_UART_OW_DATA_ERROR) {
printf("Bus/Data error.\n");
return 1;
}
while (result == MRAA_SUCCESS) {
/* The first byte (id[0]]) is the device type (family) code.
* The last byte (id[7]) is the rom code CRC value. The
* intervening bytes (id[1]-id[6]) are the unique 48 bit
* device ID.
*/
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, id[0],
id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
count++;
// continue the search with start argument set to 0
result = mraa_uart_ow_rom_search(uart, 0, id);
}
printf("Exiting...\n");
mraa_uart_ow_stop(uart);
return 0;
}
//! [Interesting]

View File

@@ -64,9 +64,9 @@ typedef struct {
mraa_result_t (*i2c_set_frequency_replace) (mraa_i2c_context dev, mraa_i2c_mode_t mode);
mraa_result_t (*i2c_address_replace) (mraa_i2c_context dev, uint8_t addr);
int (*i2c_read_replace) (mraa_i2c_context dev, uint8_t* data, int length);
uint8_t (*i2c_read_byte_replace) (mraa_i2c_context dev);
uint8_t (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
uint16_t (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_byte_replace) (mraa_i2c_context dev);
int (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_bytes_data_replace) (mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
mraa_result_t (*i2c_write_replace) (mraa_i2c_context dev, const uint8_t* data, int length);
mraa_result_t (*i2c_write_byte_replace) (mraa_i2c_context dev, uint8_t data);
@@ -75,7 +75,7 @@ typedef struct {
mraa_result_t (*i2c_stop_replace) (mraa_i2c_context dev);
mraa_result_t (*aio_init_internal_replace) (mraa_aio_context dev, int pin);
mraa_result_t (*aio_read_replace) (mraa_aio_context dev);
int (*aio_read_replace) (mraa_aio_context dev);
mraa_result_t (*aio_get_valid_fp) (mraa_aio_context dev);
mraa_result_t (*aio_init_pre) (unsigned int aio);
mraa_result_t (*aio_init_post) (mraa_aio_context dev);

View File

@@ -59,8 +59,8 @@ struct _gpio {
int pin; /**< the pin number, as known to the os. */
int phy_pin; /**< pin passed to clean init. -1 none and raw*/
int value_fp; /**< the file pointer to the value of the gpio */
void (* isr)(void *); /**< the interupt service request */
void *isr_args; /**< args return when interupt service request triggered */
void (* isr)(void *); /**< the interrupt service request */
void *isr_args; /**< args return when interrupt service request triggered */
pthread_t thread_id; /**< the isr handler thread id */
int isr_value_fp; /**< the isr file pointer on the value */
#ifndef HAVE_PTHREAD_CANCEL
@@ -148,9 +148,9 @@ struct _iio {
char* name; /**< IIO device name */
int fp; /**< IIO device in /dev */
int fp_event; /**< event file descriptor for IIO device */
void (* isr)(char* data); /**< the interupt service request */
void *isr_args; /**< args return when interupt service request triggered */
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interupt service request */
void (* isr)(char* data); /**< the interrupt service request */
void *isr_args; /**< args return when interrupt service request triggered */
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interrupt service request */
int chan_num;
pthread_t thread_id; /**< the isr handler thread id */
mraa_iio_channel* channels;
@@ -253,9 +253,9 @@ typedef struct {
*/
typedef struct {
/*@{*/
unsigned int bus_id; /**< ID as exposed in the system */
unsigned int scl; /**< i2c SCL */
unsigned int sda; /**< i2c SDA */
int bus_id; /**< ID as exposed in the system */
int scl; /**< i2c SCL */
int sda; /**< i2c SDA */
// mraa_drv_api_t drv_type; /**< Driver type */
/*@}*/
} mraa_i2c_bus_t;
@@ -268,10 +268,10 @@ typedef struct {
unsigned int bus_id; /**< The Bus ID as exposed to the system. */
unsigned int slave_s; /**< Slave select */
mraa_boolean_t three_wire; /**< Is the bus only a three wire system */
unsigned int sclk; /**< Serial Clock */
unsigned int mosi; /**< Master Out, Slave In. */
unsigned int miso; /**< Master In, Slave Out. */
unsigned int cs; /**< Chip Select, used when the board is a spi slave */
int sclk; /**< Serial Clock */
int mosi; /**< Master Out, Slave In. */
int miso; /**< Master In, Slave Out. */
int cs; /**< Chip Select, used when the board is a spi slave */
/*@}*/
} mraa_spi_bus_t;
@@ -293,19 +293,19 @@ typedef struct {
typedef struct _board_t {
/*@{*/
unsigned int phy_pin_count; /**< The Total IO pins on board */
int phy_pin_count; /**< The Total IO pins on board */
unsigned int gpio_count; /**< GPIO Count */
unsigned int aio_count; /**< Analog side Count */
unsigned int i2c_bus_count; /**< Usable i2c Count */
int i2c_bus_count; /**< Usable i2c Count */
mraa_i2c_bus_t i2c_bus[12]; /**< Array of i2c */
unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
unsigned int spi_bus_count; /**< Usable spi Count */
int spi_bus_count; /**< Usable spi Count */
mraa_spi_bus_t spi_bus[12]; /**< Array of spi */
unsigned int def_spi_bus; /**< Position in array of defult spi bus */
unsigned int adc_raw; /**< ADC raw bit value */
unsigned int adc_supported; /**< ADC supported bit value */
unsigned int def_uart_dev; /**< Position in array of defult uart */
unsigned int uart_dev_count; /**< Usable spi Count */
int uart_dev_count; /**< Usable spi Count */
mraa_uart_dev_t uart_dev[6]; /**< Array of UARTs */
mraa_boolean_t no_bus_mux; /**< i2c/spi/adc/pwm/uart bus muxing setup not required */
int pwm_default_period; /**< The default PWM period is US */

17
jsstub/Gruntfile.js Normal file
View File

@@ -0,0 +1,17 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['test/*.js']
}
}
});
grunt.registerTask('test', ['mochaTest:test']);
};

52
jsstub/README.md Normal file
View File

@@ -0,0 +1,52 @@
mraaStub - JavaScript simulation and stubs for mraa
====================
This project enables simulation of a device which might be accessed via mraa.
Currently this library supports I2c, SPI, and GPIO. This project provides
several benefits:
1. Prevent crashes in nodejs applications using mraa on unsuported or
misconfigured hardware.
2. Enable basic simulation of mraa-accessible devices for unit testing.
## Examples
The following example is based on an imaginary 'light bulb' device abstraction,
which exposes a value of brightness over a mraa-provided interface. Please see
the `test/index.js` file for an example.
## Installation
mraaStub is not yet in npm so has to be installed from git. In the future
you'll be able to install `mraaStub` from npm like this:
```
npm install mraaStub
```
Since we often switch between a mraaStub and the real mraa library, we
suggest creating an `index.js` file inside a `lib/mraaSwitcher` folder.
```js
/* index.js - file for switching between mraa and mraaStub
*/
// Define the conditions under which the mraaStub should be loaded
var platform = require('os').platform();
var m;
if (platform === 'win32') {
m = require('mraaStub');
} else {
m = require('mraa');
}
module.exports = m;
```
You can add this to your project in its own `lib/mraaSwitcher/index.js` file
and use `require('../mraaSwitcher')` everywhere!
## License
See [COPYING file](../COPYING) in the root of this repository.

223
jsstub/index.js Normal file
View File

@@ -0,0 +1,223 @@
/**
* @fileoverview This file implements a fake mraa stub which enables testing
* as well as the ability to run on Windows.
*/
var m;
var winston = require('winston');
var logger = new winston.Logger({
transports: [
new winston.transports.Console({
level: 'error',
handleExceptions: false,
json: false,
colorize: true})
],
exitOnError: false
});
/**
* @class mraaStub
* @classdesc This class is designed to stub out libmraa so we can run
* test code on unsupported platforms (specifically Windows).
*/
var mraaStub = function() {
var verison = '0.0.1';
var self = this;
self.EDGE_BOTH = 1;
self.EDGE_NONE = 2;
self.EDGE_RISING = 3;
self.EDGE_FALLING = 4;
self.DIR_IN = 1;
self.DIR_OUT = 2;
self.getVersion = function() {
return "mraaStub " + version;
};
// Stub out GPIO
function Gpio(num) {
this.num = num;
this._callback = null;
this._dir = null;
this._isr_mode = self.EDGE_NONE;
}
var logGpio = false;
Gpio.prototype._callIsr = function() {
if(this.isr_mode === self.EDGE_NONE) {
logger.log('info',"Could not call ISR. Not set up for triggering");
}
this._callback();
};
Gpio.prototype.isr = function(mode, handler){
if(logGpio) {
logger.log('info',"GPIO " + this.num + " isr stub invoked.");
}
this._isr_mode = self.EDGE_NONE;
this._callback = handler;
};
Gpio.prototype.dir = function(d) {
if(logGpio) {
logger.log('info',"GPIO " + this.num + " dir stub invoked.");
}
this._dir = d;
};
Gpio.prototype.write = function(z) {
if(logGpio) {
logger.log('logger',"GPIO " + this.num + " write stub invoked.");
}
if(this._dir !== self.DIR_OUT) {
logger.log('info',"GPIO " + this.num + " write called without DIR_OUT set.");
}
};
Gpio.prototype.read = function() {
if(logGpio) {
logger.log('info',"GPIO " + this.num + " read stub invoked.");
}
return 0;
};
// Stub out SPI
function Spi(num) {
var self = this;
this.num = num;
this._buffer = new Buffer(29);
this._buffer.fill(0);
this._loopback = false;
}
Spi.prototype._setOutput = function(buf) {
this._buffer = buf;
};
Spi.prototype._enableLoopback = function(x) {
if(x === true) {
this._loopback = true;
} else {
this._loopback = false;
}
};
Spi.prototype.write = function(b) {
logger.log('info',"SPI write stub invoked.");
if(this._loopback === true) {
return b;
}
return new Buffer(this._buffer);
};
Spi.prototype.frequency = function(f) {
logger.log('info',"SPI frequency stub invoked.");
return f;
};
Spi.prototype.lsbmode = function(t) {
logger.log('info',"SPI lsbmode stub invoked.");
};
Spi.prototype.mode = function(x) {
logger.log('info',"SPI mode stub invoked.");
};
function I2c(num) {
this._num = num;
this._regMapInitialized = false;
}
/* This function sets an internal register map for the I2c device.
*/
I2c.prototype._setRegisterMapInternal = function(buffer) {
this._regMapInitialized = true;
this._buffer = buffer;
};
I2c.prototype.frequency = function(freq) {
// Do nothing. We don't care.
};
I2c.prototype.address = function(address) {
var self = this;
self.address = address;
};
I2c.prototype.readReg = function(regAddr) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.readUInt8(regAddr);
};
I2c.prototype.readWordReg = function(regAddr) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.readUInt16LE(regAddr);
};
I2c.prototype.readBytesReg = function(regAddr, len) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.slice(regAddr,regAddr+len);
};
I2c.prototype.write = function(buf) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
var regAddr = buf[0];
var newBuf = buf.slice(1);
newBuf.copy(this._buffer, regAddr);
};
I2c.prototype.writeReg = function(regAddr, data) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
this._buffer.writeUInt8(regAddr,data);
};
I2c.prototype.writeWordReg = function(regAddr, dataWord) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
this._buffer.writeUInt16LE(regAddr,data);
};
// Export our stubs
self.Gpio = Gpio;
self.Spi = Spi;
self.I2c = I2c;
};
m = new mraaStub();
module.exports = m;

34
jsstub/package.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "mraaStub",
"version": "0.0.1",
"description": "Enables simulation of mraa interfaces for testing purposes",
"main": "index.js",
"scripts": {
"test": "grunt test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intel-iot-devkit/mraa.git"
},
"keywords": [
"mraa",
"iot",
"intel",
"libmraa",
"test",
"galileo",
"edison"
],
"author": "David A Antler <david.a.antler@intel.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/intel-iot-devkit/mraa/issues"
},
"homepage": "https://github.com/intel-iot-devkit/mraa#readme",
"devDependencies": {
"expect.js": "^0.3.1",
"grunt": "^1.0.1",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.4.5"
}
}

32
jsstub/test/index.js Normal file
View File

@@ -0,0 +1,32 @@
var expect = require('expect.js');
var m = require('../index');
var LightBulb = require('./lightbulb');
describe('LightBulb', function() {
/** Model the internal data of LightBulb as a buffer */
var bufferFullBrightness = new Buffer(
[ 'N', // Four bytes allocated for name
'a',
'm',
'e',
95 // One byte allocated for brightness. Stuff in '95' value!
]);
it('getBrightness() function should return 95', function() {
// Create a fake I2c bus based on the 'full brightness' data model
var testI2cBus = new m.I2c(0);
testI2cBus._setRegisterMapInternal(bufferFullBrightness);
// Create a new LightBulb that opens the testI2cBus, instead of a real
// mraa I2c bus.
var lightBulbI2c = new LightBulb(testI2cBus);
// presumably getBrightness will gather data from I2C and get '95'
var brightness = lightBulbI2c.getBrightness();
expect(brightness).to.be(95);
})
});

32
jsstub/test/lightbulb.js Normal file
View File

@@ -0,0 +1,32 @@
/**
* @fileoverview Implementation of a LightBulb class abstraction
*
*/
module.exports = (function() {
"use strict";
var m = require('../index');
/**
* Constructor for a new LightBulb
* @class LightBulb
*
* @classdesc This class abstracts access to the control and data registers
* on an imaginary lightbulb.
* @param {Object} A libmraa I2c object, initialized
*/
function LightBulb (i2cInterface) {
var self = this;
self._i2cInterface = i2cInterface;
self.getBrightness = function() {
// Presume our brightness data is one byte at offset 4
return self._i2cInterface.readReg(4);
}
return self;
}
return LightBulb;
})();

View File

@@ -9,6 +9,11 @@ if (FIRMATA)
add_subdirectory (firmata)
endif ()
if (ONEWIRE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DONEWIRE=1")
add_subdirectory (uart_ow)
endif ()
include_directories(
${mraa_LIB_INCLUDE_DIRS}
)
@@ -137,7 +142,7 @@ macro (mraa_CREATE_INSTALL_PKGCONFIG generated_file install_location)
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
endmacro (mraa_CREATE_INSTALL_PKGCONFIG)
mraa_create_install_pkgconfig (mraa.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
mraa_create_install_pkgconfig (mraa.pc ${LIB_INSTALL_DIR}/pkgconfig)
if (DOXYGEN_FOUND)
@@ -188,6 +193,8 @@ if (BUILDSWIG)
add_subdirectory (python)
endif ()
if (BUILDSWIGJAVA)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
add_subdirectory (java)
endif ()
if (BUILDSWIGNODE)
@@ -208,4 +215,4 @@ set_target_properties(
SOVERSION ${mraa_VERSION_MAJOR}
VERSION ${mraa_VERSION_STRING}
)
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS mraa DESTINATION ${LIB_INSTALL_DIR})

View File

@@ -56,7 +56,7 @@ aio_get_valid_fp(mraa_aio_context dev)
}
static mraa_aio_context
mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio)
mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio, unsigned int channel)
{
mraa_aio_context dev = calloc(1, sizeof(struct _aio));
if (dev == NULL) {
@@ -72,6 +72,8 @@ mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio)
return NULL;
}
dev->channel = channel;
// Open valid analog input file and get the pointer.
if (MRAA_SUCCESS != aio_get_valid_fp(dev)) {
free(dev);
@@ -123,12 +125,11 @@ mraa_aio_init(unsigned int aio)
}
// Create ADC device connected to specified channel
mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio);
mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio, board->pins[pin].aio.pinmap);
if (dev == NULL) {
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel %d", aio);
return NULL;
}
dev->channel = board->pins[pin].aio.pinmap;
dev->value_bit = DEFAULT_BITS;
if (IS_FUNC_DEFINED(dev, aio_init_pre)) {
@@ -152,7 +153,7 @@ mraa_aio_init(unsigned int aio)
return dev;
}
unsigned int
int
mraa_aio_read(mraa_aio_context dev)
{
if (IS_FUNC_DEFINED(dev, aio_read_replace)) {
@@ -165,7 +166,7 @@ mraa_aio_read(mraa_aio_context dev)
if (dev->adc_in_fp == -1) {
if (aio_get_valid_fp(dev) != MRAA_SUCCESS) {
syslog(LOG_ERR, "aio: Failed to get to the device");
return 0;
return -1;
}
}
@@ -182,8 +183,10 @@ mraa_aio_read(mraa_aio_context dev)
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
if (end == &buffer[0]) {
syslog(LOG_ERR, "aio: Value is not a decimal number");
return -1;
} else if (errno != 0) {
syslog(LOG_ERR, "aio: Errno was set");
return -1;
}
if (dev->value_bit != raw_bits) {
@@ -205,7 +208,7 @@ mraa_aio_read_float(mraa_aio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "aio: Device not valid");
return 0.0;
return -1.0;
}
float max_analog_value = (1 << dev->value_bit) - 1;

View File

@@ -64,7 +64,6 @@ static unsigned int mmap_count = 0;
mraa_result_t
mraa_beaglebone_mmap_write(mraa_gpio_context dev, int value)
{
volatile uint32_t* addr;
if (value) {
*(volatile uint32_t*) (mmap_gpio[dev->pin / 32] + AM335X_SET) = (uint32_t)(1 << (dev->pin % 32));
} else {
@@ -185,7 +184,6 @@ mraa_beaglebone_uart_init_pre(int index)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
sprintf(devpath, "/dev/ttyO%u", index + 1);
if (!mraa_file_exist(devpath)) {
@@ -218,7 +216,6 @@ mraa_beaglebone_spi_init_pre(int index)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
int deviceindex = 0;
@@ -273,10 +270,10 @@ mraa_beaglebone_i2c_init_pre(unsigned int bus)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
sprintf(devpath, "/dev/i2c-%u", plat->i2c_bus[bus].bus_id);
if (!mraa_file_exist(devpath)) {
syslog(LOG_INFO, "i2c: %s doesn't exist ", devpath);
capepath = mraa_file_unglob(SYSFS_DEVICES_CAPEMGR_SLOTS);
if (capepath == NULL) {
syslog(LOG_ERR, "i2c: Could not find CapeManager");
@@ -310,7 +307,6 @@ mraa_pwm_context
mraa_beaglebone_pwm_init_replace(int pin)
{
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
if (plat == NULL) {
syslog(LOG_ERR, "pwm: Platform Not Initialised");
@@ -418,7 +414,7 @@ mraa_beaglebone()
else
i2c0_enabled = 0;
if (mraa_file_exist("/sys/class/i2c-dev/i2c-1"))
if (mraa_file_exist("/sys/class/i2c-dev/i2c-2"))
i2c1_enabled = 1;
else
i2c1_enabled = 0;
@@ -1127,7 +1123,7 @@ mraa_beaglebone()
b->pins[64].i2c.mux_total = 0;
b->pins[64].spi.mux_total = 0;
if (i2c0_enabled == 1) {
if (i2c1_enabled == 1) {
strncpy(b->pins[65].name, "I2C2SCL", MRAA_PIN_NAME_SIZE);
b->pins[65].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[65].i2c.mux_total = 0;
@@ -1140,7 +1136,7 @@ mraa_beaglebone()
b->pins[65].gpio.mux_total = 0;
b->pins[65].i2c.mux_total = 0;
if (i2c0_enabled == 1) {
if (i2c1_enabled == 1) {
strncpy(b->pins[66].name, "I2C2SDA", MRAA_PIN_NAME_SIZE);
b->pins[66].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[66].i2c.mux_total = 0;
@@ -1380,7 +1376,7 @@ mraa_beaglebone()
b->i2c_bus[0].sda = 46 + 18;
b->i2c_bus[0].scl = 46 + 17;
b->i2c_bus[1].bus_id = 1;
b->i2c_bus[1].bus_id = 2;
b->i2c_bus[1].sda = 46 + 20;
b->i2c_bus[1].scl = 46 + 19;

View File

@@ -191,7 +191,7 @@ mraa_firmata_i2c_wait(int addr, int reg)
return MRAA_SUCCESS;
}
static uint8_t
static int
mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
{
if (mraa_firmata_send_i2c_read_req(dev, 1) == MRAA_SUCCESS) {
@@ -199,10 +199,10 @@ mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
return firmata_dev->i2cmsg[dev->addr][0];
}
}
return 0;
return -1;
}
static uint16_t
static int
mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 2) == MRAA_SUCCESS) {
@@ -215,10 +215,10 @@ mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
data = (data << 8) & 0xFF00;
data |= high;
return data;
return (int) data;
}
}
}
return 0;
return -1;
}
static int
@@ -249,16 +249,16 @@ mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return 0;
}
static uint8_t
static int
mraa_firmata_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 1) == MRAA_SUCCESS) {
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
return firmata_dev->i2cmsg[dev->addr][command];
return (int) firmata_dev->i2cmsg[dev->addr][command];
}
}
return 0;
return -1;
}
static mraa_result_t
@@ -340,12 +340,12 @@ mraa_firmata_i2c_stop(mraa_i2c_context dev)
return MRAA_SUCCESS;
}
static unsigned int
static int
mraa_firmata_aio_read(mraa_aio_context dev)
{
// careful, whilst you need to enable '0' for A0 you then need to read 14
// in t_firmata because well that makes sense doesn't it...
return (unsigned int) firmata_dev->pins[dev->channel].value;
return (int) firmata_dev->pins[dev->channel].value;
}
static mraa_result_t

View File

@@ -34,6 +34,7 @@
#include <signal.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <errno.h>
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
#define MAX_SIZE 64
@@ -46,6 +47,7 @@ mraa_gpio_get_valfp(mraa_gpio_context dev)
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
dev->value_fp = open(bu, O_RDWR);
if (dev->value_fp == -1) {
syslog(LOG_ERR, "gpio%i: Failed to open 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -64,7 +66,7 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
mraa_gpio_context dev = (mraa_gpio_context) calloc(1, sizeof(struct _gpio));
if (dev == NULL) {
syslog(LOG_CRIT, "gpio: Failed to allocate memory for context");
syslog(LOG_CRIT, "gpio%i: Failed to allocate memory for context", pin);
return NULL;
}
@@ -102,15 +104,15 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
} else {
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
if (export == -1) {
syslog(LOG_ERR, "gpio: Failed to open export for writing");
status = MRAA_ERROR_NO_RESOURCES;
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s", pin, strerror(errno));
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(export, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write %d to export", dev->pin);
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s", pin, strerror(errno));
close(export);
status = MRAA_ERROR_NO_RESOURCES;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
dev->owner = 1;
@@ -131,38 +133,37 @@ mraa_gpio_init(int pin)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "gpio: platform not initialised");
syslog(LOG_ERR, "gpio%i: init: platform not initialised", pin);
return NULL;
}
if (mraa_is_sub_platform_id(pin)) {
syslog(LOG_NOTICE, "gpio: Using sub platform");
syslog(LOG_NOTICE, "gpio%i: init: Using sub platform", pin);
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "gpio: Sub platform Not Initialised");
syslog(LOG_ERR, "gpio%i: init: Sub platform not initialised", pin);
return NULL;
}
pin = mraa_get_sub_platform_index(pin);
}
if (pin < 0 || pin >= board->phy_pin_count) {
syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin);
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)", pin, board->phy_pin_count);
return NULL;
}
if (board->pins[pin].capabilites.gpio != 1) {
syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin);
syslog(LOG_ERR, "gpio: init: pin %i not capable of gpio", pin);
return NULL;
}
if (board->pins[pin].gpio.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pin].gpio) != MRAA_SUCCESS) {
syslog(LOG_ERR, "gpio: unable to setup muxes");
syslog(LOG_ERR, "gpio%i: init: unable to setup muxes", pin);
return NULL;
}
}
mraa_gpio_context r = mraa_gpio_init_internal(board->adv_func, board->pins[pin].gpio.pinmap);
if (r == NULL) {
syslog(LOG_CRIT, "gpio: mraa_gpio_init_raw(%d) returned error", pin);
return NULL;
}
if (r->phy_pin == -1)
@@ -199,12 +200,12 @@ mraa_gpio_wait_interrupt(int fd
struct pollfd pfd[2];
if (control_fd < 0) {
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
#endif
if (fd < 0) {
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
// setup poll on POLLPRI
@@ -218,14 +219,14 @@ mraa_gpio_wait_interrupt(int fd
#ifdef HAVE_PTHREAD_CANCEL
// Wait for it forever or until pthread_cancel
// poll is a cancelable point like sleep()
int x = poll(pfd, 1, -1);
poll(pfd, 1, -1);
#else
// setup poll on the controling fd
pfd[1].fd = control_fd;
pfd[1].events = 0; // POLLHUP, POLLERR, and POLLNVAL
// Wait for it forever or until control fd is closed
int x = poll(pfd, 2, -1);
poll(pfd, 2, -1);
#endif
// do a final read to clear interrupt
@@ -250,14 +251,14 @@ mraa_gpio_interrupt_handler(void* arg)
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
fp = open(bu, O_RDONLY);
if (fp < 0) {
syslog(LOG_ERR, "gpio: failed to open gpio%d/value", dev->pin);
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to open 'value' : %s", dev->pin, strerror(errno));
return NULL;
}
}
#ifndef HAVE_PTHREAD_CANCEL
if (pipe(dev->isr_control_pipe)) {
syslog(LOG_ERR, "gpio: failed to create isr control pipe");
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to create isr control pipe: %s", dev->pin, strerror(errno));
close(fp);
return NULL;
}
@@ -322,7 +323,12 @@ mraa_gpio_interrupt_handler(void* arg)
mraa_result_t
mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
{
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
if (dev == NULL) {
syslog(LOG_ERR, "gpio: edge_mode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
return dev->advance_func->gpio_edge_mode_replace(dev, mode);
if (dev->value_fp != -1) {
@@ -335,7 +341,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
int edge = open(filepath, O_RDWR);
if (edge == -1) {
syslog(LOG_ERR, "gpio: Failed to open edge for writing");
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to open 'edge' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -359,9 +365,9 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
if (write(edge, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to edge");
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to write to 'edge': %s", dev->pin, strerror(errno));
close(edge);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(edge);
@@ -371,13 +377,19 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
mraa_result_t
mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: isr: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
// we only allow one isr per mraa_gpio_context
if (dev->thread_id != 0) {
return MRAA_ERROR_NO_RESOURCES;
}
if (MRAA_SUCCESS != mraa_gpio_edge_mode(dev, mode)) {
return MRAA_ERROR_UNSPECIFIED;
mraa_result_t ret = mraa_gpio_edge_mode(dev, mode);
if (ret != MRAA_SUCCESS) {
return ret;
}
dev->isr = fptr;
@@ -401,6 +413,10 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
{
mraa_result_t ret = MRAA_SUCCESS;
if (dev == NULL) {
return MRAA_ERROR_INVALID_HANDLE;
}
// wasting our time, there is no isr to exit from
if (dev->thread_id == 0 && dev->isr_value_fp == -1) {
return ret;
@@ -414,12 +430,12 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
if ((dev->thread_id != 0)) {
#ifdef HAVE_PTHREAD_CANCEL
if ((pthread_cancel(dev->thread_id) != 0) || (pthread_join(dev->thread_id, NULL) != 0)) {
ret = MRAA_ERROR_INVALID_HANDLE;
ret = MRAA_ERROR_INVALID_RESOURCE;
}
#else
close(dev->isr_control_pipe[1]);
if (pthread_join(dev->thread_id, NULL) != 0)
ret = MRAA_ERROR_INVALID_HANDLE;
ret = MRAA_ERROR_INVALID_RESOURCE;
close(dev->isr_control_pipe[0]);
dev->isr_control_pipe[0] = dev->isr_control_pipe[1] = -1;
@@ -429,7 +445,7 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
// close the filehandle in case it's still open
if (dev->isr_value_fp != -1) {
if (close(dev->isr_value_fp) != 0) {
ret = MRAA_ERROR_INVALID_PARAMETER;
ret = MRAA_ERROR_INVALID_RESOURCE;
}
}
@@ -443,6 +459,11 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
mraa_result_t
mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: mode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_mode_replace))
return dev->advance_func->gpio_mode_replace(dev, mode);
@@ -462,7 +483,7 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
int drive = open(filepath, O_WRONLY);
if (drive == -1) {
syslog(LOG_ERR, "gpio: Failed to open drive for writing");
syslog(LOG_ERR, "gpio%i: mode: Failed to open 'drive' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -486,8 +507,8 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
if (write(drive, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to drive mode");
close(drive);
syslog(LOG_ERR, "gpio%i: mode: Failed to write to 'drive': %s", dev->pin, strerror(errno));
close(drive);
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -500,6 +521,11 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
mraa_result_t
mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: dir: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_dir_replace)) {
return dev->advance_func->gpio_dir_replace(dev, dir);
}
@@ -511,9 +537,6 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
}
}
if (dev == NULL) {
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->value_fp != -1) {
close(dev->value_fp);
dev->value_fp = -1;
@@ -532,8 +555,9 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
case MRAA_GPIO_OUT_LOW:
return mraa_gpio_write(dev, 0);
default:
syslog(LOG_ERR, "gpio%i: dir: Failed to open 'direction' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
}
}
char bu[MAX_SIZE];
@@ -558,7 +582,8 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
if (write(direction, bu, length * sizeof(char)) == -1) {
close(direction);
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: dir: Failed to write to 'direction': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
close(direction);
@@ -575,9 +600,15 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
int fd, rc;
mraa_result_t result = MRAA_SUCCESS;
if (dev == NULL) {
syslog(LOG_ERR, "gpio: read_dir: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
snprintf(filepath, MAX_SIZE, SYSFS_CLASS_GPIO "/gpio%d/direction", dev->pin);
fd = open(filepath, O_RDONLY);
if (fd == -1) {
syslog(LOG_ERR, "gpio%i: read_dir: Failed to open 'direction' for reading: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -585,6 +616,7 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
rc = read(fd, value, sizeof(value));
close(fd);
if (rc <= 0) {
syslog(LOG_ERR, "gpio%i: read_dir: Failed to read 'direction': %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -593,7 +625,8 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
} else if (strcmp(value, "in\n") == 0) {
*dir = MRAA_GPIO_IN;
} else {
result = MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: read_dir: unknown direction: %s", dev->pin, value);
result = MRAA_ERROR_UNSPECIFIED;
}
return result;
@@ -602,8 +635,10 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
int
mraa_gpio_read(mraa_gpio_context dev)
{
if (dev == NULL)
if (dev == NULL) {
syslog(LOG_ERR, "gpio: read: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, gpio_read_replace))
return dev->advance_func->gpio_read_replace(dev);
@@ -613,7 +648,6 @@ mraa_gpio_read(mraa_gpio_context dev)
if (dev->value_fp == -1) {
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
syslog(LOG_ERR, "gpio: Failed to get value file pointer");
return -1;
}
} else {
@@ -622,7 +656,7 @@ mraa_gpio_read(mraa_gpio_context dev)
}
char bu[2];
if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) {
syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs");
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin, strerror(errno));
return -1;
}
lseek(dev->value_fp, 0, SEEK_SET);
@@ -633,8 +667,10 @@ mraa_gpio_read(mraa_gpio_context dev)
mraa_result_t
mraa_gpio_write(mraa_gpio_context dev, int value)
{
if (dev == NULL)
if (dev == NULL) {
syslog(LOG_ERR, "gpio: write: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->mmap_write != NULL)
return dev->mmap_write(dev, value);
@@ -656,13 +692,15 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
}
if (lseek(dev->value_fp, 0, SEEK_SET) == -1) {
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: write: Failed to lseek 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", value);
if (write(dev->value_fp, bu, length * sizeof(char)) == -1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "gpio%i: write: Failed to write to 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
if (IS_FUNC_DEFINED(dev, gpio_write_post))
@@ -675,16 +713,16 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
{
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
if (unexport == -1) {
syslog(LOG_ERR, "gpio: Failed to open unexport for writing");
syslog(LOG_ERR, "gpio%i: Failed to open 'unexport' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(unexport, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to unexport");
syslog(LOG_ERR, "gpio%i: Failed to write to 'unexport': %s", dev->pin, strerror(errno));
close(unexport);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(unexport);
@@ -694,10 +732,15 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
static mraa_result_t
mraa_gpio_unexport(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: unexport: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->owner) {
return mraa_gpio_unexport_force(dev);
}
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
@@ -705,6 +748,11 @@ mraa_gpio_close(mraa_gpio_context dev)
{
mraa_result_t result = MRAA_SUCCESS;
if (dev == NULL) {
syslog(LOG_ERR, "gpio: close: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_close_replace)) {
return dev->advance_func->gpio_close_replace(dev);
}
@@ -726,9 +774,10 @@ mraa_result_t
mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
{
if (dev == NULL) {
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio: owner: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
syslog(LOG_DEBUG, "gpio: Set owner to %d", (int) own);
syslog(LOG_DEBUG, "gpio%i: owner: Set owner to %d", dev->pin, (int) own);
dev->owner = own;
return MRAA_SUCCESS;
}
@@ -736,11 +785,16 @@ mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
mraa_result_t
mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: use_mmaped: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_mmap_setup)) {
return dev->advance_func->gpio_mmap_setup(dev, mmap_en);
}
syslog(LOG_ERR, "gpio: mmap not implemented on this platform");
syslog(LOG_ERR, "gpio%i: use_mmaped: mmap not implemented on this platform", dev->pin);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
@@ -748,7 +802,7 @@ int
mraa_gpio_get_pin(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
return -1;
}
return dev->phy_pin;
@@ -758,7 +812,7 @@ int
mraa_gpio_get_pin_raw(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
return -1;
}
return dev->pin;

View File

@@ -36,7 +36,8 @@
#include <sys/errno.h>
#include <sys/ioctl.h>
#include "linux/i2c-dev.h"
#include <errno.h>
#include <string.h>
typedef union i2c_smbus_data_union {
uint8_t byte; ///< data byte
@@ -78,7 +79,7 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
mraa_i2c_context dev = (mraa_i2c_context) calloc(1, sizeof(struct _i2c));
if (dev == NULL) {
syslog(LOG_CRIT, "i2c: Failed to allocate memory for context");
syslog(LOG_CRIT, "i2c%i_init: Failed to allocate memory for context", bus);
return NULL;
}
@@ -99,13 +100,13 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
char filepath[32];
snprintf(filepath, 32, "/dev/i2c-%u", bus);
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
syslog(LOG_ERR, "i2c: Failed to open requested i2c port %s", filepath);
status = MRAA_ERROR_NO_RESOURCES;
syslog(LOG_ERR, "i2c%i_init: Failed to open requested i2c port %s: %s", bus, filepath, strerror(errno));
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
if (ioctl(dev->fh, I2C_FUNCS, &dev->funcs) < 0) {
syslog(LOG_CRIT, "i2c: Failed to get I2C_FUNC map from device");
syslog(LOG_CRIT, "i2c%i_init: Failed to get I2C_FUNC map from device: %s", bus, strerror(errno));
dev->funcs = 0;
}
}
@@ -133,39 +134,39 @@ mraa_i2c_init(int bus)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "i2c: Platform Not Initialised");
syslog(LOG_ERR, "i2c%i_init: Platform Not Initialised", bus);
return NULL;
}
if (mraa_is_sub_platform_id(bus)) {
syslog(LOG_NOTICE, "i2c: Using sub platform");
syslog(LOG_NOTICE, "i2c%i_init: Using sub platform", bus);
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "i2c: Sub platform Not Initialised");
syslog(LOG_ERR, "i2c%i_init: Sub platform Not Initialised", bus);
return NULL;
}
bus = mraa_get_sub_platform_index(bus);
}
syslog(LOG_NOTICE, "i2c: Selected bus %d", bus);
syslog(LOG_NOTICE, "i2c_init: Selected bus %d", bus);
if (board->i2c_bus_count == 0) {
syslog(LOG_ERR, "No i2c buses defined in platform");
syslog(LOG_ERR, "i2c_init: No i2c buses defined in platform");
return NULL;
}
if (bus >= board->i2c_bus_count) {
syslog(LOG_ERR, "Above i2c bus count");
syslog(LOG_ERR, "i2c_init: i2c%i over i2c bus count", bus);
return NULL;
}
if (board->i2c_bus[bus].bus_id == -1) {
syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
syslog(LOG_ERR, "Invalid i2c bus %i, moving to default i2c bus %i", bus, board->def_i2c_bus);
bus = board->def_i2c_bus;
}
if (!board->no_bus_mux) {
int pos = board->i2c_bus[bus].sda;
if (board->pins[pos].i2c.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
syslog(LOG_ERR, "i2c: Failed to set-up i2c sda multiplexer");
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c sda multiplexer", bus);
return NULL;
}
}
@@ -173,7 +174,7 @@ mraa_i2c_init(int bus)
pos = board->i2c_bus[bus].scl;
if (board->pins[pos].i2c.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
syslog(LOG_ERR, "i2c: Failed to set-up i2c scl multiplexer");
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c scl multiplexer", bus);
return NULL;
}
}
@@ -213,44 +214,44 @@ mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return length;
}
return 0;
return -1;
}
uint8_t
int
mraa_i2c_read_byte(mraa_i2c_context dev)
{
if (IS_FUNC_DEFINED(dev, i2c_read_byte_replace))
return dev->advance_func->i2c_read_byte_replace(dev);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD, I2C_SMBUS_BYTE, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_byte: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0x0FF & d.byte;
}
uint8_t
int
mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
if (IS_FUNC_DEFINED(dev, i2c_read_byte_data_replace))
return dev->advance_func->i2c_read_byte_data_replace(dev, command);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_byte_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0x0FF & d.byte;
}
uint16_t
int
mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
if (IS_FUNC_DEFINED(dev, i2c_read_word_data_replace))
return dev->advance_func->i2c_read_word_data_replace(dev, command);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_word_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0xFFFF & d.word;
}
@@ -266,16 +267,23 @@ mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, i
m[0].addr = dev->addr;
m[0].flags = 0x00;
m[0].len = 1;
m[0].buf = &command;
m[0].buf = (char*) &command;
m[1].addr = dev->addr;
m[1].flags = I2C_M_RD;
m[1].len = length;
m[1].buf = data;
m[1].buf = (char*) data;
d.msgs = m;
d.nmsgs = 2;
return ioctl(dev->fh, I2C_RDWR, &d) < 0 ? -1 : length;
int ret = ioctl(dev->fh, I2C_RDWR, &d);
if (ret < 0)
{
syslog(LOG_ERR, "i2c%i: read_bytes_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return length;
}
mraa_result_t
@@ -299,7 +307,8 @@ mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
d.block[0] = length;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &d) < 0) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -311,8 +320,8 @@ mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
return dev->advance_func->i2c_write_byte_replace(dev, data);
} else {
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_byte: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -326,8 +335,8 @@ mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t
i2c_smbus_data_t d;
d.byte = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_byte_data: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -340,8 +349,8 @@ mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_
i2c_smbus_data_t d;
d.word = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_word_data: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -358,8 +367,8 @@ mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
return dev->advance_func->i2c_address_replace(dev, addr);
} else {
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr);
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: address: Failed to set slave address %d: %s", dev->busnum, addr, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}

View File

@@ -83,6 +83,7 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
int padint = 0;
int curr_bytes = 0;
char shortbuf, signchar;
int i = 0;
dev->datasize = 0;
@@ -129,12 +130,6 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
ret = sscanf(readbuf, "%ce:%c%u/%u>>%u", &shortbuf, &signchar, &chan->bits_used,
&padint, &chan->shift);
chan->bytes = padint / 8;
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
// probably should be 5?
if (ret < 0) {
// cleanup
@@ -175,6 +170,18 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
}
closedir(dir);
// channel location has to be done in channel index order so do it afetr we
// have grabbed all the correct info
for (i = 0; i < dev->chan_num; i++) {
chan = &dev->channels[i];
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
}
return MRAA_SUCCESS;
}
@@ -277,7 +284,7 @@ mraa_iio_write_string(mraa_iio_context dev, const char* attr_name, const char* d
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/%s", dev->num, attr_name);
int fd = open(buf, O_WRONLY);
if (fd != -1) {
size_t len = strlen(data);
int len = strlen(data);
ssize_t status = write(fd, data, len);
if (status == len)
result = MRAA_SUCCESS;

View File

@@ -33,7 +33,7 @@ add_custom_command (TARGET mraajava
COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mraa
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cmake -E echo "Creating jar"
COMMAND ${JAR} cvf mraa.jar mraa
COMMAND ${JAR} cvmf manifest.txt mraa.jar mraa
)
if (DOXYGEN_FOUND)
@@ -42,7 +42,7 @@ if (DOXYGEN_FOUND)
endforeach ()
endif ()
mraa_create_install_pkgconfig (mraajava.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
mraa_create_install_pkgconfig (mraajava.pc ${LIB_INSTALL_DIR}/pkgconfig)
install (TARGETS mraajava LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
install (TARGETS mraajava LIBRARY DESTINATION ${LIB_INSTALL_DIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar DESTINATION ${LIB_INSTALL_DIR}/../lib/java)

9
src/java/manifest.txt.in Normal file
View File

@@ -0,0 +1,9 @@
Manifest-version: 1.0
Name: mraa/
Specification-Title: mraa
Specification-Version: @VERSION_SHORT@
Specification-Vendor: Intel Corp.
Package-Title: mraa
Package-Version: @VERSION_SHORT@
Package-Vendor: Intel Corp.

View File

@@ -96,5 +96,34 @@ class Spi;
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
String javaAPIVersion = mraa.class.getPackage().getSpecificationVersion();
String nativeAPIVersion = mraa.getVersion().substring(1);
String javaMajor = javaAPIVersion.substring(0, javaAPIVersion.indexOf('.'));
String nativeMajor = nativeAPIVersion.substring(0, nativeAPIVersion.indexOf('.'));
if(Integer.parseInt(javaMajor) < Integer.parseInt(nativeMajor)){
System.err.println("Java library is out of date. Please update the Java library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
System.exit(1);
}
if(Integer.parseInt(javaMajor) > Integer.parseInt(nativeMajor)){
System.err.println("Native library is out of date. Please update the Native library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
System.exit(1);
}
String javaMinor = javaAPIVersion.substring(javaMajor.length() + 1, javaAPIVersion.indexOf('.', javaMajor.length() + 1));
String nativeMinor = nativeAPIVersion.substring(nativeMajor.length() + 1, nativeAPIVersion.indexOf('.', nativeMajor.length() + 1));
if(Integer.parseInt(javaMinor) < Integer.parseInt(nativeMinor)){
System.err.println("Java library is out of date. Please consider updating the Java library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
}
if(Integer.parseInt(javaMinor) > Integer.parseInt(nativeMinor)){
System.err.println("Native library is out of date. Please consider updating the Native library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
}
}
%}

View File

@@ -3,35 +3,39 @@
{
'target_name': 'mraa',
'sources': [
@mraa_LIB_SRCS_GYP@
'src/version.c',
'src/mraajsJAVASCRIPT_wrap.cxx' ],
@mraa_LIB_SRCS_GYP@
'src/version.c',
'src/mraajsJAVASCRIPT_wrap.cxx'
],
'include_dirs': [
@mraa_LIB_INCLUDE_DIRS_GYP@
],
@mraa_LIB_INCLUDE_DIRS_GYP@
],
'variables': {
"v8_version%": "<!(node -e 'console.log(process.versions.v8)' | sed 's/\.//g' | cut -c 1-5)",
"arch%": "<!(node -e 'console.log(process.arch)')"
"v8_version%": "<!(node -e 'console.log(process.versions.v8)' | sed 's/\.//g' | cut -c 1-5)",
"arch%": "<!(node -e 'console.log(process.arch)')"
},
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'conditions' : [
[ 'arch=="x64"',
{ 'defines' : [ 'X86PLAT=ON' ], },
],
[ 'arch=="ia32"',
{ 'defines' : [ 'X86PLAT=ON'], },
],
[ 'arch=="arm"',
{ 'defines' : [ 'ARMPLAT=ON'], },
],
['OS=="android"', {
'sources' : [ 'src/glob/glob.c' ],
'include_dirs' : [ 'src/glob' ],
}],
[ 'arch=="x64" or arch=="ia32"', {
'defines' : [ 'X86PLAT=ON' ],
}],
[ 'arch=="arm"', {
'defines' : [ 'ARMPLAT=ON'],
}],
],
'defines' : [ 'SWIG',
'SWIGJAVASCRIPT',
'FIRMATA=ON',
'BUILDING_NODE_EXTENSION=1',
'SWIG_V8_VERSION=0x0<(v8_version)',
'V8_VERSION=0x0<(v8_version)'
'defines' : [
'SWIG',
'SWIGJAVASCRIPT',
'FIRMATA=ON',
'ONEWIRE=ON',
'BUILDING_NODE_EXTENSION=1',
'SWIG_V8_VERSION=0x0<(v8_version)',
'V8_VERSION=0x0<(v8_version)'
]
}
]

View File

@@ -65,7 +65,7 @@
},
"func": {
"type": "Function",
"description": "Function to be called when interupt is triggered"
"description": "Function to be called when interrupt is triggered"
}
},
"return": {

View File

@@ -41,6 +41,9 @@
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#if defined(IMRAA)
#include <json-c/json.h>
@@ -52,6 +55,12 @@
#include "firmata/firmata_mraa.h"
#include "gpio.h"
#include "version.h"
#include "i2c.h"
#include "pwm.h"
#include "aio.h"
#include "spi.h"
#include "uart.h"
#define IIO_DEVICE_WILDCARD "iio:device*"
mraa_board_t* plat = NULL;
@@ -90,7 +99,7 @@ mraa_result_t
imraa_init()
{
if (plat != NULL) {
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
return MRAA_SUCCESS;
}
uid_t proc_euid = geteuid();
@@ -187,7 +196,7 @@ mraa_result_t __attribute__((constructor))
mraa_init()
{
if (plat != NULL) {
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
return MRAA_SUCCESS;
} else {
return imraa_init();
}
@@ -217,7 +226,7 @@ mraa_deinit()
}
int
mraa_set_priority(const unsigned int priority)
mraa_set_priority(const int priority)
{
struct sched_param sched_s;
@@ -282,7 +291,7 @@ mraa_iio_detect()
mraa_result_t
mraa_setup_mux_mapped(mraa_pin_t meta)
{
int mi;
unsigned int mi;
mraa_result_t ret;
mraa_gpio_context mux_i = NULL;
int last_pin = -1;
@@ -486,6 +495,15 @@ mraa_result_print(mraa_result_t result)
case MRAA_ERROR_PLATFORM_NOT_INITIALISED:
fprintf(stdout, "MRAA: Platform not initialised.\n");
break;
case MRAA_ERROR_UART_OW_SHORTED:
fprintf(stdout, "MRAA: UART OW: Bus short detected.\n");
break;
case MRAA_ERROR_UART_OW_NO_DEVICES:
fprintf(stdout, "MRAA: UART OW: No devices detected on bus.\n");
break;
case MRAA_ERROR_UART_OW_DATA_ERROR:
fprintf(stdout, "MRAA: UART OW: Data or Bus error detected.\n");
break;
case MRAA_ERROR_UNSPECIFIED:
fprintf(stdout, "MRAA: Unspecified Error.\n");
break;
@@ -666,7 +684,7 @@ mraa_get_i2c_bus_count()
}
int
mraa_get_i2c_bus_id(unsigned i2c_bus)
mraa_get_i2c_bus_id(int i2c_bus)
{
if (plat == NULL) {
return -1;
@@ -973,6 +991,9 @@ mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev)
{
#if defined(FIRMATA)
if (subplatformtype == MRAA_GENERIC_FIRMATA) {
if (plat->sub_platform != NULL) {
return MRAA_ERROR_INVALID_PARAMETER;
}
if (mraa_firmata_platform(plat, uart_dev) == MRAA_GENERIC_FIRMATA) {
syslog(LOG_NOTICE, "mraa: Added firmata subplatform");
return MRAA_SUCCESS;
@@ -984,6 +1005,22 @@ mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev)
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
mraa_remove_subplatform(mraa_platform_t subplatformtype)
{
#if defined(FIRMATA)
if (subplatformtype == MRAA_GENERIC_FIRMATA) {
if (plat == NULL || plat->sub_platform == NULL) {
return MRAA_ERROR_INVALID_PARAMETER;
}
free(plat->sub_platform->adv_func);
free(plat->sub_platform->pins);
free(plat->sub_platform);
}
#endif
return MRAA_ERROR_INVALID_PARAMETER;
}
#if defined(IMRAA)
mraa_result_t
mraa_add_from_lockfile(const char* imraa_lock_file)
@@ -1045,3 +1082,151 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
return ret;
}
#endif
void
mraa_to_upper(char* s)
{
char* t = s;
for (; *t; ++t) {
*t = toupper(*t);
}
}
mraa_result_t
mraa_atoi(char* intStr, int* value)
{
char* end;
// here 10 determines the number base in which strol is to work
long val = strtol(intStr, &end, 10);
if (*end != '\0' || errno == ERANGE || end == intStr || val > INT_MAX || val < INT_MIN) {
*value = 0;
return MRAA_ERROR_UNSPECIFIED;
}
*value = (int) val;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_io_helper(char** str, int* value, const char* delim)
{
// This function is a result of a repeated pattern within mraa_init_io
// when determining if a value can be derived from a string
char* token;
token = strsep(str, delim);
// check to see if empty string returned
if (token == NULL) {
*value = 0;
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
return mraa_atoi(token, value);
}
void*
mraa_init_io(const char* desc)
{
const char* delim = "-";
int length = 0, raw = 0;
int pin = 0, id = 0;
// 256 denotes the maximum size of our buffer
// 8 denotes the maximum size of our type rounded to the nearest power of 2
// max size is 4 + 1 for the \0 = 5 rounded to 8
char buffer[256] = { 0 }, type[8] = { 0 };
char *token = 0, *str = 0;
length = strlen(desc);
// Check to see the length is less than or equal to 255 which means
// byte 256 is supposed to be \0
if (length > 255 || desc == NULL || length == 0) {
return NULL;
}
strncpy(buffer, desc, length);
str = buffer;
token = strsep(&str, delim);
length = strlen(token);
// Check to see they haven't given us a type whose length is greater than the
// largest type we know about
if (length > 4) {
syslog(LOG_ERR, "mraa_init_io: An invalid IO type was provided");
return NULL;
}
strncpy(type, token, length);
mraa_to_upper(type);
token = strsep(&str, delim);
// Check that they've given us more information than just the type
if (token == NULL) {
syslog(LOG_ERR, "mraa_init_io: Missing information after type");
return NULL;
}
// If we cannot convert the pin to a number maybe it says raw?
if (mraa_atoi(token, &pin) != MRAA_SUCCESS) {
mraa_to_upper(token);
if (strncmp(token, "RAW", 3)) {
syslog(LOG_ERR, "mraa_init_io: Description does not adhere to a known format");
return NULL;
}
raw = 1;
}
if (!raw && str != NULL) {
syslog(LOG_ERR, "mraa_init_io: More information than required was provided");
return NULL;
}
if (strncmp(type, "GPIO", 4) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_gpio_init_raw(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for GPIO");
return NULL;
}
return (void*) mraa_gpio_init(pin);
} else if (strncmp(type, "I2C", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_i2c_init_raw(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for I2C");
return NULL;
}
return (void*) mraa_i2c_init(pin);
} else if (strncmp(type, "AIO", 3) == 0) {
if (raw) {
syslog(LOG_ERR, "mraa_init_io: Aio doesn't have a RAW mode");
return NULL;
}
return (void*) mraa_aio_init(pin);
} else if (strncmp(type, "PWM", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a useable Int");
return NULL;
}
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the pin string into a useable Int");
return NULL;
}
return (void*) mraa_pwm_init_raw(id, pin);
}
return (void*) mraa_pwm_init(pin);
} else if (strncmp(type, "SPI", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the bus string into a useable Int");
return NULL;
}
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the cs string into a useable Int");
return NULL;
}
return (void*) mraa_spi_init_raw(id, pin);
}
return (void*) mraa_spi_init(pin);
} else if (strncmp(type, "UART", 4) == 0) {
if (raw) {
return (void*) mraa_uart_init_raw(str);
}
return (void*) mraa_uart_init(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid IO type given.");
return NULL;
}

View File

@@ -41,6 +41,19 @@
%include "types.hpp"
%include "common.hpp"
%template (gpioFromDesc) mraa::initIo<mraa::Gpio>;
%template (aioFromDesc) mraa::initIo<mraa::Aio>;
%template (uartFromDesc) mraa::initIo<mraa::Uart>;
%template (spiFromDesc) mraa::initIo<mraa::Spi>;
%template (i2cFromDesc) mraa::initIo<mraa::I2c>;
%template (pwmFromDesc) mraa::initIo<mraa::Pwm>;
%ignore Aio(void* aio_context);
%ignore Pwm(void* pwm_context);
%ignore Uart(void* uart_context);
%ignore Spi(void* spi_context);
%ignore I2c(void* i2c_context);
%ignore Gpio(void* gpio_context);
%ignore Gpio::nop(uv_work_t* req);
%ignore Gpio::v8isr(uv_work_t* req);

View File

@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib@LIB_SUFFIX@
libdir=${exec_prefix}/@LIB_INSTALL_DIR@
includedir=${prefix}/include
Name: mraa

View File

@@ -27,6 +27,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <string.h>
#include "pwm.h"
#include "mraa_internal.h"
@@ -50,6 +52,11 @@ mraa_pwm_setup_duty_fp(mraa_pwm_context dev)
static mraa_result_t
mraa_pwm_write_period(mraa_pwm_context dev, int period)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_period_replace)) {
mraa_result_t result = dev->advance_func->pwm_period_replace(dev, period);
if (result == MRAA_SUCCESS) {
@@ -62,13 +69,14 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
int period_f = open(bu, O_RDWR);
if (period_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open period for writing");
syslog(LOG_ERR, "pwm%i write_period: Failed to open period for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[MAX_SIZE];
int length = snprintf(out, MAX_SIZE, "%d", period);
if (write(period_f, out, length * sizeof(char)) == -1) {
close(period_f);
syslog(LOG_ERR, "pwm%i write_period: Failed to write to period: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -80,24 +88,38 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
static mraa_result_t
mraa_pwm_write_duty(mraa_pwm_context dev, int duty)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write_duty: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_write_replace)) {
return dev->advance_func->pwm_write_replace(dev, duty);
}
if (dev->duty_fp == -1) {
if (mraa_pwm_setup_duty_fp(dev) == 1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "pwm%i write_duty: Failed to open duty_cycle for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
}
char bu[64];
int length = sprintf(bu, "%d", duty);
if (write(dev->duty_fp, bu, length * sizeof(char)) == -1)
{
syslog(LOG_ERR, "pwm%i write_duty: Failed to write to duty_cycle: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
static int
mraa_pwm_read_period(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_read_replace)) {
return dev->period;
}
@@ -108,27 +130,25 @@ mraa_pwm_read_period(mraa_pwm_context dev)
int period_f = open(bu, O_RDWR);
if (period_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open period for reading");
syslog(LOG_ERR, "pwm%i read_period: Failed to open period for reading: %s", dev->pin, strerror(errno));
return 0;
}
off_t size = lseek(period_f, 0, SEEK_END);
lseek(period_f, 0, SEEK_SET);
ssize_t rb = read(period_f, output, size + 1);
ssize_t rb = read(period_f, output, MAX_SIZE);
close(period_f);
if (rb < 0) {
syslog(LOG_ERR, "pwm: Error in reading period");
syslog(LOG_ERR, "pwm%i read_period: Failed to read period: %s", dev->pin, strerror(errno));
return -1;
}
char* endptr;
long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string conversion");
syslog(LOG_ERR, "pwm%i read_period: Error in string conversion", dev->pin);
return -1;
} else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid");
syslog(LOG_ERR, "pwm%i read_period: Number is invalid", dev->pin);
return -1;
}
dev->period = (int) ret;
@@ -138,33 +158,39 @@ mraa_pwm_read_period(mraa_pwm_context dev)
static int
mraa_pwm_read_duty(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read_duty: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_read_replace)) {
return dev->advance_func->pwm_read_replace(dev);
}
if (dev->duty_fp == -1) {
if (mraa_pwm_setup_duty_fp(dev) == 1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "pwm%i read_duty: Failed to open duty_cycle for reading: %s",
dev->pin, strerror(errno));
return -1;
}
} else {
lseek(dev->duty_fp, 0, SEEK_SET);
}
off_t size = lseek(dev->duty_fp, 0, SEEK_END);
lseek(dev->duty_fp, 0, SEEK_SET);
char output[MAX_SIZE];
ssize_t rb = read(dev->duty_fp, output, size + 1);
ssize_t rb = read(dev->duty_fp, output, MAX_SIZE);
if (rb < 0) {
syslog(LOG_ERR, "pwm: Error in reading duty");
syslog(LOG_ERR, "pwm%i read_duty: Failed to read duty_cycle: %s", dev->pin, strerror(errno));
return -1;
}
char* endptr;
long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string converstion");
syslog(LOG_ERR, "pwm%i read_duty: Error in string conversion", dev->pin);
return -1;
} else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid");
syslog(LOG_ERR, "pwm%i read_duty: Number is invalid", dev->pin);
return -1;
}
return (int) ret;
@@ -191,24 +217,24 @@ mraa_pwm_init(int pin)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "pwm: Platform Not Initialised");
syslog(LOG_ERR, "pwm_init: Platform Not Initialised");
return NULL;
}
if (mraa_is_sub_platform_id(pin)) {
syslog(LOG_NOTICE, "pwm: Using sub platform");
syslog(LOG_NOTICE, "pwm_init: Using sub platform");
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "pwm: Sub platform Not Initialised");
syslog(LOG_ERR, "pwm_init: Sub platform Not Initialised");
return NULL;
}
pin = mraa_get_sub_platform_index(pin);
}
if (pin < 0 || pin > board->phy_pin_count) {
syslog(LOG_ERR, "pwm: pin %i beyond platform definition", pin);
syslog(LOG_ERR, "pwm_init: pin %i beyond platform definition", pin);
return NULL;
}
if (board->pins[pin].capabilites.pwm != 1) {
syslog(LOG_ERR, "pwm: pin not capable of pwm");
syslog(LOG_ERR, "pwm_init: pin %i not capable of pwm", pin);
return NULL;
}
@@ -228,26 +254,26 @@ mraa_pwm_init(int pin)
mraa_gpio_context mux_i;
mux_i = mraa_gpio_init_raw(board->pins[pin].gpio.pinmap);
if (mux_i == NULL) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_init", pin);
return NULL;
}
if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_dir", pin);
return NULL;
}
if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_write", pin);
return NULL;
}
if (mraa_gpio_close(mux_i) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_close", pin);
return NULL;
}
}
if (board->pins[pin].pwm.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pin].pwm) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: Failed to set-up multiplexer");
syslog(LOG_ERR, "pwm_init: Failed to set-up pwm%i multiplexer", pin);
return NULL;
}
}
@@ -278,14 +304,14 @@ mraa_pwm_init_raw(int chipin, int pin)
snprintf(directory, MAX_SIZE, SYSFS_PWM "/pwmchip%d/pwm%d", dev->chipid, dev->pin);
struct stat dir;
if (stat(directory, &dir) == 0 && S_ISDIR(dir.st_mode)) {
syslog(LOG_NOTICE, "pwm: Pin already exported, continuing");
syslog(LOG_NOTICE, "pwm_init: pwm%i already exported, continuing", pin);
dev->owner = 0; // Not Owner
} else {
char buffer[MAX_SIZE];
snprintf(buffer, MAX_SIZE, "/sys/class/pwm/pwmchip%d/export", dev->chipid);
int export_f = open(buffer, O_WRONLY);
if (export_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open export for writing");
syslog(LOG_ERR, "pwm_init: pwm%i. Failed to open export for writing: %s", pin, strerror(errno));
free(dev);
return NULL;
}
@@ -293,7 +319,7 @@ mraa_pwm_init_raw(int chipin, int pin)
char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(export_f, out, size * sizeof(char)) == -1) {
syslog(LOG_WARNING, "pwm: Failed to write to export! Potentially already enabled");
syslog(LOG_WARNING, "pwm_init: pwm%i. Failed to write to export! (%s) Potentially already in use.", pin, strerror(errno));
close(export_f);
free(dev);
return NULL;
@@ -309,13 +335,18 @@ mraa_pwm_init_raw(int chipin, int pin)
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->period == -1) {
if (mraa_pwm_read_period(dev) <= 0)
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
if (percentage > 1.0f) {
syslog(LOG_WARNING, "pwm: number greater than 1 entered, defaulting to 100%%");
syslog(LOG_WARNING, "pwm_write: %i%% entered, defaulting to 100%%",(int) percentage * 100);
return mraa_pwm_write_duty(dev, dev->period);
}
return mraa_pwm_write_duty(dev, percentage * dev->period);
@@ -324,6 +355,11 @@ mraa_pwm_write(mraa_pwm_context dev, float percentage)
float
mraa_pwm_read(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
int period = mraa_pwm_read_period(dev);
if (period > 0) {
return (mraa_pwm_read_duty(dev) / (float) period);
@@ -347,6 +383,12 @@ mraa_result_t
mraa_pwm_period_us(mraa_pwm_context dev, int us)
{
int min, max;
if (!dev) {
syslog(LOG_ERR, "pwm: period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
min = plat->sub_platform->pwm_min_period;
max = plat->sub_platform->pwm_max_period;
@@ -355,7 +397,7 @@ mraa_pwm_period_us(mraa_pwm_context dev, int us)
max = plat->pwm_max_period;
}
if (us < min || us > max) {
syslog(LOG_ERR, "pwm: period value outside platform range");
syslog(LOG_ERR, "pwm_period: pwm%i: %i uS outside platform range", dev->pin, us);
return MRAA_ERROR_INVALID_PARAMETER;
}
return mraa_pwm_write_period(dev, us * 1000);
@@ -382,25 +424,30 @@ mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us)
mraa_result_t
mraa_pwm_enable(mraa_pwm_context dev, int enable)
{
if (!dev) {
syslog(LOG_ERR, "pwm: enable: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_enable_replace)) {
return dev->advance_func->pwm_enable_replace(dev, enable);
}
int status;
char bu[MAX_SIZE];
snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/enable", dev->chipid, dev->pin);
int enable_f = open(bu, O_RDWR);
if (enable_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open enable for writing");
syslog(LOG_ERR, "pwm_enable: pwm%i: Failed to open enable for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[2];
int size = snprintf(out, sizeof(out), "%d", enable);
if (write(enable_f, out, size * sizeof(char)) == -1) {
syslog(LOG_ERR, "pwm: Failed to write to enable");
syslog(LOG_ERR, "pwm_enable: pwm%i: Failed to write to enable: %s", dev->pin, strerror(errno));
close(enable_f);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(enable_f);
return MRAA_SUCCESS;
@@ -414,16 +461,16 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
int unexport_f = open(filepath, O_WRONLY);
if (unexport_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open unexport for writing");
syslog(LOG_ERR, "pwm_unexport: pwm%i: Failed to open unexport for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(unexport_f, out, size * sizeof(char)) == -1) {
syslog(LOG_ERR, "pwm: Failed to write to unexport");
syslog(LOG_ERR, "pwm_unexport: pwm%i: Failed to write to unexport: %s", dev->pin, strerror(errno));
close(unexport_f);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(unexport_f);
@@ -433,16 +480,26 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
mraa_result_t
mraa_pwm_unexport(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: unexport: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
mraa_pwm_enable(dev, 0);
if (dev->owner) {
return mraa_pwm_unexport_force(dev);
}
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
mraa_pwm_close(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: close: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
mraa_pwm_unexport(dev);
free(dev);
return MRAA_SUCCESS;
@@ -451,66 +508,26 @@ mraa_pwm_close(mraa_pwm_context dev)
mraa_result_t
mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner_new)
{
if (dev == NULL)
return MRAA_ERROR_INVALID_RESOURCE;
if (!dev) {
syslog(LOG_ERR, "pwm: owner: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
dev->owner = owner_new;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_pwm_config_ms(mraa_pwm_context dev, int ms, float ms_float)
{
int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
return status;
}
status = mraa_pwm_write_duty(dev, 0);
if (status != MRAA_SUCCESS) {
return status;
}
status = mraa_pwm_pulsewidth_us(dev, ms_float * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period);
return status;
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_pwm_config_percent(mraa_pwm_context dev, int ms, float percentage)
{
int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
return status;
}
status = mraa_pwm_write_duty(dev, 0);
if (status != MRAA_SUCCESS) {
return status;
}
status = mraa_pwm_pulsewidth_us(dev, (ms * 1000) * percentage);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period);
return status;
}
return MRAA_SUCCESS;
}
int
mraa_pwm_get_max_period(mraa_pwm_context dev)
{
if (plat == NULL) {
return -1;
}
if (!dev) {
syslog(LOG_ERR, "pwm: get_max_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
return plat->sub_platform->pwm_max_period;
}
@@ -523,6 +540,12 @@ mraa_pwm_get_min_period(mraa_pwm_context dev)
if (plat == NULL) {
return -1;
}
if (!dev) {
syslog(LOG_ERR, "pwm: get_min_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
return plat->sub_platform->pwm_min_period;
}

View File

@@ -1,50 +1,5 @@
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
${PYTHON_INCLUDE_DIRS}
)
set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
swig_add_module (python-mraa python mraa.i mraapy.c)
swig_link_libraries (python-mraa ${PYTHON_LIBRARIES} mraa)
if (DOXYGEN_FOUND)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} common_hpp_doc_i)
add_custom_target (pydoc
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pydoc" VERBATIM
)
endif ()
set_target_properties (${SWIG_MODULE_python-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
)
execute_process (
COMMAND ${PYTHON_EXECUTABLE} -c
"import site, sys; sys.stdout.write(site.PREFIXES[-1])"
OUTPUT_VARIABLE PYTHON_PREFIX
)
file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
execute_process (
COMMAND ${PYTHON_EXECUTABLE} -c
"import site, sys; sys.stdout.write(site.getusersitepackages().replace(site.getuserbase(), site.PREFIXES[-1]))"
OUTPUT_VARIABLE PYTHON_SITE_DIR
)
file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
string (REGEX REPLACE "^${PYTHON_PREFIX}/" ""
PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${PYTHON_SITE_DIR})
add_subdirectory (docs)
add_subdirectory (python2)
add_subdirectory (python3)

View File

@@ -1,7 +1,3 @@
%module(docstring="Python interface to libmraa") mraa
%feature("autodoc", "3");
%include typemaps.i
%include carrays.i

View File

@@ -0,0 +1,39 @@
set_source_files_properties (mraa2.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa2.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
if (PYTHON2_LIBRARY)
message ("PYTHON2 attempting to build!")
swig_add_module (python2-mraa python mraa2.i ../mraapy.c)
swig_link_libraries (python2-mraa ${PYTHON2_LIBRARIES} mraa)
target_include_directories(${SWIG_MODULE_python2-mraa_REAL_NAME}
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
"${PYTHON2_INCLUDE_DIR}"
)
if (DOXYGEN_FOUND AND PYTHON2_EXECUTABLE)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} common_hpp_doc_i)
add_custom_target (pydoc
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pydoc" VERBATIM
)
endif ()
set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
endif()
add_subdirectory (docs)

View File

@@ -36,6 +36,6 @@ if (DOXYGEN_FOUND)
COMMENT "Building HTML documentation with Sphinx"
)
add_dependencies (sphinx ${SWIG_MODULE_python-mraa_REAL_NAME})
add_dependencies (sphinx ${SWIG_MODULE_python2-mraa_REAL_NAME})
endif ()
endif ()

View File

@@ -16,13 +16,13 @@ Here is the simplest Gpio program in mraa.
:prepend: import mraa
:start-after: import mraa
GPIO Interupt (isr)
GPIO Interrupt (isr)
===================
The GPIO module allows you to set an interupt on a GPIO. This interupt is
The GPIO module allows you to set an interrupt on a GPIO. This interrupt is
controlled by the mode that the 'edge' is in. Before setting another isr please
remove the first one, multiple isrs on one pin are not supported. Some
platforms will not support interupts on all pins so please check your return
platforms will not support interrupts on all pins so please check your return
values.
**Note:** Galileo Gen1 only supports EDGE_BOTH

View File

@@ -0,0 +1,5 @@
%module(docstring="Python interface to libmraa") mraa
%feature("autodoc", "3");
%include ../mraapython.i

View File

@@ -0,0 +1,24 @@
set_source_files_properties (mraa3.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa3.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
if (PYTHON3_LIBRARY)
message ("PYTHON3 attempting to build!")
swig_add_module (python3-mraa python mraa3.i ../mraapy.c)
swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa)
target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
"${PYTHON3_INCLUDE_DIR}"
)
set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH})
endif ()

View File

@@ -0,0 +1,3 @@
%module(docstring="Python interface to libmraa") mraa
%include ../mraapython.i

View File

@@ -143,10 +143,12 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
}
int speed = 0;
if ((ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) && (speed < 4000000)) {
if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
dev->clock = speed;
} else {
// We had this on Galileo Gen1, so let it be a fallback value
dev->clock = 4000000;
syslog(LOG_WARNING, "spi: Max speed query failed, setting %d", dev->clock);
}
if (mraa_spi_mode(dev, MRAA_SPI_MODE0) != MRAA_SUCCESS) {
@@ -265,7 +267,7 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
return (int) recv;
}
uint16_t
int
mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
{
struct spi_ioc_transfer msg;
@@ -284,7 +286,7 @@ mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
syslog(LOG_ERR, "spi: Failed to perform dev transfer");
return -1;
}
return recv;
return (int) recv;
}
mraa_result_t

View File

@@ -30,6 +30,8 @@
#include <string.h>
#include <termios.h>
#include <sys/select.h>
#include <errno.h>
#include <string.h>
#include "uart.h"
#include "mraa_internal.h"
@@ -106,9 +108,7 @@ uint2speed(unsigned int speed)
return B4000000;
default:
// if we are here, then an unsupported baudrate was selected.
// Report it via syslog and return B9600, a common default.
syslog(LOG_ERR, "uart: unsupported baud rate, defaulting to 9600.");
return B9600;
return 0;
}
}
@@ -131,29 +131,29 @@ mraa_uart_context
mraa_uart_init(int index)
{
if (plat == NULL) {
syslog(LOG_ERR, "uart: platform not initialised");
syslog(LOG_ERR, "uart%i: init: platform not initialised", index);
return NULL;
}
if (mraa_is_sub_platform_id(index)) {
syslog(LOG_NOTICE, "uart: Using sub platform is not supported");
syslog(LOG_NOTICE, "uart%i: init: Using sub platform is not supported", index);
return NULL;
}
if (plat->adv_func->uart_init_pre != NULL) {
if (plat->adv_func->uart_init_pre(index) != MRAA_SUCCESS) {
syslog(LOG_ERR, "uart: failure in pre-init platform hook");
syslog(LOG_ERR, "uart%i: init: failure in pre-init platform hook", index);
return NULL;
}
}
if (plat->uart_dev_count == 0) {
syslog(LOG_ERR, "uart: platform has no UARTs defined");
syslog(LOG_ERR, "uart%i: init: platform has no UARTs defined", index);
return NULL;
}
if (plat->uart_dev_count <= index) {
syslog(LOG_ERR, "uart: platform has only %i", plat->uart_dev_count);
syslog(LOG_ERR, "uart%i: init: platform has only %i uarts", index, plat->uart_dev_count);
return NULL;
}
@@ -162,7 +162,7 @@ mraa_uart_init(int index)
if (pos >= 0) {
if (plat->pins[pos].uart.mux_total > 0) {
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) {
syslog(LOG_ERR, "uart: failed to setup muxes for RX pin");
syslog(LOG_ERR, "uart%i: init: failed to setup muxes for RX pin", index);
return NULL;
}
}
@@ -172,7 +172,7 @@ mraa_uart_init(int index)
if (pos >= 0) {
if (plat->pins[pos].uart.mux_total > 0) {
if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) {
syslog(LOG_ERR, "uart: failed to setup muxes for TX pin");
syslog(LOG_ERR, "uart%i: init: failed to setup muxes for TX pin", index);
return NULL;
}
}
@@ -199,6 +199,11 @@ mraa_uart_init(int index)
mraa_uart_context
mraa_uart_init_raw(const char* path)
{
if (!path) {
syslog(LOG_ERR, "uart: device path undefined");
return NULL;
}
mraa_uart_context dev = mraa_uart_init_internal(plat == NULL ? NULL : plat->adv_func);
if (dev == NULL) {
syslog(LOG_ERR, "uart: Failed to allocate memory for context");
@@ -206,15 +211,9 @@ mraa_uart_init_raw(const char* path)
}
dev->path = path;
if (!dev->path) {
syslog(LOG_ERR, "uart: device path undefined, open failed");
free(dev);
return NULL;
}
// now open the device
if ((dev->fd = open(dev->path, O_RDWR)) == -1) {
syslog(LOG_ERR, "uart: open() failed");
syslog(LOG_ERR, "uart: open(%s) failed: %s", path, strerror(errno));
free(dev);
return NULL;
}
@@ -224,7 +223,7 @@ mraa_uart_init_raw(const char* path)
// get current modes
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr() failed");
syslog(LOG_ERR, "uart: tcgetattr(%s) failed: %s", path, strerror(errno));
close(dev->fd);
free(dev);
return NULL;
@@ -235,7 +234,7 @@ mraa_uart_init_raw(const char* path)
// cfmakeraw is not POSIX!
cfmakeraw(&termio);
if (tcsetattr(dev->fd, TCSAFLUSH, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr() failed after cfmakeraw()");
syslog(LOG_ERR, "uart: tcsetattr(%s) failed after cfmakeraw(): %s", path, strerror(errno));
close(dev->fd);
free(dev);
return NULL;
@@ -272,7 +271,7 @@ mraa_result_t
mraa_uart_flush(mraa_uart_context dev)
{
if (!dev) {
syslog(LOG_ERR, "uart: stop: context is NULL");
syslog(LOG_ERR, "uart: flush: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
@@ -287,24 +286,29 @@ mraa_result_t
mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud)
{
if (!dev) {
syslog(LOG_ERR, "uart: stop: context is NULL");
syslog(LOG_ERR, "uart: set_baudrate: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
struct termios termio;
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr() failed");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "uart%i: set_baudrate: tcgetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
// set our baud rates
speed_t speed = uint2speed(baud);
if (speed == 0)
{
syslog(LOG_ERR, "uart%i: set_baudrate: invalid baudrate: %i", dev->index, baud);
return MRAA_ERROR_INVALID_PARAMETER;
}
cfsetispeed(&termio, speed);
cfsetospeed(&termio, speed);
// make it so
if (tcsetattr(dev->fd, TCSAFLUSH, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr() failed");
syslog(LOG_ERR, "uart%i: set_baudrate: tcsetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
return MRAA_SUCCESS;
@@ -314,14 +318,14 @@ mraa_result_t
mraa_uart_set_mode(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits)
{
if (!dev) {
syslog(LOG_ERR, "uart: stop: context is NULL");
syslog(LOG_ERR, "uart: set_mode: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
struct termios termio;
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr() failed");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "uart%i: set_mode: tcgetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
termio.c_cflag &= ~CSIZE;
@@ -375,7 +379,7 @@ mraa_uart_set_mode(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parit
}
if (tcsetattr(dev->fd, TCSAFLUSH, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr() failed");
syslog(LOG_ERR, "uart%i: set_mode: tcsetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
@@ -386,7 +390,7 @@ mraa_result_t
mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts)
{
if (!dev) {
syslog(LOG_ERR, "uart: stop: context is NULL");
syslog(LOG_ERR, "uart: set_flowcontrol: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
@@ -404,8 +408,8 @@ mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_bo
// get current modes
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr() failed");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "uart%i: set_flowcontrol: tcgetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
if (rtscts) {
@@ -415,7 +419,7 @@ mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_bo
}
if (tcsetattr(dev->fd, TCSAFLUSH, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr() failed");
syslog(LOG_ERR, "uart%i: set_flowcontrol: tcsetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
@@ -426,15 +430,15 @@ mraa_result_t
mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar)
{
if (!dev) {
syslog(LOG_ERR, "uart: stop: context is NULL");
syslog(LOG_ERR, "uart: set_timeout: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
struct termios termio;
// get current modes
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr() failed");
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
syslog(LOG_ERR, "uart%i: set_timeout: tcgetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
if (read > 0) {
read = read / 100;
@@ -444,7 +448,7 @@ mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar)
termio.c_lflag &= ~ICANON; /* Set non-canonical mode */
termio.c_cc[VTIME] = read; /* Set timeout in tenth seconds */
if (tcsetattr(dev->fd, TCSANOW, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr() failed");
syslog(LOG_ERR, "uart%i: set_timeout: tcsetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
@@ -454,6 +458,11 @@ mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar)
mraa_result_t
mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock)
{
if (!dev) {
syslog(LOG_ERR, "uart: non_blocking: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
// get current flags
int flags = fcntl(dev->fd, F_GETFL);
@@ -466,7 +475,7 @@ mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock)
// set new flags
if (fcntl(dev->fd, F_SETFL, flags) < 0) {
syslog(LOG_ERR, "failed changing fd blocking state");
syslog(LOG_ERR, "uart%i: non_blocking: failed changing fd blocking state: %s", dev->index, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
@@ -477,11 +486,9 @@ const char*
mraa_uart_get_dev_path(mraa_uart_context dev)
{
if (!dev) {
syslog(LOG_ERR, "uart: get_device_path failed, context is NULL");
return NULL;
}
if (dev->path == NULL) {
syslog(LOG_ERR, "uart: device path undefined");
return NULL;
}
@@ -497,7 +504,7 @@ mraa_uart_read(mraa_uart_context dev, char* buf, size_t len)
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart: port is not open");
syslog(LOG_ERR, "uart%i: read: port is not open", dev->index);
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -513,7 +520,7 @@ mraa_uart_write(mraa_uart_context dev, const char* buf, size_t len)
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart: port is not open");
syslog(LOG_ERR, "uart%i: write: port is not open", dev->index);
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -524,12 +531,12 @@ mraa_boolean_t
mraa_uart_data_available(mraa_uart_context dev, unsigned int millis)
{
if (!dev) {
syslog(LOG_ERR, "uart: data_available: write context is NULL");
syslog(LOG_ERR, "uart: data_available: context is NULL");
return 0;
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart: port is not open");
syslog(LOG_ERR, "uart%i: data_available: port is not open", dev->index);
return 0;
}

View File

@@ -0,0 +1,7 @@
if (ONEWIRE)
message (STATUS "INFO - Adding onewire backend support")
set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
${PROJECT_SOURCE_DIR}/src/uart_ow/uart_ow.c
PARENT_SCOPE
)
endif ()

519
src/uart_ow/uart_ow.c Normal file
View File

@@ -0,0 +1,519 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Portions (search) copyright:
* Copyright (C) 2004 Dallas Semiconductor Corporation, All Rights Reserved.
*
* For the crc8 algorithm:
* Copyright (c) 2002 Colin O'Flynn
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include "uart.h"
#include "uart_ow.h"
#include "mraa_internal.h"
// low-level read byte
static mraa_result_t
_ow_read_byte(mraa_uart_ow_context dev, uint8_t *ch)
{
while (!mraa_uart_read(dev->uart, (char*) ch, 1))
;
return MRAA_SUCCESS;
}
// low-level write byte
static int
_ow_write_byte(mraa_uart_ow_context dev, const char ch)
{
return mraa_uart_write(dev->uart, &ch, 1);
}
// Here we setup a very simple termios with the minimum required
// settings. We use this to also change speed from high to low. We
// use the low speed (9600 bd) for emitting the reset pulse, and
// high speed (115200 bd) for actual data communications.
//
static mraa_result_t
_ow_set_speed(mraa_uart_ow_context dev, mraa_boolean_t speed)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: set_speed: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
static speed_t baud;
if (speed) {
baud = B115200;
}
else {
baud = B9600;
}
struct termios termio = {
.c_cflag = baud | CS8 | CLOCAL | CREAD, .c_iflag = 0, .c_oflag = 0, .c_lflag = NOFLSH, .c_cc = { 0 },
};
tcflush(dev->uart->fd, TCIFLUSH);
// TCSANOW is required
if (tcsetattr(dev->uart->fd, TCSANOW, &termio) < 0) {
syslog(LOG_ERR, "uart_ow: tcsetattr() failed");
return MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
// search state.
// Return 1 : device found, ROM number in ROM_NO buffer
// 0 : device not found, end of search
//
static mraa_boolean_t
_ow_search(mraa_uart_ow_context dev)
{
int id_bit_number;
int last_zero, rom_byte_number, search_result;
int id_bit, cmp_id_bit;
unsigned char rom_byte_mask, search_direction;
// initialize for search
id_bit_number = 1;
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
// if the last call was not the last device
if (!dev->LastDeviceFlag) {
// 1-Wire reset
if (mraa_uart_ow_reset(dev) != MRAA_SUCCESS) {
// reset the search
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
return 0;
}
// issue the search command
mraa_uart_ow_write_byte(dev, MRAA_UART_OW_CMD_SEARCH_ROM);
// loop to do the search
do {
// read a bit and its complement
id_bit = mraa_uart_ow_bit(dev, 1);
cmp_id_bit = mraa_uart_ow_bit(dev, 1);
// check for no devices on 1-wire
if ((id_bit == 1) && (cmp_id_bit == 1))
break;
else {
// all devices coupled have 0 or 1
if (id_bit != cmp_id_bit)
search_direction = id_bit; // bit write value for search
else {
// if this discrepancy if before the Last Discrepancy
// on a previous next then pick the same as last time
if (id_bit_number < dev->LastDiscrepancy)
search_direction = ((dev->ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
else
// if equal to last pick 1, if not then pick 0
search_direction = (id_bit_number == dev->LastDiscrepancy);
// if 0 was picked then record its position in LastZero
if (search_direction == 0) {
last_zero = id_bit_number;
// check for Last discrepancy in family
if (last_zero < 9)
dev->LastFamilyDiscrepancy = last_zero;
}
}
// set or clear the bit in the ROM byte rom_byte_number
// with mask rom_byte_mask
if (search_direction == 1)
dev->ROM_NO[rom_byte_number] |= rom_byte_mask;
else
dev->ROM_NO[rom_byte_number] &= ~rom_byte_mask;
// serial number search direction write bit
mraa_uart_ow_bit(dev, search_direction);
// increment the byte counter id_bit_number
// and shift the mask rom_byte_mask
id_bit_number++;
rom_byte_mask <<= 1;
// if the mask is 0 then go to new SerialNum byte
// rom_byte_number and reset
if (rom_byte_mask == 0) {
rom_byte_number++;
rom_byte_mask = 1;
}
}
} while (rom_byte_number < 8);
// loop until through all ROM bytes 0-7
// if the search was successful then
if (id_bit_number >= 65) {
// search successful so set
// LastDiscrepancy,LastDeviceFlag,search_result
dev->LastDiscrepancy = last_zero;
// check for last device
if (dev->LastDiscrepancy == 0)
dev->LastDeviceFlag = 1;
}
search_result = 1;
}
// if no device found then reset counters so next 'search' will be
// like a first
if (!search_result || !dev->ROM_NO[0]) {
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
search_result = 0;
}
return search_result;
}
//--------------------------------------------------------------------------
// Find the 'first' devices on the 1-Wire bus
// Return 1 : device found, ROM number in ROM_NO buffer
// 0 : no device present
//
static mraa_boolean_t
_ow_first(mraa_uart_ow_context dev)
{
// reset the search state
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
return _ow_search(dev);
}
//--------------------------------------------------------------------------
// Find the 'next' devices on the 1-Wire bus
// Return 1 : device found, ROM number in ROM_NO buffer
// 0 : device not found, end of search
//
static mraa_boolean_t
_ow_next(mraa_uart_ow_context dev)
{
// leave the search state alone
return _ow_search(dev);
}
// Start of exported mraa functionality
mraa_uart_ow_context
mraa_uart_ow_init(int index)
{
mraa_uart_ow_context dev = calloc(1, sizeof(struct _mraa_uart_ow));
if (!dev)
return NULL;
dev->uart = mraa_uart_init(index);
if (!dev->uart)
{
free(dev);
return NULL;
}
// now get the fd, and set it up for non-blocking operation
if (fcntl(dev->uart->fd, F_SETFL, O_NONBLOCK) == -1) {
syslog(LOG_ERR, "uart_ow: failed to set non-blocking on fd");
mraa_uart_ow_stop(dev);
return NULL;
}
return dev;
}
mraa_uart_ow_context
mraa_uart_ow_init_raw(const char* path)
{
mraa_uart_ow_context dev = calloc(1, sizeof(struct _mraa_uart_ow));
if (!dev)
return NULL;
dev->uart = mraa_uart_init_raw(path);
if (!dev->uart)
{
free(dev);
return NULL;
}
// now get the fd, and set it up for non-blocking operation
if (fcntl(dev->uart->fd, F_SETFL, O_NONBLOCK) == -1) {
syslog(LOG_ERR, "uart_ow: failed to set non-blocking on fd");
mraa_uart_ow_stop(dev);
return NULL;
}
return dev;
}
mraa_result_t
mraa_uart_ow_stop(mraa_uart_ow_context dev)
{
mraa_result_t rv = mraa_uart_stop(dev->uart);
free(dev);
return rv;
}
const char*
mraa_uart_ow_get_dev_path(mraa_uart_ow_context dev)
{
return mraa_uart_get_dev_path(dev->uart);
}
int
mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t bit)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: ow_bit: context is NULL");
return -1;
}
int ret = 0;
uint8_t ch;
if (bit) {
ret = _ow_write_byte(dev, 0xff); /* write a 1 bit */
}
else {
ret = _ow_write_byte(dev, 0x00); /* write a 0 bit */
}
/* return the bit present on the bus (0xff is a '1', anything else
* (typically 0xfc or 0x00) is a 0
*/
if (_ow_read_byte(dev, &ch) == -1 || ret == -1) {
return -1;
}
return (ch == 0xff);
}
int
mraa_uart_ow_write_byte(mraa_uart_ow_context dev, uint8_t byte)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: write_byte: context is NULL");
return -1;
}
/* writing bytes - each bit on the byte to send corresponds to a
* byte on the uart. At the same time, we read bits (uart bytes)
* from the bus and build a byte to return. This is possible due to
* the way we wire the UART TX/RX pins together, similar to a
* loopback connection, except the devices on the 1-wire bus have
* the ability to modify the returning bitstream.
*/
uint8_t bit;
int i;
for (i = 0; i < 8; i++) {
bit = mraa_uart_ow_bit(dev, byte & 0x01);
/* prep for next bit to send, and clear space for bit read */
byte >>= 1;
/* store read bit in the msb */
if (bit)
byte |= 0x80;
}
/* return the new byte read */
return byte;
}
int
mraa_uart_ow_read_byte(mraa_uart_ow_context dev)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: read_byte: context is NULL");
return -1;
}
/* we read by sending 0xff, so the bus is released on the initial
* low pulse (uart start bit) for every timeslot, when the device
* will then send it's bits
*/
return mraa_uart_ow_write_byte(dev, 0xff);
}
mraa_result_t
mraa_uart_ow_reset(mraa_uart_ow_context dev)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: reset: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
uint8_t rv;
/* To emit a proper reset pulse, we set low speed (9600 baud) for
* the reset pulse and send 0xf0 to pull the line down for the
* minimum amount of time.
*
* From the Maxim whitepaper:
*
* Transmitting an 0xF0 from the UART forms a proper Reset
* pulse. The receive value depends on whether one or more 1-Wire
* slave devices are present, their internal timing of each slave
* device present, and the UART's detection timing within each bit
* window. If no device is present, the receive value will equal the
* transmit value. Otherwise the receive value can vary.
*/
if (_ow_set_speed(dev, 0) != MRAA_SUCCESS) {
return MRAA_ERROR_INVALID_HANDLE;
}
/* pull the data line low */
_ow_write_byte(dev, 0xf0);
_ow_read_byte(dev, &rv);
/* back up to high speed for normal data transmissions */
if (_ow_set_speed(dev, 1) != MRAA_SUCCESS) {
return MRAA_ERROR_INVALID_HANDLE;
}
/* shorted data line */
if (rv == 0x00)
return MRAA_ERROR_UART_OW_SHORTED;
/* no devices detected (no presence pulse) */
if (rv == 0xf0)
return MRAA_ERROR_UART_OW_NO_DEVICES;
/* otherwise, at least one device is present */
return MRAA_SUCCESS;
}
mraa_result_t
mraa_uart_ow_rom_search(mraa_uart_ow_context dev, mraa_boolean_t start, uint8_t* id)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: rom_search: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
// bail if there aren't any devices, or some other error occurs
mraa_result_t rv;
if ((rv = mraa_uart_ow_reset(dev)) != MRAA_SUCCESS)
return rv;
mraa_boolean_t result;
// see if we are starting from scratch
if (start)
result = _ow_first(dev);
else
result = _ow_next(dev);
if (result) {
// found one. Copy into id and return 1
int i;
for (i = 0; i < MRAA_UART_OW_ROMCODE_SIZE; i++)
id[i] = dev->ROM_NO[i];
return MRAA_SUCCESS;
} else
return MRAA_ERROR_UART_OW_NO_DEVICES;
}
mraa_result_t
mraa_uart_ow_command(mraa_uart_ow_context dev, uint8_t command, uint8_t* id)
{
if (!dev) {
syslog(LOG_ERR, "uart_ow: ow_command: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
/* send reset pulse first */
mraa_result_t rv = mraa_uart_ow_reset(dev);
if (rv != MRAA_SUCCESS)
return rv;
if (id) {
/* send the match rom command */
mraa_uart_ow_write_byte(dev, MRAA_UART_OW_CMD_MATCH_ROM);
/* sending to a specific device, so send out the full romcode */
int i;
for (i = 0; i < MRAA_UART_OW_ROMCODE_SIZE; i++)
mraa_uart_ow_write_byte(dev, id[i]);
} else {
/* send to all devices (or a single device if it's the only one
* on the bus)
*/
mraa_uart_ow_write_byte(dev, MRAA_UART_OW_CMD_SKIP_ROM);
}
mraa_uart_ow_write_byte(dev, command);
return MRAA_SUCCESS;
}
uint8_t
mraa_uart_ow_crc8(uint8_t* buffer, uint16_t length)
{
// 0x18 = X ^ 8 + X ^ 5 + X ^ 4 + X ^ 0
static const uint8_t CRC8POLY = 0x18;
uint8_t crc = 0x00;
uint16_t loop_count;
uint8_t bit_counter;
uint8_t data;
uint8_t feedback_bit;
for (loop_count = 0; loop_count != length; loop_count++) {
data = buffer[loop_count];
bit_counter = 8;
do {
feedback_bit = (crc ^ data) & 0x01;
if (feedback_bit == 0x01)
crc = crc ^ CRC8POLY;
crc = (crc >> 1) & 0x7F;
if (feedback_bit == 0x01)
crc = crc | 0x80;
data = data >> 1;
bit_counter--;
} while (bit_counter > 0);
}
return crc;
}

View File

@@ -335,19 +335,22 @@ mraa_ftdi_ft4222_detect_io_expander()
if (mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9672_ADDR, &data, 1) == 1) {
gpio_expander_chip = IO_EXP_PCA9672;
return PCA9672_PINS;
} else if (mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, &data, 1) == 1) {
gpio_expander_chip = IO_EXP_PCA9555;
uint8_t reg = PCA9555_OUTPUT_REG;
mraa_ftdi_ft4222_i2c_write_internal(ftHandleI2c, PCA9555_ADDR, &reg, 1);
mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, (uint8_t*)&pca9555OutputValue, 2);
reg = PCA9555_DIRECTION_REG;
mraa_ftdi_ft4222_i2c_write_internal(ftHandleI2c, PCA9555_ADDR, &reg, 1);
mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, (uint8_t*)&pca9555DirectionValue, 2);
return PCA9555_PINS;
} else {
gpio_expander_chip = IO_EXP_NONE;
return 0;
uint8_t reg = PCA9555_INPUT_REG;
mraa_ftdi_ft4222_i2c_write_internal(ftHandleI2c, PCA9555_ADDR, &reg, 1);
if (mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, &data, 1) == 1) {
gpio_expander_chip = IO_EXP_PCA9555;
reg = PCA9555_OUTPUT_REG;
mraa_ftdi_ft4222_i2c_write_internal(ftHandleI2c, PCA9555_ADDR, &reg, 1);
mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, (uint8_t*)&pca9555OutputValue, 2);
reg = PCA9555_DIRECTION_REG;
mraa_ftdi_ft4222_i2c_write_internal(ftHandleI2c, PCA9555_ADDR, &reg, 1);
mraa_ftdi_ft4222_i2c_read_internal(ftHandleI2c, PCA9555_ADDR, (uint8_t*)&pca9555DirectionValue, 2);
return PCA9555_PINS;
}
}
gpio_expander_chip = IO_EXP_NONE;
return 0;
}
@@ -550,17 +553,17 @@ mraa_ftdi_ft4222_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return bytes_read;
}
static uint8_t
static int
mraa_ftdi_ft4222_i2c_read_byte(mraa_i2c_context dev)
{
uint8_t data;
pthread_mutex_lock(&ft4222_lock);
int bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
pthread_mutex_unlock(&ft4222_lock);
return bytes_read == 1 ? data : 0;
return bytes_read == 1 ? data : -1;
}
static uint8_t
static int
mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
uint8_t data;
@@ -570,10 +573,13 @@ mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
if (bytesWritten == 1)
bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
pthread_mutex_unlock(&ft4222_lock);
return (bytes_read == 1) ? data : 0;
if (bytes_read == 1) {
return (int) data;
}
return -1;
}
static uint16_t
static int
mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
uint8_t buf[2];
@@ -584,8 +590,10 @@ mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
if (bytes_written == 1)
bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, buf, 2);
pthread_mutex_unlock(&ft4222_lock);
data = (bytes_read == 2) ? *(uint16_t*)buf : 0;
return data;
if (bytes_read == 2) {
return (int) data;
}
return -1;
}
static int
@@ -600,7 +608,6 @@ mraa_ftdi_ft4222_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint
return bytes_read;
}
static mraa_result_t
mraa_ftdi_ft4222_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWrite)
{
@@ -618,7 +625,6 @@ mraa_ftdi_ft4222_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
return status;
}
static mraa_result_t
mraa_ftdi_ft4222_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
{

View File

@@ -504,7 +504,6 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode
value = 0;
break;
case MRAA_GPIO_HIZ:
return MRAA_SUCCESS;
break;
default:
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
@@ -812,7 +811,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
int pos = 0;
strncpy(b->pins[pos].name, "J17-1", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 182;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 2;
@@ -899,7 +898,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++;
strncpy(b->pins[pos].name, "J18-1", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 , 0};
b->pins[pos].gpio.pinmap = 13;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 1;
@@ -908,7 +907,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++;
strncpy(b->pins[pos].name, "J18-2", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 165;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -931,7 +930,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++;
strncpy(b->pins[pos].name, "J18-7", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 12;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 0;
@@ -940,7 +939,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++;
strncpy(b->pins[pos].name, "J18-8", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 183;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 3;
@@ -1275,8 +1274,9 @@ mraa_intel_edison_fab_c()
}
if (mraa_gpio_read_dir(tristate, &tristate_dir) != MRAA_SUCCESS) {
free(b->adv_func);
goto error;
free(b->pins);
free(b->adv_func);
goto error;
}
if (tristate_dir != MRAA_GPIO_OUT) {
@@ -1296,7 +1296,10 @@ mraa_intel_edison_fab_c()
b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[0].gpio.pinmap = 130;
b->pins[0].gpio.parent_id = 0;
b->pins[0].gpio.mux_total = 0;
b->pins[0].gpio.mux_total = 1;
b->pins[0].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[0].gpio.mux[0].pin = 216;
b->pins[0].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[0].uart.pinmap = 0;
b->pins[0].uart.parent_id = 0;
b->pins[0].uart.mux_total = 0;
@@ -1305,37 +1308,52 @@ mraa_intel_edison_fab_c()
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[1].gpio.pinmap = 131;
b->pins[1].gpio.parent_id = 0;
b->pins[1].gpio.mux_total = 0;
b->pins[1].gpio.mux_total = 1;
b->pins[1].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[1].gpio.mux[0].pin = 217;
b->pins[1].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[1].uart.pinmap = 0;
b->pins[1].uart.parent_id = 0;
b->pins[1].uart.mux_total = 0;
strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[2].gpio.pinmap = 128;
b->pins[2].gpio.parent_id = 0;
b->pins[2].gpio.mux_total = 0;
b->pins[2].gpio.mux_total = 1;
b->pins[2].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[2].gpio.mux[0].pin = 218;
b->pins[2].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[3].gpio.pinmap = 12;
b->pins[3].gpio.parent_id = 0;
b->pins[3].gpio.mux_total = 0;
b->pins[3].gpio.mux_total = 1;
b->pins[3].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[3].gpio.mux[0].pin = 219;
b->pins[3].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[3].pwm.pinmap = 0;
b->pins[3].pwm.parent_id = 0;
b->pins[3].pwm.mux_total = 0;
strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 129;
b->pins[4].gpio.parent_id = 0;
b->pins[4].gpio.mux_total = 0;
b->pins[4].gpio.mux_total = 1;
b->pins[4].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[4].gpio.mux[0].pin = 220;
b->pins[4].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[5].gpio.pinmap = 13;
b->pins[5].gpio.parent_id = 0;
b->pins[5].gpio.mux_total = 0;
b->pins[5].gpio.mux_total = 1;
b->pins[5].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[5].gpio.mux[0].pin = 221;
b->pins[5].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[5].pwm.pinmap = 1;
b->pins[5].pwm.parent_id = 0;
b->pins[5].pwm.mux_total = 0;
@@ -1344,28 +1362,40 @@ mraa_intel_edison_fab_c()
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].gpio.pinmap = 182;
b->pins[6].gpio.parent_id = 0;
b->pins[6].gpio.mux_total = 0;
b->pins[6].gpio.mux_total = 1;
b->pins[6].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[6].gpio.mux[0].pin = 222;
b->pins[6].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[6].pwm.pinmap = 2;
b->pins[6].pwm.parent_id = 0;
b->pins[6].pwm.mux_total = 0;
strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 48;
b->pins[7].gpio.parent_id = 0;
b->pins[7].gpio.mux_total = 0;
b->pins[7].gpio.mux_total = 1;
b->pins[7].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[7].gpio.mux[0].pin = 223;
b->pins[7].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 49;
b->pins[8].gpio.parent_id = 0;
b->pins[8].gpio.mux_total = 0;
b->pins[8].gpio.mux_total = 1;
b->pins[8].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[8].gpio.mux[0].pin = 224;
b->pins[8].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 183;
b->pins[9].gpio.parent_id = 0;
b->pins[9].gpio.mux_total = 0;
b->pins[9].gpio.mux_total = 1;
b->pins[9].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[9].gpio.mux[0].pin = 225;
b->pins[9].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[9].pwm.pinmap = 3;
b->pins[9].pwm.parent_id = 0;
b->pins[9].pwm.mux_total = 0;
@@ -1374,131 +1404,223 @@ mraa_intel_edison_fab_c()
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[10].gpio.pinmap = 41;
b->pins[10].gpio.parent_id = 0;
b->pins[10].gpio.mux_total = 2;
b->pins[10].gpio.mux[0].pin = 263;
b->pins[10].gpio.mux[0].value = 1;
b->pins[10].gpio.mux[1].pin = 240;
b->pins[10].gpio.mux[1].value = 0;
b->pins[10].gpio.mux_total = 3;
b->pins[10].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[10].gpio.mux[0].pin = 226;
b->pins[10].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[10].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[10].gpio.mux[1].pin = 263;
b->pins[10].gpio.mux[1].value = 1;
b->pins[10].gpio.mux[2].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[10].gpio.mux[2].pin = 240;
b->pins[10].gpio.mux[2].value = 0;
b->pins[10].spi.pinmap = 5;
b->pins[10].spi.mux_total = 2;
b->pins[10].spi.mux[0].pin = 263;
b->pins[10].spi.mux[0].value = 1;
b->pins[10].spi.mux[1].pin = 240;
b->pins[10].spi.mux_total = 3;
b->pins[10].spi.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[10].spi.mux[0].pin = 226;
b->pins[10].spi.mux[0].value = MRAA_GPIO_IN;
b->pins[10].spi.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[10].spi.mux[1].pin = 263;
b->pins[10].spi.mux[1].value = 1;
b->pins[10].spi.mux[2].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[10].spi.mux[2].pin = 240;
b->pins[10].spi.mux[2].value = 1;
strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[11].gpio.pinmap = 43;
b->pins[11].gpio.parent_id = 0;
b->pins[11].gpio.mux_total = 2;
b->pins[11].gpio.mux[0].pin = 262;
b->pins[11].gpio.mux[0].value = 1;
b->pins[11].gpio.mux[1].pin = 241;
b->pins[11].gpio.mux[1].value = 0;
b->pins[11].gpio.mux_total = 3;
b->pins[11].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[11].gpio.mux[0].pin = 227;
b->pins[11].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[11].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[11].gpio.mux[1].pin = 262;
b->pins[11].gpio.mux[1].value = 1;
b->pins[11].gpio.mux[2].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[11].gpio.mux[2].pin = 241;
b->pins[11].gpio.mux[2].value = 0;
b->pins[11].spi.pinmap = 5;
b->pins[11].spi.mux_total = 2;
b->pins[11].spi.mux[0].pin = 262;
b->pins[11].spi.mux[0].value = 1;
b->pins[11].spi.mux[1].pin = 241;
b->pins[11].spi.mux_total = 3;
b->pins[11].spi.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[11].spi.mux[0].pin = 227;
b->pins[11].spi.mux[0].value = MRAA_GPIO_IN;
b->pins[10].spi.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[11].spi.mux[1].pin = 262;
b->pins[11].spi.mux[1].value = 1;
b->pins[10].spi.mux[2].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[11].spi.mux[2].pin = 241;
b->pins[11].spi.mux[2].value = 1;
strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[12].gpio.pinmap = 42;
b->pins[12].gpio.parent_id = 0;
b->pins[12].gpio.mux_total = 1;
b->pins[12].gpio.mux[0].pin = 242;
b->pins[12].gpio.mux[0].value = 0;
b->pins[12].gpio.mux_total = 2;
b->pins[12].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[12].gpio.mux[0].pin = 228;
b->pins[12].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[12].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[12].gpio.mux[1].pin = 242;
b->pins[12].gpio.mux[1].value = 0;
b->pins[12].spi.pinmap = 5;
b->pins[12].spi.mux_total = 1;
b->pins[12].spi.mux[0].pin = 242;
b->pins[12].spi.mux[0].value = 1;
b->pins[12].spi.mux_total = 2;
b->pins[12].spi.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[12].spi.mux[0].pin = 228;
b->pins[12].spi.mux[0].value = MRAA_GPIO_IN;
b->pins[12].spi.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[12].spi.mux[1].pin = 242;
b->pins[12].spi.mux[1].value = 1;
strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[13].gpio.pinmap = 40;
b->pins[13].gpio.parent_id = 0;
b->pins[13].gpio.mux_total = 1;
b->pins[13].gpio.mux[0].pin = 243;
b->pins[13].gpio.mux[0].value = 0;
b->pins[13].gpio.mux_total = 2;
b->pins[13].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[13].gpio.mux[0].pin = 229;
b->pins[13].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[13].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[13].gpio.mux[1].pin = 243;
b->pins[13].gpio.mux[1].value = 0;
b->pins[13].spi.pinmap = 5;
b->pins[13].spi.mux_total = 1;
b->pins[13].spi.mux[0].pin = 243;
b->pins[13].spi.mux[0].value = 1;
b->pins[13].spi.mux_total = 2;
b->pins[13].spi.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[13].spi.mux[0].pin = 229;
b->pins[13].spi.mux[0].value = MRAA_GPIO_IN;
b->pins[13].spi.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[13].spi.mux[1].pin = 243;
b->pins[13].spi.mux[1].value = 1;
strncpy(b->pins[14].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].aio.pinmap = 0;
b->pins[14].aio.mux_total = 1;
b->pins[14].aio.mux[0].pin = 200;
b->pins[14].aio.mux[0].value = 1;
b->pins[14].aio.mux_total = 2;
b->pins[14].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[14].aio.mux[0].pin = 208;
b->pins[14].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[14].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[14].aio.mux[1].pin = 200;
b->pins[14].aio.mux[1].value = 1;
b->pins[14].gpio.pinmap = 44;
b->pins[14].gpio.mux_total = 1;
b->pins[14].gpio.mux[0].pin = 200;
b->pins[14].gpio.mux[0].value = 0;
b->pins[14].gpio.mux_total = 2;
b->pins[14].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[14].gpio.mux[0].pin = 208;
b->pins[14].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[14].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[14].gpio.mux[1].pin = 200;
b->pins[14].gpio.mux[1].value = 0;
strncpy(b->pins[15].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].aio.pinmap = 1;
b->pins[15].aio.mux_total = 1;
b->pins[15].aio.mux[0].pin = 201;
b->pins[15].aio.mux[0].value = 1;
b->pins[15].aio.mux_total = 2;
b->pins[15].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[15].aio.mux[0].pin = 209;
b->pins[15].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[15].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[15].aio.mux[1].pin = 201;
b->pins[15].aio.mux[1].value = 1;
b->pins[15].gpio.pinmap = 45;
b->pins[15].gpio.mux_total = 1;
b->pins[15].gpio.mux[0].pin = 201;
b->pins[15].gpio.mux[0].value = 0;
b->pins[15].gpio.mux_total = 2;
b->pins[15].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[15].gpio.mux[0].pin = 209;
b->pins[15].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[15].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[15].gpio.mux[1].pin = 201;
b->pins[15].gpio.mux[1].value = 0;
strncpy(b->pins[16].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].aio.pinmap = 2;
b->pins[16].aio.mux_total = 1;
b->pins[16].aio.mux[0].pin = 202;
b->pins[16].aio.mux[0].value = 1;
b->pins[16].aio.mux_total = 2;
b->pins[16].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[16].aio.mux[0].pin = 210;
b->pins[16].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[16].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[16].aio.mux[1].pin = 202;
b->pins[16].aio.mux[1].value = 1;
b->pins[16].gpio.pinmap = 46;
b->pins[16].gpio.mux_total = 1;
b->pins[16].gpio.mux[0].pin = 202;
b->pins[16].gpio.mux[0].value = 0;
b->pins[16].gpio.mux_total = 2;
b->pins[16].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[16].gpio.mux[0].pin = 210;
b->pins[16].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[16].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[16].gpio.mux[1].pin = 202;
b->pins[16].gpio.mux[1].value = 0;
strncpy(b->pins[17].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].aio.pinmap = 3;
b->pins[17].aio.mux_total = 1;
b->pins[17].aio.mux[0].pin = 203;
b->pins[17].aio.mux[0].value = 1;
b->pins[17].aio.mux_total = 2;
b->pins[17].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[17].aio.mux[0].pin = 211;
b->pins[17].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[17].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[17].aio.mux[1].pin = 203;
b->pins[17].aio.mux[1].value = 1;
b->pins[17].gpio.pinmap = 47;
b->pins[17].gpio.mux_total = 1;
b->pins[17].gpio.mux[0].pin = 203;
b->pins[17].gpio.mux[0].value = 0;
b->pins[17].gpio.mux_total = 2;
b->pins[17].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[17].gpio.mux[0].pin = 211;
b->pins[17].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[17].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[17].gpio.mux[1].pin = 203;
b->pins[17].gpio.mux[1].value = 0;
strncpy(b->pins[18].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[18].i2c.pinmap = 1;
b->pins[18].i2c.mux_total = 1;
b->pins[18].i2c.mux[0].pin = 204;
b->pins[18].i2c.mux[0].value = 0;
b->pins[18].i2c.mux_total = 2;
b->pins[18].i2c.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].i2c.mux[0].pin = 212;
b->pins[18].i2c.mux[0].value = MRAA_GPIO_IN;
b->pins[18].i2c.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[18].i2c.mux[1].pin = 204;
b->pins[18].i2c.mux[1].value = 0;
b->pins[18].aio.pinmap = 4;
b->pins[18].aio.mux_total = 1;
b->pins[18].aio.mux[0].pin = 204;
b->pins[18].aio.mux[0].value = 1;
b->pins[18].aio.mux_total = 2;
b->pins[18].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].aio.mux[0].pin = 212;
b->pins[18].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[18].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[18].aio.mux[1].pin = 204;
b->pins[18].aio.mux[1].value = 1;
b->pins[18].gpio.pinmap = 14;
b->pins[18].gpio.mux_total = 1;
b->pins[18].gpio.mux[0].pin = 204;
b->pins[18].gpio.mux[0].value = 0;
b->pins[18].gpio.mux_total = 2;
b->pins[18].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].gpio.mux[0].pin = 212;
b->pins[18].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[18].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[18].gpio.mux[1].pin = 204;
b->pins[18].gpio.mux[1].value = 0;
strncpy(b->pins[19].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[19].i2c.pinmap = 1;
b->pins[19].i2c.mux_total = 1;
b->pins[19].i2c.mux[0].pin = 205;
b->pins[19].i2c.mux[0].value = 0;
b->pins[19].i2c.mux_total = 2;
b->pins[19].i2c.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].i2c.mux[0].pin = 213;
b->pins[19].i2c.mux[0].value = MRAA_GPIO_IN;
b->pins[19].i2c.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[19].i2c.mux[1].pin = 205;
b->pins[19].i2c.mux[1].value = 0;
b->pins[19].aio.pinmap = 5;
b->pins[19].aio.mux_total = 1;
b->pins[19].aio.mux[0].pin = 205;
b->pins[19].aio.mux[0].value = 1;
b->pins[19].aio.mux_total = 2;
b->pins[18].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].aio.mux[0].pin = 213;
b->pins[18].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[18].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[19].aio.mux[1].pin = 205;
b->pins[19].aio.mux[1].value = 1;
b->pins[19].gpio.pinmap = 165;
b->pins[19].gpio.mux_total = 1;
b->pins[19].gpio.mux[0].pin = 205;
b->pins[19].gpio.mux[0].value = 0;
b->pins[19].gpio.mux_total = 2;
b->pins[19].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].gpio.mux[0].pin = 213;
b->pins[19].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[19].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[19].gpio.mux[1].pin = 205;
b->pins[19].gpio.mux[1].value = 0;
// BUS DEFINITIONS
b->i2c_bus_count = 9;
@@ -1569,7 +1691,8 @@ mraa_intel_edison_fab_c()
pinmodes[6].pwm.sysfs = 182;
pinmodes[6].pwm.mode = 1;
// 7 and 8 are provided by something on i2c, very simplepinmodes[3].gpio.sysfs = 12;
// 7 and 8 are provided by something on i2c, very simple
pinmodes[9].gpio.sysfs = 183;
pinmodes[9].gpio.mode = 0;
pinmodes[9].pwm.sysfs = 183;
@@ -1594,7 +1717,9 @@ mraa_intel_edison_fab_c()
pinmodes[13].gpio.mode = 0;
pinmodes[13].spi.sysfs = 109; // Different pin provides, switched at mux level.
pinmodes[13].spi.mode = 1;
// Everything else but A4 A5 LEAVE
pinmodes[18].gpio.sysfs = 14;
pinmodes[18].gpio.mode = 0;
pinmodes[18].i2c.sysfs = 28;

View File

@@ -371,14 +371,14 @@ mraa_intel_galileo_gen2()
b->pins[1].uart.mux[2].value = 0;
strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 0, 0, 0 };
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 0, 0, 0, 0};
b->pins[2].gpio.pinmap = 13;
b->pins[2].gpio.parent_id = 0;
b->pins[2].gpio.mux_total = 2;
b->pins[2].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[2].gpio.mux[0].pin = 35;
b->pins[2].gpio.mux[0].value = MRAA_GPIO_IN;
b->pins[2].gpio.mux[0].pincmd = PINCMD_SET_VALUE;
b->pins[2].gpio.mux[1].pincmd = PINCMD_SET_VALUE;
b->pins[2].gpio.mux[1].pin = 77;
b->pins[2].gpio.mux[1].value = 0;
b->pins[2].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
@@ -402,7 +402,7 @@ mraa_intel_galileo_gen2()
b->pins[2].mmap.bit_pos = 5;
strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 0, 0, 0 };
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 0, 0, 0, 0 };
b->pins[3].gpio.pinmap = 14;
b->pins[3].gpio.parent_id = 0;
b->pins[3].gpio.mux_total = 3;
@@ -454,7 +454,7 @@ mraa_intel_galileo_gen2()
b->pins[3].mmap.bit_pos = 6;
strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 6;
b->pins[4].gpio.parent_id = 0;
b->pins[4].gpio.mux_total = 1;
@@ -465,7 +465,7 @@ mraa_intel_galileo_gen2()
b->pins[4].gpio.output_enable = 36;
strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 , 0 };
b->pins[5].gpio.pinmap = 0;
b->pins[5].gpio.parent_id = 0;
b->pins[5].gpio.mux_total = 2;
@@ -491,7 +491,7 @@ mraa_intel_galileo_gen2()
b->pins[5].pwm.mux[2].value = 0;
strncpy(b->pins[6].name, "IO6", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].gpio.pinmap = 1;
b->pins[6].gpio.parent_id = 0;
b->pins[6].gpio.mux_total = 2;
@@ -517,7 +517,7 @@ mraa_intel_galileo_gen2()
b->pins[6].pwm.mux[2].value = 0;
strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 38;
b->pins[7].gpio.parent_id = 0;
b->pins[7].gpio.mux_total = 1;
@@ -527,7 +527,7 @@ mraa_intel_galileo_gen2()
b->pins[7].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 40;
b->pins[8].gpio.parent_id = 0;
b->pins[8].gpio.mux_total = 1;
@@ -537,7 +537,7 @@ mraa_intel_galileo_gen2()
b->pins[8].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 4;
b->pins[9].gpio.parent_id = 0;
b->pins[9].gpio.mux_total = 2;
@@ -563,7 +563,7 @@ mraa_intel_galileo_gen2()
b->pins[9].pwm.mux[2].value = 0;
strncpy(b->pins[10].name, "IO10", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 1, 0, 0 };
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 1, 0, 0, 0 };
b->pins[10].gpio.pinmap = 10;
b->pins[10].gpio.parent_id = 0;
b->pins[10].gpio.mux_total = 2;
@@ -617,7 +617,7 @@ mraa_intel_galileo_gen2()
b->pins[10].spi.mux[2].value = 0;
strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0 };
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 0 };
b->pins[11].gpio.pinmap = 5;
b->pins[11].gpio.parent_id = 0;
b->pins[11].gpio.mux_total = 3;
@@ -663,7 +663,7 @@ mraa_intel_galileo_gen2()
b->pins[11].spi.mux[3].value = 0;
strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 1, 0, 0 };
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 1, 0, 0, 0 };
b->pins[12].gpio.pinmap = 15;
b->pins[12].gpio.parent_id = 0;
b->pins[12].gpio.mux_total = 1;
@@ -696,7 +696,7 @@ mraa_intel_galileo_gen2()
b->pins[12].mmap.bit_pos = 7;
strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0 };
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[13].gpio.pinmap = 7;
b->pins[13].gpio.parent_id = 0;
b->pins[13].gpio.mux_total = 2;
@@ -722,7 +722,7 @@ mraa_intel_galileo_gen2()
// ANALOG
strncpy(b->pins[14].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[14].aio.pinmap = 0;
b->pins[14].aio.mux_total = 2;
@@ -739,7 +739,7 @@ mraa_intel_galileo_gen2()
b->pins[14].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[15].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[15].aio.pinmap = 1;
b->pins[15].aio.mux_total = 2;
@@ -756,7 +756,7 @@ mraa_intel_galileo_gen2()
b->pins[15].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[16].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[16].aio.pinmap = 2;
b->pins[16].aio.mux_total = 2;
@@ -773,7 +773,7 @@ mraa_intel_galileo_gen2()
b->pins[16].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[17].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[17].aio.pinmap = 3;
b->pins[17].aio.mux_total = 2;
@@ -790,7 +790,7 @@ mraa_intel_galileo_gen2()
b->pins[17].gpio.mux[0].value = MRAA_GPIO_IN;
strncpy(b->pins[18].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1 };
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[18].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[18].i2c.pinmap = 1;
b->pins[18].i2c.mux_total = 3;
@@ -827,7 +827,7 @@ mraa_intel_galileo_gen2()
b->pins[18].gpio.mux[2].value = 1;
strncpy(b->pins[19].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1 };
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[19].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[19].i2c.pinmap = 1;
b->pins[19].i2c.mux_total = 3;

View File

@@ -126,8 +126,8 @@ mraa_intel_nuc5()
}
b->i2c_bus_count++;
b->i2c_bus[i].bus_id = i2c_num;
b->i2c_bus[i].sda = 12 + i;
b->i2c_bus[i].scl = 13 + i;
b->i2c_bus[i].sda = 12 + (i*2);
b->i2c_bus[i].scl = 13 + (i*2);
}
if (b->i2c_bus_count > 0) {

View File

@@ -9,12 +9,17 @@ if (BUILDSWIGJAVA)
endif()
if (BUILDSWIGPYTHON)
add_test (NAME py_general COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
if (PYTHON2INTERP_FOUND)
set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python2")
elseif (PYTHON3INTERP_FOUND)
set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python3")
endif ()
add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
add_test (NAME py_platform COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
add_test (NAME py_gpio COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
endif()