Compare commits

...

60 Commits

Author SHA1 Message Date
Brendan Le Foll
b8d73738bd imraa: split some more
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
39c9187f6d imraa.io.conf: Imraa IO configuration
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
0397d8399e intel_edison_fab_c.c: don't undo muxing if we don't own the pin
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
ab4e0cc0a1 mraa.c: add error if adding a MRAA_GENERIC_FIRMATA subplat and not supported
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
1a1fa776fd gpio.c: Remove use of sprintf in favour of snprintf
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
1d13668a26 imraa: Add argp support, split arduino functionality
This commit gets us closer to what was intended for imraa, support of setting
sysfs user permissions

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
884afe7820 firmata_curie_imu.c: Fix warning due to signed nature of function input buffer
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
15b053b484 firmata: Add pthread spin locks around uart operations
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
bb5ec8bd10 firmata: Remove all 6.2.x warnings
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 12:56:20 +01:00
Brendan Le Foll
a3c717553c cmake: enable INSTALLTOOLS by default
This means mraa-i2c and mraa-gpio are installed in <prefix>/bin by default

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-26 11:55:19 +01:00
Mihai Tudor Panu
6ce1b1c4ce python: remove temporary RPATH from _mraa.so when installing
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:15:29 +01:00
Alex Tereschenko
9f03afbcbc mock: implement UART functionality
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:04:04 +01:00
Alex Tereschenko
8a9efd1bcc uart.c: add replace functions used by mock
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:04:04 +01:00
Alex Tereschenko
1b3a9371a1 uart.c: rework mraa_uart_init_raw to use common cleanup block
This will align it with spi.c and make it easier to introduce
a replace function.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:04:04 +01:00
Alex Tereschenko
ccc4185eff uart.hpp: fix typo in setNonBlocking() function name
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:04:04 +01:00
Alex Tereschenko
6fda865af7 uart.hpp: fix typo in write() description
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:04:04 +01:00
Brendan Le Foll
dd33a32744 README.md: Fix typo in README.md
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:03:23 +01:00
Joseph Butler
7d1ee0c6fe README.MD: Fix ubuntu instructions to update repo
Signed-off-by: Joseph Butler <joseph.butler@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-25 12:02:17 +01:00
Brendan Le Foll
19791be2f5 CONTRIBUTING.md: Add author rules and suggestion on filing issues for feature review
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-24 11:36:22 +01:00
Brendan Le Foll
49ef1623b2 python: Move docs to depend on BUILDPYTHON2 to not build with py3
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 15:21:06 +01:00
Brendan Le Foll
37deb5003b mraa: Update to v1.4.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 14:44:36 +01:00
Brendan Le Foll
980dfce80e mraa.c: return MRAA_SUCCESS when trying to call mraa_add_subplatform twice
If we already have a subplatform present with the same type, return success
when trying to add it again. We don't check that the tty is the same because
that is hidden inside the t_firmata* structure but we should do at some point

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 13:58:40 +01:00
Brendan Le Foll
08e270818a firmata_mraa.c: Clean up for loops with useless statements
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:49:36 +01:00
Brendan Le Foll
6bac8594a5 mraa.c: Remove unused variables in mraa_add_from_lockfile
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:49:12 +01:00
Brendan Le Foll
11bbd05533 mraa.c: Add MRAA_SUCCESS return to mraa_remove_subplatform
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:48:47 +01:00
Brendan Le Foll
1d4b19dc4b mraa.c: Move firmata syslog message to useful location
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:48:23 +01:00
Brendan Le Foll
02a7fbf191 imraa.c: Remove unused variables
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:47:26 +01:00
Brendan Le Foll
ae15b10997 types.h: Remove tabs that crept in
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-10-11 08:38:09 +01:00
SaschaWeisenberger
be22844922 src/x86/x86.c: add support for Siemens SIMATIC IOT2000
The Siemens device "SIMATIC IOT2000" is identical to the Intel Galileo
Gen 2 regarding the gpios. So if the board name is "SIMATIC IOT2000"
treat the board as if it is Galileo Gen 2.

Signed-off-by: Sascha Weisenberger sascha.weisenberger@siemens.com
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-27 13:08:44 +01:00
Thomas Ingleby
92fdb8aa01 README: Update PPA instructions
Fixes #581

Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
2016-09-21 23:50:28 +03:00
Stefan Andritoiu
def454e33c java: Renamed pom.xml file to the standard naming convention
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-14 15:17:58 +01:00
Brendan Le Foll
122cab1f1e cmake: Add lots of fancy warnings to CC/CXX and make cmake check they exist
Thanks to Dan Liew for cmake work in fpbench that this is copied from

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-13 11:45:49 +01:00
Brendan Le Foll
6c85b61daa mraa: Fix compiler warnings unused vars and useless statements
Should have 0 functionality effect, just cleans up a few things. Fixes #577

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-13 11:20:41 +01:00
Alex Tereschenko
139d42d084 FindNodejs.cmake: added search paths for Ubuntu 16.04
Closes #566.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-12 12:24:24 +01:00
Stefan Andritoiu
8e38c762f0 java: Added automatic pom.xml file creation in CMake
This is to add mraa package in a Maven repo

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-12 12:23:18 +01:00
Jon Trulson
590f733ff9 uart_ow: convert static const int MRAA_UART_OW_ROMCODE_SIZE to #define
This is needed so that this value can be used in all places in C (and
C++) code.  Unlike C++ you can't always use a static const int
variable to declare an array size for example.  Trying to do so will
yield compiler errors.

In addition, during the declaration of the uart_ow_context, replace a
hardcoded '8' with this macro.  Originally, the '8' was hardcoded for
this very reason.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-12 12:21:46 +01:00
Brendan Le Foll
045ceb084f grossetete.md: Add documentation for uart
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-07 13:51:58 +01:00
Brendan Le Foll
ff3b3004da intel_gt_tuchuck.c: Add SPI to joule pinmap file
This commit fixes documentation for SPI bus to match latest changes in pinmap
file

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-07 13:51:32 +01:00
Brendan Le Foll
5cb2bd220e spi.hpp: Add documentation to raw mode constructor
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-07 13:27:07 +01:00
Brendan Le Foll
8ec4fcb333 intel_galileo_rev_g.c: use pincmd to set OUT_HIGH instead of value
The i/o expander looses connection as soon as direction is set so use direction
OUT_HIGH instead of setting value after direction. Closes #573

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-02 12:00:29 +01:00
Brendan Le Foll
bf2a504774 firmata_mraa.c: retry counter should not be decremented past 0
This means the retry counter works appropriately in case of failure. Closes #574

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-09-02 11:49:26 +01:00
Brendan Le Foll
9bc91f4b12 docs/joule: Rename docs to use joule naming
This also adds the 2 LEDs on the 8260 radio to the mapping

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 16:06:31 +01:00
Brendan Le Foll
6180ddaa8e README.md: update mraa instructions
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 16:03:30 +01:00
Brendan Le Foll
8a93351f0e building.md: Update building docs
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 15:53:39 +01:00
Brendan Le Foll
1591b92605 python2/cmake: Remove unused pydocs target
Pydocs has been deprecated in favour of sphinx as it's really very very ugly

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 15:43:23 +01:00
Brendan Le Foll
22b0f63238 cmake: Remove dirty tag on compilation from non git tree
This is removed to make building in buildsystems like ubuntu's or yocto's
easier. Bugs reported from old versions haven't been that annoying so this is
probably be ok

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 15:00:10 +01:00
Brendan Le Foll
2832909856 mraa: Update to v1.3.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 13:03:47 +01:00
Alex Tereschenko
636c9feb4f travis: add builds for mock
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 12:32:20 +01:00
Alex Tereschenko
0292c960b3 mock SPI: remove loop variable declarations
While working fine on my Fedora 22, under Travis (and Ubuntu)
that fails asking to enable C99 standard first, so let's be conservative.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 12:32:20 +01:00
Alex Tereschenko
9ff47aa64a mock SPI: correct error message to actually use data provided
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 12:32:20 +01:00
Houman Brinjcargorabi
a704a956ea raspberry_pi.c: Added support for pi zero
Signed-off-by: Houman Brinjcargorabi <hbrinjcar@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 12:30:56 +01:00
Brendan Le Foll
94b7477212 intel_gt_tuchuck.c: Make sure GPIOs are set to 0 muxes
Use calloc for pinsize and set mux_total to 0 in all gpios

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 12:26:36 +01:00
Brendan Le Foll
1589389c3f intel_gt_tuchuck.c: LED101 reset to GPIO338
A bios change to 395 was never made so this broke LED101

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-30 11:40:32 +01:00
Alex Tereschenko
bdbbfd03dd mraa mock: Add SPI functionality
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 16:00:53 +01:00
Alex Tereschenko
9030ae2eeb spi.c: added replace functions for all basic actions
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 16:00:53 +01:00
Alex Tereschenko
3a638caf01 spi.c: added context validity checks
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 16:00:53 +01:00
Alex Tereschenko
07f6181c91 mock_board_i2c.c: removed surplus includes
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 16:00:53 +01:00
Houman Brinjcargorabi
0630c5f505 jsonplatform.md: Added documentation
Signed-off-by: Houman Brinjcargorabi <hbrinjcar@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 15:59:53 +01:00
Houman Brinjcargorabi
4277a3ee23 mraa.c: Replaced string values with #defines
Signed-off-by: Houman Brinjcargorabi <hbrinjcar@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 15:46:39 +01:00
Jon Trulson
c976e9f982 gpio.h: remove extraneous extern C declaration
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-19 15:45:08 +01:00
82 changed files with 2889 additions and 655 deletions

View File

@@ -10,6 +10,10 @@ env:
- JSONPLAT=true NODE012=true
- JSONPLAT=true NODE4=true
- JSONPLAT=true NODE5=true
- MOCK=true NODE010=true
- MOCK=true NODE012=true
- MOCK=true NODE4=true
- MOCK=true NODE5=true
# node010 npm builds don't work in clang and anyone using npm should want to
# use something newer
- NPM=true NODE4=true
@@ -26,6 +30,7 @@ before_script:
# 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 [ "${JSONPLAT}" ]; then export JSONPLAT=ON; else export JSONPLAT=OFF; fi
- if [ "${MOCK}" ]; then export BUILDARCH="MOCK"; else export BUILDARCH=""; fi
- if [ "${NODE010}" ]; then nvm install 0.10; fi
- if [ "${NODE012}" ]; then nvm install 0.12; fi
- if [ "${NODE4}" ]; then nvm install 4.1; fi
@@ -34,8 +39,8 @@ before_script:
# Handle 0.10 NODE_ROOT_DIR differently than other versions
- wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && ./configure --prefix=/home/travis/ && make && make install && cd ..
script:
- echo "CC=$CC BUILDJAVA=$BUILDJAVA JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
- echo "CC=$CC BUILDJAVA=$BUILDJAVA BUILDARCH=$BUILDARCH JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DBUILDARCH="$BUILDARCH" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
# simple test to see if we can load our node module
- if [ ${NPM} ]; then cd build/Release/obj.target/ && node -e "var m = require('./mraa.node'); m.getVersion()";fi
addons:

View File

@@ -1,10 +1,70 @@
cmake_minimum_required (VERSION 2.8)
project (mraa C)
project (mraa C CXX)
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 ")
###############################################################################
# Detect supported warning flags
# Modified from work By Dan Liew (fpbench - MIT)
# https://github.com/delcypher/fp-bench/blob/master/CMakeLists.txt
###############################################################################
# Warnings for both the C and C++ compiler
set (MRAA_BOTH_WARNING_FLAGS
-Wall
-Werror=main
-Wformat
-Wmain
-Wuninitialized
-Winit-self
)
# Warning flags for the C compiler only
set (MRAA_C_WARNING_FLAGS
-Werror=implicit
-Werror=missing-parameter-type
)
# Warning flags for the C++ compiler only
set (MRAA_CXX_WARNING_FLAGS
-Wnon-virtual-dtor
-Woverloaded-virtual
-Wreorder
)
include (CheckCCompilerFlag)
include (CheckCXXCompilerFlag)
function (MRAA_SANITIZE_FLAG_NAME OUTPUT_VAR FLAG)
string (REPLACE "-" "_" SANITIZED_FLAG_NAME "${FLAG}")
string (REPLACE "/" "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
string (REPLACE "=" "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
string (REPLACE " " "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
set (${OUTPUT_VAR} "${SANITIZED_FLAG_NAME}" PARENT_SCOPE)
endfunction ()
# Globally set C compiler warning flags that are supported and emit
# a warning about unsupported flags
foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_C_WARNING_FLAGS})
MRAA_SANITIZE_FLAG_NAME(SANITIZED_FLAG_NAME "${flag}")
CHECK_C_COMPILER_FLAG("${flag}" HAS_C_${SANITIZED_FLAG_NAME})
if (HAS_C_${SANITIZED_FLAG_NAME})
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
else ()
message (WARNING "C compiler does not support flag \"${flag}\"")
endif ()
endforeach ()
# Globally set C++ compiler warning flags that are supported and emit
# a warning about unsupported flags
foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_CXX_WARNING_FLAGS})
MRAA_SANITIZE_FLAG_NAME (SANITIZED_FLAG_NAME "${flag}")
CHECK_CXX_COMPILER_FLAG ("${flag}" HAS_CXX_${SANITIZED_FLAG_NAME})
if (HAS_CXX_${SANITIZED_FLAG_NAME})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
else ()
message (WARNING "C++ compiler does not support flag \"${flag}\"")
endif ()
endforeach ()
# Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)
@@ -31,7 +91,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 "v1.2.3-dirty")
set (VERSION "v1.4.0")
endif ()
message (STATUS "INFO - libmraa Version ${VERSION}")
@@ -78,7 +138,7 @@ option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (ENABLEEXAMPLES "Disable building of examples" ON)
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
option (INSTALLTOOLS "Install all tools" OFF)
option (INSTALLTOOLS "Install all tools" ON)
option (BUILDTESTS "Override the addition of tests" ON)
set (BUILDARCH "" CACHE STRING "Override architecture to build for")

View File

@@ -10,7 +10,8 @@ with:
The recommended method to contribute is to fork on github, and then send pull
requests to the main project. You can open issues if you find any bugs/have
questions.
questions. If you want to work on a large feature then we suggest you file an
issue first so we can avoid dissapointments come merging time!
If you'd rather not use github you are more than welcome to send git formatted
patches to our mailing list mraa@lists.01.org which you can register for access
@@ -42,6 +43,16 @@ job. Few exceptions to coding styles:
Use common sense and don't be afraid to challenge something if it doesn't make sense!
Author Rules
------------
If you create a file, then add yourself as the Author at the top. If you did a
large contribution to it (or if you want to ;-)), then fee free to add yourself
to the contributors list in that file. You can also add your own copyright
statement to the file but cannot add a license of your own. If you're borrowing
code that comes from a project with another license, make sure to explicitly
note this in your PR.
Code signing
------------

View File

@@ -29,12 +29,12 @@ X86
* [Minnowboard Max](../master/docs/minnow_max.md)
* [NUC 5th generation](../master/docs/intel_nuc5.md)
* [UP](../master/docs/up.md)
* [Intel Grosse Tete](../master/docs/grossetete.md)
* [Intel Joule](../master/docs/grossetete.md)
ARM
---
* [Raspberry Pi](../master/docs/raspberry_pi.md)
* [Bannana Pi](../master/docs/banana_pi.md)
* [Banana Pi](../master/docs/banana_pi.md)
* [Beaglebone Black](../master/docs/beaglebone.md)
USB
@@ -45,15 +45,57 @@ Mock
----
* [Generic simulated board](../master/docs/mock.md)
JSON platform
----
* [Platform loading](../master/docs/jsonplatform.md)
Installing on your board
========
========================
Installing on Ubuntu
--------------------
Here is a PPA for installing on ubuntu:
https://launchpad.net/~mraa/+archive/ubuntu/mraa
```bash
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libmraa1 libmraa-dev mraa-tools python-mraa python3-mraa
```
Node.js package is available seperately.
Install on Arch Linux
---------------------
There is an AUR package for mraa here: https://aur.archlinux.org/packages/mraa
Installing for Node.js only
---------------------------
You can also install just the node.js mraa module by using npm. You will need a
C++ compiler and the node development headers, however it's not required to
have SWIG installed.
```bash
npm install mraa
```
Note that installing mraa in this way builds mraa without json-c so you cannot
use mraa_init_json_platform(). Also building this way means the mraa.node
includes a static version of libmraa rather than relying on a dynamic library
in /usr/lib.
Installing on Intel 32bit Yocto based opkg image
------------------------------------------------
See the section below on compiling or use our repository to install on a glibc
based yocto poky image that supports opkg. Adding this repository is as simple
as and you'll have the latest stable tagged build of mraa installed!
``` bash
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg install mraa
```
@@ -62,19 +104,11 @@ If you would like to get the latest & greatest builds from master HEAD you can
use our -dev repository
```bash
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg install mraa
```
You can also install just the node.js mraa module by using npm. You will need a
C++ compiler and the node development headers, however it's not required to
have SWIG installed.
```bash
npm install mraa
```
Compiling
=========

View File

@@ -46,9 +46,7 @@ extern "C" {
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
#include <jni.h>
extern "C" {
void mraa_java_isr_callback(void *args);
}
void mraa_java_isr_callback(void *args);
#endif
/**

View File

@@ -70,6 +70,12 @@ class Spi
}
}
/**
* Initialise SPI object using 'raw' mode. Mraa will go and grab the spidev device lablled /dev/spidev<bus>.<cs>
*
* @param bus to use
* @param cs to use
*/
Spi(int bus, int cs)
{
m_spi = mraa_spi_init_raw(bus, cs);

View File

@@ -240,11 +240,11 @@ typedef enum {
} mraa_i2c_mode_t;
typedef enum {
MRAA_UART_PARITY_NONE = 0,
MRAA_UART_PARITY_EVEN = 1,
MRAA_UART_PARITY_ODD = 2,
MRAA_UART_PARITY_MARK = 3,
MRAA_UART_PARITY_SPACE = 4
MRAA_UART_PARITY_NONE = 0,
MRAA_UART_PARITY_EVEN = 1,
MRAA_UART_PARITY_ODD = 2,
MRAA_UART_PARITY_MARK = 3,
MRAA_UART_PARITY_SPACE = 4
} mraa_uart_parity_t;
#ifdef __cplusplus

View File

@@ -124,7 +124,7 @@ class Uart
}
/**
* Write bytes in String object to a device
* Write bytes in char* buffer to a device
*
* @param data buffer pointer
* @param length maximum size of buffer
@@ -263,7 +263,7 @@ class Uart
* @return Result of operation
*/
Result
SetNonBlocking(bool nonblock)
setNonBlocking(bool nonblock)
{
return (Result) mraa_uart_set_non_blocking(m_uart, nonblock);
}

View File

@@ -64,19 +64,19 @@ extern "C" {
#include "common.h"
#include "uart.h"
/* 8 bytes (64 bits) for a device rom code */
#define MRAA_UART_OW_ROMCODE_SIZE 8
/* 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 */
unsigned char ROM_NO[MRAA_UART_OW_ROMCODE_SIZE]; /* 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
*/

View File

@@ -23,13 +23,16 @@ if (UV_ROOT_DIR)
endif()
# Now look for node. Flag an error if not found
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
if (NODE_ROOT_DIR)
add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/src)
add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
else()
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found")

View File

@@ -11,13 +11,14 @@ what you'll need:
* [SWIG](http://swig.org) 3.0.5+
* [git](http://git-scm.com)
* [python](http://python.org) 2.7 or 3.4+ (you'll need not just the interpreter but python-dev)
* [node.js](http://nodejs.org) 0.10.x or 0.12.x (you'll need not just the interpreter but nodejs-dev)
* [node.js](http://nodejs.org) 4.x recommended (you'll need not just the interpreter but nodejs-dev)
* [CMake](http://cmake.org) 2.8.8+ (3.1+ is recommended for node.js version 2+)
* [json-c](https://github.com/json-c/json-c) 0.12+ (0.10+ probably works in reality)
For Debian-like distros the below command installs the basic set:
```bash
sudo apt-get install git build-essential swig3.0 python-dev nodejs-dev cmake
sudo apt-get install git build-essential swig3.0 python-dev nodejs-dev cmake libjson-c-dev
```
To build the documentation you'll also need:
@@ -52,8 +53,9 @@ Currently our install logic puts Python bindings into standard paths, which
do not work on Debian due to their
[policy](http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html#s-paths).
We are working on a permanent solution, in the meanwhile please use this command
after `make install` to link installed modules where Debian's Python expects them:
We are working on a permanent solution, in the meantime please use this command
after `make install` to link installed modules where Debian's Python expects
them:
```bash
sudo ln -s <your install prefix, e.g. /usr>/lib/python2.7/site-packages/* /usr/lib/python2.7/dist-packages
@@ -91,30 +93,32 @@ Disabling Python module building:
Building doc, this will require [SPHINX](http://sphinx-doc.org) &
[Doxygen](http://doxygen.org):
`-DBUILDDOC=ON`
You will also require clone git submodules from your existing checkout:
`git submodule update --init --recursive`
The from doxygen2jsdoc dir:
`npm install mkdirp commander lodash bluebird pegjs`
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`
You can also enable -Wall for gcc before running cmake by exporting your wanted
CC flags to the CC env var
`export CC="gcc -Wall"`
## Dependencies continued
You'll need at least SWIG version 3.0.2 and we recommend 3.0.5 to build the
JavaScript & Python modules. If your version of SWIG is older than this then
please see above for disabling `SWIGNODE`. Otherwise you will get a weird build
failure when building the JavaScript module. The Python module builds with SWIG
2.x.
2.x but we don't test it.
During the build, we'll assume you're building from git, note that if you
compile with `git` installed your version of mraa will be tagged `-dirty`. This
simply means `git` wasn't installed or that you where building from a tarball.
You can modify `build/src/version.c` before running `make` if this is incorrect.
The instructions listed here all assume that `build/` is an empty dir that lives
inside the cloned repository of mraa.
If you have multiple versions of Python then mraa can get confused, we
recommend using virtualenv to select which version of Python you want. We test
2.7 the most but SWIG will generate valid 3.x Python code but we do not
generally support building both at once.
compile with `git` installed your version of mraa will be versioned with `git
desribe --tag` to make it easy for intentification. You can easily modify
version.c in build/src. If you don't build from a git tree then you will simply
have a version which matches the latest released version of mraa.
## Using a Yocto/OE toolchain
@@ -131,7 +135,6 @@ make
## Using Coverity
Static analysis is routinely performed using Coverity on libmraa's codebase.
This is the procedure to submit a build to Coverity. You'll need to install
`coverity-submit` for your OS.

View File

@@ -5,6 +5,20 @@ 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.4.0**
* Add support for Siemens SIMATIC IOT2000
* Cmake now enables much more error detection depending on compiler support
* Mraa Maven packages now enabled
* Galileo Gen2 AIO fix using pincmd
* Adding an already added firmata platform now returns MRAA_SUCCESS
* Cmake no longer tags builds without git as '-dirty' version.c for easier
packaging support
**1.3.0**
* Fix GT GPIO bugs
* Mock SPI and travis now uses mock and tests it
* RPI zero support
**1.2.3**
* Revert 1.2.1 binding.gyp changed that had side effect of enabling JSONPLAT in mraa.c
* improve travis.ci to load mraa.node as compiled from make npmpkg target

View File

@@ -1,7 +1,7 @@
Grosse Tete {#grossetete}
Intel Joule {#grossetete}
===========
The Grosse Tete with the Tuchuck board is supported by Mraa
The Joule Board with the daughterboard (Tuchuck) board is supported by Mraa
Revision Support
----------------
@@ -10,10 +10,33 @@ Tuchuck
Interface notes
---------------
**SPI** Currently not working
**SPI**
Two SPI buses are available, with one chipselect each. Pins listed are MRAA
numbered pins. Other chip selects are available if enabled in BIOS/EEPROM but
cannot be enabled as BIOS options. You will need the spidev kernel module
loaded, Ostro-XT does this by default.
Bus 0 (32765)
MOSI = 2
MISO = 4
CS = 6
CLK = 10
Bus 1 (32766)
MOSI = 67
MISO = 69
CS0 = 59
CS1 = 61
CLK = 65
(remove 40 from numbers to get pin header number for pins on low speed header
2)
**UART** Some pins are labelled as UARTs but are not configured in BIOS as UART
so only available UART is on the FTDI header
so only available UART is on the FTDI header. Disable the getty on ttyS2 and
use mraa's uart raw mode to initialise on ttyS2. The Jumper J8 can be used to
switch between using the FTDI 6 pin header and the micro USB output.
Pin Mapping
-----------
@@ -24,15 +47,15 @@ LEDs are numbered from 100-103.
| MRAA Number | Physical Pin | Function |
|-------------|--------------|----------|
| 1 | GPIO | GPIO |
| 2 | SPP1RX | GPIO |
| 2 | SPP1RX | GPIO SPI |
| 3 | PMICRST | NONE |
| 4 | SPP1TX | GPIO |
| 4 | SPP1TX | GPIO SPI |
| 5 | 19.2mhz | GPIO |
| 6 | SPP1FS0 | GPIO |
| 6 | SPP1FS0 | GPIO SPI |
| 7 | UART0TX | GPIO |
| 8 | SPP1FS2 | GPIO |
| 8 | SPP1FS2 | GPIO SPI |
| 9 | PWRGD | NONE |
| 10 | SPP1CLK | GPIO |
| 10 | SPP1CLK | GPIO SPI |
| 11 | I2C0SDA | I2C |
| 12 | I2S1SDI | GPIO |
| 13 | I2C0SCL | I2C |
@@ -81,17 +104,17 @@ LEDs are numbered from 100-103.
| 56 | CAMERA | NONE |
| 57 | PANEL | GPIO |
| 58 | CAMERA | NONE |
| 59 | SPP0FS0 | GPIO |
| 59 | SPP0FS0 | GPIO SPI |
| 60 | CAMERA | NONE |
| 61 | SPP0FS1 | GPIO |
| 61 | SPP0FS1 | GPIO SPI |
| 62 | SPI_DAT | SPI |
| 63 | SPP0FS2 | GPIO |
| 64 | SPICLKB | GPIO SPI |
| 65 | SPP0FS3 | GPIO |
| 66 | SPICLKA | GPIO SPI |
| 67 | SPP0TX | GPIO |
| 63 | SPP0FS2 | GPIO SPI |
| 64 | SPICLKB | GPIO |
| 65 | SPP0FS3 | GPIO SPI |
| 66 | SPICLKA | GPIO |
| 67 | SPP0TX | GPIO SPI |
| 68 | UART0RX | GPIO UART|
| 69 | SPP0RX | GPIO |
| 69 | SPP0RX | GPIO SPI |
| 70 | UART0RT | GPIO UART|
| 71 | I2C1SDA | GPIO I2C |
| 72 | UART0CT | GPIO UART|
@@ -107,6 +130,8 @@ LEDs are numbered from 100-103.
| 101 | LED101 | GPIO |
| 102 | LED102 | GPIO |
| 103 | LED103 | GPIO |
| 104 | LEDWIFI | GPIO |
| 105 | LEDBT | GPIO |
To see a live pin mapping use the command:
$ mraa-gpio list

View File

@@ -30,7 +30,6 @@ make
After you've built mraa you can install using `make install`.
## Running Imraa
Before being able to use mraa to program the Arduino101 you will need to run
imraa to flash the sketch file onto the board. The sketch file that imraa will
look for is located here: [Arduino101 Sketch](http://iotdk.intel.com/misc/ConfigurableFirmataCurieImu.ino.bin).

127
docs/jsonplatform.md Normal file
View File

@@ -0,0 +1,127 @@
JSON platform {#jsonplat}
=============
JSON platform loading allows libmraa users who work with **simple** and unsupported
boards to create JSON configuration files which libmraa understands, allowing
libmraa to just 'work' with the unsupported platform. JSON platform **does not work**
with boards which require advanced functions which overwrite default functionality or
boards that require the mux functionality.
Syntax
------
The JSON file that libmraa reads needs specific values to be set by default, they
are required in every JSON file intended to be used to load the platform.
The keywords are case sensitive so be aware when writing the JSON file.
Each heading is a top level key in the JSON file, each key's type is Array
### platform
|Key |Type |Required |Description |
|-------------|-------|-----------|-----------------------------------------------|
|id |int |no | An ID that can be assigned |
|name |string |yes | The platform name |
|pin_count |int |yes | The total pin count |
|gpio_count |int |no | The subset of pincount which able to do GPIO |
|i2c_count |int |no | The number of usable I2C ports |
|aio_count |int |no | The number of usable AIO ports |
|spi_count |int |no | The number of usable SPI ports |
|uart_count |int |no | The total UART ports |
|pwmDefPeriod |int |no | The default PWM period |
|pwmMaxPeriod |int |no | The max PWM period |
|pwmMinPeriod |int |no | The min PWM period |
### layout
**THIS INDEX'S THE PIN ARRAY**
Each available pin specified using pin_count requires a label. There is no need to use an
index identifier as the json objects are indexed as they are read, starting with the first
json object being treated as index 0.
The number of json objects in layout should be equal to the pin_count.
|Key |Type |Required |Description |
|-----------|-------|-----------|-----------------------------------------------|
|label |string |yes | The label used to describe the pin |
|invalid |boolean|no | Sets the labeled pin as an invalid pin |
### GPIO
**THIS INDEX'S THE PIN ARRAY**
For the supported GPIO pins here is where we set the raw linux pin it needs to use, the
index cannot exceed the total pin_count and the number of JSON ojects cannot exceed the
gpio_count total. The index is also used to set the specified pin's capabilities. Each set
of keys should be enclosed in a json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|-------------------------------------|
|index |int |yes | used to index the pin array |
|rawpin |int |yes | used to reference the actual IO pin |
### I2C
**THIS INDEX'S THE I2C ARRAY**
This is used to setup the I2C functionality. The total number of json objects and the index
cannot exceed the i2c_count. Each set of keys should be enclosed in a json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|-------------------------------------|
|index |int |yes | Used to index the I2C array |
|rawpin |int |yes | The sysfs pin |
|sclpin |int |no | The clock pin |
|sdapin |int |no | The data pin |
|default |boolean|no | Sets the default I2C device used |
### AIO
**THIS INDEX'S THE PIN ARRAY**
This is used to setup which pins are able to perform AIO. Each set of keys should be
enclosed in a json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|-------------------------------------|
|index |int |yes | Used to index the pin array |
|rawpin |int |yes | The sysfs pin |
### PWM
**THIS INDEX'S THE PIN ARRAY**
This is used to setup which IO pins can do PWM Each set of keys should be enclosed in a
json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|-------------------------------|
|index |int |yes | Used to index the pin array |
|rawpin |int |yes | The sysfs pin |
|chipID |int |yes | The parent ID |
## SPI
**THIS INDEX'S THE SPI ARRAY**
This is used to setup the SPI functionality. The total number of json objects and the index
cannot exceed the spi_count. Each set of keys should be enclosed in a json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|--------------------------------------------|
|index |int |yes | The index into the SPI array |
|chipID |int |yes | The parent ID |
|clock |int |no | The clock used for transmissions |
|miso |int |no | Pin used for incoming data from the slave |
|mosi |int |no | Pin used for outgoing data from the master |
|chipselect |int |no | Pin used to select the slave device |
|default |boolean|no | Sets the default SPI device |
### UART
**THIS INDEX'S THE UART ARRAY**
This is used to setup the UART functionality. The total number of json objects and the index
cannot exceed the uart_count. Each set of keys should be enclosed in a json object.
|Key |Type |Required |Description |
|-----------|-------|-----------|-----------------------------------------|
|index |int |yes | Used to index the UART array |
|chipID |int |yes | Parent ID |
|rawpin |int |yes | Sysfs pin |
|rx |int |no | Read pin |
|tx |int |no | Transmit pin |
|path |string |yes | Used to talk to a connected UART device |
|default |boolean|no | Sets the default UART device |

View File

@@ -19,6 +19,12 @@ Right now we simulate a single generic board with:
which can be read or written in bytes or words (big-endian). Technically those
registers are just an array of `uint8_t`, so you can treat them as 10 single-byte
registers or 5 single-word ones or a mix thereof.
* Single SPI bus with one Chip Select. All write functions are supported, received
data items (words or bytes) are calculated from the sent ones using
`sent_byte (or word) XOR constant` formula.
See [SPI mock header](../include/mock/mock_board_spi.h#L38-L39) for constant values.
* Single UART port. All functions are supported, but many are simple stubs. Write
always succeeds, read returns 'Z' symbol as many times as `read()` requested.
We plan to develop it further and all [contributions](../CONTRIBUTING.md) are more than welcome.
@@ -30,6 +36,12 @@ See the table below for pin layout and features
| 1 | ADC0 | AIO pin, returns random value on read |
| 2 | I2C0SDA | SDA pin for I2C0 bus |
| 3 | I2C0SCL | SCL pin for I2C0 bus |
| 4 | SPI0CS | CS pin for SPI0 bus |
| 5 | SPI0MOSI | MOSI pin for SPI0 bus |
| 6 | SPI0MISO | MISO pin for SPI0 bus |
| 7 | SPI0SCLK | SCLK pin for SPI0 bus |
| 8 | UART0RX | RX pin for UART0 port |
| 9 | UART0TX | TX pin for UART0 port |
Building
--------

View File

@@ -49,6 +49,7 @@ main()
value = 0.0f;
}
float output = mraa_pwm_read(pwm);
printf("PWM value is %f\n", output);
}
//! [Interesting]
return 0;

View File

@@ -56,7 +56,7 @@ main()
mraa_firmata_response(firm, interrupt);
uint8_t* buffer = calloc(4, 0);
char* buffer = calloc(4, 0);
if (buffer == NULL) {
free(firm);
return EXIT_FAILURE;

View File

@@ -55,7 +55,7 @@ interrupt(char* data)
mraa_iio_channel* channels = mraa_iio_get_channels(iio_device0);
int i = 0;
for (i; i < mraa_iio_get_channel_count(iio_device0); i++) {
for (; i < mraa_iio_get_channel_count(iio_device0); i++) {
if (channels[i].enabled) {
printf("channel %d - bytes %d\n", channels[i].index, channels[i].bytes);
switch (channels[i].bytes) {

View File

@@ -144,7 +144,6 @@ i2c_set_exit:
void
i2c_detect_devices(int bus)
{
mraa_result_t status = MRAA_SUCCESS;
mraa_i2c_context i2c = mraa_i2c_init(bus);
if (i2c == NULL) {
return;

View File

@@ -33,7 +33,6 @@ main(int argc, char** argv)
//! [Interesting]
mraa_spi_context spi;
spi = mraa_spi_init(0);
unsigned int response = 0;
printf("Hello, SPI initialised\n");
uint8_t data[] = { 0x00, 100 };
uint8_t* recv;

View File

@@ -1,10 +1,11 @@
add_executable (imraa imraa.c)
add_executable (imraa imraa.c imraa_arduino.c imraa_io.c imraa_lock.c)
include_directories (${PROJECT_SOURCE_DIR}/api)
include_directories (${PROJECT_SOURCE_DIR}/include)
include_directories (${PROJECT_SOURCE_DIR}/api/mraa)
include_directories (${PROJECT_SOURCE_DIR}/imraa)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
find_package (JSON-C REQUIRED)
include_directories (${JSON-C_INCLUDE_DIR})

View File

@@ -1,7 +1,7 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Longwei Su <lsu@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -29,395 +29,23 @@
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <json-c/json.h>
#include <libudev.h>
#include <error.h>
#include <sys/types.h>
#include <mraa/uart.h>
#include <mraa/gpio.h>
#include <mraa/i2c.h>
#include <mraa/pwm.h>
#include <json-c/json.h>
#include <argp.h>
#include <mraa_internal.h>
#include <imraa_arduino.h>
#include <imraa_io.h>
#include <imraa_lock.h>
#define IMRAA_CONF_FILE "/etc/imraa.conf"
typedef struct mraa_io_objects_t {
const char* type;
int index;
bool raw;
const char* label;
} mraa_io_objects_t;
const char*
imraa_list_serialport()
{
struct udev* udev;
struct udev_enumerate* enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct udev_device* dev;
const char* ret = NULL;
udev = udev_new();
if (!udev) {
printf("Can't create udev, check libudev\n");
exit(1);
}
enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "tty");
udev_enumerate_add_match_property(enumerate, "ID_VENDOR_ID", "8087");
udev_enumerate_add_match_property(enumerate, "ID_MODEL_ID", "0ab6");
// udev_enumerate_add_match_property(enumerate, "ID_SERIAL",
// "Intel_ARDUINO_101_AE6642SQ55000RS");
udev_enumerate_scan_devices(enumerate);
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices)
{
const char* path;
path = udev_list_entry_get_name(dev_list_entry);
dev = udev_device_new_from_syspath(udev, path);
ret = udev_device_get_devnode(dev);
}
udev_enumerate_unref(enumerate);
udev_unref(udev);
if (ret) {
printf("Ardunio 101 Device Node Path: %s\n", ret);
} else {
printf("Can't detect any Ardunio 101 Device on tty\n");
}
return ret;
}
mraa_result_t
imraa_reset_arduino(const char* modem)
{
mraa_uart_context uart;
uart = mraa_uart_init_raw(modem);
mraa_uart_set_baudrate(uart, 1200);
if (uart == NULL) {
fprintf(stderr, "UART failed to setup\n");
return MRAA_ERROR_UNSPECIFIED;
}
mraa_uart_stop(uart);
mraa_deinit();
return MRAA_SUCCESS;
}
int
imraa_flash_101(const char* bin_path, const char* bin_file_name, const char* tty)
{
if (imraa_reset_arduino(tty) != MRAA_SUCCESS) {
fprintf(stderr, "Failed to reset arduino on %s for unknown reason, carrying on...\n", tty);
}
char* ln = NULL;
size_t len = 0;
bool board_found = false;
const char* dfu_list = "/dfu-util -d ,8087:0ABA -l";
size_t bin_path_len = strlen(bin_path);
char* full_dfu_list = (char*) calloc((bin_path_len + strlen(dfu_list) + 1), sizeof(char));
if (!full_dfu_list) {
printf("imraa_flash_101 can't allocate string buffer for dfu list\n");
exit(1);
}
strncat(full_dfu_list, bin_path, strlen(bin_path));
strncat(full_dfu_list, dfu_list, strlen(dfu_list));
int i;
// dfu list is still needed, as the time for reset and recognized is varies from platform to
// platform.
// once dfu able to query available devices, then it is ready to flash
for (i = 0; i < 10 && board_found == false; i++) {
printf("Waiting for device...\n");
// dfu-util -d,8087:0ABA -l
FILE* dfu_result = popen(full_dfu_list, "r");
if (dfu_result == NULL) {
printf("Failed to run command\n");
exit(1);
}
if (i == 4) {
printf("Flashing is taking longer than expected\n");
printf("Try pressing MASTER_RESET button\n");
}
while (getline(&ln, &len, dfu_result) != -1) {
if (strstr(ln, "sensor_core")) {
board_found = true;
printf("Device found!\n");
break;
}
}
sleep(1);
if (pclose(dfu_result) != 0) {
printf("Failed to close command\n");
exit(1);
}
}
free(ln);
if (board_found == false) {
printf("ERROR: Device is not responding.\n");
exit(1);
}
const char* dfu_upload = "/dfu-util -d ,8087:0ABA -D ";
const char* dfu_option = " -v -a 7 -R";
int buffersize = bin_path_len + strlen(dfu_upload) + strlen(bin_file_name) + strlen(dfu_option) + 1;
char* full_dfu_upload = calloc(buffersize, sizeof(char));
if (!full_dfu_upload) {
printf("imraa_flash_101 can't allocate string buffer for dfu flash\n");
exit(1);
}
strncat(full_dfu_upload, bin_path, strlen(bin_path));
strncat(full_dfu_upload, dfu_upload, strlen(dfu_upload));
strncat(full_dfu_upload, bin_file_name, strlen(bin_file_name));
strncat(full_dfu_upload, dfu_option, strlen(dfu_option));
printf("flash cmd: %s\n", full_dfu_upload);
int status = system(full_dfu_upload);
if (status != 0) {
printf("ERROR: Upload failed on %s\n", tty);
exit(1);
}
printf("SUCCESS: Sketch will execute in about 5 seconds.\n");
free(full_dfu_list);
free(full_dfu_upload);
sleep(5);
return 0;
}
void
imraa_write_lockfile(const char* lock_file_location, const char* serialport)
{
FILE* fh;
char str[10];
json_object* platform1 = json_object_new_object();
snprintf(str, 10, "%d", MRAA_NULL_PLATFORM);
json_object_object_add(platform1, "id", json_object_new_string(str));
json_object* platform2 = json_object_new_object();
snprintf(str, 10, "%d", MRAA_GENERIC_FIRMATA);
json_object_object_add(platform2, "id", json_object_new_string(str));
json_object_object_add(platform2, "uart", json_object_new_string(serialport));
json_object* platfroms = json_object_new_array();
json_object_array_add(platfroms, platform1);
json_object_array_add(platfroms, platform2);
json_object* lock_file = json_object_new_object();
json_object_object_add(lock_file, "Platform", platfroms);
fh = fopen(lock_file_location, "w");
if (fh != NULL) {
fputs(json_object_to_json_string_ext(lock_file, JSON_C_TO_STRING_PRETTY), fh);
fclose(fh);
} else {
fprintf(stderr, "can't write to lock file\n");
}
json_object_put(lock_file);
}
void
imraa_handle_subplatform(struct json_object* jobj, bool force_update)
{
struct json_object* platform;
int i, ionum;
const char* dfu_loc = NULL;
const char* lockfile_loc = NULL;
const char* flash_loc = NULL;
const char* usbserial = NULL;
struct json_object* dfu_location;
if (json_object_object_get_ex(jobj, "dfu-utils-location", &dfu_location) == true) {
if (json_object_is_type(dfu_location, json_type_string)) {
printf("dfu location: %s\n", json_object_get_string(dfu_location));
dfu_loc = json_object_get_string(dfu_location);
} else {
fprintf(stderr, "dfu location string incorrectly parsed\n");
}
}
struct json_object* lockfile_location;
if (json_object_object_get_ex(jobj, "lockfile-location", &lockfile_location) == true) {
if (json_object_is_type(lockfile_location, json_type_string)) {
printf("lock file location: %s\n", json_object_get_string(lockfile_location));
lockfile_loc = json_object_get_string(lockfile_location);
} else {
fprintf(stderr, "lock file string incorrectly parsed\n");
}
}
if (json_object_object_get_ex(jobj, "Platform", &platform) == true) {
if (json_object_is_type(platform, json_type_array)) {
ionum = json_object_array_length(platform);
for (i = 0; i < ionum; i++) {
struct json_object* ioobj = json_object_array_get_idx(platform, i);
json_object_object_foreach(ioobj, key, val)
{
if (strcmp(key, "flash") == 0) {
flash_loc = json_object_get_string(val);
}
if (strcmp(key, "usbserial") == 0) {
usbserial = json_object_get_string(val);
}
}
}
} else {
fprintf(stderr, "platform string incorrectly parsed\n");
}
}
if (flash_loc == NULL || usbserial == NULL ) {
printf("conf didn't give image location or usb serial, skip flashing\n");
return;
}
if (!dfu_loc) {
dfu_loc = "/usr/bin";
printf("No dfu path found, using default path /usr/bin instead");
}
if (!lockfile_loc) {
lockfile_loc = "/tmp/imraa.lock";
printf("No lock path found, using default lock file /tmp/imraa.lock instead");
}
// got flash? do flash
if (access(lockfile_loc, F_OK) != -1 && force_update == false) {
printf("already exist a lock file, skip flashing\n");
printf("force upgrade? remove the lockfile or run with force\n", lockfile_loc);
return;
} else {
fprintf(stdout, "Starting to flash board\n");
if (force_update) {
fprintf(stdout, "**Caution: force update mode**\n");
}
// TODO flash img checksum, and serialport validation?
const char* detected_serialport = imraa_list_serialport();
if (detected_serialport == NULL) {
printf("No subplatform detected, check USB connection, skip flashing\n");
return;
}
if (strcmp(usbserial, "auto") != 0 && strcmp(usbserial, detected_serialport) != 0) {
printf("given serial port didn't match detected serial port, skip flashing\n");
return;
}
if (imraa_flash_101(dfu_loc, flash_loc, detected_serialport) == 0) {
imraa_write_lockfile(lockfile_loc, detected_serialport);
} else {
fprintf(stderr, "invalid flashing paramenters, please check agian\n");
fprintf(stderr, "DFU Util location: %s\n", dfu_loc);
fprintf(stderr, "Flash Img location: %s\n", dfu_loc);
fprintf(stderr, "USB Serial: %s\n", usbserial);
fprintf(stderr, "Flash failed, push master reset and try again\n");
}
}
}
void
imraa_handle_IO(struct json_object* jobj)
{
struct mraa_io_objects_t* mraa_io_obj;
struct json_object* ioarray;
int ionum = 0;
int i;
if (json_object_object_get_ex(jobj, "IO", &ioarray) == true) {
ionum = json_object_array_length(ioarray);
printf("Length of IO array is %d\n", ionum);
mraa_io_obj = (mraa_io_objects_t*) malloc(ionum * sizeof(mraa_io_objects_t));
if (!mraa_io_obj) {
printf("imraa_handle_IO malloc failed\n");
exit(1);
}
int index2 = -1;
; // optional index for io configuration;
if (json_object_is_type(ioarray, json_type_array)) {
for (i = 0; i < ionum; i++) {
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
struct json_object* x;
if (json_object_object_get_ex(ioobj, "type", &x) == true) {
mraa_io_obj[i].type = json_object_get_string(x);
}
if (json_object_object_get_ex(ioobj, "index", &x) == true) {
mraa_io_obj[i].index = json_object_get_int(x);
}
if (json_object_object_get_ex(ioobj, "raw", &x) == true) {
mraa_io_obj[i].raw = json_object_get_boolean(x);
}
if (json_object_object_get_ex(ioobj, "label", &x) == true) {
mraa_io_obj[i].label = json_object_get_string(x);
}
if (json_object_object_get_ex(ioobj, "index2", &x) == true) {
index2 = json_object_get_int(x);
}
// starting io configuration
if (strcmp(mraa_io_obj[i].type, "gpio") == 0) {
mraa_gpio_context gpio = NULL;
if (mraa_io_obj[i].raw) {
gpio = mraa_gpio_init_raw(mraa_io_obj[i].index);
} else {
gpio = mraa_gpio_init(mraa_io_obj[i].index);
}
if (gpio != NULL) {
mraa_result_t r = mraa_gpio_owner(gpio, 0);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
mraa_gpio_close(gpio);
}
} else if (strcmp(mraa_io_obj[i].type, "i2c") == 0) {
mraa_i2c_context i2c = NULL;
if (mraa_io_obj[i].raw) {
i2c = mraa_i2c_init_raw(mraa_io_obj[i].index);
} else {
i2c = mraa_i2c_init(mraa_io_obj[i].index);
}
if (i2c != NULL) {
mraa_i2c_stop(i2c);
}
} else if (strcmp(mraa_io_obj[i].type, "pwm") == 0) {
mraa_pwm_context pwm = NULL;
if (mraa_io_obj[i].raw) {
pwm = mraa_pwm_init_raw(index2, mraa_io_obj[i].index);
} else {
pwm = mraa_pwm_init(mraa_io_obj[i].index);
}
if (pwm != NULL) {
mraa_result_t r = mraa_pwm_owner(pwm, 0);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
mraa_pwm_close(pwm);
}
} else if (strcmp(mraa_io_obj[i].type, "spi") == 0) {
mraa_spi_context spi = NULL;
if (mraa_io_obj[i].raw) {
spi = mraa_spi_init_raw(mraa_io_obj[i].index, index2);
} else {
spi = mraa_spi_init(mraa_io_obj[i].index);
}
if (spi != NULL) {
mraa_spi_stop(spi);
}
} else if (strcmp(mraa_io_obj[i].type, "uart") == 0) {
mraa_uart_context uart = NULL;
if (mraa_io_obj[i].raw) {
uart = mraa_uart_init_raw(mraa_io_obj[i].label);
} else {
uart = mraa_uart_init(mraa_io_obj[i].index);
}
if (uart != NULL) {
mraa_uart_stop(uart);
}
}
}
} else {
fprintf(stderr, "IO array incorrectly parsed\n");
}
free(mraa_io_obj);
}
}
int
check_version(struct json_object* jobj)
imraa_check_version(struct json_object* jobj)
{
struct json_object* imraa_version;
if (json_object_object_get_ex(jobj, "version", &imraa_version) == true) {
@@ -434,58 +62,90 @@ check_version(struct json_object* jobj)
return 0;
}
void
print_version()
const char *argp_program_version = "imraa version 2.0";
const char *argp_program_bug_address = "http://github.com/intel-iot-devkit/mraa/issues";
static char doc[] = "somestuff";
static char args_doc[] = "-i imraa.conf";
static struct argp_option options[] = {
{"verbose", 'v', 0, 0, "Produce verbose output" },
{"quiet", 'q', 0, 0, "Don't produce any output" },
{"silent", 's', 0, OPTION_ALIAS },
{"force", 'f', 0, 0, "Force update" },
{"arduino", 'a', 0, 0, "Arduino detection" },
{"input", 'i', "FILE", 0,
"configuration file" },
{ 0 }
};
struct arguments
{
fprintf(stdout, "Version %s on %s\n", mraa_get_version(), mraa_get_platform_name());
char *args[2];
int silent, verbose, force, arduino;
char *input_file;
};
static error_t
parse_opt(int key, char *arg, struct argp_state *state)
{
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = state->input;
switch(key) {
case 'q': case 's':
arguments->silent = 1;
break;
case 'v':
arguments->verbose = 1;
break;
case 'a':
arguments->arduino = 1;
break;
case 'f':
arguments->force = 1;
break;
case 'i':
arguments->input_file = arg;
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 2) {
argp_usage(state);
}
arguments->args[state->arg_num] = arg;
break;
case ARGP_KEY_END:
if (state->arg_num < 0) {
/* Not enough arguments. */
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
void
print_help()
{
fprintf(stdout, "version Get mraa version and board name\n");
fprintf(stdout, "force Force update subplatform\n");
fprintf(stdout, "conf_path Force update with override configuration\n");
}
void
print_command_error()
{
fprintf(stdout, "Invalid command, options are:\n");
print_help();
exit(EXIT_FAILURE);
}
static struct argp argp = { options, parse_opt, args_doc, doc};
int
main(int argc, char** argv)
{
char* buffer = NULL;
char* imraa_conf_file = IMRAA_CONF_FILE;
long fsize;
bool force_update = false;
int i = 0;
uint32_t ionum = 0;
struct arguments arguments;
if (argc > 2) {
print_command_error();
}
arguments.silent = 0;
arguments.verbose = 0;
arguments.force = 0;
arguments.input_file = IMRAA_CONF_FILE;
if (argc > 1) {
if (strcmp(argv[1], "help") == 0) {
print_help();
return EXIT_SUCCESS;
} else if (strcmp(argv[1], "version") == 0) {
print_version();
return EXIT_SUCCESS;
} else if (strcmp(argv[1], "force") == 0) {
force_update = true;
} else {
imraa_conf_file = argv[1];
force_update = true;
}
}
argp_parse(&argp, argc, argv, 0, 0, &arguments);
FILE* fh = fopen(imraa_conf_file, "r");
FILE* fh = fopen(arguments.input_file, "r");
if (fh == NULL) {
fprintf(stderr, "Failed to open configuration file\n");
return EXIT_FAILURE;
@@ -497,28 +157,33 @@ main(int argc, char** argv)
buffer = calloc(fsize, sizeof(char));
if (buffer != NULL) {
int result = fread(buffer, sizeof(char), fsize, fh);
if (result != fsize) {
printf("imraa conf reading error");
if (result != (fsize - 1)) {
printf("imraa conf reading error\n");
}
} else {
printf("imraa read_conf buffer can't allocated\n");
exit(1);
}
// call reduced imraa_init (not that mraa_init) will already have been called
imraa_init();
json_object* jobj = json_tokener_parse(buffer);
if (check_version(jobj) != 0) {
if (imraa_check_version(jobj) != 0) {
printf("version of configuration file is not compatible, please check again\n");
} else {
mraa_platform_t type = mraa_get_platform_type();
imraa_handle_subplatform(jobj, force_update);
if (type == MRAA_NULL_PLATFORM || type == MRAA_UNKNOWN_PLATFORM) {
printf("imraa: Failed to do IO pinmuxing on null/unkown platform\n");
} else {
imraa_handle_IO(jobj);
if (arguments.arduino) {
imraa_handle_subplatform(jobj, arguments.force);
}
if (type == MRAA_NULL_PLATFORM || type == MRAA_UNKNOWN_PLATFORM) {
printf("imraa: attempting to do IO pinmuxing on null/unkown platform\n");
}
imraa_handle_IO(jobj);
}
fclose(fh);
json_object_put(jobj);
free(buffer);

View File

@@ -1,12 +1,8 @@
{
"version": "0.9.6",
"version": "1.4.0",
"lockfile-location": "/tmp/imraa.lock",
"dfu-utils-location": "/usr/bin",
"Platform" :[
{"id":"1280", "flash":"/usr/share/mraa/firmata101.ino.bin", "usbserial": "auto"}
],
"IO": [
{"type":"gpio", "index":0, "raw": false, "label": "none"},
{"type":"i2c", "index":0, "raw": false, "label": "i2c-0"}
]
}

12
imraa/imraa.io.conf Normal file
View File

@@ -0,0 +1,12 @@
{
"version": "1.4.0",
"lockfile-location": "/tmp/imraa.lock",
"dfu-utils-location": "/usr/bin",
"Platform" :[
{"id":"1280", "flash":"/usr/share/mraa/firmata101.ino.bin", "usbserial": "auto"}
],
"IO": [
{"type":"gpio", "index":0, "raw": false, "label": "none", "user": "brendan", "group": "brendan"},
{"type":"i2c", "index":0, "raw": false, "label": "i2c-0", "user": "brendan", "group": "user"}
]
}

279
imraa/imraa_arduino.c Normal file
View File

@@ -0,0 +1,279 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Longwei Su <lsu@ics.com>
* Copyright (c) 2015-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 <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <json-c/json.h>
#include <libudev.h>
#include <argp.h>
#include <error.h>
#include <mraa/uart.h>
#include <mraa/gpio.h>
#include <mraa/i2c.h>
#include <mraa/pwm.h>
#include <mraa_internal.h>
#include <imraa_lock.h>
const char*
imraa_list_serialport()
{
struct udev* udev;
struct udev_enumerate* enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct udev_device* dev;
const char* ret = NULL;
udev = udev_new();
if (!udev) {
printf("Can't create udev, check libudev\n");
exit(1);
}
enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "tty");
udev_enumerate_add_match_property(enumerate, "ID_VENDOR_ID", "8087");
udev_enumerate_add_match_property(enumerate, "ID_MODEL_ID", "0ab6");
// udev_enumerate_add_match_property(enumerate, "ID_SERIAL",
// "Intel_ARDUINO_101_AE6642SQ55000RS");
udev_enumerate_scan_devices(enumerate);
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices)
{
const char* path;
path = udev_list_entry_get_name(dev_list_entry);
dev = udev_device_new_from_syspath(udev, path);
ret = udev_device_get_devnode(dev);
}
udev_enumerate_unref(enumerate);
udev_unref(udev);
if (ret) {
printf("Ardunio 101 Device Node Path: %s\n", ret);
} else {
printf("Can't detect any Ardunio 101 Device on tty\n");
}
return ret;
}
mraa_result_t
imraa_reset_arduino(const char* modem)
{
mraa_uart_context uart;
uart = mraa_uart_init_raw(modem);
mraa_uart_set_baudrate(uart, 1200);
if (uart == NULL) {
fprintf(stderr, "UART failed to setup\n");
return MRAA_ERROR_UNSPECIFIED;
}
mraa_uart_stop(uart);
mraa_deinit();
return MRAA_SUCCESS;
}
int
imraa_flash_101(const char* bin_path, const char* bin_file_name, const char* tty)
{
if (imraa_reset_arduino(tty) != MRAA_SUCCESS) {
fprintf(stderr, "Failed to reset arduino on %s for unknown reason, carrying on...\n", tty);
}
char* ln = NULL;
size_t len = 0;
bool board_found = false;
const char* dfu_list = "/dfu-util -d ,8087:0ABA -l";
size_t bin_path_len = strlen(bin_path);
char* full_dfu_list = (char*) calloc((bin_path_len + strlen(dfu_list) + 1), sizeof(char));
if (!full_dfu_list) {
printf("imraa_flash_101 can't allocate string buffer for dfu list\n");
exit(1);
}
strncat(full_dfu_list, bin_path, strlen(bin_path));
strncat(full_dfu_list, dfu_list, strlen(dfu_list));
int i;
// dfu list is still needed, as the time for reset and recognized is varies from platform to
// platform.
// once dfu able to query available devices, then it is ready to flash
for (i = 0; i < 10 && board_found == false; i++) {
printf("Waiting for device...\n");
// dfu-util -d,8087:0ABA -l
FILE* dfu_result = popen(full_dfu_list, "r");
if (dfu_result == NULL) {
printf("Failed to run command\n");
exit(1);
}
if (i == 4) {
printf("Flashing is taking longer than expected\n");
printf("Try pressing MASTER_RESET button\n");
}
while (getline(&ln, &len, dfu_result) != -1) {
if (strstr(ln, "sensor_core")) {
board_found = true;
printf("Device found!\n");
break;
}
}
sleep(1);
if (pclose(dfu_result) != 0) {
printf("Failed to close command\n");
exit(1);
}
}
free(ln);
if (board_found == false) {
printf("ERROR: Device is not responding.\n");
exit(1);
}
const char* dfu_upload = "/dfu-util -d ,8087:0ABA -D ";
const char* dfu_option = " -v -a 7 -R";
int buffersize = bin_path_len + strlen(dfu_upload) + strlen(bin_file_name) + strlen(dfu_option) + 1;
char* full_dfu_upload = calloc(buffersize, sizeof(char));
if (!full_dfu_upload) {
printf("imraa_flash_101 can't allocate string buffer for dfu flash\n");
exit(1);
}
strncat(full_dfu_upload, bin_path, strlen(bin_path));
strncat(full_dfu_upload, dfu_upload, strlen(dfu_upload));
strncat(full_dfu_upload, bin_file_name, strlen(bin_file_name));
strncat(full_dfu_upload, dfu_option, strlen(dfu_option));
printf("flash cmd: %s\n", full_dfu_upload);
int status = system(full_dfu_upload);
if (status != 0) {
printf("ERROR: Upload failed on %s\n", tty);
exit(1);
}
printf("SUCCESS: Sketch will execute in about 5 seconds.\n");
free(full_dfu_list);
free(full_dfu_upload);
sleep(5);
return 0;
}
void
imraa_handle_subplatform(struct json_object* jobj, bool force_update)
{
struct json_object* platform;
int i, ionum;
const char* dfu_loc = NULL;
const char* lockfile_loc = NULL;
const char* flash_loc = NULL;
const char* usbserial = NULL;
struct json_object* dfu_location;
if (json_object_object_get_ex(jobj, "dfu-utils-location", &dfu_location) == true) {
if (json_object_is_type(dfu_location, json_type_string)) {
printf("dfu location: %s\n", json_object_get_string(dfu_location));
dfu_loc = json_object_get_string(dfu_location);
} else {
fprintf(stderr, "dfu location string incorrectly parsed\n");
}
}
struct json_object* lockfile_location;
if (json_object_object_get_ex(jobj, "lockfile-location", &lockfile_location) == true) {
if (json_object_is_type(lockfile_location, json_type_string)) {
printf("lock file location: %s\n", json_object_get_string(lockfile_location));
lockfile_loc = json_object_get_string(lockfile_location);
} else {
fprintf(stderr, "lock file string incorrectly parsed\n");
}
}
if (json_object_object_get_ex(jobj, "Platform", &platform) == true) {
if (json_object_is_type(platform, json_type_array)) {
ionum = json_object_array_length(platform);
for (i = 0; i < ionum; i++) {
struct json_object* ioobj = json_object_array_get_idx(platform, i);
json_object_object_foreach(ioobj, key, val)
{
if (strcmp(key, "flash") == 0) {
flash_loc = json_object_get_string(val);
}
if (strcmp(key, "usbserial") == 0) {
usbserial = json_object_get_string(val);
}
}
}
} else {
fprintf(stderr, "platform string incorrectly parsed\n");
}
}
if (flash_loc == NULL || usbserial == NULL ) {
printf("conf didn't give image location or usb serial, skip flashing\n");
return;
}
if (!dfu_loc) {
dfu_loc = "/usr/bin";
printf("No dfu path found, using default path /usr/bin instead");
}
if (!lockfile_loc) {
lockfile_loc = "/tmp/imraa.lock";
printf("No lock path found, using default lock file /tmp/imraa.lock instead");
}
// got flash? do flash
if (access(lockfile_loc, F_OK) != -1 && force_update == false) {
printf("already exist a lock file, skip flashing\n");
printf("force upgrade? remove the lockfile or run with force\n");
return;
} else {
fprintf(stdout, "Starting to flash board\n");
if (force_update) {
fprintf(stdout, "**Caution: force update mode**\n");
}
// TODO flash img checksum, and serialport validation?
const char* detected_serialport = imraa_list_serialport();
if (detected_serialport == NULL) {
printf("No subplatform detected, check USB connection, skip flashing\n");
return;
}
if (strcmp(usbserial, "auto") != 0 && strcmp(usbserial, detected_serialport) != 0) {
printf("given serial port didn't match detected serial port, skip flashing\n");
return;
}
if (imraa_flash_101(dfu_loc, flash_loc, detected_serialport) == 0) {
imraa_write_lockfile(lockfile_loc, detected_serialport);
} else {
fprintf(stderr, "invalid flashing paramenters, please check agian\n");
fprintf(stderr, "DFU Util location: %s\n", dfu_loc);
fprintf(stderr, "Flash Img location: %s\n", dfu_loc);
fprintf(stderr, "USB Serial: %s\n", usbserial);
fprintf(stderr, "Flash failed, push master reset and try again\n");
}
}
}

29
imraa/imraa_arduino.h Normal file
View File

@@ -0,0 +1,29 @@
/*
* Author: Brendan Le Foll <brendan.le.folL@intel.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
void imraa_handle_subplatform(struct json_object* jobj, bool force_update);

178
imraa/imraa_io.c Normal file
View File

@@ -0,0 +1,178 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2015-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 <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <error.h>
#include <sys/types.h>
#include <json-c/json.h>
#include <pwd.h>
#include <mraa/uart.h>
#include <mraa/gpio.h>
#include <mraa/i2c.h>
#include <mraa/pwm.h>
#include <mraa_internal.h>
#include <imraa_arduino.h>
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
#define MAX_SIZE 64
typedef struct mraa_io_objects_t {
const char* type;
int index;
bool raw;
const char* label;
const char* user;
} mraa_io_objects_t;
void
imraa_handle_IO(struct json_object* jobj)
{
struct mraa_io_objects_t* mraa_io_obj;
struct json_object* ioarray;
int ionum = 0;
int i;
if (json_object_object_get_ex(jobj, "IO", &ioarray) == true) {
ionum = json_object_array_length(ioarray);
printf("Length of IO array is %d\n", ionum);
mraa_io_obj = (mraa_io_objects_t*) calloc(ionum, sizeof(mraa_io_objects_t));
if (!mraa_io_obj) {
printf("imraa_handle_IO malloc failed\n");
exit(1);
}
int index2 = -1;
// optional index for io configuration;
if (json_object_is_type(ioarray, json_type_array)) {
for (i = 0; i < ionum; i++) {
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
struct json_object* x;
if (json_object_object_get_ex(ioobj, "type", &x) == true) {
mraa_io_obj[i].type = json_object_get_string(x);
}
if (json_object_object_get_ex(ioobj, "index", &x) == true) {
mraa_io_obj[i].index = json_object_get_int(x);
}
if (json_object_object_get_ex(ioobj, "raw", &x) == true) {
mraa_io_obj[i].raw = json_object_get_boolean(x);
}
if (json_object_object_get_ex(ioobj, "label", &x) == true) {
mraa_io_obj[i].label = json_object_get_string(x);
}
if (json_object_object_get_ex(ioobj, "index2", &x) == true) {
index2 = json_object_get_int(x);
}
if (json_object_object_get_ex(ioobj, "user", &x) == true) {
mraa_io_obj[i].user = json_object_get_string(x);
}
// starting io configuration
if (strcmp(mraa_io_obj[i].type, "gpio") == 0) {
mraa_gpio_context gpio = NULL;
if (mraa_io_obj[i].raw) {
gpio = mraa_gpio_init_raw(mraa_io_obj[i].index);
} else {
gpio = mraa_gpio_init(mraa_io_obj[i].index);
}
if (gpio != NULL) {
if (mraa_io_obj[i].user != NULL) {
int sysfs_gpio_pin = mraa_gpio_get_pin_raw(gpio);
if (sysfs_gpio_pin >= 0) {
char bu[MAX_SIZE];
snprintf(bu, MAX_SIZE, SYSFS_CLASS_GPIO "/gpio%d/value", sysfs_gpio_pin);
struct passwd* user = getpwnam(mraa_io_obj[i].user);
if (user != NULL) {
if (chown(bu, user->pw_uid, user->pw_gid) == -1) {
fprintf(stderr, "Couldn't change ownership of file %s to %d:%d\n", bu, user->pw_uid, user->pw_gid);
} else {
fprintf(stderr, "Invalid user %s\n", mraa_io_obj[i].user);
}
}
}
mraa_result_t r = mraa_gpio_owner(gpio, 0);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
mraa_gpio_close(gpio);
}
} else if (strcmp(mraa_io_obj[i].type, "i2c") == 0) {
mraa_i2c_context i2c = NULL;
if (mraa_io_obj[i].raw) {
i2c = mraa_i2c_init_raw(mraa_io_obj[i].index);
} else {
i2c = mraa_i2c_init(mraa_io_obj[i].index);
}
if (i2c != NULL) {
mraa_i2c_stop(i2c);
}
} else if (strcmp(mraa_io_obj[i].type, "pwm") == 0) {
mraa_pwm_context pwm = NULL;
if (mraa_io_obj[i].raw) {
pwm = mraa_pwm_init_raw(index2, mraa_io_obj[i].index);
} else {
pwm = mraa_pwm_init(mraa_io_obj[i].index);
}
if (pwm != NULL) {
mraa_result_t r = mraa_pwm_owner(pwm, 0);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
mraa_pwm_close(pwm);
}
} else if (strcmp(mraa_io_obj[i].type, "spi") == 0) {
mraa_spi_context spi = NULL;
if (mraa_io_obj[i].raw) {
spi = mraa_spi_init_raw(mraa_io_obj[i].index, index2);
} else {
spi = mraa_spi_init(mraa_io_obj[i].index);
}
if (spi != NULL) {
mraa_spi_stop(spi);
}
} else if (strcmp(mraa_io_obj[i].type, "uart") == 0) {
mraa_uart_context uart = NULL;
if (mraa_io_obj[i].raw) {
uart = mraa_uart_init_raw(mraa_io_obj[i].label);
} else {
uart = mraa_uart_init(mraa_io_obj[i].index);
}
if (uart != NULL) {
mraa_uart_stop(uart);
}
}
}
}
} else {
fprintf(stderr, "IO array incorrectly parsed\n");
}
free(mraa_io_obj);
}
}

28
imraa/imraa_io.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Author: Brendan Le Foll <brendan.le.folL@intel.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
void imraa_handle_IO(struct json_object* jobj);

71
imraa/imraa_lock.c Normal file
View File

@@ -0,0 +1,71 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.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 <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <json-c/json.h>
#include <libudev.h>
#include <argp.h>
#include <error.h>
#include <mraa/uart.h>
#include <mraa/gpio.h>
#include <mraa/i2c.h>
#include <mraa/pwm.h>
#include <mraa_internal.h>
void
imraa_write_lockfile(const char* lock_file_location, const char* serialport)
{
FILE* fh;
char str[10];
json_object* platform1 = json_object_new_object();
snprintf(str, 10, "%d", MRAA_NULL_PLATFORM);
json_object_object_add(platform1, "id", json_object_new_string(str));
json_object* platform2 = json_object_new_object();
snprintf(str, 10, "%d", MRAA_GENERIC_FIRMATA);
json_object_object_add(platform2, "id", json_object_new_string(str));
json_object_object_add(platform2, "uart", json_object_new_string(serialport));
json_object* platfroms = json_object_new_array();
json_object_array_add(platfroms, platform1);
json_object_array_add(platfroms, platform2);
json_object* lock_file = json_object_new_object();
json_object_object_add(lock_file, "Platform", platfroms);
fh = fopen(lock_file_location, "w");
if (fh != NULL) {
fputs(json_object_to_json_string_ext(lock_file, JSON_C_TO_STRING_PRETTY), fh);
fclose(fh);
} else {
fprintf(stderr, "can't write to lock file\n");
}
json_object_put(lock_file);
}

28
imraa/imraa_lock.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Author: Brendan Le Foll <brendan.le.folL@intel.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
void imraa_write_lockfile(const char* lock_file_location, const char* serialport);

View File

@@ -36,6 +36,7 @@ extern "C" {
#define MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT 41
#define MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT 41
#define MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT 41
#define MRAA_RASPBERRY_PI_ZERO_PINCOUNT 41
mraa_board_t *
mraa_raspberry_pi();

View File

@@ -24,6 +24,8 @@
#pragma once
#include <pthread.h>
#include "uart.h"
#define MODE_INPUT 0x00
@@ -99,6 +101,7 @@ typedef struct s_firmata {
char firmware[140];
uint8_t dev_count;
struct _firmata** devs;
pthread_spinlock_t lock;
} t_firmata;
t_firmata* firmata_new(const char* name);

View File

@@ -30,7 +30,7 @@ extern "C" {
#include "mraa_internal.h"
#define MRAA_MOCK_PINCOUNT 4
#define MRAA_MOCK_PINCOUNT 10
mraa_board_t*
mraa_mock_board();

View File

@@ -0,0 +1,73 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* 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
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
#define MOCK_SPI_DEFAULT_FREQ 4000000
#define MOCK_SPI_DEFAULT_MODE MRAA_SPI_MODE0
#define MOCK_SPI_DEFAULT_LSBMODE 0
#define MOCK_SPI_DEFAULT_BIT_PER_WORD 8
// This is XORed with each byte/word of the transmitted message to get the received one
#define MOCK_SPI_REPLY_DATA_MODIFIER_BYTE 0xAB
#define MOCK_SPI_REPLY_DATA_MODIFIER_WORD 0xABBA
mraa_result_t
mraa_mock_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs);
mraa_result_t
mraa_mock_spi_stop_replace(mraa_spi_context dev);
mraa_result_t
mraa_mock_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits);
mraa_result_t
mraa_mock_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb);
mraa_result_t
mraa_mock_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode);
mraa_result_t
mraa_mock_spi_frequency_replace(mraa_spi_context dev, int hz);
int
mraa_mock_spi_write_replace(mraa_spi_context dev, uint8_t data);
int
mraa_mock_spi_write_word_replace(mraa_spi_context dev, uint16_t data);
mraa_result_t
mraa_mock_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
mraa_result_t
mraa_mock_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,68 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* 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
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
// ASCII code for "Z", used as a basis for our mock reads
#define MOCK_UART_DATA_BYTE 0x5A
mraa_result_t
mraa_mock_uart_set_baudrate_replace(mraa_uart_context dev, unsigned int baud);
mraa_result_t
mraa_mock_uart_init_raw_replace(mraa_uart_context dev, const char* path);
mraa_result_t
mraa_mock_uart_flush_replace(mraa_uart_context dev);
mraa_result_t
mraa_mock_uart_set_flowcontrol_replace(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts);
mraa_result_t
mraa_mock_uart_set_mode_replace(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits);
mraa_result_t
mraa_mock_uart_set_non_blocking_replace(mraa_uart_context dev, mraa_boolean_t nonblock);
mraa_result_t
mraa_mock_uart_set_timeout_replace(mraa_uart_context dev, int read, int write, int interchar);
mraa_boolean_t
mraa_mock_uart_data_available_replace(mraa_uart_context dev, unsigned int millis);
int
mraa_mock_uart_write_replace(mraa_uart_context dev, const char* buf, size_t len);
int
mraa_mock_uart_read_replace(mraa_uart_context dev, char* buf, size_t len);
#ifdef __cplusplus
}
#endif

View File

@@ -97,8 +97,27 @@ typedef struct {
mraa_result_t (*spi_init_pre) (int bus);
mraa_result_t (*spi_init_post) (mraa_spi_context spi);
mraa_result_t (*spi_init_raw_replace) (mraa_spi_context spi, unsigned int bus, unsigned int cs);
mraa_result_t (*spi_lsbmode_replace) (mraa_spi_context dev, mraa_boolean_t lsb);
mraa_result_t (*spi_mode_replace) (mraa_spi_context dev, mraa_spi_mode_t mode);
mraa_result_t (*spi_bit_per_word_replace) (mraa_spi_context dev, unsigned int bits);
mraa_result_t (*spi_frequency_replace) (mraa_spi_context dev, int hz);
mraa_result_t (*spi_transfer_buf_replace) (mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
mraa_result_t (*spi_transfer_buf_word_replace) (mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length);
int (*spi_write_replace) (mraa_spi_context dev, uint8_t data);
int (*spi_write_word_replace) (mraa_spi_context dev, uint16_t data);
mraa_result_t (*spi_stop_replace) (mraa_spi_context dev);
mraa_result_t (*uart_init_pre) (int index);
mraa_result_t (*uart_init_post) (mraa_uart_context uart);
mraa_result_t (*uart_init_raw_replace) (mraa_uart_context dev, const char* path);
mraa_result_t (*uart_flush_replace) (mraa_uart_context dev);
mraa_result_t (*uart_set_baudrate_replace) (mraa_uart_context dev, unsigned int baud);
mraa_result_t (*uart_set_mode_replace) (mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits);
mraa_result_t (*uart_set_flowcontrol_replace) (mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts);
mraa_result_t (*uart_set_timeout_replace) (mraa_uart_context dev, int read, int write, int interchar);
mraa_result_t (*uart_set_non_blocking_replace) (mraa_uart_context dev, mraa_boolean_t nonblock);
int (*uart_read_replace) (mraa_uart_context dev, char* buf, size_t len);
int (*uart_write_replace)(mraa_uart_context dev, const char* buf, size_t len);
mraa_boolean_t (*uart_data_available_replace) (mraa_uart_context dev, unsigned int millis);
} mraa_adv_func_t;

View File

@@ -90,6 +90,8 @@ set (mraa_LIB_MOCK_SRCS_NOAUTO
${PROJECT_SOURCE_DIR}/src/mock/mock_board_gpio.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_aio.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_spi.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_uart.c
)
if (JSONPLAT)
@@ -238,6 +240,8 @@ if (BUILDSWIG)
if (BUILDSWIGJAVA)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/pom.xml.in
${CMAKE_CURRENT_BINARY_DIR}/java/mraa-${VERSION_SHORT}.pom)
add_subdirectory (java)
endif ()
if (BUILDSWIGNODE)

View File

@@ -38,6 +38,7 @@
#define PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1 "Raspberry Pi Compute Module Rev 1"
#define PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1 "Raspberry Pi Model A+ Rev 1"
#define PLATFORM_NAME_RASPBERRY_PI2_B_REV_1 "Raspberry Pi 2 Model B Rev 1"
#define PLATFORM_NAME_RASPBERRY_PI_ZERO "Raspberry Pi Zero"
#define PLATFORM_RASPBERRY_PI_B_REV_1 1
#define PLATFORM_RASPBERRY_PI_A_REV_2 2
#define PLATFORM_RASPBERRY_PI_B_REV_2 3
@@ -45,6 +46,7 @@
#define PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1 5
#define PLATFORM_RASPBERRY_PI_A_PLUS_REV_1 6
#define PLATFORM_RASPBERRY_PI2_B_REV_1 7
#define PLATFORM_RASPBERRY_PI_ZERO "Raspberry Pi Zero"
#define MMAP_PATH "/dev/mem"
#define BCM2835_PERI_BASE 0x20000000
#define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000)
@@ -230,6 +232,10 @@ mraa_raspberry_pi()
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2;
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2;
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
} else if (strstr(line, "900092")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_ZERO;
platform_detected = PLATFORM_RASPBERRY_PI_ZERO;
b->phy_pin_count = MRAA_RASPBERRY_PI_ZERO_PINCOUNT;
} else if (strstr(line, "0007") || strstr(line, "0008") || strstr(line, "0009")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2;
platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2;
@@ -490,7 +496,8 @@ mraa_raspberry_pi()
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_PLUS_REV_1) ||
(platform_detected == PLATFORM_RASPBERRY_PI_B_PLUS_REV_1) ||
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1) ||
(platform_detected == PLATFORM_RASPBERRY_PI_ZERO)) {
strncpy(b->pins[27].name, "ID_SD", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };

View File

@@ -33,13 +33,19 @@ t_firmata*
firmata_new(const char* name)
{
t_firmata* res;
mraa_result_t uart_res = MRAA_ERROR_UNSPECIFIED;
res = calloc(1, sizeof(t_firmata));
if (!res) {
return NULL;
}
int ret = pthread_spin_init(&res->lock, PTHREAD_PROCESS_SHARED);
if (ret != 0) {
syslog(LOG_ERR, "firmata; could not init locking");
free(res);
return NULL;
}
res->uart = mraa_uart_init_raw(name);
if (res->uart == NULL) {
syslog(LOG_ERR, "firmata: UART failed to setup");
@@ -69,7 +75,7 @@ firmata_close(t_firmata* firmata)
int
firmata_pull(t_firmata* firmata)
{
uint8_t buff[FIRMATA_MSG_LEN];
char buff[FIRMATA_MSG_LEN];
int r;
r = mraa_uart_data_available(firmata->uart, 40);
@@ -79,7 +85,7 @@ firmata_pull(t_firmata* firmata)
return 0;
}
if (r > 0) {
firmata_parse(firmata, buff, r);
firmata_parse(firmata, (uint8_t*) buff, r);
return r;
}
}
@@ -134,7 +140,9 @@ firmata_endParse(t_firmata* firmata)
int analog_val = firmata->parse_buff[1] | (firmata->parse_buff[2] << 7);
for (pin = 0; pin < 128; pin++) {
if (firmata->pins[pin].analog_channel == analog_ch) {
pthread_spin_lock(&firmata->lock);
firmata->pins[pin].value = analog_val;
pthread_spin_unlock(&firmata->lock);
return;
}
}
@@ -148,7 +156,9 @@ firmata_endParse(t_firmata* firmata)
for (mask = 1; mask & 0xFF; mask <<= 1, pin++) {
if (firmata->pins[pin].mode == MODE_INPUT) {
uint32_t val = (port_val & mask) ? 1 : 0;
pthread_spin_lock(&firmata->lock);
firmata->pins[pin].value = val;
pthread_spin_unlock(&firmata->lock);
}
}
return;
@@ -174,7 +184,7 @@ firmata_endParse(t_firmata* firmata)
// not ready to communicate for some time, so the only
// way to reliably query their capabilities is to wait
// until the REPORT_FIRMWARE message is heard.
uint8_t buf[80];
char buf[80];
len = 0;
buf[len++] = FIRMATA_START_SYSEX;
buf[len++] = FIRMATA_ANALOG_MAPPING_QUERY; // read analog to pin # info
@@ -209,7 +219,7 @@ firmata_endParse(t_firmata* firmata)
}
// send a state query for for every pin with any modes
for (pin = 0; pin < 128; pin++) {
uint8_t buf[512];
char buf[512];
int len = 0;
if (firmata->pins[pin].supported_modes) {
buf[len++] = FIRMATA_START_SYSEX;
@@ -241,15 +251,17 @@ firmata_endParse(t_firmata* firmata)
int reg = (firmata->parse_buff[4] & 0x7f) | ((firmata->parse_buff[5] & 0x7f) << 7);
int i = 6;
int ii = 0;
for (ii; ii < (firmata->parse_count - 7) / 2; ii++) {
pthread_spin_lock(&firmata->lock);
for (; ii < (firmata->parse_count - 7) / 2; ii++) {
firmata->i2cmsg[addr][reg+ii] = (firmata->parse_buff[i] & 0x7f) | ((firmata->parse_buff[i+1] & 0x7f) << 7);
i = i+2;
}
pthread_spin_unlock(&firmata->lock);
} else {
if (firmata->devs != NULL) {
struct _firmata* devs = firmata->devs[0];
int i = 0;
for (i; i < firmata->dev_count; i++, devs++) {
for (; i < firmata->dev_count; i++, devs++) {
if (devs != NULL) {
if (firmata->parse_buff[1] == devs->feature) {
// call func
@@ -284,7 +296,7 @@ firmata_initPins(t_firmata* firmata)
int
firmata_askFirmware(t_firmata* firmata)
{
uint8_t buf[3];
char buf[3];
int res;
buf[0] = FIRMATA_START_SYSEX;
@@ -298,7 +310,7 @@ int
firmata_pinMode(t_firmata* firmata, int pin, int mode)
{
int res;
uint8_t buff[4];
char buff[4];
firmata->pins[pin].mode = mode;
buff[0] = FIRMATA_SET_PIN_MODE;
@@ -313,7 +325,7 @@ firmata_analogWrite(t_firmata* firmata, int pin, int value)
{
int res;
uint8_t buff[3];
char buff[3];
buff[0] = 0xE0 | pin;
buff[1] = value & 0x7F;
buff[2] = (value >> 7) & 0x7F;
@@ -326,7 +338,7 @@ firmata_analogRead(t_firmata *firmata, int pin)
{
int res;
int value = 1;
uint8_t buff[2];
char buff[2];
buff[0] = FIRMATA_REPORT_ANALOG | pin;
buff[1] = value;
res = mraa_uart_write(firmata->uart, buff, 2);
@@ -338,7 +350,7 @@ firmata_digitalWrite(t_firmata* firmata, int pin, int value)
{
int i;
int res;
uint8_t buff[4];
char buff[4];
if (pin < 0 || pin > 127)
return (0);

View File

@@ -84,6 +84,7 @@ mraa_result_t
mraa_firmata_close(mraa_firmata_context dev)
{
mraa_firmata_response_stop(dev);
pthread_spin_destroy(&firmata_dev->lock);
free(dev);
return MRAA_SUCCESS;
}
@@ -92,7 +93,7 @@ static mraa_result_t
mraa_firmata_i2c_init_bus_replace(mraa_i2c_context dev)
{
int delay = 1; // this should be either 1 or 0, I don't know :)
uint8_t buff[4];
char buff[4];
buff[0] = FIRMATA_START_SYSEX;
buff[1] = FIRMATA_I2C_CONFIG;
buff[2] = delay & 0xFF, (delay >> 8) & 0xFF;
@@ -120,7 +121,7 @@ mraa_firmata_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
static mraa_result_t
mraa_firmata_send_i2c_read_req(mraa_i2c_context dev, int length)
{
uint8_t* buffer = calloc(7, 0);
char* buffer = calloc(7, 0);
if (buffer == NULL) {
return MRAA_ERROR_NO_RESOURCES;
}
@@ -149,7 +150,7 @@ mraa_firmata_send_i2c_read_req(mraa_i2c_context dev, int length)
static mraa_result_t
mraa_firmata_send_i2c_read_reg_req(mraa_i2c_context dev, uint8_t command, int length)
{
uint8_t* buffer = calloc(9, 0);
char* buffer = calloc(9, 0);
if (buffer == NULL) {
return MRAA_ERROR_NO_RESOURCES;
}
@@ -182,11 +183,17 @@ static mraa_result_t
mraa_firmata_i2c_wait(int addr, int reg)
{
int i = 0;
for (i = 0; firmata_dev->i2cmsg[addr][reg] == -1; i++) {
pthread_spin_lock(&firmata_dev->lock);
int res = firmata_dev->i2cmsg[addr][reg];
pthread_spin_unlock(&firmata_dev->lock);
for (; res == -1; i++) {
if (i > 50) {
return MRAA_ERROR_UNSPECIFIED;
}
usleep(500);
pthread_spin_lock(&firmata_dev->lock);
res = firmata_dev->i2cmsg[addr][reg];
pthread_spin_unlock(&firmata_dev->lock);
}
return MRAA_SUCCESS;
}
@@ -239,7 +246,7 @@ mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
if (mraa_firmata_send_i2c_read_req(dev, length) == MRAA_SUCCESS) {
if (mraa_firmata_i2c_wait(dev->addr, 0) == MRAA_SUCCESS) {
int i = 0;
for (i = 0; i < length; i++) {
for (; i < length; i++) {
data[i] = firmata_dev->i2cmsg[dev->addr][i];
}
return length;
@@ -266,7 +273,7 @@ mraa_firmata_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWri
{
// buffer needs 5 bytes for firmata, and 2 bytes for every byte of data
int buffer_size = (bytesToWrite*2) + 5;
uint8_t* buffer = calloc(buffer_size, 0);
char* buffer = calloc(buffer_size, 0);
if (buffer == NULL) {
return MRAA_ERROR_NO_RESOURCES;
}
@@ -277,7 +284,7 @@ mraa_firmata_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWri
buffer[2] = dev->addr;
buffer[3] = I2C_MODE_WRITE << 3;
// we need to write until FIRMATA_END_SYSEX
for (i; i < (buffer_size-1); i++) {
for (; i < (buffer_size-1); i++) {
buffer[ii] = data[i] & 0x7F;
buffer[ii+1] = (data[i] >> 7) & 0x7f;
ii = ii+2;
@@ -291,7 +298,7 @@ mraa_firmata_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWri
static mraa_result_t
mraa_firmata_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
{
uint8_t* buffer = calloc(7, 0);
char* buffer = calloc(7, 0);
if (buffer == NULL) {
return MRAA_ERROR_NO_RESOURCES;
}
@@ -310,7 +317,7 @@ mraa_firmata_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
static mraa_result_t
mraa_firmata_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
{
uint8_t* buffer = calloc(9, 0);
char* buffer = calloc(9, 0);
if (buffer == NULL) {
return MRAA_ERROR_NO_RESOURCES;
}
@@ -345,7 +352,10 @@ 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 (int) firmata_dev->pins[dev->channel].value;
pthread_spin_lock(&firmata_dev->lock);
int ret = (int) firmata_dev->pins[dev->channel].value;
pthread_spin_unlock(&firmata_dev->lock);
return ret;
}
static mraa_result_t
@@ -380,7 +390,10 @@ mraa_firmata_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode)
static int
mraa_firmata_gpio_read_replace(mraa_gpio_context dev)
{
return firmata_dev->pins[dev->pin].value;
pthread_spin_lock(&firmata_dev->lock);
int res = firmata_dev->pins[dev->pin].value;
pthread_spin_unlock(&firmata_dev->lock);
return res;
}
static mraa_result_t
@@ -517,6 +530,8 @@ mraa_firmata_pull_handler(void* vp)
isr_prev = isr_now;
usleep(100);
}
return NULL;
}
mraa_board_t*
@@ -537,7 +552,7 @@ mraa_firmata_plat_init(const char* uart_dev)
// if this isn't working then we have an issue with our uart
int retry = 20;
while (!firmata_dev->isReady && retry--) {
while (!firmata_dev->isReady && --retry) {
firmata_pull(firmata_dev);
}

View File

@@ -44,7 +44,7 @@ static mraa_result_t
mraa_gpio_get_valfp(mraa_gpio_context dev)
{
char bu[MAX_SIZE];
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
snprintf(bu, MAX_SIZE, 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));

View File

@@ -309,7 +309,7 @@ mraa_iio_wait_event(int fd, char* data, int* read_size)
// 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);
memset(data, 0, 100);
*read_size = read(fd, data, 100);
@@ -376,10 +376,7 @@ mraa_iio_get_event_data(mraa_iio_context dev)
char buf[MAX_SIZE];
char readbuf[32];
int fd;
int ret = 0;
int padint = 0;
int curr_bytes = 0;
char shortbuf, signchar;
memset(buf, 0, MAX_SIZE);
memset(readbuf, 0, 32);
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS, dev->num);
@@ -441,7 +438,7 @@ mraa_iio_event_poll_nonblock(int fd, struct iio_event_data* data)
// 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);
read(fd, data, sizeof(struct iio_event_data));
@@ -573,9 +570,7 @@ mraa_result_t
mraa_iio_create_trigger(mraa_iio_context dev, const char* trigger)
{
struct stat configfs_status;
struct stat trigger_status;
char buf[MAX_SIZE];
int ret;
if (stat(IIO_CONFIGFS_TRIGGER, &configfs_status) == 0) {
memset(buf, 0, MAX_SIZE);

38
src/java/pom.xml.in Normal file
View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.mraa</groupId>
<artifactId>mraa</artifactId>
<version>@VERSION_SHORT@</version>
<packaging>jar</packaging>
<name>mraa</name>
<description>Low Level Skeleton Library for IO Communication on GNU/Linux platforms</description>
<url>http://mraa.io</url>
<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/intel-iot-devkit/mraa/blob/master/COPYING</url>
</license>
</licenses>
<developers>
<developer>
<name>Mraa contributors https://github.com/intel-iot-devkit/mraa/graphs/contributors</name>
<email>mraa@lists.01.org</email>
<organization>Intel IoT Developer kit</organization>
<organizationUrl>https://github.com/intel-iot-devkit</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/intel-iot-devkit/mraa.git</connection>
<developerConnection>scm:git:ssh://github.com:intel-iot-devkit/mraa.git</developerConnection>
<url>https://github.com/intel-iot-devkit/mraa/tree/master</url>
</scm>
</project>

View File

@@ -80,7 +80,6 @@ mraa_init_json_platform_platform(json_object* jobj_platform, mraa_board_t* board
{
json_object* jobj_temp = NULL;
const char* temp_string = NULL;
int temp_count = 0;
int length = 0;
mraa_result_t ret = MRAA_SUCCESS;
@@ -600,8 +599,8 @@ mraa_init_json_platform(const char* platform_json)
mraa_result_t ret = MRAA_SUCCESS;
char* buffer = NULL;
struct stat st;
int file_lock = 0, array_length = 0, i = 0;
json_object *jobj_platform = NULL, *jobj_temp = NULL;
int file_lock = 0, i = 0;
json_object *jobj_platform = NULL;
mraa_board_t* board = NULL;
// Try to lock the file for use

View File

@@ -30,8 +30,11 @@
#include "mock/mock_board_gpio.h"
#include "mock/mock_board_aio.h"
#include "mock/mock_board_i2c.h"
#include "mock/mock_board_spi.h"
#include "mock/mock_board_uart.h"
#define PLATFORM_NAME "MRAA mock platform"
#define UART_DEV_PATH "dummy"
mraa_board_t*
mraa_mock_board()
@@ -55,12 +58,25 @@ mraa_mock_board()
b->i2c_bus[0].scl = 3;
b->def_i2c_bus = b->i2c_bus[0].bus_id;
b->spi_bus_count = 0;
b->spi_bus_count = 1;
b->def_spi_bus = 0;
b->spi_bus[0].bus_id = 0;
b->spi_bus[0].slave_s = 0;
b->spi_bus[0].cs = 4;
b->spi_bus[0].mosi = 5;
b->spi_bus[0].miso = 6;
b->spi_bus[0].sclk = 7;
b->pwm_default_period = 0;
b->pwm_max_period = 0;
b->pwm_min_period = 0;
b->uart_dev_count = 1;
b->def_uart_dev = 0;
b->uart_dev[0].rx = 8;
b->uart_dev[0].tx = 9;
b->uart_dev[0].device_path = UART_DEV_PATH;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_MOCK_PINCOUNT);
if (b->pins == NULL) {
goto error;
@@ -99,6 +115,26 @@ mraa_mock_board()
b->adv_func->i2c_write_byte_replace = &mraa_mock_i2c_write_byte_replace;
b->adv_func->i2c_write_byte_data_replace = &mraa_mock_i2c_write_byte_data_replace;
b->adv_func->i2c_write_word_data_replace = &mraa_mock_i2c_write_word_data_replace;
b->adv_func->spi_init_raw_replace = &mraa_mock_spi_init_raw_replace;
b->adv_func->spi_stop_replace = &mraa_mock_spi_stop_replace;
b->adv_func->spi_bit_per_word_replace = &mraa_mock_spi_bit_per_word_replace;
b->adv_func->spi_lsbmode_replace = &mraa_mock_spi_lsbmode_replace;
b->adv_func->spi_mode_replace = &mraa_mock_spi_mode_replace;
b->adv_func->spi_frequency_replace = &mraa_mock_spi_frequency_replace;
b->adv_func->spi_write_replace = &mraa_mock_spi_write_replace;
b->adv_func->spi_write_word_replace = &mraa_mock_spi_write_word_replace;
b->adv_func->spi_transfer_buf_replace = &mraa_mock_spi_transfer_buf_replace;
b->adv_func->spi_transfer_buf_word_replace = &mraa_mock_spi_transfer_buf_word_replace;
b->adv_func->uart_init_raw_replace = &mraa_mock_uart_init_raw_replace;
b->adv_func->uart_set_baudrate_replace = &mraa_mock_uart_set_baudrate_replace;
b->adv_func->uart_flush_replace = &mraa_mock_uart_flush_replace;
b->adv_func->uart_set_flowcontrol_replace = &mraa_mock_uart_set_flowcontrol_replace;
b->adv_func->uart_set_mode_replace = &mraa_mock_uart_set_mode_replace;
b->adv_func->uart_set_non_blocking_replace = &mraa_mock_uart_set_non_blocking_replace;
b->adv_func->uart_set_timeout_replace = &mraa_mock_uart_set_timeout_replace;
b->adv_func->uart_data_available_replace = &mraa_mock_uart_data_available_replace;
b->adv_func->uart_write_replace = &mraa_mock_uart_write_replace;
b->adv_func->uart_read_replace = &mraa_mock_uart_read_replace;
// Pin definitions
int pos = 0;
@@ -127,6 +163,44 @@ mraa_mock_board()
b->pins[pos].i2c.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "SPI0CS", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[pos].spi.mux_total = 0;
b->pins[pos].spi.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "SPI0MOSI", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[pos].spi.mux_total = 0;
b->pins[pos].spi.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "SPI0MISO", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[pos].spi.mux_total = 0;
b->pins[pos].spi.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "SPI0SCLK", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[pos].spi.mux_total = 0;
b->pins[pos].spi.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "UART0RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "UART0TX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
pos++;
return b;
error:

View File

@@ -26,9 +26,6 @@
#include <string.h>
#include "common.h"
#include "mock/mock_board.h"
#include "mock/mock_board_gpio.h"
#include "mock/mock_board_aio.h"
#include "mock/mock_board_i2c.h"
mraa_result_t

179
src/mock/mock_board_spi.c Normal file
View File

@@ -0,0 +1,179 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* 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 <string.h>
#if defined(MSYS)
#define __USE_LINUX_IOCTL_DEFS
#endif
#include <sys/ioctl.h>
#if defined(MSYS)
// There's no spidev.h on MSYS, so we need to provide our own,
// and only *after* including ioctl.h as that one contains prerequisites.
#include "linux/spi_kernel_headers.h"
#else
#include <linux/spi/spidev.h>
#endif
#include "common.h"
#include "mock/mock_board_spi.h"
mraa_result_t
mraa_mock_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs)
{
dev->clock = MOCK_SPI_DEFAULT_FREQ;
if ((mraa_spi_mode(dev, MOCK_SPI_DEFAULT_MODE) != MRAA_SUCCESS) ||
(mraa_spi_lsbmode(dev, MOCK_SPI_DEFAULT_LSBMODE) != MRAA_SUCCESS) ||
(mraa_spi_bit_per_word(dev, MOCK_SPI_DEFAULT_BIT_PER_WORD) != MRAA_SUCCESS)) {
return MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_stop_replace(mraa_spi_context dev)
{
free(dev);
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits)
{
if (bits == 0) {
syslog(LOG_ERR, "spi: bit_per_word: Cannot set to zero");
return MRAA_ERROR_INVALID_PARAMETER;
}
dev->bpw = bits;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb)
{
dev->lsb = lsb;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode)
{
uint8_t spi_mode = 0;
switch (mode) {
case MRAA_SPI_MODE0:
spi_mode = SPI_MODE_0;
break;
case MRAA_SPI_MODE1:
spi_mode = SPI_MODE_1;
break;
case MRAA_SPI_MODE2:
spi_mode = SPI_MODE_2;
break;
case MRAA_SPI_MODE3:
spi_mode = SPI_MODE_3;
break;
default:
syslog(LOG_ERR, "spi: mode: Invalid SPI mode %d selected", mode);
return MRAA_ERROR_INVALID_PARAMETER;
}
dev->mode = spi_mode;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_frequency_replace(mraa_spi_context dev, int hz)
{
if (hz <= 0) {
syslog(LOG_ERR, "spi: frequency: Cannot set to zero or negative");
return MRAA_ERROR_INVALID_PARAMETER;
}
dev->clock = hz;
return MRAA_SUCCESS;
}
int
mraa_mock_spi_write_replace(mraa_spi_context dev, uint8_t data)
{
return (int) (data ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE);
}
int
mraa_mock_spi_write_word_replace(mraa_spi_context dev, uint16_t data)
{
return (int) (data ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD);
}
mraa_result_t
mraa_mock_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
{
if (data == NULL) {
syslog(LOG_ERR, "spi: transfer_buf: Incoming data is null, cannot proceed");
return MRAA_ERROR_INVALID_PARAMETER;
}
if (length <= 0) {
syslog(LOG_ERR, "spi: transfer_buf: Length given is equal to or less than zero, cannot proceed");
return MRAA_ERROR_INVALID_PARAMETER;
}
if (rxbuf != NULL) {
int i;
for (i = 0; i < length; ++i) {
rxbuf[i] = data[i] ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE;
}
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length)
{
if (data == NULL) {
syslog(LOG_ERR, "spi: transfer_buf_word: Incoming data is null, cannot proceed");
return MRAA_ERROR_INVALID_PARAMETER;
}
if (length <= 0) {
syslog(LOG_ERR, "spi: transfer_buf_word: Length given is equal to or less than zero, cannot proceed");
return MRAA_ERROR_INVALID_PARAMETER;
}
if (rxbuf != NULL) {
// length is given in bytes, but arrays are comprised of words
int i;
for (i = 0; i < (length / 2); ++i) {
rxbuf[i] = data[i] ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD;
}
}
return MRAA_SUCCESS;
}

100
src/mock/mock_board_uart.c Normal file
View File

@@ -0,0 +1,100 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* 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 <string.h>
#include "common.h"
#include "mock/mock_board_uart.h"
mraa_result_t
mraa_mock_uart_set_baudrate_replace(mraa_uart_context dev, unsigned int baud)
{
// Limits are taken from uart.c::uint2speed(), they don't matter much anyway
if ((baud < 0) || (baud > 4000000)) {
syslog(LOG_ERR, "uart%i: set_baudrate: invalid baudrate: %i", dev->index, baud);
return MRAA_ERROR_INVALID_PARAMETER;
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_init_raw_replace(mraa_uart_context dev, const char* path)
{
// The only thing we have to do from the original uart_init_raw()
return mraa_uart_set_baudrate(dev, 9600);
}
mraa_result_t
mraa_mock_uart_flush_replace(mraa_uart_context dev)
{
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_set_flowcontrol_replace(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts)
{
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_set_mode_replace(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits)
{
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_set_non_blocking_replace(mraa_uart_context dev, mraa_boolean_t nonblock)
{
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_set_timeout_replace(mraa_uart_context dev, int read, int write, int interchar)
{
return MRAA_SUCCESS;
}
mraa_boolean_t
mraa_mock_uart_data_available_replace(mraa_uart_context dev, unsigned int millis)
{
// Our mock implementation will always have "incoming" data
return 1;
}
int
mraa_mock_uart_write_replace(mraa_uart_context dev, const char* buf, size_t len)
{
// Our mock implementation always succeeds when sending data
return len;
}
int
mraa_mock_uart_read_replace(mraa_uart_context dev, char* buf, size_t len)
{
// We'll return MOCK_UART_DATA_BYTE, len times
memset(buf, MOCK_UART_DATA_BYTE, len);
return len;
}

View File

@@ -69,7 +69,6 @@ mraa_iio_info_t* plat_iio = NULL;
mraa_lang_func_t* lang_func = NULL;
char* platform_name = NULL;
static char* platform_long_name = NULL;
static int num_i2c_devices = 0;
static int num_iio_devices = 0;
@@ -953,7 +952,7 @@ mraa_find_i2c_bus(const char* devname, int startfrom)
// i2c devices are numbered numerically so 0 must exist otherwise there is
// no i2c-dev loaded
if (mraa_file_exist("/sys/class/i2c-dev/i2c-0")) {
for (i; i < num_i2c_devices; i++) {
for (;i < num_i2c_devices; i++) {
off_t size, err;
snprintf(path, 64, "/sys/class/i2c-dev/i2c-%u/name", i);
fd = open(path, O_RDONLY);
@@ -1028,13 +1027,21 @@ 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 (plat->sub_platform->platform_type == subplatformtype) {
syslog(LOG_NOTICE, "mraa: Firmata subplatform already present");
return MRAA_SUCCESS;
}
syslog(LOG_NOTICE, "mraa: We don't support multiple firmata subplatforms!");
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
if (mraa_firmata_platform(plat, uart_dev) == MRAA_GENERIC_FIRMATA) {
syslog(LOG_NOTICE, "mraa: Added firmata subplatform");
return MRAA_SUCCESS;
}
syslog(LOG_NOTICE, "mraa: Failed to add firmata subplatform");
}
#else
if (subplatformtype == MRAA_GENERIC_FIRMATA) {
syslog(LOG_NOTICE, "mraa: Cannot add Firmata platform as support not compiled in");
}
#endif
@@ -1052,6 +1059,7 @@ mraa_remove_subplatform(mraa_platform_t subplatformtype)
free(plat->sub_platform->adv_func);
free(plat->sub_platform->pins);
free(plat->sub_platform);
return MRAA_SUCCESS;
}
#endif
return MRAA_ERROR_INVALID_PARAMETER;
@@ -1062,9 +1070,7 @@ mraa_result_t
mraa_add_from_lockfile(const char* imraa_lock_file)
{
mraa_result_t ret = MRAA_SUCCESS;
mraa_platform_t type = plat->platform_type;
char* buffer = NULL;
off_t file_size;
struct stat st;
int i = 0;
uint32_t subplat_num = 0;
@@ -1110,7 +1116,15 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
uartdev = NULL;
}
}
} else {
if (json_object_object_get_ex(jobj_lock, "IO", &ioarray) == true &&
json_object_is_type(ioarray, json_type_array)) {
/* assume we have declared IO so we are preinitialised and wipe the
* advance func array
*/
memset(plat->adv_func, 0, sizeof(mraa_adv_func_t));
}
}
else {
ret = MRAA_ERROR_INVALID_RESOURCE;
}
json_object_put(jobj_lock);
@@ -1210,7 +1224,7 @@ mraa_init_io(const char* desc)
return NULL;
}
if (strncmp(type, "GPIO", 4) == 0) {
if (strncmp(type, GPIO_KEY, strlen(GPIO_KEY)) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_gpio_init_raw(pin);
@@ -1219,7 +1233,7 @@ mraa_init_io(const char* desc)
return NULL;
}
return (void*) mraa_gpio_init(pin);
} else if (strncmp(type, "I2C", 3) == 0) {
} else if (strncmp(type, I2C_KEY, strlen(I2C_KEY)) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_i2c_init_raw(pin);
@@ -1228,13 +1242,13 @@ mraa_init_io(const char* desc)
return NULL;
}
return (void*) mraa_i2c_init(pin);
} else if (strncmp(type, "AIO", 3) == 0) {
} else if (strncmp(type, AIO_KEY, strlen(AIO_KEY)) == 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) {
} else if (strncmp(type, PWM_KEY, strlen(PWM_KEY)) == 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");
@@ -1247,7 +1261,7 @@ mraa_init_io(const char* desc)
return (void*) mraa_pwm_init_raw(id, pin);
}
return (void*) mraa_pwm_init(pin);
} else if (strncmp(type, "SPI", 3) == 0) {
} else if (strncmp(type, SPI_KEY, strlen(SPI_KEY)) == 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");
@@ -1260,7 +1274,7 @@ mraa_init_io(const char* desc)
return (void*) mraa_spi_init_raw(id, pin);
}
return (void*) mraa_spi_init(pin);
} else if (strncmp(type, "UART", 4) == 0) {
} else if (strncmp(type, UART_KEY, strlen(UART_KEY)) == 0) {
if (raw) {
return (void*) mraa_uart_init_raw(str);
}

View File

@@ -6,7 +6,7 @@
#ifdef DOXYGEN
//and doesn't seem to work correctly in SWIG's preprocessor
#ifdef SWIGPYTHON
#ifdef SWIGPYTHON2
%include common_hpp_doc.i
%include gpio_class_doc.i
%include i2c_class_doc.i

View File

@@ -18,22 +18,20 @@ if (PYTHON2_LIBRARY)
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}"
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DSWIGPYTHON2=${SWIG_FOUND}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
install (TARGETS ${SWIG_MODULE_python2-mraa_REAL_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH}
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH}
)
endif()
add_subdirectory (docs)

View File

@@ -15,10 +15,14 @@ if (PYTHON3_LIBRARY)
set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DDSWIGPYTHON3=${SWIG_FOUND}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH})
install (TARGETS ${SWIG_MODULE_python3-mraa_REAL_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH}
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH}
)
endif ()

View File

@@ -135,10 +135,22 @@ mraa_spi_init(int bus)
mraa_spi_context
mraa_spi_init_raw(unsigned int bus, unsigned int cs)
{
mraa_result_t status = MRAA_SUCCESS;
mraa_spi_context dev = mraa_spi_init_internal(plat == NULL ? NULL : plat->adv_func);
if (dev == NULL) {
syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
return NULL;
status = MRAA_ERROR_NO_RESOURCES;
goto init_raw_cleanup;
}
if (IS_FUNC_DEFINED(dev, spi_init_raw_replace)) {
status = dev->advance_func->spi_init_raw_replace(dev, bus, cs);
if (status == MRAA_SUCCESS) {
return dev;
} else {
goto init_raw_cleanup;
}
}
char path[MAX_SIZE];
@@ -147,8 +159,8 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
dev->devfd = open(path, O_RDWR);
if (dev->devfd < 0) {
syslog(LOG_ERR, "spi: Failed opening SPI Device. bus:%s", path);
free(dev);
return NULL;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_raw_cleanup;
}
int speed = 0;
@@ -160,18 +172,26 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
syslog(LOG_WARNING, "spi: Max speed query failed, setting %d", dev->clock);
}
if (mraa_spi_mode(dev, MRAA_SPI_MODE0) != MRAA_SUCCESS) {
free(dev);
return NULL;
status = mraa_spi_mode(dev, MRAA_SPI_MODE0);
if (status != MRAA_SUCCESS) {
goto init_raw_cleanup;
}
if (mraa_spi_lsbmode(dev, 0) != MRAA_SUCCESS) {
free(dev);
return NULL;
status = mraa_spi_lsbmode(dev, 0);
if (status != MRAA_SUCCESS) {
goto init_raw_cleanup;
}
if (mraa_spi_bit_per_word(dev, 8) != MRAA_SUCCESS) {
free(dev);
status = mraa_spi_bit_per_word(dev, 8);
if (status != MRAA_SUCCESS) {
goto init_raw_cleanup;
}
init_raw_cleanup:
if (status != MRAA_SUCCESS) {
if (dev != NULL) {
free(dev);
}
return NULL;
}
@@ -181,6 +201,15 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
mraa_result_t
mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: mode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_mode_replace)) {
return dev->advance_func->spi_mode_replace(dev, mode);
}
uint8_t spi_mode = 0;
switch (mode) {
case MRAA_SPI_MODE0:
@@ -212,6 +241,15 @@ mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
mraa_result_t
mraa_spi_frequency(mraa_spi_context dev, int hz)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: frequency: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_frequency_replace)) {
return dev->advance_func->spi_frequency_replace(dev, hz);
}
int speed = 0;
dev->clock = hz;
if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
@@ -226,6 +264,11 @@ mraa_spi_frequency(mraa_spi_context dev, int hz)
mraa_result_t
mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: lsbmode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_lsbmode_replace)) {
return dev->advance_func->spi_lsbmode_replace(dev, lsb);
}
@@ -246,6 +289,15 @@ mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
mraa_result_t
mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: bit_per_word: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_bit_per_word_replace)) {
return dev->advance_func->spi_bit_per_word_replace(dev, bits);
}
if (ioctl(dev->devfd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
syslog(LOG_ERR, "spi: Failed to set bit per word");
return MRAA_ERROR_INVALID_RESOURCE;
@@ -257,6 +309,15 @@ mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
int
mraa_spi_write(mraa_spi_context dev, uint8_t data)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: write: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, spi_write_replace)) {
return dev->advance_func->spi_write_replace(dev, data);
}
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
@@ -279,6 +340,15 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
int
mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: write_word: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, spi_write_word_replace)) {
return dev->advance_func->spi_write_word_replace(dev, data);
}
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
@@ -301,6 +371,15 @@ mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
mraa_result_t
mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: transfer_buf: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_transfer_buf_replace)) {
return dev->advance_func->spi_transfer_buf_replace(dev, data, rxbuf, length);
}
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
@@ -320,6 +399,15 @@ mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int l
mraa_result_t
mraa_spi_transfer_buf_word(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: transfer_buf_word: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_transfer_buf_word_replace)) {
return dev->advance_func->spi_transfer_buf_word_replace(dev, data, rxbuf, length);
}
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
@@ -339,6 +427,11 @@ mraa_spi_transfer_buf_word(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf
uint8_t*
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: write_buf: context is invalid");
return NULL;
}
uint8_t* recv = malloc(sizeof(uint8_t) * length);
if (mraa_spi_transfer_buf(dev, data, recv, length) != MRAA_SUCCESS) {
@@ -351,6 +444,11 @@ mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
uint16_t*
mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: write_buf_word: context is invalid");
return NULL;
}
uint16_t* recv = malloc(sizeof(uint16_t) * length);
if (mraa_spi_transfer_buf_word(dev, data, recv, length) != MRAA_SUCCESS) {
@@ -363,6 +461,15 @@ mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length)
mraa_result_t
mraa_spi_stop(mraa_spi_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "spi: stop: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, spi_stop_replace)) {
return dev->advance_func->spi_stop_replace(dev);
}
close(dev->devfd);
free(dev);
return MRAA_SUCCESS;

View File

@@ -201,23 +201,36 @@ mraa_uart_init(int index)
mraa_uart_context
mraa_uart_init_raw(const char* path)
{
mraa_result_t status = MRAA_SUCCESS;
if (!path) {
syslog(LOG_ERR, "uart: device path undefined");
return NULL;
status = MRAA_ERROR_INVALID_PARAMETER;
goto init_raw_cleanup;
}
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");
return NULL;
status = MRAA_ERROR_NO_RESOURCES;
goto init_raw_cleanup;
}
dev->path = path;
if (IS_FUNC_DEFINED(dev, uart_init_raw_replace)) {
status = dev->advance_func->uart_init_raw_replace(dev, path);
if (status == MRAA_SUCCESS) {
return dev;
} else {
goto init_raw_cleanup;
}
}
// now open the device
if ((dev->fd = open(dev->path, O_RDWR)) == -1) {
syslog(LOG_ERR, "uart: open(%s) failed: %s", path, strerror(errno));
free(dev);
return NULL;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_raw_cleanup;
}
// now setup the tty and the selected baud rate
@@ -226,9 +239,8 @@ mraa_uart_init_raw(const char* path)
// get current modes
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart: tcgetattr(%s) failed: %s", path, strerror(errno));
close(dev->fd);
free(dev);
return NULL;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_raw_cleanup;
}
// setup for a 'raw' mode. 8N1, no echo or special character
@@ -237,14 +249,23 @@ mraa_uart_init_raw(const char* path)
cfmakeraw(&termio);
if (tcsetattr(dev->fd, TCSAFLUSH, &termio) < 0) {
syslog(LOG_ERR, "uart: tcsetattr(%s) failed after cfmakeraw(): %s", path, strerror(errno));
close(dev->fd);
free(dev);
return NULL;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_raw_cleanup;
}
if (mraa_uart_set_baudrate(dev, 9600) != MRAA_SUCCESS) {
close(dev->fd);
free(dev);
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_raw_cleanup;
}
init_raw_cleanup:
if (status != MRAA_SUCCESS) {
if (dev != NULL) {
if (dev->fd >= 0) {
close(dev->fd);
}
free(dev);
}
return NULL;
}
@@ -277,6 +298,10 @@ mraa_uart_flush(mraa_uart_context dev)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_flush_replace)) {
return dev->advance_func->uart_flush_replace(dev);
}
if (tcdrain(dev->fd) == -1) {
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
@@ -292,6 +317,10 @@ mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_set_baudrate_replace)) {
return dev->advance_func->uart_set_baudrate_replace(dev, baud);
}
struct termios termio;
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart%i: set_baudrate: tcgetattr() failed: %s", dev->index, strerror(errno));
@@ -324,6 +353,10 @@ mraa_uart_set_mode(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parit
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_set_mode_replace)) {
return dev->advance_func->uart_set_mode_replace(dev, bytesize, parity, stopbits);
}
struct termios termio;
if (tcgetattr(dev->fd, &termio)) {
syslog(LOG_ERR, "uart%i: set_mode: tcgetattr() failed: %s", dev->index, strerror(errno));
@@ -396,6 +429,10 @@ mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_bo
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_set_flowcontrol_replace)) {
return dev->advance_func->uart_set_flowcontrol_replace(dev, xonxoff, rtscts);
}
// hardware flow control
int action = TCIOFF;
if (xonxoff) {
@@ -436,6 +473,10 @@ mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_set_timeout_replace)) {
return dev->advance_func->uart_set_timeout_replace(dev, read, write, interchar);
}
struct termios termio;
// get current modes
if (tcgetattr(dev->fd, &termio)) {
@@ -465,6 +506,10 @@ mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_set_non_blocking_replace)) {
return dev->advance_func->uart_set_non_blocking_replace(dev, nonblock);
}
// get current flags
int flags = fcntl(dev->fd, F_GETFL);
@@ -505,6 +550,10 @@ mraa_uart_read(mraa_uart_context dev, char* buf, size_t len)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_read_replace)) {
return dev->advance_func->uart_read_replace(dev, buf, len);
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart%i: read: port is not open", dev->index);
return MRAA_ERROR_INVALID_RESOURCE;
@@ -521,6 +570,10 @@ mraa_uart_write(mraa_uart_context dev, const char* buf, size_t len)
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_write_replace)) {
return dev->advance_func->uart_write_replace(dev, buf, len);
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart%i: write: port is not open", dev->index);
return MRAA_ERROR_INVALID_RESOURCE;
@@ -537,6 +590,10 @@ mraa_uart_data_available(mraa_uart_context dev, unsigned int millis)
return 0;
}
if (IS_FUNC_DEFINED(dev, uart_data_available_replace)) {
return dev->advance_func->uart_data_available_replace(dev, millis);
}
if (dev->fd < 0) {
syslog(LOG_ERR, "uart%i: data_available: port is not open", dev->index);
return 0;

View File

@@ -320,7 +320,7 @@ mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t 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) {
if (_ow_read_byte(dev, &ch) != MRAA_SUCCESS || ret == -1) {
return -1;
}
return (ch == 0xff);

View File

@@ -208,11 +208,14 @@ mraa_intel_edison_gpio_init_post(mraa_gpio_context dev)
mraa_result_t
mraa_intel_edison_gpio_close_pre(mraa_gpio_context dev)
{
if (dev->phy_pin >= 0) {
int pin = dev->phy_pin;
if (agpioOutputen[pin]) {
mraa_gpio_close(agpioOutputen[pin]);
agpioOutputen[pin] = NULL;
// check if we own it
if (dev->owner != 0) {
if (dev->phy_pin >= 0) {
int pin = dev->phy_pin;
if (agpioOutputen[pin]) {
mraa_gpio_close(agpioOutputen[pin]);
agpioOutputen[pin] = NULL;
}
}
}
return MRAA_SUCCESS;

View File

@@ -808,9 +808,9 @@ mraa_intel_galileo_gen2()
b->pins[18].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].aio.mux[0].pin = 57;
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].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].aio.mux[1].pin = 60;
b->pins[18].aio.mux[1].value = 1;
b->pins[18].aio.mux[1].value = MRAA_GPIO_OUT_HIGH;
b->pins[18].aio.mux[2].pincmd = PINCMD_SET_VALUE;
b->pins[18].aio.mux[2].pin = 78;
b->pins[18].aio.mux[2].value = 0;
@@ -819,9 +819,9 @@ mraa_intel_galileo_gen2()
b->pins[18].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].gpio.mux[0].pin = 57;
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].pincmd = PINCMD_SET_DIRECTION;
b->pins[18].gpio.mux[1].pin = 60;
b->pins[18].gpio.mux[1].value = 1;
b->pins[18].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH;
b->pins[18].gpio.mux[2].pincmd = PINCMD_SET_VALUE;
b->pins[18].gpio.mux[2].pin = 78;
b->pins[18].gpio.mux[2].value = 1;
@@ -845,9 +845,9 @@ mraa_intel_galileo_gen2()
b->pins[19].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].aio.mux[0].pin = 59;
b->pins[19].aio.mux[0].value = MRAA_GPIO_IN;
b->pins[19].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
b->pins[19].aio.mux[1].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].aio.mux[1].pin = 60;
b->pins[19].aio.mux[1].value = 1;
b->pins[19].aio.mux[1].value = MRAA_GPIO_OUT_HIGH;
b->pins[19].aio.mux[2].pincmd = PINCMD_SET_VALUE;
b->pins[19].aio.mux[2].pin = 79;
b->pins[19].aio.mux[2].value = 0;
@@ -856,9 +856,9 @@ mraa_intel_galileo_gen2()
b->pins[19].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].gpio.mux[0].pin = 59;
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].pincmd = PINCMD_SET_DIRECTION;
b->pins[19].gpio.mux[1].pin = 60;
b->pins[19].gpio.mux[1].value = 1;
b->pins[19].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH;
b->pins[19].gpio.mux[2].pincmd = PINCMD_SET_VALUE;
b->pins[19].gpio.mux[2].pin = 79;
b->pins[19].gpio.mux[2].value = 1;

