├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── COPYING ├── Doxyfile.in ├── Doxyfile.java.in ├── DoxygenLayout.xml ├── README.md ├── api ├── mraa.h ├── mraa.hpp └── mraa │ ├── aio.h │ ├── aio.hpp │ ├── common.h │ ├── common.hpp │ ├── firmata.h │ ├── gpio.h │ ├── gpio.hpp │ ├── i2c.h │ ├── i2c.hpp │ ├── iio.h │ ├── iio.hpp │ ├── iio_kernel_headers.h │ ├── initio.h │ ├── initio.hpp │ ├── led.h │ ├── led.hpp │ ├── pwm.h │ ├── pwm.hpp │ ├── spi.h │ ├── spi.hpp │ ├── types.h │ ├── types.hpp │ ├── uart.h │ ├── uart.hpp │ ├── uart_ow.h │ └── uart_ow.hpp ├── cmake ├── Toolchains │ └── README.md └── modules │ ├── COPYING-CMAKE-SCRIPTS │ ├── Copyright.txt │ ├── FindFtd2xx.cmake │ ├── FindFtd4222.cmake │ ├── FindJSON-C.cmake │ ├── FindNodejs.cmake │ ├── FindSphinx.cmake │ ├── FindUDEV.cmake │ ├── FindYuidoc.cmake │ ├── GetGitRevisionDescription.cmake │ ├── GetGitRevisionDescription.cmake.in │ ├── LICENSE_1_0.txt │ ├── OpenCVDetectPython.cmake │ └── version.c.in ├── docker-compose.yaml ├── docs ├── 96boards.md ├── adlink_ipi_arm.md ├── adlink_ipi_x86.md ├── banana_pi.md ├── beaglebone.md ├── building.md ├── changelog.md ├── de_nano_soc.md ├── debugging.md ├── edison.md ├── firmata.md ├── ftdi_ft4222.md ├── galileorevd.md ├── galileorevh.md ├── grossetete.md ├── grovepi.md ├── i2c.txt ├── iei-tank.md ├── iio.md ├── imraa.md ├── index.java.md ├── index.md ├── intel_de3815.md ├── intel_nuc5.md ├── internals.md ├── joule.md ├── jsonplatform.md ├── linkit_7688.md ├── minnow_max.md ├── mock.md ├── npm.md ├── omega2.md ├── orange_pi_prime.md ├── phyboard-wega.md ├── platform-hooks.md ├── radxa_cm3.md ├── radxa_cm5_io.md ├── radxa_e25.md ├── radxa_rock_3a.md ├── radxa_rock_3b.md ├── radxa_rock_3c.md ├── radxa_rock_5a.md ├── radxa_rock_5b.md ├── radxa_zero3.md ├── raspberry_pi.md ├── rockpi4.md ├── static_code_analysis.md ├── testing.md ├── up.md ├── up2.md ├── up_xtreme.md └── visionfive.md ├── examples ├── CMakeLists.txt ├── c++ │ ├── CMakeLists.txt │ ├── aio.cpp │ ├── gpio.cpp │ ├── gpio_advanced.cpp │ ├── i2c.cpp │ ├── iio.cpp │ ├── led.cpp │ ├── pwm.cpp │ ├── spi.cpp │ ├── uart.cpp │ └── uart_ow.cpp ├── c │ ├── CMakeLists.txt │ ├── aio.c │ ├── gpio.c │ ├── gpio_advanced.c │ ├── gpio_multiple_rw.c │ ├── hellomraa.c │ ├── i2c_hmc5883l.c │ ├── i2c_mpu6050.c │ ├── iio.c │ ├── initio.c │ ├── led.c │ ├── pwm.c │ ├── spi.c │ ├── uart.c │ ├── uart_advanced.c │ └── uart_ow.c ├── java │ ├── AioA0.java │ ├── BlinkIO.java │ ├── BlinkOnboard.java │ ├── Bmp85.java │ ├── CyclePwm3.java │ ├── Example.java │ ├── FTDITest.java │ ├── GpioMmapped.java │ ├── GpioRead6.java │ ├── HelloEdison.java │ ├── I2cCompass.java │ ├── Isr.java │ ├── SpiMAX7219.java │ ├── SpiMCP4261.java │ └── UartExample.java ├── javascript │ ├── AioA0.js │ ├── Blink-IO.js │ ├── GPIO_DigitalRead.js │ ├── GPIO_DigitalWrite.js │ ├── bmp85.js │ ├── firmata.js │ ├── gpio-tool.js │ ├── initio.js │ ├── isr.js │ ├── rgblcd.js │ ├── spi.js │ └── uart.js ├── platform │ ├── CMakeLists.txt │ ├── Up2Leds.java │ ├── firmata_curie_imu.c │ ├── gpio_edison.c │ ├── i2c_firmata.c │ ├── initio.c │ ├── initio.cpp │ ├── initio.py │ ├── intel-aero.json │ ├── turbotjson.json │ └── up2-leds.cpp ├── python │ ├── aio.py │ ├── firmata.py │ ├── gpio.py │ ├── gpio_advanced.py │ ├── i2c_bmp85.py │ ├── i2c_rgb.py │ ├── led.py │ ├── pwm.py │ ├── spi.py │ ├── spi_loopback.py │ ├── uart.py │ ├── uart_receiver.py │ └── uart_sender.py └── samples.mapping.txt ├── imraa ├── CMakeLists.txt ├── imraa.c ├── imraa.conf ├── imraa.io.conf ├── imraa.service ├── imraa_arduino.c ├── imraa_arduino.h ├── imraa_io.c ├── imraa_io.h ├── imraa_lock.c └── imraa_lock.h ├── include ├── arm │ ├── 96boards.h │ ├── adlink_ipi.h │ ├── am335x.h │ ├── banana.h │ ├── beaglebone.h │ ├── de_nano_soc.h │ ├── orange_pi_prime.h │ ├── phyboard.h │ ├── radxa_cm3.h │ ├── radxa_cm5_io.h │ ├── radxa_e25.h │ ├── radxa_rock_3a.h │ ├── radxa_rock_3b.h │ ├── radxa_rock_3c.h │ ├── radxa_rock_5a.h │ ├── radxa_rock_5b.h │ ├── raspberry_pi.h │ ├── rockpi4.h │ └── siemens │ │ ├── iot2050.h │ │ ├── platform.h │ │ └── platform_iot2050.h ├── firmata │ ├── firmata.h │ └── firmata_mraa.h ├── gpio │ └── gpio_chardev.h ├── grovepi │ └── grovepi.h ├── initio │ └── initio_keys.h ├── java │ └── mraajni.h ├── linux │ ├── README │ ├── compiler.h │ ├── gpio.h │ ├── i2c-dev.h │ ├── posix_types.h │ ├── spi_kernel_headers.h │ └── types.h ├── mips │ └── mediatek.h ├── mock │ ├── mock_board.h │ ├── mock_board_aio.h │ ├── mock_board_gpio.h │ ├── mock_board_i2c.h │ ├── mock_board_spi.h │ └── mock_board_uart.h ├── mraa_adv_func.h ├── mraa_internal.h ├── mraa_internal_types.h ├── mraa_lang_func.h ├── peripheralmanager │ └── peripheralman.h ├── python │ └── mraapy.h ├── riscv │ └── visionfive.h ├── version.h └── x86 │ ├── iei_tank.h │ ├── intel_adlink_lec_al.h │ ├── intel_cherryhills.h │ ├── intel_de3815.h │ ├── intel_edison_fab_c.h │ ├── intel_galileo_rev_d.h │ ├── intel_galileo_rev_g.h │ ├── intel_ilk.h │ ├── intel_joule_expansion.h │ ├── intel_minnow_byt_compatible.h │ ├── intel_nuc5.h │ ├── intel_sofia_3gr.h │ ├── up.h │ ├── up2.h │ └── up_xtreme.h ├── jsstub ├── Gruntfile.js ├── README.md ├── index.js ├── package.json └── test │ ├── index.js │ └── lightbulb.js ├── scripts ├── build-android.sh ├── build-doc.sh ├── run-cmake.sh └── sonar-scan.sh ├── src ├── CMakeLists.txt ├── aio │ └── aio.c ├── arm │ ├── 96boards.c │ ├── CMakeLists.txt │ ├── adlink_ipi.c │ ├── am335x.c │ ├── arm.c │ ├── banana.c │ ├── beaglebone.c │ ├── de_nano_soc.c │ ├── orange_pi_prime.c │ ├── phyboard.c │ ├── radxa_cm3.c │ ├── radxa_cm5_io.c │ ├── radxa_e25.c │ ├── radxa_rock_3a.c │ ├── radxa_rock_3b.c │ ├── radxa_rock_3c.c │ ├── radxa_rock_5a.c │ ├── radxa_rock_5b.c │ ├── raspberry_pi.c │ ├── rockpi4.c │ └── siemens │ │ ├── iot2050.c │ │ ├── platform.c │ │ └── platform_iot2050.c ├── doxy2swig.py ├── firmata │ ├── CMakeLists.txt │ ├── firmata.c │ └── firmata_mraa.c ├── glob │ ├── glob.c │ └── glob.h ├── gpio │ ├── gpio.c │ └── gpio_chardev.c ├── grovepi │ ├── CMakeLists.txt │ └── grovepi.c ├── i2c │ ├── LICENSE │ └── i2c.c ├── iio │ └── iio.c ├── initio │ └── initio.c ├── java │ ├── CMakeLists.txt │ ├── manifest.txt.in │ ├── mraajava.i │ ├── mraajava.pc.cmake │ ├── mraajni.c │ └── pom.xml.in ├── javascript │ ├── CMakeLists.txt │ ├── binding.gyp.cmake │ ├── doxygen2jsdoc_custom.json │ ├── mraajs.i │ └── package.json.cmake ├── json │ └── jsonplatform.c ├── led │ └── led.c ├── mips │ ├── CMakeLists.txt │ ├── mediatek.c │ └── mips.c ├── mock │ ├── CMakeLists.txt │ ├── mock.c │ ├── mock_board.c │ ├── mock_board_aio.c │ ├── mock_board_gpio.c │ ├── mock_board_i2c.c │ ├── mock_board_spi.c │ └── mock_board_uart.c ├── mraa.c ├── mraa.i ├── mraa.pc.cmake ├── peripheralman │ ├── CMakeLists.txt │ └── peripheralman.c ├── pwm │ └── pwm.c ├── python │ ├── CMakeLists.txt │ ├── mraapy.c │ ├── mraapython.i │ └── python3 │ │ ├── CMakeLists.txt │ │ ├── docs │ │ ├── CMakeLists.txt │ │ ├── conf.py.in │ │ ├── example.rst │ │ ├── index.rst │ │ └── mraa.rst │ │ └── mraa3.i ├── riscv │ ├── CMakeLists.txt │ ├── riscv.c │ └── visionfive.c ├── spi │ └── spi.c ├── uart │ └── uart.c ├── uart_ow │ ├── CMakeLists.txt │ └── uart_ow.c ├── usb │ ├── CMakeLists.txt │ └── ft4222 │ │ ├── CMakeLists.txt │ │ ├── ftdi_ft4222.cxx │ │ └── ftdi_ft4222.hpp └── x86 │ ├── CMakeLists.txt │ ├── adlink-ipi.c │ ├── iei_tank.c │ ├── intel_cherryhills.c │ ├── intel_de3815.c │ ├── intel_edison_fab_c.c │ ├── intel_galileo_rev_d.c │ ├── intel_galileo_rev_g.c │ ├── intel_ilk.c │ ├── intel_joule_expansion.c │ ├── intel_minnow_byt_compatible.c │ ├── intel_nuc5.c │ ├── intel_sofia_3gr.c │ ├── up.c │ ├── up2.c │ ├── up_xtreme.c │ └── x86.c ├── tests ├── CMakeLists.txt ├── check_clean.py ├── check_samplenames.py ├── general_checks.py ├── gpio_checks.py ├── mock │ ├── CMakeLists.txt │ ├── aio_checks.py │ ├── general_checks.py │ ├── gpio_checks_basic.py │ ├── gpio_checks_dir.py │ ├── gpio_checks_edge.py │ ├── gpio_checks_isr.py │ ├── gpio_checks_mode.py │ ├── gpio_checks_write_read.py │ ├── i2c_checks_addr.py │ ├── i2c_checks_freq.py │ ├── i2c_checks_read.py │ ├── i2c_checks_read_byte.py │ ├── i2c_checks_read_byte_data.py │ ├── i2c_checks_read_bytes_data.py │ ├── i2c_checks_read_word_data.py │ ├── i2c_checks_shared.py │ ├── i2c_checks_write.py │ ├── i2c_checks_write_byte.py │ ├── i2c_checks_write_byte_data.py │ ├── i2c_checks_write_word_data.py │ ├── platform_checks.py │ ├── spi_checks_bit_per_word.py │ ├── spi_checks_freq.py │ ├── spi_checks_lsbmode.py │ ├── spi_checks_mode.py │ ├── spi_checks_shared.py │ ├── spi_checks_write.py │ ├── spi_checks_write_byte.py │ ├── spi_checks_write_word.py │ ├── uart_checks_data_available.py │ ├── uart_checks_flush.py │ ├── uart_checks_read.py │ ├── uart_checks_sendbreak.py │ ├── uart_checks_set_baudrate.py │ ├── uart_checks_set_flowcontrol.py │ ├── uart_checks_set_mode.py │ ├── uart_checks_set_nonblocking.py │ ├── uart_checks_set_timeout.py │ ├── uart_checks_shared.py │ └── uart_checks_write.py ├── platform_checks.py └── unit │ ├── CMakeLists.txt │ ├── api │ ├── api_common_h_unit.cxx │ ├── api_common_hpp_unit.cxx │ ├── mraa_initio_h_unit.cxx │ └── mraa_initio_hpp_unit.cxx │ └── platform_extender │ └── platform_extender.cxx └── tools ├── CMakeLists.txt ├── mraa-gpio.c ├── mraa-i2c.c └── mraa-uart.c /.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -2 2 | AlignEscapedNewlinesLeft: true 3 | AlignTrailingComments: true 4 | AllowAllParametersOfDeclarationOnNextLine: false 5 | AllowShortFunctionsOnASingleLine: false 6 | AllowShortIfStatementsOnASingleLine: false 7 | AllowShortLoopsOnASingleLine: false 8 | AlwaysBreakBeforeMultilineStrings: false 9 | AlwaysBreakTemplateDeclarations: false 10 | AlwaysBreakAfterDefinitionReturnType: true 11 | BinPackParameters: false 12 | BreakBeforeBinaryOperators: false 13 | BreakBeforeBraces: Linux 14 | BreakBeforeTernaryOperators: false 15 | BreakConstructorInitializersBeforeComma: false 16 | ColumnLimit: 100 17 | CommentPragmas: '' 18 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 19 | ConstructorInitializerIndentWidth: 0 20 | ContinuationIndentWidth: 0 21 | Cpp11BracedListStyle: false 22 | DerivePointerBinding: false 23 | IndentCaseLabels: true 24 | IndentFunctionDeclarationAfterType: false 25 | IndentWidth: 4 26 | Language: Cpp 27 | MaxEmptyLinesToKeep: 2 28 | NamespaceIndentation: None 29 | ObjCSpaceAfterProperty: true 30 | ObjCSpaceBeforeProtocolList: true 31 | PenaltyBreakBeforeFirstCallParameter: 100 32 | PenaltyBreakComment: 100 33 | PenaltyBreakFirstLessLess: 0 34 | PenaltyBreakString: 100 35 | PenaltyExcessCharacter: 1 36 | PenaltyReturnTypeOnItsOwnLine: 20 37 | PointerBindsToType: true 38 | PointerAlignment: Left 39 | SpaceBeforeAssignmentOperators: true 40 | SpaceBeforeParens: ControlStatements 41 | SpaceInEmptyParentheses: false 42 | SpacesBeforeTrailingComments: 1 43 | SpacesInAngles: false 44 | SpacesInCStyleCastParentheses: false 45 | SpaceAfterCStyleCast: true 46 | SpacesInContainerLiterals: false 47 | SpacesInParentheses: false 48 | Standard: Cpp11 49 | TabWidth: 4 50 | UseTab: Never 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | install/ 3 | 4 | # Object files 5 | *.o 6 | *.lib 7 | *.so 8 | *.lo 9 | *.la 10 | *.pyc 11 | 12 | # Temp files 13 | *.swp 14 | *.swo 15 | *~ 16 | 17 | # npmpub files 18 | src/mraajsJAVASCRIPT_wrap.cxx 19 | src/version.c 20 | package.json 21 | binding.gyp 22 | READMEFIRST 23 | npm-debug.log 24 | 25 | # Sonar 26 | .scannerwork/ 27 | 28 | # Visual Studio Code 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doxygen2jsdoc"] 2 | path = doxygen2jsdoc 3 | url = https://github.com/intel-iot-devkit/doxygen2jsdoc.git 4 | branch = master 5 | [submodule "doxyport"] 6 | path = doxyport 7 | url = https://github.com/intel-iot-devkit/doxyport.git 8 | branch = master 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright © 2014-2019 Intel Corporation and others 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /api/mraa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright © 2014 Intel Corporation 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | * 23 | * SPDX-License-Identifier: MIT 24 | */ 25 | 26 | #pragma once 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include "mraa/pwm.h" 33 | #include "mraa/aio.h" 34 | #include "mraa/gpio.h" 35 | #include "mraa/spi.h" 36 | #include "mraa/i2c.h" 37 | #include "mraa/uart.h" 38 | #include "mraa/uart_ow.h" 39 | #include "mraa/led.h" 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /api/mraa.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * SPDX-License-Identifier: MIT 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "mraa/common.hpp" 30 | #include "mraa/pwm.hpp" 31 | #include "mraa/aio.hpp" 32 | #include "mraa/gpio.hpp" 33 | #include "mraa/i2c.hpp" 34 | #include "mraa/spi.hpp" 35 | #include "mraa/uart.hpp" 36 | #include "mraa/led.hpp" 37 | -------------------------------------------------------------------------------- /cmake/Toolchains/README.md: -------------------------------------------------------------------------------- 1 | This directory used to contain an OE-Toolchain file. A far better one is now included 2 | with Devtool/OE-SDK. 3 | 4 | https://git.yoctoproject.org/cgit.cgi/poky/plain/meta/recipes-devtools/cmake/cmake/OEToolchainConfig.cmake 5 | 6 | The following may be interesting for certain Java/Cross-compilation reasons: 7 | ``` 8 | # for Cmake java 9 | set( JAVA_AWT_INCLUDE_PATH $ENV{JAVA_HOME}/include CACHE PATH "" FORCE) 10 | set( JAVA_AWT_LIBRARY $ENV{JAVA_HOME}/jre/lib/amd64/libjawt.so CACHE FILEPATH "" FORCE) 11 | set( JAVA_INCLUDE_PATH $ENV{JAVA_HOME}/include CACHE PATH "" FORCE) 12 | set( JAVA_INCLUDE_PATH2 $ENV{JAVA_HOME}/include/linux CACHE PATH "" FORCE) 13 | set( JAVA_JVM_LIBRARY $ENV{JAVA_HOME}/jre/lib/amd64/libjvm.so CACHE FILEPATH "" FORCE) 14 | ``` -------------------------------------------------------------------------------- /cmake/modules/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /cmake/modules/FindJSON-C.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | # JSON-C_FOUND - true if library and headers were found 5 | # JSON-C_INCLUDE_DIRS - include directories 6 | # JSON-C_LIBRARIES - library directories 7 | 8 | find_package (PkgConfig) 9 | pkg_search_module (PC_JSON-C QUIET json-c json) 10 | 11 | find_path (JSON-C_INCLUDE_DIR json.h HINTS ${PC_JSON-C_INCLUDEDIR} 12 | ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json) 13 | 14 | find_library (JSON-C_LIBRARY NAMES json-c libjson-c HINTS ${PC_JSON-C_LIBDIR} 15 | ${PC_JSON-C_LIBRARY_DIRS}) 16 | 17 | set (JSON-C_LIBRARIES ${JSON-C_LIBRARY}) 18 | set (JSON-C_INCLUDE_DIRS ${JSON-C_INCLUDE_DIR}) 19 | 20 | include (FindPackageHandleStandardArgs) 21 | 22 | find_package_handle_standard_args (JSON-C DEFAULT_MSG JSON-C_LIBRARY JSON-C_INCLUDE_DIR) 23 | 24 | mark_as_advanced (JSON-C_INCLUDE_DIR JSON-C_LIBRARY) 25 | -------------------------------------------------------------------------------- /cmake/modules/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | find_program (SPHINX_EXECUTABLE NAMES sphinx-build 5 | HINTS 6 | $ENV{SPHINX_DIR} 7 | PATH_SUFFIXES bin 8 | DOC "Sphinx documentation generator" 9 | ) 10 | 11 | include (FindPackageHandleStandardArgs) 12 | 13 | find_package_handle_standard_args (Sphinx DEFAULT_MSG 14 | SPHINX_EXECUTABLE 15 | ) 16 | 17 | # Get Sphinx Version 18 | if (SPHINX_EXECUTABLE) 19 | execute_process(COMMAND ${SPHINX_EXECUTABLE} --version 20 | OUTPUT_VARIABLE SPHINX_VERSION_STRING 21 | OUTPUT_STRIP_TRAILING_WHITESPACE 22 | ERROR_STRIP_TRAILING_WHITESPACE) 23 | if (SPHINX_VERSION_STRING) 24 | string(REPLACE "Sphinx (sphinx-build) " "" SPHINX_VERSION ${SPHINX_VERSION_STRING}) 25 | message (STATUS "Sphinx version is ${SPHINX_VERSION}") 26 | endif () 27 | endif () 28 | 29 | mark_as_advanced (SPHINX_EXECUTABLE) 30 | -------------------------------------------------------------------------------- /cmake/modules/FindUDEV.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | # UDEV_FOUND - true if library and headers were found 5 | # UDEV_INCLUDE_DIRS - include directories 6 | # UDEV_LIBRARIES - library directories 7 | 8 | find_package (PkgConfig) 9 | pkg_check_modules (PC_UDEV QUIET udev) 10 | 11 | find_path (UDEV_INCLUDE_DIR libudev.h HINTS ${PC_UDEV_INCLUDEDIR} 12 | ${PC_UDEV_INCLUDE_DIRS} PATH_SUFFIXES udev) 13 | 14 | find_library (UDEV_LIBRARY NAMES udev libudev HINTS ${PC_UDEV_LIBDIR} 15 | ${PC_UDEV_LIBRARY_DIRS}) 16 | 17 | set (UDEV_LIBRARIES ${UDEV_LIBRARY}) 18 | set (UDEV_INCLUDE_DIRS ${UDEV_INCLUDE_DIR}) 19 | 20 | include (FindPackageHandleStandardArgs) 21 | 22 | find_package_handle_standard_args (UDEV DEFAULT_MSG UDEV_LIBRARY UDEV_INCLUDE_DIR) 23 | 24 | mark_as_advanced (UDEV_INCLUDE_DIR UDEV_LIBRARY) 25 | -------------------------------------------------------------------------------- /cmake/modules/FindYuidoc.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | find_program (YUIDOC_EXECUTABLE NAMES yuidoc 5 | HINTS $ENV{YUIDOC_DIR} 6 | PATHS usr usr/local 7 | PATH_SUFFIXES bin 8 | DOC "Yuidoc documentation generator" 9 | ) 10 | 11 | include (FindPackageHandleStandardArgs) 12 | 13 | find_package_handle_standard_args (Yuidoc DEFAULT_MSG 14 | YUIDOC_EXECUTABLE 15 | ) 16 | 17 | # Get Yuidoc version 18 | if (YUIDOC_EXECUTABLE) 19 | execute_process(COMMAND ${YUIDOC_EXECUTABLE} --version 20 | ERROR_VARIABLE YUIDOC_VERSION 21 | OUTPUT_STRIP_TRAILING_WHITESPACE 22 | ERROR_STRIP_TRAILING_WHITESPACE) 23 | if (YUIDOC_VERSION) 24 | message (STATUS "Yuidoc version is ${YUIDOC_VERSION}") 25 | endif () 26 | endif () 27 | 28 | mark_as_advanced (YUIDOC_EXECUTABLE) 29 | -------------------------------------------------------------------------------- /cmake/modules/GetGitRevisionDescription.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Internal file for GetGitRevisionDescription.cmake 3 | # 4 | # Requires CMake 2.6 or newer (uses the 'function' command) 5 | # 6 | # Original Author: 7 | # 2009-2010 Ryan Pavlik 8 | # http://academic.cleardefinition.com 9 | # Iowa State University HCI Graduate Program/VRAC 10 | # 11 | # Copyright Iowa State University 2009-2010. 12 | # Distributed under the Boost Software License, Version 1.0. 13 | # (See accompanying file LICENSE_1_0.txt or copy at 14 | # http://www.boost.org/LICENSE_1_0.txt) 15 | # 16 | # SPDX-License-Identifier: BSL-1.0 17 | 18 | set(HEAD_HASH) 19 | 20 | file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) 21 | 22 | string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) 23 | if(HEAD_CONTENTS MATCHES "ref") 24 | # named branch 25 | string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") 26 | if(EXISTS "@GIT_DIR@/${HEAD_REF}") 27 | configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 28 | elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") 29 | configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 30 | set(HEAD_HASH "${HEAD_REF}") 31 | endif() 32 | else() 33 | # detached HEAD 34 | configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) 35 | endif() 36 | 37 | if(NOT HEAD_HASH) 38 | file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) 39 | string(STRIP "${HEAD_HASH}" HEAD_HASH) 40 | endif() 41 | -------------------------------------------------------------------------------- /cmake/modules/LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /cmake/modules/version.c.in: -------------------------------------------------------------------------------- 1 | // Auto-Generated file 2 | #include "version.h" 3 | 4 | const char* gVERSION = "@VERSION@"; 5 | const char* gVERSION_SHORT = "@VERSION_SHORT@"; 6 | -------------------------------------------------------------------------------- /docs/debugging.md: -------------------------------------------------------------------------------- 1 | Debugging libmraa {#debugging} 2 | ================= 3 | 4 | This page contains a few debugging tip. When filing an issue please go through 5 | this list as it's the first thing we'll ask you to do. 6 | 7 | ### Finding your mraa version 8 | 9 | Getting the exact version of libmraa you're running is really important to us. 10 | The best way to get this is to call mraa_get_version() or mraa.getVersion(). If 11 | you built from git then please tell us which commit hash you used. Mraa no 12 | longer tags itself as 'dirty' if built as a non tagged version but simply uses 13 | the latest version number listed in the top level CMakeLists.txt file. Note 14 | that you may have to wipe the build/ dir for git sha version to be absolutely 15 | correct. 16 | 17 | ### Finding error logs 18 | 19 | mraa logs pretty much everything that goes wrong to syslog. These days it'll go 20 | to the systemd journal so check with `sudo journalctl -f` whilst running your 21 | app or check all libmraa messages with `journalctl -t libmraa`. Grab all the 22 | messages from the initialisation message right up to your last one. Using a 23 | pastebin is always a good idea, I like dpaste.com. If your system does not have 24 | systemd likely your log is in /var/log/messages or a similar location. 25 | 26 | ### Common errors to check for 27 | 28 | * Not running as a user with permissions to the physical char devices/files 29 | that require access. Check quickly if it works as root and you likely have 30 | such an issue. The log file will reflect this 31 | * Incorrect IO pin numbers, mraa uses physical connector pin numbering see your 32 | platform documentation for details 33 | * Your platform is unsupported or has been detected wrongly (logfile will show this) 34 | * Using the wrong pin, check pin capabilities either using the API or your 35 | platform documentation 36 | 37 | -------------------------------------------------------------------------------- /docs/firmata.md: -------------------------------------------------------------------------------- 1 | Using Firmata board with mraa {#firmata} 2 | ============================= 3 | 4 | Mraa can use a Firmata board as a subplatform. This means one can access the 5 | native IO as well as the IO on a firmata compatible board 6 | 7 | ### Supported Firmata boards ### 8 | 9 | - Genuino/Arduino 101 running either CustomFirmata or StandardFirmata 10 | - Other Arduino boards will likely work but are as of yet unsuported 11 | 12 | ### Using the subplatform API ### 13 | 14 | Using the subplatform API is relatively simple, simply add '512', the platform 15 | offset to any IO calls. I2c 0 becomes I2c 512+0 etc... The API works from UPM 16 | or mraa in any of the bindings as long as you compiled mraa with -DFIRMATA=ON. 17 | Currently -DFIRMATA is not compatible with USBPLAT. Multiple subplatforms are 18 | not yet supported 19 | 20 | ### Sending custom SYSSEX messages ### 21 | 22 | You can use the firmata API to send custom SYSEX messages. 23 | 24 | ### CurieImu Plugin ### 25 | 26 | Using Customisable firmata we're able to use the onboard IMU to get data. This 27 | uses the public SYSEX firmata API from mraa and there is a UPM module that 28 | exposes this capability in a simple way. To use it your board needs to use 29 | CustomFirmata with the CurieIMU plugin 30 | 31 | ### Limitations ### 32 | 33 | Only one instance of mraa (one process linking to mraa) can communicate to an 34 | firmata subplatform. This is a limitation due to only having one application 35 | using the Uart at once. In order to get around this a daemon type methodology 36 | has to be used. Technically you can mirror the TTY port from firmata but this 37 | is likely going to cause issues 38 | -------------------------------------------------------------------------------- /docs/galileorevd.md: -------------------------------------------------------------------------------- 1 | Galileo Gen 1 - Rev D {#galileorevd} 2 | ===================== 3 | 4 | Galileo is a microcontroller board based on the Intel(R) Quark(TM) SoC X1000 5 | Application Processor, a 32-bit Intel Pentium-class system on a chip. 6 | 7 | The rev D board has the following limitations in libmraa: 8 | 9 | - gpio 13 will not switch the LED as it's a different Gpio, use raw gpio '3' to do this 10 | - gpio register access via /dev/uio is limited to pin2 and 3 11 | - gpio interrupts will only work on GPIO_EDGE_BOTH 12 | - adc kernel module will return 12bit number. MRAA defaults shift this to 10bits 13 | - AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything 14 | else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio 15 | -------------------------------------------------------------------------------- /docs/grossetete.md: -------------------------------------------------------------------------------- 1 | Grosstete {#grossetete} 2 | ========= 3 | 4 | You probably meant to go here: @ref joule. 5 | 6 | Note: This page will be deleted in the future, don't link to it! 7 | -------------------------------------------------------------------------------- /docs/i2c.txt: -------------------------------------------------------------------------------- 1 | It is considered best practice to make sure the address is correct before doing 2 | any calls on i2c, in case another application or even thread changed the addres 3 | on that bus. Multiple instances of the same bus can exist. 4 | -------------------------------------------------------------------------------- /docs/iei-tank.md: -------------------------------------------------------------------------------- 1 | IEI TANK AIoT Dev. Kit {#iei-tank} 2 | ================================ 3 | TANK AIoT Dev. Kit features rich I/O and dual PCIe by 16 slots with by 8 signal 4 | for add-on card installation such as PoE (IPCEI-4POE) card or acceleration card 5 | (Mustang-F100-A10 & Mustang-V100-RX8) to enhance function and performance for 6 | various applications. 7 | 8 | For the full specifications please visit the product page: 9 | 10 | https://www.ieiworld.com/tank-aiot-development-kit 11 | 12 | Interface notes 13 | ----------------------- 14 | The MRAA platform file was developed using an IEI TANK-870-Q170 and may not 15 | be compatible with other TANK systems. 6 serial ports and 8 digital pins are 16 | available and can be controlled using MRAA on this system. 17 | 18 | **UART** 19 | * 4 x RS-232 (2 x RJ-45, 2 x DB-9 w/2.5KV isolation protection) 20 | * 2 x RS-232/422/485 (DB-9) 21 | 22 | **GPIO** 23 | * 8-bit digital I/O , 4-bit input / 4-bit output (DB9) 24 | 25 | Pin Mapping 26 | -------------------- 27 | The GPIO numbering in MRAA is explained in the table below. To use the pins 28 | the *gpio_f7188x* Linux kernel module must be available and loaded. 29 | 30 | | MRAA Pin | DB9 Pin | Sysfs GPIO | Function | 31 | |----------|--------------|------------|-----------------| 32 | | 0 | 1 | 4 | DIN0 | 33 | | 1 | 2 | 0 | DOUT0 | 34 | | 2 | 3 | 11 | DIN1 | 35 | | 3 | 4 | 1 | DOUT1 | 36 | | 4 | 5 | 12 | DIN2 | 37 | | 5 | 6 | 2 | DOUT2 | 38 | | 6 | 7 | 13 | DIN3 | 39 | | 7 | 8 | 3 | DOUT3 | 40 | | 8 | 9 | | +5V | 41 | -------------------------------------------------------------------------------- /docs/iio.md: -------------------------------------------------------------------------------- 1 | iio {#iio} 2 | === 3 | IIO is the kernel's framework for supporting sensors. 4 | ## Using dummy_iio driver 5 | For platforms without IIO hardware the iio_dummy driver can be used. You can 6 | add the driver by either rebuilding the kernel with IIO component enabled or 7 | just building the IIO modules and load them. You must add the following config 8 | fragment. Known to work for kernel 3.19 and later. 9 |

