Compare commits

...

29 Commits

Author SHA1 Message Date
Brendan Le Foll
ea6d771c2b gpio.h: Add gpio_event doc
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
mihais
2b98fc7869 gpio: chardev interface / multiple gpio support for sysfs
Signed-off-by: Mihai Stefanescu <mihai.t.gh.stefanescu@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Brendan Le Foll
fbc2ad6045 chardev: split up helper functions in gpio_chardev
Remove some _multiple functions and replace with generic function that
does both. Some general cleanup and will move more interrnal mraa
functions to use the _mraa prefix

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Brendan Le Foll
32ab283c2b firmata_mraa.c: Fix warnings in firmata code due to incorrect code
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Mihai Stefanescu
9f7caf1561 Joule: Add gpiod mapping for Joule
Signed-off-by: Mihai Stefanescu <mihai.t.gh.stefanescu@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Brendan Le Foll
12c1904fba gpio.h: Add stripped kernel header
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Mihai Stefanescu
1665e09928 gpio: Add gpio chardev interface
Signed-off-by: Mihai Stefanescu <mihai.t.gh.stefanescu@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:42:02 +01:00
Brendan Le Foll
aa7006cce9 travis: Remove IPK & RPM builds
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:40:00 +01:00
Brendan Le Foll
9bc3ffe815 raspberry_pi.c: Removing spi_frequency_replace as that has become default behaviour
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:34:40 +01:00
Brendan Le Foll
7840710d1b spi.c: Stop trusting SPI_IOC_RD_MAX_SPEED_HZ from the kernel and trust our users
SPI_IOC_RD_MAX_SPEED_HZ is often incorrect and too low (RPI, UP2, galileo g1 at
least). Likely this is because driver writers are too concious of possible
issues or because they don't have the final hardware. Because of this we now
will only LOG_NOTICE on exceeding SPI_IOC_RD_MAX_SPEED_HZ and try keep going
anyways. This effectively will put the burden of not exceeding
SPI_IOC_RD_MAX_SPEED_HZ on our users.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 13:34:40 +01:00
Brendan Le Foll
ae2371c804 cmake: Remove all cpack options including IPK generation
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-03-05 11:45:39 +01:00
Alex Tereschenko
2deaa73ebf static code analysis: correct SonarCloud URL
According to SonarCloud's email notification,
they're dropping sonarqube.com in favor of sonarcloud.io.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-03-02 20:27:15 +01:00
Mihai Tudor Panu
fbb7d92320 mraa: Update to v1.9.0
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-02-15 15:08:49 -08:00
Alex Tereschenko
2d210621cc mraa.c: make mraa_gpio_lookup() return proper pin index
Pinmap field value is an OS pin number, not mraa pin index,
so make the function return the proper one.

Fixes #817.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-02-07 17:28:58 +01:00
Brendan Le Foll
568c077061 building.md: Add note for static builds and bindings
Closes #864

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-02-07 09:42:34 +01:00
Mihai Tudor Panu
616ffc0b94 cmake: fix indentation on some messages for consistency
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-02-06 20:48:32 -05:00
Mihai Tudor Panu
60b77d5da9 FindNodejs: extend search path to detect ubuntu provided nodejs
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-02-06 20:29:37 -05:00
Noel Eck
cb03cab04a FindNodejs: Updated to find node<version>
Updates to the FindNodejs.cmake module to find newer installs of nodejs
across other distros.  For example openSUSE: /usr/include/node6/node.h

    * Added PATH_SUFFIX to find_path for node.h.
    * Standardized usage of message() (added STATUS)
    * Call find_package_handle_standard_args with version
    * Reformatted to look uniform.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-02-06 10:05:39 -08:00
Khem Raj
c9566bdc6f examples: include endian.h for be16toh and le16toh declarations
this gets exposed on musl, on glibc endian.h gets pulled in indirectly

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-02-06 13:34:28 +01:00
Manivannan Sadhasivam
eda9d03547 examples: Cleanup Python examples
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-02-06 13:31:19 +01:00
Alex Tereschenko
c7faa20c14 readme: add Sonar quality gate badge
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-02-06 13:27:37 +01:00
Alex Tereschenko
2c9d9aaf80 intel_edison_fab_c.c: use snprintf(), not sprintf(), to avoid overflows
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-02-03 17:05:25 +01:00
Alex Tereschenko
fd937e69ef src/led.c: make sure we don't try to close a NULL dir
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-02-03 17:05:25 +01:00
Alex Tereschenko
6e13268301 examples: fix static code analysis findings
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-02-03 17:05:25 +01:00
Alex Tereschenko
9b08a97d46 docs: add static code analysis documentation
Fixes #782.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-01-28 15:34:50 +01:00
Manivannan Sadhasivam
25b951dd6a examples: Fix samples.mapping
Fix samples.mapping.txt with the cleaned-up C++ examples

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-01-25 11:24:23 +01:00
Manivannan Sadhasivam
9f44dc45d8 api: mraa: gpio: Fix doxygen warning
This commit fixes the below doxygen warning:

"warning: unexpected token in comment block while parsing the argument of command param"

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-01-25 11:23:36 +01:00
Manivannan Sadhasivam
d7490d87f2 api: mraa: Add cleaned-up C++ examples to doxygen doc
Add the cleaned-up C++ examples to doxygen doc by modifying the @snippet
tag.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-01-25 11:23:36 +01:00
Manivannan Sadhasivam
83a67b96fd examples: Cleanup C++ examples
Modify the C++ examples to be of same coding standard like C. As a
part of this cleanup, a new LED example is also added.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2018-01-25 11:23:36 +01:00
74 changed files with 2848 additions and 1038 deletions

View File

@@ -14,8 +14,6 @@ before_install:
jobs:
fast_finish: true
allow_failures:
- env: TARGET=ipk
include:
- &run-with-clang
stage: Clang 3.8
@@ -93,9 +91,5 @@ jobs:
env: TARGET=imraa
- <<: *run-additional-jobs
env: TARGET=ftdi4442
- <<: *run-additional-jobs
env: TARGET=ipk
- <<: *run-additional-jobs
env: TARGET=rpm
- <<: *run-additional-jobs
env: TARGET=sonar-scan

View File

