Compare commits

...

108 Commits

Author SHA1 Message Date
Thomas Ingleby
2a682aaa65 python: doc: add python doc to python3
Make sure that right python is used for the right bindings docs

Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
2016-08-13 13:33:58 +02:00
Brendan Le Foll
d700cae7c4 mraa: Update to v1.2.3
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-10 11:33:28 +01:00
Brendan Le Foll
356096350b README.md: Add travis build status
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-10 11:21:54 +01:00
Brendan Le Foll
b4919de733 .travis.yml: Add npmpkg travis builds
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-10 11:21:54 +01:00
Brendan Le Foll
49ee1ebef5 Revert "binding.gyp.cmake: Fix npm builds by stopping dependency on json-c"
This reverts commit 50213f97bc. This sets
JSONPLAT during compilation and doesn't disable it during cmake's configure
process which is done by jenkins. This means that mraa_init_platform_json never
gets define since it's under an #ifndef
2016-08-10 09:17:48 +01:00
Brendan Le Foll
c0fbccb3b6 mraa: Update to v1.2.2
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-09 14:10:48 +01:00
Thomas Ingleby
fce4daab02 mraa: Correct spelling of capabilities
Type was correctly spelt, but the member in the platform strut was not.
My mistake from 2014.

Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
2016-08-08 21:44:00 +02:00
Brendan Le Foll
29be2b64c0 mraa: Update to v1.2.1
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-03 16:50:09 +01:00
Brendan Le Foll
50213f97bc binding.gyp.cmake: Fix npm builds by stopping dependency on json-c
This disables JSONPLAT but means we can build on stuff without json-c

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-03 16:49:30 +01:00
Brendan Le Foll
e675123d50 mraa: Update to v1.2.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-03 13:29:15 +01:00
Brendan Le Foll
36153ad7ad intel_galileo_rev_d.c: Move code for gen1 from pwm.c to advance function
This re-enables correct PWM on gen1

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-03 13:27:35 +01:00
Brendan Le Foll
aed965c27d pwm.c: Remove manual gpio muxing when using a pin that has both pwm & gpio enabled
This fixes PWM on the GT platform. The code was only used on gen1 galileo and
is rarely used because it's the only platform in mraa that supports 2 functions
on the same pin without any time of advanced function pointer being called
(gen2/edison). GT however has kernel side muxing which causes the gpio to be
initialised meaning the PWM channel is never set to active as it's activated
after the GPIO is opened and the GPIO keeps precendence

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-08-03 13:25:32 +01:00
Houman Brinjcargorabi
5d763cb7e5 Example: Added example json file for reference
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
5d94d0a13c travisl.yml: Added the ability to build with json plat to the tests
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
ca0d740ee0 CMakeLists: Added json platform options and build
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
c7570ff7c2 types.h: Added json platform type
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
a8a7771a16 mraa_internal_types: Changed pinmap type from unsigned to signed Int
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
1ce0b138d2 mraa_internal_types.h: changed unsigned ints in board_t to ints and removed const modifiers
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Houman Brinjcargorabi
8ba8ce3b26 mraa.c: Added init platform from json file
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:33:29 +01:00
Alex Tereschenko
346f447c4d mock: added I2C functionality
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:28:53 +01:00
Alex Tereschenko
26718a67a2 mock: split out aio and gpio implementations to separate files
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:28:53 +01:00
Alex Tereschenko
0021b1aace i2c: fixed i2c_stop_replace function never being called
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:28:53 +01:00
Alex Tereschenko
da3efdc4b9 i2c: added standard context validity checks
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:28:53 +01:00
Houman Brinjcargorabi
230b6084ba firmata_mraa.c: Fixed aio bug
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-27 11:10:54 +01:00
Brendan Le Foll
8cd1a06562 mraa: Update to v1.1.2
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-12 12:31:23 +01:00
Brendan Le Foll
874d0f47bd gt: allow for i2c bus to move around a little
Unfortunately GT has alot of i2c buses, the second lot of designware buses can
turn up after the i915 i2c buses but since they all have the same name, we do a
dumb check to see if they are 5/6 or 9/10. Hopefully future kernel/firmware
will let us do something smarter.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-12 12:26:46 +01:00
Brendan Le Foll
6c9aeb9b9e mraa-i2c: stop switching on every platform type and assume linux
This patch makes mraa-i2c give sensible bus numbers

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-12 12:09:37 +01:00
Alex Tereschenko
63b244cfc3 mock: added AIO pin and logic
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-11 10:48:43 +01:00
Alex Tereschenko
917a1bd371 aio: added context validity and replace function checks to aio_close()
Added standard context validity check, another check for a replace function
and corrected a return statement to fit our standard code style.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-11 10:48:43 +01:00
Alex Tereschenko
e43459d031 aio: added standard context validity check to aio_read()
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-11 10:48:43 +01:00
Mihai Tudor Panu
eabee5f864 gt-tuchuck: fix I2C bus typos in board definition file
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-09 08:40:10 +01:00
Jamie Tanna
a22ff43f59 travis-ci: Update infrastructure to Trusty Tahr
Update Travis to use the latest version of Ubuntu: 14.04.3 Trusty Tahr.

- Fix issue where Node v0.10 did not get installed, therefore builds
  would fail. In addition, don't hardcode the path to Node v0.10.36 as
  there have since been updates to v0.10.
- Fix issue where CMake cannot find the PythonLibs folder, fixed via
  https://github.com/travis-ci/travis-ci/issues/5326
- Ensure that we have the Python2 development headers

Signed-off-by: Jamie Tanna <jamie@jamietanna.co.uk>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-08 16:01:30 +01:00
Alex Tereschenko
1af737f3d9 mock: mraa with mock platform now works in Windows under MSYS2
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-05 19:32:58 +01:00
Alex Tereschenko
bcb6adc551 mock: added mraa mock platform infra and GPIO implementation
Mock platform allows one to use mraa without having any real HW.

This commit makes necessary foundational changes and implements
GPIO functionality as well as adds respective tests.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-05 16:19:05 +01:00
Houman Brinjcargorabi
593fd0be54 mraa.c: Removed duplicate sys/stat.h
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-05 11:11:19 +01:00
Houman Brinjcargorabi
3992f9d596 mraa.c: Remove duplicate string.h include
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-05 11:03:44 +01:00
Brendan Le Foll
43718e7cbf imraa.c: Remove double include unistd.h
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-07-04 11:21:04 +01:00
Brendan Le Foll
d336e9f8d6 mraa: Update to v1.1.1
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-30 16:13:55 +01:00
Alex Tereschenko
9634f17a2a gpio: fixed potential null pointer dereference in mraa_gpio_read_dir()
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-30 16:10:11 +01:00
Brendan Le Foll
dfecc68320 .travis.yml: add python3 support
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 11:20:46 +01:00
Brendan Le Foll
b9a6d2a86a .travis.yml: build our own version of swig
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 11:20:46 +01:00
Brendan Le Foll
bc178b27ee .travis.yml: move to travis containers
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 11:20:40 +01:00
Brendan Le Foll
fe9264c98f mraa.c: fix unsigned int comparison by usign UINT_MAX instead of -1
This works since both are essentially 'impossible' values.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 10:02:50 +01:00
Lay, Kuan Loon
de0543923c iio: mount matrix compliant to IIO core kernel standard
IIO mount matrix is supported in kernel version 4.6.
Change mraa_iio_get_mount_matrix to take in one more parameter
‘mount matrix sysfs entry name’, because different sensor driver
may expose different mount matrix sysfs entry.

Following link explain the mount matrix usage and sysfs entry:
https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio

Signed-off-by: Lay, Kuan Loon <kuan.loon.lay@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 10:02:08 +01:00
David Antler
b1d23303f7 Change messaging to indicate mraaStub is on npm
The module has been added to npm.  See:

  https://www.npmjs.com/package/mraaStub

Signed-off-by: David Antler <david.a.antler@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 10:02:05 +01:00
Bruce Beare
c1fd2896c2 edison: fix edison spelling errors
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 09:59:29 +01:00
Bruce Beare
5704c15665 gt: Add module lights to the gpio HAL
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-29 09:58:57 +01:00
Houman Brinjcargorabi
b5b84c6186 examples: Added examples for initio by description
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-27 11:46:24 +01:00
Alex Tereschenko
0bd488bc53 cmake: fixed incorrect MRAAPLATFORMFORCE definition
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-27 11:44:30 +01:00
Alex Tereschenko
f9bc314223 x86.c: fixed typo in Tuchuck board forced enablement
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-27 11:43:38 +01:00
Brendan Le Foll
50e1b568fb pydocs: Fix sys.path for multi python because added python2 dir
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-24 14:21:55 +01:00
Brendan Le Foll
a54386c5d3 mraa: Update to v1.1.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-23 17:23:56 +01:00
Brendan Le Foll
0577321f4c intel_gt: add support for gt + Tuchuck board
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-23 16:16:38 +01:00
Brendan Le Foll
5f515f7648 mraa-gpio.c: dont display pins set as not MRAA_PINS_VALID
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-20 12:18:38 +01:00
Brendan Le Foll
3d2163e2cb mraa-gpio.c: Fix raw gpio setting
setraw was not using mraa_gpio_init_raw so did not work

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-20 10:39:20 +01:00
Alex Tereschenko
8af6843566 PWM: added workaround for Edison's problem with 0% duty
As described in issue #91, on Edison setting 0% duty doesn't
disable the PWM on a pin completely.

Therefore we add a couple of Edison-specific _pre functions
and an internal PWM state variable, which we use to toggle PWM
enabled/disabled based on what duty is set for the pin.

Closes #91.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-16 14:12:33 +01:00
Houman brinjcargorabi
c413a43d5a mraa.c: Fixed logic error when deciding if the description is null
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 15:21:55 +01:00
Stefan Andritoiu
03b548c33b java: Added version information & checks to ensure Java version matches Native version
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 15:21:12 +01:00
Brendan Le Foll
5160d909d3 OpenCVDetectPython.cmake: set minimum python versions
This fixes compilation when python is not found or only one version of python
is found

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 12:11:05 +01:00
Houman brinjcargorabi
8329bcab62 intel_edison_fab_c.c: fixed the pins not being freed in the event of a tristate read failing
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:29:17 +01:00
Houman brinjcargorabi
e8d6f38ee0 intel_nuc5.c: Fixed incorrect I2C numbering, effectively not shifting the pin number correctly
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:29:15 +01:00
Brendan Le Foll
a177a3f729 cmake: Fix tests with multiple python bindings being built
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-06-01 11:21:20 +01:00
Brendan Le Foll
99841419ab python: Support building of both python2 & python3 bindings
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-26 14:51:34 +01:00
David Antler
1cfdfcddc6 Add JavaScript mraaStub project
Signed-off-by: David Antler <david.a.antler@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:28:04 +01:00
Houman brinjcargorabi
a321d6707f mraa.i: Swig interface options to ignore the void* IO constructors and pre-initialise the c++ template functions
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
b6e6374370 c++: Added the ability to initialise a class using a context struct
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
bcf1584fbe mraa.c: Added common function to init io from a description
Signed-off-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-24 11:21:13 +01:00
Houman brinjcargorabi
a9de84b74a intel_galileo_rev_g.c: Corrected typo in mapping re setting the pincmd for GPIO2
Fixes typo in 95c259f6b2

Acked-by: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-20 11:26:59 +01:00
Alex Tereschenko
0ee25fbd4d pwm.hpp: fixed some typos and styling in comments
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:52:16 +01:00
Bruno Meneguele
4fc3e7a73f banana_pi.md: fixed header table layout
In the second table (second 8-pin connector) wasn't present the table header and
because of that the layout was broken.

Signed-off-by: Bruno Eduardo de Oliveira Meneguele <bmeneguele@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:51:52 +01:00
Brendan Le Foll
88d878648b beaglebone.c: Remove unused variables
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:51:07 +01:00
Alexandru Timohi
828338a69a libmraa: Fix compilation warnings about unsigned ints
Make better use of unsigned/signed ints, signed ints are preffered unless there
is a good reason not to.

Signed-off-by: Alexandru Timohi <alexandru.timohi@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 11:50:33 +01:00
Brendan Le Foll
022b36355f x86: Fix capabilities being initialised with only 7 bits
This whilst ugly should not cause an issue because of our use of calloc.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-19 10:23:10 +01:00
Brendan Le Foll
3969af2b24 iio.c: Fix the location mapping in iio
Go through channel array after getting byte mapping to correctly map channel
location. Doing it at the same time as mapping the indexes is unreliable
depending on filename etc...

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 12:31:47 +01:00
Stefan Andritoiu
b15ab84f61 README.md: Added java bindings to README
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 09:05:39 +01:00
Michael Kellner
d3a220479d beaglebone.c: fix beaglebone i2c bus 2 not existing
Signed-off-by: Michael Kellner mkellner@intlweb.com
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 09:02:21 +01:00
Noel Eck
905abdec7c travis-ci: Updates to ensure MRAA builds with clang.
The MRAA clang build was getting overridden with gcc.
This commit allows MRAA to build with clang and adds nodejs
0.10 to the build matrix.  Note, this means 8 builds
(2 compilers x 4 versions of nodejs).

    * Added compiler directive for clang/gcc.

    * Added build for node010.

    * Added make install to cover the MRAA install.

Signed-off-by: Noel Eck <noel.eck@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-16 08:59:19 +01:00
Brendan Le Foll
db546456d2 building.md: Fix typos in INSTALL_PREFIX
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 17:26:02 +01:00
Jon Trulson
f6d9cf57c9 uart_ow: add ow specific context and store search state there
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:50:02 +01:00
Mihai Tudor Panu
a702cdf4d5 ft4222: fixed pca9555 expander detection
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:48:40 +01:00
Evgen48
800c89bfa4 examples/java: input pin number should be parsed in base 10, not in base 8, similar to c++ sample
Signed-off-by: Eugene Smirnov <o1o2o3o4o5@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-05-04 09:46:16 +01:00
Brendan Le Foll
887acf54e1 mraa: Update to v1.0.0
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-28 15:59:40 +01:00
Brendan Le Foll
3a88c44620 i2c.c: rollback change to mraa_i2c_init that stopped default bus being used
Partly rollsback f2c4d95c15 which stopped
mraa_i2c_init from switching i2c bus silently. If you don't want this to
happen, you need to use mraa_i2c_init_raw. Closes #497.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-26 10:59:59 +01:00
Brendan Le Foll
5e867419bc spi.hpp: rename Spi::write_word to Spi::WriteWord
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:38:21 +01:00
Brendan Le Foll
4195a61e52 pwm: remove pwm config_* apis as unused
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:37:50 +01:00
Brendan Le Foll
c524c3d372 spi: mraa_spi_write_word can now return -1 in error cases
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 15:11:08 +01:00
Brendan Le Foll
b258867c37 aio.c: pass channel to mraa_aio_init_internal
This fixes previous broken commit because dev is not defined before
_internal_init but since fp is taken during internal init we need to know the
channel number. This does not affect the internal override API.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 12:17:32 +01:00
Brendan Le Foll
56e45f6de5 aio.c: Set channel number before grabbing filepointer
Fixes #495

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 11:53:49 +01:00
Robert Chiras
cdfdd2b9e3 Add support for android build
Using NPM, this module can be cross-compiled for Android using NDK.
But, when compiling for Android, we need to add glob.c to source files
(as in Android.mk).
Also, re-arranged the layout in binding.gyp for better readability.

Signed-off-by: Robert Chiras <robert.chiras@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-25 11:48:38 +01:00
Brendan Le Foll
c1465bd694 i2c: Make i2c advance function match new prototypes
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:59:17 +01:00
Brendan Le Foll
1e4516d026 i2c: Add exceptions for C++ i2c errors
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:58:57 +01:00
Brendan Le Foll
0b74aa68ab aio: Change mraa_aio_read to use int and return -1
This commit changes also the _replace function and adds exceptions to the C++
API for errors in AIO read

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 11:57:26 +01:00
Brendan Le Foll
e961558fd2 mraa: add mraa_remove_subplatform call
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-22 09:38:30 +01:00
Eugene Bolshakov
6d8ec87e0e edison: change pin initialization by adding pin commands
Pullup/pulldown resistors are disabled during GPIO initialization.

Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-19 18:39:11 +01:00
Brendan Le Foll
acf90073a8 types: Remove MRAA_ERROR_PLATFORM_ALREADY_INITIALISED
Enum was deprecated in 0.10.x and causes issues with strict C89 compliance so
is now removed

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:51:44 +01:00
wda2945
2404b0a683 pwm.c: Improve pwm error handling
Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
0da3d35a8f i2c.c: Fix typo in syslog message
Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
1ebe377487 uart.c: Improve error handling
Changed syslog messages and some error returns.

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 14:02:02 +01:00
wda2945
e757844a3d gpio.c: Improve gpio error handling
Changed syslog messages and some error returns.

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 13:46:25 +01:00
wda2945
f2c4d95c15 i2c: Improve i2c Error Handling
Edited syslog messages. Changed some return types to used signed and using -1
to indicate errors

Signed-off-by: Martin G Lane-Smith <mlanesmith@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 13:46:25 +01:00
Brendan Le Foll
c41c3b41d5 uart_ow: Better error handling in corner cases
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-15 12:03:32 +01:00
Brendan Le Foll
4a52ad6c4f uart_ow: Make onewire functionality optional but on by default
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-14 13:52:09 +01:00
Jon Trulson
a379eb7bf6 uart_ow: Initial support for Dallas 1-wire over UART support for MRAA
This commit introduces support for Dallas Semiconductor (DS) 1-wire
compliant device support using an available UART device.

The principle of operation is described in the following Application
note by Maxim Electronics:

https://www.maximintegrated.com/en/app-notes/index.mvp/id/214

with help (1-wire search) from:
https://www.maximintegrated.com/en/app-notes/index.mvp/id/187

It has been tested on Galileo 2 and Edison, with 2 DS 1-wire devices,
the DS18B20 and DS2413 connected to the bus.  A UPM driver for the
DS2413 is already complete and a PR will be submitted after this one.

It is important that you use a UART with CMOS/TTL level voltages
(3.3v/5v) RX and TX lines.  DO NOT use standard RS232 level voltages
or you are going to have a bad day.

In order for this to work, a simple interface circuit, using a single
diode must be constructed:

(forgive my "Asciihematic" :)

-|
U|
A| TX---|<--+
R|          |
T| RX-------o--------o 1-wire data bus
-|

The diode on TX is a 1N4148 (cheap and common), with the cathode
connected to TX, and the anode connected to RX and the 1-wire data
line.

The 1-wire data line requires a pull-up resistor, as the DS 1-wire
spec requires. 4.7-5K is typical for DS 1-wire buses.

NOTE: DHT-type (temp/humidity sensor) 1-wire devices ARE NOT DS 1-wire
compliant, and will not work with this code/circuit unfortunately.

Also note, this will use up one of your UARTs, which cannot be used
for any other purpose (ie: to access true UART-type serial devices).

You can however, connect as many DS 1-wire devices as feasible to this
UART, as it will function as a DS 1-wire bus master.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-14 13:41:31 +01:00
Noel Eck
69d9c26e6e pkg_config: Update mraa.pc.cmake to use new install dir
LIB_SUFFIX is no longer used.  Replaced with LIB_INSTALL_DIR
which provides the correct lib dir with arch suffix.

Moved the call to include(GNUInstallDirs) prior to checking the
CMAKE_INSTALL_LIBDIR - which is set by include(GNUInstallDirs).

Tested with cmake 2.8 and cmake 3.5.

Signed-off-by: Noel Eck <noel.eck@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-12 14:18:19 +01:00
Mihai Tudor Panu
62e113ed3f cmake: use LIB_INSTALL_DIR throughout instead of CMAKE_INSTALL_LIBDIR
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-12 14:18:19 +01:00
Alex Tereschenko
00a0abd030 isr.js: updated JS ISR example to avoid GPIO context being destroyed
Closes #403.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:28:22 +01:00
Alex Tereschenko
ecf049eccd spi.c: removed hard frequency cap in mraa_spi_init_raw()
We rely on driver-supplied information in mraa_spi_frequency(),
so let's be consistent.

Closes #132.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:27:34 +01:00
Fathi Boudra
e1c500414b docs: fix spelling errors
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-04-11 15:13:06 +01:00
142 changed files with 8071 additions and 1188 deletions

View File

@@ -1,32 +1,55 @@
language: cpp
sudo: required
dist: trusty
env:
- CC=gcc CXX=gcc
- CC=clang CXX=clang++
- NODE010=true
- NODE012=true
- NODE4=true
- NODE5=true
- NODE012=true
- JSONPLAT=true NODE010=true
- JSONPLAT=true NODE012=true
- JSONPLAT=true NODE4=true
- JSONPLAT=true NODE5=true
# node010 npm builds don't work in clang and anyone using npm should want to
# use something newer
- NPM=true NODE4=true
- NPM=true NODE5=true
compiler:
- clang
- gcc
before_install:
# Via https://github.com/travis-ci/travis-ci/issues/5326
- export PATH="$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")"
install:
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
- sudo add-apt-repository --yes ppa:kalakris/cmake
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
- sudo apt-get update -qq
- sudo apt-get install -y -qq swig3.0 python git cmake
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
- sudo update-java-alternatives -s java-8-oracle
before_script:
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
- if [ "${JSONPLAT}" ]; then export JSONPLAT=ON; else export JSONPLAT=OFF; fi
- if [ "${NODE010}" ]; then nvm install 0.10; fi
- if [ "${NODE012}" ]; then nvm install 0.12; fi
- if [ "${NODE4}" ]; then nvm install 4.1; fi
- if [ "${NODE5}" ]; then nvm install 5; fi
- npm install node-gyp && export NODE_GYP="/home/travis/build/intel-iot-devkit/mraa/node_modules/node-gyp/bin/node-gyp.js"
# Handle 0.10 NODE_ROOT_DIR differently than other versions
- wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && ./configure --prefix=/home/travis/ && make && make install && cd ..
script:
- mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" .. && make && make test
- echo "CC=$CC BUILDJAVA=$BUILDJAVA JSONPLAT=$JSONPLAT NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
- if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi
# simple test to see if we can load our node module
- if [ ${NPM} ]; then cd build/Release/obj.target/ && node -e "var m = require('./mraa.node'); m.getVersion()";fi
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
- kalakris-cmake
packages:
- clang-3.6
- g++-4.8
- cmake
- python
- python-dev
- python3
- python3-dev
- git
- libjson0
- libjson0-dev

View File

@@ -37,7 +37,8 @@ LOCAL_SRC_FILES := \
src/x86/intel_sofia_3gr.c \
src/x86/intel_minnow_byt_compatible.c \
src/x86/intel_cherryhills.c \
src/x86/up.c
src/x86/up.c \
src/x86/intel_gt_tuchuck.c
# glob.c pulled in from NetBSD project (BSD 3-clause License)
LOCAL_SRC_FILES += \

View File

@@ -5,11 +5,17 @@ FIND_PACKAGE (Threads REQUIRED)
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer ")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
# Set CMAKE_LIB_INSTALL_DIR if not defined
# Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)
# Older cmake might not pick CMAKE_INSTALL_LIBDIR right
if (CMAKE_INSTALL_LIBDIR)
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
else ()
set (LIB_INSTALL_DIR "lib" CACHE PATH "Installation path for libraries")
endif ()
# By default, build shared object libraries on linux
if (UNIX AND NOT APPLE)
if (NOT DEFINED BUILD_SHARED_LIBS)
@@ -25,7 +31,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 "v0.10.1-dirty")
set (VERSION "v1.2.3-dirty")
endif ()
message (STATUS "INFO - libmraa Version ${VERSION}")
@@ -64,18 +70,20 @@ option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDSWIGJAVA "Build Java API." OFF)
option (USBPLAT "Detection USB platform." OFF)
option (FIRMATA "Add Firmata support to mraa." OFF)
option (ONEWIRE "Add Onewire support to mraa." ON)
option (JSONPLAT "Add Platform loading via a json file." ON)
option (IMRAA "Add Imraa support to mraa." OFF)
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (ENABLEEXAMPLES "Disable building of examples" ON)
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
option (INSTALLTOOLS "Install all tools" OFF)
option (BUILDARCH "Override architecture to build for - override" OFF)
option (BUILDTESTS "Override the addition of tests" ON)
set (MRAAPLATFORMFORCE "" CACHE STRING "ALL")
set (BUILDARCH "" CACHE STRING "Override architecture to build for")
set (MRAAPLATFORMFORCE "ALL" CACHE STRING "Override platform to build for")
if (NOT BUILDSWIG)
set (BUILDSWIGPYTHON OFF)
@@ -97,17 +105,14 @@ if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
set (X86PLAT ON)
elseif (DETECTED_ARCH MATCHES "arm.*")
set (ARMPLAT ON)
elseif (DETECTED_ARCH STREQUAL "MOCK")
set (MOCKPLAT ON)
else ()
message (FATAL_ERROR "Only x86 and arm platforms currently supported")
message (FATAL_ERROR "Only x86, arm and mock platforms currently supported")
endif()
if (BUILDSWIGPYTHON OR BUILDTESTS)
if (BUILDPYTHON3)
set (PYTHONBUILD_VERSION 3)
else ()
set (PYTHONBUILD_VERSION 2.7)
endif ()
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
include (cmake/modules/OpenCVDetectPython.cmake)
endif ()
if (BUILDDOC)
@@ -195,9 +200,7 @@ if (IMRAA)
add_subdirectory (imraa)
endif ()
if (BUILDTESTS)
if (${PYTHONINTERP_FOUND})
enable_testing ()
add_subdirectory (tests)
endif ()
if (BUILDTESTS AND PYTHON_DEFAULT_EXECUTABLE)
enable_testing ()
add_subdirectory (tests)
endif ()

View File

@@ -4,10 +4,10 @@
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
==============
Libmraa is a C/C++ library with bindings to javascript & python to interface
with the IO on Galileo, Edison & other platforms, with a structured and sane
API where port names/numbering matches the board that you are on. Use of
libmraa does not tie you to specific hardware with board detection done at
Libmraa is a C/C++ library with bindings to Java, Python and JavaScript to
interface with the IO on Galileo, Edison & other platforms, with a structured
and sane API where port names/numbering matches the board that you are on. Use
of libmraa does not tie you to specific hardware with board detection done at
runtime you can create portable code that will work across the supported
platforms.
@@ -15,6 +15,8 @@ The intent is to make it easier for developers and sensor manufacturers to map
their sensors & actuators on top of supported hardware and to allow control of
low level communication protocol by high level languages & constructs.
[![Build Status](https://travis-ci.org/intel-iot-devkit/mraa.svg?branch=master)](https://travis-ci.org/intel-iot-devkit/mraa)
Supported Boards
================
@@ -27,6 +29,7 @@ X86
* [Minnowboard Max](../master/docs/minnow_max.md)
* [NUC 5th generation](../master/docs/intel_nuc5.md)
* [UP](../master/docs/up.md)
* [Intel Grosse Tete](../master/docs/grossetete.md)
ARM
---
@@ -38,6 +41,10 @@ USB
---
* [FT4222](../master/docs/ftdi_ft4222.md)
Mock
----
* [Generic simulated board](../master/docs/mock.md)
Installing on your board
========

View File

@@ -33,6 +33,7 @@ extern "C" {
#include "mraa/spi.h"
#include "mraa/i2c.h"
#include "mraa/uart.h"
#include "mraa/uart_ow.h"
#ifdef __cplusplus
}

View File

@@ -59,19 +59,20 @@ typedef struct _aio* mraa_aio_context;
mraa_aio_context mraa_aio_init(unsigned int pin);
/**
* Read the input voltage. By default mraa will shift
* the raw value up or down to a 10 bit value.
* Read the input voltage. By default mraa will shift the raw value up or down
* to a 10 bit value.
*
* @param dev The AIO context
* @returns The current input voltage.
* @returns The current input voltage or -1 for error
*/
unsigned int mraa_aio_read(mraa_aio_context dev);
int mraa_aio_read(mraa_aio_context dev);
/**
* Read the input voltage and return it as a normalized float (0.0f-1.0f).
*
* @param dev The AIO context
* @returns The current input voltage as a normalized float (0.0f-1.0f)
* @returns The current input voltage as a normalized float (0.0f-1.0f), error
* will be signaled by -1.0f
*/
float mraa_aio_read_float(mraa_aio_context dev);

View File

@@ -47,13 +47,26 @@ class Aio
*
* @param pin channel number to read ADC inputs
*/
Aio(unsigned int pin)
Aio(int pin)
{
m_aio = mraa_aio_init(pin);
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
}
}
/**
* Aio Constructor, takes a pointer to the AIO context and initialises
* the AIO class
*
* @param void * to an AIO context
*/
Aio(void* aio_context)
{
m_aio = (mraa_aio_context) aio_context;
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO context");
}
}
/**
* Aio destructor
*/
@@ -65,22 +78,32 @@ class Aio
* Read a value from the AIO pin. By default mraa will shift
* the raw value up or down to a 10 bit value.
*
* @throws std::invalid_argument in case of error
* @returns The current input voltage. By default, a 10bit value
*/
int
unsigned int
read()
{
return mraa_aio_read(m_aio);
int x = mraa_aio_read(m_aio);
if (x == -1) {
throw std::invalid_argument("Unknown error in Aio::read()");
}
return (unsigned int) x;
}
/**
* Read a value from the AIO pin and return it as a normalized float.
*
* @throws std::invalid_argument in case of error
* @returns The current input voltage as a normalized float (0.0f-1.0f)
*/
float
readFloat()
{
return mraa_aio_read_float(m_aio);
float x = mraa_aio_read_float(m_aio);
if (x == -1.0f) {
throw std::invalid_argument("Unknown error in Aio::readFloat()");
}
return x;
}
/**
* Set the bit value which mraa will shift the raw reading

View File

@@ -44,6 +44,7 @@
if (res != MRAA_SUCCESS) \
return res;} while(0)
/** @file
*
* This file defines the basic shared values for libmraa
@@ -159,7 +160,7 @@ const char* mraa_get_platform_version(int platform_offset);
* @param priority Value from typically 0 to 99
* @return The priority value set
*/
int mraa_set_priority(const unsigned int priority);
int mraa_set_priority(const int priority);
/** Get the version string of mraa autogenerated from git tag
*
@@ -214,7 +215,7 @@ int mraa_get_i2c_bus_count();
* @param i2c_bus the logical I2C bus number
* @return I2C adapter number in sysfs. Function will return -1 on failure
*/
int mraa_get_i2c_bus_id(unsigned int i2c_bus);
int mraa_get_i2c_bus_id(int i2c_bus);
/**
* Get specified platform pincount, board must be initialised.
@@ -284,6 +285,38 @@ int mraa_get_sub_platform_index(int pin_or_bus_id);
*/
mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev);
/**
* Remove a mraa subplatform
*
* @param subplatform type
*
* @return mraa_result indicating success
*/
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype);
/**
* Create IO using a description in the format:
* [io]-[pin]
* [io]-[raw]-[pin]
* [io]-[raw]-[id]-[pin]
* [io]-[raw]-[path]
*
* @param IO description
*
* @return void* to IO context or NULL
*/
void* mraa_init_io(const char* desc);
/**
* Instantiate an unknown board using a json file
*
* @param Path to the json file, relative to the folder the program
* was initially run in or a direct path
*
* @return mraa_result indicating success
*/
mraa_result_t mraa_init_json_platform(const char* path);
#ifdef __cplusplus
}
#endif

View File

@@ -78,7 +78,7 @@ getVersion()
* @return The priority value set
*/
inline int
setPriority(const unsigned int priority)
setPriority(const int priority)
{
return mraa_set_priority(priority);
}
@@ -195,7 +195,7 @@ getI2cBusCount()
* @return I2C adapter number in sysfs. Function will return -1 on failure
*/
inline int
getI2cBusId(unsigned int i2c_bus)
getI2cBusId(int i2c_bus)
{
return mraa_get_i2c_bus_id(i2c_bus);
}
@@ -303,4 +303,42 @@ addSubplatform(Platform subplatformtype, std::string uart_dev)
return (Result) mraa_add_subplatform((mraa_platform_t) subplatformtype, uart_dev.c_str());
}
inline Result
removeSubplatform(Platform subplatformtype)
{
return (Result) mraa_remove_subplatform((mraa_platform_t) subplatformtype);
}
/**
* Create IO using a description in the format:
* [io]-[pin]
* [io]-[raw]-[pin]
* [io]-[raw]-[id]-[pin]
* [io]-[raw]-[path]
*
* @param IO description
*
* @return class T initialised using pointer to IO or NULL
*/
template <class T>
inline T*
initIo(std::string desc)
{
return new T(mraa_init_io(desc.c_str()));
}
/**
* Instantiate an unknown board using a json file
*
* @param Path to the json file, relative to the folder the program
* was initially run in or a direct path
*
* @return Result indicating success
*/
inline Result
initJsonPlatform(std::string path)
{
return (Result) mraa_init_json_platform(path.c_str());
}
}

View File

