Compare commits
44 Commits
pydoc-fix
...
rename_int
Author | SHA1 | Date | |
---|---|---|---|
|
68554d4fc6 | ||
|
2623f9ad37 | ||
|
594e548f77 | ||
|
49ef1623b2 | ||
|
37deb5003b | ||
|
980dfce80e | ||
|
08e270818a | ||
|
6bac8594a5 | ||
|
11bbd05533 | ||
|
1d4b19dc4b | ||
|
02a7fbf191 | ||
|
ae15b10997 | ||
|
be22844922 | ||
|
92fdb8aa01 | ||
|
def454e33c | ||
|
122cab1f1e | ||
|
6c85b61daa | ||
|
139d42d084 | ||
|
8e38c762f0 | ||
|
590f733ff9 | ||
|
045ceb084f | ||
|
ff3b3004da | ||
|
5cb2bd220e | ||
|
8ec4fcb333 | ||
|
bf2a504774 | ||
|
9bc91f4b12 | ||
|
6180ddaa8e | ||
|
8a93351f0e | ||
|
1591b92605 | ||
|
22b0f63238 | ||
|
2832909856 | ||
|
636c9feb4f | ||
|
0292c960b3 | ||
|
9ff47aa64a | ||
|
a704a956ea | ||
|
94b7477212 | ||
|
1589389c3f | ||
|
bdbbfd03dd | ||
|
9030ae2eeb | ||
|
3a638caf01 | ||
|
07f6181c91 | ||
|
0630c5f505 | ||
|
4277a3ee23 | ||
|
c976e9f982 |
@@ -10,6 +10,10 @@ env:
|
||||
- JSONPLAT=true NODE012=true
|
||||
- JSONPLAT=true NODE4=true
|
||||
- JSONPLAT=true NODE5=true
|
||||
- MOCK=true NODE010=true
|
||||
- MOCK=true NODE012=true
|
||||
- MOCK=true NODE4=true
|
||||
- MOCK=true NODE5=true
|
||||
# node010 npm builds don't work in clang and anyone using npm should want to
|
||||
# use something newer
|
||||
- NPM=true NODE4=true
|
||||
@@ -26,6 +30,7 @@ before_script:
|
||||
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
|
||||
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
|
||||
- if [ "${JSONPLAT}" ]; then export JSONPLAT=ON; else export JSONPLAT=OFF; fi
|
||||
- if [ "${MOCK}" ]; then export BUILDARCH="MOCK"; else export BUILDARCH=""; fi
|
||||
- if [ "${NODE010}" ]; then nvm install 0.10; fi
|
||||
- if [ "${NODE012}" ]; then nvm install 0.12; fi
|
||||
- if [ "${NODE4}" ]; then nvm install 4.1; fi
|
||||
@@ -34,8 +39,8 @@ before_script:
|
||||
# Handle 0.10 NODE_ROOT_DIR differently than other versions
|
||||
- wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && ./configure --prefix=/home/travis/ && make && make install && cd ..
|
||||
script:
|
||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
||||
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
|
||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA BUILDARCH=$BUILDARCH JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
||||
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DBUILDARCH="$BUILDARCH" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
|
||||
# simple test to see if we can load our node module
|
||||
- if [ ${NPM} ]; then cd build/Release/obj.target/ && node -e "var m = require('./mraa.node'); m.getVersion()";fi
|
||||
addons:
|
||||
|
@@ -29,8 +29,8 @@ LOCAL_SRC_FILES := \
|
||||
src/uart/uart.c \
|
||||
src/x86/x86.c \
|
||||
src/iio/iio.c \
|
||||
src/x86/intel_galileo_rev_d.c \
|
||||
src/x86/intel_galileo_rev_g.c \
|
||||
src/x86/intel_galileo_gen_1.c \
|
||||
src/x86/intel_galileo_gen_2.c \
|
||||
src/x86/intel_edison_fab_c.c \
|
||||
src/x86/intel_de3815.c \
|
||||
src/x86/intel_nuc5.c \
|
||||
|
@@ -1,10 +1,70 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project (mraa C)
|
||||
project (mraa C CXX)
|
||||
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer ")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
|
||||
###############################################################################
|
||||
# Detect supported warning flags
|
||||
# Modified from work By Dan Liew (fpbench - MIT)
|
||||
# https://github.com/delcypher/fp-bench/blob/master/CMakeLists.txt
|
||||
###############################################################################
|
||||
# Warnings for both the C and C++ compiler
|
||||
|
||||
set (MRAA_BOTH_WARNING_FLAGS
|
||||
-Wall
|
||||
-Werror=main
|
||||
-Wformat
|
||||
-Wmain
|
||||
-Wuninitialized
|
||||
-Winit-self
|
||||
)
|
||||
|
||||
# Warning flags for the C compiler only
|
||||
set (MRAA_C_WARNING_FLAGS
|
||||
-Werror=implicit
|
||||
-Werror=missing-parameter-type
|
||||
)
|
||||
|
||||
# Warning flags for the C++ compiler only
|
||||
set (MRAA_CXX_WARNING_FLAGS
|
||||
-Wnon-virtual-dtor
|
||||
-Woverloaded-virtual
|
||||
-Wreorder
|
||||
)
|
||||
|
||||
include (CheckCCompilerFlag)
|
||||
include (CheckCXXCompilerFlag)
|
||||
function (MRAA_SANITIZE_FLAG_NAME OUTPUT_VAR FLAG)
|
||||
string (REPLACE "-" "_" SANITIZED_FLAG_NAME "${FLAG}")
|
||||
string (REPLACE "/" "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
|
||||
string (REPLACE "=" "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
|
||||
string (REPLACE " " "_" SANITIZED_FLAG_NAME "${SANITIZED_FLAG_NAME}")
|
||||
set (${OUTPUT_VAR} "${SANITIZED_FLAG_NAME}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
# Globally set C compiler warning flags that are supported and emit
|
||||
# a warning about unsupported flags
|
||||
foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_C_WARNING_FLAGS})
|
||||
MRAA_SANITIZE_FLAG_NAME(SANITIZED_FLAG_NAME "${flag}")
|
||||
CHECK_C_COMPILER_FLAG("${flag}" HAS_C_${SANITIZED_FLAG_NAME})
|
||||
if (HAS_C_${SANITIZED_FLAG_NAME})
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
|
||||
else ()
|
||||
message (WARNING "C compiler does not support flag \"${flag}\"")
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# Globally set C++ compiler warning flags that are supported and emit
|
||||
# a warning about unsupported flags
|
||||
foreach (flag ${MRAA_BOTH_WARNING_FLAGS} ${MRAA_CXX_WARNING_FLAGS})
|
||||
MRAA_SANITIZE_FLAG_NAME (SANITIZED_FLAG_NAME "${flag}")
|
||||
CHECK_CXX_COMPILER_FLAG ("${flag}" HAS_CXX_${SANITIZED_FLAG_NAME})
|
||||
if (HAS_CXX_${SANITIZED_FLAG_NAME})
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
|
||||
else ()
|
||||
message (WARNING "C++ compiler does not support flag \"${flag}\"")
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||
include(GNUInstallDirs)
|
||||
@@ -31,7 +91,7 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v1.2.3-dirty")
|
||||
set (VERSION "v1.4.0")
|
||||
endif ()
|
||||
|
||||
message (STATUS "INFO - libmraa Version ${VERSION}")
|
||||
|
@@ -10,7 +10,8 @@ with:
|
||||
|
||||
The recommended method to contribute is to fork on github, and then send pull
|
||||
requests to the main project. You can open issues if you find any bugs/have
|
||||
questions.
|
||||
questions. If you want to work on a large feature then we suggest you file an
|
||||
issue first so we can avoid dissapointments come merging time!
|
||||
|
||||
If you'd rather not use github you are more than welcome to send git formatted
|
||||
patches to our mailing list mraa@lists.01.org which you can register for access
|
||||
@@ -42,6 +43,16 @@ job. Few exceptions to coding styles:
|
||||
|
||||
Use common sense and don't be afraid to challenge something if it doesn't make sense!
|
||||
|
||||
Author Rules
|
||||
------------
|
||||
|
||||
If you create a file, then add yourself as the Author at the top. If you did a
|
||||
large contribution to it (or if you want to ;-)), then fee free to add yourself
|
||||
to the contributors list in that file. You can also add your own copyright
|
||||
statement to the file but cannot add a license of your own. If you're borrowing
|
||||
code that comes from a project with another license, make sure to explicitly
|
||||
note this in your PR.
|
||||
|
||||
Code signing
|
||||
------------
|
||||
|
||||
|
61
README.md
61
README.md
@@ -22,14 +22,14 @@ Supported Boards
|
||||
|
||||
X86
|
||||
---
|
||||
* [Galileo Gen 1 - Rev D](../master/docs/galileorevd.md)
|
||||
* [Galileo Gen 2 - Rev H](../master/docs/galileorevh.md)
|
||||
* [Galileo Gen 1 - Rev D](../master/docs/galileogen1.md)
|
||||
* [Galileo Gen 2 - Rev H](../master/docs/galileogen2.md)
|
||||
* [Edison](../master/docs/edison.md)
|
||||
* [Intel DE3815](../master/docs/intel_de3815.md)
|
||||
* [Minnowboard Max](../master/docs/minnow_max.md)
|
||||
* [NUC 5th generation](../master/docs/intel_nuc5.md)
|
||||
* [UP](../master/docs/up.md)
|
||||
* [Intel Grosse Tete](../master/docs/grossetete.md)
|
||||
* [Intel Joule](../master/docs/grossetete.md)
|
||||
|
||||
ARM
|
||||
---
|
||||
@@ -45,15 +45,56 @@ Mock
|
||||
----
|
||||
* [Generic simulated board](../master/docs/mock.md)
|
||||
|
||||
JSON platform
|
||||
----
|
||||
* [Platform loading](../master/docs/jsonplatform.md)
|
||||
|
||||
Installing on your board
|
||||
========
|
||||
========================
|
||||
|
||||
Installing on Ubuntu
|
||||
--------------------
|
||||
|
||||
Here is a PPA for installing on ubuntu:
|
||||
https://launchpad.net/~mraa/+archive/ubuntu/mraa
|
||||
|
||||
```bash
|
||||
sudo add-apt-repository ppa:mraa/mraa
|
||||
sudo apt-get install libmraa1 libmraa-dev mraa-tools python-mraa python3-mraa
|
||||
```
|
||||
|
||||
Node.js package is available seperately.
|
||||
|
||||
Install on Arch Linux
|
||||
---------------------
|
||||
|
||||
There is an AUR package for mraa here: https://aur.archlinux.org/packages/mraa
|
||||
|
||||
Installing for Node.js only
|
||||
---------------------------
|
||||
|
||||
You can also install just the node.js mraa module by using npm. You will need a
|
||||
C++ compiler and the node development headers, however it's not required to
|
||||
have SWIG installed.
|
||||
|
||||
```bash
|
||||
npm install mraa
|
||||
```
|
||||
|
||||
Note that installing mraa in this way builds mraa without json-c so you cannot
|
||||
use mraa_init_json_platform(). Also building this way means the mraa.node
|
||||
includes a static version of libmraa rather than relying on a dynamic library
|
||||
in /usr/lib.
|
||||
|
||||
Installing on Intel 32bit Yocto based opkg image
|
||||
------------------------------------------------
|
||||
|
||||
See the section below on compiling or use our repository to install on a glibc
|
||||
based yocto poky image that supports opkg. Adding this repository is as simple
|
||||
as and you'll have the latest stable tagged build of mraa installed!
|
||||
|
||||
``` bash
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
opkg update
|
||||
opkg install mraa
|
||||
```
|
||||
@@ -62,19 +103,11 @@ If you would like to get the latest & greatest builds from master HEAD you can
|
||||
use our -dev repository
|
||||
|
||||
```bash
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
|
||||
opkg update
|
||||
opkg install mraa
|
||||
```
|
||||
|
||||
You can also install just the node.js mraa module by using npm. You will need a
|
||||
C++ compiler and the node development headers, however it's not required to
|
||||
have SWIG installed.
|
||||
|
||||
```bash
|
||||
npm install mraa
|
||||
```
|
||||
|
||||
Compiling
|
||||
=========
|
||||
|
||||
|
@@ -46,9 +46,7 @@ extern "C" {
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
#include <jni.h>
|
||||
extern "C" {
|
||||
void mraa_java_isr_callback(void *args);
|
||||
}
|
||||
void mraa_java_isr_callback(void *args);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@@ -70,6 +70,12 @@ class Spi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise SPI object using 'raw' mode. Mraa will go and grab the spidev device lablled /dev/spidev<bus>.<cs>
|
||||
*
|
||||
* @param bus to use
|
||||
* @param cs to use
|
||||
*/
|
||||
Spi(int bus, int cs)
|
||||
{
|
||||
m_spi = mraa_spi_init_raw(bus, cs);
|
||||
|
@@ -240,11 +240,11 @@ typedef enum {
|
||||
} mraa_i2c_mode_t;
|
||||
|
||||
typedef enum {
|
||||
MRAA_UART_PARITY_NONE = 0,
|
||||
MRAA_UART_PARITY_EVEN = 1,
|
||||
MRAA_UART_PARITY_ODD = 2,
|
||||
MRAA_UART_PARITY_MARK = 3,
|
||||
MRAA_UART_PARITY_SPACE = 4
|
||||
MRAA_UART_PARITY_NONE = 0,
|
||||
MRAA_UART_PARITY_EVEN = 1,
|
||||
MRAA_UART_PARITY_ODD = 2,
|
||||
MRAA_UART_PARITY_MARK = 3,
|
||||
MRAA_UART_PARITY_SPACE = 4
|
||||
} mraa_uart_parity_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -64,19 +64,19 @@ extern "C" {
|
||||
#include "common.h"
|
||||
#include "uart.h"
|
||||
|
||||
/* 8 bytes (64 bits) for a device rom code */
|
||||
#define MRAA_UART_OW_ROMCODE_SIZE 8
|
||||
|
||||
/* for now, we simply use the normal MRAA UART context */
|
||||
typedef struct _mraa_uart_ow {
|
||||
mraa_uart_context uart;
|
||||
/* search state */
|
||||
unsigned char ROM_NO[8]; /* 8 byte (64b) rom code */
|
||||
unsigned char ROM_NO[MRAA_UART_OW_ROMCODE_SIZE]; /* 8 byte (64b) rom code */
|
||||
int LastDiscrepancy;
|
||||
int LastFamilyDiscrepancy;
|
||||
mraa_boolean_t LastDeviceFlag;
|
||||
} *mraa_uart_ow_context;
|
||||
|
||||
/* 8 bytes (64 bits) for a device rom code */
|
||||
static const int MRAA_UART_OW_ROMCODE_SIZE = 8;
|
||||
|
||||
/**
|
||||
* UART One Wire ROM related Command bytes
|
||||
*/
|
||||
|
@@ -23,13 +23,16 @@ if (UV_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
# Now look for node. Flag an error if not found
|
||||
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
||||
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
|
||||
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||
if (NODE_ROOT_DIR)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
||||
else()
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - node.h not found")
|
||||
|
@@ -11,13 +11,14 @@ what you'll need:
|
||||
* [SWIG](http://swig.org) 3.0.5+
|
||||
* [git](http://git-scm.com)
|
||||
* [python](http://python.org) 2.7 or 3.4+ (you'll need not just the interpreter but python-dev)
|
||||
* [node.js](http://nodejs.org) 0.10.x or 0.12.x (you'll need not just the interpreter but nodejs-dev)
|
||||
* [node.js](http://nodejs.org) 4.x recommended (you'll need not just the interpreter but nodejs-dev)
|
||||
* [CMake](http://cmake.org) 2.8.8+ (3.1+ is recommended for node.js version 2+)
|
||||
* [json-c](https://github.com/json-c/json-c) 0.12+ (0.10+ probably works in reality)
|
||||
|
||||
For Debian-like distros the below command installs the basic set:
|
||||
|
||||
```bash
|
||||
sudo apt-get install git build-essential swig3.0 python-dev nodejs-dev cmake
|
||||
sudo apt-get install git build-essential swig3.0 python-dev nodejs-dev cmake libjson-c-dev
|
||||
```
|
||||
|
||||
To build the documentation you'll also need:
|
||||
@@ -52,8 +53,9 @@ Currently our install logic puts Python bindings into standard paths, which
|
||||
do not work on Debian due to their
|
||||
[policy](http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html#s-paths).
|
||||
|
||||
We are working on a permanent solution, in the meanwhile please use this command
|
||||
after `make install` to link installed modules where Debian's Python expects them:
|
||||
We are working on a permanent solution, in the meantime please use this command
|
||||
after `make install` to link installed modules where Debian's Python expects
|
||||
them:
|
||||
|
||||
```bash
|
||||
sudo ln -s <your install prefix, e.g. /usr>/lib/python2.7/site-packages/* /usr/lib/python2.7/dist-packages
|
||||
@@ -91,30 +93,32 @@ Disabling Python module building:
|
||||
Building doc, this will require [SPHINX](http://sphinx-doc.org) &
|
||||
[Doxygen](http://doxygen.org):
|
||||
`-DBUILDDOC=ON`
|
||||
You will also require clone git submodules from your existing checkout:
|
||||
`git submodule update --init --recursive`
|
||||
The from doxygen2jsdoc dir:
|
||||
`npm install mkdirp commander lodash bluebird pegjs`
|
||||
|
||||
Override build architecture (this is useful because on x86 ARM code is not
|
||||
compiled so use this flag to force the target arch)
|
||||
`-DBUILDARCH=arm`
|
||||
|
||||
You can also enable -Wall for gcc before running cmake by exporting your wanted
|
||||
CC flags to the CC env var
|
||||
`export CC="gcc -Wall"`
|
||||
|
||||
## Dependencies continued
|
||||
|
||||
You'll need at least SWIG version 3.0.2 and we recommend 3.0.5 to build the
|
||||
JavaScript & Python modules. If your version of SWIG is older than this then
|
||||
please see above for disabling `SWIGNODE`. Otherwise you will get a weird build
|
||||
failure when building the JavaScript module. The Python module builds with SWIG
|
||||
2.x.
|
||||
2.x but we don't test it.
|
||||
|
||||
During the build, we'll assume you're building from git, note that if you
|
||||
compile with `git` installed your version of mraa will be tagged `-dirty`. This
|
||||
simply means `git` wasn't installed or that you where building from a tarball.
|
||||
You can modify `build/src/version.c` before running `make` if this is incorrect.
|
||||
The instructions listed here all assume that `build/` is an empty dir that lives
|
||||
inside the cloned repository of mraa.
|
||||
|
||||
If you have multiple versions of Python then mraa can get confused, we
|
||||
recommend using virtualenv to select which version of Python you want. We test
|
||||
2.7 the most but SWIG will generate valid 3.x Python code but we do not
|
||||
generally support building both at once.
|
||||
compile with `git` installed your version of mraa will be versioned with `git
|
||||
desribe --tag` to make it easy for intentification. You can easily modify
|
||||
version.c in build/src. If you don't build from a git tree then you will simply
|
||||
have a version which matches the latest released version of mraa.
|
||||
|
||||
## Using a Yocto/OE toolchain
|
||||
|
||||
@@ -131,7 +135,6 @@ make
|
||||
|
||||
## Using Coverity
|
||||
|
||||
Static analysis is routinely performed using Coverity on libmraa's codebase.
|
||||
This is the procedure to submit a build to Coverity. You'll need to install
|
||||
`coverity-submit` for your OS.
|
||||
|
||||
|
@@ -5,6 +5,20 @@ This changelog is meant as a quick & rough guide to what has changed between
|
||||
versions. The API is now fairly stable but when new calls/features are added
|
||||
they are listed here. Anything pre 0.2.x is ignored.
|
||||
|
||||
**1.4.0**
|
||||
* Add support for Siemens SIMATIC IOT2000
|
||||
* Cmake now enables much more error detection depending on compiler support
|
||||
* Mraa Maven packages now enabled
|
||||
* Galileo Gen2 AIO fix using pincmd
|
||||
* Adding an already added firmata platform now returns MRAA_SUCCESS
|
||||
* Cmake no longer tags builds without git as '-dirty' version.c for easier
|
||||
packaging support
|
||||
|
||||
**1.3.0**
|
||||
* Fix GT GPIO bugs
|
||||
* Mock SPI and travis now uses mock and tests it
|
||||
* RPI zero support
|
||||
|
||||
**1.2.3**
|
||||
* Revert 1.2.1 binding.gyp changed that had side effect of enabling JSONPLAT in mraa.c
|
||||
* improve travis.ci to load mraa.node as compiled from make npmpkg target
|
||||
|
@@ -1,10 +1,12 @@
|
||||
Galileo Gen 1 - Rev D {#galileorevd}
|
||||
Galileo Gen 1 (Rev D) {#galileogen1}
|
||||
=====================
|
||||
|
||||
Galileo is a microcontroller board based on the Intel(R) Quark(TM) SoC X1000
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip.
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip. The gen1
|
||||
board is smaller than the gen2 board and can be easily identified by it's lack
|
||||
of full size USB port and it has a 3.5mm jack serial connector.
|
||||
|
||||
The rev D board has the following limitations in libmraa:
|
||||
The gen1 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
|
@@ -1,8 +1,10 @@
|
||||
Galileo Gen 2 - Rev H {#galileorevh}
|
||||
Galileo Gen 2 (Rev H) {#galileogen1}
|
||||
=====================
|
||||
|
||||
Galileo is a microcontroller board based on the Intel(R) Quark(TM) SoC X1000
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip.
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip. A gen2
|
||||
board can be indetified as it has a full size USB connector and features a 6pin
|
||||
FTDI connector for serial debugging
|
||||
|
||||
The Gen 2 board has the following limitations in libmraa:
|
||||
|
@@ -1,112 +0,0 @@
|
||||
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
|
@@ -37,8 +37,8 @@ functionality.
|
||||
|
||||
Specific platform information for supported platforms is documented here:
|
||||
|
||||
- @ref galileorevd
|
||||
- @ref galileorevh
|
||||
- @ref galileogen1
|
||||
- @ref galileogen2
|
||||
- @ref edison
|
||||
- @ref de3815
|
||||
- @ref minnowmax
|
||||
|
@@ -37,8 +37,8 @@ functionality.
|
||||
|
||||
Specific platform information for supported platforms is documented here:
|
||||
|
||||
- @ref galileorevd
|
||||
- @ref galileorevh
|
||||
- @ref galileogen1
|
||||
- @ref galileogen2
|
||||
- @ref edison
|
||||
- @ref de3815
|
||||
- @ref minnowmax
|
||||
|
127
docs/jsonplatform.md
Normal file
127
docs/jsonplatform.md
Normal file
@@ -0,0 +1,127 @@
|
||||
JSON platform {#jsonplat}
|
||||
=============
|
||||
|
||||
JSON platform loading allows libmraa users who work with **simple** and unsupported
|
||||
boards to create JSON configuration files which libmraa understands, allowing
|
||||
libmraa to just 'work' with the unsupported platform. JSON platform **does not work**
|
||||
with boards which require advanced functions which overwrite default functionality or
|
||||
boards that require the mux functionality.
|
||||
|
||||
Syntax
|
||||
------
|
||||
|
||||
The JSON file that libmraa reads needs specific values to be set by default, they
|
||||
are required in every JSON file intended to be used to load the platform.
|
||||
The keywords are case sensitive so be aware when writing the JSON file.
|
||||
Each heading is a top level key in the JSON file, each key's type is Array
|
||||
|
||||
### platform
|
||||
|Key |Type |Required |Description |
|
||||
|-------------|-------|-----------|-----------------------------------------------|
|
||||
|id |int |no | An ID that can be assigned |
|
||||
|name |string |yes | The platform name |
|
||||
|pin_count |int |yes | The total pin count |
|
||||
|gpio_count |int |no | The subset of pincount which able to do GPIO |
|
||||
|i2c_count |int |no | The number of usable I2C ports |
|
||||
|aio_count |int |no | The number of usable AIO ports |
|
||||
|spi_count |int |no | The number of usable SPI ports |
|
||||
|uart_count |int |no | The total UART ports |
|
||||
|pwmDefPeriod |int |no | The default PWM period |
|
||||
|pwmMaxPeriod |int |no | The max PWM period |
|
||||
|pwmMinPeriod |int |no | The min PWM period |
|
||||
|
||||
### layout
|
||||
|
||||
**THIS INDEX'S THE PIN ARRAY**
|
||||
Each available pin specified using pin_count requires a label. There is no need to use an
|
||||
index identifier as the json objects are indexed as they are read, starting with the first
|
||||
json object being treated as index 0.
|
||||
|
||||
The number of json objects in layout should be equal to the pin_count.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-----------------------------------------------|
|
||||
|label |string |yes | The label used to describe the pin |
|
||||
|invalid |boolean|no | Sets the labeled pin as an invalid pin |
|
||||
|
||||
### GPIO
|
||||
|
||||
**THIS INDEX'S THE PIN ARRAY**
|
||||
For the supported GPIO pins here is where we set the raw linux pin it needs to use, the
|
||||
index cannot exceed the total pin_count and the number of JSON ojects cannot exceed the
|
||||
gpio_count total. The index is also used to set the specified pin's capabilities. Each set
|
||||
of keys should be enclosed in a json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-------------------------------------|
|
||||
|index |int |yes | used to index the pin array |
|
||||
|rawpin |int |yes | used to reference the actual IO pin |
|
||||
|
||||
### I2C
|
||||
|
||||
**THIS INDEX'S THE I2C ARRAY**
|
||||
This is used to setup the I2C functionality. The total number of json objects and the index
|
||||
cannot exceed the i2c_count. Each set of keys should be enclosed in a json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-------------------------------------|
|
||||
|index |int |yes | Used to index the I2C array |
|
||||
|rawpin |int |yes | The sysfs pin |
|
||||
|sclpin |int |no | The clock pin |
|
||||
|sdapin |int |no | The data pin |
|
||||
|default |boolean|no | Sets the default I2C device used |
|
||||
|
||||
### AIO
|
||||
|
||||
**THIS INDEX'S THE PIN ARRAY**
|
||||
This is used to setup which pins are able to perform AIO. Each set of keys should be
|
||||
enclosed in a json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-------------------------------------|
|
||||
|index |int |yes | Used to index the pin array |
|
||||
|rawpin |int |yes | The sysfs pin |
|
||||
|
||||
### PWM
|
||||
|
||||
**THIS INDEX'S THE PIN ARRAY**
|
||||
This is used to setup which IO pins can do PWM Each set of keys should be enclosed in a
|
||||
json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-------------------------------|
|
||||
|index |int |yes | Used to index the pin array |
|
||||
|rawpin |int |yes | The sysfs pin |
|
||||
|chipID |int |yes | The parent ID |
|
||||
|
||||
## SPI
|
||||
|
||||
**THIS INDEX'S THE SPI ARRAY**
|
||||
This is used to setup the SPI functionality. The total number of json objects and the index
|
||||
cannot exceed the spi_count. Each set of keys should be enclosed in a json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|--------------------------------------------|
|
||||
|index |int |yes | The index into the SPI array |
|
||||
|chipID |int |yes | The parent ID |
|
||||
|clock |int |no | The clock used for transmissions |
|
||||
|miso |int |no | Pin used for incoming data from the slave |
|
||||
|mosi |int |no | Pin used for outgoing data from the master |
|
||||
|chipselect |int |no | Pin used to select the slave device |
|
||||
|default |boolean|no | Sets the default SPI device |
|
||||
|
||||
### UART
|
||||
|
||||
**THIS INDEX'S THE UART ARRAY**
|
||||
This is used to setup the UART functionality. The total number of json objects and the index
|
||||
cannot exceed the uart_count. Each set of keys should be enclosed in a json object.
|
||||
|
||||
|Key |Type |Required |Description |
|
||||
|-----------|-------|-----------|-----------------------------------------|
|
||||
|index |int |yes | Used to index the UART array |
|
||||
|chipID |int |yes | Parent ID |
|
||||
|rawpin |int |yes | Sysfs pin |
|
||||
|rx |int |no | Read pin |
|
||||
|tx |int |no | Transmit pin |
|
||||
|path |string |yes | Used to talk to a connected UART device |
|
||||
|default |boolean|no | Sets the default UART device |
|
@@ -19,6 +19,10 @@ Right now we simulate a single generic board with:
|
||||
which can be read or written in bytes or words (big-endian). Technically those
|
||||
registers are just an array of `uint8_t`, so you can treat them as 10 single-byte
|
||||
registers or 5 single-word ones or a mix thereof.
|
||||
* Single SPI bus with one Chip Select. All write functions are supported, received
|
||||
data items (words or bytes) are calculated from the sent ones using
|
||||
`sent_byte (or word) XOR constant` formula.
|
||||
See [SPI mock header](../include/mock/mock_board_spi.h#L38-L39) for constant values.
|
||||
|
||||
We plan to develop it further and all [contributions](../CONTRIBUTING.md) are more than welcome.
|
||||
|
||||
@@ -30,6 +34,10 @@ See the table below for pin layout and features
|
||||
| 1 | ADC0 | AIO pin, returns random value on read |
|
||||
| 2 | I2C0SDA | SDA pin for I2C0 bus |
|
||||
| 3 | I2C0SCL | SCL pin for I2C0 bus |
|
||||
| 4 | SPI0CS | CS pin for SPI0 bus |
|
||||
| 5 | SPI0MOSI | MOSI pin for SPI0 bus |
|
||||
| 6 | SPI0MISO | MISO pin for SPI0 bus |
|
||||
| 7 | SPI0SCLK | SCLK pin for SPI0 bus |
|
||||
|
||||
Building
|
||||
--------
|
||||
|
@@ -49,6 +49,7 @@ main()
|
||||
value = 0.0f;
|
||||
}
|
||||
float output = mraa_pwm_read(pwm);
|
||||
printf("PWM value is %f\n", output);
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
|
@@ -55,7 +55,7 @@ interrupt(char* data)
|
||||
mraa_iio_channel* channels = mraa_iio_get_channels(iio_device0);
|
||||
int i = 0;
|
||||
|
||||
for (i; i < mraa_iio_get_channel_count(iio_device0); i++) {
|
||||
for (; i < mraa_iio_get_channel_count(iio_device0); i++) {
|
||||
if (channels[i].enabled) {
|
||||
printf("channel %d - bytes %d\n", channels[i].index, channels[i].bytes);
|
||||
switch (channels[i].bytes) {
|
||||
|
@@ -144,7 +144,6 @@ i2c_set_exit:
|
||||
void
|
||||
i2c_detect_devices(int bus)
|
||||
{
|
||||
mraa_result_t status = MRAA_SUCCESS;
|
||||
mraa_i2c_context i2c = mraa_i2c_init(bus);
|
||||
if (i2c == NULL) {
|
||||
return;
|
||||
|
@@ -33,7 +33,6 @@ main(int argc, char** argv)
|
||||
//! [Interesting]
|
||||
mraa_spi_context spi;
|
||||
spi = mraa_spi_init(0);
|
||||
unsigned int response = 0;
|
||||
printf("Hello, SPI initialised\n");
|
||||
uint8_t data[] = { 0x00, 100 };
|
||||
uint8_t* recv;
|
||||
|
@@ -282,7 +282,7 @@ imraa_handle_subplatform(struct json_object* jobj, bool force_update)
|
||||
// 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);
|
||||
printf("force upgrade? remove the lockfile or run with force\n");
|
||||
return;
|
||||
} else {
|
||||
fprintf(stdout, "Starting to flash board\n");
|
||||
@@ -463,8 +463,6 @@ main(int argc, char** argv)
|
||||
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();
|
||||
|
@@ -36,6 +36,7 @@ extern "C" {
|
||||
#define MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT 41
|
||||
#define MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT 41
|
||||
#define MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT 41
|
||||
#define MRAA_RASPBERRY_PI_ZERO_PINCOUNT 41
|
||||
|
||||
mraa_board_t *
|
||||
mraa_raspberry_pi();
|
||||
|
@@ -30,7 +30,7 @@ extern "C" {
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MRAA_MOCK_PINCOUNT 4
|
||||
#define MRAA_MOCK_PINCOUNT 8
|
||||
|
||||
mraa_board_t*
|
||||
mraa_mock_board();
|
||||
|
73
include/mock/mock_board_spi.h
Normal file
73
include/mock/mock_board_spi.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MOCK_SPI_DEFAULT_FREQ 4000000
|
||||
#define MOCK_SPI_DEFAULT_MODE MRAA_SPI_MODE0
|
||||
#define MOCK_SPI_DEFAULT_LSBMODE 0
|
||||
#define MOCK_SPI_DEFAULT_BIT_PER_WORD 8
|
||||
// This is XORed with each byte/word of the transmitted message to get the received one
|
||||
#define MOCK_SPI_REPLY_DATA_MODIFIER_BYTE 0xAB
|
||||
#define MOCK_SPI_REPLY_DATA_MODIFIER_WORD 0xABBA
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_stop_replace(mraa_spi_context dev);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_frequency_replace(mraa_spi_context dev, int hz);
|
||||
|
||||
int
|
||||
mraa_mock_spi_write_replace(mraa_spi_context dev, uint8_t data);
|
||||
|
||||
int
|
||||
mraa_mock_spi_write_word_replace(mraa_spi_context dev, uint16_t data);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -97,7 +97,16 @@ typedef struct {
|
||||
|
||||
mraa_result_t (*spi_init_pre) (int bus);
|
||||
mraa_result_t (*spi_init_post) (mraa_spi_context spi);
|
||||
mraa_result_t (*spi_init_raw_replace) (mraa_spi_context spi, unsigned int bus, unsigned int cs);
|
||||
mraa_result_t (*spi_lsbmode_replace) (mraa_spi_context dev, mraa_boolean_t lsb);
|
||||
mraa_result_t (*spi_mode_replace) (mraa_spi_context dev, mraa_spi_mode_t mode);
|
||||
mraa_result_t (*spi_bit_per_word_replace) (mraa_spi_context dev, unsigned int bits);
|
||||
mraa_result_t (*spi_frequency_replace) (mraa_spi_context dev, int hz);
|
||||
mraa_result_t (*spi_transfer_buf_replace) (mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
|
||||
mraa_result_t (*spi_transfer_buf_word_replace) (mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length);
|
||||
int (*spi_write_replace) (mraa_spi_context dev, uint8_t data);
|
||||
int (*spi_write_word_replace) (mraa_spi_context dev, uint16_t data);
|
||||
mraa_result_t (*spi_stop_replace) (mraa_spi_context dev);
|
||||
|
||||
mraa_result_t (*uart_init_pre) (int index);
|
||||
mraa_result_t (*uart_init_post) (mraa_uart_context uart);
|
||||
|
@@ -30,10 +30,10 @@ extern "C" {
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MRAA_INTEL_GALILEO_REV_D_PINCOUNT 25
|
||||
#define MRAA_INTEL_GALILEO_GEN_1_PINCOUNT 25
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_rev_d();
|
||||
mraa_intel_galileo_g1();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MRAA_INTEL_GALILEO_GEN_2_PINCOUNT 25
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_gen2();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -32,8 +32,8 @@ set (mraa_LIB_SRCS_NOAUTO
|
||||
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/x86/x86.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_d.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_g.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_gen_1.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_gen_2.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_edison_fab_c.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_de3815.c
|
||||
${PROJECT_SOURCE_DIR}/src/x86/intel_nuc5.c
|
||||
@@ -50,9 +50,9 @@ message (STATUS "INFO - Adding support for platform ${MRAAPLATFORMFORCE}")
|
||||
if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Dx${MRAAPLATFORMFORCE} -DMRAA_PLATFORM_FORCE=${MRAAPLATFORMFORCE}")
|
||||
if (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GALILEO_GEN2")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_g.c)
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_gen_2.c)
|
||||
elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GALILEO_GEN1")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_rev_d.c)
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_galileo_gen_1.c)
|
||||
elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_DE3815")
|
||||
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_de3815.c)
|
||||
elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_EDISON_FAB_C")
|
||||
@@ -90,6 +90,7 @@ set (mraa_LIB_MOCK_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_gpio.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_aio.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c
|
||||
${PROJECT_SOURCE_DIR}/src/mock/mock_board_spi.c
|
||||
)
|
||||
|
||||
if (JSONPLAT)
|
||||
@@ -238,6 +239,8 @@ if (BUILDSWIG)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/pom.xml.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/java/mraa-${VERSION_SHORT}.pom)
|
||||
add_subdirectory (java)
|
||||
endif ()
|
||||
if (BUILDSWIGNODE)
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#define PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1 "Raspberry Pi Compute Module Rev 1"
|
||||
#define PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1 "Raspberry Pi Model A+ Rev 1"
|
||||
#define PLATFORM_NAME_RASPBERRY_PI2_B_REV_1 "Raspberry Pi 2 Model B Rev 1"
|
||||
#define PLATFORM_NAME_RASPBERRY_PI_ZERO "Raspberry Pi Zero"
|
||||
#define PLATFORM_RASPBERRY_PI_B_REV_1 1
|
||||
#define PLATFORM_RASPBERRY_PI_A_REV_2 2
|
||||
#define PLATFORM_RASPBERRY_PI_B_REV_2 3
|
||||
@@ -45,6 +46,7 @@
|
||||
#define PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1 5
|
||||
#define PLATFORM_RASPBERRY_PI_A_PLUS_REV_1 6
|
||||
#define PLATFORM_RASPBERRY_PI2_B_REV_1 7
|
||||
#define PLATFORM_RASPBERRY_PI_ZERO "Raspberry Pi Zero"
|
||||
#define MMAP_PATH "/dev/mem"
|
||||
#define BCM2835_PERI_BASE 0x20000000
|
||||
#define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000)
|
||||
@@ -230,6 +232,10 @@ mraa_raspberry_pi()
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
|
||||
} else if (strstr(line, "900092")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_ZERO;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_ZERO;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_ZERO_PINCOUNT;
|
||||
} else if (strstr(line, "0007") || strstr(line, "0008") || strstr(line, "0009")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2;
|
||||
@@ -490,7 +496,8 @@ mraa_raspberry_pi()
|
||||
|
||||
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_PLUS_REV_1) ||
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI_B_PLUS_REV_1) ||
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1) ||
|
||||
(platform_detected == PLATFORM_RASPBERRY_PI_ZERO)) {
|
||||
|
||||
strncpy(b->pins[27].name, "ID_SD", MRAA_PIN_NAME_SIZE);
|
||||
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
@@ -182,7 +182,7 @@ 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++) {
|
||||
for (; firmata_dev->i2cmsg[addr][reg] == -1; i++) {
|
||||
if (i > 50) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
if (mraa_firmata_send_i2c_read_req(dev, length) == MRAA_SUCCESS) {
|
||||
if (mraa_firmata_i2c_wait(dev->addr, 0) == MRAA_SUCCESS) {
|
||||
int i = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
for (; i < length; i++) {
|
||||
data[i] = firmata_dev->i2cmsg[dev->addr][i];
|
||||
}
|
||||
return length;
|
||||
@@ -277,7 +277,7 @@ mraa_firmata_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWri
|
||||
buffer[2] = dev->addr;
|
||||
buffer[3] = I2C_MODE_WRITE << 3;
|
||||
// we need to write until FIRMATA_END_SYSEX
|
||||
for (i; i < (buffer_size-1); i++) {
|
||||
for (; i < (buffer_size-1); i++) {
|
||||
buffer[ii] = data[i] & 0x7F;
|
||||
buffer[ii+1] = (data[i] >> 7) & 0x7f;
|
||||
ii = ii+2;
|
||||
@@ -537,7 +537,7 @@ mraa_firmata_plat_init(const char* uart_dev)
|
||||
|
||||
// if this isn't working then we have an issue with our uart
|
||||
int retry = 20;
|
||||
while (!firmata_dev->isReady && retry--) {
|
||||
while (!firmata_dev->isReady && --retry) {
|
||||
firmata_pull(firmata_dev);
|
||||
}
|
||||
|
||||
|
@@ -309,7 +309,7 @@ mraa_iio_wait_event(int fd, char* data, int* read_size)
|
||||
|
||||
// Wait for it forever or until pthread_cancel
|
||||
// poll is a cancelable point like sleep()
|
||||
int x = poll(&pfd, 1, -1);
|
||||
poll(&pfd, 1, -1);
|
||||
|
||||
memset(data, 0, 100);
|
||||
*read_size = read(fd, data, 100);
|
||||
@@ -376,10 +376,7 @@ mraa_iio_get_event_data(mraa_iio_context dev)
|
||||
char buf[MAX_SIZE];
|
||||
char readbuf[32];
|
||||
int fd;
|
||||
int ret = 0;
|
||||
int padint = 0;
|
||||
int curr_bytes = 0;
|
||||
char shortbuf, signchar;
|
||||
|
||||
memset(buf, 0, MAX_SIZE);
|
||||
memset(readbuf, 0, 32);
|
||||
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS, dev->num);
|
||||
@@ -441,7 +438,7 @@ mraa_iio_event_poll_nonblock(int fd, struct iio_event_data* data)
|
||||
|
||||
// Wait for it forever or until pthread_cancel
|
||||
// poll is a cancelable point like sleep()
|
||||
int x = poll(&pfd, 1, -1);
|
||||
poll(&pfd, 1, -1);
|
||||
|
||||
read(fd, data, sizeof(struct iio_event_data));
|
||||
|
||||
@@ -573,9 +570,7 @@ mraa_result_t
|
||||
mraa_iio_create_trigger(mraa_iio_context dev, const char* trigger)
|
||||
{
|
||||
struct stat configfs_status;
|
||||
struct stat trigger_status;
|
||||
char buf[MAX_SIZE];
|
||||
int ret;
|
||||
|
||||
if (stat(IIO_CONFIGFS_TRIGGER, &configfs_status) == 0) {
|
||||
memset(buf, 0, MAX_SIZE);
|
||||
|
38
src/java/pom.xml.in
Normal file
38
src/java/pom.xml.in
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.mraa</groupId>
|
||||
<artifactId>mraa</artifactId>
|
||||
<version>@VERSION_SHORT@</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>mraa</name>
|
||||
<description>Low Level Skeleton Library for IO Communication on GNU/Linux platforms</description>
|
||||
<url>http://mraa.io</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://github.com/intel-iot-devkit/mraa/blob/master/COPYING</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Mraa contributors https://github.com/intel-iot-devkit/mraa/graphs/contributors</name>
|
||||
<email>mraa@lists.01.org</email>
|
||||
<organization>Intel IoT Developer kit</organization>
|
||||
<organizationUrl>https://github.com/intel-iot-devkit</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/intel-iot-devkit/mraa.git</connection>
|
||||
<developerConnection>scm:git:ssh://github.com:intel-iot-devkit/mraa.git</developerConnection>
|
||||
<url>https://github.com/intel-iot-devkit/mraa/tree/master</url>
|
||||
</scm>
|
||||
|
||||
</project>
|
@@ -80,7 +80,6 @@ mraa_init_json_platform_platform(json_object* jobj_platform, mraa_board_t* board
|
||||
{
|
||||
json_object* jobj_temp = NULL;
|
||||
const char* temp_string = NULL;
|
||||
int temp_count = 0;
|
||||
int length = 0;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
|
||||
@@ -600,8 +599,8 @@ mraa_init_json_platform(const char* platform_json)
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
char* buffer = NULL;
|
||||
struct stat st;
|
||||
int file_lock = 0, array_length = 0, i = 0;
|
||||
json_object *jobj_platform = NULL, *jobj_temp = NULL;
|
||||
int file_lock = 0, i = 0;
|
||||
json_object *jobj_platform = NULL;
|
||||
mraa_board_t* board = NULL;
|
||||
|
||||
// Try to lock the file for use
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "mock/mock_board_gpio.h"
|
||||
#include "mock/mock_board_aio.h"
|
||||
#include "mock/mock_board_i2c.h"
|
||||
#include "mock/mock_board_spi.h"
|
||||
|
||||
#define PLATFORM_NAME "MRAA mock platform"
|
||||
|
||||
@@ -55,7 +56,14 @@ mraa_mock_board()
|
||||
b->i2c_bus[0].scl = 3;
|
||||
b->def_i2c_bus = b->i2c_bus[0].bus_id;
|
||||
|
||||
b->spi_bus_count = 0;
|
||||
b->spi_bus_count = 1;
|
||||
b->def_spi_bus = 0;
|
||||
b->spi_bus[0].bus_id = 0;
|
||||
b->spi_bus[0].slave_s = 0;
|
||||
b->spi_bus[0].cs = 4;
|
||||
b->spi_bus[0].mosi = 5;
|
||||
b->spi_bus[0].miso = 6;
|
||||
b->spi_bus[0].sclk = 7;
|
||||
|
||||
b->pwm_default_period = 0;
|
||||
b->pwm_max_period = 0;
|
||||
@@ -99,6 +107,16 @@ mraa_mock_board()
|
||||
b->adv_func->i2c_write_byte_replace = &mraa_mock_i2c_write_byte_replace;
|
||||
b->adv_func->i2c_write_byte_data_replace = &mraa_mock_i2c_write_byte_data_replace;
|
||||
b->adv_func->i2c_write_word_data_replace = &mraa_mock_i2c_write_word_data_replace;
|
||||
b->adv_func->spi_init_raw_replace = &mraa_mock_spi_init_raw_replace;
|
||||
b->adv_func->spi_stop_replace = &mraa_mock_spi_stop_replace;
|
||||
b->adv_func->spi_bit_per_word_replace = &mraa_mock_spi_bit_per_word_replace;
|
||||
b->adv_func->spi_lsbmode_replace = &mraa_mock_spi_lsbmode_replace;
|
||||
b->adv_func->spi_mode_replace = &mraa_mock_spi_mode_replace;
|
||||
b->adv_func->spi_frequency_replace = &mraa_mock_spi_frequency_replace;
|
||||
b->adv_func->spi_write_replace = &mraa_mock_spi_write_replace;
|
||||
b->adv_func->spi_write_word_replace = &mraa_mock_spi_write_word_replace;
|
||||
b->adv_func->spi_transfer_buf_replace = &mraa_mock_spi_transfer_buf_replace;
|
||||
b->adv_func->spi_transfer_buf_word_replace = &mraa_mock_spi_transfer_buf_word_replace;
|
||||
|
||||
// Pin definitions
|
||||
int pos = 0;
|
||||
@@ -127,6 +145,30 @@ mraa_mock_board()
|
||||
b->pins[pos].i2c.pinmap = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPI0CS", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPI0MOSI", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPI0MISO", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPI0SCLK", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 0;
|
||||
pos++;
|
||||
|
||||
return b;
|
||||
|
||||
error:
|
||||
|
@@ -26,9 +26,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "mock/mock_board.h"
|
||||
#include "mock/mock_board_gpio.h"
|
||||
#include "mock/mock_board_aio.h"
|
||||
#include "mock/mock_board_i2c.h"
|
||||
|
||||
mraa_result_t
|
||||
|
179
src/mock/mock_board_spi.c
Normal file
179
src/mock/mock_board_spi.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
* Copyright (c) 2016 Alex Tereschenko.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(MSYS)
|
||||
// There's no spidev.h on MSYS, so we need to provide our own,
|
||||
// and only *after* including ioctl.h as that one contains prerequisites.
|
||||
#include "linux/spi_kernel_headers.h"
|
||||
#else
|
||||
#include <linux/spi/spidev.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "mock/mock_board_spi.h"
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs)
|
||||
{
|
||||
dev->clock = MOCK_SPI_DEFAULT_FREQ;
|
||||
|
||||
if ((mraa_spi_mode(dev, MOCK_SPI_DEFAULT_MODE) != MRAA_SUCCESS) ||
|
||||
(mraa_spi_lsbmode(dev, MOCK_SPI_DEFAULT_LSBMODE) != MRAA_SUCCESS) ||
|
||||
(mraa_spi_bit_per_word(dev, MOCK_SPI_DEFAULT_BIT_PER_WORD) != MRAA_SUCCESS)) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_stop_replace(mraa_spi_context dev)
|
||||
{
|
||||
free(dev);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits)
|
||||
{
|
||||
if (bits == 0) {
|
||||
syslog(LOG_ERR, "spi: bit_per_word: Cannot set to zero");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dev->bpw = bits;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
{
|
||||
dev->lsb = lsb;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode)
|
||||
{
|
||||
uint8_t spi_mode = 0;
|
||||
|
||||
switch (mode) {
|
||||
case MRAA_SPI_MODE0:
|
||||
spi_mode = SPI_MODE_0;
|
||||
break;
|
||||
case MRAA_SPI_MODE1:
|
||||
spi_mode = SPI_MODE_1;
|
||||
break;
|
||||
case MRAA_SPI_MODE2:
|
||||
spi_mode = SPI_MODE_2;
|
||||
break;
|
||||
case MRAA_SPI_MODE3:
|
||||
spi_mode = SPI_MODE_3;
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_ERR, "spi: mode: Invalid SPI mode %d selected", mode);
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dev->mode = spi_mode;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_frequency_replace(mraa_spi_context dev, int hz)
|
||||
{
|
||||
if (hz <= 0) {
|
||||
syslog(LOG_ERR, "spi: frequency: Cannot set to zero or negative");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
dev->clock = hz;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
mraa_mock_spi_write_replace(mraa_spi_context dev, uint8_t data)
|
||||
{
|
||||
return (int) (data ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE);
|
||||
}
|
||||
|
||||
int
|
||||
mraa_mock_spi_write_word_replace(mraa_spi_context dev, uint16_t data)
|
||||
{
|
||||
return (int) (data ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
|
||||
{
|
||||
if (data == NULL) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf: Incoming data is null, cannot proceed");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (length <= 0) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf: Length given is equal to or less than zero, cannot proceed");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (rxbuf != NULL) {
|
||||
int i;
|
||||
for (i = 0; i < length; ++i) {
|
||||
rxbuf[i] = data[i] ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE;
|
||||
}
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_mock_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length)
|
||||
{
|
||||
if (data == NULL) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf_word: Incoming data is null, cannot proceed");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (length <= 0) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf_word: Length given is equal to or less than zero, cannot proceed");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (rxbuf != NULL) {
|
||||
// length is given in bytes, but arrays are comprised of words
|
||||
int i;
|
||||
for (i = 0; i < (length / 2); ++i) {
|
||||
rxbuf[i] = data[i] ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD;
|
||||
}
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
26
src/mraa.c
26
src/mraa.c
@@ -69,7 +69,6 @@ mraa_iio_info_t* plat_iio = NULL;
|
||||
mraa_lang_func_t* lang_func = NULL;
|
||||
|
||||
char* platform_name = NULL;
|
||||
static char* platform_long_name = NULL;
|
||||
|
||||
static int num_i2c_devices = 0;
|
||||
static int num_iio_devices = 0;
|
||||
@@ -953,7 +952,7 @@ mraa_find_i2c_bus(const char* devname, int startfrom)
|
||||
// i2c devices are numbered numerically so 0 must exist otherwise there is
|
||||
// no i2c-dev loaded
|
||||
if (mraa_file_exist("/sys/class/i2c-dev/i2c-0")) {
|
||||
for (i; i < num_i2c_devices; i++) {
|
||||
for (;i < num_i2c_devices; i++) {
|
||||
off_t size, err;
|
||||
snprintf(path, 64, "/sys/class/i2c-dev/i2c-%u/name", i);
|
||||
fd = open(path, O_RDONLY);
|
||||
@@ -1028,13 +1027,17 @@ mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev)
|
||||
#if defined(FIRMATA)
|
||||
if (subplatformtype == MRAA_GENERIC_FIRMATA) {
|
||||
if (plat->sub_platform != NULL) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
if (plat->sub_platform->platform_type == subplatformtype) {
|
||||
syslog(LOG_NOTICE, "mraa: Firmata subplatform already present");
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
syslog(LOG_NOTICE, "mraa: We don't support multiple firmata subplatforms!");
|
||||
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
}
|
||||
if (mraa_firmata_platform(plat, uart_dev) == MRAA_GENERIC_FIRMATA) {
|
||||
syslog(LOG_NOTICE, "mraa: Added firmata subplatform");
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
syslog(LOG_NOTICE, "mraa: Failed to add firmata subplatform");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1052,6 +1055,7 @@ mraa_remove_subplatform(mraa_platform_t subplatformtype)
|
||||
free(plat->sub_platform->adv_func);
|
||||
free(plat->sub_platform->pins);
|
||||
free(plat->sub_platform);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
@@ -1062,9 +1066,7 @@ mraa_result_t
|
||||
mraa_add_from_lockfile(const char* imraa_lock_file)
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
mraa_platform_t type = plat->platform_type;
|
||||
char* buffer = NULL;
|
||||
off_t file_size;
|
||||
struct stat st;
|
||||
int i = 0;
|
||||
uint32_t subplat_num = 0;
|
||||
@@ -1210,7 +1212,7 @@ mraa_init_io(const char* desc)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strncmp(type, "GPIO", 4) == 0) {
|
||||
if (strncmp(type, GPIO_KEY, strlen(GPIO_KEY)) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
|
||||
return (void*) mraa_gpio_init_raw(pin);
|
||||
@@ -1219,7 +1221,7 @@ mraa_init_io(const char* desc)
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_gpio_init(pin);
|
||||
} else if (strncmp(type, "I2C", 3) == 0) {
|
||||
} else if (strncmp(type, I2C_KEY, strlen(I2C_KEY)) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
|
||||
return (void*) mraa_i2c_init_raw(pin);
|
||||
@@ -1228,13 +1230,13 @@ mraa_init_io(const char* desc)
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_i2c_init(pin);
|
||||
} else if (strncmp(type, "AIO", 3) == 0) {
|
||||
} else if (strncmp(type, AIO_KEY, strlen(AIO_KEY)) == 0) {
|
||||
if (raw) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Aio doesn't have a RAW mode");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_aio_init(pin);
|
||||
} else if (strncmp(type, "PWM", 3) == 0) {
|
||||
} else if (strncmp(type, PWM_KEY, strlen(PWM_KEY)) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a useable Int");
|
||||
@@ -1247,7 +1249,7 @@ mraa_init_io(const char* desc)
|
||||
return (void*) mraa_pwm_init_raw(id, pin);
|
||||
}
|
||||
return (void*) mraa_pwm_init(pin);
|
||||
} else if (strncmp(type, "SPI", 3) == 0) {
|
||||
} else if (strncmp(type, SPI_KEY, strlen(SPI_KEY)) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the bus string into a useable Int");
|
||||
@@ -1260,7 +1262,7 @@ mraa_init_io(const char* desc)
|
||||
return (void*) mraa_spi_init_raw(id, pin);
|
||||
}
|
||||
return (void*) mraa_spi_init(pin);
|
||||
} else if (strncmp(type, "UART", 4) == 0) {
|
||||
} else if (strncmp(type, UART_KEY, strlen(UART_KEY)) == 0) {
|
||||
if (raw) {
|
||||
return (void*) mraa_uart_init_raw(str);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
#ifdef DOXYGEN
|
||||
//and doesn't seem to work correctly in SWIG's preprocessor
|
||||
#ifdef SWIGPYTHON
|
||||
#ifdef SWIGPYTHON2
|
||||
%include common_hpp_doc.i
|
||||
%include gpio_class_doc.i
|
||||
%include i2c_class_doc.i
|
||||
|
@@ -18,17 +18,11 @@ if (PYTHON2_LIBRARY)
|
||||
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} ${_file}class_doc_i)
|
||||
endforeach ()
|
||||
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} common_hpp_doc_i)
|
||||
|
||||
add_custom_target (pydoc
|
||||
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with pydoc" VERBATIM
|
||||
)
|
||||
endif ()
|
||||
|
||||
set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
|
||||
OUTPUT_NAME _mraa
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DSWIGPYTHON2=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
|
@@ -19,8 +19,8 @@ Welcome to mraa's documentation!
|
||||
Supported Platforms
|
||||
===================
|
||||
|
||||
* `Galileo Gen 1 - Rev D <../galileorevd.html>`_
|
||||
* `Galileo Gen 2 - Rev H <../galileorevh.html>`_
|
||||
* `Galileo Gen 1 <../galileogen1.html>`_
|
||||
* `Galileo Gen 2 <../galileogen2.html>`_
|
||||
* `Intel Edison <../edison.html>`_
|
||||
* `Intel(R) NUC DE3815tykhe <../de3815.html>`_
|
||||
* `Intel(R) Minnowboard Max <../minnowmax.html>`_
|
||||
|
@@ -15,7 +15,7 @@ if (PYTHON3_LIBRARY)
|
||||
|
||||
set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
|
||||
OUTPUT_NAME _mraa
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DDSWIGPYTHON3=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
|
129
src/spi/spi.c
129
src/spi/spi.c
@@ -135,10 +135,22 @@ mraa_spi_init(int bus)
|
||||
mraa_spi_context
|
||||
mraa_spi_init_raw(unsigned int bus, unsigned int cs)
|
||||
{
|
||||
mraa_result_t status = MRAA_SUCCESS;
|
||||
|
||||
mraa_spi_context dev = mraa_spi_init_internal(plat == NULL ? NULL : plat->adv_func);
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
|
||||
return NULL;
|
||||
status = MRAA_ERROR_NO_RESOURCES;
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_init_raw_replace)) {
|
||||
status = dev->advance_func->spi_init_raw_replace(dev, bus, cs);
|
||||
if (status == MRAA_SUCCESS) {
|
||||
return dev;
|
||||
} else {
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
char path[MAX_SIZE];
|
||||
@@ -147,8 +159,8 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
|
||||
dev->devfd = open(path, O_RDWR);
|
||||
if (dev->devfd < 0) {
|
||||
syslog(LOG_ERR, "spi: Failed opening SPI Device. bus:%s", path);
|
||||
free(dev);
|
||||
return NULL;
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
|
||||
int speed = 0;
|
||||
@@ -160,18 +172,26 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
|
||||
syslog(LOG_WARNING, "spi: Max speed query failed, setting %d", dev->clock);
|
||||
}
|
||||
|
||||
if (mraa_spi_mode(dev, MRAA_SPI_MODE0) != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
status = mraa_spi_mode(dev, MRAA_SPI_MODE0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
|
||||
if (mraa_spi_lsbmode(dev, 0) != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
status = mraa_spi_lsbmode(dev, 0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
|
||||
if (mraa_spi_bit_per_word(dev, 8) != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
status = mraa_spi_bit_per_word(dev, 8);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
goto init_raw_cleanup;
|
||||
}
|
||||
|
||||
init_raw_cleanup:
|
||||
if (status != MRAA_SUCCESS) {
|
||||
if (dev != NULL) {
|
||||
free(dev);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -181,6 +201,15 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
|
||||
mraa_result_t
|
||||
mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: mode: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_mode_replace)) {
|
||||
return dev->advance_func->spi_mode_replace(dev, mode);
|
||||
}
|
||||
|
||||
uint8_t spi_mode = 0;
|
||||
switch (mode) {
|
||||
case MRAA_SPI_MODE0:
|
||||
@@ -212,6 +241,15 @@ mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
|
||||
mraa_result_t
|
||||
mraa_spi_frequency(mraa_spi_context dev, int hz)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: frequency: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_frequency_replace)) {
|
||||
return dev->advance_func->spi_frequency_replace(dev, hz);
|
||||
}
|
||||
|
||||
int speed = 0;
|
||||
dev->clock = hz;
|
||||
if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
|
||||
@@ -226,6 +264,11 @@ mraa_spi_frequency(mraa_spi_context dev, int hz)
|
||||
mraa_result_t
|
||||
mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: lsbmode: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_lsbmode_replace)) {
|
||||
return dev->advance_func->spi_lsbmode_replace(dev, lsb);
|
||||
}
|
||||
@@ -246,6 +289,15 @@ mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
mraa_result_t
|
||||
mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: bit_per_word: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_bit_per_word_replace)) {
|
||||
return dev->advance_func->spi_bit_per_word_replace(dev, bits);
|
||||
}
|
||||
|
||||
if (ioctl(dev->devfd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
|
||||
syslog(LOG_ERR, "spi: Failed to set bit per word");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
@@ -257,6 +309,15 @@ mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
|
||||
int
|
||||
mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: write: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_write_replace)) {
|
||||
return dev->advance_func->spi_write_replace(dev, data);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
@@ -279,6 +340,15 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
int
|
||||
mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: write_word: context is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_write_word_replace)) {
|
||||
return dev->advance_func->spi_write_word_replace(dev, data);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
@@ -301,6 +371,15 @@ mraa_spi_write_word(mraa_spi_context dev, uint16_t data)
|
||||
mraa_result_t
|
||||
mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_transfer_buf_replace)) {
|
||||
return dev->advance_func->spi_transfer_buf_replace(dev, data, rxbuf, length);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
@@ -320,6 +399,15 @@ mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int l
|
||||
mraa_result_t
|
||||
mraa_spi_transfer_buf_word(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: transfer_buf_word: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_transfer_buf_word_replace)) {
|
||||
return dev->advance_func->spi_transfer_buf_word_replace(dev, data, rxbuf, length);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
@@ -339,6 +427,11 @@ mraa_spi_transfer_buf_word(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf
|
||||
uint8_t*
|
||||
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: write_buf: context is invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t* recv = malloc(sizeof(uint8_t) * length);
|
||||
|
||||
if (mraa_spi_transfer_buf(dev, data, recv, length) != MRAA_SUCCESS) {
|
||||
@@ -351,6 +444,11 @@ mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
|
||||
uint16_t*
|
||||
mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: write_buf_word: context is invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint16_t* recv = malloc(sizeof(uint16_t) * length);
|
||||
|
||||
if (mraa_spi_transfer_buf_word(dev, data, recv, length) != MRAA_SUCCESS) {
|
||||
@@ -363,6 +461,15 @@ mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length)
|
||||
mraa_result_t
|
||||
mraa_spi_stop(mraa_spi_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "spi: stop: context is invalid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, spi_stop_replace)) {
|
||||
return dev->advance_func->spi_stop_replace(dev);
|
||||
}
|
||||
|
||||
close(dev->devfd);
|
||||
free(dev);
|
||||
return MRAA_SUCCESS;
|
||||
|
@@ -320,7 +320,7 @@ mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t bit)
|
||||
/* return the bit present on the bus (0xff is a '1', anything else
|
||||
* (typically 0xfc or 0x00) is a 0
|
||||
*/
|
||||
if (_ow_read_byte(dev, &ch) == -1 || ret == -1) {
|
||||
if (_ow_read_byte(dev, &ch) != MRAA_SUCCESS || ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
return (ch == 0xff);
|
||||
|
@@ -29,7 +29,7 @@
|
||||
#include <linux/spi/spidev.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "x86/intel_galileo_rev_d.h"
|
||||
#include "x86/intel_galileo_gen_1.h"
|
||||
|
||||
#define UIO_PATH "/dev/uio0"
|
||||
#define PLATFORM_NAME "Intel Galileo Gen 1"
|
||||
@@ -169,7 +169,7 @@ mraa_intel_galileo_g1_pwm_init_pre(int pin)
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_rev_d()
|
||||
mraa_intel_galileo_g1()
|
||||
{
|
||||
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
||||
if (b == NULL) {
|
||||
@@ -196,7 +196,7 @@ mraa_intel_galileo_rev_d()
|
||||
b->adv_func->spi_lsbmode_replace = &mraa_intel_galileo_g1_spi_lsbmode_replace;
|
||||
b->adv_func->pwm_init_pre = mraa_intel_galileo_g1_pwm_init_pre;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_GALILEO_REV_D_PINCOUNT, sizeof(mraa_pininfo_t));
|
||||
b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_GALILEO_GEN_1_PINCOUNT, sizeof(mraa_pininfo_t));
|
||||
if (b->pins == NULL) {
|
||||
free(b->adv_func);
|
||||
goto error;
|
@@ -28,7 +28,7 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "x86/intel_galileo_rev_g.h"
|
||||
#include "x86/intel_galileo_gen_2.h"
|
||||
|
||||
#define MAX_SIZE 64
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
@@ -262,7 +262,7 @@ mraa_intel_galileo_g2_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_gen2()
|
||||
mraa_intel_galileo_g2()
|
||||
{
|
||||
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
||||
if (b == NULL) {
|
||||
@@ -808,9 +808,9 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[18].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[18].aio.mux[0].pin = 57;
|
||||
b->pins[18].aio.mux[0].value = MRAA_GPIO_IN;
|
||||
b->pins[18].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
|
||||
b->pins[18].aio.mux[1].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[18].aio.mux[1].pin = 60;
|
||||
b->pins[18].aio.mux[1].value = 1;
|
||||
b->pins[18].aio.mux[1].value = MRAA_GPIO_OUT_HIGH;
|
||||
b->pins[18].aio.mux[2].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[18].aio.mux[2].pin = 78;
|
||||
b->pins[18].aio.mux[2].value = 0;
|
||||
@@ -819,9 +819,9 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[18].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[18].gpio.mux[0].pin = 57;
|
||||
b->pins[18].gpio.mux[0].value = MRAA_GPIO_IN;
|
||||
b->pins[18].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
|
||||
b->pins[18].gpio.mux[1].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[18].gpio.mux[1].pin = 60;
|
||||
b->pins[18].gpio.mux[1].value = 1;
|
||||
b->pins[18].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH;
|
||||
b->pins[18].gpio.mux[2].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[18].gpio.mux[2].pin = 78;
|
||||
b->pins[18].gpio.mux[2].value = 1;
|
||||
@@ -845,9 +845,9 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[19].aio.mux[0].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[19].aio.mux[0].pin = 59;
|
||||
b->pins[19].aio.mux[0].value = MRAA_GPIO_IN;
|
||||
b->pins[19].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
|
||||
b->pins[19].aio.mux[1].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[19].aio.mux[1].pin = 60;
|
||||
b->pins[19].aio.mux[1].value = 1;
|
||||
b->pins[19].aio.mux[1].value = MRAA_GPIO_OUT_HIGH;
|
||||
b->pins[19].aio.mux[2].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[19].aio.mux[2].pin = 79;
|
||||
b->pins[19].aio.mux[2].value = 0;
|
||||
@@ -856,9 +856,9 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[19].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[19].gpio.mux[0].pin = 59;
|
||||
b->pins[19].gpio.mux[0].value = MRAA_GPIO_IN;
|
||||
b->pins[19].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE;
|
||||
b->pins[19].gpio.mux[1].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[19].gpio.mux[1].pin = 60;
|
||||
b->pins[19].gpio.mux[1].value = 1;
|
||||
b->pins[19].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH;
|
||||
b->pins[19].gpio.mux[2].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[19].gpio.mux[2].pin = 79;
|
||||
b->pins[19].gpio.mux[2].value = 1;
|
@@ -47,7 +47,7 @@ mraa_gt_tuchuck_board()
|
||||
b->adc_raw = 0;
|
||||
b->adc_supported = 0;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_GT_TUCHUCK_PINCOUNT);
|
||||
b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_GT_TUCHUCK_PINCOUNT, sizeof(mraa_pininfo_t));
|
||||
if (b->pins == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@@ -81,22 +81,14 @@ mraa_gt_tuchuck_board()
|
||||
|
||||
b->def_i2c_bus = b->i2c_bus[0].bus_id;
|
||||
|
||||
#if 0
|
||||
b->spi_bus_count = 6;
|
||||
b->spi_bus_count = 3;
|
||||
b->def_spi_bus = 0;
|
||||
b->spi_bus[0].bus_id = 32764;
|
||||
b->spi_bus[0].slave_s = 1;
|
||||
b->spi_bus[1].bus_id = 32764;
|
||||
b->spi_bus[1].slave_s = 2;
|
||||
b->spi_bus[2].bus_id = 32765;
|
||||
b->spi_bus[2].slave_s = 0;
|
||||
b->spi_bus[3].bus_id = 32765;
|
||||
b->spi_bus[3].slave_s = 1;
|
||||
b->spi_bus[4].bus_id = 32766;
|
||||
b->spi_bus[4].slave_s = 0;
|
||||
b->spi_bus[5].bus_id = 32766;
|
||||
b->spi_bus[5].slave_s = 1;
|
||||
#endif
|
||||
b->spi_bus[0].bus_id = 32765;
|
||||
b->spi_bus[0].slave_s = 0;
|
||||
b->spi_bus[1].bus_id = 32766;
|
||||
b->spi_bus[1].slave_s = 0;
|
||||
b->spi_bus[2].bus_id = 32766;
|
||||
b->spi_bus[2].slave_s = 1;
|
||||
|
||||
int pos = 0;
|
||||
|
||||
@@ -111,7 +103,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP1RX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 421;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -124,7 +116,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP1TX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 422;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -136,7 +128,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP1FS0", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 417;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -152,7 +144,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP1FS2", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 419;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -165,7 +157,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP1CLK", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 416;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -455,7 +447,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0FS0", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 411;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -465,43 +457,43 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0FS1", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 412;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPI_DAT", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 385;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0FS2", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 411;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPICLKB", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 384;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0FS3", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 410;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPICLKA", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 383;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0TX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 414;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -516,7 +508,7 @@ mraa_gt_tuchuck_board()
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "SPP0RX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 415;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
@@ -558,6 +550,7 @@ mraa_gt_tuchuck_board()
|
||||
strncpy(b->pins[pos].name, "UART1TX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[pos].gpio.pinmap = 484;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].uart.pinmap = 0;
|
||||
b->pins[pos].uart.parent_id = 0;
|
||||
b->pins[pos].uart.mux_total = 0;
|
||||
@@ -574,6 +567,7 @@ mraa_gt_tuchuck_board()
|
||||
strncpy(b->pins[pos].name, "UART1RX", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[pos].gpio.pinmap = 483;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].uart.pinmap = 0;
|
||||
b->pins[pos].uart.parent_id = 0;
|
||||
b->pins[pos].uart.mux_total = 0;
|
||||
@@ -590,6 +584,7 @@ mraa_gt_tuchuck_board()
|
||||
strncpy(b->pins[pos].name, "UART1RT", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
|
||||
b->pins[pos].gpio.pinmap = 485;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].uart.pinmap = 0;
|
||||
b->pins[pos].uart.parent_id = 0;
|
||||
b->pins[pos].uart.mux_total = 0;
|
||||
@@ -598,6 +593,7 @@ mraa_gt_tuchuck_board()
|
||||
strncpy(b->pins[pos].name, "RTC_CLK", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 367;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "UART1CT", 8);
|
||||
@@ -616,32 +612,37 @@ mraa_gt_tuchuck_board()
|
||||
strncpy(b->pins[pos].name, "LED100", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 337;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "LED101", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
// if BIOS is pre-L then this is 338
|
||||
b->pins[pos].gpio.pinmap = 395;
|
||||
b->pins[pos].gpio.pinmap = 338;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "LED102", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 339;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "LED103", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 340;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "LEDWIFI", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 438;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "LEDBT", 8);
|
||||
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[pos].gpio.pinmap = 439;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
return b;
|
||||
|
@@ -89,7 +89,7 @@ mraa_intel_minnowboard_byt_compatible(mraa_boolean_t turbot)
|
||||
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
||||
|
||||
struct utsname running_uname;
|
||||
int uname_major, uname_minor, max_pins[28];
|
||||
int uname_major, uname_minor;
|
||||
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
|
@@ -86,7 +86,7 @@ mraa_up_board()
|
||||
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
||||
|
||||
struct utsname running_uname;
|
||||
int uname_major, uname_minor, max_pins[27];
|
||||
int uname_major, uname_minor;
|
||||
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
|
@@ -28,8 +28,8 @@
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#include "x86/intel_galileo_rev_d.h"
|
||||
#include "x86/intel_galileo_rev_g.h"
|
||||
#include "x86/intel_galileo_gen_1.h"
|
||||
#include "x86/intel_galileo_gen_2.h"
|
||||
#include "x86/intel_edison_fab_c.h"
|
||||
#include "x86/intel_de3815.h"
|
||||
#include "x86/intel_nuc5.h"
|
||||
@@ -51,9 +51,9 @@ mraa_x86_platform()
|
||||
FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
|
||||
if (fh != NULL) {
|
||||
if (getline(&line, &len, fh) != -1) {
|
||||
if (strncmp(line, "GalileoGen2", 11) == 0) {
|
||||
if (strncmp(line, "GalileoGen2", 11) == 0 || strncmp(line, "SIMATIC IOT2000", 15) == 0) {
|
||||
platform_type = MRAA_INTEL_GALILEO_GEN2;
|
||||
plat = mraa_intel_galileo_gen2();
|
||||
plat = mraa_intel_galileo_g2();
|
||||
} else if (strncmp(line, "BODEGA BAY", 10) == 0) {
|
||||
platform_type = MRAA_INTEL_EDISON_FAB_C;
|
||||
plat = mraa_intel_edison_fab_c();
|
||||
@@ -74,7 +74,7 @@ mraa_x86_platform()
|
||||
plat = mraa_intel_minnowboard_byt_compatible(0);
|
||||
} else if (strncasecmp(line, "Galileo", 7) == 0) {
|
||||
platform_type = MRAA_INTEL_GALILEO_GEN1;
|
||||
plat = mraa_intel_galileo_rev_d();
|
||||
plat = mraa_intel_galileo_g1();
|
||||
} else if (strncasecmp(line, "MinnowBoard Compatible", 22) == 0) {
|
||||
platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
|
||||
plat = mraa_intel_minnowboard_byt_compatible(1);
|
||||
@@ -116,7 +116,7 @@ mraa_x86_platform()
|
||||
return platform_type;
|
||||
#else
|
||||
#if defined(xMRAA_INTEL_GALILEO_GEN2)
|
||||
plat = mraa_intel_galileo_gen2();
|
||||
plat = mraa_intel_galileo_g2();
|
||||
#elif defined(xMRAA_INTEL_EDISON_FAB_C)
|
||||
plat = mraa_intel_edison_fab_c();
|
||||
#elif defined(xMRAA_INTEL_DE3815)
|
||||
@@ -124,7 +124,7 @@ mraa_x86_platform()
|
||||
#elif defined(xMRAA_INTEL_MINNOWBOARD_MAX)
|
||||
plat = mraa_intel_minnowboard_byt_compatible();
|
||||
#elif defined(xMRAA_INTEL_GALILEO_GEN1)
|
||||
plat = mraa_intel_galileo_rev_d();
|
||||
plat = mraa_intel_galileo_g1();
|
||||
#elif defined(xMRAA_INTEL_NUC5)
|
||||
plat = mraa_intel_nuc5();
|
||||
#elif defined(xMRAA_INTEL_SOFIA_3GR)
|
||||
|
@@ -22,6 +22,14 @@ add_test (NAME py_i2c_read_bytes_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMA
|
||||
add_test (NAME py_i2c_read_word_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/i2c_checks_read_word_data.py)
|
||||
add_test (NAME py_i2c_write_word_data COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/i2c_checks_write_word_data.py)
|
||||
|
||||
add_test (NAME py_spi_bit_per_word COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_bit_per_word.py)
|
||||
add_test (NAME py_spi_checks_lsbmode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_lsbmode.py)
|
||||
add_test (NAME py_spi_checks_mode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_mode.py)
|
||||
add_test (NAME py_spi_checks_freq COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_freq.py)
|
||||
add_test (NAME py_spi_checks_write_byte COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write_byte.py)
|
||||
add_test (NAME py_spi_checks_write_word COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write_word.py)
|
||||
add_test (NAME py_spi_checks_write COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/spi_checks_write.py)
|
||||
|
||||
set_tests_properties(py_general
|
||||
py_platform
|
||||
py_gpio_basic
|
||||
@@ -42,4 +50,11 @@ set_tests_properties(py_general
|
||||
py_i2c_read_bytes_data
|
||||
py_i2c_read_word_data
|
||||
py_i2c_write_word_data
|
||||
py_spi_bit_per_word
|
||||
py_spi_checks_lsbmode
|
||||
py_spi_checks_mode
|
||||
py_spi_checks_freq
|
||||
py_spi_checks_write_byte
|
||||
py_spi_checks_write_word
|
||||
py_spi_checks_write
|
||||
PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
@@ -27,7 +27,7 @@
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
PLATFORM_PINCOUNT = 4
|
||||
PLATFORM_PINCOUNT = 8
|
||||
PLATFORM_STD_ADC_RES_BITS = 10
|
||||
PLATFORM_MAX_ADC_RES_BITS = 12
|
||||
|
||||
|
48
tests/mock/spi_checks_bit_per_word.py
Normal file
48
tests/mock/spi_checks_bit_per_word.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksBitPerWord(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_bit_per_word(self):
|
||||
TEST_BIT_PER_WORD = 16
|
||||
self.assertEqual(self.spi.bitPerWord(TEST_BIT_PER_WORD),
|
||||
m.SUCCESS,
|
||||
"Setting bit per word to %d did not return success" %TEST_BIT_PER_WORD)
|
||||
|
||||
def test_i2c_frequency_invalid_smaller_than_min(self):
|
||||
TEST_BIT_PER_WORD = -100
|
||||
self.assertRaises(OverflowError, self.spi.bitPerWord, TEST_BIT_PER_WORD)
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
56
tests/mock/spi_checks_freq.py
Normal file
56
tests/mock/spi_checks_freq.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksFreq(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_set_freq(self):
|
||||
TEST_FREQ = 20000000
|
||||
self.assertEqual(self.spi.frequency(TEST_FREQ),
|
||||
m.SUCCESS,
|
||||
"Setting SPI frequency to %d did not return success" %TEST_FREQ)
|
||||
|
||||
def test_spi_set_freq_invalid_smaller_than_min_zero(self):
|
||||
TEST_FREQ = 0
|
||||
self.assertEqual(self.spi.frequency(TEST_FREQ),
|
||||
m.ERROR_INVALID_PARAMETER,
|
||||
"Setting SPI frequency to %d did not return error" %TEST_FREQ)
|
||||
|
||||
def test_spi_set_freq_invalid_smaller_than_min_negative(self):
|
||||
TEST_FREQ = -10
|
||||
self.assertEqual(self.spi.frequency(TEST_FREQ),
|
||||
m.ERROR_INVALID_PARAMETER,
|
||||
"Setting SPI frequency to %d did not return error" %TEST_FREQ)
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
55
tests/mock/spi_checks_lsbmode.py
Normal file
55
tests/mock/spi_checks_lsbmode.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksLsbmode(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_set_lsbmode_false(self):
|
||||
TEST_LSBMODE = False
|
||||
self.assertEqual(self.spi.lsbmode(TEST_LSBMODE),
|
||||
m.SUCCESS,
|
||||
"Setting LSB mode to %s did not return success" %TEST_LSBMODE)
|
||||
|
||||
def test_spi_set_lsbmode_true(self):
|
||||
TEST_LSBMODE = True
|
||||
self.assertEqual(self.spi.lsbmode(TEST_LSBMODE),
|
||||
m.SUCCESS,
|
||||
"Setting LSB mode to %s did not return success" %TEST_LSBMODE)
|
||||
|
||||
def test_spi_set_lsbmode_invalid(self):
|
||||
TEST_LSBMODE = 10
|
||||
self.assertRaises(TypeError, self.spi.lsbmode, TEST_LSBMODE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
74
tests/mock/spi_checks_mode.py
Normal file
74
tests/mock/spi_checks_mode.py
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksMode(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_set_mode_MODE0(self):
|
||||
TEST_MODE = m.SPI_MODE0
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.SUCCESS,
|
||||
"Setting SPI mode to %d did not return success" %TEST_MODE)
|
||||
|
||||
def test_spi_set_mode_MODE1(self):
|
||||
TEST_MODE = m.SPI_MODE1
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.SUCCESS,
|
||||
"Setting SPI mode to %d did not return success" %TEST_MODE)
|
||||
|
||||
def test_spi_set_mode_MODE2(self):
|
||||
TEST_MODE = m.SPI_MODE2
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.SUCCESS,
|
||||
"Setting SPI mode to %d did not return success" %TEST_MODE)
|
||||
|
||||
def test_spi_set_mode_MODE3(self):
|
||||
TEST_MODE = m.SPI_MODE3
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.SUCCESS,
|
||||
"Setting SPI mode to %d did not return success" %TEST_MODE)
|
||||
|
||||
def test_spi_set_mode_invalid_smaller_than_min(self):
|
||||
TEST_MODE = -10
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.ERROR_INVALID_PARAMETER,
|
||||
"Setting SPI mode to %d did not return error" %TEST_MODE)
|
||||
|
||||
def test_spi_set_mode_invalid_bigger_than_max(self):
|
||||
TEST_MODE = 150
|
||||
self.assertEqual(self.spi.mode(TEST_MODE),
|
||||
m.ERROR_INVALID_PARAMETER,
|
||||
"Setting SPI mode to %d did not return error" %TEST_MODE)
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
28
tests/mock/spi_checks_shared.py
Normal file
28
tests/mock/spi_checks_shared.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
MRAA_SPI_BUS_NUM = 0
|
||||
MOCK_SPI_REPLY_DATA_MODIFIER_BYTE = 0xAB
|
||||
MOCK_SPI_REPLY_DATA_MODIFIER_WORD = 0xABBA
|
||||
MOCK_SPI_TEST_DATA_LEN = 5
|
45
tests/mock/spi_checks_write.py
Normal file
45
tests/mock/spi_checks_write.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksWrite(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_write(self):
|
||||
DATA_TO_WRITE = bytearray([0xEE for i in range(MOCK_SPI_TEST_DATA_LEN)])
|
||||
DATA_TO_EXPECT = bytearray([0xEE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE for i in range(MOCK_SPI_TEST_DATA_LEN)])
|
||||
self.assertEqual(self.spi.write(DATA_TO_WRITE),
|
||||
DATA_TO_EXPECT,
|
||||
"SPI write() returned unexpected data")
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
52
tests/mock/spi_checks_write_byte.py
Normal file
52
tests/mock/spi_checks_write_byte.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksWriteByte(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_write_byte(self):
|
||||
TEST_BYTE = 0xEE
|
||||
self.assertEqual(self.spi.writeByte(TEST_BYTE),
|
||||
TEST_BYTE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE,
|
||||
"SPI writeByte() returned unexpected data")
|
||||
|
||||
def test_spi_write_byte_invalid_bigger_than_max(self):
|
||||
TEST_VALUE = 0xEEFF
|
||||
self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE)
|
||||
|
||||
def test_spi_write_byte_invalid_smaller_than_min(self):
|
||||
TEST_VALUE = -1
|
||||
self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE)
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
52
tests/mock/spi_checks_write_word.py
Normal file
52
tests/mock/spi_checks_write_word.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
from spi_checks_shared import *
|
||||
|
||||
class SpiChecksWriteWord(u.TestCase):
|
||||
def setUp(self):
|
||||
self.spi = m.Spi(MRAA_SPI_BUS_NUM)
|
||||
|
||||
def tearDown(self):
|
||||
del self.spi
|
||||
|
||||
def test_spi_write_word(self):
|
||||
TEST_WORD = 0xAAEE
|
||||
self.assertEqual(self.spi.writeWord(TEST_WORD),
|
||||
TEST_WORD ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD,
|
||||
"SPI writeWord() returned unexpected data")
|
||||
|
||||
def test_spi_write_word_invalid_bigger_than_max(self):
|
||||
TEST_VALUE = 0xEEFFEE
|
||||
self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE)
|
||||
|
||||
def test_spi_write_word_invalid_smaller_than_min(self):
|
||||
TEST_VALUE = -1
|
||||
self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE)
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
Reference in New Issue
Block a user