10 | CONFIG_IIO_DUMMY_EVGEN=m
11 | CONFIG_IIO_SIMPLE_DUMMY=m
12 | CONFIG_IIO_SIMPLE_DUMMY_EVENTS=y
13 | CONFIG_IIO_SIMPLE_DUMMY_BUFFER=y
14 | 
15 | ### Add driver to kernel 16 | Boot with new kernel, then load modules 17 |

18 | $ modprobe iio_dummy
19 | $ modprobe iio_dummy_evgen
20 | 
21 | ### Load kernel modules 22 | Depending our your kernel config, some of these modules may already be loaded. 23 |

24 | $ insmod drivers/iio/industrialio.ko
25 | $ insmod drivers/iio/kfifo_buf.ko
26 | $ insmod drivers/staging/iio/iio_dummy_evgen.ko
27 | $ insmod drivers/staging/iio/iio_dummy.ko
28 | 
29 | ## 'RAW' access 30 | 31 | Mraa supports raw access 32 | 33 | ###Channels 34 | 35 | ###Attributes 36 | 37 | ###Events 38 | 39 | ###Triggers 40 | 41 | Activate the trigger in /sys/class/iio 42 | $ echo 1 > trigger0/trigger_now 43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/platform-hooks.md: -------------------------------------------------------------------------------- 1 | platform-hooks {#hooks} 2 | ============== 3 | 4 | Hooks can be defined per supported platform to allow for highly custom 5 | operations if needed. This feature of MRAA should only be used by developers 6 | defining the board definitions, NOT an end user. 7 | 8 | ##Types of Hooks 9 | 10 | ###REPLACE 11 | Defining a replace function will entirely replace the associate function. This 12 | should only be done if your new function can handle everything the mraa 13 | function would normally. 14 | 15 | ###PRE 16 | Any functionality defined here will be performed when the main function is 17 | called. 18 | 19 | ###POST 20 | Any functionality perfomed here is done just before the normal function 21 | returns. All post functions will have passed into them the return value that 22 | would normally be returned. 23 | 24 | ##Hooks 25 | ### GPIO 26 | * init (pre-post) 27 | * mode (replace-pre-post) 28 | * dir (replace-pre-post) 29 | * write (pre-post) 30 | * use-mmaped (replace-pre-post) 31 | 32 | ### I2C 33 | * init (pre-post) - On RAW 34 | -------------------------------------------------------------------------------- /docs/radxa_zero3.md: -------------------------------------------------------------------------------- 1 | Radxa ZERO 3 {#_Radxa} 2 | ===================== 3 | 4 | Radxa ZERO 3 is an ultra-small, versatile platform that can be used for a wide variety of applications, including IoT devices, machine learning edge computing, home automation, education, and entertainment. 5 | 6 | The ZERO 3W and ZERO 3E differ only in storage and network interfaces. 7 | 8 | Pin Mapping 9 | ----------- 10 | 11 | The Radxa ZERO 3's GPIO pinout is compatible with the [Radxa ROCK 3C](./radxa_rock_3c.md). 12 | 13 | Supports 14 | -------- 15 | 16 | You can find additional product support in the following channels: 17 | 18 | - [Product Info](https://docs.radxa.com/en/zero/zero3) 19 | - [Forums](https://forum.radxa.com/c/rock3) 20 | - [Github](https://github.com/radxa) 21 | -------------------------------------------------------------------------------- /docs/testing.md: -------------------------------------------------------------------------------- 1 | # Testing mraa 2 | 3 | Mraa has a test suite written in python which can be run by users to check 4 | their platform is working correctly. The aim is to have a full API coverage 5 | using python scripts using unittests. Currently the test suite is far from 6 | complete. 7 | 8 | ## Supported platforms 9 | 10 | Intel Galileo v1 was used and is currently the only supported platform. Tests 11 | were conducted on Intel Galileo v2, but because of hardware differences, some 12 | failures may occur. Logic will be added to auto-select board to work on. To 13 | start with boards with an arduino type shield/layout should work 14 | 15 | ## How to run these tests 16 | 17 | You need to compile from source with -DBUILDSWIGPYTHON=ON and then tests can be 18 | executed with: 19 | $ make test 20 | 21 | More detail can be seen by running: 22 | $ ctest -VV 23 | 24 | Note tests will not run on platforms which cannot initialise, checking the 25 | amount of 'skipped' tests can be useful 26 | 27 | ## What's next? 28 | 29 | At this point tests were made to do a quick sanity check. In the future the 30 | followings will be implemented: 31 | * Create a physical layer that will emulate sensors behavior and generate I/O 32 | signals. This layer will be available to the community and will help replace 33 | the need of specific sensors. The simplest solution will be chosen allowing 34 | anyone to rapidly implement it. 35 | * Implement stress tests over long periods of time. This feature alone is 36 | possible only with the use of a physical layer since it will behave both as 37 | signals generator and interpreter. 38 | * Analyze a tests result collection solution (and after, interpretation). This 39 | is useful since tests mean nothing without a history and possibility to 40 | check on results. 41 | * Any idea welcome! 42 | 43 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (c) 2 | add_subdirectory (platform) 3 | 4 | if (NOT ANDROID_TOOLCHAIN) 5 | add_subdirectory (c++) 6 | endif () 7 | 8 | install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples/ DESTINATION ${CMAKE_INSTALL_DATADIR}/mraa/examples) 9 | -------------------------------------------------------------------------------- /examples/c++/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_language(CXX) 2 | 3 | add_executable (aio_cpp aio.cpp) 4 | add_executable (gpio_advanced_cpp gpio_advanced.cpp) 5 | add_executable (gpio_cpp gpio.cpp) 6 | add_executable (pwm_cpp pwm.cpp) 7 | add_executable (i2c_cpp i2c.cpp) 8 | add_executable (spi_cpp spi.cpp) 9 | add_executable (uart_cpp uart.cpp) 10 | add_executable (iio_cpp iio.cpp) 11 | add_executable (led_cpp led.cpp) 12 | 13 | include_directories(${PROJECT_SOURCE_DIR}/api) 14 | include_directories(${PROJECT_SOURCE_DIR}/api/mraa) 15 | 16 | target_link_libraries (aio_cpp mraa stdc++) 17 | target_link_libraries (gpio_advanced_cpp mraa stdc++) 18 | target_link_libraries (gpio_cpp mraa stdc++) 19 | target_link_libraries (pwm_cpp mraa stdc++) 20 | target_link_libraries (i2c_cpp mraa stdc++ m) 21 | target_link_libraries (spi_cpp mraa stdc++) 22 | target_link_libraries (uart_cpp mraa stdc++) 23 | target_link_libraries (iio_cpp mraa stdc++) 24 | target_link_libraries (led_cpp mraa stdc++) 25 | 26 | if (ONEWIRE) 27 | add_executable (uart_ow_cpp uart_ow.cpp) 28 | target_link_libraries (uart_ow_cpp mraa stdc++) 29 | endif () 30 | -------------------------------------------------------------------------------- /examples/c++/aio.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Contributors: Alex Tereschenko 4 | * Contributors: Manivannan Sadhasivam 5 | * Copyright (c) 2014 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | * 9 | * Example usage: Reads ADC A0 value continuously. Press Ctrl+C to exit. 10 | */ 11 | 12 | /* standard headers */ 13 | #include 14 | #include 15 | #include 16 | 17 | /* mraa headers */ 18 | #include "mraa/aio.hpp" 19 | #include "mraa/common.hpp" 20 | 21 | /* AIO port */ 22 | #define AIO_PORT 0 23 | 24 | volatile sig_atomic_t flag = 1; 25 | 26 | void 27 | sig_handler(int signum) 28 | { 29 | if (signum == SIGINT) { 30 | std::cout << "Exiting..." << std::endl; 31 | flag = 0; 32 | } 33 | } 34 | 35 | int 36 | main(void) 37 | { 38 | uint16_t value; 39 | float float_value; 40 | 41 | signal(SIGINT, sig_handler); 42 | 43 | //! [Interesting] 44 | /* initialize AIO */ 45 | mraa::Aio aio(AIO_PORT); 46 | 47 | while (flag) { 48 | value = aio.read(); 49 | float_value = aio.readFloat(); 50 | std::cout << "ADC A0 read %X - %d" << value << value << std::endl; 51 | std::cout << "ADC A0 read float - %.5f" << float_value << std::endl; 52 | } 53 | //! [Interesting] 54 | 55 | return EXIT_SUCCESS; 56 | } 57 | -------------------------------------------------------------------------------- /examples/c++/gpio_advanced.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Manivannan Sadhasivam 3 | * Copyright (c) 2018 Linaro Ltd. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Example usage: Configures GPIO pin for interrupt and waits 30 seconds for the isr to trigger 8 | * 9 | */ 10 | 11 | /* standard headers */ 12 | #include 13 | #include 14 | #include 15 | 16 | /* mraa headers */ 17 | #include "mraa/common.hpp" 18 | #include "mraa/gpio.hpp" 19 | 20 | #define GPIO_PIN 6 21 | 22 | void 23 | int_handler(void* args) 24 | { 25 | std::cout << "ISR triggered" << std::endl; 26 | } 27 | 28 | int 29 | main(void) 30 | { 31 | mraa::Result status; 32 | 33 | //! [Interesting] 34 | /* initialize GPIO */ 35 | mraa::Gpio gpio(GPIO_PIN); 36 | 37 | /* set GPIO to input */ 38 | status = gpio.dir(mraa::DIR_IN); 39 | if (status != mraa::SUCCESS) { 40 | printError(status); 41 | return EXIT_FAILURE; 42 | } 43 | 44 | /* configure ISR for GPIO */ 45 | status = gpio.isr(mraa::EDGE_BOTH, &int_handler, NULL); 46 | if (status != mraa::SUCCESS) { 47 | printError(status); 48 | return EXIT_FAILURE; 49 | } 50 | 51 | /* wait 30 seconds isr trigger */ 52 | sleep(30); 53 | //! [Interesting] 54 | 55 | return EXIT_SUCCESS; 56 | } 57 | -------------------------------------------------------------------------------- /examples/c++/led.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Manivannan Sadhasivam 3 | * Copyright (c) 2018, Linaro Ltd. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Example usage: Reads maximum brightness value for user led and turns it 8 | * on/off depending on current state. Then sets led trigger 9 | * to heartbeat. 10 | * 11 | */ 12 | 13 | /* standard headers */ 14 | #include 15 | #include 16 | #include 17 | 18 | /* mraa headers */ 19 | #include "mraa/common.hpp" 20 | #include "mraa/led.hpp" 21 | 22 | /* LED name */ 23 | #define USER_LED "user1" 24 | 25 | /* trigger type */ 26 | #define LED_TRIGGER "heartbeat" 27 | 28 | int 29 | main(void) 30 | { 31 | mraa::Result status; 32 | int val; 33 | 34 | //! [Interesting] 35 | /* initialize user1 led */ 36 | mraa::Led led(USER_LED); 37 | 38 | /* read maximum brightness */ 39 | val = led.readMaxBrightness(); 40 | std::cout << "maximum brightness value for user1 led is: %d" << val << std::endl; 41 | if (val >= 1) { 42 | val = 0; 43 | } else { 44 | /* never reached mostly */ 45 | val = 1; 46 | } 47 | 48 | /* turn led on/off depending on max_brightness value */ 49 | status = led.setBrightness(val); 50 | if (status != mraa::SUCCESS) { 51 | printError(status); 52 | return EXIT_FAILURE; 53 | } 54 | 55 | /* sleep for 5 seconds */ 56 | usleep(5000000); 57 | 58 | /* set led trigger to heartbeat */ 59 | status = led.trigger(LED_TRIGGER); 60 | if (status != mraa::SUCCESS) { 61 | printError(status); 62 | return EXIT_FAILURE; 63 | } 64 | 65 | std::cout << "led trigger set to: heartbeat" << std::endl; 66 | //! [Interesting] 67 | 68 | return EXIT_SUCCESS; 69 | } 70 | -------------------------------------------------------------------------------- /examples/c++/pwm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Example usage: Generates PWM at a step rate of 0.01 continuously. 8 | * Press Ctrl+C to exit 9 | */ 10 | 11 | /* standard headers */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /* mraa headers */ 18 | #include "mraa/common.hpp" 19 | #include "mraa/pwm.hpp" 20 | 21 | #define PWM_PORT 3 22 | 23 | volatile sig_atomic_t flag = 1; 24 | 25 | void 26 | sig_handler(int signum) 27 | { 28 | if (signum == SIGINT) { 29 | std::cout << "Exiting..." << std::endl; 30 | flag = 0; 31 | } 32 | } 33 | 34 | int 35 | main(void) 36 | { 37 | float value = 0.0f; 38 | 39 | signal(SIGINT, sig_handler); 40 | 41 | //! [Interesting] 42 | mraa::Pwm pwm(PWM_PORT); 43 | std::cout << "Cycling PWM on IO3 (pwm3)" << std::endl; 44 | pwm.enable(true); 45 | 46 | while (flag) { 47 | value = value + 0.01f; 48 | pwm.write(value); 49 | usleep(50000); 50 | if (value >= 1.0f) { 51 | value = 0.0f; 52 | } 53 | } 54 | //! [Interesting] 55 | 56 | return EXIT_SUCCESS; 57 | } 58 | -------------------------------------------------------------------------------- /examples/c++/spi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Contributors: Manivannan Sadhasivam 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | * 8 | * Example usage: Sends data continuously to a Spi device. Press Ctrl+C to exit 9 | * 10 | */ 11 | 12 | /* standard headers */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | /* mraa headers */ 19 | #include "mraa/common.hpp" 20 | #include "mraa/spi.hpp" 21 | 22 | #define SPI_PORT 0 23 | 24 | volatile sig_atomic_t flag = 1; 25 | 26 | void 27 | sig_handler(int signum) 28 | { 29 | if (signum == SIGINT) { 30 | std::cout << "Exiting..." << std::endl; 31 | flag = 0; 32 | } 33 | } 34 | 35 | int 36 | main(void) 37 | { 38 | uint8_t data[] = { 0x00, 100 }; 39 | uint8_t rxBuf[2]; 40 | uint8_t* recv; 41 | int i; 42 | 43 | signal(SIGINT, sig_handler); 44 | 45 | //! [Interesting] 46 | mraa::Spi spi(SPI_PORT); 47 | 48 | while (flag) { 49 | for (i = 90; i < 130; i++) { 50 | data[1] = i; 51 | recv = spi.write(data, 2); 52 | std::cout << "Writing -%i" << i << std::endl; 53 | if (recv) { 54 | std::cout << "RECIVED-%i-%i" << recv[0] << recv[1] << std::endl; 55 | free(recv); 56 | } 57 | usleep(100000); 58 | } 59 | 60 | for (i = 130; i > 90; i--) { 61 | data[1] = i; 62 | if (spi.transfer(data, rxBuf, 2) == mraa::SUCCESS) { 63 | std::cout << "Writing -%i" << i << std::endl; 64 | std::cout << "RECIVED-%i-%i" << rxBuf[0] << rxBuf[1] << std::endl; 65 | } 66 | usleep(100000); 67 | } 68 | } 69 | //! [Interesting] 70 | 71 | return EXIT_SUCCESS; 72 | } 73 | -------------------------------------------------------------------------------- /examples/c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(aio aio.c) 2 | add_executable(gpio gpio.c) 3 | add_executable(gpio_advanced gpio_advanced.c) 4 | add_executable(hellomraa hellomraa.c) 5 | add_executable(i2c_hmc5883l i2c_hmc5883l.c) 6 | add_executable(i2c_mpu6050 i2c_mpu6050.c) 7 | add_executable(led led.c) 8 | add_executable(pwm pwm.c) 9 | add_executable(spi spi.c) 10 | add_executable(uart uart.c) 11 | add_executable(uart_advanced uart_advanced.c) 12 | if (NOT ANDROID_TOOLCHAIN) 13 | add_executable(iio iio.c) 14 | endif() 15 | 16 | include_directories(${PROJECT_SOURCE_DIR}/api) 17 | include_directories(${PROJECT_SOURCE_DIR}/api/mraa) 18 | 19 | target_link_libraries(aio mraa) 20 | target_link_libraries(gpio mraa) 21 | target_link_libraries(gpio_advanced mraa) 22 | target_link_libraries(hellomraa mraa) 23 | target_link_libraries(i2c_hmc5883l mraa m) 24 | target_link_libraries(i2c_mpu6050 mraa) 25 | target_link_libraries(led mraa) 26 | target_link_libraries(pwm mraa) 27 | target_link_libraries(spi mraa) 28 | target_link_libraries(uart mraa) 29 | target_link_libraries(uart_advanced mraa) 30 | if (NOT ANDROID_TOOLCHAIN) 31 | target_link_libraries(iio mraa) 32 | endif() 33 | if (ONEWIRE) 34 | add_executable (uart_ow uart_ow.c) 35 | target_link_libraries (uart_ow mraa) 36 | endif () 37 | -------------------------------------------------------------------------------- /examples/c/hellomraa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | //! [Interesting] 12 | #include "mraa.h" 13 | 14 | int 15 | main(int argc, char** argv) 16 | { 17 | const char* board_name = mraa_get_platform_name(); 18 | fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name); 19 | 20 | mraa_deinit(); 21 | 22 | return MRAA_SUCCESS; 23 | } 24 | //! [Interesting] 25 | -------------------------------------------------------------------------------- /examples/c/initio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Stefanescu 3 | * Copyright (c) 2018 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | 10 | #include "mraa/initio.h" 11 | 12 | int 13 | main() 14 | { 15 | printf("Starting example\n"); 16 | 17 | mraa_io_descriptor* desc; 18 | if (mraa_io_init("g:3:1-upm_stuff", &desc) != MRAA_SUCCESS) { 19 | printf("Error in mraa_io_init()\n"); 20 | } 21 | 22 | printf("Leftover string = %s\n", desc->leftover_str); 23 | 24 | /* Check value set in mraa_io_init. */ 25 | printf("Gpio value = %d\n", mraa_gpio_read(desc->gpios[0])); 26 | 27 | if (mraa_io_close(desc) != MRAA_SUCCESS) { 28 | printf("failed to close mraa io descriptor\n"); 29 | } 30 | 31 | printf("Done\n"); 32 | } -------------------------------------------------------------------------------- /examples/c/uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Brendan Le Foll 4 | * Contributors: Manivannan Sadhasivam 5 | * Copyright (c) 2014, 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | * 9 | * Example usage: Prints "Hello Mraa!" recursively. Press Ctrl+C to exit 10 | * 11 | */ 12 | 13 | /* standard headers */ 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* mraa header */ 20 | #include "mraa/uart.h" 21 | 22 | #define UART 0 23 | 24 | volatile sig_atomic_t flag = 1; 25 | 26 | void 27 | sig_handler(int signum) 28 | { 29 | if (signum == SIGINT) { 30 | fprintf(stdout, "Exiting...\n"); 31 | flag = 0; 32 | } 33 | } 34 | 35 | int 36 | main(int argc, char** argv) 37 | { 38 | mraa_uart_context uart; 39 | char buffer[] = "Hello Mraa!"; 40 | 41 | /* install signal handler */ 42 | signal(SIGINT, sig_handler); 43 | 44 | /* initialize mraa for the platform (not needed most of the times) */ 45 | mraa_init(); 46 | 47 | //! [Interesting] 48 | /* initialize UART */ 49 | uart = mraa_uart_init(UART); 50 | if (uart == NULL) { 51 | fprintf(stderr, "Failed to initialize UART\n"); 52 | goto err_exit; 53 | } 54 | 55 | while (flag) { 56 | /* send data through UART */ 57 | mraa_uart_write(uart, buffer, sizeof(buffer)); 58 | 59 | sleep(1); 60 | } 61 | 62 | /* stop UART */ 63 | mraa_uart_stop(uart); 64 | 65 | //! [Interesting] 66 | /* deinitialize mraa for the platform (not needed most of the times) */ 67 | mraa_deinit(); 68 | 69 | return EXIT_SUCCESS; 70 | 71 | err_exit: 72 | /* deinitialize mraa for the platform (not needed most of the times) */ 73 | mraa_deinit(); 74 | 75 | return EXIT_FAILURE; 76 | } 77 | -------------------------------------------------------------------------------- /examples/java/AioA0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nandkishor Sonar 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Petre Eftime 5 | * Copyright (c) 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | 11 | //! [Interesting] 12 | import mraa.Aio; 13 | 14 | public class AioA0 { 15 | 16 | static { 17 | try { 18 | System.loadLibrary("mraajava"); 19 | } catch (UnsatisfiedLinkError e) { 20 | System.err.println( 21 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 22 | e); 23 | System.exit(1); 24 | } 25 | } 26 | 27 | public static void main(String[] args) { 28 | Aio a0 = new Aio(0); 29 | 30 | for (int i = 100; i > 0; --i) { 31 | int adc_value = a0.read(); 32 | float adc_value_float = a0.readFloat(); 33 | System.out.println(String.format("ADC A0 read %X - %d", adc_value, adc_value)); 34 | System.out.println(String.format("ADC A0 read %.5f", adc_value_float)); 35 | Thread.sleep(500); 36 | } 37 | 38 | } 39 | } 40 | //! [Interesting] 41 | -------------------------------------------------------------------------------- /examples/java/BlinkIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Author: Thomas Ingleby 4 | * Copyright (c) 2014 Intel Corporation. 5 | * Author: Petre Eftime 6 | * Copyright (c) 2015 Intel Corporation. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | 12 | import mraa.Dir; 13 | import mraa.Gpio; 14 | import mraa.Result; 15 | import mraa.mraa; 16 | 17 | public class BlinkIO { 18 | static { 19 | try { 20 | System.loadLibrary("mraajava"); 21 | } catch (UnsatisfiedLinkError e) { 22 | System.err.println( 23 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 24 | e); 25 | System.exit(1); 26 | } 27 | } 28 | 29 | final static int DEFAULT_IOPIN = 8; 30 | 31 | public static void main(String argv[]) throws InterruptedException { 32 | int iopin = DEFAULT_IOPIN; 33 | if (argv.length == 0) { 34 | System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN); 35 | } else { 36 | iopin = Integer.valueOf(argv[0]); 37 | } 38 | 39 | //! [Interesting] 40 | Gpio gpio = new Gpio(iopin); 41 | Result result = gpio.dir(Dir.DIR_OUT); 42 | if (result != Result.SUCCESS) { 43 | mraa.printError(result); 44 | System.exit(1); 45 | } 46 | 47 | for (int i = 100; i > 0; --i) { 48 | gpio.write(1); 49 | Thread.sleep(1000); 50 | gpio.write(0); 51 | Thread.sleep(1000); 52 | } 53 | //! [Interesting] 54 | } 55 | } -------------------------------------------------------------------------------- /examples/java/Bmp85.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alexander Komarov 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | public class Bmp85 { 9 | static { 10 | try { 11 | System.loadLibrary("mraajava"); 12 | } catch (UnsatisfiedLinkError e) { 13 | System.err.println( 14 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 15 | e); 16 | System.exit(1); 17 | } 18 | } 19 | public static void main(String argv[]) { 20 | mraa.mraa.init(); 21 | System.out.println(mraa.mraa.getVersion()); 22 | 23 | // helper function to go from hex val to dec 24 | // function char(x) { return parseInt(x, 16); } 25 | 26 | mraa.I2c i2c = new mraa.I2c(0); 27 | i2c.address((byte)0x77); 28 | i2c.writeByte((byte)0xd0); 29 | /* 30 | SWIGTYPE_p_unsigned_char data0 = new SWIGTYPE_p_unsigned_char();*/ 31 | byte[] data = new byte[1]; 32 | i2c.read(data); 33 | System.out.println((new Integer(data[0])).toString()); 34 | 35 | i2c.writeReg((byte)0xf4, (byte)0x2e); 36 | // initialise device 37 | if (i2c.readReg((byte)0xd0) != 0x55) { 38 | System.out.println("error"); 39 | } 40 | 41 | // we want to read temperature so write 0x2e into control reg 42 | i2c.writeReg((byte)0xf4, (byte)0x2e); 43 | 44 | // read a 16bit reg, obviously it's uncalibrated so mostly a useless value 45 | // :) 46 | System.out.println(i2c.readWordReg((byte)0xf6)); 47 | 48 | byte[] buf = new byte[2]; 49 | buf[0] = (byte)0xf4; 50 | buf[1] = (byte)0x2e; 51 | i2c.write(buf); 52 | 53 | i2c.writeByte((byte)0xf6); 54 | int d = i2c.readReg((byte)2); 55 | System.out.println((new Integer(d)).toString()); 56 | }; 57 | } 58 | ; 59 | -------------------------------------------------------------------------------- /examples/java/CyclePwm3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Jakub Kramarz 5 | * Copyright (c) 2015 VirtusLab 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | import mraa.Pwm; 11 | 12 | public class CyclePwm3 { 13 | static { 14 | try { 15 | System.loadLibrary("mraajava"); 16 | } catch (UnsatisfiedLinkError e) { 17 | System.err.println( 18 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 19 | e); 20 | System.exit(1); 21 | } 22 | } 23 | public static void main(String argv[]) throws InterruptedException { 24 | //! [Interesting] 25 | Pwm pwm = new mraa.Pwm(3); 26 | pwm.period_us(200); 27 | pwm.enable(true); 28 | 29 | float value = 0; 30 | for (int i = 100; i > 0; --i) { 31 | value += 0.01; 32 | pwm.write(value); 33 | Thread.sleep(50); 34 | if (value >= 1) { 35 | value = 0; 36 | } 37 | } 38 | //! [Interesting] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/java/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Petre Eftime 5 | * Copyright (c) 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | //! [Interesting] 11 | import mraa.mraa; 12 | 13 | public class Example { 14 | static { 15 | try { 16 | System.loadLibrary("mraajava"); 17 | } catch (UnsatisfiedLinkError e) { 18 | System.err.println( 19 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 20 | e); 21 | System.exit(1); 22 | } 23 | } 24 | public static void main(String argv[]) { 25 | String board = mraa.getPlatformName(); 26 | String version = mraa.getVersion(); 27 | System.out.println("hello mraa"); 28 | System.out.println(String.format("Version: %s", version)); 29 | System.out.println(String.format("Running on %s", board)); 30 | }; 31 | } 32 | //! [Interesting] 33 | -------------------------------------------------------------------------------- /examples/java/FTDITest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Petre Eftime 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | import mraa.*; 9 | 10 | public class FTDITest { 11 | 12 | public static void main(String[] args) throws InterruptedException { 13 | String board = mraa.getPlatformName(); 14 | String version = mraa.getVersion(); 15 | 16 | System.out.println(String.format("Version: %s", version)); 17 | System.out.println(String.format("Running on %s", board)); 18 | 19 | if (mraa.hasSubPlatform()) { 20 | System.out.println("Subplatform detected"); 21 | 22 | /* Print when button is pressed */ 23 | Gpio button = new Gpio(515); 24 | button.dir(Dir.DIR_IN); 25 | button.isr(Edge.EDGE_FALLING, new Runnable() { 26 | 27 | @Override 28 | public void run() { 29 | System.out.println("Button pressed"); 30 | } 31 | }); 32 | 33 | /* Blink FTDI board LED */ 34 | Gpio led = new Gpio(514); 35 | led.dir(Dir.DIR_OUT); 36 | for (int i = 100; i > 0; --i) { 37 | led.write(i % 2); 38 | Thread.sleep(500); 39 | } 40 | } else { 41 | System.out.println("Subplatform not detected"); 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /examples/java/GpioMmapped.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Petre Eftime 5 | * Copyright (c) 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | import mraa.Gpio; 11 | import mraa.mraa; 12 | 13 | public class GpioMmapped { 14 | static { 15 | try { 16 | System.loadLibrary("mraajava"); 17 | } catch (UnsatisfiedLinkError e) { 18 | System.err.println( 19 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 20 | e); 21 | System.exit(1); 22 | } 23 | } 24 | public static void main(String argv[]) throws InterruptedException { 25 | //! [Interesting] 26 | String board = mraa.getPlatformName(); 27 | String version = mraa.getVersion(); 28 | System.out.println("hello mraa"); 29 | System.out.println(String.format("Version: %s", version)); 30 | System.out.println(String.format("Platform: %s", board)); 31 | 32 | Gpio gpio = new Gpio(1); 33 | 34 | gpio.useMmap(true); 35 | 36 | for (int i = 1000; i > 0; --i) { 37 | gpio.write(1); 38 | Thread.sleep(50); 39 | gpio.write(0); 40 | Thread.sleep(50); 41 | } 42 | //! [Interesting] 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /examples/java/GpioRead6.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Jakub Kramarz 5 | * Copyright (c) 2015 VirtusLab 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | import mraa.Dir; 11 | import mraa.Gpio; 12 | import mraa.mraa; 13 | 14 | public class GpioRead6 { 15 | static { 16 | try { 17 | System.loadLibrary("mraajava"); 18 | } catch (UnsatisfiedLinkError e) { 19 | System.err.println( 20 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 21 | e); 22 | System.exit(1); 23 | } 24 | } 25 | public static void main(String argv[]) throws InterruptedException { 26 | System.out.println(String.format("MRAA Version: %s\nStarting Read on IO6\n", mraa.getVersion())); 27 | //! [Interesting] 28 | Gpio gpio = new Gpio(6); 29 | 30 | gpio.dir(Dir.DIR_IN); 31 | 32 | for (int i = 100; i > 0; --i) { 33 | System.out.format("Gpio is %d\n", gpio.read()); 34 | Thread.sleep(1000); 35 | } 36 | //! [Interesting] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/java/SpiMCP4261.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alexander Komarov 3 | * Copyright (c) 2014 Intel Corporation. 4 | * Author: Petre Eftime 5 | * Copyright (c) 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | import mraa.Spi; 11 | 12 | public class SpiMCP4261 { 13 | static { 14 | try { 15 | System.loadLibrary("mraajava"); 16 | } catch (UnsatisfiedLinkError e) { 17 | System.err.println( 18 | "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 19 | e); 20 | System.exit(1); 21 | } 22 | } 23 | public static void main(String argv[]) throws InterruptedException { 24 | //! [Interesting] 25 | Spi spi = new Spi(0); 26 | 27 | System.out.println("Hello, SPI initialised"); 28 | byte data[] = {0x00, 100}; 29 | for (int cnt = 100; cnt > 0; --cnt) { 30 | for (int i = 90; i < 130; i++) { 31 | data[1] = (byte) i; 32 | byte[] recv = spi.write(data); 33 | System.out.println(String.format("Writing - %d", i)); 34 | System.out.println(String.format("Received - %d - %d", recv[0], recv[1])); 35 | Thread.sleep(100); 36 | } 37 | for (int i = 130; i > 90; i--) { 38 | data[1] = (byte) i; 39 | byte[] recv = spi.write(data); 40 | System.out.println(String.format("Writing - %d", i)); 41 | System.out.println(String.format("Received - %d - %d", recv[0], recv[1])); 42 | Thread.sleep(100); 43 | } 44 | } 45 | //! [Interesting] 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /examples/java/UartExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Brendan Le Foll 4 | * Author: Petre Eftime 5 | * Copyright (c) 2014, 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | 11 | import mraa.Result; 12 | import mraa.Uart; 13 | import mraa.UartParity; 14 | 15 | public class UartExample { 16 | 17 | public static void main(String[] args) { 18 | //! [Interesting] 19 | Uart uart = new Uart(0); 20 | 21 | if (uart.setBaudRate(115200) != Result.SUCCESS) { 22 | System.err.println("Error setting baud rate"); 23 | System.exit(1); 24 | } 25 | 26 | if (uart.setMode(8, UartParity.UART_PARITY_NONE, 1) != Result.SUCCESS) { 27 | System.err.println("Error setting mode"); 28 | System.exit(1); 29 | } 30 | 31 | if (uart.setFlowcontrol(false, false) != Result.SUCCESS) { 32 | System.err.println("Error setting flow control"); 33 | System.exit(1); 34 | } 35 | 36 | uart.writeStr("Hello monkeys"); 37 | //! [Interesting] 38 | } 39 | } -------------------------------------------------------------------------------- /examples/javascript/AioA0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Dan Yocom 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console 12 | 13 | let analogPin0 = new mraa.Aio(0); //setup access analog inpuput pin 0 14 | let analogValue = analogPin0.read(); //read the value of the analog pin 15 | let analogValueFloat = analogPin0.readFloat(); //read the pin value as a float 16 | console.log(analogValue); //write the value of the analog pin to the console 17 | console.log(analogValueFloat.toFixed(5)); //write the value in the float format 18 | -------------------------------------------------------------------------------- /examples/javascript/Blink-IO.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Dan Yocom 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console 12 | 13 | let myLed = new mraa.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2) 14 | myLed.dir(mraa.DIR_OUT); //set the gpio direction to output 15 | let ledState = true; //Boolean to hold the state of Led 16 | 17 | function periodicActivity() { 18 | myLed.write(ledState ? 1 : 0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) 19 | ledState = !ledState; //invert the ledState 20 | } 21 | 22 | setInterval(periodicActivity, 1000); //call the periodicActivity function every second 23 | -------------------------------------------------------------------------------- /examples/javascript/GPIO_DigitalRead.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Dan Yocom 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console 12 | 13 | let myDigitalPin = new mraa.Gpio(6); //setup digital read on pin 6 14 | myDigitalPin.dir(mraa.DIR_IN); //set the gpio direction to input 15 | 16 | function periodicActivity() { 17 | let myDigitalValue = myDigitalPin.read(); //read the digital value of the pin 18 | console.log('Gpio value is ' + myDigitalValue); //write the read value out to the console 19 | } 20 | 21 | setInterval(periodicActivity, 1000); //call the indicated function every 1 second (1000 milliseconds) 22 | -------------------------------------------------------------------------------- /examples/javascript/GPIO_DigitalWrite.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Dan Yocom 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console 12 | 13 | let myDigitalPin = new mraa.Gpio(5); //setup digital read on pin 5 14 | myDigitalPin.dir(mraa.DIR_OUT); //set the gpio direction to output 15 | myDigitalPin.write(1); //set the digital pin to high (1) 16 | -------------------------------------------------------------------------------- /examples/javascript/bmp85.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Author: Brendan Le Foll 5 | * Copyright (c) 2014 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | "use strict"; 11 | 12 | const mraa = require('mraa'); //require mraa 13 | 14 | let i2cDevice = new mraa.I2c(0); 15 | i2cDevice.address(0x77); 16 | 17 | // initialise device 18 | if (i2cDevice.readReg(0xd0) != 0x55) { 19 | console.log("error"); 20 | } 21 | 22 | // we want to read temperature so write 0x2e into control reg 23 | i2cDevice.writeReg(0xf4, 0x2e); 24 | 25 | // read a 16bit reg, obviously it's uncalibrated so mostly a useless value :) 26 | console.log(i2cDevice.readWordReg(0xf6)); 27 | 28 | // and we can do the same thing with the read()/write() calls if we wished 29 | // thought I'd really not recommend it! 30 | let buf = new Buffer(2); 31 | buf[0] = 0xf4; 32 | buf[1] = 0x2e; 33 | console.log(buf.toString('hex')); 34 | i2cDevice.write(buf); 35 | 36 | i2cDevice.writeByte(0xf6); 37 | let result = i2cDevice.read(2); 38 | console.log(result.toString('hex')); 39 | -------------------------------------------------------------------------------- /examples/javascript/firmata.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ron Evans (@deadprogram) 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); 11 | console.log('MRAA Version: ' + mraa.getVersion()); 12 | 13 | // open connection to firmata 14 | mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0"); 15 | -------------------------------------------------------------------------------- /examples/javascript/initio.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Houman Brinjcargorabi 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); 11 | 12 | // GPIO-PIN 13 | mraa.gpioFromDesc("gpio-1"); 14 | // GPIO-RAW-RAWPIN 15 | mraa.gpioFromDesc("gpio-raw-131"); 16 | // AIO-PIN 17 | mraa.aioFromDesc("aio-1"); 18 | //PWM-PIN 19 | mraa.pwmFromDesc("pwm-6"); 20 | // PWM-RAW-CHIPID-PIN 21 | mraa.pwmFromDesc("pwm-raw-0-1") 22 | // UART-INDEX: the index is the one represented internally in the uart_dev array 23 | mraa.uartFromDesc("uart-0"); 24 | // UART-RAW-PATH 25 | mraa.uartFromDesc("uart-raw-/dev/ttyS0"); 26 | // SPI-INDEX: same as UART 27 | mraa.spiFromDesc("spi-0"); 28 | // SPI-RAW-BUS-CS: USED to open and use /dev/spidev. 29 | mraa.spiFromDesc("spi-raw-0-1"); 30 | // I2C-INDEX: same as UART 31 | mraa.i2cFromDesc("i2c-0"); 32 | // I2C-RAW-BUS 33 | mraa.i2cFromDesc("i2c-raw-0"); 34 | -------------------------------------------------------------------------------- /examples/javascript/isr.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | * Copyright (c) 2015 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); 11 | 12 | function hello() { 13 | console.log("HELLO!!!!"); 14 | } 15 | 16 | let pin = new mraa.Gpio(14); 17 | pin.isr(mraa.EDGE_BOTH, hello); 18 | 19 | setInterval(function() { 20 | // It's important to refer to our GPIO context here, 21 | // otherwise it will be garbage-collected 22 | console.log("Waiting for an interrupt at GPIO pin " + pin.getPin() + "..."); 23 | }, 10000); 24 | -------------------------------------------------------------------------------- /examples/javascript/rgblcd.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | 12 | let i2cDevice = new mraa.I2c(0); 13 | i2cDevice.address(0x62); 14 | i2cDevice.writeReg(0, 0); 15 | i2cDevice.writeReg(1, 0); 16 | 17 | i2cDevice.writeReg(0x08, 0xAA); 18 | i2cDevice.writeReg(0x04, 255); 19 | i2cDevice.writeReg(0x02, 255); 20 | -------------------------------------------------------------------------------- /examples/javascript/spi.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Author: Brendan Le Foll 5 | * Copyright (c) 2015 Intel Corporation. 6 | * 7 | * SPDX-License-Identifier: MIT 8 | */ 9 | 10 | "use strict"; 11 | 12 | const mraa = require('mraa'); //require mraa 13 | 14 | let spiDevice = new mraa.Spi(0); 15 | let buf = new Buffer(4); 16 | buf[0] = 0xf4; 17 | buf[1] = 0x2e; 18 | buf[2] = 0x3e; 19 | buf[3] = 0x4e; 20 | let buf2 = spiDevice.write(buf); 21 | console.log("Sent: " + buf.toString('hex') + ". Received: " + buf2.toString('hex')); 22 | -------------------------------------------------------------------------------- /examples/javascript/uart.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Eugene Bolshakov 3 | * Copyright (c) 2015 Eugene Bolshakov 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | "use strict"; 9 | 10 | const mraa = require('mraa'); //require mraa 11 | console.log('MRAA Version: ' + mraa.getVersion()); 12 | let uart = new mraa.Uart(0); 13 | 14 | console.log("Note: connect Rx and Tx of UART with a wire before use"); 15 | 16 | function sleep(delay) { 17 | delay += new Date().getTime(); 18 | while (new Date() < delay) {} 19 | } 20 | 21 | console.log("Set UART parameters"); 22 | 23 | uart.setBaudRate(115200); 24 | uart.setMode(8, 0, 1); 25 | uart.setFlowcontrol(false, false); 26 | sleep(200); 27 | 28 | console.log("First write-read circle:"); 29 | 30 | uart.writeStr("test\n"); 31 | sleep(200); 32 | console.log(uart.readStr(6)); 33 | sleep(200); 34 | 35 | console.log("Second write-read circle:"); 36 | 37 | uart.writeStr("2nd test\n"); 38 | sleep(200); 39 | console.log(uart.readStr(10)); 40 | -------------------------------------------------------------------------------- /examples/platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable (gpio_edison gpio_edison.c) 2 | target_link_libraries (gpio_edison mraa) 3 | 4 | add_executable (up2-leds up2-leds.cpp) 5 | target_link_libraries (up2-leds mraa) 6 | 7 | include_directories(${PROJECT_SOURCE_DIR}/api) 8 | include_directories(${PROJECT_SOURCE_DIR}/api/mraa) 9 | 10 | if (FIRMATA) 11 | add_executable (firmata_curie_imu firmata_curie_imu.c) 12 | add_executable (i2c_firmata i2c_firmata.c) 13 | target_link_libraries (firmata_curie_imu mraa) 14 | target_link_libraries (i2c_firmata mraa) 15 | endif() 16 | -------------------------------------------------------------------------------- /examples/platform/firmata_curie_imu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | 10 | #include "mraa.h" 11 | #include "mraa/firmata.h" 12 | 13 | #define FIRMATA_START_SYSEX 0xF0 14 | #define FIRMATA_END_SYSEX 0xF7 15 | #define FIRMATA_CURIE_IMU 0x11 16 | #define FIRMATA_CURIE_IMU_READ_ACCEL 0x00 17 | 18 | void 19 | interrupt(uint8_t* buf, int length) 20 | { 21 | printf("reg read returned: %d, with buffer size %d\n", ((buf[6] & 0x7f) | ((buf[7] & 0x7f) << 7)), length); 22 | } 23 | 24 | int 25 | main() 26 | { 27 | mraa_init(); 28 | //! [Interesting] 29 | 30 | /** 31 | * This example reads from the FirmataCurieIMU plugin 32 | */ 33 | 34 | mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0"); 35 | mraa_firmata_context firm = mraa_firmata_init(FIRMATA_CURIE_IMU); 36 | if (firm == NULL) { 37 | return EXIT_FAILURE; 38 | } 39 | 40 | mraa_firmata_response(firm, interrupt); 41 | 42 | char* buffer = calloc(4, 0); 43 | if (buffer == NULL) { 44 | free(firm); 45 | return EXIT_FAILURE; 46 | } 47 | buffer[0] = FIRMATA_START_SYSEX; 48 | buffer[1] = FIRMATA_CURIE_IMU; 49 | buffer[2] = FIRMATA_CURIE_IMU_READ_ACCEL; 50 | buffer[3] = FIRMATA_END_SYSEX; 51 | 52 | mraa_firmata_write_sysex(firm, buffer, 4); 53 | 54 | sleep(1); 55 | 56 | // stop the isr and set it again 57 | mraa_firmata_response_stop(firm); 58 | mraa_firmata_response(firm, interrupt); 59 | mraa_firmata_write_sysex(firm, buffer, 4); 60 | 61 | sleep(1); 62 | 63 | // close everything and try again 64 | mraa_firmata_close(firm); 65 | firm = mraa_firmata_init(FIRMATA_CURIE_IMU); 66 | mraa_firmata_response(firm, interrupt); 67 | mraa_firmata_write_sysex(firm, buffer, 4); 68 | 69 | sleep(10); 70 | 71 | mraa_firmata_close(firm); 72 | //! [Interesting] 73 | 74 | return EXIT_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /examples/platform/gpio_edison.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2015 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | //! [Interesting] 13 | #include "mraa.h" 14 | 15 | int 16 | main(int argc, char** argv) 17 | { 18 | mraa_result_t ret = MRAA_SUCCESS; 19 | mraa_platform_t platform_type = mraa_get_platform_type(); 20 | 21 | if (platform_type != MRAA_INTEL_EDISON_FAB_C) { 22 | fprintf(stderr, "Error: This program can only run on an edison\n"); 23 | ret = MRAA_ERROR_INVALID_PLATFORM; 24 | goto end; 25 | } 26 | 27 | // MRAA_INTEL_EDISON_GP182 == 0 so this will initialise pin0 on arduino 28 | // which is hardware gpio 130 and not 182 29 | mraa_gpio_context gpio182 = mraa_gpio_init(MRAA_INTEL_EDISON_GP182); 30 | if (gpio182 == NULL) { 31 | fprintf(stderr, "Error: Failed to open gpio182\n"); 32 | ret = MRAA_ERROR_INVALID_PLATFORM; 33 | goto end; 34 | } 35 | mraa_gpio_dir(gpio182, MRAA_GPIO_OUT); 36 | 37 | // we set the owner to false here, this makes sure that we do not close the 38 | // gpio from sysfs in mraa_gpio_close meaning it will stay as an output and 39 | // we will not always transition from 0->1 as gpio182 as output has the 40 | // default position of '0'. Note that the value could change as a result of 41 | // a mraa_gpio_dir however meaning we always go from 0->1 or 1->0 42 | mraa_gpio_owner(gpio182, false); 43 | int val = mraa_gpio_read(gpio182); 44 | printf("GPIO%d (mraa pin %d) was: %d, will set to %d\n", 182, mraa_gpio_get_pin(gpio182), val, !val); 45 | mraa_gpio_write(gpio182, !val); 46 | mraa_gpio_close(gpio182); 47 | 48 | end: 49 | mraa_deinit(); 50 | return ret; 51 | } 52 | //! [Interesting] 53 | -------------------------------------------------------------------------------- /examples/platform/i2c_firmata.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include "mraa.h" 9 | 10 | int 11 | main(int argc, char** argv) 12 | { 13 | mraa_init(); 14 | mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0"); 15 | 16 | mraa_i2c_context i2c; 17 | i2c = mraa_i2c_init(0 + 512); 18 | #if 0 19 | mraa_i2c_address(i2c, 0x62); 20 | 21 | #if 1 22 | uint8_t rx_tx_buf[2]; 23 | rx_tx_buf[0] = 0x0; 24 | rx_tx_buf[1] = 0x0; 25 | mraa_i2c_write(i2c, rx_tx_buf, 2); 26 | #endif 27 | //mraa_i2c_write_byte_data(i2c, 0x0, 0x0); 28 | mraa_i2c_write_byte_data(i2c, 0x0, 0x1); 29 | 30 | mraa_i2c_write_byte_data(i2c, 0xFF, 0x08); 31 | mraa_i2c_write_byte_data(i2c, 0x00, 0x04); 32 | mraa_i2c_write_byte_data(i2c, 0xA0, 0x02); 33 | #else 34 | mraa_i2c_address(i2c, 0x77); 35 | int res = mraa_i2c_read_byte_data(i2c, 0xd0); 36 | printf("res is 0x%x\n", res); 37 | 38 | uint8_t data[2]; 39 | mraa_i2c_write_byte(i2c, 0x77); 40 | mraa_i2c_read(i2c, data, 1); 41 | 42 | res = mraa_i2c_read_word_data(i2c, 0xAA); // BMP085_CAL_AC1 43 | printf("res is %d\n", res); 44 | #endif 45 | sleep(10); 46 | } 47 | -------------------------------------------------------------------------------- /examples/platform/initio.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Houman Brinjcargorabi 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "mraa.hpp" 13 | 14 | int 15 | main() 16 | { 17 | // GPIO-PIN 18 | mraa::Gpio* gpio = mraa::initIo("gpio-1"); 19 | // GPIO-RAW-RAWPIN 20 | mmraa::Gpio* gpioraw = mraa::initIo initIo("gpio-raw-131"); 21 | // AIO-PIN 22 | mraa::Aio aio = mraa::initIo("aio-0"); 23 | // PWM-PIN 24 | mraa::Pwm pwm = mraa::initIo("pwm-6"); 25 | // PWM-RAW-CHIPID-PIN 26 | mraa::Pwm pwmraw = mraa::initIo("pwm-raw-0,1"); 27 | // UART-INDEX: the index is the one represented internally in the uart_dev array 28 | mraa::Uart uart = mraa::initIo("uart-1"); 29 | // UART-RAW-PATH 30 | mraa::Uart uartraw = mraa::initIo("uart-raw-/dev/ttyS0"); 31 | // SPI-INDEX: same as UART 32 | mraa::Spi spi = mraa::initIo("spi-0"); 33 | // SPI-RAW-BUS-CS: USED to open and use /dev/spidev. 34 | mraa::Spi spiraw = mraa::initIo("spi-raw-0-1"); 35 | // I2C-INDEX: same as UART 36 | mraa::I2c i2c = mraa::initIo("i2c-0"); 37 | // I2C-RAW-BUS 38 | mraa::I2c i2craw = mraa::initIo("i2c-raw-0"); 39 | 40 | // FREE STUFF 41 | delete gpio; 42 | delete gpioraw; 43 | delete aio; 44 | delete pwm; 45 | delete pwmraw; 46 | delete uart; 47 | delete uartraw; 48 | delete spi; 49 | delete spiraw; 50 | delete i2c; 51 | delete i2craw; 52 | } 53 | -------------------------------------------------------------------------------- /examples/platform/initio.py: -------------------------------------------------------------------------------- 1 | #!/bin/usr/env python 2 | 3 | # Author: Houman Brinjcargorabi 4 | # Copyright (c) 2016 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | 10 | # GPIO-PIN 11 | m.gpioFromDesc("gpio-1"); 12 | # GPIO-RAW-RAWPIN 13 | m.gpioFromDesc("gpio-raw-131"); 14 | # AIO-PIN 15 | m.aioFromDesc("aio-1"); 16 | # PWM-PIN 17 | m.pwmFromDesc("pwm-6"); 18 | # PWM-RAW-CHIPID-PIN 19 | m.pwmFromDesc("pwm-raw-0-1") 20 | # UART-INDEX: the index is the one represented internally in the uart_dev array 21 | m.uartFromDesc("uart-0"); 22 | # UART-RAW-PATH 23 | m.uartFromDesc("uart-raw-/dev/ttyS0"); 24 | # SPI-INDEX: same as UART 25 | m.spiFromDesc("spi-0"); 26 | # SPI-RAW-BUS-CS: USED to open and use /dev/spidev. 27 | m.spiFromDesc("spi-raw-0-1"); 28 | # I2C-INDEX: same as UART 29 | m.i2cFromDesc("i2c-0"); 30 | # I2C-RAW-BUS 31 | m.i2cFromDesc("i2c-raw-0"); 32 | -------------------------------------------------------------------------------- /examples/platform/intel-aero.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "platform":[ 4 | { 5 | "id":301, 6 | "name":"Intel Aero", 7 | "pin_count": 0, 8 | "gpio_count": 0, 9 | "i2c_count": 1, 10 | "aio_count": 0, 11 | "spi_count": 1, 12 | "uart_count": 0, 13 | } 14 | ], 15 | "layout":[ 16 | ], 17 | "GPIO":[ 18 | ], 19 | "I2C": [ 20 | { "index": 0, "bus" : 2, "default":true } 21 | ], 22 | "SPI": [ 23 | { "index":0, "bus": 3, "slaveselect": 0, "default": true} 24 | ], 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/python/aio.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Brendan Le Foll 4 | # Copyright (c) 2014 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Reads integer and float value from ADC 9 | 10 | import mraa 11 | 12 | print(mraa.getVersion()) 13 | 14 | try: 15 | # initialise AIO 16 | x = mraa.Aio(0) 17 | 18 | # read integer value 19 | print(x.read()) 20 | 21 | # read float value 22 | print("%.5f" % x.readFloat()) 23 | except: 24 | print("Are you sure you have an ADC?") 25 | -------------------------------------------------------------------------------- /examples/python/firmata.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Ron Evans (@deadprogram) 4 | # Copyright (c) 2016 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa 9 | 10 | print (mraa.getVersion()) 11 | 12 | mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0"); 13 | -------------------------------------------------------------------------------- /examples/python/gpio.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Manivannan Sadhasivam 4 | # Copyright (c) 2018 Linaro Ltd. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Toggles GPIO 23 and 24 continuously in an alternative pattern 9 | 10 | import mraa 11 | import time 12 | 13 | # initialise gpio 23 14 | gpio_1 = mraa.Gpio(23) 15 | 16 | # initialise gpio 24 17 | gpio_2 = mraa.Gpio(24) 18 | 19 | # set gpio 23 to output 20 | gpio_1.dir(mraa.DIR_OUT) 21 | 22 | # set gpio 24 to output 23 | gpio_2.dir(mraa.DIR_OUT) 24 | 25 | # toggle both gpio's 26 | while True: 27 | gpio_1.write(1) 28 | gpio_2.write(0) 29 | 30 | time.sleep(1) 31 | 32 | gpio_1.write(0) 33 | gpio_2.write(1) 34 | 35 | time.sleep(1) 36 | -------------------------------------------------------------------------------- /examples/python/gpio_advanced.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Brendan Le Foll 4 | # Copyright (c) 2014 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Triggers ISR upon GPIO state change 9 | 10 | import mraa 11 | import time 12 | import sys 13 | 14 | class Counter: 15 | count = 0 16 | 17 | c = Counter() 18 | 19 | # inside a python interrupt you cannot use 'basic' types so you'll need to use 20 | # objects 21 | def isr_routine(gpio): 22 | print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read())) 23 | c.count += 1 24 | 25 | # GPIO 26 | pin = 6; 27 | 28 | try: 29 | # initialise GPIO 30 | x = mraa.Gpio(pin) 31 | 32 | print("Starting ISR for pin " + repr(pin)) 33 | 34 | # set direction and edge types for interrupt 35 | x.dir(mraa.DIR_IN) 36 | x.isr(mraa.EDGE_BOTH, isr_routine, x) 37 | 38 | # wait until ENTER is pressed 39 | var = raw_input("Press ENTER to stop") 40 | x.isrExit() 41 | except ValueError as e: 42 | print(e) 43 | -------------------------------------------------------------------------------- /examples/python/i2c_bmp85.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Brendan Le Foll 4 | # Copyright (c) 2014 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Shows the 'advanced' i2c functionality from python i2c 9 | # read/write 10 | 11 | import mraa as m 12 | 13 | # initialise I2C 14 | x = m.I2c(0) 15 | x.address(0x77) 16 | 17 | # initialise device 18 | if x.readReg(0xd0) != 0x55: 19 | print("error") 20 | 21 | # we want to read temperature so write 0x2e into control reg 22 | x.writeReg(0xf4, 0x2e) 23 | 24 | # read a 16bit reg, obviously it's uncalibrated so mostly a useless value :) 25 | print(str(x.readWordReg(0xf6))) 26 | 27 | # and we can do the same thing with the read()/write() calls if we wished 28 | # thought I'd really not recommend it! 29 | 30 | x.write(bytearray(b'0xf40x2e')) 31 | 32 | x.writeByte(0xf6) 33 | d = x.read(2) 34 | 35 | # WARNING: python 3.2+ call 36 | print(str(d)) 37 | print(int.from_bytes(d, byteorder='little')) 38 | -------------------------------------------------------------------------------- /examples/python/i2c_rgb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Brendan Le Foll 4 | # Copyright (c) 2014 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Changes the Grove-LCD RGB backlight to a nice shade of purple 9 | 10 | import mraa 11 | 12 | # initialise I2C 13 | x = mraa.I2c(0) 14 | x.address(0x62) 15 | 16 | # initialise device 17 | x.writeReg(0, 0) 18 | x.writeReg(1, 0) 19 | 20 | # write RGB color data 21 | x.writeReg(0x08, 0xAA) 22 | x.writeReg(0x04, 255) 23 | x.writeReg(0x02, 255) 24 | -------------------------------------------------------------------------------- /examples/python/led.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Manivannan Sadhasivam 4 | # Copyright (c) 2018 Linaro Ltd. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Reads maximum brightness value for user1 led and turns it 9 | # on/off depending on current state. Then sets led trigger 10 | # to heartbeat 11 | 12 | import mraa 13 | import time 14 | 15 | # initialise user1 led 16 | led_1 = mraa.Led("user1") 17 | 18 | # read maximum brightness 19 | val = led_1.readMaxBrightness() 20 | 21 | print("maximum brightness value for user1 led is: %d" % val); 22 | 23 | # turn led on/off depending on read max_brightness value 24 | if (val >= 1): 25 | val = 0 26 | # never reached mostly 27 | else: 28 | val = 1 29 | 30 | # set LED brightness 31 | led_1.setBrightness(val) 32 | 33 | # sleep for 5 seconds 34 | time.sleep(5) 35 | 36 | led_1.trigger("heartbeat") 37 | 38 | print("led trigger set to: heartbeat") 39 | -------------------------------------------------------------------------------- /examples/python/pwm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Thomas Ingleby 4 | # Copyright (c) 2014 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Generates PWM at a step rate of 0.01 continuously. 9 | 10 | import mraa 11 | import time 12 | 13 | # initialise PWM 14 | x = mraa.Pwm(3) 15 | 16 | # set PWM period 17 | x.period_us(700) 18 | 19 | # enable PWM 20 | x.enable(True) 21 | 22 | value= 0.0 23 | 24 | while True: 25 | # write PWM value 26 | x.write(value) 27 | 28 | time.sleep(0.05) 29 | 30 | value = value + 0.01 31 | if value >= 1: 32 | value = 0.0 33 | -------------------------------------------------------------------------------- /examples/python/spi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Henry Bruce 4 | # Copyright (c) 2016 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | # Example Usage: Read from MCP3004 ADC pin 0 in single ended mode 9 | 10 | import mraa 11 | import time 12 | 13 | # initialise SPI 14 | dev = mraa.Spi(0) 15 | 16 | # prepare data to send 17 | txbuf = bytearray(3) 18 | txbuf[0] = 0x01 19 | txbuf[1] = 0x80 20 | txbuf[2] = 0x00 21 | 22 | while True: 23 | # send data through SPI 24 | rxbuf = dev.write(txbuf) 25 | value = ((rxbuf[1] & 0x03) << 8) | rxbuf[2] 26 | print(value) 27 | 28 | time.sleep(0.5) 29 | -------------------------------------------------------------------------------- /examples/python/spi_loopback.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Brendan Le Foll 4 | # Copyright (c) 2015 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Loopbacks data between MISO and MOSI 100 times 9 | 10 | import mraa as m 11 | import random as rand 12 | 13 | # intialise SPI 14 | dev = m.Spi(0) 15 | 16 | for x in range(0,100): 17 | txbuf = bytearray(4) 18 | for y in range(0,4): 19 | txbuf[y] = rand.randrange(0, 256) 20 | 21 | # send and receive data through SPI 22 | rxbuf = dev.write(txbuf) 23 | if rxbuf != txbuf: 24 | print("Data mismatch!") 25 | exit(1) 26 | -------------------------------------------------------------------------------- /examples/python/uart.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Manivannan Sadhasivam 4 | # Copyright (c) 2018 Linaro Ltd. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Sends data through UART 9 | 10 | import mraa 11 | import time 12 | import sys 13 | 14 | # serial port 15 | port = "/dev/ttyACM0" 16 | 17 | data = 'Hello Mraa!' 18 | 19 | # initialise UART 20 | uart = mraa.Uart(port) 21 | 22 | # send data through UART 23 | uart.write(bytearray(data, 'utf-8')) 24 | -------------------------------------------------------------------------------- /examples/python/uart_receiver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2015 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Expects 'X' flag from the sender. This example requires 9 | # `uart_sender.py` to be running on the other end. 10 | 11 | import mraa 12 | 13 | # Initialise UART 14 | u = mraa.Uart(0) 15 | 16 | # Set UART parameters 17 | u.setBaudRate(115200) 18 | u.setMode(8, mraa.UART_PARITY_NONE, 1) 19 | u.setFlowcontrol(False, False) 20 | 21 | # Start a neverending loop waiting for data to arrive. 22 | # Press Ctrl+C to get out of it. 23 | while True: 24 | if u.dataAvailable(): 25 | # We are doing 1-byte reads here 26 | data_byte = u.readStr(1) 27 | print(data_byte) 28 | 29 | # Just a two-way half-duplex communication example, "X" is a flag 30 | if data_byte == "X": 31 | u.writeStr("Yes, master!") 32 | -------------------------------------------------------------------------------- /examples/python/uart_sender.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2015 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Example Usage: Sends some info messages in the form of bytearray and strings 9 | # along with `X` flag and prints the response from other end. 10 | # This example requires uart_receiver.py to be running on the 11 | # other end. 12 | 13 | import mraa 14 | import sys 15 | 16 | sys.stdout.write("Initializing UART...") 17 | u = mraa.Uart(0) 18 | print("...done") 19 | 20 | print("Setting UART parameters: baudrate 115200, 8N1, no flow control") 21 | u.setBaudRate(115200) 22 | u.setMode(8, mraa.UART_PARITY_NONE, 1) 23 | u.setFlowcontrol(False, False) 24 | 25 | msg_b = bytearray("Hello, mraa byte array!", "ascii") 26 | print("Sending message as a byte array: '{0}'".format(msg_b)) 27 | u.write(msg_b) 28 | # Make sure the message gets out to the line. 29 | # It's generally unnecessary (and performance-degrading) to do this explicitly, 30 | # UART driver normally takes care of that, but it may be useful with specific 31 | # half-duplex endpoints, like Dynamixel servos. 32 | u.flush() 33 | 34 | msg_s = "Hello, mraa string!" 35 | print("Sending message as a string: '{0}'".format(msg_s)) 36 | u.writeStr(msg_s) 37 | 38 | sys.stdout.write("Two-way, half-duplex communication, sending a flag...") 39 | u.writeStr("X") 40 | print("...sent, awaiting response...") 41 | # Checking for data in the RX buffer, giving it a 100ms timeout 42 | if u.dataAvailable(100): 43 | print("We've got a response: '{0}', says the other side".format(u.readStr(20))) 44 | else: 45 | print("No data received, do you have anything at the other end?") 46 | -------------------------------------------------------------------------------- /examples/samples.mapping.txt: -------------------------------------------------------------------------------- 1 | aio.cpp java/AioA0.java 2 | gpio.cpp java/BlinkIO.java 3 | i2c.cpp java/I2cCompass.java 4 | pwm.cpp java/CyclePwm3.java 5 | spi.cpp java/SpiMCP4261.java 6 | uart.cpp java/UartExample.java 7 | -------------------------------------------------------------------------------- /imraa/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable (imraa imraa.c imraa_arduino.c imraa_io.c imraa_lock.c) 2 | 3 | include_directories (${PROJECT_SOURCE_DIR}/api) 4 | include_directories (${PROJECT_SOURCE_DIR}/include) 5 | include_directories (${PROJECT_SOURCE_DIR}/api/mraa) 6 | include_directories (${PROJECT_SOURCE_DIR}/imraa) 7 | 8 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1") 9 | 10 | find_package (JSON-C REQUIRED) 11 | include_directories (${JSON-C_INCLUDE_DIR}) 12 | find_package (UDEV REQUIRED) 13 | include_directories (${UDEV_INCLUDE_DIR}) 14 | target_link_libraries (imraa mraa ${JSON-C_LIBRARIES} ${UDEV_LIBRARIES}) 15 | 16 | set_property (TARGET imraa PROPERTY C_STANDARD 99) 17 | 18 | install (TARGETS imraa DESTINATION bin) 19 | -------------------------------------------------------------------------------- /imraa/imraa.conf: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "lockfile-location": "/tmp/imraa.lock", 4 | "dfu-utils-location": "/usr/bin", 5 | "Platform" :[ 6 | {"id":"1280", "flash":"/usr/share/mraa/firmata101.ino.bin", "usbserial": "auto"} 7 | ], 8 | } 9 | -------------------------------------------------------------------------------- /imraa/imraa.io.conf: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.4.0", 3 | "lockfile-location": "/tmp/imraa.lock", 4 | "dfu-utils-location": "/usr/bin", 5 | "Platform" :[ 6 | {"id":"1280", "flash":"/usr/share/mraa/firmata101.ino.bin", "usbserial": "auto"} 7 | ], 8 | "IO": [ 9 | {"type":"gpio", "index":0, "raw": false, "label": "none", "user": "brendan", "group": "brendan"}, 10 | {"type":"i2c", "index":0, "raw": false, "label": "i2c-0", "user": "brendan", "group": "user"} 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /imraa/imraa.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=imraa 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=/usr/bin/imraa -a 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | -------------------------------------------------------------------------------- /imraa/imraa_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | void imraa_handle_subplatform(struct json_object* jobj, bool force_update); 11 | 12 | 13 | -------------------------------------------------------------------------------- /imraa/imraa_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | void imraa_handle_IO(struct json_object* jobj); 11 | 12 | -------------------------------------------------------------------------------- /imraa/imraa_lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | void 28 | imraa_write_lockfile(const char* lock_file_location, const char* serialport) 29 | { 30 | FILE* fh; 31 | char str[10]; 32 | json_object* platform1 = json_object_new_object(); 33 | snprintf(str, 10, "%d", MRAA_NULL_PLATFORM); 34 | json_object_object_add(platform1, "id", json_object_new_string(str)); 35 | 36 | json_object* platform2 = json_object_new_object(); 37 | snprintf(str, 10, "%d", MRAA_GENERIC_FIRMATA); 38 | json_object_object_add(platform2, "id", json_object_new_string(str)); 39 | json_object_object_add(platform2, "uart", json_object_new_string(serialport)); 40 | 41 | json_object* platfroms = json_object_new_array(); 42 | json_object_array_add(platfroms, platform1); 43 | json_object_array_add(platfroms, platform2); 44 | json_object* lock_file = json_object_new_object(); 45 | json_object_object_add(lock_file, "Platform", platfroms); 46 | fh = fopen(lock_file_location, "w"); 47 | if (fh != NULL) { 48 | fputs(json_object_to_json_string_ext(lock_file, JSON_C_TO_STRING_PRETTY), fh); 49 | fclose(fh); 50 | } else { 51 | fprintf(stderr, "can't write to lock file\n"); 52 | } 53 | json_object_put(lock_file); 54 | } 55 | -------------------------------------------------------------------------------- /imraa/imraa_lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | void imraa_write_lockfile(const char* lock_file_location, const char* serialport); 11 | 12 | -------------------------------------------------------------------------------- /include/arm/96boards.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Srinivas Kandagatla 3 | * Copyright (c) 2015 Linaro Limited. 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * Copied from include/arm/banana.h 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "mraa_internal.h" 18 | 19 | #define MRAA_96BOARDS_LS_GPIO_COUNT 12 20 | #define MRAA_96BOARDS_LS_I2C_COUNT 2 21 | #define MRAA_96BOARDS_LS_SPI_COUNT 1 22 | #define MRAA_96BOARDS_LS_UART_COUNT 2 23 | #define MRAA_96BOARDS_LS_PIN_COUNT 40 24 | #define MRAA_96BOARDS_LED_COUNT 6 25 | 26 | mraa_board_t* mraa_96boards(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/adlink_ipi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Santhanakumar A 4 | * Copyright (c) 2014 Intel Corporation. 5 | * Copyright (c) 2019 ADLINK Technology Inc. 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "mraa_internal.h" 17 | 18 | mraa_board_t * 19 | mraa_adlink_ipi(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/arm/am335x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Norbert Wesp 3 | * Author: Stefan Müller-Klieser 4 | * Copyright (c) 2016 Phytec Messtechnik GmbH. 5 | * 6 | * Based on src/arm/beaglebone.c 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "common.h" 23 | 24 | #define SYSFS_CLASS_PWM "/sys/class/pwm/" 25 | #define SYSFS_CLASS_MMC "/sys/class/mmc_host/" 26 | 27 | #define MMAP_PATH "/dev/mem" 28 | #define MAX_SIZE 64 29 | 30 | #define AM335X_GPIO0_BASE 0x44e07000 31 | #define AM335X_GPIO1_BASE 0x4804c000 32 | #define AM335X_GPIO2_BASE 0x481AC000 33 | #define AM335X_GPIO3_BASE 0x481AE000 34 | #define AM335X_GPIO_SIZE (4 * 1024) 35 | #define AM335X_IN 0x138 36 | #define AM335X_CLR 0x190 37 | #define AM335X_SET 0x194 38 | 39 | /** 40 | * Writes 'value' to gpio_context 'dev' 41 | * 42 | * @return mraa_result_t indicating success of actions. 43 | */ 44 | mraa_result_t mraa_am335x_mmap_write(mraa_gpio_context dev, int value); 45 | 46 | /** 47 | * Unsetup register of mmap_gpio[] 48 | * 49 | * @return mraa_result_t indicating success of actions. 50 | */ 51 | mraa_result_t mraa_am335x_mmap_unsetup(); 52 | 53 | /** 54 | * Read from gpio_context 'dev' 55 | * 56 | * @return int result indicating success of actions. 57 | */ 58 | int mraa_am335x_mmap_read(mraa_gpio_context dev); 59 | 60 | /** 61 | * Disables gpio_context 'dev' in case of 'en' or mmap'ing gpio_context 'dev' 62 | * 63 | * @return mraa_result_t indicating success of actions. 64 | */ 65 | mraa_result_t mraa_am335x_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /include/arm/banana.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Michael Ring 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "mraa_internal.h" 16 | 17 | #define MRAA_BANANA_PI_PINCOUNT 35 18 | #define MRAA_BANANA_PRO_PINCOUNT 41 19 | 20 | mraa_board_t* mraa_banana(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arm/beaglebone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Michael Ring 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "mraa_internal.h" 16 | 17 | #define MRAA_BEAGLEBONE_BLACK_PINCOUNT 93 18 | 19 | mraa_board_t * 20 | mraa_beaglebone(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arm/de_nano_soc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Tudor Panu 3 | * Copyright (c) 2017 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // 1x32 Arduino header, 1x40 GPIO_0/JP1, 1x40 GPIO_1/JP7, 17 | // 9 LEDs (8 User + HPS_LED), 4 switches, 3 buttons (2 User + HPS_KEY) 18 | // 10 ADC pins 19 | #define MRAA_DE_NANO_SOC_PINCOUNT 138 20 | 21 | mraa_board_t * 22 | mraa_de_nano_soc(); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/arm/orange_pi_prime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Gunjan 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include "mraa_internal.h" 14 | 15 | #define MRAA_ORANGE_PI_PRIME_GPIO_COUNT 28 16 | #define MRAA_ORANGE_PI_PRIME_I2C_COUNT 2 17 | #define MRAA_ORANGE_PI_PRIME_SPI_COUNT 1 18 | #define MRAA_ORANGE_PI_PRIME_UART_COUNT 1 19 | #define MRAA_ORANGE_PI_PRIME_PIN_COUNT 40 20 | 21 | mraa_board_t * 22 | mraa_orange_pi_prime(); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/arm/phyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Norbert Wesp 3 | * Author: Stefan Müller-Klieser 4 | * Copyright (c) 2016 Phytec Messtechnik GmbH. 5 | * 6 | * Based on include/arm/beaglebone.h 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "mraa_internal.h" 18 | 19 | #define MRAA_PHYBOARD_WEGA_PINCOUNT 117 20 | 21 | mraa_board_t * mraa_phyboard(); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /include/arm/radxa_cm3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) 2023 Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_CM3_GPIO_COUNT 28 17 | #define MRAA_RADXA_CM3_I2C_COUNT 3 18 | #define MRAA_RADXA_CM3_SPI_COUNT 2 19 | #define MRAA_RADXA_CM3_UART_COUNT 1 20 | #define MRAA_RADXA_CM3_PWM_COUNT 9 21 | #define MRAA_RADXA_CM3_AIO_COUNT 0 22 | #define MRAA_RADXA_CM3_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_CM3_IO "Radxa Compute Module 3(CM3) IO Board" 24 | #define PLATFORM_NAME_RADXA_CM3_IO_2 "Radxa CM3 IO Board" 25 | #define PLATFORM_NAME_RADXA_CM3_RPI_CM4_IO "Radxa CM3 RPI CM4 IO" // The core board of the Radxa CM3 is compatible with the RPI CM4 IO backplane. 26 | 27 | mraa_board_t * 28 | mraa_radxa_cm3(); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /include/arm/radxa_cm5_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_CM5_IO_GPIO_COUNT 25 17 | #define MRAA_RADXA_CM5_IO_I2C_COUNT 4 18 | #define MRAA_RADXA_CM5_IO_SPI_COUNT 1 19 | #define MRAA_RADXA_CM5_IO_UART_COUNT 2 20 | #define MRAA_RADXA_CM5_IO_PWM_COUNT 7 21 | #define MRAA_RADXA_CM5_IO_AIO_COUNT 1 22 | #define MRAA_RADXA_CM5_IO_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_CM5_IO "Radxa CM5 IO" 24 | 25 | mraa_board_t * 26 | mraa_radxa_cm5_io(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/radxa_e25.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) 2023 Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_E25_GPIO_COUNT 17 17 | #define MRAA_RADXA_E25_I2C_COUNT 1 18 | #define MRAA_RADXA_E25_SPI_COUNT 2 19 | #define MRAA_RADXA_E25_UART_COUNT 3 20 | #define MRAA_RADXA_E25_PWM_COUNT 6 21 | #define MRAA_RADXA_E25_AIO_COUNT 1 22 | #define MRAA_RADXA_E25_PIN_COUNT 26 23 | #define PLATFORM_NAME_RADXA_E25 "Radxa E25 Carrier Board" 24 | 25 | mraa_board_t * 26 | mraa_radxa_e25(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/radxa_rock_3a.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_ROCK_3A_GPIO_COUNT 28 17 | #define MRAA_RADXA_ROCK_3A_I2C_COUNT 3 18 | #define MRAA_RADXA_ROCK_3A_SPI_COUNT 1 19 | #define MRAA_RADXA_ROCK_3A_UART_COUNT 7 20 | #define MRAA_RADXA_ROCK_3A_PWM_COUNT 11 21 | #define MRAA_RADXA_ROCK_3A_AIO_COUNT 1 22 | #define MRAA_RADXA_ROCK_3A_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_ROCK_3A "Radxa ROCK3 Model A" 24 | 25 | mraa_board_t * 26 | mraa_radxa_rock_3a(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/radxa_rock_3b.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_ROCK_3B_GPIO_COUNT 28 17 | #define MRAA_RADXA_ROCK_3B_I2C_COUNT 3 18 | #define MRAA_RADXA_ROCK_3B_SPI_COUNT 1 19 | #define MRAA_RADXA_ROCK_3B_UART_COUNT 6 20 | #define MRAA_RADXA_ROCK_3B_PWM_COUNT 11 21 | #define MRAA_RADXA_ROCK_3B_AIO_COUNT 1 22 | #define MRAA_RADXA_ROCK_3B_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_ROCK_3B "Radxa ROCK 3 Model B" 24 | 25 | mraa_board_t * 26 | mraa_radxa_rock_3b(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/radxa_rock_3c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_ROCK_3C_GPIO_COUNT 27 17 | #define MRAA_RADXA_ROCK_3C_I2C_COUNT 2 18 | #define MRAA_RADXA_ROCK_3C_SPI_COUNT 1 19 | #define MRAA_RADXA_ROCK_3C_UART_COUNT 5 20 | #define MRAA_RADXA_ROCK_3C_PWM_COUNT 6 21 | #define MRAA_RADXA_ROCK_3C_AIO_COUNT 0 22 | #define MRAA_RADXA_ROCK_3C_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_ROCK_3C "Radxa ROCK3 Model C" 24 | #define PLATFORM_NAME_RADXA_ZERO3 "Radxa ZERO 3" 25 | 26 | mraa_board_t * 27 | mraa_radxa_rock_3c(); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /include/arm/radxa_rock_5a.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_ROCK_5A_GPIO_COUNT 27 17 | #define MRAA_RADXA_ROCK_5A_I2C_COUNT 5 18 | #define MRAA_RADXA_ROCK_5A_SPI_COUNT 2 19 | #define MRAA_RADXA_ROCK_5A_UART_COUNT 5 20 | #define MRAA_RADXA_ROCK_5A_PWM_COUNT 9 21 | #define MRAA_RADXA_ROCK_5A_AIO_COUNT 1 22 | #define MRAA_RADXA_ROCK_5A_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_ROCK_5A "Radxa ROCK 5A" 24 | 25 | mraa_board_t * 26 | mraa_radxa_rock_5a(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/radxa_rock_5b.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Nascs 3 | * Copyright (c) Radxa Limited. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_RADXA_ROCK_5B_GPIO_COUNT 26 17 | #define MRAA_RADXA_ROCK_5B_I2C_COUNT 4 18 | #define MRAA_RADXA_ROCK_5B_SPI_COUNT 2 19 | #define MRAA_RADXA_ROCK_5B_UART_COUNT 4 20 | #define MRAA_RADXA_ROCK_5B_PWM_COUNT 14 21 | #define MRAA_RADXA_ROCK_5B_AIO_COUNT 1 22 | #define MRAA_RADXA_ROCK_5B_PIN_COUNT 40 23 | #define PLATFORM_NAME_RADXA_ROCK_5B "Radxa ROCK 5B" 24 | 25 | mraa_board_t * 26 | mraa_radxa_rock_5b(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/arm/raspberry_pi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Author: Michael Ring 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "mraa_internal.h" 16 | 17 | #define MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT 27 18 | #define MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT 35 19 | #define MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT 41 20 | #define MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT 41 21 | #define MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT 41 22 | #define MRAA_RASPBERRY_PI_ZERO_PINCOUNT 41 23 | #define MRAA_RASPBERRY_PI3_B_PINCOUNT 41 24 | #define MRAA_RASPBERRY_PI_ZERO_W_PINCOUNT 41 25 | #define MRAA_RASPBERRY_PI3_B_PLUS_PINCOUNT 41 26 | #define MRAA_RASPBERRY_PI3_A_PLUS_PINCOUNT 41 27 | #define MRAA_RASPBERRY_PI4_B_PINCOUNT 41 28 | #define MRAA_RASPBERRY_PI_400_PINCOUNT 41 29 | #define MRAA_RASPBERRY_PI5_B_PINCOUNT 41 30 | mraa_board_t * 31 | mraa_raspberry_pi(); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /include/arm/rockpi4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brian 3 | * Copyright (c) 2019 Vamrs Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_ROCKPI4_GPIO_COUNT 27 17 | #define MRAA_ROCKPI4_I2C_COUNT 3 18 | #define MRAA_ROCKPI4_SPI_COUNT 2 19 | #define MRAA_ROCKPI4_UART_COUNT 2 20 | #define MRAA_ROCKPI4_PWM_COUNT 2 21 | #define MRAA_ROCKPI4_AIO_COUNT 1 22 | #define MRAA_ROCKPI4_PIN_COUNT 40 23 | 24 | mraa_board_t * 25 | mraa_rockpi4(); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /include/arm/siemens/iot2050.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Le Jin 3 | * Copyright (c) Siemens AG, 2019 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | #pragma once 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include "mraa_internal.h" 31 | 32 | #define PLATFORM_NAME "SIMATIC IOT2050" 33 | #define MRAA_IOT2050_PINCOUNT 21 34 | 35 | mraa_board_t * 36 | mraa_siemens_iot2050(); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /include/arm/siemens/platform_iot2050.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Le Jin 3 | * Copyright (c) Siemens AG, 2019 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | #ifndef _PLATFORM_IOT2050_H_ 25 | #define _PLATFORM_IOT2050_H_ 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | #include "arm/siemens/platform.h" 30 | pin_mux_interface_t *iot2050_pinmux_get_instance(void); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /include/firmata/firmata_mraa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | mraa_platform_t mraa_firmata_platform(mraa_board_t* board, const char* uart_dev); 17 | 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /include/grovepi/grovepi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Tudor Panu 3 | * Copyright (c) 2017 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "i2c.h" 15 | #include "mraa_internal.h" 16 | 17 | #define GROVEPI_ADDRESS 0x04 18 | #define GROVEPI_REGISTER 0x01 19 | #define GROVEPI_GPIO_READ 0x01 20 | #define GROVEPI_GPIO_WRITE 0x02 21 | #define GROVEPI_AIO_READ 0x03 22 | #define GROVEPI_PWM 0x04 23 | #define GROVEPI_GPIO_MODE 0x05 24 | #define GROVEPI_FIRMWARE 0x08 25 | 26 | mraa_platform_t mraa_grovepi_platform(mraa_board_t* board, const int i2c_bus); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/initio/initio_keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Stefanescu 3 | * Copyright (c) 2018 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /*gpio modes */ 15 | #define G_MODE_STRONG "mode_strong" 16 | #define G_MODE_PULLUP "mode_pullup" 17 | #define G_MODE_PULLDOWN "mode_pulldown" 18 | #define G_MODE_HIZ "mode_hiz" 19 | #define G_MODE_ACTIVE_LOW "mode_active_low" 20 | #define G_MODE_OPEN_DRAIN "mode_open_drain" 21 | #define G_MODE_OPEN_SOURCE "mode_open_source" 22 | 23 | /*gpio direction modes */ 24 | #define G_DIR_OUT "out" 25 | #define G_DIR_IN "in" 26 | #define G_DIR_OUT_HIGH "out_high" 27 | #define G_DIR_OUT_LOW "out_low" 28 | 29 | /*gpio edge modes */ 30 | #define G_EDGE_NONE "edge_none" 31 | #define G_EDGE_BOTH "edge_both" 32 | #define G_EDGE_RISING "edge_rising" 33 | #define G_EDGE_FALLING "edge_falling" 34 | 35 | /*gpio input modes */ 36 | #define G_INPUT_ACTIVE_HIGH "input_high" 37 | #define G_INPUT_ACTIVE_LOW "input_low" 38 | 39 | /*gpio output driver modes */ 40 | #define G_OUTPUT_OPEN_DRAIN "output_open_drain" 41 | #define G_OUTPUT_PUSH_PULL "output_push_pull" 42 | /*---------------------------------------------*/ 43 | 44 | /* i2c modes */ 45 | #define I_MODE_STD "std" 46 | #define I_MODE_FAST "fast" 47 | #define I_MODE_HIGH "high" 48 | /*---------------------------------------------*/ 49 | 50 | /* spi modes */ 51 | #define S_MODE_0 "mode0" 52 | #define S_MODE_1 "mode1" 53 | #define S_MODE_2 "mode2" 54 | #define S_MODE_3 "mode3" 55 | /*---------------------------------------------*/ 56 | 57 | /* uart parity types */ 58 | #define U_PARITY_NONE "N" 59 | #define U_PARITY_EVEN "E" 60 | #define U_PARITY_ODD "O" 61 | #define U_PARITY_MARK "M" 62 | #define U_PARITY_SPACE "S" 63 | /*---------------------------------------------*/ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif -------------------------------------------------------------------------------- /include/java/mraajni.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Henry Bruce 3 | * Copyright (c) 2014-2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | #include "mraa/types.h" 16 | 17 | // location for defining JNI version to use 18 | #define JNI_REQUIRED_VERSION JNI_VERSION_1_6 19 | 20 | void mraa_java_set_jvm(JavaVM* vm); 21 | void mraa_java_isr_callback(void* args); 22 | mraa_result_t mraa_java_attach_thread(); 23 | void mraa_java_detach_thread(); 24 | void* mraa_java_create_global_ref(void* args); 25 | void mraa_java_delete_global_ref(void* ref); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /include/linux/README: -------------------------------------------------------------------------------- 1 | These headers was automatically generated from a Linux kernel header 2 | of the same name, to make information necessary for userspace to 3 | call into the kernel available to libc. It contains only constants, 4 | structures, and macros generated from the original header, and thus, 5 | contains no copyrightable information. 6 | -------------------------------------------------------------------------------- /include/linux/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UAPI_LINUX_COMPILER_H 2 | #define _UAPI_LINUX_COMPILER_H 3 | 4 | /* 5 | * This file is not currently in the Linux kernel tree. 6 | * Upstream uapi headers refer to but there is 7 | * no such uapi file. We've sent this upstream, and are optimistically 8 | * adding it to bionic in the meantime. This should be replaced by 9 | * a scrubbed header from external/kernel-headers when possible. 10 | * 11 | * An alternative to this file is to check in a symbolic link to the 12 | * non-uapi . That's fine for building bionic too. 13 | */ 14 | 15 | #define __user 16 | #define __force 17 | 18 | #endif /* _UAPI_LINUX_COMPILER_H */ 19 | -------------------------------------------------------------------------------- /include/linux/posix_types.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Linux kernel header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to libc. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef _LINUX_POSIX_TYPES_H 20 | #define _LINUX_POSIX_TYPES_H 21 | #undef __FD_SETSIZE 22 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 23 | #define __FD_SETSIZE 1024 24 | typedef struct { 25 | unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))]; 26 | } __kernel_fd_set; 27 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 28 | typedef void (*__kernel_sighandler_t)(int); 29 | typedef int __kernel_key_t; 30 | typedef int __kernel_mqd_t; 31 | #if !defined(MSYS) 32 | #include 33 | #endif 34 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 35 | #endif 36 | -------------------------------------------------------------------------------- /include/mips/mediatek.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Serge Vakulenko 3 | * Copyright (c) 2017 Serge Vakulenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | mraa_board_t * 17 | mraa_mtk_linkit(); 18 | mraa_board_t * 19 | mraa_mtk_omega2(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/mock/mock_board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_MOCK_PINCOUNT 10 17 | 18 | mraa_board_t* 19 | mraa_mock_board(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/mock/mock_board_aio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | mraa_result_t 17 | mraa_mock_aio_init_internal_replace(mraa_aio_context dev, int pin); 18 | 19 | mraa_result_t 20 | mraa_mock_aio_close_replace(mraa_aio_context dev); 21 | 22 | int 23 | mraa_mock_aio_read_replace(mraa_aio_context dev); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /include/mock/mock_board_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | mraa_result_t 17 | mraa_mock_gpio_init_internal_replace(mraa_gpio_context dev, int pin); 18 | 19 | mraa_result_t 20 | mraa_mock_gpio_close_replace(mraa_gpio_context dev); 21 | 22 | mraa_result_t 23 | mraa_mock_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir); 24 | 25 | mraa_result_t 26 | mraa_mock_gpio_read_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t* dir); 27 | 28 | int 29 | mraa_mock_gpio_read_replace(mraa_gpio_context dev); 30 | 31 | mraa_result_t 32 | mraa_mock_gpio_write_replace(mraa_gpio_context dev, int value); 33 | 34 | mraa_result_t 35 | mraa_mock_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode); 36 | 37 | mraa_result_t 38 | mraa_mock_gpio_isr_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode, void (*fptr)(void*), void* args); 39 | 40 | mraa_result_t 41 | mraa_mock_gpio_isr_exit_replace(mraa_gpio_context dev); 42 | 43 | mraa_result_t 44 | mraa_mock_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /include/mock/mock_board_i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // Mock I2C device address 17 | #define MOCK_I2C_DEV_ADDR 0x33 18 | // Mock I2C device data registers block length in bytes. Our code assumes it's >= 1. 19 | #define MOCK_I2C_DEV_DATA_LEN 10 20 | // Initial value for each byte in the mock I2C device data registers 21 | #define MOCK_I2C_DEV_DATA_INIT_BYTE 0xAB 22 | 23 | mraa_result_t 24 | mraa_mock_i2c_init_bus_replace(mraa_i2c_context dev); 25 | 26 | mraa_result_t 27 | mraa_mock_i2c_stop_replace(mraa_i2c_context dev); 28 | 29 | mraa_result_t 30 | mraa_mock_i2c_set_frequency_replace(mraa_i2c_context dev, mraa_i2c_mode_t mode); 31 | 32 | mraa_result_t 33 | mraa_mock_i2c_address_replace(mraa_i2c_context dev, uint8_t addr); 34 | 35 | int 36 | mraa_mock_i2c_read_replace(mraa_i2c_context dev, uint8_t* data, int length); 37 | 38 | int 39 | mraa_mock_i2c_read_byte_replace(mraa_i2c_context dev); 40 | 41 | int 42 | mraa_mock_i2c_read_byte_data_replace(mraa_i2c_context dev, uint8_t command); 43 | 44 | int 45 | mraa_mock_i2c_read_bytes_data_replace(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length); 46 | 47 | int 48 | mraa_mock_i2c_read_word_data_replace(mraa_i2c_context dev, uint8_t command); 49 | 50 | mraa_result_t 51 | mraa_mock_i2c_write_replace(mraa_i2c_context dev, const uint8_t* data, int length); 52 | 53 | mraa_result_t 54 | mraa_mock_i2c_write_byte_replace(mraa_i2c_context dev, const uint8_t data); 55 | 56 | mraa_result_t 57 | mraa_mock_i2c_write_byte_data_replace(mraa_i2c_context dev, const uint8_t data, const uint8_t command); 58 | 59 | mraa_result_t 60 | mraa_mock_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data, const uint8_t command); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /include/mock/mock_board_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MOCK_SPI_DEFAULT_FREQ 4000000 17 | #define MOCK_SPI_DEFAULT_MODE MRAA_SPI_MODE0 18 | #define MOCK_SPI_DEFAULT_LSBMODE 0 19 | #define MOCK_SPI_DEFAULT_BIT_PER_WORD 8 20 | // This is XORed with each byte/word of the transmitted message to get the received one 21 | #define MOCK_SPI_REPLY_DATA_MODIFIER_BYTE 0xAB 22 | #define MOCK_SPI_REPLY_DATA_MODIFIER_WORD 0xABBA 23 | 24 | mraa_result_t 25 | mraa_mock_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs); 26 | 27 | mraa_result_t 28 | mraa_mock_spi_stop_replace(mraa_spi_context dev); 29 | 30 | mraa_result_t 31 | mraa_mock_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits); 32 | 33 | mraa_result_t 34 | mraa_mock_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb); 35 | 36 | mraa_result_t 37 | mraa_mock_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode); 38 | 39 | mraa_result_t 40 | mraa_mock_spi_frequency_replace(mraa_spi_context dev, int hz); 41 | 42 | int 43 | mraa_mock_spi_write_replace(mraa_spi_context dev, uint8_t data); 44 | 45 | int 46 | mraa_mock_spi_write_word_replace(mraa_spi_context dev, uint16_t data); 47 | 48 | mraa_result_t 49 | mraa_mock_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length); 50 | 51 | mraa_result_t 52 | mraa_mock_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, uint16_t* rxbuf, int length); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /include/mock/mock_board_uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // ASCII code for "Z", used as a basis for our mock reads 17 | #define MOCK_UART_DATA_BYTE 0x5A 18 | 19 | mraa_result_t 20 | mraa_mock_uart_set_baudrate_replace(mraa_uart_context dev, unsigned int baud); 21 | 22 | mraa_result_t 23 | mraa_mock_uart_init_raw_replace(mraa_uart_context dev, const char* path); 24 | 25 | mraa_result_t 26 | mraa_mock_uart_flush_replace(mraa_uart_context dev); 27 | 28 | mraa_result_t 29 | mraa_mock_uart_sendbreak_replace(mraa_uart_context dev, int duration); 30 | 31 | mraa_result_t 32 | mraa_mock_uart_set_flowcontrol_replace(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts); 33 | 34 | mraa_result_t 35 | mraa_mock_uart_set_mode_replace(mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits); 36 | 37 | mraa_result_t 38 | mraa_mock_uart_set_non_blocking_replace(mraa_uart_context dev, mraa_boolean_t nonblock); 39 | 40 | mraa_result_t 41 | mraa_mock_uart_set_timeout_replace(mraa_uart_context dev, int read, int write, int interchar); 42 | 43 | mraa_boolean_t 44 | mraa_mock_uart_data_available_replace(mraa_uart_context dev, unsigned int millis); 45 | 46 | int 47 | mraa_mock_uart_write_replace(mraa_uart_context dev, const char* buf, size_t len); 48 | 49 | int 50 | mraa_mock_uart_read_replace(mraa_uart_context dev, char* buf, size_t len); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /include/mraa_lang_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Henry Bruce 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | typedef struct { 11 | void (*python_isr)(void (*isr)(void*), void* isr_args); 12 | void (*java_isr_callback)(void *args); 13 | mraa_result_t (*java_attach_thread)(); 14 | void (*java_detach_thread)(); 15 | void* (*java_create_global_ref)(void* args); 16 | void (*java_delete_global_ref)(void* ref); 17 | 18 | } mraa_lang_func_t; 19 | -------------------------------------------------------------------------------- /include/peripheralmanager/peripheralman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | mraa_platform_t mraa_peripheralman_platform(); 17 | 18 | void pman_mraa_deinit(); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /include/python/mraapy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Henry Bruce 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | void mraa_python_isr(void (*isr)(void*), void* isr_args); 11 | -------------------------------------------------------------------------------- /include/riscv/visionfive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Daniel Bovensiepen 3 | * Author: Zhu Jia Xing 4 | * Copyright (c) 2022 Siemens Ltd. China. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "mraa_internal.h" 16 | 17 | #define MRAA_VISIONFIVE_PINCOUNT 41 18 | 19 | mraa_board_t * 20 | mraa_visionfive(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | extern const char* gVERSION; 15 | extern const char* gVERSION_SHORT; 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /include/x86/iei_tank.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Tudor Panu 3 | * Copyright (c) 2018 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_IEI_TANK_PINCOUNT 9 17 | #define MRAA_IEI_TANK_UARTCOUNT 6 18 | 19 | mraa_board_t* 20 | mraa_iei_tank(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/x86/intel_adlink_lec_al.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Author: Gowtham R 3 | * Based on work from: Dan O'Donovan 4 | * Nicola Lunghi 5 | * Copyright (c) 2017 Emutex Ltd. 6 | * Copyright (c) 2014 Intel Corporation. 7 | * Copyright (c) 2019 ADLINK Technology Inc. 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | 12 | 13 | 14 | #pragma once 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "mraa_internal.h" 21 | 22 | // +1 as pins are "1 indexed" 23 | #define MRAA_LEC_AL_PINCOUNT (40 + 1) 24 | 25 | mraa_board_t* 26 | mraa_lec_al_board(); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /include/x86/intel_cherryhills.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Karena Anum Kamaruzaman 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // +1 as pins are "1 indexed" 17 | #define MRAA_INTEL_CHERRYHILLS_PINCOUNT (5 + 1) 18 | 19 | mraa_board_t* 20 | mraa_intel_cherryhills(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/x86/intel_de3815.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_DE3815_PINCOUNT 18 17 | 18 | mraa_board_t* 19 | mraa_intel_de3815(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/x86/intel_edison_fab_c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_EDISON_PINCOUNT 25 17 | 18 | mraa_board_t* 19 | mraa_intel_edison_fab_c(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/x86/intel_galileo_rev_d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_GALILEO_REV_D_PINCOUNT 25 17 | 18 | mraa_board_t* 19 | mraa_intel_galileo_rev_d(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/x86/intel_galileo_rev_g.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_GALILEO_GEN_2_PINCOUNT 25 17 | 18 | mraa_board_t* 19 | mraa_intel_galileo_gen2(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/x86/intel_ilk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Jeet Arora 3 | * Copyright (c) 2021 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // +1 as pins are "1 indexed" 17 | #define MRAA_INTEL_ILK_PINCOUNT (40 + 1) 18 | 19 | mraa_board_t* 20 | mraa_intel_ilk(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /include/x86/intel_joule_expansion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // +1 as pins are "1 indexed" 17 | // we have 20 useless pins then the 4 LEDS and the 2 LEDs on the module. 18 | // There is another pin for the built-in button. 19 | #define MRAA_INTEL_JOULE_EXPANSION_PINCOUNT (40 * 2 + 23 + 1 + 2 + 1) 20 | 21 | mraa_board_t* 22 | mraa_joule_expansion_board(); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/x86/intel_minnow_byt_compatible.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Thomas Ingleby 3 | * Copyright (c) 2014 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | // +1 as pins are "1 indexed" 17 | #define MRAA_INTEL_MINNOW_MAX_PINCOUNT (26 + 1) 18 | #define MRAA_INTEL_MINNOW_TURBOT_PINCOUNT (27 + 1) 19 | 20 | mraa_board_t* 21 | mraa_intel_minnowboard_byt_compatible(mraa_boolean_t); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /include/x86/intel_nuc5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Brendan Le Foll 3 | * Copyright (c) 2015 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_NUC5_PINCOUNT 18 17 | 18 | mraa_board_t* 19 | mraa_intel_nuc5(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /include/x86/intel_sofia_3gr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lay, Kuan Loon 3 | * Copyright (c) 2015 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "mraa_internal.h" 15 | 16 | #define MRAA_INTEL_SOFIA_3GR_PINCOUNT 8 17 | 18 | mraa_board_t* mraa_intel_sofia_3gr(); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /include/x86/up.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Dan O'Donovan 3 | * Copyright (c) 2015 Emutex Ltd. 4 | * Copyright (c) 2014 Intel Corporation. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "mraa_internal.h" 16 | 17 | // +1 as pins are "1 indexed" 18 | #define MRAA_UP_PINCOUNT (40 + 1) 19 | #define MRAA_UP_GPIOCOUNT (28) 20 | 21 | mraa_board_t* 22 | mraa_up_board(); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/x86/up2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Javier Arteaga 3 | * Based on work from: Dan O'Donovan 4 | * Nicola Lunghi 5 | * Copyright (c) 2017 Emutex Ltd. 6 | * Copyright (c) 2014 Intel Corporation. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "mraa_internal.h" 18 | 19 | // +1 as pins are "1 indexed" 20 | #define MRAA_UP2_PINCOUNT (40 + 1) 21 | 22 | mraa_board_t* 23 | mraa_up2_board(); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /include/x86/up_xtreme.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Michael Campion 3 | * Based on work from: Dan O'Donovan 4 | * Nicola Lunghi 5 | * Copyright (c) 2019 Emutex Ltd. 6 | * Copyright (c) 2014 Intel Corporation. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "mraa_internal.h" 18 | 19 | // +1 as pins are "1 indexed" 20 | #define MRAA_UPXTREME_PINCOUNT (40 + 1) 21 | 22 | mraa_board_t* 23 | mraa_upxtreme_board(); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /jsstub/Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: David Antler 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | module.exports = function(grunt) { 9 | grunt.loadNpmTasks('grunt-mocha-test'); 10 | // Project configuration. 11 | grunt.initConfig({ 12 | pkg: grunt.file.readJSON('package.json'), 13 | mochaTest: { 14 | test: { 15 | options: { 16 | reporter: 'spec' 17 | }, 18 | src: ['test/*.js'] 19 | } 20 | } 21 | }); 22 | 23 | grunt.registerTask('test', ['mochaTest:test']); 24 | }; 25 | -------------------------------------------------------------------------------- /jsstub/README.md: -------------------------------------------------------------------------------- 1 | mraaStub - JavaScript simulation and stubs for mraa 2 | ==================== 3 | 4 | This project enables simulation of a device which might be accessed via mraa. 5 | Currently this library supports I2c, SPI, and GPIO. This project provides 6 | several benefits: 7 | 8 | 1. Prevent crashes in nodejs applications using mraa on unsuported or 9 | misconfigured hardware. 10 | 2. Enable basic simulation of mraa-accessible devices for unit testing. 11 | 12 | ## Examples 13 | 14 | The following example is based on an imaginary 'light bulb' device abstraction, 15 | which exposes a value of brightness over a mraa-provided interface. Please see 16 | the `test/index.js` file for an example. 17 | 18 | ## Installation 19 | 20 | You may install `mraaStub` from npm like this: 21 | 22 | ``` 23 | npm install mraaStub 24 | ``` 25 | 26 | Since we often switch between a mraaStub and the real mraa library, we 27 | suggest creating an `index.js` file inside a `lib/mraaSwitcher` folder. 28 | 29 | ```js 30 | /* index.js - file for switching between mraa and mraaStub 31 | */ 32 | 33 | // Define the conditions under which the mraaStub should be loaded 34 | var platform = require('os').platform(); 35 | var m; 36 | 37 | if (platform === 'win32') { 38 | m = require('mraaStub'); 39 | } else { 40 | m = require('mraa'); 41 | } 42 | 43 | module.exports = m; 44 | ``` 45 | 46 | You can add this to your project in its own `lib/mraaSwitcher/index.js` file 47 | and use `require('../mraaSwitcher')` everywhere! 48 | 49 | ## License 50 | 51 | See [COPYING file](../COPYING) in the root of this repository. 52 | -------------------------------------------------------------------------------- /jsstub/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mraaStub", 3 | "version": "0.0.1", 4 | "description": "Enables simulation of mraa interfaces for testing purposes", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "grunt test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/intel-iot-devkit/mraa.git" 12 | }, 13 | "keywords": [ 14 | "mraa", 15 | "iot", 16 | "intel", 17 | "libmraa", 18 | "test", 19 | "galileo", 20 | "edison" 21 | ], 22 | "author": "David A Antler ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/intel-iot-devkit/mraa/issues" 26 | }, 27 | "homepage": "https://github.com/intel-iot-devkit/mraa#readme", 28 | "devDependencies": { 29 | "expect.js": "^0.3.1", 30 | "grunt": "^1.0.1", 31 | "grunt-mocha-test": "^0.12.7", 32 | "mocha": "^2.4.5" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jsstub/test/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: David Antler 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | var expect = require('expect.js'); 9 | var m = require('../index'); 10 | var LightBulb = require('./lightbulb'); 11 | 12 | describe('LightBulb', function() { 13 | 14 | /** Model the internal data of LightBulb as a buffer */ 15 | var bufferFullBrightness = new Buffer( 16 | [ 'N', // Four bytes allocated for name 17 | 'a', 18 | 'm', 19 | 'e', 20 | 95 // One byte allocated for brightness. Stuff in '95' value! 21 | ]); 22 | 23 | it('getBrightness() function should return 95', function() { 24 | 25 | // Create a fake I2c bus based on the 'full brightness' data model 26 | var testI2cBus = new m.I2c(0); 27 | testI2cBus._setRegisterMapInternal(bufferFullBrightness); 28 | 29 | // Create a new LightBulb that opens the testI2cBus, instead of a real 30 | // mraa I2c bus. 31 | var lightBulbI2c = new LightBulb(testI2cBus); 32 | 33 | // presumably getBrightness will gather data from I2C and get '95' 34 | var brightness = lightBulbI2c.getBrightness(); 35 | 36 | expect(brightness).to.be(95); 37 | }) 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /jsstub/test/lightbulb.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: David Antler 3 | * Copyright (c) 2016 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * 8 | * @fileoverview Implementation of a LightBulb class abstraction 9 | * 10 | */ 11 | 12 | module.exports = (function() { 13 | "use strict"; 14 | var m = require('../index'); 15 | 16 | /** 17 | * Constructor for a new LightBulb 18 | * @class LightBulb 19 | * 20 | * @classdesc This class abstracts access to the control and data registers 21 | * on an imaginary lightbulb. 22 | * @param {Object} A libmraa I2c object, initialized 23 | */ 24 | function LightBulb (i2cInterface) { 25 | var self = this; 26 | self._i2cInterface = i2cInterface; 27 | 28 | self.getBrightness = function() { 29 | // Presume our brightness data is one byte at offset 4 30 | return self._i2cInterface.readReg(4); 31 | } 32 | 33 | return self; 34 | } 35 | 36 | return LightBulb; 37 | })(); 38 | 39 | -------------------------------------------------------------------------------- /scripts/build-doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Author: Nicolas Oliver 4 | # Copyright (c) 2017 Intel Corporation. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -x 8 | set -e 9 | 10 | # Install doxygen2jsdoc dependencies 11 | cd doxygen2jsdoc && npm install && cd .. 12 | 13 | # Install doxyport dependencies 14 | cd doxyport && make setup && cd .. 15 | 16 | # Make Documentation 17 | make -j8 -Cbuild 18 | 19 | # Make Java Documentation 20 | cd build/src/java && echo ../../../src/mraa.i > mraa.i.list && \ 21 | ../../../doxyport/doxyport mraa.i.list \ 22 | --cmake ../../compile_commands.json \ 23 | --source ../../../api,../../../api/mraa \ 24 | --destination $(pwd)/ \ 25 | --convert-protected-to-private \ 26 | --output mraa-java-files.txt \ 27 | --mapping ../../../examples/samples.mapping.txt && \ 28 | doxygen Doxyfile && cd ../../../ 29 | 30 | # Copy output to build/html/ directory 31 | cp -r build/src/python/python3/docs/html build/html/python && \ 32 | cp -r build/src/java/html build/html/java && \ 33 | cp build/jsdoc/ternjs/mraa/doc.js build/html/node/mraa_tern.js 34 | -------------------------------------------------------------------------------- /scripts/run-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Author: Nicolas Oliver 4 | # Copyright (c) 2017 Intel Corporation. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -x 8 | set -e 9 | 10 | # Run cmake 11 | cmake \ 12 | -DBUILDARCH=$BUILDARCH \ 13 | -DBUILDDOC=$BUILDDOC \ 14 | -DBUILDSWIG=$BUILDSWIG \ 15 | -DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \ 16 | -DBUILDSWIGNODE=$BUILDSWIGNODE \ 17 | -DBUILDSWIGJAVA=$BUILDSWIGJAVA \ 18 | -DUSBPLAT=$USBPLAT \ 19 | -DFIRMATA=$FIRMATA \ 20 | -DONEWIRE=$ONEWIRE \ 21 | -DJSONPLAT=$JSONPLAT \ 22 | -DIMRAA=$IMRAA \ 23 | -DFTDI4222=$FTDI4222 \ 24 | -DENABLEEXAMPLES=$ENABLEEXAMPLES \ 25 | -DINSTALLTOOLS=$INSTALLTOOLS \ 26 | -DBUILDTESTS=$BUILDTESTS \ 27 | -DUSEPYTHON3TESTS=$USEPYTHON3TESTS \ 28 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ 29 | -H. \ 30 | -Bbuild 31 | -------------------------------------------------------------------------------- /src/arm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (INFO " - Adding ARM platforms") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_ARM_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /src/arm/siemens/platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Le Jin 3 | * Copyright (c) Siemens AG, 2019 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | #include 25 | #include "arm/siemens/platform.h" 26 | #include "arm/siemens/platform_iot2050.h" 27 | 28 | void * 29 | platfrom_pinmux_get_instance(char *platform) 30 | { 31 | pin_mux_interface_t *instance = NULL; 32 | if(!strcmp(platform, "iot2050")) { 33 | instance = iot2050_pinmux_get_instance(); 34 | } 35 | if((instance) && (instance->initialized == false) && (instance->ops.init)) { 36 | return instance->ops.init()?instance:NULL; 37 | } 38 | else { 39 | return NULL; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/firmata/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (FIRMATA) 2 | message (STATUS "INFO - Adding firmata backend support") 3 | set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 4 | ${PROJECT_SOURCE_DIR}/src/firmata/firmata.c 5 | ${PROJECT_SOURCE_DIR}/src/firmata/firmata_mraa.c 6 | PARENT_SCOPE 7 | ) 8 | endif () 9 | -------------------------------------------------------------------------------- /src/grovepi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 2 | ${PROJECT_SOURCE_DIR}/src/grovepi/grovepi.c 3 | PARENT_SCOPE 4 | ) 5 | -------------------------------------------------------------------------------- /src/i2c/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2005-2014 RoadNarrows LLC. 4 | http://roadnarrows.com 5 | All Rights Reserved 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/java/manifest.txt.in: -------------------------------------------------------------------------------- 1 | Manifest-version: 1.0 2 | 3 | Name: mraa/ 4 | Specification-Title: mraa 5 | Specification-Version: @VERSION_SHORT@ 6 | Package-Title: mraa 7 | Package-Version: @VERSION_SHORT@ 8 | -------------------------------------------------------------------------------- /src/java/mraajava.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib@LIB_SUFFIX@ 4 | includedir=${prefix}/include 5 | 6 | Name: mraa 7 | Description: Low Level Skeleton Library for Communication 8 | Version: @mraa_VERSION_STRING@ 9 | 10 | Libs: -L${libdir} -lmraajava 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /src/java/pom.xml.in: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.eclipse.mraa 8 | mraa 9 | @VERSION_SHORT@ 10 | jar 11 | 12 | mraa 13 | Low Level Skeleton Library for IO Communication on GNU/Linux platforms 14 | http://mraa.io 15 | 16 | 17 | 18 | MIT License 19 | https://github.com/eclipse/mraa/blob/master/COPYING 20 | 21 | 22 | 23 | 24 | 25 | Mraa contributors https://github.com/eclipse/mraa/graphs/contributors 26 | mraa@lists.01.org 27 | Eclipse Foundation 28 | https://github.com/eclipse 29 | 30 | 31 | 32 | 33 | scm:git:git://github.com/eclipse/mraa.git 34 | scm:git:ssh://github.com:eclipse/mraa.git 35 | https://github.com/eclipse/mraa/tree/master 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/javascript/binding.gyp.cmake: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'mraa', 5 | 'sources': [ 6 | @mraa_LIB_SRCS_GYP@ 7 | 'src/version.c', 8 | 'src/mraajsJAVASCRIPT_wrap.cxx' 9 | ], 10 | 'include_dirs': [ 11 | @mraa_LIB_INCLUDE_DIRS_GYP@ 12 | ], 13 | 'variables': { 14 | "v8_version%": " /dev/null || echo node` -e 'console.log(process.versions.v8)' | sed 's/\.//g' | cut -c 1-5)", 15 | "arch%": " /dev/null || echo node` -e 'console.log(process.arch)')" 16 | }, 17 | 'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 18 | 'cflags!': [ '-fno-exceptions' ], 19 | 'conditions' : [ 20 | ['OS=="android"', { 21 | 'sources' : [ 'src/glob/glob.c' ], 22 | 'include_dirs' : [ 'src/glob' ], 23 | }], 24 | [ 'arch=="x64" or arch=="ia32"', { 25 | 'defines' : [ 'X86PLAT=ON' ], 26 | }], 27 | [ 'arch=="arm"', { 28 | 'defines' : [ 'ARMPLAT=ON'], 29 | }], 30 | ], 31 | 'defines' : [ 32 | 'SWIG', 33 | 'SWIGJAVASCRIPT', 34 | 'FIRMATA=ON', 35 | 'ONEWIRE=ON', 36 | 'BUILDING_NODE_EXTENSION=1', 37 | 'SWIG_V8_VERSION=0x0<(v8_version)', 38 | 'V8_VERSION=0x0<(v8_version)' 39 | ] 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /src/javascript/package.json.cmake: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "mraa", 3 | "description": "IO library that helps you use I2c, SPI, gpio, uart, pwm, analog inputs (aio) and more on a number of platforms such as the Intel galileo, the Intel edison and others", 4 | "keywords":["gpio", "edison","galileo","io", "mraajs", "spi", "i2c", "minnow", "intel", "firmata"], 5 | "homepage": "http://github.com/intel-iot-devkit/mraa", 6 | "main" : "./mraa.node", 7 | "engines": { 8 | "node": ">= 0.10.x" 9 | }, 10 | "bugs": { 11 | "url" : "http://github.com/intel-iot-devkit/mraa/issues" 12 | }, 13 | "license": "MIT", 14 | "version": "@VERSION@", 15 | "authors": "See github.com/intel-iot-devkit/mraa/graphs/contributors", 16 | "scripts": { 17 | "test": "node -p -e 'require(\".\").getVersion()'" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/mips/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (INFO " - Adding MIPS platforms") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_MIPS_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /src/mips/mips.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Serge Vakulenko 3 | * Copyright (c) 2017 Serge Vakulenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "mraa_internal.h" 12 | #include "mips/mediatek.h" 13 | 14 | mraa_platform_t 15 | mraa_mips_platform() 16 | { 17 | mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; 18 | size_t len = 100; 19 | char* line = malloc(len); 20 | FILE* fh = fopen("/proc/cpuinfo", "r"); 21 | if (fh != NULL) { 22 | while (getline(&line, &len, fh) != -1) { 23 | if (strncmp(line, "machine", 7) == 0) { 24 | if (strstr(line, "MediaTek LinkIt Smart 7688")) { 25 | platform_type = MRAA_MTK_LINKIT; 26 | } 27 | if (strstr(line, "Onion Omega2")) { 28 | platform_type = MRAA_MTK_OMEGA2; 29 | } 30 | } 31 | } 32 | fclose(fh); 33 | } 34 | free(line); 35 | 36 | switch (platform_type) { 37 | case MRAA_MTK_LINKIT: 38 | plat = mraa_mtk_linkit(); 39 | break; 40 | case MRAA_MTK_OMEGA2: 41 | plat = mraa_mtk_omega2(); 42 | break; 43 | default: 44 | plat = NULL; 45 | syslog(LOG_ERR, "Unknown Platform, currently not supported by MRAA"); 46 | } 47 | return platform_type; 48 | } 49 | -------------------------------------------------------------------------------- /src/mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (INFO " - Adding mock platform") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_MOCK_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /src/mock/mock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | 10 | #include "mraa_internal.h" 11 | 12 | #include "mock/mock_board.h" 13 | 14 | mraa_platform_t 15 | mraa_mock_platform() 16 | { 17 | mraa_platform_t platform_type = MRAA_MOCK_PLATFORM; 18 | plat = mraa_mock_board(); 19 | 20 | if (plat == NULL) { 21 | syslog(LOG_ERR, "Was not able to initialize mock platform"); 22 | return MRAA_ERROR_PLATFORM_NOT_INITIALISED; 23 | } 24 | 25 | return platform_type; 26 | } 27 | -------------------------------------------------------------------------------- /src/mock/mock_board_aio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Alex Tereschenko 3 | * Copyright (c) 2016 Alex Tereschenko. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | #include "mock/mock_board_aio.h" 13 | 14 | mraa_result_t 15 | mraa_mock_aio_init_internal_replace(mraa_aio_context dev, int pin) 16 | { 17 | dev->channel = pin; 18 | return MRAA_SUCCESS; 19 | } 20 | 21 | mraa_result_t 22 | mraa_mock_aio_close_replace(mraa_aio_context dev) 23 | { 24 | free(dev); 25 | return MRAA_SUCCESS; 26 | } 27 | 28 | int 29 | mraa_mock_aio_read_replace(mraa_aio_context dev) 30 | { 31 | // return some random number between 0 and max value, based on the resolution 32 | int max_value = (1 << dev->value_bit) - 1; 33 | srand(time(NULL)); 34 | return rand() % max_value; 35 | } 36 | -------------------------------------------------------------------------------- /src/mraa.i: -------------------------------------------------------------------------------- 1 | %rename("%(strip:[MRAA_])s", %$isenumitem) ""; 2 | 3 | %include stdint.i 4 | %include std_string.i 5 | %include exception.i 6 | 7 | %{ 8 | #include "common.hpp" 9 | #include "types.hpp" 10 | #include "gpio.hpp" 11 | #include "pwm.hpp" 12 | #include "i2c.hpp" 13 | #include "spi.hpp" 14 | #include "aio.hpp" 15 | #include "uart.hpp" 16 | #include "led.hpp" 17 | %} 18 | 19 | %exception { 20 | try { 21 | $action 22 | } catch(const std::invalid_argument& e) { 23 | SWIG_exception(SWIG_ValueError, e.what()); 24 | } catch(...) { 25 | SWIG_exception(SWIG_RuntimeError, "Unknown exception"); 26 | } 27 | } 28 | 29 | %include "types.hpp" 30 | 31 | %include "common.hpp" 32 | %template (gpioFromDesc) mraa::initIo; 33 | %template (aioFromDesc) mraa::initIo; 34 | %template (uartFromDesc) mraa::initIo; 35 | %template (spiFromDesc) mraa::initIo; 36 | %template (i2cFromDesc) mraa::initIo; 37 | %template (pwmFromDesc) mraa::initIo; 38 | %template (ledFromDesc) mraa::initIo; 39 | 40 | %ignore Aio(void* aio_context); 41 | %ignore Pwm(void* pwm_context); 42 | %ignore Uart(void* uart_context); 43 | %ignore Spi(void* spi_context); 44 | %ignore I2c(void* i2c_context); 45 | %ignore Gpio(void* gpio_context); 46 | %ignore Led(void* led_context); 47 | 48 | %ignore Gpio::nop(uv_work_t* req); 49 | %ignore Gpio::v8isr(uv_work_t* req); 50 | %ignore Gpio::v8isr(uv_work_t* req, int status); 51 | %ignore Gpio::uvwork(void *ctx); 52 | %ignore isr(Edge mode, void (*fptr)(void*), void* args); 53 | 54 | %include "gpio.hpp" 55 | 56 | %include "i2c.hpp" 57 | 58 | %include "pwm.hpp" 59 | 60 | %include "spi.hpp" 61 | 62 | %include "aio.hpp" 63 | 64 | %include "uart.hpp" 65 | 66 | %include "led.hpp" 67 | -------------------------------------------------------------------------------- /src/mraa.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/@LIB_INSTALL_DIR@ 4 | includedir=${prefix}/include 5 | 6 | Name: mraa 7 | Description: Low Level Skeleton Library for Communication 8 | Version: @mraa_VERSION_STRING@ 9 | 10 | Libs: -L${libdir} -lmraa 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /src/peripheralman/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (STATUS "INFO - Adding Peripheral Manager platform") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_PERIPHERALMAN_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /src/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON) 2 | set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src") 3 | 4 | if (PYTHON3_LIBRARY) 5 | add_subdirectory (python3) 6 | endif () 7 | -------------------------------------------------------------------------------- /src/python/python3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set_source_files_properties (mraa3.i PROPERTIES CPLUSPLUS ON) 2 | set_source_files_properties (mraa3.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src") 3 | 4 | message (STATUS "PYTHON3 attempting to build!") 5 | 6 | if (CMAKE_VERSION VERSION_LESS "3.8") 7 | swig_add_module (python3-mraa python mraa3.i ../mraapy.c) 8 | else () 9 | swig_add_library (python3-mraa LANGUAGE python SOURCES mraa3.i ../mraapy.c) 10 | endif () 11 | swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa) 12 | 13 | target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME} 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/../.." 16 | "${PYTHON3_INCLUDE_DIR}" 17 | ) 18 | 19 | if (DOXYGEN_FOUND AND PYTHON3_EXECUTABLE) 20 | foreach (_file ${DOCCLASSES}) 21 | add_dependencies (${SWIG_MODULE_python3-mraa_REAL_NAME} ${_file}class_doc_i) 22 | endforeach () 23 | add_dependencies (${SWIG_MODULE_python3-mraa_REAL_NAME} common_hpp_doc_i) 24 | endif () 25 | 26 | set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES 27 | OUTPUT_NAME _mraa 28 | COMPILE_FLAGS "-DSWIGPYTHON=${SWIG_FOUND} -DSWIGPYTHON3=${SWIG_FOUND}" 29 | ) 30 | 31 | install (TARGETS ${SWIG_MODULE_python3-mraa_REAL_NAME} 32 | DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH} 33 | ) 34 | 35 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.py 36 | DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH} 37 | ) 38 | 39 | add_subdirectory (docs) 40 | -------------------------------------------------------------------------------- /src/python/python3/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (DOXYGEN_FOUND) 2 | find_package (Sphinx 1.3 REQUIRED) 3 | if (SPHINX_FOUND AND SPHINX_VERSION VERSION_GREATER "1.3") 4 | if (NOT DEFINED SPHINX_THEME) 5 | set (SPHINX_THEME default) 6 | endif () 7 | 8 | if (NOT DEFINED SPHINX_THEME_DIR) 9 | set (SPHINX_THEME_DIR) 10 | endif () 11 | 12 | # configured documentation tools and intermediate build results 13 | set (BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") 14 | 15 | # Sphinx cache with pickled ReST documents 16 | set (SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/doctrees") 17 | 18 | # HTML output directory 19 | set (SPHINX_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/html") 20 | 21 | # doc .rst locations 22 | set (SPHINX_DOC_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") 23 | 24 | configure_file( 25 | "${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in" 26 | "${BINARY_BUILD_DIR}/conf.py" 27 | @ONLY 28 | ) 29 | 30 | add_custom_target(sphinx ALL 31 | ${SPHINX_EXECUTABLE} -b html 32 | -c "${BINARY_BUILD_DIR}" 33 | -d "${SPHINX_CACHE_DIR}" 34 | "${SPHINX_DOC_LOCATION}" 35 | "${SPHINX_HTML_DIR}" 36 | COMMENT "Building HTML documentation with Sphinx" 37 | ) 38 | 39 | add_dependencies (sphinx ${SWIG_MODULE_python3-mraa_REAL_NAME}) 40 | else () 41 | message (SEND_ERROR "ERROR - Failed to find a compatible version of Sphinx. Python API doc will not be generated") 42 | endif (SPHINX_FOUND AND SPHINX_VERSION VERSION_GREATER "1.3") 43 | endif () 44 | -------------------------------------------------------------------------------- /src/python/python3/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. . documentation master file, created by 2 | sphinx-quickstart on Thu May 1 18:34:23 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to mraa's documentation! 7 | ================================ 8 | 9 | .. include:: ../../../../docs/index.md 10 | :start-after: ============== 11 | :end-before: ## API 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | mraa 17 | example 18 | 19 | Supported Platforms 20 | =================== 21 | 22 | * `Galileo Gen 1 - Rev D <../galileorevd.html>`_ 23 | * `Galileo Gen 2 - Rev H <../galileorevh.html>`_ 24 | * `Intel Edison <../edison.html>`_ 25 | * `Intel(R) NUC DE3815tykhe <../de3815.html>`_ 26 | * `Intel(R) Minnowboard Max <../minnowmax.html>`_ 27 | * `Raspberry Pi <../rasppi.html>`_ 28 | * `Banana Pi/Pro <../bananapi.html>`_ 29 | * `Beaglebone Black <../beaglebone.html>`_ 30 | * `phyBOARD-Wega <../phyboard-wega.html>`_ 31 | * `Intel NUC NUC5i5MYBE <../nuc5.html>`_ 32 | * `UP <../up.html>`_ 33 | * `UP Squared<../up2.html>`_ 34 | * `FTDI FT4222H <../ft4222.html>`_ 35 | 36 | Compiling & Debugging libmraa 37 | ============================= 38 | 39 | Libmraa is a C library and SWIG is used to generate bindings therefore to 40 | debug, you very quickly need to use the same methods as you would for debugging 41 | a C library. Generally attaching gdb to python works well, build mraa with 42 | debug symbols and set breakpoints either in the SWIG _wrap functions, the C++ 43 | method/functions or the underlying C function. More info can be found on the 44 | C/C++ documentation: 45 | 46 | * `Debugging <../debugging.html>`_ 47 | * `Building from source <../building.html>`_ 48 | 49 | API Changelog 50 | ============= 51 | 52 | `Changelog <../changelog.html>`_ 53 | 54 | 55 | Indices and tables 56 | ================== 57 | 58 | * :ref:`genindex` 59 | * :ref:`modindex` 60 | * :ref:`search` 61 | 62 | -------------------------------------------------------------------------------- /src/python/python3/docs/mraa.rst: -------------------------------------------------------------------------------- 1 | ### 2 | API 3 | ### 4 | 5 | Aio 6 | === 7 | .. autoclass:: mraa.Aio 8 | :members: 9 | :undoc-members: 10 | :show-inheritance: 11 | 12 | I2c 13 | === 14 | .. autoclass:: mraa.I2c 15 | :members: 16 | :undoc-members: 17 | :show-inheritance: 18 | 19 | Gpio 20 | ==== 21 | .. autoclass:: mraa.Gpio 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | Led 27 | === 28 | .. autoclass:: mraa.Led 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | 33 | Pwm 34 | === 35 | .. autoclass:: mraa.Pwm 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | 40 | Spi 41 | === 42 | .. autoclass:: mraa.Spi 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Uart 48 | ==== 49 | .. autoclass:: mraa.Uart 50 | :members: 51 | :undoc-members: 52 | :show-inheritance: 53 | 54 | Common 55 | ====== 56 | 57 | .. automodule:: mraa 58 | :members: 59 | :exclude-members: Gpio, Led, Aio, Uart, Spi, I2c, Pwm, uint8Array, uint8Array_frompointer 60 | -------------------------------------------------------------------------------- /src/python/python3/mraa3.i: -------------------------------------------------------------------------------- 1 | %module(docstring="Python interface to libmraa") mraa 2 | 3 | %include ../mraapython.i 4 | -------------------------------------------------------------------------------- /src/riscv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (INFO " - Adding RISC-V platforms") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_RISCV_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /src/riscv/riscv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Daniel Bovensiepen 3 | * Author: Zhu Jia Xing 4 | * Copyright (c) 2022 Siemens Ltd. China. 5 | * 6 | * SPDX-License-Identifier: MIT 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include "riscv/visionfive.h" 13 | #include "mraa_internal.h" 14 | 15 | mraa_platform_t 16 | mraa_riscv_platform() 17 | { 18 | mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; 19 | if (mraa_file_contains("/proc/device-tree/compatible", "visionfive")) { 20 | platform_type = MRAA_VISIONFIVE; 21 | } 22 | 23 | switch (platform_type) { 24 | case MRAA_VISIONFIVE: 25 | plat = mraa_visionfive(); 26 | break; 27 | 28 | default: 29 | plat = NULL; 30 | syslog(LOG_ERR, "Unknown Platform, currently not supported by MRAA"); 31 | } 32 | return platform_type; 33 | } 34 | -------------------------------------------------------------------------------- /src/uart_ow/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (ONEWIRE) 2 | message (STATUS "INFO - Adding onewire backend support") 3 | set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 4 | ${PROJECT_SOURCE_DIR}/src/uart_ow/uart_ow.c 5 | PARENT_SCOPE 6 | ) 7 | endif () 8 | -------------------------------------------------------------------------------- /src/usb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(ft4222) 2 | -------------------------------------------------------------------------------- /src/usb/ft4222/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (FTDI4222) 2 | set(target_name mraa-platform-ft4222) 3 | add_library(${target_name} SHARED ftdi_ft4222.cxx ftdi_ft4222.hpp) 4 | target_link_libraries(${target_name} ${LIBFT4222_LIBRARIES}) 5 | install(TARGETS ${target_name} DESTINATION ${LIB_INSTALL_DIR}) 6 | 7 | set_target_properties( 8 | ${target_name} 9 | PROPERTIES 10 | SOVERSION ${mraa_VERSION_MAJOR} 11 | VERSION ${mraa_VERSION_STRING} 12 | ) 13 | if (MSYS) 14 | # Under MSYS we have to put our generated DLL into bin, otherwise it's not picked up 15 | install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_BINDIR}) 16 | else () 17 | install(TARGETS ${target_name} DESTINATION ${LIB_INSTALL_DIR}) 18 | endif () 19 | endif() 20 | -------------------------------------------------------------------------------- /src/usb/ft4222/ftdi_ft4222.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _EXPORT_USERS_NECK_MRAA_FT4222_SRC_USB_FT4222_FTDI_FT4222_HPP 2 | #define _EXPORT_USERS_NECK_MRAA_FT4222_SRC_USB_FT4222_FTDI_FT4222_HPP 3 | 4 | /* 5 | * Author: Henry Bruce 6 | * Copyright (c) 2015 Intel Corporation. 7 | * 8 | * SPDX-License-Identifier: MIT 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | 16 | #include 17 | #include "mraa_internal.h" 18 | 19 | /** 20 | * Attempt to initialize a mraa_board_t for a UMFT4222EV module 21 | * 22 | * @param board Pointer to valid board structure. If a mraa_board_t 23 | * is initialized, it will be added to board->sub_platform 24 | * 25 | * @return MRAA_SUCCESS if a valid subplaform has been initialized, 26 | * otherwise return MRAA_ERROR_PLATFORM_NOT_INITIALISED 27 | */ 28 | mraa_result_t mraa_usb_platform_extender(mraa_board_t* board); 29 | 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/x86/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message (STATUS "INFO - Adding x86 platforms") 2 | set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} 3 | ${mraa_LIB_X86_SRCS_NOAUTO} PARENT_SCOPE) 4 | -------------------------------------------------------------------------------- /tests/check_clean.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright (c) 2016 Intel Corporation. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import unittest as u 6 | import re, fnmatch, os 7 | 8 | rootDir = 'src/java' 9 | swigtypeStr = 'SWIGTYPE' 10 | 11 | class Clean(u.TestCase): 12 | 13 | def test_existing_swigtype(self): 14 | unclean = [] 15 | 16 | for fileName in os.listdir(rootDir): 17 | if swigtypeStr in fileName: 18 | unclean.append(fileName) 19 | 20 | self.assertEqual( len(unclean), 0, 21 | "\nmraa contains unclean Java bindings:\n" + \ 22 | "\n".join(unclean) + "\n\n") 23 | 24 | if __name__ == '__main__': 25 | u.main() 26 | -------------------------------------------------------------------------------- /tests/general_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Costin Constantin 4 | # Copyright (c) 2015 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | from __future__ import print_function 9 | 10 | import mraa as m 11 | import unittest as u 12 | 13 | class GeneralChecks(u.TestCase): 14 | def test_mraa_version(self): 15 | self.version = m.getVersion() 16 | print("Version is: " + self.version) 17 | self.assertIsNotNone(self.version) 18 | 19 | if __name__ == "__main__": 20 | u.main() 21 | -------------------------------------------------------------------------------- /tests/mock/aio_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_AIO_TEST_PIN = 0 12 | PLATFORM_STD_ADC_RES_BITS = 10 13 | PLATFORM_MAX_ADC_RES_BITS = 12 14 | 15 | class AioChecks(u.TestCase): 16 | def setUp(self): 17 | self.pin = m.Aio(MRAA_AIO_TEST_PIN) 18 | 19 | def tearDown(self): 20 | del self.pin 21 | 22 | def test_aio_get_bit(self): 23 | self.assertEqual(self.pin.getBit(), PLATFORM_STD_ADC_RES_BITS, "Wrong ADC resolution reported") 24 | 25 | def test_aio_set_bit(self): 26 | self.pin.setBit(PLATFORM_MAX_ADC_RES_BITS) 27 | self.assertEqual(self.pin.getBit(), PLATFORM_MAX_ADC_RES_BITS, "Wrong ADC resolution reported after setBit()") 28 | 29 | def test_aio_read(self): 30 | self.assertNotEqual(self.pin.read(), -1, "Error returned when reading ADC value") 31 | 32 | def test_aio_read_float_std_res(self): 33 | self.pin.setBit(PLATFORM_STD_ADC_RES_BITS) 34 | self.assertNotEqual(self.pin.readFloat(), -1, "Error returned when reading float ADC value at standard resolution") 35 | 36 | def test_aio_read_float_max_res(self): 37 | self.pin.setBit(PLATFORM_MAX_ADC_RES_BITS) 38 | self.assertNotEqual(self.pin.readFloat(), -1, "Error returned when reading float ADC value at maximum resolution") 39 | 40 | if __name__ == "__main__": 41 | u.main() 42 | -------------------------------------------------------------------------------- /tests/mock/general_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Costin Constantin 4 | # Copyright (c) 2015 Intel Corporation. 5 | # 6 | # Contributors: Alex Tereschenko 7 | # 8 | # SPDX-License-Identifier: MIT 9 | 10 | import mraa as m 11 | import unittest as u 12 | 13 | class GeneralChecks(u.TestCase): 14 | def test_mraa_version(self): 15 | version = m.getVersion() 16 | print("Version is: " + version) 17 | self.assertIsNotNone(version) 18 | self.assertNotEqual(version, "", "MRAA version is an empty string") 19 | 20 | if __name__ == "__main__": 21 | u.main() 22 | -------------------------------------------------------------------------------- /tests/mock/gpio_checks_basic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_TEST_PIN = 0 12 | 13 | class GpioChecksBasic(u.TestCase): 14 | def setUp(self): 15 | self.pin = m.Gpio(MRAA_TEST_PIN) 16 | 17 | def tearDown(self): 18 | del self.pin 19 | 20 | def test_gpio_state_after_init(self): 21 | # After GPIO init it should be in INPUT and LOW state 22 | self.assertEqual(self.pin.read(), 0, "GPIO is in a wrong state after init") 23 | 24 | def test_gpio_dir_after_init(self): 25 | # After GPIO init it should be in INPUT and LOW state 26 | self.assertEqual(self.pin.readDir(), m.DIR_IN, "GPIO has wrong direction after init") 27 | 28 | def test_get_pin_num(self): 29 | self.assertEqual(self.pin.getPin(), MRAA_TEST_PIN, "Returned GPIO pin number is incorrect") 30 | 31 | if __name__ == '__main__': 32 | u.main() 33 | -------------------------------------------------------------------------------- /tests/mock/gpio_checks_edge.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_TEST_PIN = 0 12 | 13 | class GpioChecksEdge(u.TestCase): 14 | def setUp(self): 15 | self.pin = m.Gpio(MRAA_TEST_PIN) 16 | 17 | def tearDown(self): 18 | del self.pin 19 | 20 | def test_set_edge_mode_NONE(self): 21 | res = self.pin.edge(m.EDGE_NONE) 22 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_NONE did not return unimplemented") 23 | 24 | def test_set_edge_mode_BOTH(self): 25 | res = self.pin.edge(m.EDGE_BOTH) 26 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_BOTH did not return unimplemented") 27 | 28 | def test_set_edge_mode_RISING(self): 29 | res = self.pin.edge(m.EDGE_RISING) 30 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_RISING did not return unimplemented") 31 | 32 | def test_set_edge_mode_FALLING(self): 33 | res = self.pin.edge(m.EDGE_FALLING) 34 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_FALLING did not return unimplemented") 35 | 36 | if __name__ == '__main__': 37 | u.main() 38 | -------------------------------------------------------------------------------- /tests/mock/gpio_checks_isr.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_TEST_PIN = 0 12 | 13 | def test_isr(): 14 | print("In the ISR") 15 | 16 | class GpioChecksIsr(u.TestCase): 17 | def setUp(self): 18 | self.pin = m.Gpio(MRAA_TEST_PIN) 19 | 20 | def tearDown(self): 21 | del self.pin 22 | 23 | def test_set_isr(self): 24 | self.pin.dir(m.DIR_IN) 25 | res = self.pin.isr(m.EDGE_BOTH, test_isr, None) 26 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Enabling ISR did not return unimplemented") 27 | 28 | def test_isr_exit(self): 29 | self.pin.dir(m.DIR_IN) 30 | self.pin.isr(m.EDGE_BOTH, test_isr, None) 31 | res = self.pin.isrExit() 32 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Calling isrExit() did not return unimplemented") 33 | 34 | if __name__ == '__main__': 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/gpio_checks_mode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_TEST_PIN = 0 12 | 13 | class GpioChecksMode(u.TestCase): 14 | def setUp(self): 15 | self.pin = m.Gpio(MRAA_TEST_PIN) 16 | 17 | def tearDown(self): 18 | del self.pin 19 | 20 | def test_set_mode_STRONG(self): 21 | res = self.pin.mode(m.MODE_STRONG) 22 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_STRONG did not return unimplemented") 23 | 24 | def test_set_mode_PULLUP(self): 25 | res = self.pin.mode(m.MODE_PULLUP) 26 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_PULLUP did not return unimplemented") 27 | 28 | def test_set_mode_PULLDOWN(self): 29 | res = self.pin.mode(m.MODE_PULLDOWN) 30 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_PULLDOWN did not return unimplemented") 31 | 32 | def test_set_mode_HIZ(self): 33 | res = self.pin.mode(m.MODE_HIZ) 34 | self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_HIZ did not return unimplemented") 35 | 36 | if __name__ == '__main__': 37 | u.main() 38 | -------------------------------------------------------------------------------- /tests/mock/gpio_checks_write_read.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | MRAA_TEST_PIN = 0 12 | 13 | class GpioChecksWriteRead(u.TestCase): 14 | def setUp(self): 15 | self.pin = m.Gpio(MRAA_TEST_PIN) 16 | 17 | def tearDown(self): 18 | del self.pin 19 | 20 | def test_gpio_as_output_write_HIGH(self): 21 | self.pin.dir(m.DIR_OUT) 22 | res = self.pin.write(1) 23 | self.assertEqual(res, m.SUCCESS, "Setting GPIO to HIGH failed") 24 | res = self.pin.read() 25 | self.assertEqual(res, 1, "GPIO is not HIGH after write(1)") 26 | 27 | def test_gpio_as_output_write_LOW(self): 28 | self.pin.dir(m.DIR_OUT) 29 | res = self.pin.write(0) 30 | self.assertEqual(res, m.SUCCESS, "Setting GPIO to LOW failed") 31 | res = self.pin.read() 32 | self.assertEqual(res, 0, "GPIO is not LOW after write(0)") 33 | 34 | def test_gpio_as_output_write_invalid(self): 35 | self.pin.dir(m.DIR_OUT) 36 | value = 10 37 | res = self.pin.write(value) 38 | self.assertNotEqual(res, m.SUCCESS, "Writing " + str(value) + " to GPIO should have failed") 39 | res = self.pin.read() 40 | self.assertNotEqual(res, value, "Writing " + str(value) + " to GPIO should not have set it to " + str(value)) 41 | 42 | def test_gpio_as_input_write_HIGH(self): 43 | self.pin.dir(m.DIR_IN) 44 | res = self.pin.write(1) 45 | self.assertNotEqual(res, m.SUCCESS, "Setting GPIO in INPUT to HIGH should have failed") 46 | 47 | def test_gpio_as_input_write_LOW(self): 48 | self.pin.dir(m.DIR_IN) 49 | res = self.pin.write(0) 50 | self.assertNotEqual(res, m.SUCCESS, "Setting GPIO in INPUT to LOW should have failed") 51 | 52 | if __name__ == '__main__': 53 | u.main() 54 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_addr.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksAddr(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_address(self): 21 | self.assertEqual(self.i2c.address(0x10), 22 | m.SUCCESS, 23 | "Setting address to 0x10 did not return success") 24 | 25 | def test_i2c_address_invalid_bigger_than_max(self): 26 | # For standard 7-bit addressing 0x7F is max address 27 | self.assertEqual(self.i2c.address(0xFF), 28 | m.ERROR_INVALID_PARAMETER, 29 | "Setting address to 0xFF did not return INVALID_PARAMETER") 30 | 31 | def test_i2c_address_invalid_smaller_than_min(self): 32 | self.assertRaises(OverflowError, self.i2c.address, -100) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_freq.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksFreq(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_frequency_STD(self): 21 | self.assertEqual(self.i2c.frequency(m.I2C_STD), 22 | m.SUCCESS, 23 | "Setting frequency to I2C_STD did not return success") 24 | 25 | def test_i2c_frequency_FAST(self): 26 | self.assertEqual(self.i2c.frequency(m.I2C_FAST), 27 | m.SUCCESS, 28 | "Setting frequency to I2C_FAST did not return success") 29 | 30 | def test_i2c_frequency_HIGH(self): 31 | self.assertEqual(self.i2c.frequency(m.I2C_HIGH), 32 | m.SUCCESS, 33 | "Setting frequency to I2C_HIGH did not return success") 34 | 35 | def test_i2c_frequency_invalid_bigger_than_max(self): 36 | self.assertEqual(self.i2c.frequency(100), 37 | m.ERROR_INVALID_PARAMETER, 38 | "Setting frequency to 100 did not return INVALID_PARAMETER") 39 | 40 | def test_i2c_frequency_invalid_smaller_than_min(self): 41 | self.assertEqual(self.i2c.frequency(-100), 42 | m.ERROR_INVALID_PARAMETER, 43 | "Setting frequency to -100 did not return INVALID_PARAMETER") 44 | 45 | if __name__ == "__main__": 46 | u.main() 47 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_read.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksRead(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_read_full_reg_range(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | expected_res = bytearray([MRAA_MOCK_I2C_DATA_INIT_BYTE for i in range(MRAA_MOCK_I2C_DATA_LEN)]) 23 | res = self.i2c.read(MRAA_MOCK_I2C_DATA_LEN) 24 | self.assertEqual(res, expected_res, "I2C read() of full register range returned unexpected data") 25 | 26 | def test_i2c_read_part_reg_range(self): 27 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 28 | expected_res = bytearray([MRAA_MOCK_I2C_DATA_INIT_BYTE for i in range(MRAA_MOCK_I2C_DATA_LEN - 1)]) 29 | res = self.i2c.read(MRAA_MOCK_I2C_DATA_LEN - 1) 30 | self.assertEqual(res, expected_res, "I2C read() of partial register range returned unexpected data") 31 | 32 | def test_i2c_read_invalid_addr(self): 33 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 34 | self.assertRaises(IOError, self.i2c.read, MRAA_MOCK_I2C_DATA_LEN) 35 | 36 | def test_i2c_read_invalid_len_bigger_than_max(self): 37 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 38 | self.assertRaises(IOError, self.i2c.read, MRAA_MOCK_I2C_DATA_LEN + 1) 39 | 40 | if __name__ == "__main__": 41 | u.main() 42 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_read_byte.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksReadByte(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_read_byte(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | expected_res = MRAA_MOCK_I2C_DATA_INIT_BYTE 23 | res = self.i2c.readByte() 24 | self.assertEqual(res, expected_res, "I2C readByte() returned unexpected data") 25 | 26 | def test_i2c_read_byte_invalid_addr(self): 27 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 28 | self.assertRaises(ValueError, self.i2c.readByte) 29 | 30 | if __name__ == "__main__": 31 | u.main() 32 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_read_byte_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksReadByteData(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_read_byte_data(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | expected_res = MRAA_MOCK_I2C_DATA_INIT_BYTE 23 | res = self.i2c.readReg(MRAA_MOCK_I2C_DATA_LEN - 1) 24 | self.assertEqual(res, expected_res, "I2C readReg() returned unexpected data") 25 | 26 | def test_i2c_read_byte_data_invalid_addr(self): 27 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 28 | self.assertRaises(ValueError, self.i2c.readReg, MRAA_MOCK_I2C_DATA_LEN - 1) 29 | 30 | def test_i2c_read_byte_data_invalid_reg(self): 31 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 32 | self.assertRaises(ValueError, self.i2c.readReg, MRAA_MOCK_I2C_DATA_LEN) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_read_word_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksReadWordData(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_read_word_data(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | high_byte = 0xAA 23 | low_byte = 0xBB 24 | expected_res = (high_byte << 8) + low_byte 25 | self.i2c.writeReg(MRAA_MOCK_I2C_DATA_LEN - 2, high_byte) 26 | self.i2c.writeReg(MRAA_MOCK_I2C_DATA_LEN - 1, low_byte) 27 | res = self.i2c.readWordReg(MRAA_MOCK_I2C_DATA_LEN - 2) 28 | self.assertEqual(res, expected_res, "I2C readWordReg() returned unexpected data") 29 | 30 | def test_i2c_read_word_data_invalid_addr(self): 31 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 32 | self.assertRaises(ValueError, self.i2c.readWordReg, MRAA_MOCK_I2C_DATA_LEN - 2) 33 | 34 | def test_i2c_read_word_data_invalid_reg(self): 35 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 36 | self.assertRaises(ValueError, self.i2c.readReg, MRAA_MOCK_I2C_DATA_LEN) 37 | 38 | if __name__ == "__main__": 39 | u.main() 40 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_shared.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | MRAA_I2C_BUS_NUM = 0 9 | # These are defined in mock_board.c 10 | MRAA_MOCK_I2C_ADDR = 0x33 11 | MRAA_MOCK_I2C_DATA_LEN = 10 12 | MRAA_MOCK_I2C_DATA_INIT_BYTE = 0xAB 13 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_write_byte.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksWriteByte(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_write_byte(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | test_byte = 0xEE 23 | self.assertEqual(self.i2c.writeByte(test_byte), 24 | m.SUCCESS, 25 | "I2C writeByte() did not return success") 26 | self.assertEqual(self.i2c.readByte(), 27 | test_byte, 28 | "I2C readByte() after writeByte() returned unexpected data") 29 | 30 | def test_i2c_write_byte_invalid_addr(self): 31 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 32 | self.assertEqual(self.i2c.writeByte(0xEE), 33 | m.ERROR_UNSPECIFIED, 34 | "I2C writeByte() to invalid address did not return error") 35 | 36 | if __name__ == "__main__": 37 | u.main() 38 | -------------------------------------------------------------------------------- /tests/mock/i2c_checks_write_byte_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from i2c_checks_shared import * 12 | 13 | class I2cChecksWriteByteData(u.TestCase): 14 | def setUp(self): 15 | self.i2c = m.I2c(MRAA_I2C_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.i2c 19 | 20 | def test_i2c_write_byte_data(self): 21 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 22 | test_byte = 0xEE 23 | reg = MRAA_MOCK_I2C_DATA_LEN - 1 24 | self.assertEqual(self.i2c.writeReg(reg, test_byte), 25 | m.SUCCESS, 26 | "I2C writeReg() did not return success") 27 | self.assertEqual(self.i2c.readReg(reg), 28 | test_byte, 29 | "I2C readReg() after writeReg() returned unexpected data") 30 | 31 | def test_i2c_write_byte_data_invalid_addr(self): 32 | self.i2c.address(MRAA_MOCK_I2C_ADDR - 1) 33 | test_byte = 0xEE 34 | reg = MRAA_MOCK_I2C_DATA_LEN - 1 35 | self.assertEqual(self.i2c.writeReg(reg, test_byte), 36 | m.ERROR_UNSPECIFIED, 37 | "I2C writeReg() to invalid address did not return error") 38 | 39 | def test_i2c_write_byte_data_invalid_reg(self): 40 | self.i2c.address(MRAA_MOCK_I2C_ADDR) 41 | test_byte = 0xEE 42 | reg = MRAA_MOCK_I2C_DATA_LEN 43 | self.assertEqual(self.i2c.writeReg(reg, test_byte), 44 | m.ERROR_UNSPECIFIED, 45 | "I2C writeReg() with invalid register did not return error") 46 | 47 | if __name__ == "__main__": 48 | u.main() 49 | -------------------------------------------------------------------------------- /tests/mock/platform_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Costin Constantin 4 | # Copyright (c) 2015 Intel Corporation. 5 | # 6 | # Contributors: Alex Tereschenko 7 | # 8 | # SPDX-License-Identifier: MIT 9 | 10 | import mraa as m 11 | import unittest as u 12 | 13 | PLATFORM_PINCOUNT = 10 14 | PLATFORM_STD_ADC_RES_BITS = 10 15 | PLATFORM_MAX_ADC_RES_BITS = 12 16 | 17 | class PlatformChecks(u.TestCase): 18 | def test_platform_pin_count(self): 19 | self.assertEqual(m.getPinCount(), PLATFORM_PINCOUNT, "Wrong number of pins reported by platform") 20 | 21 | def test_adc_std_res(self): 22 | adc_std_res = m.adcSupportedBits() 23 | print("Platform ADC standard resolution is: " + str(adc_std_res) + " bits") 24 | self.assertEqual(adc_std_res, PLATFORM_STD_ADC_RES_BITS, "Wrong ADC standard resolution") 25 | 26 | def test_adc_max_res(self): 27 | adc_max_res = m.adcRawBits() 28 | print("Platform ADC max. resolution is: " + str(adc_max_res) + " bits") 29 | self.assertEqual(adc_max_res, PLATFORM_MAX_ADC_RES_BITS, "Wrong ADC max. resolution") 30 | 31 | if __name__ == "__main__": 32 | u.main() 33 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_bit_per_word.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksBitPerWord(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_bit_per_word(self): 21 | TEST_BIT_PER_WORD = 16 22 | self.assertEqual(self.spi.bitPerWord(TEST_BIT_PER_WORD), 23 | m.SUCCESS, 24 | "Setting bit per word to %d did not return success" %TEST_BIT_PER_WORD) 25 | 26 | def test_i2c_frequency_invalid_smaller_than_min(self): 27 | TEST_BIT_PER_WORD = -100 28 | self.assertRaises(OverflowError, self.spi.bitPerWord, TEST_BIT_PER_WORD) 29 | 30 | if __name__ == "__main__": 31 | u.main() 32 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_freq.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksFreq(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_set_freq(self): 21 | TEST_FREQ = 20000000 22 | self.assertEqual(self.spi.frequency(TEST_FREQ), 23 | m.SUCCESS, 24 | "Setting SPI frequency to %d did not return success" %TEST_FREQ) 25 | 26 | def test_spi_set_freq_invalid_smaller_than_min_zero(self): 27 | TEST_FREQ = 0 28 | self.assertEqual(self.spi.frequency(TEST_FREQ), 29 | m.ERROR_INVALID_PARAMETER, 30 | "Setting SPI frequency to %d did not return error" %TEST_FREQ) 31 | 32 | def test_spi_set_freq_invalid_smaller_than_min_negative(self): 33 | TEST_FREQ = -10 34 | self.assertEqual(self.spi.frequency(TEST_FREQ), 35 | m.ERROR_INVALID_PARAMETER, 36 | "Setting SPI frequency to %d did not return error" %TEST_FREQ) 37 | 38 | if __name__ == "__main__": 39 | u.main() 40 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_lsbmode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksLsbmode(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_set_lsbmode_false(self): 21 | TEST_LSBMODE = False 22 | self.assertEqual(self.spi.lsbmode(TEST_LSBMODE), 23 | m.SUCCESS, 24 | "Setting LSB mode to %s did not return success" %TEST_LSBMODE) 25 | 26 | def test_spi_set_lsbmode_true(self): 27 | TEST_LSBMODE = True 28 | self.assertEqual(self.spi.lsbmode(TEST_LSBMODE), 29 | m.SUCCESS, 30 | "Setting LSB mode to %s did not return success" %TEST_LSBMODE) 31 | 32 | def test_spi_set_lsbmode_invalid(self): 33 | TEST_LSBMODE = 10 34 | self.assertRaises(TypeError, self.spi.lsbmode, TEST_LSBMODE) 35 | 36 | 37 | if __name__ == "__main__": 38 | u.main() 39 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_shared.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | MRAA_SPI_BUS_NUM = 0 9 | MOCK_SPI_REPLY_DATA_MODIFIER_BYTE = 0xAB 10 | MOCK_SPI_REPLY_DATA_MODIFIER_WORD = 0xABBA 11 | MOCK_SPI_TEST_DATA_LEN = 5 12 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_write.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksWrite(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_write(self): 21 | DATA_TO_WRITE = bytearray([0xEE for i in range(MOCK_SPI_TEST_DATA_LEN)]) 22 | DATA_TO_EXPECT = bytearray([0xEE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE for i in range(MOCK_SPI_TEST_DATA_LEN)]) 23 | self.assertEqual(self.spi.write(DATA_TO_WRITE), 24 | DATA_TO_EXPECT, 25 | "SPI write() returned unexpected data") 26 | 27 | if __name__ == "__main__": 28 | u.main() 29 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_write_byte.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksWriteByte(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_write_byte(self): 21 | TEST_BYTE = 0xEE 22 | self.assertEqual(self.spi.writeByte(TEST_BYTE), 23 | TEST_BYTE ^ MOCK_SPI_REPLY_DATA_MODIFIER_BYTE, 24 | "SPI writeByte() returned unexpected data") 25 | 26 | def test_spi_write_byte_invalid_bigger_than_max(self): 27 | TEST_VALUE = 0xEEFF 28 | self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE) 29 | 30 | def test_spi_write_byte_invalid_smaller_than_min(self): 31 | TEST_VALUE = -1 32 | self.assertRaises(OverflowError, self.spi.writeByte, TEST_VALUE) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/spi_checks_write_word.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from spi_checks_shared import * 12 | 13 | class SpiChecksWriteWord(u.TestCase): 14 | def setUp(self): 15 | self.spi = m.Spi(MRAA_SPI_BUS_NUM) 16 | 17 | def tearDown(self): 18 | del self.spi 19 | 20 | def test_spi_write_word(self): 21 | TEST_WORD = 0xAAEE 22 | self.assertEqual(self.spi.writeWord(TEST_WORD), 23 | TEST_WORD ^ MOCK_SPI_REPLY_DATA_MODIFIER_WORD, 24 | "SPI writeWord() returned unexpected data") 25 | 26 | def test_spi_write_word_invalid_bigger_than_max(self): 27 | TEST_VALUE = 0xEEFFEE 28 | self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE) 29 | 30 | def test_spi_write_word_invalid_smaller_than_min(self): 31 | TEST_VALUE = -1 32 | self.assertRaises(OverflowError, self.spi.writeWord, TEST_VALUE) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_data_available.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksDataAvailable(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_data_available(self): 21 | self.assertEqual(self.uart.dataAvailable(10), 22 | True, 23 | "Running UART dataAvailable() did not return True") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_flush.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksFlush(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_flush(self): 21 | self.assertEqual(self.uart.flush(), 22 | m.SUCCESS, 23 | "Running UART flush() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_read.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksRead(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_read(self): 21 | TEST_DATA_LEN = 10 22 | EXPECTED_RESULT = bytearray([MOCK_UART_DATA_BYTE for x in range(TEST_DATA_LEN)]) 23 | self.assertEqual(self.uart.read(TEST_DATA_LEN), 24 | EXPECTED_RESULT, 25 | "Running UART read(%d) did not return %s" % (TEST_DATA_LEN, repr(EXPECTED_RESULT))) 26 | 27 | def test_uart_readStr(self): 28 | TEST_DATA_LEN = 10 29 | EXPECTED_RESULT = chr(MOCK_UART_DATA_BYTE) * TEST_DATA_LEN 30 | self.assertEqual(self.uart.readStr(TEST_DATA_LEN), 31 | EXPECTED_RESULT, 32 | "Running UART readStr(%d) did not return %s" % (TEST_DATA_LEN, EXPECTED_RESULT)) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_sendbreak.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Jon Trulson 4 | # Copyright (c) 2017 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSendbreak(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_sendbreak(self): 21 | self.assertEqual(self.uart.sendBreak(0), 22 | m.SUCCESS, 23 | "Running UART sendBreak() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_set_baudrate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSetBaudrate(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_baudrate_115200(self): 21 | TEST_BAUDRATE = 115200 22 | self.assertEqual(self.uart.setBaudRate(TEST_BAUDRATE), 23 | m.SUCCESS, 24 | "Setting baudrate to %d did not return success" % TEST_BAUDRATE) 25 | 26 | def test_uart_baudrate_invalid_bigger_than_max(self): 27 | TEST_BAUDRATE = 10000000 28 | self.assertEqual(self.uart.setBaudRate(TEST_BAUDRATE), 29 | m.ERROR_INVALID_PARAMETER, 30 | "Setting baudrate to %d did not return INVALID_PARAMETER" % TEST_BAUDRATE) 31 | 32 | if __name__ == "__main__": 33 | u.main() 34 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_set_flowcontrol.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSetFlowControl(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_set_flowcontrol(self): 21 | self.assertEqual(self.uart.setFlowcontrol(False, True), 22 | m.SUCCESS, 23 | "Running UART setFlowControl() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_set_mode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSetMode(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_set_mode(self): 21 | self.assertEqual(self.uart.setMode(8, m.UART_PARITY_NONE, 1), 22 | m.SUCCESS, 23 | "Running UART setMode() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_set_nonblocking.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSetNonBlocking(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_set_nonblocking(self): 21 | self.assertEqual(self.uart.setNonBlocking(True), 22 | m.SUCCESS, 23 | "Running UART setNonBlocking() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_set_timeout.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksSetTimeout(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_set_timeout(self): 21 | self.assertEqual(self.uart.setTimeout(10, 10, 10), 22 | m.SUCCESS, 23 | "Running UART setTimeout() did not return success") 24 | 25 | if __name__ == "__main__": 26 | u.main() 27 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_shared.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | MRAA_UART_DEV_NUM = 0 9 | # This one is defined in mock_board_uart.h 10 | MOCK_UART_DATA_BYTE = 0x5A 11 | -------------------------------------------------------------------------------- /tests/mock/uart_checks_write.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Alex Tereschenko 4 | # Copyright (c) 2016 Alex Tereschenko. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | import mraa as m 9 | import unittest as u 10 | 11 | from uart_checks_shared import * 12 | 13 | class UartChecksWrite(u.TestCase): 14 | def setUp(self): 15 | self.uart = m.Uart(MRAA_UART_DEV_NUM) 16 | 17 | def tearDown(self): 18 | del self.uart 19 | 20 | def test_uart_write(self): 21 | TEST_DATA_LEN = 10 22 | TEST_DATA = bytearray([x for x in range(TEST_DATA_LEN)]) 23 | self.assertEqual(self.uart.write(TEST_DATA), 24 | TEST_DATA_LEN, 25 | "Running UART write(%s) did not return %d" % (repr(TEST_DATA), TEST_DATA_LEN)) 26 | 27 | def test_uart_writeStr(self): 28 | TEST_DATA = "Hello" 29 | TEST_DATA_LEN = len(TEST_DATA) 30 | self.assertEqual(self.uart.writeStr(TEST_DATA), 31 | TEST_DATA_LEN, 32 | "Running UART writeStr(%s) did not return %d" % (TEST_DATA, TEST_DATA_LEN)) 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/platform_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Costin Constantin 4 | # Copyright (c) 2015 Intel Corporation. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | 8 | from __future__ import print_function 9 | 10 | import mraa as m 11 | import unittest as u 12 | 13 | @u.skipIf(m.getPlatformName() == "Unknown platform", "Not valid platform loaded") 14 | class PlatformChecks(u.TestCase): 15 | pass 16 | 17 | 18 | @u.skipUnless(m.getPlatformName() == "Intel Edison", "Only for edison Board") 19 | class PlatformChecksEdison(u.TestCase): 20 | def test_mraa_check_platform_no_of_pins(self): 21 | pinCount = m.getPinCount() 22 | self.assertEqual(pinCount, 20, "Wrong number. of pins. Check platform ...") 23 | 24 | def test_mraa_check_platform_ADC_max_resolution(self): 25 | self.p_ADC_mres = m.adcRawBits() 26 | print("Platform ADC max. resolution is: " + str(self.p_ADC_mres) + " bits") 27 | self.assertEqual(self.p_ADC_mres, 12, "Wrong ADC max. resolution. Check platform ...") 28 | 29 | def test_mraa_check_platform_ADC_resolution(self): 30 | self.p_ADC_res = m.adcSupportedBits() 31 | print("Platform ADC resolution is: " + str(self.p_ADC_res) + " bits") 32 | self.assertEqual(self.p_ADC_res, 10, "Wrong ADC supported resolution. Check platform ...") 33 | 34 | if __name__ == "__main__": 35 | u.main() 36 | -------------------------------------------------------------------------------- /tests/unit/api/mraa_initio_hpp_unit.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Mihai Stefanescu 3 | * Copyright (c) 2018 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | #include "mraa/initio.hpp" 9 | #include "gtest/gtest.h" 10 | #include 11 | #include 12 | 13 | 14 | /* MRAA IO INIT hpp test fixture */ 15 | class mraa_initio_hpp_unit : public ::testing::Test 16 | { 17 | }; 18 | 19 | /* Test for an invalid AIO init. */ 20 | TEST_F(mraa_initio_hpp_unit, test_aio_init_invalid) 21 | { 22 | ASSERT_THROW(mraa::MraaIo io("a:bogus:10"), std::runtime_error); 23 | } 24 | 25 | /* Test for a valid AIO init. */ 26 | TEST_F(mraa_initio_hpp_unit, test_aio_init_valid) 27 | { 28 | mraa::MraaIo io("a:0:10"); 29 | ASSERT_EQ(1, io.aios.size()); 30 | } 31 | -------------------------------------------------------------------------------- /tests/unit/platform_extender/platform_extender.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Noel Eck 3 | * Copyright (c) 2018 Intel Corporation. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | */ 7 | 8 | 9 | #include 10 | 11 | #include "gtest/gtest.h" 12 | #include "mraa/common.h" 13 | #include "mraa_internal_types.h" 14 | 15 | /* MRAA test fixture */ 16 | class plaform_extender : public ::testing::Test {}; 17 | 18 | /* Not much to test w/o hw - test a no-init case. 19 | * Note, w/o a link to libmraa, this binary does NOT initialize mraa 20 | * with the loader constructor attribute. This is intended. */ 21 | TEST_F(plaform_extender, test_no_init) 22 | { 23 | mraa_board_t plat = {}; 24 | 25 | void* usblib = dlopen("libmraa-platform-ft4222.so", RTLD_LAZY); 26 | ASSERT_NE((void*)NULL, usblib) 27 | << "Failed to load libmraa-platform-ft4222.so, reason (" << dlerror() 28 | << ")"; 29 | 30 | fptr_add_platform_extender add_ft4222_platform = 31 | (fptr_add_platform_extender)dlsym(usblib, "mraa_usb_platform_extender"); 32 | 33 | ASSERT_NE((void*)NULL, add_ft4222_platform) << "Symbol 'add_ft4222_platform' " 34 | << "does not exist in libmraa-platform-ft4222.so"; 35 | 36 | ASSERT_EQ(MRAA_ERROR_PLATFORM_NOT_INITIALISED, add_ft4222_platform(&plat)) 37 | << "Initialization returned a valid platform. Make sure no Ft4222 " 38 | << "device is connected"; 39 | } 40 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable (mraa-gpio mraa-gpio.c) 2 | add_executable (mraa-i2c mraa-i2c.c) 3 | add_executable (mraa-uart mraa-uart.c) 4 | 5 | include_directories (${PROJECT_SOURCE_DIR}/api) 6 | # FIXME Hack to access mraa internal types used by mraa-i2c 7 | include_directories (${PROJECT_SOURCE_DIR}/include) 8 | include_directories (${PROJECT_SOURCE_DIR}/api/mraa) 9 | 10 | target_link_libraries (mraa-gpio mraa) 11 | target_link_libraries (mraa-i2c mraa) 12 | target_link_libraries (mraa-uart mraa) 13 | 14 | if (INSTALLTOOLS) 15 | install (TARGETS mraa-gpio DESTINATION bin) 16 | install (TARGETS mraa-i2c DESTINATION bin) 17 | install (TARGETS mraa-uart DESTINATION bin) 18 | endif() 19 | --------------------------------------------------------------------------------