@@ -71,7 +71,7 @@ mraa_result_t mraa_firmata_write_sysex(mraa_firmata_context dev, char* msg, int
* calling it need to make sure they are the only thread calling this.
*
* @param dev The Firmata context
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered, the returned buffer and length are the arguments.
* @return Result of operation
*/

View File

@@ -77,13 +77,13 @@ typedef enum {
} mraa_gpio_dir_t;
/**
* Gpio Edge types for interupts
* Gpio Edge types for interrupts
*/
typedef enum {
MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interrupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interrupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interrupt on falling only */
} mraa_gpio_edge_t;
/**
@@ -112,11 +112,11 @@ mraa_gpio_context mraa_gpio_init_raw(int gpiopin);
mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
/**
* Set an interupt on pin
* Set an interrupt on pin
*
* @param dev The Gpio context
* @param edge The edge mode to set the gpio into
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
@@ -124,7 +124,7 @@ mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (*fptr)(void*), void* args);
/**
* Stop the current interupt watcher on this Gpio, and set the Gpio edge mode
* Stop the current interrupt watcher on this Gpio, and set the Gpio edge mode
* to MRAA_GPIO_EDGE_NONE
*
* @param dev The Gpio context

View File

@@ -60,13 +60,13 @@ typedef enum {
} Dir;
/**
* Gpio Edge types for interupts
* Gpio Edge types for interrupts
*/
typedef enum {
EDGE_NONE = 0, /**< No interrupt on Gpio */
EDGE_BOTH = 1, /**< Interupt on rising & falling */
EDGE_RISING = 2, /**< Interupt on rising only */
EDGE_FALLING = 3 /**< Interupt on falling only */
EDGE_BOTH = 1, /**< Interrupt on rising & falling */
EDGE_RISING = 2, /**< Interrupt on rising only */
EDGE_FALLING = 3 /**< Interrupt on falling only */
} Edge;
/**
@@ -80,7 +80,7 @@ class Gpio
{
public:
/**
* Instanciates a Gpio object
* Instantiates a Gpio object
*
* @param pin pin number to use
* @param owner (optional) Set pin owner, default behaviour is to 'own'
@@ -107,6 +107,19 @@ class Gpio
mraa_gpio_owner(m_gpio, 0);
}
}
/**
* Gpio Constructor, takes a pointer to the GPIO context and initialises
* the GPIO class
*
* @param void * to GPIO context
*/
Gpio(void* gpio_context)
{
m_gpio = (mraa_gpio_context) gpio_context;
if (m_gpio == NULL) {
throw std::invalid_argument("Invalid GPIO context");
}
}
/**
* Gpio object destructor, this will only unexport the gpio if we where
* the owner
@@ -186,7 +199,7 @@ class Gpio
* Sets a callback to be called when pin value changes
*
* @param mode The edge mode to set
* @param fptr Function pointer to function to be called when interupt is
* @param fptr Function pointer to function to be called when interrupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
@@ -198,7 +211,7 @@ class Gpio
}
/**
* Exits callback - this call will not kill the isr thread immediatly
* Exits callback - this call will not kill the isr thread immediately
* but only when it is out of it's critical section
*
* @return Result of operation

View File

@@ -78,42 +78,40 @@ mraa_i2c_context mraa_i2c_init_raw(unsigned int bus);
mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode);
/**
* Simple bulk read from an i2c context, this will always begin with the i2c
* offset 0x0
* Simple bulk read from an i2c context
*
* @param dev The i2c context
* @param data pointer to the byte array to read data in to
* @param length max number of bytes to read
* @return length of the read in bytes or 0
* @return length of the read in bytes or -1
*/
int mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length);
/**
* Simple read for a single byte from the i2c context, this will always begin
* with the i2c offset 0x0
* Simple read for a single byte from the i2c context
*
* @param dev The i2c context
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
int mraa_i2c_read_byte(mraa_i2c_context dev);
/**
* Read a single byte from i2c context, from designated register
*
* @param dev The i2c context
* @param command The register
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
int mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
/**
* Read a single word from i2c context, from designated register
*
* @param dev The i2c context
* @param command The register
* @return The result of the read and 0 if failed
* @return The result of the read or -1 if failed
*/
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
int mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
/**
* Bulk read from i2c context, starting from designated register
@@ -138,7 +136,7 @@ int mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* dat
mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length);
/**
* Write a single byte to an i2c context, always at offset 0x0
* Write a single byte to an i2c context
*
* @param dev The i2c context
* @param data The byte to write
@@ -167,12 +165,10 @@ mraa_result_t mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data,
mraa_result_t mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
/**
* Sets the i2c context address.
* Sets the i2c slave address.
*
* @param dev The i2c context
* @param address The address to set for the slave (ignoring the least
* signifcant bit). If set to 0, the slave will only respond to the
* general call address.
* @param address The address to set for the slave (7-bit address)
* @return Result of operation
*/
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, uint8_t address);

View File

@@ -62,6 +62,18 @@ class I2c
throw std::invalid_argument("Invalid i2c bus");
}
}
/**
* I2C constructor, takes a pointer to a I2C context and initialises the I2C class
*
* @param void * to an I2C context
*/
I2c(void* i2c_context)
{
m_i2c = (mraa_i2c_context) i2c_context;
if (m_i2c == NULL) {
throw std::invalid_argument("Invalid I2C context");
}
}
/**
* Closes the I2c Bus used. This does not guarrantee the bus will not
@@ -103,12 +115,17 @@ class I2c
/**
* Read exactly one byte from the bus
*
* @throws std::invalid_argument in case of error
* @return char read from the bus
*/
uint8_t
readByte()
{
return (uint8_t) mraa_i2c_read_byte(m_i2c);
int x = mraa_i2c_read_byte(m_i2c);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readByte()");
}
return (uint8_t) x;
}
/**
@@ -128,24 +145,36 @@ class I2c
* Read byte from an i2c register
*
* @param reg Register to read from
*
* @throws std::invalid_argument in case of error
* @return char read from register
*/
uint8_t
readReg(uint8_t reg)
{
return mraa_i2c_read_byte_data(m_i2c, reg);
int x = mraa_i2c_read_byte_data(m_i2c, reg);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readReg()");
}
return (uint8_t) x;
}
/**
* Read word from an i2c register
*
* @param reg Register to read from
*
* @throws std::invalid_argument in case of error
* @return char read from register
*/
uint16_t
readWordReg(uint8_t reg)
{
return mraa_i2c_read_word_data(m_i2c, reg);
int x = mraa_i2c_read_word_data(m_i2c, reg);
if (x == -1) {
throw std::invalid_argument("Unknown error in I2c::readReg()");
}
return (uint16_t) x;
}
/**

View File

@@ -121,7 +121,7 @@ mraa_result_t mraa_iio_event_extract_event(struct iio_event_data* event,
int* channel2,
int* different);
mraa_result_t mraa_iio_get_mounting_matrix(mraa_iio_context dev, float mm[9]);
mraa_result_t mraa_iio_get_mount_matrix(mraa_iio_context dev, const char *sysfs_name, float mm[9]);
mraa_result_t mraa_iio_create_trigger(mraa_iio_context dev, const char* trigger);

View File

@@ -106,7 +106,12 @@ enum iio_event_direction {
};
//linux/iio/events.h
#if defined(MSYS)
#define __USE_LINUX_IOCTL_DEFS
#include <sys/ioctl.h>
#else
#include <linux/ioctl.h>
#endif
/**
* struct iio_event_data - The actual event being pushed to userspace

View File

@@ -65,7 +65,7 @@ mraa_pwm_context mraa_pwm_init(int pin);
mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
/**
* Set the ouput duty-cycle percentage, as a float
* Set the output duty-cycle percentage, as a float
*
* @param dev The Pwm context to use
* @param percentage A floating-point value representing percentage of output.
@@ -76,7 +76,7 @@ mraa_pwm_context mraa_pwm_init_raw(int chipid, int pin);
mraa_result_t mraa_pwm_write(mraa_pwm_context dev, float percentage);
/**
* Read the ouput duty-cycle percentage, as a float
* Read the output duty-cycle percentage, as a float
*
* @param dev The Pwm context to use
* @return percentage A floating-point value representing percentage of output.
@@ -166,26 +166,6 @@ mraa_result_t mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner);
*/
mraa_result_t mraa_pwm_close(mraa_pwm_context dev);
/**
* Set Both Period and DutyCycle on a PWM context
*
* @param dev The pwm context to use
* @param period represented in ms.
* @param duty dutycycle of the pwm signal.
* @return Result of operation
*/
mraa_result_t mraa_pwm_config_ms(mraa_pwm_context dev, int period, float duty);
/**
* Set Both Period and DutyCycle on a PWM context. Duty represented as percentage.
*
* @param dev The pwm context to use
* @param period represented in ms.
* @param duty duty percantage. i.e. 50% = 0.5f
* @return Result of operation
*/
mraa_result_t mraa_pwm_config_percent(mraa_pwm_context dev, int period, float duty);
/**
* Get the maximum pwm period in us
*

View File

@@ -46,9 +46,9 @@ class Pwm
*
* @param pin the pin number used on your board
* @param owner if you are the owner of the pin the destructor will
* @param chipid the pwmchip to use, use only in raw mode
* unexport the pin from sysfs, default behaviour is you are the owner
* if the pinmapper exported it
* @param chipid the pwmchip to use, use only in raw mode
*/
Pwm(int pin, bool owner = true, int chipid = -1)
{
@@ -66,6 +66,20 @@ class Pwm
mraa_pwm_owner(m_pwm, 0);
}
}
/**
* Pwm constructor, takes a pointer to the PWM context and
* initialises the class
*
* @param void * to a PWM context
*/
Pwm(void* pwm_context)
{
m_pwm = (mraa_pwm_context) pwm_context;
if (m_pwm == NULL) {
throw std::invalid_argument("Invalid PWM context");
}
}
/**
* Pwm destructor
*/
@@ -77,7 +91,7 @@ class Pwm
* Set the output duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* output. The value should lie between 0.0f (representing 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
* @return Result of operation
@@ -88,10 +102,10 @@ class Pwm
return (Result) mraa_pwm_write(m_pwm, percentage);
}
/**
* Read the ouput duty-cycle percentage, as a float
* Read the output duty-cycle percentage, as a float
*
* @return A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* output. The value should lie between 0.0f (representing 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
*/
@@ -134,7 +148,7 @@ class Pwm
return (Result) mraa_pwm_period_us(m_pwm, us);
}
/**
* Set pulsewidth, As represnted by seconds in a (float)
* Set pulsewidth, as represented by seconds in a float
*
* @param seconds The duration of a pulse
* @return Result of operation
@@ -179,33 +193,9 @@ class Pwm
return (Result) mraa_pwm_enable(m_pwm, enable);
}
/**
* Set the period and duty of a PWM object.
* Get the maximum PWM period in us
*
* @param period represented in ms.
* @param duty represnted in ms as float.
* @return Result of operation
*/
Result
config_ms(int period, float duty)
{
return (Result) mraa_pwm_config_ms(m_pwm, period, duty);
}
/**
* Set the period and duty (percent) of a PWM object.
*
* @param period as represented in ms.
* @param duty percentage i.e. 50% = 0.5f
* @return Result of operation
*/
Result
config_percent(int period, float duty)
{
return (Result) mraa_pwm_config_percent(m_pwm, period, duty);
}
/**
* Get the maximum pwm period in us
*
* @return max pwm in us
* @return max PWM period in us
*/
int
max_period()
@@ -213,9 +203,9 @@ class Pwm
return mraa_pwm_get_max_period(m_pwm);
}
/**
* Get the minimum pwm period in us
* Get the minimum PWM period in us
*
* @return min pwm in us
* @return min PWM period in us
*/
int
min_period()

View File

@@ -111,13 +111,13 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
int mraa_spi_write(mraa_spi_context dev, uint8_t data);
/**
*Write Two Bytes to the SPI device.
* Write Two Bytes to the SPI device.
*
* @param dev The Spi context
* @param data Data to send
* @return Data received on the miso line
*/
uint16_t mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
int mraa_spi_write_word(mraa_spi_context dev, uint16_t data);
/**
* Write Buffer of bytes to the SPI device. The pointer return has to be

View File

@@ -79,6 +79,20 @@ class Spi
}
}
/**
* Spi Constructor, takes a pointer to a SPI context and initialises
* the SPI class
*
* @param void * to SPI context
*/
Spi(void* spi_context)
{
m_spi = (mraa_spi_context) spi_context;
if (m_spi == NULL) {
throw std::invalid_argument("Invalid SPI context");
}
}
/**
* Closes spi bus
*/
@@ -127,10 +141,10 @@ class Spi
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line
* @return data received on the miso line or -1 in case of error
*/
uint16_t
write_word(uint16_t data)
int
writeWord(uint16_t data)
{
return mraa_spi_write_word(m_spi, (uint16_t) data);
}
@@ -161,7 +175,7 @@ class Spi
* @return uint8_t* data received on the miso line. Same length as passed in
*/
uint16_t*
write_word(uint16_t* txBuf, int length)
writeWord(uint16_t* txBuf, int length)
{
return mraa_spi_write_buf_word(m_spi, txBuf, length);
}

View File

@@ -50,6 +50,7 @@ typedef enum {
MRAA_INTEL_SOFIA_3GR = 10, /**< The Intel SoFIA 3GR */
MRAA_INTEL_CHERRYHILLS = 11, /**< The Intel Braswell Cherryhills */
MRAA_UP = 12, /**< The UP Board */
MRAA_INTEL_GT_TUCHUCK = 13, /**< The Intel GT Tuchuck Board */
// USB platform extenders start at 256
MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
@@ -57,6 +58,8 @@ typedef enum {
// contains bit 9 so is subplatform
MRAA_GENERIC_FIRMATA = 1280, /**< Firmata uart platform/bridge */
MRAA_MOCK_PLATFORM = 96, /**< Mock platform, which requires no real hardware */
MRAA_JSON_PLATFORM = 97, /**< User initialised platform from json*/
MRAA_NULL_PLATFORM = 98, /**< Platform with no capabilities that hosts a sub platform */
MRAA_UNKNOWN_PLATFORM =
99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
@@ -206,7 +209,9 @@ typedef enum {
MRAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
MRAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
MRAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
MRAA_ERROR_PLATFORM_ALREADY_INITIALISED = 0, /**< Board is already initialised, same as MRAA_SUCESS */
MRAA_ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
MRAA_ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
MRAA_ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
MRAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} mraa_result_t;

View File

@@ -50,6 +50,8 @@ typedef enum {
A96BOARDS = 9, /**< Linaro 96boards, A prefix for 'ARM' since not allowed numerical */
INTEL_SOFIA_3GR = 10, /**< The Intel SoFIA 3GR */
INTEL_CHERRYHILLS = 11, /**< The Intel Braswell Cherryhills */
INTEL_UP = 12, /**< The UP Board */
INTEL_GT_TUCHUCK = 13, /**< The Intel GT Board */
FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
@@ -204,7 +206,9 @@ typedef enum {
ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
ERROR_PLATFORM_ALREADY_INITIALISED = 0, /**< Board is already initialised, same as SUCCESS */
ERROR_UART_OW_SHORTED = 12, /**< UART OW Short Circuit Detected*/
ERROR_UART_OW_NO_DEVICES = 13, /**< UART OW No devices detected */
ERROR_UART_OW_DATA_ERROR = 14, /**< UART OW Data/Bus error detected */
ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} Result;

View File

@@ -75,6 +75,20 @@ class Uart
}
}
/**
* Uart Constructor, takes a pointer to the UART context and initialises
* the UART class
*
* @param void * to a UART context
*/
Uart(void* uart_context)
{
m_uart = (mraa_uart_context) uart_context;
if (m_uart == NULL) {
throw std::invalid_argument("Invalid UART context");
}
}
/**
* Uart destructor
*/

197
api/mraa/uart_ow.h Normal file
View File

@@ -0,0 +1,197 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
/**
* @file
* @brief UART OW module
*
* This module allows one to use MRAA's UART support in order to
* interact with Dallas 1-wire compliant devices on a 1-wire bus. It
* makes use of the UART for timing purposes. The principle of
* operation is described here:
* https://www.maximintegrated.com/en/app-notes/index.mvp/id/214
*
* It is important the you use a UART with CMOS/TTL level voltages
* (3.3v/5v) RX and TX lines. DO NOT use standard RS232 level
* voltages, or you are going to have a bad day.
*
* In addition, a diode should be placed across the RX and
* TX lines like so:
*
* -|
* U|
* A| TX---|<--+
* R| |
* T| RX-------o--------o 1-wire data bus
* -|
*
* The diode on TX is a 1N4148 (cheap and common), with the cathode
* connected to TX, and the anode connected to RX and the rest of the
* 1-wire data line.
*
* @snippet uart_ow.c Interesting
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "common.h"
#include "uart.h"
/* for now, we simply use the normal MRAA UART context */
typedef struct _mraa_uart_ow {
mraa_uart_context uart;
/* search state */
unsigned char ROM_NO[8]; /* 8 byte (64b) rom code */
int LastDiscrepancy;
int LastFamilyDiscrepancy;
mraa_boolean_t LastDeviceFlag;
} *mraa_uart_ow_context;
/* 8 bytes (64 bits) for a device rom code */
static const int MRAA_UART_OW_ROMCODE_SIZE = 8;
/**
* UART One Wire ROM related Command bytes
*/
typedef enum {
MRAA_UART_OW_CMD_READ_ROM = 0x33, /**< read rom, when only one device on bus */
MRAA_UART_OW_CMD_MATCH_ROM = 0x55, /**< match a specific rom code */
MRAA_UART_OW_CMD_SKIP_ROM = 0xcc, /**< skip match/search rom */
MRAA_UART_OW_CMD_SEARCH_ROM_ALARM = 0xec, /**< search all roms in alarm state */
MRAA_UART_OW_CMD_SEARCH_ROM = 0xf0 /**< search all rom codes */
} mraa_uart_ow_rom_cmd_t;
/**
* Initialise uart_ow_context, uses UART board mapping
*
* @param uart the index of the uart set to use
* @return uart_ow context or NULL
*/
mraa_uart_ow_context mraa_uart_ow_init(int uart);
/**
* Initialise a raw uart_ow_context. No board setup.
*
* @param path for example "/dev/ttyS0"
* @return uart_ow context or NULL
*/
mraa_uart_ow_context mraa_uart_ow_init_raw(const char* path);
/**
* Get char pointer with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @param dev uart_ow context
* @return char pointer of device path
*/
const char* mraa_uart_ow_get_dev_path(mraa_uart_ow_context dev);
/**
* Destroy a mraa_uart_ow_context
*
* @param dev uart_ow context
* @return mraa_result_t
*/
mraa_result_t mraa_uart_ow_stop(mraa_uart_ow_context dev);
/**
* Read a byte from the 1-wire bus
*
* @param dev uart_ow context
* @return the byte read or -1 for error
*/
int mraa_uart_ow_read_byte(mraa_uart_ow_context dev);
/**
* Write a byte to a 1-wire bus
*
* @param dev uart_ow context
* @param byte the byte to write to the bus
* @return the byte read back during the time slot or -1 for error
*/
int mraa_uart_ow_write_byte(mraa_uart_ow_context dev, uint8_t byte);
/**
* Write a bit to a 1-wire bus and read a bit corresponding to the
* time slot back. This is possible due to the way we wired the TX
* and RX together with a diode, forming a loopback.
*
* @param dev uart_ow context
* @param bit the bit to write to the bus
* @return the bit read back during the time slot or -1 for error
*/
int mraa_uart_ow_bit(mraa_uart_ow_context dev, uint8_t bit);
/**
* Send a reset pulse to the 1-wire bus and test for device presence
*
* @param dev uart_ow context
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_reset(mraa_uart_ow_context dev);
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the uart_ow.c example
* for an idea on how to use this function to identify all devices
* present on the bus.
*
* @param dev uart_ow context
* @param start true to start a new search from scratch, false to
* continue an existing search
* @param id the 8-byte rom code id of the current matched device when
* a device is found
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_rom_search(mraa_uart_ow_context dev, mraa_boolean_t start, uint8_t* id);
/**
* Send a command byte to a device on the 1-wire bus
*
* @param dev uart_ow context
* @param command the command byte to send
* @param id the rom code id of the device to receive the command,
* NULL for all devices on the bus
* @return one of the mraa_result_t values
*/
mraa_result_t mraa_uart_ow_command(mraa_uart_ow_context dev, uint8_t command, uint8_t* id);
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
*
* @param buffer the buffer containing the data
* @param length the length of the buffer
* @return the computed CRC
*/
uint8_t mraa_uart_ow_crc8(uint8_t* buffer, uint16_t length);
#ifdef __cplusplus
}
#endif

277
api/mraa/uart_ow.hpp Normal file
View File

@@ -0,0 +1,277 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "uart_ow.h"
#include "types.hpp"
#include <stdexcept>
#include <cstring>
namespace mraa
{
/**
* @brief API for UART One Wire
*
* This file defines the UartOW (UART to Dallas 1-wire) interface for libmraa
*
* @snippet UartOW.cpp Interesting
*/
class UartOW
{
public:
/**
* UartOW Constructor, takes a pin number which will map directly to the
* linux uart number, this 'enables' the uart, nothing more
*
* @throws std::invalid_argument in case of error
* @param uart the index of the uart to use
*/
UartOW(int uart)
{
m_uart = mraa_uart_ow_init(uart);
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART_OW");
}
}
/**
* UartOW Constructor, takes a string to the path of the serial
* interface that is needed.
*
* @throws std::invalid_argument in case of error
* @param path the file path for the UART to use
*/
UartOW(std::string path)
{
m_uart = mraa_uart_ow_init_raw(path.c_str());
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART");
}
}
/**
* Uart destructor
*/
~UartOW()
{
mraa_uart_ow_stop(m_uart);
}
/**
* Get string with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @return char pointer of device path
*/
std::string
getDevicePath()
{
std::string ret_val(mraa_uart_ow_get_dev_path(m_uart));
return ret_val;
}
/**
* Read a byte from the 1-wire bus
*
* @throws std::invalid_argument in case of error
* @return the byte read
*/
uint8_t
readByte()
{
int res = mraa_uart_ow_read_byte(m_uart);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return (uint8_t) res;
}
/**
* Write a byte to a 1-wire bus
*
* @param byte the byte to write to the bus
*
* @throws std::invalid_argument in case of error
* @return the byte read back during the time slot
*/
uint8_t
writeByte(uint8_t byte)
{
int res = mraa_uart_ow_write_byte(m_uart, byte);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return (uint8_t) res;
}
/**
* Write a bit to a 1-wire bus and read a bit corresponding to the
* time slot back. This is possible due to the way we wired the TX
* and RX together with a diode, forming a loopback.
*
* @param bit the bit to write to the bus
* @throws std::invalid_argument in case of error
* @return the bit read back during the time slot
*/
bool
writeBit(bool bit)
{
int res = mraa_uart_ow_bit(m_uart, (bit) ? 1 : 0);
if (res == -1) {
throw std::invalid_argument("Unknown UART_OW error");
}
return ((res) ? true : false);
}
/**
* Send a reset pulse to the 1-wire bus and test for device presence
*
* @return one of the mraa::Result values
*/
mraa::Result
reset()
{
return (mraa::Result) mraa_uart_ow_reset(m_uart);
}
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the uart_ow.c example
* for an idea on how to use this function to identify all devices
* present on the bus.
*
* @param start true to start a search from scratch, false to
* continue a previously started search
* @param id the 8-byte rom code id of the current matched device when a
* device is found
* @return one of the mraa::Result values
*/
mraa::Result
search(bool start, uint8_t* id)
{
return (mraa::Result) mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
}
/**
* Begin a rom code search of the 1-wire bus. This function
* implements the 1-wire search algorithm. See the UartOW.cpp
* example for an idea on how to use this function to identify all
* devices present on the bus.
*
* @param start true to start a search from scratch, false to
* continue a previously started search
* @return an empty string if no [more] devices are found, or a
* string containing the 8-byte romcode of a detected device.
*/
std::string
search(bool start)
{
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
mraa_result_t rv;
rv = mraa_uart_ow_rom_search(m_uart, (start) ? 1 : 0, id);
if (rv == MRAA_SUCCESS) {
// we found one
std::string idStr((char*) id, MRAA_UART_OW_ROMCODE_SIZE);
return idStr;
} else {
// failure, or end of search
return "";
}
}
/**
* Send a command byte to a device on the 1-wire bus
*
* @param command the command byte to send
* @param id the rom code id of the device to receive the command,
* NULL for all devices on the bus
* @return one of the mraa::Result values
*/
mraa::Result
command(uint8_t command, uint8_t* id)
{
return (mraa::Result) mraa_uart_ow_command(m_uart, command, id);
}
/**
* Send a command byte to a device on the 1-wire bus, supplying
* the id as a std::string
*
* @param command the command byte to send
* @param id std::string representing the code id of the device to
* receive the command, or an empty string for all devices on the
* bus. This string should be 8 bytes in size.
* @return one of the mraa::Result values
*/
mraa::Result
command(uint8_t command, std::string id)
{
if (id.empty() == 0)
return (mraa::Result) mraa_uart_ow_command(m_uart, command, NULL);
else {
if (id.size() != 8) {
// Only 8 byte romcodes are legal.
throw std::invalid_argument(std::string(__FUNCTION__) +
": id must be 8 bytes only");
}
return (mraa::Result) mraa_uart_ow_command(m_uart, command, (uint8_t*) id.c_str());
}
}
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a buffer
*
* @param buffer the buffer containing the data
* @param length the length of the buffer
* @return the computed CRC
*/
uint8_t
crc8(uint8_t* buffer, uint16_t length)
{
return mraa_uart_ow_crc8(buffer, length);
}
/**
* Perform a Dallas 1-wire compliant CRC8 computation on a
* std::string based buffer
*
* @param buffer std::string buffer containing the data
* @return the computed CRC
*/
uint8_t
crc8(std::string buffer)
{
return mraa_uart_ow_crc8((uint8_t*) buffer.c_str(), buffer.size());
}
private:
mraa_uart_ow_context m_uart;
};
}

View File