@@ -91,7 +91,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
message (WARNING " - Install git to compile a production libmraa!")
set (VERSION "v1.8.0")
set (VERSION "v1.9.0")
endif ()
message (STATUS "INFO - libmraa Version ${VERSION}")
@@ -134,8 +134,6 @@ 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 (ENABLEEXAMPLES "Disable building of examples" ON)
option (INSTALLTOOLS "Install all tools" ON)
option (BUILDTESTS "Override the addition of tests" ON)
@@ -197,66 +195,6 @@ if (BUILDDOC)
endif (DOXYGEN_FOUND AND DOXYGEN_VERSION VERSION_GREATER "1.8")
endif ()
if (IPK)
# Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
if (DEFINED ENV{OECORE_TARGET_SYSROOT})
GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
else ()
# debian uses amd64 to denote x86_64
if (DETECTED_ARCH STREQUAL "x86_64")
set (TARGET_ARCH "amd64")
else ()
set (TARGET_ARCH ${DETECTED_ARCH})
endif ()
endif ()
message (STATUS "INFO - Package arch is ${TARGET_ARCH}")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${TARGET_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
set(mraa_PACKAGE_ON_TAG ".")
if ("${VERSION_COMMIT}" STREQUAL "")
set(mraa_PACKAGE_ON_TAG "")
endif()
set(CPACK_PACKAGE_VERSION
"${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_NAME "mraa")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
set(CPACK_DEBIAN_PACKAGE_PROVIDES "mraa-dev, mraa-dbg, mraa-doc")
set(CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_PROVIDES}, libmraa, libmraa-dev, libmraa-doc")
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
include (CPack)
endif()
if (RPM)
message (STATUS "INFO - Enabled RPM packaging for ${DETECTED_ARCH}")
set(CMAKE_INSTALL_PREFIX "/usr")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_VERSION
"${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
# Get distro tag (e.g. 'fc20') by parsing output of rpm --showrc
EXECUTE_PROCESS(
COMMAND rpm --showrc
COMMAND grep -w dist
COMMAND sed -e "s/\\t./ /"
COMMAND awk "{printf \"%s\", \$NF}"
OUTPUT_VARIABLE DIST_TAG
)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
include(CPack)
endif()
add_subdirectory (src)
if (ENABLEEXAMPLES)
add_subdirectory (examples)

View File

@@ -16,7 +16,7 @@ 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)
[![Build Status](https://travis-ci.org/intel-iot-devkit/mraa.svg?branch=master)](https://travis-ci.org/intel-iot-devkit/mraa) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=mraa-master&metric=alert_status)](https://sonarcloud.io/dashboard?id=mraa-master)
Supported Boards
================
@@ -123,28 +123,6 @@ in /usr/lib.
Subplatforms (i.e. Firmata) have to be added manually with this kind of install
from your application, as shown in [this example](examples/javascript/firmata.js).
Installing on Intel 32bit Yocto based opkg image
------------------------------------------------
See the section below on compiling or use our repository to install on a glibc
based yocto poky image that supports opkg. Adding this repository is as simple
as and you'll have the latest stable tagged build of mraa installed!
``` bash
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg install mraa
```
If you would like to get the latest & greatest builds from master HEAD you can
use our -dev repository
```bash
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic-dev/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg install mraa
```
Compiling
=========

View File

@@ -36,7 +36,7 @@ namespace mraa
*
* This file defines the aio interface for libmraa
*
* @snippet AioA0.cpp Interesting
* @snippet aio.cpp Interesting
*/
class Aio
{

View File

@@ -50,6 +50,17 @@
if (res != MRAA_SUCCESS) \
return res;} while(0)
/**
* Simple deprecated macro
*/
#ifdef __GNUC__
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED
#endif
/** @file
*

View File

@@ -61,7 +61,10 @@ typedef enum {
MRAA_GPIO_STRONG = 0, /**< Default. Strong high and low */
MRAA_GPIO_PULLUP = 1, /**< Resistive High */
MRAA_GPIO_PULLDOWN = 2, /**< Resistive Low */
MRAA_GPIO_HIZ = 3 /**< High Z State */
MRAA_GPIO_HIZ = 3, /**< High Z State */
MRAA_GPIOD_ACTIVE_LOW = 4,
MRAA_GPIOD_OPEN_DRAIN = 5,
MRAA_GPIOD_OPEN_SOURCE = 6,
} mraa_gpio_mode_t;
/**
@@ -101,6 +104,18 @@ typedef enum {
MRAA_GPIO_PUSH_PULL = 1, /**< Push Pull Configuration */
} mraa_gpio_out_driver_mode_t;
typedef long long unsigned int mraa_timestamp_t;
/**
* Gpio event object
*/
typedef struct {
int id; /**< id of event */
mraa_timestamp_t timestamp; /**< timestamp */
} mraa_gpio_event;
typedef mraa_gpio_event* mraa_gpio_events_t;
/**
* Initialise gpio_context, based on board number
*
@@ -109,6 +124,16 @@ typedef enum {
*/
mraa_gpio_context mraa_gpio_init(int pin);
/**
* Initialise gpio_context, based on board number, for multiple pins (can be one).
*
* @param pins Pin array read from the board
* @param num_pins Number of pins - must be the same as the pins array length provided
* as the first argument.
* @returns gpio context or NULL
*/
mraa_gpio_context mraa_gpio_init_multi(int pins[], int num_pins);
/**
* Initialise gpio context without any mapping to a pin
*
@@ -127,10 +152,10 @@ 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 interrupt on pin
* Set an interrupt on pin(s).
*
* @param dev The Gpio context
* @param edge The edge mode to set the gpio into
* @param edge The edge mode to set the gpio(s) into
* @param fptr Function pointer to function to be called when interrupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
@@ -138,9 +163,19 @@ 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);
/**
* Get an array of structures describing triggered events.
*
* @param dev The Gpio context
* @return Array of structures containing pairs of pin id's and the associated timestamp.
* An event with negative id value indicates that no event was triggered for the respective pin.
* The array length is that of the number of pins provided in mraa_gpio_init_multi().
*/
mraa_gpio_events_t mraa_gpio_get_events(mraa_gpio_context dev);
/**
* Stop the current interrupt watcher on this Gpio, and set the Gpio edge mode
* to MRAA_GPIO_EDGE_NONE
* to MRAA_GPIO_EDGE_NONE(only for sysfs interface).
*
* @param dev The Gpio context
* @return Result of operation
@@ -148,35 +183,36 @@ mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (
mraa_result_t mraa_gpio_isr_exit(mraa_gpio_context dev);
/**
* Set Gpio Output Mode,
* Set Gpio(s) Output Mode,
*
* @param dev The Gpio context
* @param mode The Gpio Output Mode
* @param mode The Gpio(s) Output Mode
* @return Result of operation
*/
mraa_result_t mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode);
/**
* Set Gpio direction
* Set Gpio(s) direction
*
* @param dev The Gpio context
* @param dir The direction of the Gpio
* @param dir The direction of the Gpio(s)
* @return Result of operation
*/
mraa_result_t mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir);
/**
* Read Gpio direction
* Read Gpio(s) direction
*
* @param dev The Gpio context
* @param dir The address where to store the Gpio direction
* @param dir The address where to store the Gpio(s) direction
* @return Result of operation
*/
mraa_result_t mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir);
/**
* Close the Gpio context
* - Will free the memory for the context and unexport the Gpio
* - Will free the memory for the context and unexport the Gpio - sysfs interface.
* - Will free up the memory used by context and close related file descriptors - chardev interface.
*
* @param dev The Gpio context
* @return Result of operation
@@ -192,6 +228,16 @@ mraa_result_t mraa_gpio_close(mraa_gpio_context dev);
*/
int mraa_gpio_read(mraa_gpio_context dev);
/**
* Read the Gpio(s) value. The user must provide an integer array with a length equal to the
* number of pins provided to mraa_gpio_init_multi() function.
*
* @param dev The Gpio context
* @param output_values The array provided by the user. Existing values will be overwritten with the newly read ones.
* @return Result of operation
*/
mraa_result_t mraa_gpio_read_multi(mraa_gpio_context dev, int output_values[]);
/**
* Write to the Gpio Value.
*
@@ -201,6 +247,17 @@ int mraa_gpio_read(mraa_gpio_context dev);
*/
mraa_result_t mraa_gpio_write(mraa_gpio_context dev, int value);
/**
* Write to the Gpio(s) Value. The user must provide an integer array with a length equal to the
* number of pins provided to mraa_gpio_init_multi() function.
*
* @param dev The Gpio context
* @param output_values The array provided by the user. It must contain the values intended to be written
* to the gpio pins, in the same order as the init function.
* @return Result of operation
*/
mraa_result_t mraa_gpio_write_multi(mraa_gpio_context dev, int input_values[]);
/**
* Change ownership of the context.
*
@@ -211,13 +268,15 @@ mraa_result_t mraa_gpio_write(mraa_gpio_context dev, int value);
mraa_result_t mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t owner);
/**
* Enable using memory mapped io instead of sysfs
* Enable using memory mapped io instead of sysfs, chardev based I/O can be
* considered memorymapped
*
* @deprecated
* @param dev The Gpio context
* @param mmap Use mmap instead of sysfs
* @return Result of operation
*/
mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap);
DEPRECATED mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap);
/**
* Get a pin number of the gpio, invalid will return -1

View File

@@ -90,7 +90,7 @@ typedef enum {
*
* This file defines the gpio interface for libmraa
*
* @snippet Blink-IO.cpp Interesting
* @snippet gpio.cpp Interesting
*/
class Gpio
{
@@ -347,7 +347,7 @@ class Gpio
/**
* Change Gpio output driver mode
*
* @param mode @param mode Set output driver mode
* @param mode Set output driver mode
* @return Result of operation
*/
Result

View File

@@ -38,7 +38,7 @@ namespace mraa
* selecting the correct address
* @htmlinclude i2c.txt
*
* @snippet I2c-compass.cpp Interesting
* @snippet i2c.cpp Interesting
*/
class I2c
{

View File

@@ -67,7 +67,7 @@ public:
*
* This file defines the C++ iio interface for libmraa
*
* @snippet Iio-dummy.cpp Interesting
* @snippet iio.cpp Interesting
*/
class Iio
{

View File

@@ -36,6 +36,7 @@ namespace mraa
*
* This file defines the LED interface for libmraa
*
* @snippet led.cpp Interesting
*/
class Led
{

View File

@@ -36,7 +36,7 @@ namespace mraa
*
* This file defines the PWM interface for libmraa
*
* @snippet Pwm3-cycle.cpp Interesting
* @snippet pwm.cpp Interesting
*/
class Pwm
{

View File

@@ -51,7 +51,7 @@ typedef enum {
*
* This file defines the SPI interface for libmraa
*
* @snippet Spi-pot.cpp Interesting
* @snippet spi.cpp Interesting
*/
class Spi
{

View File

@@ -40,7 +40,7 @@ namespace mraa
*
* This file defines the UART interface for libmraa
*
* @snippet Uart-example.cpp Interesting
* @snippet uart.cpp Interesting
*/
class Uart
{

View File

@@ -37,7 +37,7 @@ namespace mraa
*
* This file defines the UartOW (UART to Dallas 1-wire) interface for libmraa
*
* @snippet UartOW.cpp Interesting
* @snippet uart_ow.cpp Interesting
*/
class UartOW
{

View File

@@ -1,222 +0,0 @@
# - The builtin (binary) CPack Deb generator (Unix only)
# CPackDeb may be used to create Deb package using CPack.
# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
# used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
#
# However CPackRPM has specific features which are controlled by
# the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
# the wiki:
# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
# However as a handy reminder here comes the list of specific variables:
#
# CPACK_DEBIAN_PACKAGE_NAME
# Mandatory : YES
# Default : CPACK_PACKAGE_NAME (lower case)
# The debian package summary
# CPACK_DEBIAN_PACKAGE_VERSION
# Mandatory : YES
# Default : CPACK_PACKAGE_VERSION
# The debian package version
# CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# Mandatory : YES
# Default : Output of dpkg --print-architecture or i386
# The debian package architecture
# CPACK_DEBIAN_PACKAGE_DEPENDS
# Mandatory : NO
# Default : -
# May be used to set deb dependencies.
# CPACK_DEBIAN_PACKAGE_MAINTAINER
# Mandatory : YES
# Default : CPACK_PACKAGE_CONTACT
# The debian package maintainer
# CPACK_DEBIAN_PACKAGE_DESCRIPTION
# Mandatory : YES
# Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
# The debian package description
# CPACK_DEBIAN_PACKAGE_SECTION
# Mandatory : YES
# Default : 'devel'
# The debian package section
# CPACK_DEBIAN_PACKAGE_PRIORITY
# Mandatory : YES
# Default : 'optional'
# The debian package priority
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
# Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# CPack script for creating Debian package
# Author: Mathieu Malaterre
#
# http://wiki.debian.org/HowToPackageForDebian
IF(CMAKE_BINARY_DIR)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
ENDIF(CMAKE_BINARY_DIR)
IF(NOT UNIX)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
ENDIF(NOT UNIX)
# Let's define the control file found in debian package:
# Binary package:
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
# DEBIAN/control
# debian policy enforce lower case for package name
# Package: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)
# Version: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
IF(NOT CPACK_PACKAGE_VERSION)
MESSAGE(FATAL_ERROR "Debian package requires a package version")
ENDIF(NOT CPACK_PACKAGE_VERSION)
SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
# Architecture: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# There is no such thing as i686 architecture on debian, you should use i386 instead
# $ dpkg --print-architecture
FIND_PROGRAM(DPKG_CMD dpkg)
IF(NOT DPKG_CMD)
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
ENDIF(NOT DPKG_CMD)
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# have a look at GET_PROPERTY(result GLOBAL PROPERTY ENABLED_FEATURES),
# this returns the successful FIND_PACKAGE() calls, maybe this can help
# Depends:
# You should set: DEBIAN_PACKAGE_DEPENDS
# TODO: automate 'objdump -p | grep NEEDED'
IF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
MESSAGE(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
# Maintainer: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
IF(NOT CPACK_PACKAGE_CONTACT)
MESSAGE(FATAL_ERROR "Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
ENDIF(NOT CPACK_PACKAGE_CONTACT)
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
# Description: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
MESSAGE(FATAL_ERROR "Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
# Section: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
# Priority: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
# Recommends:
# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
# Suggests:
# You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
# Typical examples are:
# - conffiles
# - postinst
# - postrm
# - prerm"
# Usage:
# SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
# For debian source packages:
# debian/control
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
# .dsc
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
# Builds-Depends:
#IF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
# "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
# )
#ENDIF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# Description: (mandatory)
#if(NOT CPACK_SECTION)
# message(FATAL_ERROR "opkg package requires a package section")
#endif(NOT CPACK_SECTION)
# Package for opkg
FIND_PROGRAM(OPKG_CMD opkg-build)
if( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
message("CPack: opkg-build not found. Skipping packaging")
else( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
SET(CPACK_OPKG_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
FILE(MAKE_DIRECTORY ${CPACK_OPKG_ROOTDIR}/CONTROL)
set(CPACK_OPKG_CONTROL_FILE "${CPACK_OPKG_ROOTDIR}/CONTROL/control")
# Write controlfile
FILE(WRITE ${CPACK_OPKG_CONTROL_FILE}
"Package: ${CPACK_PACKAGE_NAME}
Version: ${CPACK_PACKAGE_VERSION}
Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
Architecture: ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}
Section: ${CPACK_DEBIAN_PACKAGE_SECTION}
Priority: optional
Maintainer: ${CPACK_DEBIAN_PACKAGE_MAINTAINER}
Depends:
Provides: ${CPACK_DEBIAN_PACKAGE_PROVIDES}
Replaces: ${CPACK_DEBIAN_PACKAGE_REPLACES}
Conflicts: ${CPACK_DEBIAN_PACKAGE_CONFLICTS}
Source: https://github.com/intel-iot-devkit/mraa
#Essential: no
")
set(OPKG_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
execute_process(
COMMAND "${OPKG_CMD}" "-o" "0" "${CPACK_PACKAGE_FILE_NAME}" "."
RESULT_VARIABLE _result
OUTPUT_VARIABLE _res_output
ERROR_VARIABLE _res_error
WORKING_DIRECTORY ${CPACK_TOPLEVEL_DIRECTORY}
)
if(${_result})
message("Result '${_result}'")
message("Output '${_res_output}'")
message("Error '${_res_error}'")
else(${_result})
message("CPack: Package ${OPKG_FILE_NAME}.ipk generated.")
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
file(RENAME ${CPACK_TOPLEVEL_DIRECTORY}/${OPKG_FILE_NAME}.ipk ${CPACK_BINARY_DIR}/${OPKG_FILE_NAME}.ipk)
endif(${_result})
endif( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )

View File

@@ -1,69 +1,68 @@
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
macro(add_include_dir dir)
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
macro(add_include_dir dir)
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
endif()
endmacro()
find_program (NODEJS_EXECUTABLE NAMES node nodejs
HINTS
$ENV{NODE_DIR}
PATH_SUFFIXES bin
DOC "Node.js interpreter"
)
DOC "Node.js interpreter")
include (FindPackageHandleStandardArgs)
# If compat-libuv package exists, it must be at start of include path
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
if (UV_ROOT_DIR)
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
add_include_dir(${UV_ROOT_DIR})
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
add_include_dir(${UV_ROOT_DIR})
endif()
# Now look for node. Flag an error if not found
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
find_path (NODE_ROOT_DIR
NAMES node.h src/node.h
PATH_SUFFIXES node node4 node5 node6 node7 node8 nodejs
PATHS /usr/include /usr/local/include)
message(STATUS "INFO - NODE_ROOT_DIR is ${NODE_ROOT_DIR}")
if (NODE_ROOT_DIR)
add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/src)
add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR})
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/src)
else()
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found")
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found")
endif()
# Check that v8.h is in NODEJS_INCLUDE_DIRS
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT V8_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - v8.h not found")
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - v8.h not found")
endif()
# Check that uv.h is in NODEJS_INCLUDE_DIRS
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT UV_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - uv.h not found")
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - uv.h not found")
endif()
find_package_handle_standard_args (Nodejs DEFAULT_MSG
NODEJS_EXECUTABLE
NODEJS_INCLUDE_DIRS
)
if (NODEJS_EXECUTABLE)
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _NODE_VERSION_RESULT)
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _NODE_VERSION_RESULT)
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
OUTPUT_VARIABLE _V8_VERSION
RESULT_VARIABLE _V8_RESULT)
OUTPUT_VARIABLE _V8_VERSION
RESULT_VARIABLE _V8_RESULT)
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
@@ -86,12 +85,15 @@ if (NODEJS_EXECUTABLE)
set (V8_VERSION_MINOR"14")
set (V8_VERSION_PATCH "5")
set (V8_VERSION_STRING "3.28.72")
message ("defaulted to node 0.10.30")
message (STATUS "defaulted to node 0.10.30")
endif ()
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
message ("INFO - Node version is " ${NODE_VERSION_STRING})
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
mark_as_advanced (NODEJS_EXECUTABLE)
endif ()
mark_as_advanced (NODEJS_EXECUTABLE)
find_package_handle_standard_args (Nodejs
REQUIRED_VARS NODEJS_EXECUTABLE NODEJS_INCLUDE_DIRS
VERSION_VAR NODE_VERSION_STRING)
message(STATUS "Found v8: ${V8_ROOT_DIR}/v8.h (found version \"${V8_VERSION_STRING}\")")
endif ()

View File

@@ -21,8 +21,6 @@ services:
- JSONPLAT=${JSONPLAT:-OFF}
- IMRAA=${IMRAA:-OFF}
- FTDI4222=${FTDI4222:-OFF}
- IPK=${IPK:-OFF}
- RPM=${RPM:-OFF}
- ENABLEEXAMPLES=${ENABLEEXAMPLES:-OFF}
- INSTALLTOOLS=${INSTALLTOOLS:-ON}
- CC=${CC:-clang-3.8}
@@ -105,20 +103,6 @@ services:
- FTDI4222=ON
command: bash -c "./scripts/run-cmake.sh && make -Cbuild"
ipk:
extends: all
environment:
- IPK=ON
- ENABLEEXAMPLES=ON
command: bash -c "./scripts/run-cmake.sh && make -Cbuild package"
rpm:
extends: all
environment:
- RPM=ON
- ENABLEEXAMPLES=ON
command: bash -c "./scripts/run-cmake.sh && make -Cbuild package"
python2:
extends: base
image: inteliotdevkit/mraa-python

View File

@@ -111,6 +111,10 @@ CC flags to the CC env var
Sometimes it's nice to build a static library, on Linux systems just set
`-DBUILD_SHARED_LIBS=OFF`
Note that for static builds the python bindings will not build as they would
require a static python etc... You can try to link mraa statically to the
python binding module by adding -fPIC with `-DCMAKE_C_FLAGS=-fPIC`. You can
also use the node.js gyp build system to get node.js static bindings.
## Dependencies continued
@@ -139,18 +143,6 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/oe-sdk_cross.cmake ..
make
~~~~~~~~~~~~~
## Using Coverity
This is the procedure to submit a build to Coverity. You'll need to install
`coverity-submit` for your OS.
~~~~~~~~~~~~~{.sh}
mkdir covbuild/ && cd covbuild
cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
cov-build --dir cov-int make
tar caf mraa.tar.bz2 cov-int
~~~~~~~~~~~~~
## Building Java bindings
Have JAVA_HOME set to JDK install directory. Most distributions set this from `/etc/profile.d/`
@@ -172,23 +164,6 @@ java -cp $DIR_WHERE_YOU_INSTALLED_MRAA/mraa.jar:. Example
If you want to add or improve Java bindings for mraa, please follow the <a href="https://github.com/intel-iot-devkit/upm/blob/master/docs/creating_java_bindings.md">Creating Java Bindings Guide</a>.
## Building an IPK/RPM package using `cpack`
You can get `cpack` to generate an IPK or RPM package fairly easily if you have
the correct packaging tools
~~~~~~~~~~~~~{.sh}
cmake -DIPK=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make package
~~~~~~~~~~~~~
To use RPM simply enable the RPM option. You'll need `rpmbuild` installed on your
build machine.
~~~~~~~~~~~~~{.sh}
cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
~~~~~~~~~~~~~
## Building for the Android Things Peripheralmanager Client
Requirements:

View File

@@ -5,6 +5,15 @@ 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.9.0**
* Added support for RPi Zero W
* Added support for MIPS based Omega2 and Linkit Smart 7688
* New APIs for sysfs onboard LED control using the gpio-leds driver
* Restructured and cleaned-up examples
* Improved documentation generation and CI integration
* Static analysis fixes, added SonarQube badge
* Enhanced Node.js detection on some Linux distros (OpenSUSE)
**1.8.0**
* Added Up2 support & grovePi subplatform support
* Various improvements on 96board, rpi, beaglebone & Up boards

View File

@@ -71,6 +71,10 @@ glance at our @ref debugging page too
More information on compiling is @ref building page.
## STATIC CODE ANALYSIS
See @ref static_code_analysis page.
## CONTRIBUTING
Please see the @ref contributing page, the @ref internals page may also be of

View File

@@ -0,0 +1,93 @@
Static code analysis {#static_code_analysis}
====================
We use [SonarQube](https://www.sonarqube.org/) for static code analysis scans.
These are automated via Travis, same as our usual builds.
Automated scans
---------------
We don't use the Travis' plugin for Sonar due to the fact we use Docker
and not the bare Travis, and these two are not compatible.
We have a dedicated `docker-compose` target for scans, `sonar-scan`. Necessary
values are passed to Sonar scanner as command-line parameters.
For the whole config to work, the following one-time configuration steps are necessary:
* Create organization and project in SonarQube - done already,
https://sonarcloud.io/organizations/mraa-github (key: mraa-github)
and https://sonarcloud.io/dashboard?id=mraa-master (key: mraa-master);
* Create technical account on GitHub with push permissions for mraa repo.
It is used for reporting pull request statuses in the "checks" area.
We have `intel-iot-devkit-helperbot` for this, shared with UPM.
* Add several environment variables in Travis:
* `GITHUB_TOKEN` (secure) - GH OAuth token for the technical user,
with `public_repo` privileges only;
* `SONAR_TOKEN` (secure) - this one comes from the SonarQube org properties;
* `SONAR_ORG`, `SONAR_PROJ_KEY` (may be public) - project and org keys (names)
from SonarQube org, see above;
These scans are executed each time there's an internal pull request (from a branch
local to main mraa repo) or a `master` branch push.
Upon the former the so called "preview" scan is executed, which doesn't
upload anything to SonarQube organization and only reports the result within the PR.
Upon `master` branch push a normal scan is executed and results are uploaded to
SonarQube.
When there's a so called "external" pull request (originating somewhere else
than mraa's main repo, e.g. from a fork), no scan is done for
security reasons, as code within such PR would have access to tokens listed above.
In view of such setup, it's beneficial to create internal pull requests as much
as possible, because you'll catch problems right away - in the preview scan,
before PR is merged.
Manual scans
------------
It's a good practice to run the scan manually before actually submitting a PR.
There may also be a need to run the scan manually out-of-cycle, so here's how.
Just use the command line from [the scanner script](../master/scripts/sonar-scan.sh).
See `sonar_cmd_base` variable specifically and just replace various tokens
listed there with proper ones. Please also don't forget that you need to run the
build wrapper first, so that the scanner knows what to scan.
The set of commands for the main mraa repo and SonarQube project would look like
the below. Note that it will upload results to the SonarQube by default,
if you don't want that, setup a throwaway "project" in SonarQube, or create a
separate "organization" dedicated to your mraa repo fork:
```bash
$> export PATH=~/bin/sonar/sonar-scanner-3.0.3.778-linux/bin/:~/bin/sonar/build-wrapper-linux-x86/:$PATH
$> build-wrapper-linux-x86-64 --out-dir bw-output make clean all
$> sonar-scanner \
-Dsonar.projectKey=mraa-master \
-Dsonar.projectBaseDir=/PATH/TO/YOUR/MRAA/REPO/CLONE \
-Dsonar.sources=/PATH/TO/YOUR/MRAA/REPO/CLONE \
-Dsonar.inclusions='api/**/*,CMakeLists.txt,examples/**/*,imraa/**/*,include/**/*,src/*,src/**/*,tests/**/*' \
-Dsonar.cfamily.build-wrapper-output=/PATH/TO/YOUR/MRAA/REPO/CLONE/YOUR_BUILD_DIR/bw-output \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=mraa-github \
-Dsonar.login=YOUR_SONAR_LOGIN_TOKEN_HERE
```
Notice that we first set the `PATH` to point to our downloaded copy of Sonar tools.
You can find more information on setting these up in SonarQube's nice
[Getting Started tutorial](https://about.sonarcloud.io/get-started/).
Using Coverity
--------------
In the past we've used Coverity to do static code analysis scans. Below is the
documentation on that setup - for archiving purposes.
This is the procedure to submit a build to Coverity. You'll need to install
`coverity-submit` for your OS.
```bash
mkdir covbuild/ && cd covbuild
cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
cov-build --dir cov-int make
tar caf mraa.tar.bz2 cov-int
```

View File

@@ -1,60 +0,0 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributors: Alex Tereschenko <alex.mkrs@gmail.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <signal.h>
#include "mraa.hpp"
int running = 0;
void
sig_handler(int signo)
{
if (signo == SIGINT) {
printf("closing down nicely\n");
running = -1;
}
}
//! [Interesting]
int
main()
{
uint16_t adc_value;
float adc_value_float;
mraa::Aio a0(0);
signal(SIGINT, sig_handler);
while (running == 0) {
adc_value = a0.read();
adc_value_float = a0.readFloat();
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
fprintf(stdout, "ADC A0 read float - %.5f (Ctrl+C to exit)\n", adc_value_float);
}
return MRAA_SUCCESS;
}
//! [Interesting]

View File

@@ -1,27 +1,29 @@
enable_language(CXX)
add_executable (AioA0 AioA0.cpp)
add_executable (blink-io-cpp Blink-IO.cpp)
add_executable (Pwm3-cycle Pwm3-cycle.cpp)
add_executable (I2c-compass I2c-compass.cpp)
add_executable (Spi-pot Spi-pot.cpp)
add_executable (Uart Uart-example.cpp)
add_executable (Isr-pin6 Isr-pin6.cpp)
add_executable (Iio-dummy Iio-dummy.cpp)
add_executable (aio_cpp aio.cpp)
add_executable (gpio_advanced_cpp gpio_advanced.cpp)
add_executable (gpio_cpp gpio.cpp)
add_executable (pwm_cpp pwm.cpp)
add_executable (i2c_cpp i2c.cpp)
add_executable (spi_cpp spi.cpp)
add_executable (uart_cpp uart.cpp)
add_executable (iio_cpp iio.cpp)
add_executable (led_cpp led.cpp)
include_directories(${PROJECT_SOURCE_DIR}/api)
include_directories(${PROJECT_SOURCE_DIR}/api/mraa)
target_link_libraries (AioA0 mraa stdc++)
target_link_libraries (blink-io-cpp mraa stdc++)
target_link_libraries (Pwm3-cycle mraa stdc++)
target_link_libraries (I2c-compass mraa stdc++ m)
target_link_libraries (Spi-pot mraa stdc++)
target_link_libraries (Uart mraa stdc++)
target_link_libraries (Isr-pin6 mraa stdc++)
target_link_libraries (Iio-dummy mraa stdc++)
target_link_libraries (aio_cpp mraa stdc++)
target_link_libraries (gpio_advanced_cpp mraa stdc++)
target_link_libraries (gpio_cpp mraa stdc++)
target_link_libraries (pwm_cpp mraa stdc++)
target_link_libraries (i2c_cpp mraa stdc++ m)
target_link_libraries (spi_cpp mraa stdc++)
target_link_libraries (uart_cpp mraa stdc++)
target_link_libraries (iio_cpp mraa stdc++)
target_link_libraries (led_cpp mraa stdc++)
if (ONEWIRE)
add_executable (UartOW UartOW.cpp)
target_link_libraries (UartOW mraa stdc++)
add_executable (uart_ow_cpp uart_ow.cpp)
target_link_libraries (uart_ow_cpp mraa stdc++)
endif ()

View File

@@ -1,6 +1,7 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Contributors: Alex Tereschenko <alex.mkrs@gmail.com>
* Contributors: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -21,53 +22,52 @@
* 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.
*
* Example usage: Reads ADC A0 value continuously. Press Ctrl+C to exit.
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "mraa.hpp"
#define DEFAULT_IOPIN 8
/* mraa headers */
#include "mraa/aio.hpp"
#include "mraa/common.hpp"
static int iopin;
int running = 0;
/* AIO port */
#define AIO_PORT 0
volatile sig_atomic_t flag = 1;
void
sig_handler(int signo)
sig_handler(int signum)
{
if (signo == SIGINT) {
printf("closing IO%d nicely\n", iopin);
running = -1;
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main(int argc, char** argv)
main(void)
{
if (argc < 2) {
printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
iopin = DEFAULT_IOPIN;
} else {
iopin = strtol(argv[1], NULL, 10);
}
uint16_t value;
float float_value;
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Gpio gpio(iopin);
mraa::Result response = gpio.dir(mraa::DIR_OUT);
if (response != mraa::SUCCESS) {
mraa::printError(response);
return 1;
}
/* initialize AIO */
mraa::Aio aio(AIO_PORT);
while (running == 0) {
response = gpio.write(1);
sleep(1);
response = gpio.write(0);
sleep(1);
while (flag) {
value = aio.read();
float_value = aio.readFloat();
std::cout << "ADC A0 read %X - %d" << value << value << std::endl;
std::cout << "ADC A0 read float - %.5f" << float_value << std::endl;
}
return response;
//! [Interesting]
return EXIT_SUCCESS;
}

114
examples/c++/gpio.cpp Normal file
View File

@@ -0,0 +1,114 @@
/*
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2018 Linaro Ltd.
*
* 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.
*
* Example usage: Toggles GPIO's 23 and 24 recursively. Press Ctrl+C to exit
*
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/gpio.hpp"
/* gpio declaration */
#define GPIO_PIN_1 23
#define GPIO_PIN_2 24
volatile sig_atomic_t flag = 1;
void
sig_handler(int signum)
{
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main(void)
{
mraa::Result status;
/* install signal handler */
signal(SIGINT, sig_handler);
//! [Interesting]
/* initialize GPIO pin */
mraa::Gpio gpio_1(GPIO_PIN_1);
/* initialize GPIO pin */
mraa::Gpio gpio_2(GPIO_PIN_2);
/* set GPIO to output */
status = gpio_1.dir(mraa::DIR_OUT);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
/* set gpio 24 to output */
status = gpio_2.dir(mraa::DIR_OUT);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
/* toggle both GPIO's */
while (flag) {
status = gpio_1.write(1);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
status = gpio_2.write(0);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
sleep(1);
status = gpio_1.write(0);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
status = gpio_2.write(1);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
sleep(1);
}
//! [Interesting]
return EXIT_SUCCESS;
}

View File

@@ -1,7 +1,6 @@
/*
* Author: Brendan Le Foll
* Contributors: Alex Tereschenko <alext.mkrs@gmail.com>
* Copyright (c) 2015 Intel Corporation.
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2018 Linaro Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -21,39 +20,54 @@
* 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.
*
* Example usage: Configures GPIO pin for interrupt and waits 30 seconds for the isr to trigger
*
*/
/* standard headers */
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include "mraa.hpp"
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/gpio.hpp"
static volatile int counter = 0;
static volatile int oldcounter = 0;
#define GPIO_PIN 6
void
interrupt(void* args)
int_handler(void* args)
{
++counter;
std::cout << "ISR triggered" << std::endl;
}
int
main()
main(void)
{
mraa::Gpio x(6);
mraa::Result status;
x.dir(mraa::DIR_IN);
//! [Interesting]
/* initialize GPIO */
mraa::Gpio gpio(GPIO_PIN);
x.isr(mraa::EDGE_BOTH, &interrupt, NULL);
int i = 100;
for (; i > 0; --i) {
if (counter != oldcounter) {
fprintf(stdout, "timeout counter == %d\n", counter);
oldcounter = counter;
}
// got to relieve our poor CPU!
sleep(1);
/* set GPIO to input */
status = gpio.dir(mraa::DIR_IN);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
return MRAA_SUCCESS;
/* configure ISR for GPIO */
status = gpio.isr(mraa::EDGE_BOTH, &int_handler, NULL);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
/* wait 30 seconds isr trigger */
sleep(30);
//! [Interesting]
return EXIT_SUCCESS;
}

View File

@@ -21,13 +21,22 @@
* 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.
*
* Example usage: Outputs X,Y,Z co-ordinates and direction recursively using
* HMC5883L. Press Ctrl+C to exit.
*
*/
/* standard headers */
#include <iostream>
#include <math.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "math.h"
#include "mraa.hpp"
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/i2c.hpp"
#define MAX_BUFFER_LENGTH 6
#define HMC5883L_I2C_ADDR 0x1E
@@ -79,42 +88,41 @@
#define SCALE_3_03_MG 3.03
#define SCALE_4_35_MG 4.35
#define I2C_BUS 0
int running = 0;
volatile sig_atomic_t flag = 1;
void
sig_handler(int signo)
sig_handler(int signum)
{
if (signo == SIGINT) {
printf("closing nicely\n");
running = -1;
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main()
main(void)
{
float direction = 0;
int16_t x = 0, y = 0, z = 0;
float direction;
int16_t x, y, z;
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::I2c i2c(0);
mraa::I2c i2c(I2C_BUS);
i2c.address(HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_CONF_REG_B;
rx_tx_buf[1] = GA_1_3_REG;
i2c.write(rx_tx_buf, 2);
//! [Interesting]
i2c.address(HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_MODE_REG;
rx_tx_buf[1] = HMC5883L_CONT_MODE;
i2c.write(rx_tx_buf, 2);
signal(SIGINT, sig_handler);
while (running == 0) {
while (flag) {
i2c.address(HMC5883L_I2C_ADDR);
i2c.writeByte(HMC5883L_DATA_REG);
@@ -132,11 +140,13 @@ main()
if (direction < 0)
direction += 2 * M_PI;
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
z * SCALE_0_92_MG);
printf("Heading : %f\n", direction * 180 / M_PI);
std::cout << "Compass scaled data x : %f, y : %f, z : %f" << x * SCALE_0_92_MG
<< y * SCALE_0_92_MG << z * SCALE_0_92_MG << std::endl;
std::cout << "Heading : %f" << direction * 180 / M_PI << std::endl;
sleep(1);
}
//! [Interesting]
return MRAA_SUCCESS;
return EXIT_SUCCESS;
}

View File

@@ -20,14 +20,23 @@
* 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.
*
* Example usage: Sets accelerometer scale and registers for the threshold event
*
*/
#include "mraa/iio.hpp"
/* standard headers */
#include <float.h>
#include <iostream>
#include <math.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/iio.hpp"
#define EXPECT_FAILURE 0
#define EXPECT_SUCCESS 1
@@ -82,9 +91,9 @@ log_result(std::string test_name, std::string attr_name, bool expect_success, bo
else
result = success ? "FAIL" : "PASS";
if (attr_name.empty())
fprintf(stdout, "%s: %s\n", test_name.c_str(), result.c_str());
std::cout << "%s: %s" << test_name.c_str() << result.c_str() << std::endl;
else
fprintf(stdout, "%s(%s): %s\n", test_name.c_str(), attr_name.c_str(), result.c_str());
std::cout << "%s(%s): %s" << test_name.c_str() << attr_name.c_str() << result.c_str() << std::endl;
}
// Generate iio_dummy driver event by writing a string to a specific sysfs node
@@ -113,10 +122,10 @@ class IioTestHandler : public mraa::IioHandler
}
};
//! [Interesting]
int
main()
main(void)
{
//! [Interesting]
IioTestHandler testHandler;
std::string deviceName;
try {
@@ -144,7 +153,6 @@ main()
return EXIT_FAILURE;
}
std::cout << "Using IIO device0. Name is " << iio_device->getDeviceName() << std::endl;
IIO_RUN(writeFloat, "in_accel_x_raw", 100, EXPECT_FAILURE);
IIO_RUN(writeFloat, "in_voltage0_scale", 100, EXPECT_FAILURE);
@@ -157,8 +165,9 @@ main()
generate_event();
usleep(500000);
log_result("eventReceived", "", (eventCount == 1), true);
//! [Interesting]
delete iio_device;
return EXIT_SUCCESS;
}
//! [Interesting]

86
examples/c++/led.cpp Normal file
View File

@@ -0,0 +1,86 @@
/*
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2018, Linaro Ltd.
*
* 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.
*
* Example usage: Reads maximum brightness value for user led and turns it
* on/off depending on current state. Then sets led trigger
* to heartbeat.
*
*/
/* standard headers */
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/led.hpp"
/* LED name */
#define USER_LED "user1"
/* trigger type */
#define LED_TRIGGER "heartbeat"
int
main(void)
{
mraa::Result status;
int val;
//! [Interesting]
/* initialize user1 led */
mraa::Led led(USER_LED);
/* read maximum brightness */
val = led.readMaxBrightness();
std::cout << "maximum brightness value for user1 led is: %d" << val << std::endl;
if (val >= 1) {
val = 0;
} else {
/* never reached mostly */
val = 1;
}
/* turn led on/off depending on max_brightness value */
status = led.setBrightness(val);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
/* sleep for 5 seconds */
usleep(5000000);
/* set led trigger to heartbeat */
status = led.trigger(LED_TRIGGER);
if (status != mraa::SUCCESS) {
printError(status);
return EXIT_FAILURE;
}
std::cout << "led trigger set to: heartbeat" << std::endl;
//! [Interesting]
return EXIT_SUCCESS;
}

View File

@@ -20,35 +20,47 @@
* 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.
*
* Example usage: Generates PWM at a step rate of 0.01 continuously.
* Press Ctrl+C to exit
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "mraa.hpp"
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/pwm.hpp"
int running = 0;
#define PWM_PORT 3
volatile sig_atomic_t flag = 1;
void
sig_handler(int signo)
sig_handler(int signum)
{
if (signo == SIGINT) {
printf("closing PWM nicely\n");
running = -1;
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main()
main(void)
{
float value = 0.0f;
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Pwm pwm(3);
fprintf(stdout, "Cycling PWM on IO3 (pwm3) \n");
mraa::Pwm pwm(PWM_PORT);
std::cout << "Cycling PWM on IO3 (pwm3)" << std::endl;
pwm.enable(true);
float value = 0.0f;
while (running == 0) {
while (flag) {
value = value + 0.01f;
pwm.write(value);
usleep(50000);
@@ -58,5 +70,5 @@ main()
}
//! [Interesting]
return MRAA_SUCCESS;
return EXIT_SUCCESS;
}

View File

@@ -1,5 +1,6 @@
/*
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Contributors: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -20,58 +21,69 @@
* 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.
*
* Example usage: Sends data continuously to a Spi device. Press Ctrl+C to exit
*
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include "mraa.hpp"
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/spi.hpp"
int running = 0;
#define SPI_PORT 0
volatile sig_atomic_t flag = 1;
void
sig_handler(int signo)
sig_handler(int signum)
{
if (signo == SIGINT) {
printf("closing spi nicely\n");
running = -1;
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main()
main(void)
{
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Spi spi(0);
uint8_t data[] = { 0x00, 100 };
uint8_t rxBuf[2];
uint8_t* recv;
while (running == 0) {
int i;
int i;
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Spi spi(SPI_PORT);
while (flag) {
for (i = 90; i < 130; i++) {
data[1] = i;
recv = spi.write(data, 2);
printf("Writing -%i", i);
std::cout << "Writing -%i" << i << std::endl;
if (recv) {
printf("RECIVED-%i-%i\n", recv[0], recv[1]);
std::cout << "RECIVED-%i-%i" << recv[0] << recv[1] << std::endl;
free(recv);
}
usleep(100000);
}
for (i = 130; i > 90; i--) {
data[1] = i;
if (spi.transfer(data, rxBuf, 2) == mraa::SUCCESS) {
printf("Writing -%i", i);
printf("RECIVED-%i-%i\n", rxBuf[0], rxBuf[1]);
std::cout << "Writing -%i" << i << std::endl;
std::cout << "RECIVED-%i-%i" << rxBuf[0] << rxBuf[1] << std::endl;
}
usleep(100000);
}
}
//! [Interesting]
return mraa::SUCCESS;
return EXIT_SUCCESS;
}

View File

@@ -1,5 +1,6 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributors: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -20,51 +21,81 @@
* 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.
*
* Example usage: Prints "Hello Mraa!" recursively. Press Ctrl+C to exit
*
*/
#include <exception>
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "mraa.hpp"
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/uart.hpp"
/* UART port */
#define UART_PORT 0
const char* dev_path = "/dev/ttyS0";
volatile sig_atomic_t flag = 1;
void
sig_handler(int signum)
{
if (signum == SIGINT) {
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
int
main()
main(void)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// If you have a valid platform configuration use numbers to represent uart
// device. If not use raw mode where std::string is taken as a constructor
// parameter
mraa::Uart* dev;
mraa::Uart* uart;
try {
dev = new mraa::Uart(0);
uart = new mraa::Uart(UART_PORT);
} catch (std::exception& e) {
std::cout << e.what() << ", likely invalid platform config" << std::endl;
std::cerr << e.what() << ", likely invalid platform config" << std::endl;
}
try {
dev = new mraa::Uart("/dev/ttyACM0");
uart = new mraa::Uart(dev_path);
} catch (std::exception& e) {
std::cout << "Error while setting up raw UART, do you have a uart?" << std::endl;
std::cerr << "Error while setting up raw UART, do you have a uart?" << std::endl;
std::terminate();
}
if (dev->setBaudRate(115200) != mraa::SUCCESS) {
std::cout << "Error setting parity on UART" << std::endl;
if (uart->setBaudRate(115200) != mraa::SUCCESS) {
std::cerr << "Error setting parity on UART" << std::endl;
}
if (dev->setMode(8, mraa::UART_PARITY_NONE, 1) != mraa::SUCCESS) {
std::cout << "Error setting parity on UART" << std::endl;
if (uart->setMode(8, mraa::UART_PARITY_NONE, 1) != mraa::SUCCESS) {
std::cerr << "Error setting parity on UART" << std::endl;
}
if (dev->setFlowcontrol(false, false) != mraa::SUCCESS) {
std::cout << "Error setting flow control UART" << std::endl;
if (uart->setFlowcontrol(false, false) != mraa::SUCCESS) {
std::cerr << "Error setting flow control UART" << std::endl;
}
dev->writeStr("Hello monkeys");
while (flag) {
/* send data through uart */
uart->writeStr("Hello Mraa!");
sleep(1);
}
//! [Interesting]
delete dev;
delete uart;
return mraa::SUCCESS;
return EXIT_SUCCESS;
}

View File

@@ -20,51 +20,59 @@
* 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.
*
* Example usage: Search and print the found OW device ID recursively.
*
*/
#include "iostream"
#include "stdio.h"
//! [Interesting]
#include "uart_ow.hpp"
/* standard headers */
#include <iostream>
#include <stdlib.h>
/* mraa headers */
#include "mraa/common.hpp"
#include "mraa/uart_ow.hpp"
int
main(int argc, char** argv)
main(void)
{
mraa::Result status;
std::string id;
uint8_t count = 0;
uint8_t* ptr;
//! [Interesting]
mraa::UartOW uart(0);
// Reset the ow bus and see if anything is present
mraa::Result rv;
if ((rv = uart.reset()) == mraa::SUCCESS) {
if ((status = uart.reset()) == mraa::SUCCESS) {
std::cout << "Reset succeeded, device(s) detected!" << std::endl;
} else {
std::cout << "Reset failed, returned " << int(rv) << ". No devices on bus?" << std::endl;
return 1;
std::cout << "Reset failed, returned " << int(status) << ". No devices on bus?" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Looking for devices..." << std::endl;
;
uint8_t count = 0;
// start the search from scratch
std::string id = uart.search(true);
id = uart.search(true);
if (id.empty()) {
std::cout << "No devices detected." << std::endl;
return 1;
return EXIT_FAILURE;
}
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.data();
ptr = (uint8_t*) id.data();
// 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]);
std::cout << "Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x" << count << ptr[0]
<< ptr[6] << ptr[5] << ptr[4] << ptr[3] << ptr[2] << ptr[1] << ptr[7] << std::endl;
count++;
// continue the search with start argument set to false
@@ -72,7 +80,7 @@ main(int argc, char** argv)
}
std::cout << "Exiting..." << std::endl;
//! [Interesting]
return 0;
return EXIT_SUCCESS;
}
//! [Interesting]

View File

@@ -123,7 +123,7 @@ main(void)
}
/* set slave address */
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
status = mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
if (status != MRAA_SUCCESS) {
goto err_exit;
}

View File

@@ -27,6 +27,7 @@
*/
/* standard headers */
#include <endian.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -28,6 +28,7 @@
/* standard headers */
#include <stdlib.h>
#include <unistd.h>
#include <endian.h>
/* mraa header */
#include "mraa/iio.h"

103
examples/gpio_multiple_rw.c Normal file
View File

@@ -0,0 +1,103 @@
/* This currently works only on Intel Joule Platform. */
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "mraa/gpio.h"
int running = 0;
void
sig_handler(int signo)
{
if (signo == SIGINT) {
printf("Closing down nicely\n");
running = -1;
}
}
int main(int argc, char** argv)
{
mraa_result_t r = MRAA_SUCCESS;
/* These are Joule's onboard LED's. */
int default_joule_leds[] = {100, 101, 102, 103};
int *gpio_pins;
int num_pins;
int *input_values, *output_values;
printf("Provide int arg(s) if you want to toggle gpio pins other than Joule's onboard LED's\n");
if (argc < 2) {
gpio_pins = default_joule_leds;
num_pins = 4;
} else {
num_pins = argc - 1;
gpio_pins = malloc(num_pins * sizeof(int));
for (int i = 0; i < num_pins; ++i) {
gpio_pins[i] = strtol(argv[i+1], NULL, 10);
}
}
/* Allocate input and output values arrays. */
input_values = malloc(num_pins * sizeof(int));
output_values = malloc(num_pins * sizeof(int));
mraa_init();
fprintf(stdout, "MRAA Version: %s\nStarting program...\n", mraa_get_version());
mraa_gpio_context gpio = mraa_gpio_init_multi(gpio_pins, num_pins);
if (gpio == NULL) {
fprintf(stderr, "Error during gpio initialization\n");
exit(1);
}
r = mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
signal(SIGINT, sig_handler);
/* Set input values first. */
memset(input_values, 0, num_pins * sizeof(int));
while (running == 0) {
r = mraa_gpio_write_multi(gpio, input_values);
sleep(1);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
} else {
r = mraa_gpio_read_multi(gpio, output_values);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
}
for (int i = 0; i < num_pins; ++i) {
input_values[i] = (input_values[i] + 1) % 2;
}
}
memset(input_values, 0, num_pins * sizeof(int));
mraa_gpio_write_multi(gpio, input_values);
r = mraa_gpio_close(gpio);
if (r != MRAA_SUCCESS) {
mraa_result_print(r);
}
/* Cleanup. */
if (argc >= 2) {
free(gpio_pins);
}
free(input_values);
free(output_values);
return r;
}

View File

@@ -21,14 +21,21 @@
# 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.
#
# Example Usage: Reads integer and float value from ADC
import mraa
print (mraa.getVersion())
print(mraa.getVersion())
try:
# initialise AIO
x = mraa.Aio(0)
print (x.read())
print ("%.5f" % x.readFloat())
# read integer value
print(x.read())
# read float value
print("%.5f" % x.readFloat())
except:
print ("Are you sure you have an ADC?")
print("Are you sure you have an ADC?")

52
examples/python/gpio.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python
# Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
# Copyright (c) 2018 Linaro Ltd.
#
# 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.
#
# Example Usage: Toggles GPIO 23 and 24 continuously in an alternative pattern
import mraa
import time
# initialise gpio 23
gpio_1 = mraa.Gpio(23)
# initialise gpio 24
gpio_2 = mraa.Gpio(24)
# set gpio 23 to output
gpio_1.dir(mraa.DIR_OUT)
# set gpio 24 to output
gpio_2.dir(mraa.DIR_OUT)
# toggle both gpio's
while True:
gpio_1.write(1)
gpio_2.write(0)
time.sleep(1)
gpio_1.write(0)
gpio_2.write(1)
time.sleep(1)

View File

@@ -21,34 +21,39 @@
# 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
#
# Example Usage: Triggers ISR upon GPIO state change
import mraa
import time
import sys
class Counter:
count = 0
count = 0
c = Counter()
# 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()))
c.count+=1
def isr_routine(gpio):
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))
c.count += 1
# GPIO
pin = 6;
if (len(sys.argv) == 2):
try:
pin = int(sys.argv[1], 10)
except ValueError:
printf("Invalid pin " + sys.argv[1])
try:
x = mraa.Gpio(pin)
print("Starting ISR for pin " + repr(pin))
x.dir(mraa.DIR_IN)
x.isr(mraa.EDGE_BOTH, test, x)
var = raw_input("Press ENTER to stop")
x.isrExit()
# initialise GPIO
x = mraa.Gpio(pin)
print("Starting ISR for pin " + repr(pin))
# set direction and edge types for interrupt
x.dir(mraa.DIR_IN)
x.isr(mraa.EDGE_BOTH, isr_routine, x)
# wait until ENTER is pressed
var = raw_input("Press ENTER to stop")
x.isrExit()
except ValueError as e:
print(e)

View File

@@ -1,30 +0,0 @@
#!/usr/bin/env python
# Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
# Copyright (c) 2014 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import mraa
print (mraa.getVersion())
x = mraa.Gpio(13)
x.dir(mraa.DIR_OUT)
x.write(1)

View File

@@ -21,18 +21,19 @@
# 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
#
# Example Usage: Shows the 'advanced' i2c functionality from python i2c
# read/write
import mraa as m
# this example will show the 'advanced' i2c functionality from python i2c
# read/write
# initialise I2C
x = m.I2c(0)
x.address(0x77)
# initialise device
if x.readReg(0xd0) != 0x55:
print("error")
print("error")
# we want to read temperature so write 0x2e into control reg
x.writeReg(0xf4, 0x2e)

View File

@@ -21,11 +21,12 @@
# 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
#
# Example Usage: Changes the Grove-LCD RGB backlight to a nice shade of purple
import mraa
# This example will change the LCD backlight on the Grove-LCD RGB backlight
# to a nice shade of purple
# initialise I2C
x = mraa.I2c(0)
x.address(0x62)
@@ -33,7 +34,7 @@ x.address(0x62)
x.writeReg(0, 0)
x.writeReg(1, 0)
# sent RGB color data
# write RGB color data
x.writeReg(0x08, 0xAA)
x.writeReg(0x04, 255)
x.writeReg(0x02, 255)

55
examples/python/led.py Normal file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env python
# Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
# Copyright (c) 2018 Linaro Ltd.
#
# 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.
#
# Example Usage: Reads maximum brightness value for user1 led and turns it
# on/off depending on current state. Then sets led trigger
# to heartbeat
import mraa
import time
# initialise user1 led
led_1 = mraa.Led("user1")
# read maximum brightness
val = led_1.readMaxBrightness()
print("maximum brightness value for user1 led is: %d" % val);
# turn led on/off depending on read max_brightness value
if (val >= 1):
val = 0
# never reached mostly
else:
val = 1
# set LED brightness
led_1.setBrightness(val)
# sleep for 5 seconds
time.sleep(5)
led_1.trigger("heartbeat")
print("led trigger set to: heartbeat")

View File

@@ -21,18 +21,29 @@
# 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.
#
# Example Usage: Generates PWM at a step rate of 0.01 continuously.
import mraa
import time
# initialise PWM
x = mraa.Pwm(3)
# set PWM period
x.period_us(700)
# enable PWM
x.enable(True)
value= 0.0
while True:
# write PWM value
x.write(value)
time.sleep(0.05)
value = value + 0.01
if value >= 1:
value = 0.0

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
# Copyright (c) 2015 Intel Corporation.
# Author: Henry Bruce <henry.bruce@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -22,22 +22,24 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
import mraa as m
import random as rand
# Example Usage: Read from MCP3004 ADC pin 0 in single ended mode
# Excuse the super boring example, I was out of fun devices to play with, this
# will write and read the same data back to itself, a few 100 times, just short
# MISO & MOSI on your board
import mraa
import time
dev = m.Spi(0)
# initialise SPI
dev = mraa.Spi(0)
for x in range(0,100):
txbuf = bytearray(4)
for y in range(0,4):
txbuf[y] = rand.randrange(0, 256)
rxbuf = dev.write(txbuf)
if rxbuf != txbuf:
print("We have an error captain!")
break
exit(1)
# prepare data to send
txbuf = bytearray(3)
txbuf[0] = 0x01
txbuf[1] = 0x80
txbuf[2] = 0x00
while True:
# send data through SPI
rxbuf = dev.write(txbuf)
value = ((rxbuf[1] & 0x03) << 8) | rxbuf[2]
print(value)
time.sleep(0.5)

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Author: Henry Bruce <henry.bruce@intel.com>
# Copyright (c) 2016 Intel Corporation.
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
# Copyright (c) 2015 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -21,20 +21,22 @@
# 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
#
# Example Usage: Loopbacks data between MISO and MOSI 100 times
# Read from MCP3004 ADC pin 0 in single ended mode
import mraa
import time
import mraa as m
import random as rand
dev = mraa.Spi(0)
txbuf = bytearray(3)
txbuf[0] = 0x01
txbuf[1] = 0x80
txbuf[2] = 0x00
# intialise SPI
dev = m.Spi(0)
while True:
for x in range(0,100):
txbuf = bytearray(4)
for y in range(0,4):
txbuf[y] = rand.randrange(0, 256)
# send and receive data through SPI
rxbuf = dev.write(txbuf)
value = ((rxbuf[1] & 0x03) << 8) | rxbuf[2]
print value
time.sleep(0.5)
if rxbuf != txbuf:
print("Data mismatch!")
exit(1)

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
# Copyright (c) 2014 Intel Corporation.
# Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
# Copyright (c) 2018 Linaro Ltd.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -21,15 +21,20 @@
# 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.
#
# Example Usage: Sends data through UART
import mraa
import time
import sys
x = mraa.Gpio(8)
x.dir(mraa.DIR_OUT)
# serial port
port = "/dev/ttyACM0"
while True:
x.write(1)
time.sleep(0.2)
x.write(0)
time.sleep(0.2)
data = 'Hello Mraa!'
# initialise UART
uart = mraa.Uart(port)
# send data through UART
uart.write(bytearray(data, 'utf-8'))

View File

@@ -21,11 +21,14 @@
# 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
#
# Example Usage: Expects 'X' flag from the sender. This example requires
# `uart_sender.py` to be running on the other end.
import mraa
# Initialize UART
u=mraa.Uart(0)
# Initialise UART
u = mraa.Uart(0)
# Set UART parameters
u.setBaudRate(115200)
@@ -35,10 +38,11 @@ u.setFlowcontrol(False, False)
# Start a neverending loop waiting for data to arrive.
# Press Ctrl+C to get out of it.
while True:
if u.dataAvailable():
# We are doing 1-byte reads here
data_byte = u.readStr(1)
print(data_byte)
# Just a two-way half-duplex communication example, "X" is a flag
if data_byte == "X":
u.writeStr("Yes, master!")
if u.dataAvailable():
# We are doing 1-byte reads here
data_byte = u.readStr(1)
print(data_byte)
# Just a two-way half-duplex communication example, "X" is a flag
if data_byte == "X":
u.writeStr("Yes, master!")

View File

@@ -21,12 +21,17 @@
# 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
#
# Example Usage: Sends some info messages in the form of bytearray and strings
# along with `X` flag and prints the response from other end.
# This example requires uart_receiver.py to be running on the
# other end.
import mraa
import sys
sys.stdout.write("Initializing UART...")
u=mraa.Uart(0)
u = mraa.Uart(0)
print("...done")
print("Setting UART parameters: baudrate 115200, 8N1, no flow control")
@@ -52,6 +57,6 @@ u.writeStr("X")
print("...sent, awaiting response...")
# Checking for data in the RX buffer, giving it a 100ms timeout
if u.dataAvailable(100):
print("We've got a response: '{0}', says the other side".format(u.readStr(20)))
print("We've got a response: '{0}', says the other side".format(u.readStr(20)))
else:
print("No data received, do you have anything at the other end?")
print("No data received, do you have anything at the other end?")

View File

@@ -1,6 +1,6 @@
AioA0.cpp java/AioA0.java
Blink-IO.cpp java/BlinkIO.java
I2c-compass.cpp java/I2cCompass.java
Pwm3-cycle.cpp java/CyclePwm3.java
Spi-pot.cpp java/SpiMCP4261.java
Uart-example.cpp java/UartExample.java
aio.cpp java/AioA0.java
gpio.cpp java/BlinkIO.java
i2c.cpp java/I2cCompass.java
pwm.cpp java/CyclePwm3.java
spi.cpp java/SpiMCP4261.java
uart.cpp java/UartExample.java

View File

@@ -0,0 +1,74 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2018 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"
#include "linux/gpio.h"
typedef struct {
int chip_fd;
struct gpiochip_info chip_info;
} mraa_gpiod_chip_info;
typedef struct gpioline_info mraa_gpiod_line_info;
void _mraa_free_gpio_groups(mraa_gpio_context dev);
void _mraa_close_gpio_event_handles(mraa_gpio_context dev);
void _mraa_close_gpio_desc(mraa_gpio_context dev);
int _mraa_gpiod_ioctl(int fd, unsigned long gpio_request, void* data);
mraa_gpiod_chip_info* mraa_get_chip_info_by_path(const char* path);
mraa_gpiod_chip_info* mraa_get_chip_info_by_name(const char* name);
mraa_gpiod_chip_info* mraa_get_chip_info_by_label(const char* label);
mraa_gpiod_chip_info* mraa_get_chip_info_by_number(unsigned number);
mraa_gpiod_line_info* mraa_get_line_info_from_descriptor(int chip_fd, unsigned line_number);
mraa_gpiod_line_info* mraa_get_line_info_by_chip_number(unsigned chip_number, unsigned line_number);
mraa_gpiod_line_info* mraa_get_line_info_by_chip_name(const char* chip_name, unsigned line_number);
mraa_gpiod_line_info* mraa_get_line_info_by_chip_label(const char* chip_label, unsigned line_number);
int mraa_get_lines_handle(int chip_fd, unsigned line_offsets[], unsigned num_lines, unsigned flags, unsigned default_value);
int mraa_set_line_values(int line_handle, unsigned int num_lines, unsigned char input_values[]);
int mraa_get_line_values(int line_handle, unsigned int num_lines, unsigned char output_values[]);
mraa_boolean_t mraa_is_gpio_line_kernel_owned(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_dir_out(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_active_low(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_open_drain(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_open_source(mraa_gpiod_line_info *linfo);
int mraa_get_number_of_gpio_chips();
/* Multiple gpio support. */
typedef struct _gpio_group* mraa_gpiod_group_t;
#ifdef __cplusplus
}
#endif

81
include/linux/gpio.h Normal file
View File

@@ -0,0 +1,81 @@
/*
* This header was manually generated from a Linux kernel header linux/gpio.h,
* to make information necessary for compilation to be available. It contains
* only constants, structures, and macros generated from the original header,
* and thus, contains no copyrightable information.
*/
#ifndef _GPIO_H_
#define _GPIO_H_
#include <linux/ioctl.h>
#include <linux/types.h>
struct gpiochip_info {
char name[32];
char label[32];
__u32 lines;
};
#define GPIOLINE_FLAG_KERNEL (1UL << 0)
#define GPIOLINE_FLAG_IS_OUT (1UL << 1)
#define GPIOLINE_FLAG_ACTIVE_LOW (1UL << 2)
#define GPIOLINE_FLAG_OPEN_DRAIN (1UL << 3)
#define GPIOLINE_FLAG_OPEN_SOURCE (1UL << 4)
struct gpioline_info {
__u32 line_offset;
__u32 flags;
char name[32];
char consumer[32];
};
#define GPIOHANDLES_MAX 64
#define GPIOHANDLE_REQUEST_INPUT (1UL << 0)
#define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1)
#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2)
#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3)
#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4)
struct gpiohandle_request {
__u32 lineoffsets[GPIOHANDLES_MAX];
__u32 flags;
__u8 default_values[GPIOHANDLES_MAX];
char consumer_label[32];
__u32 lines;
int fd;
};
struct gpiohandle_data {
__u8 values[GPIOHANDLES_MAX];
};
#define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data)
#define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data)
#define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0)
#define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1)
#define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1))
struct gpioevent_request {
__u32 lineoffset;
__u32 handleflags;
__u32 eventflags;
char consumer_label[32];
int fd;
};
#define GPIOEVENT_EVENT_RISING_EDGE 0x01
#define GPIOEVENT_EVENT_FALLING_EDGE 0x02
struct gpioevent_data {
__u64 timestamp;
__u32 id;
};
#define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info)
#define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
#define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
#define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
#endif /* _GPIO_H_ */

View File

@@ -106,6 +106,26 @@ struct _firmata {
};
#endif
struct _gpio_group {
int is_required;
int dev_fd;
int gpiod_handle;
unsigned int gpio_chip;
/* We can have multiple lines in a gpio group. */
unsigned int num_gpio_lines;
unsigned int *gpio_lines;
/* R/W stuff.*/
unsigned char *rw_values;
/* Reverse mapping to original pin number indexes. */
unsigned int *gpio_group_to_pins_table;
unsigned int flags;
/* Event specific fields. */
int *event_handles;
};
/**
* A structure representing a gpio pin.
*/
@@ -134,8 +154,24 @@ struct _gpio {
#ifdef PERIPHERALMAN
AGpio *bgpio;
#endif
struct _gpio_group *gpio_group;
unsigned int num_chips;
int *pin_to_gpio_table;
unsigned int num_pins;
mraa_gpio_events_t events;
int *provided_pins;
struct _gpio *next;
};
/* Macro for looping over gpio chips. */
#define for_each_gpio_group(group, dev) \
for (int k = 0; \
k < dev->num_chips && (group = &dev->gpio_group[k]); \
++k) \
if (dev->gpio_group[k].is_required)
/**
* A structure representing a I2C bus
*/
@@ -315,6 +351,10 @@ typedef struct {
mraa_mux_t mux[6]; /** Array holding information about mux */
unsigned int output_enable; /** Output Enable GPIO, for level shifting */
mraa_pin_cap_complex_t complex_cap;
/* GPIOD_INTERFACE */
unsigned int gpio_chip;
unsigned int gpio_line;
/*@}*/
} mraa_pin_t;
@@ -447,6 +487,7 @@ typedef struct _board_t {
mraa_pininfo_t* pins; /**< Pointer to pin array */
mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */
struct _board_t* sub_platform; /**< Pointer to sub platform */
mraa_boolean_t chardev_capable; /**< Decide what interface is being used: old sysfs or new char device*/
/*@}*/
} mraa_board_t;

View File

@@ -32,7 +32,8 @@ extern "C" {
// +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_JOULE_EXPANSION_PINCOUNT (40*2 + 23 +1 +2)
// There is another pin for the built-in button.
#define MRAA_INTEL_JOULE_EXPANSION_PINCOUNT (40 * 2 + 23 + 1 + 2 + 1)
mraa_board_t*
mraa_joule_expansion_board();

View File

@@ -72,8 +72,6 @@ cmake \
-DJSONPLAT=$JSONPLAT \
-DIMRAA=$IMRAA \
-DFTDI4222=$FTDI4222 \
-DIPK=$IPK \
-DRPM=$RPM \
-DENABLEEXAMPLES=$ENABLEEXAMPLES \
-DINSTALLTOOLS=$INSTALLTOOLS \
-DBUILDTESTS=$BUILDTESTS \

View File

@@ -17,8 +17,6 @@ cmake \
-DJSONPLAT=$JSONPLAT \
-DIMRAA=$IMRAA \
-DFTDI4222=$FTDI4222 \
-DIPK=$IPK \
-DRPM=$RPM \
-DENABLEEXAMPLES=$ENABLEEXAMPLES \
-DINSTALLTOOLS=$INSTALLTOOLS \
-DBUILDTESTS=$BUILDTESTS \

View File

@@ -54,7 +54,7 @@ sonar_cmd_base="build-wrapper-linux-x86-64 --out-dir ${bw_output_path} make clea
-Dsonar.java.binaries='src' \
-Dsonar.coverage.exclusions='**/*' \
-Dsonar.cfamily.build-wrapper-output=${bw_output_path} \
-Dsonar.host.url=https://sonarqube.com \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG} \
-Dsonar.login=${SONAR_TOKEN} \
"

View File

@@ -23,6 +23,7 @@ include_directories(
set (mraa_LIB_SRCS_NOAUTO
${PROJECT_SOURCE_DIR}/src/mraa.c
${PROJECT_SOURCE_DIR}/src/gpio/gpio.c
${PROJECT_SOURCE_DIR}/src/gpio/gpio_chardev.c
${PROJECT_SOURCE_DIR}/src/i2c/i2c.c
${PROJECT_SOURCE_DIR}/src/pwm/pwm.c
${PROJECT_SOURCE_DIR}/src/spi/spi.c

View File

@@ -436,14 +436,6 @@ mraa_raspberry_pi_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_SUCCESS;
}
mraa_result_t
mraa_raspberry_pi_spi_frequency_replace(mraa_spi_context dev, int hz)
{
// RPI driver doesn't like being queried for it's max speed
dev->clock = hz;
return MRAA_SUCCESS;
}
mraa_board_t*
mraa_raspberry_pi()
{
@@ -630,7 +622,6 @@ mraa_raspberry_pi()
b->adv_func->spi_init_pre = &mraa_raspberry_pi_spi_init_pre;
b->adv_func->i2c_init_pre = &mraa_raspberry_pi_i2c_init_pre;
b->adv_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup;
b->adv_func->spi_frequency_replace = &mraa_raspberry_pi_spi_frequency_replace;
b->adv_func->pwm_init_raw_replace = &mraa_raspberry_pi_pwm_initraw_replace;
b->adv_func->pwm_write_replace = &mraa_raspberry_pi_pwm_write_duty_replace;
b->adv_func->pwm_period_replace = &mraa_raspberry_pi_pwm_period_us_replace;

View File

@@ -96,7 +96,7 @@ mraa_firmata_i2c_init_bus_replace(mraa_i2c_context dev)
char buff[4];
buff[0] = FIRMATA_START_SYSEX;
buff[1] = FIRMATA_I2C_CONFIG;
buff[2] = delay & 0xFF, (delay >> 8) & 0xFF;
buff[2] = delay & 0xFF;
buff[3] = FIRMATA_END_SYSEX;
mraa_uart_write(firmata_dev->uart, buff, 4);
@@ -217,7 +217,7 @@ mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
uint8_t rawdata[2];
rawdata[0] = firmata_dev->i2cmsg[dev->addr][command];
rawdata[1] = firmata_dev->i2cmsg[dev->addr][command+1];
uint16_t data = (uint16_t) rawdata;
uint16_t data = (uint16_t) *rawdata;
uint8_t high = (data & 0xFF00) >> 8;
data = (data << 8) & 0xFF00;
data |= high;

File diff suppressed because it is too large Load Diff

412
src/gpio/gpio_chardev.c Normal file
View File

@@ -0,0 +1,412 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2018 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 "linux/gpio.h"
#include "mraa_internal.h"
#include "gpio/gpio_chardev.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
#define MAX_SIZE 64
#define POLL_TIMEOUT
#define DEV_DIR "/dev/"
#define CHIP_DEV_PREFIX "gpiochip"
#define STR_SIZE 64
void
_mraa_free_gpio_groups(mraa_gpio_context dev)
{
mraa_gpiod_group_t gpio_iter;
for_each_gpio_group(gpio_iter, dev) {
free(gpio_iter->gpio_lines);
free(gpio_iter->rw_values);
free(gpio_iter->gpio_group_to_pins_table);
if (gpio_iter->gpiod_handle != -1) {
close(gpio_iter->gpiod_handle);
}
if (gpio_iter->event_handles != NULL) {
for (int j = 0; j < gpio_iter->num_gpio_lines; ++j) {
close(gpio_iter->event_handles[j]);
}
free(gpio_iter->event_handles);
}
close(gpio_iter->dev_fd);
}
free(dev->gpio_group);
/* Also delete the pin to gpio chip mapping. */
free(dev->pin_to_gpio_table);
/* User provided array saved internally. */
free(dev->provided_pins);
/* Finally, delete event array. */
free(dev->events);
}
void
_mraa_close_gpio_event_handles(mraa_gpio_context dev)
{
mraa_gpiod_group_t gpio_iter;
for_each_gpio_group(gpio_iter, dev) {
if (gpio_iter->event_handles != NULL) {
for (int j = 0; j < gpio_iter->num_gpio_lines; ++j) {
close(gpio_iter->event_handles[j]);
}
free(gpio_iter->event_handles);
/* In the end, _mraa_free_gpio_groups will be called. */
gpio_iter->event_handles = NULL;
}
}
}
void
_mraa_close_gpio_desc(mraa_gpio_context dev)
{
mraa_gpiod_group_t gpio_iter;
for_each_gpio_group(gpio_iter, dev) {
if (gpio_iter->gpiod_handle != -1) {
close(gpio_iter->gpiod_handle);
gpio_iter->gpiod_handle = -1;
}
}
}
int
_mraa_gpiod_ioctl(int fd, unsigned long gpio_request, void* data)
{
int status;
status = ioctl(fd, gpio_request, data);
if (status < 0) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: ioctl() error %s", strerror(errno));
}
return status;
}
int
mraa_get_lines_handle(int chip_fd, unsigned line_offsets[], unsigned num_lines, unsigned flags, unsigned default_value)
{
int status;
struct gpiohandle_request __gpio_hreq;
__gpio_hreq.lines = num_lines;
memcpy(__gpio_hreq.lineoffsets, line_offsets, num_lines * sizeof __gpio_hreq.lineoffsets[0]);
if (flags & GPIOHANDLE_REQUEST_OUTPUT) {
memset(__gpio_hreq.default_values, 0, num_lines * sizeof __gpio_hreq.default_values[0]);
}
__gpio_hreq.flags = flags;
status = _mraa_gpiod_ioctl(chip_fd, GPIO_GET_LINEHANDLE_IOCTL, &__gpio_hreq);
if (status < 0) {
syslog(LOG_ERR, "gpiod: ioctl() fail");
return status;
}
if (__gpio_hreq.fd <= 0) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid file descriptor");
}
return __gpio_hreq.fd;
}
mraa_gpiod_chip_info*
mraa_get_chip_info_by_path(const char* path)
{
mraa_gpiod_chip_info* cinfo;
int chip_fd, status;
if (path == NULL) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid device path");
return NULL;
}
chip_fd = open(path, O_RDWR | O_CLOEXEC);
if (chip_fd < 0) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: could not open device file %s", path);
return NULL;
}
cinfo = malloc(sizeof *cinfo);
if (!cinfo) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: malloc() fail");
close(chip_fd);
return NULL;
}
cinfo->chip_fd = chip_fd;
status = _mraa_gpiod_ioctl(cinfo->chip_fd, GPIO_GET_CHIPINFO_IOCTL, &cinfo->chip_info);
if (status < 0) {
close(cinfo->chip_fd);
free(cinfo);
return NULL;
}
return cinfo;
}
mraa_gpiod_chip_info*
mraa_get_chip_info_by_name(const char* name)
{
mraa_gpiod_chip_info* cinfo;
char* full_path;
/* TODO: check for string lengths first. */
full_path = malloc(STR_SIZE * sizeof *full_path);
if (!full_path) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: malloc() fail");
return NULL;
}
snprintf(full_path, STR_SIZE, "%s%s", DEV_DIR, name);
cinfo = mraa_get_chip_info_by_path(full_path);
free(full_path);
return cinfo;
}
mraa_gpiod_chip_info*
mraa_get_chip_info_by_label(const char* label)
{
/* TODO */
return NULL;
}
mraa_gpiod_chip_info*
mraa_get_chip_info_by_number(unsigned number)
{
mraa_gpiod_chip_info* cinfo;
char* full_path;
/* TODO: check for string lengths first. */
full_path = malloc(STR_SIZE * sizeof *full_path);
if (!full_path) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: malloc() fail");
return NULL;
}
snprintf(full_path, STR_SIZE, "%s%s%u", DEV_DIR, CHIP_DEV_PREFIX, number);
cinfo = mraa_get_chip_info_by_path(full_path);
free(full_path);
return cinfo;
}
mraa_gpiod_line_info*
mraa_get_line_info_from_descriptor(int chip_fd, unsigned line_number)
{
int status;
mraa_gpiod_line_info* linfo;
linfo = malloc(sizeof *linfo);
if (!linfo) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: malloc() fail");
return NULL;
}
linfo->line_offset = line_number;
status = _mraa_gpiod_ioctl(chip_fd, GPIO_GET_LINEINFO_IOCTL, linfo);
if (status < 0) {
free(linfo);
return NULL;
}
return linfo;
}
mraa_gpiod_line_info*
mraa_get_line_info_by_chip_number(unsigned chip_number, unsigned line_number)
{
mraa_gpiod_line_info* linfo;
mraa_gpiod_chip_info* cinfo;
cinfo = mraa_get_chip_info_by_number(chip_number);
if (!cinfo) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid chip number");
return NULL;
}
linfo = mraa_get_line_info_from_descriptor(cinfo->chip_fd, line_number);
free(cinfo);
return linfo;
}
mraa_gpiod_line_info*
mraa_get_line_info_by_chip_name(const char* chip_name, unsigned line_number)
{
mraa_gpiod_line_info* linfo;
mraa_gpiod_chip_info* cinfo;
cinfo = mraa_get_chip_info_by_name(chip_name);
if (!cinfo) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid chip number");
return NULL;
}
linfo = mraa_get_line_info_from_descriptor(cinfo->chip_fd, line_number);
free(cinfo);
return linfo;
}
mraa_gpiod_line_info*
mraa_get_line_info_by_chip_label(const char* chip_label, unsigned line_number)
{
mraa_gpiod_line_info* linfo;
mraa_gpiod_chip_info* cinfo;
cinfo = mraa_get_chip_info_by_label(chip_label);
if (!cinfo) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid chip number");
return NULL;
}
linfo = mraa_get_line_info_from_descriptor(cinfo->chip_fd, line_number);
free(cinfo);
return linfo;
}
int
mraa_set_line_values(int line_handle, unsigned int num_lines, unsigned char input_values[])
{
int status;
struct gpiohandle_data __hdata;
memcpy(__hdata.values, input_values, num_lines * sizeof(unsigned char));
status = _mraa_gpiod_ioctl(line_handle, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &__hdata);
if (status < 0) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: ioctl() fail");
}
return status;
}
int
mraa_get_line_values(int line_handle, unsigned int num_lines, unsigned char output_values[])
{
int status;
struct gpiohandle_data __hdata;
status = _mraa_gpiod_ioctl(line_handle, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &__hdata);
if (status < 0) {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: ioctl() fail");
return status;
}
memcpy(output_values, __hdata.values, num_lines * sizeof(unsigned char));
return status;
}
mraa_boolean_t
mraa_is_gpio_line_kernel_owned(mraa_gpiod_line_info *linfo)
{
return (linfo->flags & GPIOLINE_FLAG_IS_OUT);
}
mraa_boolean_t
mraa_is_gpio_line_dir_out(mraa_gpiod_line_info *linfo)
{
return (linfo->flags & GPIOLINE_FLAG_IS_OUT);
}
mraa_boolean_t
mraa_is_gpio_line_active_low(mraa_gpiod_line_info *linfo)
{
return (linfo->flags & GPIOLINE_FLAG_ACTIVE_LOW);
}
mraa_boolean_t
mraa_is_gpio_line_open_drain(mraa_gpiod_line_info *linfo)
{
return (linfo->flags & GPIOLINE_FLAG_OPEN_DRAIN);
}
mraa_boolean_t
mraa_is_gpio_line_open_source(mraa_gpiod_line_info *linfo)
{
return (linfo->flags & GPIOHANDLE_REQUEST_OPEN_SOURCE);
}
int
mraa_get_number_of_gpio_chips()
{
int num_chips = 0;
DIR* dev_dir;
struct dirent* dir;
const unsigned int len = strlen(CHIP_DEV_PREFIX);
dev_dir = opendir(DEV_DIR);
if (dev_dir) {
while ((dir = readdir(dev_dir)) != NULL) {
if (!strncmp(dir->d_name, CHIP_DEV_PREFIX, len)) {
num_chips++;
}
}
closedir(dev_dir);
} else {
syslog(LOG_ERR, "[GPIOD_INTERFACE]: opendir() error");
return -1;
}
/* Assume opendir() error. */
return num_chips;
}

View File

@@ -113,12 +113,16 @@ mraa_led_init_internal(const char* led)
dev->count = cnt;
if (dev->led_name == NULL) {
syslog(LOG_CRIT, "led: init: unknown device specified");
closedir(dir);
if (dir != NULL) {
closedir(dir);
}
free(dev);
return NULL;
}
closedir(dir);
if (dir != NULL) {
closedir(dir);
}
return dev;
}

View File

@@ -45,7 +45,7 @@
#include <unistd.h>
#include <ctype.h>
#include <limits.h>
#include <sys/utsname.h>
#if defined(IMRAA)
#include <json-c/json.h>
@@ -57,6 +57,7 @@
#include "firmata/firmata_mraa.h"
#include "grovepi/grovepi.h"
#include "gpio.h"
#include "gpio/gpio_chardev.h"
#include "version.h"
#include "i2c.h"
#include "pwm.h"
@@ -98,6 +99,21 @@ mraa_set_log_level(int level)
return MRAA_ERROR_INVALID_PARAMETER;
}
mraa_boolean_t mraa_is_kernel_chardev_interface_compatible()
{
if (mraa_get_number_of_gpio_chips() <= 0) {
return 0;
}
return 1;
}
/* TODO: Add all relevant checks here and return the overall result. */
mraa_boolean_t mraa_is_platform_chardev_interface_capable()
{
return mraa_is_kernel_chardev_interface_compatible();
}
/**
* Whilst the actual mraa init function is now called imraa_init, it's only
* callable externally if IMRAA is enabled
@@ -218,6 +234,11 @@ imraa_init()
return MRAA_ERROR_NO_RESOURCES;
}
plat->chardev_capable = mraa_is_platform_chardev_interface_capable();
if (plat->chardev_capable) {
syslog(LOG_NOTICE, "libmraa: support for chardev interface is activated");
}
syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type());
return MRAA_SUCCESS;
}
@@ -883,7 +904,7 @@ mraa_gpio_lookup(const char* pin_name)
for (i = 0; i < plat->gpio_count; i++) {
if (plat->pins[i].name != NULL &&
strncmp(pin_name, plat->pins[i].name, strlen(plat->pins[i].name) + 1) == 0) {
return plat->pins[i].gpio.pinmap;
return i;
}
}
return -1;

View File

@@ -1,7 +1,7 @@
set_source_files_properties (mraa2.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa2.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
message ("PYTHON2 attempting to build!")
message (STATUS "PYTHON2 attempting to build!")
if (CMAKE_VERSION VERSION_LESS "3.8")
swig_add_module (python2-mraa python mraa2.i ../mraapy.c)

View File

@@ -12,7 +12,7 @@ Hello GPIO
Here is the simplest Gpio program in mraa.
.. literalinclude:: ../../../../examples/python/hello_gpio.py
.. literalinclude:: ../../../../examples/python/gpio.py
:prepend: import mraa
:start-after: import mraa
@@ -27,7 +27,7 @@ values.
**Note:** Galileo Gen1 only supports EDGE_BOTH
.. literalinclude:: ../../../../examples/python/hello_isr.py
.. literalinclude:: ../../../../examples/python/gpio_advanced.py
:prepend: import mraa
:start-after: import mraa
@@ -44,7 +44,7 @@ The I2c module module has a number of different ways of interacting with the
i2c bus, including a number of overloaded read() calls and the writeReg()
helper function.
.. literalinclude:: ../../../../examples/python/bmp85.py
.. literalinclude:: ../../../../examples/python/i2c_bmp85.py
:prepend: x = m.I2c(0)
:start-after: x = m.I2c(0)
@@ -56,7 +56,7 @@ Pwm
The PWM module is rather simple, note that different hardware support PWM
generation is various different ways so results may vary.
.. literalinclude:: ../../../../examples/python/cycle-pwm3.py
.. literalinclude:: ../../../../examples/python/pwm.py
:prepend: import mraa
:start-after: import mraa
@@ -91,3 +91,13 @@ Receiver:
.. literalinclude:: ../../../../examples/python/uart_receiver.py
:prepend: import mraa
:start-after: import mraa
LED
===
LED module is used for controlling the on-board LEDs. With the
help of this module, we can control the brightness, trigger etc...
.. literalinclude:: ../../../../examples/python/led.py
:prepend: import mraa
:start-after: import mraa

View File

@@ -1,7 +1,7 @@
set_source_files_properties (mraa3.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa3.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
message ("PYTHON3 attempting to build!")
message (STATUS "PYTHON3 attempting to build!")
if (CMAKE_VERSION VERSION_LESS "3.8")
swig_add_module (python3-mraa python mraa3.i ../mraapy.c)

View File

@@ -256,9 +256,12 @@ mraa_spi_frequency(mraa_spi_context dev, int hz)
int speed = 0;
dev->clock = hz;
if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
if (speed < hz) {
dev->clock = speed;
syslog(LOG_WARNING, "spi: Selected speed reduced to max allowed speed");
if (speed < hz) {
// We wanted to never go higher than SPI_IOC_RD_MAX_SPEED_HZ but it
// seems a bunch of drivers don't have this set to the actual max
// so we only complain about it
// dev->clock = speed;
syslog(LOG_NOTICE, "spi: Selected speed (%dhz) is higher than the kernel max allowed speed (%shz)", hz, SPI_IOC_RD_MAX_SPEED_HZ);
}
}
return MRAA_SUCCESS;

View File

@@ -1,3 +1,3 @@
message (INFO " - Adding x86 platforms")
message (STATUS "INFO - Adding x86 platforms")
set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
${mraa_LIB_X86_SRCS_NOAUTO} PARENT_SCOPE)

View File

@@ -147,7 +147,7 @@ mraa_intel_edison_pinmode_change(int sysfs, int mode)
mraa_result_t ret = MRAA_SUCCESS;
char mode_buf[MAX_MODE_SIZE];
int length = sprintf(mode_buf, "%s%u", useDebugFS ? "mode" : "", mode);
int length = snprintf(mode_buf, MAX_MODE_SIZE, "%s%u", useDebugFS ? "mode" : "", mode);
if (write(modef, mode_buf, length * sizeof(char)) == -1) {
ret = MRAA_ERROR_INVALID_RESOURCE;
}

View File

@@ -160,12 +160,16 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 451;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 22;
pos++;
strncpy(b->pins[pos].name, "SPP1RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 421;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 64;
pos++;
strncpy(b->pins[pos].name, "PMICRST", 8);
@@ -179,18 +183,24 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 422;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 65;
pos++;
strncpy(b->pins[pos].name, "19.2mhz", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 356;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 41;
pos++;
strncpy(b->pins[pos].name, "SPP1FS0", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 417;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 60;
pos++;
strncpy(b->pins[pos].name, "UART0TX", 8);
@@ -200,12 +210,16 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 39;
pos++;
strncpy(b->pins[pos].name, "SPP1FS2", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 419;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 62;
pos++;
strncpy(b->pins[pos].name, "PWRGD", 8);
@@ -220,6 +234,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 416;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 59;
pos++;
strncpy(b->pins[pos].name, "I2C0SDA", 8);
@@ -234,6 +250,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 381;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 24;
pos++;
strncpy(b->pins[pos].name, "I2C0SCL", 8);
@@ -248,6 +266,10 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 382;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 24;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 25;
pos++;
strncpy(b->pins[pos].name, "II0SDA", 8);
@@ -262,6 +284,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 380;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 23;
pos++;
strncpy(b->pins[pos].name, "IIC0SCL", 8);
@@ -276,6 +300,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 379;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 22;
pos++;
strncpy(b->pins[pos].name, "IIC1SDA", 8);
@@ -291,6 +317,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 378;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 21;
pos++;
strncpy(b->pins[pos].name, "IIC1SCL", 8);
@@ -308,12 +336,16 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 43;
pos++;
strncpy(b->pins[pos].name, "ISH_IO6", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 343;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 28;
pos++;
strncpy(b->pins[pos].name, "UART1RX", 8);
@@ -323,12 +355,16 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 42;
pos++;
strncpy(b->pins[pos].name, "ISH_IO5", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 342;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 27;
pos++;
strncpy(b->pins[pos].name, "PWM0", 8);
@@ -338,12 +374,16 @@ mraa_joule_expansion_board()
b->pins[pos].pwm.pinmap = 0;
b->pins[pos].pwm.parent_id = 0;
b->pins[pos].pwm.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 34;
pos++;
strncpy(b->pins[pos].name, "ISH_IO4", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 341;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 26;
pos++;
strncpy(b->pins[pos].name, "PWM1", 8);
@@ -353,6 +393,8 @@ mraa_joule_expansion_board()
b->pins[pos].pwm.pinmap = 1;
b->pins[pos].pwm.parent_id = 0;
b->pins[pos].pwm.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 35;
pos++;
strncpy(b->pins[pos].name, "ISH_IO3", 8);
@@ -360,6 +402,8 @@ mraa_joule_expansion_board()
// High level will be V1P8 - VBE on MBT3904D
b->pins[pos].gpio.pinmap = 340;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 25;
pos++;
// pin 30
@@ -370,6 +414,8 @@ mraa_joule_expansion_board()
b->pins[pos].pwm.pinmap = 2;
b->pins[pos].pwm.parent_id = 0;
b->pins[pos].pwm.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 36;
pos++;
strncpy(b->pins[pos].name, "ISH_IO2", 8);
@@ -377,6 +423,8 @@ mraa_joule_expansion_board()
// High level will be V1P8 - VBE on MBT3904D
b->pins[pos].gpio.pinmap = 339;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 24;
pos++;
strncpy(b->pins[pos].name, "PWM3", 8);
@@ -386,6 +434,8 @@ mraa_joule_expansion_board()
b->pins[pos].pwm.pinmap = 3;
b->pins[pos].pwm.parent_id = 0;
b->pins[pos].pwm.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 37;
pos++;
strncpy(b->pins[pos].name, "ISH_IO1", 8);
@@ -393,6 +443,8 @@ mraa_joule_expansion_board()
// High level will be V1P8 - VBE on MBT3904D
b->pins[pos].gpio.pinmap = 338;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 23;
pos++;
strncpy(b->pins[pos].name, "1.8V", 8);
@@ -404,6 +456,8 @@ mraa_joule_expansion_board()
// High level will be V1P8 - VBE on MBT3904D
b->pins[pos].gpio.pinmap = 337;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 22;
pos++;
strncpy(b->pins[pos].name, "GND", 8);
@@ -473,6 +527,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 456;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 27;
pos++;
strncpy(b->pins[pos].name, "1.8V", 8);
@@ -483,6 +539,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 270;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 4;
b->pins[pos].gpio.gpio_line = 6;
pos++;
strncpy(b->pins[pos].name, "GND", 8);
@@ -493,6 +551,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 271;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 4;
b->pins[pos].gpio.gpio_line = 7;
pos++;
strncpy(b->pins[pos].name, "CAMERA", 8);
@@ -503,6 +563,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 272;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 4;
b->pins[pos].gpio.gpio_line = 8;
pos++;
strncpy(b->pins[pos].name, "CAMERA", 8);
@@ -513,6 +575,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 411;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 54;
pos++;
// pin 60
@@ -524,6 +588,8 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 412;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 55;
pos++;
strncpy(b->pins[pos].name, "SPI_DAT", 8);
@@ -536,30 +602,40 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 413;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 56;
pos++;
strncpy(b->pins[pos].name, "SPICLKB", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 384;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 27;
pos++;
strncpy(b->pins[pos].name, "SPP0CLK", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 410;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 53;
pos++;
strncpy(b->pins[pos].name, "SPICLKA", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 383;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 26;
pos++;
strncpy(b->pins[pos].name, "SPP0TX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 414;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 57;
pos++;
strncpy(b->pins[pos].name, "UART0RX", 8);
@@ -569,12 +645,16 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 38;
pos++;
strncpy(b->pins[pos].name, "SPP0RX", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 415;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 58;
pos++;
// pin 70
@@ -585,6 +665,8 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 40;
pos++;
strncpy(b->pins[pos].name, "I2C1SDA", 8);
@@ -602,6 +684,8 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 41;
pos++;
strncpy(b->pins[pos].name, "I2C1SCL", 8);
@@ -619,6 +703,8 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 51;
pos++;
strncpy(b->pins[pos].name, "I2C2SDA", 8);
@@ -636,6 +722,8 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 50;
pos++;
strncpy(b->pins[pos].name, "I2C2SCL", 8);
@@ -653,12 +741,16 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 52;
pos++;
strncpy(b->pins[pos].name, "RTC_CLK", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 367;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 1;
b->pins[pos].gpio.gpio_line = 10;
pos++;
// pin 80
@@ -668,6 +760,8 @@ mraa_joule_expansion_board()
b->pins[pos].uart.pinmap = 0;
b->pins[pos].uart.parent_id = 0;
b->pins[pos].uart.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 53;
pos++;
while (pos != 100) {
@@ -679,24 +773,32 @@ mraa_joule_expansion_board()
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 337;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 22;
pos++;
strncpy(b->pins[pos].name, "LED101", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 338;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 23;
pos++;
strncpy(b->pins[pos].name, "LED102", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 339;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 24;
pos++;
strncpy(b->pins[pos].name, "LED103", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 340;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 2;
b->pins[pos].gpio.gpio_line = 25;
pos++;
strncpy(b->pins[pos].name, "LEDBT", 8);
@@ -711,6 +813,14 @@ mraa_joule_expansion_board()
b->pins[pos].gpio.mux_total = 0;
pos++;
strncpy(b->pins[pos].name, "GPBTN", 8);
b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 446;
b->pins[pos].gpio.mux_total = 0;
b->pins[pos].gpio.gpio_chip = 0;
b->pins[pos].gpio.gpio_line = 17;
pos++;
return b;
error: