Compare commits
415 Commits
v0.7.5
...
pythonmult
Author | SHA1 | Date | |
---|---|---|---|
|
8ce214ae86 | ||
|
8329bcab62 | ||
|
e8d6f38ee0 | ||
|
a177a3f729 | ||
|
99841419ab | ||
|
1cfdfcddc6 | ||
|
a321d6707f | ||
|
b6e6374370 | ||
|
bcf1584fbe | ||
|
a9de84b74a | ||
|
0ee25fbd4d | ||
|
4fc3e7a73f | ||
|
88d878648b | ||
|
828338a69a | ||
|
022b36355f | ||
|
3969af2b24 | ||
|
b15ab84f61 | ||
|
d3a220479d | ||
|
905abdec7c | ||
|
db546456d2 | ||
|
f6d9cf57c9 | ||
|
a702cdf4d5 | ||
|
800c89bfa4 | ||
|
887acf54e1 | ||
|
3a88c44620 | ||
|
5e867419bc | ||
|
4195a61e52 | ||
|
c524c3d372 | ||
|
b258867c37 | ||
|
56e45f6de5 | ||
|
cdfdd2b9e3 | ||
|
c1465bd694 | ||
|
1e4516d026 | ||
|
0b74aa68ab | ||
|
e961558fd2 | ||
|
6d8ec87e0e | ||
|
acf90073a8 | ||
|
2404b0a683 | ||
|
0da3d35a8f | ||
|
1ebe377487 | ||
|
e757844a3d | ||
|
f2c4d95c15 | ||
|
c41c3b41d5 | ||
|
4a52ad6c4f | ||
|
a379eb7bf6 | ||
|
69d9c26e6e | ||
|
62e113ed3f | ||
|
00a0abd030 | ||
|
ecf049eccd | ||
|
e1c500414b | ||
|
a9429204e3 | ||
|
faa8d4d3d4 | ||
|
b86ad8f073 | ||
|
a218056905 | ||
|
52f9c48bbc | ||
|
0fabc9b46a | ||
|
21bea74b74 | ||
|
8b02c419f8 | ||
|
296ed38227 | ||
|
14de175425 | ||
|
63a29e92ea | ||
|
49ab97f81c | ||
|
319c932036 | ||
|
35b2426170 | ||
|
8c0aa5af2c | ||
|
a7c688b867 | ||
|
6fc2bef13f | ||
|
747429ca7e | ||
|
c302269750 | ||
|
de0b9e72c6 | ||
|
2fb577d348 | ||
|
30322f8ac5 | ||
|
5cfddd6bcc | ||
|
a17079c460 | ||
|
fac9d99f01 | ||
|
ec267c3482 | ||
|
df2e131d26 | ||
|
317c85ecb6 | ||
|
f1f578363a | ||
|
0fb2aed7af | ||
|
405e601387 | ||
|
0e5dadeb8c | ||
|
9a5abb7d56 | ||
|
334a57be11 | ||
|
1d4f721d4f | ||
|
67eaf78fbf | ||
|
451dcbad6c | ||
|
a52ce5d5bb | ||
|
de42b9558f | ||
|
9b157e6f19 | ||
|
915be98d03 | ||
|
420486519b | ||
|
91452e5c83 | ||
|
5789f5001d | ||
|
7088527339 | ||
|
f07a442860 | ||
|
2919b38b15 | ||
|
603834461f | ||
|
537a69923b | ||
|
59107f0a29 | ||
|
612f566c99 | ||
|
cae63bbd52 | ||
|
04f7cbff5d | ||
|
4b76fbd14c | ||
|
78caa990f1 | ||
|
f2cbe1c68d | ||
|
10e1301bef | ||
|
edd554b606 | ||
|
168764481a | ||
|
3397c95c0a | ||
|
95c259f6b2 | ||
|
6c83886a51 | ||
|
143bc38e47 | ||
|
a51f3a939f | ||
|
65dc2e7ea3 | ||
|
14617d0f36 | ||
|
076a648ef9 | ||
|
51c60a0ac4 | ||
|
85a848960a | ||
|
a797003ec6 | ||
|
53058d500b | ||
|
029e08669c | ||
|
12b5130c1a | ||
|
237308898c | ||
|
b1fd66c561 | ||
|
bc1c3469f5 | ||
|
44b2367fdc | ||
|
d313ac0579 | ||
|
9d497e08cd | ||
|
0633cd4145 | ||
|
8230d7cb45 | ||
|
d8024bb516 | ||
|
29ddf56b67 | ||
|
3b9c4f2bad | ||
|
7f78b6760f | ||
|
441a24aaea | ||
|
9c2f3c83c9 | ||
|
65514bb432 | ||
|
c770c4c669 | ||
|
511332cda5 | ||
|
82cfa32f70 | ||
|
a387d5e4d4 | ||
|
df8d471cfb | ||
|
350a6489ee | ||
|
389d0ceafd | ||
|
8e8ed7d52d | ||
|
2b73083955 | ||
|
f9501c5c78 | ||
|
3b2a5b8429 | ||
|
00e8f72ef4 | ||
|
e354c59b6c | ||
|
ca11078fd0 | ||
|
6b3794003f | ||
|
699d476de1 | ||
|
0899f1e995 | ||
|
baa1fcf7be | ||
|
32d36dfbd0 | ||
|
2a6bf2b16d | ||
|
b33bd5ccd2 | ||
|
1865dd0ba1 | ||
|
944670f66a | ||
|
839bdb9011 | ||
|
a73882240b | ||
|
43ae362be8 | ||
|
6bf706befb | ||
|
1fd4ed5736 | ||
|
d2fcb88c4b | ||
|
cb4c9152d6 | ||
|
61011df748 | ||
|
d04911d569 | ||
|
1f57c6c082 | ||
|
51340c6289 | ||
|
14960c4190 | ||
|
c101117ece | ||
|
9202eb172d | ||
|
3e1c528571 | ||
|
1ce28ee082 | ||
|
8710280142 | ||
|
cc4fe26c09 | ||
|
084883c210 | ||
|
04f3b93f85 | ||
|
5c10ad05ee | ||
|
1015beec47 | ||
|
67f5ab7346 | ||
|
1f41b2f97e | ||
|
7fce2e2a3a | ||
|
44e705a518 | ||
|
8ff42482ec | ||
|
3924070171 | ||
|
ff31d6763c | ||
|
ba5318fee9 | ||
|
2e5e3eaea2 | ||
|
078218f680 | ||
|
c86fe2a12b | ||
|
8b68f3040e | ||
|
c564dad68f | ||
|
ecc04d7511 | ||
|
c63e38a57e | ||
|
78a4d12a37 | ||
|
0aed0003ff | ||
|
bdb5ef66e9 | ||
|
caebb8b1fb | ||
|
ab14b9de43 | ||
|
7e302242db | ||
|
3483db363f | ||
|
c2681dc78c | ||
|
6c0881848b | ||
|
03d741ff3e | ||
|
0ebab9603e | ||
|
a87a104efe | ||
|
6d391ce605 | ||
|
63604ef5cc | ||
|
a708e08101 | ||
|
8c40842e4b | ||
|
ed0124cc70 | ||
|
86a0e10c03 | ||
|
7f85f2bbdb | ||
|
92cc9ea176 | ||
|
ff6b304fd2 | ||
|
2bb00b494f | ||
|
d430b5c2b5 | ||
|
ea183b3738 | ||
|
d4b32ec1c5 | ||
|
e98bd8653a | ||
|
ff34651325 | ||
|
58cf292dfc | ||
|
15e400eaf2 | ||
|
8862ebd9f2 | ||
|
79609ba359 | ||
|
27c097e82e | ||
|
725ce5e946 | ||
|
fd531abd3d | ||
|
f4385a8b82 | ||
|
ee69045ea8 | ||
|
fcfdeb1304 | ||
|
d5233adbf9 | ||
|
4ffb094063 | ||
|
8e4a809f12 | ||
|
5f01de1bf1 | ||
|
7703634bc5 | ||
|
6a85c57c06 | ||
|
924f4b4799 | ||
|
3429b5383d | ||
|
bd4f6998a7 | ||
|
11211936b6 | ||
|
7ea11f0dd3 | ||
|
c1d081c783 | ||
|
ae80d4afc8 | ||
|
131021a629 | ||
|
0049ba1378 | ||
|
448f14f41c | ||
|
fbfe3e315f | ||
|
b77bf40c34 | ||
|
cb09ff2327 | ||
|
e975a690ab | ||
|
3750e2cfa2 | ||
|
e7e58509f0 | ||
|
8d7c0722ab | ||
|
0bd1ab2c53 | ||
|
edb7f8a215 | ||
|
219632a1b8 | ||
|
8a548de8ae | ||
|
13086cb2db | ||
|
069985641e | ||
|
657f28a67d | ||
|
2df28fa883 | ||
|
078b6371d7 | ||
|
7a55a1384a | ||
|
dc240913c7 | ||
|
4c41d2c2df | ||
|
e5f28ab04c | ||
|
325ac461d6 | ||
|
7fa4990d81 | ||
|
3b55cc70bf | ||
|
65614f5f58 | ||
|
529cf8a26e | ||
|
acfb74f04e | ||
|
2c97fd5953 | ||
|
b192e7a223 | ||
|
2b9e832ff9 | ||
|
d8c2c7c483 | ||
|
8c19105309 | ||
|
ba9ab4b384 | ||
|
d920d136ea | ||
|
0f312545e0 | ||
|
1947426baf | ||
|
f9a31956ab | ||
|
d80e4295aa | ||
|
36fabe3245 | ||
|
c0dfb71237 | ||
|
47ec54c333 | ||
|
38aa9e8fe6 | ||
|
5e0c6d3807 | ||
|
b2e8af641b | ||
|
e14534b071 | ||
|
5cf54fdbc2 | ||
|
759d387c5a | ||
|
ccafc77641 | ||
|
2dd94cda3b | ||
|
b1016635c3 | ||
|
c7a405a531 | ||
|
063a3154aa | ||
|
5f4f0a2aef | ||
|
1c7bd53bf3 | ||
|
efc79d13c0 | ||
|
e8cb060f4e | ||
|
93839d4865 | ||
|
caaf36dfb6 | ||
|
8d252c62cd | ||
|
57b3775ae9 | ||
|
2dd46494ff | ||
|
5b1068fc62 | ||
|
bde9715c94 | ||
|
90accf7b04 | ||
|
fa772a0a9d | ||
|
80024ff184 | ||
|
049ba5fa9f | ||
|
937a38c4ac | ||
|
cd4626852d | ||
|
8e63c718e4 | ||
|
51436f6a0a | ||
|
0836067900 | ||
|
c89b04eb19 | ||
|
6aaf48940e | ||
|
bf803209aa | ||
|
799f1409b9 | ||
|
df8492a8f7 | ||
|
63ff901674 | ||
|
f9af006c97 | ||
|
621bf5266e | ||
|
338feb2c3e | ||
|
dbd1a31536 | ||
|
3c3136d43a | ||
|
b8e1f79b4d | ||
|
e6c3dd24a6 | ||
|
3059c06fa0 | ||
|
24d4446193 | ||
|
18249d5ecc | ||
|
31750be753 | ||
|
a7414edca3 | ||
|
06e5e7dc11 | ||
|
42d169e003 | ||
|
bda9f4d211 | ||
|
0e44dfac44 | ||
|
013c04c7b9 | ||
|
b7a0968489 | ||
|
2db72217d5 | ||
|
08fe460772 | ||
|
70600dece4 | ||
|
eae2b58cbe | ||
|
7d11bd4cdc | ||
|
effc813e42 | ||
|
32aa4310c8 | ||
|
434f454139 | ||
|
1a29dc9910 | ||
|
0aac9df414 | ||
|
e2aaa349ff | ||
|
0071039fa0 | ||
|
35760929db | ||
|
c9c6ac785a | ||
|
5c7bab1c79 | ||
|
b650a9fdc9 | ||
|
f245cacd6f | ||
|
99b7f131d9 | ||
|
54bf18b246 | ||
|
17eb7a791a | ||
|
1937473c01 | ||
|
a0791f8277 | ||
|
3934897864 | ||
|
679d1a55b6 | ||
|
b2a0bbfcbc | ||
|
07343e2ee7 | ||
|
fc55088c03 | ||
|
a49d8d6d12 | ||
|
2101e491ce | ||
|
6284806b96 | ||
|
3e76bee085 | ||
|
ba85c9ebc2 | ||
|
b841d6c75c | ||
|
c03d746544 | ||
|
c84cd4328a | ||
|
570fba9463 | ||
|
4757d039ab | ||
|
eb5a3ac5d2 | ||
|
5bd5f2d546 | ||
|
4031124081 | ||
|
b109a12dd1 | ||
|
308289497e | ||
|
4acb0e5562 | ||
|
b20a685b0c | ||
|
79e33890b6 | ||
|
7c5972ad15 | ||
|
c9cfb42326 | ||
|
93d326bff4 | ||
|
89d25cffeb | ||
|
99901d05f7 | ||
|
33645791af | ||
|
453eefc56a | ||
|
001e291d63 | ||
|
802c5af986 | ||
|
11bf69e29a | ||
|
7058fea8bd | ||
|
99593ec640 | ||
|
13118e949b | ||
|
30cf8ec560 | ||
|
5740e46ae0 | ||
|
d5e5539be3 | ||
|
7ada55982d | ||
|
6302b635aa | ||
|
4a6bf832bc | ||
|
1c9b87bfd3 | ||
|
e353508e30 | ||
|
e170e21031 | ||
|
6dfe6ff6bc | ||
|
8f48df0533 |
31
.travis.yml
31
.travis.yml
@@ -1,9 +1,34 @@
|
||||
language: cpp
|
||||
env:
|
||||
- NODE010=true
|
||||
- NODE012=true
|
||||
- NODE4=true
|
||||
- NODE5=true
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
- gcc
|
||||
install:
|
||||
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
|
||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y -qq swig python git
|
||||
- sudo apt-get install -y -qq swig3.0 python git cmake
|
||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||
- sudo update-java-alternatives -s java-8-oracle
|
||||
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 [ "${NODE012}" ]; then nvm install 0.12; fi
|
||||
- if [ "${NODE4}" ]; then nvm install 4.1; fi
|
||||
- if [ "${NODE5}" ]; then nvm install 5; fi
|
||||
# Handle 0.10 NODE_ROOT_DIR differently than other versions
|
||||
- if [ -z ${NODE010} ]; then export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; else export NODE_ROOT_DIR=/home/travis/.nvm/v0.10.36; fi
|
||||
script:
|
||||
- mkdir build && cd build && cmake -DBUILDSWIGPYTHON=ON .. && make && make test
|
||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
||||
- mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DCMAKE_INSTALL_PREFIX:PATH=../install .. && make install && make test
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
|
61
Android.mk
Normal file
61
Android.mk
Normal file
@@ -0,0 +1,61 @@
|
||||
# Copyright (C) 2015 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libmraa
|
||||
LOCAL_CFLAGS += -Wno-unused-parameter -DX86PLAT=1
|
||||
LOCAL_SHARED_LIBRARIES := libcutils libutils libdl libc
|
||||
LOCAL_SRC_FILES := \
|
||||
src/mraa.c \
|
||||
src/gpio/gpio.c \
|
||||
src/i2c/i2c.c \
|
||||
src/pwm/pwm.c \
|
||||
src/spi/spi.c \
|
||||
src/aio/aio.c \
|
||||
src/uart/uart.c \
|
||||
src/x86/x86.c \
|
||||
src/iio/iio.c \
|
||||
src/x86/intel_galileo_rev_d.c \
|
||||
src/x86/intel_galileo_rev_g.c \
|
||||
src/x86/intel_edison_fab_c.c \
|
||||
src/x86/intel_de3815.c \
|
||||
src/x86/intel_nuc5.c \
|
||||
src/x86/intel_sofia_3gr.c \
|
||||
src/x86/intel_minnow_byt_compatible.c \
|
||||
src/x86/intel_cherryhills.c \
|
||||
src/x86/up.c
|
||||
|
||||
# glob.c pulled in from NetBSD project (BSD 3-clause License)
|
||||
LOCAL_SRC_FILES += \
|
||||
src/glob/glob.c
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/include/linux \
|
||||
$(LOCAL_PATH)/include/x86 \
|
||||
$(LOCAL_PATH)/api \
|
||||
$(LOCAL_PATH)/api/mraa \
|
||||
$(LOCAL_PATH)/src/glob
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDE_DIRS := \
|
||||
$(LOCAL_PATH)/api \
|
||||
$(LOCAL_PATH)/api/mraa
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
@@ -1,27 +1,41 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project (mraa)
|
||||
project (mraa C)
|
||||
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
|
||||
set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer ")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
|
||||
|
||||
# Set CMAKE_LIB_INSTALL_DIR if not defined
|
||||
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Older cmake might not pick CMAKE_INSTALL_LIBDIR right
|
||||
if (CMAKE_INSTALL_LIBDIR)
|
||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
||||
else ()
|
||||
set (LIB_INSTALL_DIR "lib" CACHE PATH "Installation path for libraries")
|
||||
endif ()
|
||||
|
||||
# By default, build shared object libraries on linux
|
||||
if (UNIX AND NOT APPLE)
|
||||
if (NOT DEFINED BUILD_SHARED_LIBS)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||
|
||||
# Make a version file containing the current version from git.
|
||||
include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.7.5-dirty")
|
||||
set (VERSION "v1.0.0-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - libmraa Version ${VERSION}")
|
||||
message (STATUS "INFO - libmraa Version ${VERSION}")
|
||||
message (STATUS "INFO - cmake Version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
|
||||
|
||||
#parse the version information into pieces.
|
||||
string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
|
||||
@@ -54,13 +68,20 @@ option (BUILDSWIG "Build swig modules." ON)
|
||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||
option (BUILDSWIGNODE "Build swig node modules." ON)
|
||||
option (BUILDSWIGJAVA "Build Java API." OFF)
|
||||
option (USBPLAT "Detection USB platform." OFF)
|
||||
option (FIRMATA "Add Firmata support to mraa." OFF)
|
||||
option (ONEWIRE "Add Onewire support to mraa." ON)
|
||||
option (IMRAA "Add Imraa support to mraa." OFF)
|
||||
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (BUILDPYTHON3 "Use python3 for building/installing" OFF)
|
||||
option (ENABLEEXAMPLES "Disable building of examples" ON)
|
||||
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
|
||||
option (INSTALLTOOLS "Install all tools" OFF)
|
||||
option (BUILDARCH "Override architecture to build for - override" OFF)
|
||||
option (TESTS "Override the addition of tests" ON)
|
||||
option (BUILDTESTS "Override the addition of tests" ON)
|
||||
|
||||
set (MRAAPLATFORMFORCE "" CACHE STRING "ALL")
|
||||
|
||||
if (NOT BUILDSWIG)
|
||||
set (BUILDSWIGPYTHON OFF)
|
||||
@@ -71,10 +92,10 @@ endif()
|
||||
if (NOT BUILDARCH)
|
||||
include (TargetArch)
|
||||
target_architecture (DETECTED_ARCH)
|
||||
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
||||
message (STATUS "INFO - Target arch is ${DETECTED_ARCH}")
|
||||
else ()
|
||||
set (DETECTED_ARCH ${BUILDARCH})
|
||||
message( INFO " - Override arch is ${DETECTED_ARCH}")
|
||||
message (STATUS "INFO - Override arch is ${DETECTED_ARCH}")
|
||||
endif()
|
||||
|
||||
if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
|
||||
@@ -83,22 +104,11 @@ if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
|
||||
elseif (DETECTED_ARCH MATCHES "arm.*")
|
||||
set (ARMPLAT ON)
|
||||
else ()
|
||||
message(FATAL_ERROR "Only x86 and arm platforms currently supported")
|
||||
message (FATAL_ERROR "Only x86 and arm platforms currently supported")
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
else ()
|
||||
set (PYTHONBUILD_VERSION 2.7)
|
||||
endif ()
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
if (TESTS)
|
||||
if (${PYTHONINTERP_FOUND})
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
endif ()
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
include (cmake/modules/OpenCVDetectPython.cmake)
|
||||
endif ()
|
||||
|
||||
if (BUILDDOC)
|
||||
@@ -106,6 +116,9 @@ if (BUILDDOC)
|
||||
find_package (Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/src/java/Doxyfile @ONLY)
|
||||
endif ()
|
||||
add_custom_target (doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
@@ -127,9 +140,9 @@ if (IPK)
|
||||
set (TARGET_ARCH ${DETECTED_ARCH})
|
||||
endif ()
|
||||
endif ()
|
||||
message (INFO " - Package arch is ${TARGET_ARCH}")
|
||||
message (STATUS "INFO - Package arch is ${TARGET_ARCH}")
|
||||
|
||||
set(CPACK_GENERATOR "DEB" "TGZ")
|
||||
set(CPACK_GENERATOR "DEB")
|
||||
set(OPKG_ARCH ${TARGET_ARCH})
|
||||
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
||||
@@ -137,7 +150,7 @@ if (IPK)
|
||||
if ("${VERSION_COMMIT}" STREQUAL "")
|
||||
set(mraa_PACKAGE_ON_TAG "")
|
||||
endif()
|
||||
set(CPACK_PACKAGE_VERSION
|
||||
set(CPACK_PACKAGE_VERSION
|
||||
"${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
||||
set(CPACK_PACKAGE_NAME "mraa")
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
@@ -151,7 +164,8 @@ if (IPK)
|
||||
endif()
|
||||
|
||||
if (RPM)
|
||||
message (INFO " - Enabled RPM packaging for ${DETECTED_ARCH}")
|
||||
message (STATUS "INFO - Enabled RPM packaging for ${DETECTED_ARCH}")
|
||||
set(CMAKE_INSTALL_PREFIX "/usr")
|
||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
|
||||
@@ -161,12 +175,14 @@ if (RPM)
|
||||
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
||||
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
||||
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
|
||||
EXECUTE_PROCESS(COMMAND rpm --showrc
|
||||
COMMAND grep -E "dist[[:space:]]*\\."
|
||||
COMMAND sed -e "s/^.*dist\\s*\\.//"
|
||||
COMMAND tr \\n \\t
|
||||
COMMAND sed -e s/\\t//
|
||||
OUTPUT_VARIABLE DIST_TAG)
|
||||
# Get distro tag (e.g. 'fc20') by parsing output of rpm --showrc
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND rpm --showrc
|
||||
COMMAND grep -w dist
|
||||
COMMAND sed -e "s/\\t./ /"
|
||||
COMMAND awk "{printf \"%s\", \$NF}"
|
||||
OUTPUT_VARIABLE DIST_TAG
|
||||
)
|
||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
|
||||
include(CPack)
|
||||
endif()
|
||||
@@ -175,3 +191,12 @@ add_subdirectory (src)
|
||||
if (ENABLEEXAMPLES)
|
||||
add_subdirectory (examples)
|
||||
endif ()
|
||||
|
||||
if (IMRAA)
|
||||
add_subdirectory (imraa)
|
||||
endif ()
|
||||
|
||||
if (BUILDTESTS AND PYTHON_DEFAULT_EXECUTABLE)
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Contributing to libmraa {#contributing}
|
||||
Contributing to libmraa {#contributing}
|
||||
======================
|
||||
|
||||
libmraa is an opensource project and we are actively looking for people to help
|
||||
@@ -13,7 +13,8 @@ requests to the main project. You can open issues if you find any bugs/have
|
||||
questions.
|
||||
|
||||
If you'd rather not use github you are more than welcome to send git formatted
|
||||
patches to brendan.le.foll@intel.com.
|
||||
patches to our mailing list mraa@lists.01.org which you can register for access
|
||||
on: https://lists.01.org/mailman/listinfo/mraa
|
||||
|
||||
Basic rules
|
||||
-----------
|
3
COPYING
3
COPYING
@@ -1,4 +1,5 @@
|
||||
Copyright © 2014 Intel Corporation
|
||||
The MIT License (MIT)
|
||||
Copyright © 2014-2016 Intel Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
@@ -755,7 +755,8 @@ WARN_LOGFILE =
|
||||
|
||||
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/api/ \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/api/mraa/ \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/docs/
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/docs/ \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/CONTRIBUTING.md
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
|
2324
Doxyfile.java.in
Normal file
2324
Doxyfile.java.in
Normal file
File diff suppressed because it is too large
Load Diff
55
README.md
55
README.md
@@ -1,10 +1,13 @@
|
||||
<p align="center">
|
||||
<img src="http://iotdk.intel.com/misc/logos/mraa.png" height="150px" width="auto" algt="Mraa Logo"/>
|
||||
</p>
|
||||
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
|
||||
==============
|
||||
|
||||
Libmraa is a C/C++ library with bindings to javascript & python to interface
|
||||
with the IO on Galileo, Edison & other platforms, with a structured and sane
|
||||
API where port names/numbering matches the board that you are on. Use of
|
||||
libmraa does not tie you to specific hardware with board detection done at
|
||||
Libmraa is a C/C++ library with bindings to Java, Python and JavaScript to
|
||||
interface with the IO on Galileo, Edison & other platforms, with a structured
|
||||
and sane API where port names/numbering matches the board that you are on. Use
|
||||
of libmraa does not tie you to specific hardware with board detection done at
|
||||
runtime you can create portable code that will work across the supported
|
||||
platforms.
|
||||
|
||||
@@ -23,6 +26,7 @@ X86
|
||||
* [Intel DE3815](../master/docs/intel_de3815.md)
|
||||
* [Minnowboard Max](../master/docs/minnow_max.md)
|
||||
* [NUC 5th generation](../master/docs/intel_nuc5.md)
|
||||
* [UP](../master/docs/up.md)
|
||||
|
||||
ARM
|
||||
---
|
||||
@@ -30,26 +34,30 @@ ARM
|
||||
* [Bannana Pi](../master/docs/banana_pi.md)
|
||||
* [Beaglebone Black](../master/docs/beaglebone.md)
|
||||
|
||||
USB
|
||||
---
|
||||
* [FT4222](../master/docs/ftdi_ft4222.md)
|
||||
|
||||
Installing on your board
|
||||
========
|
||||
|
||||
See the section below on compiling or use our repository to install on an
|
||||
eglibc 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!
|
||||
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/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
opkg update
|
||||
opkg install libmraa0
|
||||
opkg install mraa
|
||||
```
|
||||
|
||||
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/1.1/intelgalactic-dev" > /etc/opkg/mraa-upm.conf
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
opkg update
|
||||
opkg install libmraa0
|
||||
opkg install mraa
|
||||
```
|
||||
|
||||
You can also install just the node.js mraa module by using npm. You will need a
|
||||
@@ -78,17 +86,24 @@ issues in github or join us in #mraa on freenode IRC, hang around for a little
|
||||
while because we're not necessarily on 24/7, but we'll get back to you! Have a
|
||||
glance at our [debugging](../master/docs/debugging.md) page too.
|
||||
|
||||
C/C++ API Documentation
|
||||
===========
|
||||
API Documentation
|
||||
=================
|
||||
|
||||
The C/C++ documentation is available [here](http://iotdk.intel.com/docs/master/mraa/)
|
||||
<a href="http://c.mraa.io"><img src="http://iotdk.intel.com/misc/logos/c++.png"/></a>
|
||||
<a href="http://java.mraa.io"><img src="http://iotdk.intel.com/misc/logos/java.png"/></a>
|
||||
<a href="http://py.mraa.io"><img src="http://iotdk.intel.com/misc/logos/python.png"/></a>
|
||||
<a href="http://js.mraa.io"><img src="http://iotdk.intel.com/misc/logos/node.png"/></a>
|
||||
|
||||
Python API Documentation
|
||||
===========
|
||||
Contact Us
|
||||
==========
|
||||
|
||||
The Python documentation is available [here](http://iotdk.intel.com/docs/master/mraa/python)
|
||||
To ask questions either file issues in github or send emails on our [mailing
|
||||
list](https://lists.01.org/mailman/listinfo/mraa). You might also catch us on
|
||||
the mraa channel on freenode IRC.
|
||||
|
||||
NodeJS API documentation
|
||||
===========
|
||||
See the [Contribution](CONTRIBUTING.md) documentation for more details.
|
||||
|
||||
The Javascript documention is available [here](http://iotdk.intel.com/docs/master/mraa/node/modules/mraa.html)
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Version changelog [here](docs/changelog.md).
|
||||
|
@@ -33,6 +33,7 @@ extern "C" {
|
||||
#include "mraa/spi.h"
|
||||
#include "mraa/i2c.h"
|
||||
#include "mraa/uart.h"
|
||||
#include "mraa/uart_ow.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -59,19 +59,20 @@ typedef struct _aio* mraa_aio_context;
|
||||
mraa_aio_context mraa_aio_init(unsigned int pin);
|
||||
|
||||
/**
|
||||
* Read the input voltage. By default mraa will shift
|
||||
* the raw value up or down to a 10 bit value.
|
||||
* Read the input voltage. By default mraa will shift the raw value up or down
|
||||
* to a 10 bit value.
|
||||
*
|
||||
* @param dev The AIO context
|
||||
* @returns The current input voltage.
|
||||
* @returns The current input voltage or -1 for error
|
||||
*/
|
||||
unsigned int mraa_aio_read(mraa_aio_context dev);
|
||||
int mraa_aio_read(mraa_aio_context dev);
|
||||
|
||||
/**
|
||||
* Read the input voltage and return it as a normalized float (0.0f-1.0f).
|
||||
*
|
||||
* @param dev The AIO context
|
||||
* @returns The current input voltage as a normalized float (0.0f-1.0f)
|
||||
* @returns The current input voltage as a normalized float (0.0f-1.0f), error
|
||||
* will be signaled by -1.0f
|
||||
*/
|
||||
float mraa_aio_read_float(mraa_aio_context dev);
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include "aio.h"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace mraa
|
||||
{
|
||||
@@ -35,7 +36,7 @@ namespace mraa
|
||||
*
|
||||
* This file defines the aio interface for libmraa
|
||||
*
|
||||
* @snippet examples/c++/AioA0.cpp Interesting
|
||||
* @snippet AioA0.cpp Interesting
|
||||
*/
|
||||
class Aio
|
||||
{
|
||||
@@ -46,13 +47,26 @@ class Aio
|
||||
*
|
||||
* @param pin channel number to read ADC inputs
|
||||
*/
|
||||
Aio(unsigned int pin)
|
||||
Aio(int pin)
|
||||
{
|
||||
m_aio = mraa_aio_init(pin);
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio Constructor, takes a pointer to the AIO context and initialises
|
||||
* the AIO class
|
||||
*
|
||||
* @param void * to an AIO context
|
||||
*/
|
||||
Aio(void* aio_context)
|
||||
{
|
||||
m_aio = (mraa_aio_context) aio_context;
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio destructor
|
||||
*/
|
||||
@@ -64,33 +78,43 @@ class Aio
|
||||
* Read a value from the AIO pin. By default mraa will shift
|
||||
* the raw value up or down to a 10 bit value.
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @returns The current input voltage. By default, a 10bit value
|
||||
*/
|
||||
int
|
||||
unsigned int
|
||||
read()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
int x = mraa_aio_read(m_aio);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in Aio::read()");
|
||||
}
|
||||
return (unsigned int) x;
|
||||
}
|
||||
/**
|
||||
* Read a value from the AIO pin and return it as a normalized float.
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @returns The current input voltage as a normalized float (0.0f-1.0f)
|
||||
*/
|
||||
float
|
||||
readFloat()
|
||||
{
|
||||
return mraa_aio_read_float(m_aio);
|
||||
float x = mraa_aio_read_float(m_aio);
|
||||
if (x == -1.0f) {
|
||||
throw std::invalid_argument("Unknown error in Aio::readFloat()");
|
||||
}
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* Set the bit value which mraa will shift the raw reading
|
||||
* from the ADC to. I.e. 10bits
|
||||
* @param bits the bits the return from read should be i.e 10
|
||||
* @return mraa result type
|
||||
* @return mraa::Result type
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
setBit(int bits)
|
||||
{
|
||||
return mraa_aio_set_bit(m_aio, bits);
|
||||
return (Result) mraa_aio_set_bit(m_aio, bits);
|
||||
}
|
||||
/**
|
||||
* Gets the bit value mraa is shifting the analog read to.
|
||||
|
@@ -24,11 +24,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "types.h"
|
||||
|
||||
#define MRAA_PLATFORM_NAME_MAX_SIZE 64
|
||||
#define MRAA_PIN_NAME_SIZE 12
|
||||
|
||||
#define MRAA_SUB_PLATFORM_BIT_SHIFT 9
|
||||
#define MRAA_SUB_PLATFORM_MASK (1<<MRAA_SUB_PLATFORM_BIT_SHIFT)
|
||||
|
||||
#define MRAA_MAIN_PLATFORM_OFFSET 0
|
||||
#define MRAA_SUB_PLATFORM_OFFSET 1
|
||||
|
||||
/** Executes function func and returns its result in case of error
|
||||
*/
|
||||
#define MRAA_RETURN_FOR_ERROR(func) do { \
|
||||
mraa_result_t res; \
|
||||
res = func; \
|
||||
if (res != MRAA_SUCCESS) \
|
||||
return res;} while(0)
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the basic shared values for libmraa
|
||||
@@ -49,9 +64,7 @@ typedef unsigned int mraa_boolean_t;
|
||||
*
|
||||
* Detects running platform and attempts to use included pinmap, this is run on
|
||||
* module/library init/load but is handy to rerun to check board initialised
|
||||
* correctly. MRAA_SUCCESS inidicates correct (first time) initialisation
|
||||
* whilst MRAA_ERROR_PLATFORM_ALREADY_INITIALISED indicates the board is
|
||||
* already initialised correctly
|
||||
* correctly. MRAA_SUCCESS inidicates correct initialisation.
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
@@ -89,6 +102,14 @@ mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode);
|
||||
*/
|
||||
unsigned int mraa_adc_raw_bits();
|
||||
|
||||
/**
|
||||
* Check the specified board's bit size when reading the value
|
||||
*
|
||||
* @param specified platform offset; 0 for main platform, 1 foor sub platform
|
||||
* @return raw bits being read from kernel module. zero if no ADC
|
||||
*/
|
||||
unsigned int mraa_get_platform_adc_raw_bits(uint8_t platform_offset);
|
||||
|
||||
/**
|
||||
* Return value that the raw value should be shifted to. Zero if no ADC
|
||||
*
|
||||
@@ -96,6 +117,14 @@ unsigned int mraa_adc_raw_bits();
|
||||
*/
|
||||
unsigned int mraa_adc_supported_bits();
|
||||
|
||||
/**
|
||||
* Return value that the raw value should be shifted to. Zero if no ADC
|
||||
*
|
||||
* @param specified platform offset; 0 for main platform, 1 foor sub platform
|
||||
* @return return actual bit size the adc value should be understood as.
|
||||
*/
|
||||
unsigned int mraa_get_platform_adc_supported_bits(int platform_offset);
|
||||
|
||||
/**
|
||||
* Sets the log level to use from 0-7 where 7 is very verbose. These are the
|
||||
* syslog log levels, see syslog(3) for more information on the levels.
|
||||
@@ -109,7 +138,17 @@ mraa_result_t mraa_set_log_level(int level);
|
||||
*
|
||||
* @return platform name
|
||||
*/
|
||||
char* mraa_get_platform_name();
|
||||
const char* mraa_get_platform_name();
|
||||
|
||||
/**
|
||||
* Return the platform's versioning info, the information given depends per
|
||||
* platform and can be NULL. platform_offset has to be given. Do not modify
|
||||
* this pointer
|
||||
*
|
||||
* @param specified platform offset; 0 for main platform, 1 for sub platform
|
||||
* @return platform's versioning string
|
||||
*/
|
||||
const char* mraa_get_platform_version(int platform_offset);
|
||||
|
||||
/**
|
||||
* This function attempts to set the mraa process to a given priority and the
|
||||
@@ -120,7 +159,7 @@ char* mraa_get_platform_name();
|
||||
* @param priority Value from typically 0 to 99
|
||||
* @return The priority value set
|
||||
*/
|
||||
int mraa_set_priority(const unsigned int priority);
|
||||
int mraa_set_priority(const int priority);
|
||||
|
||||
/** Get the version string of mraa autogenerated from git tag
|
||||
*
|
||||
@@ -145,6 +184,15 @@ void mraa_result_print(mraa_result_t result);
|
||||
*/
|
||||
mraa_platform_t mraa_get_platform_type();
|
||||
|
||||
/**
|
||||
* Get combined platform type, board must be initialised.
|
||||
* The combined type is represented as
|
||||
* (sub_platform_type << 8) | main_platform_type
|
||||
*
|
||||
* @return int combined platform type
|
||||
*/
|
||||
int mraa_get_platform_combined_type();
|
||||
|
||||
/**
|
||||
* Get platform pincount, board must be initialised.
|
||||
*
|
||||
@@ -166,7 +214,15 @@ int mraa_get_i2c_bus_count();
|
||||
* @param i2c_bus the logical I2C bus number
|
||||
* @return I2C adapter number in sysfs. Function will return -1 on failure
|
||||
*/
|
||||
int mraa_get_i2c_bus_id(unsigned int i2c_bus);
|
||||
int mraa_get_i2c_bus_id(int i2c_bus);
|
||||
|
||||
/**
|
||||
* Get specified platform pincount, board must be initialised.
|
||||
*
|
||||
* @param specified platform offset; 0 for main platform, 1 foor sub platform
|
||||
* @return uint of physical pin count on the in-use platform
|
||||
*/
|
||||
unsigned int mraa_get_platform_pin_count(uint8_t platform_offset);
|
||||
|
||||
/**
|
||||
* Get name of pin, board must be initialised.
|
||||
@@ -176,6 +232,80 @@ int mraa_get_i2c_bus_id(unsigned int i2c_bus);
|
||||
*/
|
||||
char* mraa_get_pin_name(int pin);
|
||||
|
||||
/**
|
||||
* Get default i2c bus, board must be initialised.
|
||||
*
|
||||
* @return int default i2c bus index
|
||||
*/
|
||||
int mraa_get_default_i2c_bus(uint8_t platform_offset);
|
||||
|
||||
/**
|
||||
* Detect presence of sub platform.
|
||||
*
|
||||
* @return mraa_boolean_t 1 if sub platform is present and initialized, 0 otherwise
|
||||
*/
|
||||
mraa_boolean_t mraa_has_sub_platform();
|
||||
|
||||
|
||||
/**
|
||||
* Check if pin or bus id includes sub platform mask.
|
||||
*
|
||||
* @param int pin or bus number
|
||||
*
|
||||
* @return mraa_boolean_t 1 if pin or bus is for sub platform, 0 otherwise
|
||||
*/
|
||||
mraa_boolean_t mraa_is_sub_platform_id(int pin_or_bus_id);
|
||||
|
||||
/**
|
||||
* Convert pin or bus index to corresponding sub platform id.
|
||||
*
|
||||
* @param int pin or bus index
|
||||
*
|
||||
* @return int sub platform pin or bus number
|
||||
*/
|
||||
int mraa_get_sub_platform_id(int pin_or_bus_index);
|
||||
|
||||
/**
|
||||
* Convert pin or bus sub platform id to index.
|
||||
*
|
||||
* @param int sub platform pin or bus id
|
||||
*
|
||||
* @return int pin or bus index
|
||||
*/
|
||||
int mraa_get_sub_platform_index(int pin_or_bus_id);
|
||||
|
||||
/**
|
||||
* Add mraa subplatform
|
||||
*
|
||||
* @param subplatform type
|
||||
* @param uart device subplatform is on
|
||||
*
|
||||
* @return mraa_result_t indicating success
|
||||
*/
|
||||
mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev);
|
||||
|
||||
/**
|
||||
* Remove a mraa subplatform
|
||||
*
|
||||
* @param subplatform type
|
||||
*
|
||||
* @return mraa_result indicating success
|
||||
*/
|
||||
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype);
|
||||
|
||||
/**
|
||||
* Create IO using a description in the format:
|
||||
* [io]-[pin]
|
||||
* [io]-[raw]-[pin]
|
||||
* [io]-[raw]-[id]-[pin]
|
||||
* [io]-[raw]-[path]
|
||||
*
|
||||
* @param IO description
|
||||
*
|
||||
* @return void* to IO context or NULL
|
||||
*/
|
||||
void* mraa_init_io(const char* desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "types.hpp"
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
@@ -45,16 +46,14 @@ namespace mraa
|
||||
*
|
||||
* Detects running platform and attempts to use included pinmap, this is run on
|
||||
* module/library init/load but is handy to rerun to check board initialised
|
||||
* correctly. MRAA_SUCCESS inidicates correct (first time) initialisation
|
||||
* whilst MRAA_ERROR_PLATFORM_ALREADY_INITIALISED indicates the board is
|
||||
* already initialised correctly
|
||||
* correctly. mraa::SUCCESS inidicates correct initialisation.
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
inline mraa_result_t
|
||||
inline Result
|
||||
init()
|
||||
{
|
||||
return mraa_init();
|
||||
return (Result) mraa_init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +78,7 @@ getVersion()
|
||||
* @return The priority value set
|
||||
*/
|
||||
inline int
|
||||
setPriority(const unsigned int priority)
|
||||
setPriority(const int priority)
|
||||
{
|
||||
return mraa_set_priority(priority);
|
||||
}
|
||||
@@ -87,23 +86,23 @@ setPriority(const unsigned int priority)
|
||||
/**
|
||||
* Get platform type, board must be initialised.
|
||||
*
|
||||
* @return mraa_platform_t Platform type enum
|
||||
* @return mraa::platform Platform type enum
|
||||
*/
|
||||
inline mraa_platform_t
|
||||
inline Platform
|
||||
getPlatformType()
|
||||
{
|
||||
return mraa_get_platform_type();
|
||||
return (Platform) mraa_get_platform_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a textual representation of the mraa_result_t
|
||||
* Print a textual representation of the mraa::Result
|
||||
*
|
||||
* @param result the result to print
|
||||
* @param Result the Result to print
|
||||
*/
|
||||
inline void
|
||||
printError(mraa_result_t result)
|
||||
printError(Result result)
|
||||
{
|
||||
mraa_result_print(result);
|
||||
mraa_result_print((mraa_result_t) result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,9 +113,9 @@ printError(mraa_result_t result)
|
||||
* @return boolean if the mode is supported, 0=false.
|
||||
*/
|
||||
inline bool
|
||||
pinModeTest(int pin, mraa_pinmodes_t mode)
|
||||
pinModeTest(int pin, Pinmodes mode)
|
||||
{
|
||||
return (bool) mraa_pin_mode_test(pin, mode);
|
||||
return (bool) mraa_pin_mode_test(pin, (mraa_pinmodes_t) mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +152,19 @@ getPlatformName()
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return platform versioning info. Returns NULL if no info present.
|
||||
*
|
||||
* @param optional subplatform identifier
|
||||
* @return platform versioning info
|
||||
*/
|
||||
inline std::string
|
||||
getPlatformVersion(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
|
||||
{
|
||||
std::string ret_val(mraa_get_platform_version(platform_offset));
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return count of physical pins on the running platform
|
||||
*
|
||||
@@ -183,7 +195,7 @@ getI2cBusCount()
|
||||
* @return I2C adapter number in sysfs. Function will return -1 on failure
|
||||
*/
|
||||
inline int
|
||||
getI2cBusId(unsigned int i2c_bus)
|
||||
getI2cBusId(int i2c_bus)
|
||||
{
|
||||
return mraa_get_i2c_bus_id(i2c_bus);
|
||||
}
|
||||
@@ -209,9 +221,110 @@ getPinName(int pin)
|
||||
* @param level
|
||||
* @return Result of operation
|
||||
*/
|
||||
inline mraa_result_t
|
||||
inline Result
|
||||
setLogLevel(int level)
|
||||
{
|
||||
return mraa_set_log_level(level);
|
||||
return (Result) mraa_set_log_level(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect presence of sub platform.
|
||||
*
|
||||
* @return bool true if sub platform is present and initialized, false otherwise
|
||||
*/
|
||||
inline bool
|
||||
hasSubPlatform()
|
||||
{
|
||||
return static_cast<bool>(mraa_has_sub_platform());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if pin or bus id includes sub platform mask.
|
||||
*
|
||||
* @param int pin or bus number
|
||||
*
|
||||
* @return mraa_boolean_t 1 if pin or bus is for sub platform, 0 otherwise
|
||||
*/
|
||||
inline bool
|
||||
isSubPlatformId(int pin_or_bus_id)
|
||||
{
|
||||
return static_cast<bool>(mraa_is_sub_platform_id(pin_or_bus_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert pin or bus index to corresponding sub platform id.
|
||||
*
|
||||
* @param int pin or bus index
|
||||
*
|
||||
* @return int sub platform pin or bus number
|
||||
*/
|
||||
inline int
|
||||
getSubPlatformId(int pin_or_bus_index)
|
||||
{
|
||||
return mraa_get_sub_platform_id(pin_or_bus_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert pin or bus sub platform id to index.
|
||||
*
|
||||
* @param int sub platform pin or bus id
|
||||
*
|
||||
* @return int pin or bus index
|
||||
*/
|
||||
inline int
|
||||
getSubPlatformIndex(int pin_or_bus_id)
|
||||
{
|
||||
return mraa_get_sub_platform_index(pin_or_bus_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default i2c bus, board must be initialised.
|
||||
*
|
||||
* @param optional subplatform identifier
|
||||
* @return default i2c bus for paltform
|
||||
*/
|
||||
inline int
|
||||
getDefaultI2cBus(int platform_offset=MRAA_MAIN_PLATFORM_OFFSET)
|
||||
{
|
||||
return mraa_get_default_i2c_bus(platform_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mraa subplatform
|
||||
*
|
||||
* @param subplatformtype the type of subplatform to add
|
||||
* (e.g. MRAA_GENERIC_FIRMATA)
|
||||
* @param uart_dev subplatform device string (e.g. "/dev/ttyACM0")
|
||||
* @return Result of operation
|
||||
*/
|
||||
inline Result
|
||||
addSubplatform(Platform subplatformtype, std::string uart_dev)
|
||||
{
|
||||
return (Result) mraa_add_subplatform((mraa_platform_t) subplatformtype, uart_dev.c_str());
|
||||
}
|
||||
|
||||
inline Result
|
||||
removeSubplatform(Platform subplatformtype)
|
||||
{
|
||||
return (Result) mraa_remove_subplatform((mraa_platform_t) subplatformtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create IO using a description in the format:
|
||||
* [io]-[pin]
|
||||
* [io]-[raw]-[pin]
|
||||
* [io]-[raw]-[id]-[pin]
|
||||
* [io]-[raw]-[path]
|
||||
*
|
||||
* @param IO description
|
||||
*
|
||||
* @return class T initialised using pointer to IO or NULL
|
||||
*/
|
||||
template <class T>
|
||||
inline T*
|
||||
initIo(std::string desc)
|
||||
{
|
||||
return new T(mraa_init_io(desc.c_str()));
|
||||
}
|
||||
|
||||
}
|
||||
|
101
api/mraa/firmata.h
Normal file
101
api/mraa/firmata.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Firmata IO
|
||||
*
|
||||
* Firmata IO lets you SYSEX messages construct and ask for a callback on a
|
||||
* SYSEX messages. This is meant to provide a way to call custom firmata APIs
|
||||
* especially using the Custom firmata API
|
||||
*
|
||||
* @snippet firmata_curie_imu.c Interesting
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Opaque pointer definition to the internal struct _firmata. This context
|
||||
* refers to one firmata 'extension' letting you write/return SYSEX messages
|
||||
* directly
|
||||
*/
|
||||
typedef struct _firmata* mraa_firmata_context;
|
||||
|
||||
/**
|
||||
* Initialise firmata context on a feature. This feature is what will be
|
||||
* listened on if you request a response callback
|
||||
*
|
||||
* @param firmata feature
|
||||
* @return firmata context or NULL
|
||||
*/
|
||||
mraa_firmata_context mraa_firmata_init(int feature);
|
||||
|
||||
/**
|
||||
* Sends a custom SYSEX message to the firmata board.
|
||||
*
|
||||
* @param dev The Firmata context
|
||||
* @param msg The SYSEX message
|
||||
* @param length The length of the sysex message
|
||||
*/
|
||||
mraa_result_t mraa_firmata_write_sysex(mraa_firmata_context dev, char* msg, int length);
|
||||
|
||||
/**
|
||||
* Set a callback on 'feature'. This function is not thread safe and threads
|
||||
* calling it need to make sure they are the only thread calling this.
|
||||
*
|
||||
* @param dev The Firmata context
|
||||
* @param fptr Function pointer to function to be called when interrupt is
|
||||
* triggered, the returned buffer and length are the arguments.
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_firmata_response(mraa_firmata_context dev, void (*fptr)(uint8_t*, int));
|
||||
|
||||
/**
|
||||
* Stop getting events on feature. This is more efficient than mraa_firmata_close
|
||||
* as it can be re-enabled without adding a feature
|
||||
*
|
||||
* @param dev The Firmata context
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_firmata_response_stop(mraa_firmata_context dev);
|
||||
|
||||
/**
|
||||
* Free all firmata handle resources, this will leave an element in an array
|
||||
* internally that will be skipped, avoid closing many firmata contexts often
|
||||
* as there is a cost to doing this
|
||||
*
|
||||
* @param dev The Firmata context
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_firmata_close(mraa_firmata_context dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -28,11 +28,10 @@
|
||||
* @file
|
||||
* @brief General Purpose IO
|
||||
*
|
||||
* Gpio is the General Purpose IO interface to libmraa. It's features depends on
|
||||
* Gpio is the General Purpose IO interface to libmraa. Its features depend on
|
||||
* the board type used, it can use gpiolibs (exported via a kernel module
|
||||
* through sysfs), or memory mapped IO via a /dev/uio device or /dev/mem
|
||||
* depending again on the board configuratio, or memory mapped IO via a
|
||||
* /dev/uio device or /dev/mem depending again on the board configuration
|
||||
* depending again on the board configuration.
|
||||
*
|
||||
* @snippet gpio_read6.c Interesting
|
||||
*/
|
||||
@@ -41,15 +40,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
#include <Python.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
#include <jni.h>
|
||||
extern "C" {
|
||||
void mraa_java_isr_callback(void *args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Opaque pointer definition to the internal struct _gpio
|
||||
*/
|
||||
@@ -76,13 +77,13 @@ typedef enum {
|
||||
} mraa_gpio_dir_t;
|
||||
|
||||
/**
|
||||
* Gpio Edge types for interupts
|
||||
* Gpio Edge types for interrupts
|
||||
*/
|
||||
typedef enum {
|
||||
MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
|
||||
MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
|
||||
MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
|
||||
MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
|
||||
MRAA_GPIO_EDGE_BOTH = 1, /**< Interrupt on rising & falling */
|
||||
MRAA_GPIO_EDGE_RISING = 2, /**< Interrupt on rising only */
|
||||
MRAA_GPIO_EDGE_FALLING = 3 /**< Interrupt on falling only */
|
||||
} mraa_gpio_edge_t;
|
||||
|
||||
/**
|
||||
@@ -111,11 +112,11 @@ mraa_gpio_context mraa_gpio_init_raw(int gpiopin);
|
||||
mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
|
||||
|
||||
/**
|
||||
* Set an interupt on pin
|
||||
* Set an interrupt on pin
|
||||
*
|
||||
* @param dev The Gpio context
|
||||
* @param edge The edge mode to set the gpio into
|
||||
* @param fptr Function pointer to function to be called when interupt is
|
||||
* @param fptr Function pointer to function to be called when interrupt is
|
||||
* triggered
|
||||
* @param args Arguments passed to the interrupt handler (fptr)
|
||||
* @return Result of operation
|
||||
@@ -123,7 +124,7 @@ mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
|
||||
mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (*fptr)(void*), void* args);
|
||||
|
||||
/**
|
||||
* Stop the current interupt watcher on this Gpio, and set the Gpio edge mode
|
||||
* Stop the current interrupt watcher on this Gpio, and set the Gpio edge mode
|
||||
* to MRAA_GPIO_EDGE_NONE
|
||||
*
|
||||
* @param dev The Gpio context
|
||||
@@ -149,6 +150,15 @@ mraa_result_t mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode);
|
||||
*/
|
||||
mraa_result_t mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir);
|
||||
|
||||
/**
|
||||
* Read Gpio direction
|
||||
*
|
||||
* @param dev The Gpio context
|
||||
* @param dir The address where to store the Gpio direction
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir);
|
||||
|
||||
/**
|
||||
* Close the Gpio context
|
||||
* - Will free the memory for the context and unexport the Gpio
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "gpio.h"
|
||||
#include "types.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(SWIGJAVASCRIPT)
|
||||
@@ -43,9 +44,9 @@ namespace mraa
|
||||
*/
|
||||
typedef enum {
|
||||
MODE_STRONG = 0, /**< Default. Strong High and Low */
|
||||
MODE_PULLUP = 1, /**< Interupt on rising & falling */
|
||||
MODE_PULLDOWN = 2, /**< Interupt on rising only */
|
||||
MODE_HIZ = 3 /**< Interupt on falling only */
|
||||
MODE_PULLUP = 1, /**< Resistive High */
|
||||
MODE_PULLDOWN = 2, /**< Resistive Low */
|
||||
MODE_HIZ = 3 /**< High Z State */
|
||||
} Mode;
|
||||
|
||||
/**
|
||||
@@ -59,39 +60,15 @@ typedef enum {
|
||||
} Dir;
|
||||
|
||||
/**
|
||||
* Gpio Edge types for interupts
|
||||
* Gpio Edge types for interrupts
|
||||
*/
|
||||
typedef enum {
|
||||
EDGE_NONE = 0, /**< No interrupt on Gpio */
|
||||
EDGE_BOTH = 1, /**< Interupt on rising & falling */
|
||||
EDGE_RISING = 2, /**< Interupt on rising only */
|
||||
EDGE_FALLING = 3 /**< Interupt on falling only */
|
||||
EDGE_BOTH = 1, /**< Interrupt on rising & falling */
|
||||
EDGE_RISING = 2, /**< Interrupt on rising only */
|
||||
EDGE_FALLING = 3 /**< Interrupt on falling only */
|
||||
} Edge;
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
|
||||
class IsrCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IsrCallback()
|
||||
{
|
||||
}
|
||||
virtual void
|
||||
run()
|
||||
{ /* empty, overloaded in Java*/
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
void
|
||||
generic_isr_callback(void* data)
|
||||
{
|
||||
IsrCallback* callback = (IsrCallback*) data;
|
||||
callback->run();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief API to General Purpose IO
|
||||
*
|
||||
@@ -103,7 +80,7 @@ class Gpio
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Instanciates a Gpio object
|
||||
* Instantiates a Gpio object
|
||||
*
|
||||
* @param pin pin number to use
|
||||
* @param owner (optional) Set pin owner, default behaviour is to 'own'
|
||||
@@ -130,6 +107,19 @@ class Gpio
|
||||
mraa_gpio_owner(m_gpio, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio Constructor, takes a pointer to the GPIO context and initialises
|
||||
* the GPIO class
|
||||
*
|
||||
* @param void * to GPIO context
|
||||
*/
|
||||
Gpio(void* gpio_context)
|
||||
{
|
||||
m_gpio = (mraa_gpio_context) gpio_context;
|
||||
if (m_gpio == NULL) {
|
||||
throw std::invalid_argument("Invalid GPIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio object destructor, this will only unexport the gpio if we where
|
||||
* the owner
|
||||
@@ -144,21 +134,24 @@ class Gpio
|
||||
* @param mode The edge mode to set
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
edge(Edge mode)
|
||||
{
|
||||
return mraa_gpio_edge_mode(m_gpio, (mraa_gpio_edge_t) mode);
|
||||
return (Result) mraa_gpio_edge_mode(m_gpio, (mraa_gpio_edge_t) mode);
|
||||
}
|
||||
#if defined(SWIGPYTHON)
|
||||
mraa_result_t
|
||||
Result
|
||||
isr(Edge mode, PyObject* pyfunc, PyObject* args)
|
||||
{
|
||||
return mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, (void (*) (void*)) pyfunc, (void*) args);
|
||||
return (Result) mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, (void (*) (void*)) pyfunc, (void*) args);
|
||||
}
|
||||
#elif defined(SWIGJAVASCRIPT)
|
||||
static void
|
||||
v8isr(uv_work_t* req, int status)
|
||||
{
|
||||
#if NODE_MODULE_VERSION >= 0x000D
|
||||
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
||||
#endif
|
||||
mraa::Gpio* This = (mraa::Gpio*) req->data;
|
||||
int argc = 1;
|
||||
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
|
||||
@@ -185,7 +178,7 @@ class Gpio
|
||||
uv_queue_work(uv_default_loop(), req, nop, v8isr);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Result
|
||||
isr(Edge mode, v8::Handle<v8::Function> func)
|
||||
{
|
||||
#if NODE_MODULE_VERSION >= 0x000D
|
||||
@@ -193,37 +186,37 @@ class Gpio
|
||||
#else
|
||||
m_v8isr = v8::Persistent<v8::Function>::New(func);
|
||||
#endif
|
||||
return mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, &uvwork, this);
|
||||
return (Result) mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, &uvwork, this);
|
||||
}
|
||||
#elif defined(SWIGJAVA)
|
||||
mraa_result_t
|
||||
isr(Edge mode, IsrCallback* cb, void* args)
|
||||
#elif defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
Result
|
||||
isr(Edge mode, jobject runnable)
|
||||
{
|
||||
return mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, generic_isr_callback, cb);
|
||||
return (Result) mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, mraa_java_isr_callback, runnable);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
/**
|
||||
* Sets a callback to be called when pin value changes
|
||||
*
|
||||
* @param mode The edge mode to set
|
||||
* @param fptr Function pointer to function to be called when interupt is
|
||||
* @param fptr Function pointer to function to be called when interrupt is
|
||||
* triggered
|
||||
* @param args Arguments passed to the interrupt handler (fptr)
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
isr(Edge mode, void (*fptr)(void*), void* args)
|
||||
{
|
||||
return mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, fptr, args);
|
||||
return (Result) mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) mode, fptr, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Exits callback - this call will not kill the isr thread immediatly
|
||||
* Exits callback - this call will not kill the isr thread immediately
|
||||
* but only when it is out of it's critical section
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
isrExit()
|
||||
{
|
||||
#if defined(SWIGJAVASCRIPT)
|
||||
@@ -234,7 +227,7 @@ class Gpio
|
||||
m_v8isr.Clear();
|
||||
#endif
|
||||
#endif
|
||||
return mraa_gpio_isr_exit(m_gpio);
|
||||
return (Result) mraa_gpio_isr_exit(m_gpio);
|
||||
}
|
||||
/**
|
||||
* Change Gpio mode
|
||||
@@ -242,10 +235,10 @@ class Gpio
|
||||
* @param mode The mode to change the gpio into
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
mode(Mode mode)
|
||||
{
|
||||
return mraa_gpio_mode(m_gpio, (mraa_gpio_mode_t) mode);
|
||||
return (Result )mraa_gpio_mode(m_gpio, (mraa_gpio_mode_t) mode);
|
||||
}
|
||||
/**
|
||||
* Change Gpio direction
|
||||
@@ -253,11 +246,28 @@ class Gpio
|
||||
* @param dir The direction to change the gpio into
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
dir(Dir dir)
|
||||
{
|
||||
return mraa_gpio_dir(m_gpio, (mraa_gpio_dir_t) dir);
|
||||
return (Result )mraa_gpio_dir(m_gpio, (mraa_gpio_dir_t) dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Gpio direction
|
||||
*
|
||||
* @throw std::runtime_error in case of failure
|
||||
* @return Result of operation
|
||||
*/
|
||||
Dir
|
||||
readDir()
|
||||
{
|
||||
mraa_gpio_dir_t dir;
|
||||
if (mraa_gpio_read_dir(m_gpio, &dir) != MRAA_SUCCESS) {
|
||||
throw std::runtime_error("Failed to read direction");
|
||||
}
|
||||
return (Dir) dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read value from Gpio
|
||||
*
|
||||
@@ -274,10 +284,10 @@ class Gpio
|
||||
* @param value Value to write to Gpio
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
write(int value)
|
||||
{
|
||||
return mraa_gpio_write(m_gpio, value);
|
||||
return (Result) mraa_gpio_write(m_gpio, value);
|
||||
}
|
||||
/**
|
||||
* Enable use of mmap i/o if available.
|
||||
@@ -285,10 +295,10 @@ class Gpio
|
||||
* @param enable true to use mmap
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
useMmap(bool enable)
|
||||
{
|
||||
return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
|
||||
return (Result) mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
|
||||
}
|
||||
/**
|
||||
* Get pin number of Gpio. If raw param is True will return the
|
||||
|
@@ -78,42 +78,40 @@ mraa_i2c_context mraa_i2c_init_raw(unsigned int bus);
|
||||
mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode);
|
||||
|
||||
/**
|
||||
* Simple bulk read from an i2c context, this will always begin with the i2c
|
||||
* offset 0x0
|
||||
* Simple bulk read from an i2c context
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data pointer to the byte array to read data in to
|
||||
* @param length max number of bytes to read
|
||||
* @return length of the read in bytes or 0
|
||||
* @return length of the read in bytes or -1
|
||||
*/
|
||||
int mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length);
|
||||
|
||||
/**
|
||||
* Simple read for a single byte from the i2c context, this will always begin
|
||||
* with the i2c offset 0x0
|
||||
* Simple read for a single byte from the i2c context
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @return The result of the read and 0 if failed
|
||||
* @return The result of the read or -1 if failed
|
||||
*/
|
||||
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
|
||||
int mraa_i2c_read_byte(mraa_i2c_context dev);
|
||||
|
||||
/**
|
||||
* Read a single byte from i2c context, from designated register
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param command The register
|
||||
* @return The result of the read and 0 if failed
|
||||
* @return The result of the read or -1 if failed
|
||||
*/
|
||||
uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
|
||||
int mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Read a single word from i2c context, from designated register
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param command The register
|
||||
* @return The result of the read and 0 if failed
|
||||
* @return The result of the read or -1 if failed
|
||||
*/
|
||||
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
|
||||
int mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Bulk read from i2c context, starting from designated register
|
||||
@@ -138,7 +136,7 @@ int mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* dat
|
||||
mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length);
|
||||
|
||||
/**
|
||||
* Write a single byte to an i2c context, always at offset 0x0
|
||||
* Write a single byte to an i2c context
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data The byte to write
|
||||
@@ -167,12 +165,10 @@ mraa_result_t mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data,
|
||||
mraa_result_t mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Sets the i2c context address.
|
||||
* Sets the i2c slave address.
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param address The address to set for the slave (ignoring the least
|
||||
* signifcant bit). If set to 0, the slave will only respond to the
|
||||
* general call address.
|
||||
* @param address The address to set for the slave (7-bit address)
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, uint8_t address);
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "i2c.h"
|
||||
#include "types.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa
|
||||
@@ -61,6 +62,18 @@ class I2c
|
||||
throw std::invalid_argument("Invalid i2c bus");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* I2C constructor, takes a pointer to a I2C context and initialises the I2C class
|
||||
*
|
||||
* @param void * to an I2C context
|
||||
*/
|
||||
I2c(void* i2c_context)
|
||||
{
|
||||
m_i2c = (mraa_i2c_context) i2c_context;
|
||||
if (m_i2c == NULL) {
|
||||
throw std::invalid_argument("Invalid I2C context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the I2c Bus used. This does not guarrantee the bus will not
|
||||
@@ -80,10 +93,10 @@ class I2c
|
||||
* @param mode Frequency to set the bus to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
frequency(mraa_i2c_mode_t mode)
|
||||
Result
|
||||
frequency(I2cMode mode)
|
||||
{
|
||||
return mraa_i2c_frequency(m_i2c, mode);
|
||||
return (Result) mraa_i2c_frequency(m_i2c, (mraa_i2c_mode_t) mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,21 +106,26 @@ class I2c
|
||||
* @param address Communicate to the i2c slave on this address
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
address(uint8_t address)
|
||||
{
|
||||
return mraa_i2c_address(m_i2c, address);
|
||||
return (Result) mraa_i2c_address(m_i2c, address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read exactly one byte from the bus
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from the bus
|
||||
*/
|
||||
uint8_t
|
||||
readByte()
|
||||
{
|
||||
return (uint8_t) mraa_i2c_read_byte(m_i2c);
|
||||
int x = mraa_i2c_read_byte(m_i2c);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readByte()");
|
||||
}
|
||||
return (uint8_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,24 +145,36 @@ class I2c
|
||||
* Read byte from an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from register
|
||||
*/
|
||||
uint8_t
|
||||
readReg(uint8_t reg)
|
||||
{
|
||||
return mraa_i2c_read_byte_data(m_i2c, reg);
|
||||
int x = mraa_i2c_read_byte_data(m_i2c, reg);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readReg()");
|
||||
}
|
||||
return (uint8_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read word from an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from register
|
||||
*/
|
||||
uint16_t
|
||||
readWordReg(uint8_t reg)
|
||||
{
|
||||
return mraa_i2c_read_word_data(m_i2c, reg);
|
||||
int x = mraa_i2c_read_word_data(m_i2c, reg);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readReg()");
|
||||
}
|
||||
return (uint16_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,10 +198,10 @@ class I2c
|
||||
* @param data The byte to send on the bus
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
writeByte(uint8_t data)
|
||||
{
|
||||
return mraa_i2c_write_byte(m_i2c, data);
|
||||
return (Result) mraa_i2c_write_byte(m_i2c, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,10 +212,10 @@ class I2c
|
||||
* @param length Size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
write(const uint8_t* data, int length)
|
||||
{
|
||||
return mraa_i2c_write(m_i2c, data, length);
|
||||
return (Result) mraa_i2c_write(m_i2c, data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,10 +225,10 @@ class I2c
|
||||
* @param data Value to write to register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
writeReg(uint8_t reg, uint8_t data)
|
||||
{
|
||||
return mraa_i2c_write_byte_data(m_i2c, data, reg);
|
||||
return (Result) mraa_i2c_write_byte_data(m_i2c, data, reg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,10 +238,10 @@ class I2c
|
||||
* @param data Value to write to register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
writeWordReg(uint8_t reg, uint16_t data)
|
||||
{
|
||||
return mraa_i2c_write_word_data(m_i2c, data, reg);
|
||||
return (Result) mraa_i2c_write_word_data(m_i2c, data, reg);
|
||||
}
|
||||
|
||||
private:
|
||||
|
139
api/mraa/iio.h
Normal file
139
api/mraa/iio.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "iio_kernel_headers.h"
|
||||
|
||||
typedef struct {
|
||||
int index;
|
||||
int enabled;
|
||||
char* type;
|
||||
mraa_boolean_t lendian;
|
||||
int signedd;
|
||||
unsigned int offset;
|
||||
uint64_t mask;
|
||||
unsigned int bits_used;
|
||||
unsigned int bytes;
|
||||
unsigned int shift;
|
||||
unsigned int location;
|
||||
} mraa_iio_channel;
|
||||
|
||||
typedef struct {
|
||||
char* name;
|
||||
int enabled;
|
||||
} mraa_iio_event;
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief iio
|
||||
*
|
||||
* An iio context represents an IIO device
|
||||
*
|
||||
* @snippet iio_driver.c Interesting
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Opaque pointer definition to the internal struct _iio
|
||||
*/
|
||||
typedef struct _iio* mraa_iio_context;
|
||||
|
||||
/**
|
||||
* Initialise iio context
|
||||
*
|
||||
* @param bus iio device to use
|
||||
* @return i2c context or NULL
|
||||
*/
|
||||
mraa_iio_context mraa_iio_init(int device);
|
||||
|
||||
mraa_result_t mraa_iio_trigger_buffer(mraa_iio_context dev, void (*fptr)(char* data), void* args);
|
||||
|
||||
const char* mraa_iio_get_device_name(mraa_iio_context dev);
|
||||
|
||||
int mraa_iio_get_device_num_by_name(const char* name);
|
||||
|
||||
int mraa_iio_read_size(mraa_iio_context dev);
|
||||
|
||||
mraa_iio_channel* mraa_iio_get_channels(mraa_iio_context dev);
|
||||
|
||||
int mraa_iio_get_channel_count(mraa_iio_context dev);
|
||||
|
||||
mraa_result_t mraa_iio_read_float(mraa_iio_context dev, const char* filename, float* data);
|
||||
|
||||
mraa_result_t mraa_iio_read_int(mraa_iio_context dev, const char* filename, int* data);
|
||||
|
||||
mraa_result_t mraa_iio_read_string(mraa_iio_context dev, const char* filename, char* data, int max_len);
|
||||
|
||||
mraa_result_t mraa_iio_write_float(mraa_iio_context dev, const char* attr_chan, const float data);
|
||||
|
||||
mraa_result_t mraa_iio_write_int(mraa_iio_context dev, const char* attr_chan, const int data);
|
||||
|
||||
mraa_result_t mraa_iio_write_string(mraa_iio_context dev, const char* attr_chan, const char* data);
|
||||
|
||||
mraa_result_t mraa_iio_get_channel_data(mraa_iio_context dev);
|
||||
|
||||
mraa_result_t mraa_iio_get_event_data(mraa_iio_context dev);
|
||||
|
||||
mraa_result_t mraa_iio_event_poll(mraa_iio_context dev, struct iio_event_data* data);
|
||||
|
||||
mraa_result_t
|
||||
mraa_iio_event_setup_callback(mraa_iio_context dev, void (*fptr)(struct iio_event_data* data, void* args), void* args);
|
||||
|
||||
mraa_result_t mraa_iio_event_extract_event(struct iio_event_data* event,
|
||||
int* chan_type,
|
||||
int* modifier,
|
||||
int* type,
|
||||
int* direction,
|
||||
int* channel,
|
||||
int* channel2,
|
||||
int* different);
|
||||
|
||||
mraa_result_t mraa_iio_get_mounting_matrix(mraa_iio_context dev, float mm[9]);
|
||||
|
||||
mraa_result_t mraa_iio_create_trigger(mraa_iio_context dev, const char* trigger);
|
||||
|
||||
mraa_result_t mraa_iio_update_channels(mraa_iio_context dev);
|
||||
/**
|
||||
* De-inits an mraa_iio_context device
|
||||
*
|
||||
* @param dev The iio context
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_iio_close(mraa_iio_context dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
245
api/mraa/iio.hpp
Normal file
245
api/mraa/iio.hpp
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include "iio.h"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace mraa
|
||||
{
|
||||
|
||||
struct IioEventData
|
||||
{
|
||||
int channelType;
|
||||
int modifier;
|
||||
int type;
|
||||
int direction;
|
||||
int channel;
|
||||
int channel2;
|
||||
int diff;
|
||||
};
|
||||
|
||||
class IioHandler
|
||||
{
|
||||
public:
|
||||
virtual void onIioEvent(const IioEventData& eventData) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief API to Industrial IO
|
||||
*
|
||||
* This file defines the C++ iio interface for libmraa
|
||||
*
|
||||
* @snippet iio_dummy_test.cpp Interesting
|
||||
*/
|
||||
class Iio
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Iio Constructor, takes a device number which will map directly to sysfs
|
||||
* e.g. device 0 maps to /sys/bus/iio/devices/iio:device0
|
||||
*
|
||||
* @param device IIO device number
|
||||
*
|
||||
* @throws std::invalid_argument if initialization fails
|
||||
*/
|
||||
Iio(int device)
|
||||
{
|
||||
m_iio = mraa_iio_init(device);
|
||||
if (m_iio == NULL) {
|
||||
std::ostringstream oss;
|
||||
oss << "IIO device " << device << " is not valid";
|
||||
throw std::invalid_argument(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iio Constructor
|
||||
*
|
||||
* @param deviceName IIO device name
|
||||
*
|
||||
* @throws std::invalid_argument if initialization fails
|
||||
*/
|
||||
Iio(const std::string& deviceName)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
int id = mraa_iio_get_device_num_by_name(deviceName.c_str());
|
||||
if (id == -1) {
|
||||
oss << "IIO device name " << deviceName << " not found";
|
||||
throw std::invalid_argument(oss.str());
|
||||
}
|
||||
m_iio = mraa_iio_init(id);
|
||||
if (m_iio == NULL) {
|
||||
oss << "IIO device " << deviceName << " is not valid";
|
||||
throw std::invalid_argument(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iio destructor
|
||||
*/
|
||||
~Iio()
|
||||
{
|
||||
mraa_iio_close(m_iio);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get device name
|
||||
*
|
||||
* @returns The device name
|
||||
*/
|
||||
std::string
|
||||
getDeviceName() const
|
||||
{
|
||||
return mraa_iio_get_device_name(m_iio);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an int value from specified attribute.
|
||||
*
|
||||
* @param attributeName attribute mame
|
||||
*
|
||||
* @returns The int value
|
||||
*
|
||||
* @throws std::invalid_argument if read fails
|
||||
*/
|
||||
int
|
||||
readInt(const std::string& attributeName) const
|
||||
{
|
||||
int value;
|
||||
mraa_result_t res = mraa_iio_read_int(m_iio, attributeName.c_str(), &value);
|
||||
if (res != MRAA_SUCCESS) {
|
||||
std::ostringstream oss;
|
||||
oss << "IIO readInt for attibute " << attributeName << " failed";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a float value from specified attribute.
|
||||
*
|
||||
* @param attributeName attribute mame
|
||||
*
|
||||
* @returns The float value
|
||||
*
|
||||
* @throws std::invalid_argument if read fails
|
||||
*/
|
||||
float
|
||||
readFloat(const std::string& attributeName) const
|
||||
{
|
||||
float value;
|
||||
mraa_result_t res = mraa_iio_read_float(m_iio, attributeName.c_str(), &value);
|
||||
if (res != MRAA_SUCCESS) {
|
||||
std::ostringstream oss;
|
||||
oss << "IIO readFloat for attibute " << attributeName << " failed";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an int value to specified attribute.
|
||||
*
|
||||
* @param attributeName attribute mame
|
||||
* @param value int value
|
||||
*
|
||||
* @throws std::invalid_argument if write fails
|
||||
*/
|
||||
void
|
||||
writeInt(const std::string& attributeName, int value) const
|
||||
{
|
||||
mraa_result_t res = mraa_iio_write_int(m_iio, attributeName.c_str(), value);
|
||||
if (res != MRAA_SUCCESS) {
|
||||
std::ostringstream oss;
|
||||
oss << "IIO writeInt for attibute " << attributeName << " failed";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a float value to specified attribute.
|
||||
*
|
||||
* @param attributeName attribute mame
|
||||
* @param value float value
|
||||
*
|
||||
* @throws std::invalid_argument if write fails
|
||||
*/
|
||||
void
|
||||
writeFloat(const std::string& attributeName, float value) const
|
||||
{
|
||||
mraa_result_t res = mraa_iio_write_float(m_iio, attributeName.c_str(), value);
|
||||
if (res != MRAA_SUCCESS) {
|
||||
std::ostringstream oss;
|
||||
oss << "IIO writeFloat for attibute " << attributeName << " failed";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register event handler.
|
||||
*
|
||||
* @param handler handler class that implements IioHandler
|
||||
*
|
||||
* @throws std::invalid_argument on failure
|
||||
*/
|
||||
void
|
||||
registerEventHandler(IioHandler* handler) const
|
||||
{
|
||||
mraa_result_t res = mraa_iio_event_setup_callback(m_iio, private_event_handler, handler);
|
||||
if (res != MRAA_SUCCESS) {
|
||||
throw std::runtime_error("registerEventHandler failed");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void private_event_handler(iio_event_data* data, void *args)
|
||||
{
|
||||
if (args != NULL) {
|
||||
IioHandler* handler = (IioHandler*)args;
|
||||
IioEventData eventData;
|
||||
int chan_type, modifier, type, direction, channel, channel2, different;
|
||||
mraa_iio_event_extract_event(data, &chan_type, &modifier, &type, &direction, &channel, &channel2, &different);
|
||||
eventData.channelType = chan_type;
|
||||
eventData.modifier = modifier;
|
||||
eventData.type = type;
|
||||
eventData.direction = direction;
|
||||
eventData.channel = channel;
|
||||
eventData.channel2 = channel2;
|
||||
eventData.diff = different;
|
||||
handler->onIioEvent(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_iio_context m_iio;
|
||||
};
|
||||
|
||||
}
|
136
api/mraa/iio_kernel_headers.h
Normal file
136
api/mraa/iio_kernel_headers.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
//For kernel 4.1+,
|
||||
//#include <linux/iio/types.h>
|
||||
//#include <linux/iio/events.h>
|
||||
|
||||
//linux/iio/types.h
|
||||
enum iio_chan_type {
|
||||
IIO_VOLTAGE,
|
||||
IIO_CURRENT,
|
||||
IIO_POWER,
|
||||
IIO_ACCEL,
|
||||
IIO_ANGL_VEL,
|
||||
IIO_MAGN,
|
||||
IIO_LIGHT,
|
||||
IIO_INTENSITY,
|
||||
IIO_PROXIMITY,
|
||||
IIO_TEMP,
|
||||
IIO_INCLI,
|
||||
IIO_ROT,
|
||||
IIO_ANGL,
|
||||
IIO_TIMESTAMP,
|
||||
IIO_CAPACITANCE,
|
||||
IIO_ALTVOLTAGE,
|
||||
IIO_CCT,
|
||||
IIO_PRESSURE,
|
||||
IIO_HUMIDITYRELATIVE,
|
||||
IIO_ACTIVITY,
|
||||
IIO_STEPS,
|
||||
IIO_ENERGY,
|
||||
IIO_DISTANCE,
|
||||
IIO_VELOCITY,
|
||||
};
|
||||
|
||||
enum iio_modifier {
|
||||
IIO_NO_MOD,
|
||||
IIO_MOD_X,
|
||||
IIO_MOD_Y,
|
||||
IIO_MOD_Z,
|
||||
IIO_MOD_X_AND_Y,
|
||||
IIO_MOD_X_AND_Z,
|
||||
IIO_MOD_Y_AND_Z,
|
||||
IIO_MOD_X_AND_Y_AND_Z,
|
||||
IIO_MOD_X_OR_Y,
|
||||
IIO_MOD_X_OR_Z,
|
||||
IIO_MOD_Y_OR_Z,
|
||||
IIO_MOD_X_OR_Y_OR_Z,
|
||||
IIO_MOD_LIGHT_BOTH,
|
||||
IIO_MOD_LIGHT_IR,
|
||||
IIO_MOD_ROOT_SUM_SQUARED_X_Y,
|
||||
IIO_MOD_SUM_SQUARED_X_Y_Z,
|
||||
IIO_MOD_LIGHT_CLEAR,
|
||||
IIO_MOD_LIGHT_RED,
|
||||
IIO_MOD_LIGHT_GREEN,
|
||||
IIO_MOD_LIGHT_BLUE,
|
||||
IIO_MOD_QUATERNION,
|
||||
IIO_MOD_TEMP_AMBIENT,
|
||||
IIO_MOD_TEMP_OBJECT,
|
||||
IIO_MOD_NORTH_MAGN,
|
||||
IIO_MOD_NORTH_TRUE,
|
||||
IIO_MOD_NORTH_MAGN_TILT_COMP,
|
||||
IIO_MOD_NORTH_TRUE_TILT_COMP,
|
||||
IIO_MOD_RUNNING,
|
||||
IIO_MOD_JOGGING,
|
||||
IIO_MOD_WALKING,
|
||||
IIO_MOD_STILL,
|
||||
IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
|
||||
};
|
||||
|
||||
enum iio_event_type {
|
||||
IIO_EV_TYPE_THRESH,
|
||||
IIO_EV_TYPE_MAG,
|
||||
IIO_EV_TYPE_ROC,
|
||||
IIO_EV_TYPE_THRESH_ADAPTIVE,
|
||||
IIO_EV_TYPE_MAG_ADAPTIVE,
|
||||
IIO_EV_TYPE_CHANGE,
|
||||
};
|
||||
|
||||
enum iio_event_direction {
|
||||
IIO_EV_DIR_EITHER,
|
||||
IIO_EV_DIR_RISING,
|
||||
IIO_EV_DIR_FALLING,
|
||||
IIO_EV_DIR_NONE,
|
||||
};
|
||||
|
||||
//linux/iio/events.h
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
/**
|
||||
* struct iio_event_data - The actual event being pushed to userspace
|
||||
* @id: event identifier
|
||||
* @timestamp: best estimate of time of event occurrence (often from
|
||||
* the interrupt handler)
|
||||
*/
|
||||
struct iio_event_data {
|
||||
unsigned long long int id;
|
||||
long long int timestamp;
|
||||
};
|
||||
|
||||
#define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
|
||||
|
||||
#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
|
||||
|
||||
#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0x7F)
|
||||
|
||||
#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
|
||||
|
||||
/* Event code number extraction depends on which type of event we have.
|
||||
* Perhaps review this function in the future*/
|
||||
#define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((short int)(mask & 0xFFFF))
|
||||
#define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((short int)(((mask) >> 16) & 0xFFFF))
|
||||
|
||||
#define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
|
||||
#define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)
|
@@ -65,7 +65,7 @@ mraa_pwm_context mraa_pwm_init(int pin);
|
||||
mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
|
||||
|
||||
/**
|
||||
* Set the ouput duty-cycle percentage, as a float
|
||||
* Set the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @param dev The Pwm context to use
|
||||
* @param percentage A floating-point value representing percentage of output.
|
||||
@@ -76,7 +76,7 @@ mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
|
||||
mraa_result_t mraa_pwm_write(mraa_pwm_context dev, float percentage);
|
||||
|
||||
/**
|
||||
* Read the ouput duty-cycle percentage, as a float
|
||||
* Read the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @param dev The Pwm context to use
|
||||
* @return percentage A floating-point value representing percentage of output.
|
||||
@@ -166,39 +166,21 @@ mraa_result_t mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner);
|
||||
*/
|
||||
mraa_result_t mraa_pwm_close(mraa_pwm_context dev);
|
||||
|
||||
/**
|
||||
* Set Both Period and DutyCycle on a PWM context
|
||||
*
|
||||
* @param dev The pwm context to use
|
||||
* @param period represented in ms.
|
||||
* @param duty dutycycle of the pwm signal.
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_pwm_config_ms(mraa_pwm_context dev, int period, float duty);
|
||||
|
||||
/**
|
||||
* Set Both Period and DutyCycle on a PWM context. Duty represented as percentage.
|
||||
*
|
||||
* @param dev The pwm context to use
|
||||
* @param period represented in ms.
|
||||
* @param duty duty percantage. i.e. 50% = 0.5f
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_pwm_config_percent(mraa_pwm_context dev, int period, float duty);
|
||||
|
||||
/**
|
||||
* Get the maximum pwm period in us
|
||||
*
|
||||
* @param dev The pwm context to use
|
||||
* @return max pwm in us
|
||||
*/
|
||||
int mraa_pwm_get_max_period();
|
||||
int mraa_pwm_get_max_period(mraa_pwm_context dev);
|
||||
|
||||
/**
|
||||
* Get the minimum pwm period in us
|
||||
*
|
||||
* @param dev The pwm context to use
|
||||
* @return min pwm in us
|
||||
*/
|
||||
int mraa_pwm_get_min_period();
|
||||
int mraa_pwm_get_min_period(mraa_pwm_context dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "pwm.h"
|
||||
#include "types.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa
|
||||
@@ -45,9 +46,9 @@ class Pwm
|
||||
*
|
||||
* @param pin the pin number used on your board
|
||||
* @param owner if you are the owner of the pin the destructor will
|
||||
* @param chipid the pwmchip to use, use only in raw mode
|
||||
* unexport the pin from sysfs, default behaviour is you are the owner
|
||||
* if the pinmapper exported it
|
||||
* @param chipid the pwmchip to use, use only in raw mode
|
||||
*/
|
||||
Pwm(int pin, bool owner = true, int chipid = -1)
|
||||
{
|
||||
@@ -65,6 +66,20 @@ class Pwm
|
||||
mraa_pwm_owner(m_pwm, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pwm constructor, takes a pointer to the PWM context and
|
||||
* initialises the class
|
||||
*
|
||||
* @param void * to a PWM context
|
||||
*/
|
||||
Pwm(void* pwm_context)
|
||||
{
|
||||
m_pwm = (mraa_pwm_context) pwm_context;
|
||||
if (m_pwm == NULL) {
|
||||
throw std::invalid_argument("Invalid PWM context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pwm destructor
|
||||
*/
|
||||
@@ -76,21 +91,21 @@ class Pwm
|
||||
* Set the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @param percentage A floating-point value representing percentage of
|
||||
* output. The value should lie between 0.0f (representing on 0%) and
|
||||
* output. The value should lie between 0.0f (representing 0%) and
|
||||
* 1.0f Values above or below this range will be set at either 0.0f or
|
||||
* 1.0f
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
write(float percentage)
|
||||
{
|
||||
return mraa_pwm_write(m_pwm, percentage);
|
||||
return (Result) mraa_pwm_write(m_pwm, percentage);
|
||||
}
|
||||
/**
|
||||
* Read the ouput duty-cycle percentage, as a float
|
||||
* Read the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @return A floating-point value representing percentage of
|
||||
* output. The value should lie between 0.0f (representing on 0%) and
|
||||
* output. The value should lie between 0.0f (representing 0%) and
|
||||
* 1.0f Values above or below this range will be set at either 0.0f or
|
||||
* 1.0f
|
||||
*/
|
||||
@@ -105,10 +120,10 @@ class Pwm
|
||||
* @param period Period represented as a float in seconds
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
period(float period)
|
||||
{
|
||||
return mraa_pwm_period(m_pwm, period);
|
||||
return (Result) mraa_pwm_period(m_pwm, period);
|
||||
}
|
||||
/**
|
||||
* Set period, milliseconds
|
||||
@@ -116,10 +131,10 @@ class Pwm
|
||||
* @param ms milliseconds for period
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
period_ms(int ms)
|
||||
{
|
||||
return mraa_pwm_period_ms(m_pwm, ms);
|
||||
return (Result) mraa_pwm_period_ms(m_pwm, ms);
|
||||
}
|
||||
/**
|
||||
* Set period, microseconds
|
||||
@@ -127,21 +142,21 @@ class Pwm
|
||||
* @param us microseconds as period
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
period_us(int us)
|
||||
{
|
||||
return mraa_pwm_period_us(m_pwm, us);
|
||||
return (Result) mraa_pwm_period_us(m_pwm, us);
|
||||
}
|
||||
/**
|
||||
* Set pulsewidth, As represnted by seconds in a (float)
|
||||
* Set pulsewidth, as represented by seconds in a float
|
||||
*
|
||||
* @param seconds The duration of a pulse
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
pulsewidth(float seconds)
|
||||
{
|
||||
return mraa_pwm_pulsewidth(m_pwm, seconds);
|
||||
return (Result) mraa_pwm_pulsewidth(m_pwm, seconds);
|
||||
}
|
||||
/**
|
||||
* Set pulsewidth, milliseconds
|
||||
@@ -149,10 +164,10 @@ class Pwm
|
||||
* @param ms milliseconds for pulsewidth
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
pulsewidth_ms(int ms)
|
||||
{
|
||||
return mraa_pwm_pulsewidth_ms(m_pwm, ms);
|
||||
return (Result) mraa_pwm_pulsewidth_ms(m_pwm, ms);
|
||||
}
|
||||
/**
|
||||
* The pulsewidth, microseconds
|
||||
@@ -160,10 +175,10 @@ class Pwm
|
||||
* @param us microseconds for pulsewidth
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
pulsewidth_us(int us)
|
||||
{
|
||||
return mraa_pwm_pulsewidth_us(m_pwm, us);
|
||||
return (Result) mraa_pwm_pulsewidth_us(m_pwm, us);
|
||||
}
|
||||
/**
|
||||
* Set the enable status of the PWM pin. None zero will assume on with
|
||||
@@ -172,57 +187,30 @@ class Pwm
|
||||
* @param enable enable status of pin
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
return mraa_pwm_enable(m_pwm, 1);
|
||||
else
|
||||
return mraa_pwm_enable(m_pwm, 0);
|
||||
return (Result) mraa_pwm_enable(m_pwm, enable);
|
||||
}
|
||||
/**
|
||||
* Set the period and duty of a PWM object.
|
||||
* Get the maximum PWM period in us
|
||||
*
|
||||
* @param period represented in ms.
|
||||
* @param duty represnted in ms as float.
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
config_ms(int period, float duty)
|
||||
{
|
||||
return mraa_pwm_config_ms(m_pwm, period, duty);
|
||||
}
|
||||
/**
|
||||
* Set the period and duty (percent) of a PWM object.
|
||||
*
|
||||
* @param period as represented in ms.
|
||||
* @param duty percentage i.e. 50% = 0.5f
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
config_percent(int period, float duty)
|
||||
{
|
||||
return mraa_pwm_config_percent(m_pwm, period, duty);
|
||||
}
|
||||
/**
|
||||
* Get the maximum pwm period in us
|
||||
*
|
||||
* @return max pwm in us
|
||||
* @return max PWM period in us
|
||||
*/
|
||||
int
|
||||
max_period()
|
||||
{
|
||||
return mraa_pwm_get_max_period();
|
||||
return mraa_pwm_get_max_period(m_pwm);
|
||||
}
|
||||
/**
|
||||
* Get the minimum pwm period in us
|
||||
* Get the minimum PWM period in us
|
||||
*
|
||||
* @return min pwm in us
|
||||
* @return min PWM period in us
|
||||
*/
|
||||
int
|
||||
min_period()
|
||||
{
|
||||
return mraa_pwm_get_min_period();
|
||||
return mraa_pwm_get_min_period(m_pwm);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -111,13 +111,13 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
|
||||
int mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
|
||||
/**
|
||||
*Write Two Bytes to the SPI device.
|
||||
* Write Two Bytes to the SPI device.
|
||||
*
|
||||
* @param dev The Spi context
|
||||
* @param data Data to send
|
||||
* @return Data received on the miso line
|
||||
*/
|
||||
uint16_t mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
|
||||
int mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
|
||||
|
||||
/**
|
||||
* Write Buffer of bytes to the SPI device. The pointer return has to be
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spi.h"
|
||||
#include "types.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa
|
||||
@@ -69,6 +70,29 @@ class Spi
|
||||
}
|
||||
}
|
||||
|
||||
Spi(int bus, int cs)
|
||||
{
|
||||
m_spi = mraa_spi_init_raw(bus, cs);
|
||||
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument("Error initialising SPI bus");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spi Constructor, takes a pointer to a SPI context and initialises
|
||||
* the SPI class
|
||||
*
|
||||
* @param void * to SPI context
|
||||
*/
|
||||
Spi(void* spi_context)
|
||||
{
|
||||
m_spi = (mraa_spi_context) spi_context;
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument("Invalid SPI context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes spi bus
|
||||
*/
|
||||
@@ -83,10 +107,10 @@ class Spi
|
||||
* @param mode the mode. See Linux spidev doc
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
mode(Spi_Mode mode)
|
||||
{
|
||||
return mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode);
|
||||
return (Result) mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,10 +119,10 @@ class Spi
|
||||
* @param hz the frequency to set in hz
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
frequency(int hz)
|
||||
{
|
||||
return mraa_spi_frequency(m_spi, hz);
|
||||
return (Result) mraa_spi_frequency(m_spi, hz);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +141,10 @@ class Spi
|
||||
* Write single byte to the SPI device
|
||||
*
|
||||
* @param data the byte to send
|
||||
* @return data received on the miso line
|
||||
* @return data received on the miso line or -1 in case of error
|
||||
*/
|
||||
uint16_t
|
||||
write_word(uint16_t data)
|
||||
int
|
||||
writeWord(uint16_t data)
|
||||
{
|
||||
return mraa_spi_write_word(m_spi, (uint16_t) data);
|
||||
}
|
||||
@@ -151,7 +175,7 @@ class Spi
|
||||
* @return uint8_t* data received on the miso line. Same length as passed in
|
||||
*/
|
||||
uint16_t*
|
||||
write_word(uint16_t* txBuf, int length)
|
||||
writeWord(uint16_t* txBuf, int length)
|
||||
{
|
||||
return mraa_spi_write_buf_word(m_spi, txBuf, length);
|
||||
}
|
||||
@@ -167,10 +191,10 @@ class Spi
|
||||
* @param length size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
transfer(uint8_t* txBuf, uint8_t* rxBuf, int length)
|
||||
{
|
||||
return mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length);
|
||||
return (Result) mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,10 +206,10 @@ class Spi
|
||||
* @param length size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
transfer_word(uint16_t* txBuf, uint16_t* rxBuf, int length)
|
||||
{
|
||||
return mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length);
|
||||
return (Result) mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -195,10 +219,10 @@ class Spi
|
||||
* @param lsb Use least significant bit transmission - 0 for msbi
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
lsbmode(bool lsb)
|
||||
{
|
||||
return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
|
||||
return (Result) mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,10 +231,10 @@ class Spi
|
||||
* @param bits bits per word
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
bitPerWord(unsigned int bits)
|
||||
{
|
||||
return mraa_spi_bit_per_word(m_spi, bits);
|
||||
return (Result) mraa_spi_bit_per_word(m_spi, bits);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -46,7 +46,18 @@ typedef enum {
|
||||
MRAA_BEAGLEBONE = 6, /**< The different BeagleBone Black Modes B/C */
|
||||
MRAA_BANANA = 7, /**< Allwinner A20 based Banana Pi and Banana Pro */
|
||||
MRAA_INTEL_NUC5 = 8, /**< The Intel 5th generations Broadwell NUCs */
|
||||
MRAA_96BOARDS = 9, /**< Linaro 96boards */
|
||||
MRAA_INTEL_SOFIA_3GR = 10, /**< The Intel SoFIA 3GR */
|
||||
MRAA_INTEL_CHERRYHILLS = 11, /**< The Intel Braswell Cherryhills */
|
||||
MRAA_UP = 12, /**< The UP Board */
|
||||
|
||||
// USB platform extenders start at 256
|
||||
MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
||||
|
||||
// contains bit 9 so is subplatform
|
||||
MRAA_GENERIC_FIRMATA = 1280, /**< Firmata uart platform/bridge */
|
||||
|
||||
MRAA_NULL_PLATFORM = 98, /**< Platform with no capabilities that hosts a sub platform */
|
||||
MRAA_UNKNOWN_PLATFORM =
|
||||
99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
|
||||
} mraa_platform_t;
|
||||
@@ -195,7 +206,9 @@ typedef enum {
|
||||
MRAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
|
||||
MRAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
|
||||
MRAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
|
||||
MRAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised */
|
||||
MRAA_ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
|
||||
MRAA_ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
|
||||
MRAA_ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
|
||||
|
||||
MRAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
|
||||
} mraa_result_t;
|
||||
|
245
api/mraa/types.hpp
Normal file
245
api/mraa/types.hpp
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright © 2014 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the basic shared types for libmraa
|
||||
* this file is different to common.h in that swig takes this as an input
|
||||
*/
|
||||
|
||||
namespace mraa
|
||||
{
|
||||
|
||||
//These enums must match the enums in types.h
|
||||
|
||||
/**
|
||||
* MRAA supported platform types
|
||||
*/
|
||||
typedef enum {
|
||||
INTEL_GALILEO_GEN1 = 0, /**< The Generation 1 Galileo platform (RevD) */
|
||||
INTEL_GALILEO_GEN2 = 1, /**< The Generation 2 Galileo platform (RevG/H) */
|
||||
INTEL_EDISON_FAB_C = 2, /**< The Intel Edison (FAB C) */
|
||||
INTEL_DE3815 = 3, /**< The Intel DE3815 Baytrail NUC */
|
||||
INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
|
||||
RASPBERRY_PI = 5, /**< The different Raspberry PI Models -like A,B,A+,B+ */
|
||||
BEAGLEBONE = 6, /**< The different BeagleBone Black Modes B/C */
|
||||
BANANA = 7, /**< Allwinner A20 based Banana Pi and Banana Pro */
|
||||
INTEL_NUC5 = 8, /**< The Intel 5th generations Broadwell NUCs */
|
||||
A96BOARDS = 9, /**< Linaro 96boards, A prefix for 'ARM' since not allowed numerical */
|
||||
INTEL_SOFIA_3GR = 10, /**< The Intel SoFIA 3GR */
|
||||
INTEL_CHERRYHILLS = 11, /**< The Intel Braswell Cherryhills */
|
||||
|
||||
FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
||||
|
||||
GENERIC_FIRMATA = 1280, /**< Firmata uart platform/bridge */
|
||||
|
||||
NULL_PLATFORM = 98,
|
||||
UNKNOWN_PLATFORM =
|
||||
99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
|
||||
} Platform;
|
||||
|
||||
/**
|
||||
* Intel edison miniboard numbering enum
|
||||
*/
|
||||
typedef enum {
|
||||
INTEL_EDISON_MINIBOARD_J17_1 = 0,
|
||||
INTEL_EDISON_MINIBOARD_J17_5 = 4,
|
||||
INTEL_EDISON_MINIBOARD_J17_7 = 6,
|
||||
INTEL_EDISON_MINIBOARD_J17_8 = 7,
|
||||
INTEL_EDISON_MINIBOARD_J17_9 = 8,
|
||||
INTEL_EDISON_MINIBOARD_J17_10 = 9,
|
||||
INTEL_EDISON_MINIBOARD_J17_11 = 10,
|
||||
INTEL_EDISON_MINIBOARD_J17_12 = 11,
|
||||
INTEL_EDISON_MINIBOARD_J17_14 = 13,
|
||||
INTEL_EDISON_MINIBOARD_J18_1 = 14,
|
||||
INTEL_EDISON_MINIBOARD_J18_2 = 15,
|
||||
INTEL_EDISON_MINIBOARD_J18_6 = 19,
|
||||
INTEL_EDISON_MINIBOARD_J18_7 = 20,
|
||||
INTEL_EDISON_MINIBOARD_J18_8 = 21,
|
||||
INTEL_EDISON_MINIBOARD_J18_10 = 23,
|
||||
INTEL_EDISON_MINIBOARD_J18_11 = 24,
|
||||
INTEL_EDISON_MINIBOARD_J18_12 = 25,
|
||||
INTEL_EDISON_MINIBOARD_J18_13 = 26,
|
||||
INTEL_EDISON_MINIBOARD_J19_4 = 31,
|
||||
INTEL_EDISON_MINIBOARD_J19_5 = 32,
|
||||
INTEL_EDISON_MINIBOARD_J19_6 = 33,
|
||||
INTEL_EDISON_MINIBOARD_J19_8 = 35,
|
||||
INTEL_EDISON_MINIBOARD_J19_9 = 36,
|
||||
INTEL_EDISON_MINIBOARD_J19_10 = 37,
|
||||
INTEL_EDISON_MINIBOARD_J19_11 = 38,
|
||||
INTEL_EDISON_MINIBOARD_J19_12 = 39,
|
||||
INTEL_EDISON_MINIBOARD_J19_13 = 40,
|
||||
INTEL_EDISON_MINIBOARD_J19_14 = 41,
|
||||
INTEL_EDISON_MINIBOARD_J20_3 = 44,
|
||||
INTEL_EDISON_MINIBOARD_J20_4 = 45,
|
||||
INTEL_EDISON_MINIBOARD_J20_5 = 46,
|
||||
INTEL_EDISON_MINIBOARD_J20_6 = 47,
|
||||
INTEL_EDISON_MINIBOARD_J20_7 = 48,
|
||||
INTEL_EDISON_MINIBOARD_J20_8 = 49,
|
||||
INTEL_EDISON_MINIBOARD_J20_9 = 50,
|
||||
INTEL_EDISON_MINIBOARD_J20_10 = 51,
|
||||
INTEL_EDISON_MINIBOARD_J20_11 = 52,
|
||||
INTEL_EDISON_MINIBOARD_J20_12 = 53,
|
||||
INTEL_EDISON_MINIBOARD_J20_13 = 54,
|
||||
INTEL_EDISON_MINIBOARD_J20_14 = 55
|
||||
} IntelEdisonMiniboard;
|
||||
|
||||
/**
|
||||
* Intel Edison raw GPIO numbering enum
|
||||
*/
|
||||
typedef enum {
|
||||
INTEL_EDISON_GP182 = 0,
|
||||
INTEL_EDISON_GP135 = 4,
|
||||
INTEL_EDISON_GP27 = 6,
|
||||
INTEL_EDISON_GP20 = 7,
|
||||
INTEL_EDISON_GP28 = 8,
|
||||
INTEL_EDISON_GP111 = 0,
|
||||
INTEL_EDISON_GP109 = 10,
|
||||
INTEL_EDISON_GP115 = 11,
|
||||
INTEL_EDISON_GP128 = 13,
|
||||
INTEL_EDISON_GP13 = 14,
|
||||
INTEL_EDISON_GP165 = 15,
|
||||
INTEL_EDISON_GP19 = 19,
|
||||
INTEL_EDISON_GP12 = 20,
|
||||
INTEL_EDISON_GP183 = 21,
|
||||
INTEL_EDISON_GP110 = 23,
|
||||
INTEL_EDISON_GP114 = 24,
|
||||
INTEL_EDISON_GP129 = 25,
|
||||
INTEL_EDISON_GP130 = 26,
|
||||
INTEL_EDISON_GP44 = 31,
|
||||
INTEL_EDISON_GP46 = 32,
|
||||
INTEL_EDISON_GP48 = 33,
|
||||
INTEL_EDISON_GP131 = 35,
|
||||
INTEL_EDISON_GP14 = 36,
|
||||
INTEL_EDISON_GP40 = 37,
|
||||
INTEL_EDISON_GP43 = 38,
|
||||
INTEL_EDISON_GP77 = 39,
|
||||
INTEL_EDISON_GP82 = 40,
|
||||
INTEL_EDISON_GP83 = 41,
|
||||
INTEL_EDISON_GP134 = 44,
|
||||
INTEL_EDISON_GP45 = 45,
|
||||
INTEL_EDISON_GP47 = 46,
|
||||
INTEL_EDISON_GP49 = 47,
|
||||
INTEL_EDISON_GP15 = 48,
|
||||
INTEL_EDISON_GP84 = 49,
|
||||
INTEL_EDISON_GP42 = 50,
|
||||
INTEL_EDISON_GP41 = 51,
|
||||
INTEL_EDISON_GP78 = 52,
|
||||
INTEL_EDISON_GP79 = 53,
|
||||
INTEL_EDISON_GP80 = 54,
|
||||
INTEL_EDISON_GP81 = 55
|
||||
} IntelEdison;
|
||||
|
||||
/**
|
||||
* Raspberry PI Wiring compatible numbering enum
|
||||
*/
|
||||
typedef enum {
|
||||
RASPBERRY_WIRING_PIN8 = 3,
|
||||
RASPBERRY_WIRING_PIN9 = 5,
|
||||
RASPBERRY_WIRING_PIN7 = 7,
|
||||
RASPBERRY_WIRING_PIN15 = 8,
|
||||
RASPBERRY_WIRING_PIN16 = 10,
|
||||
RASPBERRY_WIRING_PIN0 = 11,
|
||||
RASPBERRY_WIRING_PIN1 = 12,
|
||||
RASPBERRY_WIRING_PIN2 = 13,
|
||||
RASPBERRY_WIRING_PIN3 = 15,
|
||||
RASPBERRY_WIRING_PIN4 = 16,
|
||||
RASPBERRY_WIRING_PIN5 = 18,
|
||||
RASPBERRY_WIRING_PIN12 = 19,
|
||||
RASPBERRY_WIRING_PIN13 = 21,
|
||||
RASPBERRY_WIRING_PIN6 = 22,
|
||||
RASPBERRY_WIRING_PIN14 = 23,
|
||||
RASPBERRY_WIRING_PIN10 = 24,
|
||||
RASPBERRY_WIRING_PIN11 = 26,
|
||||
RASPBERRY_WIRING_PIN17 = 29, // RPi B V2
|
||||
RASPBERRY_WIRING_PIN21 = 29,
|
||||
RASPBERRY_WIRING_PIN18 = 30, // RPi B V2
|
||||
RASPBERRY_WIRING_PIN19 = 31, // RPI B V2
|
||||
RASPBERRY_WIRING_PIN22 = 31,
|
||||
RASPBERRY_WIRING_PIN20 = 32, // RPi B V2
|
||||
RASPBERRY_WIRING_PIN26 = 32,
|
||||
RASPBERRY_WIRING_PIN23 = 33,
|
||||
RASPBERRY_WIRING_PIN24 = 35,
|
||||
RASPBERRY_WIRING_PIN27 = 36,
|
||||
RASPBERRY_WIRING_PIN25 = 37,
|
||||
RASPBERRY_WIRING_PIN28 = 38,
|
||||
RASPBERRY_WIRING_PIN29 = 40
|
||||
} RaspberryWiring;
|
||||
|
||||
/**
|
||||
* MRAA return codes
|
||||
*/
|
||||
typedef enum {
|
||||
SUCCESS = 0, /**< Expected response */
|
||||
ERROR_FEATURE_NOT_IMPLEMENTED = 1, /**< Feature TODO */
|
||||
ERROR_FEATURE_NOT_SUPPORTED = 2, /**< Feature not supported by HW */
|
||||
ERROR_INVALID_VERBOSITY_LEVEL = 3, /**< Verbosity level wrong */
|
||||
ERROR_INVALID_PARAMETER = 4, /**< Parameter invalid */
|
||||
ERROR_INVALID_HANDLE = 5, /**< Handle invalid */
|
||||
ERROR_NO_RESOURCES = 6, /**< No resource of that type avail */
|
||||
ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
|
||||
ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
|
||||
ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
|
||||
ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
|
||||
ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
|
||||
ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
|
||||
ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
|
||||
ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
|
||||
|
||||
ERROR_UNSPECIFIED = 99 /**< Unknown Error */
|
||||
} Result;
|
||||
|
||||
/**
|
||||
* Enum representing different possible modes for a pin.
|
||||
*/
|
||||
typedef enum {
|
||||
PIN_VALID = 0, /**< Pin Valid */
|
||||
PIN_GPIO = 1, /**< General Purpose IO */
|
||||
PIN_PWM = 2, /**< Pulse Width Modulation */
|
||||
PIN_FAST_GPIO = 3, /**< Faster GPIO */
|
||||
PIN_SPI = 4, /**< SPI */
|
||||
PIN_I2C = 5, /**< I2C */
|
||||
PIN_AIO = 6, /**< Analog in */
|
||||
PIN_UART = 7 /**< UART */
|
||||
} Pinmodes;
|
||||
|
||||
/**
|
||||
* Enum reprensenting different i2c speeds/modes
|
||||
*/
|
||||
typedef enum {
|
||||
I2C_STD = 0, /**< up to 100Khz */
|
||||
I2C_FAST = 1, /**< up to 400Khz */
|
||||
I2C_HIGH = 2 /**< up to 3.4Mhz */
|
||||
} I2cMode;
|
||||
|
||||
typedef enum {
|
||||
UART_PARITY_NONE = 0,
|
||||
UART_PARITY_EVEN = 1,
|
||||
UART_PARITY_ODD = 2,
|
||||
UART_PARITY_MARK = 3,
|
||||
UART_PARITY_SPACE = 4
|
||||
} UartParity;
|
||||
|
||||
}
|
@@ -118,6 +118,15 @@ mraa_result_t mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xo
|
||||
*/
|
||||
mraa_result_t mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar);
|
||||
|
||||
/**
|
||||
* Set the blocking state for write operations
|
||||
*
|
||||
* @param dev The UART context
|
||||
* @param nonblock new nonblocking state
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock);
|
||||
|
||||
/**
|
||||
* Get Char pointer with tty device path within Linux
|
||||
* For example. Could point to "/dev/ttyS0"
|
||||
|
@@ -27,6 +27,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "uart.h"
|
||||
#include "types.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
@@ -73,6 +75,20 @@ class Uart
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uart Constructor, takes a pointer to the UART context and initialises
|
||||
* the UART class
|
||||
*
|
||||
* @param void * to a UART context
|
||||
*/
|
||||
Uart(void* uart_context)
|
||||
{
|
||||
m_uart = (mraa_uart_context) uart_context;
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Invalid UART context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Uart destructor
|
||||
*/
|
||||
@@ -124,12 +140,17 @@ class Uart
|
||||
* Read bytes from the device into a String object
|
||||
*
|
||||
* @param length to read
|
||||
* @throws std::bad_alloc If there is no space left for read.
|
||||
* @return string of data
|
||||
*/
|
||||
std::string
|
||||
readStr(int length)
|
||||
{
|
||||
char* data = (char*) malloc(sizeof(char) * length);
|
||||
if (data == NULL) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
int v = mraa_uart_read(m_uart, data, (size_t) length);
|
||||
std::string ret(data, v);
|
||||
free(data);
|
||||
@@ -170,10 +191,10 @@ class Uart
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
flush()
|
||||
{
|
||||
return mraa_uart_flush(m_uart);
|
||||
return (Result) mraa_uart_flush(m_uart);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,26 +205,26 @@ class Uart
|
||||
* @param baud unsigned int of baudrate i.e. 9600
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
setBaudRate(unsigned int baud)
|
||||
{
|
||||
return mraa_uart_set_baudrate(m_uart, baud);
|
||||
return (Result) mraa_uart_set_baudrate(m_uart, baud);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the transfer mode
|
||||
* For example setting the mode to 8N1 would be
|
||||
* "dev.setMode(8,MRAA_UART_PARITY_NONE , 1)"
|
||||
* "dev.setMode(8,UART_PARITY_NONE , 1)"
|
||||
*
|
||||
* @param bytesize data bits
|
||||
* @param parity Parity bit setting
|
||||
* @param stopbits stop bits
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
setMode(int bytesize, mraa_uart_parity_t parity, int stopbits)
|
||||
Result
|
||||
setMode(int bytesize, UartParity parity, int stopbits)
|
||||
{
|
||||
return mraa_uart_set_mode(m_uart, bytesize, parity, stopbits);
|
||||
return (Result) mraa_uart_set_mode(m_uart, bytesize, (mraa_uart_parity_t) parity, stopbits);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,10 +234,10 @@ class Uart
|
||||
* @param rtscts RTS/CTS out of band hardware flow control
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
setFlowcontrol(bool xonxoff, bool rtscts)
|
||||
{
|
||||
return mraa_uart_set_flowcontrol(m_uart, xonxoff, rtscts);
|
||||
return (Result) mraa_uart_set_flowcontrol(m_uart, xonxoff, rtscts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,10 +249,23 @@ class Uart
|
||||
* @param interchar inbetween char timeout
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t
|
||||
Result
|
||||
setTimeout(int read, int write, int interchar)
|
||||
{
|
||||
return mraa_uart_set_timeout(m_uart, read, write, interchar);
|
||||
return (Result) mraa_uart_set_timeout(m_uart, read, write, interchar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the blocking state for write operations
|
||||
*
|
||||
* @param dev The UART context
|
||||
* @param nonblock new nonblocking state
|
||||
* @return Result of operation
|
||||
*/
|
||||
Result
|
||||
SetNonBlocking(bool nonblock)
|
||||
{
|
||||
return (Result) mraa_uart_set_non_blocking(m_uart, nonblock);
|
||||
}
|
||||
|
||||
private:
|
||||
|
197
api/mraa/uart_ow.h
Normal file
197
api/mraa/uart_ow.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief UART OW module
|
||||
*
|
||||
* This module allows one to use MRAA's UART support in order to
|
||||
* interact with Dallas 1-wire compliant devices on a 1-wire bus. It
|
||||
* makes use of the UART for timing purposes. The principle of
|
||||
* operation is described here:
|
||||
* https://www.maximintegrated.com/en/app-notes/index.mvp/id/214
|
||||
*
|
||||
* It is important the you use a UART with CMOS/TTL level voltages
|
||||
* (3.3v/5v) RX and TX lines. DO NOT use standard RS232 level
|
||||
* voltages, or you are going to have a bad day.
|
||||
*
|
||||
* In addition, a diode should be placed across the RX and
|
||||
* TX lines like so:
|
||||
*
|
||||
* -|
|
||||
* U|
|
||||
* A| TX---|<--+
|
||||
* R| |
|
||||
* T| RX-------o--------o 1-wire data bus
|
||||
* -|
|
||||
*
|
||||
* The diode on TX is a 1N4148 (cheap and common), with the cathode
|
||||
* connected to TX, and the anode connected to RX and the rest of the
|
||||
* 1-wire data line.
|
||||
*
|
||||
* @snippet uart_ow.c Interesting
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "uart.h"
|
||||
|
||||
/* for now, we simply use the normal MRAA UART context */
|
||||
typedef struct _mraa_uart_ow {
|
||||
mraa_uart_context uart;
|
||||
/* search state */
|
||||
unsigned char ROM_NO[8]; /* 8 byte (64b) rom code */
|
||||
int LastDiscrepancy;
|
||||
int LastFamilyDiscrepancy;
|
||||
mraa_boolean_t LastDeviceFlag;
|
||||
} *mraa_uart_ow_context;
|
||||
|
||||
/* 8 bytes (64 bits) for a device rom code */
|
||||
static const int MRAA_UART_OW_ROMCODE_SIZE = 8;
|
||||
|
||||
/**
|
||||
* UART One Wire ROM related Command bytes
|
||||
*/
|
||||
typedef enum {
|
||||
MRAA_UART_OW_CMD_READ_ROM = 0x33, /**< read rom, when only one device on bus */
|
||||
MRAA_UART_OW_CMD_MATCH_ROM = 0x55, /**< match a specific rom code */
|
||||
MRAA_UART_OW_CMD_SKIP_ROM = 0xcc, /**< skip match/search rom */
|
||||
MRAA_UART_OW_CMD_SEARCH_ROM_ALARM = 0xec, /**< search all roms in alarm state */
|
||||
MRAA_UART_OW_CMD_SEARCH_ROM = 0xf0 /**< search all rom codes */
|
||||
} mraa_uart_ow_rom_cmd_t;
|
||||
|
||||
/**
|
||||
* Initialise uart_ow_context, uses UART board mapping
|
||||
*
|
||||
* @param uart the index of the uart set to use
|
||||
* @return uart_ow context or NULL
|
||||
*/
|
||||
mraa_uart_ow_context mraa_uart_ow_init(int uart);
|
||||
|
||||
/**
|
||||
* Initialise a raw uart_ow_context. No board setup.
|
||||
*
|
||||
* @param path for example "/dev/ttyS0"
|
||||
* @return uart_ow context or NULL
|
||||
*/
|
||||
mraa_uart_ow_context mraa_uart_ow_init_raw(const char* path);
|
||||
|
||||
/**
|
||||
* Get char pointer with tty device path within Linux
|
||||
* For example. Could point to "/dev/ttyS0"
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @return char pointer of device path
|
||||
*/
|
||||
const char* mraa_uart_ow_get_dev_path(mraa_uart_ow_context dev);
|
||||
|
||||
/**
|
||||
* Destroy a mraa_uart_ow_context
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @return mraa_result_t
|
||||
*/
|
||||
mraa_result_t mraa_uart_ow_stop(mraa_uart_ow_context dev);
|
||||
|
||||
/**
|
||||
* Read a byte from the 1-wire bus
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @return the byte read or -1 for error
|
||||
*/
|
||||
int mraa_uart_ow_read_byte(mraa_uart_ow_context dev);
|
||||
|
||||
/**
|
||||
* Write a byte to a 1-wire bus
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @param byte the byte to write to the bus
|
||||
* @return the byte read back during the time slot or -1 for error
|
||||
*/
|
||||
int mraa_uart_ow_write_byte(mraa_uart_ow_context dev, uint8_t byte);
|
||||
|
||||
/**
|
||||
* Write a bit to a 1-wire bus and read a bit corresponding to the
|
||||
* time slot back. This is possible due to the way we wired the TX
|
||||
* and RX together with a diode, forming a loopback.
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @param bit the bit to write to the bus
|
||||
* @return the bit read back during the time slot or -1 for error
|
||||
*/
|
||||
int mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t bit);
|
||||
|
||||
/**
|
||||
* Send a reset pulse to the 1-wire bus and test for device presence
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @return one of the mraa_result_t values
|
||||
*/
|
||||
mraa_result_t mraa_uart_ow_reset(mraa_uart_ow_context dev);
|
||||
|
||||
/**
|
||||
* Begin a rom code search of the 1-wire bus. This function
|
||||
* implements the 1-wire search algorithm. See the uart_ow.c example
|
||||
* for an idea on how to use this function to identify all devices
|
||||
* present on the bus.
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @param start true to start a new search from scratch, false to
|
||||
* continue an existing search
|
||||
* @param id the 8-byte rom code id of the current matched device when
|
||||
* a device is found
|
||||
* @return one of the mraa_result_t values
|
||||
*/
|
||||
mraa_result_t mraa_uart_ow_rom_search(mraa_uart_ow_context dev, mraa_boolean_t start, uint8_t* id);
|
||||
|
||||
/**
|
||||
* Send a command byte to a device on the 1-wire bus
|
||||
*
|
||||
* @param dev uart_ow context
|
||||
* @param command the command byte to send
|
||||
* @param id the rom code id of the device to receive the command,
|
||||
* NULL for all devices on the bus
|
||||
* @return one of the mraa_result_t values
|
||||
*/
|
||||
mraa_result_t mraa_uart_ow_command(mraa_uart_ow_context dev, uint8_t command, uint8_t* id);
|
||||
|
||||
/**
|
||||
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
|
||||
*
|
||||
* @param buffer the buffer containing the data
|
||||
* @param length the length of the buffer
|
||||
* @return the computed CRC
|
||||
*/
|
||||
uint8_t mraa_uart_ow_crc8(uint8_t* buffer, uint16_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
277
api/mraa/uart_ow.hpp
Normal file
277
api/mraa/uart_ow.hpp
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "uart_ow.h"
|
||||
#include "types.hpp"
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
namespace mraa
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief API for UART One Wire
|
||||
*
|
||||
* This file defines the UartOW (UART to Dallas 1-wire) interface for libmraa
|
||||
*
|
||||
* @snippet UartOW.cpp Interesting
|
||||
*/
|
||||
class UartOW
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* UartOW Constructor, takes a pin number which will map directly to the
|
||||
* linux uart number, this 'enables' the uart, nothing more
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @param uart the index of the uart to use
|
||||
*/
|
||||
UartOW(int uart)
|
||||
{
|
||||
m_uart = mraa_uart_ow_init(uart);
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Error initialising UART_OW");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UartOW Constructor, takes a string to the path of the serial
|
||||
* interface that is needed.
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @param path the file path for the UART to use
|
||||
*/
|
||||
UartOW(std::string path)
|
||||
{
|
||||
m_uart = mraa_uart_ow_init_raw(path.c_str());
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Error initialising UART");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uart destructor
|
||||
*/
|
||||
~UartOW()
|
||||
{
|
||||
mraa_uart_ow_stop(m_uart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string with tty device path within Linux
|
||||
* For example. Could point to "/dev/ttyS0"
|
||||
*
|
||||
* @return char pointer of device path
|
||||
*/
|
||||
std::string
|
||||
getDevicePath()
|
||||
{
|
||||
std::string ret_val(mraa_uart_ow_get_dev_path(m_uart));
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a byte from the 1-wire bus
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return the byte read
|
||||
*/
|
||||
uint8_t
|
||||
readByte()
|
||||
{
|
||||
int res = mraa_uart_ow_read_byte(m_uart);
|
||||
if (res == -1) {
|
||||
throw std::invalid_argument("Unknown UART_OW error");
|
||||
}
|
||||
return (uint8_t) res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a byte to a 1-wire bus
|
||||
*
|
||||
* @param byte the byte to write to the bus
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return the byte read back during the time slot
|
||||
*/
|
||||
uint8_t
|
||||
writeByte(uint8_t byte)
|
||||
{
|
||||
int res = mraa_uart_ow_write_byte(m_uart, byte);
|
||||
if (res == -1) {
|
||||
throw std::invalid_argument("Unknown UART_OW error");
|
||||
}
|
||||
return (uint8_t) res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a bit to a 1-wire bus and read a bit corresponding to the
|
||||
* time slot back. This is possible due to the way we wired the TX
|
||||
* and RX together with a diode, forming a loopback.
|
||||
*
|
||||
* @param bit the bit to write to the bus
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return the bit read back during the time slot
|
||||
*/
|
||||
bool
|
||||
writeBit(bool bit)
|
||||
{
|
||||
int res = mraa_uart_ow_bit(m_uart, (bit) ? 1 : 0);
|
||||
if (res == -1) {
|
||||
throw std::invalid_argument("Unknown UART_OW error");
|
||||
}
|
||||
return ((res) ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reset pulse to the 1-wire bus and test for device presence
|
||||
*
|
||||
* @return one of the mraa::Result values
|
||||
*/
|
||||
mraa::Result
|
||||
reset()
|
||||
{
|
||||
return (mraa::Result) mraa_uart_ow_reset(m_uart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a rom code search of the 1-wire bus. This function
|
||||
* implements the 1-wire search algorithm. See the uart_ow.c example
|
||||
* for an idea on how to use this function to identify all devices
|
||||
* present on the bus.
|
||||
*
|
||||
* @param start true to start a search from scratch, false to
|
||||
* continue a previously started search
|
||||
* @param id the 8-byte rom code id of the current matched device when a
|
||||
* device is found
|
||||
* @return one of the mraa::Result values
|
||||
*/
|
||||
mraa::Result
|
||||
search(bool start, uint8_t* id)
|
||||
{
|
||||
return (mraa::Result) mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a rom code search of the 1-wire bus. This function
|
||||
* implements the 1-wire search algorithm. See the UartOW.cpp
|
||||
* example for an idea on how to use this function to identify all
|
||||
* devices present on the bus.
|
||||
*
|
||||
* @param start true to start a search from scratch, false to
|
||||
* continue a previously started search
|
||||
* @return an empty string if no [more] devices are found, or a
|
||||
* string containing the 8-byte romcode of a detected device.
|
||||
*/
|
||||
std::string
|
||||
search(bool start)
|
||||
{
|
||||
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
|
||||
mraa_result_t rv;
|
||||
|
||||
rv = mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
|
||||
|
||||
if (rv == MRAA_SUCCESS) {
|
||||
// we found one
|
||||
std::string idStr((char*) id, MRAA_UART_OW_ROMCODE_SIZE);
|
||||
return idStr;
|
||||
} else {
|
||||
// failure, or end of search
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a command byte to a device on the 1-wire bus
|
||||
*
|
||||
* @param command the command byte to send
|
||||
* @param id the rom code id of the device to receive the command,
|
||||
* NULL for all devices on the bus
|
||||
* @return one of the mraa::Result values
|
||||
*/
|
||||
mraa::Result
|
||||
command(uint8_t command, uint8_t* id)
|
||||
{
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a command byte to a device on the 1-wire bus, supplying
|
||||
* the id as a std::string
|
||||
*
|
||||
* @param command the command byte to send
|
||||
* @param id std::string representing the code id of the device to
|
||||
* receive the command, or an empty string for all devices on the
|
||||
* bus. This string should be 8 bytes in size.
|
||||
* @return one of the mraa::Result values
|
||||
*/
|
||||
mraa::Result
|
||||
command(uint8_t command, std::string id)
|
||||
{
|
||||
if (id.empty() == 0)
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, NULL);
|
||||
else {
|
||||
if (id.size() != 8) {
|
||||
// Only 8 byte romcodes are legal.
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": id must be 8 bytes only");
|
||||
}
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, (uint8_t*) id.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
|
||||
*
|
||||
* @param buffer the buffer containing the data
|
||||
* @param length the length of the buffer
|
||||
* @return the computed CRC
|
||||
*/
|
||||
uint8_t
|
||||
crc8(uint8_t* buffer, uint16_t length)
|
||||
{
|
||||
return mraa_uart_ow_crc8(buffer, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a Dallas 1-wire compliant CRC8 computation on a
|
||||
* std::string based buffer
|
||||
*
|
||||
* @param buffer std::string buffer containing the data
|
||||
* @return the computed CRC
|
||||
*/
|
||||
uint8_t
|
||||
crc8(std::string buffer)
|
||||
{
|
||||
return mraa_uart_ow_crc8((uint8_t*) buffer.c_str(), buffer.size());
|
||||
}
|
||||
|
||||
private:
|
||||
mraa_uart_ow_context m_uart;
|
||||
};
|
||||
}
|
22
cmake/modules/COPYING-CMAKE-SCRIPTS
Normal file
22
cmake/modules/COPYING-CMAKE-SCRIPTS
Normal file
@@ -0,0 +1,22 @@
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
73
cmake/modules/FindFtd2xx.cmake
Normal file
73
cmake/modules/FindFtd2xx.cmake
Normal file
@@ -0,0 +1,73 @@
|
||||
# - Try to find libftd2xx
|
||||
# Once done this will define
|
||||
#
|
||||
# LIBFTD2XX_FOUND - system has libftd2xx
|
||||
# LIBFTD2XX_INCLUDE_DIRS - the libftd2xx include directory
|
||||
# LIBFTD2XX_LIBRARIES - Link these to use libftd2xx
|
||||
# LIBFTD2XX_DEFINITIONS - Compiler switches required for using libftd2xx
|
||||
#
|
||||
# Adapted from cmake-modules Google Code project
|
||||
#
|
||||
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# (Changes for libftd2xx) Copyright (c) 2008 Kyle Machulis <kyle@nonpolynomial.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if (LIBFTD2XX_LIBRARIES AND LIBFTD2XX_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(LIBFTD2XX_FOUND TRUE)
|
||||
else (LIBFTD2XX_LIBRARIES AND LIBFTD2XX_INCLUDE_DIRS)
|
||||
find_path(LIBFTD2XX_INCLUDE_DIR
|
||||
NAMES
|
||||
ftd2xx.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/opt/local/include
|
||||
/sw/include
|
||||
)
|
||||
|
||||
SET(FTD2XX_LIBNAME ftd2xx)
|
||||
IF(WIN32)
|
||||
SET(FTD2XX_LIBNAME ftd2xx.lib)
|
||||
ENDIF(WIN32)
|
||||
|
||||
find_library(LIBFTD2XX_LIBRARY
|
||||
NAMES
|
||||
${FTD2XX_LIBNAME}
|
||||
PATHS
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
)
|
||||
|
||||
if(LIBFTD2XX_INCLUDE_DIR)
|
||||
set(LIBFTD2XX_INCLUDE_DIRS
|
||||
${LIBFTD2XX_INCLUDE_DIR}
|
||||
)
|
||||
endif(LIBFTD2XX_INCLUDE_DIR)
|
||||
set(LIBFTD2XX_LIBRARIES
|
||||
${LIBFTD2XX_LIBRARY}
|
||||
)
|
||||
|
||||
if (LIBFTD2XX_INCLUDE_DIRS AND LIBFTD2XX_LIBRARIES)
|
||||
set(LIBFTD2XX_FOUND TRUE)
|
||||
endif (LIBFTD2XX_INCLUDE_DIRS AND LIBFTD2XX_LIBRARIES)
|
||||
|
||||
if (LIBFTD2XX_FOUND)
|
||||
if (NOT libftd2xx_FIND_QUIETLY)
|
||||
message(STATUS "Found libftd2xx: ${LIBFTD2XX_LIBRARIES}")
|
||||
endif (NOT libftd2xx_FIND_QUIETLY)
|
||||
else (LIBFTD2XX_FOUND)
|
||||
if (libftd2xx_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find libftd2xx")
|
||||
endif (libftd2xx_FIND_REQUIRED)
|
||||
endif (LIBFTD2XX_FOUND)
|
||||
|
||||
# show the LIBFTD2XX_INCLUDE_DIRS and LIBFTD2XX_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(LIBFTD2XX_INCLUDE_DIRS LIBFTD2XX_LIBRARIES)
|
||||
|
||||
endif (LIBFTD2XX_LIBRARIES AND LIBFTD2XX_INCLUDE_DIRS)
|
75
cmake/modules/FindFtd4222.cmake
Normal file
75
cmake/modules/FindFtd4222.cmake
Normal file
@@ -0,0 +1,75 @@
|
||||
# - Try to find LIBFT4222
|
||||
# Once done this will define
|
||||
#
|
||||
# LIBFT4222_FOUND - system has LIBFT4222
|
||||
# LIBFT4222_INCLUDE_DIRS - the LIBFT4222 include directory
|
||||
# LIBFT4222_LIBRARIES - Link these to use LIBFT4222
|
||||
# LIBFT4222_DEFINITIONS - Compiler switches required for using LIBFT4222
|
||||
#
|
||||
# Adapted from cmake-modules Google Code project
|
||||
#
|
||||
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
|
||||
#
|
||||
# (Changes for LIBFTD2XX) Copyright (c) 2008 Kyle Machulis <kyle@nonpolynomial.com>
|
||||
# (Changes for LIBFT4222) Henry Bruce <henry.bruce@intel.com> Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(LIBFT4222_FOUND TRUE)
|
||||
else (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS)
|
||||
find_path(LIBFT4222_INCLUDE_DIR
|
||||
NAMES
|
||||
libft4222.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/opt/local/include
|
||||
/sw/include
|
||||
)
|
||||
|
||||
SET(FTD4222_LIBNAME ft4222)
|
||||
IF(WIN32)
|
||||
SET(FTD4222_LIBNAME LibFT4222.lib)
|
||||
ENDIF(WIN32)
|
||||
|
||||
find_library(LIBFT4222_LIBRARY
|
||||
NAMES
|
||||
${FTD4222_LIBNAME}
|
||||
PATHS
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
/opt/local/lib
|
||||
/sw/lib
|
||||
)
|
||||
|
||||
if(LIBFT4222_INCLUDE_DIR)
|
||||
set(LIBFT4222_INCLUDE_DIRS
|
||||
${LIBFT4222_INCLUDE_DIR}
|
||||
)
|
||||
endif(LIBFT4222_INCLUDE_DIR)
|
||||
set(LIBFT4222_LIBRARIES
|
||||
${LIBFT4222_LIBRARY}
|
||||
)
|
||||
|
||||
if (LIBFT4222_INCLUDE_DIRS AND LIBFT4222_LIBRARIES)
|
||||
set(LIBFT4222_FOUND TRUE)
|
||||
endif (LIBFT4222_INCLUDE_DIRS AND LIBFT4222_LIBRARIES)
|
||||
|
||||
if (LIBFT4222_FOUND)
|
||||
if (NOT LIBFT4222_FIND_QUIETLY)
|
||||
message(STATUS "Found LIBFT4222: ${LIBFT4222_LIBRARIES}")
|
||||
endif (NOT LIBFT4222_FIND_QUIETLY)
|
||||
else (LIBFT4222_FOUND)
|
||||
if (LIBFT4222_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find LIBFT4222")
|
||||
endif (LIBFT4222_FIND_REQUIRED)
|
||||
endif (LIBFT4222_FOUND)
|
||||
|
||||
# show the LIBFT4222_INCLUDE_DIRS and LIBFT4222_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(LIBFT4222_INCLUDE_DIRS LIBFT4222_LIBRARIES)
|
||||
|
||||
endif (LIBFT4222_LIBRARIES AND LIBFT4222_INCLUDE_DIRS)
|
||||
|
21
cmake/modules/FindJSON-C.cmake
Normal file
21
cmake/modules/FindJSON-C.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
# JSON-C_FOUND - true if library and headers were found
|
||||
# JSON-C_INCLUDE_DIRS - include directories
|
||||
# JSON-C_LIBRARIES - library directories
|
||||
|
||||
find_package (PkgConfig)
|
||||
pkg_check_modules (PC_JSON-C QUIET json-c)
|
||||
|
||||
find_path (JSON-C_INCLUDE_DIR json.h HINTS ${PC_JSON-C_INCLUDEDIR}
|
||||
${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json)
|
||||
|
||||
find_library (JSON-C_LIBRARY NAMES json-c libjson-c HINTS ${PC_JSON-C_LIBDIR}
|
||||
${PC_JSON-C_LIBRARY_DIRS})
|
||||
|
||||
set (JSON-C_LIBRARIES ${JSON-C_LIBRARY})
|
||||
set (JSON-C_INCLUDE_DIRS ${JSON-C_INCLUDE_DIR})
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args (JSON-C DEFAULT_MSG JSON-C_LIBRARY JSON-C_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced (JSON-C_INCLUDE_DIR JSON-C_LIBRARY)
|
@@ -1,4 +1,12 @@
|
||||
find_program (NODE_EXECUTABLE NAMES node nodejs
|
||||
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
|
||||
macro(add_include_dir dir)
|
||||
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
|
||||
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||
HINTS
|
||||
$ENV{NODE_DIR}
|
||||
PATH_SUFFIXES bin
|
||||
@@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node nodejs
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
||||
# If compat-libuv package exists, it must be at start of include path
|
||||
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
|
||||
if (UV_ROOT_DIR)
|
||||
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||
add_include_dir(${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"
|
||||
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}/include/node)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
||||
else()
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - node.h not found")
|
||||
endif()
|
||||
|
||||
set (NODE_INCLUDE_DIRS
|
||||
${NODE_ROOT_DIR}/src
|
||||
${NODE_ROOT_DIR}/node
|
||||
${NODE_ROOT_DIR}/deps/v8/include
|
||||
${NODE_ROOT_DIR}/deps/uv/include
|
||||
# Check that v8.h is in NODEJS_INCLUDE_DIRS
|
||||
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||
if (NOT V8_ROOT_DIR)
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - v8.h not found")
|
||||
endif()
|
||||
|
||||
# Check that uv.h is in NODEJS_INCLUDE_DIRS
|
||||
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||
if (NOT UV_ROOT_DIR)
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - uv.h not found")
|
||||
endif()
|
||||
|
||||
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
||||
NODEJS_EXECUTABLE
|
||||
NODEJS_INCLUDE_DIRS
|
||||
)
|
||||
|
||||
find_package_handle_standard_args (Node DEFAULT_MSG
|
||||
NODE_EXECUTABLE
|
||||
NODE_INCLUDE_DIRS
|
||||
)
|
||||
|
||||
if (NODE_EXECUTABLE)
|
||||
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
||||
if (NODEJS_EXECUTABLE)
|
||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||
OUTPUT_VARIABLE _VERSION
|
||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||
OUTPUT_VARIABLE _V8_VERSION
|
||||
RESULT_VARIABLE _V8_RESULT)
|
||||
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
||||
@@ -48,12 +80,15 @@ if (NODE_EXECUTABLE)
|
||||
set (NODE_VERSION_MINOR "10")
|
||||
set (NODE_VERSION_PATCH "30")
|
||||
set (V8_VERSION_MAJOR "3")
|
||||
set (V8_VERSION_MAJOR "14")
|
||||
set (V8_VERSION_MAJOR "5")
|
||||
set (V8_VERSION_MINOR"14")
|
||||
set (V8_VERSION_PATCH "5")
|
||||
set (V8_VERSION_STRING "3.28.72")
|
||||
message ("defaulted to node 0.10.30")
|
||||
endif ()
|
||||
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
|
||||
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
||||
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
||||
message ("INFO - Node version is " ${NODE_VERSION_STRING})
|
||||
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
|
||||
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||
endif ()
|
||||
|
||||
mark_as_advanced (NODE_EXECUTABLE)
|
||||
|
21
cmake/modules/FindUDEV.cmake
Normal file
21
cmake/modules/FindUDEV.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
# UDEV_FOUND - true if library and headers were found
|
||||
# UDEV_INCLUDE_DIRS - include directories
|
||||
# UDEV_LIBRARIES - library directories
|
||||
|
||||
find_package (PkgConfig)
|
||||
pkg_check_modules (PC_UDEV QUIET udev)
|
||||
|
||||
find_path (UDEV_INCLUDE_DIR libudev.h HINTS ${PC_UDEV_INCLUDEDIR}
|
||||
${PC_UDEV_INCLUDE_DIRS} PATH_SUFFIXES udev)
|
||||
|
||||
find_library (UDEV_LIBRARY NAMES udev libudev HINTS ${PC_UDEV_LIBDIR}
|
||||
${PC_UDEV_LIBRARY_DIRS})
|
||||
|
||||
set (UDEV_LIBRARIES ${UDEV_LIBRARY})
|
||||
set (UDEV_INCLUDE_DIRS ${UDEV_INCLUDE_DIR})
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args (UDEV DEFAULT_MSG UDEV_LIBRARY UDEV_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced (UDEV_INCLUDE_DIR UDEV_LIBRARY)
|
158
cmake/modules/OpenCVDetectPython.cmake
Normal file
158
cmake/modules/OpenCVDetectPython.cmake
Normal file
@@ -0,0 +1,158 @@
|
||||
# Find specified Python version
|
||||
# Arguments:
|
||||
# preferred_version (value): Version to check for first
|
||||
# min_version (value): Minimum supported version
|
||||
# library_env (value): Name of Python library ENV variable to check
|
||||
# include_dir_env (value): Name of Python include directory ENV variable to check
|
||||
# found (variable): Set if interpreter found
|
||||
# executable (variable): Output of executable found
|
||||
# version_string (variable): Output of found version
|
||||
# version_major (variable): Output of found major version
|
||||
# version_minor (variable): Output of found minor version
|
||||
# libs_found (variable): Set if libs found
|
||||
# libs_version_string (variable): Output of found libs version
|
||||
# libraries (variable): Output of found Python libraries
|
||||
# library (variable): Output of found Python library
|
||||
# debug_libraries (variable): Output of found Python debug libraries
|
||||
# debug_library (variable): Output of found Python debug library
|
||||
# include_path (variable): Output of found Python include path
|
||||
# include_dir (variable): Output of found Python include dir
|
||||
# include_dir2 (variable): Output of found Python include dir2
|
||||
# packages_path (variable): Output of found Python packages path
|
||||
function(find_python preferred_version min_version library_env include_dir_env
|
||||
found executable version_string version_major version_minor
|
||||
libs_found libs_version_string libraries library debug_libraries
|
||||
debug_library include_path include_dir include_dir2 packages_path)
|
||||
if(NOT ${found})
|
||||
if(${executable})
|
||||
set(PYTHON_EXECUTABLE "${${executable}}")
|
||||
endif()
|
||||
|
||||
find_package(PythonInterp "${preferred_version}")
|
||||
if(NOT PYTHONINTERP_FOUND)
|
||||
find_package(PythonInterp "${min_version}")
|
||||
endif()
|
||||
|
||||
if(PYTHONINTERP_FOUND)
|
||||
# Copy outputs
|
||||
set(_found ${PYTHONINTERP_FOUND})
|
||||
set(_executable ${PYTHON_EXECUTABLE})
|
||||
set(_version_string ${PYTHON_VERSION_STRING})
|
||||
set(_version_major ${PYTHON_VERSION_MAJOR})
|
||||
set(_version_minor ${PYTHON_VERSION_MINOR})
|
||||
set(_version_patch ${PYTHON_VERSION_PATCH})
|
||||
|
||||
# Clear find_host_package side effects
|
||||
unset(PYTHONINTERP_FOUND)
|
||||
unset(PYTHON_EXECUTABLE CACHE)
|
||||
unset(PYTHON_VERSION_STRING)
|
||||
unset(PYTHON_VERSION_MAJOR)
|
||||
unset(PYTHON_VERSION_MINOR)
|
||||
unset(PYTHON_VERSION_PATCH)
|
||||
endif()
|
||||
|
||||
if(_found)
|
||||
set(_version_major_minor "${_version_major}.${_version_minor}")
|
||||
|
||||
if(NOT ANDROID AND NOT APPLE_FRAMEWORK)
|
||||
# not using _version_string here, because it might not conform to the CMake version format
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
# builder version can differ from target, matching base version (e.g. 2.7)
|
||||
find_package(PythonLibs "${_version_major_minor}")
|
||||
else()
|
||||
find_package(PythonLibs "${_version_major_minor}.${_version_patch}" EXACT)
|
||||
endif()
|
||||
|
||||
if(PYTHONLIBS_FOUND)
|
||||
# Copy outputs
|
||||
set(_libs_found ${PYTHONLIBS_FOUND})
|
||||
set(_libraries ${PYTHON_LIBRARIES})
|
||||
set(_include_path ${PYTHON_INCLUDE_PATH})
|
||||
set(_include_dirs ${PYTHON_INCLUDE_DIRS})
|
||||
set(_debug_libraries ${PYTHON_DEBUG_LIBRARIES})
|
||||
set(_libs_version_string ${PYTHONLIBS_VERSION_STRING})
|
||||
set(_debug_library ${PYTHON_DEBUG_LIBRARY})
|
||||
set(_library ${PYTHON_LIBRARY})
|
||||
set(_library_debug ${PYTHON_LIBRARY_DEBUG})
|
||||
set(_library_release ${PYTHON_LIBRARY_RELEASE})
|
||||
set(_include_dir ${PYTHON_INCLUDE_DIR})
|
||||
set(_include_dir2 ${PYTHON_INCLUDE_DIR2})
|
||||
|
||||
# Clear find_package side effects
|
||||
unset(PYTHONLIBS_FOUND)
|
||||
unset(PYTHON_LIBRARIES)
|
||||
unset(PYTHON_INCLUDE_PATH)
|
||||
unset(PYTHON_INCLUDE_DIRS)
|
||||
unset(PYTHON_DEBUG_LIBRARIES)
|
||||
unset(PYTHONLIBS_VERSION_STRING)
|
||||
unset(PYTHON_DEBUG_LIBRARY CACHE)
|
||||
unset(PYTHON_LIBRARY)
|
||||
unset(PYTHON_LIBRARY_DEBUG)
|
||||
unset(PYTHON_LIBRARY_RELEASE)
|
||||
unset(PYTHON_LIBRARY CACHE)
|
||||
unset(PYTHON_LIBRARY_DEBUG CACHE)
|
||||
unset(PYTHON_LIBRARY_RELEASE CACHE)
|
||||
unset(PYTHON_INCLUDE_DIR CACHE)
|
||||
unset(PYTHON_INCLUDE_DIR2 CACHE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${_executable} -c "from distutils.sysconfig import *; print(get_python_lib())"
|
||||
RESULT_VARIABLE _cvpy_process
|
||||
OUTPUT_VARIABLE _std_packages_path
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if("${_std_packages_path}" MATCHES "site-packages")
|
||||
set(_packages_path "python${_version_major_minor}/site-packages")
|
||||
else() #debian based assumed, install to the dist-packages.
|
||||
set(_packages_path "python${_version_major_minor}/dist-packages")
|
||||
endif()
|
||||
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${${packages_path}}")
|
||||
set(_packages_path "lib${LIB_SUFFIX}/${_packages_path}")
|
||||
else()
|
||||
set(_packages_path "lib/${_packages_path}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Export return values
|
||||
set(${found} "${_found}" CACHE INTERNAL "")
|
||||
set(${executable} "${_executable}" CACHE FILEPATH "Path to Python interpretor")
|
||||
set(${version_string} "${_version_string}" CACHE INTERNAL "")
|
||||
set(${version_major} "${_version_major}" CACHE INTERNAL "")
|
||||
set(${version_minor} "${_version_minor}" CACHE INTERNAL "")
|
||||
set(${libs_found} "${_libs_found}" CACHE INTERNAL "")
|
||||
set(${libs_version_string} "${_libs_version_string}" CACHE INTERNAL "")
|
||||
set(${libraries} "${_libraries}" CACHE INTERNAL "Python libraries")
|
||||
set(${library} "${_library}" CACHE FILEPATH "Path to Python library")
|
||||
set(${debug_libraries} "${_debug_libraries}" CACHE INTERNAL "")
|
||||
set(${debug_library} "${_debug_library}" CACHE FILEPATH "Path to Python debug")
|
||||
set(${include_path} "${_include_path}" CACHE INTERNAL "")
|
||||
set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
|
||||
set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
|
||||
set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
|
||||
endif()
|
||||
endfunction(find_python)
|
||||
|
||||
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
|
||||
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
|
||||
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
|
||||
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
|
||||
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
|
||||
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
|
||||
|
||||
find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
|
||||
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
|
||||
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
|
||||
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
|
||||
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
|
||||
PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
|
||||
|
||||
|
||||
if(PYTHON_DEFAULT_EXECUTABLE)
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
|
||||
elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
|
||||
endif()
|
@@ -13,7 +13,9 @@
|
||||
# "There are many more known variants/revisions that we do not handle/detect."
|
||||
|
||||
set(archdetect_c_code "
|
||||
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
|
||||
#if defined(__aarch64__)
|
||||
#error cmake_ARCH armv8
|
||||
#elif defined(__arm__) || defined(__TARGET_ARCH_ARM)
|
||||
#if defined(__ARM_ARCH_7__) \\
|
||||
|| defined(__ARM_ARCH_7A__) \\
|
||||
|| defined(__ARM_ARCH_7R__) \\
|
||||
|
@@ -75,6 +75,8 @@ style numbers.
|
||||
|
||||
There is also a second 8-pin connector on the Banana Pi, the pins are as follows:
|
||||
|
||||
| MRAA Number | Physical Pin | Function |
|
||||
|-------------|--------------|-----------|
|
||||
| 27 | P1-19 | 5V VCC |
|
||||
| 28 | P1-20 | 3V3 VCC |
|
||||
| 29 | P1-21 | GPIO(PH5) |
|
||||
|
140
docs/building.md
140
docs/building.md
@@ -1,10 +1,10 @@
|
||||
Building libmraa {#building}
|
||||
===============
|
||||
|
||||
libmraa uses cmake in order to make compilation relatively painless. Cmake runs
|
||||
build out of tree so the recommended way is to clone from git and make a build/
|
||||
libmraa uses cmake in order to make compilation relatively painless. CMake runs
|
||||
build out of tree so the recommended way is to clone from git and make a `build/`
|
||||
directory inside the clone directory.
|
||||
|
||||
For building imraa check [building imraa](./imraa.md)
|
||||
## Build dependencies
|
||||
Not all these are required but if you're unsure of what you're doing this is
|
||||
what you'll need:
|
||||
@@ -12,11 +12,17 @@ what you'll need:
|
||||
* [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)
|
||||
* [CMake](http://cmake.org) 2.8.8+
|
||||
* [CMake](http://cmake.org) 2.8.8+ (3.1+ is recommended for node.js version 2+)
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
To build the documentation you'll also need:
|
||||
* [Doxygen](http://www.stack.nl/~dimitri/doxygen/) 1.8.9.1+
|
||||
* [Graphviz](http://graphviz.org/) 2+ (For doxygen graph generation)
|
||||
* [Graphviz](http://graphviz.org/) 2+ (For Doxygen graph generation)
|
||||
* [Sphinx](http://sphinx-doc.org/) 1.1.3+ (For Python docs)
|
||||
|
||||
|
||||
@@ -33,81 +39,101 @@ If this goes wrong and you have all the dependencies installed, then please
|
||||
file an issue with the full output of `cmake ..` and `make` or however far you
|
||||
got.
|
||||
|
||||
After that you can install built files (into default path) by running:
|
||||
|
||||
|
||||
```bash
|
||||
sudo make install
|
||||
```
|
||||
|
||||
See flags for adjusting install paths in the section below.
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
sudo ln -s <your install prefix, e.g. /usr>/lib/python2.7/site-packages/* /usr/lib/python2.7/dist-packages
|
||||
```
|
||||
|
||||
Same approach works for Python 3, you'll just need to adjust the version number
|
||||
in the path accordingly.
|
||||
|
||||
## Configuration flags
|
||||
|
||||
Our cmake configure has a number of options, cmake-gui or ccmake (cmake -i is
|
||||
Our CMake configuration has a number of options, `cmake-gui` or `ccmake` (`cmake -i` is
|
||||
no longer with us :() can show you all the options. A few of the more common
|
||||
ones are listed below. Note that when the option starts with CMAKE_ it's an
|
||||
option that is made available by cmake and will be similar in all cmake
|
||||
projects. You need to add them after `cmake` but before `..`.
|
||||
ones are listed below. Note that when the option starts with `CMAKE_` it's an
|
||||
option that is made available by CMake and will be similar in all CMake
|
||||
projects. You need to add them after `cmake` but before `..`
|
||||
|
||||
A few recommended options:
|
||||
Changing install path from /usr/local to /usr:
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=/usr
|
||||
|
||||
Building debug build - adds -g and disables optimisations - this will force a
|
||||
Changing install path from `/usr/local` to `/usr`:
|
||||
`-DCMAKE_INSTALL_PREFIX:PATH=/usr`
|
||||
|
||||
Building debug build - adds `-g` and disables optimisations - this will force a
|
||||
full rebuild:
|
||||
-DCMAKE_BUILD_TYPE=DEBUG
|
||||
`-DCMAKE_BUILD_TYPE=DEBUG`
|
||||
|
||||
Using clang instead of gcc:
|
||||
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++
|
||||
Using `clang` instead of `gcc`:
|
||||
`-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++`
|
||||
|
||||
Building with an older version of SWIG (< 3.0.2) requires the disabling of javascript:
|
||||
-DBUILDSWIGNODE=OFF
|
||||
Building with an older version of SWIG (< 3.0.2) requires the disabling of JavaScript:
|
||||
`-DBUILDSWIGNODE=OFF`
|
||||
|
||||
Disabling python module building:
|
||||
-DBUILDSWIGPYTHON=OFF
|
||||
Disabling Python module building:
|
||||
`-DBUILDSWIGPYTHON=OFF`
|
||||
|
||||
Building doc, this will require [SPHINX](http://sphinx-doc.org) &
|
||||
[Doxygen](http://doxygen.org):
|
||||
-DBUILDDOC=ON
|
||||
`-DBUILDDOC=ON`
|
||||
|
||||
Building with python3 (careful you need to clear cmake cache between python
|
||||
version switches!)
|
||||
-DBUILDPYTHON3=ON
|
||||
|
||||
Override build architecture (this is useful because on x86 arm code is not
|
||||
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
|
||||
`-DBUILDARCH=arm`
|
||||
|
||||
## 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
|
||||
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.
|
||||
|
||||
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 form 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
|
||||
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
|
||||
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.
|
||||
|
||||
## Using a yocto/oe toolchain
|
||||
## Using a Yocto/OE toolchain
|
||||
|
||||
In order to compile with a yocto/oe toolchain use the following toolchain file.
|
||||
This works well on the edison 1.6 SDK. First source the environment file, then
|
||||
use our cmake toolchain file.
|
||||
In order to compile with a Yocto/OE toolchain use the following toolchain file.
|
||||
This works well on the Edison 1.7.2 SDK. First source the environment file, then
|
||||
use our CMake toolchain file.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
source /opt/poky-edison/1.6/environment-setup-core2-32-poky-linux
|
||||
source /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux
|
||||
mkdir build
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/oe-sdk_cross.cmake ..
|
||||
make
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
## Using coverity
|
||||
## 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.
|
||||
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.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
mkdir covbuild/ && cd covbuild
|
||||
@@ -117,34 +143,38 @@ tar caf mraa.tar.bz2 cov-int
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
## Building Java bindings
|
||||
Have JAVA_HOME set to JDK install directory. Most distributions set this from /etc/profile.d/ and have a way of switching between alternatives. We support both OpenJDK and Oracle's JDK. On Arch Linux with openjdk8 you'll have to set this yourself like this:
|
||||
Have JAVA_HOME set to JDK install directory. Most distributions set this from `/etc/profile.d/`
|
||||
and have a way of switching between alternatives. We support both OpenJDK and Oracle's JDK.
|
||||
On Arch Linux with OpenJDK 8 you'll have to set this yourself like this:
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
export JAVA_HOME=/usr/lib/jvm/default/
|
||||
~~~~~~~~~~~~~
|
||||
Then use the cmake configuration flag:
|
||||
-DBUILDSWIGJAVA=ON
|
||||
To compile Example.java
|
||||
Then use the CMake configuration flag:
|
||||
`-DBUILDSWIGJAVA=ON`
|
||||
To compile `Example.java`
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
javac -cp $DIR_WHERE_YOU_INSTALLED_MRAA/mraa.jar:. Example.java
|
||||
~~~~~~~~~~~~~
|
||||
To run, make sure libmraajava.so is in LD_LIBRARY_PATH
|
||||
To run, make sure `libmraajava.so` is in `LD_LIBRARY_PATH`
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
jave -cp $DIR_WHERE_YOU_INSTALLED_MRAA/mraa.jar:. Example
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
## Building an IPK/RPM package using cpack
|
||||
If you want to add or improve Java bindings for mraa, please follow the [Creating Java Bindings Guide](https://github.com/intel-iot-devkit/upm/blob/master/docs/creating_java_bindings.md).
|
||||
|
||||
You can get cpack to generate an IPK or RPM package fairly easily if you have
|
||||
## Building an IPK/RPM package using `cpack`
|
||||
|
||||
You can get `cpack` to generate an IPK or RPM package fairly easily if you have
|
||||
the correct packaging tools
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
cmake -DIPK=ON -DCMAKE_INSTAL_PREFIX=/usr ..
|
||||
cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
make package
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
To use RPM simply enable the RPM option. You'll need rpmbuild installed on your
|
||||
To use RPM simply enable the RPM option. You'll need `rpmbuild` installed on your
|
||||
build machine.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
cmake -DRPM=ON -DCMAKE_INSTAL_PREFIX=/usr ..
|
||||
cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
~~~~~~~~~~~~~
|
||||
|
268
docs/changelog.md
Normal file
268
docs/changelog.md
Normal file
@@ -0,0 +1,268 @@
|
||||
Changelog {#changelog}
|
||||
=========
|
||||
|
||||
This changelog is meant as a quick & rough guide to what has changed between
|
||||
versions. The API is now fairly stable but when new calls/features are added
|
||||
they are listed here. Anything pre 0.2.x is ignored.
|
||||
|
||||
**1.0.0**
|
||||
* Change API to enhance error checking in C. Changes include:
|
||||
- mraa_aio_read
|
||||
- mraa_i2c_read_byte
|
||||
- mraa_i2c_read
|
||||
- mraa_i2c_read_byte_data
|
||||
- mraa_i2c_read_word_data
|
||||
- mraa_spi_write_word
|
||||
- mraa::Spi:write_word becomes mraa::Spi::writeWord
|
||||
* Remove MRAA_ERROR_PLATFORM_ALREADY_INITIALISED which was deprecated for C89 compatibility
|
||||
* Remove pwm config_* apis as unused
|
||||
* Add mraa_remove_subplatform
|
||||
* Support NPM for android
|
||||
* Fix AIO always returning channel 0 with firmata support
|
||||
|
||||
**0.10.1**
|
||||
* Remove imraa from node package
|
||||
|
||||
**0.10.0**
|
||||
* Add Firmata support with -DFIRMATA=ON
|
||||
* Add imraa with support for pinmuxing and arduino101 flashing
|
||||
* Add better support for NVM installed node via NODE_ROOT_DIR.
|
||||
* Mraa bindings now link to libmraa.so.x
|
||||
* mraa_init() now returns MRAA_SUCCESS if platform is already initialize
|
||||
* Mraa java bindings now support JNI 1.6+
|
||||
* Added support for a02082 rpi2
|
||||
* Mraa has a logo!
|
||||
|
||||
**0.9.6**
|
||||
* ftdi ft4222 now dynamically loaded
|
||||
* FT4222 improved ISR code
|
||||
|
||||
**0.9.5**
|
||||
* Add support for the UP board (up-board.org)
|
||||
* Support OpenJDK 7 as well as OpenJDK 8
|
||||
* 96board better pin numbering
|
||||
* node v4 improvements
|
||||
* Support for PCA9555 i2c expander read/write on FT4222
|
||||
|
||||
**0.9.4**
|
||||
* Fix issue with edison ADC initilisation
|
||||
* documentation update
|
||||
|
||||
**0.9.3**
|
||||
* Intel edison detection much improved
|
||||
* ftdi ft4222 interrupt improvement
|
||||
* small fixes to java lib
|
||||
|
||||
**0.9.2**
|
||||
* Fix bug with mraa_init & USBPLAT
|
||||
* Add mraa_gpio_read_dir call
|
||||
* Enable cherryhill/braswell platform
|
||||
* Improved 96 board support
|
||||
|
||||
**0.9.1**
|
||||
* Minnowboard Turbot support
|
||||
* Change to java runables for ISR support
|
||||
* New platform version call
|
||||
* Default i2c bus on edison miniboard is now i2c-1
|
||||
* More compatibility with node.js versions > 0.10
|
||||
* New C++ get i2c default bus call
|
||||
* Various bug fixes & optimisations
|
||||
|
||||
**0.9.0**
|
||||
* Beta iio API in C & C++ (no SWIG support)
|
||||
* Added 96Board support
|
||||
* Added Brillo/Android support
|
||||
* Java ISR fixes
|
||||
* FT4222 gpio support
|
||||
|
||||
**0.8.1**
|
||||
* Nodejs 4.1.1 support
|
||||
* Java examples fixes
|
||||
* Nodejs SPI tweaks
|
||||
* Misc fixes
|
||||
|
||||
**0.8.0**
|
||||
* Better java support
|
||||
* Support for FT4222 subplatforms
|
||||
* New types.hpp improves C++ & SWIG APIs
|
||||
* Added support for minnowboard max compatible boards
|
||||
|
||||
**0.7.5**
|
||||
* 5th Generation NUC i2c support
|
||||
* NPM 0.10.x ia32 fix
|
||||
|
||||
**0.7.4**
|
||||
* Minnowboard i2c fix
|
||||
* Add NPM arm support
|
||||
* Uart initialisation improved
|
||||
* Better i2c bus detection on DE3815 & mmax
|
||||
|
||||
**0.7.3**
|
||||
* DE3815 i2c fix when using different kernels
|
||||
* Fixed various memory leaks in SWIG wrappers
|
||||
* gpio enums all prefixed with mraa_
|
||||
* Fix SPI CS pin caps causing mux_total to be > 0
|
||||
* Improved error checking/handling
|
||||
|
||||
**0.7.2**
|
||||
* Fix node.js npm builds with binding.gyp that didn't use --target-arch
|
||||
|
||||
**0.7.1**
|
||||
* Uart now uses binary arrays and has optional 'Str' functions in C++/SWIG
|
||||
* Various Uart module bugfixes
|
||||
* Node.js 0.12.4 support
|
||||
* Node.js documentation support
|
||||
|
||||
**0.7.0**
|
||||
* Uart module now contains read/write interactions and configuration
|
||||
* Python API contains more buffer checks
|
||||
* Java support
|
||||
* RPM cpack support
|
||||
|
||||
**0.6.2**
|
||||
* Node.js 0.12 support
|
||||
* NPM support
|
||||
* Formatting done with clang-format
|
||||
* Various examples and documentation updates
|
||||
* Supported added for Beaglebone Black + Banana Pi
|
||||
|
||||
**0.6.1**
|
||||
* 16bit spi iunctions added
|
||||
* Node.js ISR now supported
|
||||
|
||||
**0.6.0**
|
||||
* add device path queries for uart
|
||||
* add platform configuration querying
|
||||
* gpio sample added
|
||||
* improve i2c/spi write/read API for python & nodejs
|
||||
* performance improvements on edison & galileo
|
||||
|
||||
**0.5.4**
|
||||
* pwm read_* fix introduced in 0.5.3
|
||||
* improved npmpkg support
|
||||
|
||||
**0.5.3**
|
||||
* OE toolchain support added to CMake
|
||||
* Various UART fixes
|
||||
* SPI add CS exposure
|
||||
* Remove functions from mraa.c into modules
|
||||
* Rework of support for mmap
|
||||
* Intel Edison MMAP support added. Read and Write
|
||||
* I2C clean up, add cleaner functions
|
||||
* MinnowBoard Max support added
|
||||
* PWM period is written before duty
|
||||
* Node GYP build supported added
|
||||
* Add Get Platform Name function
|
||||
|
||||
**0.5.2**
|
||||
* pwm improvement & bugfix
|
||||
* spi mraa_spi_bit_per_word fix
|
||||
* new spi transfer function
|
||||
* i2c object api uses uint8_t
|
||||
* i2c readReg() calls added
|
||||
* edison i2c bus now defaults to a sensible value
|
||||
* edison uart enable support
|
||||
* edison hardware CS exposed as IO10
|
||||
* DE3815tykhe NUC support
|
||||
|
||||
**0.5.1**
|
||||
* Intel Edison - Mini breakout board support
|
||||
* Change to use syslog throughout instead of printing to stderr.
|
||||
* Fix misc issues brought up throuh coverity scans
|
||||
* Clear up Analog call documentation
|
||||
|
||||
**0.5.0**
|
||||
* Intel Edison - Arduino board support.
|
||||
* Boost Allowable i2c busses to 12
|
||||
* Additional platform hooks added
|
||||
* ADC is now 10bits by default on all platforms but can be changed
|
||||
|
||||
**0.4.5**
|
||||
* if only one spidev we default to it reguardless of number
|
||||
* mraa_pwm_config_ms & mraa_pwm_config_percent functions added
|
||||
* Uart C++ class added, adds python & node support
|
||||
* galileo gen2 gpio modes supported
|
||||
|
||||
**0.4.4**
|
||||
* prefix SPI mode with MRAA_SPI_
|
||||
* added C++ adc bitness calls
|
||||
|
||||
**0.4.3**
|
||||
* SPI Mode function now functional, API Change in SPI
|
||||
* I2C read in swig worked on.
|
||||
* Galileo Gen 2: PWM setting period sets all channel's period
|
||||
* Galileo Gen 2: I2C setup now specific to Gen 2.
|
||||
* General commits around freeing memory at the right times.
|
||||
|
||||
**0.4.2**
|
||||
* Barebone UART module added.
|
||||
* Hook branch merged.
|
||||
* I2C init hooks added.
|
||||
* Intel Galileo Gen 2, I2C gpio pins now go hiz input when I2C initialised.
|
||||
|
||||
**0.4.1**
|
||||
* Rename python & nodejs modules to mraa
|
||||
* common.hpp introduced for C++
|
||||
* python & nodejs modules can now take binary strings for Spi & I2c
|
||||
* improved Aio module and clear bitness
|
||||
* Improved Galileo Gen 2 support
|
||||
|
||||
**0.4.0**
|
||||
* Rename to mraa
|
||||
* get_platform_type function added.
|
||||
|
||||
**0.3.1**
|
||||
* Initial Intel Galileo Gen 2 support
|
||||
* mraa_gpio_isr parameters added.
|
||||
* Detection of different supported platforms added.
|
||||
|
||||
**0.3.0**
|
||||
* mraa_i2c_read now returns length of read
|
||||
|
||||
**0.2.9**
|
||||
* Add global mraa.h & mraa.hpp headers
|
||||
* usage of "gpio.h" is not legal you need to use "mraa/gpio.h" unless adding
|
||||
-L/usr/include/mraa
|
||||
|
||||
**0.2.8**
|
||||
* Added mraa_set_priority call
|
||||
* Added mmap gpio call mraa_gpio_use_mmaped
|
||||
|
||||
**0.2.7**
|
||||
* C++ API now uses basic types and not unistd types as C
|
||||
* Clearer and consistent use of unistd tpyes in C api
|
||||
|
||||
**0.2.6**
|
||||
* C++ examples added, using c++ headers/api.
|
||||
* moved to open instead of fopen in all modules
|
||||
* rename mraa_check functions and made them internal to mraa only.
|
||||
* removed "export" functions from api
|
||||
* Intel Galileo Gen 1 (rev d) fixes, incorrect definition of some items
|
||||
* SPI, implementation completed.
|
||||
* I2C internal function, completed.
|
||||
* PWM fix bug in period set method.
|
||||
* Swig upstream can be used for building.
|
||||
* No longer builds docs on default cmake, needs flag
|
||||
* GPIO/PWM ownership guard prevents closing on existing pins, still can be forced.
|
||||
|
||||
**0.2.5**
|
||||
* C++/Python/Node Enums/const names now do not contain MRAA_GPIO
|
||||
* Enum type declaration for C++ changed
|
||||
* Python/Node get_version() -> GetVersion()
|
||||
* i2c read calls don't use const char* and i2c write calls do
|
||||
|
||||
**0.2.4**
|
||||
* All mraa_ contexts now are pointers to the actual struct which is not
|
||||
delcared in the header. The only end user change is that instead of
|
||||
returning a type mraa_gpio_context pointer mraa_gpio_init() now returns a
|
||||
mraa_gpio_context (which is actually a pointer to struct _gpio internally).
|
||||
* C++ API is available, use the .hpp headers and add stdc++ to the linker
|
||||
flags.
|
||||
* Initial SPI implementation is provided
|
||||
|
||||
**0.2.3**
|
||||
* mraa_aio_read_u16() -> mraa_aio_read()
|
||||
* mraa_aio_read() now returns a uint16_t instead of an unsigned int
|
||||
|
||||
**0.2.2**
|
||||
* First version with API considered 'stable'
|
@@ -17,6 +17,8 @@ Intel Arduino board
|
||||
The Edison used with the Arduino board has the following limitations
|
||||
in libmraa:
|
||||
|
||||
- Do not use the 'reset' button on the arduino shields, there is a hardware
|
||||
bug and the platform will likely not come back up correctly
|
||||
- I2C is exposed on i2c-6, therefore you must use bus 6 and not bus 0
|
||||
- PWM available on default swizzler positions. (3,5,6,9)
|
||||
- SPI exposed is also used for the ADC. Try not to use your own CS.
|
||||
@@ -31,6 +33,14 @@ in libmraa:
|
||||
else. Therefore use `mraa_gpio_init(14)` to use A0 as a GPIO
|
||||
- Arduino pin 7 can sometimes negatively impact the WiFi capability, if using
|
||||
WiFi avoid using this pin
|
||||
- Edison's i2c-1 can be used using for example the sparkfun i2c breakout ontop
|
||||
of the Arduino breakout board, this is not supported officially so asking for
|
||||
mraa_i2c_init(1) will result in getting i2c bus 6 (the default one). However
|
||||
using raw mode (mraa_i2c_init_raw(1)) this bus is fully usable
|
||||
- If you want to use /dev/ttyMFD2 you have to use the raw uart mode passing a
|
||||
std::string or char* argument of "/dev/ttyMFD2" to mraa:Uart() or
|
||||
mraa_uart_init_raw. By default there is a getty running on that interface so
|
||||
you will need to disable that first
|
||||
|
||||
Because of the way IO is setup with the tristate on the Arduino breakout board
|
||||
IO will be flipped as it is setup. It's recommended to setup IO pins &
|
||||
|
37
docs/firmata.md
Normal file
37
docs/firmata.md
Normal file
@@ -0,0 +1,37 @@
|
||||
Using Firmata board with mraa {#firmata}
|
||||
=============================
|
||||
|
||||
Mraa can use a Firmata board as a subplatform. This means one can access the
|
||||
native IO as well as the IO on a firmata compatible board
|
||||
|
||||
### Supported Firmata boards ###
|
||||
|
||||
- Genuino/Arduino 101 running either CustomFirmata or StandardFirmata
|
||||
- Other Arduino boards will likely work but are as of yet unsuported
|
||||
|
||||
### Using the subplatform API ###
|
||||
|
||||
Using the subplatform API is relatively simple, simply add '512', the platform
|
||||
offset to any IO calls. I2c 0 becomes I2c 512+0 etc... The API works from UPM
|
||||
or mraa in any of the bindings as long as you compiled mraa with -DFIRMATA=ON.
|
||||
Currently -DFIRMATA is not compatible with USBPLAT. Multiple subplatforms are
|
||||
not yet supported
|
||||
|
||||
### Sending custom SYSSEX messages ###
|
||||
|
||||
You can use the firmata API to send custom SYSEX messages.
|
||||
|
||||
### CurieImu Plugin ###
|
||||
|
||||
Using Customisable firmata we're able to use the onboard IMU to get data. This
|
||||
uses the public SYSEX firmata API from mraa and there is a UPM module that
|
||||
exposes this capability in a simple way. To use it your board needs to use
|
||||
CustomFirmata with the CurieIMU plugin
|
||||
|
||||
### Limitations ###
|
||||
|
||||
Only one instance of mraa (one process linking to mraa) can communicate to an
|
||||
firmata subplatform. This is a limitation due to only having one application
|
||||
using the Uart at once. In order to get around this a daemon type methodology
|
||||
has to be used. Technically you can mirror the TTY port from firmata but this
|
||||
is likely going to cause issues
|
80
docs/ftdi_ft4222.md
Normal file
80
docs/ftdi_ft4222.md
Normal file
@@ -0,0 +1,80 @@
|
||||
FTDI FT4222H {#ft4222}
|
||||
============
|
||||
|
||||
The FT4222H is a High/Full Speed USB2.0-to-Quad SPI/I2C device controller. Mraa
|
||||
supports it as a USB subplatform using the libft4222 library from FTDI which
|
||||
can be found
|
||||
[here](http://www.ftdichip.com/Support/SoftwareExamples/libft4222-1.2.1.4.tgz).
|
||||
You need the latest version for the GPIO to work.
|
||||
|
||||
The FT4222H has 4 configuration modes selected by {DCNF1, DCNF0}. The chip
|
||||
configuration mode will determine the number of USB interfaces for data streams
|
||||
and for GPIOs control. Mraa supports chip modes CNFMODE0 and CNFMODE3. In
|
||||
CNFMODE0 the chip can provide either 4 GPIOs and SPI, or 2 GPIOs and I2C
|
||||
since SCL/SDA are shared with GPIO0/GPIO1. It is possible to change this
|
||||
selection dynamically by calling the corresponding mraa init functions.
|
||||
CNFMODE3 on the other hand will only provide SPI or I2C.
|
||||
|
||||
By default, both modes start with I2C enabled and the driver will scan for
|
||||
known GPIO expanders on the I2C bus when the FT4222H is initialized.
|
||||
|
||||
Supported GPIO expanders:
|
||||
* PCA9672
|
||||
* PCA9555
|
||||
* PCF8575
|
||||
|
||||
Output from 'mraa-gpio list' would be as follows:
|
||||
~~~~~~~~~~~~~
|
||||
512 IGPIO0/SCL0: GPIO I2C
|
||||
513 IGPIO1/SDA0: GPIO I2C
|
||||
514 INT-GPIO2: GPIO
|
||||
515 INT-GPIO3: GPIO
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
When an I2C GPIO expander is present, the pins on the expander will appear after
|
||||
the 4 FT4222H GPIO pins (i.e. starting at physical pin #4, logical pin #516).
|
||||
~~~~~~~~~~~~~
|
||||
512 IGPIO0/SCL0: GPIO I2C
|
||||
513 IGPIO1/SDA0: GPIO I2C
|
||||
514 INT-GPIO2: GPIO
|
||||
515 INT-GPIO3: GPIO
|
||||
516 EXP-GPIO0: GPIO
|
||||
517 EXP-GPIO1: GPIO
|
||||
518 EXP-GPIO2: GPIO
|
||||
519 EXP-GPIO3: GPIO
|
||||
520 EXP-GPIO4: GPIO
|
||||
521 EXP-GPIO5: GPIO
|
||||
522 EXP-GPIO6: GPIO
|
||||
523 EXP-GPIO7: GPIO
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
If a PCA9545 I2C switch is detected an extra four I2C busses will appear,
|
||||
representing the four downstream busses. Output from 'mraa-i2c list'
|
||||
would be as follows:
|
||||
~~~~~~~~~~~~~
|
||||
Bus 512: id=00 type=ft4222 default
|
||||
Bus 513: id=01 type=ft4222
|
||||
Bus 514: id=02 type=ft4222
|
||||
Bus 515: id=03 type=ft4222
|
||||
Bus 516: id=04 type=ft4222
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Please note that some mraa features might not be fully implemented yet and they
|
||||
are still under development (e.g. SPI replacement functions).
|
||||
|
||||
We tested the module using FTDI's UMFT4222EV reference board. More details on
|
||||
this board can be found
|
||||
[here](http://www.ftdichip.com/Support/Documents/DataSheets/Modules/DS_UMFT4222EV.pdf).
|
||||
|
||||
Interface notes
|
||||
---------------
|
||||
|
||||
You will need to unload all ftdi kernel modules for libft4222 to work
|
||||
correctly. You will also have to compile mraa with FT4222 support which may not
|
||||
be enabled by default.
|
||||
|
||||
The cmake options to build this driver are:
|
||||
~~~~~~~~~~~~~
|
||||
FTDI4222=ON
|
||||
USBPLAT=ON
|
||||
~~~~~~~~~~~~~
|
@@ -8,7 +8,7 @@ The rev D board has the following limitations in libmraa:
|
||||
|
||||
- gpio 13 will not switch the LED as it's a different Gpio, use raw gpio '3' to do this
|
||||
- gpio register access via /dev/uio is limited to pin2 and 3
|
||||
- gpio interupts will only work on GPIO_EDGE_BOTH
|
||||
- gpio interrupts will only work on GPIO_EDGE_BOTH
|
||||
- adc kernel module will return 12bit number. MRAA defaults shift this to 10bits
|
||||
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
|
||||
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio
|
||||
|
@@ -17,6 +17,16 @@ The Gen 2 board has the following limitations in libmraa:
|
||||
accuracy of 10bits.
|
||||
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
|
||||
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio
|
||||
- To explicitly use GPIO 10 for SPI and allow the kernel to handle the chip select, set
|
||||
`intel_qrk_plat_galileo_gen2.gpio_cs=1` on the kernel line in the boot config on the
|
||||
galileo, this can be found at `/media/mmcblk0p1/boot/grub/grub.conf`
|
||||
- if done correctly it should look similiar to this:
|
||||
|
||||
<pre>
|
||||
title Quark X1000 kernel-MassStorage iot-devkit on SD IMR-On IO-APIC/HPET NoEMU debug
|
||||
root (hd0,0)
|
||||
kernel /bzImage root=/dev/mmcblk0p2 <b>intel_qrk_plat_galileo_gen2.gpio_cs=1</b> rootwait console=ttyS1,115200n8 earlycon=uart8250,mmio32,0x8010f000,115200n8 reboot=efi,warm apic=debug rw LABEL=boot debugshell=5
|
||||
</pre>
|
||||
|
||||
Uart 1 on gen2
|
||||
--------------
|
||||
@@ -26,8 +36,8 @@ possible to use it from A2(Rx)/A3(Tx). However mraa does not support this
|
||||
directly so you need to enable the muxing manually. Here is an example of how
|
||||
this is done, this was tested using an FTDI 3.3V TTL cable:
|
||||
|
||||
```
|
||||
$ systemctl stop serial-getty@ttyS1.service
|
||||
|
||||
$ python
|
||||
>>> # Configure the Muxes for Uart1 on Aio2/3
|
||||
>>> import mraa as m
|
||||
@@ -53,4 +63,4 @@ $ python
|
||||
>>> x.writeStr('hello')
|
||||
>>> x.read(5)
|
||||
bytearray(b'dsds\n')
|
||||
|
||||
```
|
||||
|
44
docs/iio.md
Normal file
44
docs/iio.md
Normal file
@@ -0,0 +1,44 @@
|
||||
iio {#iio}
|
||||
===
|
||||
IIO is the kernel's framework for supporting sensors.
|
||||
## Using dummy_iio driver
|
||||
For platforms without IIO hardware the iio_dummy driver can be used. You can
|
||||
add the driver by either rebuilding the kernel with IIO component enabled or
|
||||
just building the IIO modules and load them. You must add the following config
|
||||
fragment. Known to work for kernel 3.19 and later.
|
||||
<pre><code>
|
||||
CONFIG_IIO_DUMMY_EVGEN=m
|
||||
CONFIG_IIO_SIMPLE_DUMMY=m
|
||||
CONFIG_IIO_SIMPLE_DUMMY_EVENTS=y
|
||||
CONFIG_IIO_SIMPLE_DUMMY_BUFFER=y
|
||||
</code></pre>
|
||||
### Add driver to kernel
|
||||
Boot with new kernel, then load modules
|
||||
<pre><code>
|
||||
$ modprobe iio_dummy
|
||||
$ modprobe iio_dummy_evgen
|
||||
</code></pre>
|
||||
### Load kernel modules
|
||||
Depending our your kernel config, some of these modules may already be loaded.
|
||||
<pre><code>
|
||||
$ insmod drivers/iio/industrialio.ko
|
||||
$ insmod drivers/iio/kfifo_buf.ko
|
||||
$ insmod drivers/staging/iio/iio_dummy_evgen.ko
|
||||
$ insmod drivers/staging/iio/iio_dummy.ko
|
||||
</code></pre>
|
||||
## 'RAW' access
|
||||
|
||||
Mraa supports raw access
|
||||
|
||||
###Channels
|
||||
|
||||
###Attributes
|
||||
|
||||
###Events
|
||||
|
||||
###Triggers
|
||||
|
||||
Activate the trigger in /sys/class/iio
|
||||
$ echo 1 > trigger0/trigger_now
|
||||
|
||||
|
63
docs/imraa.md
Normal file
63
docs/imraa.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Building mraa with imraa {#buildingimraa}
|
||||
Imraa allows seamless communication between the Arduino101 and your mraa
|
||||
projects. Imraa will flash an arduino101 and allow automatic loading of the
|
||||
MRAA_GENERIC_FIRMATA subplatform to the first process that calls imraa_init
|
||||
(done through mraa_init automatically)
|
||||
|
||||
## Build dependencies
|
||||
To build imraa, you'll need to build mraa with -DIMRAA=ON and all the normal
|
||||
dependencies for build mraa, see [Building mraa](./building.md).
|
||||
You'll also need the following:
|
||||
* [dfu-utils-cross](https://github.com/arduino/dfu-utils-cross) or dfu 0.8 (0.9
|
||||
does not work well with the 101). Precompiled binaries can be found on
|
||||
[here](https://github.com/01org/intel-arduino-tools)
|
||||
* [json-c](https://github.com/json-c/json-c): likely called libjson-c-dev or
|
||||
json-c-devel
|
||||
* libudev: likely called libudev-dev or libudev-devel
|
||||
|
||||
## Basic build steps
|
||||
This will build mraa with imraa for the local default path. To build mraa for
|
||||
the system add `-DCMAKE_INSTALL_PREFIX=/usr` to the cmake command before
|
||||
running it.
|
||||
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DIMRAA=ON -DFIRMATA=ON ..
|
||||
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).
|
||||
Once downloaded the file needs to be renamed and moved to the where mraa was
|
||||
installed. This is dependant on whether you installed locally or for the
|
||||
system. The example below is for a locally installed copy. Note this sketch is
|
||||
using ConfigurableFirmata + the [CurieIMU plugin](https://github.com/intel-iot-devkit/FirmataCurieIMU).
|
||||
|
||||
|
||||
```bash
|
||||
$ mv ConfigurableFirmataCurieImu.ino.bin firmata101.ino.bin
|
||||
$ mv firmata101.ino.bin /usr/local/share/mraa
|
||||
```
|
||||
|
||||
You will also need to move the imraa config so that imraa can find it.
|
||||
```bash
|
||||
$ mv mraa/imraa/imraa.conf /etc/
|
||||
```
|
||||
|
||||
To flash the board run imraa and it will create the lockfile and flash the
|
||||
Arduino101. You may need root permissions or to add yourself to the uucp or
|
||||
modem group to access the device node (typically /dev/ttyACM0).
|
||||
```
|
||||
$ imraa
|
||||
```
|
||||
|
||||
After this is successful you will be able to use mraa like normal, in the
|
||||
background mraa will handle talking to the arduino101 by creating
|
||||
/tmp/imraa.lock which imraa_init() will parse on startup.
|
||||
|
69
docs/index.java.md
Normal file
69
docs/index.java.md
Normal file
@@ -0,0 +1,69 @@
|
||||
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
|
||||
==============
|
||||
|
||||
Libmraa is a C/C++ library with bindings to Java, Python and JavaScript to
|
||||
interface with the I/O on Galileo, Edison & other platforms, with a structured
|
||||
and sane API where port names/numbering matches the board that you are on. Use
|
||||
of libmraa does not tie you to specific hardware with board detection done at
|
||||
runtime you can create portable code that will work across the supported
|
||||
platforms.
|
||||
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
their sensors & actuators on top of supported hardware and to allow control of
|
||||
low level communication protocol by high level languages & constructs.
|
||||
|
||||
## API
|
||||
|
||||
These interfaces allow you to interact with all libmraa functionality. The
|
||||
Java classes directly wrap the C/C++ API and provide a near 1:1 mapping of
|
||||
functionality.
|
||||
|
||||
<center>
|
||||
| C API Modules | Java API Classes |
|
||||
|:----------------------:|:----------------------------:|
|
||||
| @ref gpio.h "gpio" | @ref mraa::Gpio "Gpio class" |
|
||||
| @ref i2c.h "i2c" | @ref mraa::I2c "I2c class" |
|
||||
| @ref aio.h "aio" | @ref mraa::Aio "Aio class" |
|
||||
| @ref pwm.h "pwm" | @ref mraa::Pwm "Pwm class" |
|
||||
| @ref spi.h "spi" | @ref mraa::Spi "Spi class" |
|
||||
| @ref uart.h "uart" | @ref mraa::Uart "Uart class" |
|
||||
| @ref common.h "common" | @ref mraa::mraa "mraa class" |
|
||||
</center>
|
||||
|
||||
### Hello Mraa
|
||||
@snippet HelloEdison.java Interesting
|
||||
|
||||
## Supported platforms
|
||||
|
||||
Specific platform information for supported platforms is documented here:
|
||||
|
||||
- @ref galileorevd
|
||||
- @ref galileorevh
|
||||
- @ref edison
|
||||
- @ref de3815
|
||||
- @ref minnowmax
|
||||
- @ref rasppi
|
||||
- @ref bananapi
|
||||
- @ref beaglebone
|
||||
- @ref nuc5
|
||||
- @ref ft4222
|
||||
|
||||
## DEBUGGING
|
||||
|
||||
Sometimes it just doesn't want to work, let us try and help you, you can file
|
||||
issues in github or join us in #mraa on freenode IRC, hang around for a little
|
||||
while because we're not necessarily on 24/7, but we'll get back to you! Have a
|
||||
glance at our @debugging page too
|
||||
|
||||
## COMPILING
|
||||
|
||||
More information on compiling is @ref building page.
|
||||
|
||||
## CONTRIBUTING
|
||||
|
||||
Please see the @ref contributing page, the @ref internals page may also be of
|
||||
use.
|
||||
|
||||
## API Changelog
|
||||
|
||||
Version @ref changelog here.
|
196
docs/index.md
196
docs/index.md
@@ -1,14 +1,14 @@
|
||||
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
|
||||
==============
|
||||
|
||||
Libmraa is a C/C++ library with bindings to javascript & python to interface
|
||||
with the IO on Galileo, Edison & other platforms, with a structured and sane
|
||||
API where port names/numbering matches the board that you are on. Use of
|
||||
libmraa does not tie you to specific hardware with board detection done at
|
||||
Libmraa is a C/C++ library with bindings to Python, Javascript and Java to
|
||||
interface with the I/O on Galileo, Edison & other platforms, with a structured
|
||||
and sane API where port names/numbering matches the board that you are on. Use
|
||||
of libmraa does not tie you to specific hardware with board detection done at
|
||||
runtime you can create portable code that will work across the supported
|
||||
platforms.
|
||||
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
their sensors & actuators on top of supported hardware and to allow control of
|
||||
low level communication protocol by high level languages & constructs.
|
||||
|
||||
@@ -46,6 +46,8 @@ Specific platform information for supported platforms is documented here:
|
||||
- @ref bananapi
|
||||
- @ref beaglebone
|
||||
- @ref nuc5
|
||||
- @ref up
|
||||
- @ref ft4222
|
||||
|
||||
## DEBUGGING
|
||||
|
||||
@@ -65,186 +67,4 @@ use.
|
||||
|
||||
## API Changelog
|
||||
|
||||
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.
|
||||
|
||||
**0.7.5**
|
||||
* 5th Generation NUC i2c support
|
||||
* NPM 0.10.x ia32 fix
|
||||
|
||||
**0.7.4**
|
||||
* Minnowboard i2c fix
|
||||
* Add NPM arm support
|
||||
* Uart initialisation improved
|
||||
* Better i2c bus detection on DE3815 & mmax
|
||||
|
||||
**0.7.3**
|
||||
* DE3815 i2c fix when using different kernels
|
||||
* Fixed various memory leaks in SWIG wrappers
|
||||
* gpio enums all prefixed with mraa_
|
||||
* Fix SPI CS pin caps causing mux_total to be > 0
|
||||
* Improved error checking/handling
|
||||
|
||||
**0.7.2**
|
||||
* Fix node.js npm builds with binding.gyp that didn't use --target-arch
|
||||
|
||||
**0.7.1**
|
||||
* Uart now uses binary arrays and has optional 'Str' functions in C++/SWIG
|
||||
* Various Uart module bugfixes
|
||||
* Node.js 0.12.4 support
|
||||
* Node.js documentation support
|
||||
|
||||
**0.7.0**
|
||||
* Uart module now contains read/write interactions and configuration
|
||||
* Python API contains more buffer checks
|
||||
* Java support
|
||||
* RPM cpack support
|
||||
|
||||
**0.6.2**
|
||||
* Node.js 0.12 support
|
||||
* NPM support
|
||||
* Formatting done with clang-format
|
||||
* Various examples and documentation updates
|
||||
* Supported added for Beaglebone Black + Banana Pi
|
||||
|
||||
**0.6.1**
|
||||
* 16bit spi iunctions added
|
||||
* Node.js ISR now supported
|
||||
|
||||
**0.6.0**
|
||||
* add device path queries for uart
|
||||
* add platform configuration querying
|
||||
* gpio sample added
|
||||
* improve i2c/spi write/read API for python & nodejs
|
||||
* performance improvements on edison & galileo
|
||||
|
||||
**0.5.4**
|
||||
* pwm read_* fix introduced in 0.5.3
|
||||
* improved npmpkg support
|
||||
|
||||
**0.5.3**
|
||||
* OE toolchain support added to CMake
|
||||
* Various UART fixes
|
||||
* SPI add CS exposure
|
||||
* Remove functions from mraa.c into modules
|
||||
* Rework of support for mmap
|
||||
* Intel Edison MMAP support added. Read and Write
|
||||
* I2C clean up, add cleaner functions
|
||||
* MinnowBoard Max support added
|
||||
* PWM period is written before duty
|
||||
* Node GYP build supported added
|
||||
* Add Get Platform Name function
|
||||
|
||||
**0.5.2**
|
||||
* pwm improvement & bugfix
|
||||
* spi mraa_spi_bit_per_word fix
|
||||
* new spi transfer function
|
||||
* i2c object api uses uint8_t
|
||||
* i2c readReg() calls added
|
||||
* edison i2c bus now defaults to a sensible value
|
||||
* edison uart enable support
|
||||
* edison hardware CS exposed as IO10
|
||||
* DE3815tykhe NUC support
|
||||
|
||||
**0.5.1**
|
||||
* Intel Edison - Mini breakout board support
|
||||
* Change to use syslog throughout instead of printing to stderr.
|
||||
* Fix misc issues brought up throuh coverity scans
|
||||
* Clear up Analog call documentation
|
||||
|
||||
**0.5.0**
|
||||
* Intel Edison - Arduino board support.
|
||||
* Boost Allowable i2c busses to 12
|
||||
* Additional platform hooks added
|
||||
* ADC is now 10bits by default on all platforms but can be changed
|
||||
|
||||
**0.4.5**
|
||||
* if only one spidev we default to it reguardless of number
|
||||
* mraa_pwm_config_ms & mraa_pwm_config_percent functions added
|
||||
* Uart C++ class added, adds python & node support
|
||||
* galileo gen2 gpio modes supported
|
||||
|
||||
**0.4.4**
|
||||
* prefix SPI mode with MRAA_SPI_
|
||||
* added C++ adc bitness calls
|
||||
|
||||
**0.4.3**
|
||||
* SPI Mode function now functional, API Change in SPI
|
||||
* I2C read in swig worked on.
|
||||
* Galileo Gen 2: PWM setting period sets all channel's period
|
||||
* Galileo Gen 2: I2C setup now specific to Gen 2.
|
||||
* General commits around freeing memory at the right times.
|
||||
|
||||
**0.4.2**
|
||||
* Barebone UART module added.
|
||||
* Hook branch merged.
|
||||
* I2C init hooks added.
|
||||
* Intel Galileo Gen 2, I2C gpio pins now go hiz input when I2C initialised.
|
||||
|
||||
**0.4.1**
|
||||
* Rename python & nodejs modules to mraa
|
||||
* common.hpp introduced for C++
|
||||
* python & nodejs modules can now take binary strings for Spi & I2c
|
||||
* improved Aio module and clear bitness
|
||||
* Improved Galileo Gen 2 support
|
||||
|
||||
**0.4.0**
|
||||
* Rename to mraa
|
||||
* get_platform_type function added.
|
||||
|
||||
**0.3.1**
|
||||
* Initial Intel Galileo Gen 2 support
|
||||
* mraa_gpio_isr parameters added.
|
||||
* Detection of different supported platforms added.
|
||||
|
||||
**0.3.0**
|
||||
* mraa_i2c_read now returns length of read
|
||||
|
||||
**0.2.9**
|
||||
* Add global mraa.h & mraa.hpp headers
|
||||
* usage of "gpio.h" is not legal you need to use "mraa/gpio.h" unless adding
|
||||
-L/usr/include/mraa
|
||||
|
||||
**0.2.8**
|
||||
* Added mraa_set_priority call
|
||||
* Added mmap gpio call mraa_gpio_use_mmaped
|
||||
|
||||
**0.2.7**
|
||||
* C++ API now uses basic types and not unistd types as C
|
||||
* Clearer and consistent use of unistd tpyes in C api
|
||||
|
||||
**0.2.6**
|
||||
* C++ examples added, using c++ headers/api.
|
||||
* moved to open instead of fopen in all modules
|
||||
* rename mraa_check functions and made them internal to mraa only.
|
||||
* removed "export" functions from api
|
||||
* Intel Galileo Gen 1 (rev d) fixes, incorrect definition of some items
|
||||
* SPI, implementation completed.
|
||||
* I2C internal function, completed.
|
||||
* PWM fix bug in period set method.
|
||||
* Swig upstream can be used for building.
|
||||
* No longer builds docs on default cmake, needs flag
|
||||
* GPIO/PWM ownership guard prevents closing on existing pins, still can be forced.
|
||||
|
||||
**0.2.5**
|
||||
* C++/Python/Node Enums/const names now do not contain MRAA_GPIO
|
||||
* Enum type declaration for C++ changed
|
||||
* Python/Node get_version() -> GetVersion()
|
||||
* i2c read calls don't use const char* and i2c write calls do
|
||||
|
||||
**0.2.4**
|
||||
* All mraa_ contexts now are pointers to the actual struct which is not
|
||||
delcared in the header. The only end user change is that instead of
|
||||
returning a type mraa_gpio_context pointer mraa_gpio_init() now returns a
|
||||
mraa_gpio_context (which is actually a pointer to struct _gpio internally).
|
||||
* C++ API is available, use the .hpp headers and add stdc++ to the linker
|
||||
flags.
|
||||
* Initial SPI implementation is provided
|
||||
|
||||
**0.2.3**
|
||||
* mraa_aio_read_u16() -> mraa_aio_read()
|
||||
* mraa_aio_read() now returns a uint16_t instead of an unsigned int
|
||||
|
||||
**0.2.2**
|
||||
* First version with API considered 'stable'
|
||||
Version @ref changelog here.
|
||||
|
84
docs/up.md
Normal file
84
docs/up.md
Normal file
@@ -0,0 +1,84 @@
|
||||
UP Board {#up}
|
||||
============
|
||||
|
||||
UP Board is based on the Intel(R) Atom(TM) x5-Z83xx SoC (formerly Cherry Trail).
|
||||
It includes 2GB RAM, 16/32GB eMMC flash, 6 USB2.0 ports, 1 USB 3.0 OTG port,
|
||||
1 Gigabit Ethernet, HDMI and DSI Graphics ports, RTC and a 40-pin I/O header.
|
||||
The form-factor for the board is based on the Raspberry Pi 2, and can be used
|
||||
with many of the add-on HAT boards designed for the Raspberry Pi 2.
|
||||
|
||||
Interface notes
|
||||
---------------
|
||||
|
||||
**PWM** PWM frequency range is from 293 Hz to 6.4 MHz. 8-bit resolution is
|
||||
supported for duty-cycle adjustments, but this reduces for frequencies > 97.6kHz
|
||||
|
||||
**I2C** 2 I2C channels support standard-mode (100kHz) and fast-mode (400kHz).
|
||||
Bus frequency can be selected in BIOS settings. Note that, unlike Raspberry Pi,
|
||||
the I2C controller issues Repeated-START commands for combined transactions
|
||||
(e.g. a write-then-read transaction) which may not be supported by some I2C
|
||||
slave devices. For such devices, it is advisable to use separate write and
|
||||
read transactions to ensure that Repeated-STARTs are not issued.
|
||||
|
||||
**SPI** Bus frequencies up to 25MHz are supported, in steps which are less
|
||||
granular at higher speeds. E.g. Available speeds include:
|
||||
25MHz, 12.5MHz, 8.33MHz, 6.25MHz, 5MHz, 4.167MHz, 3.571MHz, 3.125MHz, etc.
|
||||
Please be aware that speeds in between those steps will be rounded UP to the
|
||||
next nearest available speed, and capped at 25MHz.
|
||||
At the time of writing, only a single native chip-select is available (SPI CS0).
|
||||
|
||||
**UART** 2 high-speed UARTs are available, supporting baud rates up to
|
||||
support baud rates between 300 and 3686400. Hardware flow-control signals are
|
||||
not exposed, so software flow-control may be needed for rates above 115200.
|
||||
A console UART is also available but is not fully supported at this time.
|
||||
|
||||
Pin Mapping
|
||||
-----------
|
||||
|
||||
The GPIO numbering in the following pin mapping is based on the Raspberry Pi
|
||||
model 2 and B+ numbering scheme.
|
||||
|
||||
Note that there is an enum to use wiringPi style numbers.
|
||||
|
||||
| MRAA Number | Physical Pin | Function | Sysfs GPIO | Notes |
|
||||
|-------------|--------------|----------|------------|----------------------|
|
||||
| 1 | P1-01 | 3V3 VCC | | |
|
||||
| 2 | P1-02 | 5V VCC | | |
|
||||
| 3 | P1-03 | I2C SDA1 | 2 | I2C1 (/dev/i2c-1) |
|
||||
| 4 | P1-04 | 5V VCC | | |
|
||||
| 5 | P1-05 | I2C SCL1 | 3 | I2C1 (/dev/i2c-1) |
|
||||
| 6 | P1-06 | GND | | |
|
||||
| 7 | P1-07 | GPIO(4) | 4 | |
|
||||
| 8 | P1-08 | UART TX1 | 14 | UART1 (/dev/ttyS1) |
|
||||
| 9 | P1-09 | GND | | |
|
||||
| 10 | P1-10 | UART RX1 | 15 | UART1 (/dev/ttyS1) |
|
||||
| 11 | P1-11 | GPIO(17) | 17 | |
|
||||
| 12 | P1-12 | I2S CLK | 18 | I2S0 (PCM Audio) |
|
||||
| 13 | P1-13 | UART RX2 | 27 | UART2 (/dev/ttyS2) |
|
||||
| 14 | P1-14 | GND | | |
|
||||
| 15 | P1-15 | GPIO(22) | 22 | |
|
||||
| 16 | P1-16 | GPIO(23) | 23 | |
|
||||
| 17 | P1-17 | 3V3 VCC | | |
|
||||
| 18 | P1-18 | GPIO(24) | 24 | |
|
||||
| 19 | P1-19 | SPI MOSI | 10 | SPI2 (/dev/spidev2.x)|
|
||||
| 20 | P1-20 | GND | | |
|
||||
| 21 | P1-21 | SPI MISO | 9 | SPI2 (/dev/spidev2.x)|
|
||||
| 22 | P1-22 | UART TX2 | 25 | UART2 (/dev/ttyS2) |
|
||||
| 23 | P1-23 | SPI SCL | 11 | SPI2 (/dev/spidev2.x)|
|
||||
| 24 | P1-24 | SPI CS0 | 8 | SPI2 (/dev/spidev2.0)|
|
||||
| 25 | P1-25 | GND | | |
|
||||
| 26 | P1-26 | SPI CS1 | 7 | SPI2 (/dev/spidev2.1)|
|
||||
| 27 | P1-27 | I2C SDA0 | 0 | I2C0 (/dev/i2c-0) |
|
||||
| 28 | P1-28 | I2C SCL0 | 1 | I2C0 (/dev/i2c-0) |
|
||||
| 29 | P1-29 | GPIO(5) | 5 | |
|
||||
| 30 | P1-30 | GND | | |
|
||||
| 31 | P1-31 | GPIO(6) | 6 | |
|
||||
| 32 | P1-32 | PWM0 | 12 | PWM Chip 0 Channel 0 |
|
||||
| 33 | P1-33 | PWM1 | 13 | PWM Chip 1 Channel 0 |
|
||||
| 34 | P1-34 | GND | | |
|
||||
| 35 | P1-35 | I2S FRM | 19 | I2S0 (PCM Audio) |
|
||||
| 36 | P1-36 | GPIO(16) | 16 | |
|
||||
| 37 | P1-37 | GPIO(26) | 26 | |
|
||||
| 38 | P1-38 | I2S DIN | 20 | I2S0 (PCM Audio) |
|
||||
| 39 | P1-39 | GND | | |
|
||||
| 40 | P1-40 | I2S DOUT | 21 | I2S0 (PCM Audio) |
|
@@ -10,9 +10,14 @@ add_executable (mmap-io2 mmap-io2.c)
|
||||
add_executable (blink_onboard blink_onboard.c)
|
||||
add_executable (uart uart.c)
|
||||
add_executable (mraa-gpio mraa-gpio.c)
|
||||
add_executable (mraa-i2c mraa-i2c.c)
|
||||
add_executable (spi_max7219 spi_max7219.c)
|
||||
add_executable (iio_driver iio_driver.c)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/api)
|
||||
# FIXME Hack to access mraa internal types used by mraa-i2c
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/api/mraa)
|
||||
|
||||
target_link_libraries (hellomraa mraa)
|
||||
target_link_libraries (i2c_HMC5883L mraa m)
|
||||
@@ -26,12 +31,31 @@ target_link_libraries (mmap-io2 mraa)
|
||||
target_link_libraries (blink_onboard mraa)
|
||||
target_link_libraries (uart mraa)
|
||||
target_link_libraries (mraa-gpio mraa)
|
||||
target_link_libraries (mraa-i2c mraa)
|
||||
target_link_libraries (spi_max7219 mraa)
|
||||
target_link_libraries (iio_driver mraa)
|
||||
|
||||
if (ONEWIRE)
|
||||
add_executable (uart_ow uart_ow.c)
|
||||
target_link_libraries (uart_ow mraa)
|
||||
endif ()
|
||||
|
||||
if (FIRMATA)
|
||||
add_executable (firmata_curie_imu firmata_curie_imu.c)
|
||||
add_executable (i2c_firmata i2c_firmata.c)
|
||||
target_link_libraries (firmata_curie_imu mraa)
|
||||
target_link_libraries (i2c_firmata mraa)
|
||||
endif ()
|
||||
|
||||
add_subdirectory (c++)
|
||||
|
||||
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples/ DESTINATION share/mraa/examples)
|
||||
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples/ DESTINATION ${CMAKE_INSTALL_DATADIR}/mraa/examples)
|
||||
|
||||
if (INSTALLGPIOTOOL)
|
||||
if (INSTALLGPIOTOOL AND NOT INSTALLTOOLS)
|
||||
install (TARGETS mraa-gpio DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if (INSTALLTOOLS)
|
||||
install (TARGETS mraa-gpio DESTINATION bin)
|
||||
install (TARGETS mraa-i2c DESTINATION bin)
|
||||
endif()
|
||||
|
@@ -33,7 +33,7 @@ main(int argc, char** argv)
|
||||
{
|
||||
mraa_platform_t platform = mraa_get_platform_type();
|
||||
mraa_gpio_context gpio, gpio_in = NULL;
|
||||
char* board_name = mraa_get_platform_name();
|
||||
const char* board_name = mraa_get_platform_name();
|
||||
int ledstate = 0;
|
||||
|
||||
switch (platform) {
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mraa.hpp"
|
||||
@@ -58,10 +57,10 @@ main(int argc, char** argv)
|
||||
//! [Interesting]
|
||||
mraa::Gpio* gpio = new mraa::Gpio(iopin);
|
||||
if (gpio == NULL) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
return mraa::ERROR_UNSPECIFIED;
|
||||
}
|
||||
mraa_result_t response = gpio->dir(mraa::DIR_OUT);
|
||||
if (response != MRAA_SUCCESS) {
|
||||
mraa::Result response = gpio->dir(mraa::DIR_OUT);
|
||||
if (response != mraa::SUCCESS) {
|
||||
mraa::printError(response);
|
||||
return 1;
|
||||
}
|
||||
|
@@ -1,9 +1,13 @@
|
||||
enable_language(CXX)
|
||||
|
||||
add_executable (AioA0 AioA0.cpp)
|
||||
add_executable (blink-io-cpp Blink-IO.cpp)
|
||||
add_executable (Pwm3-cycle Pwm3-cycle.cpp)
|
||||
add_executable (I2c-compass I2c-compass.cpp)
|
||||
add_executable (Spi-pot Spi-pot.cpp)
|
||||
add_executable (Uart Uart-example.cpp)
|
||||
add_executable (Isr-pin6 Isr-pin6.cpp)
|
||||
add_executable (Iio-dummy Iio-dummy.cpp)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/api)
|
||||
|
||||
@@ -13,3 +17,10 @@ target_link_libraries (Pwm3-cycle mraa stdc++)
|
||||
target_link_libraries (I2c-compass mraa stdc++ m)
|
||||
target_link_libraries (Spi-pot mraa stdc++)
|
||||
target_link_libraries (Uart mraa stdc++)
|
||||
target_link_libraries (Isr-pin6 mraa stdc++)
|
||||
target_link_libraries (Iio-dummy mraa stdc++)
|
||||
|
||||
if (ONEWIRE)
|
||||
add_executable (UartOW UartOW.cpp)
|
||||
target_link_libraries (UartOW mraa stdc++)
|
||||
endif ()
|
||||
|
157
examples/c++/Iio-dummy.cpp
Normal file
157
examples/c++/Iio-dummy.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Author: Henry Bruce
|
||||
* Copyright (c) 2015 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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include "mraa/iio.hpp"
|
||||
|
||||
#define EXPECT_FAILURE 0
|
||||
#define EXPECT_SUCCESS 1
|
||||
|
||||
#define IIO_TRY(func) \
|
||||
{ \
|
||||
bool success = true; \
|
||||
try { \
|
||||
iio_device->func; \
|
||||
} catch (std::exception& e) { \
|
||||
success = false; \
|
||||
} \
|
||||
log_result(#func, "", true, success); \
|
||||
}
|
||||
|
||||
// Macro to run IIO method on attribute and log output
|
||||
#define IIO_RUN(func, attr, value, expect) \
|
||||
{ \
|
||||
std::string attr_name = attr; \
|
||||
bool success = true; \
|
||||
try { \
|
||||
iio_device->func(attr_name, value); \
|
||||
} catch (std::exception& e) { \
|
||||
success = false; \
|
||||
} \
|
||||
log_result(#func, attr_name, expect, success); \
|
||||
}
|
||||
|
||||
// Macro to run IIO method on attribute and check for expected result and log output
|
||||
#define IIO_TEST(func, attr, value, expect) \
|
||||
{ \
|
||||
std::string attr_name = attr; \
|
||||
bool success = false; \
|
||||
try { \
|
||||
success = fabs(iio_device->func(attr_name) - value) < FLT_EPSILON; \
|
||||
} catch (std::exception& e) { \
|
||||
success = false; \
|
||||
} \
|
||||
log_result(#func, attr_name, expect, success); \
|
||||
}
|
||||
|
||||
mraa::Iio* iio_device;
|
||||
int eventCount = 0;
|
||||
|
||||
// Log result of test. Note a "fail" (i.e. success is false) will be displayed as a pass if a fail was expected
|
||||
void log_result(std::string test_name, std::string attr_name, bool expect_success, bool success)
|
||||
{
|
||||
std::string result;
|
||||
if (expect_success)
|
||||
result = success ? "PASS" : "FAIL";
|
||||
else
|
||||
result = success ? "FAIL" : "PASS";
|
||||
if (attr_name.empty())
|
||||
fprintf(stdout, "%s: %s\n", test_name.c_str(), result.c_str());
|
||||
else
|
||||
fprintf(stdout, "%s(%s): %s\n", test_name.c_str(), attr_name.c_str(), result.c_str());
|
||||
}
|
||||
|
||||
// Generate iio_dummy driver event by writing a string to a specific sysfs node
|
||||
bool generate_event()
|
||||
{
|
||||
FILE *fp = fopen("/sys/bus/iio/devices/iio_evgen/poke_ev0", "w");
|
||||
if (fp == NULL)
|
||||
return false;
|
||||
fprintf(fp, "1\n");
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// IIO event handler that checks for event from dummy_iio_evgen driver
|
||||
class IioTestHandler : public mraa::IioHandler
|
||||
{
|
||||
protected:
|
||||
void onIioEvent(const mraa::IioEventData& eventData) {
|
||||
if (eventData.channelType == IIO_VOLTAGE && eventData.direction == IIO_EV_DIR_RISING && eventData.type == IIO_EV_TYPE_THRESH)
|
||||
eventCount++;
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
IioTestHandler testHandler;
|
||||
std::string deviceName;
|
||||
try {
|
||||
mraa::Iio* iio_device0 = new mraa::Iio(0);
|
||||
std::cout << "IIO device 0 found by id." << std::endl;
|
||||
deviceName = iio_device0->getDeviceName();
|
||||
delete iio_device0;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "IIO device 0 not found." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
mraa::Iio* iio_device1 = new mraa::Iio(1);
|
||||
delete iio_device1;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "IIO device 1 not found. This is expected behavior." << std::endl;
|
||||
}
|
||||
|
||||
try {
|
||||
iio_device = new mraa::Iio(deviceName);
|
||||
std::cout << "IIO device 0 found by name." << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "IIO device 0 not found." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Using IIO device0. Name is " << iio_device->getDeviceName() << std::endl;
|
||||
IIO_RUN(writeFloat, "in_accel_x_raw", 100, EXPECT_FAILURE);
|
||||
IIO_RUN(writeFloat, "in_voltage0_scale", 100, EXPECT_FAILURE);
|
||||
IIO_RUN(writeInt, "out_voltage0_raw", 100, EXPECT_SUCCESS);
|
||||
IIO_TEST(readInt, "in_accel_x_raw", 34, EXPECT_SUCCESS);
|
||||
IIO_TEST(readFloat, "in_voltage0_scale", 0.001333, EXPECT_SUCCESS);
|
||||
IIO_RUN(writeInt, "events/in_voltage0_thresh_rising_en", 1, EXPECT_SUCCESS);
|
||||
IIO_TRY(registerEventHandler(&testHandler));
|
||||
eventCount = 0;
|
||||
generate_event();
|
||||
usleep(500000);
|
||||
log_result("eventReceived", "", (eventCount == 1), true);
|
||||
|
||||
delete iio_device;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
57
examples/c++/Isr-pin6.cpp
Normal file
57
examples/c++/Isr-pin6.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll
|
||||
* Copyright (c) 2015 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 <unistd.h>
|
||||
|
||||
#include "mraa.hpp"
|
||||
|
||||
static volatile int counter = 0;
|
||||
static volatile int oldcounter = 0;
|
||||
|
||||
void
|
||||
interrupt(void* args)
|
||||
{
|
||||
++counter;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
mraa::Gpio* x = new mraa::Gpio(6);
|
||||
|
||||
x->dir(mraa::DIR_IN);
|
||||
|
||||
x->isr(mraa::EDGE_BOTH, &interrupt, NULL);
|
||||
|
||||
for (;;) {
|
||||
if (counter != oldcounter) {
|
||||
fprintf(stdout, "timeout counter == %d\n", counter);
|
||||
oldcounter = counter;
|
||||
}
|
||||
// got to relieve our poor CPU!
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@@ -66,7 +66,7 @@ main()
|
||||
}
|
||||
for (i = 130; i > 90; i--) {
|
||||
data[1] = i;
|
||||
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
|
||||
if (spi->transfer(data, rxBuf, 2) == mraa::SUCCESS) {
|
||||
printf("Writing -%i", i);
|
||||
printf("RECIVED-%i-%i\n", rxBuf[0], rxBuf[1]);
|
||||
}
|
||||
@@ -76,5 +76,5 @@ main()
|
||||
delete spi;
|
||||
//! [Interesting]
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
@@ -49,15 +49,15 @@ main()
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
if (dev->setBaudRate(115200) != MRAA_SUCCESS) {
|
||||
if (dev->setBaudRate(115200) != mraa::SUCCESS) {
|
||||
std::cout << "Error setting parity on UART" << std::endl;
|
||||
}
|
||||
|
||||
if (dev->setMode(8, MRAA_UART_PARITY_NONE, 1) != MRAA_SUCCESS) {
|
||||
if (dev->setMode(8, mraa::UART_PARITY_NONE, 1) != mraa::SUCCESS) {
|
||||
std::cout << "Error setting parity on UART" << std::endl;
|
||||
}
|
||||
|
||||
if (dev->setFlowcontrol(false, false) != MRAA_SUCCESS) {
|
||||
if (dev->setFlowcontrol(false, false) != mraa::SUCCESS) {
|
||||
std::cout << "Error setting flow control UART" << std::endl;
|
||||
}
|
||||
|
||||
@@ -66,5 +66,5 @@ main()
|
||||
|
||||
delete dev;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
82
examples/c++/UartOW.cpp
Normal file
82
examples/c++/UartOW.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "stdio.h"
|
||||
#include "iostream"
|
||||
//! [Interesting]
|
||||
#include "uart_ow.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa::UartOW* uart = new mraa::UartOW(0);
|
||||
|
||||
// Reset the ow bus and see if anything is present
|
||||
mraa::Result rv;
|
||||
|
||||
if ((rv = uart->reset()) == mraa::SUCCESS) {
|
||||
cout << "Reset succeeded, device(s) detected!" << endl;
|
||||
} else {
|
||||
cout << "Reset failed, returned " << int(rv) << ". No devices on bus?" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Looking for devices..." << endl;
|
||||
;
|
||||
|
||||
uint8_t count = 0;
|
||||
// start the search from scratch
|
||||
string id = uart->search(true);
|
||||
|
||||
if (id.empty()) {
|
||||
cout << "No devices detected." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!id.empty()) {
|
||||
// hack so we don't need to cast each element of the romcode
|
||||
// for printf purposes
|
||||
uint8_t* ptr = (uint8_t*) id.c_str();
|
||||
|
||||
// The first byte (0) is the device type (family) code.
|
||||
// The last byte (7) is the rom code CRC value. The
|
||||
// intervening bytes are the unique 48 bit device ID.
|
||||
|
||||
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, ptr[0],
|
||||
ptr[6], ptr[5], ptr[4], ptr[3], ptr[2], ptr[1], ptr[7]);
|
||||
count++;
|
||||
|
||||
// continue the search with start argument set to false
|
||||
id = uart->search(false);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete uart;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
92
examples/firmata_curie_imu.c
Normal file
92
examples/firmata_curie_imu.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll
|
||||
* 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 <unistd.h>
|
||||
|
||||
#include "mraa.h"
|
||||
#include "mraa/firmata.h"
|
||||
|
||||
#define FIRMATA_START_SYSEX 0xF0
|
||||
#define FIRMATA_END_SYSEX 0xF7
|
||||
#define FIRMATA_CURIE_IMU 0x11
|
||||
#define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
|
||||
|
||||
void
|
||||
interrupt(uint8_t* buf, int length)
|
||||
{
|
||||
printf("reg read returned: %d, with buffer size %d\n", ((buf[6] & 0x7f) | ((buf[7] & 0x7f) << 7)), length);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
mraa_init();
|
||||
//! [Interesting]
|
||||
|
||||
/**
|
||||
* This example reads from the FirmataCurieIMU plugin
|
||||
*/
|
||||
|
||||
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||
mraa_firmata_context firm = mraa_firmata_init(FIRMATA_CURIE_IMU);
|
||||
if (firm == NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mraa_firmata_response(firm, interrupt);
|
||||
|
||||
uint8_t* buffer = calloc(4, 0);
|
||||
if (buffer == NULL) {
|
||||
free(firm);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_CURIE_IMU;
|
||||
buffer[2] = FIRMATA_CURIE_IMU_READ_ACCEL;
|
||||
buffer[3] = FIRMATA_END_SYSEX;
|
||||
|
||||
mraa_firmata_write_sysex(firm, buffer, 4);
|
||||
|
||||
sleep(1);
|
||||
|
||||
// stop the isr and set it again
|
||||
mraa_firmata_response_stop(firm);
|
||||
mraa_firmata_response(firm, interrupt);
|
||||
mraa_firmata_write_sysex(firm, buffer, 4);
|
||||
|
||||
sleep(1);
|
||||
|
||||
// close everything and try again
|
||||
mraa_firmata_close(firm);
|
||||
firm = mraa_firmata_init(FIRMATA_CURIE_IMU);
|
||||
mraa_firmata_response(firm, interrupt);
|
||||
mraa_firmata_write_sysex(firm, buffer, 4);
|
||||
|
||||
sleep(10);
|
||||
|
||||
mraa_firmata_close(firm);
|
||||
//! [Interesting]
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@@ -31,18 +31,9 @@
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
char* board_name = mraa_get_platform_name();
|
||||
int i2c_bus, i, i2c_adapter;
|
||||
|
||||
const char* board_name = mraa_get_platform_name();
|
||||
fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);
|
||||
|
||||
i2c_bus = mraa_get_i2c_bus_count();
|
||||
|
||||
for (i = 0; i < i2c_bus; i++) {
|
||||
i2c_adapter = mraa_get_i2c_bus_id(i);
|
||||
fprintf(stdout, "I2C[%d] adapter=%d\n", i, i2c_adapter);
|
||||
}
|
||||
|
||||
mraa_deinit();
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
|
64
examples/i2c_firmata.c
Normal file
64
examples/i2c_firmata.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_init();
|
||||
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||
|
||||
mraa_i2c_context i2c;
|
||||
i2c = mraa_i2c_init(0 + 512);
|
||||
#if 0
|
||||
mraa_i2c_address(i2c, 0x62);
|
||||
|
||||
#if 1
|
||||
uint8_t rx_tx_buf[2];
|
||||
rx_tx_buf[0] = 0x0;
|
||||
rx_tx_buf[1] = 0x0;
|
||||
mraa_i2c_write(i2c, rx_tx_buf, 2);
|
||||
#endif
|
||||
//mraa_i2c_write_byte_data(i2c, 0x0, 0x0);
|
||||
mraa_i2c_write_byte_data(i2c, 0x0, 0x1);
|
||||
|
||||
mraa_i2c_write_byte_data(i2c, 0xFF, 0x08);
|
||||
mraa_i2c_write_byte_data(i2c, 0x00, 0x04);
|
||||
mraa_i2c_write_byte_data(i2c, 0xA0, 0x02);
|
||||
#else
|
||||
mraa_i2c_address(i2c, 0x77);
|
||||
int res = mraa_i2c_read_byte_data(i2c, 0xd0);
|
||||
printf("res is 0x%x\n", res);
|
||||
|
||||
uint8_t data[2];
|
||||
mraa_i2c_write_byte(i2c, 0x77);
|
||||
mraa_i2c_read(i2c, data, 1);
|
||||
|
||||
res = mraa_i2c_read_word_data(i2c, 0xAA); // BMP085_CAL_AC1
|
||||
printf("res is %d\n", res);
|
||||
#endif
|
||||
sleep(10);
|
||||
|
||||
}
|
145
examples/iio_driver.c
Normal file
145
examples/iio_driver.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll
|
||||
* Copyright (c) 2015 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 <unistd.h>
|
||||
#include "mraa/iio.h"
|
||||
|
||||
static void
|
||||
printword(uint16_t input, mraa_iio_channel* chan)
|
||||
{
|
||||
int16_t res;
|
||||
|
||||
if (!chan->lendian) {
|
||||
input = be16toh(input);
|
||||
} else {
|
||||
input = le16toh(input);
|
||||
}
|
||||
|
||||
input >>= chan->shift;
|
||||
input &= chan->mask;
|
||||
if (chan->signedd) {
|
||||
res = (int16_t)(input << (16 - chan->bits_used)) >> (16 - chan->bits_used);
|
||||
} else {
|
||||
res = input;
|
||||
}
|
||||
printf(" value = %05f\n", (float) res);
|
||||
}
|
||||
|
||||
mraa_iio_context iio_device0;
|
||||
mraa_iio_context iio_device6;
|
||||
|
||||
void
|
||||
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++) {
|
||||
if (channels[i].enabled) {
|
||||
printf("channel %d - bytes %d\n", channels[i].index, channels[i].bytes);
|
||||
switch (channels[i].bytes) {
|
||||
case 2:
|
||||
printword(*(uint16_t*) (data + channels[i].location), &channels[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
event_interrupt(struct iio_event_data* data)
|
||||
{
|
||||
int chan_type;
|
||||
int modifier;
|
||||
int type;
|
||||
int direction;
|
||||
int channel;
|
||||
int channel2;
|
||||
int different;
|
||||
mraa_iio_event_extract_event(data, &chan_type, &modifier, &type, &direction, &channel, &channel2, &different);
|
||||
|
||||
printf("event time %lld id %lld extracted chan_type %d modifier %d type %d direction %d "
|
||||
"channel %d channel2 %d different %d\n",
|
||||
data->timestamp, data->id, chan_type, modifier, type, direction, channel, channel2, different);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
//! [Interesting]
|
||||
iio_device0 = mraa_iio_init(0);
|
||||
if (iio_device0 == NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
float iio_float;
|
||||
int iio_int;
|
||||
mraa_result_t ret;
|
||||
|
||||
ret = mraa_iio_write_float(iio_device0, "in_accel_scale", 0.019163);
|
||||
if (ret == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "IIO write success\n");
|
||||
}
|
||||
|
||||
ret = mraa_iio_read_float(iio_device0, "in_accel_scale", &iio_float);
|
||||
if (ret == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "IIO read %f\n", iio_float);
|
||||
}
|
||||
|
||||
ret = mraa_iio_write_int(iio_device0, "scan_elements/in_accel_x_en", 1);
|
||||
if (ret == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "IIO write success\n");
|
||||
}
|
||||
|
||||
ret = mraa_iio_read_int(iio_device0, "scan_elements/in_accel_x_en", &iio_int);
|
||||
if (ret == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "IIO read %d\n", iio_int);
|
||||
}
|
||||
|
||||
if (mraa_iio_trigger_buffer(iio_device0, interrupt, NULL) == MRAA_SUCCESS) {
|
||||
sleep(100);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
struct iio_event_data event;
|
||||
iio_device6 = mraa_iio_init(6);
|
||||
if (iio_device6 == NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mraa_iio_write_int(iio_device6, "events/in_proximity2_thresh_either_en", 1);
|
||||
|
||||
|
||||
// Blocking until event fired
|
||||
if (mraa_iio_event_poll(iio_device6, &event) == MRAA_SUCCESS) {
|
||||
event_interrupt(&event); //just to show data
|
||||
}
|
||||
|
||||
if (mraa_iio_event_setup_callback(iio_device6, event_interrupt, NULL) == MRAA_SUCCESS) {
|
||||
sleep(100);
|
||||
return EXIT_SUCCESS;
|
||||
}*/
|
||||
|
||||
//! [Interesting]
|
||||
return EXIT_FAILURE;
|
||||
}
|
56
examples/java/AioA0.java
Normal file
56
examples/java/AioA0.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: Nandkishor Sonar
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
|
||||
//! [Interesting]
|
||||
import mraa.Aio;
|
||||
|
||||
public class AioA0 {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Aio a0 = new Aio(0);
|
||||
|
||||
while (true) {
|
||||
int adc_value = a0.read();
|
||||
float adc_value_float = a0.readFloat();
|
||||
System.out.println(String.format("ADC A0 read %X - %d", adc_value, adc_value));
|
||||
System.out.println(String.format("ADC A0 read %.5f", adc_value_float));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
72
examples/java/BlinkIO.java
Normal file
72
examples/java/BlinkIO.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.Result;
|
||||
import mraa.mraa;
|
||||
|
||||
public class BlinkIO {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
final static int DEFAULT_IOPIN = 8;
|
||||
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
int iopin = DEFAULT_IOPIN;
|
||||
if (argv.length == 0) {
|
||||
System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN);
|
||||
} else {
|
||||
iopin = Integer.valueOf(argv[0]);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
Gpio gpio = new Gpio(iopin);
|
||||
Result result = gpio.dir(Dir.DIR_OUT);
|
||||
if (result != Result.SUCCESS) {
|
||||
mraa.printError(result);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
gpio.write(1);
|
||||
Thread.sleep(1000);
|
||||
gpio.write(0);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
@@ -1,3 +1,8 @@
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.Platform;
|
||||
import mraa.mraa;
|
||||
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
@@ -25,52 +30,52 @@
|
||||
*/
|
||||
|
||||
public class BlinkOnboard {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
mraa.mraa_platform_t platform = mraa.mraa.getPlatformType();
|
||||
mraa.Gpio gpio, gpio_in;
|
||||
if (platform == mraa.mraa_platform_t.INTEL_GALILEO_GEN1) {
|
||||
gpio = new mraa.Gpio(3);
|
||||
} else if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) {
|
||||
gpio = new mraa.Gpio(21);
|
||||
} else {
|
||||
gpio = new mraa.Gpio(13);
|
||||
}
|
||||
System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n",
|
||||
mraa.mraa.getVersion(), platform.toString());
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
Platform platform = mraa.getPlatformType();
|
||||
Gpio gpio, gpio_in;
|
||||
if (platform == Platform.INTEL_GALILEO_GEN1) {
|
||||
gpio = new Gpio(3);
|
||||
} else if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
|
||||
gpio = new Gpio(21);
|
||||
} else {
|
||||
gpio = new Gpio(13);
|
||||
}
|
||||
System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n",
|
||||
mraa.getVersion(), platform.toString());
|
||||
|
||||
gpio.dir(mraa.Dir.DIR_OUT);
|
||||
// on platforms with physical button use gpio_in
|
||||
if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) {
|
||||
gpio_in = new mraa.Gpio(14);
|
||||
gpio_in.dir(mraa.Dir.DIR_IN);
|
||||
System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!");
|
||||
} else {
|
||||
gpio_in = null;
|
||||
}
|
||||
gpio.dir(Dir.DIR_OUT);
|
||||
// on platforms with physical button use gpio_in
|
||||
if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
|
||||
gpio_in = new Gpio(14);
|
||||
gpio_in.dir(Dir.DIR_IN);
|
||||
System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!");
|
||||
} else {
|
||||
gpio_in = null;
|
||||
}
|
||||
|
||||
boolean state = false;
|
||||
while (true) {
|
||||
if (gpio_in != null && gpio_in.read() == 0) {
|
||||
return;
|
||||
}
|
||||
if (state) {
|
||||
state = false;
|
||||
gpio.write(1);
|
||||
} else {
|
||||
state = true;
|
||||
gpio.write(0);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
boolean state = false;
|
||||
while (true) {
|
||||
if (gpio_in != null && gpio_in.read() == 0) {
|
||||
return;
|
||||
}
|
||||
if (state) {
|
||||
state = false;
|
||||
gpio.write(1);
|
||||
} else {
|
||||
state = true;
|
||||
gpio.write(0);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,31 +24,34 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class CyclePwm3 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
mraa.mraa.init();
|
||||
mraa.Pwm pwm = new mraa.Pwm(3);
|
||||
pwm.period_us(200);
|
||||
pwm.enable(true);
|
||||
import mraa.Pwm;
|
||||
|
||||
float value = 0;
|
||||
while (true) {
|
||||
value += 0.01;
|
||||
pwm.write(value);
|
||||
Thread.sleep(50);
|
||||
if (value >= 1) {
|
||||
value = 0;
|
||||
}
|
||||
public class CyclePwm3 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
Pwm pwm = new mraa.Pwm(3);
|
||||
pwm.period_us(200);
|
||||
pwm.enable(true);
|
||||
|
||||
float value = 0;
|
||||
while (true) {
|
||||
value += 0.01;
|
||||
pwm.write(value);
|
||||
Thread.sleep(50);
|
||||
if (value >= 1) {
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Author: Alexander Komarov <alexander.komarov@intel.com>
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -22,6 +24,9 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//! [Interesting]
|
||||
import mraa.mraa;
|
||||
|
||||
public class Example {
|
||||
static {
|
||||
try {
|
||||
@@ -34,8 +39,11 @@ public class Example {
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) {
|
||||
mraa.mraa.init();
|
||||
System.out.println(mraa.mraa.getVersion());
|
||||
String board = mraa.getPlatformName();
|
||||
String version = mraa.getVersion();
|
||||
System.out.println("hello mraa");
|
||||
System.out.println(String.format("Version: %s", version));
|
||||
System.out.println(String.format("Running on %s", board));
|
||||
};
|
||||
}
|
||||
;
|
||||
//! [Interesting]
|
||||
|
62
examples/java/FTDITest.java
Normal file
62
examples/java/FTDITest.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Author: Petre Eftime <petre.p.eftime@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.
|
||||
*/
|
||||
|
||||
import mraa.*;
|
||||
|
||||
public class FTDITest {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
String board = mraa.getPlatformName();
|
||||
String version = mraa.getVersion();
|
||||
|
||||
System.out.println(String.format("Version: %s", version));
|
||||
System.out.println(String.format("Running on %s", board));
|
||||
|
||||
if (mraa.hasSubPlatform()) {
|
||||
System.out.println("Subplatform detected");
|
||||
|
||||
/* Print when button is pressed */
|
||||
Gpio button = new Gpio(515);
|
||||
button.dir(Dir.DIR_IN);
|
||||
button.isr(Edge.EDGE_FALLING, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Button pressed");
|
||||
}
|
||||
});
|
||||
|
||||
/* Blink FTDI board LED */
|
||||
Gpio led = new Gpio(514);
|
||||
led.dir(Dir.DIR_OUT);
|
||||
for (int i = 0;; i = (i + 1) % 2) {
|
||||
led.write(i);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Subplatform not detected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
60
examples/java/GpioMmapped.java
Normal file
60
examples/java/GpioMmapped.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
import mraa.Gpio;
|
||||
import mraa.mraa;
|
||||
|
||||
public class GpioMmapped {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
String board = mraa.getPlatformName();
|
||||
String version = mraa.getVersion();
|
||||
System.out.println("hello mraa");
|
||||
System.out.println(String.format("Version: %s", version));
|
||||
|
||||
Gpio gpio = new Gpio(1);
|
||||
|
||||
gpio.useMmap(true);
|
||||
|
||||
while (true) {
|
||||
gpio.write(1);
|
||||
Thread.sleep(50);
|
||||
gpio.write(0);
|
||||
Thread.sleep(50);
|
||||
}
|
||||
//! [Interesting]
|
||||
};
|
||||
}
|
@@ -24,21 +24,32 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.mraa;
|
||||
|
||||
public class GpioRead6 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
System.out.println(String.format("MRAA Version: %s\nStarting Read on IO6\n", mraa.getVersion()));
|
||||
//! [Interesting]
|
||||
Gpio gpio = new Gpio(6);
|
||||
|
||||
gpio.dir(Dir.DIR_IN);
|
||||
|
||||
while (true) {
|
||||
System.out.format("Gpio is %d\n", gpio.read());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) {
|
||||
mraa.mraa.init();
|
||||
mraa.Gpio gpio_in = new mraa.Gpio(6);
|
||||
gpio_in.dir(mraa.Dir.DIR_IN);
|
||||
System.out.format("Gpio is %d\n", gpio_in.read());
|
||||
}
|
||||
}
|
||||
|
73
examples/java/HelloEdison.java
Normal file
73
examples/java/HelloEdison.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
//! [Interesting]
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.IntelEdison;
|
||||
import mraa.mraa;
|
||||
import mraa.Platform;
|
||||
import mraa.Result;
|
||||
|
||||
public class HelloEdison {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) {
|
||||
Platform platform = mraa.getPlatformType();
|
||||
|
||||
if (platform != Platform.INTEL_EDISON_FAB_C) {
|
||||
System.err.println("Error: This program can only be run on edison");
|
||||
System.exit(Result.ERROR_INVALID_PLATFORM.swigValue());
|
||||
}
|
||||
|
||||
/*
|
||||
* MRAA_INTEL_EDISON_GP182 == 0, so this will initialise pin0 on arduino,
|
||||
* which is hardware GPIO 130 and not 182
|
||||
* We set the owner to false here, this makes sure that we do not close the
|
||||
* gpio from sysfs in mraa_gpio_close meaning it will stay as an output and
|
||||
* we will not always transition from 0->1 as gpio182 as output has the
|
||||
* default position of '0'. Note that the value could change as a result of
|
||||
* a mraa_gpio_dir however meaning we always go from 0->1 or 1->0
|
||||
*/
|
||||
Gpio gpio182 = new Gpio(IntelEdison.INTEL_EDISON_GP182.swigValue(), false);
|
||||
gpio182.dir(Dir.DIR_OUT);
|
||||
|
||||
int val = gpio182.read();
|
||||
|
||||
System.out.println(String.format("GPIO%d (mraa pin %d) was: %d, will set to %d\n", 182,
|
||||
gpio182.getPin(), val, val == 0 ? 1 : 0));
|
||||
|
||||
gpio182.write(val == 0 ? 1 : 0);
|
||||
};
|
||||
}
|
||||
//! [Interesting]
|
135
examples/java/I2cCompass.java
Normal file
135
examples/java/I2cCompass.java
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
import mraa.I2c;
|
||||
|
||||
public class I2cCompass {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
final static byte MAX_BUFFER_LENGTH = 6;
|
||||
final static byte CONF_BUFFER_LENGTH = 2;
|
||||
final static short HMC5883L_I2C_ADDR = 0x1E;
|
||||
|
||||
// configuration registers
|
||||
final static byte HMC5883L_CONF_REG_A = 0x00;
|
||||
final static byte HMC5883L_CONF_REG_B = 0x01;
|
||||
|
||||
// mode register
|
||||
final static byte HMC5883L_MODE_REG = 0x02;
|
||||
|
||||
// data register
|
||||
final static byte HMC5883L_X_MSB_REG = 0;
|
||||
final static byte HMC5883L_X_LSB_REG = 1;
|
||||
final static byte HMC5883L_Z_MSB_REG = 2;
|
||||
final static byte HMC5883L_Z_LSB_REG = 3;
|
||||
final static byte HMC5883L_Y_MSB_REG = 4;
|
||||
final static byte HMC5883L_Y_LSB_REG = 5;
|
||||
final static byte DATA_REG_SIZE = 6;
|
||||
|
||||
// status register
|
||||
final static byte HMC5883L_STATUS_REG = 0x09;
|
||||
|
||||
// ID registers
|
||||
final static byte HMC5883L_ID_A_REG = 0x0A;
|
||||
final static byte HMC5883L_ID_B_REG = 0x0B;
|
||||
final static byte HMC5883L_ID_C_REG = 0x0C;
|
||||
|
||||
final static byte HMC5883L_CONT_MODE = 0x00;
|
||||
final static byte HMC5883L_DATA_REG = 0x03;
|
||||
|
||||
// scales
|
||||
final static byte GA_0_88_REG = ((byte) (0x00 << 5));
|
||||
final static byte GA_1_3_REG = ((byte) (0x01 << 5));
|
||||
final static byte GA_1_9_REG = ((byte) (0x02 << 5));
|
||||
final static byte GA_2_5_REG = ((byte) (0x03 << 5));
|
||||
final static byte GA_4_0_REG = ((byte) (0x04 << 5));
|
||||
final static byte GA_4_7_REG = ((byte) (0x05 << 5));
|
||||
final static byte GA_5_6_REG = ((byte) (0x06 << 5));
|
||||
final static byte GA_8_1_REG = ((byte) (0x07 << 5));
|
||||
|
||||
// digital resolutions
|
||||
final static float SCALE_0_73_MG = 0.73f;
|
||||
final static float SCALE_0_92_MG = 0.92f;
|
||||
final static float SCALE_1_22_MG = 1.22f;
|
||||
final static float SCALE_1_52_MG = 1.52f;
|
||||
final static float SCALE_2_27_MG = 2.27f;
|
||||
final static float SCALE_2_56_MG = 2.56f;
|
||||
final static float SCALE_3_03_MG = 3.03f;
|
||||
final static float SCALE_4_35_MG = 4.35f;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
float direction = 0;
|
||||
int x, y, z;
|
||||
byte[] rx_tx_buf = new byte[MAX_BUFFER_LENGTH];
|
||||
byte[] conf_buf = new byte[CONF_BUFFER_LENGTH];
|
||||
|
||||
//! [Interesting]
|
||||
I2c i2c = new I2c(0);
|
||||
|
||||
i2c.address(HMC5883L_I2C_ADDR);
|
||||
conf_buf[0] = HMC5883L_CONF_REG_B;
|
||||
conf_buf[1] = GA_1_3_REG;
|
||||
i2c.write(conf_buf);
|
||||
//! [Interesting]
|
||||
|
||||
i2c.address(HMC5883L_I2C_ADDR);
|
||||
conf_buf[0] = HMC5883L_MODE_REG;
|
||||
conf_buf[1] = HMC5883L_CONT_MODE;
|
||||
i2c.write(conf_buf);
|
||||
|
||||
while (true) {
|
||||
i2c.address(HMC5883L_I2C_ADDR);
|
||||
i2c.writeByte(HMC5883L_DATA_REG);
|
||||
|
||||
i2c.address(HMC5883L_I2C_ADDR);
|
||||
i2c.read(rx_tx_buf);
|
||||
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8) | rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Z_LSB_REG];
|
||||
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
direction = (float) Math.atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG);
|
||||
|
||||
if (direction < 0)
|
||||
direction += 2 * Math.PI;
|
||||
|
||||
System.out.println(String.format("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
|
||||
z * SCALE_0_92_MG));
|
||||
System.out.println(String.format("Heading : %f\n", direction * 180 / Math.PI));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,33 +22,64 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import mraa.Dir;
|
||||
import mraa.Edge;
|
||||
import mraa.Gpio;
|
||||
|
||||
public class Isr {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) {
|
||||
mraa.mraa.init();
|
||||
|
||||
mraa.Gpio gpio = new mraa.Gpio(7);
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
int pin = 6;
|
||||
if (argv.length == 1) {
|
||||
try {
|
||||
pin = Integer.parseInt(argv[0]);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
|
||||
Gpio gpio = null;
|
||||
try {
|
||||
gpio = new Gpio(pin);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
return;
|
||||
}
|
||||
System.out.println("Starting ISR for pin " + Integer.toString(pin) + ". Press ENTER to stop");
|
||||
Runnable callback = new JavaCallback(gpio);
|
||||
gpio.isr(Edge.EDGE_RISING, callback);
|
||||
try {
|
||||
String input = console.readLine();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
gpio.isrExit();
|
||||
}
|
||||
|
||||
mraa.IsrCallback callback = new JavaCallback();
|
||||
|
||||
gpio.isr(mraa.Edge.EDGE_RISING, callback, null);
|
||||
while (true)
|
||||
;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
class JavaCallback extends mraa.IsrCallback {
|
||||
public JavaCallback() { super(); }
|
||||
class JavaCallback implements Runnable {
|
||||
private Gpio gpio;
|
||||
|
||||
public void run() { System.out.println("JavaCallback.run()"); }
|
||||
public JavaCallback(Gpio gpio) {
|
||||
this.gpio = gpio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String pin = Integer.toString(gpio.getPin(true));
|
||||
String level = Integer.toString(gpio.read());
|
||||
System.out.println("Pin " + pin + " = " + level);
|
||||
}
|
||||
}
|
||||
|
93
examples/java/SpiMAX7219.java
Normal file
93
examples/java/SpiMAX7219.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Author: Michael Ring <mail@michael-ring.org>
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import mraa.Result;
|
||||
import mraa.Spi;
|
||||
|
||||
public class SpiMAX7219 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
Spi spi = new Spi(1);
|
||||
|
||||
spi.frequency(400000);
|
||||
spi.lsbmode(false);
|
||||
|
||||
if(spi.bitPerWord(16) != Result.SUCCESS) {
|
||||
System.err.println("Could not set SPI Device to 16Bit mode, exit...");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
spi.write_word(0x0900); //Do not decode bits
|
||||
spi.write_word(0x0a05); // Brightness of LEDs
|
||||
spi.write_word(0x0b07); // Show all Scan Lines
|
||||
spi.write_word(0x0c01); // Display on
|
||||
spi.write_word(0x0f00); // Testmode off
|
||||
|
||||
short dataAA55[] = { 0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855 };
|
||||
ByteBuffer buf = ByteBuffer.allocate(dataAA55.length * 2);
|
||||
for (int i = 0; i < dataAA55.length; i++)
|
||||
buf.putShort(dataAA55[i]);
|
||||
|
||||
spi.write(buf.array());
|
||||
Thread.sleep(2000);
|
||||
|
||||
short data55AA[] = { 0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa };
|
||||
buf = ByteBuffer.allocate(data55AA.length * 2);
|
||||
for (int i = 0; i < data55AA.length; i++)
|
||||
buf.putShort(data55AA[i]);
|
||||
|
||||
spi.write(buf.array());
|
||||
Thread.sleep(2000);
|
||||
|
||||
short data[] = { 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800 };
|
||||
buf = ByteBuffer.allocate(data.length * 2);
|
||||
for (int i = 0; i < data.length; i++)
|
||||
buf.putShort(data[i]);
|
||||
|
||||
spi.write(buf.array());
|
||||
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
spi.write_word((i << 8) + (1 << j));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
spi.write_word(i << 8);
|
||||
}
|
||||
//! [Interesting]
|
||||
};
|
||||
}
|
64
examples/java/SpiMCP4261.java
Normal file
64
examples/java/SpiMCP4261.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Author: Alexander Komarov <alexander.komarov@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
import mraa.Spi;
|
||||
|
||||
public class SpiMCP4261 {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
Spi spi = new Spi(0);
|
||||
|
||||
System.out.println("Hello, SPI initialised");
|
||||
byte data[] = {0x00, 100};
|
||||
while (true) {
|
||||
for (int i = 90; i < 130; i++) {
|
||||
data[1] = (byte) i;
|
||||
byte[] recv = spi.write(data);
|
||||
System.out.println(String.format("Writing - %d", i));
|
||||
System.out.println(String.format("Received - %d - %d", recv[0], recv[1]));
|
||||
Thread.sleep(100);
|
||||
}
|
||||
for (int i = 130; i > 90; i--) {
|
||||
data[1] = (byte) i;
|
||||
byte[] recv = spi.write(data);
|
||||
System.out.println(String.format("Writing - %d", i));
|
||||
System.out.println(String.format("Received - %d - %d", recv[0], recv[1]));
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
};
|
||||
}
|
56
examples/java/UartExample.java
Normal file
56
examples/java/UartExample.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2014, 2015 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.
|
||||
*/
|
||||
|
||||
|
||||
import mraa.Result;
|
||||
import mraa.Uart;
|
||||
import mraa.UartParity;
|
||||
|
||||
public class UartExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//! [Interesting]
|
||||
Uart uart = new Uart(0);
|
||||
|
||||
if (uart.setBaudRate(115200) != Result.SUCCESS) {
|
||||
System.err.println("Error setting baud rate");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (uart.setMode(8, UartParity.UART_PARITY_NONE, 1) != Result.SUCCESS) {
|
||||
System.err.println("Error setting mode");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (uart.setFlowcontrol(false, false) != Result.SUCCESS) {
|
||||
System.err.println("Error setting flow control");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
uart.writeStr("Hello monkeys");
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
@@ -29,11 +29,12 @@ var myLed = new m.Gpio(13); //LED hooked up to digital pin 13 (or built in pin o
|
||||
myLed.dir(m.DIR_OUT); //set the gpio direction to output
|
||||
var ledState = true; //Boolean to hold the state of Led
|
||||
|
||||
periodicActivity(); //call the periodicActivity function
|
||||
|
||||
function periodicActivity()
|
||||
{
|
||||
myLed.write(ledState?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low)
|
||||
ledState = !ledState; //invert the ledState
|
||||
setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)
|
||||
}
|
||||
|
||||
periodicActivity(); //call the periodicActivity function
|
||||
|
||||
|
@@ -26,30 +26,27 @@
|
||||
|
||||
var m = require('mraa'); //require mraa
|
||||
|
||||
// helper function to go from hex val to dec
|
||||
function char(x) { return parseInt(x, 16); }
|
||||
|
||||
x = new m.I2c(0)
|
||||
x.address(0x77)
|
||||
|
||||
// initialise device
|
||||
if (x.readReg(char('0xd0')) != char('0x55')) {
|
||||
if (x.readReg(0xd0) != 0x55) {
|
||||
console.log("error");
|
||||
}
|
||||
|
||||
// we want to read temperature so write 0x2e into control reg
|
||||
x.writeReg(char('0xf4'), char('0x2e'))
|
||||
x.writeReg(0xf4, 0x2e)
|
||||
|
||||
// read a 16bit reg, obviously it's uncalibrated so mostly a useless value :)
|
||||
console.log(x.readWordReg(char('0xf6')))
|
||||
console.log(x.readWordReg(0xf6))
|
||||
|
||||
// and we can do the same thing with the read()/write() calls if we wished
|
||||
// thought I'd really not recommend it!
|
||||
buf = new Buffer(2)
|
||||
buf[0] = char('0xf4')
|
||||
buf[1] = char('0x2e')
|
||||
buf[0] = 0xf4
|
||||
buf[1] = 0x2e
|
||||
console.log(buf.toString('hex'))
|
||||
x.write(buf)
|
||||
|
||||
x.writeByte(char('0xf6'))
|
||||
x.writeByte(0xf6)
|
||||
d = x.read(2)
|
||||
|
29
examples/javascript/firmata.js
Normal file
29
examples/javascript/firmata.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Author: Ron Evans (@deadprogram)
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var mraa = require('mraa');
|
||||
console.log('MRAA Version: ' + mraa.getVersion());
|
||||
|
||||
// open connection to firmata
|
||||
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
107
examples/javascript/gpio-tool.js
Normal file
107
examples/javascript/gpio-tool.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@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.
|
||||
*/
|
||||
|
||||
var mraa = require('mraa');
|
||||
const readline = require('readline');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
function printUsage() {
|
||||
console.log("version Print version");
|
||||
console.log("get pin Get pin level");
|
||||
console.log("set pin level Set pin level");
|
||||
console.log("monitor pin Monitor pin level changes");
|
||||
}
|
||||
|
||||
function getVersion() {
|
||||
console.log('MRAA Version: ' + mraa.getVersion());
|
||||
}
|
||||
|
||||
function setPin() {
|
||||
var pinNumber = arguments[0];
|
||||
var pinValue = arguments[1];
|
||||
var pin = new mraa.Gpio(pinNumber);
|
||||
pin.dir(mraa.DIR_OUT);
|
||||
pin.write(pinNumber, pinValue);
|
||||
}
|
||||
|
||||
function getPin() {
|
||||
var pinNumber = arguments[0];
|
||||
var pin = new mraa.Gpio(pinNumber);
|
||||
pin.dir(mraa.DIR_IN);
|
||||
console.log('Gpio ' + pinNumber + ' = ' + pin.read());
|
||||
}
|
||||
|
||||
function onPinLevelChange() {
|
||||
console.log('gpio level change');
|
||||
}
|
||||
|
||||
function monitorPin() {
|
||||
var pinNumber = arguments[0];
|
||||
try {
|
||||
var pin = new mraa.Gpio(pinNumber);
|
||||
pin.dir(mraa.DIR_IN);
|
||||
pin.isr(mraa.EDGE_BOTH, onPinLevelChange);
|
||||
rl.question('Press ENTER to stop', function(answer) {
|
||||
rl.close();
|
||||
pin.isrExit();
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
const args = process.argv;
|
||||
const argc = args.length;
|
||||
if (argc >= 3) {
|
||||
const cmd = args[2];
|
||||
switch (args[2]) {
|
||||
case "version":
|
||||
getVersion();
|
||||
break;
|
||||
case "get":
|
||||
var pinNumber = parseInt(args[3]);
|
||||
getPin(pinNumber);
|
||||
break;
|
||||
case "set":
|
||||
var pinNumber = parseInt(args[3]);
|
||||
var pinValue = parseInt(args[4]);
|
||||
getPin(pinNumber, pinValue);
|
||||
break;
|
||||
case "monitor":
|
||||
var pinNumber = parseInt(args[3]);
|
||||
monitorPin(pinNumber);
|
||||
break;
|
||||
default:
|
||||
console.log("Invalid command " + args[2]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.log("Command not specified");
|
||||
printUsage();
|
||||
}
|
||||
|
@@ -8,3 +8,9 @@ function h() {
|
||||
|
||||
x = new m.Gpio(14)
|
||||
x.isr(m.EDGE_BOTH, h)
|
||||
|
||||
setInterval(function() {
|
||||
// It's important to refer to our GPIO context here,
|
||||
// otherwise it will be garbage-collected
|
||||
console.log("Waiting for an interrupt at GPIO pin " + x.getPin() + "...")
|
||||
}, 10000)
|
||||
|
@@ -24,14 +24,11 @@
|
||||
|
||||
var m = require('mraa'); //require mraa
|
||||
|
||||
// helper function to go from hex val to dec
|
||||
function char(x) { return parseInt(x, 16); }
|
||||
|
||||
x = new m.I2c(0)
|
||||
x.address(0x62)
|
||||
x.writeReg(0, 0)
|
||||
x.writeReg(1, 0)
|
||||
|
||||
x.writeReg(char('0x08'), char('0xAA'))
|
||||
x.writeReg(char('0x04'), 255)
|
||||
x.writeReg(char('0x02'), 255)
|
||||
x.writeReg(0x08, 0xAA)
|
||||
x.writeReg(0x04, 255)
|
||||
x.writeReg(0x02, 255)
|
||||
|
@@ -26,15 +26,12 @@
|
||||
|
||||
var m = require('mraa'); //require mraa
|
||||
|
||||
// helper function to go from hex val to dec
|
||||
function char(x) { return parseInt(x, 16); }
|
||||
|
||||
x = new m.Spi(0)
|
||||
buf = new Buffer(4)
|
||||
buf[0] = char('0xf4')
|
||||
buf[1] = char('0x2e')
|
||||
buf[2] = char('0x3e')
|
||||
buf[3] = char('0x4e')
|
||||
buf[0] = 0xf4
|
||||
buf[1] = 0x2e
|
||||
buf[2] = 0x3e
|
||||
buf[3] = 0x4e
|
||||
buf2 = x.write(buf)
|
||||
console.log("Sent: " + buf.toString('hex') + ". Received: " + buf2.toString('hex'))
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
* Author: Eugene Bolshakov <pub@relvarsoft.com>
|
||||
* Copyright (c) 2015 Eugene Bolshakov
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,6 +23,32 @@
|
||||
*/
|
||||
|
||||
var m = require('mraa'); //require mraa
|
||||
|
||||
console.log('MRAA Version: ' + m.getVersion());
|
||||
u = new m.Uart(0)
|
||||
console.log(u.getDevicePath())
|
||||
|
||||
console.log("Note: connect Rx and Tx of UART with a wire before use");
|
||||
|
||||
function sleep(delay) {
|
||||
delay += new Date().getTime();
|
||||
while (new Date() < delay) { }
|
||||
}
|
||||
|
||||
console.log("Set UART parameters");
|
||||
|
||||
u.setBaudRate(115200);
|
||||
u.setMode(8, 0, 1);
|
||||
u.setFlowcontrol(false, false);
|
||||
sleep(200);
|
||||
|
||||
console.log("First write-read circle:");
|
||||
|
||||
u.writeStr("test\n");
|
||||
sleep(200);
|
||||
console.log(u.readStr(6));
|
||||
sleep(200);
|
||||
|
||||
console.log("Second write-read circle:");
|
||||
|
||||
u.writeStr("2nd test\n");
|
||||
sleep(200);
|
||||
console.log(u.readStr(10));
|
||||
|
@@ -59,34 +59,45 @@ print_command_error()
|
||||
print_help();
|
||||
}
|
||||
|
||||
void
|
||||
list_pins()
|
||||
int
|
||||
list_platform_pins(uint8_t platform_offset)
|
||||
{
|
||||
int pin_count = mraa_get_pin_count();
|
||||
if (pin_count == 0) {
|
||||
fprintf(stdout, "No Pins\n");
|
||||
return;
|
||||
}
|
||||
int pin_count = mraa_get_platform_pin_count(platform_offset);
|
||||
int i;
|
||||
for (i = 0; i < pin_count; ++i) {
|
||||
if (strcmp(mraa_get_pin_name(i), "INVALID") != 0) {
|
||||
fprintf(stdout, "%02d ", i);
|
||||
fprintf(stdout, "%*s: ", (MRAA_PIN_NAME_SIZE - 1), mraa_get_pin_name(i));
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_GPIO))
|
||||
int pin_id = platform_offset > 0 ? mraa_get_sub_platform_id(i) : i;
|
||||
char* pin_name = mraa_get_pin_name(pin_id);
|
||||
if (strcmp(pin_name, "INVALID") != 0) {
|
||||
fprintf(stdout, "%02d ", pin_id);
|
||||
fprintf(stdout, "%*s: ", (MRAA_PIN_NAME_SIZE - 1), pin_name);
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_GPIO))
|
||||
fprintf(stdout, "GPIO ");
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_I2C))
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_I2C))
|
||||
fprintf(stdout, "I2C ");
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_SPI))
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_SPI))
|
||||
fprintf(stdout, "SPI ");
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_PWM))
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_PWM))
|
||||
fprintf(stdout, "PWM ");
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_AIO))
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_AIO))
|
||||
fprintf(stdout, "AIO ");
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_UART))
|
||||
if (mraa_pin_mode_test(pin_id, MRAA_PIN_UART))
|
||||
fprintf(stdout, "UART ");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
return pin_count;
|
||||
}
|
||||
|
||||
int
|
||||
list_pins()
|
||||
{
|
||||
int pin_count = 0;
|
||||
pin_count += list_platform_pins(MRAA_MAIN_PLATFORM_OFFSET);
|
||||
pin_count += list_platform_pins(MRAA_SUB_PLATFORM_OFFSET);
|
||||
if (pin_count == 0) {
|
||||
fprintf(stdout, "No Pins\n");
|
||||
}
|
||||
return pin_count;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
|
284
examples/mraa-i2c.c
Normal file
284
examples/mraa-i2c.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2014 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 <unistd.h>
|
||||
#include "mraa/i2c.h"
|
||||
|
||||
#include "mraa_internal_types.h"
|
||||
|
||||
extern mraa_board_t* plat;
|
||||
|
||||
void
|
||||
print_version()
|
||||
{
|
||||
fprintf(stdout, "Version %s on %s", mraa_get_version(), mraa_get_platform_name());
|
||||
if (plat != NULL && plat->sub_platform != NULL)
|
||||
fprintf(stdout, " with %s", plat->sub_platform->platform_name);
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_help()
|
||||
{
|
||||
fprintf(stdout, "version Get mraa version and board name\n");
|
||||
fprintf(stdout, "list List available busses\n");
|
||||
fprintf(stdout, "detect bus List detected devices on specified bus\n");
|
||||
fprintf(stdout, "get bus device reg Get value from specified device register\n");
|
||||
fprintf(stdout, "set bus device reg value Set specified device register to value\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_command_error()
|
||||
{
|
||||
fprintf(stdout, "Invalid command, options are:\n");
|
||||
print_help();
|
||||
}
|
||||
|
||||
void
|
||||
print_bus(mraa_board_t* board)
|
||||
{
|
||||
int i, bus;
|
||||
for (i = 0; i < board->i2c_bus_count; ++i) {
|
||||
char* busType;
|
||||
switch (board->platform_type) {
|
||||
case MRAA_INTEL_GALILEO_GEN1:
|
||||
case MRAA_INTEL_GALILEO_GEN2:
|
||||
case MRAA_INTEL_EDISON_FAB_C:
|
||||
case MRAA_INTEL_DE3815:
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
case MRAA_RASPBERRY_PI:
|
||||
case MRAA_BEAGLEBONE:
|
||||
case MRAA_BANANA:
|
||||
case MRAA_UP:
|
||||
bus = i;
|
||||
busType = "linux";
|
||||
break;
|
||||
case MRAA_FTDI_FT4222:
|
||||
busType = "ft4222";
|
||||
bus = mraa_get_sub_platform_id(i);
|
||||
break;
|
||||
default:
|
||||
busType = "unknown";
|
||||
break;
|
||||
}
|
||||
int id = board->i2c_bus[i].bus_id;
|
||||
fprintf(stdout, "Bus %3d: id=%02d type=%s ", bus, id, busType);
|
||||
if (i == board->def_i2c_bus)
|
||||
fprintf(stdout, " default");
|
||||
if (id == -1)
|
||||
fprintf(stdout, " disabled");
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_busses()
|
||||
{
|
||||
print_bus(plat);
|
||||
if (mraa_has_sub_platform())
|
||||
print_bus(plat->sub_platform);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
i2c_get(int bus, uint8_t device_address, uint8_t register_address, uint8_t* data)
|
||||
{
|
||||
mraa_result_t status = MRAA_SUCCESS;
|
||||
mraa_i2c_context i2c = mraa_i2c_init(bus);
|
||||
if (i2c == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
status = mraa_i2c_address(i2c, device_address);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto i2c_get_exit;
|
||||
}
|
||||
status = mraa_i2c_write_byte(i2c, register_address);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto i2c_get_exit;
|
||||
}
|
||||
status = mraa_i2c_read(i2c, data, 1) == 1 ? MRAA_SUCCESS : MRAA_ERROR_UNSPECIFIED;
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto i2c_get_exit;
|
||||
}
|
||||
i2c_get_exit:
|
||||
mraa_i2c_stop(i2c);
|
||||
return status;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
i2c_set(int bus, uint8_t device_address, uint8_t register_address, uint8_t data)
|
||||
{
|
||||
mraa_result_t status = MRAA_SUCCESS;
|
||||
mraa_i2c_context i2c = mraa_i2c_init(bus);
|
||||
if (i2c == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
status = mraa_i2c_address(i2c, device_address);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Could not set i2c device address\n");
|
||||
goto i2c_set_exit;
|
||||
}
|
||||
status = mraa_i2c_write_byte_data(i2c, data, register_address);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Could not write to i2c register. Status = %d\n", status);
|
||||
goto i2c_set_exit;
|
||||
}
|
||||
i2c_set_exit:
|
||||
mraa_i2c_stop(i2c);
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
i2c_detect_devices(int bus)
|
||||
{
|
||||
mraa_result_t status = MRAA_SUCCESS;
|
||||
mraa_i2c_context i2c = mraa_i2c_init(bus);
|
||||
if (i2c == NULL) {
|
||||
return;
|
||||
}
|
||||
int addr;
|
||||
for (addr = 0x0; addr < 0x80; ++addr) {
|
||||
uint8_t value;
|
||||
if ((addr) % 16 == 0)
|
||||
printf("%02x: ", addr);
|
||||
if (i2c_get(bus, addr, 0, &value) == MRAA_SUCCESS)
|
||||
printf("%02x ", addr);
|
||||
else
|
||||
printf("-- ");
|
||||
if ((addr + 1) % 16 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
process_command(int argc, char** argv)
|
||||
{
|
||||
int status = 0;
|
||||
if (strcmp(argv[1], "help") == 0) {
|
||||
print_help();
|
||||
return 0;
|
||||
} else if (strcmp(argv[1], "version") == 0) {
|
||||
print_version();
|
||||
return 0;
|
||||
} else if (strcmp(argv[1], "list") == 0) {
|
||||
print_busses();
|
||||
return 0;
|
||||
} else if (strcmp(argv[1], "detect") == 0) {
|
||||
if (argc == 3) {
|
||||
int bus = strtol(argv[2], NULL, 0);
|
||||
i2c_detect_devices(bus);
|
||||
return 0;
|
||||
} else {
|
||||
print_command_error();
|
||||
return 1;
|
||||
}
|
||||
} else if ((strcmp(argv[1], "get") == 0) || (strcmp(argv[1], "getrpt") == 0)) {
|
||||
if (argc == 5) {
|
||||
int interation = 0;
|
||||
mraa_boolean_t should_repeat = strcmp(argv[1], "getrpt") == 0;
|
||||
int bus = strtol(argv[2], NULL, 0);
|
||||
uint8_t device_address = strtol(argv[3], NULL, 0);
|
||||
uint8_t register_address = strtol(argv[4], NULL, 0);
|
||||
// fprintf(stdout, "Device %02X, Register = %02X\n", device_address, register_address);
|
||||
uint8_t data;
|
||||
do {
|
||||
if (i2c_get(bus, device_address, register_address, &data) == MRAA_SUCCESS) {
|
||||
if (should_repeat)
|
||||
fprintf(stdout, "%4d: ", interation);
|
||||
fprintf(stdout, "Register %#02X = %#02X\n", register_address, data);
|
||||
status = 0;
|
||||
} else {
|
||||
fprintf(stdout, "i2c get failed\n");
|
||||
status = 1;
|
||||
}
|
||||
interation++;
|
||||
usleep(10000);
|
||||
} while (should_repeat && status == 0);
|
||||
} else {
|
||||
print_command_error();
|
||||
status = 1;
|
||||
}
|
||||
return status;
|
||||
} else if ((strcmp(argv[1], "set") == 0)) {
|
||||
if (argc == 6) {
|
||||
int bus = strtol(argv[2], NULL, 0);
|
||||
uint8_t device_address = strtol(argv[3], NULL, 0);
|
||||
uint8_t register_address = strtol(argv[4], NULL, 0);
|
||||
uint8_t value = strtol(argv[5], NULL, 0);
|
||||
fprintf(stdout, "Device %02X, Register = %02X, Value = %02X\n", device_address,
|
||||
register_address, value);
|
||||
if (i2c_set(bus, device_address, register_address, value) != MRAA_SUCCESS) {
|
||||
fprintf(stdout, "i2c set failed\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
print_command_error();
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
print_command_error();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run_interactive_mode()
|
||||
{
|
||||
char command[80];
|
||||
while (1) {
|
||||
int i, argc = 1;
|
||||
char* argv[32];
|
||||
char* arg;
|
||||
argv[0] = "mraa-i2c";
|
||||
fprintf(stdout, "Command: ");
|
||||
fgets(command, 80, stdin);
|
||||
command[strlen(command) - 1] = 0;
|
||||
if (strcmp(command, "q") == 0)
|
||||
return;
|
||||
char* str = strtok(command, " ");
|
||||
while (str != NULL) {
|
||||
arg = malloc(strlen(str) + 1);
|
||||
argv[argc++] = strcpy(arg, str);
|
||||
str = strtok(NULL, " ");
|
||||
}
|
||||
process_command(argc, argv);
|
||||
for (i = 1; i < argc; ++i)
|
||||
free(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_set_log_level(7);
|
||||
if (argc == 1) {
|
||||
run_interactive_mode();
|
||||
return 0;
|
||||
} else
|
||||
return process_command(argc, argv);
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
# Author: Ron Evans (@deadprogram)
|
||||
# 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
|
||||
@@ -20,9 +20,10 @@
|
||||
# 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
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa
|
||||
|
||||
u = mraa.Uart(0)
|
||||
print u.getDevicePath()
|
||||
print (mraa.getVersion())
|
||||
|
||||
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
@@ -24,20 +24,31 @@
|
||||
|
||||
import mraa
|
||||
import time
|
||||
import sys
|
||||
|
||||
class Counter:
|
||||
count = 0
|
||||
|
||||
c = Counter()
|
||||
|
||||
# inside a python interupt you cannot use 'basic' types so you'll need to use
|
||||
# inside a python interrupt you cannot use 'basic' types so you'll need to use
|
||||
# objects
|
||||
def test(args):
|
||||
print("wooo")
|
||||
def test(gpio):
|
||||
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))
|
||||
c.count+=1
|
||||
|
||||
x = mraa.Gpio(6)
|
||||
x.dir(mraa.DIR_IN)
|
||||
x.isr(mraa.EDGE_BOTH, test, test)
|
||||
|
||||
time.sleep(500)
|
||||
pin = 6;
|
||||
if (len(sys.argv) == 2):
|
||||
try:
|
||||
pin = int(sys.argv[1], 10)
|
||||
except ValueError:
|
||||
printf("Invalid pin " + sys.argv[1])
|
||||
try:
|
||||
x = mraa.Gpio(pin)
|
||||
print("Starting ISR for pin " + repr(pin))
|
||||
x.dir(mraa.DIR_IN)
|
||||
x.isr(mraa.EDGE_BOTH, test, x)
|
||||
var = raw_input("Press ENTER to stop")
|
||||
x.isrExit()
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
|
44
examples/python/uart_receiver.py
Normal file
44
examples/python/uart_receiver.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2015 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
|
||||
|
||||
# Initialize UART
|
||||
u=mraa.Uart(0)
|
||||
|
||||
# Set UART parameters
|
||||
u.setBaudRate(115200)
|
||||
u.setMode(8, mraa.UART_PARITY_NONE, 1)
|
||||
u.setFlowcontrol(False, False)
|
||||
|
||||
# Start a neverending loop waiting for data to arrive.
|
||||
# Press Ctrl+C to get out of it.
|
||||
while True:
|
||||
if u.dataAvailable():
|
||||
# We are doing 1-byte reads here
|
||||
data_byte = u.readStr(1)
|
||||
print(data_byte)
|
||||
# Just a two-way half-duplex communication example, "X" is a flag
|
||||
if data_byte == "X":
|
||||
u.writeStr("Yes, master!")
|
57
examples/python/uart_sender.py
Normal file
57
examples/python/uart_sender.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2015 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
|
||||
import sys
|
||||
|
||||
sys.stdout.write("Initializing UART...")
|
||||
u=mraa.Uart(0)
|
||||
print("...done")
|
||||
|
||||
print("Setting UART parameters: baudrate 115200, 8N1, no flow control")
|
||||
u.setBaudRate(115200)
|
||||
u.setMode(8, mraa.UART_PARITY_NONE, 1)
|
||||
u.setFlowcontrol(False, False)
|
||||
|
||||
msg_b = bytearray("Hello, mraa byte array!", "ascii")
|
||||
print("Sending message as a byte array: '{0}'".format(msg_b))
|
||||
u.write(msg_b)
|
||||
# Make sure the message gets out to the line.
|
||||
# It's generally unnecessary (and performance-degrading) to do this explicitly,
|
||||
# UART driver normally takes care of that, but it may be useful with specific
|
||||
# half-duplex endpoints, like Dynamixel servos.
|
||||
u.flush()
|
||||
|
||||
msg_s = "Hello, mraa string!"
|
||||
print("Sending message as a string: '{0}'".format(msg_s))
|
||||
u.writeStr(msg_s)
|
||||
|
||||
sys.stdout.write("Two-way, half-duplex communication, sending a flag...")
|
||||
u.writeStr("X")
|
||||
print("...sent, awaiting response...")
|
||||
# Checking for data in the RX buffer, giving it a 100ms timeout
|
||||
if u.dataAvailable(100):
|
||||
print("We've got a response: '{0}', says the other side".format(u.readStr(20)))
|
||||
else:
|
||||
print("No data received, do you have anything at the other end?")
|
16
examples/samples.mapping.txt
Normal file
16
examples/samples.mapping.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
analogin_a0.c java/AioA0.java
|
||||
cycle-pwm3.c java/CyclePwm3.java
|
||||
gpio_read6.c java/GpioRead6.java
|
||||
helloedison.c java/HelloEdison.java
|
||||
hellomraa.c java/Example.java
|
||||
i2c_HMC5883L.c java/I2cCompass.java
|
||||
mmap-io2.c java/GpioMmapped.java
|
||||
spi_max7219.c java/SpiMAX7219.java
|
||||
spi_mcp4261.c java/SpiMCP4261.java
|
||||
uart.c java/UartExample.java
|
||||
AioA0.cpp java/AioA0.java
|
||||
Blink-IO.cpp java/BlinkIO.java
|
||||
I2c-compass.cpp java/I2cCompass.java
|
||||
Pwm3-cycle.cpp java/CyclePwm3.java
|
||||
Spi-pot.cpp java/SpiMCP4261.java
|
||||
Uart-example.cpp java/UartExample.java
|
92
examples/uart_ow.c
Normal file
92
examples/uart_ow.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "stdio.h"
|
||||
//! [Interesting]
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_uart_ow_context uart;
|
||||
uart = mraa_uart_ow_init(0);
|
||||
|
||||
if (!uart) {
|
||||
printf("mraa_uart_ow_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Reset the ow bus and see if anything is present
|
||||
mraa_result_t rv;
|
||||
|
||||
if ((rv = mraa_uart_ow_reset(uart)) == MRAA_SUCCESS) {
|
||||
printf("Reset succeeded, device(s) detected!\n");
|
||||
} else {
|
||||
printf("Reset failed, returned %d. No devices on bus?\n", rv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Looking for devices...\n");
|
||||
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
|
||||
|
||||
/* we are essentially doing a binary tree search through the 64
|
||||
* bit address space. id is modified during this search, and will
|
||||
* be set to the valid rom code for each device found.
|
||||
*/
|
||||
|
||||
uint8_t count = 0;
|
||||
|
||||
// start the search from scratch
|
||||
mraa_result_t result = mraa_uart_ow_rom_search(uart, 1, id);
|
||||
if (result == MRAA_ERROR_UART_OW_NO_DEVICES) {
|
||||
printf("No devices detected.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (result == MRAA_ERROR_UART_OW_DATA_ERROR) {
|
||||
printf("Bus/Data error.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (result == MRAA_SUCCESS) {
|
||||
/* The first byte (id[0]]) is the device type (family) code.
|
||||
* The last byte (id[7]) is the rom code CRC value. The
|
||||
* intervening bytes (id[1]-id[6]) are the unique 48 bit
|
||||
* device ID.
|
||||
*/
|
||||
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, id[0],
|
||||
id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
|
||||
count++;
|
||||
|
||||
// continue the search with start argument set to 0
|
||||
result = mraa_uart_ow_rom_search(uart, 0, id);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
mraa_uart_ow_stop(uart);
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
17
imraa/CMakeLists.txt
Normal file
17
imraa/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
add_executable (imraa imraa.c)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/api)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/api/mraa)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
|
||||
|
||||
find_package (JSON-C REQUIRED)
|
||||
include_directories (${JSON-C_INCLUDE_DIR})
|
||||
find_package (UDEV REQUIRED)
|
||||
include_directories (${UDEV_INCLUDE_DIR})
|
||||
target_link_libraries (imraa mraa ${JSON-C_LIBRARIES} ${UDEV_LIBRARIES})
|
||||
|
||||
set_property (TARGET imraa PROPERTY C_STANDARD 99)
|
||||
|
||||
install (TARGETS imraa DESTINATION bin)
|
527
imraa/imraa.c
Normal file
527
imraa/imraa.c
Normal file
@@ -0,0 +1,527 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Longwei Su <lsu@ics.com>
|
||||
* Copyright (c) 2015 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 <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <json-c/json.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#include <mraa/uart.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
#include <mraa_internal.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)
|
||||
{
|
||||
struct json_object* imraa_version;
|
||||
if (json_object_object_get_ex(jobj, "version", &imraa_version) == true) {
|
||||
if (json_object_is_type(imraa_version, json_type_string)) {
|
||||
printf("imraa version is %s good\n", json_object_get_string(imraa_version));
|
||||
// TODO check version?
|
||||
} else {
|
||||
fprintf(stderr, "version string incorrectly parsed\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "no version specified\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_version()
|
||||
{
|
||||
fprintf(stdout, "Version %s on %s\n", mraa_get_version(), mraa_get_platform_name());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (argc > 2) {
|
||||
print_command_error();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
FILE* fh = fopen(imraa_conf_file, "r");
|
||||
if (fh == NULL) {
|
||||
fprintf(stderr, "Failed to open configuration file\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fseek(fh, 0, SEEK_END);
|
||||
fsize = ftell(fh) + 1;
|
||||
fseek(fh, 0, SEEK_SET);
|
||||
buffer = calloc(fsize, sizeof(char));
|
||||
if (buffer != NULL) {
|
||||
int result = fread(buffer, sizeof(char), fsize, fh);
|
||||
if (result != fsize) {
|
||||
printf("imraa conf reading error");
|
||||
}
|
||||
} else {
|
||||
printf("imraa read_conf buffer can't allocated\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
imraa_init();
|
||||
|
||||
json_object* jobj = json_tokener_parse(buffer);
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
fclose(fh);
|
||||
json_object_put(jobj);
|
||||
free(buffer);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
12
imraa/imraa.conf
Normal file
12
imraa/imraa.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": "0.9.6",
|
||||
"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"}
|
||||
]
|
||||
}
|
9
imraa/imraa.service
Normal file
9
imraa/imraa.service
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=imraa
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/imraa
|
||||
|
||||
[Install]
|
||||
WantedBy = multi-user.target
|
46
include/arm/96boards.h
Normal file
46
include/arm/96boards.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
|
||||
* Copyright (c) 2015 Linaro Limited.
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Copied from include/arm/banana.h
|
||||
*
|
||||
* 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 MRAA_96BOARDS_LS_GPIO_COUNT 12
|
||||
#define MRAA_96BOARDS_LS_I2C_COUNT 2
|
||||
#define MRAA_96BOARDS_LS_SPI_COUNT 1
|
||||
#define MRAA_96BOARDS_LS_UART_COUNT 2
|
||||
#define MRAA_96BOARDS_LS_PIN_COUNT 40
|
||||
|
||||
mraa_board_t* mraa_96boards();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user