@@ -3,7 +3,7 @@
# JSON-C_LIBRARIES - library directories
find_package (PkgConfig)
pkg_check_modules (PC_JSON-C QUIET json-c)
pkg_search_module (PC_JSON-C QUIET json-c json)
find_path (JSON-C_INCLUDE_DIR json.h HINTS ${PC_JSON-C_INCLUDEDIR}
${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json)

View File

@@ -0,0 +1,160 @@
# Find specified Python version
# Arguments:
# preferred_version (value): Version to check for first
# min_version (value): Minimum supported version
# library_env (value): Name of Python library ENV variable to check
# include_dir_env (value): Name of Python include directory ENV variable to check
# found (variable): Set if interpreter found
# executable (variable): Output of executable found
# version_string (variable): Output of found version
# version_major (variable): Output of found major version
# version_minor (variable): Output of found minor version
# libs_found (variable): Set if libs found
# libs_version_string (variable): Output of found libs version
# libraries (variable): Output of found Python libraries
# library (variable): Output of found Python library
# debug_libraries (variable): Output of found Python debug libraries
# debug_library (variable): Output of found Python debug library
# include_path (variable): Output of found Python include path
# include_dir (variable): Output of found Python include dir
# include_dir2 (variable): Output of found Python include dir2
# packages_path (variable): Output of found Python packages path
function(find_python preferred_version min_version library_env include_dir_env
found executable version_string version_major version_minor
libs_found libs_version_string libraries library debug_libraries
debug_library include_path include_dir include_dir2 packages_path)
if(NOT ${found})
if(${executable})
set(PYTHON_EXECUTABLE "${${executable}}")
endif()
find_package(PythonInterp "${preferred_version}")
if(NOT PYTHONINTERP_FOUND)
find_package(PythonInterp "${min_version}")
endif()
if(PYTHONINTERP_FOUND)
# Copy outputs
set(_found ${PYTHONINTERP_FOUND})
set(_executable ${PYTHON_EXECUTABLE})
set(_version_string ${PYTHON_VERSION_STRING})
set(_version_major ${PYTHON_VERSION_MAJOR})
set(_version_minor ${PYTHON_VERSION_MINOR})
set(_version_patch ${PYTHON_VERSION_PATCH})
# Clear find_host_package side effects
unset(PYTHONINTERP_FOUND)
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON_VERSION_STRING)
unset(PYTHON_VERSION_MAJOR)
unset(PYTHON_VERSION_MINOR)
unset(PYTHON_VERSION_PATCH)
endif()
if(_found)
set(_version_major_minor "${_version_major}.${_version_minor}")
if(NOT ANDROID AND NOT APPLE_FRAMEWORK)
# not using _version_string here, because it might not conform to the CMake version format
if(CMAKE_CROSSCOMPILING)
# builder version can differ from target, matching base version (e.g. 2.7)
find_package(PythonLibs "${_version_major_minor}")
else()
find_package(PythonLibs "${_version_major_minor}.${_version_patch}" EXACT)
endif()
if(PYTHONLIBS_FOUND)
# Copy outputs
set(_libs_found ${PYTHONLIBS_FOUND})
set(_libraries ${PYTHON_LIBRARIES})
set(_include_path ${PYTHON_INCLUDE_PATH})
set(_include_dirs ${PYTHON_INCLUDE_DIRS})
set(_debug_libraries ${PYTHON_DEBUG_LIBRARIES})
set(_libs_version_string ${PYTHONLIBS_VERSION_STRING})
set(_debug_library ${PYTHON_DEBUG_LIBRARY})
set(_library ${PYTHON_LIBRARY})
set(_library_debug ${PYTHON_LIBRARY_DEBUG})
set(_library_release ${PYTHON_LIBRARY_RELEASE})
set(_include_dir ${PYTHON_INCLUDE_DIR})
set(_include_dir2 ${PYTHON_INCLUDE_DIR2})
# Clear find_package side effects
unset(PYTHONLIBS_FOUND)
unset(PYTHON_LIBRARIES)
unset(PYTHON_INCLUDE_PATH)
unset(PYTHON_INCLUDE_DIRS)
unset(PYTHON_DEBUG_LIBRARIES)
unset(PYTHONLIBS_VERSION_STRING)
unset(PYTHON_DEBUG_LIBRARY CACHE)
unset(PYTHON_LIBRARY)
unset(PYTHON_LIBRARY_DEBUG)
unset(PYTHON_LIBRARY_RELEASE)
unset(PYTHON_LIBRARY CACHE)
unset(PYTHON_LIBRARY_DEBUG CACHE)
unset(PYTHON_LIBRARY_RELEASE CACHE)
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_INCLUDE_DIR2 CACHE)
endif()
endif()
execute_process(COMMAND ${_executable} -c "from distutils.sysconfig import *; print(get_python_lib())"
RESULT_VARIABLE _cvpy_process
OUTPUT_VARIABLE _std_packages_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${_std_packages_path}" MATCHES "site-packages")
set(_packages_path "python${_version_major_minor}/site-packages")
else() #debian based assumed, install to the dist-packages.
set(_packages_path "python${_version_major_minor}/dist-packages")
endif()
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${${packages_path}}")
set(_packages_path "lib${LIB_SUFFIX}/${_packages_path}")
else()
set(_packages_path "lib/${_packages_path}")
endif()
endif()
# Export return values
set(${found} "${_found}" CACHE INTERNAL "")
set(${executable} "${_executable}" CACHE FILEPATH "Path to Python interpretor")
set(${version_string} "${_version_string}" CACHE INTERNAL "")
set(${version_major} "${_version_major}" CACHE INTERNAL "")
set(${version_minor} "${_version_minor}" CACHE INTERNAL "")
set(${libs_found} "${_libs_found}" CACHE INTERNAL "")
set(${libs_version_string} "${_libs_version_string}" CACHE INTERNAL "")
set(${libraries} "${_libraries}" CACHE INTERNAL "Python libraries")
set(${library} "${_library}" CACHE FILEPATH "Path to Python library")
set(${debug_libraries} "${_debug_libraries}" CACHE INTERNAL "")
set(${debug_library} "${_debug_library}" CACHE FILEPATH "Path to Python debug")
set(${include_path} "${_include_path}" CACHE INTERNAL "")
set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
endif()
endfunction(find_python)
set(MIN_VER_PYTHON2 2.7)
set(MIN_VER_PYTHON3 3.2)
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
if(PYTHON_DEFAULT_EXECUTABLE)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
endif()

View File

@@ -75,6 +75,8 @@ style numbers.
There is also a second 8-pin connector on the Banana Pi, the pins are as follows:
| MRAA Number | Physical Pin | Function |
|-------------|--------------|-----------|
| 27 | P1-19 | 5V VCC |
| 28 | P1-20 | 3V3 VCC |
| 29 | P1-21 | GPIO(PH5) |

View File

@@ -92,10 +92,6 @@ Building doc, this will require [SPHINX](http://sphinx-doc.org) &
[Doxygen](http://doxygen.org):
`-DBUILDDOC=ON`
Building with Python 3 (careful you need to clear CMake cache between Python
version switches!)
`-DBUILDPYTHON3=ON`
Override build architecture (this is useful because on x86 ARM code is not
compiled so use this flag to force the target arch)
`-DBUILDARCH=arm`
@@ -172,7 +168,7 @@ You can get `cpack` to generate an IPK or RPM package fairly easily if you have
the correct packaging tools
~~~~~~~~~~~~~{.sh}
cmake -DIPK=ON -DCMAKE_INSTAL_PREFIX=/usr ..
cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make package
~~~~~~~~~~~~~
@@ -180,5 +176,5 @@ To use RPM simply enable the RPM option. You'll need `rpmbuild` installed on you
build machine.
~~~~~~~~~~~~~{.sh}
cmake -DRPM=ON -DCMAKE_INSTAL_PREFIX=/usr ..
cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
~~~~~~~~~~~~~

View File

@@ -5,6 +5,59 @@ This changelog is meant as a quick & rough guide to what has changed between
versions. The API is now fairly stable but when new calls/features are added
they are listed here. Anything pre 0.2.x is ignored.
**1.2.3**
* Revert 1.2.1 binding.gyp changed that had side effect of enabling JSONPLAT in mraa.c
* improve travis.ci to load mraa.node as compiled from make npmpkg target
**1.2.2**
* remove jsonplat from prehashed npm builds (see docs/npm.md for details)
* internal spelling fix
**1.2.1**
* Fix npm pkg build - no other fix
**1.2.0**
* JSON platform support
* mock I2c functionality
* Intel Grosse Tete PWM fix
* AIO firmata bug fix
**1.1.2**
* Mock platform support
* mraa-i2c treats i2c buses by default as linux
* grosse tete i2c fixes
* travis now uses 14.04 instead of 12.04
**1.1.1**
* IIO 4.6 kernel matrix support
* Intel Grosse Tete radio led support
* mraa_init_io() examples
* MRAAPLATFORMFORCE fixes
* fix python documentation
**1.1.0**
* build python2 & python3 bindings
* Intel Grosse Tete support
* mraa_init_io() generic funtion
* mraa-gpio fixes
* edison PWM 0% improvements
* iio location maping fix
**1.0.0**
* Change API to enhance error checking in C. Changes include:
- mraa_aio_read
- mraa_i2c_read_byte
- mraa_i2c_read
- mraa_i2c_read_byte_data
- mraa_i2c_read_word_data
- mraa_spi_write_word
- mraa::Spi:write_word becomes mraa::Spi::writeWord
* Remove MRAA_ERROR_PLATFORM_ALREADY_INITIALISED which was deprecated for C89 compatibility
* Remove pwm config_* apis as unused
* Add mraa_remove_subplatform
* Support NPM for android
* Fix AIO always returning channel 0 with firmata support
**0.10.1**
* Remove imraa from node package
@@ -35,7 +88,7 @@ they are listed here. Anything pre 0.2.x is ignored.
**0.9.3**
* Intel edison detection much improved
* ftdi ft4222 interupt improvement
* ftdi ft4222 interrupt improvement
* small fixes to java lib
**0.9.2**

View File

@@ -8,7 +8,7 @@ The rev D board has the following limitations in libmraa:
- gpio 13 will not switch the LED as it's a different Gpio, use raw gpio '3' to do this
- gpio register access via /dev/uio is limited to pin2 and 3
- gpio interupts will only work on GPIO_EDGE_BOTH
- gpio interrupts will only work on GPIO_EDGE_BOTH
- adc kernel module will return 12bit number. MRAA defaults shift this to 10bits
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio

112
docs/grossetete.md Normal file
View File

@@ -0,0 +1,112 @@
Grosse Tete {#grossetete}
===========
The Grosse Tete with the Tuchuck board is supported by Mraa
Revision Support
----------------
Tuchuck
Interface notes
---------------
**SPI** Currently not working
**UART** Some pins are labelled as UARTs but are not configured in BIOS as UART
so only available UART is on the FTDI header
Pin Mapping
-----------
Tuchuck has two breakouts, breakout #1 is 1-40 whilst breakout2 is 41-80. The
LEDs are numbered from 100-103.
| MRAA Number | Physical Pin | Function |
|-------------|--------------|----------|
| 1 | GPIO | GPIO |
| 2 | SPP1RX | GPIO |
| 3 | PMICRST | NONE |
| 4 | SPP1TX | GPIO |
| 5 | 19.2mhz | GPIO |
| 6 | SPP1FS0 | GPIO |
| 7 | UART0TX | GPIO |
| 8 | SPP1FS2 | GPIO |
| 9 | PWRGD | NONE |
| 10 | SPP1CLK | GPIO |
| 11 | I2C0SDA | I2C |
| 12 | I2S1SDI | GPIO |
| 13 | I2C0SCL | I2C |
| 14 | I2S1SDO | GPIO |
| 15 | I2C1SDA | I2C |
| 16 | I2S1WS | GPIO |
| 17 | I2C1SCL | I2C |
| 18 | I2S1CLK | GPIO |
| 19 | I2C2SDA | I2C |
| 20 | I2S1MCL | GPIO |
| 21 | I2C2SCL | I2CO |
| 22 | UART1TX | UART |
| 23 | I2S4SDO | NONE |
| 24 | UART1RX | UART |
| 25 | I2S4SDI | NONE |
| 26 | PWM0 | GPIO PWM |
| 27 | I2S4BLK | GPIO |
| 28 | PWM1 | GPIO PWM |
| 29 | I2S4WS | NONE |
| 30 | PWM2 | GPIO PWM |
| 31 | I2S3SDO | NONE |
| 32 | PWM3 | GPIO PWM |
| 33 | I2S3SDI | NONE |
| 34 | 1.8V | NONE |
| 35 | I2S4BLK | GPIO |
| 36 | GND | NONE |
| 37 | GND | NONE |
| 38 | GND | NONE |
| 39 | GND | NONE |
| 40 | 3.3V | NONE |
| 41 | GND | NONE |
| 42 | 5V | NONE |
| 43 | GND | NONE |
| 44 | 5V | NONE |
| 45 | GND | NONE |
| 46 | 3.3V | NONE |
| 47 | GND | NONE |
| 48 | 3.3V | NONE |
| 49 | GND | NONE |
| 50 | 1.8V | NONE |
| 51 | GPIO | GPIO |
| 52 | 1.8V | NONE |
| 53 | PANEL | GPIO |
| 54 | GND | NONE |
| 55 | PANEL | GPIO |
| 56 | CAMERA | NONE |
| 57 | PANEL | GPIO |
| 58 | CAMERA | NONE |
| 59 | SPP0FS0 | GPIO |
| 60 | CAMERA | NONE |
| 61 | SPP0FS1 | GPIO |
| 62 | SPI_DAT | SPI |
| 63 | SPP0FS2 | GPIO |
| 64 | SPICLKB | GPIO SPI |
| 65 | SPP0FS3 | GPIO |
| 66 | SPICLKA | GPIO SPI |
| 67 | SPP0TX | GPIO |
| 68 | UART0RX | GPIO UART|
| 69 | SPP0RX | GPIO |
| 70 | UART0RT | GPIO UART|
| 71 | I2C1SDA | GPIO I2C |
| 72 | UART0CT | GPIO UART|
| 73 | I2C1SCL | GPIO I2C |
| 74 | UART1TX | GPIO UART|
| 75 | I2C2SDA | GPIO I2C |
| 76 | UART1RX | GPIO UART|
| 77 | I2C1SCL | GPIO I2C |
| 78 | UART1RT | GPIO UART|
| 79 | RTC_CLK | GPIO |
| 80 | UART1CT | GPIO UART|
| 100 | LED100 | GPIO |
| 101 | LED101 | GPIO |
| 102 | LED102 | GPIO |
| 103 | LED103 | GPIO |
To see a live pin mapping use the command:
$ mraa-gpio list

View File

@@ -46,6 +46,8 @@ Specific platform information for supported platforms is documented here:
- @ref bananapi
- @ref beaglebone
- @ref nuc5
- @ref up
- @ref grossetete
- @ref ft4222
## DEBUGGING

View File

@@ -47,6 +47,7 @@ Specific platform information for supported platforms is documented here:
- @ref beaglebone
- @ref nuc5
- @ref up
- @ref grossetete
- @ref ft4222
## DEBUGGING

92
docs/mock.md Normal file
View File

@@ -0,0 +1,92 @@
Mock platform {#mock}
=============
Mocking capability allows libmraa user to work with the library without any real
hardware available. Enabling this requires library recompilation with architecture
override (see Building section below). When mock is enabled, library simulates
actual HW operations at the backend so that for the application it looks
like a usual board. Being implemented at the backend, the functionality is available
in all language bindings libmraa supports.
Board configuration
-------------------
This feature is yet in the experimental mode and not all functionality is available.
Right now we simulate a single generic board with:
* GPIO (without ISR)
* ADC with 10 (std)/12 (max) bit resolution, which returns random values on read
* Single I2C bus with one device at address 0x33 and 10 bytes of register space,
which can be read or written in bytes or words (big-endian). Technically those
registers are just an array of `uint8_t`, so you can treat them as 10 single-byte
registers or 5 single-word ones or a mix thereof.
We plan to develop it further and all [contributions](../CONTRIBUTING.md) are more than welcome.
See the table below for pin layout and features
| MRAA Number | Pin Name | Notes |
|-------------|----------|---------------------------------------|
| 0 | GPIO0 | GPIO pin, no muxing, no ISR |
| 1 | ADC0 | AIO pin, returns random value on read |
| 2 | I2C0SDA | SDA pin for I2C0 bus |
| 3 | I2C0SCL | SCL pin for I2C0 bus |
Building
--------
Generally all the building steps are the same as listed
in the [main building guide](./building.md), you just need to set some specific
CMake options.
### Linux
To build under Linux, follow standard instructions, just make sure to set
the `-DBUILDARCH="MOCK"` CMake option.
### Windows
Mocking capability allows us to build and use libmraa under Windows. That helps
if you e.g. don't want to leave your customary Windows-based Python IDE, but
want to develop libmraa-based programs.
Building Node.js bindings was not yet tested under Windows as MSYS2
does not have a ready-made package. Java was not tested either.
#### Prerequisites
You'll need the following to build libmraa under Windows:
* [MSYS2](http://mingw-w64.org/doku.php/download/msys2) basic installation
* Several additional packages, install them by running
```bash
pacman -S cmake base-devel gcc git
```
#### Compiling
The procedure is conceptually the same as under Linux - you first need to run
CMake with specific options to generate makefiles and then run make to build everything.
* Run MSYS2 shell (not a MinGW one)
* Clone the libmraa git repo (let's assume into `/home/test/mraa/mraa-src` dir)
* Create a build directory outside of the clone one (let's say `/home/test/mraa/mraa-build`)
* Run CMake, switching off unsupported options and enabling mock platform:
```bash
cmake ../mraa-src/ -DBUILDARCH="MOCK" -DBUILDSWIGNODE=OFF -DENABLEEXAMPLES=OFF
```
* Make, install and test:
```bash
make clean && make install && make test
```
All tests should pass.
**Note:** To have autocompletion in Python IDE, just point it to MSYS2's Python
and make sure to specify any additional paths pointing to site-packages dir
with mraa module if IDE requires that ("Interpreter Paths" in PyCharm).
With the above settings the module will be installed into `/usr/local/lib/python2.7/site-packages`
and the libmraa itself - into `/usr/local/bin`.

View File

@@ -35,6 +35,11 @@ target_link_libraries (mraa-i2c mraa)
target_link_libraries (spi_max7219 mraa)
target_link_libraries (iio_driver mraa)
if (ONEWIRE)
add_executable (uart_ow uart_ow.c)
target_link_libraries (uart_ow mraa)
endif ()
if (FIRMATA)
add_executable (firmata_curie_imu firmata_curie_imu.c)
add_executable (i2c_firmata i2c_firmata.c)

View File

@@ -19,3 +19,8 @@ target_link_libraries (Spi-pot mraa stdc++)
target_link_libraries (Uart mraa stdc++)
target_link_libraries (Isr-pin6 mraa stdc++)
target_link_libraries (Iio-dummy mraa stdc++)
if (ONEWIRE)
add_executable (UartOW UartOW.cpp)
target_link_libraries (UartOW mraa stdc++)
endif ()

82
examples/c++/UartOW.cpp Normal file
View File

@@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "stdio.h"
#include "iostream"
//! [Interesting]
#include "uart_ow.hpp"
using namespace std;
int
main(int argc, char** argv)
{
mraa::UartOW* uart = new mraa::UartOW(0);
// Reset the ow bus and see if anything is present
mraa::Result rv;
if ((rv = uart->reset()) == mraa::SUCCESS) {
cout << "Reset succeeded, device(s) detected!" << endl;
} else {
cout << "Reset failed, returned " << int(rv) << ". No devices on bus?" << endl;
return 1;
}
cout << "Looking for devices..." << endl;
;
uint8_t count = 0;
// start the search from scratch
string id = uart->search(true);
if (id.empty()) {
cout << "No devices detected." << endl;
return 1;
}
while (!id.empty()) {
// hack so we don't need to cast each element of the romcode
// for printf purposes
uint8_t* ptr = (uint8_t*) id.c_str();
// The first byte (0) is the device type (family) code.
// The last byte (7) is the rom code CRC value. The
// intervening bytes are the unique 48 bit device ID.
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, ptr[0],
ptr[6], ptr[5], ptr[4], ptr[3], ptr[2], ptr[1], ptr[7]);
count++;
// continue the search with start argument set to false
id = uart->search(false);
}
cout << "Exiting..." << endl;
delete uart;
return 0;
}
//! [Interesting]

68
examples/c++/initio.cpp Normal file
View File

@@ -0,0 +1,68 @@
/*
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mraa.hpp"
int main()
{
// GPIO-PIN
mraa::Gpio* gpio = mraa::initIo<mraa::Gpio>("gpio-1");
// GPIO-RAW-RAWPIN
mmraa::Gpio* gpioraw = mraa::initIo<mraa::Gpio>initIo("gpio-raw-131");
// AIO-PIN
mraa::Aio aio = mraa::initIo<mraa::Aio>("aio-0");
// PWM-PIN
mraa::Pwm pwm = mraa::initIo<mraa::Pwm>("pwm-6");
// PWM-RAW-CHIPID-PIN
mraa::Pwm pwmraw = mraa::initIo<mraa::Pwm>("pwm-raw-0,1");
// UART-INDEX: the index is the one represented internally in the uart_dev array
mraa::Uart uart = mraa::initIo<mraa::Uart>("uart-1");
// UART-RAW-PATH
mraa::Uart uartraw = mraa::initIo<mraa::Uart>("uart-raw-/dev/ttyS0");
// SPI-INDEX: same as UART
mraa::Spi spi = mraa::initIo<mraa::Spi>("spi-0");
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
mraa::Spi spiraw = mraa::initIo<mraa::Spi>("spi-raw-0-1");
// I2C-INDEX: same as UART
mraa::I2c i2c = mraa::initIo<mraa::I2c>("i2c-0");
// I2C-RAW-BUS
mraa::I2c i2craw = mraa::initIo<mraa::I2c>("i2c-raw-0");
// FREE STUFF
delete gpio;
delete gpioraw;
delete aio;
delete pwm;
delete pwmraw;
delete uart;
delete uartraw;
delete spi;
delete spiraw;
delete i2c;
delete i2craw;
}

69
examples/initio.c Normal file
View File

@@ -0,0 +1,69 @@
/*
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mraa.h"
int main()
{
// GPIO-PIN
mraa_gpio_context gpio = (mraa_gpio_context) init_io("gpio-1");
// GPIO-RAW-RAWPIN
mraa_gpio_context gpioraw = (mraa_gpio_context) init_io("gpio-raw-131");
// AIO-PIN
mraa_aio_context aio = (mraa_aio_context) init_io("aio-0");
// PWM-PIN
mraa_pwm_context pwm = (mraa_pwm_context) init_io("pwm-6");
// PWM-RAW-CHIPID-PIN
mraa_pwm_context pwmraw= (mraa_pwm_context) init_io("pwm-raw-0,1");
// UART-INDEX: the index is the one represented internally in the uart_dev array
mraa_uart_context uart = (mraa_uart_context) init_io("uart-1");
// UART-RAW-PATH
mraa_uart_context uartraw = (mraa_uart_context) init_io("uart-raw-/dev/ttyS0");
// SPI-INDEX: same as UART
mraa_spi_context spi = (mraa_spi_context) init_io("spi-0");
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
mraa_spi_context spiraw = (mraa_spi_context) init_io("spi-raw-0-1");
// I2C-INDEX: same as UART
mraa_i2c_context i2c = (mraa_i2c_context) init_io("i2c-0");
// I2C-RAW-BUS
mraa_i2c_context i2craw = (mraa_i2c_context) init_io("i2c-raw-0");
// FREE STUFF
mraa_gpio_close(gpio);
mraa_gpio_close(gpioraw);
mraa_aio_close(aio);
mraa_pwm_close(pwm);
mraa_pwm_close(pwmraw);
mraa_uart_close(uart);
mraa_uart_close(uartraw);
mraa_spi_close(spi);
mraa_spi_close(spiraw);
mraa_i2c_close(i2c);
mraa_i2c_close(i2craw);
}

View File

@@ -50,7 +50,7 @@ public class BlinkIO {
if (argv.length == 0) {
System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN);
} else {
iopin = Integer.valueOf(argv[0], DEFAULT_IOPIN);
iopin = Integer.valueOf(argv[0]);
}
//! [Interesting]

View File

@@ -0,0 +1,48 @@
/*
* Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var m = require('mraa');
// GPIO-PIN
m.gpioFromDesc("gpio-1");
// GPIO-RAW-RAWPIN
m.gpioFromDesc("gpio-raw-131");
// AIO-PIN
m.aioFromDesc("aio-1");
//PWM-PIN
m.pwmFromDesc("pwm-6");
// PWM-RAW-CHIPID-PIN
m.pwmFromDesc("pwm-raw-0-1")
// UART-INDEX: the index is the one represented internally in the uart_dev array
m.uartFromDesc("uart-0");
// UART-RAW-PATH
m.uartFromDesc("uart-raw-/dev/ttyS0");
// SPI-INDEX: same as UART
m.spiFromDesc("spi-0");
// SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
m.spiFromDesc("spi-raw-0-1");
// I2C-INDEX: same as UART
m.i2cFromDesc("i2c-0");
// I2C-RAW-BUS
m.i2cFromDesc("i2c-raw-0");

View File

@@ -8,3 +8,9 @@ function h() {
x = new m.Gpio(14)
x.isr(m.EDGE_BOTH, h)
setInterval(function() {
// It's important to refer to our GPIO context here,
// otherwise it will be garbage-collected
console.log("Waiting for an interrupt at GPIO pin " + x.getPin() + "...")
}, 10000)

View File

@@ -67,7 +67,7 @@ list_platform_pins(uint8_t platform_offset)
for (i = 0; i < pin_count; ++i) {
int pin_id = platform_offset > 0 ? mraa_get_sub_platform_id(i) : i;
char* pin_name = mraa_get_pin_name(pin_id);
if (strcmp(pin_name, "INVALID") != 0) {
if (strcmp(pin_name, "INVALID") != 0 && mraa_pin_mode_test(pin_id, MRAA_PIN_VALID)) {
fprintf(stdout, "%02d ", pin_id);
fprintf(stdout, "%*s: ", (MRAA_PIN_NAME_SIZE - 1), pin_name);
if (mraa_pin_mode_test(pin_id, MRAA_PIN_GPIO))
@@ -103,7 +103,13 @@ list_pins()
mraa_result_t
gpio_set(int pin, int level, mraa_boolean_t raw)
{
mraa_gpio_context gpio = mraa_gpio_init(pin);
mraa_gpio_context gpio;
if (raw) {
gpio = mraa_gpio_init_raw(pin);
}
else {
gpio = mraa_gpio_init(pin);
}
if (gpio != NULL) {
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
if (raw != 0) {

View File

@@ -65,24 +65,13 @@ print_bus(mraa_board_t* board)
for (i = 0; i < board->i2c_bus_count; ++i) {
char* busType;
switch (board->platform_type) {
case MRAA_INTEL_GALILEO_GEN1:
case MRAA_INTEL_GALILEO_GEN2:
case MRAA_INTEL_EDISON_FAB_C:
case MRAA_INTEL_DE3815:
case MRAA_INTEL_MINNOWBOARD_MAX:
case MRAA_RASPBERRY_PI:
case MRAA_BEAGLEBONE:
case MRAA_BANANA:
case MRAA_UP:
bus = i;
busType = "linux";
break;
case MRAA_FTDI_FT4222:
busType = "ft4222";
bus = mraa_get_sub_platform_id(i);
break;
default:
busType = "unknown";
busType = "linux";
bus = i;
break;
}
int id = board->i2c_bus[i].bus_id;

View File

@@ -0,0 +1,73 @@
{
"version": "1.0.0",
"platform":[
{ "id":300,
"name":"Turbot",
"pin_count": 28,
"gpio_count": 28,
"i2c_count": 1,
"aio_count": 0,
"spi_count": 1,
"uart_count": 1,
"pwmDefPeriod":500,
"pwmMaxPeriod":1000000000,
"pwmMinPeriod":1
}
],
"layout":[
{"label": "INVALID", "invalid": true},
{"label": "GND"},
{"label": "GND"},
{"label": "5v"},
{"label": "3.3v"},
{"label": "SPI_CS"},
{"label": "UART1TX"},
{"label": "SPIMISO"},
{"label": "UART1RX"},
{"label": "SPIMOSI"},
{"label": "UART1CT"},
{"label": "SPI_CLK"},
{"label": "UART1RT"},
{"label": "I2C_SCL"},
{"label": "I2S_CLK"},
{"label": "I2C_SDA"},
{"label": "I2S_FRM"},
{"label": "UART2TX"},
{"label": "I2S_DO"},
{"label": "UART2RX"},
{"label": "I2S_DI"},
{"label": "S5_0"},
{"label": "PWM0"},
{"label": "S5_1"},
{"label": "PWM1"},
{"label": "S5_4"},
{"label": "I2S_MCLK"},
{"label": "S5_22"}
],
"GPIO":[
{ "index": 10, "rawpin": 483 },
{ "index": 12, "rawpin": 482 },
{ "index": 14, "rawpin": 472 },
{ "index": 16, "rawpin": 473 },
{ "index": 18, "rawpin": 475 },
{ "index": 20, "rawpin": 474 },
{ "index": 21, "rawpin": 338 },
{ "index": 23, "rawpin": 339 },
{ "index": 25, "rawpin": 340 },
{ "index": 26, "rawpin": 509 },
{ "index": 27, "rawpin": 360 }
],
"I2C": [
{ "sclpin":13, "sdapin":15, "rawpin": 0, "index": 0, "default":true }
],
"PWM": [
{ "index":22, "rawpin":0, "chipID":0},
{ "index":24, "rawpin":0, "chipID":1 }
],
"SPI": [
{ "index":0, "chipID": 0, "clock": 11, "miso": 7, "mosi": 9, "chipselect": 5, "default": true}
],
"UART":[
{ "index":0, "chipID":0, "rawpin":0, "path":"/dev/ttyS0", "default":true}
]
}

View File

@@ -31,7 +31,7 @@ class Counter:
c = Counter()
# inside a python interupt you cannot use 'basic' types so you'll need to use
# inside a python interrupt you cannot use 'basic' types so you'll need to use
# objects
def test(gpio):
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))

48
examples/python/initio.py Normal file
View File

@@ -0,0 +1,48 @@
#!/bin/usr/env python
# Author: Houman Brinjcargorabi <houman.brinjcargorabi@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
import mraa as m
# GPIO-PIN
m.gpioFromDesc("gpio-1");
# GPIO-RAW-RAWPIN
m.gpioFromDesc("gpio-raw-131");
# AIO-PIN
m.aioFromDesc("aio-1");
# PWM-PIN
m.pwmFromDesc("pwm-6");
# PWM-RAW-CHIPID-PIN
m.pwmFromDesc("pwm-raw-0-1")
# UART-INDEX: the index is the one represented internally in the uart_dev array
m.uartFromDesc("uart-0");
# UART-RAW-PATH
m.uartFromDesc("uart-raw-/dev/ttyS0");
# SPI-INDEX: same as UART
m.spiFromDesc("spi-0");
# SPI-RAW-BUS-CS: USED to open and use /dev/spidev<BUS>.<CS>
m.spiFromDesc("spi-raw-0-1");
# I2C-INDEX: same as UART
m.i2cFromDesc("i2c-0");
# I2C-RAW-BUS
m.i2cFromDesc("i2c-raw-0");

92
examples/uart_ow.c Normal file
View File

@@ -0,0 +1,92 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "stdio.h"
//! [Interesting]
#include "mraa.h"
int
main(int argc, char** argv)
{
mraa_uart_ow_context uart;
uart = mraa_uart_ow_init(0);
if (!uart) {
printf("mraa_uart_ow_init() failed\n");
return 1;
}
// Reset the ow bus and see if anything is present
mraa_result_t rv;
if ((rv = mraa_uart_ow_reset(uart)) == MRAA_SUCCESS) {
printf("Reset succeeded, device(s) detected!\n");
} else {
printf("Reset failed, returned %d. No devices on bus?\n", rv);
return 1;
}
printf("Looking for devices...\n");
uint8_t id[MRAA_UART_OW_ROMCODE_SIZE];
/* we are essentially doing a binary tree search through the 64
* bit address space. id is modified during this search, and will
* be set to the valid rom code for each device found.
*/
uint8_t count = 0;
// start the search from scratch
mraa_result_t result = mraa_uart_ow_rom_search(uart, 1, id);
if (result == MRAA_ERROR_UART_OW_NO_DEVICES) {
printf("No devices detected.\n");
return 1;
}
if (result == MRAA_ERROR_UART_OW_DATA_ERROR) {
printf("Bus/Data error.\n");
return 1;
}
while (result == MRAA_SUCCESS) {
/* The first byte (id[0]]) is the device type (family) code.
* The last byte (id[7]) is the rom code CRC value. The
* intervening bytes (id[1]-id[6]) are the unique 48 bit
* device ID.
*/
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, id[0],
id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
count++;
// continue the search with start argument set to 0
result = mraa_uart_ow_rom_search(uart, 0, id);
}
printf("Exiting...\n");
mraa_uart_ow_stop(uart);
return 0;
}
//! [Interesting]

View File

@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>

View File

@@ -28,6 +28,8 @@ typedef struct {
typedef void (*__kernel_sighandler_t)(int);
typedef int __kernel_key_t;
typedef int __kernel_mqd_t;
#if !defined(MSYS)
#include <asm/posix_types.h>
#endif
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#endif

View File

@@ -0,0 +1,58 @@
/*
* This header was manually generated from a Linux kernel header
* linux/spi/spidev.h, to make information necessary for compilation
* to be available under MSYS. It contains only constants,
* structures, and macros generated from the original header, and thus,
* contains no copyrightable information.
*/
#ifndef _SPI_KERNEL_HEADERS_H
#define _SPI_KERNEL_HEADERS_H
#include <linux/types.h>
#define SPI_CPHA 0x01
#define SPI_CPOL 0x02
#define SPI_MODE_0 (0|0)
#define SPI_MODE_1 (0|SPI_CPHA)
#define SPI_MODE_2 (SPI_CPOL|0)
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
#define SPI_IOC_MAGIC 'k'
struct spi_ioc_transfer {
__u64 tx_buf;
__u64 rx_buf;
__u32 len;
__u32 speed_hz;
__u16 delay_usecs;
__u8 bits_per_word;
__u8 cs_change;
__u8 tx_nbits;
__u8 rx_nbits;
__u16 pad;
};
#define SPI_MSGSIZE(N) \
((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
#define SPI_IOC_RD_MODE _IOR(SPI_IOC_MAGIC, 1, __u8)
#define SPI_IOC_WR_MODE _IOW(SPI_IOC_MAGIC, 1, __u8)
#define SPI_IOC_RD_LSB_FIRST _IOR(SPI_IOC_MAGIC, 2, __u8)
#define SPI_IOC_WR_LSB_FIRST _IOW(SPI_IOC_MAGIC, 2, __u8)
#define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8)
#define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8)
#define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32)
#define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32)
#define SPI_IOC_RD_MODE32 _IOR(SPI_IOC_MAGIC, 5, __u32)
#define SPI_IOC_WR_MODE32 _IOW(SPI_IOC_MAGIC, 5, __u32)
#endif

40
include/mock/mock_board.h Normal file
View File

@@ -0,0 +1,40 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
#define MRAA_MOCK_PINCOUNT 4
mraa_board_t*
mraa_mock_board();
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,44 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
mraa_result_t
mraa_mock_aio_init_internal_replace(mraa_aio_context dev, int pin);
mraa_result_t
mraa_mock_aio_close_replace(mraa_aio_context dev);
int
mraa_mock_aio_read_replace(mraa_aio_context dev);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,65 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
mraa_result_t
mraa_mock_gpio_init_internal_replace(mraa_gpio_context dev, int pin);
mraa_result_t
mraa_mock_gpio_close_replace(mraa_gpio_context dev);
mraa_result_t
mraa_mock_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t
mraa_mock_gpio_read_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t* dir);
int
mraa_mock_gpio_read_replace(mraa_gpio_context dev);
mraa_result_t
mraa_mock_gpio_write_replace(mraa_gpio_context dev, int value);
mraa_result_t
mraa_mock_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode);
mraa_result_t
mraa_mock_gpio_isr_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args);
mraa_result_t
mraa_mock_gpio_isr_exit_replace(mraa_gpio_context dev);
mraa_result_t
mraa_mock_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,81 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
// Mock I2C device address
#define MOCK_I2C_DEV_ADDR 0x33
// Mock I2C device data registers block length in bytes. Our code assumes it's >= 1.
#define MOCK_I2C_DEV_DATA_LEN 10
// Initial value for each byte in the mock I2C device data registers
#define MOCK_I2C_DEV_DATA_INIT_BYTE 0xAB
mraa_result_t
mraa_mock_i2c_init_bus_replace(mraa_i2c_context dev);
mraa_result_t
mraa_mock_i2c_stop_replace(mraa_i2c_context dev);
mraa_result_t
mraa_mock_i2c_set_frequency_replace(mraa_i2c_context dev, mraa_i2c_mode_t mode);
mraa_result_t
mraa_mock_i2c_address_replace(mraa_i2c_context dev, uint8_t addr);
int
mraa_mock_i2c_read_replace(mraa_i2c_context dev, uint8_t* data, int length);
int
mraa_mock_i2c_read_byte_replace(mraa_i2c_context dev);
int
mraa_mock_i2c_read_byte_data_replace(mraa_i2c_context dev, uint8_t command);
int
mraa_mock_i2c_read_bytes_data_replace(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
int
mraa_mock_i2c_read_word_data_replace(mraa_i2c_context dev, uint8_t command);
mraa_result_t
mraa_mock_i2c_write_replace(mraa_i2c_context dev, const uint8_t* data, int length);
mraa_result_t
mraa_mock_i2c_write_byte_replace(mraa_i2c_context dev, const uint8_t data);
mraa_result_t
mraa_mock_i2c_write_byte_data_replace(mraa_i2c_context dev, const uint8_t data, const uint8_t command);
mraa_result_t
mraa_mock_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
#ifdef __cplusplus
}
#endif

View File

@@ -48,6 +48,7 @@ typedef struct {
mraa_result_t (*gpio_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_dir_pre) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_dir_post) (mraa_gpio_context dev, mraa_gpio_dir_t dir);
mraa_result_t (*gpio_read_dir_replace) (mraa_gpio_context dev, mraa_gpio_dir_t *dir);
int (*gpio_read_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_write_replace) (mraa_gpio_context dev, int value);
@@ -56,6 +57,8 @@ typedef struct {
mraa_result_t (*gpio_mmap_setup) (mraa_gpio_context dev, mraa_boolean_t en);
mraa_result_t (*gpio_interrupt_handler_init_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_wait_interrupt_replace) (mraa_gpio_context dev);
mraa_result_t (*gpio_isr_replace) (mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args);
mraa_result_t (*gpio_isr_exit_replace) (mraa_gpio_context dev);
mraa_result_t (*i2c_init_pre) (unsigned int bus);
mraa_result_t (*i2c_init_bus_replace) (mraa_i2c_context dev);
@@ -64,9 +67,9 @@ typedef struct {
mraa_result_t (*i2c_set_frequency_replace) (mraa_i2c_context dev, mraa_i2c_mode_t mode);
mraa_result_t (*i2c_address_replace) (mraa_i2c_context dev, uint8_t addr);
int (*i2c_read_replace) (mraa_i2c_context dev, uint8_t* data, int length);
uint8_t (*i2c_read_byte_replace) (mraa_i2c_context dev);
uint8_t (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
uint16_t (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_byte_replace) (mraa_i2c_context dev);
int (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_bytes_data_replace) (mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
mraa_result_t (*i2c_write_replace) (mraa_i2c_context dev, const uint8_t* data, int length);
mraa_result_t (*i2c_write_byte_replace) (mraa_i2c_context dev, uint8_t data);
@@ -75,7 +78,8 @@ typedef struct {
mraa_result_t (*i2c_stop_replace) (mraa_i2c_context dev);
mraa_result_t (*aio_init_internal_replace) (mraa_aio_context dev, int pin);
mraa_result_t (*aio_read_replace) (mraa_aio_context dev);
mraa_result_t (*aio_close_replace) (mraa_aio_context dev);
int (*aio_read_replace) (mraa_aio_context dev);
mraa_result_t (*aio_get_valid_fp) (mraa_aio_context dev);
mraa_result_t (*aio_init_pre) (unsigned int aio);
mraa_result_t (*aio_init_post) (mraa_aio_context dev);
@@ -87,7 +91,9 @@ typedef struct {
mraa_result_t (*pwm_period_replace) (mraa_pwm_context dev, int period);
float (*pwm_read_replace) (mraa_pwm_context dev);
mraa_result_t (*pwm_write_replace) (mraa_pwm_context dev, float duty);
mraa_result_t (*pwm_write_pre) (mraa_pwm_context dev, float percentage);
mraa_result_t (*pwm_enable_replace) (mraa_pwm_context dev, int enable);
mraa_result_t (*pwm_enable_pre) (mraa_pwm_context dev, int enable);
mraa_result_t (*spi_init_pre) (int bus);
mraa_result_t (*spi_init_post) (mraa_spi_context spi);

View File

@@ -37,6 +37,7 @@ extern "C" {
#include "mraa_lang_func.h"
extern mraa_board_t* plat;
extern char* platform_name;
extern mraa_iio_info_t* plat_iio;
extern mraa_lang_func_t* lang_func;
@@ -62,6 +63,13 @@ mraa_platform_t mraa_x86_platform();
*/
mraa_platform_t mraa_arm_platform();
/**
* setup a mock platform
*
* @return mraa_platform_t of the init'ed platform
*/
mraa_platform_t mraa_mock_platform();
/**
* runtime detect running usb platform extender
*

View File

@@ -40,6 +40,46 @@
#define MRAA_IO_SETUP_FAILURE -2
#define MRAA_NO_SUCH_IO -1
// Json platform keys
#define INDEX_KEY "index"
#define NAME_KEY "name"
#define PIN_COUNT_KEY "pin_count"
#define GPIO_COUNT_KEY "gpio_count"
#define AIO_COUNT_KEY "aio_count"
#define SPI_COUNT_KEY "spi_count"
#define I2C_COUNT_KEY "i2c_count"
#define UART_COUNT_KEY "uart_count"
#define PWMDEFAULT_KEY "pwmDefPeriod"
#define PWMMAX_KEY "pwmMaxPeriod"
#define PWMMIN_KEY "pwmMinPeriod"
#define LABEL_KEY "label"
#define DEFAULT_KEY "default"
#define INVALID_KEY "invalid"
#define SCLPIN_KEY "sclpin"
#define SDAPIN_KEY "sdapin"
#define CHIP_ID_KEY "chipID"
#define RAW_PIN_KEY "rawpin"
#define RXPIN_KEY "rx"
#define TXPIN_KEY "tx"
#define UART_PATH_KEY "path"
#define CLOCK_KEY "clock"
#define MISO_KEY "miso"
#define MOSI_KEY "mosi"
#define CS_KEY "chipselect"
#define PIN_KEY "pin"
#define IO_KEY "layout"
#define PLATFORM_KEY "platform"
// IO keys
#define GPIO_KEY "GPIO"
#define SPI_KEY "SPI"
#define UART_KEY "UART"
#define I2C_KEY "I2C"
#define PWM_KEY "PWM"
#define AIO_KEY "AIO"
#define MRAA_JSONPLAT_ENV_VAR "MRAA_JSON_PLATFORM"
#ifdef FIRMATA
struct _firmata {
/*@*/
@@ -59,8 +99,8 @@ struct _gpio {
int pin; /**< the pin number, as known to the os. */
int phy_pin; /**< pin passed to clean init. -1 none and raw*/
int value_fp; /**< the file pointer to the value of the gpio */
void (* isr)(void *); /**< the interupt service request */
void *isr_args; /**< args return when interupt service request triggered */
void (* isr)(void *); /**< the interrupt service request */
void *isr_args; /**< args return when interrupt service request triggered */
pthread_t thread_id; /**< the isr handler thread id */
int isr_value_fp; /**< the isr file pointer on the value */
#ifndef HAVE_PTHREAD_CANCEL
@@ -71,6 +111,10 @@ struct _gpio {
mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
int (*mmap_read) (mraa_gpio_context dev);
mraa_adv_func_t* advance_func; /**< override function table */
#if defined(MOCKPLAT)
mraa_gpio_dir_t mock_dir; /**< mock direction of the pin */
int mock_state; /**< mock state of the pin */
#endif
/*@}*/
};
@@ -85,6 +129,11 @@ struct _i2c {
unsigned long funcs; /**< /dev/i2c-* device capabilities as per https://www.kernel.org/doc/Documentation/i2c/functionality */
void *handle; /**< generic handle for non-standard drivers that don't use file descriptors */
mraa_adv_func_t* advance_func; /**< override function table */
#if defined(MOCKPLAT)
uint8_t mock_dev_addr; /**< address of the mock I2C device */
uint8_t mock_dev_data_len; /**< mock device data register block length in bytes */
uint8_t* mock_dev_data; /**< mock device data register block contents */
#endif
/*@}*/
};
@@ -148,9 +197,9 @@ struct _iio {
char* name; /**< IIO device name */
int fp; /**< IIO device in /dev */
int fp_event; /**< event file descriptor for IIO device */
void (* isr)(char* data); /**< the interupt service request */
void *isr_args; /**< args return when interupt service request triggered */
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interupt service request */
void (* isr)(char* data); /**< the interrupt service request */
void *isr_args; /**< args return when interrupt service request triggered */
void (* isr_event)(struct iio_event_data* data, void* args); /**< the event interrupt service request */
int chan_num;
pthread_t thread_id; /**< the isr handler thread id */
mraa_iio_channel* channels;
@@ -213,7 +262,7 @@ typedef struct {
typedef struct {
/*@{*/
unsigned int pinmap; /**< sysfs pin */
int pinmap; /**< sysfs pin */
unsigned int parent_id; /** parent chip id */
unsigned int mux_total; /** Numfer of muxes needed for operation of pin */
mraa_mux_t mux[6]; /** Array holding information about mux */
@@ -237,7 +286,7 @@ typedef struct {
typedef struct {
/*@{*/
char name[MRAA_PIN_NAME_SIZE]; /**< Pin's real world name */
mraa_pincapabilities_t capabilites; /**< Pin Capabiliites */
mraa_pincapabilities_t capabilities; /**< Pin Capabiliites */
mraa_pin_t gpio; /**< GPIO structure */
mraa_pin_t pwm; /**< PWM structure */
mraa_pin_t aio; /**< Anaglog Pin */
@@ -253,9 +302,9 @@ typedef struct {
*/
typedef struct {
/*@{*/
unsigned int bus_id; /**< ID as exposed in the system */
unsigned int scl; /**< i2c SCL */
unsigned int sda; /**< i2c SDA */
int bus_id; /**< ID as exposed in the system */
int scl; /**< i2c SCL */
int sda; /**< i2c SDA */
// mraa_drv_api_t drv_type; /**< Driver type */
/*@}*/
} mraa_i2c_bus_t;
@@ -268,10 +317,10 @@ typedef struct {
unsigned int bus_id; /**< The Bus ID as exposed to the system. */
unsigned int slave_s; /**< Slave select */
mraa_boolean_t three_wire; /**< Is the bus only a three wire system */
unsigned int sclk; /**< Serial Clock */
unsigned int mosi; /**< Master Out, Slave In. */
unsigned int miso; /**< Master In, Slave Out. */
unsigned int cs; /**< Chip Select, used when the board is a spi slave */
int sclk; /**< Serial Clock */
int mosi; /**< Master Out, Slave In. */
int miso; /**< Master In, Slave Out. */
int cs; /**< Chip Select, used when the board is a spi slave */
/*@}*/
} mraa_spi_bus_t;
@@ -283,7 +332,7 @@ typedef struct {
unsigned int index; /**< ID as exposed in the system */
int rx; /**< uart rx */
int tx; /**< uart tx */
const char* device_path; /**< To store "/dev/ttyS1" for example */
char* device_path; /**< To store "/dev/ttyS1" for example */
/*@}*/
} mraa_uart_dev_t;
@@ -293,26 +342,26 @@ typedef struct {
typedef struct _board_t {
/*@{*/
unsigned int phy_pin_count; /**< The Total IO pins on board */
unsigned int gpio_count; /**< GPIO Count */
unsigned int aio_count; /**< Analog side Count */
unsigned int i2c_bus_count; /**< Usable i2c Count */
int phy_pin_count; /**< The Total IO pins on board */
int gpio_count; /**< GPIO Count */
int aio_count; /**< Analog side Count */
int i2c_bus_count; /**< Usable i2c Count */
mraa_i2c_bus_t i2c_bus[12]; /**< Array of i2c */
unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
unsigned int spi_bus_count; /**< Usable spi Count */
int spi_bus_count; /**< Usable spi Count */
mraa_spi_bus_t spi_bus[12]; /**< Array of spi */
unsigned int def_spi_bus; /**< Position in array of defult spi bus */
unsigned int adc_raw; /**< ADC raw bit value */
unsigned int adc_supported; /**< ADC supported bit value */
unsigned int def_uart_dev; /**< Position in array of defult uart */
unsigned int uart_dev_count; /**< Usable spi Count */
int uart_dev_count; /**< Usable spi Count */
mraa_uart_dev_t uart_dev[6]; /**< Array of UARTs */
mraa_boolean_t no_bus_mux; /**< i2c/spi/adc/pwm/uart bus muxing setup not required */
int pwm_default_period; /**< The default PWM period is US */
int pwm_max_period; /**< Maximum period in us */
int pwm_min_period; /**< Minimum period in us */
mraa_platform_t platform_type; /**< Platform type */
const char* platform_name; /**< Platform Name pointer */
char* platform_name; /**< Platform Name pointer */
const char* platform_version; /**< Platform versioning info */
mraa_pininfo_t* pins; /**< Pointer to pin array */
mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */

View File

@@ -0,0 +1,42 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
// +1 as pins are "1 indexed"
// we have 20 useless pins then the 4 LEDS and the 2 LEDs on the module.
#define MRAA_INTEL_GT_TUCHUCK_PINCOUNT (40*2 + 23 +1 +2)
mraa_board_t*
mraa_gt_tuchuck_board();
#ifdef __cplusplus
}
#endif

17
jsstub/Gruntfile.js Normal file
View File

@@ -0,0 +1,17 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['test/*.js']
}
}
});
grunt.registerTask('test', ['mochaTest:test']);
};

51
jsstub/README.md Normal file
View File

@@ -0,0 +1,51 @@
mraaStub - JavaScript simulation and stubs for mraa
====================
This project enables simulation of a device which might be accessed via mraa.
Currently this library supports I2c, SPI, and GPIO. This project provides
several benefits:
1. Prevent crashes in nodejs applications using mraa on unsuported or
misconfigured hardware.
2. Enable basic simulation of mraa-accessible devices for unit testing.
## Examples
The following example is based on an imaginary 'light bulb' device abstraction,
which exposes a value of brightness over a mraa-provided interface. Please see
the `test/index.js` file for an example.
## Installation
You may install `mraaStub` from npm like this:
```
npm install mraaStub
```
Since we often switch between a mraaStub and the real mraa library, we
suggest creating an `index.js` file inside a `lib/mraaSwitcher` folder.
```js
/* index.js - file for switching between mraa and mraaStub
*/
// Define the conditions under which the mraaStub should be loaded
var platform = require('os').platform();
var m;
if (platform === 'win32') {
m = require('mraaStub');
} else {
m = require('mraa');
}
module.exports = m;
```
You can add this to your project in its own `lib/mraaSwitcher/index.js` file
and use `require('../mraaSwitcher')` everywhere!
## License
See [COPYING file](../COPYING) in the root of this repository.

223
jsstub/index.js Normal file
View File

@@ -0,0 +1,223 @@
/**
* @fileoverview This file implements a fake mraa stub which enables testing
* as well as the ability to run on Windows.
*/
var m;
var winston = require('winston');
var logger = new winston.Logger({
transports: [
new winston.transports.Console({
level: 'error',
handleExceptions: false,
json: false,
colorize: true})
],
exitOnError: false
});
/**
* @class mraaStub
* @classdesc This class is designed to stub out libmraa so we can run
* test code on unsupported platforms (specifically Windows).
*/
var mraaStub = function() {
var verison = '0.0.1';
var self = this;
self.EDGE_BOTH = 1;
self.EDGE_NONE = 2;
self.EDGE_RISING = 3;
self.EDGE_FALLING = 4;
self.DIR_IN = 1;
self.DIR_OUT = 2;
self.getVersion = function() {
return "mraaStub " + version;
};
// Stub out GPIO
function Gpio(num) {
this.num = num;
this._callback = null;
this._dir = null;
this._isr_mode = self.EDGE_NONE;
}
var logGpio = false;
Gpio.prototype._callIsr = function() {
if(this.isr_mode === self.EDGE_NONE) {
logger.log('info',"Could not call ISR. Not set up for triggering");
}
this._callback();
};
Gpio.prototype.isr = function(mode, handler){
if(logGpio) {
logger.log('info',"GPIO " + this.num + " isr stub invoked.");
}
this._isr_mode = self.EDGE_NONE;
this._callback = handler;
};
Gpio.prototype.dir = function(d) {
if(logGpio) {
logger.log('info',"GPIO " + this.num + " dir stub invoked.");
}
this._dir = d;
};
Gpio.prototype.write = function(z) {
if(logGpio) {
logger.log('logger',"GPIO " + this.num + " write stub invoked.");
}
if(this._dir !== self.DIR_OUT) {
logger.log('info',"GPIO " + this.num + " write called without DIR_OUT set.");
}
};
Gpio.prototype.read = function() {
if(logGpio) {
logger.log('info',"GPIO " + this.num + " read stub invoked.");
}
return 0;
};
// Stub out SPI
function Spi(num) {
var self = this;
this.num = num;
this._buffer = new Buffer(29);
this._buffer.fill(0);
this._loopback = false;
}
Spi.prototype._setOutput = function(buf) {
this._buffer = buf;
};
Spi.prototype._enableLoopback = function(x) {
if(x === true) {
this._loopback = true;
} else {
this._loopback = false;
}
};
Spi.prototype.write = function(b) {
logger.log('info',"SPI write stub invoked.");
if(this._loopback === true) {
return b;
}
return new Buffer(this._buffer);
};
Spi.prototype.frequency = function(f) {
logger.log('info',"SPI frequency stub invoked.");
return f;
};
Spi.prototype.lsbmode = function(t) {
logger.log('info',"SPI lsbmode stub invoked.");
};
Spi.prototype.mode = function(x) {
logger.log('info',"SPI mode stub invoked.");
};
function I2c(num) {
this._num = num;
this._regMapInitialized = false;
}
/* This function sets an internal register map for the I2c device.
*/
I2c.prototype._setRegisterMapInternal = function(buffer) {
this._regMapInitialized = true;
this._buffer = buffer;
};
I2c.prototype.frequency = function(freq) {
// Do nothing. We don't care.
};
I2c.prototype.address = function(address) {
var self = this;
self.address = address;
};
I2c.prototype.readReg = function(regAddr) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.readUInt8(regAddr);
};
I2c.prototype.readWordReg = function(regAddr) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.readUInt16LE(regAddr);
};
I2c.prototype.readBytesReg = function(regAddr, len) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
return this._buffer.slice(regAddr,regAddr+len);
};
I2c.prototype.write = function(buf) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
var regAddr = buf[0];
var newBuf = buf.slice(1);
newBuf.copy(this._buffer, regAddr);
};
I2c.prototype.writeReg = function(regAddr, data) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
this._buffer.writeUInt8(regAddr,data);
};
I2c.prototype.writeWordReg = function(regAddr, dataWord) {
if(!this._regMapInitialized) {
logger.log('error', "Need to set reg map");
}
if(!this.address) {
logger.log('error', "Need to set address");
}
this._buffer.writeUInt16LE(regAddr,data);
};
// Export our stubs
self.Gpio = Gpio;
self.Spi = Spi;
self.I2c = I2c;
};
m = new mraaStub();
module.exports = m;

34
jsstub/package.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "mraaStub",
"version": "0.0.1",
"description": "Enables simulation of mraa interfaces for testing purposes",
"main": "index.js",
"scripts": {
"test": "grunt test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intel-iot-devkit/mraa.git"
},
"keywords": [
"mraa",
"iot",
"intel",
"libmraa",
"test",
"galileo",
"edison"
],
"author": "David A Antler <david.a.antler@intel.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/intel-iot-devkit/mraa/issues"
},
"homepage": "https://github.com/intel-iot-devkit/mraa#readme",
"devDependencies": {
"expect.js": "^0.3.1",
"grunt": "^1.0.1",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.4.5"
}
}

32
jsstub/test/index.js Normal file
View File

@@ -0,0 +1,32 @@
var expect = require('expect.js');
var m = require('../index');
var LightBulb = require('./lightbulb');
describe('LightBulb', function() {
/** Model the internal data of LightBulb as a buffer */
var bufferFullBrightness = new Buffer(
[ 'N', // Four bytes allocated for name
'a',
'm',
'e',
95 // One byte allocated for brightness. Stuff in '95' value!
]);
it('getBrightness() function should return 95', function() {
// Create a fake I2c bus based on the 'full brightness' data model
var testI2cBus = new m.I2c(0);
testI2cBus._setRegisterMapInternal(bufferFullBrightness);
// Create a new LightBulb that opens the testI2cBus, instead of a real
// mraa I2c bus.
var lightBulbI2c = new LightBulb(testI2cBus);
// presumably getBrightness will gather data from I2C and get '95'
var brightness = lightBulbI2c.getBrightness();
expect(brightness).to.be(95);
})
});

32
jsstub/test/lightbulb.js Normal file
View File

@@ -0,0 +1,32 @@
/**
* @fileoverview Implementation of a LightBulb class abstraction
*
*/
module.exports = (function() {
"use strict";
var m = require('../index');
/**
* Constructor for a new LightBulb
* @class LightBulb
*
* @classdesc This class abstracts access to the control and data registers
* on an imaginary lightbulb.
* @param {Object} A libmraa I2c object, initialized
*/
function LightBulb (i2cInterface) {
var self = this;
self._i2cInterface = i2cInterface;
self.getBrightness = function() {
// Presume our brightness data is one byte at offset 4
return self._i2cInterface.readReg(4);
}
return self;
}
return LightBulb;
})();

View File

@@ -9,6 +9,11 @@ if (FIRMATA)
add_subdirectory (firmata)
endif ()
if (ONEWIRE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DONEWIRE=1")
add_subdirectory (uart_ow)
endif ()
include_directories(
${mraa_LIB_INCLUDE_DIRS}
)
@@ -36,6 +41,7 @@ set (mraa_LIB_X86_SRCS_NOAUTO
${PROJECT_SOURCE_DIR}/src/x86/intel_sofia_3gr.c
${PROJECT_SOURCE_DIR}/src/x86/intel_cherryhills.c
${PROJECT_SOURCE_DIR}/src/x86/up.c
${PROJECT_SOURCE_DIR}/src/x86/intel_gt_tuchuck.c
)
message (STATUS "INFO - Adding support for platform ${MRAAPLATFORMFORCE}")
@@ -61,6 +67,8 @@ if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL")
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_cherryhills.c)
elseif (${MRAAPLATFORMFORCE} STREQUAL "MRAA_UP")
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/up.c)
elseif( ${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_GT_TUCHUCK")
set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_gt_tuchuck.c)
else ()
message (FATAL_ERROR "Unknown x86 platform enabled!")
endif ()
@@ -76,8 +84,27 @@ set (mraa_LIB_ARM_SRCS_NOAUTO
${PROJECT_SOURCE_DIR}/src/arm/banana.c
)
set (mraa_LIB_MOCK_SRCS_NOAUTO
${PROJECT_SOURCE_DIR}/src/mock/mock.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_gpio.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_aio.c
${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c
)
if (JSONPLAT)
find_package (JSON-C QUIET)
if (${JSON-C_FOUND})
set (mraa_LIB_SRCS_NOAUTO
${mraa_LIB_SRCS_NOAUTO}
${PROJECT_SOURCE_DIR}/src/json/jsonplatform.c
)
endif ()
endif ()
set (mraa_LIBS ${CMAKE_THREAD_LIBS_INIT})
if (X86PLAT)
add_subdirectory(x86)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DX86PLAT=1")
@@ -88,6 +115,14 @@ if (ARMPLAT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DARMPLAT=1")
endif()
if (MOCKPLAT)
add_subdirectory(mock)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMOCKPLAT=1")
if (MSYS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMSYS=1")
endif ()
endif()
if (USBPLAT)
message (STATUS "INFO - Adding USB platforms")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSBPLAT=1")
@@ -112,11 +147,24 @@ if (USBPLAT)
add_subdirectory(usb)
endif ()
if (IMRAA)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
find_package (JSON-C REQUIRED)
include_directories (${JSON-C_INCLUDE_DIR})
set (mraa_LIBS ${mraa_LIBS} ${JSON-C_LIBRARIES})
if (JSONPLAT OR IMRAA)
find_package (JSON-C QUIET)
if (NOT ${JSON-C_FOUND})
if (IMRAA)
message (FATAL_ERROR "Enabled IMRAA but JSON-C library not found")
elseif (JSONPLAT)
message (WARNING "Enabled JSONPLAT but JSON-C library not found: Ignoring JSONPLAT")
endif ()
else ()
if (JSONPLAT)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DJSONPLAT=1")
endif ()
if (IMRAA)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1")
endif ()
include_directories (${JSON-C_INCLUDE_DIR})
set (mraa_LIBS ${mraa_LIBS} ${JSON-C_LIBRARIES})
endif ()
endif ()
set (mraa_LIB_SRCS
@@ -137,7 +185,7 @@ macro (mraa_CREATE_INSTALL_PKGCONFIG generated_file install_location)
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
endmacro (mraa_CREATE_INSTALL_PKGCONFIG)
mraa_create_install_pkgconfig (mraa.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
mraa_create_install_pkgconfig (mraa.pc ${LIB_INSTALL_DIR}/pkgconfig)
if (DOXYGEN_FOUND)
@@ -188,6 +236,8 @@ if (BUILDSWIG)
add_subdirectory (python)
endif ()
if (BUILDSWIGJAVA)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
add_subdirectory (java)
endif ()
if (BUILDSWIGNODE)
@@ -208,4 +258,9 @@ set_target_properties(
SOVERSION ${mraa_VERSION_MAJOR}
VERSION ${mraa_VERSION_STRING}
)
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (MSYS)
# Under MSYS we have to put our generated DLL into bin, otherwise it's not picked up
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_BINDIR})
else ()
install(TARGETS mraa DESTINATION ${LIB_INSTALL_DIR})
endif ()

View File

@@ -56,7 +56,7 @@ aio_get_valid_fp(mraa_aio_context dev)
}
static mraa_aio_context
mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio)
mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio, unsigned int channel)
{
mraa_aio_context dev = calloc(1, sizeof(struct _aio));
if (dev == NULL) {
@@ -72,6 +72,8 @@ mraa_aio_init_internal(mraa_adv_func_t* func_table, int aio)
return NULL;
}
dev->channel = channel;
// Open valid analog input file and get the pointer.
if (MRAA_SUCCESS != aio_get_valid_fp(dev)) {
free(dev);
@@ -111,7 +113,7 @@ mraa_aio_init(unsigned int aio)
syslog(LOG_ERR, "aio: requested channel out of range");
return NULL;
}
if (board->pins[pin].capabilites.aio != 1) {
if (board->pins[pin].capabilities.aio != 1) {
syslog(LOG_ERR, "aio: pin %i not capable of aio", pin);
return NULL;
}
@@ -123,12 +125,11 @@ mraa_aio_init(unsigned int aio)
}
// Create ADC device connected to specified channel
mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio);
mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio, board->pins[pin].aio.pinmap);
if (dev == NULL) {
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel %d", aio);
return NULL;
}
dev->channel = board->pins[pin].aio.pinmap;
dev->value_bit = DEFAULT_BITS;
if (IS_FUNC_DEFINED(dev, aio_init_pre)) {
@@ -152,9 +153,14 @@ mraa_aio_init(unsigned int aio)
return dev;
}
unsigned int
int
mraa_aio_read(mraa_aio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "aio: read: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, aio_read_replace)) {
return dev->advance_func->aio_read_replace(dev);
}
@@ -165,7 +171,7 @@ mraa_aio_read(mraa_aio_context dev)
if (dev->adc_in_fp == -1) {
if (aio_get_valid_fp(dev) != MRAA_SUCCESS) {
syslog(LOG_ERR, "aio: Failed to get to the device");
return 0;
return -1;
}
}
@@ -182,8 +188,10 @@ mraa_aio_read(mraa_aio_context dev)
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
if (end == &buffer[0]) {
syslog(LOG_ERR, "aio: Value is not a decimal number");
return -1;
} else if (errno != 0) {
syslog(LOG_ERR, "aio: Errno was set");
return -1;
}
if (dev->value_bit != raw_bits) {
@@ -205,7 +213,7 @@ mraa_aio_read_float(mraa_aio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "aio: Device not valid");
return 0.0;
return -1.0;
}
float max_analog_value = (1 << dev->value_bit) - 1;
@@ -217,13 +225,22 @@ mraa_aio_read_float(mraa_aio_context dev)
mraa_result_t
mraa_aio_close(mraa_aio_context dev)
{
if (NULL != dev) {
if (dev->adc_in_fp != -1)
close(dev->adc_in_fp);
free(dev);
if (dev == NULL) {
syslog(LOG_ERR, "aio: close: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
return (MRAA_SUCCESS);
if (IS_FUNC_DEFINED(dev, aio_close_replace)) {
return dev->advance_func->aio_close_replace(dev);
}
if (dev->adc_in_fp != -1) {
close(dev->adc_in_fp);
}
free(dev);
return MRAA_SUCCESS;
}
mraa_result_t

View File

@@ -63,9 +63,9 @@ void mraa_96boards_pininfo(mraa_board_t* board, int index, int sysfs_pin,
vsnprintf(pininfo->name, MRAA_PIN_NAME_SIZE, fmt, arg_ptr);
va_end(arg_ptr);
if (sysfs_pin >= 0)
pininfo->capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
pininfo->capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
else
pininfo->capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
pininfo->capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
pininfo->gpio.pinmap = sysfs_pin;
pininfo->gpio.mux_total = 0;
}

View File

@@ -305,37 +305,37 @@ mraa_banana()
b->adv_func->gpio_mmap_setup = &mraa_banana_mmap_setup;
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[1].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[2].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (i2c2 == 1) {
strncpy(b->pins[3].name, "TWI2-SDA", MRAA_PIN_NAME_SIZE); // PB21 Pin53 TWI2-SDA
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
} else {
strncpy(b->pins[3].name, "PB21", MRAA_PIN_NAME_SIZE); // PB21 Pin53 TWI2-SDA
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[3].gpio.pinmap = 53;
strncpy(b->pins[4].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (i2c2 == 1) {
strncpy(b->pins[5].name, "TWI2-SCK", MRAA_PIN_NAME_SIZE); // PB20 Pin52 TWI2-SCK
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
} else {
strncpy(b->pins[5].name, "PB20", MRAA_PIN_NAME_SIZE); // PB20 Pin52 TWI2-SCK
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[5].gpio.pinmap = 52;
strncpy(b->pins[6].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (platform_detected == PLATFORM_BANANA_PRO) {
strncpy(b->pins[7].name, "PH02", MRAA_PIN_NAME_SIZE); // PH2 Pin226
@@ -344,7 +344,7 @@ mraa_banana()
strncpy(b->pins[7].name, "PI03", MRAA_PIN_NAME_SIZE); // PI3 Pin259 PWM
b->pins[7].gpio.pinmap = 259;
}
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
if (platform_detected == PLATFORM_BANANA_PRO) {
strncpy(b->pins[8].name, "UART4_TX", MRAA_PIN_NAME_SIZE); // PH4 Pin228 UART4_TX
@@ -353,10 +353,10 @@ mraa_banana()
strncpy(b->pins[8].name, "UART3_TX", MRAA_PIN_NAME_SIZE); // PH0 Pin224 UART3_TX
b->pins[8].gpio.pinmap = 224;
}
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
strncpy(b->pins[9].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (platform_detected == PLATFORM_BANANA_PRO) {
strncpy(b->pins[10].name, "UART4_RX", MRAA_PIN_NAME_SIZE); // PH5 Pin229 UART4_RX
@@ -365,10 +365,10 @@ mraa_banana()
strncpy(b->pins[10].name, "UART3_RX", MRAA_PIN_NAME_SIZE); // PH1 Pin225 UART3_RX
b->pins[10].gpio.pinmap = 225;
}
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
strncpy(b->pins[11].name, "PI19", MRAA_PIN_NAME_SIZE); // PI19 Pin275 IO+UART2_RX
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[11].gpio.pinmap = 275;
if (platform_detected == PLATFORM_BANANA_PRO) {
@@ -378,143 +378,143 @@ mraa_banana()
strncpy(b->pins[12].name, "PH02", MRAA_PIN_NAME_SIZE); // PH2 Pin226
b->pins[12].gpio.pinmap = 226;
}
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
strncpy(b->pins[13].name, "PI18", MRAA_PIN_NAME_SIZE); // PI18 Pin274 UART2_TX
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[13].gpio.pinmap = 274;
strncpy(b->pins[14].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[15].name, "PI17", MRAA_PIN_NAME_SIZE); // PI17 Pin273 UART2_CTS
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].gpio.pinmap = 273;
strncpy(b->pins[16].name, "PH20", MRAA_PIN_NAME_SIZE); // PH20 Pin 244 CAN_TX
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].gpio.pinmap = 244;
strncpy(b->pins[17].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[18].name, "PH21", MRAA_PIN_NAME_SIZE); // PH21 Pin245 CAN_RX
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].gpio.pinmap = 245;
strncpy(b->pins[19].name, "SPI0MOSI", MRAA_PIN_NAME_SIZE); // PI12 SPI0
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[19].gpio.pinmap = 268;
strncpy(b->pins[20].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[21].name, "SPI0MISO", MRAA_PIN_NAME_SIZE); // PI13 SPI0
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[21].gpio.pinmap = 269;
strncpy(b->pins[22].name, "PI16", MRAA_PIN_NAME_SIZE); // PI16 UART2_RTS
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[22].gpio.pinmap = 272;
strncpy(b->pins[23].name, "SPI0CLK", MRAA_PIN_NAME_SIZE); // PI11 SPI0
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[23].gpio.pinmap = 267;
strncpy(b->pins[24].name, "SPI0CS0", MRAA_PIN_NAME_SIZE); // PI10 SPI0
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[24].gpio.pinmap = 266;
strncpy(b->pins[25].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[26].name, "SPI0CS1", MRAA_PIN_NAME_SIZE); // PI14 SPI0
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[26].gpio.pinmap = 270;
if (platform_detected == PLATFORM_BANANA_PI) {
strncpy(b->pins[27].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[28].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[29].name, "PH05", MRAA_PIN_NAME_SIZE); // PH5
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 229;
strncpy(b->pins[30].name, "PI21", MRAA_PIN_NAME_SIZE); // PI21 UART7_RX
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[30].gpio.pinmap = 277;
strncpy(b->pins[31].name, "PH03", MRAA_PIN_NAME_SIZE); // PH3
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].gpio.pinmap = 227;
strncpy(b->pins[32].name, "PI20", MRAA_PIN_NAME_SIZE); // PI20 UART7_TX
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[32].gpio.pinmap = 276;
strncpy(b->pins[33].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
if (platform_detected == PLATFORM_BANANA_PRO) {
strncpy(b->pins[27].name, "HAT_SDA", MRAA_PIN_NAME_SIZE); // PI1 TWI3-SDA i2c3
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].gpio.pinmap = 257;
strncpy(b->pins[28].name, "HAT_SCK", MRAA_PIN_NAME_SIZE); // PI0 TWI3-SCK i2c3
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].gpio.pinmap = 256;
strncpy(b->pins[29].name, "PB03", MRAA_PIN_NAME_SIZE); // PB3 IR0_TX/SPDIF_MCLK
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 35;
strncpy(b->pins[30].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[31].name, "PI21", MRAA_PIN_NAME_SIZE); // PI21 UART7_RX
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[31].gpio.pinmap = 277;
strncpy(b->pins[32].name, "PI20", MRAA_PIN_NAME_SIZE); // PI20 UART7_TX
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[32].gpio.pinmap = 276;
strncpy(b->pins[33].name, "PB13", MRAA_PIN_NAME_SIZE); // PB13 SPDIF_D0
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].gpio.pinmap = 45;
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[35].name, "PB07", MRAA_PIN_NAME_SIZE); // PB07 I2S0_LRCK
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].gpio.pinmap = 39;
strncpy(b->pins[36].name, "PB06", MRAA_PIN_NAME_SIZE); // PB06 I2S0BCLK
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[36].gpio.pinmap = 38;
strncpy(b->pins[37].name, "PB05", MRAA_PIN_NAME_SIZE); // PB05 I2S0MCK
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[37].gpio.pinmap = 37;
strncpy(b->pins[38].name, "PB12", MRAA_PIN_NAME_SIZE); // PB12 I2S0_DI
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[38].gpio.pinmap = 44;
strncpy(b->pins[39].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[40].name, "PB08", MRAA_PIN_NAME_SIZE); // PB08 I2S0_DO0
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].gpio.pinmap = 40;
}
@@ -528,7 +528,7 @@ mraa_banana()
b->gpio_count = 0;
int i;
for (i = 0; i < b->phy_pin_count; i++) {
if (b->pins[i].capabilites.gpio) {
if (b->pins[i].capabilities.gpio) {
b->gpio_count++;
}
}

View File

@@ -64,7 +64,6 @@ static unsigned int mmap_count = 0;
mraa_result_t
mraa_beaglebone_mmap_write(mraa_gpio_context dev, int value)
{
volatile uint32_t* addr;
if (value) {
*(volatile uint32_t*) (mmap_gpio[dev->pin / 32] + AM335X_SET) = (uint32_t)(1 << (dev->pin % 32));
} else {
@@ -185,7 +184,6 @@ mraa_beaglebone_uart_init_pre(int index)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
sprintf(devpath, "/dev/ttyO%u", index + 1);
if (!mraa_file_exist(devpath)) {
@@ -218,7 +216,6 @@ mraa_beaglebone_spi_init_pre(int index)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
int deviceindex = 0;
@@ -273,10 +270,10 @@ mraa_beaglebone_i2c_init_pre(unsigned int bus)
{
mraa_result_t ret = MRAA_ERROR_NO_RESOURCES;
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
sprintf(devpath, "/dev/i2c-%u", plat->i2c_bus[bus].bus_id);
if (!mraa_file_exist(devpath)) {
syslog(LOG_INFO, "i2c: %s doesn't exist ", devpath);
capepath = mraa_file_unglob(SYSFS_DEVICES_CAPEMGR_SLOTS);
if (capepath == NULL) {
syslog(LOG_ERR, "i2c: Could not find CapeManager");
@@ -310,13 +307,12 @@ mraa_pwm_context
mraa_beaglebone_pwm_init_replace(int pin)
{
char devpath[MAX_SIZE];
char overlay[MAX_SIZE];
char* capepath = NULL;
if (plat == NULL) {
syslog(LOG_ERR, "pwm: Platform Not Initialised");
return NULL;
}
if (plat->pins[pin].capabilites.pwm != 1) {
if (plat->pins[pin].capabilities.pwm != 1) {
syslog(LOG_ERR, "pwm: pin not capable of pwm");
return NULL;
}
@@ -418,7 +414,7 @@ mraa_beaglebone()
else
i2c0_enabled = 0;
if (mraa_file_exist("/sys/class/i2c-dev/i2c-1"))
if (mraa_file_exist("/sys/class/i2c-dev/i2c-2"))
i2c1_enabled = 1;
else
i2c1_enabled = 0;
@@ -529,20 +525,20 @@ mraa_beaglebone()
b->adv_func->pwm_init_replace = &mraa_beaglebone_pwm_init_replace;
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[1].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[2].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (emmc_enabled == 1) {
strncpy(b->pins[3].name, "MMC1_D6", MRAA_PIN_NAME_SIZE);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[3].name, "GPIO38", MRAA_PIN_NAME_SIZE);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[3].gpio.pinmap = 38;
b->pins[3].gpio.parent_id = 0;
@@ -550,10 +546,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[4].name, "MMC1_D7", MRAA_PIN_NAME_SIZE);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[4].name, "GPIO39", MRAA_PIN_NAME_SIZE);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[4].gpio.pinmap = 39;
b->pins[4].gpio.parent_id = 0;
@@ -561,10 +557,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[5].name, "MMC1_D2", MRAA_PIN_NAME_SIZE);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[5].name, "GPIO34", MRAA_PIN_NAME_SIZE);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[5].gpio.pinmap = 34;
b->pins[5].gpio.parent_id = 0;
@@ -572,10 +568,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[6].name, "MMC1_D3", MRAA_PIN_NAME_SIZE);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[6].name, "GPIO35", MRAA_PIN_NAME_SIZE);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[6].gpio.pinmap = 35;
b->pins[6].gpio.parent_id = 0;
@@ -583,50 +579,50 @@ mraa_beaglebone()
// TODO TIMER4
strncpy(b->pins[7].name, "GPIO66", MRAA_PIN_NAME_SIZE);
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 66;
b->pins[7].gpio.parent_id = 0;
b->pins[7].gpio.mux_total = 0;
// TODO TIMER7
strncpy(b->pins[8].name, "GPIO67", MRAA_PIN_NAME_SIZE);
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 67;
b->pins[8].gpio.parent_id = 0;
b->pins[8].gpio.mux_total = 0;
// TODO TIMER5
strncpy(b->pins[9].name, "GPIO69", MRAA_PIN_NAME_SIZE);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 69;
b->pins[9].gpio.parent_id = 0;
b->pins[9].gpio.mux_total = 0;
// TODO TIMER6
strncpy(b->pins[10].name, "GPIO68", MRAA_PIN_NAME_SIZE);
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[10].gpio.pinmap = 68;
b->pins[10].gpio.parent_id = 0;
b->pins[10].gpio.mux_total = 0;
strncpy(b->pins[11].name, "GPIO45", MRAA_PIN_NAME_SIZE);
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].gpio.pinmap = 45;
b->pins[11].gpio.parent_id = 0;
b->pins[11].gpio.mux_total = 0;
strncpy(b->pins[12].name, "GPIO44", MRAA_PIN_NAME_SIZE);
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].gpio.pinmap = 44;
b->pins[12].gpio.parent_id = 0;
b->pins[12].gpio.mux_total = 0;
if (ehrpwm2b_enabled == 1) {
strncpy(b->pins[13].name, "EHRPWM2B", MRAA_PIN_NAME_SIZE);
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[13].name, "GPIO23", MRAA_PIN_NAME_SIZE);
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[13].gpio.pinmap = 23;
b->pins[13].gpio.parent_id = 0;
@@ -635,42 +631,42 @@ mraa_beaglebone()
b->pins[13].pwm.mux_total = 0;
strncpy(b->pins[14].name, "GPIO26", MRAA_PIN_NAME_SIZE);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[14].gpio.pinmap = 26;
b->pins[14].gpio.parent_id = 0;
b->pins[14].gpio.mux_total = 0;
strncpy(b->pins[15].name, "GPIO47", MRAA_PIN_NAME_SIZE);
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].gpio.pinmap = 47;
b->pins[15].gpio.parent_id = 0;
b->pins[15].gpio.mux_total = 0;
strncpy(b->pins[16].name, "GPIO46", MRAA_PIN_NAME_SIZE);
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].gpio.pinmap = 46;
b->pins[16].gpio.parent_id = 0;
b->pins[16].gpio.mux_total = 0;
// TODO PWM0_SYNCO
strncpy(b->pins[17].name, "GPIO27", MRAA_PIN_NAME_SIZE);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[17].gpio.pinmap = 27;
b->pins[17].gpio.parent_id = 0;
b->pins[17].gpio.mux_total = 0;
strncpy(b->pins[18].name, "GPIO65", MRAA_PIN_NAME_SIZE);
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].gpio.pinmap = 65;
b->pins[18].gpio.parent_id = 0;
b->pins[18].gpio.mux_total = 0;
if (ehrpwm2a_enabled == 1) {
strncpy(b->pins[19].name, "EHRPWM2A", MRAA_PIN_NAME_SIZE);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[19].name, "GPIO22", MRAA_PIN_NAME_SIZE);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[19].gpio.pinmap = 22;
b->pins[19].gpio.parent_id = 0;
@@ -680,10 +676,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[20].name, "MMC1_CMD", MRAA_PIN_NAME_SIZE);
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[20].name, "GPIO63", MRAA_PIN_NAME_SIZE);
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[20].gpio.pinmap = 63;
b->pins[20].gpio.parent_id = 0;
@@ -691,10 +687,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[21].name, "MMC1_CLK", MRAA_PIN_NAME_SIZE);
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[21].name, "GPIO62", MRAA_PIN_NAME_SIZE);
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[21].gpio.pinmap = 62;
b->pins[21].gpio.parent_id = 0;
@@ -702,10 +698,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[22].name, "MMC1_D5", MRAA_PIN_NAME_SIZE);
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[22].name, "GPIO37", MRAA_PIN_NAME_SIZE);
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[22].gpio.pinmap = 37;
b->pins[22].gpio.parent_id = 0;
@@ -713,10 +709,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[23].name, "MMC_D4", MRAA_PIN_NAME_SIZE);
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[23].name, "GPIO36", MRAA_PIN_NAME_SIZE);
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[23].gpio.pinmap = 36;
b->pins[23].gpio.parent_id = 0;
@@ -724,10 +720,10 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[24].name, "MMC_D1", MRAA_PIN_NAME_SIZE);
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[24].name, "GPIO33", MRAA_PIN_NAME_SIZE);
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[24].gpio.pinmap = 33;
b->pins[24].gpio.parent_id = 0;
@@ -735,27 +731,27 @@ mraa_beaglebone()
if (emmc_enabled == 1) {
strncpy(b->pins[25].name, "MMC1_D0", MRAA_PIN_NAME_SIZE);
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[25].name, "GPIO32", MRAA_PIN_NAME_SIZE);
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[25].gpio.pinmap = 32;
b->pins[25].gpio.parent_id = 0;
b->pins[25].gpio.mux_total = 0;
strncpy(b->pins[26].name, "GPIO61", MRAA_PIN_NAME_SIZE);
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[26].gpio.pinmap = 61;
b->pins[26].gpio.parent_id = 0;
b->pins[26].gpio.mux_total = 0;
if (hdmi_enabled == 1) {
strncpy(b->pins[27].name, "LCD_VSYNC", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[27].name, "GPIO86", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[27].gpio.pinmap = 86;
b->pins[27].gpio.parent_id = 0;
@@ -763,10 +759,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[28].name, "LCD_PCLK", MRAA_PIN_NAME_SIZE);
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[28].name, "GPIO88", MRAA_PIN_NAME_SIZE);
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[28].gpio.pinmap = 88;
b->pins[28].gpio.parent_id = 0;
@@ -774,10 +770,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[29].name, "LCD_HSYNC", MRAA_PIN_NAME_SIZE);
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[29].name, "GPIO87", MRAA_PIN_NAME_SIZE);
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[29].gpio.pinmap = 87;
b->pins[29].gpio.parent_id = 0;
@@ -785,10 +781,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[30].name, "LCD_AC_BIAS", MRAA_PIN_NAME_SIZE);
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[30].name, "GPIO89", MRAA_PIN_NAME_SIZE);
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[30].gpio.pinmap = 89;
b->pins[30].gpio.parent_id = 0;
@@ -796,11 +792,11 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[31].name, "LCD_D14", MRAA_PIN_NAME_SIZE);
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
// TODO UART5_CTS this is ignored when using ADAFRUIT
strncpy(b->pins[31].name, "GPIO10", MRAA_PIN_NAME_SIZE);
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[31].gpio.pinmap = 10;
b->pins[31].gpio.parent_id = 0;
@@ -809,11 +805,11 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[32].name, "LCD_D15", MRAA_PIN_NAME_SIZE);
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
// TODO UART5_RTS this is ignored when using ADAFRUIT
strncpy(b->pins[32].name, "GPIO11", MRAA_PIN_NAME_SIZE);
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[32].gpio.pinmap = 11;
b->pins[32].gpio.parent_id = 0;
@@ -822,11 +818,11 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[33].name, "LCD_D13", MRAA_PIN_NAME_SIZE);
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
// TODO UART4_RTS this is ignored when using ADAFRUIT
strncpy(b->pins[33].name, "GPIO9", MRAA_PIN_NAME_SIZE);
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[33].gpio.pinmap = 9;
b->pins[33].gpio.parent_id = 0;
@@ -836,10 +832,10 @@ mraa_beaglebone()
// TODO PWM_1B
if (hdmi_enabled == 1) {
strncpy(b->pins[34].name, "LCD_D11", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[34].name, "GPIO81", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[34].gpio.pinmap = 81;
b->pins[34].gpio.parent_id = 0;
@@ -847,11 +843,11 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[35].name, "LCD_D12", MRAA_PIN_NAME_SIZE);
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
// TODO UART4_CTS this is ignored when using ADAFRUIT
strncpy(b->pins[35].name, "GPIO8", MRAA_PIN_NAME_SIZE);
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[35].gpio.pinmap = 8;
b->pins[35].gpio.parent_id = 0;
@@ -861,10 +857,10 @@ mraa_beaglebone()
// TODO PWM_1A
if (hdmi_enabled == 1) {
strncpy(b->pins[36].name, "LCD_D10", MRAA_PIN_NAME_SIZE);
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[36].name, "GPIO80", MRAA_PIN_NAME_SIZE);
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[36].gpio.pinmap = 80;
b->pins[36].gpio.parent_id = 0;
@@ -872,17 +868,17 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[37].name, "LCD_D8", MRAA_PIN_NAME_SIZE);
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
if (uart5_enabled == 1) {
strncpy(b->pins[37].name, "UART5TX", MRAA_PIN_NAME_SIZE);
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[37].name, "GPIO78", MRAA_PIN_NAME_SIZE);
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
}
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[37].gpio.pinmap = 78;
b->pins[37].gpio.parent_id = 0;
b->pins[37].gpio.mux_total = 0;
@@ -890,15 +886,15 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[38].name, "LCD_D9", MRAA_PIN_NAME_SIZE);
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
// TODO UART5_RX
if (uart5_enabled == 1) {
strncpy(b->pins[38].name, "UART5RX", MRAA_PIN_NAME_SIZE);
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[38].name, "GPIO79", MRAA_PIN_NAME_SIZE);
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
}
b->pins[38].gpio.pinmap = 79;
@@ -908,10 +904,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[39].name, "LCD_D6", MRAA_PIN_NAME_SIZE);
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[39].name, "GPIO76", MRAA_PIN_NAME_SIZE);
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[39].gpio.pinmap = 76;
b->pins[39].gpio.parent_id = 0;
@@ -919,10 +915,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[40].name, "LCD_D7", MRAA_PIN_NAME_SIZE);
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[40].name, "GPIO77", MRAA_PIN_NAME_SIZE);
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[40].gpio.pinmap = 77;
b->pins[40].gpio.parent_id = 0;
@@ -930,10 +926,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[41].name, "LCD_D4", MRAA_PIN_NAME_SIZE);
b->pins[41].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[41].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[41].name, "GPIO74", MRAA_PIN_NAME_SIZE);
b->pins[41].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[41].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[41].gpio.pinmap = 74;
b->pins[41].gpio.parent_id = 0;
@@ -941,10 +937,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[42].name, "LCD_D5", MRAA_PIN_NAME_SIZE);
b->pins[42].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[42].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[42].name, "GPIO75", MRAA_PIN_NAME_SIZE);
b->pins[42].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[42].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[42].gpio.pinmap = 75;
b->pins[42].gpio.parent_id = 0;
@@ -952,10 +948,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[43].name, "LCD_D2", MRAA_PIN_NAME_SIZE);
b->pins[43].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[43].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[43].name, "GPIO72", MRAA_PIN_NAME_SIZE);
b->pins[43].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[43].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[43].gpio.pinmap = 72;
b->pins[43].gpio.parent_id = 0;
@@ -963,10 +959,10 @@ mraa_beaglebone()
if (hdmi_enabled == 1) {
strncpy(b->pins[44].name, "LCD_D3", MRAA_PIN_NAME_SIZE);
b->pins[44].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[44].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[44].name, "GPIO73", MRAA_PIN_NAME_SIZE);
b->pins[44].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[44].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
}
b->pins[44].gpio.pinmap = 73;
b->pins[44].gpio.parent_id = 0;
@@ -975,10 +971,10 @@ mraa_beaglebone()
// TODO PWM_2A
if (hdmi_enabled == 1) {
strncpy(b->pins[45].name, "LCD_D0", MRAA_PIN_NAME_SIZE);
b->pins[45].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[45].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[45].name, "GPIO70", MRAA_PIN_NAME_SIZE);
b->pins[45].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[45].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[45].gpio.pinmap = 70;
b->pins[45].gpio.parent_id = 0;
@@ -987,51 +983,51 @@ mraa_beaglebone()
// TODO PWM_2B
if (hdmi_enabled == 1) {
strncpy(b->pins[46].name, "LCD_D1", MRAA_PIN_NAME_SIZE);
b->pins[46].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[46].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[46].name, "GPIO71", MRAA_PIN_NAME_SIZE);
b->pins[46].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[46].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[46].gpio.pinmap = 71;
b->pins[46].gpio.parent_id = 0;
b->pins[46].gpio.mux_total = 0;
strncpy(b->pins[47].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[47].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[47].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[48].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[48].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[48].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[49].name, "3.3V", MRAA_PIN_NAME_SIZE);
b->pins[49].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[49].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[50].name, "3.3V", MRAA_PIN_NAME_SIZE);
b->pins[50].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[50].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[51].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[51].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[51].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[52].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[52].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[52].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[53].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[53].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[53].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[54].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[54].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[54].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[55].name, "PWR", MRAA_PIN_NAME_SIZE);
b->pins[55].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[55].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[56].name, "RESET", MRAA_PIN_NAME_SIZE);
b->pins[56].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[56].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
if (uart4_enabled == 1) {
strncpy(b->pins[57].name, "UART4_RX", MRAA_PIN_NAME_SIZE);
b->pins[57].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[57].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[57].name, "GPIO30", MRAA_PIN_NAME_SIZE);
b->pins[57].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[57].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
b->pins[57].gpio.pinmap = 30;
b->pins[57].gpio.parent_id = 0;
@@ -1039,17 +1035,17 @@ mraa_beaglebone()
b->pins[57].uart.mux_total = 0;
strncpy(b->pins[58].name, "GPIO60", MRAA_PIN_NAME_SIZE);
b->pins[58].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[58].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[58].gpio.pinmap = 60;
b->pins[58].gpio.parent_id = 0;
b->pins[58].gpio.mux_total = 0;
if (uart4_enabled == 1) {
strncpy(b->pins[59].name, "UART4_TX", MRAA_PIN_NAME_SIZE);
b->pins[59].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[59].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[59].name, "GPIO31", MRAA_PIN_NAME_SIZE);
b->pins[59].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[59].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
b->pins[59].gpio.pinmap = 31;
b->pins[59].gpio.parent_id = 0;
@@ -1058,10 +1054,10 @@ mraa_beaglebone()
if (ehrpwm1a_enabled == 1) {
strncpy(b->pins[60].name, "EHRPWM1A", MRAA_PIN_NAME_SIZE);
b->pins[60].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[60].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[60].name, "GPIO50", MRAA_PIN_NAME_SIZE);
b->pins[60].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[60].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[60].gpio.pinmap = 50;
b->pins[60].gpio.parent_id = 0;
@@ -1071,17 +1067,17 @@ mraa_beaglebone()
// TODO PWM_TRIP2_IN (not a PWM output, but used for sync cf ref. manual)
strncpy(b->pins[61].name, "GPIO48", MRAA_PIN_NAME_SIZE);
b->pins[61].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[61].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[61].gpio.pinmap = 48;
b->pins[61].gpio.parent_id = 0;
b->pins[61].gpio.mux_total = 0;
if (ehrpwm1b_enabled == 1) {
strncpy(b->pins[62].name, "EHRPWM1B", MRAA_PIN_NAME_SIZE);
b->pins[62].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[62].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
} else {
strncpy(b->pins[62].name, "GPIO51", MRAA_PIN_NAME_SIZE);
b->pins[62].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[62].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
}
b->pins[62].gpio.pinmap = 51;
b->pins[62].gpio.parent_id = 0;
@@ -1092,15 +1088,15 @@ mraa_beaglebone()
if ((i2c0_enabled == 1) || (spi0_enabled == 1)) {
if (i2c0_enabled == 1) {
strncpy(b->pins[63].name, "I2C1SCL", MRAA_PIN_NAME_SIZE);
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
}
if (spi0_enabled == 1) {
strncpy(b->pins[63].name, "SPI0CS0", MRAA_PIN_NAME_SIZE);
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[63].name, "GPIO4", MRAA_PIN_NAME_SIZE);
b->pins[63].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
b->pins[63].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
}
b->pins[63].gpio.pinmap = 4;
b->pins[63].gpio.parent_id = 0;
@@ -1111,15 +1107,15 @@ mraa_beaglebone()
if ((i2c0_enabled == 1) || (spi0_enabled == 1)) {
if (i2c0_enabled == 1) {
strncpy(b->pins[64].name, "I2C1SDA", MRAA_PIN_NAME_SIZE);
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
}
if (spi0_enabled == 1) {
strncpy(b->pins[64].name, "SPI0D1", MRAA_PIN_NAME_SIZE);
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[64].name, "GPIO5", MRAA_PIN_NAME_SIZE);
b->pins[64].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
b->pins[64].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 1, 0, 0 };
}
b->pins[64].gpio.pinmap = 5;
b->pins[64].gpio.parent_id = 0;
@@ -1127,26 +1123,26 @@ mraa_beaglebone()
b->pins[64].i2c.mux_total = 0;
b->pins[64].spi.mux_total = 0;
if (i2c0_enabled == 1) {
if (i2c1_enabled == 1) {
strncpy(b->pins[65].name, "I2C2SCL", MRAA_PIN_NAME_SIZE);
b->pins[65].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[65].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[65].i2c.mux_total = 0;
} else {
strncpy(b->pins[65].name, "GPIO13", MRAA_PIN_NAME_SIZE);
b->pins[65].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[65].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
}
b->pins[65].gpio.pinmap = 13;
b->pins[65].gpio.parent_id = 0;
b->pins[65].gpio.mux_total = 0;
b->pins[65].i2c.mux_total = 0;
if (i2c0_enabled == 1) {
if (i2c1_enabled == 1) {
strncpy(b->pins[66].name, "I2C2SDA", MRAA_PIN_NAME_SIZE);
b->pins[66].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[66].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[66].i2c.mux_total = 0;
} else {
strncpy(b->pins[66].name, "GPIO12", MRAA_PIN_NAME_SIZE);
b->pins[66].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[66].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
}
b->pins[66].gpio.pinmap = 12;
b->pins[66].gpio.parent_id = 0;
@@ -1156,19 +1152,19 @@ mraa_beaglebone()
if ((spi0_enabled == 1) || uart2_enabled == 1 || ehrpwm0b_enabled == 1) {
if (uart2_enabled == 1) {
strncpy(b->pins[67].name, "UART2_TX", MRAA_PIN_NAME_SIZE);
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 };
}
if (spi0_enabled == 1) {
strncpy(b->pins[67].name, "SPI0D0", MRAA_PIN_NAME_SIZE);
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
}
if (ehrpwm0b_enabled == 1) {
strncpy(b->pins[67].name, "EHRPWM0B", MRAA_PIN_NAME_SIZE);
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
}
} else {
strncpy(b->pins[67].name, "GPIO3", MRAA_PIN_NAME_SIZE);
b->pins[67].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
b->pins[67].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
}
b->pins[67].gpio.pinmap = 3;
b->pins[67].gpio.parent_id = 0;
@@ -1181,19 +1177,19 @@ mraa_beaglebone()
if ((spi0_enabled == 1) || uart2_enabled == 1 || ehrpwm0a_enabled == 1) {
if (uart2_enabled == 1) {
strncpy(b->pins[68].name, "UART2_RX", MRAA_PIN_NAME_SIZE);
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 1 };
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 1 };
}
if (spi0_enabled == 1) {
strncpy(b->pins[68].name, "SPI0CLK", MRAA_PIN_NAME_SIZE);
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
}
if (ehrpwm0a_enabled == 1) {
strncpy(b->pins[68].name, "EHRPWM0A", MRAA_PIN_NAME_SIZE);
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
}
} else {
strncpy(b->pins[68].name, "GPIO2", MRAA_PIN_NAME_SIZE);
b->pins[68].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
b->pins[68].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 1 };
}
b->pins[68].gpio.pinmap = 2;
b->pins[68].gpio.parent_id = 0;
@@ -1205,17 +1201,17 @@ mraa_beaglebone()
// TODO PWM0_SYNCO ?? PWM
strncpy(b->pins[69].name, "GPIO49", MRAA_PIN_NAME_SIZE);
b->pins[69].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[69].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[69].gpio.pinmap = 49;
b->pins[69].gpio.parent_id = 0;
b->pins[69].gpio.mux_total = 0;
if (uart1_enabled == 1) {
strncpy(b->pins[70].name, "UART1_RX", MRAA_PIN_NAME_SIZE);
b->pins[70].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[70].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[70].name, "GPIO15", MRAA_PIN_NAME_SIZE);
b->pins[70].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[70].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
b->pins[70].gpio.pinmap = 15;
b->pins[70].gpio.parent_id = 0;
@@ -1223,26 +1219,26 @@ mraa_beaglebone()
b->pins[70].uart.mux_total = 0;
strncpy(b->pins[71].name, "GPIO117", MRAA_PIN_NAME_SIZE);
b->pins[71].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[71].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[71].gpio.pinmap = 117;
b->pins[71].gpio.parent_id = 0;
b->pins[71].gpio.mux_total = 0;
if (uart1_enabled == 1) {
strncpy(b->pins[72].name, "UART1_RX", MRAA_PIN_NAME_SIZE);
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
} else {
strncpy(b->pins[72].name, "GPIO14", MRAA_PIN_NAME_SIZE);
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
}
b->pins[72].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[72].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[72].gpio.pinmap = 14;
b->pins[72].gpio.parent_id = 0;
b->pins[72].gpio.mux_total = 0;
b->pins[72].uart.mux_total = 0;
strncpy(b->pins[73].name, "GPIO115", MRAA_PIN_NAME_SIZE);
b->pins[73].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[73].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[73].gpio.pinmap = 115;
b->pins[73].gpio.parent_id = 0;
b->pins[73].gpio.mux_total = 0;
@@ -1250,14 +1246,14 @@ mraa_beaglebone()
if (emmc_enabled != 1) {
if (spi1_enabled == 1) {
strncpy(b->pins[74].name, "SPI1CS0", MRAA_PIN_NAME_SIZE);
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
} else {
strncpy(b->pins[74].name, "GPIO113", MRAA_PIN_NAME_SIZE);
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[74].name, "MCASP0XX", MRAA_PIN_NAME_SIZE);
b->pins[74].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[74].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
}
b->pins[74].gpio.pinmap = 113;
b->pins[74].gpio.parent_id = 0;
@@ -1267,14 +1263,14 @@ mraa_beaglebone()
if (emmc_enabled != 1) {
if (spi1_enabled == 1) {
strncpy(b->pins[75].name, "SPI1D0", MRAA_PIN_NAME_SIZE);
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
} else {
strncpy(b->pins[75].name, "GPIO111", MRAA_PIN_NAME_SIZE);
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[75].name, "MMC1_SD", MRAA_PIN_NAME_SIZE);
b->pins[75].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[75].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
b->pins[75].gpio.pinmap = 111;
b->pins[75].gpio.parent_id = 0;
@@ -1284,14 +1280,14 @@ mraa_beaglebone()
if (emmc_enabled != 1) {
if (spi1_enabled == 1) {
strncpy(b->pins[76].name, "SPI1D1", MRAA_PIN_NAME_SIZE);
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
} else {
strncpy(b->pins[76].name, "GPIO112", MRAA_PIN_NAME_SIZE);
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[76].name, "MMC2_SD", MRAA_PIN_NAME_SIZE);
b->pins[76].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[76].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
b->pins[76].gpio.pinmap = 112;
b->pins[76].gpio.parent_id = 0;
@@ -1301,14 +1297,14 @@ mraa_beaglebone()
if (emmc_enabled != 1) {
if (spi1_enabled == 1) {
strncpy(b->pins[77].name, "SPI1CLK", MRAA_PIN_NAME_SIZE);
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
} else {
strncpy(b->pins[77].name, "GPIO110", MRAA_PIN_NAME_SIZE);
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
}
} else {
strncpy(b->pins[77].name, "MMC0_SD", MRAA_PIN_NAME_SIZE);
b->pins[77].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[77].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
b->pins[77].gpio.pinmap = 110;
b->pins[77].gpio.parent_id = 0;
@@ -1317,60 +1313,60 @@ mraa_beaglebone()
strncpy(b->pins[78].name, "VDD_ADC", MRAA_PIN_NAME_SIZE);
b->pins[78].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[78].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// TODO AIN4
strncpy(b->pins[79].name, "AIN4", MRAA_PIN_NAME_SIZE);
b->pins[79].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[79].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
strncpy(b->pins[80].name, "GND_ADC", MRAA_PIN_NAME_SIZE);
b->pins[80].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[80].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// TODO AIN6
strncpy(b->pins[81].name, "AIN6", MRAA_PIN_NAME_SIZE);
b->pins[81].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[81].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
// TODO AIN5
strncpy(b->pins[82].name, "AIN5", MRAA_PIN_NAME_SIZE);
b->pins[82].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[82].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
// TODO AIN2
strncpy(b->pins[83].name, "AIN2", MRAA_PIN_NAME_SIZE);
b->pins[83].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[83].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
// TODO AIN3
strncpy(b->pins[84].name, "AIN3", MRAA_PIN_NAME_SIZE);
b->pins[84].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[84].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
// TODO AIN0
strncpy(b->pins[85].name, "AIN0", MRAA_PIN_NAME_SIZE);
b->pins[85].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[85].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
// TODO AIN1
strncpy(b->pins[86].name, "AIN1", MRAA_PIN_NAME_SIZE);
b->pins[86].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[86].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
strncpy(b->pins[87].name, "GPIO20", MRAA_PIN_NAME_SIZE);
b->pins[87].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[87].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[87].gpio.pinmap = 20;
b->pins[87].gpio.parent_id = 0;
b->pins[87].gpio.mux_total = 0;
strncpy(b->pins[88].name, "GPIO7", MRAA_PIN_NAME_SIZE);
b->pins[88].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[88].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[88].gpio.pinmap = 7;
b->pins[88].gpio.parent_id = 0;
b->pins[88].gpio.mux_total = 0;
// GND
strncpy(b->pins[89].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[89].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[89].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// GND
strncpy(b->pins[90].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[90].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[90].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// GND
strncpy(b->pins[91].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[91].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[91].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// GND
strncpy(b->pins[92].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[92].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[92].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
// BUS DEFINITIONS
b->i2c_bus_count = 2;
@@ -1380,7 +1376,7 @@ mraa_beaglebone()
b->i2c_bus[0].sda = 46 + 18;
b->i2c_bus[0].scl = 46 + 17;
b->i2c_bus[1].bus_id = 1;
b->i2c_bus[1].bus_id = 2;
b->i2c_bus[1].sda = 46 + 20;
b->i2c_bus[1].scl = 46 + 19;
@@ -1421,7 +1417,7 @@ mraa_beaglebone()
b->gpio_count = 0;
int i;
for (i = 0; i < b->phy_pin_count; i++)
if (b->pins[i].capabilites.gpio)
if (b->pins[i].capabilities.gpio)
b->gpio_count++;
return b;

View File

@@ -292,63 +292,63 @@ mraa_raspberry_pi()
b->adv_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup;
strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
b->pins[0].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[1].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[2].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[3].name, "SDA0", MRAA_PIN_NAME_SIZE);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[3].gpio.pinmap = 2;
b->pins[3].gpio.mux_total = 0;
b->pins[3].i2c.pinmap = 0;
b->pins[3].i2c.mux_total = 0;
strncpy(b->pins[4].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[5].name, "SCL0", MRAA_PIN_NAME_SIZE);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[5].gpio.pinmap = 3;
b->pins[5].gpio.mux_total = 0;
b->pins[5].i2c.pinmap = 0;
b->pins[5].i2c.mux_total = 0;
strncpy(b->pins[6].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[7].name, "GPIO4", MRAA_PIN_NAME_SIZE);
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 4;
b->pins[7].gpio.mux_total = 0;
strncpy(b->pins[8].name, "UART_TX", MRAA_PIN_NAME_SIZE);
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[8].gpio.pinmap = 14;
b->pins[8].gpio.mux_total = 0;
b->pins[8].uart.parent_id = 0;
b->pins[8].uart.mux_total = 0;
strncpy(b->pins[9].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[10].name, "UART_RX", MRAA_PIN_NAME_SIZE);
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[10].gpio.pinmap = 15;
b->pins[10].gpio.mux_total = 0;
b->pins[10].uart.parent_id = 0;
b->pins[10].uart.mux_total = 0;
strncpy(b->pins[11].name, "GPIO17", MRAA_PIN_NAME_SIZE);
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].gpio.pinmap = 17;
b->pins[11].gpio.mux_total = 0;
strncpy(b->pins[12].name, "GPIO18", MRAA_PIN_NAME_SIZE);
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].gpio.pinmap = 18;
b->pins[12].gpio.mux_total = 0;
@@ -359,71 +359,71 @@ mraa_raspberry_pi()
strncpy(b->pins[13].name, "GPIO27", MRAA_PIN_NAME_SIZE);
b->pins[13].gpio.pinmap = 27;
}
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[13].gpio.mux_total = 0;
strncpy(b->pins[14].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[15].name, "GPIO22", MRAA_PIN_NAME_SIZE);
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].gpio.pinmap = 22;
b->pins[15].gpio.mux_total = 0;
strncpy(b->pins[16].name, "GPIO23", MRAA_PIN_NAME_SIZE);
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].gpio.pinmap = 23;
b->pins[16].gpio.mux_total = 0;
strncpy(b->pins[17].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[18].name, "GPIO24", MRAA_PIN_NAME_SIZE);
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].gpio.pinmap = 24;
b->pins[18].gpio.mux_total = 0;
strncpy(b->pins[19].name, "SPI_MOSI", MRAA_PIN_NAME_SIZE);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[19].gpio.pinmap = 10;
b->pins[19].gpio.mux_total = 0;
b->pins[19].spi.pinmap = 0;
b->pins[19].spi.mux_total = 0;
strncpy(b->pins[20].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[20].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[21].name, "SPI_MISO", MRAA_PIN_NAME_SIZE);
b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[21].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[21].gpio.pinmap = 9;
b->pins[21].gpio.mux_total = 0;
b->pins[21].spi.pinmap = 0;
b->pins[21].spi.mux_total = 0;
strncpy(b->pins[22].name, "GPIO25", MRAA_PIN_NAME_SIZE);
b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[22].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[22].gpio.pinmap = 25;
b->pins[22].gpio.mux_total = 0;
strncpy(b->pins[23].name, "SPI_CLK", MRAA_PIN_NAME_SIZE);
b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[23].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[23].gpio.pinmap = 11;
b->pins[23].gpio.mux_total = 0;
b->pins[23].spi.pinmap = 0;
b->pins[23].spi.mux_total = 0;
strncpy(b->pins[24].name, "SPI_CS0", MRAA_PIN_NAME_SIZE);
b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[24].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[24].gpio.pinmap = 8;
b->pins[24].gpio.mux_total = 0;
b->pins[24].spi.pinmap = 0;
b->pins[24].spi.mux_total = 0;
strncpy(b->pins[25].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[25].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[26].name, "SPI_CS1", MRAA_PIN_NAME_SIZE);
b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[26].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[26].gpio.pinmap = 7;
b->pins[26].gpio.mux_total = 0;
b->pins[26].spi.pinmap = 0;
@@ -432,36 +432,36 @@ mraa_raspberry_pi()
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_REV_2) ||
(platform_detected == PLATFORM_RASPBERRY_PI_B_REV_2)) {
strncpy(b->pins[27].name, "5V", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[28].name, "3V3", MRAA_PIN_NAME_SIZE);
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[29].name, "GPIO8", MRAA_PIN_NAME_SIZE);
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 8;
b->pins[29].gpio.mux_total = 0;
strncpy(b->pins[30].name, "GPIO9", MRAA_PIN_NAME_SIZE);
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[30].gpio.pinmap = 9;
b->pins[30].gpio.mux_total = 0;
strncpy(b->pins[31].name, "GPIO10", MRAA_PIN_NAME_SIZE);
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].gpio.pinmap = 10;
b->pins[31].gpio.mux_total = 0;
strncpy(b->pins[32].name, "GPIO11", MRAA_PIN_NAME_SIZE);
b->pins[32].gpio.pinmap = 11;
b->pins[32].gpio.mux_total = 0;
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[33].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
// BUS DEFINITIONS
@@ -493,62 +493,62 @@ mraa_raspberry_pi()
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
strncpy(b->pins[27].name, "ID_SD", MRAA_PIN_NAME_SIZE);
b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[27].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[28].name, "ID_SC", MRAA_PIN_NAME_SIZE);
b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[28].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[29].name, "GPIO05", MRAA_PIN_NAME_SIZE);
b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 5;
b->pins[29].gpio.mux_total = 0;
strncpy(b->pins[30].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[30].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[31].name, "GPIO06", MRAA_PIN_NAME_SIZE);
b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].gpio.pinmap = 6;
b->pins[31].gpio.mux_total = 0;
strncpy(b->pins[32].name, "GPIO12", MRAA_PIN_NAME_SIZE);
b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[32].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[32].gpio.pinmap = 12;
b->pins[32].gpio.mux_total = 0;
strncpy(b->pins[33].name, "GPIO13", MRAA_PIN_NAME_SIZE);
b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].gpio.pinmap = 13;
b->pins[33].gpio.mux_total = 0;
strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[34].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[35].name, "GPIO19", MRAA_PIN_NAME_SIZE);
b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].gpio.pinmap = 19;
b->pins[35].gpio.mux_total = 0;
strncpy(b->pins[36].name, "GPIO16", MRAA_PIN_NAME_SIZE);
b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[36].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[36].gpio.pinmap = 16;
b->pins[36].gpio.mux_total = 0;
strncpy(b->pins[37].name, "GPIO26", MRAA_PIN_NAME_SIZE);
b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[37].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[37].gpio.pinmap = 26;
b->pins[37].gpio.mux_total = 0;
strncpy(b->pins[38].name, "GPIO20", MRAA_PIN_NAME_SIZE);
b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[38].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[38].gpio.pinmap = 20;
b->pins[38].gpio.mux_total = 0;
strncpy(b->pins[39].name, "GND", MRAA_PIN_NAME_SIZE);
b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
b->pins[39].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[40].name, "GPIO21", MRAA_PIN_NAME_SIZE);
b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].gpio.pinmap = 21;
b->pins[40].gpio.mux_total = 0;
}
@@ -556,7 +556,7 @@ mraa_raspberry_pi()
b->gpio_count = 0;
int i;
for (i = 0; i < b->phy_pin_count; i++) {
if (b->pins[i].capabilites.gpio) {
if (b->pins[i].capabilities.gpio) {
b->gpio_count++;
}
}

View File

@@ -191,7 +191,7 @@ mraa_firmata_i2c_wait(int addr, int reg)
return MRAA_SUCCESS;
}
static uint8_t
static int
mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
{
if (mraa_firmata_send_i2c_read_req(dev, 1) == MRAA_SUCCESS) {
@@ -199,10 +199,10 @@ mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
return firmata_dev->i2cmsg[dev->addr][0];
}
}
return 0;
return -1;
}
static uint16_t
static int
mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 2) == MRAA_SUCCESS) {
@@ -215,10 +215,10 @@ mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
data = (data << 8) & 0xFF00;
data |= high;
return data;
return (int) data;
}
}
}
return 0;
return -1;
}
static int
@@ -249,16 +249,16 @@ mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return 0;
}
static uint8_t
static int
mraa_firmata_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 1) == MRAA_SUCCESS) {
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
return firmata_dev->i2cmsg[dev->addr][command];
return (int) firmata_dev->i2cmsg[dev->addr][command];
}
}
return 0;
return -1;
}
static mraa_result_t
@@ -340,17 +340,20 @@ mraa_firmata_i2c_stop(mraa_i2c_context dev)
return MRAA_SUCCESS;
}
static unsigned int
static int
mraa_firmata_aio_read(mraa_aio_context dev)
{
// careful, whilst you need to enable '0' for A0 you then need to read 14
// in t_firmata because well that makes sense doesn't it...
return (unsigned int) firmata_dev->pins[dev->channel].value;
return (int) firmata_dev->pins[dev->channel].value;
}
static mraa_result_t
mraa_firmata_aio_init_internal_replace(mraa_aio_context dev, int aio)
{
// set the channel, since we override internal it's never set
// offset by 14 because it makes total logical sense.
dev->channel = aio + 14;
// firmata considers A0 pin0 as well as actual pin0 :/
firmata_pinMode(firmata_dev, aio, MODE_ANALOG);
// register for updates on that ADC channel
@@ -568,69 +571,69 @@ mraa_firmata_plat_init(const char* uart_dev)
}
strncpy(b->pins[0].name, "IO0", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[0].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[0].gpio.pinmap = 0;
strncpy(b->pins[1].name, "IO1", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[1].gpio.pinmap = 1;
strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[2].gpio.pinmap = 2;
strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[3].gpio.pinmap = 3;
strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 4;
strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[5].gpio.pinmap = 5;
strncpy(b->pins[6].name, "IO6", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].gpio.pinmap = 6;
strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 7;
strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 8;
strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].capabilities = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 9;
strncpy(b->pins[10].name, "IO10", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[10].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[10].gpio.pinmap = 10;
strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].gpio.pinmap = 11;
strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].gpio.pinmap = 12;
strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[13].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[13].gpio.pinmap = 13;
strncpy(b->pins[10].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].gpio.pinmap = 14;
b->pins[14].aio.pinmap = 14;
strncpy(b->pins[11].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].gpio.pinmap = 15;
b->pins[15].aio.pinmap = 15;
strncpy(b->pins[12].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].gpio.pinmap = 16;
b->pins[16].aio.pinmap = 16;
strncpy(b->pins[13].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].gpio.pinmap = 17;
b->pins[17].aio.pinmap = 17;
strncpy(b->pins[13].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[18].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[18].gpio.pinmap = 18;
b->pins[18].aio.pinmap = 18;
strncpy(b->pins[13].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[19].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[19].gpio.pinmap = 19;
b->pins[19].aio.pinmap = 19;

View File

@@ -34,6 +34,7 @@
#include <signal.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <errno.h>
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
#define MAX_SIZE 64
@@ -46,6 +47,7 @@ mraa_gpio_get_valfp(mraa_gpio_context dev)
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
dev->value_fp = open(bu, O_RDWR);
if (dev->value_fp == -1) {
syslog(LOG_ERR, "gpio%i: Failed to open 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -64,7 +66,7 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
mraa_gpio_context dev = (mraa_gpio_context) calloc(1, sizeof(struct _gpio));
if (dev == NULL) {
syslog(LOG_CRIT, "gpio: Failed to allocate memory for context");
syslog(LOG_CRIT, "gpio%i: Failed to allocate memory for context", pin);
return NULL;
}
@@ -102,15 +104,15 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
} else {
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
if (export == -1) {
syslog(LOG_ERR, "gpio: Failed to open export for writing");
status = MRAA_ERROR_NO_RESOURCES;
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s", pin, strerror(errno));
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(export, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write %d to export", dev->pin);
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s", pin, strerror(errno));
close(export);
status = MRAA_ERROR_NO_RESOURCES;
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
dev->owner = 1;
@@ -131,38 +133,37 @@ mraa_gpio_init(int pin)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "gpio: platform not initialised");
syslog(LOG_ERR, "gpio%i: init: platform not initialised", pin);
return NULL;
}
if (mraa_is_sub_platform_id(pin)) {
syslog(LOG_NOTICE, "gpio: Using sub platform");
syslog(LOG_NOTICE, "gpio%i: init: Using sub platform", pin);
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "gpio: Sub platform Not Initialised");
syslog(LOG_ERR, "gpio%i: init: Sub platform not initialised", pin);
return NULL;
}
pin = mraa_get_sub_platform_index(pin);
}
if (pin < 0 || pin >= board->phy_pin_count) {
syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin);
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)", pin, board->phy_pin_count);
return NULL;
}
if (board->pins[pin].capabilites.gpio != 1) {
syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin);
if (board->pins[pin].capabilities.gpio != 1) {
syslog(LOG_ERR, "gpio: init: pin %i not capable of gpio", pin);
return NULL;
}
if (board->pins[pin].gpio.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pin].gpio) != MRAA_SUCCESS) {
syslog(LOG_ERR, "gpio: unable to setup muxes");
syslog(LOG_ERR, "gpio%i: init: unable to setup muxes", pin);
return NULL;
}
}
mraa_gpio_context r = mraa_gpio_init_internal(board->adv_func, board->pins[pin].gpio.pinmap);
if (r == NULL) {
syslog(LOG_CRIT, "gpio: mraa_gpio_init_raw(%d) returned error", pin);
return NULL;
}
if (r->phy_pin == -1)
@@ -199,12 +200,12 @@ mraa_gpio_wait_interrupt(int fd
struct pollfd pfd[2];
if (control_fd < 0) {
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
#endif
if (fd < 0) {
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
// setup poll on POLLPRI
@@ -218,14 +219,14 @@ mraa_gpio_wait_interrupt(int fd
#ifdef HAVE_PTHREAD_CANCEL
// Wait for it forever or until pthread_cancel
// poll is a cancelable point like sleep()
int x = poll(pfd, 1, -1);
poll(pfd, 1, -1);
#else
// setup poll on the controling fd
pfd[1].fd = control_fd;
pfd[1].events = 0; // POLLHUP, POLLERR, and POLLNVAL
// Wait for it forever or until control fd is closed
int x = poll(pfd, 2, -1);
poll(pfd, 2, -1);
#endif
// do a final read to clear interrupt
@@ -250,14 +251,14 @@ mraa_gpio_interrupt_handler(void* arg)
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
fp = open(bu, O_RDONLY);
if (fp < 0) {
syslog(LOG_ERR, "gpio: failed to open gpio%d/value", dev->pin);
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to open 'value' : %s", dev->pin, strerror(errno));
return NULL;
}
}
#ifndef HAVE_PTHREAD_CANCEL
if (pipe(dev->isr_control_pipe)) {
syslog(LOG_ERR, "gpio: failed to create isr control pipe");
syslog(LOG_ERR, "gpio%i: interrupt_handler: failed to create isr control pipe: %s", dev->pin, strerror(errno));
close(fp);
return NULL;
}
@@ -322,7 +323,12 @@ mraa_gpio_interrupt_handler(void* arg)
mraa_result_t
mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
{
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
if (dev == NULL) {
syslog(LOG_ERR, "gpio: edge_mode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_edge_mode_replace))
return dev->advance_func->gpio_edge_mode_replace(dev, mode);
if (dev->value_fp != -1) {
@@ -335,7 +341,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
int edge = open(filepath, O_RDWR);
if (edge == -1) {
syslog(LOG_ERR, "gpio: Failed to open edge for writing");
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to open 'edge' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -359,9 +365,9 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
if (write(edge, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to edge");
syslog(LOG_ERR, "gpio%i: edge_mode: Failed to write to 'edge': %s", dev->pin, strerror(errno));
close(edge);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(edge);
@@ -371,13 +377,23 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
mraa_result_t
mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: isr: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_isr_replace)) {
return dev->advance_func->gpio_isr_replace(dev, mode, fptr, args);
}
// we only allow one isr per mraa_gpio_context
if (dev->thread_id != 0) {
return MRAA_ERROR_NO_RESOURCES;
}
if (MRAA_SUCCESS != mraa_gpio_edge_mode(dev, mode)) {
return MRAA_ERROR_UNSPECIFIED;
mraa_result_t ret = mraa_gpio_edge_mode(dev, mode);
if (ret != MRAA_SUCCESS) {
return ret;
}
dev->isr = fptr;
@@ -401,6 +417,14 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
{
mraa_result_t ret = MRAA_SUCCESS;
if (dev == NULL) {
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_isr_exit_replace)) {
return dev->advance_func->gpio_isr_exit_replace(dev);
}
// wasting our time, there is no isr to exit from
if (dev->thread_id == 0 && dev->isr_value_fp == -1) {
return ret;
@@ -414,12 +438,12 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
if ((dev->thread_id != 0)) {
#ifdef HAVE_PTHREAD_CANCEL
if ((pthread_cancel(dev->thread_id) != 0) || (pthread_join(dev->thread_id, NULL) != 0)) {
ret = MRAA_ERROR_INVALID_HANDLE;
ret = MRAA_ERROR_INVALID_RESOURCE;
}
#else
close(dev->isr_control_pipe[1]);
if (pthread_join(dev->thread_id, NULL) != 0)
ret = MRAA_ERROR_INVALID_HANDLE;
ret = MRAA_ERROR_INVALID_RESOURCE;
close(dev->isr_control_pipe[0]);
dev->isr_control_pipe[0] = dev->isr_control_pipe[1] = -1;
@@ -429,7 +453,7 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
// close the filehandle in case it's still open
if (dev->isr_value_fp != -1) {
if (close(dev->isr_value_fp) != 0) {
ret = MRAA_ERROR_INVALID_PARAMETER;
ret = MRAA_ERROR_INVALID_RESOURCE;
}
}
@@ -443,6 +467,11 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
mraa_result_t
mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: mode: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_mode_replace))
return dev->advance_func->gpio_mode_replace(dev, mode);
@@ -462,7 +491,7 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
int drive = open(filepath, O_WRONLY);
if (drive == -1) {
syslog(LOG_ERR, "gpio: Failed to open drive for writing");
syslog(LOG_ERR, "gpio%i: mode: Failed to open 'drive' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -486,8 +515,8 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
if (write(drive, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to drive mode");
close(drive);
syslog(LOG_ERR, "gpio%i: mode: Failed to write to 'drive': %s", dev->pin, strerror(errno));
close(drive);
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -500,6 +529,11 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
mraa_result_t
mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: dir: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_dir_replace)) {
return dev->advance_func->gpio_dir_replace(dev, dir);
}
@@ -511,9 +545,6 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
}
}
if (dev == NULL) {
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->value_fp != -1) {
close(dev->value_fp);
dev->value_fp = -1;
@@ -532,8 +563,9 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
case MRAA_GPIO_OUT_LOW:
return mraa_gpio_write(dev, 0);
default:
syslog(LOG_ERR, "gpio%i: dir: Failed to open 'direction' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
}
}
char bu[MAX_SIZE];
@@ -558,7 +590,8 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
if (write(direction, bu, length * sizeof(char)) == -1) {
close(direction);
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: dir: Failed to write to 'direction': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
close(direction);
@@ -575,9 +608,24 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
int fd, rc;
mraa_result_t result = MRAA_SUCCESS;
if (dev == NULL) {
syslog(LOG_ERR, "gpio: read_dir: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dir == NULL) {
syslog(LOG_ERR, "gpio: read_dir: output parameter for dir is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_read_dir_replace)) {
return dev->advance_func->gpio_read_dir_replace(dev, dir);
}
snprintf(filepath, MAX_SIZE, SYSFS_CLASS_GPIO "/gpio%d/direction", dev->pin);
fd = open(filepath, O_RDONLY);
if (fd == -1) {
syslog(LOG_ERR, "gpio%i: read_dir: Failed to open 'direction' for reading: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -585,6 +633,7 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
rc = read(fd, value, sizeof(value));
close(fd);
if (rc <= 0) {
syslog(LOG_ERR, "gpio%i: read_dir: Failed to read 'direction': %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -593,7 +642,8 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
} else if (strcmp(value, "in\n") == 0) {
*dir = MRAA_GPIO_IN;
} else {
result = MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: read_dir: unknown direction: %s", dev->pin, value);
result = MRAA_ERROR_UNSPECIFIED;
}
return result;
@@ -602,8 +652,10 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
int
mraa_gpio_read(mraa_gpio_context dev)
{
if (dev == NULL)
if (dev == NULL) {
syslog(LOG_ERR, "gpio: read: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, gpio_read_replace))
return dev->advance_func->gpio_read_replace(dev);
@@ -613,7 +665,6 @@ mraa_gpio_read(mraa_gpio_context dev)
if (dev->value_fp == -1) {
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
syslog(LOG_ERR, "gpio: Failed to get value file pointer");
return -1;
}
} else {
@@ -622,7 +673,7 @@ mraa_gpio_read(mraa_gpio_context dev)
}
char bu[2];
if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) {
syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs");
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin, strerror(errno));
return -1;
}
lseek(dev->value_fp, 0, SEEK_SET);
@@ -633,8 +684,10 @@ mraa_gpio_read(mraa_gpio_context dev)
mraa_result_t
mraa_gpio_write(mraa_gpio_context dev, int value)
{
if (dev == NULL)
if (dev == NULL) {
syslog(LOG_ERR, "gpio: write: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->mmap_write != NULL)
return dev->mmap_write(dev, value);
@@ -656,13 +709,15 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
}
if (lseek(dev->value_fp, 0, SEEK_SET) == -1) {
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio%i: write: Failed to lseek 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", value);
if (write(dev->value_fp, bu, length * sizeof(char)) == -1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "gpio%i: write: Failed to write to 'value': %s", dev->pin, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
if (IS_FUNC_DEFINED(dev, gpio_write_post))
@@ -675,16 +730,16 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
{
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
if (unexport == -1) {
syslog(LOG_ERR, "gpio: Failed to open unexport for writing");
syslog(LOG_ERR, "gpio%i: Failed to open 'unexport' for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(unexport, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to unexport");
syslog(LOG_ERR, "gpio%i: Failed to write to 'unexport': %s", dev->pin, strerror(errno));
close(unexport);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(unexport);
@@ -694,10 +749,15 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
static mraa_result_t
mraa_gpio_unexport(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: unexport: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (dev->owner) {
return mraa_gpio_unexport_force(dev);
}
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
@@ -705,6 +765,11 @@ mraa_gpio_close(mraa_gpio_context dev)
{
mraa_result_t result = MRAA_SUCCESS;
if (dev == NULL) {
syslog(LOG_ERR, "gpio: close: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_close_replace)) {
return dev->advance_func->gpio_close_replace(dev);
}
@@ -726,9 +791,10 @@ mraa_result_t
mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
{
if (dev == NULL) {
return MRAA_ERROR_INVALID_RESOURCE;
syslog(LOG_ERR, "gpio: owner: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
syslog(LOG_DEBUG, "gpio: Set owner to %d", (int) own);
syslog(LOG_DEBUG, "gpio%i: owner: Set owner to %d", dev->pin, (int) own);
dev->owner = own;
return MRAA_SUCCESS;
}
@@ -736,11 +802,16 @@ mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
mraa_result_t
mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: use_mmaped: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, gpio_mmap_setup)) {
return dev->advance_func->gpio_mmap_setup(dev, mmap_en);
}
syslog(LOG_ERR, "gpio: mmap not implemented on this platform");
syslog(LOG_ERR, "gpio%i: use_mmaped: mmap not implemented on this platform", dev->pin);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
@@ -748,7 +819,7 @@ int
mraa_gpio_get_pin(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
return -1;
}
return dev->phy_pin;
@@ -758,7 +829,7 @@ int
mraa_gpio_get_pin_raw(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
syslog(LOG_ERR, "gpio: get_pin: context is invalid");
return -1;
}
return dev->pin;

View File

@@ -34,9 +34,13 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/errno.h>
#if defined(MSYS)
#define __USE_LINUX_IOCTL_DEFS
#endif
#include <sys/ioctl.h>
#include "linux/i2c-dev.h"
#include <errno.h>
#include <string.h>
typedef union i2c_smbus_data_union {
uint8_t byte; ///< data byte
@@ -78,7 +82,7 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
mraa_i2c_context dev = (mraa_i2c_context) calloc(1, sizeof(struct _i2c));
if (dev == NULL) {
syslog(LOG_CRIT, "i2c: Failed to allocate memory for context");
syslog(LOG_CRIT, "i2c%i_init: Failed to allocate memory for context", bus);
return NULL;
}
@@ -99,13 +103,13 @@ mraa_i2c_init_internal(mraa_adv_func_t* advance_func, unsigned int bus)
char filepath[32];
snprintf(filepath, 32, "/dev/i2c-%u", bus);
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
syslog(LOG_ERR, "i2c: Failed to open requested i2c port %s", filepath);
status = MRAA_ERROR_NO_RESOURCES;
syslog(LOG_ERR, "i2c%i_init: Failed to open requested i2c port %s: %s", bus, filepath, strerror(errno));
status = MRAA_ERROR_INVALID_RESOURCE;
goto init_internal_cleanup;
}
if (ioctl(dev->fh, I2C_FUNCS, &dev->funcs) < 0) {
syslog(LOG_CRIT, "i2c: Failed to get I2C_FUNC map from device");
syslog(LOG_CRIT, "i2c%i_init: Failed to get I2C_FUNC map from device: %s", bus, strerror(errno));
dev->funcs = 0;
}
}
@@ -133,39 +137,39 @@ mraa_i2c_init(int bus)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "i2c: Platform Not Initialised");
syslog(LOG_ERR, "i2c%i_init: Platform Not Initialised", bus);
return NULL;
}
if (mraa_is_sub_platform_id(bus)) {
syslog(LOG_NOTICE, "i2c: Using sub platform");
syslog(LOG_NOTICE, "i2c%i_init: Using sub platform", bus);
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "i2c: Sub platform Not Initialised");
syslog(LOG_ERR, "i2c%i_init: Sub platform Not Initialised", bus);
return NULL;
}
bus = mraa_get_sub_platform_index(bus);
}
syslog(LOG_NOTICE, "i2c: Selected bus %d", bus);
syslog(LOG_NOTICE, "i2c_init: Selected bus %d", bus);
if (board->i2c_bus_count == 0) {
syslog(LOG_ERR, "No i2c buses defined in platform");
syslog(LOG_ERR, "i2c_init: No i2c buses defined in platform");
return NULL;
}
if (bus >= board->i2c_bus_count) {
syslog(LOG_ERR, "Above i2c bus count");
syslog(LOG_ERR, "i2c_init: i2c%i over i2c bus count", bus);
return NULL;
}
if (board->i2c_bus[bus].bus_id == -1) {
syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
syslog(LOG_ERR, "Invalid i2c bus %i, moving to default i2c bus %i", bus, board->def_i2c_bus);
bus = board->def_i2c_bus;
}
if (!board->no_bus_mux) {
int pos = board->i2c_bus[bus].sda;
if (board->pins[pos].i2c.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
syslog(LOG_ERR, "i2c: Failed to set-up i2c sda multiplexer");
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c sda multiplexer", bus);
return NULL;
}
}
@@ -173,7 +177,7 @@ mraa_i2c_init(int bus)
pos = board->i2c_bus[bus].scl;
if (board->pins[pos].i2c.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) {
syslog(LOG_ERR, "i2c: Failed to set-up i2c scl multiplexer");
syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c scl multiplexer", bus);
return NULL;
}
}
@@ -193,6 +197,11 @@ mraa_i2c_init_raw(unsigned int bus)
mraa_result_t
mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: frequency: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_set_frequency_replace)) {
return dev->advance_func->i2c_set_frequency_replace(dev, mode);
}
@@ -202,6 +211,11 @@ mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
int
mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: read: context is invalid");
return -1;
}
int bytes_read = 0;
if (IS_FUNC_DEFINED(dev, i2c_read_replace)) {
bytes_read = dev->advance_func->i2c_read_replace(dev, data, length);
@@ -213,44 +227,59 @@ mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return length;
}
return 0;
return -1;
}
uint8_t
int
mraa_i2c_read_byte(mraa_i2c_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: read_byte: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, i2c_read_byte_replace))
return dev->advance_func->i2c_read_byte_replace(dev);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD, I2C_SMBUS_BYTE, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_byte: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0x0FF & d.byte;
}
uint8_t
int
mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: read_byte_data: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, i2c_read_byte_data_replace))
return dev->advance_func->i2c_read_byte_data_replace(dev, command);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_byte_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0x0FF & d.byte;
}
uint16_t
int
mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: read_word_data: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, i2c_read_word_data_replace))
return dev->advance_func->i2c_read_word_data_replace(dev, command);
i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return 0;
syslog(LOG_ERR, "i2c%i: read_word_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return 0xFFFF & d.word;
}
@@ -258,6 +287,11 @@ mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
int
mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: read_bytes_data: context is invalid");
return -1;
}
if (IS_FUNC_DEFINED(dev, i2c_read_bytes_data_replace))
return dev->advance_func->i2c_read_bytes_data_replace(dev, command, data, length);
struct i2c_rdwr_ioctl_data d;
@@ -266,21 +300,33 @@ mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, i
m[0].addr = dev->addr;
m[0].flags = 0x00;
m[0].len = 1;
m[0].buf = &command;
m[0].buf = (char*) &command;
m[1].addr = dev->addr;
m[1].flags = I2C_M_RD;
m[1].len = length;
m[1].buf = data;
m[1].buf = (char*) data;
d.msgs = m;
d.nmsgs = 2;
return ioctl(dev->fh, I2C_RDWR, &d) < 0 ? -1 : length;
int ret = ioctl(dev->fh, I2C_RDWR, &d);
if (ret < 0)
{
syslog(LOG_ERR, "i2c%i: read_bytes_data: Access error: %s", dev->busnum, strerror(errno));
return -1;
}
return length;
}
mraa_result_t
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: write: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_write_replace))
return dev->advance_func->i2c_write_replace(dev, data, length);
i2c_smbus_data_t d;
@@ -299,7 +345,8 @@ mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
d.block[0] = length;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &d) < 0) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -307,12 +354,17 @@ mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
mraa_result_t
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: write_byte: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_write_byte_replace)) {
return dev->advance_func->i2c_write_byte_replace(dev, data);
} else {
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_byte: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -321,13 +373,18 @@ mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
mraa_result_t
mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: write_byte_data: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_write_byte_data_replace))
return dev->advance_func->i2c_write_byte_data_replace(dev, data, command);
i2c_smbus_data_t d;
d.byte = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_byte_data: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -335,13 +392,18 @@ mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t
mraa_result_t
mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: write_word_data: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_write_word_data_replace))
return dev->advance_func->i2c_write_word_data_replace(dev, data, command);
i2c_smbus_data_t d;
d.word = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: write_word_data: Access error: %s", dev->busnum, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -350,6 +412,7 @@ mraa_result_t
mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: address: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
@@ -358,8 +421,8 @@ mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
return dev->advance_func->i2c_address_replace(dev, addr);
} else {
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr);
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "i2c%i: address: Failed to set slave address %d: %s", dev->busnum, addr, strerror(errno));
return MRAA_ERROR_UNSPECIFIED;
}
return MRAA_SUCCESS;
}
@@ -369,6 +432,15 @@ mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
mraa_result_t
mraa_i2c_stop(mraa_i2c_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "i2c: stop: context is invalid");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, i2c_stop_replace)) {
return dev->advance_func->i2c_stop_replace(dev);
}
free(dev);
return MRAA_SUCCESS;
}