View File

@@ -47,7 +47,7 @@ mraa_gt_tuchuck_board()
b->adc_raw = 0;
b->adc_supported = 0;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_GT_TUCHUCK_PINCOUNT);
b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_GT_TUCHUCK_PINCOUNT, sizeof(mraa_pininfo_t));
if (b->pins == NULL) {
goto error;
}
@@ -81,22 +81,14 @@ mraa_gt_tuchuck_board()
b->def_i2c_bus = b->i2c_bus[0].bus_id;
#if 0
b->spi_bus_count = 6;
b->spi_bus_count = 3;
b->def_spi_bus = 0;
b->spi_bus[0].bus_id = 32764;
b->spi_bus[0].slave_s = 1;
b->spi_bus[1].bus_id = 32764;
b->spi_bus[1].slave_s = 2;
b->spi_bus[2].bus_id = 32765;
b->spi_bus[2].slave_s = 0;
b->spi_bus[3].bus_id = 32765;
b->spi_bus[3].slave_s = 1;
b->spi_bus[4].bus_id = 32766;
b->spi_bus[4].slave_s = 0;
b->spi_bus[5].bus_id = 32766;
b->spi_bus[5].slave_s = 1;
#endif
b->spi_bus[0].bus_id = 32765;
b->spi_bus[0].slave_s = 0;
b->spi_bus[1].bus_id = 32766;
b->spi_bus[1].slave_s = 0;
b->spi_bus[2].bus_id = 32766;
b->spi_bus[2].slave_s = 1;
int pos = 0;
@@ -111,7 +103,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP1RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 421;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -124,7 +116,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP1TX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 422;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -136,7 +128,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP1FS0", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 417;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -152,7 +144,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP1FS2", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 419;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -165,7 +157,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP1CLK", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 416;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -455,7 +447,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP0FS0", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 411;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -465,43 +457,43 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP0FS1", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 412;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPI_DAT", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 385;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPP0FS2", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 411;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPICLKB", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 384;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPP0FS3", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 410;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPICLKA", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 383;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "SPP0TX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 414;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -516,7 +508,7 @@ mraa_gt_tuchuck_board()
pos++;
strncpy(b->pins[pos].name, "SPP0RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 415;
b->pins[pos].gpio.mux_total = 0;
pos++;
@@ -558,6 +550,7 @@ mraa_gt_tuchuck_board()
strncpy(b->pins[pos].name, "UART1TX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[pos].gpio.pinmap = 484;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
@@ -574,6 +567,7 @@ mraa_gt_tuchuck_board()
strncpy(b->pins[pos].name, "UART1RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[pos].gpio.pinmap = 483;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
@@ -590,6 +584,7 @@ mraa_gt_tuchuck_board()
strncpy(b->pins[pos].name, "UART1RT", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[pos].gpio.pinmap = 485;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
@@ -598,6 +593,7 @@ mraa_gt_tuchuck_board()
strncpy(b->pins[pos].name, "RTC_CLK", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 367;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "UART1CT", 8);
@@ -616,32 +612,37 @@ mraa_gt_tuchuck_board()
strncpy(b->pins[pos].name, "LED100", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 337;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "LED101", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
// if BIOS is pre-L then this is 338
b->pins[pos].gpio.pinmap = 395;
b->pins[pos].gpio.pinmap = 338;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "LED102", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 339;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "LED103", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 340;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "LEDWIFI", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 438;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "LEDBT", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 439;
b->pins[pos].gpio.mux_total = 0;
pos++;
return b;

View File

@@ -89,7 +89,7 @@ mraa_intel_minnowboard_byt_compatible(mraa_boolean_t turbot)
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
struct utsname running_uname;
int uname_major, uname_minor, max_pins[28];
int uname_major, uname_minor;
if (b == NULL) {
return NULL;

View File

@@ -86,7 +86,7 @@ mraa_up_board()
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
struct utsname running_uname;
int uname_major, uname_minor, max_pins[27];
int uname_major, uname_minor;
if (b == NULL) {
return NULL;

View File

@@ -51,7 +51,7 @@ mraa_x86_platform()
FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
if (fh != NULL) {
if (getline(&line, &len, fh) != -1) {
if (strncmp(line, "GalileoGen2", 11) == 0) {
if (strncmp(line, "GalileoGen2", 11) == 0 || strncmp(line, "SIMATIC IOT2000", 15) == 0) {
platform_type = MRAA_INTEL_GALILEO_GEN2;
plat = mraa_intel_galileo_gen2();
} else if (strncmp(line, "BODEGA BAY", 10) == 0) {

View File

@@ -22,6 +22,24 @@ add_test (NAME py_i2c_read_bytes_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMA
add_test (NAME py_i2c_read_word_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/i2c_checks_read_word_data.py)
add_test (NAME py_i2c_write_word_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/i2c_checks_write_word_data.py)
add_test (NAME py_spi_bit_per_word COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_bit_per_word.py)
add_test (NAME py_spi_checks_lsbmode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_lsbmode.py)
add_test (NAME py_spi_checks_mode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_mode.py)
add_test (NAME py_spi_checks_freq COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_freq.py)
add_test (NAME py_spi_checks_write_byte COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write_byte.py)
add_test (NAME py_spi_checks_write_word COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write_word.py)
add_test (NAME py_spi_checks_write COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write.py)
add_test (NAME py_uart_checks_set_baudrate COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_set_baudrate.py)
add_test (NAME py_uart_checks_flush COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_flush.py)
add_test (NAME py_uart_checks_set_flowcontrol COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_set_flowcontrol.py)
add_test (NAME py_uart_checks_set_mode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_set_mode.py)
add_test (NAME py_uart_checks_set_nonblocking COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_set_nonblocking.py)
add_test (NAME py_uart_checks_set_timeout COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_set_timeout.py)
add_test (NAME py_uart_checks_data_available COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_data_available.py)
add_test (NAME py_uart_checks_write COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_write.py)
add_test (NAME py_uart_checks_read COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_read.py)
set_tests_properties(py_general
py_platform
py_gpio_basic
@@ -42,4 +60,20 @@ set_tests_properties(py_general
py_i2c_read_bytes_data
py_i2c_read_word_data
py_i2c_write_word_data
py_spi_bit_per_word
py_spi_checks_lsbmode
py_spi_checks_mode
py_spi_checks_freq
py_spi_checks_write_byte
py_spi_checks_write_word
py_spi_checks_write
py_uart_checks_set_baudrate
py_uart_checks_flush
py_uart_checks_set_flowcontrol
py_uart_checks_set_mode
py_uart_checks_set_nonblocking
py_uart_checks_set_timeout
py_uart_checks_data_available
py_uart_checks_write
py_uart_checks_read
PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")

View File

@@ -27,7 +27,7 @@
import mraa as m
import unittest as u
PLATFORM_PINCOUNT = 4
PLATFORM_PINCOUNT = 10
PLATFORM_STD_ADC_RES_BITS = 10
PLATFORM_MAX_ADC_RES_BITS = 12

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksBitPerWord(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_bit_per_word(self):
TEST_BIT_PER_WORD = 16
self.assertEqual(self.spi.bitPerWord(TEST_BIT_PER_WORD),
m.SUCCESS,
"Setting bit per word to %d did not return success" %TEST_BIT_PER_WORD)
def test_i2c_frequency_invalid_smaller_than_min(self):
TEST_BIT_PER_WORD = -100
self.assertRaises(OverflowError, self.spi.bitPerWord, TEST_BIT_PER_WORD)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksFreq(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_set_freq(self):
TEST_FREQ = 20000000
self.assertEqual(self.spi.frequency(TEST_FREQ),
m.SUCCESS,
"Setting SPI frequency to %d did not return success" %TEST_FREQ)
def test_spi_set_freq_invalid_smaller_than_min_zero(self):
TEST_FREQ = 0
self.assertEqual(self.spi.frequency(TEST_FREQ),
m.ERROR_INVALID_PARAMETER,
"Setting SPI frequency to %d did not return error" %TEST_FREQ)
def test_spi_set_freq_invalid_smaller_than_min_negative(self):
TEST_FREQ = -10
self.assertEqual(self.spi.frequency(TEST_FREQ),
m.ERROR_INVALID_PARAMETER,
"Setting SPI frequency to %d did not return error" %TEST_FREQ)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksLsbmode(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_set_lsbmode_false(self):
TEST_LSBMODE = False
self.assertEqual(self.spi.lsbmode(TEST_LSBMODE),
m.SUCCESS,
"Setting LSB mode to %s did not return success" %TEST_LSBMODE)
def test_spi_set_lsbmode_true(self):
TEST_LSBMODE = True
self.assertEqual(self.spi.lsbmode(TEST_LSBMODE),
m.SUCCESS,
"Setting LSB mode to %s did not return success" %TEST_LSBMODE)
def test_spi_set_lsbmode_invalid(self):
TEST_LSBMODE = 10
self.assertRaises(TypeError, self.spi.lsbmode, TEST_LSBMODE)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,74 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksMode(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_set_mode_MODE0(self):
TEST_MODE = m.SPI_MODE0
self.assertEqual(self.spi.mode(TEST_MODE),
m.SUCCESS,
"Setting SPI mode to %d did not return success" %TEST_MODE)
def test_spi_set_mode_MODE1(self):
TEST_MODE = m.SPI_MODE1
self.assertEqual(self.spi.mode(TEST_MODE),
m.SUCCESS,
"Setting SPI mode to %d did not return success" %TEST_MODE)
def test_spi_set_mode_MODE2(self):
TEST_MODE = m.SPI_MODE2
self.assertEqual(self.spi.mode(TEST_MODE),
m.SUCCESS,
"Setting SPI mode to %d did not return success" %TEST_MODE)
def test_spi_set_mode_MODE3(self):
TEST_MODE = m.SPI_MODE3
self.assertEqual(self.spi.mode(TEST_MODE),
m.SUCCESS,
"Setting SPI mode to %d did not return success" %TEST_MODE)
def test_spi_set_mode_invalid_smaller_than_min(self):
TEST_MODE = -10
self.assertEqual(self.spi.mode(TEST_MODE),
m.ERROR_INVALID_PARAMETER,
"Setting SPI mode to %d did not return error" %TEST_MODE)
def test_spi_set_mode_invalid_bigger_than_max(self):
TEST_MODE = 150
self.assertEqual(self.spi.mode(TEST_MODE),
m.ERROR_INVALID_PARAMETER,
"Setting SPI mode to %d did not return error" %TEST_MODE)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
MRAA_SPI_BUS_NUM = 0
MOCK_SPI_REPLY_DATA_MODIFIER_BYTE = 0xAB
MOCK_SPI_REPLY_DATA_MODIFIER_WORD = 0xABBA
MOCK_SPI_TEST_DATA_LEN = 5

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksWrite(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_write(self):
DATA_TO_WRITE = bytearray([0xEE for i in range(MOCK_SPI_TEST_DATA_LEN)])
DATA_TO_EXPECT = bytearray([0xEE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE for i in range(MOCK_SPI_TEST_DATA_LEN)])
self.assertEqual(self.spi.write(DATA_TO_WRITE),
DATA_TO_EXPECT,
"SPI write() returned unexpected data")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksWriteByte(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_write_byte(self):
TEST_BYTE = 0xEE
self.assertEqual(self.spi.writeByte(TEST_BYTE),
TEST_BYTE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE,
"SPI writeByte() returned unexpected data")
def test_spi_write_byte_invalid_bigger_than_max(self):
TEST_VALUE = 0xEEFF
self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE)
def test_spi_write_byte_invalid_smaller_than_min(self):
TEST_VALUE = -1
self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from spi_checks_shared import *
class SpiChecksWriteWord(u.TestCase):
def setUp(self):
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
def tearDown(self):
del self.spi
def test_spi_write_word(self):
TEST_WORD = 0xAAEE
self.assertEqual(self.spi.writeWord(TEST_WORD),
TEST_WORD ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD,
"SPI writeWord() returned unexpected data")
def test_spi_write_word_invalid_bigger_than_max(self):
TEST_VALUE = 0xEEFFEE
self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE)
def test_spi_write_word_invalid_smaller_than_min(self):
TEST_VALUE = -1
self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksDataAvailable(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_data_available(self):
self.assertEqual(self.uart.dataAvailable(10),
True,
"Running UART dataAvailable() did not return True")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksFlush(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_flush(self):
self.assertEqual(self.uart.flush(),
m.SUCCESS,
"Running UART flush() did not return success")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksRead(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_read(self):
TEST_DATA_LEN = 10
EXPECTED_RESULT = bytearray([MOCK_UART_DATA_BYTE for x in range(TEST_DATA_LEN)])
self.assertEqual(self.uart.read(TEST_DATA_LEN),
EXPECTED_RESULT,
"Running UART read(%d) did not return %s" % (TEST_DATA_LEN, repr(EXPECTED_RESULT)))
def test_uart_readStr(self):
TEST_DATA_LEN = 10
EXPECTED_RESULT = chr(MOCK_UART_DATA_BYTE) * TEST_DATA_LEN
self.assertEqual(self.uart.readStr(TEST_DATA_LEN),
EXPECTED_RESULT,
"Running UART readStr(%d) did not return %s" % (TEST_DATA_LEN, EXPECTED_RESULT))
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSetBaudrate(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_baudrate_115200(self):
TEST_BAUDRATE = 115200
self.assertEqual(self.uart.setBaudRate(TEST_BAUDRATE),
m.SUCCESS,
"Setting baudrate to %d did not return success" % TEST_BAUDRATE)
def test_uart_baudrate_invalid_bigger_than_max(self):
TEST_BAUDRATE = 10000000
self.assertEqual(self.uart.setBaudRate(TEST_BAUDRATE),
m.ERROR_INVALID_PARAMETER,
"Setting baudrate to %d did not return INVALID_PARAMETER" % TEST_BAUDRATE)
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSetFlowControl(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_set_flowcontrol(self):
self.assertEqual(self.uart.setFlowcontrol(False, True),
m.SUCCESS,
"Running UART setFlowControl() did not return success")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSetMode(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_set_mode(self):
self.assertEqual(self.uart.setMode(8, m.UART_PARITY_NONE, 1),
m.SUCCESS,
"Running UART setMode() did not return success")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSetNonBlocking(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_set_nonblocking(self):
self.assertEqual(self.uart.setNonBlocking(True),
m.SUCCESS,
"Running UART setNonBlocking() did not return success")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSetTimeout(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_set_timeout(self):
self.assertEqual(self.uart.setTimeout(10, 10, 10),
m.SUCCESS,
"Running UART setTimeout() did not return success")
if __name__ == "__main__":
u.main()

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
MRAA_UART_DEV_NUM = 0
# This one is defined in mock_board_uart.h
MOCK_UART_DATA_BYTE = 0x5A

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
# Copyright (c) 2016 Alex Tereschenko.
#
# 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.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksWrite(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_write(self):
TEST_DATA_LEN = 10
TEST_DATA = bytearray([x for x in range(TEST_DATA_LEN)])
self.assertEqual(self.uart.write(TEST_DATA),
TEST_DATA_LEN,
"Running UART write(%s) did not return %d" % (repr(TEST_DATA), TEST_DATA_LEN))
def test_uart_writeStr(self):
TEST_DATA = "Hello"
TEST_DATA_LEN = len(TEST_DATA)
self.assertEqual(self.uart.writeStr(TEST_DATA),
TEST_DATA_LEN,
"Running UART writeStr(%s) did not return %d" % (TEST_DATA, TEST_DATA_LEN))
if __name__ == "__main__":
u.main()