Compare commits
199 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2a682aaa65 | ||
|
d700cae7c4 | ||
|
356096350b | ||
|
b4919de733 | ||
|
49ee1ebef5 | ||
|
c0fbccb3b6 | ||
|
fce4daab02 | ||
|
29be2b64c0 | ||
|
50213f97bc | ||
|
e675123d50 | ||
|
36153ad7ad | ||
|
aed965c27d | ||
|
5d763cb7e5 | ||
|
5d94d0a13c | ||
|
ca0d740ee0 | ||
|
c7570ff7c2 | ||
|
a8a7771a16 | ||
|
1ce0b138d2 | ||
|
8ba8ce3b26 | ||
|
346f447c4d | ||
|
26718a67a2 | ||
|
0021b1aace | ||
|
da3efdc4b9 | ||
|
230b6084ba | ||
|
8cd1a06562 | ||
|
874d0f47bd | ||
|
6c9aeb9b9e | ||
|
63b244cfc3 | ||
|
917a1bd371 | ||
|
e43459d031 | ||
|
eabee5f864 | ||
|
a22ff43f59 | ||
|
1af737f3d9 | ||
|
bcb6adc551 | ||
|
593fd0be54 | ||
|
3992f9d596 | ||
|
43718e7cbf | ||
|
d336e9f8d6 | ||
|
9634f17a2a | ||
|
dfecc68320 | ||
|
b9a6d2a86a | ||
|
bc178b27ee | ||
|
fe9264c98f | ||
|
de0543923c | ||
|
b1d23303f7 | ||
|
c1fd2896c2 | ||
|
5704c15665 | ||
|
b5b84c6186 | ||
|
0bd488bc53 | ||
|
f9bc314223 | ||
|
50e1b568fb | ||
|
a54386c5d3 | ||
|
0577321f4c | ||
|
5f515f7648 | ||
|
3d2163e2cb | ||
|
8af6843566 | ||
|
c413a43d5a | ||
|
03b548c33b | ||
|
5160d909d3 | ||
|
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 |
59
.travis.yml
59
.travis.yml
@@ -1,32 +1,55 @@
|
||||
language: cpp
|
||||
sudo: required
|
||||
dist: trusty
|
||||
env:
|
||||
- CC=gcc CXX=gcc
|
||||
- CC=clang CXX=clang++
|
||||
- NODE010=true
|
||||
- NODE012=true
|
||||
- NODE4=true
|
||||
- NODE5=true
|
||||
- NODE012=true
|
||||
- JSONPLAT=true NODE010=true
|
||||
- JSONPLAT=true NODE012=true
|
||||
- JSONPLAT=true NODE4=true
|
||||
- JSONPLAT=true NODE5=true
|
||||
# node010 npm builds don't work in clang and anyone using npm should want to
|
||||
# use something newer
|
||||
- NPM=true NODE4=true
|
||||
- NPM=true NODE5=true
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
before_install:
|
||||
# Via https://github.com/travis-ci/travis-ci/issues/5326
|
||||
- export PATH="$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")"
|
||||
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 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:
|
||||
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36/include"
|
||||
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
||||
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
||||
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`/include"; fi
|
||||
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`/include"; fi
|
||||
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`/include"; fi
|
||||
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
|
||||
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
|
||||
- if [ "${JSONPLAT}" ]; then export JSONPLAT=ON; else export JSONPLAT=OFF; fi
|
||||
- if [ "${NODE010}" ]; then nvm install 0.10; fi
|
||||
- if [ "${NODE012}" ]; then nvm install 0.12; fi
|
||||
- if [ "${NODE4}" ]; then nvm install 4.1; fi
|
||||
- if [ "${NODE5}" ]; then nvm install 5; fi
|
||||
- npm install node-gyp && export NODE_GYP="/home/travis/build/intel-iot-devkit/mraa/node_modules/node-gyp/bin/node-gyp.js"
|
||||
# Handle 0.10 NODE_ROOT_DIR differently than other versions
|
||||
- wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && ./configure --prefix=/home/travis/ && make && make install && cd ..
|
||||
script:
|
||||
- mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" .. && make && make test
|
||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
||||
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
|
||||
# simple test to see if we can load our node module
|
||||
- if [ ${NPM} ]; then cd build/Release/obj.target/ && node -e "var m = require('./mraa.node'); m.getVersion()";fi
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-precise-3.6
|
||||
- ubuntu-toolchain-r-test
|
||||
- kalakris-cmake
|
||||
packages:
|
||||
- clang-3.6
|
||||
- g++-4.8
|
||||
- cmake
|
||||
- python
|
||||
- python-dev
|
||||
- python3
|
||||
- python3-dev
|
||||
- git
|
||||
- libjson0
|
||||
- libjson0-dev
|
||||
|
@@ -36,7 +36,9 @@ LOCAL_SRC_FILES := \
|
||||
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/intel_cherryhills.c \
|
||||
src/x86/up.c \
|
||||
src/x86/intel_gt_tuchuck.c
|
||||
|
||||
# glob.c pulled in from NetBSD project (BSD 3-clause License)
|
||||
LOCAL_SRC_FILES += \
|
||||
|
@@ -5,11 +5,17 @@ FIND_PACKAGE (Threads REQUIRED)
|
||||
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer ")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
|
||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
||||
|
||||
# Set CMAKE_LIB_INSTALL_DIR if not defined
|
||||
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Older cmake might not pick CMAKE_INSTALL_LIBDIR right
|
||||
if (CMAKE_INSTALL_LIBDIR)
|
||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
||||
else ()
|
||||
set (LIB_INSTALL_DIR "lib" CACHE PATH "Installation path for libraries")
|
||||
endif ()
|
||||
|
||||
# By default, build shared object libraries on linux
|
||||
if (UNIX AND NOT APPLE)
|
||||
if (NOT DEFINED BUILD_SHARED_LIBS)
|
||||
@@ -25,11 +31,11 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.9.5-dirty")
|
||||
set (VERSION "v1.2.3-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - libmraa Version ${VERSION}")
|
||||
message (INFO " - cmake Version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_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}")
|
||||
@@ -63,17 +69,21 @@ 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 (JSONPLAT "Add Platform loading via a json file." ON)
|
||||
option (IMRAA "Add Imraa support to mraa." OFF)
|
||||
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||
option (ENABLEEXAMPLES "Disable building of examples" ON)
|
||||
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
|
||||
option (INSTALLTOOLS "Install all tools" OFF)
|
||||
option (BUILDARCH "Override architecture to build for - override" OFF)
|
||||
option (BUILDTESTS "Override the addition of tests" ON)
|
||||
|
||||
set (MRAAPLATFORMFORCE "" CACHE STRING "ALL")
|
||||
set (BUILDARCH "" CACHE STRING "Override architecture to build for")
|
||||
|
||||
set (MRAAPLATFORMFORCE "ALL" CACHE STRING "Override platform to build for")
|
||||
|
||||
if (NOT BUILDSWIG)
|
||||
set (BUILDSWIGPYTHON OFF)
|
||||
@@ -84,10 +94,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"
|
||||
@@ -95,17 +105,14 @@ if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
|
||||
set (X86PLAT ON)
|
||||
elseif (DETECTED_ARCH MATCHES "arm.*")
|
||||
set (ARMPLAT ON)
|
||||
elseif (DETECTED_ARCH STREQUAL "MOCK")
|
||||
set (MOCKPLAT ON)
|
||||
else ()
|
||||
message(FATAL_ERROR "Only x86 and arm platforms currently supported")
|
||||
message (FATAL_ERROR "Only x86, arm and mock platforms currently supported")
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
else ()
|
||||
set (PYTHONBUILD_VERSION 2.7)
|
||||
endif ()
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
include (cmake/modules/OpenCVDetectPython.cmake)
|
||||
endif ()
|
||||
|
||||
if (BUILDDOC)
|
||||
@@ -137,9 +144,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
|
||||
@@ -161,7 +168,7 @@ 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")
|
||||
@@ -189,9 +196,11 @@ if (ENABLEEXAMPLES)
|
||||
add_subdirectory (examples)
|
||||
endif ()
|
||||
|
||||
if (BUILDTESTS)
|
||||
if (${PYTHONINTERP_FOUND})
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
if (IMRAA)
|
||||
add_subdirectory (imraa)
|
||||
endif ()
|
||||
|
||||
if (BUILDTESTS AND PYTHON_DEFAULT_EXECUTABLE)
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
|
20
README.md
20
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.
|
||||
|
||||
@@ -12,6 +15,8 @@ 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.
|
||||
|
||||
[](https://travis-ci.org/intel-iot-devkit/mraa)
|
||||
|
||||
Supported Boards
|
||||
================
|
||||
|
||||
@@ -24,6 +29,7 @@ X86
|
||||
* [Minnowboard Max](../master/docs/minnow_max.md)
|
||||
* [NUC 5th generation](../master/docs/intel_nuc5.md)
|
||||
* [UP](../master/docs/up.md)
|
||||
* [Intel Grosse Tete](../master/docs/grossetete.md)
|
||||
|
||||
ARM
|
||||
---
|
||||
@@ -35,6 +41,10 @@ USB
|
||||
---
|
||||
* [FT4222](../master/docs/ftdi_ft4222.md)
|
||||
|
||||
Mock
|
||||
----
|
||||
* [Generic simulated board](../master/docs/mock.md)
|
||||
|
||||
Installing on your board
|
||||
========
|
||||
|
||||
@@ -94,7 +104,7 @@ API Documentation
|
||||
Contact Us
|
||||
==========
|
||||
|
||||
To ask questions eithe file issues in github or send emails on our [mailing
|
||||
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.
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -47,13 +47,26 @@ class Aio
|
||||
*
|
||||
* @param pin channel number to read ADC inputs
|
||||
*/
|
||||
Aio(unsigned int pin)
|
||||
Aio(int pin)
|
||||
{
|
||||
m_aio = mraa_aio_init(pin);
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio Constructor, takes a pointer to the AIO context and initialises
|
||||
* the AIO class
|
||||
*
|
||||
* @param void * to an AIO context
|
||||
*/
|
||||
Aio(void* aio_context)
|
||||
{
|
||||
m_aio = (mraa_aio_context) aio_context;
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio destructor
|
||||
*/
|
||||
@@ -65,22 +78,32 @@ class Aio
|
||||
* Read a value from the AIO pin. By default mraa will shift
|
||||
* the raw value up or down to a 10 bit value.
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @returns The current input voltage. By default, a 10bit value
|
||||
*/
|
||||
int
|
||||
unsigned int
|
||||
read()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
int x = mraa_aio_read(m_aio);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in Aio::read()");
|
||||
}
|
||||
return (unsigned int) x;
|
||||
}
|
||||
/**
|
||||
* Read a value from the AIO pin and return it as a normalized float.
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @returns The current input voltage as a normalized float (0.0f-1.0f)
|
||||
*/
|
||||
float
|
||||
readFloat()
|
||||
{
|
||||
return mraa_aio_read_float(m_aio);
|
||||
float x = mraa_aio_read_float(m_aio);
|
||||
if (x == -1.0f) {
|
||||
throw std::invalid_argument("Unknown error in Aio::readFloat()");
|
||||
}
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* Set the bit value which mraa will shift the raw reading
|
||||
|
@@ -44,6 +44,7 @@
|
||||
if (res != MRAA_SUCCESS) \
|
||||
return res;} while(0)
|
||||
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the basic shared values for libmraa
|
||||
@@ -64,9 +65,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
|
||||
*/
|
||||
@@ -161,7 +160,7 @@ const char* mraa_get_platform_version(int platform_offset);
|
||||
* @param priority Value from typically 0 to 99
|
||||
* @return The priority value set
|
||||
*/
|
||||
int mraa_set_priority(const unsigned int priority);
|
||||
int mraa_set_priority(const int priority);
|
||||
|
||||
/** Get the version string of mraa autogenerated from git tag
|
||||
*
|
||||
@@ -216,7 +215,7 @@ int mraa_get_i2c_bus_count();
|
||||
* @param i2c_bus the logical I2C bus number
|
||||
* @return I2C adapter number in sysfs. Function will return -1 on failure
|
||||
*/
|
||||
int mraa_get_i2c_bus_id(unsigned int i2c_bus);
|
||||
int mraa_get_i2c_bus_id(int i2c_bus);
|
||||
|
||||
/**
|
||||
* Get specified platform pincount, board must be initialised.
|
||||
@@ -276,7 +275,47 @@ int mraa_get_sub_platform_id(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);
|
||||
|
||||
/**
|
||||
* Instantiate an unknown board using a json file
|
||||
*
|
||||
* @param Path to the json file, relative to the folder the program
|
||||
* was initially run in or a direct path
|
||||
*
|
||||
* @return mraa_result indicating success
|
||||
*/
|
||||
mraa_result_t mraa_init_json_platform(const char* path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -46,9 +46,7 @@ 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
|
||||
*/
|
||||
@@ -80,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);
|
||||
}
|
||||
@@ -197,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);
|
||||
}
|
||||
@@ -260,7 +258,7 @@ isSubPlatformId(int pin_or_bus_id)
|
||||
*
|
||||
* @return int sub platform pin or bus number
|
||||
*/
|
||||
inline int
|
||||
inline int
|
||||
getSubPlatformId(int pin_or_bus_index)
|
||||
{
|
||||
return mraa_get_sub_platform_id(pin_or_bus_index);
|
||||
@@ -290,4 +288,57 @@ 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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate an unknown board using a json file
|
||||
*
|
||||
* @param Path to the json file, relative to the folder the program
|
||||
* was initially run in or a direct path
|
||||
*
|
||||
* @return Result indicating success
|
||||
*/
|
||||
inline Result
|
||||
initJsonPlatform(std::string path)
|
||||
{
|
||||
return (Result) mraa_init_json_platform(path.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
|
@@ -40,21 +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 JavaVM *globVM;
|
||||
extern void mraa_java_isr_callback(void *);
|
||||
extern "C" {
|
||||
void mraa_java_isr_callback(void *args);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Opaque pointer definition to the internal struct _gpio
|
||||
*/
|
||||
@@ -81,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;
|
||||
|
||||
/**
|
||||
@@ -116,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
|
||||
@@ -128,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
|
||||
|
@@ -44,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;
|
||||
|
||||
/**
|
||||
@@ -60,13 +60,13 @@ typedef enum {
|
||||
} Dir;
|
||||
|
||||
/**
|
||||
* Gpio Edge types for interupts
|
||||
* Gpio Edge types for interrupts
|
||||
*/
|
||||
typedef enum {
|
||||
EDGE_NONE = 0, /**< No interrupt on Gpio */
|
||||
EDGE_BOTH = 1, /**< Interupt on rising & falling */
|
||||
EDGE_RISING = 2, /**< Interupt on rising only */
|
||||
EDGE_FALLING = 3 /**< Interupt on falling only */
|
||||
EDGE_BOTH = 1, /**< Interrupt on rising & falling */
|
||||
EDGE_RISING = 2, /**< Interrupt on rising only */
|
||||
EDGE_FALLING = 3 /**< Interrupt on falling only */
|
||||
} Edge;
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ class Gpio
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Instanciates a Gpio object
|
||||
* Instantiates a Gpio object
|
||||
*
|
||||
* @param pin pin number to use
|
||||
* @param owner (optional) Set pin owner, default behaviour is to 'own'
|
||||
@@ -107,6 +107,19 @@ class Gpio
|
||||
mraa_gpio_owner(m_gpio, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio Constructor, takes a pointer to the GPIO context and initialises
|
||||
* the GPIO class
|
||||
*
|
||||
* @param void * to GPIO context
|
||||
*/
|
||||
Gpio(void* gpio_context)
|
||||
{
|
||||
m_gpio = (mraa_gpio_context) gpio_context;
|
||||
if (m_gpio == NULL) {
|
||||
throw std::invalid_argument("Invalid GPIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio object destructor, this will only unexport the gpio if we where
|
||||
* the owner
|
||||
@@ -186,7 +199,7 @@ class Gpio
|
||||
* Sets a callback to be called when pin value changes
|
||||
*
|
||||
* @param mode The edge mode to set
|
||||
* @param fptr Function pointer to function to be called when interupt is
|
||||
* @param fptr Function pointer to function to be called when interrupt is
|
||||
* triggered
|
||||
* @param args Arguments passed to the interrupt handler (fptr)
|
||||
* @return Result of operation
|
||||
@@ -198,7 +211,7 @@ class Gpio
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits callback - this call will not kill the isr thread immediatly
|
||||
* Exits callback - this call will not kill the isr thread immediately
|
||||
* but only when it is out of it's critical section
|
||||
*
|
||||
* @return Result of operation
|
||||
|
@@ -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);
|
||||
|
@@ -62,6 +62,18 @@ class I2c
|
||||
throw std::invalid_argument("Invalid i2c bus");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* I2C constructor, takes a pointer to a I2C context and initialises the I2C class
|
||||
*
|
||||
* @param void * to an I2C context
|
||||
*/
|
||||
I2c(void* i2c_context)
|
||||
{
|
||||
m_i2c = (mraa_i2c_context) i2c_context;
|
||||
if (m_i2c == NULL) {
|
||||
throw std::invalid_argument("Invalid I2C context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the I2c Bus used. This does not guarrantee the bus will not
|
||||
@@ -103,12 +115,17 @@ class I2c
|
||||
/**
|
||||
* Read exactly one byte from the bus
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from the bus
|
||||
*/
|
||||
uint8_t
|
||||
readByte()
|
||||
{
|
||||
return (uint8_t) mraa_i2c_read_byte(m_i2c);
|
||||
int x = mraa_i2c_read_byte(m_i2c);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readByte()");
|
||||
}
|
||||
return (uint8_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,24 +145,36 @@ class I2c
|
||||
* Read byte from an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from register
|
||||
*/
|
||||
uint8_t
|
||||
readReg(uint8_t reg)
|
||||
{
|
||||
return mraa_i2c_read_byte_data(m_i2c, reg);
|
||||
int x = mraa_i2c_read_byte_data(m_i2c, reg);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readReg()");
|
||||
}
|
||||
return (uint8_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read word from an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
*
|
||||
* @throws std::invalid_argument in case of error
|
||||
* @return char read from register
|
||||
*/
|
||||
uint16_t
|
||||
readWordReg(uint8_t reg)
|
||||
{
|
||||
return mraa_i2c_read_word_data(m_i2c, reg);
|
||||
int x = mraa_i2c_read_word_data(m_i2c, reg);
|
||||
if (x == -1) {
|
||||
throw std::invalid_argument("Unknown error in I2c::readReg()");
|
||||
}
|
||||
return (uint16_t) x;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -121,7 +121,7 @@ mraa_result_t mraa_iio_event_extract_event(struct iio_event_data* event,
|
||||
int* channel2,
|
||||
int* different);
|
||||
|
||||
mraa_result_t mraa_iio_get_mounting_matrix(mraa_iio_context dev, float mm[9]);
|
||||
mraa_result_t mraa_iio_get_mount_matrix(mraa_iio_context dev, const char *sysfs_name, float mm[9]);
|
||||
|
||||
mraa_result_t mraa_iio_create_trigger(mraa_iio_context dev, const char* trigger);
|
||||
|
||||
|
@@ -106,7 +106,12 @@ enum iio_event_direction {
|
||||
};
|
||||
|
||||
//linux/iio/events.h
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#include <sys/ioctl.h>
|
||||
#else
|
||||
#include <linux/ioctl.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct iio_event_data - The actual event being pushed to userspace
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -46,9 +46,9 @@ class Pwm
|
||||
*
|
||||
* @param pin the pin number used on your board
|
||||
* @param owner if you are the owner of the pin the destructor will
|
||||
* @param chipid the pwmchip to use, use only in raw mode
|
||||
* unexport the pin from sysfs, default behaviour is you are the owner
|
||||
* if the pinmapper exported it
|
||||
* @param chipid the pwmchip to use, use only in raw mode
|
||||
*/
|
||||
Pwm(int pin, bool owner = true, int chipid = -1)
|
||||
{
|
||||
@@ -66,6 +66,20 @@ class Pwm
|
||||
mraa_pwm_owner(m_pwm, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pwm constructor, takes a pointer to the PWM context and
|
||||
* initialises the class
|
||||
*
|
||||
* @param void * to a PWM context
|
||||
*/
|
||||
Pwm(void* pwm_context)
|
||||
{
|
||||
m_pwm = (mraa_pwm_context) pwm_context;
|
||||
if (m_pwm == NULL) {
|
||||
throw std::invalid_argument("Invalid PWM context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pwm destructor
|
||||
*/
|
||||
@@ -77,7 +91,7 @@ class Pwm
|
||||
* Set the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @param percentage A floating-point value representing percentage of
|
||||
* output. The value should lie between 0.0f (representing on 0%) and
|
||||
* output. The value should lie between 0.0f (representing 0%) and
|
||||
* 1.0f Values above or below this range will be set at either 0.0f or
|
||||
* 1.0f
|
||||
* @return Result of operation
|
||||
@@ -88,10 +102,10 @@ class Pwm
|
||||
return (Result) mraa_pwm_write(m_pwm, percentage);
|
||||
}
|
||||
/**
|
||||
* Read the ouput duty-cycle percentage, as a float
|
||||
* Read the output duty-cycle percentage, as a float
|
||||
*
|
||||
* @return A floating-point value representing percentage of
|
||||
* output. The value should lie between 0.0f (representing on 0%) and
|
||||
* output. The value should lie between 0.0f (representing 0%) and
|
||||
* 1.0f Values above or below this range will be set at either 0.0f or
|
||||
* 1.0f
|
||||
*/
|
||||
@@ -134,7 +148,7 @@ class Pwm
|
||||
return (Result) mraa_pwm_period_us(m_pwm, us);
|
||||
}
|
||||
/**
|
||||
* Set pulsewidth, As represnted by seconds in a (float)
|
||||
* Set pulsewidth, as represented by seconds in a float
|
||||
*
|
||||
* @param seconds The duration of a pulse
|
||||
* @return Result of operation
|
||||
@@ -176,54 +190,27 @@ class Pwm
|
||||
Result
|
||||
enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
return (Result) mraa_pwm_enable(m_pwm, 1);
|
||||
else
|
||||
return (Result) 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
|
||||
*/
|
||||
Result
|
||||
config_ms(int period, float duty)
|
||||
{
|
||||
return (Result) mraa_pwm_config_ms(m_pwm, period, duty);
|
||||
}
|
||||
/**
|
||||
* Set the period and duty (percent) of a PWM object.
|
||||
*
|
||||
* @param period as represented in ms.
|
||||
* @param duty percentage i.e. 50% = 0.5f
|
||||
* @return Result of operation
|
||||
*/
|
||||
Result
|
||||
config_percent(int period, float duty)
|
||||
{
|
||||
return (Result) mraa_pwm_config_percent(m_pwm, period, duty);
|
||||
}
|
||||
/**
|
||||
* Get the maximum pwm period in us
|
||||
*
|
||||
* @return max pwm in us
|
||||
* @return max PWM period in us
|
||||
*/
|
||||
int
|
||||
max_period()
|
||||
{
|
||||
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
|
||||
|
@@ -79,6 +79,20 @@ class Spi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spi Constructor, takes a pointer to a SPI context and initialises
|
||||
* the SPI class
|
||||
*
|
||||
* @param void * to SPI context
|
||||
*/
|
||||
Spi(void* spi_context)
|
||||
{
|
||||
m_spi = (mraa_spi_context) spi_context;
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument("Invalid SPI context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes spi bus
|
||||
*/
|
||||
@@ -127,10 +141,10 @@ class Spi
|
||||
* Write single byte to the SPI device
|
||||
*
|
||||
* @param data the byte to send
|
||||
* @return data received on the miso line
|
||||
* @return data received on the miso line or -1 in case of error
|
||||
*/
|
||||
uint16_t
|
||||
write_word(uint16_t data)
|
||||
int
|
||||
writeWord(uint16_t data)
|
||||
{
|
||||
return mraa_spi_write_word(m_spi, (uint16_t) data);
|
||||
}
|
||||
@@ -161,7 +175,7 @@ class Spi
|
||||
* @return uint8_t* data received on the miso line. Same length as passed in
|
||||
*/
|
||||
uint16_t*
|
||||
write_word(uint16_t* txBuf, int length)
|
||||
writeWord(uint16_t* txBuf, int length)
|
||||
{
|
||||
return mraa_spi_write_buf_word(m_spi, txBuf, length);
|
||||
}
|
||||
|
@@ -50,10 +50,16 @@ typedef enum {
|
||||
MRAA_INTEL_SOFIA_3GR = 10, /**< The Intel SoFIA 3GR */
|
||||
MRAA_INTEL_CHERRYHILLS = 11, /**< The Intel Braswell Cherryhills */
|
||||
MRAA_UP = 12, /**< The UP Board */
|
||||
MRAA_INTEL_GT_TUCHUCK = 13, /**< The Intel GT Tuchuck 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_MOCK_PLATFORM = 96, /**< Mock platform, which requires no real hardware */
|
||||
MRAA_JSON_PLATFORM = 97, /**< User initialised platform from json*/
|
||||
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 */
|
||||
@@ -203,7 +209,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;
|
||||
@@ -239,8 +247,6 @@ typedef enum {
|
||||
MRAA_UART_PARITY_SPACE = 4
|
||||
} mraa_uart_parity_t;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -46,7 +46,18 @@ typedef enum {
|
||||
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 */
|
||||
INTEL_UP = 12, /**< The UP Board */
|
||||
INTEL_GT_TUCHUCK = 13, /**< The Intel GT Board */
|
||||
|
||||
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;
|
||||
@@ -195,7 +206,9 @@ typedef enum {
|
||||
ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
|
||||
ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
|
||||
ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
|
||||
ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already 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;
|
||||
|
@@ -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"
|
||||
|
@@ -75,6 +75,20 @@ class Uart
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uart Constructor, takes a pointer to the UART context and initialises
|
||||
* the UART class
|
||||
*
|
||||
* @param void * to a UART context
|
||||
*/
|
||||
Uart(void* uart_context)
|
||||
{
|
||||
m_uart = (mraa_uart_context) uart_context;
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Invalid UART context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Uart destructor
|
||||
*/
|
||||
@@ -126,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);
|
||||
@@ -236,6 +255,19 @@ class Uart
|
||||
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:
|
||||
mraa_uart_context m_uart;
|
||||
};
|
||||
|
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;
|
||||
};
|
||||
}
|
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_search_module (PC_JSON-C QUIET json-c json)
|
||||
|
||||
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)
|
@@ -23,13 +23,13 @@ if (UV_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
# Now look for node. Flag an error if not found
|
||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
||||
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}/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/node)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
||||
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")
|
||||
|
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)
|
160
cmake/modules/OpenCVDetectPython.cmake
Normal file
160
cmake/modules/OpenCVDetectPython.cmake
Normal file
@@ -0,0 +1,160 @@
|
||||
# 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)
|
||||
|
||||
set(MIN_VER_PYTHON2 2.7)
|
||||
set(MIN_VER_PYTHON3 3.2)
|
||||
|
||||
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()
|
@@ -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) |
|
||||
|
@@ -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/`
|
||||
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:
|
||||
@@ -92,10 +92,6 @@ Building doc, this will require [SPHINX](http://sphinx-doc.org) &
|
||||
[Doxygen](http://doxygen.org):
|
||||
`-DBUILDDOC=ON`
|
||||
|
||||
Building with Python 3 (careful you need to clear CMake cache between Python
|
||||
version switches!)
|
||||
`-DBUILDPYTHON3=ON`
|
||||
|
||||
Override build architecture (this is useful because on x86 ARM code is not
|
||||
compiled so use this flag to force the target arch)
|
||||
`-DBUILDARCH=arm`
|
||||
@@ -172,7 +168,7 @@ You can get `cpack` to generate an IPK or RPM package fairly easily if you have
|
||||
the correct packaging tools
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
cmake -DIPK=ON -DCMAKE_INSTAL_PREFIX=/usr ..
|
||||
cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
make package
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
@@ -180,5 +176,5 @@ To use RPM simply enable the RPM option. You'll need `rpmbuild` installed on you
|
||||
build machine.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
cmake -DRPM=ON -DCMAKE_INSTAL_PREFIX=/usr ..
|
||||
cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
~~~~~~~~~~~~~
|
||||
|
@@ -5,6 +5,76 @@ 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.2.3**
|
||||
* Revert 1.2.1 binding.gyp changed that had side effect of enabling JSONPLAT in mraa.c
|
||||
* improve travis.ci to load mraa.node as compiled from make npmpkg target
|
||||
|
||||
**1.2.2**
|
||||
* remove jsonplat from prehashed npm builds (see docs/npm.md for details)
|
||||
* internal spelling fix
|
||||
|
||||
**1.2.1**
|
||||
* Fix npm pkg build - no other fix
|
||||
|
||||
**1.2.0**
|
||||
* JSON platform support
|
||||
* mock I2c functionality
|
||||
* Intel Grosse Tete PWM fix
|
||||
* AIO firmata bug fix
|
||||
|
||||
**1.1.2**
|
||||
* Mock platform support
|
||||
* mraa-i2c treats i2c buses by default as linux
|
||||
* grosse tete i2c fixes
|
||||
* travis now uses 14.04 instead of 12.04
|
||||
|
||||
**1.1.1**
|
||||
* IIO 4.6 kernel matrix support
|
||||
* Intel Grosse Tete radio led support
|
||||
* mraa_init_io() examples
|
||||
* MRAAPLATFORMFORCE fixes
|
||||
* fix python documentation
|
||||
|
||||
**1.1.0**
|
||||
* build python2 & python3 bindings
|
||||
* Intel Grosse Tete support
|
||||
* mraa_init_io() generic funtion
|
||||
* mraa-gpio fixes
|
||||
* edison PWM 0% improvements
|
||||
* iio location maping fix
|
||||
|
||||
**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
|
||||
@@ -18,7 +88,7 @@ they are listed here. Anything pre 0.2.x is ignored.
|
||||
|
||||
**0.9.3**
|
||||
* Intel edison detection much improved
|
||||
* ftdi ft4222 interupt improvement
|
||||
* ftdi ft4222 interrupt improvement
|
||||
* small fixes to java lib
|
||||
|
||||
**0.9.2**
|
||||
|
@@ -37,6 +37,10 @@ in libmraa:
|
||||
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
|
@@ -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')
|
||||
|
||||
```
|
||||
|
112
docs/grossetete.md
Normal file
112
docs/grossetete.md
Normal file
@@ -0,0 +1,112 @@
|
||||
Grosse Tete {#grossetete}
|
||||
===========
|
||||
|
||||
The Grosse Tete with the Tuchuck board is supported by Mraa
|
||||
|
||||
Revision Support
|
||||
----------------
|
||||
Tuchuck
|
||||
|
||||
Interface notes
|
||||
---------------
|
||||
|
||||
**SPI** Currently not working
|
||||
|
||||
**UART** Some pins are labelled as UARTs but are not configured in BIOS as UART
|
||||
so only available UART is on the FTDI header
|
||||
|
||||
Pin Mapping
|
||||
-----------
|
||||
|
||||
Tuchuck has two breakouts, breakout #1 is 1-40 whilst breakout2 is 41-80. The
|
||||
LEDs are numbered from 100-103.
|
||||
|
||||
| MRAA Number | Physical Pin | Function |
|
||||
|-------------|--------------|----------|
|
||||
| 1 | GPIO | GPIO |
|
||||
| 2 | SPP1RX | GPIO |
|
||||
| 3 | PMICRST | NONE |
|
||||
| 4 | SPP1TX | GPIO |
|
||||
| 5 | 19.2mhz | GPIO |
|
||||
| 6 | SPP1FS0 | GPIO |
|
||||
| 7 | UART0TX | GPIO |
|
||||
| 8 | SPP1FS2 | GPIO |
|
||||
| 9 | PWRGD | NONE |
|
||||
| 10 | SPP1CLK | GPIO |
|
||||
| 11 | I2C0SDA | I2C |
|
||||
| 12 | I2S1SDI | GPIO |
|
||||
| 13 | I2C0SCL | I2C |
|
||||
| 14 | I2S1SDO | GPIO |
|
||||
| 15 | I2C1SDA | I2C |
|
||||
| 16 | I2S1WS | GPIO |
|
||||
| 17 | I2C1SCL | I2C |
|
||||
| 18 | I2S1CLK | GPIO |
|
||||
| 19 | I2C2SDA | I2C |
|
||||
| 20 | I2S1MCL | GPIO |
|
||||
| 21 | I2C2SCL | I2CO |
|
||||
| 22 | UART1TX | UART |
|
||||
| 23 | I2S4SDO | NONE |
|
||||
| 24 | UART1RX | UART |
|
||||
| 25 | I2S4SDI | NONE |
|
||||
| 26 | PWM0 | GPIO PWM |
|
||||
| 27 | I2S4BLK | GPIO |
|
||||
| 28 | PWM1 | GPIO PWM |
|
||||
| 29 | I2S4WS | NONE |
|
||||
| 30 | PWM2 | GPIO PWM |
|
||||
| 31 | I2S3SDO | NONE |
|
||||
| 32 | PWM3 | GPIO PWM |
|
||||
| 33 | I2S3SDI | NONE |
|
||||
| 34 | 1.8V | NONE |
|
||||
| 35 | I2S4BLK | GPIO |
|
||||
| 36 | GND | NONE |
|
||||
| 37 | GND | NONE |
|
||||
| 38 | GND | NONE |
|
||||
| 39 | GND | NONE |
|
||||
| 40 | 3.3V | NONE |
|
||||
| 41 | GND | NONE |
|
||||
| 42 | 5V | NONE |
|
||||
| 43 | GND | NONE |
|
||||
| 44 | 5V | NONE |
|
||||
| 45 | GND | NONE |
|
||||
| 46 | 3.3V | NONE |
|
||||
| 47 | GND | NONE |
|
||||
| 48 | 3.3V | NONE |
|
||||
| 49 | GND | NONE |
|
||||
| 50 | 1.8V | NONE |
|
||||
| 51 | GPIO | GPIO |
|
||||
| 52 | 1.8V | NONE |
|
||||
| 53 | PANEL | GPIO |
|
||||
| 54 | GND | NONE |
|
||||
| 55 | PANEL | GPIO |
|
||||
| 56 | CAMERA | NONE |
|
||||
| 57 | PANEL | GPIO |
|
||||
| 58 | CAMERA | NONE |
|
||||
| 59 | SPP0FS0 | GPIO |
|
||||
| 60 | CAMERA | NONE |
|
||||
| 61 | SPP0FS1 | GPIO |
|
||||
| 62 | SPI_DAT | SPI |
|
||||
| 63 | SPP0FS2 | GPIO |
|
||||
| 64 | SPICLKB | GPIO SPI |
|
||||
| 65 | SPP0FS3 | GPIO |
|
||||
| 66 | SPICLKA | GPIO SPI |
|
||||
| 67 | SPP0TX | GPIO |
|
||||
| 68 | UART0RX | GPIO UART|
|
||||
| 69 | SPP0RX | GPIO |
|
||||
| 70 | UART0RT | GPIO UART|
|
||||
| 71 | I2C1SDA | GPIO I2C |
|
||||
| 72 | UART0CT | GPIO UART|
|
||||
| 73 | I2C1SCL | GPIO I2C |
|
||||
| 74 | UART1TX | GPIO UART|
|
||||
| 75 | I2C2SDA | GPIO I2C |
|
||||
| 76 | UART1RX | GPIO UART|
|
||||
| 77 | I2C1SCL | GPIO I2C |
|
||||
| 78 | UART1RT | GPIO UART|
|
||||
| 79 | RTC_CLK | GPIO |
|
||||
| 80 | UART1CT | GPIO UART|
|
||||
| 100 | LED100 | GPIO |
|
||||
| 101 | LED101 | GPIO |
|
||||
| 102 | LED102 | GPIO |
|
||||
| 103 | LED103 | GPIO |
|
||||
|
||||
To see a live pin mapping use the command:
|
||||
$ mraa-gpio list
|
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.
|
||||
|
@@ -46,6 +46,8 @@ Specific platform information for supported platforms is documented here:
|
||||
- @ref bananapi
|
||||
- @ref beaglebone
|
||||
- @ref nuc5
|
||||
- @ref up
|
||||
- @ref grossetete
|
||||
- @ref ft4222
|
||||
|
||||
## DEBUGGING
|
||||
|
@@ -47,6 +47,7 @@ Specific platform information for supported platforms is documented here:
|
||||
- @ref beaglebone
|
||||
- @ref nuc5
|
||||
- @ref up
|
||||
- @ref grossetete
|
||||
- @ref ft4222
|
||||
|
||||
## DEBUGGING
|
||||
|
92
docs/mock.md
Normal file
92
docs/mock.md
Normal file
@@ -0,0 +1,92 @@
|
||||
Mock platform {#mock}
|
||||
=============
|
||||
|
||||
Mocking capability allows libmraa user to work with the library without any real
|
||||
hardware available. Enabling this requires library recompilation with architecture
|
||||
override (see Building section below). When mock is enabled, library simulates
|
||||
actual HW operations at the backend so that for the application it looks
|
||||
like a usual board. Being implemented at the backend, the functionality is available
|
||||
in all language bindings libmraa supports.
|
||||
|
||||
Board configuration
|
||||
-------------------
|
||||
|
||||
This feature is yet in the experimental mode and not all functionality is available.
|
||||
Right now we simulate a single generic board with:
|
||||
* GPIO (without ISR)
|
||||
* ADC with 10 (std)/12 (max) bit resolution, which returns random values on read
|
||||
* Single I2C bus with one device at address 0x33 and 10 bytes of register space,
|
||||
which can be read or written in bytes or words (big-endian). Technically those
|
||||
registers are just an array of `uint8_t`, so you can treat them as 10 single-byte
|
||||
registers or 5 single-word ones or a mix thereof.
|
||||
|
||||
We plan to develop it further and all [contributions](../CONTRIBUTING.md) are more than welcome.
|
||||
|
||||
See the table below for pin layout and features
|
||||
|
||||
| MRAA Number | Pin Name | Notes |
|
||||
|-------------|----------|---------------------------------------|
|
||||
| 0 | GPIO0 | GPIO pin, no muxing, no ISR |
|
||||
| 1 | ADC0 | AIO pin, returns random value on read |
|
||||
| 2 | I2C0SDA | SDA pin for I2C0 bus |
|
||||
| 3 | I2C0SCL | SCL pin for I2C0 bus |
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
Generally all the building steps are the same as listed
|
||||
in the [main building guide](./building.md), you just need to set some specific
|
||||
CMake options.
|
||||
|
||||
### Linux
|
||||
|
||||
To build under Linux, follow standard instructions, just make sure to set
|
||||
the `-DBUILDARCH="MOCK"` CMake option.
|
||||
|
||||
### Windows
|
||||
|
||||
Mocking capability allows us to build and use libmraa under Windows. That helps
|
||||
if you e.g. don't want to leave your customary Windows-based Python IDE, but
|
||||
want to develop libmraa-based programs.
|
||||
|
||||
Building Node.js bindings was not yet tested under Windows as MSYS2
|
||||
does not have a ready-made package. Java was not tested either.
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
You'll need the following to build libmraa under Windows:
|
||||
|
||||
* [MSYS2](http://mingw-w64.org/doku.php/download/msys2) basic installation
|
||||
* Several additional packages, install them by running
|
||||
|
||||
```bash
|
||||
pacman -S cmake base-devel gcc git
|
||||
```
|
||||
|
||||
#### Compiling
|
||||
|
||||
The procedure is conceptually the same as under Linux - you first need to run
|
||||
CMake with specific options to generate makefiles and then run make to build everything.
|
||||
|
||||
* Run MSYS2 shell (not a MinGW one)
|
||||
* Clone the libmraa git repo (let's assume into `/home/test/mraa/mraa-src` dir)
|
||||
* Create a build directory outside of the clone one (let's say `/home/test/mraa/mraa-build`)
|
||||
* Run CMake, switching off unsupported options and enabling mock platform:
|
||||
|
||||
```bash
|
||||
cmake ../mraa-src/ -DBUILDARCH="MOCK" -DBUILDSWIGNODE=OFF -DENABLEEXAMPLES=OFF
|
||||
```
|
||||
|
||||
* Make, install and test:
|
||||
|
||||
```bash
|
||||
make clean && make install && make test
|
||||
```
|
||||
|
||||
All tests should pass.
|
||||
|
||||
**Note:** To have autocompletion in Python IDE, just point it to MSYS2's Python
|
||||
and make sure to specify any additional paths pointing to site-packages dir
|
||||
with mraa module if IDE requires that ("Interpreter Paths" in PyCharm).
|
||||
With the above settings the module will be installed into `/usr/local/lib/python2.7/site-packages`
|
||||
and the libmraa itself - into `/usr/local/bin`.
|
@@ -35,6 +35,18 @@ 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 ${CMAKE_INSTALL_DATADIR}/mraa/examples)
|
||||
|
@@ -19,3 +19,8 @@ target_link_libraries (Spi-pot mraa stdc++)
|
||||
target_link_libraries (Uart mraa stdc++)
|
||||
target_link_libraries (Isr-pin6 mraa stdc++)
|
||||
target_link_libraries (Iio-dummy mraa stdc++)
|
||||
|
||||
if (ONEWIRE)
|
||||
add_executable (UartOW UartOW.cpp)
|
||||
target_link_libraries (UartOW mraa stdc++)
|
||||
endif ()
|
||||
|
82
examples/c++/UartOW.cpp
Normal file
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]
|
68
examples/c++/initio.cpp
Normal file
68
examples/c++/initio.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mraa.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
// GPIO-PIN
|
||||
mraa::Gpio* gpio = mraa::initIo<mraa::Gpio>("gpio-1");
|
||||
// GPIO-RAW-RAWPIN
|
||||
mmraa::Gpio* gpioraw = mraa::initIo<mraa::Gpio>initIo("gpio-raw-131");
|
||||
// AIO-PIN
|
||||
mraa::Aio aio = mraa::initIo<mraa::Aio>("aio-0");
|
||||
// PWM-PIN
|
||||
mraa::Pwm pwm = mraa::initIo<mraa::Pwm>("pwm-6");
|
||||
// PWM-RAW-CHIPID-PIN
|
||||
mraa::Pwm pwmraw = mraa::initIo<mraa::Pwm>("pwm-raw-0,1");
|
||||
// UART-INDEX: the index is the one represented internally in the uart_dev array
|
||||
mraa::Uart uart = mraa::initIo<mraa::Uart>("uart-1");
|
||||
// UART-RAW-PATH
|
||||
mraa::Uart uartraw = mraa::initIo<mraa::Uart>("uart-raw-/dev/ttyS0");
|
||||
// SPI-INDEX: same as UART
|
||||
mraa::Spi spi = mraa::initIo<mraa::Spi>("spi-0");
|
||||
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
|
||||
mraa::Spi spiraw = mraa::initIo<mraa::Spi>("spi-raw-0-1");
|
||||
// I2C-INDEX: same as UART
|
||||
mraa::I2c i2c = mraa::initIo<mraa::I2c>("i2c-0");
|
||||
// I2C-RAW-BUS
|
||||
mraa::I2c i2craw = mraa::initIo<mraa::I2c>("i2c-raw-0");
|
||||
|
||||
// FREE STUFF
|
||||
delete gpio;
|
||||
delete gpioraw;
|
||||
delete aio;
|
||||
delete pwm;
|
||||
delete pwmraw;
|
||||
delete uart;
|
||||
delete uartraw;
|
||||
delete spi;
|
||||
delete spiraw;
|
||||
delete i2c;
|
||||
delete i2craw;
|
||||
}
|
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;
|
||||
}
|
@@ -32,8 +32,6 @@ int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
const char* board_name = mraa_get_platform_name();
|
||||
int i2c_bus, i, i2c_adapter;
|
||||
|
||||
fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);
|
||||
|
||||
mraa_deinit();
|
||||
|
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);
|
||||
|
||||
}
|
69
examples/initio.c
Normal file
69
examples/initio.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
// GPIO-PIN
|
||||
mraa_gpio_context gpio = (mraa_gpio_context) init_io("gpio-1");
|
||||
// GPIO-RAW-RAWPIN
|
||||
mraa_gpio_context gpioraw = (mraa_gpio_context) init_io("gpio-raw-131");
|
||||
// AIO-PIN
|
||||
mraa_aio_context aio = (mraa_aio_context) init_io("aio-0");
|
||||
// PWM-PIN
|
||||
mraa_pwm_context pwm = (mraa_pwm_context) init_io("pwm-6");
|
||||
// PWM-RAW-CHIPID-PIN
|
||||
mraa_pwm_context pwmraw= (mraa_pwm_context) init_io("pwm-raw-0,1");
|
||||
// UART-INDEX: the index is the one represented internally in the uart_dev array
|
||||
mraa_uart_context uart = (mraa_uart_context) init_io("uart-1");
|
||||
// UART-RAW-PATH
|
||||
mraa_uart_context uartraw = (mraa_uart_context) init_io("uart-raw-/dev/ttyS0");
|
||||
// SPI-INDEX: same as UART
|
||||
mraa_spi_context spi = (mraa_spi_context) init_io("spi-0");
|
||||
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
|
||||
mraa_spi_context spiraw = (mraa_spi_context) init_io("spi-raw-0-1");
|
||||
// I2C-INDEX: same as UART
|
||||
mraa_i2c_context i2c = (mraa_i2c_context) init_io("i2c-0");
|
||||
// I2C-RAW-BUS
|
||||
mraa_i2c_context i2craw = (mraa_i2c_context) init_io("i2c-raw-0");
|
||||
|
||||
|
||||
// FREE STUFF
|
||||
mraa_gpio_close(gpio);
|
||||
mraa_gpio_close(gpioraw);
|
||||
mraa_aio_close(aio);
|
||||
mraa_pwm_close(pwm);
|
||||
mraa_pwm_close(pwmraw);
|
||||
mraa_uart_close(uart);
|
||||
mraa_uart_close(uartraw);
|
||||
mraa_spi_close(spi);
|
||||
mraa_spi_close(spiraw);
|
||||
mraa_i2c_close(i2c);
|
||||
mraa_i2c_close(i2craw);
|
||||
}
|
@@ -50,7 +50,7 @@ public class BlinkIO {
|
||||
if (argv.length == 0) {
|
||||
System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN);
|
||||
} else {
|
||||
iopin = Integer.valueOf(argv[0], DEFAULT_IOPIN);
|
||||
iopin = Integer.valueOf(argv[0]);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@@ -22,6 +22,9 @@
|
||||
* 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;
|
||||
@@ -37,6 +40,7 @@ public class Isr {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
int pin = 6;
|
||||
if (argv.length == 1) {
|
||||
@@ -45,21 +49,37 @@ public class Isr {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
System.out.println("Starting ISR for pin " + Integer.toString(pin));
|
||||
Gpio gpio = new Gpio(pin);
|
||||
|
||||
Runnable callback = new JavaCallback();
|
||||
|
||||
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);
|
||||
while (true)
|
||||
Thread.sleep(999999);
|
||||
};
|
||||
try {
|
||||
String input = console.readLine();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
gpio.isrExit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JavaCallback implements Runnable {
|
||||
private Gpio gpio;
|
||||
|
||||
public JavaCallback(Gpio gpio) {
|
||||
this.gpio = gpio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Gpio level changed");
|
||||
String pin = Integer.toString(gpio.getPin(true));
|
||||
String level = Integer.toString(gpio.read());
|
||||
System.out.println("Pin " + pin + " = " + level);
|
||||
}
|
||||
}
|
||||
|
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");
|
@@ -31,8 +31,10 @@ const rl = readline.createInterface({
|
||||
});
|
||||
|
||||
function printUsage() {
|
||||
console.log("version Print version");
|
||||
console.log("get pin Get pin value");
|
||||
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() {
|
||||
@@ -55,17 +57,22 @@ function getPin() {
|
||||
}
|
||||
|
||||
function onPinLevelChange() {
|
||||
console.log('gpio change');
|
||||
console.log('gpio level change');
|
||||
}
|
||||
|
||||
function monitorPin() {
|
||||
var pinNumber = arguments[0];
|
||||
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();
|
||||
});
|
||||
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;
|
||||
|
48
examples/javascript/initio.js
Normal file
48
examples/javascript/initio.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@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 m = require('mraa');
|
||||
|
||||
// GPIO-PIN
|
||||
m.gpioFromDesc("gpio-1");
|
||||
// GPIO-RAW-RAWPIN
|
||||
m.gpioFromDesc("gpio-raw-131");
|
||||
// AIO-PIN
|
||||
m.aioFromDesc("aio-1");
|
||||
//PWM-PIN
|
||||
m.pwmFromDesc("pwm-6");
|
||||
// PWM-RAW-CHIPID-PIN
|
||||
m.pwmFromDesc("pwm-raw-0-1")
|
||||
// UART-INDEX: the index is the one represented internally in the uart_dev array
|
||||
m.uartFromDesc("uart-0");
|
||||
// UART-RAW-PATH
|
||||
m.uartFromDesc("uart-raw-/dev/ttyS0");
|
||||
// SPI-INDEX: same as UART
|
||||
m.spiFromDesc("spi-0");
|
||||
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
|
||||
m.spiFromDesc("spi-raw-0-1");
|
||||
// I2C-INDEX: same as UART
|
||||
m.i2cFromDesc("i2c-0");
|
||||
// I2C-RAW-BUS
|
||||
m.i2cFromDesc("i2c-raw-0");
|
@@ -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)
|
||||
|
@@ -67,7 +67,7 @@ list_platform_pins(uint8_t platform_offset)
|
||||
for (i = 0; i < pin_count; ++i) {
|
||||
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) {
|
||||
if (strcmp(pin_name, "INVALID") != 0 && mraa_pin_mode_test(pin_id, MRAA_PIN_VALID)) {
|
||||
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))
|
||||
@@ -97,13 +97,19 @@ list_pins()
|
||||
if (pin_count == 0) {
|
||||
fprintf(stdout, "No Pins\n");
|
||||
}
|
||||
return pin_count;
|
||||
}
|
||||
|
||||
|
||||
mraa_result_t
|
||||
gpio_set(int pin, int level, mraa_boolean_t raw)
|
||||
{
|
||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
||||
mraa_gpio_context gpio;
|
||||
if (raw) {
|
||||
gpio = mraa_gpio_init_raw(pin);
|
||||
}
|
||||
else {
|
||||
gpio = mraa_gpio_init(pin);
|
||||
}
|
||||
if (gpio != NULL) {
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
|
||||
if (raw != 0) {
|
||||
|
@@ -65,24 +65,13 @@ print_bus(mraa_board_t* board)
|
||||
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";
|
||||
busType = "linux";
|
||||
bus = i;
|
||||
break;
|
||||
}
|
||||
int id = board->i2c_bus[i].bus_id;
|
||||
|
73
examples/platform/turbotjson.json
Normal file
73
examples/platform/turbotjson.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"platform":[
|
||||
{ "id":300,
|
||||
"name":"Turbot",
|
||||
"pin_count": 28,
|
||||
"gpio_count": 28,
|
||||
"i2c_count": 1,
|
||||
"aio_count": 0,
|
||||
"spi_count": 1,
|
||||
"uart_count": 1,
|
||||
"pwmDefPeriod":500,
|
||||
"pwmMaxPeriod":1000000000,
|
||||
"pwmMinPeriod":1
|
||||
}
|
||||
],
|
||||
"layout":[
|
||||
{"label": "INVALID", "invalid": true},
|
||||
{"label": "GND"},
|
||||
{"label": "GND"},
|
||||
{"label": "5v"},
|
||||
{"label": "3.3v"},
|
||||
{"label": "SPI_CS"},
|
||||
{"label": "UART1TX"},
|
||||
{"label": "SPIMISO"},
|
||||
{"label": "UART1RX"},
|
||||
{"label": "SPIMOSI"},
|
||||
{"label": "UART1CT"},
|
||||
{"label": "SPI_CLK"},
|
||||
{"label": "UART1RT"},
|
||||
{"label": "I2C_SCL"},
|
||||
{"label": "I2S_CLK"},
|
||||
{"label": "I2C_SDA"},
|
||||
{"label": "I2S_FRM"},
|
||||
{"label": "UART2TX"},
|
||||
{"label": "I2S_DO"},
|
||||
{"label": "UART2RX"},
|
||||
{"label": "I2S_DI"},
|
||||
{"label": "S5_0"},
|
||||
{"label": "PWM0"},
|
||||
{"label": "S5_1"},
|
||||
{"label": "PWM1"},
|
||||
{"label": "S5_4"},
|
||||
{"label": "I2S_MCLK"},
|
||||
{"label": "S5_22"}
|
||||
],
|
||||
"GPIO":[
|
||||
{ "index": 10, "rawpin": 483 },
|
||||
{ "index": 12, "rawpin": 482 },
|
||||
{ "index": 14, "rawpin": 472 },
|
||||
{ "index": 16, "rawpin": 473 },
|
||||
{ "index": 18, "rawpin": 475 },
|
||||
{ "index": 20, "rawpin": 474 },
|
||||
{ "index": 21, "rawpin": 338 },
|
||||
{ "index": 23, "rawpin": 339 },
|
||||
{ "index": 25, "rawpin": 340 },
|
||||
{ "index": 26, "rawpin": 509 },
|
||||
{ "index": 27, "rawpin": 360 }
|
||||
],
|
||||
"I2C": [
|
||||
{ "sclpin":13, "sdapin":15, "rawpin": 0, "index": 0, "default":true }
|
||||
],
|
||||
"PWM": [
|
||||
{ "index":22, "rawpin":0, "chipID":0},
|
||||
{ "index":24, "rawpin":0, "chipID":1 }
|
||||
],
|
||||
"SPI": [
|
||||
{ "index":0, "chipID": 0, "clock": 11, "miso": 7, "mosi": 9, "chipselect": 5, "default": true}
|
||||
],
|
||||
"UART":[
|
||||
{ "index":0, "chipID":0, "rawpin":0, "path":"/dev/ttyS0", "default":true}
|
||||
]
|
||||
}
|
29
examples/python/firmata.py
Normal file
29
examples/python/firmata.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# 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.
|
||||
|
||||
import mraa
|
||||
|
||||
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)
|
||||
|
48
examples/python/initio.py
Normal file
48
examples/python/initio.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/bin/usr/env python
|
||||
|
||||
# Author: Houman Brinjcargorabi <houman.brinjcargorabi@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 as m
|
||||
|
||||
# GPIO-PIN
|
||||
m.gpioFromDesc("gpio-1");
|
||||
# GPIO-RAW-RAWPIN
|
||||
m.gpioFromDesc("gpio-raw-131");
|
||||
# AIO-PIN
|
||||
m.aioFromDesc("aio-1");
|
||||
# PWM-PIN
|
||||
m.pwmFromDesc("pwm-6");
|
||||
# PWM-RAW-CHIPID-PIN
|
||||
m.pwmFromDesc("pwm-raw-0-1")
|
||||
# UART-INDEX: the index is the one represented internally in the uart_dev array
|
||||
m.uartFromDesc("uart-0");
|
||||
# UART-RAW-PATH
|
||||
m.uartFromDesc("uart-raw-/dev/ttyS0");
|
||||
# SPI-INDEX: same as UART
|
||||
m.spiFromDesc("spi-0");
|
||||
# SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
|
||||
m.spiFromDesc("spi-raw-0-1");
|
||||
# I2C-INDEX: same as UART
|
||||
m.i2cFromDesc("i2c-0");
|
||||
# I2C-RAW-BUS
|
||||
m.i2cFromDesc("i2c-raw-0");
|
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)
|
526
imraa/imraa.c
Normal file
526
imraa/imraa.c
Normal file
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* 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 <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
|
114
include/firmata/firmata.h
Normal file
114
include/firmata/firmata.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
* Copyright (c) 2015 Jules Dourlens (jdourlens@gmail.com)
|
||||
*
|
||||
* 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.h"
|
||||
|
||||
#define MODE_INPUT 0x00
|
||||
#define MODE_OUTPUT 0x01
|
||||
#define MODE_ANALOG 0x02
|
||||
#define MODE_PWM 0x03
|
||||
#define MODE_SERVO 0x04
|
||||
#define MODE_SHIFT 0x05
|
||||
#define MODE_I2C 0x06
|
||||
|
||||
#define LOW 0
|
||||
#define HIGH 1
|
||||
|
||||
#define FIRMATA_START_SYSEX 0xF0 // start a MIDI Sysex message
|
||||
#define FIRMATA_END_SYSEX 0xF7 // end a MIDI Sysex message
|
||||
#define FIRMATA_PIN_MODE_QUERY 0x72 // ask for current and supported pin modes
|
||||
#define FIRMATA_PIN_MODE_RESPONSE 0x73 // reply with current and supported pin modes
|
||||
#define FIRMATA_PIN_STATE_QUERY 0x6D
|
||||
#define FIRMATA_PIN_STATE_RESPONSE 0x6E
|
||||
#define FIRMATA_CAPABILITY_QUERY 0x6B
|
||||
#define FIRMATA_CAPABILITY_RESPONSE 0x6C
|
||||
#define FIRMATA_ANALOG_MAPPING_QUERY 0x69
|
||||
#define FIRMATA_ANALOG_MAPPING_RESPONSE 0x6A
|
||||
|
||||
#define FIRMATA_DIGITAL_MESSAGE 0x90 // send data for a digital pin
|
||||
#define FIRMATA_ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
|
||||
#define FIRMATA_ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
|
||||
#define FIRMATA_REPORT_ANALOG 0xC0 // enable analog input by pin #
|
||||
#define FIRMATA_REPORT_DIGITAL 0xD0 // enable digital input by port pair
|
||||
|
||||
#define FIRMATA_I2C_CONFIG 0x78
|
||||
#define FIRMATA_I2C_REPLY 0x77
|
||||
#define FIRMATA_I2C_REQUEST 0x76
|
||||
|
||||
#define I2C_MODE_WRITE 0x00
|
||||
#define I2C_MODE_READ 0x01
|
||||
#define I2C_CONTINUOUSREAD 0x02
|
||||
#define I2C_STOP_READING 0x03
|
||||
|
||||
#define FIRMATA_SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc
|
||||
|
||||
#define FIRMATA_REPORT_VERSION 0xF9 // report protocol version
|
||||
#define FIRMATA_SYSTEM_RESET 0xFF // reset from MIDI
|
||||
|
||||
#define FIRMATA_START_SYSEX 0xF0 // start a MIDI Sysex message
|
||||
#define FIRMATA_END_SYSEX 0xF7 // end a MIDI Sysex message
|
||||
|
||||
// extended command set using sysex (0-127/0x00-0x7F)
|
||||
/* 0x00-0x0F reserved for custom commands */
|
||||
#define FIRMATA_SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
|
||||
#define FIRMATA_STRING 0x71 // a string message with 14-bits per char
|
||||
#define FIRMATA_REPORT_FIRMWARE 0x79 // report name and version of the firmware
|
||||
#define FIRMATA_SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
|
||||
#define FIRMATA_SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
|
||||
|
||||
#define FIRMATA_MSG_LEN 1024
|
||||
|
||||
typedef struct s_pin {
|
||||
uint8_t mode;
|
||||
uint8_t analog_channel;
|
||||
uint64_t supported_modes;
|
||||
uint32_t value;
|
||||
} t_pin;
|
||||
|
||||
typedef struct s_firmata {
|
||||
mraa_uart_context uart;
|
||||
t_pin pins[128];
|
||||
int i2cmsg[256][256];
|
||||
int parse_command_len;
|
||||
int parse_count;
|
||||
uint8_t parse_buff[FIRMATA_MSG_LEN];
|
||||
int isReady;
|
||||
char firmware[140];
|
||||
uint8_t dev_count;
|
||||
struct _firmata** devs;
|
||||
} t_firmata;
|
||||
|
||||
t_firmata* firmata_new(const char* name);
|
||||
void firmata_initPins(t_firmata* firmata);
|
||||
int firmata_askFirmware(t_firmata* firmata);
|
||||
int firmata_pinMode(t_firmata* firmata, int pin, int mode);
|
||||
int firmata_digitalWrite(t_firmata* firmata, int pin, int value);
|
||||
int firmata_analogWrite(t_firmata* firmata, int pin, int value);
|
||||
int firmata_analogRead(t_firmata* firmata, int pin);
|
||||
int firmata_pull(t_firmata* firmata);
|
||||
void firmata_parse(t_firmata* firmata, const uint8_t* buf, int len);
|
||||
void firmata_endParse(t_firmata* firmata);
|
||||
void firmata_close(t_firmata* firmata);
|
38
include/firmata/firmata_mraa.h
Normal file
38
include/firmata/firmata_mraa.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
mraa_platform_t mraa_firmata_platform(mraa_board_t* board, const char* uart_dev);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
46
include/java/mraajni.h
Normal file
46
include/java/mraajni.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 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
|
||||
* "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 <jni.h>
|
||||
#include "mraa/types.h"
|
||||
|
||||
// location for defining JNI version to use
|
||||
#define JNI_REQUIRED_VERSION JNI_VERSION_1_6
|
||||
|
||||
void mraa_java_set_jvm(JavaVM* vm);
|
||||
void mraa_java_isr_callback(void* args);
|
||||
mraa_result_t mraa_java_attach_thread();
|
||||
void mraa_java_detach_thread();
|
||||
void* mraa_java_create_global_ref(void* args);
|
||||
void mraa_java_delete_global_ref(void* ref);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -28,6 +28,8 @@ typedef struct {
|
||||
typedef void (*__kernel_sighandler_t)(int);
|
||||
typedef int __kernel_key_t;
|
||||
typedef int __kernel_mqd_t;
|
||||
#if !defined(MSYS)
|
||||
#include <asm/posix_types.h>
|
||||
#endif
|
||||
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
|
||||
#endif
|
||||
|
58
include/linux/spi_kernel_headers.h
Normal file
58
include/linux/spi_kernel_headers.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This header was manually generated from a Linux kernel header
|
||||
* linux/spi/spidev.h, to make information necessary for compilation
|
||||
* to be available under MSYS. It contains only constants,
|
||||
* structures, and macros generated from the original header, and thus,
|
||||
* contains no copyrightable information.
|
||||
*/
|
||||
#ifndef _SPI_KERNEL_HEADERS_H
|
||||
#define _SPI_KERNEL_HEADERS_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define SPI_CPHA 0x01
|
||||
#define SPI_CPOL 0x02
|
||||
|
||||
#define SPI_MODE_0 (0|0)
|
||||
#define SPI_MODE_1 (0|SPI_CPHA)
|
||||
#define SPI_MODE_2 (SPI_CPOL|0)
|
||||
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
|
||||
|
||||
#define SPI_IOC_MAGIC 'k'
|
||||
|
||||
struct spi_ioc_transfer {
|
||||
__u64 tx_buf;
|
||||
__u64 rx_buf;
|
||||
|
||||
__u32 len;
|
||||
__u32 speed_hz;
|
||||
|
||||
__u16 delay_usecs;
|
||||
__u8 bits_per_word;
|
||||
__u8 cs_change;
|
||||
__u8 tx_nbits;
|
||||
__u8 rx_nbits;
|
||||
__u16 pad;
|
||||
};
|
||||
|
||||
#define SPI_MSGSIZE(N) \
|
||||
((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
|
||||
? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
|
||||
#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
|
||||
|
||||
#define SPI_IOC_RD_MODE _IOR(SPI_IOC_MAGIC, 1, __u8)
|
||||
#define SPI_IOC_WR_MODE _IOW(SPI_IOC_MAGIC, 1, __u8)
|
||||
|
||||
#define SPI_IOC_RD_LSB_FIRST _IOR(SPI_IOC_MAGIC, 2, __u8)
|
||||
#define SPI_IOC_WR_LSB_FIRST _IOW(SPI_IOC_MAGIC, 2, __u8)
|
||||
|
||||
#define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8)
|
||||
#define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8)
|
||||
|
||||
#define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32)
|
||||
#define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32)
|
||||
|
||||
#define SPI_IOC_RD_MODE32 _IOR(SPI_IOC_MAGIC, 5, __u32)
|
||||
#define SPI_IOC_WR_MODE32 _IOW(SPI_IOC_MAGIC, 5, __u32)
|
||||
|
||||
#endif
|
40
include/mock/mock_board.h
Normal file
40
include/mock/mock_board.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MRAA_MOCK_PINCOUNT 4
|
||||
|
||||
mraa_board_t*
|
||||
mraa_mock_board();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
44
include/mock/mock_board_aio.h
Normal file
44
include/mock/mock_board_aio.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_aio_init_internal_replace(mraa_aio_context dev, int pin);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_aio_close_replace(mraa_aio_context dev);
|
||||
|
||||
int
|
||||
mraa_mock_aio_read_replace(mraa_aio_context dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
65
include/mock/mock_board_gpio.h
Normal file
65
include/mock/mock_board_gpio.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_init_internal_replace(mraa_gpio_context dev, int pin);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_close_replace(mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_read_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t* dir);
|
||||
|
||||
int
|
||||
mraa_mock_gpio_read_replace(mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_write_replace(mraa_gpio_context dev, int value);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_isr_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_isr_exit_replace(mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
81
include/mock/mock_board_i2c.h
Normal file
81
include/mock/mock_board_i2c.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
// Mock I2C device address
|
||||
#define MOCK_I2C_DEV_ADDR 0x33
|
||||
// Mock I2C device data registers block length in bytes. Our code assumes it's >= 1.
|
||||
#define MOCK_I2C_DEV_DATA_LEN 10
|
||||
// Initial value for each byte in the mock I2C device data registers
|
||||
#define MOCK_I2C_DEV_DATA_INIT_BYTE 0xAB
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_init_bus_replace(mraa_i2c_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_stop_replace(mraa_i2c_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_set_frequency_replace(mraa_i2c_context dev, mraa_i2c_mode_t mode);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_address_replace(mraa_i2c_context dev, uint8_t addr);
|
||||
|
||||
int
|
||||
mraa_mock_i2c_read_replace(mraa_i2c_context dev, uint8_t* data, int length);
|
||||
|
||||
int
|
||||
mraa_mock_i2c_read_byte_replace(mraa_i2c_context dev);
|
||||
|
||||
int
|
||||
mraa_mock_i2c_read_byte_data_replace(mraa_i2c_context dev, uint8_t command);
|
||||
|
||||
int
|
||||
mraa_mock_i2c_read_bytes_data_replace(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
|
||||
|
||||
int
|
||||
mraa_mock_i2c_read_word_data_replace(mraa_i2c_context dev, uint8_t command);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_write_replace(mraa_i2c_context dev, const uint8_t* data, int length);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_write_byte_replace(mraa_i2c_context dev, const uint8_t data);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_write_byte_data_replace(mraa_i2c_context dev, const uint8_t data, const uint8_t command);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -37,6 +37,7 @@ typedef struct {
|
||||
mraa_result_t (*gpio_init_post) (mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t (*gpio_close_pre) (mraa_gpio_context dev);
|
||||
mraa_result_t (*gpio_close_replace) (mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t (*gpio_mode_replace) (mraa_gpio_context dev, mraa_gpio_mode_t mode);
|
||||
mraa_result_t (*gpio_mode_pre) (mraa_gpio_context dev, mraa_gpio_mode_t mode);
|
||||
@@ -47,6 +48,7 @@ typedef struct {
|
||||
mraa_result_t (*gpio_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
|
||||
mraa_result_t (*gpio_dir_pre) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
|
||||
mraa_result_t (*gpio_dir_post) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
|
||||
mraa_result_t (*gpio_read_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t *dir);
|
||||
|
||||
int (*gpio_read_replace) (mraa_gpio_context dev);
|
||||
mraa_result_t (*gpio_write_replace) (mraa_gpio_context dev, int value);
|
||||
@@ -55,6 +57,8 @@ typedef struct {
|
||||
mraa_result_t (*gpio_mmap_setup) (mraa_gpio_context dev, mraa_boolean_t en);
|
||||
mraa_result_t (*gpio_interrupt_handler_init_replace) (mraa_gpio_context dev);
|
||||
mraa_result_t (*gpio_wait_interrupt_replace) (mraa_gpio_context dev);
|
||||
mraa_result_t (*gpio_isr_replace) (mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args);
|
||||
mraa_result_t (*gpio_isr_exit_replace) (mraa_gpio_context dev);
|
||||
|
||||
mraa_result_t (*i2c_init_pre) (unsigned int bus);
|
||||
mraa_result_t (*i2c_init_bus_replace) (mraa_i2c_context dev);
|
||||
@@ -63,9 +67,9 @@ typedef struct {
|
||||
mraa_result_t (*i2c_set_frequency_replace) (mraa_i2c_context dev, mraa_i2c_mode_t mode);
|
||||
mraa_result_t (*i2c_address_replace) (mraa_i2c_context dev, uint8_t addr);
|
||||
int (*i2c_read_replace) (mraa_i2c_context dev, uint8_t* data, int length);
|
||||
uint8_t (*i2c_read_byte_replace) (mraa_i2c_context dev);
|
||||
uint8_t (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
|
||||
uint16_t (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
|
||||
int (*i2c_read_byte_replace) (mraa_i2c_context dev);
|
||||
int (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
|
||||
int (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
|
||||
int (*i2c_read_bytes_data_replace) (mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
|
||||
mraa_result_t (*i2c_write_replace) (mraa_i2c_context dev, const uint8_t* data, int length);
|
||||
mraa_result_t (*i2c_write_byte_replace) (mraa_i2c_context dev, uint8_t data);
|
||||
@@ -73,14 +77,23 @@ typedef struct {
|
||||
mraa_result_t (*i2c_write_word_data_replace) (mraa_i2c_context dev, const uint16_t data, const uint8_t command);
|
||||
mraa_result_t (*i2c_stop_replace) (mraa_i2c_context dev);
|
||||
|
||||
mraa_result_t (*aio_init_internal_replace) (mraa_aio_context dev, int pin);
|
||||
mraa_result_t (*aio_close_replace) (mraa_aio_context dev);
|
||||
int (*aio_read_replace) (mraa_aio_context dev);
|
||||
mraa_result_t (*aio_get_valid_fp) (mraa_aio_context dev);
|
||||
mraa_result_t (*aio_init_pre) (unsigned int aio);
|
||||
mraa_result_t (*aio_init_post) (mraa_aio_context dev);
|
||||
|
||||
mraa_pwm_context (*pwm_init_replace) (int pin);
|
||||
mraa_pwm_context (*pwm_init_internal_replace) (void* func_table, int pin);
|
||||
mraa_result_t (*pwm_init_pre) (int pin);
|
||||
mraa_result_t (*pwm_init_post) (mraa_pwm_context pwm);
|
||||
mraa_result_t (*pwm_period_replace) (mraa_pwm_context dev, int period);
|
||||
float (*pwm_read_replace) (mraa_pwm_context dev);
|
||||
mraa_result_t (*pwm_write_replace) (mraa_pwm_context dev, float duty);
|
||||
mraa_result_t (*pwm_write_pre) (mraa_pwm_context dev, float percentage);
|
||||
mraa_result_t (*pwm_enable_replace) (mraa_pwm_context dev, int enable);
|
||||
mraa_result_t (*pwm_enable_pre) (mraa_pwm_context dev, int enable);
|
||||
|
||||
mraa_result_t (*spi_init_pre) (int bus);
|
||||
mraa_result_t (*spi_init_post) (mraa_spi_context spi);
|
||||
|
@@ -34,9 +34,12 @@ extern "C" {
|
||||
#include "common.h"
|
||||
#include "mraa_internal_types.h"
|
||||
#include "mraa_adv_func.h"
|
||||
#include "mraa_lang_func.h"
|
||||
|
||||
extern mraa_board_t* plat;
|
||||
extern char* platform_name;
|
||||
extern mraa_iio_info_t* plat_iio;
|
||||
extern mraa_lang_func_t* lang_func;
|
||||
|
||||
/**
|
||||
* Takes in pin information and sets up the multiplexors.
|
||||
@@ -60,6 +63,13 @@ mraa_platform_t mraa_x86_platform();
|
||||
*/
|
||||
mraa_platform_t mraa_arm_platform();
|
||||
|
||||
/**
|
||||
* setup a mock platform
|
||||
*
|
||||
* @return mraa_platform_t of the init'ed platform
|
||||
*/
|
||||
mraa_platform_t mraa_mock_platform();
|
||||
|
||||
/**
|
||||
* runtime detect running usb platform extender
|
||||
*
|
||||
@@ -130,6 +140,24 @@ mraa_boolean_t mraa_link_targets(const char* filename, const char* targetname);
|
||||
*/
|
||||
int mraa_find_i2c_bus(const char* devname, int startfrom);
|
||||
|
||||
#if defined(IMRAA)
|
||||
/**
|
||||
* read Imraa subplatform lock file, caller is responsible to free return
|
||||
* struct array
|
||||
*
|
||||
* @param imraa lockfile location
|
||||
* @return the number of subplatforms added
|
||||
*/
|
||||
uint32_t mraa_add_from_lockfile(const char* imraa_lock_file);
|
||||
|
||||
/**
|
||||
* Internal imraa init function
|
||||
*
|
||||
* @return mraa_result_t indicating success
|
||||
*/
|
||||
mraa_result_t imraa_init();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Copyright (c) 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
|
||||
@@ -40,6 +40,57 @@
|
||||
#define MRAA_IO_SETUP_FAILURE -2
|
||||
#define MRAA_NO_SUCH_IO -1
|
||||
|
||||
// Json platform keys
|
||||
#define INDEX_KEY "index"
|
||||
#define NAME_KEY "name"
|
||||
#define PIN_COUNT_KEY "pin_count"
|
||||
#define GPIO_COUNT_KEY "gpio_count"
|
||||
#define AIO_COUNT_KEY "aio_count"
|
||||
#define SPI_COUNT_KEY "spi_count"
|
||||
#define I2C_COUNT_KEY "i2c_count"
|
||||
#define UART_COUNT_KEY "uart_count"
|
||||
#define PWMDEFAULT_KEY "pwmDefPeriod"
|
||||
#define PWMMAX_KEY "pwmMaxPeriod"
|
||||
#define PWMMIN_KEY "pwmMinPeriod"
|
||||
#define LABEL_KEY "label"
|
||||
#define DEFAULT_KEY "default"
|
||||
#define INVALID_KEY "invalid"
|
||||
#define SCLPIN_KEY "sclpin"
|
||||
#define SDAPIN_KEY "sdapin"
|
||||
#define CHIP_ID_KEY "chipID"
|
||||
#define RAW_PIN_KEY "rawpin"
|
||||
#define RXPIN_KEY "rx"
|
||||
#define TXPIN_KEY "tx"
|
||||
#define UART_PATH_KEY "path"
|
||||
#define CLOCK_KEY "clock"
|
||||
#define MISO_KEY "miso"
|
||||
#define MOSI_KEY "mosi"
|
||||
#define CS_KEY "chipselect"
|
||||
#define PIN_KEY "pin"
|
||||
#define IO_KEY "layout"
|
||||
#define PLATFORM_KEY "platform"
|
||||
|
||||
// IO keys
|
||||
#define GPIO_KEY "GPIO"
|
||||
#define SPI_KEY "SPI"
|
||||
#define UART_KEY "UART"
|
||||
#define I2C_KEY "I2C"
|
||||
#define PWM_KEY "PWM"
|
||||
#define AIO_KEY "AIO"
|
||||
|
||||
#define MRAA_JSONPLAT_ENV_VAR "MRAA_JSON_PLATFORM"
|
||||
|
||||
#ifdef FIRMATA
|
||||
struct _firmata {
|
||||
/*@*/
|
||||
uint8_t feature; /**< the feature */
|
||||
uint8_t index;
|
||||
void (* isr)(uint8_t*, int); /**< the feature response request */
|
||||
mraa_boolean_t added; /**< boolean to set if responses already set in devs array */
|
||||
/*@}*/
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A structure representing a gpio pin.
|
||||
*/
|
||||
@@ -48,8 +99,8 @@ struct _gpio {
|
||||
int pin; /**< the pin number, as known to the os. */
|
||||
int phy_pin; /**< pin passed to clean init. -1 none and raw*/
|
||||
int value_fp; /**< the file pointer to the value of the gpio */
|
||||
void (* isr)(void *); /**< the interupt service request */
|
||||
void *isr_args; /**< args return when interupt service request triggered */
|
||||
void (* isr)(void *); /**< the interrupt service request */
|
||||
void *isr_args; /**< args return when interrupt service request triggered */
|
||||
pthread_t thread_id; /**< the isr handler thread id */
|
||||
int isr_value_fp; /**< the isr file pointer on the value */
|
||||
#ifndef HAVE_PTHREAD_CANCEL
|
||||
@@ -60,6 +111,10 @@ struct _gpio {
|
||||
mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
|
||||
int (*mmap_read) (mraa_gpio_context dev);
|
||||
mraa_adv_func_t* advance_func; /**< override function table */
|
||||
#if defined(MOCKPLAT)
|
||||
mraa_gpio_dir_t mock_dir; /**< mock direction of the pin */
|
||||
int mock_state; /**< mock state of the pin */
|
||||
#endif
|
||||
/*@}*/
|
||||
};
|
||||
|
||||
@@ -74,6 +129,11 @@ struct _i2c {
|
||||
unsigned long funcs; /**< /dev/i2c-* device capabilities as per https://www.kernel.org/doc/Documentation/i2c/functionality */
|
||||
void *handle; /**< generic handle for non-standard drivers that don't use file descriptors */
|
||||
mraa_adv_func_t* advance_func; /**< override function table */
|
||||
#if defined(MOCKPLAT)
|
||||
uint8_t mock_dev_addr; /**< address of the mock I2C device */
|
||||
uint8_t mock_dev_data_len; /**< mock device data register block length in bytes */
|
||||
uint8_t* mock_dev_data; /**< mock device data register block contents */
|
||||
#endif
|
||||
/*@}*/
|
||||
};
|
||||
|
||||
@@ -137,9 +197,9 @@ struct _iio {
|
||||
char* name; /**< IIO device name */
|
||||
int fp; /**< IIO device in /dev */
|
||||
int fp_event; /**< event file descriptor for IIO device */
|
||||
void (* isr)(char* data); /**< the interupt service request */
|
||||
void *isr_args; /**< args return when interupt service request triggered */
|
||||
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interupt service request */
|
||||
void (* isr)(char* data); /**< the interrupt service request */
|
||||
void *isr_args; /**< args return when interrupt service request triggered */
|
||||
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interrupt service request */
|
||||
int chan_num;
|
||||
pthread_t thread_id; /**< the isr handler thread id */
|
||||
mraa_iio_channel* channels;
|
||||
@@ -164,13 +224,31 @@ typedef struct {
|
||||
/*@}*/
|
||||
} mraa_pincapabilities_t;
|
||||
|
||||
|
||||
/**
|
||||
* Pin commands definition for mraa_mux_t struc
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
PINCMD_UNDEFINED = 0, // do not modify, default command for zero value, used for backward compatibility with boards where pincmd is not defined (it will be deleted later)
|
||||
PINCMD_SET_VALUE = 1, // set a pin's value
|
||||
PINCMD_SET_DIRECTION = 2, // set a pin's direction (value like MRAA_GPIO_OUT, MRAA_GPIO_OUT_HIGH...)
|
||||
PINCMD_SET_IN_VALUE = 3, // set input direction and value
|
||||
PINCMD_SET_OUT_VALUE = 4, // set output direction and value
|
||||
PINCMD_SET_MODE = 5, // set pin's mode
|
||||
PINCMD_SKIP = 6 // just skip this command, do not apply pin and value
|
||||
} pincmd_t;
|
||||
|
||||
|
||||
/**
|
||||
* A Structure representing a multiplexer and the required value
|
||||
*/
|
||||
typedef struct {
|
||||
/*@{*/
|
||||
unsigned int pin; /**< Raw GPIO pin id */
|
||||
unsigned int value; /**< Raw GPIO value */
|
||||
unsigned int pincmd; /**< Pin command pincmd_xxxx */
|
||||
/**< At this time not all boards will support it -> TO DO */
|
||||
unsigned int pin; /**< Raw GPIO pin id */
|
||||
unsigned int value; /**< Raw GPIO value */
|
||||
/*@}*/
|
||||
} mraa_mux_t;
|
||||
|
||||
@@ -184,12 +262,11 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
/*@{*/
|
||||
unsigned int pinmap; /**< sysfs pin */
|
||||
int pinmap; /**< sysfs pin */
|
||||
unsigned int parent_id; /** parent chip id */
|
||||
unsigned int mux_total; /** Numfer of muxes needed for operation of pin */
|
||||
mraa_mux_t mux[6]; /** Array holding information about mux */
|
||||
unsigned int output_enable; /** Output Enable GPIO, for level shifting */
|
||||
unsigned int pullup_enable; /** Pull-Up enable GPIO, inputs */
|
||||
mraa_pin_cap_complex_t complex_cap;
|
||||
/*@}*/
|
||||
} mraa_pin_t;
|
||||
@@ -209,7 +286,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
/*@{*/
|
||||
char name[MRAA_PIN_NAME_SIZE]; /**< Pin's real world name */
|
||||
mraa_pincapabilities_t capabilites; /**< Pin Capabiliites */
|
||||
mraa_pincapabilities_t capabilities; /**< Pin Capabiliites */
|
||||
mraa_pin_t gpio; /**< GPIO structure */
|
||||
mraa_pin_t pwm; /**< PWM structure */
|
||||
mraa_pin_t aio; /**< Anaglog Pin */
|
||||
@@ -225,9 +302,9 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
/*@{*/
|
||||
unsigned int bus_id; /**< ID as exposed in the system */
|
||||
unsigned int scl; /**< i2c SCL */
|
||||
unsigned int sda; /**< i2c SDA */
|
||||
int bus_id; /**< ID as exposed in the system */
|
||||
int scl; /**< i2c SCL */
|
||||
int sda; /**< i2c SDA */
|
||||
// mraa_drv_api_t drv_type; /**< Driver type */
|
||||
/*@}*/
|
||||
} mraa_i2c_bus_t;
|
||||
@@ -240,10 +317,10 @@ typedef struct {
|
||||
unsigned int bus_id; /**< The Bus ID as exposed to the system. */
|
||||
unsigned int slave_s; /**< Slave select */
|
||||
mraa_boolean_t three_wire; /**< Is the bus only a three wire system */
|
||||
unsigned int sclk; /**< Serial Clock */
|
||||
unsigned int mosi; /**< Master Out, Slave In. */
|
||||
unsigned int miso; /**< Master In, Slave Out. */
|
||||
unsigned int cs; /**< Chip Select, used when the board is a spi slave */
|
||||
int sclk; /**< Serial Clock */
|
||||
int mosi; /**< Master Out, Slave In. */
|
||||
int miso; /**< Master In, Slave Out. */
|
||||
int cs; /**< Chip Select, used when the board is a spi slave */
|
||||
/*@}*/
|
||||
} mraa_spi_bus_t;
|
||||
|
||||
@@ -255,7 +332,7 @@ typedef struct {
|
||||
unsigned int index; /**< ID as exposed in the system */
|
||||
int rx; /**< uart rx */
|
||||
int tx; /**< uart tx */
|
||||
const char* device_path; /**< To store "/dev/ttyS1" for example */
|
||||
char* device_path; /**< To store "/dev/ttyS1" for example */
|
||||
/*@}*/
|
||||
} mraa_uart_dev_t;
|
||||
|
||||
@@ -265,26 +342,26 @@ typedef struct {
|
||||
|
||||
typedef struct _board_t {
|
||||
/*@{*/
|
||||
unsigned int phy_pin_count; /**< The Total IO pins on board */
|
||||
unsigned int gpio_count; /**< GPIO Count */
|
||||
unsigned int aio_count; /**< Analog side Count */
|
||||
unsigned int i2c_bus_count; /**< Usable i2c Count */
|
||||
int phy_pin_count; /**< The Total IO pins on board */
|
||||
int gpio_count; /**< GPIO Count */
|
||||
int aio_count; /**< Analog side Count */
|
||||
int i2c_bus_count; /**< Usable i2c Count */
|
||||
mraa_i2c_bus_t i2c_bus[12]; /**< Array of i2c */
|
||||
unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
|
||||
unsigned int spi_bus_count; /**< Usable spi Count */
|
||||
int spi_bus_count; /**< Usable spi Count */
|
||||
mraa_spi_bus_t spi_bus[12]; /**< Array of spi */
|
||||
unsigned int def_spi_bus; /**< Position in array of defult spi bus */
|
||||
unsigned int adc_raw; /**< ADC raw bit value */
|
||||
unsigned int adc_supported; /**< ADC supported bit value */
|
||||
unsigned int def_uart_dev; /**< Position in array of defult uart */
|
||||
unsigned int uart_dev_count; /**< Usable spi Count */
|
||||
int uart_dev_count; /**< Usable spi Count */
|
||||
mraa_uart_dev_t uart_dev[6]; /**< Array of UARTs */
|
||||
mraa_boolean_t no_bus_mux; /**< i2c/spi/adc/pwm/uart bus muxing setup not required */
|
||||
int pwm_default_period; /**< The default PWM period is US */
|
||||
int pwm_max_period; /**< Maximum period in us */
|
||||
int pwm_min_period; /**< Minimum period in us */
|
||||
mraa_platform_t platform_type; /**< Platform type */
|
||||
const char* platform_name; /**< Platform Name pointer */
|
||||
char* platform_name; /**< Platform Name pointer */
|
||||
const char* platform_version; /**< Platform versioning info */
|
||||
mraa_pininfo_t* pins; /**< Pointer to pin array */
|
||||
mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */
|
||||
|
35
include/mraa_lang_func.h
Normal file
35
include/mraa_lang_func.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct {
|
||||
void (*python_isr)(void (*isr)(void*), void* isr_args);
|
||||
void (*java_isr_callback)(void *args);
|
||||
mraa_result_t (*java_attach_thread)();
|
||||
void (*java_detach_thread)();
|
||||
void* (*java_create_global_ref)(void* args);
|
||||
void (*java_delete_global_ref)(void* ref);
|
||||
|
||||
} mraa_lang_func_t;
|
27
include/python/mraapy.h
Normal file
27
include/python/mraapy.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void mraa_python_isr(void (*isr)(void*), void* isr_args);
|
@@ -28,12 +28,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "mraa_internal.h"
|
||||
|
||||
mraa_result_t mraa_ftdi_ft4222_init();
|
||||
mraa_result_t mraa_ftdi_ft4222_get_version(unsigned int* versionChip, unsigned int* versionLib);
|
||||
mraa_board_t* mraa_ftdi_ft4222();
|
||||
|
||||
void *libft4222_lib;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
42
include/x86/intel_gt_tuchuck.h
Normal file
42
include/x86/intel_gt_tuchuck.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
// +1 as pins are "1 indexed"
|
||||
// we have 20 useless pins then the 4 LEDS and the 2 LEDs on the module.
|
||||
#define MRAA_INTEL_GT_TUCHUCK_PINCOUNT (40*2 + 23 +1 +2)
|
||||
|
||||
mraa_board_t*
|
||||
mraa_gt_tuchuck_board();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
17
jsstub/Gruntfile.js
Normal file
17
jsstub/Gruntfile.js
Normal file
@@ -0,0 +1,17 @@
|
||||
module.exports = function(grunt) {
|
||||
grunt.loadNpmTasks('grunt-mocha-test');
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
mochaTest: {
|
||||
test: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
src: ['test/*.js']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['mochaTest:test']);
|
||||
};
|
51
jsstub/README.md
Normal file
51
jsstub/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
mraaStub - JavaScript simulation and stubs for mraa
|
||||
====================
|
||||
|
||||
This project enables simulation of a device which might be accessed via mraa.
|
||||
Currently this library supports I2c, SPI, and GPIO. This project provides
|
||||
several benefits:
|
||||
|
||||
1. Prevent crashes in nodejs applications using mraa on unsuported or
|
||||
misconfigured hardware.
|
||||
2. Enable basic simulation of mraa-accessible devices for unit testing.
|
||||
|
||||
## Examples
|
||||
|
||||
The following example is based on an imaginary 'light bulb' device abstraction,
|
||||
which exposes a value of brightness over a mraa-provided interface. Please see
|
||||
the `test/index.js` file for an example.
|
||||
|
||||
## Installation
|
||||
|
||||
You may install `mraaStub` from npm like this:
|
||||
|
||||
```
|
||||
npm install mraaStub
|
||||
```
|
||||
|
||||
Since we often switch between a mraaStub and the real mraa library, we
|
||||
suggest creating an `index.js` file inside a `lib/mraaSwitcher` folder.
|
||||
|
||||
```js
|
||||
/* index.js - file for switching between mraa and mraaStub
|
||||
*/
|
||||
|
||||
// Define the conditions under which the mraaStub should be loaded
|
||||
var platform = require('os').platform();
|
||||
var m;
|
||||
|
||||
if (platform === 'win32') {
|
||||
m = require('mraaStub');
|
||||
} else {
|
||||
m = require('mraa');
|
||||
}
|
||||
|
||||
module.exports = m;
|
||||
```
|
||||
|
||||
You can add this to your project in its own `lib/mraaSwitcher/index.js` file
|
||||
and use `require('../mraaSwitcher')` everywhere!
|
||||
|
||||
## License
|
||||
|
||||
See [COPYING file](../COPYING) in the root of this repository.
|
223
jsstub/index.js
Normal file
223
jsstub/index.js
Normal file
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* @fileoverview This file implements a fake mraa stub which enables testing
|
||||
* as well as the ability to run on Windows.
|
||||
*/
|
||||
|
||||
var m;
|
||||
var winston = require('winston');
|
||||
var logger = new winston.Logger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: 'error',
|
||||
handleExceptions: false,
|
||||
json: false,
|
||||
colorize: true})
|
||||
],
|
||||
exitOnError: false
|
||||
});
|
||||
|
||||
/**
|
||||
* @class mraaStub
|
||||
* @classdesc This class is designed to stub out libmraa so we can run
|
||||
* test code on unsupported platforms (specifically Windows).
|
||||
*/
|
||||
var mraaStub = function() {
|
||||
var verison = '0.0.1';
|
||||
var self = this;
|
||||
self.EDGE_BOTH = 1;
|
||||
self.EDGE_NONE = 2;
|
||||
self.EDGE_RISING = 3;
|
||||
self.EDGE_FALLING = 4;
|
||||
self.DIR_IN = 1;
|
||||
self.DIR_OUT = 2;
|
||||
|
||||
self.getVersion = function() {
|
||||
return "mraaStub " + version;
|
||||
};
|
||||
|
||||
// Stub out GPIO
|
||||
function Gpio(num) {
|
||||
this.num = num;
|
||||
this._callback = null;
|
||||
this._dir = null;
|
||||
this._isr_mode = self.EDGE_NONE;
|
||||
}
|
||||
|
||||
var logGpio = false;
|
||||
Gpio.prototype._callIsr = function() {
|
||||
if(this.isr_mode === self.EDGE_NONE) {
|
||||
logger.log('info',"Could not call ISR. Not set up for triggering");
|
||||
}
|
||||
this._callback();
|
||||
};
|
||||
|
||||
Gpio.prototype.isr = function(mode, handler){
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " isr stub invoked.");
|
||||
}
|
||||
this._isr_mode = self.EDGE_NONE;
|
||||
this._callback = handler;
|
||||
};
|
||||
|
||||
Gpio.prototype.dir = function(d) {
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " dir stub invoked.");
|
||||
}
|
||||
this._dir = d;
|
||||
};
|
||||
Gpio.prototype.write = function(z) {
|
||||
if(logGpio) {
|
||||
logger.log('logger',"GPIO " + this.num + " write stub invoked.");
|
||||
}
|
||||
if(this._dir !== self.DIR_OUT) {
|
||||
logger.log('info',"GPIO " + this.num + " write called without DIR_OUT set.");
|
||||
}
|
||||
};
|
||||
Gpio.prototype.read = function() {
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " read stub invoked.");
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Stub out SPI
|
||||
function Spi(num) {
|
||||
var self = this;
|
||||
this.num = num;
|
||||
this._buffer = new Buffer(29);
|
||||
this._buffer.fill(0);
|
||||
this._loopback = false;
|
||||
}
|
||||
|
||||
Spi.prototype._setOutput = function(buf) {
|
||||
this._buffer = buf;
|
||||
};
|
||||
|
||||
Spi.prototype._enableLoopback = function(x) {
|
||||
if(x === true) {
|
||||
this._loopback = true;
|
||||
} else {
|
||||
this._loopback = false;
|
||||
}
|
||||
};
|
||||
|
||||
Spi.prototype.write = function(b) {
|
||||
logger.log('info',"SPI write stub invoked.");
|
||||
if(this._loopback === true) {
|
||||
return b;
|
||||
}
|
||||
return new Buffer(this._buffer);
|
||||
};
|
||||
|
||||
Spi.prototype.frequency = function(f) {
|
||||
logger.log('info',"SPI frequency stub invoked.");
|
||||
return f;
|
||||
};
|
||||
|
||||
Spi.prototype.lsbmode = function(t) {
|
||||
logger.log('info',"SPI lsbmode stub invoked.");
|
||||
};
|
||||
|
||||
Spi.prototype.mode = function(x) {
|
||||
logger.log('info',"SPI mode stub invoked.");
|
||||
};
|
||||
|
||||
function I2c(num) {
|
||||
this._num = num;
|
||||
this._regMapInitialized = false;
|
||||
}
|
||||
|
||||
/* This function sets an internal register map for the I2c device.
|
||||
*/
|
||||
I2c.prototype._setRegisterMapInternal = function(buffer) {
|
||||
this._regMapInitialized = true;
|
||||
this._buffer = buffer;
|
||||
};
|
||||
|
||||
I2c.prototype.frequency = function(freq) {
|
||||
// Do nothing. We don't care.
|
||||
};
|
||||
|
||||
I2c.prototype.address = function(address) {
|
||||
var self = this;
|
||||
self.address = address;
|
||||
};
|
||||
|
||||
I2c.prototype.readReg = function(regAddr) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.readUInt8(regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.readWordReg = function(regAddr) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.readUInt16LE(regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.readBytesReg = function(regAddr, len) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.slice(regAddr,regAddr+len);
|
||||
};
|
||||
|
||||
I2c.prototype.write = function(buf) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
var regAddr = buf[0];
|
||||
var newBuf = buf.slice(1);
|
||||
newBuf.copy(this._buffer, regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.writeReg = function(regAddr, data) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
this._buffer.writeUInt8(regAddr,data);
|
||||
};
|
||||
|
||||
I2c.prototype.writeWordReg = function(regAddr, dataWord) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
this._buffer.writeUInt16LE(regAddr,data);
|
||||
};
|
||||
|
||||
// Export our stubs
|
||||
self.Gpio = Gpio;
|
||||
self.Spi = Spi;
|
||||
self.I2c = I2c;
|
||||
|
||||
};
|
||||
|
||||
m = new mraaStub();
|
||||
|
||||
module.exports = m;
|
34
jsstub/package.json
Normal file
34
jsstub/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "mraaStub",
|
||||
"version": "0.0.1",
|
||||
"description": "Enables simulation of mraa interfaces for testing purposes",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/intel-iot-devkit/mraa.git"
|
||||
},
|
||||
"keywords": [
|
||||
"mraa",
|
||||
"iot",
|
||||
"intel",
|
||||
"libmraa",
|
||||
"test",
|
||||
"galileo",
|
||||
"edison"
|
||||
],
|
||||
"author": "David A Antler <david.a.antler@intel.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/intel-iot-devkit/mraa/issues"
|
||||
},
|
||||
"homepage": "https://github.com/intel-iot-devkit/mraa#readme",
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-mocha-test": "^0.12.7",
|
||||
"mocha": "^2.4.5"
|
||||
}
|
||||
}
|
32
jsstub/test/index.js
Normal file
32
jsstub/test/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
var expect = require('expect.js');
|
||||
var m = require('../index');
|
||||
var LightBulb = require('./lightbulb');
|
||||
|
||||
describe('LightBulb', function() {
|
||||
|
||||
/** Model the internal data of LightBulb as a buffer */
|
||||
var bufferFullBrightness = new Buffer(
|
||||
[ 'N', // Four bytes allocated for name
|
||||
'a',
|
||||
'm',
|
||||
'e',
|
||||
95 // One byte allocated for brightness. Stuff in '95' value!
|
||||
]);
|
||||
|
||||
it('getBrightness() function should return 95', function() {
|
||||
|
||||
// Create a fake I2c bus based on the 'full brightness' data model
|
||||
var testI2cBus = new m.I2c(0);
|
||||
testI2cBus._setRegisterMapInternal(bufferFullBrightness);
|
||||
|
||||
// Create a new LightBulb that opens the testI2cBus, instead of a real
|
||||
// mraa I2c bus.
|
||||
var lightBulbI2c = new LightBulb(testI2cBus);
|
||||
|
||||
// presumably getBrightness will gather data from I2C and get '95'
|
||||
var brightness = lightBulbI2c.getBrightness();
|
||||
|
||||
expect(brightness).to.be(95);
|
||||
})
|
||||
});
|
||||
|
32
jsstub/test/lightbulb.js
Normal file
32
jsstub/test/lightbulb.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @fileoverview Implementation of a LightBulb class abstraction
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = (function() {
|
||||
"use strict";
|
||||
var m = require('../index');
|
||||
|
||||
/**
|
||||
* Constructor for a new LightBulb
|
||||
* @class LightBulb
|
||||
*
|
||||
* @classdesc This class abstracts access to the control and data registers
|
||||
* on an imaginary lightbulb.
|
||||
* @param {Object} A libmraa I2c object, initialized
|
||||
*/
|
||||
function LightBulb (i2cInterface) {
|
||||
var self = this;
|
||||
self._i2cInterface = i2cInterface;
|
||||
|
||||
self.getBrightness = function() {
|
||||
// Presume our brightness data is one byte at offset 4
|
||||
return self._i2cInterface.readReg(4);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
return LightBulb;
|
||||
})();
|
||||
|
@@ -4,6 +4,16 @@ set (mraa_LIB_INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
if (FIRMATA)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFIRMATA=1")
|
||||
add_subdirectory (firmata)
|
||||
endif ()
|
||||
|
||||
if (ONEWIRE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DONEWIRE=1")
|
||||
add_subdirectory (uart_ow)
|
||||
endif ()
|
||||
|
||||
include_directories(
|
||||
${mraa_LIB_INCLUDE_DIRS}
|
||||
)
|
||||
@@ -17,6 +27,7 @@ set (mraa_LIB_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/aio/aio.c
|
||||
${PROJECT_SOURCE_DIR}/src/uart/uart.c
|
||||
${PROJECT_SOURCE_DIR}/src/iio/iio.c
|
||||
${mraa_LIB_SRCS_NOAUTO}
|
||||
)
|
||||
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO
|
||||
@@ -30,9 +41,10 @@ set (mraa_LIB_X86_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_sofia_3gr.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_cherryhills.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/up.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_gt_tuchuck.c
|
||||
)
|
||||
|
||||
message (INFO " - Adding support for platform ${MRAAPLATFORMFORCE}")
|
||||
message (STATUS "INFO - Adding support for platform ${MRAAPLATFORMFORCE}")
|
||||
|
||||
#keywords in if statements are case sensitive
|
||||
if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL")
|
||||
@@ -55,11 +67,13 @@ if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_cherryhills.c)
|
||||
elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_UP")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/up.c)
|
||||
elseif( ${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GT_TUCHUCK")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_gt_tuchuck.c)
|
||||
else ()
|
||||
message (ERROR " - Unknown x86 platform enabled!")
|
||||
message (FATAL_ERROR "Unknown x86 platform enabled!")
|
||||
endif ()
|
||||
else ()
|
||||
message (INFO " - Adding support for all platforms")
|
||||
message (STATUS "INFO - Adding support for all platforms")
|
||||
endif ()
|
||||
|
||||
set (mraa_LIB_ARM_SRCS_NOAUTO
|
||||
@@ -70,8 +84,27 @@ set (mraa_LIB_ARM_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/arm/banana.c
|
||||
)
|
||||
|
||||
set (mraa_LIB_MOCK_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_gpio.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_aio.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c
|
||||
)
|
||||
|
||||
if (JSONPLAT)
|
||||
find_package (JSON-C QUIET)
|
||||
if (${JSON-C_FOUND})
|
||||
set (mraa_LIB_SRCS_NOAUTO
|
||||
${mraa_LIB_SRCS_NOAUTO}
|
||||
${PROJECT_SOURCE_DIR}/src/json/jsonplatform.c
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
set (mraa_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
|
||||
if (X86PLAT)
|
||||
add_subdirectory(x86)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DX86PLAT=1")
|
||||
@@ -82,8 +115,16 @@ if (ARMPLAT)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DARMPLAT=1")
|
||||
endif()
|
||||
|
||||
if (MOCKPLAT)
|
||||
add_subdirectory(mock)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMOCKPLAT=1")
|
||||
if (MSYS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMSYS=1")
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
if (USBPLAT)
|
||||
message (INFO " - Adding USB platforms")
|
||||
message (STATUS "INFO - Adding USB platforms")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSBPLAT=1")
|
||||
if (FTDID2xx)
|
||||
find_package (Ftd2xx)
|
||||
@@ -91,21 +132,41 @@ if (USBPLAT)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFTDID2XX=1")
|
||||
set (mraa_LIBS ${mraa_LIBS} ${LIBFTD2XX_LIBRARIES})
|
||||
else ()
|
||||
message (WARNING " - Enabled FTDID2xx support but library not found")
|
||||
message (SEND_ERROR "Enabled FTDID2xx support but library not found")
|
||||
endif ()
|
||||
endif ()
|
||||
if (FTDI4222)
|
||||
find_package (Ftd4222)
|
||||
if (${LIBFT4222_FOUND})
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFTDI4222=1")
|
||||
set (mraa_LIBS ${mraa_LIBS} ${LIBFT4222_LIBRARIES})
|
||||
set (mraa_LIBS ${mraa_LIBS} dl)
|
||||
else ()
|
||||
message (WARNING " - Enabled FTDI4222 support but library not found")
|
||||
message (SEND_ERROR "Enabled FTDI4222 support but library not found")
|
||||
endif ()
|
||||
endif ()
|
||||
add_subdirectory(usb)
|
||||
endif ()
|
||||
|
||||
if (JSONPLAT OR IMRAA)
|
||||
find_package (JSON-C QUIET)
|
||||
if (NOT ${JSON-C_FOUND})
|
||||
if (IMRAA)
|
||||
message (FATAL_ERROR "Enabled IMRAA but JSON-C library not found")
|
||||
elseif (JSONPLAT)
|
||||
message (WARNING "Enabled JSONPLAT but JSON-C library not found: Ignoring JSONPLAT")
|
||||
endif ()
|
||||
else ()
|
||||
if (JSONPLAT)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DJSONPLAT=1")
|
||||
endif ()
|
||||
if (IMRAA)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
|
||||
endif ()
|
||||
include_directories (${JSON-C_INCLUDE_DIR})
|
||||
set (mraa_LIBS ${mraa_LIBS} ${JSON-C_LIBRARIES})
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
set (mraa_LIB_SRCS
|
||||
${mraa_LIB_PLAT_SRCS_NOAUTO}
|
||||
# autogenerated version file
|
||||
@@ -117,17 +178,6 @@ set (mraa_LIB_GLOB_HEADERS
|
||||
${PROJECT_SOURCE_DIR}/api/mraa.hpp
|
||||
)
|
||||
|
||||
add_library (mraa ${mraa_LIB_SRCS})
|
||||
|
||||
|
||||
target_link_libraries (mraa ${mraa_LIBS})
|
||||
|
||||
set_target_properties(
|
||||
mraa
|
||||
PROPERTIES
|
||||
SOVERSION ${mraa_VERSION_MAJOR}
|
||||
VERSION ${mraa_VERSION_STRING}
|
||||
)
|
||||
install (FILES ${mraa_LIB_GLOB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install (DIRECTORY ${PROJECT_SOURCE_DIR}/api/mraa/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mraa)
|
||||
|
||||
@@ -135,9 +185,8 @@ macro (mraa_CREATE_INSTALL_PKGCONFIG generated_file install_location)
|
||||
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
|
||||
endmacro (mraa_CREATE_INSTALL_PKGCONFIG)
|
||||
mraa_create_install_pkgconfig (mraa.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
mraa_create_install_pkgconfig (mraa.pc ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
|
||||
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
if (DOXYGEN_FOUND)
|
||||
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
||||
@@ -187,14 +236,31 @@ if (BUILDSWIG)
|
||||
add_subdirectory (python)
|
||||
endif ()
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
|
||||
add_subdirectory (java)
|
||||
endif ()
|
||||
if (BUILDSWIGNODE)
|
||||
if (SWIG_VERSION VERSION_GREATER 3.0.4)
|
||||
add_subdirectory (javascript)
|
||||
else ()
|
||||
message ("WARN - SWIG is ${SWIG_VERSION}. Please upgrade to 3.0.5+ to build nodejs addon")
|
||||
message (SEND_ERROR "SWIG is ${SWIG_VERSION}. Please upgrade to 3.0.5+ to build nodejs addon")
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
add_library (mraa ${mraa_LIB_SRCS})
|
||||
target_link_libraries (mraa ${mraa_LIBS})
|
||||
set_target_properties(
|
||||
mraa
|
||||
PROPERTIES
|
||||
SOVERSION ${mraa_VERSION_MAJOR}
|
||||
VERSION ${mraa_VERSION_STRING}
|
||||
)
|
||||
if (MSYS)
|
||||
# Under MSYS we have to put our generated DLL into bin, otherwise it's not picked up
|
||||
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
else ()
|
||||
install(TARGETS mraa DESTINATION ${LIB_INSTALL_DIR})
|
||||
endif ()
|
||||
|
121
src/aio/aio.c
121
src/aio/aio.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Author: Nandkishor Sonar
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014, 2015 Intel Corporation.
|
||||
* Copyright (c) 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
|
||||
@@ -56,7 +56,7 @@ aio_get_valid_fp(mraa_aio_context dev)
|
||||
}
|
||||
|
||||
static mraa_aio_context
|
||||
mraa_aio_init_internal(mraa_adv_func_t* func_table)
|
||||
mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio, unsigned int channel)
|
||||
{
|
||||
mraa_aio_context dev = calloc(1, sizeof(struct _aio));
|
||||
if (dev == NULL) {
|
||||
@@ -64,29 +64,72 @@ mraa_aio_init_internal(mraa_adv_func_t* func_table)
|
||||
}
|
||||
dev->advance_func = func_table;
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, aio_init_internal_replace)) {
|
||||
if (dev->advance_func->aio_init_internal_replace(dev, aio) == MRAA_SUCCESS) {
|
||||
return dev;
|
||||
}
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->channel = channel;
|
||||
|
||||
// Open valid analog input file and get the pointer.
|
||||
if (MRAA_SUCCESS != aio_get_valid_fp(dev)) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
mraa_aio_context
|
||||
mraa_aio_init(unsigned int aio)
|
||||
{
|
||||
if (plat == NULL) {
|
||||
mraa_board_t* board = plat;
|
||||
int pin;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "aio: Platform not initialised");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_is_sub_platform_id(aio)) {
|
||||
syslog(LOG_NOTICE, "aio: Using sub platform is not supported");
|
||||
syslog(LOG_NOTICE, "aio: Using sub platform");
|
||||
board = board->sub_platform;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "aio: Sub platform Not Initialised");
|
||||
return NULL;
|
||||
}
|
||||
aio = mraa_get_sub_platform_index(aio);
|
||||
}
|
||||
|
||||
// aio are always past the gpio_count in the pin array
|
||||
pin = aio + board->gpio_count;
|
||||
|
||||
if (pin < 0 || pin >= board->phy_pin_count) {
|
||||
syslog(LOG_ERR, "aio: pin %i beyond platform definition", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (aio >= board->aio_count) {
|
||||
syslog(LOG_ERR, "aio: requested channel out of range");
|
||||
return NULL;
|
||||
}
|
||||
if (board->pins[pin].capabilities.aio != 1) {
|
||||
syslog(LOG_ERR, "aio: pin %i not capable of aio", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (board->pins[pin].aio.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(board->pins[pin].aio) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ADC device connected to specified channel
|
||||
mraa_aio_context dev = mraa_aio_init_internal(plat->adv_func);
|
||||
mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio, board->pins[pin].aio.pinmap);
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel %d", aio);
|
||||
return NULL;
|
||||
}
|
||||
int pin = aio + plat->gpio_count;
|
||||
dev->channel = plat->pins[pin].aio.pinmap;
|
||||
dev->value_bit = DEFAULT_BITS;
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, aio_init_pre)) {
|
||||
@@ -96,32 +139,6 @@ mraa_aio_init(unsigned int aio)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (aio > plat->aio_count) {
|
||||
syslog(LOG_ERR, "aio: requested channel out of range");
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plat->pins[pin].capabilites.aio != 1) {
|
||||
syslog(LOG_ERR, "aio: pin uncapable of aio");
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plat->pins[pin].aio.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Open valid analog input file and get the pointer.
|
||||
if (MRAA_SUCCESS != aio_get_valid_fp(dev)) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
raw_bits = mraa_adc_raw_bits();
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, aio_init_post)) {
|
||||
mraa_result_t ret = dev->advance_func->aio_init_post(dev);
|
||||
@@ -131,19 +148,30 @@ mraa_aio_init(unsigned int aio)
|
||||
}
|
||||
}
|
||||
|
||||
raw_bits = mraa_adc_raw_bits();
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
int
|
||||
mraa_aio_read(mraa_aio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "aio: read: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, aio_read_replace)) {
|
||||
return dev->advance_func->aio_read_replace(dev);
|
||||
}
|
||||
|
||||
char buffer[17];
|
||||
unsigned int shifter_value = 0;
|
||||
|
||||
if (dev->adc_in_fp == -1) {
|
||||
if (aio_get_valid_fp(dev) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "aio: Failed to get to the device");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +188,10 @@ mraa_aio_read(mraa_aio_context dev)
|
||||
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
|
||||
if (end == &buffer[0]) {
|
||||
syslog(LOG_ERR, "aio: Value is not a decimal number");
|
||||
return -1;
|
||||
} else if (errno != 0) {
|
||||
syslog(LOG_ERR, "aio: Errno was set");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dev->value_bit != raw_bits) {
|
||||
@@ -183,7 +213,7 @@ mraa_aio_read_float(mraa_aio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "aio: Device not valid");
|
||||
return 0.0;
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
float max_analog_value = (1 << dev->value_bit) - 1;
|
||||
@@ -195,13 +225,22 @@ mraa_aio_read_float(mraa_aio_context dev)
|
||||
mraa_result_t
|
||||
mraa_aio_close(mraa_aio_context dev)
|
||||
{
|
||||
if (NULL != dev) {
|
||||
if (dev->adc_in_fp != -1)
|
||||
close(dev->adc_in_fp);
|
||||
free(dev);
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "aio: close: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return (MRAA_SUCCESS);
|
||||
if (IS_FUNC_DEFINED(dev, aio_close_replace)) {
|
||||
return dev->advance_func->aio_close_replace(dev);
|
||||
}
|
||||
|
||||
if (dev->adc_in_fp != -1) {
|
||||
close(dev->adc_in_fp);
|
||||
}
|
||||
|
||||
free(dev);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
|
@@ -63,9 +63,9 @@ void mraa_96boards_pininfo(mraa_board_t* board, int index, int sysfs_pin,
|
||||
vsnprintf(pininfo->name, MRAA_PIN_NAME_SIZE, fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
if (sysfs_pin >= 0)
|
||||
pininfo->capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
pininfo->capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
else
|
||||
pininfo->capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
pininfo->capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
pininfo->gpio.pinmap = sysfs_pin;
|
||||
pininfo->gpio.mux_total = 0;
|
||||
}
|
||||
|
104
src/arm/banana.c
104
src/arm/banana.c
@@ -305,37 +305,37 @@ mraa_banana()
|
||||
b->adv_func->gpio_mmap_setup = &mraa_banana_mmap_setup;
|
||||
|
||||
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[1].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[2].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (i2c2 == 1) {
|
||||
strncpy(b->pins[3].name, "TWI2-SDA", MRAA_PIN_NAME_SIZE); // PB21 Pin53 TWI2-SDA
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[3].name, "PB21", MRAA_PIN_NAME_SIZE); // PB21 Pin53 TWI2-SDA
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[3].gpio.pinmap = 53;
|
||||
|
||||
strncpy(b->pins[4].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (i2c2 == 1) {
|
||||
strncpy(b->pins[5].name, "TWI2-SCK", MRAA_PIN_NAME_SIZE); // PB20 Pin52 TWI2-SCK
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[5].name, "PB20", MRAA_PIN_NAME_SIZE); // PB20 Pin52 TWI2-SCK
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[5].gpio.pinmap = 52;
|
||||
|
||||
strncpy(b->pins[6].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PRO) {
|
||||
strncpy(b->pins[7].name, "PH02", MRAA_PIN_NAME_SIZE); // PH2 Pin226
|
||||
@@ -344,7 +344,7 @@ mraa_banana()
|
||||
strncpy(b->pins[7].name, "PI03", MRAA_PIN_NAME_SIZE); // PI3 Pin259 PWM
|
||||
b->pins[7].gpio.pinmap = 259;
|
||||
}
|
||||
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PRO) {
|
||||
strncpy(b->pins[8].name, "UART4_TX", MRAA_PIN_NAME_SIZE); // PH4 Pin228 UART4_TX
|
||||
@@ -353,10 +353,10 @@ mraa_banana()
|
||||
strncpy(b->pins[8].name, "UART3_TX", MRAA_PIN_NAME_SIZE); // PH0 Pin224 UART3_TX
|
||||
b->pins[8].gpio.pinmap = 224;
|
||||
}
|
||||
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
|
||||
strncpy(b->pins[9].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PRO) {
|
||||
strncpy(b->pins[10].name, "UART4_RX", MRAA_PIN_NAME_SIZE); // PH5 Pin229 UART4_RX
|
||||
@@ -365,10 +365,10 @@ mraa_banana()
|
||||
strncpy(b->pins[10].name, "UART3_RX", MRAA_PIN_NAME_SIZE); // PH1 Pin225 UART3_RX
|
||||
b->pins[10].gpio.pinmap = 225;
|
||||
}
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
|
||||
strncpy(b->pins[11].name, "PI19", MRAA_PIN_NAME_SIZE); // PI19 Pin275 IO+UART2_RX
|
||||
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[11].gpio.pinmap = 275;
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PRO) {
|
||||
@@ -378,143 +378,143 @@ mraa_banana()
|
||||
strncpy(b->pins[12].name, "PH02", MRAA_PIN_NAME_SIZE); // PH2 Pin226
|
||||
b->pins[12].gpio.pinmap = 226;
|
||||
}
|
||||
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[13].name, "PI18", MRAA_PIN_NAME_SIZE); // PI18 Pin274 UART2_TX
|
||||
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[13].gpio.pinmap = 274;
|
||||
|
||||
strncpy(b->pins[14].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[15].name, "PI17", MRAA_PIN_NAME_SIZE); // PI17 Pin273 UART2_CTS
|
||||
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].gpio.pinmap = 273;
|
||||
|
||||
strncpy(b->pins[16].name, "PH20", MRAA_PIN_NAME_SIZE); // PH20 Pin 244 CAN_TX
|
||||
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].gpio.pinmap = 244;
|
||||
|
||||
strncpy(b->pins[17].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[18].name, "PH21", MRAA_PIN_NAME_SIZE); // PH21 Pin245 CAN_RX
|
||||
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].gpio.pinmap = 245;
|
||||
|
||||
strncpy(b->pins[19].name, "SPI0MOSI", MRAA_PIN_NAME_SIZE); // PI12 SPI0
|
||||
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[19].gpio.pinmap = 268;
|
||||
|
||||
strncpy(b->pins[20].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[21].name, "SPI0MISO", MRAA_PIN_NAME_SIZE); // PI13 SPI0
|
||||
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[21].gpio.pinmap = 269;
|
||||
|
||||
strncpy(b->pins[22].name, "PI16", MRAA_PIN_NAME_SIZE); // PI16 UART2_RTS
|
||||
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[22].gpio.pinmap = 272;
|
||||
|
||||
strncpy(b->pins[23].name, "SPI0CLK", MRAA_PIN_NAME_SIZE); // PI11 SPI0
|
||||
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[23].gpio.pinmap = 267;
|
||||
|
||||
strncpy(b->pins[24].name, "SPI0CS0", MRAA_PIN_NAME_SIZE); // PI10 SPI0
|
||||
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[24].gpio.pinmap = 266;
|
||||
|
||||
strncpy(b->pins[25].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[26].name, "SPI0CS1", MRAA_PIN_NAME_SIZE); // PI14 SPI0
|
||||
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[26].gpio.pinmap = 270;
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PI) {
|
||||
strncpy(b->pins[27].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[28].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[29].name, "PH05", MRAA_PIN_NAME_SIZE); // PH5
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].gpio.pinmap = 229;
|
||||
|
||||
strncpy(b->pins[30].name, "PI21", MRAA_PIN_NAME_SIZE); // PI21 UART7_RX
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[30].gpio.pinmap = 277;
|
||||
|
||||
strncpy(b->pins[31].name, "PH03", MRAA_PIN_NAME_SIZE); // PH3
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].gpio.pinmap = 227;
|
||||
|
||||
strncpy(b->pins[32].name, "PI20", MRAA_PIN_NAME_SIZE); // PI20 UART7_TX
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[32].gpio.pinmap = 276;
|
||||
|
||||
strncpy(b->pins[33].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
if (platform_detected == PLATFORM_BANANA_PRO) {
|
||||
|
||||
strncpy(b->pins[27].name, "HAT_SDA", MRAA_PIN_NAME_SIZE); // PI1 TWI3-SDA i2c3
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].gpio.pinmap = 257;
|
||||
|
||||
strncpy(b->pins[28].name, "HAT_SCK", MRAA_PIN_NAME_SIZE); // PI0 TWI3-SCK i2c3
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].gpio.pinmap = 256;
|
||||
|
||||
strncpy(b->pins[29].name, "PB03", MRAA_PIN_NAME_SIZE); // PB3 IR0_TX/SPDIF_MCLK
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].gpio.pinmap = 35;
|
||||
|
||||
strncpy(b->pins[30].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[31].name, "PI21", MRAA_PIN_NAME_SIZE); // PI21 UART7_RX
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[31].gpio.pinmap = 277;
|
||||
|
||||
strncpy(b->pins[32].name, "PI20", MRAA_PIN_NAME_SIZE); // PI20 UART7_TX
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[32].gpio.pinmap = 276;
|
||||
|
||||
strncpy(b->pins[33].name, "PB13", MRAA_PIN_NAME_SIZE); // PB13 SPDIF_D0
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].gpio.pinmap = 45;
|
||||
|
||||
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[35].name, "PB07", MRAA_PIN_NAME_SIZE); // PB07 I2S0_LRCK
|
||||
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].gpio.pinmap = 39;
|
||||
|
||||
strncpy(b->pins[36].name, "PB06", MRAA_PIN_NAME_SIZE); // PB06 I2S0BCLK
|
||||
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].gpio.pinmap = 38;
|
||||
|
||||
strncpy(b->pins[37].name, "PB05", MRAA_PIN_NAME_SIZE); // PB05 I2S0MCK
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[37].gpio.pinmap = 37;
|
||||
|
||||
strncpy(b->pins[38].name, "PB12", MRAA_PIN_NAME_SIZE); // PB12 I2S0_DI
|
||||
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[38].gpio.pinmap = 44;
|
||||
|
||||
strncpy(b->pins[39].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[40].name, "PB08", MRAA_PIN_NAME_SIZE); // PB08 I2S0_DO0
|
||||
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].gpio.pinmap = 40;
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ mraa_banana()
|
||||
b->gpio_count = 0;
|
||||
int i;
|
||||
for (i = 0; i < b->phy_pin_count; i++) {
|
||||
if (b->pins[i].capabilites.gpio) {
|
||||
if (b->pins[i].capabilities.gpio) {
|
||||
b->gpio_count++;
|
||||
}
|
||||
}
|
||||
|
@@ -64,7 +64,6 @@ static unsigned int mmap_count = 0;
|
||||
mraa_result_t
|
||||
mraa_beaglebone_mmap_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
volatile uint32_t* addr;
|
||||
if (value) {
|
||||
*(volatile uint32_t*) (mmap_gpio[dev->pin / 32] + AM335X_SET) = (uint32_t)(1 << (dev->pin % 32));
|
||||
} else {
|
||||
@@ -185,7 +184,6 @@ mraa_beaglebone_uart_init_pre(int index)
|
||||
{
|
||||
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
|
||||
char devpath[MAX_SIZE];
|
||||
char overlay[MAX_SIZE];
|
||||
char* capepath = NULL;
|
||||
sprintf(devpath, "/dev/ttyO%u", index + 1);
|
||||
if (!mraa_file_exist(devpath)) {
|
||||
@@ -218,7 +216,6 @@ mraa_beaglebone_spi_init_pre(int index)
|
||||
{
|
||||
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
|
||||
char devpath[MAX_SIZE];
|
||||
char overlay[MAX_SIZE];
|
||||
char* capepath = NULL;
|
||||
int deviceindex = 0;
|
||||
|
||||
@@ -273,10 +270,10 @@ mraa_beaglebone_i2c_init_pre(unsigned int bus)
|
||||
{
|
||||
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
|
||||
char devpath[MAX_SIZE];
|
||||
char overlay[MAX_SIZE];
|
||||
char* capepath = NULL;
|
||||
sprintf(devpath, "/dev/i2c-%u", plat->i2c_bus[bus].bus_id);
|
||||
if (!mraa_file_exist(devpath)) {
|
||||
syslog(LOG_INFO, "i2c: %s doesn't exist ", devpath);
|
||||
capepath = mraa_file_unglob(SYSFS_DEVICES_CAPEMGR_SLOTS);
|
||||
if (capepath == NULL) {
|
||||
syslog(LOG_ERR, "i2c: Could not find CapeManager");
|
||||
@@ -310,13 +307,12 @@ mraa_pwm_context
|
||||
mraa_beaglebone_pwm_init_replace(int pin)
|
||||
{
|
||||
char devpath[MAX_SIZE];
|
||||
char overlay[MAX_SIZE];
|
||||
char* capepath = NULL;
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "pwm: Platform Not Initialised");
|
||||
return NULL;
|
||||
}
|
||||
if (plat->pins[pin].capabilites.pwm != 1) {
|
||||
if (plat->pins[pin].capabilities.pwm != 1) {
|
||||
syslog(LOG_ERR, "pwm: pin not capable of pwm");
|
||||
return NULL;
|
||||
}
|
||||
@@ -418,7 +414,7 @@ mraa_beaglebone()
|
||||
else
|
||||
i2c0_enabled = 0;
|
||||
|
||||
if (mraa_file_exist("/sys/class/i2c-dev/i2c-1"))
|
||||
if (mraa_file_exist("/sys/class/i2c-dev/i2c-2"))
|
||||
i2c1_enabled = 1;
|
||||
else
|
||||
i2c1_enabled = 0;
|
||||
@@ -529,20 +525,20 @@ mraa_beaglebone()
|
||||
b->adv_func->pwm_init_replace = &mraa_beaglebone_pwm_init_replace;
|
||||
|
||||
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[1].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[2].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[3].name, "MMC1_D6", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[3].name, "GPIO38", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[3].gpio.pinmap = 38;
|
||||
b->pins[3].gpio.parent_id = 0;
|
||||
@@ -550,10 +546,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[4].name, "MMC1_D7", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[4].name, "GPIO39", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[4].gpio.pinmap = 39;
|
||||
b->pins[4].gpio.parent_id = 0;
|
||||
@@ -561,10 +557,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[5].name, "MMC1_D2", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[5].name, "GPIO34", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[5].gpio.pinmap = 34;
|
||||
b->pins[5].gpio.parent_id = 0;
|
||||
@@ -572,10 +568,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[6].name, "MMC1_D3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[6].name, "GPIO35", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[6].gpio.pinmap = 35;
|
||||
b->pins[6].gpio.parent_id = 0;
|
||||
@@ -583,50 +579,50 @@ mraa_beaglebone()
|
||||
|
||||
// TODO TIMER4
|
||||
strncpy(b->pins[7].name, "GPIO66", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].gpio.pinmap = 66;
|
||||
b->pins[7].gpio.parent_id = 0;
|
||||
b->pins[7].gpio.mux_total = 0;
|
||||
|
||||
// TODO TIMER7
|
||||
strncpy(b->pins[8].name, "GPIO67", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[8].gpio.pinmap = 67;
|
||||
b->pins[8].gpio.parent_id = 0;
|
||||
b->pins[8].gpio.mux_total = 0;
|
||||
|
||||
// TODO TIMER5
|
||||
strncpy(b->pins[9].name, "GPIO69", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[9].gpio.pinmap = 69;
|
||||
b->pins[9].gpio.parent_id = 0;
|
||||
b->pins[9].gpio.mux_total = 0;
|
||||
|
||||
// TODO TIMER6
|
||||
strncpy(b->pins[10].name, "GPIO68", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[10].gpio.pinmap = 68;
|
||||
b->pins[10].gpio.parent_id = 0;
|
||||
b->pins[10].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[11].name, "GPIO45", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[11].gpio.pinmap = 45;
|
||||
b->pins[11].gpio.parent_id = 0;
|
||||
b->pins[11].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[12].name, "GPIO44", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].gpio.pinmap = 44;
|
||||
b->pins[12].gpio.parent_id = 0;
|
||||
b->pins[12].gpio.mux_total = 0;
|
||||
|
||||
if (ehrpwm2b_enabled == 1) {
|
||||
strncpy(b->pins[13].name, "EHRPWM2B", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[13].name, "GPIO23", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[13].gpio.pinmap = 23;
|
||||
b->pins[13].gpio.parent_id = 0;
|
||||
@@ -635,42 +631,42 @@ mraa_beaglebone()
|
||||
b->pins[13].pwm.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[14].name, "GPIO26", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[14].gpio.pinmap = 26;
|
||||
b->pins[14].gpio.parent_id = 0;
|
||||
b->pins[14].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[15].name, "GPIO47", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].gpio.pinmap = 47;
|
||||
b->pins[15].gpio.parent_id = 0;
|
||||
b->pins[15].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[16].name, "GPIO46", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].gpio.pinmap = 46;
|
||||
b->pins[16].gpio.parent_id = 0;
|
||||
b->pins[16].gpio.mux_total = 0;
|
||||
|
||||
// TODO PWM0_SYNCO
|
||||
strncpy(b->pins[17].name, "GPIO27", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[17].gpio.pinmap = 27;
|
||||
b->pins[17].gpio.parent_id = 0;
|
||||
b->pins[17].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[18].name, "GPIO65", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].gpio.pinmap = 65;
|
||||
b->pins[18].gpio.parent_id = 0;
|
||||
b->pins[18].gpio.mux_total = 0;
|
||||
|
||||
if (ehrpwm2a_enabled == 1) {
|
||||
strncpy(b->pins[19].name, "EHRPWM2A", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[19].name, "GPIO22", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[19].gpio.pinmap = 22;
|
||||
b->pins[19].gpio.parent_id = 0;
|
||||
@@ -680,10 +676,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[20].name, "MMC1_CMD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[20].name, "GPIO63", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[20].gpio.pinmap = 63;
|
||||
b->pins[20].gpio.parent_id = 0;
|
||||
@@ -691,10 +687,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[21].name, "MMC1_CLK", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[21].name, "GPIO62", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[21].gpio.pinmap = 62;
|
||||
b->pins[21].gpio.parent_id = 0;
|
||||
@@ -702,10 +698,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[22].name, "MMC1_D5", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[22].name, "GPIO37", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[22].gpio.pinmap = 37;
|
||||
b->pins[22].gpio.parent_id = 0;
|
||||
@@ -713,10 +709,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[23].name, "MMC_D4", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[23].name, "GPIO36", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[23].gpio.pinmap = 36;
|
||||
b->pins[23].gpio.parent_id = 0;
|
||||
@@ -724,10 +720,10 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[24].name, "MMC_D1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[24].name, "GPIO33", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[24].gpio.pinmap = 33;
|
||||
b->pins[24].gpio.parent_id = 0;
|
||||
@@ -735,27 +731,27 @@ mraa_beaglebone()
|
||||
|
||||
if (emmc_enabled == 1) {
|
||||
strncpy(b->pins[25].name, "MMC1_D0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[25].name, "GPIO32", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[25].gpio.pinmap = 32;
|
||||
b->pins[25].gpio.parent_id = 0;
|
||||
b->pins[25].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[26].name, "GPIO61", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[26].gpio.pinmap = 61;
|
||||
b->pins[26].gpio.parent_id = 0;
|
||||
b->pins[26].gpio.mux_total = 0;
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[27].name, "LCD_VSYNC", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[27].name, "GPIO86", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[27].gpio.pinmap = 86;
|
||||
b->pins[27].gpio.parent_id = 0;
|
||||
@@ -763,10 +759,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[28].name, "LCD_PCLK", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[28].name, "GPIO88", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[28].gpio.pinmap = 88;
|
||||
b->pins[28].gpio.parent_id = 0;
|
||||
@@ -774,10 +770,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[29].name, "LCD_HSYNC", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[29].name, "GPIO87", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[29].gpio.pinmap = 87;
|
||||
b->pins[29].gpio.parent_id = 0;
|
||||
@@ -785,10 +781,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[30].name, "LCD_AC_BIAS", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[30].name, "GPIO89", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[30].gpio.pinmap = 89;
|
||||
b->pins[30].gpio.parent_id = 0;
|
||||
@@ -796,11 +792,11 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[31].name, "LCD_D14", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
// TODO UART5_CTS this is ignored when using ADAFRUIT
|
||||
strncpy(b->pins[31].name, "GPIO10", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[31].gpio.pinmap = 10;
|
||||
b->pins[31].gpio.parent_id = 0;
|
||||
@@ -809,11 +805,11 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[32].name, "LCD_D15", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
// TODO UART5_RTS this is ignored when using ADAFRUIT
|
||||
strncpy(b->pins[32].name, "GPIO11", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[32].gpio.pinmap = 11;
|
||||
b->pins[32].gpio.parent_id = 0;
|
||||
@@ -822,11 +818,11 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[33].name, "LCD_D13", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
// TODO UART4_RTS this is ignored when using ADAFRUIT
|
||||
strncpy(b->pins[33].name, "GPIO9", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[33].gpio.pinmap = 9;
|
||||
b->pins[33].gpio.parent_id = 0;
|
||||
@@ -836,10 +832,10 @@ mraa_beaglebone()
|
||||
// TODO PWM_1B
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[34].name, "LCD_D11", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[34].name, "GPIO81", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[34].gpio.pinmap = 81;
|
||||
b->pins[34].gpio.parent_id = 0;
|
||||
@@ -847,11 +843,11 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[35].name, "LCD_D12", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
// TODO UART4_CTS this is ignored when using ADAFRUIT
|
||||
strncpy(b->pins[35].name, "GPIO8", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[35].gpio.pinmap = 8;
|
||||
b->pins[35].gpio.parent_id = 0;
|
||||
@@ -861,10 +857,10 @@ mraa_beaglebone()
|
||||
// TODO PWM_1A
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[36].name, "LCD_D10", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[36].name, "GPIO80", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[36].gpio.pinmap = 80;
|
||||
b->pins[36].gpio.parent_id = 0;
|
||||
@@ -872,17 +868,17 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[37].name, "LCD_D8", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
if (uart5_enabled == 1) {
|
||||
strncpy(b->pins[37].name, "UART5TX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[37].name, "GPIO78", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
}
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[37].gpio.pinmap = 78;
|
||||
b->pins[37].gpio.parent_id = 0;
|
||||
b->pins[37].gpio.mux_total = 0;
|
||||
@@ -890,15 +886,15 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[38].name, "LCD_D9", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
// TODO UART5_RX
|
||||
if (uart5_enabled == 1) {
|
||||
strncpy(b->pins[38].name, "UART5RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[38].name, "GPIO79", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
}
|
||||
b->pins[38].gpio.pinmap = 79;
|
||||
@@ -908,10 +904,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[39].name, "LCD_D6", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[39].name, "GPIO76", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[39].gpio.pinmap = 76;
|
||||
b->pins[39].gpio.parent_id = 0;
|
||||
@@ -919,10 +915,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[40].name, "LCD_D7", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[40].name, "GPIO77", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[40].gpio.pinmap = 77;
|
||||
b->pins[40].gpio.parent_id = 0;
|
||||
@@ -930,10 +926,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[41].name, "LCD_D4", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[41].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[41].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[41].name, "GPIO74", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[41].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[41].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[41].gpio.pinmap = 74;
|
||||
b->pins[41].gpio.parent_id = 0;
|
||||
@@ -941,10 +937,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[42].name, "LCD_D5", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[42].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[42].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[42].name, "GPIO75", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[42].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[42].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[42].gpio.pinmap = 75;
|
||||
b->pins[42].gpio.parent_id = 0;
|
||||
@@ -952,10 +948,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[43].name, "LCD_D2", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[43].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[43].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[43].name, "GPIO72", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[43].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[43].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[43].gpio.pinmap = 72;
|
||||
b->pins[43].gpio.parent_id = 0;
|
||||
@@ -963,10 +959,10 @@ mraa_beaglebone()
|
||||
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[44].name, "LCD_D3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[44].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[44].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[44].name, "GPIO73", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[44].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[44].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[44].gpio.pinmap = 73;
|
||||
b->pins[44].gpio.parent_id = 0;
|
||||
@@ -975,10 +971,10 @@ mraa_beaglebone()
|
||||
// TODO PWM_2A
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[45].name, "LCD_D0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[45].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[45].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[45].name, "GPIO70", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[45].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[45].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[45].gpio.pinmap = 70;
|
||||
b->pins[45].gpio.parent_id = 0;
|
||||
@@ -987,51 +983,51 @@ mraa_beaglebone()
|
||||
// TODO PWM_2B
|
||||
if (hdmi_enabled == 1) {
|
||||
strncpy(b->pins[46].name, "LCD_D1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[46].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[46].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[46].name, "GPIO71", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[46].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[46].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[46].gpio.pinmap = 71;
|
||||
b->pins[46].gpio.parent_id = 0;
|
||||
b->pins[46].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[47].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[47].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[47].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[48].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[48].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[48].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[49].name, "3.3V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[49].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[49].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[50].name, "3.3V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[50].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[50].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[51].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[51].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[51].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[52].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[52].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[52].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[53].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[53].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[53].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[54].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[54].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[54].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[55].name, "PWR", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[55].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[55].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[56].name, "RESET", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[56].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[56].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
if (uart4_enabled == 1) {
|
||||
strncpy(b->pins[57].name, "UART4_RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[57].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[57].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[57].name, "GPIO30", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[57].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[57].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
b->pins[57].gpio.pinmap = 30;
|
||||
b->pins[57].gpio.parent_id = 0;
|
||||
@@ -1039,17 +1035,17 @@ mraa_beaglebone()
|
||||
b->pins[57].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[58].name, "GPIO60", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[58].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[58].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[58].gpio.pinmap = 60;
|
||||
b->pins[58].gpio.parent_id = 0;
|
||||
b->pins[58].gpio.mux_total = 0;
|
||||
|
||||
if (uart4_enabled == 1) {
|
||||
strncpy(b->pins[59].name, "UART4_TX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[59].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[59].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[59].name, "GPIO31", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[59].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[59].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
b->pins[59].gpio.pinmap = 31;
|
||||
b->pins[59].gpio.parent_id = 0;
|
||||
@@ -1058,10 +1054,10 @@ mraa_beaglebone()
|
||||
|
||||
if (ehrpwm1a_enabled == 1) {
|
||||
strncpy(b->pins[60].name, "EHRPWM1A", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[60].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[60].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[60].name, "GPIO50", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[60].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[60].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[60].gpio.pinmap = 50;
|
||||
b->pins[60].gpio.parent_id = 0;
|
||||
@@ -1071,17 +1067,17 @@ mraa_beaglebone()
|
||||
|
||||
// TODO PWM_TRIP2_IN (not a PWM output, but used for sync cf ref. manual)
|
||||
strncpy(b->pins[61].name, "GPIO48", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[61].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[61].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[61].gpio.pinmap = 48;
|
||||
b->pins[61].gpio.parent_id = 0;
|
||||
b->pins[61].gpio.mux_total = 0;
|
||||
|
||||
if (ehrpwm1b_enabled == 1) {
|
||||
strncpy(b->pins[62].name, "EHRPWM1B", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[62].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[62].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[62].name, "GPIO51", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[62].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[62].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[62].gpio.pinmap = 51;
|
||||
b->pins[62].gpio.parent_id = 0;
|
||||
@@ -1092,15 +1088,15 @@ mraa_beaglebone()
|
||||
if ((i2c0_enabled == 1) || (spi0_enabled == 1)) {
|
||||
if (i2c0_enabled == 1) {
|
||||
strncpy(b->pins[63].name, "I2C1SCL", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
}
|
||||
if (spi0_enabled == 1) {
|
||||
strncpy(b->pins[63].name, "SPI0CS0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[63].name, "GPIO4", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
}
|
||||
b->pins[63].gpio.pinmap = 4;
|
||||
b->pins[63].gpio.parent_id = 0;
|
||||
@@ -1111,15 +1107,15 @@ mraa_beaglebone()
|
||||
if ((i2c0_enabled == 1) || (spi0_enabled == 1)) {
|
||||
if (i2c0_enabled == 1) {
|
||||
strncpy(b->pins[64].name, "I2C1SDA", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
}
|
||||
if (spi0_enabled == 1) {
|
||||
strncpy(b->pins[64].name, "SPI0D1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[64].name, "GPIO5", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
|
||||
}
|
||||
b->pins[64].gpio.pinmap = 5;
|
||||
b->pins[64].gpio.parent_id = 0;
|
||||
@@ -1127,26 +1123,26 @@ mraa_beaglebone()
|
||||
b->pins[64].i2c.mux_total = 0;
|
||||
b->pins[64].spi.mux_total = 0;
|
||||
|
||||
if (i2c0_enabled == 1) {
|
||||
if (i2c1_enabled == 1) {
|
||||
strncpy(b->pins[65].name, "I2C2SCL", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[65].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[65].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[65].i2c.mux_total = 0;
|
||||
} else {
|
||||
strncpy(b->pins[65].name, "GPIO13", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[65].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[65].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
}
|
||||
b->pins[65].gpio.pinmap = 13;
|
||||
b->pins[65].gpio.parent_id = 0;
|
||||
b->pins[65].gpio.mux_total = 0;
|
||||
b->pins[65].i2c.mux_total = 0;
|
||||
|
||||
if (i2c0_enabled == 1) {
|
||||
if (i2c1_enabled == 1) {
|
||||
strncpy(b->pins[66].name, "I2C2SDA", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[66].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[66].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[66].i2c.mux_total = 0;
|
||||
} else {
|
||||
strncpy(b->pins[66].name, "GPIO12", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[66].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[66].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
}
|
||||
b->pins[66].gpio.pinmap = 12;
|
||||
b->pins[66].gpio.parent_id = 0;
|
||||
@@ -1156,19 +1152,19 @@ mraa_beaglebone()
|
||||
if ((spi0_enabled == 1) || uart2_enabled == 1 || ehrpwm0b_enabled == 1) {
|
||||
if (uart2_enabled == 1) {
|
||||
strncpy(b->pins[67].name, "UART2_TX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
if (spi0_enabled == 1) {
|
||||
strncpy(b->pins[67].name, "SPI0D0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
if (ehrpwm0b_enabled == 1) {
|
||||
strncpy(b->pins[67].name, "EHRPWM0B", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[67].name, "GPIO3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
|
||||
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
|
||||
}
|
||||
b->pins[67].gpio.pinmap = 3;
|
||||
b->pins[67].gpio.parent_id = 0;
|
||||
@@ -1181,19 +1177,19 @@ mraa_beaglebone()
|
||||
if ((spi0_enabled == 1) || uart2_enabled == 1 || ehrpwm0a_enabled == 1) {
|
||||
if (uart2_enabled == 1) {
|
||||
strncpy(b->pins[68].name, "UART2_RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 1 };
|
||||
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 1 };
|
||||
}
|
||||
if (spi0_enabled == 1) {
|
||||
strncpy(b->pins[68].name, "SPI0CLK", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
if (ehrpwm0a_enabled == 1) {
|
||||
strncpy(b->pins[68].name, "EHRPWM0A", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[68].name, "GPIO2", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
|
||||
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
|
||||
}
|
||||
b->pins[68].gpio.pinmap = 2;
|
||||
b->pins[68].gpio.parent_id = 0;
|
||||
@@ -1205,17 +1201,17 @@ mraa_beaglebone()
|
||||
|
||||
// TODO PWM0_SYNCO ?? PWM
|
||||
strncpy(b->pins[69].name, "GPIO49", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[69].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[69].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[69].gpio.pinmap = 49;
|
||||
b->pins[69].gpio.parent_id = 0;
|
||||
b->pins[69].gpio.mux_total = 0;
|
||||
|
||||
if (uart1_enabled == 1) {
|
||||
strncpy(b->pins[70].name, "UART1_RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[70].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[70].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[70].name, "GPIO15", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[70].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[70].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
b->pins[70].gpio.pinmap = 15;
|
||||
b->pins[70].gpio.parent_id = 0;
|
||||
@@ -1223,26 +1219,26 @@ mraa_beaglebone()
|
||||
b->pins[70].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[71].name, "GPIO117", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[71].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[71].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[71].gpio.pinmap = 117;
|
||||
b->pins[71].gpio.parent_id = 0;
|
||||
b->pins[71].gpio.mux_total = 0;
|
||||
|
||||
if (uart1_enabled == 1) {
|
||||
strncpy(b->pins[72].name, "UART1_RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
} else {
|
||||
strncpy(b->pins[72].name, "GPIO14", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
}
|
||||
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[72].gpio.pinmap = 14;
|
||||
b->pins[72].gpio.parent_id = 0;
|
||||
b->pins[72].gpio.mux_total = 0;
|
||||
b->pins[72].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[73].name, "GPIO115", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[73].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[73].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[73].gpio.pinmap = 115;
|
||||
b->pins[73].gpio.parent_id = 0;
|
||||
b->pins[73].gpio.mux_total = 0;
|
||||
@@ -1250,14 +1246,14 @@ mraa_beaglebone()
|
||||
if (emmc_enabled != 1) {
|
||||
if (spi1_enabled == 1) {
|
||||
strncpy(b->pins[74].name, "SPI1CS0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[74].name, "GPIO113", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[74].name, "MCASP0XX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
b->pins[74].gpio.pinmap = 113;
|
||||
b->pins[74].gpio.parent_id = 0;
|
||||
@@ -1267,14 +1263,14 @@ mraa_beaglebone()
|
||||
if (emmc_enabled != 1) {
|
||||
if (spi1_enabled == 1) {
|
||||
strncpy(b->pins[75].name, "SPI1D0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[75].name, "GPIO111", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[75].name, "MMC1_SD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[75].gpio.pinmap = 111;
|
||||
b->pins[75].gpio.parent_id = 0;
|
||||
@@ -1284,14 +1280,14 @@ mraa_beaglebone()
|
||||
if (emmc_enabled != 1) {
|
||||
if (spi1_enabled == 1) {
|
||||
strncpy(b->pins[76].name, "SPI1D1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[76].name, "GPIO112", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[76].name, "MMC2_SD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[76].gpio.pinmap = 112;
|
||||
b->pins[76].gpio.parent_id = 0;
|
||||
@@ -1301,14 +1297,14 @@ mraa_beaglebone()
|
||||
if (emmc_enabled != 1) {
|
||||
if (spi1_enabled == 1) {
|
||||
strncpy(b->pins[77].name, "SPI1CLK", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
} else {
|
||||
strncpy(b->pins[77].name, "GPIO110", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
}
|
||||
} else {
|
||||
strncpy(b->pins[77].name, "MMC0_SD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
b->pins[77].gpio.pinmap = 110;
|
||||
b->pins[77].gpio.parent_id = 0;
|
||||
@@ -1317,60 +1313,60 @@ mraa_beaglebone()
|
||||
|
||||
|
||||
strncpy(b->pins[78].name, "VDD_ADC", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[78].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[78].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// TODO AIN4
|
||||
strncpy(b->pins[79].name, "AIN4", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[79].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[79].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
|
||||
strncpy(b->pins[80].name, "GND_ADC", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[80].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[80].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
// TODO AIN6
|
||||
strncpy(b->pins[81].name, "AIN6", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[81].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[81].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
// TODO AIN5
|
||||
strncpy(b->pins[82].name, "AIN5", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[82].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[82].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
// TODO AIN2
|
||||
strncpy(b->pins[83].name, "AIN2", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[83].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[83].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
// TODO AIN3
|
||||
strncpy(b->pins[84].name, "AIN3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[84].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[84].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
// TODO AIN0
|
||||
strncpy(b->pins[85].name, "AIN0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[85].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[85].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
// TODO AIN1
|
||||
strncpy(b->pins[86].name, "AIN1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[86].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[86].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
|
||||
|
||||
strncpy(b->pins[87].name, "GPIO20", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[87].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[87].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[87].gpio.pinmap = 20;
|
||||
b->pins[87].gpio.parent_id = 0;
|
||||
b->pins[87].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[88].name, "GPIO7", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[88].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[88].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[88].gpio.pinmap = 7;
|
||||
b->pins[88].gpio.parent_id = 0;
|
||||
b->pins[88].gpio.mux_total = 0;
|
||||
|
||||
// GND
|
||||
strncpy(b->pins[89].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[89].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[89].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// GND
|
||||
strncpy(b->pins[90].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[90].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[90].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// GND
|
||||
strncpy(b->pins[91].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[91].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[91].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// GND
|
||||
strncpy(b->pins[92].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[92].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[92].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// BUS DEFINITIONS
|
||||
b->i2c_bus_count = 2;
|
||||
@@ -1380,7 +1376,7 @@ mraa_beaglebone()
|
||||
b->i2c_bus[0].sda = 46 + 18;
|
||||
b->i2c_bus[0].scl = 46 + 17;
|
||||
|
||||
b->i2c_bus[1].bus_id = 1;
|
||||
b->i2c_bus[1].bus_id = 2;
|
||||
b->i2c_bus[1].sda = 46 + 20;
|
||||
b->i2c_bus[1].scl = 46 + 19;
|
||||
|
||||
@@ -1421,7 +1417,7 @@ mraa_beaglebone()
|
||||
b->gpio_count = 0;
|
||||
int i;
|
||||
for (i = 0; i < b->phy_pin_count; i++)
|
||||
if (b->pins[i].capabilites.gpio)
|
||||
if (b->pins[i].capabilities.gpio)
|
||||
b->gpio_count++;
|
||||
|
||||
return b;
|
||||
|
@@ -246,7 +246,7 @@ mraa_raspberry_pi()
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_A_PLUS_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
|
||||
} else if (strstr(line, "a01041") || strstr(line, "a21041")) {
|
||||
} else if (strstr(line, "a01041") || strstr(line, "a21041") || strstr(line, "a02082")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI2_B_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI2_B_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT;
|
||||
@@ -292,63 +292,63 @@ mraa_raspberry_pi()
|
||||
b->adv_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup;
|
||||
|
||||
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[1].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[2].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[3].name, "SDA0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[3].gpio.pinmap = 2;
|
||||
b->pins[3].gpio.mux_total = 0;
|
||||
b->pins[3].i2c.pinmap = 0;
|
||||
b->pins[3].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[4].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[5].name, "SCL0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
|
||||
b->pins[5].gpio.pinmap = 3;
|
||||
b->pins[5].gpio.mux_total = 0;
|
||||
b->pins[5].i2c.pinmap = 0;
|
||||
b->pins[5].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[6].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[7].name, "GPIO4", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].gpio.pinmap = 4;
|
||||
b->pins[7].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[8].name, "UART_TX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[8].gpio.pinmap = 14;
|
||||
b->pins[8].gpio.mux_total = 0;
|
||||
b->pins[8].uart.parent_id = 0;
|
||||
b->pins[8].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[9].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[10].name, "UART_RX", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[10].gpio.pinmap = 15;
|
||||
b->pins[10].gpio.mux_total = 0;
|
||||
b->pins[10].uart.parent_id = 0;
|
||||
b->pins[10].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[11].name, "GPIO17", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[11].gpio.pinmap = 17;
|
||||
b->pins[11].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[12].name, "GPIO18", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].gpio.pinmap = 18;
|
||||
b->pins[12].gpio.mux_total = 0;
|
||||
|
||||
@@ -359,71 +359,71 @@ mraa_raspberry_pi()
|
||||
strncpy(b->pins[13].name, "GPIO27", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[13].gpio.pinmap = 27;
|
||||
}
|
||||
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[13].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[14].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[15].name, "GPIO22", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[15].gpio.pinmap = 22;
|
||||
b->pins[15].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[16].name, "GPIO23", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[16].gpio.pinmap = 23;
|
||||
b->pins[16].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[17].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[18].name, "GPIO24", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[18].gpio.pinmap = 24;
|
||||
b->pins[18].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[19].name, "SPI_MOSI", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[19].gpio.pinmap = 10;
|
||||
b->pins[19].gpio.mux_total = 0;
|
||||
b->pins[19].spi.pinmap = 0;
|
||||
b->pins[19].spi.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[20].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[21].name, "SPI_MISO", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[21].gpio.pinmap = 9;
|
||||
b->pins[21].gpio.mux_total = 0;
|
||||
b->pins[21].spi.pinmap = 0;
|
||||
b->pins[21].spi.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[22].name, "GPIO25", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[22].gpio.pinmap = 25;
|
||||
b->pins[22].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[23].name, "SPI_CLK", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[23].gpio.pinmap = 11;
|
||||
b->pins[23].gpio.mux_total = 0;
|
||||
b->pins[23].spi.pinmap = 0;
|
||||
b->pins[23].spi.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[24].name, "SPI_CS0", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[24].gpio.pinmap = 8;
|
||||
b->pins[24].gpio.mux_total = 0;
|
||||
b->pins[24].spi.pinmap = 0;
|
||||
b->pins[24].spi.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[25].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[26].name, "SPI_CS1", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[26].gpio.pinmap = 7;
|
||||
b->pins[26].gpio.mux_total = 0;
|
||||
b->pins[26].spi.pinmap = 0;
|
||||
@@ -432,36 +432,36 @@ mraa_raspberry_pi()
|
||||
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_REV_2) ||
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI_B_REV_2)) {
|
||||
strncpy(b->pins[27].name, "5V", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[28].name, "3V3", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[29].name, "GPIO8", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].gpio.pinmap = 8;
|
||||
b->pins[29].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[30].name, "GPIO9", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].gpio.pinmap = 9;
|
||||
b->pins[30].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[31].name, "GPIO10", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].gpio.pinmap = 10;
|
||||
b->pins[31].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[32].name, "GPIO11", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[32].gpio.pinmap = 11;
|
||||
b->pins[32].gpio.mux_total = 0;
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[33].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
// BUS DEFINITIONS
|
||||
@@ -493,62 +493,62 @@ mraa_raspberry_pi()
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
|
||||
|
||||
strncpy(b->pins[27].name, "ID_SD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[28].name, "ID_SC", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[29].name, "GPIO05", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[29].gpio.pinmap = 5;
|
||||
b->pins[29].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[30].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[31].name, "GPIO06", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[31].gpio.pinmap = 6;
|
||||
b->pins[31].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[32].name, "GPIO12", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[32].gpio.pinmap = 12;
|
||||
b->pins[32].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[33].name, "GPIO13", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[33].gpio.pinmap = 13;
|
||||
b->pins[33].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[35].name, "GPIO19", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[35].gpio.pinmap = 19;
|
||||
b->pins[35].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[36].name, "GPIO16", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[36].gpio.pinmap = 16;
|
||||
b->pins[36].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[37].name, "GPIO26", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[37].gpio.pinmap = 26;
|
||||
b->pins[37].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[38].name, "GPIO20", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[38].gpio.pinmap = 20;
|
||||
b->pins[38].gpio.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[39].name, "GND", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
strncpy(b->pins[40].name, "GPIO21", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[40].gpio.pinmap = 21;
|
||||
b->pins[40].gpio.mux_total = 0;
|
||||
}
|
||||
@@ -556,7 +556,7 @@ mraa_raspberry_pi()
|
||||
b->gpio_count = 0;
|
||||
int i;
|
||||
for (i = 0; i < b->phy_pin_count; i++) {
|
||||
if (b->pins[i].capabilites.gpio) {
|
||||
if (b->pins[i].capabilities.gpio) {
|
||||
b->gpio_count++;
|
||||
}
|
||||
}
|
||||
|
8
src/firmata/CMakeLists.txt
Normal file
8
src/firmata/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
if (FIRMATA)
|
||||
message (STATUS "INFO - Adding firmata backend support")
|
||||
set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
|
||||
${PROJECT_SOURCE_DIR}/src/firmata/firmata.c
|
||||
${PROJECT_SOURCE_DIR}/src/firmata/firmata_mraa.c
|
||||
PARENT_SCOPE
|
||||
)
|
||||
endif ()
|
361
src/firmata/firmata.c
Normal file
361
src/firmata/firmata.c
Normal file
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
* Copyright (c) 2015 Jules Dourlens (jdourlens@gmail.com)
|
||||
*
|
||||
* 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 "firmata/firmata.h"
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
t_firmata*
|
||||
firmata_new(const char* name)
|
||||
{
|
||||
t_firmata* res;
|
||||
mraa_result_t uart_res = MRAA_ERROR_UNSPECIFIED;
|
||||
|
||||
res = calloc(1, sizeof(t_firmata));
|
||||
if (!res) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res->uart = mraa_uart_init_raw(name);
|
||||
if (res->uart == NULL) {
|
||||
syslog(LOG_ERR, "firmata: UART failed to setup");
|
||||
free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
firmata_initPins(res);
|
||||
|
||||
if (mraa_uart_set_baudrate(res->uart, 57600) != MRAA_SUCCESS) {
|
||||
syslog(LOG_WARNING, "firmata: Failed to set correct baud rate on %s", name);
|
||||
}
|
||||
|
||||
firmata_askFirmware(res);
|
||||
syslog(LOG_INFO, "firmata: Device opened at: %s", name);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
firmata_close(t_firmata* firmata)
|
||||
{
|
||||
mraa_uart_stop(firmata->uart);
|
||||
free(firmata);
|
||||
}
|
||||
|
||||
int
|
||||
firmata_pull(t_firmata* firmata)
|
||||
{
|
||||
uint8_t buff[FIRMATA_MSG_LEN];
|
||||
int r;
|
||||
|
||||
r = mraa_uart_data_available(firmata->uart, 40);
|
||||
if (r > 0) {
|
||||
r = mraa_uart_read(firmata->uart, buff, sizeof(buff));
|
||||
if (r < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (r > 0) {
|
||||
firmata_parse(firmata, buff, r);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
firmata_parse(t_firmata* firmata, const uint8_t* buf, int len)
|
||||
{
|
||||
const uint8_t* p;
|
||||
const uint8_t* end;
|
||||
|
||||
p = buf;
|
||||
end = p + len;
|
||||
for (p = buf; p < end; p++) {
|
||||
uint8_t msn = *p & 0xF0;
|
||||
if (msn == 0xE0 || msn == 0x90 || *p == 0xF9) {
|
||||
firmata->parse_command_len = 3;
|
||||
firmata->parse_count = 0;
|
||||
} else if (msn == 0xC0 || msn == 0xD0) {
|
||||
firmata->parse_command_len = 2;
|
||||
firmata->parse_count = 0;
|
||||
} else if (*p == FIRMATA_START_SYSEX) {
|
||||
firmata->parse_count = 0;
|
||||
firmata->parse_command_len = sizeof(firmata->parse_buff);
|
||||
} else if (*p == FIRMATA_END_SYSEX) {
|
||||
firmata->parse_command_len = firmata->parse_count + 1;
|
||||
} else if (*p & 0x80) {
|
||||
firmata->parse_command_len = 1;
|
||||
firmata->parse_count = 0;
|
||||
}
|
||||
if (firmata->parse_count < (int) sizeof(firmata->parse_buff)) {
|
||||
firmata->parse_buff[firmata->parse_count] = (uint8_t)(*p);
|
||||
firmata->parse_count++;
|
||||
}
|
||||
if (firmata->parse_count == firmata->parse_command_len) {
|
||||
firmata_endParse(firmata);
|
||||
firmata->parse_count = 0;
|
||||
firmata->parse_command_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
firmata_endParse(t_firmata* firmata)
|
||||
{
|
||||
uint8_t cmd = (firmata->parse_buff[0] & 0xF0);
|
||||
int pin;
|
||||
|
||||
if (cmd == 0xE0 && firmata->parse_count == 3) {
|
||||
int analog_ch = (firmata->parse_buff[0] & 0x0F);
|
||||
int analog_val = firmata->parse_buff[1] | (firmata->parse_buff[2] << 7);
|
||||
for (pin = 0; pin < 128; pin++) {
|
||||
if (firmata->pins[pin].analog_channel == analog_ch) {
|
||||
firmata->pins[pin].value = analog_val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cmd == 0x90 && firmata->parse_count == 3) {
|
||||
int port_num = (firmata->parse_buff[0] & 0x0F);
|
||||
int port_val = firmata->parse_buff[1] | (firmata->parse_buff[2] << 7);
|
||||
int pin = port_num * 8;
|
||||
int mask;
|
||||
for (mask = 1; mask & 0xFF; mask <<= 1, pin++) {
|
||||
if (firmata->pins[pin].mode == MODE_INPUT) {
|
||||
uint32_t val = (port_val & mask) ? 1 : 0;
|
||||
firmata->pins[pin].value = val;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (firmata->parse_buff[0] == FIRMATA_START_SYSEX &&
|
||||
firmata->parse_buff[firmata->parse_count - 1] == FIRMATA_END_SYSEX) {
|
||||
if (firmata->parse_buff[1] == FIRMATA_REPORT_FIRMWARE) {
|
||||
int len = 0;
|
||||
int i;
|
||||
for (i = 4; i < firmata->parse_count - 2; i += 2) {
|
||||
firmata->firmware[len++] =
|
||||
(firmata->parse_buff[i] & 0x7F) | ((firmata->parse_buff[i + 1] & 0x7F) << 7);
|
||||
}
|
||||
firmata->firmware[len++] = '-';
|
||||
firmata->firmware[len++] = firmata->parse_buff[2] + '0';
|
||||
firmata->firmware[len++] = '.';
|
||||
firmata->firmware[len++] = firmata->parse_buff[3] + '0';
|
||||
firmata->firmware[len++] = 0;
|
||||
syslog(LOG_INFO, "firmata: sketch name:: %s", firmata->firmware);
|
||||
// query the board's capabilities only after hearing the
|
||||
// REPORT_FIRMWARE message. For boards that reset when
|
||||
// the port open (eg, Arduino with reset=DTR), they are
|
||||
// not ready to communicate for some time, so the only
|
||||
// way to reliably query their capabilities is to wait
|
||||
// until the REPORT_FIRMWARE message is heard.
|
||||
uint8_t buf[80];
|
||||
len = 0;
|
||||
buf[len++] = FIRMATA_START_SYSEX;
|
||||
buf[len++] = FIRMATA_ANALOG_MAPPING_QUERY; // read analog to pin # info
|
||||
buf[len++] = FIRMATA_END_SYSEX;
|
||||
buf[len++] = FIRMATA_START_SYSEX;
|
||||
buf[len++] = FIRMATA_CAPABILITY_QUERY; // read capabilities
|
||||
buf[len++] = FIRMATA_END_SYSEX;
|
||||
for (i = 0; i < 16; i++) {
|
||||
buf[len++] = 0xC0 | i; // report analog
|
||||
buf[len++] = 1;
|
||||
buf[len++] = 0xD0 | i; // report digital
|
||||
buf[len++] = 1;
|
||||
}
|
||||
firmata->isReady = 1;
|
||||
mraa_uart_write(firmata->uart, buf, len);
|
||||
} else if (firmata->parse_buff[1] == FIRMATA_CAPABILITY_RESPONSE) {
|
||||
int pin, i, n;
|
||||
for (pin = 0; pin < 128; pin++) {
|
||||
firmata->pins[pin].supported_modes = 0;
|
||||
}
|
||||
for (i = 2, n = 0, pin = 0; i < firmata->parse_count; i++) {
|
||||
if (firmata->parse_buff[i] == 127) {
|
||||
pin++;
|
||||
n = 0;
|
||||
continue;
|
||||
}
|
||||
if (n == 0) {
|
||||
// first byte is supported mode
|
||||
firmata->pins[pin].supported_modes |= (1 << firmata->parse_buff[i]);
|
||||
}
|
||||
n = n ^ 1;
|
||||
}
|
||||
// send a state query for for every pin with any modes
|
||||
for (pin = 0; pin < 128; pin++) {
|
||||
uint8_t buf[512];
|
||||
int len = 0;
|
||||
if (firmata->pins[pin].supported_modes) {
|
||||
buf[len++] = FIRMATA_START_SYSEX;
|
||||
buf[len++] = FIRMATA_PIN_STATE_QUERY;
|
||||
buf[len++] = pin;
|
||||
buf[len++] = FIRMATA_END_SYSEX;
|
||||
}
|
||||
mraa_uart_write(firmata->uart, buf, len);
|
||||
}
|
||||
} else if (firmata->parse_buff[1] == FIRMATA_ANALOG_MAPPING_RESPONSE) {
|
||||
int pin = 0;
|
||||
int i;
|
||||
for (i = 2; i < firmata->parse_count - 1; i++) {
|
||||
firmata->pins[pin].analog_channel = firmata->parse_buff[i];
|
||||
pin++;
|
||||
}
|
||||
return;
|
||||
} else if (firmata->parse_buff[1] == FIRMATA_PIN_STATE_RESPONSE && firmata->parse_count >= 6) {
|
||||
int pin = firmata->parse_buff[2];
|
||||
firmata->pins[pin].mode = firmata->parse_buff[3];
|
||||
firmata->pins[pin].value = firmata->parse_buff[4];
|
||||
if (firmata->parse_count > 6)
|
||||
firmata->pins[pin].value |= (firmata->parse_buff[5] << 7);
|
||||
if (firmata->parse_count > 7)
|
||||
firmata->pins[pin].value |= (firmata->parse_buff[6] << 14);
|
||||
// disable this to check the firmata_devs responses
|
||||
} else if (firmata->parse_buff[1] == FIRMATA_I2C_REPLY) {
|
||||
int addr = (firmata->parse_buff[2] & 0x7f) | ((firmata->parse_buff[3] & 0x7f) << 7);
|
||||
int reg = (firmata->parse_buff[4] & 0x7f) | ((firmata->parse_buff[5] & 0x7f) << 7);
|
||||
int i = 6;
|
||||
int ii = 0;
|
||||
for (ii; ii < (firmata->parse_count - 7) / 2; ii++) {
|
||||
firmata->i2cmsg[addr][reg+ii] = (firmata->parse_buff[i] & 0x7f) | ((firmata->parse_buff[i+1] & 0x7f) << 7);
|
||||
i = i+2;
|
||||
}
|
||||
} else {
|
||||
if (firmata->devs != NULL) {
|
||||
struct _firmata* devs = firmata->devs[0];
|
||||
int i = 0;
|
||||
for (i; i < firmata->dev_count; i++, devs++) {
|
||||
if (devs != NULL) {
|
||||
if (firmata->parse_buff[1] == devs->feature) {
|
||||
// call func
|
||||
if (devs->isr) {
|
||||
devs->isr(firmata->parse_buff, firmata->parse_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
firmata_initPins(t_firmata* firmata)
|
||||
{
|
||||
int i;
|
||||
|
||||
firmata->parse_count = 0;
|
||||
firmata->parse_command_len = 0;
|
||||
firmata->isReady = 0;
|
||||
for (i = 0; i < 128; i++) {
|
||||
firmata->pins[i].mode = 255;
|
||||
firmata->pins[i].analog_channel = 127;
|
||||
firmata->pins[i].supported_modes = 0;
|
||||
firmata->pins[i].value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
firmata_askFirmware(t_firmata* firmata)
|
||||
{
|
||||
uint8_t buf[3];
|
||||
int res;
|
||||
|
||||
buf[0] = FIRMATA_START_SYSEX;
|
||||
buf[1] = FIRMATA_REPORT_FIRMWARE; // read firmata name & version
|
||||
buf[2] = FIRMATA_END_SYSEX;
|
||||
res = mraa_uart_write(firmata->uart, buf, 3);
|
||||
return (res);
|
||||
}
|
||||
|
||||
int
|
||||
firmata_pinMode(t_firmata* firmata, int pin, int mode)
|
||||
{
|
||||
int res;
|
||||
uint8_t buff[4];
|
||||
|
||||
firmata->pins[pin].mode = mode;
|
||||
buff[0] = FIRMATA_SET_PIN_MODE;
|
||||
buff[1] = pin;
|
||||
buff[2] = mode;
|
||||
res = mraa_uart_write(firmata->uart, buff, 3);
|
||||
return (res);
|
||||
}
|
||||
|
||||
int
|
||||
firmata_analogWrite(t_firmata* firmata, int pin, int value)
|
||||
{
|
||||
int res;
|
||||
|
||||
uint8_t buff[3];
|
||||
buff[0] = 0xE0 | pin;
|
||||
buff[1] = value & 0x7F;
|
||||
buff[2] = (value >> 7) & 0x7F;
|
||||
res = mraa_uart_write(firmata->uart, buff, 3);
|
||||
return (res);
|
||||
}
|
||||
|
||||
int
|
||||
firmata_analogRead(t_firmata *firmata, int pin)
|
||||
{
|
||||
int res;
|
||||
int value = 1;
|
||||
uint8_t buff[2];
|
||||
buff[0] = FIRMATA_REPORT_ANALOG | pin;
|
||||
buff[1] = value;
|
||||
res = mraa_uart_write(firmata->uart, buff, 2);
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
firmata_digitalWrite(t_firmata* firmata, int pin, int value)
|
||||
{
|
||||
int i;
|
||||
int res;
|
||||
uint8_t buff[4];
|
||||
|
||||
if (pin < 0 || pin > 127)
|
||||
return (0);
|
||||
firmata->pins[pin].value = value;
|
||||
int port_num = pin / 8;
|
||||
int port_val = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
int p = port_num * 8 + i;
|
||||
if (firmata->pins[p].mode == MODE_OUTPUT || firmata->pins[p].mode == MODE_INPUT) {
|
||||
if (firmata->pins[p].value) {
|
||||
port_val |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
buff[0] = FIRMATA_DIGITAL_MESSAGE | port_num;
|
||||
buff[1] = port_val & 0x7F;
|
||||
buff[2] = (port_val >> 7) & 0x7F;
|
||||
res = mraa_uart_write(firmata->uart, buff, 3);
|
||||
return (res);
|
||||
}
|
700
src/firmata/firmata_mraa.c
Normal file
700
src/firmata/firmata_mraa.c
Normal file
@@ -0,0 +1,700 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "firmata.h"
|
||||
#include "mraa_internal.h"
|
||||
#include "firmata/firmata_mraa.h"
|
||||
#include "firmata/firmata.h"
|
||||
|
||||
static t_firmata* firmata_dev;
|
||||
static pthread_t thread_id;
|
||||
static volatile int isr_detected;
|
||||
|
||||
mraa_firmata_context
|
||||
mraa_firmata_init(int feature)
|
||||
{
|
||||
mraa_firmata_context dev = (mraa_firmata_context) calloc(1, sizeof(struct _firmata));
|
||||
if (dev == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
dev->feature = (uint8_t) feature;
|
||||
dev->added = 0;
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_firmata_write_sysex(mraa_firmata_context dev, char* msg, int length)
|
||||
{
|
||||
return mraa_uart_write(firmata_dev->uart, msg, length);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_firmata_response(mraa_firmata_context dev, void (*fptr)(uint8_t*, int))
|
||||
{
|
||||
if (dev->added == 0) {
|
||||
struct _firmata** ptr;
|
||||
ptr = realloc(firmata_dev->devs, (firmata_dev->dev_count+1) * sizeof(struct _firmata*));
|
||||
if (ptr == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
firmata_dev->devs = ptr;
|
||||
dev->index = firmata_dev->dev_count;
|
||||
firmata_dev->dev_count++;
|
||||
firmata_dev->devs[dev->index] = dev;
|
||||
dev->added = 1;
|
||||
}
|
||||
dev->isr = fptr;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_firmata_response_stop(mraa_firmata_context dev)
|
||||
{
|
||||
dev->isr = NULL;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_firmata_close(mraa_firmata_context dev)
|
||||
{
|
||||
mraa_firmata_response_stop(dev);
|
||||
free(dev);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_init_bus_replace(mraa_i2c_context dev)
|
||||
{
|
||||
int delay = 1; // this should be either 1 or 0, I don't know :)
|
||||
uint8_t buff[4];
|
||||
buff[0] = FIRMATA_START_SYSEX;
|
||||
buff[1] = FIRMATA_I2C_CONFIG;
|
||||
buff[2] = delay & 0xFF, (delay >> 8) & 0xFF;
|
||||
buff[3] = FIRMATA_END_SYSEX;
|
||||
mraa_uart_write(firmata_dev->uart, buff, 4);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_address(mraa_i2c_context dev, uint8_t addr)
|
||||
{
|
||||
// only thing needed and it's already done
|
||||
//dev->addr = (int) addr;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
|
||||
{
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_send_i2c_read_req(mraa_i2c_context dev, int length)
|
||||
{
|
||||
uint8_t* buffer = calloc(7, 0);
|
||||
if (buffer == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_I2C_REQUEST;
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_READ << 3;
|
||||
|
||||
// number of bytes
|
||||
buffer[4] = length & 0x7f;
|
||||
buffer[5] = (length >> 7) & 0x7f;
|
||||
buffer[6] = FIRMATA_END_SYSEX;
|
||||
|
||||
if (mraa_uart_write(firmata_dev->uart, buffer, 7) != 7) {
|
||||
free(buffer);
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
// this needs a lock :)
|
||||
memset(&firmata_dev->i2cmsg[dev->addr][0], -1, sizeof(int)*length);
|
||||
|
||||
free(buffer);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_send_i2c_read_reg_req(mraa_i2c_context dev, uint8_t command, int length)
|
||||
{
|
||||
uint8_t* buffer = calloc(9, 0);
|
||||
if (buffer == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_I2C_REQUEST;
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_READ << 3;
|
||||
|
||||
// register to read from
|
||||
buffer[4] = command & 0x7f;
|
||||
buffer[5] = (command >> 7) & 0x7f;
|
||||
// number of bytes
|
||||
buffer[6] = length & 0x7f;
|
||||
buffer[7] = (length >> 7) & 0x7f;
|
||||
buffer[8] = FIRMATA_END_SYSEX;
|
||||
|
||||
if (mraa_uart_write(firmata_dev->uart, buffer, 9) != 9) {
|
||||
free(buffer);
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
// this needs a lock :)
|
||||
memset(&firmata_dev->i2cmsg[dev->addr][command], -1, sizeof(int)*length);
|
||||
|
||||
free(buffer);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_wait(int addr, int reg)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; firmata_dev->i2cmsg[addr][reg] == -1; i++) {
|
||||
if (i > 50) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
usleep(500);
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
|
||||
{
|
||||
if (mraa_firmata_send_i2c_read_req(dev, 1) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, 0) == MRAA_SUCCESS) {
|
||||
return firmata_dev->i2cmsg[dev->addr][0];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 2) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
|
||||
uint8_t rawdata[2];
|
||||
rawdata[0] = firmata_dev->i2cmsg[dev->addr][command];
|
||||
rawdata[1] = firmata_dev->i2cmsg[dev->addr][command+1];
|
||||
uint16_t data = (uint16_t) rawdata;
|
||||
uint8_t high = (data & 0xFF00) >> 8;
|
||||
data = (data << 8) & 0xFF00;
|
||||
data |= high;
|
||||
|
||||
return (int) data;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
|
||||
{
|
||||
if (mraa_firmata_send_i2c_read_reg_req(dev, command, length) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
|
||||
memcpy(data, &firmata_dev->i2cmsg[dev->addr][command], sizeof(int)*length);
|
||||
return length;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
{
|
||||
if (mraa_firmata_send_i2c_read_req(dev, length) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, 0) == MRAA_SUCCESS) {
|
||||
int i = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
data[i] = firmata_dev->i2cmsg[dev->addr][i];
|
||||
}
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 1) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
|
||||
return (int) firmata_dev->i2cmsg[dev->addr][command];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWrite)
|
||||
{
|
||||
// buffer needs 5 bytes for firmata, and 2 bytes for every byte of data
|
||||
int buffer_size = (bytesToWrite*2) + 5;
|
||||
uint8_t* buffer = calloc(buffer_size, 0);
|
||||
if (buffer == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
int i = 0;
|
||||
int ii = 4;
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_I2C_REQUEST;
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_WRITE << 3;
|
||||
// we need to write until FIRMATA_END_SYSEX
|
||||
for (i; i < (buffer_size-1); i++) {
|
||||
buffer[ii] = data[i] & 0x7F;
|
||||
buffer[ii+1] = (data[i] >> 7) & 0x7f;
|
||||
ii = ii+2;
|
||||
}
|
||||
buffer[buffer_size-1] = FIRMATA_END_SYSEX;
|
||||
mraa_uart_write(firmata_dev->uart, buffer, buffer_size);
|
||||
free(buffer);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
|
||||
{
|
||||
uint8_t* buffer = calloc(7, 0);
|
||||
if (buffer == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_I2C_REQUEST;
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_WRITE << 3;
|
||||
buffer[4] = data & 0x7F;
|
||||
buffer[5] = (data >> 7) & 0x7F;
|
||||
buffer[6] = FIRMATA_END_SYSEX;
|
||||
mraa_uart_write(firmata_dev->uart, buffer, 7);
|
||||
free(buffer);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
|
||||
{
|
||||
uint8_t* buffer = calloc(9, 0);
|
||||
if (buffer == NULL) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
buffer[0] = FIRMATA_START_SYSEX;
|
||||
buffer[1] = FIRMATA_I2C_REQUEST;
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_WRITE << 3;
|
||||
buffer[4] = command & 0x7F;
|
||||
buffer[5] = (command >> 7) & 0x7F;
|
||||
buffer[6] = data & 0x7F;
|
||||
buffer[7] = (data >> 7) & 0x7F;
|
||||
buffer[8] = FIRMATA_END_SYSEX;
|
||||
mraa_uart_write(firmata_dev->uart, buffer, 9);
|
||||
free(buffer);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
|
||||
{
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_i2c_stop(mraa_i2c_context dev)
|
||||
{
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_aio_read(mraa_aio_context dev)
|
||||
{
|
||||
// careful, whilst you need to enable '0' for A0 you then need to read 14
|
||||
// in t_firmata because well that makes sense doesn't it...
|
||||
return (int) firmata_dev->pins[dev->channel].value;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_aio_init_internal_replace(mraa_aio_context dev, int aio)
|
||||
{
|
||||
// set the channel, since we override internal it's never set
|
||||
// offset by 14 because it makes total logical sense.
|
||||
dev->channel = aio + 14;
|
||||
// firmata considers A0 pin0 as well as actual pin0 :/
|
||||
firmata_pinMode(firmata_dev, aio, MODE_ANALOG);
|
||||
// register for updates on that ADC channel
|
||||
firmata_analogRead(firmata_dev, aio);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_init_internal_replace(mraa_gpio_context dev, int pin)
|
||||
{
|
||||
dev->pin = pin;
|
||||
dev->phy_pin = pin;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
{
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_firmata_gpio_read_replace(mraa_gpio_context dev)
|
||||
{
|
||||
return firmata_dev->pins[dev->pin].value;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_write_replace(mraa_gpio_context dev, int write_value)
|
||||
{
|
||||
if (write_value == 0) {
|
||||
firmata_digitalWrite(firmata_dev, dev->phy_pin, LOW);
|
||||
} else {
|
||||
firmata_digitalWrite(firmata_dev, dev->phy_pin, HIGH);
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
{
|
||||
switch (dir) {
|
||||
case MRAA_GPIO_IN:
|
||||
firmata_pinMode(firmata_dev, dev->phy_pin, MODE_INPUT);
|
||||
break;
|
||||
case MRAA_GPIO_OUT:
|
||||
firmata_pinMode(firmata_dev, dev->phy_pin, MODE_OUTPUT);
|
||||
break;
|
||||
case MRAA_GPIO_OUT_LOW:
|
||||
firmata_pinMode(firmata_dev, dev->phy_pin, MODE_OUTPUT);
|
||||
firmata_digitalWrite(firmata_dev, dev->phy_pin, LOW);
|
||||
break;
|
||||
case MRAA_GPIO_OUT_HIGH:
|
||||
firmata_pinMode(firmata_dev, dev->phy_pin, MODE_OUTPUT);
|
||||
firmata_digitalWrite(firmata_dev, dev->phy_pin, HIGH);
|
||||
break;
|
||||
default:
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case MRAA_GPIO_EDGE_BOTH:
|
||||
return MRAA_SUCCESS;
|
||||
default:
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_interrupt_handler_init_replace(mraa_gpio_context dev)
|
||||
{
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_wait_interrupt_replace(mraa_gpio_context dev)
|
||||
{
|
||||
while (!((isr_detected >> dev->pin) & 1)) {
|
||||
usleep(100);
|
||||
}
|
||||
// might want to lock here?
|
||||
isr_detected &= ~(1 << dev->pin);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_gpio_close_replace(mraa_gpio_context dev)
|
||||
{
|
||||
free(dev);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_pwm_context
|
||||
mraa_firmata_pwm_init_internal_replace(void* func_table, int pin)
|
||||
{
|
||||
mraa_pwm_context dev = (mraa_pwm_context) calloc(1, sizeof(struct _pwm));
|
||||
if (dev == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
dev->pin = pin;
|
||||
dev->chipid = 512;
|
||||
dev->period = 2048000; // Locked, in ns
|
||||
dev->advance_func = (mraa_adv_func_t*) func_table;
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_pwm_write_replace(mraa_pwm_context dev, float percentage)
|
||||
{
|
||||
int value = (int)((percentage - 1) / 8000);
|
||||
firmata_analogWrite(firmata_dev, dev->pin, value);
|
||||
firmata_dev->pins[dev->pin].value = value;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static float
|
||||
mraa_firmata_pwm_read_replace(mraa_pwm_context dev)
|
||||
{
|
||||
int value = firmata_dev->pins[dev->pin].value;
|
||||
if (value) {
|
||||
return (value + 1) * 8000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_firmata_pwm_enable_replace(mraa_pwm_context dev, int enable)
|
||||
{
|
||||
if (enable) {
|
||||
firmata_pinMode(firmata_dev, dev->pin, MODE_PWM);
|
||||
firmata_dev->pins[dev->pin].value = 0;
|
||||
} else {
|
||||
firmata_pinMode(firmata_dev, dev->pin, MODE_INPUT);
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static void*
|
||||
mraa_firmata_pull_handler(void* vp)
|
||||
{
|
||||
int i, isr_now, isr_prev;
|
||||
isr_prev = 0;
|
||||
while(1) {
|
||||
isr_now = 0;
|
||||
firmata_pull(firmata_dev);
|
||||
// would prefer to send board pointer as argument
|
||||
for(i = 0; i < 14; i++) {
|
||||
isr_now |= (firmata_dev->pins[i].value & 1) << i;
|
||||
}
|
||||
// might want to lock here?
|
||||
isr_detected = isr_prev ^ isr_now; //both edges for now
|
||||
isr_prev = isr_now;
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_firmata_plat_init(const char* uart_dev)
|
||||
{
|
||||
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
firmata_dev = firmata_new(uart_dev);
|
||||
if (firmata_dev == NULL) {
|
||||
syslog(LOG_WARNING, "firmata: Failed to open uart to Firmata dev on %s", uart_dev);
|
||||
fprintf(stderr, "Mraa expected to find a Firmata device on %s, is the port in use?\n", uart_dev);
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// if this isn't working then we have an issue with our uart
|
||||
int retry = 20;
|
||||
while (!firmata_dev->isReady && retry--) {
|
||||
firmata_pull(firmata_dev);
|
||||
}
|
||||
|
||||
if (!retry) {
|
||||
syslog(LOG_ERR, "firmata: Failed to find a valid Firmata board on %s", uart_dev);
|
||||
firmata_close(firmata_dev);
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pthread_create(&thread_id, NULL, mraa_firmata_pull_handler, NULL);
|
||||
|
||||
b->platform_name = "firmata";
|
||||
// do we support 2.5? Or are we more 2.3?
|
||||
// or should we return the flashed sketch name?
|
||||
b->platform_version = firmata_dev->firmware;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
b->adc_supported = 10;
|
||||
b->phy_pin_count = 20;
|
||||
b->i2c_bus_count = 1;
|
||||
b->def_i2c_bus = 0;
|
||||
b->i2c_bus[0].bus_id = 0;
|
||||
b->pwm_min_period = 2048;
|
||||
b->pwm_max_period = 2048;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) calloc(b->phy_pin_count, sizeof(mraa_pininfo_t));
|
||||
if (b->pins == NULL) {
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(b->pins[0].name, "IO0", 8);
|
||||
b->pins[0].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[0].gpio.pinmap = 0;
|
||||
strncpy(b->pins[1].name, "IO1", 8);
|
||||
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[1].gpio.pinmap = 1;
|
||||
strncpy(b->pins[2].name, "IO2", 8);
|
||||
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[2].gpio.pinmap = 2;
|
||||
strncpy(b->pins[3].name, "IO3", 8);
|
||||
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[3].gpio.pinmap = 3;
|
||||
strncpy(b->pins[4].name, "IO4", 8);
|
||||
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[4].gpio.pinmap = 4;
|
||||
strncpy(b->pins[5].name, "IO5", 8);
|
||||
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[5].gpio.pinmap = 5;
|
||||
strncpy(b->pins[6].name, "IO6", 8);
|
||||
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[6].gpio.pinmap = 6;
|
||||
strncpy(b->pins[7].name, "IO7", 8);
|
||||
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[7].gpio.pinmap = 7;
|
||||
strncpy(b->pins[8].name, "IO8", 8);
|
||||
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[8].gpio.pinmap = 8;
|
||||
strncpy(b->pins[9].name, "IO9", 8);
|
||||
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||
b->pins[9].gpio.pinmap = 9;
|
||||
strncpy(b->pins[10].name, "IO10", 8);
|
||||
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[10].gpio.pinmap = 10;
|
||||
strncpy(b->pins[11].name, "IO11", 8);
|
||||
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[11].gpio.pinmap = 11;
|
||||
strncpy(b->pins[12].name, "IO12", 8);
|
||||
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[12].gpio.pinmap = 12;
|
||||
strncpy(b->pins[13].name, "IO13", 8);
|
||||
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[13].gpio.pinmap = 13;
|
||||
strncpy(b->pins[10].name, "A0", 8);
|
||||
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[14].gpio.pinmap = 14;
|
||||
b->pins[14].aio.pinmap = 14;
|
||||
strncpy(b->pins[11].name, "A1", 8);
|
||||
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[15].gpio.pinmap = 15;
|
||||
b->pins[15].aio.pinmap = 15;
|
||||
strncpy(b->pins[12].name, "A2", 8);
|
||||
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[16].gpio.pinmap = 16;
|
||||
b->pins[16].aio.pinmap = 16;
|
||||
strncpy(b->pins[13].name, "A3", 8);
|
||||
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[17].gpio.pinmap = 17;
|
||||
b->pins[17].aio.pinmap = 17;
|
||||
strncpy(b->pins[13].name, "A4", 8);
|
||||
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[18].gpio.pinmap = 18;
|
||||
b->pins[18].aio.pinmap = 18;
|
||||
strncpy(b->pins[13].name, "A5", 8);
|
||||
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
|
||||
b->pins[19].gpio.pinmap = 19;
|
||||
b->pins[19].aio.pinmap = 19;
|
||||
|
||||
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
|
||||
if (b->adv_func == NULL) {
|
||||
free(b->pins);
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b->adv_func->gpio_init_internal_replace = &mraa_firmata_gpio_init_internal_replace;
|
||||
b->adv_func->gpio_mode_replace = &mraa_firmata_gpio_mode_replace;
|
||||
b->adv_func->gpio_dir_replace = &mraa_firmata_gpio_dir_replace;
|
||||
b->adv_func->gpio_edge_mode_replace = &mraa_firmata_gpio_edge_mode_replace;
|
||||
b->adv_func->gpio_interrupt_handler_init_replace = &mraa_firmata_gpio_interrupt_handler_init_replace;
|
||||
b->adv_func->gpio_wait_interrupt_replace = &mraa_firmata_gpio_wait_interrupt_replace;
|
||||
b->adv_func->gpio_read_replace = &mraa_firmata_gpio_read_replace;
|
||||
b->adv_func->gpio_write_replace = &mraa_firmata_gpio_write_replace;
|
||||
b->adv_func->gpio_close_replace = &mraa_firmata_gpio_close_replace;
|
||||
|
||||
b->adv_func->aio_init_internal_replace = &mraa_firmata_aio_init_internal_replace;
|
||||
b->adv_func->aio_read_replace = &mraa_firmata_aio_read;
|
||||
|
||||
b->adv_func->pwm_init_internal_replace = &mraa_firmata_pwm_init_internal_replace;
|
||||
b->adv_func->pwm_write_replace = &mraa_firmata_pwm_write_replace;
|
||||
b->adv_func->pwm_read_replace = &mraa_firmata_pwm_read_replace;
|
||||
b->adv_func->pwm_enable_replace = &mraa_firmata_pwm_enable_replace;
|
||||
|
||||
b->adv_func->i2c_init_bus_replace = &mraa_firmata_i2c_init_bus_replace;
|
||||
b->adv_func->i2c_set_frequency_replace = &mraa_firmata_i2c_frequency;
|
||||
b->adv_func->i2c_address_replace = &mraa_firmata_i2c_address;
|
||||
b->adv_func->i2c_read_replace = &mraa_firmata_i2c_read;
|
||||
b->adv_func->i2c_read_byte_replace = &mraa_firmata_i2c_read_byte;
|
||||
b->adv_func->i2c_read_byte_data_replace = &mraa_firmata_i2c_read_byte_data;
|
||||
b->adv_func->i2c_read_word_data_replace = &mraa_firmata_i2c_read_word_data;
|
||||
b->adv_func->i2c_read_bytes_data_replace = &mraa_firmata_i2c_read_bytes_data;
|
||||
b->adv_func->i2c_write_replace = &mraa_firmata_i2c_write;
|
||||
b->adv_func->i2c_write_byte_replace = &mraa_firmata_i2c_write_byte;
|
||||
b->adv_func->i2c_write_byte_data_replace = &mraa_firmata_i2c_write_byte_data;
|
||||
b->adv_func->i2c_write_word_data_replace = &mraa_firmata_i2c_write_word_data;
|
||||
b->adv_func->i2c_stop_replace = &mraa_firmata_i2c_stop;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
mraa_platform_t
|
||||
mraa_firmata_platform(mraa_board_t* board, const char* uart_dev)
|
||||
{
|
||||
/**
|
||||
* Firmata boards are not something we can detect so we just trust the user
|
||||
* to initialise them themselves and is the only platform type not to be
|
||||
* initialised from mraa_init(). Good luck!
|
||||
*/
|
||||
mraa_board_t* sub_plat = NULL;
|
||||
|
||||
sub_plat = mraa_firmata_plat_init(uart_dev);
|
||||
if (sub_plat != NULL) {
|
||||
sub_plat->platform_type = MRAA_GENERIC_FIRMATA;
|
||||
board->sub_platform = sub_plat;
|
||||
return sub_plat->platform_type;
|
||||
}
|
||||
|
||||
return MRAA_NULL_PLATFORM;
|
||||
}
|
318
src/gpio/gpio.c
318
src/gpio/gpio.c
@@ -34,6 +34,7 @@
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
#define MAX_SIZE 64
|
||||
@@ -46,6 +47,7 @@ mraa_gpio_get_valfp(mraa_gpio_context dev)
|
||||
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
|
||||
dev->value_fp = open(bu, O_RDWR);
|
||||
if (dev->value_fp == -1) {
|
||||
syslog(LOG_ERR, "gpio%i: Failed to open 'value': %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
|
||||
|
||||
mraa_gpio_context dev = (mraa_gpio_context) calloc(1, sizeof(struct _gpio));
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "gpio: Failed to allocate memory for context");
|
||||
syslog(LOG_CRIT, "gpio%i: Failed to allocate memory for context", pin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -102,15 +104,15 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
|
||||
} else {
|
||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||
if (export == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to open export for writing");
|
||||
status = MRAA_ERROR_NO_RESOURCES;
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s", pin, strerror(errno));
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_internal_cleanup;
|
||||
}
|
||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
if (write(export, bu, length * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to write %d to export", dev->pin);
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s", pin, strerror(errno));
|
||||
close(export);
|
||||
status = MRAA_ERROR_NO_RESOURCES;
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_internal_cleanup;
|
||||
}
|
||||
dev->owner = 1;
|
||||
@@ -131,38 +133,37 @@ mraa_gpio_init(int pin)
|
||||
{
|
||||
mraa_board_t* board = plat;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "gpio: platform not initialised");
|
||||
syslog(LOG_ERR, "gpio%i: init: platform not initialised", pin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_is_sub_platform_id(pin)) {
|
||||
syslog(LOG_NOTICE, "gpio: Using sub platform");
|
||||
syslog(LOG_NOTICE, "gpio%i: init: Using sub platform", pin);
|
||||
board = board->sub_platform;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "gpio: Sub platform Not Initialised");
|
||||
syslog(LOG_ERR, "gpio%i: init: Sub platform not initialised", pin);
|
||||
return NULL;
|
||||
}
|
||||
pin = mraa_get_sub_platform_index(pin);
|
||||
}
|
||||
|
||||
if (pin < 0 || pin > board->phy_pin_count) {
|
||||
syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin);
|
||||
if (pin < 0 || pin >= board->phy_pin_count) {
|
||||
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)", pin, board->phy_pin_count);
|
||||
return NULL;
|
||||
}
|
||||
if (board->pins[pin].capabilites.gpio != 1) {
|
||||
syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin);
|
||||
if (board->pins[pin].capabilities.gpio != 1) {
|
||||
syslog(LOG_ERR, "gpio: init: pin %i not capable of gpio", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (board->pins[pin].gpio.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(board->pins[pin].gpio) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "gpio: unable to setup muxes");
|
||||
syslog(LOG_ERR, "gpio%i: init: unable to setup muxes", pin);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mraa_gpio_context r = mraa_gpio_init_internal(board->adv_func, board->pins[pin].gpio.pinmap);
|
||||
if (r == NULL) {
|
||||
syslog(LOG_CRIT, "gpio: mraa_gpio_init_raw(%d) returned error", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (r->phy_pin == -1)
|
||||
@@ -199,12 +200,12 @@ mraa_gpio_wait_interrupt(int fd
|
||||
struct pollfd pfd[2];
|
||||
|
||||
if (control_fd < 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fd < 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// setup poll on POLLPRI
|
||||
@@ -218,14 +219,14 @@ mraa_gpio_wait_interrupt(int fd
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
// Wait for it forever or until pthread_cancel
|
||||
// poll is a cancelable point like sleep()
|
||||
int x = poll(pfd, 1, -1);
|
||||
poll(pfd, 1, -1);
|
||||
#else
|
||||
// setup poll on the controling fd
|
||||
pfd[1].fd = control_fd;
|
||||
pfd[1].events = 0; // POLLHUP, POLLERR, and POLLNVAL
|
||||
|
||||
// Wait for it forever or until control fd is closed
|
||||
int x = poll(pfd, 2, -1);
|
||||
poll(pfd, 2, -1);
|
||||
#endif
|
||||
|
||||
// do a final read to clear interrupt
|
||||
@@ -234,36 +235,6 @@ mraa_gpio_wait_interrupt(int fd
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
pthread_key_t env_key;
|
||||
|
||||
extern JavaVM *globVM;
|
||||
static pthread_once_t env_key_init = PTHREAD_ONCE_INIT;
|
||||
|
||||
jmethodID runGlobal;
|
||||
|
||||
static void make_env_key(void)
|
||||
{
|
||||
|
||||
JNIEnv *jenv;
|
||||
(*globVM)->GetEnv(globVM, (void **)&jenv, JNI_VERSION_1_6);
|
||||
|
||||
jclass rcls = (*jenv)->FindClass(jenv, "java/lang/Runnable");
|
||||
jmethodID runm = (*jenv)->GetMethodID(jenv, rcls, "run", "()V");
|
||||
|
||||
runGlobal = (jmethodID)(*jenv)->NewGlobalRef(jenv, (jobject)runm);
|
||||
|
||||
pthread_key_create(&env_key, NULL);
|
||||
}
|
||||
|
||||
void mraa_java_isr_callback(void* data)
|
||||
{
|
||||
JNIEnv *jenv = (JNIEnv *) pthread_getspecific(env_key);
|
||||
(*jenv)->CallVoidMethod(jenv, (jobject)data, runGlobal);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void*
|
||||
mraa_gpio_interrupt_handler(void* arg)
|
||||
{
|
||||
@@ -280,14 +251,14 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
|
||||
fp = open(bu, O_RDONLY);
|
||||
if (fp < 0) {
|
||||
syslog(LOG_ERR, "gpio: failed to open gpio%d/value", dev->pin);
|
||||
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to open 'value' : %s", dev->pin, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_PTHREAD_CANCEL
|
||||
if (pipe(dev->isr_control_pipe)) {
|
||||
syslog(LOG_ERR, "gpio: failed to create isr control pipe");
|
||||
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to create isr control pipe: %s", dev->pin, strerror(errno));
|
||||
close(fp);
|
||||
return NULL;
|
||||
}
|
||||
@@ -295,21 +266,15 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
|
||||
dev->isr_value_fp = fp;
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
JNIEnv *jenv;
|
||||
if(dev->isr == mraa_java_isr_callback) {
|
||||
jint err = (*globVM)->AttachCurrentThreadAsDaemon(globVM, (void **)&jenv, NULL);
|
||||
|
||||
if (err != JNI_OK) {
|
||||
if (lang_func->java_attach_thread != NULL) {
|
||||
if (dev->isr == lang_func->java_isr_callback) {
|
||||
if (lang_func->java_attach_thread() != MRAA_SUCCESS) {
|
||||
close(dev->isr_value_fp);
|
||||
dev->isr_value_fp = -1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_once(&env_key_init, make_env_key);
|
||||
pthread_setspecific(env_key, jenv);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
if (IS_FUNC_DEFINED(dev, gpio_wait_interrupt_replace)) {
|
||||
@@ -325,71 +290,11 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
#endif
|
||||
#ifdef SWIGPYTHON
|
||||
// In order to call a python object (all python functions are objects) we
|
||||
// need to aquire the GIL (Global Interpreter Lock). This may not always be
|
||||
// necessary but especially if doing IO (like print()) python will segfault
|
||||
// if we do not hold a lock on the GIL
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyObject* arglist;
|
||||
PyObject* ret;
|
||||
arglist = Py_BuildValue("(O)", dev->isr_args);
|
||||
if (arglist == NULL) {
|
||||
syslog(LOG_ERR, "gpio: Py_BuildValue NULL");
|
||||
if (lang_func->python_isr != NULL) {
|
||||
lang_func->python_isr(dev->isr, dev->isr_args);
|
||||
} else {
|
||||
ret = PyEval_CallObject((PyObject*) dev->isr, arglist);
|
||||
if (ret == NULL) {
|
||||
syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
|
||||
PyObject *pvalue, *ptype, *ptraceback;
|
||||
PyObject *pvalue_pystr, *ptype_pystr, *ptraceback_pystr;
|
||||
char *pvalue_cstr, *ptype_cstr, *ptraceback_cstr;
|
||||
PyErr_Fetch(&pvalue, &ptype, &ptraceback);
|
||||
pvalue_pystr = PyObject_Str(pvalue);
|
||||
ptype_pystr = PyObject_Str(ptype);
|
||||
ptraceback_pystr = PyObject_Str(ptraceback);
|
||||
// Python2
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
pvalue_cstr = PyString_AsString(pvalue_pystr);
|
||||
ptype_cstr = PyString_AsString(ptype_pystr);
|
||||
ptraceback_cstr = PyString_AsString(ptraceback_pystr);
|
||||
// Python 3 and up
|
||||
#elif PY_VERSION_HEX >= 0x03000000
|
||||
// In Python 3 we need one extra conversion
|
||||
PyObject *pvalue_ustr, *ptype_ustr, *ptraceback_ustr;
|
||||
pvalue_ustr = PyUnicode_AsUTF8String(pvalue_pystr);
|
||||
pvalue_cstr = PyBytes_AsString(pvalue_ustr);
|
||||
ptype_ustr = PyUnicode_AsUTF8String(ptype_pystr);
|
||||
ptype_cstr = PyBytes_AsString(ptype_ustr);
|
||||
ptraceback_ustr = PyUnicode_AsUTF8String(ptraceback_pystr);
|
||||
ptraceback_cstr = PyBytes_AsString(ptraceback_ustr);
|
||||
#endif // PY_VERSION_HEX
|
||||
syslog(LOG_ERR, "gpio: the error was %s:%s:%s",
|
||||
pvalue_cstr,
|
||||
ptype_cstr,
|
||||
ptraceback_cstr
|
||||
);
|
||||
Py_XDECREF(pvalue);
|
||||
Py_XDECREF(ptype);
|
||||
Py_XDECREF(ptraceback);
|
||||
Py_XDECREF(pvalue_pystr);
|
||||
Py_XDECREF(ptype_pystr);
|
||||
Py_XDECREF(ptraceback_pystr);
|
||||
// Python 3 and up
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
Py_XDECREF(pvalue_ustr);
|
||||
Py_XDECREF(ptype_ustr);
|
||||
Py_XDECREF(ptraceback_ustr);
|
||||
#endif // PY_VERSION_HEX
|
||||
} else {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
Py_DECREF(arglist);
|
||||
dev->isr(dev->isr_args);
|
||||
}
|
||||
|
||||
PyGILState_Release(gilstate);
|
||||
#else
|
||||
dev->isr(dev->isr_args);
|
||||
#endif
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
#endif
|
||||
@@ -402,13 +307,14 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
close(dev->isr_value_fp);
|
||||
dev->isr_value_fp = -1;
|
||||
}
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
|
||||
if(dev->isr == mraa_java_isr_callback) {
|
||||
(*jenv)->DeleteGlobalRef(jenv, (jobject)dev->isr_args);
|
||||
(*globVM)->DetachCurrentThread(globVM);
|
||||
if (lang_func->java_detach_thread != NULL && lang_func->java_delete_global_ref != NULL) {
|
||||
if (dev->isr == lang_func->java_isr_callback) {
|
||||
lang_func->java_delete_global_ref(dev->isr_args);
|
||||
lang_func->java_detach_thread();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -417,7 +323,12 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
mraa_result_t
|
||||
mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
{
|
||||
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: edge_mode: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
|
||||
return dev->advance_func->gpio_edge_mode_replace(dev, mode);
|
||||
|
||||
if (dev->value_fp != -1) {
|
||||
@@ -430,7 +341,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
|
||||
int edge = open(filepath, O_RDWR);
|
||||
if (edge == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to open edge for writing");
|
||||
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to open 'edge' for writing: %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -454,9 +365,9 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(edge, bu, length * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to write to edge");
|
||||
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to write to 'edge': %s", dev->pin, strerror(errno));
|
||||
close(edge);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
close(edge);
|
||||
@@ -466,26 +377,35 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
mraa_result_t
|
||||
mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: isr: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_isr_replace)) {
|
||||
return dev->advance_func->gpio_isr_replace(dev, mode, fptr, args);
|
||||
}
|
||||
|
||||
// we only allow one isr per mraa_gpio_context
|
||||
if (dev->thread_id != 0) {
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
|
||||
if (MRAA_SUCCESS != mraa_gpio_edge_mode(dev, mode)) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
mraa_result_t ret = mraa_gpio_edge_mode(dev, mode);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev->isr = fptr;
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
JNIEnv *jenv;
|
||||
/* Most UPM sensors use the C API, the global ref must be created here. */
|
||||
|
||||
/* Most UPM sensors use the C API, the Java global ref must be created here. */
|
||||
/* The reason for checking the callback function is internal callbacks. */
|
||||
if (fptr == mraa_java_isr_callback) {
|
||||
(*globVM)->GetEnv(globVM, (void **)&jenv, JNI_VERSION_1_6);
|
||||
jobject grunnable = (*jenv)->NewGlobalRef(jenv, (jobject) args);
|
||||
args = (void *) grunnable;
|
||||
if (lang_func->java_create_global_ref != NULL) {
|
||||
if (dev->isr == lang_func->java_isr_callback) {
|
||||
args = lang_func->java_create_global_ref(args);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
dev->isr_args = args;
|
||||
pthread_create(&dev->thread_id, NULL, mraa_gpio_interrupt_handler, (void*) dev);
|
||||
|
||||
@@ -497,6 +417,14 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
|
||||
if (dev == NULL) {
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_isr_exit_replace)) {
|
||||
return dev->advance_func->gpio_isr_exit_replace(dev);
|
||||
}
|
||||
|
||||
// wasting our time, there is no isr to exit from
|
||||
if (dev->thread_id == 0 && dev->isr_value_fp == -1) {
|
||||
return ret;
|
||||
@@ -510,12 +438,12 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
if ((dev->thread_id != 0)) {
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
if ((pthread_cancel(dev->thread_id) != 0) || (pthread_join(dev->thread_id, NULL) != 0)) {
|
||||
ret = MRAA_ERROR_INVALID_HANDLE;
|
||||
ret = MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
#else
|
||||
close(dev->isr_control_pipe[1]);
|
||||
if (pthread_join(dev->thread_id, NULL) != 0)
|
||||
ret = MRAA_ERROR_INVALID_HANDLE;
|
||||
ret = MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
close(dev->isr_control_pipe[0]);
|
||||
dev->isr_control_pipe[0] = dev->isr_control_pipe[1] = -1;
|
||||
@@ -525,7 +453,7 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
// close the filehandle in case it's still open
|
||||
if (dev->isr_value_fp != -1) {
|
||||
if (close(dev->isr_value_fp) != 0) {
|
||||
ret = MRAA_ERROR_INVALID_PARAMETER;
|
||||
ret = MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,6 +467,11 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
mraa_result_t
|
||||
mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: mode: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_mode_replace))
|
||||
return dev->advance_func->gpio_mode_replace(dev, mode);
|
||||
|
||||
@@ -558,7 +491,7 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
|
||||
int drive = open(filepath, O_WRONLY);
|
||||
if (drive == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to open drive for writing");
|
||||
syslog(LOG_ERR, "gpio%i: mode: Failed to open 'drive' for writing: %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -582,8 +515,8 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(drive, bu, length * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to write to drive mode");
|
||||
close(drive);
|
||||
syslog(LOG_ERR, "gpio%i: mode: Failed to write to 'drive': %s", dev->pin, strerror(errno));
|
||||
close(drive);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -596,6 +529,11 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
mraa_result_t
|
||||
mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: dir: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_dir_replace)) {
|
||||
return dev->advance_func->gpio_dir_replace(dev, dir);
|
||||
}
|
||||
@@ -607,9 +545,6 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
}
|
||||
}
|
||||
|
||||
if (dev == NULL) {
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
if (dev->value_fp != -1) {
|
||||
close(dev->value_fp);
|
||||
dev->value_fp = -1;
|
||||
@@ -628,8 +563,9 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
case MRAA_GPIO_OUT_LOW:
|
||||
return mraa_gpio_write(dev, 0);
|
||||
default:
|
||||
syslog(LOG_ERR, "gpio%i: dir: Failed to open 'direction' for writing: %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char bu[MAX_SIZE];
|
||||
@@ -654,7 +590,8 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
|
||||
if (write(direction, bu, length * sizeof(char)) == -1) {
|
||||
close(direction);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
syslog(LOG_ERR, "gpio%i: dir: Failed to write to 'direction': %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
close(direction);
|
||||
@@ -671,9 +608,24 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
int fd, rc;
|
||||
mraa_result_t result = MRAA_SUCCESS;
|
||||
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: read_dir: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (dir == NULL) {
|
||||
syslog(LOG_ERR, "gpio: read_dir: output parameter for dir is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_read_dir_replace)) {
|
||||
return dev->advance_func->gpio_read_dir_replace(dev, dir);
|
||||
}
|
||||
|
||||
snprintf(filepath, MAX_SIZE, SYSFS_CLASS_GPIO "/gpio%d/direction", dev->pin);
|
||||
fd = open(filepath, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
syslog(LOG_ERR, "gpio%i: read_dir: Failed to open 'direction' for reading: %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -681,6 +633,7 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
rc = read(fd, value, sizeof(value));
|
||||
close(fd);
|
||||
if (rc <= 0) {
|
||||
syslog(LOG_ERR, "gpio%i: read_dir: Failed to read 'direction': %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -689,7 +642,8 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
} else if (strcmp(value, "in\n") == 0) {
|
||||
*dir = MRAA_GPIO_IN;
|
||||
} else {
|
||||
result = MRAA_ERROR_INVALID_RESOURCE;
|
||||
syslog(LOG_ERR, "gpio%i: read_dir: unknown direction: %s", dev->pin, value);
|
||||
result = MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -698,8 +652,10 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
int
|
||||
mraa_gpio_read(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev == NULL)
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: read: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_read_replace))
|
||||
return dev->advance_func->gpio_read_replace(dev);
|
||||
@@ -709,7 +665,6 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
|
||||
if (dev->value_fp == -1) {
|
||||
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "gpio: Failed to get value file pointer");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@@ -718,7 +673,7 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
}
|
||||
char bu[2];
|
||||
if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) {
|
||||
syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs");
|
||||
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
lseek(dev->value_fp, 0, SEEK_SET);
|
||||
@@ -729,8 +684,10 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
mraa_result_t
|
||||
mraa_gpio_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
if (dev == NULL)
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: write: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (dev->mmap_write != NULL)
|
||||
return dev->mmap_write(dev, value);
|
||||
@@ -752,13 +709,15 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
|
||||
}
|
||||
|
||||
if (lseek(dev->value_fp, 0, SEEK_SET) == -1) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
syslog(LOG_ERR, "gpio%i: write: Failed to lseek 'value': %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
char bu[MAX_SIZE];
|
||||
int length = snprintf(bu, sizeof(bu), "%d", value);
|
||||
if (write(dev->value_fp, bu, length * sizeof(char)) == -1) {
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "gpio%i: write: Failed to write to 'value': %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_write_post))
|
||||
@@ -771,16 +730,16 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
|
||||
{
|
||||
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
|
||||
if (unexport == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to open unexport for writing");
|
||||
syslog(LOG_ERR, "gpio%i: Failed to open 'unexport' for writing: %s", dev->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
char bu[MAX_SIZE];
|
||||
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
if (write(unexport, bu, length * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "gpio: Failed to write to unexport");
|
||||
syslog(LOG_ERR, "gpio%i: Failed to write to 'unexport': %s", dev->pin, strerror(errno));
|
||||
close(unexport);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
close(unexport);
|
||||
@@ -790,10 +749,15 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
|
||||
static mraa_result_t
|
||||
mraa_gpio_unexport(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: unexport: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (dev->owner) {
|
||||
return mraa_gpio_unexport_force(dev);
|
||||
}
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
@@ -801,6 +765,16 @@ mraa_gpio_close(mraa_gpio_context dev)
|
||||
{
|
||||
mraa_result_t result = MRAA_SUCCESS;
|
||||
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: close: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_close_replace)) {
|
||||
return dev->advance_func->gpio_close_replace(dev);
|
||||
}
|
||||
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_close_pre)) {
|
||||
result = dev->advance_func->gpio_close_pre(dev);
|
||||
}
|
||||
@@ -817,9 +791,10 @@ mraa_result_t
|
||||
mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
syslog(LOG_ERR, "gpio: owner: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
syslog(LOG_DEBUG, "gpio: Set owner to %d", (int) own);
|
||||
syslog(LOG_DEBUG, "gpio%i: owner: Set owner to %d", dev->pin, (int) own);
|
||||
dev->owner = own;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -827,11 +802,16 @@ mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
|
||||
mraa_result_t
|
||||
mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: use_mmaped: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_mmap_setup)) {
|
||||
return dev->advance_func->gpio_mmap_setup(dev, mmap_en);
|
||||
}
|
||||
|
||||
syslog(LOG_ERR, "gpio: mmap not implemented on this platform");
|
||||
syslog(LOG_ERR, "gpio%i: use_mmaped: mmap not implemented on this platform", dev->pin);
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -839,7 +819,7 @@ int
|
||||
mraa_gpio_get_pin(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: context is invalid");
|
||||
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
return dev->phy_pin;
|
||||
@@ -849,7 +829,7 @@ int
|
||||
mraa_gpio_get_pin_raw(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "gpio: context is invalid");
|
||||
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
return dev->pin;
|
||||
|
147
src/i2c/i2c.c
147
src/i2c/i2c.c
@@ -34,9 +34,13 @@
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include "linux/i2c-dev.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef union i2c_smbus_data_union {
|
||||
uint8_t byte; ///< data byte
|
||||
@@ -78,7 +82,7 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
|
||||
|
||||
mraa_i2c_context dev = (mraa_i2c_context) calloc(1, sizeof(struct _i2c));
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "i2c: Failed to allocate memory for context");
|
||||
syslog(LOG_CRIT, "i2c%i_init: Failed to allocate memory for context", bus);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -99,13 +103,13 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
|
||||
char filepath[32];
|
||||
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
||||
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
|
||||
syslog(LOG_ERR, "i2c: Failed to open requested i2c port %s", filepath);
|
||||
status = MRAA_ERROR_NO_RESOURCES;
|
||||
syslog(LOG_ERR, "i2c%i_init: Failed to open requested i2c port %s: %s", bus, filepath, strerror(errno));
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_internal_cleanup;
|
||||
}
|
||||
|
||||
if (ioctl(dev->fh, I2C_FUNCS, &dev->funcs) < 0) {
|
||||
syslog(LOG_CRIT, "i2c: Failed to get I2C_FUNC map from device");
|
||||
syslog(LOG_CRIT, "i2c%i_init: Failed to get I2C_FUNC map from device: %s", bus, strerror(errno));
|
||||
dev->funcs = 0;
|
||||
}
|
||||
}
|
||||
@@ -133,39 +137,39 @@ mraa_i2c_init(int bus)
|
||||
{
|
||||
mraa_board_t* board = plat;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "i2c: Platform Not Initialised");
|
||||
syslog(LOG_ERR, "i2c%i_init: Platform Not Initialised", bus);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_is_sub_platform_id(bus)) {
|
||||
syslog(LOG_NOTICE, "i2c: Using sub platform");
|
||||
syslog(LOG_NOTICE, "i2c%i_init: Using sub platform", bus);
|
||||
board = board->sub_platform;
|
||||
if (board == NULL) {
|
||||
syslog(LOG_ERR, "i2c: Sub platform Not Initialised");
|
||||
syslog(LOG_ERR, "i2c%i_init: Sub platform Not Initialised", bus);
|
||||
return NULL;
|
||||
}
|
||||
bus = mraa_get_sub_platform_index(bus);
|
||||
}
|
||||
syslog(LOG_NOTICE, "i2c: Selected bus %d", bus);
|
||||
syslog(LOG_NOTICE, "i2c_init: Selected bus %d", bus);
|
||||
|
||||
if (board->i2c_bus_count == 0) {
|
||||
syslog(LOG_ERR, "No i2c buses defined in platform");
|
||||
syslog(LOG_ERR, "i2c_init: No i2c buses defined in platform");
|
||||
return NULL;
|
||||
}
|
||||
if (bus >= board->i2c_bus_count) {
|
||||
syslog(LOG_ERR, "Above i2c bus count");
|
||||
syslog(LOG_ERR, "i2c_init: i2c%i over i2c bus count", bus);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (board->i2c_bus[bus].bus_id == -1) {
|
||||
syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
|
||||
syslog(LOG_ERR, "Invalid i2c bus %i, moving to default i2c bus %i", bus, board->def_i2c_bus);
|
||||
bus = board->def_i2c_bus;
|
||||
}
|
||||
if (!board->no_bus_mux) {
|
||||
int pos = board->i2c_bus[bus].sda;
|
||||
if (board->pins[pos].i2c.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "i2c: Failed to set-up i2c sda multiplexer");
|
||||
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c sda multiplexer", bus);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -173,7 +177,7 @@ mraa_i2c_init(int bus)
|
||||
pos = board->i2c_bus[bus].scl;
|
||||
if (board->pins[pos].i2c.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "i2c: Failed to set-up i2c scl multiplexer");
|
||||
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c scl multiplexer", bus);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -193,6 +197,11 @@ mraa_i2c_init_raw(unsigned int bus)
|
||||
mraa_result_t
|
||||
mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: frequency: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_set_frequency_replace)) {
|
||||
return dev->advance_func->i2c_set_frequency_replace(dev, mode);
|
||||
}
|
||||
@@ -202,6 +211,11 @@ mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
|
||||
int
|
||||
mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: read: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bytes_read = 0;
|
||||
if (IS_FUNC_DEFINED(dev, i2c_read_replace)) {
|
||||
bytes_read = dev->advance_func->i2c_read_replace(dev, data, length);
|
||||
@@ -213,44 +227,59 @@ mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
return length;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
int
|
||||
mraa_i2c_read_byte(mraa_i2c_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: read_byte: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_read_byte_replace))
|
||||
return dev->advance_func->i2c_read_byte_replace(dev);
|
||||
i2c_smbus_data_t d;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD, I2C_SMBUS_BYTE, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
syslog(LOG_ERR, "i2c%i: read_byte: Access error: %s", dev->busnum, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0x0FF & d.byte;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
int
|
||||
mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: read_byte_data: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_read_byte_data_replace))
|
||||
return dev->advance_func->i2c_read_byte_data_replace(dev, command);
|
||||
i2c_smbus_data_t d;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
syslog(LOG_ERR, "i2c%i: read_byte_data: Access error: %s", dev->busnum, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0x0FF & d.byte;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
int
|
||||
mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: read_word_data: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_read_word_data_replace))
|
||||
return dev->advance_func->i2c_read_word_data_replace(dev, command);
|
||||
i2c_smbus_data_t d;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
syslog(LOG_ERR, "i2c%i: read_word_data: Access error: %s", dev->busnum, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0xFFFF & d.word;
|
||||
}
|
||||
@@ -258,6 +287,11 @@ mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
||||
int
|
||||
mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: read_bytes_data: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_read_bytes_data_replace))
|
||||
return dev->advance_func->i2c_read_bytes_data_replace(dev, command, data, length);
|
||||
struct i2c_rdwr_ioctl_data d;
|
||||
@@ -266,21 +300,33 @@ mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, i
|
||||
m[0].addr = dev->addr;
|
||||
m[0].flags = 0x00;
|
||||
m[0].len = 1;
|
||||
m[0].buf = &command;
|
||||
m[0].buf = (char*) &command;
|
||||
m[1].addr = dev->addr;
|
||||
m[1].flags = I2C_M_RD;
|
||||
m[1].len = length;
|
||||
m[1].buf = data;
|
||||
m[1].buf = (char*) data;
|
||||
|
||||
d.msgs = m;
|
||||
d.nmsgs = 2;
|
||||
|
||||
return ioctl(dev->fh, I2C_RDWR, &d) < 0 ? -1 : length;
|
||||
int ret = ioctl(dev->fh, I2C_RDWR, &d);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "i2c%i: read_bytes_data: Access error: %s", dev->busnum, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: write: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_write_replace))
|
||||
return dev->advance_func->i2c_write_replace(dev, data, length);
|
||||
i2c_smbus_data_t d;
|
||||
@@ -298,18 +344,27 @@ mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||
}
|
||||
d.block[0] = length;
|
||||
|
||||
return mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &d);
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c%i: write: Access error: %s", dev->busnum, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: write_byte: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_write_byte_replace)) {
|
||||
return dev->advance_func->i2c_write_byte_replace(dev, data);
|
||||
} else {
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "i2c%i: write_byte: Access error: %s", dev->busnum, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -318,13 +373,18 @@ mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
|
||||
mraa_result_t
|
||||
mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: write_byte_data: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_write_byte_data_replace))
|
||||
return dev->advance_func->i2c_write_byte_data_replace(dev, data, command);
|
||||
i2c_smbus_data_t d;
|
||||
d.byte = data;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "i2c%i: write_byte_data: Access error: %s", dev->busnum, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -332,13 +392,18 @@ mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t
|
||||
mraa_result_t
|
||||
mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: write_word_data: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_write_word_data_replace))
|
||||
return dev->advance_func->i2c_write_word_data_replace(dev, data, command);
|
||||
i2c_smbus_data_t d;
|
||||
d.word = data;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "i2c%i: write_word_data: Access error: %s", dev->busnum, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -347,6 +412,7 @@ mraa_result_t
|
||||
mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: address: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -355,8 +421,8 @@ mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
|
||||
return dev->advance_func->i2c_address_replace(dev, addr);
|
||||
} else {
|
||||
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr);
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "i2c%i: address: Failed to set slave address %d: %s", dev->busnum, addr, strerror(errno));
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -366,6 +432,15 @@ mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
|
||||
mraa_result_t
|
||||
mraa_i2c_stop(mraa_i2c_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "i2c: stop: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, i2c_stop_replace)) {
|
||||
return dev->advance_func->i2c_stop_replace(dev);
|
||||
}
|
||||
|
||||
free(dev);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user