View File

@@ -27,13 +27,15 @@
#include "dirent.h"
#include <string.h>
#include <poll.h>
#if defined(MSYS)
#define __USE_LINUX_IOCTL_DEFS
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
#define MAX_SIZE 128
#define IIO_DEVICE "iio:device"
#define IIO_SCAN_ELEM "scan_elements"
#define IIO_MOUNTING_MATRIX "mounting_matrix"
#define IIO_SLASH_DEV "/dev/" IIO_DEVICE
#define IIO_SYSFS_DEVICE "/sys/bus/iio/devices/" IIO_DEVICE
#define IIO_EVENTS "events"
@@ -83,6 +85,7 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
int padint = 0;
int curr_bytes = 0;
char shortbuf, signchar;
int i = 0;
dev->datasize = 0;
@@ -129,12 +132,6 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
ret = sscanf(readbuf, "%ce:%c%u/%u>>%u", &shortbuf, &signchar, &chan->bits_used,
&padint, &chan->shift);
chan->bytes = padint / 8;
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
// probably should be 5?
if (ret < 0) {
// cleanup
@@ -175,6 +172,18 @@ mraa_iio_get_channel_data(mraa_iio_context dev)
}
closedir(dir);
// channel location has to be done in channel index order so do it afetr we
// have grabbed all the correct info
for (i = 0; i < dev->chan_num; i++) {
chan = &dev->channels[i];
if (curr_bytes % chan->bytes == 0) {
chan->location = curr_bytes;
} else {
chan->location = curr_bytes - curr_bytes % chan->bytes + chan->bytes;
}
curr_bytes = chan->location + chan->bytes;
}
return MRAA_SUCCESS;
}
@@ -277,7 +286,7 @@ mraa_iio_write_string(mraa_iio_context dev, const char* attr_name, const char* d
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/%s", dev->num, attr_name);
int fd = open(buf, O_WRONLY);
if (fd != -1) {
size_t len = strlen(data);
int len = strlen(data);
ssize_t status = write(fd, data, len);
if (status == len)
result = MRAA_SUCCESS;
@@ -539,18 +548,18 @@ mraa_iio_event_extract_event(struct iio_event_data* event,
}
mraa_result_t
mraa_iio_get_mounting_matrix(mraa_iio_context dev, float mm[9])
mraa_iio_get_mount_matrix(mraa_iio_context dev, const char *sysfs_name, float mm[9])
{
char buf[MAX_SIZE];
FILE* fp;
int ret;
memset(buf, 0, MAX_SIZE);
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_MOUNTING_MATRIX, dev->num);
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/%s", dev->num, sysfs_name);
fp = fopen(buf, "r");
if (fp != NULL) {
ret = fscanf(fp, "%f %f %f\n%f %f %f\n%f %f %f\n", &mm[0], &mm[1], &mm[2], &mm[3], &mm[4], &mm[5],
&mm[6], &mm[7], &mm[8]);
ret = fscanf(fp, "%f, %f, %f; %f, %f, %f; %f, %f, %f\n", &mm[0], &mm[1], &mm[2], &mm[3],
&mm[4], &mm[5],&mm[6], &mm[7], &mm[8]);
fclose(fp);
if (ret != 9) {
return MRAA_ERROR_UNSPECIFIED;

View File

@@ -33,7 +33,7 @@ add_custom_command (TARGET mraajava
COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mraa
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cmake -E echo "Creating jar"
COMMAND ${JAR} cvf mraa.jar mraa
COMMAND ${JAR} cvmf manifest.txt mraa.jar mraa
)
if (DOXYGEN_FOUND)
@@ -42,7 +42,7 @@ if (DOXYGEN_FOUND)
endforeach ()
endif ()
mraa_create_install_pkgconfig (mraajava.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
mraa_create_install_pkgconfig (mraajava.pc ${LIB_INSTALL_DIR}/pkgconfig)
install (TARGETS mraajava LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
install (TARGETS mraajava LIBRARY DESTINATION ${LIB_INSTALL_DIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar DESTINATION ${LIB_INSTALL_DIR}/../lib/java)

7
src/java/manifest.txt.in Normal file
View File

@@ -0,0 +1,7 @@
Manifest-version: 1.0
Name: mraa/
Specification-Title: mraa
Specification-Version: @VERSION_SHORT@
Package-Title: mraa
Package-Version: @VERSION_SHORT@

View File

@@ -96,5 +96,34 @@ class Spi;
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
String javaAPIVersion = mraa.class.getPackage().getSpecificationVersion();
String nativeAPIVersion = mraa.getVersion().substring(1);
String javaMajor = javaAPIVersion.substring(0, javaAPIVersion.indexOf('.'));
String nativeMajor = nativeAPIVersion.substring(0, nativeAPIVersion.indexOf('.'));
if(Integer.parseInt(javaMajor) < Integer.parseInt(nativeMajor)){
System.err.println("Java library is out of date. Please update the Java library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
System.exit(1);
}
if(Integer.parseInt(javaMajor) > Integer.parseInt(nativeMajor)){
System.err.println("Native library is out of date. Please update the Native library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
System.exit(1);
}
String javaMinor = javaAPIVersion.substring(javaMajor.length() + 1, javaAPIVersion.indexOf('.', javaMajor.length() + 1));
String nativeMinor = nativeAPIVersion.substring(nativeMajor.length() + 1, nativeAPIVersion.indexOf('.', nativeMajor.length() + 1));
if(Integer.parseInt(javaMinor) < Integer.parseInt(nativeMinor)){
System.err.println("Java library is out of date. Please consider updating the Java library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
}
if(Integer.parseInt(javaMinor) > Integer.parseInt(nativeMinor)){
System.err.println("Native library is out of date. Please consider updating the Native library.");
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
}
}
%}

View File

@@ -3,35 +3,39 @@
{
'target_name': 'mraa',
'sources': [
@mraa_LIB_SRCS_GYP@
'src/version.c',
'src/mraajsJAVASCRIPT_wrap.cxx' ],
@mraa_LIB_SRCS_GYP@
'src/version.c',
'src/mraajsJAVASCRIPT_wrap.cxx'
],
'include_dirs': [
@mraa_LIB_INCLUDE_DIRS_GYP@
],
@mraa_LIB_INCLUDE_DIRS_GYP@
],
'variables': {
"v8_version%": "<!(node -e 'console.log(process.versions.v8)' | sed 's/\.//g' | cut -c 1-5)",
"arch%": "<!(node -e 'console.log(process.arch)')"
"v8_version%": "<!(node -e 'console.log(process.versions.v8)' | sed 's/\.//g' | cut -c 1-5)",
"arch%": "<!(node -e 'console.log(process.arch)')"
},
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
'cflags!': [ '-fno-exceptions' ],
'conditions' : [
[ 'arch=="x64"',
{ 'defines' : [ 'X86PLAT=ON' ], },
],
[ 'arch=="ia32"',
{ 'defines' : [ 'X86PLAT=ON'], },
],
[ 'arch=="arm"',
{ 'defines' : [ 'ARMPLAT=ON'], },
],
['OS=="android"', {
'sources' : [ 'src/glob/glob.c' ],
'include_dirs' : [ 'src/glob' ],
}],
[ 'arch=="x64" or arch=="ia32"', {
'defines' : [ 'X86PLAT=ON' ],
}],
[ 'arch=="arm"', {
'defines' : [ 'ARMPLAT=ON'],
}],
],
'defines' : [ 'SWIG',
'SWIGJAVASCRIPT',
'FIRMATA=ON',
'BUILDING_NODE_EXTENSION=1',
'SWIG_V8_VERSION=0x0<(v8_version)',
'V8_VERSION=0x0<(v8_version)'
'defines' : [
'SWIG',
'SWIGJAVASCRIPT',
'FIRMATA=ON',
'ONEWIRE=ON',
'BUILDING_NODE_EXTENSION=1',
'SWIG_V8_VERSION=0x0<(v8_version)',
'V8_VERSION=0x0<(v8_version)'
]
}
]

View File

@@ -65,7 +65,7 @@
},
"func": {
"type": "Function",
"description": "Function to be called when interupt is triggered"
"description": "Function to be called when interrupt is triggered"
}
},
"return": {

716
src/json/jsonplatform.c Normal file
View File

@@ -0,0 +1,716 @@
/*
* Author: Houman Brinjcargorabi <Houman.Brinjcargorabi@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <json-c/json.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "mraa_internal.h"
typedef mraa_result_t (*init_plat_func_t)(json_object*, mraa_board_t*, int);
mraa_result_t
mraa_init_json_platform_get_pin(json_object* jobj, const char* io, const char* key, int index, int* pin)
{
json_object* jobj_temp = NULL;
if (json_object_object_get_ex(jobj, key, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_int)) {
syslog(LOG_ERR, "init_json_platform: %s %s at position: %d is not an int", io, key, index);
return MRAA_ERROR_INVALID_RESOURCE;
}
*pin = (unsigned int) json_object_get_int(jobj_temp);
return MRAA_SUCCESS;
}
syslog(LOG_ERR, "init_json_platform: No %s specified for %s at position: %d", key, io, index);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
mraa_result_t
mraa_init_json_platform_get_index(json_object* jobj, const char* io, const char* key, int index, int* pos, int upper)
{
json_object* jobj_temp = NULL;
if (json_object_object_get_ex(jobj, key, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_int)) {
syslog(LOG_ERR, "init_json_platform: %s index at position: %d not an int", io, index);
return MRAA_ERROR_INVALID_RESOURCE;
}
*pos = (int) json_object_get_int(jobj_temp);
if (*pos < 0 || *pos > upper) {
syslog(LOG_ERR,
"init_json_platform: %s %s at position: %d, gave: %d which was out of range", io,
key, index, *pos);
return MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
syslog(LOG_ERR, "init_json_platform: An %s was not found for the %s", key, io);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
mraa_result_t
mraa_init_json_platform_platform(json_object* jobj_platform, mraa_board_t* board, int index)
{
json_object* jobj_temp = NULL;
const char* temp_string = NULL;
int temp_count = 0;
int length = 0;
mraa_result_t ret = MRAA_SUCCESS;
// Set the platform name
if (json_object_object_get_ex(jobj_platform, NAME_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_string)) {
syslog(LOG_ERR, "init_json_platform: Platform name not a string");
return MRAA_ERROR_NO_RESOURCES;
}
temp_string = json_object_get_string(jobj_temp);
if (temp_string == NULL || (length = strlen(temp_string)) == 0) {
syslog(LOG_ERR, "init_json_platform: Empty string provided for \"%s\" key in platform", NAME_KEY);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
board->platform_name = (char*) calloc(length, sizeof(char));
strncpy(board->platform_name, temp_string, length);
} else {
syslog(LOG_ERR, "init_json_platform: No \"%s\" key in platform", NAME_KEY);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
// Get the physical pincount
ret = mraa_init_json_platform_get_pin(jobj_platform, PLATFORM_KEY, PIN_COUNT_KEY, index,
&(board->phy_pin_count));
if (ret != MRAA_SUCCESS) {
return ret;
}
// Setup the pins
board->pins = (mraa_pininfo_t*) calloc(board->phy_pin_count, sizeof(mraa_pininfo_t));
if (board->pins == NULL) {
syslog(LOG_ERR, "init_json_platform: Unable to allocate space for the pins");
return MRAA_ERROR_INVALID_RESOURCE;
}
// set the inital counts to -1 so we know if they don't exist
board->gpio_count = -1;
board->aio_count = -1;
board->uart_dev_count = -1;
board->i2c_bus_count = -1;
board->spi_bus_count = -1;
// Check to see if they've provided a GPIO count
ret = mraa_init_json_platform_get_index(jobj_platform, PLATFORM_KEY, GPIO_COUNT_KEY, index,
&(board->gpio_count), board->phy_pin_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// Check to see if they've provided a AIO count
ret = mraa_init_json_platform_get_index(jobj_platform, PLATFORM_KEY, AIO_COUNT_KEY, index,
&(board->aio_count), board->phy_pin_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// Check to see if they've provided a UART count
ret = mraa_init_json_platform_get_index(jobj_platform, PLATFORM_KEY, UART_COUNT_KEY, index,
&(board->uart_dev_count), 6);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// Check to see if they've provided a I2C count
ret = mraa_init_json_platform_get_index(jobj_platform, PLATFORM_KEY, I2C_COUNT_KEY, index,
&(board->i2c_bus_count), 12);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// Check to see if they've provided a SPI count
ret = mraa_init_json_platform_get_index(jobj_platform, PLATFORM_KEY, SPI_COUNT_KEY, index,
&(board->spi_bus_count), 12);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// Set the PWM default numbers
board->pwm_default_period = -1;
board->pwm_max_period = -1;
board->pwm_min_period = -1;
// Setup the PWM rates if they exist
ret = mraa_init_json_platform_get_pin(jobj_platform, PLATFORM_KEY, PWMDEFAULT_KEY, index,
&(board->pwm_default_period));
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
ret = mraa_init_json_platform_get_pin(jobj_platform, PLATFORM_KEY, PWMMAX_KEY, index,
&(board->pwm_max_period));
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
ret = mraa_init_json_platform_get_pin(jobj_platform, PLATFORM_KEY, PWMMIN_KEY, index,
&(board->pwm_min_period));
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
return ret;
}
// A hacky logical xor to ensure the value's have all been set or none should have been set
// Here we infer that IF A != B and B != C then A == C since they're working on binary values
if (((board->pwm_default_period == -1) != (board->pwm_max_period == -1)) ||
((board->pwm_min_period == -1) != (board->pwm_max_period == -1))) {
syslog(LOG_ERR, "init_json_platform: One of more PWM settings missing in the platform"
"configuration");
return MRAA_ERROR_INVALID_RESOURCE;
}
// Set our platform type
board->platform_type = MRAA_JSON_PLATFORM;
board->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_io(json_object* jobj_io, mraa_board_t* board, int index)
{
const char* temp_string = NULL;
json_object* jobj_temp = NULL;
int pos = 0;
int invalid = 0;
pos = index;
// set the label for the IO
if (json_object_object_get_ex(jobj_io, LABEL_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_string)) {
syslog(LOG_ERR, "init_json_platform: IO label at position: %d not a string", index);
return MRAA_ERROR_NO_RESOURCES;
}
temp_string = json_object_get_string(jobj_temp);
// set the gpio label
strncpy(board->pins[pos].name, temp_string, 8);
} else {
syslog(LOG_ERR, "init_json_platform: No IO Label");
return MRAA_ERROR_INVALID_RESOURCE;
}
if (json_object_object_get_ex(jobj_io, INVALID_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_boolean)) {
syslog(LOG_ERR, "init_json_platform: Default I2C device key has an incorrect value");
return MRAA_ERROR_INVALID_RESOURCE;
}
invalid = json_object_get_boolean(jobj_temp);
}
if (invalid) {
board->pins[pos].capabilities = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
} else {
board->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_gpio(json_object* jobj_gpio, mraa_board_t* board, int index)
{
int pos = 0;
mraa_result_t ret = MRAA_SUCCESS;
// Get the gpio index
ret = mraa_init_json_platform_get_index(jobj_gpio, GPIO_KEY, INDEX_KEY, index, &pos,
board->phy_pin_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the gpio sysfs pin;
ret = mraa_init_json_platform_get_pin(jobj_gpio, GPIO_KEY, RAW_PIN_KEY, index,
&(board->pins[pos].gpio.pinmap));
if (ret != MRAA_SUCCESS) {
return ret;
}
board->pins[pos].capabilities.gpio = 1;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_aio(json_object* jobj_aio, mraa_board_t* board, int index)
{
int pos = 0;
mraa_result_t ret = MRAA_SUCCESS;
// Get the gpio index
ret = mraa_init_json_platform_get_index(jobj_aio, AIO_KEY, INDEX_KEY, index, &pos, board->phy_pin_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the gpio sysfs pin;
ret = mraa_init_json_platform_get_pin(jobj_aio, AIO_KEY, RAW_PIN_KEY, index,
&(board->pins[pos].aio.pinmap));
if (ret != MRAA_SUCCESS) {
return ret;
}
board->pins[pos].capabilities.aio = 1;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_i2c(json_object* jobj_i2c, mraa_board_t* board, int index)
{
int pos = 0;
int pin = 0;
int sysfs_pin = 0;
mraa_result_t ret = MRAA_SUCCESS;
json_object* jobj_temp = NULL;
// Get the I2C bus array index
ret = mraa_init_json_platform_get_index(jobj_i2c, I2C_KEY, INDEX_KEY, index, &pos, board->i2c_bus_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the sysfs pin
ret = mraa_init_json_platform_get_pin(jobj_i2c, I2C_KEY, RAW_PIN_KEY, index, &sysfs_pin);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Setup the sda pin
ret = mraa_init_json_platform_get_index(jobj_i2c, I2C_KEY, SDAPIN_KEY, index, &pin,
board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->i2c_bus[pos].sda = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.i2c = 1;
board->pins[pin].i2c.pinmap = sysfs_pin;
board->i2c_bus[pos].sda = pin;
} else {
return ret;
}
// Setup the scl pin
ret = mraa_init_json_platform_get_index(jobj_i2c, I2C_KEY, SCLPIN_KEY, index, &pin,
board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->i2c_bus[pos].scl = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.i2c = 1;
board->pins[pin].i2c.pinmap = sysfs_pin;
board->i2c_bus[pos].scl = pin;
} else {
return ret;
}
board->i2c_bus[pos].bus_id = pos;
// check to see if this i2c is the default one
if (json_object_object_get_ex(jobj_i2c, DEFAULT_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_boolean)) {
syslog(LOG_ERR, "init_json_platform: Default I2C device key has an incorrect value");
return MRAA_ERROR_INVALID_RESOURCE;
}
if (json_object_get_boolean(jobj_temp)) {
board->def_i2c_bus = pos;
}
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_pwm(json_object* jobj_pwm, mraa_board_t* board, int index)
{
int pos = 0;
int parent_id = 0;
int sysfs_pin = 0;
mraa_result_t ret = MRAA_SUCCESS;
// Get the index into the physical pin array
ret = mraa_init_json_platform_get_index(jobj_pwm, PWM_KEY, INDEX_KEY, index, &pos, board->phy_pin_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the parent id
ret = mraa_init_json_platform_get_pin(jobj_pwm, PWM_KEY, CHIP_ID_KEY, index, &parent_id);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the sysfs pin
ret = mraa_init_json_platform_get_pin(jobj_pwm, PWM_KEY, RAW_PIN_KEY, index, &sysfs_pin);
if (ret != MRAA_SUCCESS) {
return ret;
}
board->pins[pos].capabilities.pwm = 1;
board->pins[pos].pwm.pinmap = sysfs_pin;
board->pins[pos].pwm.parent_id = parent_id;
return ret;
}
mraa_result_t
mraa_init_json_platform_spi(json_object* jobj_spi, mraa_board_t* board, int index)
{
int pos = 0;
int pin = 0;
int parent_id = 0;
json_object* jobj_temp = NULL;
mraa_result_t ret = MRAA_SUCCESS;
// Get the index into the physical pin array
ret = mraa_init_json_platform_get_index(jobj_spi, SPI_KEY, INDEX_KEY, index, &pos, board->spi_bus_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the parent id
ret = mraa_init_json_platform_get_pin(jobj_spi, SPI_KEY, CHIP_ID_KEY, index, &parent_id);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Setup the clock pin
ret = mraa_init_json_platform_get_index(jobj_spi, SPI_KEY, CLOCK_KEY, index, &pin, board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->spi_bus[pos].sclk = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.spi = 1;
board->pins[pin].spi.parent_id = parent_id;
board->spi_bus[pos].sclk = pin;
} else {
return ret;
}
// Setup the MISO pin
ret = mraa_init_json_platform_get_index(jobj_spi, SPI_KEY, MISO_KEY, index, &pin, board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->spi_bus[pos].miso = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.spi = 1;
board->pins[pin].spi.parent_id = parent_id;
board->spi_bus[pos].miso = pin;
} else {
return ret;
}
// Setup the MOSI pin
ret = mraa_init_json_platform_get_index(jobj_spi, SPI_KEY, MOSI_KEY, index, &pin, board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->spi_bus[pos].mosi = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.spi = 1;
board->pins[pin].spi.parent_id = parent_id;
board->spi_bus[pos].mosi = pin;
} else {
return ret;
}
// Setup the CS pin
ret = mraa_init_json_platform_get_index(jobj_spi, SPI_KEY, CS_KEY, index, &pin, board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->spi_bus[pos].cs = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.spi = 1;
board->pins[pin].spi.parent_id = parent_id;
board->spi_bus[pos].cs = pin;
} else {
return ret;
}
// check to see if this SPI is the default one
if (json_object_object_get_ex(jobj_spi, DEFAULT_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_boolean)) {
syslog(LOG_ERR, "init_json_platform: Default I2C device key has an incorrect value");
return MRAA_ERROR_INVALID_RESOURCE;
}
if (json_object_get_boolean(jobj_temp)) {
board->def_spi_bus = pos;
}
}
return ret;
}
mraa_result_t
mraa_init_json_platform_uart(json_object* jobj_uart, mraa_board_t* board, int index)
{
json_object* jobj_temp = NULL;
mraa_result_t ret = MRAA_SUCCESS;
int pos = 0;
int pin = 0;
int sysfs_pin = 0;
int parent_id = 0;
int length = 0;
const char* temp_string = NULL;
// Get the index into the uart bus
ret = mraa_init_json_platform_get_index(jobj_uart, UART_KEY, INDEX_KEY, index, &pos,
board->uart_dev_count - 1);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the parent id
ret = mraa_init_json_platform_get_pin(jobj_uart, UART_KEY, CHIP_ID_KEY, index, &parent_id);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Get the sysfs pin
ret = mraa_init_json_platform_get_pin(jobj_uart, UART_KEY, RAW_PIN_KEY, index, &sysfs_pin);
if (ret != MRAA_SUCCESS) {
return ret;
}
// Setup the rx pin
ret = mraa_init_json_platform_get_index(jobj_uart, UART_KEY, RXPIN_KEY, index, &pin,
board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->uart_dev[pos].rx = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.uart = 1;
board->pins[pin].uart.pinmap = sysfs_pin;
board->pins[pin].uart.parent_id = parent_id;
board->uart_dev[pos].rx = pin;
} else {
return ret;
}
// Setup the TX pin
ret = mraa_init_json_platform_get_index(jobj_uart, UART_KEY, TXPIN_KEY, index, &pin,
board->phy_pin_count - 1);
if (ret == MRAA_ERROR_NO_DATA_AVAILABLE) {
board->uart_dev[pos].tx = -1;
} else if (ret == MRAA_SUCCESS) {
board->pins[pin].capabilities.uart = 1;
board->pins[pin].uart.pinmap = sysfs_pin;
board->pins[pin].uart.parent_id = parent_id;
board->uart_dev[pos].tx = pin;
} else {
return ret;
}
// Setup the path
if (json_object_object_get_ex(jobj_uart, UART_PATH_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_string)) {
syslog(LOG_ERR, "init_json_platform: UART Path at index: %d was not a string", index);
return MRAA_ERROR_NO_RESOURCES;
}
temp_string = json_object_get_string(jobj_temp);
if (temp_string == NULL || (length = strlen(temp_string)) == 0) {
syslog(LOG_ERR, "init_json_platform: UART Path at index: %d was empty", index);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
board->uart_dev[pos].device_path = (char*) calloc(length, sizeof(char));
strncpy(board->uart_dev[pos].device_path, temp_string, length);
} else {
syslog(LOG_ERR, "init_json_platform: UART config at index: %d needs a path", index);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
// If this element is supposed to be default set it.
if (json_object_object_get_ex(jobj_uart, DEFAULT_KEY, &jobj_temp)) {
if (!json_object_is_type(jobj_temp, json_type_boolean)) {
syslog(LOG_ERR, "init_json_platform: Default UART device key has an incorrect value");
return MRAA_ERROR_INVALID_RESOURCE;
}
if (json_object_get_boolean(jobj_temp)) {
board->def_uart_dev = pos;
}
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_json_platform_loop(json_object* jobj_platform, const char* obj_key, mraa_board_t* board, init_plat_func_t func)
{
mraa_result_t ret = MRAA_SUCCESS;
int i = 0, array_length = 0;
json_object *jobj_temp = NULL, *jobj_io = NULL;
if (json_object_object_get_ex(jobj_platform, obj_key, &jobj_temp)) {
array_length = json_object_array_length(jobj_temp);
for (i = 0; i < array_length; i++) {
// Get the json object at position i
jobj_io = json_object_array_get_idx(jobj_temp, i);
// Check to see it's the right type
if (!json_object_is_type(jobj_io, json_type_object)) {
syslog(LOG_ERR, "init_json_platform: One of more of the elements in the \"%s\" "
"array where not JSON objects",
obj_key);
return MRAA_ERROR_INVALID_RESOURCE;
}
ret = (*func)(jobj_io, board, i);
if (ret != MRAA_SUCCESS) {
return ret;
}
}
} else {
syslog(LOG_ERR, "init_json_platform: No \"%s\" info found in json file", obj_key);
ret = MRAA_ERROR_NO_DATA_AVAILABLE;
}
return ret;
}
mraa_result_t
mraa_init_json_platform_size_check(json_object* jobj_platform,
const char* obj_key,
mraa_board_t* board,
init_plat_func_t func,
int range)
{
json_object* jobj_temp = NULL;
mraa_result_t ret = MRAA_SUCCESS;
int array_length = 0;
if (json_object_object_get_ex(jobj_platform, obj_key, &jobj_temp)) {
// Make sure the value for the key is an array
if (!json_object_is_type(jobj_temp, json_type_array)) {
syslog(LOG_ERR, "init_json_platform: json key \"%s\" should be an array", obj_key);
return MRAA_ERROR_INVALID_RESOURCE;
}
// make sure we don't have more than our range
array_length = json_object_array_length(jobj_temp);
if (array_length > range) {
syslog(LOG_ERR,
"init_json_platform: The size of the %s array given was %d, max was: %d",
obj_key, array_length, range);
return MRAA_ERROR_INVALID_RESOURCE;
}
ret = mraa_init_json_platform_loop(jobj_platform, obj_key, board, func);
if (ret != MRAA_SUCCESS) {
return ret;
}
return MRAA_SUCCESS;
}
syslog(LOG_NOTICE, "init_json_platform: %s wasn't found in the json file", obj_key);
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
mraa_result_t
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;
mraa_board_t* board = NULL;
// Try to lock the file for use
if ((file_lock = open(platform_json, O_RDONLY)) == -1) {
syslog(LOG_ERR, "init_json_platform: Failed to open platform file");
return MRAA_ERROR_INVALID_RESOURCE;
}
if (fstat(file_lock, &st) != 0 || (!S_ISREG(st.st_mode))) {
syslog(LOG_ERR, "init_json_platform: Failed to retrieve information about a file or the "
"file specified is not actually a file");
close(file_lock);
return MRAA_ERROR_INVALID_RESOURCE;
}
buffer = mmap(0, st.st_size, PROT_READ, MAP_SHARED, file_lock, 0);
close(file_lock);
if (buffer == MAP_FAILED) {
syslog(LOG_ERR, "init_json_platform: Failed to read platform file");
return MRAA_ERROR_INVALID_RESOURCE;
}
// Parse the json file
jobj_platform = json_tokener_parse(buffer);
// Allocate some memory for the board information
board = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
if (board == NULL) {
munmap(buffer, st.st_size);
return MRAA_ERROR_INVALID_HANDLE;
}
// Call our helper to go through and init our board for the "Platform" data
ret = mraa_init_json_platform_loop(jobj_platform, PLATFORM_KEY, board, mraa_init_json_platform_platform);
if (ret != MRAA_SUCCESS) {
goto unsuccessful;
}
// Setup the IO's with their labels
ret = mraa_init_json_platform_size_check(jobj_platform, IO_KEY, board,
mraa_init_json_platform_io, board->phy_pin_count);
if (ret != MRAA_SUCCESS) {
goto unsuccessful;
}
// Setup GPIO
ret = mraa_init_json_platform_size_check(jobj_platform, GPIO_KEY, board,
mraa_init_json_platform_gpio, board->phy_pin_count);
if (ret != MRAA_SUCCESS) {
goto unsuccessful;
}
// Setup AIO
ret = mraa_init_json_platform_size_check(jobj_platform, AIO_KEY, board,
mraa_init_json_platform_aio, board->phy_pin_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
goto unsuccessful;
}
// Setup SPI
ret = mraa_init_json_platform_size_check(jobj_platform, SPI_KEY, board,
mraa_init_json_platform_spi, board->spi_bus_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
goto unsuccessful;
}
// Setup I2C
ret = mraa_init_json_platform_size_check(jobj_platform, I2C_KEY, board,
mraa_init_json_platform_i2c, board->i2c_bus_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
goto unsuccessful;
}
// Setup UART
ret = mraa_init_json_platform_size_check(jobj_platform, UART_KEY, board,
mraa_init_json_platform_uart, board->uart_dev_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
for (i = 0; i < board->uart_dev_count; i++) {
if (board->uart_dev[i].device_path != NULL) {
free(plat->uart_dev[i].device_path);
}
}
goto unsuccessful;
}
// Setup PWM
ret = mraa_init_json_platform_size_check(jobj_platform, PWM_KEY, board,
mraa_init_json_platform_pwm, board->phy_pin_count);
if (ret != MRAA_SUCCESS && ret != MRAA_ERROR_NO_DATA_AVAILABLE) {
goto unsuccessful;
}
// Free the old empty platform
free(plat);
// Set the new one in it's place
plat = board;
platform_name = plat->platform_name;
// We made it to the end without anything going wrong, just cleanup
ret = MRAA_SUCCESS;
syslog(LOG_NOTICE, "init_json_platform: Platform %s initialised via json", platform_name);
goto cleanup;
unsuccessful:
free(board->platform_name);
free(board->pins);
free(board->adv_func);
free(board);
cleanup:
json_object_put(jobj_platform);
munmap(buffer, st.st_size);
return ret;
}

3
src/mock/CMakeLists.txt Normal file
View File

@@ -0,0 +1,3 @@
message (INFO " - Adding mock platform")
set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
${mraa_LIB_MOCK_SRCS_NOAUTO} PARENT_SCOPE)

43
src/mock/mock.c Normal file
View File

@@ -0,0 +1,43 @@
/*
* 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 "mraa_internal.h"
#include "mock/mock_board.h"
mraa_platform_t
mraa_mock_platform()
{
mraa_platform_t platform_type = MRAA_MOCK_PLATFORM;
plat = mraa_mock_board();
if (plat == NULL) {
syslog(LOG_ERR, "Was not able to initialize mock platform");
return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
}
return platform_type;
}

136
src/mock/mock_board.c Normal file
View File

@@ -0,0 +1,136 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "mock/mock_board.h"
#include "mock/mock_board_gpio.h"
#include "mock/mock_board_aio.h"
#include "mock/mock_board_i2c.h"
#define PLATFORM_NAME "MRAA mock platform"
mraa_board_t*
mraa_mock_board()
{
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
if (b == NULL) {
return NULL;
}
// General board definitions
b->platform_name = PLATFORM_NAME;
b->phy_pin_count = MRAA_MOCK_PINCOUNT;
b->gpio_count = 1;
b->aio_count = 1;
b->adc_raw = 12;
b->adc_supported = 10;
b->i2c_bus_count = 1;
b->i2c_bus[0].bus_id = 0;
b->i2c_bus[0].sda = 2;
b->i2c_bus[0].scl = 3;
b->def_i2c_bus = b->i2c_bus[0].bus_id;
b->spi_bus_count = 0;
b->pwm_default_period = 0;
b->pwm_max_period = 0;
b->pwm_min_period = 0;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_MOCK_PINCOUNT);
if (b->pins == NULL) {
goto error;
}
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
if (b->adv_func == NULL) {
free(b->pins);
goto error;
}
// Replace functions
b->adv_func->gpio_init_internal_replace = &mraa_mock_gpio_init_internal_replace;
b->adv_func->gpio_close_replace = &mraa_mock_gpio_close_replace;
b->adv_func->gpio_dir_replace = &mraa_mock_gpio_dir_replace;
b->adv_func->gpio_read_dir_replace = &mraa_mock_gpio_read_dir_replace;
b->adv_func->gpio_read_replace = &mraa_mock_gpio_read_replace;
b->adv_func->gpio_write_replace = &mraa_mock_gpio_write_replace;
b->adv_func->gpio_edge_mode_replace = &mraa_mock_gpio_edge_mode_replace;
b->adv_func->gpio_isr_replace = &mraa_mock_gpio_isr_replace;
b->adv_func->gpio_isr_exit_replace = &mraa_mock_gpio_isr_exit_replace;
b->adv_func->gpio_mode_replace = &mraa_mock_gpio_mode_replace;
b->adv_func->aio_init_internal_replace = &mraa_mock_aio_init_internal_replace;
b->adv_func->aio_close_replace = &mraa_mock_aio_close_replace;
b->adv_func->aio_read_replace = &mraa_mock_aio_read_replace;
b->adv_func->i2c_init_bus_replace = &mraa_mock_i2c_init_bus_replace;
b->adv_func->i2c_stop_replace = &mraa_mock_i2c_stop_replace;
b->adv_func->i2c_set_frequency_replace = &mraa_mock_i2c_set_frequency_replace;
b->adv_func->i2c_address_replace = &mraa_mock_i2c_address_replace;
b->adv_func->i2c_read_replace = &mraa_mock_i2c_read_replace;
b->adv_func->i2c_read_byte_replace = &mraa_mock_i2c_read_byte_replace;
b->adv_func->i2c_read_byte_data_replace = &mraa_mock_i2c_read_byte_data_replace;
b->adv_func->i2c_read_bytes_data_replace = &mraa_mock_i2c_read_bytes_data_replace;
b->adv_func->i2c_read_word_data_replace = &mraa_mock_i2c_read_word_data_replace;
b->adv_func->i2c_write_replace = &mraa_mock_i2c_write_replace;
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;
// Pin definitions
int pos = 0;
strncpy(b->pins[pos].name, "GPIO0", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 0;
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "ADC0", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 };
b->pins[pos].aio.pinmap = 0;
b->pins[pos].aio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "I2C0SDA", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[pos].i2c.mux_total = 0;
b->pins[pos].i2c.pinmap = 0;
pos++;
strncpy(b->pins[pos].name, "I2C0SCL", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[pos].i2c.mux_total = 0;
b->pins[pos].i2c.pinmap = 0;
pos++;
return b;
error:
syslog(LOG_CRIT, "MRAA mock: Platform failed to initialise");
free(b);
return NULL;
}

52
src/mock/mock_board_aio.c Normal file
View File

@@ -0,0 +1,52 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "mock/mock_board_aio.h"
mraa_result_t
mraa_mock_aio_init_internal_replace(mraa_aio_context dev, int pin)
{
dev->channel = pin;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_aio_close_replace(mraa_aio_context dev)
{
free(dev);
return MRAA_SUCCESS;
}
int
mraa_mock_aio_read_replace(mraa_aio_context dev)
{
// return some random number between 0 and max value, based on the resolution
int max_value = (1 << dev->value_bit) - 1;
srand(time(NULL));
return rand() % max_value;
}

130
src/mock/mock_board_gpio.c Normal file
View File

@@ -0,0 +1,130 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "mock/mock_board_gpio.h"
mraa_result_t
mraa_mock_gpio_init_internal_replace(mraa_gpio_context dev, int pin)
{
dev->value_fp = -1;
dev->isr_value_fp = -1;
dev->isr_thread_terminating = 0;
dev->phy_pin = pin;
// We are always the owner
dev->owner = 1;
#ifndef HAVE_PTHREAD_CANCEL
dev->isr_control_pipe[0] = dev->isr_control_pipe[1] = -1;
#endif
// We start as INPUT and LOW
dev->mock_dir = MRAA_GPIO_IN;
dev->mock_state = 0;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_gpio_close_replace(mraa_gpio_context dev)
{
free(dev);
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir)
{
switch (dir) {
case MRAA_GPIO_OUT_HIGH:
dev->mock_dir = MRAA_GPIO_OUT;
return mraa_gpio_write(dev, 1);
case MRAA_GPIO_OUT_LOW:
dev->mock_dir = MRAA_GPIO_OUT;
return mraa_gpio_write(dev, 0);
case MRAA_GPIO_IN:
case MRAA_GPIO_OUT:
dev->mock_dir = dir;
return MRAA_SUCCESS;
default:
syslog(LOG_ERR, "gpio: dir: invalid direction '%d' to set", (int) dir);
return MRAA_ERROR_INVALID_PARAMETER;
}
}
mraa_result_t
mraa_mock_gpio_read_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t* dir)
{
*dir = dev->mock_dir;
return MRAA_SUCCESS;
}
int
mraa_mock_gpio_read_replace(mraa_gpio_context dev)
{
return dev->mock_state;
}
mraa_result_t
mraa_mock_gpio_write_replace(mraa_gpio_context dev, int value)
{
if ((value < 0) || (value > 1)) {
syslog(LOG_ERR, "gpio: write: incorrect value '%d' passed to write(), must be 0 or 1", value);
return MRAA_ERROR_INVALID_PARAMETER;
}
if (dev->mock_dir == MRAA_GPIO_IN) {
syslog(LOG_ERR, "gpio: write: cannot write to pin set to INPUT");
return MRAA_ERROR_INVALID_RESOURCE;
}
dev->mock_state = value;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode)
{
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
mraa_result_t
mraa_mock_gpio_isr_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args)
{
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
mraa_result_t
mraa_mock_gpio_isr_exit_replace(mraa_gpio_context dev)
{
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
mraa_result_t
mraa_mock_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode)
{
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}

246
src/mock/mock_board_i2c.c Normal file
View File

@@ -0,0 +1,246 @@
/*
* Author: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2016 Alex Tereschenko.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "mock/mock_board.h"
#include "mock/mock_board_gpio.h"
#include "mock/mock_board_aio.h"
#include "mock/mock_board_i2c.h"
mraa_result_t
mraa_mock_i2c_init_bus_replace(mraa_i2c_context dev)
{
dev->mock_dev_addr = MOCK_I2C_DEV_ADDR;
dev->mock_dev_data_len = MOCK_I2C_DEV_DATA_LEN;
dev->mock_dev_data = (uint8_t*) calloc(dev->mock_dev_data_len, sizeof(uint8_t));
if (dev->mock_dev_data == NULL) {
syslog(LOG_CRIT, "i2c%i: init: Failed to allocate memory for mock device context", dev->busnum);
return MRAA_ERROR_NO_RESOURCES;
}
// Set initial values for mock device "data registers"
memset(dev->mock_dev_data, MOCK_I2C_DEV_DATA_INIT_BYTE, dev->mock_dev_data_len);
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_i2c_stop_replace(mraa_i2c_context dev)
{
free(dev->mock_dev_data);
free(dev);
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_i2c_set_frequency_replace(mraa_i2c_context dev, mraa_i2c_mode_t mode)
{
switch (mode) {
case MRAA_I2C_STD:
case MRAA_I2C_FAST:
case MRAA_I2C_HIGH:
return MRAA_SUCCESS;
break;
default:
syslog(LOG_ERR, "i2c%i: set_frequency: Invalid I2C frequency selected", dev->busnum);
return MRAA_ERROR_INVALID_PARAMETER;
}
}
mraa_result_t
mraa_mock_i2c_address_replace(mraa_i2c_context dev, uint8_t addr)
{
const uint8_t MAX_I2C_ADDR = 0x7F;
if (addr > MAX_I2C_ADDR) {
syslog(LOG_ERR, "i2c%i: address: Slave address 0x%X is bigger than max supported (0x%X)",
dev->busnum, addr, MAX_I2C_ADDR);
return MRAA_ERROR_INVALID_PARAMETER;
}
return MRAA_SUCCESS;
}
int
mraa_mock_i2c_read_replace(mraa_i2c_context dev, uint8_t* data, int length)
{
if (dev->addr == dev->mock_dev_addr) {
// Account for possible mismatch between length and our "register" range
int copy_len = (length <= dev->mock_dev_data_len) ? length : dev->mock_dev_data_len;
memcpy(data, dev->mock_dev_data, copy_len);
return copy_len;
} else {
// Not our mock device
return -1;
}
}
int
mraa_mock_i2c_read_byte_replace(mraa_i2c_context dev)
{
if (dev->addr == dev->mock_dev_addr) {
return dev->mock_dev_data[0];
} else {
// Not our mock device
return -1;
}
}
int
mraa_mock_i2c_read_byte_data_replace(mraa_i2c_context dev, uint8_t command)
{
if (dev->addr == dev->mock_dev_addr) {
if (command < dev->mock_dev_data_len) {
return dev->mock_dev_data[command];
} else {
syslog(LOG_ERR,
"i2c%i: read_byte_data: Command/register number is too big, max is 0x%X",
dev->busnum, dev->mock_dev_data_len - 1);
return -1;
}
} else {
// Not our mock device
return -1;
}
}
int
mraa_mock_i2c_read_bytes_data_replace(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
{
if (dev->addr == dev->mock_dev_addr) {
if (command >= dev->mock_dev_data_len) {
syslog(LOG_ERR,
"i2c%i: read_bytes_data: Command/register number is too big, max is 0x%X",
dev->busnum, dev->mock_dev_data_len - 1);
return -1;
}
if (length <= 0) {
syslog(LOG_ERR,
"i2c%i: read_bytes_data: Length to read is invalid (%d), cannot proceed",
dev->busnum, length);
return -1;
}
int i = 0;
// We read requested length, but only up to mock device data length
for (i = command; (i < (command + length)) && (i < dev->mock_dev_data_len); ++i) {
data[i - command] = dev->mock_dev_data[i];
}
return (i - command);
} else {
// Not our mock device
return -1;
}
}
int
mraa_mock_i2c_read_word_data_replace(mraa_i2c_context dev, uint8_t command)
{
if (dev->addr == dev->mock_dev_addr) {
if ((command + 1) < dev->mock_dev_data_len) {
// Let's say the device is big-endian
int result = (dev->mock_dev_data[command] << 8) + dev->mock_dev_data[command + 1];
return result;
} else {
syslog(LOG_ERR,
"i2c%i: read_word_data: Command/register number is too big, max is 0x%X",
dev->busnum, dev->mock_dev_data_len - 2);
return -1;
}
} else {
// Not our mock device
return -1;
}
}
mraa_result_t
mraa_mock_i2c_write_replace(mraa_i2c_context dev, const uint8_t* data, int length)
{
if (dev->addr == dev->mock_dev_addr) {
int copy_len = (length <= dev->mock_dev_data_len) ? length : dev->mock_dev_data_len;
memcpy(dev->mock_dev_data, data, copy_len);
return MRAA_SUCCESS;
} else {
// Not our mock device
return MRAA_ERROR_UNSPECIFIED;
}
}
mraa_result_t
mraa_mock_i2c_write_byte_replace(mraa_i2c_context dev, const uint8_t data)
{
if (dev->addr == dev->mock_dev_addr) {
dev->mock_dev_data[0] = data;
return MRAA_SUCCESS;
} else {
// Not our mock device
return MRAA_ERROR_UNSPECIFIED;
}
}
mraa_result_t
mraa_mock_i2c_write_byte_data_replace(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
{
if (dev->addr == dev->mock_dev_addr) {
if (command < dev->mock_dev_data_len) {
dev->mock_dev_data[command] = data;
return MRAA_SUCCESS;
} else {
syslog(LOG_ERR,
"i2c%i: write_byte_data: Command/register number is too big, max is 0x%X",
dev->busnum, dev->mock_dev_data_len - 1);
return MRAA_ERROR_UNSPECIFIED;
}
} else {
// Not our mock device
return MRAA_ERROR_UNSPECIFIED;
}
}
mraa_result_t
mraa_mock_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
{
if (dev->addr == dev->mock_dev_addr) {
if ((command + 1) < dev->mock_dev_data_len) {
// Let's say the device is big-endian
dev->mock_dev_data[command] = (data & 0xFF00) >> 8;
dev->mock_dev_data[command + 1] = data & 0x00FF;
return MRAA_SUCCESS;
} else {
syslog(LOG_ERR,
"i2c%i: write_word_data: Command/register number is too big, max is 0x%X",
dev->busnum, dev->mock_dev_data_len - 2);
return MRAA_ERROR_UNSPECIFIED;
}
} else {
// Not our mock device
return MRAA_ERROR_UNSPECIFIED;
}
}

View File

@@ -36,11 +36,14 @@
#include <glob.h>
#include <ftw.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <unistd.h>
#include <ctype.h>
#include <limits.h>
#if defined(IMRAA)
#include <json-c/json.h>
@@ -52,13 +55,20 @@
#include "firmata/firmata_mraa.h"
#include "gpio.h"
#include "version.h"
#include "i2c.h"
#include "pwm.h"
#include "aio.h"
#include "spi.h"
#include "uart.h"
#define IIO_DEVICE_WILDCARD "iio:device*"
mraa_board_t* plat = NULL;
mraa_iio_info_t* plat_iio = NULL;
mraa_lang_func_t* lang_func = NULL;
static char* platform_name = NULL;
char* platform_name = NULL;
static char* platform_long_name = NULL;
static int num_i2c_devices = 0;
@@ -90,9 +100,11 @@ mraa_result_t
imraa_init()
{
if (plat != NULL) {
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
return MRAA_SUCCESS;
}
char* env_var;
mraa_result_t ret;
mraa_platform_t platform_type = MRAA_NULL_PLATFORM;
uid_t proc_euid = geteuid();
struct passwd* proc_user = getpwuid(proc_euid);
@@ -106,16 +118,34 @@ imraa_init()
syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);
mraa_platform_t platform_type;
// Check to see if the enviroment variable has been set
env_var = getenv(MRAA_JSONPLAT_ENV_VAR);
if (env_var != NULL) {
// We only care about success, the init will write to syslog if things went wrong
switch ((ret = mraa_init_json_platform(env_var))) {
case MRAA_SUCCESS:
platform_type = plat->platform_type;
break;
default:
syslog(LOG_NOTICE, "libmraa was unable to initialise a platform from json");
}
}
// Not an else because if the env var didn't load what we wanted maybe we can still load something
if (platform_type == MRAA_NULL_PLATFORM) {
#if defined(X86PLAT)
// Use runtime x86 platform detection
platform_type = mraa_x86_platform();
// Use runtime x86 platform detection
platform_type = mraa_x86_platform();
#elif defined(ARMPLAT)
// Use runtime ARM platform detection
platform_type = mraa_arm_platform();
// Use runtime ARM platform detection
platform_type = mraa_arm_platform();
#elif defined(MOCKPLAT)
// Use mock platform
platform_type = mraa_mock_platform();
#else
#error mraa_ARCH NOTHING
#endif
}
if (plat != NULL) {
plat->platform_type = platform_type;
@@ -187,7 +217,7 @@ mraa_result_t __attribute__((constructor))
mraa_init()
{
if (plat != NULL) {
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
return MRAA_SUCCESS;
} else {
return imraa_init();
}
@@ -196,6 +226,7 @@ mraa_init()
void
mraa_deinit()
{
int i = 0;
if (plat != NULL) {
if (plat->pins != NULL) {
free(plat->pins);
@@ -207,6 +238,19 @@ mraa_deinit()
}
free(sub_plat);
}
#if defined(JSONPLAT)
if (plat->platform_type == MRAA_JSON_PLATFORM) {
// Free the platform name
free(plat->platform_name);
// Free the UART device path
for (i = 0; i < plat->uart_dev_count; i++) {
if (plat->uart_dev[i].device_path != NULL) {
free(plat->uart_dev[i].device_path);
}
}
}
#endif
free(plat);
}
@@ -217,7 +261,7 @@ mraa_deinit()
}
int
mraa_set_priority(const unsigned int priority)
mraa_set_priority(const int priority)
{
struct sched_param sched_s;
@@ -282,10 +326,11 @@ mraa_iio_detect()
mraa_result_t
mraa_setup_mux_mapped(mraa_pin_t meta)
{
int mi;
unsigned int mi;
mraa_result_t ret;
mraa_gpio_context mux_i = NULL;
int last_pin = -1;
// avoids the unsigned comparison and we should never have a pin that is UINT_MAX!
unsigned int last_pin = UINT_MAX;
for (mi = 0; mi < meta.mux_total; mi++) {
@@ -486,6 +531,15 @@ mraa_result_print(mraa_result_t result)
case MRAA_ERROR_PLATFORM_NOT_INITIALISED:
fprintf(stdout, "MRAA: Platform not initialised.\n");
break;
case MRAA_ERROR_UART_OW_SHORTED:
fprintf(stdout, "MRAA: UART OW: Bus short detected.\n");
break;
case MRAA_ERROR_UART_OW_NO_DEVICES:
fprintf(stdout, "MRAA: UART OW: No devices detected on bus.\n");
break;
case MRAA_ERROR_UART_OW_DATA_ERROR:
fprintf(stdout, "MRAA: UART OW: Data or Bus error detected.\n");
break;
case MRAA_ERROR_UNSPECIFIED:
fprintf(stdout, "MRAA: Unspecified Error.\n");
break;
@@ -526,35 +580,35 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
switch (mode) {
case MRAA_PIN_VALID:
if (current_plat->pins[pin].capabilites.valid == 1)
if (current_plat->pins[pin].capabilities.valid == 1)
return 1;
break;
case MRAA_PIN_GPIO:
if (current_plat->pins[pin].capabilites.gpio == 1)
if (current_plat->pins[pin].capabilities.gpio == 1)
return 1;
break;
case MRAA_PIN_PWM:
if (current_plat->pins[pin].capabilites.pwm == 1)
if (current_plat->pins[pin].capabilities.pwm == 1)
return 1;
break;
case MRAA_PIN_FAST_GPIO:
if (current_plat->pins[pin].capabilites.fast_gpio == 1)
if (current_plat->pins[pin].capabilities.fast_gpio == 1)
return 1;
break;
case MRAA_PIN_SPI:
if (current_plat->pins[pin].capabilites.spi == 1)
if (current_plat->pins[pin].capabilities.spi == 1)
return 1;
break;
case MRAA_PIN_I2C:
if (current_plat->pins[pin].capabilites.i2c == 1)
if (current_plat->pins[pin].capabilities.i2c == 1)
return 1;
break;
case MRAA_PIN_AIO:
if (current_plat->pins[pin].capabilites.aio == 1)
if (current_plat->pins[pin].capabilities.aio == 1)
return 1;
break;
case MRAA_PIN_UART:
if (current_plat->pins[pin].capabilites.uart == 1)
if (current_plat->pins[pin].capabilities.uart == 1)
return 1;
break;
default:
@@ -666,7 +720,7 @@ mraa_get_i2c_bus_count()
}
int
mraa_get_i2c_bus_id(unsigned i2c_bus)
mraa_get_i2c_bus_id(int i2c_bus)
{
if (plat == NULL) {
return -1;
@@ -973,6 +1027,9 @@ 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 (mraa_firmata_platform(plat, uart_dev) == MRAA_GENERIC_FIRMATA) {
syslog(LOG_NOTICE, "mraa: Added firmata subplatform");
return MRAA_SUCCESS;
@@ -984,6 +1041,22 @@ mraa_add_subplatform(mraa_platform_t subplatformtype, const char* uart_dev)
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
mraa_remove_subplatform(mraa_platform_t subplatformtype)
{
#if defined(FIRMATA)
if (subplatformtype == MRAA_GENERIC_FIRMATA) {
if (plat == NULL || plat->sub_platform == NULL) {
return MRAA_ERROR_INVALID_PARAMETER;
}
free(plat->sub_platform->adv_func);
free(plat->sub_platform->pins);
free(plat->sub_platform);
}
#endif
return MRAA_ERROR_INVALID_PARAMETER;
}
#if defined(IMRAA)
mraa_result_t
mraa_add_from_lockfile(const char* imraa_lock_file)
@@ -1045,3 +1118,163 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
return ret;
}
#endif
void
mraa_to_upper(char* s)
{
char* t = s;
for (; *t; ++t) {
*t = toupper(*t);
}
}
mraa_result_t
mraa_atoi(char* intStr, int* value)
{
char* end;
// here 10 determines the number base in which strol is to work
long val = strtol(intStr, &end, 10);
if (*end != '\0' || errno == ERANGE || end == intStr || val > INT_MAX || val < INT_MIN) {
*value = 0;
return MRAA_ERROR_UNSPECIFIED;
}
*value = (int) val;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_init_io_helper(char** str, int* value, const char* delim)
{
// This function is a result of a repeated pattern within mraa_init_io
// when determining if a value can be derived from a string
char* token;
token = strsep(str, delim);
// check to see if empty string returned
if (token == NULL) {
*value = 0;
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
return mraa_atoi(token, value);
}
void*
mraa_init_io(const char* desc)
{
const char* delim = "-";
int length = 0, raw = 0;
int pin = 0, id = 0;
// 256 denotes the maximum size of our buffer
// 8 denotes the maximum size of our type rounded to the nearest power of 2
// max size is 4 + 1 for the \0 = 5 rounded to 8
char buffer[256] = { 0 }, type[8] = { 0 };
char *token = 0, *str = 0;
if (desc == NULL) {
return NULL;
}
length = strlen(desc);
// Check to see the length is less than or equal to 255 which means
// byte 256 is supposed to be \0
if (length > 255 || length == 0) {
return NULL;
}
strncpy(buffer, desc, length);
str = buffer;
token = strsep(&str, delim);
length = strlen(token);
// Check to see they haven't given us a type whose length is greater than the
// largest type we know about
if (length > 4) {
syslog(LOG_ERR, "mraa_init_io: An invalid IO type was provided");
return NULL;
}
strncpy(type, token, length);
mraa_to_upper(type);
token = strsep(&str, delim);
// Check that they've given us more information than just the type
if (token == NULL) {
syslog(LOG_ERR, "mraa_init_io: Missing information after type");
return NULL;
}
// If we cannot convert the pin to a number maybe it says raw?
if (mraa_atoi(token, &pin) != MRAA_SUCCESS) {
mraa_to_upper(token);
if (strncmp(token, "RAW", 3)) {
syslog(LOG_ERR, "mraa_init_io: Description does not adhere to a known format");
return NULL;
}
raw = 1;
}
if (!raw && str != NULL) {
syslog(LOG_ERR, "mraa_init_io: More information than required was provided");
return NULL;
}
if (strncmp(type, "GPIO", 4) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_gpio_init_raw(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for GPIO");
return NULL;
}
return (void*) mraa_gpio_init(pin);
} else if (strncmp(type, "I2C", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
return (void*) mraa_i2c_init_raw(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for I2C");
return NULL;
}
return (void*) mraa_i2c_init(pin);
} else if (strncmp(type, "AIO", 3) == 0) {
if (raw) {
syslog(LOG_ERR, "mraa_init_io: Aio doesn't have a RAW mode");
return NULL;
}
return (void*) mraa_aio_init(pin);
} else if (strncmp(type, "PWM", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a useable Int");
return NULL;
}
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the pin string into a useable Int");
return NULL;
}
return (void*) mraa_pwm_init_raw(id, pin);
}
return (void*) mraa_pwm_init(pin);
} else if (strncmp(type, "SPI", 3) == 0) {
if (raw) {
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the bus string into a useable Int");
return NULL;
}
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the cs string into a useable Int");
return NULL;
}
return (void*) mraa_spi_init_raw(id, pin);
}
return (void*) mraa_spi_init(pin);
} else if (strncmp(type, "UART", 4) == 0) {
if (raw) {
return (void*) mraa_uart_init_raw(str);
}
return (void*) mraa_uart_init(pin);
}
syslog(LOG_ERR, "mraa_init_io: Invalid IO type given.");
return NULL;
}
#ifndef JSONPLAT
mraa_result_t
mraa_init_json_platform(const char* desc)
{
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
}
#endif

View File

@@ -41,6 +41,19 @@
%include "types.hpp"
%include "common.hpp"
%template (gpioFromDesc) mraa::initIo<mraa::Gpio>;
%template (aioFromDesc) mraa::initIo<mraa::Aio>;
%template (uartFromDesc) mraa::initIo<mraa::Uart>;
%template (spiFromDesc) mraa::initIo<mraa::Spi>;
%template (i2cFromDesc) mraa::initIo<mraa::I2c>;
%template (pwmFromDesc) mraa::initIo<mraa::Pwm>;
%ignore Aio(void* aio_context);
%ignore Pwm(void* pwm_context);
%ignore Uart(void* uart_context);
%ignore Spi(void* spi_context);
%ignore I2c(void* i2c_context);
%ignore Gpio(void* gpio_context);
%ignore Gpio::nop(uv_work_t* req);
%ignore Gpio::v8isr(uv_work_t* req);

View File

@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib@LIB_SUFFIX@
libdir=${exec_prefix}/@LIB_INSTALL_DIR@
includedir=${prefix}/include
Name: mraa

View File

@@ -27,6 +27,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <string.h>
#include "pwm.h"
#include "mraa_internal.h"
@@ -50,6 +52,11 @@ mraa_pwm_setup_duty_fp(mraa_pwm_context dev)
static mraa_result_t
mraa_pwm_write_period(mraa_pwm_context dev, int period)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_period_replace)) {
mraa_result_t result = dev->advance_func->pwm_period_replace(dev, period);
if (result == MRAA_SUCCESS) {
@@ -62,13 +69,14 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
int period_f = open(bu, O_RDWR);
if (period_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open period for writing");
syslog(LOG_ERR, "pwm%i write_period: Failed to open period for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[MAX_SIZE];
int length = snprintf(out, MAX_SIZE, "%d", period);
if (write(period_f, out, length * sizeof(char)) == -1) {
close(period_f);
syslog(LOG_ERR, "pwm%i write_period: Failed to write to period: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
@@ -80,24 +88,38 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
static mraa_result_t
mraa_pwm_write_duty(mraa_pwm_context dev, int duty)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write_duty: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_write_replace)) {
return dev->advance_func->pwm_write_replace(dev, duty);
}
if (dev->duty_fp == -1) {
if (mraa_pwm_setup_duty_fp(dev) == 1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "pwm%i write_duty: Failed to open duty_cycle for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
}
char bu[64];
int length = sprintf(bu, "%d", duty);
if (write(dev->duty_fp, bu, length * sizeof(char)) == -1)
{
syslog(LOG_ERR, "pwm%i write_duty: Failed to write to duty_cycle: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
static int
mraa_pwm_read_period(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_read_replace)) {
return dev->period;
}
@@ -108,27 +130,25 @@ mraa_pwm_read_period(mraa_pwm_context dev)
int period_f = open(bu, O_RDWR);
if (period_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open period for reading");
syslog(LOG_ERR, "pwm%i read_period: Failed to open period for reading: %s", dev->pin, strerror(errno));
return 0;
}
off_t size = lseek(period_f, 0, SEEK_END);
lseek(period_f, 0, SEEK_SET);
ssize_t rb = read(period_f, output, size + 1);
ssize_t rb = read(period_f, output, MAX_SIZE);
close(period_f);
if (rb < 0) {
syslog(LOG_ERR, "pwm: Error in reading period");
syslog(LOG_ERR, "pwm%i read_period: Failed to read period: %s", dev->pin, strerror(errno));
return -1;
}
char* endptr;
long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string conversion");
syslog(LOG_ERR, "pwm%i read_period: Error in string conversion", dev->pin);
return -1;
} else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid");
syslog(LOG_ERR, "pwm%i read_period: Number is invalid", dev->pin);
return -1;
}
dev->period = (int) ret;
@@ -138,33 +158,39 @@ mraa_pwm_read_period(mraa_pwm_context dev)
static int
mraa_pwm_read_duty(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read_duty: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_read_replace)) {
return dev->advance_func->pwm_read_replace(dev);
}
if (dev->duty_fp == -1) {
if (mraa_pwm_setup_duty_fp(dev) == 1) {
return MRAA_ERROR_INVALID_HANDLE;
syslog(LOG_ERR, "pwm%i read_duty: Failed to open duty_cycle for reading: %s",
dev->pin, strerror(errno));
return -1;
}
} else {
lseek(dev->duty_fp, 0, SEEK_SET);
}
off_t size = lseek(dev->duty_fp, 0, SEEK_END);
lseek(dev->duty_fp, 0, SEEK_SET);
char output[MAX_SIZE];
ssize_t rb = read(dev->duty_fp, output, size + 1);
ssize_t rb = read(dev->duty_fp, output, MAX_SIZE);
if (rb < 0) {
syslog(LOG_ERR, "pwm: Error in reading duty");
syslog(LOG_ERR, "pwm%i read_duty: Failed to read duty_cycle: %s", dev->pin, strerror(errno));
return -1;
}
char* endptr;
long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string converstion");
syslog(LOG_ERR, "pwm%i read_duty: Error in string conversion", dev->pin);
return -1;
} else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid");
syslog(LOG_ERR, "pwm%i read_duty: Number is invalid", dev->pin);
return -1;
}
return (int) ret;
@@ -191,24 +217,24 @@ mraa_pwm_init(int pin)
{
mraa_board_t* board = plat;
if (board == NULL) {
syslog(LOG_ERR, "pwm: Platform Not Initialised");
syslog(LOG_ERR, "pwm_init: Platform Not Initialised");
return NULL;
}
if (mraa_is_sub_platform_id(pin)) {
syslog(LOG_NOTICE, "pwm: Using sub platform");
syslog(LOG_NOTICE, "pwm_init: Using sub platform");
board = board->sub_platform;
if (board == NULL) {
syslog(LOG_ERR, "pwm: Sub platform Not Initialised");
syslog(LOG_ERR, "pwm_init: Sub platform Not Initialised");
return NULL;
}
pin = mraa_get_sub_platform_index(pin);
}
if (pin < 0 || pin > board->phy_pin_count) {
syslog(LOG_ERR, "pwm: pin %i beyond platform definition", pin);
syslog(LOG_ERR, "pwm_init: pin %i beyond platform definition", pin);
return NULL;
}
if (board->pins[pin].capabilites.pwm != 1) {
syslog(LOG_ERR, "pwm: pin not capable of pwm");
if (board->pins[pin].capabilities.pwm != 1) {
syslog(LOG_ERR, "pwm_init: pin %i not capable of pwm", pin);
return NULL;
}
@@ -223,31 +249,9 @@ mraa_pwm_init(int pin)
return NULL;
}
if (board->pins[pin].capabilites.gpio == 1) {
// This deserves more investigation
mraa_gpio_context mux_i;
mux_i = mraa_gpio_init_raw(board->pins[pin].gpio.pinmap);
if (mux_i == NULL) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
return NULL;
}
if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
return NULL;
}
if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
return NULL;
}
if (mraa_gpio_close(mux_i) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
return NULL;
}
}
if (board->pins[pin].pwm.mux_total > 0) {
if (mraa_setup_mux_mapped(board->pins[pin].pwm) != MRAA_SUCCESS) {
syslog(LOG_ERR, "pwm: Failed to set-up multiplexer");
syslog(LOG_ERR, "pwm_init: Failed to set-up pwm%i multiplexer", pin);
return NULL;
}
}
@@ -278,14 +282,14 @@ mraa_pwm_init_raw(int chipin, int pin)
snprintf(directory, MAX_SIZE, SYSFS_PWM "/pwmchip%d/pwm%d", dev->chipid, dev->pin);
struct stat dir;
if (stat(directory, &dir) == 0 && S_ISDIR(dir.st_mode)) {
syslog(LOG_NOTICE, "pwm: Pin already exported, continuing");
syslog(LOG_NOTICE, "pwm_init: pwm%i already exported, continuing", pin);
dev->owner = 0; // Not Owner
} else {
char buffer[MAX_SIZE];
snprintf(buffer, MAX_SIZE, "/sys/class/pwm/pwmchip%d/export", dev->chipid);
int export_f = open(buffer, O_WRONLY);
if (export_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open export for writing");
syslog(LOG_ERR, "pwm_init: pwm%i. Failed to open export for writing: %s", pin, strerror(errno));
free(dev);
return NULL;
}
@@ -293,7 +297,7 @@ mraa_pwm_init_raw(int chipin, int pin)
char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(export_f, out, size * sizeof(char)) == -1) {
syslog(LOG_WARNING, "pwm: Failed to write to export! Potentially already enabled");
syslog(LOG_WARNING, "pwm_init: pwm%i. Failed to write to export! (%s) Potentially already in use.", pin, strerror(errno));
close(export_f);
free(dev);
return NULL;
@@ -309,13 +313,25 @@ mraa_pwm_init_raw(int chipin, int pin)
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
if (!dev) {
syslog(LOG_ERR, "pwm: write: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_write_pre)) {
if (dev->advance_func->pwm_write_pre(dev, percentage) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_pwm_write (pwm%i): pwm_write_pre failed, see syslog", dev->pin);
return MRAA_ERROR_UNSPECIFIED;
}
}
if (dev->period == -1) {
if (mraa_pwm_read_period(dev) <= 0)
return MRAA_ERROR_NO_DATA_AVAILABLE;
}
if (percentage > 1.0f) {
syslog(LOG_WARNING, "pwm: number greater than 1 entered, defaulting to 100%%");
syslog(LOG_WARNING, "pwm_write: %i%% entered, defaulting to 100%%",(int) percentage * 100);
return mraa_pwm_write_duty(dev, dev->period);
}
return mraa_pwm_write_duty(dev, percentage * dev->period);
@@ -324,6 +340,11 @@ mraa_pwm_write(mraa_pwm_context dev, float percentage)
float
mraa_pwm_read(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: read: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
int period = mraa_pwm_read_period(dev);
if (period > 0) {
return (mraa_pwm_read_duty(dev) / (float) period);
@@ -347,6 +368,12 @@ mraa_result_t
mraa_pwm_period_us(mraa_pwm_context dev, int us)
{
int min, max;
if (!dev) {
syslog(LOG_ERR, "pwm: period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
min = plat->sub_platform->pwm_min_period;
max = plat->sub_platform->pwm_max_period;
@@ -355,7 +382,7 @@ mraa_pwm_period_us(mraa_pwm_context dev, int us)
max = plat->pwm_max_period;
}
if (us < min || us > max) {
syslog(LOG_ERR, "pwm: period value outside platform range");
syslog(LOG_ERR, "pwm_period: pwm%i: %i uS outside platform range", dev->pin, us);
return MRAA_ERROR_INVALID_PARAMETER;
}
return mraa_pwm_write_period(dev, us * 1000);
@@ -382,25 +409,37 @@ mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us)
mraa_result_t
mraa_pwm_enable(mraa_pwm_context dev, int enable)
{
if (!dev) {
syslog(LOG_ERR, "pwm: enable: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, pwm_enable_replace)) {
return dev->advance_func->pwm_enable_replace(dev, enable);
}
int status;
if (IS_FUNC_DEFINED(dev, pwm_enable_pre)) {
if (dev->advance_func->pwm_enable_pre(dev, enable) != MRAA_SUCCESS) {
syslog(LOG_ERR, "mraa_pwm_enable (pwm%i): pwm_enable_pre failed, see syslog", dev->pin);
return MRAA_ERROR_UNSPECIFIED;
}
}
char bu[MAX_SIZE];
snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/enable", dev->chipid, dev->pin);
int enable_f = open(bu, O_RDWR);
if (enable_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open enable for writing");
syslog(LOG_ERR, "pwm_enable: pwm%i: Failed to open enable for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[2];
int size = snprintf(out, sizeof(out), "%d", enable);
if (write(enable_f, out, size * sizeof(char)) == -1) {
syslog(LOG_ERR, "pwm: Failed to write to enable");
syslog(LOG_ERR, "pwm_enable: pwm%i: Failed to write to enable: %s", dev->pin, strerror(errno));
close(enable_f);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(enable_f);
return MRAA_SUCCESS;
@@ -414,16 +453,16 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
int unexport_f = open(filepath, O_WRONLY);
if (unexport_f == -1) {
syslog(LOG_ERR, "pwm: Failed to open unexport for writing");
syslog(LOG_ERR, "pwm_unexport: pwm%i: Failed to open unexport for writing: %s", dev->pin, strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(unexport_f, out, size * sizeof(char)) == -1) {
syslog(LOG_ERR, "pwm: Failed to write to unexport");
syslog(LOG_ERR, "pwm_unexport: pwm%i: Failed to write to unexport: %s", dev->pin, strerror(errno));
close(unexport_f);
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_UNSPECIFIED;
}
close(unexport_f);
@@ -433,16 +472,26 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
mraa_result_t
mraa_pwm_unexport(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: unexport: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
mraa_pwm_enable(dev, 0);
if (dev->owner) {
return mraa_pwm_unexport_force(dev);
}
return MRAA_ERROR_INVALID_RESOURCE;
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_result_t
mraa_pwm_close(mraa_pwm_context dev)
{
if (!dev) {
syslog(LOG_ERR, "pwm: close: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
mraa_pwm_unexport(dev);
free(dev);
return MRAA_SUCCESS;
@@ -451,66 +500,26 @@ mraa_pwm_close(mraa_pwm_context dev)
mraa_result_t
mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner_new)
{
if (dev == NULL)
return MRAA_ERROR_INVALID_RESOURCE;
if (!dev) {
syslog(LOG_ERR, "pwm: owner: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
dev->owner = owner_new;
return MRAA_SUCCESS;
}
mraa_result_t
mraa_pwm_config_ms(mraa_pwm_context dev, int ms, float ms_float)
{
int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
return status;
}
status = mraa_pwm_write_duty(dev, 0);
if (status != MRAA_SUCCESS) {
return status;
}
status = mraa_pwm_pulsewidth_us(dev, ms_float * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period);
return status;
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_pwm_config_percent(mraa_pwm_context dev, int ms, float percentage)
{
int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
return status;
}
status = mraa_pwm_write_duty(dev, 0);
if (status != MRAA_SUCCESS) {
return status;
}
status = mraa_pwm_pulsewidth_us(dev, (ms * 1000) * percentage);
if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period);
return status;
}
return MRAA_SUCCESS;
}
int
mraa_pwm_get_max_period(mraa_pwm_context dev)
{
if (plat == NULL) {
return -1;
}
if (!dev) {
syslog(LOG_ERR, "pwm: get_max_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
return plat->sub_platform->pwm_max_period;
}
@@ -523,6 +532,12 @@ mraa_pwm_get_min_period(mraa_pwm_context dev)
if (plat == NULL) {
return -1;
}
if (!dev) {
syslog(LOG_ERR, "pwm: get_min_period: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (mraa_is_sub_platform_id(dev->chipid)) {
return plat->sub_platform->pwm_min_period;
}

View File

@@ -1,50 +1,5 @@
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
${PYTHON_INCLUDE_DIRS}
)
set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
swig_add_module (python-mraa python mraa.i mraapy.c)
swig_link_libraries (python-mraa ${PYTHON_LIBRARIES} mraa)
if (DOXYGEN_FOUND)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} common_hpp_doc_i)
add_custom_target (pydoc
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pydoc" VERBATIM
)
endif ()
set_target_properties (${SWIG_MODULE_python-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
)
execute_process (
COMMAND ${PYTHON_EXECUTABLE} -c
"import site, sys; sys.stdout.write(site.PREFIXES[-1])"
OUTPUT_VARIABLE PYTHON_PREFIX
)
file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
execute_process (
COMMAND ${PYTHON_EXECUTABLE} -c
"import site, sys; sys.stdout.write(site.getusersitepackages().replace(site.getuserbase(), site.PREFIXES[-1]))"
OUTPUT_VARIABLE PYTHON_SITE_DIR
)
file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
string (REGEX REPLACE "^${PYTHON_PREFIX}/" ""
PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${PYTHON_SITE_DIR})
add_subdirectory (docs)
add_subdirectory (python2)
add_subdirectory (python3)

View File

@@ -1,7 +1,3 @@
%module(docstring="Python interface to libmraa") mraa
%feature("autodoc", "3");
%include typemaps.i
%include carrays.i

View File

@@ -0,0 +1,39 @@
set_source_files_properties (mraa2.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa2.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
if (PYTHON2_LIBRARY)
message ("PYTHON2 attempting to build!")
swig_add_module (python2-mraa python mraa2.i ../mraapy.c)
swig_link_libraries (python2-mraa ${PYTHON2_LIBRARIES} mraa)
target_include_directories(${SWIG_MODULE_python2-mraa_REAL_NAME}
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
"${PYTHON2_INCLUDE_DIR}"
)
if (DOXYGEN_FOUND AND PYTHON2_EXECUTABLE)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} common_hpp_doc_i)
add_custom_target (pydoc
python2 /usr/bin/pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pydoc" VERBATIM
)
endif ()
set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
endif()
add_subdirectory (docs)

View File

@@ -36,6 +36,6 @@ if (DOXYGEN_FOUND)
COMMENT "Building HTML documentation with Sphinx"
)
add_dependencies (sphinx ${SWIG_MODULE_python-mraa_REAL_NAME})
add_dependencies (sphinx ${SWIG_MODULE_python2-mraa_REAL_NAME})
endif ()
endif ()

View File

@@ -19,7 +19,7 @@ import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, "@CMAKE_BINARY_DIR@/src/python")
sys.path.insert(0, "@CMAKE_BINARY_DIR@/src/python/python2")
# -- General configuration ------------------------------------------------

View File

@@ -16,13 +16,13 @@ Here is the simplest Gpio program in mraa.
:prepend: import mraa
:start-after: import mraa
GPIO Interupt (isr)
GPIO Interrupt (isr)
===================
The GPIO module allows you to set an interupt on a GPIO. This interupt is
The GPIO module allows you to set an interrupt on a GPIO. This interrupt is
controlled by the mode that the 'edge' is in. Before setting another isr please
remove the first one, multiple isrs on one pin are not supported. Some
platforms will not support interupts on all pins so please check your return
platforms will not support interrupts on all pins so please check your return
values.
**Note:** Galileo Gen1 only supports EDGE_BOTH

Some files were not shown because too many files have changed in this diff Show More