Compare commits

...

23 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
48 changed files with 1136 additions and 224 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

@@ -75,7 +75,6 @@ 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)
@@ -109,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)
@@ -202,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

@@ -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
*/

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.
@@ -293,6 +293,19 @@ mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char*
*/
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);
}
@@ -309,4 +309,22 @@ 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

@@ -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

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

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
@@ -91,7 +105,7 @@ class Pwm
* 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,9 +193,9 @@ class Pwm
return (Result) mraa_pwm_enable(m_pwm, enable);
}
/**
* Get the maximum pwm period in us
* Get the maximum PWM period in us
*
* @return max pwm in us
* @return max PWM period in us
*/
int
max_period()
@@ -189,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

@@ -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
*/

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
*/

View File

@@ -62,9 +62,17 @@ extern "C" {
#include <stdio.h>
#include "common.h"
#include "uart.h"
/* for now, we simply use the normal MRAA UART context */
typedef struct _uart* mraa_uart_ow_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;

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

@@ -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

@@ -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

@@ -193,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)

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

@@ -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)

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

@@ -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;
@@ -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;
@@ -675,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;
@@ -1073,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,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

@@ -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

@@ -40,17 +40,11 @@
#include "uart_ow.h"
#include "mraa_internal.h"
// global search state
static unsigned char ROM_NO[8]; /* 8 byte (64b) rom code */
static int LastDiscrepancy;
static int LastFamilyDiscrepancy;
static mraa_boolean_t LastDeviceFlag;
// low-level read byte
static mraa_result_t
_ow_read_byte(mraa_uart_ow_context dev, uint8_t *ch)
{
while (!mraa_uart_read(dev, (char*) ch, 1))
while (!mraa_uart_read(dev->uart, (char*) ch, 1))
;
return MRAA_SUCCESS;
@@ -60,7 +54,7 @@ _ow_read_byte(mraa_uart_ow_context dev, uint8_t *ch)
static int
_ow_write_byte(mraa_uart_ow_context dev, const char ch)
{
return mraa_uart_write(dev, &ch, 1);
return mraa_uart_write(dev->uart, &ch, 1);
}
// Here we setup a very simple termios with the minimum required
@@ -69,7 +63,7 @@ _ow_write_byte(mraa_uart_ow_context dev, const char ch)
// high speed (115200 bd) for actual data communications.
//
static mraa_result_t
_ow_set_speed(mraa_uart_context dev, mraa_boolean_t speed)
_ow_set_speed(mraa_uart_ow_context dev, mraa_boolean_t speed)
{
if (!dev) {
@@ -89,10 +83,10 @@ _ow_set_speed(mraa_uart_context dev, mraa_boolean_t speed)
.c_cflag = baud | CS8 | CLOCAL | CREAD, .c_iflag = 0, .c_oflag = 0, .c_lflag = NOFLSH, .c_cc = { 0 },
};
tcflush(dev->fd, TCIFLUSH);
tcflush(dev->uart->fd, TCIFLUSH);
// TCSANOW is required
if (tcsetattr(dev->fd, TCSANOW, &termio) < 0) {
if (tcsetattr(dev->uart->fd, TCSANOW, &termio) < 0) {
syslog(LOG_ERR, "uart_ow: tcsetattr() failed");
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -121,13 +115,13 @@ _ow_search(mraa_uart_ow_context dev)
search_result = 0;
// if the last call was not the last device
if (!LastDeviceFlag) {
if (!dev->LastDeviceFlag) {
// 1-Wire reset
if (mraa_uart_ow_reset(dev) != MRAA_SUCCESS) {
// reset the search
LastDiscrepancy = 0;
LastDeviceFlag = 0;
LastFamilyDiscrepancy = 0;
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
return 0;
}
@@ -150,26 +144,26 @@ _ow_search(mraa_uart_ow_context dev)
else {
// if this discrepancy if before the Last Discrepancy
// on a previous next then pick the same as last time
if (id_bit_number < LastDiscrepancy)
search_direction = ((ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
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 == LastDiscrepancy);
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)
LastFamilyDiscrepancy = last_zero;
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)
ROM_NO[rom_byte_number] |= rom_byte_mask;
dev->ROM_NO[rom_byte_number] |= rom_byte_mask;
else
ROM_NO[rom_byte_number] &= ~rom_byte_mask;
dev->ROM_NO[rom_byte_number] &= ~rom_byte_mask;
// serial number search direction write bit
mraa_uart_ow_bit(dev, search_direction);
@@ -192,21 +186,21 @@ _ow_search(mraa_uart_ow_context dev)
if (id_bit_number >= 65) {
// search successful so set
// LastDiscrepancy,LastDeviceFlag,search_result
LastDiscrepancy = last_zero;
dev->LastDiscrepancy = last_zero;
// check for last device
if (LastDiscrepancy == 0)
LastDeviceFlag = 1;
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 || !ROM_NO[0]) {
LastDiscrepancy = 0;
LastDeviceFlag = 0;
LastFamilyDiscrepancy = 0;
if (!search_result || !dev->ROM_NO[0]) {
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
search_result = 0;
}
@@ -222,9 +216,9 @@ static mraa_boolean_t
_ow_first(mraa_uart_ow_context dev)
{
// reset the search state
LastDiscrepancy = 0;
LastDeviceFlag = 0;
LastFamilyDiscrepancy = 0;
dev->LastDiscrepancy = 0;
dev->LastDeviceFlag = 0;
dev->LastFamilyDiscrepancy = 0;
return _ow_search(dev);
}
@@ -246,13 +240,20 @@ _ow_next(mraa_uart_ow_context dev)
mraa_uart_ow_context
mraa_uart_ow_init(int index)
{
mraa_uart_ow_context dev = mraa_uart_init(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->fd, F_SETFL, O_NONBLOCK) == -1) {
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;
@@ -264,13 +265,19 @@ mraa_uart_ow_init(int index)
mraa_uart_ow_context
mraa_uart_ow_init_raw(const char* path)
{
mraa_uart_ow_context dev = mraa_uart_init_raw(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->fd, F_SETFL, O_NONBLOCK) == -1) {
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;
@@ -282,13 +289,15 @@ mraa_uart_ow_init_raw(const char* path)
mraa_result_t
mraa_uart_ow_stop(mraa_uart_ow_context dev)
{
return mraa_uart_stop(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);
return mraa_uart_get_dev_path(dev->uart);
}
int
@@ -438,7 +447,7 @@ mraa_uart_ow_rom_search(mraa_uart_ow_context dev, mraa_boolean_t start, uint8_t*
// found one. Copy into id and return 1
int i;
for (i = 0; i < MRAA_UART_OW_ROMCODE_SIZE; i++)
id[i] = ROM_NO[i];
id[i] = dev->ROM_NO[i];
return MRAA_SUCCESS;
} else

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;
}

View File

@@ -811,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;
@@ -898,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;
@@ -907,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++;
@@ -930,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;
@@ -939,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;
@@ -1274,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) {
@@ -1316,7 +1317,7 @@ mraa_intel_edison_fab_c()
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 = 1;
@@ -1325,7 +1326,7 @@ mraa_intel_edison_fab_c()
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 = 1;
@@ -1337,7 +1338,7 @@ mraa_intel_edison_fab_c()
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 = 1;
@@ -1370,7 +1371,7 @@ mraa_intel_edison_fab_c()
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 = 1;
@@ -1379,7 +1380,7 @@ mraa_intel_edison_fab_c()
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 = 1;

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()