Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
88341c7e56 | ||
|
0a43974175 | ||
|
5e20a1cc02 | ||
|
23feec94d0 | ||
|
0cba580ca6 | ||
|
1dd5f89b37 | ||
|
03114cbadb | ||
|
c5102dffba | ||
|
d1037eda59 | ||
|
d1717fa2bb | ||
|
2b5e38b40c | ||
|
4e5ec299ed | ||
|
60f2e639b2 | ||
|
6d5a3d796c | ||
|
c5c5c9b700 |
@@ -3,9 +3,8 @@ project (mraa)
|
||||
|
||||
FIND_PACKAGE (Threads)
|
||||
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer -DDEBUG")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
|
||||
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -DDEBUG")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||
@@ -15,10 +14,10 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.5.0-dirty")
|
||||
set (VERSION "v0.5.1-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - MRAA Version ${VERSION}")
|
||||
message (INFO " - libmraa Version ${VERSION}")
|
||||
|
||||
#parse the version information into pieces.
|
||||
string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
|
||||
|
@@ -1,4 +1,4 @@
|
||||
MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms
|
||||
libmraa - Low Level Skeleton Library for Communication on GNU/Linux platforms
|
||||
==============
|
||||
|
||||
Library in C/C++ to interface with Galileo & other Intel platforms, in a
|
||||
|
@@ -157,7 +157,8 @@ mraa_result_t mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir);
|
||||
mraa_result_t mraa_gpio_close(mraa_gpio_context dev);
|
||||
|
||||
/**
|
||||
* Read the Gpio value.
|
||||
* Read the Gpio value. This can be 0 or 1. A resonse of -1 means that there
|
||||
* was a fatal error.
|
||||
*
|
||||
* @param dev The Gpio context
|
||||
* @return Result of operation
|
||||
|
@@ -34,7 +34,7 @@ namespace mraa {
|
||||
* Gpio Output modes
|
||||
*/
|
||||
typedef enum {
|
||||
MODE_STRONG = 0, /**< No interrupt on Gpio */
|
||||
MODE_STRONG = 0, /**< Default. Strong High and Low */
|
||||
MODE_PULLUP = 1, /**< Interupt on rising & falling */
|
||||
MODE_PULLDOWN = 2, /**< Interupt on rising only */
|
||||
MODE_HIZ = 3 /**< Interupt on falling only */
|
||||
|
@@ -32,3 +32,18 @@ Using clang instead of gcc:
|
||||
|
||||
Building with an older version of swig (swig 2.0+) requires the disabling of javascript:
|
||||
-DBUILDSWIGNODE=OFF
|
||||
|
||||
Using coverity
|
||||
--------------
|
||||
|
||||
Static analysis is routinely performed using coverity on libmraa's codebase.
|
||||
This is the procedure to submit a build to coverity. You'll need to install
|
||||
coverity-submit for your OS.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
mkdir covbuild/ && cd covbuild
|
||||
cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
|
||||
cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
|
||||
cov-build --dir cov-int make
|
||||
tar caf mraa.tar..bz2 cov-int
|
||||
~~~~~~~~~~~~~
|
||||
|
@@ -4,8 +4,13 @@ Intel Edison {#edison}
|
||||
Edison is a dual core Silvermont Atom clocked at 500MHz. The Edison
|
||||
also features 4GB of storage, 1GB ram and onboard wifi and bluetooth.
|
||||
|
||||
Currently the Arduino breakout board is supported by libmraa.
|
||||
Currently Supported boards:
|
||||
- Intel Arduino board
|
||||
- Intel breakout board
|
||||
|
||||
|
||||
Intel Arduino board
|
||||
-------------------
|
||||
The Edison used with the Arduino board has the following limitations
|
||||
in libmraa:
|
||||
|
||||
@@ -14,3 +19,69 @@ in libmraa:
|
||||
- SPI exposed is also used for the ADC. Try not to use your own CS.
|
||||
- ADC kernel module will return 12bit number but the ADC itself only has an
|
||||
accuracy of 10bits. This ADC is only included on the arduino board.
|
||||
|
||||
Intel breakout board
|
||||
--------------------
|
||||
|
||||
- Both I2C buses are avaible 1 & 6
|
||||
|
||||
Please see the following table on how the physical pins map to mraa pin numbers
|
||||
|
||||
| MRAA Number | Physical Pin | Edison Pin | Notes | Pinmode0 | Pinmode1 | Pinmode2 |
|
||||
|-------------|--------------|---------------|-------------------------|----------|------------|----------|
|
||||
| 0 | J17-1 | GP182 | | GPIO-182 | PWM2 | |
|
||||
| 1 | J17-2 | NC | Nothing from mraa | | | |
|
||||
| 2 | J17-3 | NC | Nothing from mraa | | | |
|
||||
| 3 | J17-4 | VIN | Nothing from mraa | | | |
|
||||
| 4 | J17-5 | GP135 | | GPIO-135 | UART | |
|
||||
| 5 | J17-6 | RCVR_MODE | Nothing from mraa | | | |
|
||||
| 6 | J17-7 | GP27 | | GPIO-27 | I2C-6-SCL | |
|
||||
| 7 | J17-8 | GP20 | | GPIO-20 | I2C-1-SDA | |
|
||||
| 8 | J17-9 | GP28 | | GPIO-28 | I2C-6-SDA | |
|
||||
| 9 | J17-10 | GP111 | | GPIO-111 | SPI-5-CS1 | |
|
||||
| 10 | J17-11 | GP109 | | GPIO-109 | SPI-5-SCK | |
|
||||
| 11 | J17-12 | GP115 | | GPIO-115 | SPI-5-MOSI | |
|
||||
| 12 | J17-13 | OSC_CLK_OUT_0 | Nothing from mraa/check | | | |
|
||||
| 13 | J17-14 | GP128 | | GPIO-128 | UART-1-CTS | |
|
||||
| 14 | J18-1 | GP13 | | GPIO-13 | PWM1 | |
|
||||
| 15 | J18-2 | GP165 | | GPIO-165 | | |
|
||||
| 16 | J18-3 | GPI_PWRBTN_N | Nothing from mraa | | | |
|
||||
| 17 | J18-4 | MSIC_SLP_CLK2 | Nothing from mraa | | | |
|
||||
| 18 | J18-5 | V_VBAT_BKUP | Nothing from mraa | | | |
|
||||
| 19 | J18-6 | GP19 | | GPIO-19 | I2C-1-SCL | |
|
||||
| 20 | J18-7 | GP12 | PWM0 | GPIO-12 | PWM0 | |
|
||||
| 21 | J18-8 | GP183 | PWM3 | GPIO-183 | PWM3 | |
|
||||
| 22 | J18-9 | NC | Nothing from mraa | | | |
|
||||
| 23 | J18-10 | GP110 | | GPIO-110 | SPI-5-CS0 | |
|
||||
| 24 | J18-11 | GP114 | | GPIO-114 | SPI-5-MISO | |
|
||||
| 25 | J18-12 | GP129 | | GPIO-129 | UART-1-RTS | |
|
||||
| 26 | J18-13 | GP130 | | GPIO-130 | UART-1-RX | |
|
||||
| 27 | J18-14 | FW_RCVR | Nothing from mraa | | | |
|
||||
| 28 | J19-1 | NC | Nothing from mraa | | | |
|
||||
| 29 | J19-2 | V_V1P80 | Nothing from mraa | | | |
|
||||
| 30 | J19-3 | GND | Nothing from mraa | | | |
|
||||
| 31 | J19-4 | GP44 | | GPIO-44 | | |
|
||||
| 32 | J19-5 | GP46 | | GPIO-46 | | |
|
||||
| 33 | J19-6 | GP48 | | GPIO-48 | | |
|
||||
| 34 | J19-7 | RESET_OUT | Nothing from mraa | | | |
|
||||
| 35 | J19-8 | GP131 | | GPIO-131 | UART-1-TX | |
|
||||
| 36 | J19-9 | GP14 | | GPIO-14 | | |
|
||||
| 37 | J19-10 | GP40 | | GPIO-40 | SSP2_CLK | |
|
||||
| 38 | J19-11 | GP43 | | GPIO-43 | SSP2_TXD | |
|
||||
| 39 | J19-12 | GP77 | | GPIO-77 | SD | |
|
||||
| 40 | J19-13 | GP82 | | GPIO-82 | SD | |
|
||||
| 41 | J19-14 | GP83 | | GPIO-83 | SD | |
|
||||
| 42 | J20-1 | V_VSYS | Nothing from mraa | | | |
|
||||
| 43 | J20-2 | V_V3P30 | Nothing from mraa | | | |
|
||||
| 44 | J20-3 | GP134 | | | | |
|
||||
| 45 | J20-4 | GP45 | | GPIO-45 | | |
|
||||
| 46 | J20-5 | GP47 | | GPIO-47 | | |
|
||||
| 47 | J20-6 | GP49 | | GPIO-49 | | |
|
||||
| 48 | J20-7 | GP15 | | GPIO-15 | | |
|
||||
| 49 | J20-8 | GP84 | | GPIO-84 | SD | |
|
||||
| 50 | J20-9 | GP42 | | GPIO-42 | SSP2_RXD | |
|
||||
| 51 | J20-10 | GP41 | | GPIO-41 | SSP2_FS | |
|
||||
| 52 | J20-11 | GP78 | | GPIO-78 | SD | |
|
||||
| 53 | J20-12 | GP79 | | GPIO-79 | SD | |
|
||||
| 54 | J20-13 | GP80 | | GPIO-80 | SD | |
|
||||
| 55 | J20-14 | GP81 | | GPIO-81 | SD | |
|
||||
|
@@ -1,4 +1,4 @@
|
||||
MRAA - Low Level Skeleton Library for Communication on Intel platforms
|
||||
libmraa - Low Level Skeleton Library for Communication on Intel platforms
|
||||
==============
|
||||
|
||||
Library in C/C++ to interface with Galileo & other Intel platforms, in a
|
||||
@@ -36,6 +36,7 @@ Specific platform information for supported platforms is documented here:
|
||||
|
||||
- @ref galileorevd
|
||||
- @ref galileorevh
|
||||
- @ref edison
|
||||
|
||||
### ENV RECOMENDATIONS
|
||||
|
||||
@@ -49,11 +50,12 @@ cmake, libm and pthreads are technically required to compile.
|
||||
|
||||
## COMPILING
|
||||
|
||||
More information on compiling is @ref building page
|
||||
More information on compiling is @ref building page.
|
||||
|
||||
## CONTRIBUTING
|
||||
|
||||
Please see the @ref contributing page
|
||||
Please see the @ref contributing page, the @ref internals page may also be of
|
||||
use.
|
||||
|
||||
## API Changelog
|
||||
|
||||
@@ -61,6 +63,12 @@ This changelog is meant as a quick & rough guide to what has changed between
|
||||
versions. The API is now fairly stable but when new calls/features are added
|
||||
they are listed here. Anything pre 0.2.x is ignored.
|
||||
|
||||
**0.5.1**
|
||||
* Intel Edison - Mini breakout board support
|
||||
* Change to use syslog throughout instead of printing to stderr.
|
||||
* Fix misc issues brought up throuh coverity scans
|
||||
* Clear up Analog call documentation
|
||||
|
||||
**0.5.0**
|
||||
* Intel Edison - Arduino board support.
|
||||
* Boost Allowable i2c busses to 12
|
||||
|
130
docs/internals.md
Normal file
130
docs/internals.md
Normal file
@@ -0,0 +1,130 @@
|
||||
libmraa Internals {#internals}
|
||||
=================
|
||||
|
||||
For building see @ref building. This will describe the general internal build
|
||||
of libmraa and will be useful to developers who'd like to understand more of
|
||||
how libmraa works or who'd like to add additional platforms. The internals will
|
||||
deal with the C API as that is the low level API which libmraa is built around.
|
||||
Note that C++ is simply a header only wrapper of the C API.
|
||||
|
||||
libmraa has the philosophy that the board mapping is what we typically use in
|
||||
the API with the execption of i2c/spi bus numbering as they are typically not
|
||||
labelled on boards and so we use the kernel numbering scheme. Whilst this can
|
||||
confuse some, it's typically not an issue as platforms rarely expose more than
|
||||
one of these for user use and so when this is the case, libmraa will always use
|
||||
the bus in the pinmapper. For example edison uses i2c #6 but since there is
|
||||
only one, libmraa will try to be helpful and everything is treated as 6 when
|
||||
doing a mraa_i2c_init and so when this is the case, libmraa will always use the
|
||||
bus in the pinmapper. For example edison uses i2c #6 but since there is only
|
||||
one, libmraa will try to be helpful and everything is treated as 6 when doing a
|
||||
mraa_i2c_init().
|
||||
|
||||
In libmraa, all code is split into 7 modules, src/{i2c, spi, gpio, uart, pwm,
|
||||
aio and common}. These should be fairly self explanatory in goals/purpose but a
|
||||
few work in different ways. Public APIs are stored in api/ and internal headers
|
||||
are in include/
|
||||
|
||||
### Logging ###
|
||||
|
||||
Logging is now done purely in syslog(). Note that on platforms running systemd
|
||||
journald will intercept syslog(3) calls and log to the journal instead. You can
|
||||
set the log mask by using mraa_set_log_level(). Doing a DEBUG build of libmraa
|
||||
will also cause the DEBUG macro to be defined which will cause the syslog mask
|
||||
to be unset.
|
||||
|
||||
### Contexts ###
|
||||
|
||||
libmraa uses contexts to store all information, this context cannot be accessed
|
||||
by the user and so it's layout can and may be changed without warning to users.
|
||||
If an init() function fails it will return NULL and further calls with this
|
||||
context will lead to undefined behaviour.
|
||||
|
||||
### Pinmapper ###
|
||||
|
||||
The mraa_board_t is defined in mraa/common.h. It's a mostly static structure
|
||||
initialised during mraa_init(). The pinmap file in
|
||||
src/{manufacturer}_{boardname}_{revision}.c then fills this array. It's also
|
||||
where platform hooks can be defined, functions that will be run at various
|
||||
'hook' points in the code.
|
||||
|
||||
The mraa_pininfo_t structure needs to be set for the board pincount (set in a
|
||||
macro in the platform configuration header. Every pin will have a
|
||||
mraa_pincapabilities_t which will define what it can do. The doxygen doc
|
||||
explains how this works but it's essentially a bitfield which needs to be set
|
||||
for every capability the pin can have. Gpios can have multiple muxes which will
|
||||
be set at the gpio init before it can be toggled.
|
||||
|
||||
### i2c ###
|
||||
|
||||
I2c from userspace in GNU/Linux is handled by character devices handled by the
|
||||
kernel driver i2c-dev. For more details the i2c/dev-interface documentation
|
||||
file in the kernel is the place to go.
|
||||
|
||||
In libmraa, we re-use part of a library - libi2c from RoadNarrows -
|
||||
i2c/smbus.c. This library simply makes it easier for us to handle the error
|
||||
conditions that can arrise when writing on i2c buses. Essentially the API is
|
||||
fairly simple consisting of writes & reads.
|
||||
|
||||
Careful - on alot of platforms i2cdetect will often crash, for finding your i2c
|
||||
addresses please look at your sensors datasheet!
|
||||
|
||||
### spi ###
|
||||
|
||||
### gpio ###
|
||||
|
||||
GPIO is probably the most complicated and odd module in libmraa. It is based on
|
||||
the gpiolib kernel driver framework which uses sysfs. There is a lot of good
|
||||
documentation in gpio/sysfs.txt in the kernel docs.
|
||||
|
||||
The main issue is that gpios on hobbyist boards typically come with a number of
|
||||
muxers or level shifters and are often mapped in crazy ways. libmraa's goal is
|
||||
to make the label on your board match the API :) We hope that pleases you.
|
||||
|
||||
Because boards are very different we use alot of platform hooks (@ref hooks) to
|
||||
make the initialisation work on all platforms. The hope is that simple
|
||||
platforms with no level shifters or expanders will work with just the pinmap
|
||||
definition.
|
||||
|
||||
GPIOs are typically interfaced via sysfs because that's easier for us but we
|
||||
can also work with fast gpio. This is typically preffered to do mmap gpio
|
||||
access. This is however trickier and typically relies on lots of platform
|
||||
hooks. We do support by default to go hit /dev/mem or another device at
|
||||
specific addresses to toggle gpios which is how mmap access works on some
|
||||
boards.
|
||||
|
||||
### uart ###
|
||||
|
||||
libmraa does not support UART/serial as there are many good libraries that do
|
||||
this already. In the future we may wrap or use one. However the class exists to
|
||||
set the pinmapper correctly for uart to work on some platforms.
|
||||
|
||||
### pwm ###
|
||||
|
||||
### aio ###
|
||||
|
||||
### Initialisation ###
|
||||
|
||||
mraa_init() needs to be called in order to initialise the platform files or
|
||||
'pinmap'. Because calling this is tedious libmraa uses a C constructor to run
|
||||
mraa_init on library load. This means that it is not possible to stop this
|
||||
running and all functino calls like mraa_set_log_level() will not work during
|
||||
mraa_init(). This feature is supported by most sane compilers & libcs but you
|
||||
can turn off CTORS in uclibc, though I've yet to find a configuration with
|
||||
someone doing that. mraa_init() can be called multiple times if you feel like
|
||||
being 'safe'.
|
||||
|
||||
In the SWIG modulse mraa_init() is called during the %init stage of the module
|
||||
loading. This is simply to avoid mraa_init() running 'too' early, though I've
|
||||
never seen an issue in running it in a CTOR.
|
||||
|
||||
### SWIG ###
|
||||
|
||||
At the time when libmraa was created the only - working - API/wrapper
|
||||
generation tool that supported nodejs was SWIG. For more general information on
|
||||
swig please see the swig documentation.
|
||||
|
||||
The src/{javascript, python} & src/mraa.i folders contain all the files for the
|
||||
swig generation. The C++ headers in api/mraa/ are given as input sources to
|
||||
SWIG. SWIG modules do not link to libmraa (although maybe that would be a good
|
||||
idea...)
|
||||
|
@@ -1,16 +1,25 @@
|
||||
Hooks can be defined per supported platform to allow for highly custom operations if needed.
|
||||
This feature of MRAA should only be used by developers defining the board definitions, NOT an end user.
|
||||
platform-hooks {#hooks}
|
||||
==============
|
||||
|
||||
Hooks can be defined per supported platform to allow for highly custom
|
||||
operations if needed. This feature of MRAA should only be used by developers
|
||||
defining the board definitions, NOT an end user.
|
||||
|
||||
##Types of Hooks
|
||||
|
||||
###REPLACE
|
||||
Defining a replace function will entirely replace the associate function. This should only be done if your new function can handle everything the mraa function would normally.
|
||||
Defining a replace function will entirely replace the associate function. This
|
||||
should only be done if your new function can handle everything the mraa
|
||||
function would normally.
|
||||
|
||||
###PRE
|
||||
Any functionality defined here will be performed when the main function is called.
|
||||
Any functionality defined here will be performed when the main function is
|
||||
called.
|
||||
|
||||
###POST
|
||||
Any functionality perfomed here is done just before the normal function returns. All post functions will have passed into them the return value that would normally be returned.
|
||||
Any functionality perfomed here is done just before the normal function
|
||||
returns. All post functions will have passed into them the return value that
|
||||
would normally be returned.
|
||||
|
||||
##Hooks
|
||||
### GPIO
|
||||
|
@@ -114,7 +114,7 @@ mraa_aio_init(unsigned int aio_channel)
|
||||
unsigned int
|
||||
mraa_aio_read(mraa_aio_context dev)
|
||||
{
|
||||
char buffer[16];
|
||||
char buffer[17];
|
||||
unsigned int shifter_value = 0;
|
||||
|
||||
if (dev->adc_in_fp == -1) {
|
||||
@@ -125,13 +125,15 @@ mraa_aio_read(mraa_aio_context dev)
|
||||
if (read(dev->adc_in_fp, buffer, sizeof(buffer)) < 1) {
|
||||
syslog(LOG_ERR, "Failed to read a sensible value");
|
||||
}
|
||||
// force NULL termination of string
|
||||
buffer[16] = '\0';
|
||||
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
||||
|
||||
errno = 0;
|
||||
char *end;
|
||||
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
|
||||
if (end == &buffer[0]) {
|
||||
syslog(LOG_ERR, "%s is not a decimal number", buffer);
|
||||
syslog(LOG_ERR, "value is not a decimal number");
|
||||
}
|
||||
else if (errno != 0) {
|
||||
syslog(LOG_ERR, "errno was set");
|
||||
|
@@ -87,6 +87,11 @@ mraa_gpio_init_raw(int pin)
|
||||
int length;
|
||||
|
||||
mraa_gpio_context dev = (mraa_gpio_context) malloc(sizeof(struct _gpio));
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "Failed to allocate memory for context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(dev, 0, sizeof(struct _gpio));
|
||||
dev->value_fp = -1;
|
||||
dev->isr_value_fp = -1;
|
||||
@@ -102,6 +107,7 @@ mraa_gpio_init_raw(int pin)
|
||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||
if (export == -1) {
|
||||
syslog(LOG_ERR, "Failed to open export for writing");
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
@@ -430,6 +436,9 @@ mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir)
|
||||
int
|
||||
mraa_gpio_read(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev == NULL)
|
||||
return -1;
|
||||
|
||||
if (dev->value_fp == -1) {
|
||||
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Failed to get value file pointer");
|
||||
@@ -442,17 +451,19 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
char bu[2];
|
||||
if (read(dev->value_fp, bu, 2*sizeof(char)) != 2) {
|
||||
syslog(LOG_ERR, "Failed to read a sensible value from sysfs");
|
||||
return -1;
|
||||
}
|
||||
lseek(dev->value_fp, 0, SEEK_SET);
|
||||
int ret = strtol(bu, NULL, 10);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
return strtol(bu, NULL, 10);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_gpio_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
if (dev == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
|
||||
if (dev->mmap == 1)
|
||||
return mraa_gpio_write_register(dev,value);
|
||||
|
||||
@@ -551,6 +562,7 @@ mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
|
||||
fd = open(mmp->mem_dev, O_RDWR);
|
||||
if (fd < 1) {
|
||||
syslog(LOG_ERR, "Unable to open memory device");
|
||||
close(fd);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->reg_sz = mmp->mem_sz;
|
||||
|
@@ -55,8 +55,10 @@ mraa_i2c_init_raw(unsigned int bus)
|
||||
return NULL;
|
||||
}
|
||||
mraa_i2c_context dev = (mraa_i2c_context) malloc(sizeof(struct _i2c));
|
||||
if (dev == NULL)
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "Failed to allocate memory for context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char filepath[32];
|
||||
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
||||
@@ -96,9 +98,6 @@ uint8_t
|
||||
mraa_i2c_read_byte(mraa_i2c_context dev)
|
||||
{
|
||||
uint8_t byte = i2c_smbus_read_byte(dev->fh);
|
||||
if (byte < 0) {
|
||||
return -1;
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,7 @@ static mraa_gpio_context tristate;
|
||||
static mraa_intel_edison_pinmodes_t pinmodes[MRAA_INTEL_EDISON_PINCOUNT];
|
||||
static unsigned int outputen[] = {248,249,250,251,252,253,254,255,256,257,258,259,260,261,232,233,234,235,236,237};
|
||||
static unsigned int pullup_map[] = {216,217,218,219,220,221,222,223,224,225,226,227,228,229,208,209,210,211,212,213};
|
||||
static int miniboard = 0;
|
||||
|
||||
static mraa_result_t
|
||||
mraa_intel_edison_pinmode_change(int sysfs, int mode)
|
||||
@@ -69,6 +70,7 @@ mraa_intel_edison_pinmode_change(int sysfs, int mode)
|
||||
char mode_buf[MAX_MODE_SIZE];
|
||||
int length = sprintf(mode_buf, "mode%u",mode);
|
||||
if (write(modef, mode_buf, length*sizeof(char)) == -1) {
|
||||
close(modef);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
close(modef);
|
||||
@@ -109,8 +111,14 @@ mraa_intel_edison_gpio_init_post(mraa_gpio_context dev)
|
||||
if (dev == NULL)
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
int sysfs = pinmodes[dev->phy_pin].gpio.sysfs;
|
||||
int mode = pinmodes[dev->phy_pin].gpio.mode;
|
||||
int sysfs, mode;
|
||||
if (miniboard == 1) {
|
||||
sysfs = dev->pin;
|
||||
mode = 0;
|
||||
} else {
|
||||
sysfs = pinmodes[dev->phy_pin].gpio.sysfs;
|
||||
mode = pinmodes[dev->phy_pin].gpio.mode;
|
||||
}
|
||||
mraa_result_t ret = mraa_intel_edison_pinmode_change(sysfs, mode);
|
||||
|
||||
return ret;
|
||||
@@ -119,38 +127,50 @@ mraa_intel_edison_gpio_init_post(mraa_gpio_context dev)
|
||||
mraa_result_t
|
||||
mraa_intel_edison_i2c_init_pre(unsigned int bus)
|
||||
{
|
||||
if(bus != 6) {
|
||||
syslog(LOG_ERR, "Edison: You can't use that bus :/");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
if (miniboard == 0) {
|
||||
if(bus != 6) {
|
||||
syslog(LOG_ERR, "Edison: You can't use that bus :/");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
mraa_gpio_write(tristate, 0);
|
||||
mraa_gpio_context io18_gpio = mraa_gpio_init_raw(14);
|
||||
mraa_gpio_context io19_gpio = mraa_gpio_init_raw(165);
|
||||
mraa_gpio_dir(io18_gpio, MRAA_GPIO_IN);
|
||||
mraa_gpio_dir(io19_gpio, MRAA_GPIO_IN);
|
||||
mraa_gpio_close(io18_gpio);
|
||||
mraa_gpio_close(io19_gpio);
|
||||
|
||||
mraa_gpio_context io18_enable = mraa_gpio_init_raw(236);
|
||||
mraa_gpio_context io19_enable = mraa_gpio_init_raw(237);
|
||||
mraa_gpio_dir(io18_enable, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io19_enable, MRAA_GPIO_OUT);
|
||||
mraa_gpio_write(io18_enable, 0);
|
||||
mraa_gpio_write(io19_enable, 0);
|
||||
mraa_gpio_close(io18_enable);
|
||||
mraa_gpio_close(io19_enable);
|
||||
|
||||
mraa_gpio_context io18_pullup = mraa_gpio_init_raw(212);
|
||||
mraa_gpio_context io19_pullup = mraa_gpio_init_raw(213);
|
||||
mraa_gpio_dir(io18_pullup, MRAA_GPIO_IN);
|
||||
mraa_gpio_dir(io19_pullup, MRAA_GPIO_IN);
|
||||
mraa_gpio_close(io18_pullup);
|
||||
mraa_gpio_close(io19_pullup);
|
||||
|
||||
mraa_intel_edison_pinmode_change(28, 1);
|
||||
mraa_intel_edison_pinmode_change(27, 1);
|
||||
|
||||
mraa_gpio_write(tristate, 1);
|
||||
} else {
|
||||
if(bus != 6 && bus != 1) {
|
||||
syslog(LOG_ERR, "Edison: You can't use that bus :/");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
int scl = plat->pins[plat->i2c_bus[bus].scl].gpio.pinmap;
|
||||
int sda = plat->pins[plat->i2c_bus[bus].sda].gpio.pinmap;
|
||||
mraa_intel_edison_pinmode_change(sda, 1);
|
||||
mraa_intel_edison_pinmode_change(scl, 1);
|
||||
}
|
||||
mraa_gpio_write(tristate, 0);
|
||||
mraa_gpio_context io18_gpio = mraa_gpio_init_raw(14);
|
||||
mraa_gpio_context io19_gpio = mraa_gpio_init_raw(165);
|
||||
mraa_gpio_dir(io18_gpio, MRAA_GPIO_IN);
|
||||
mraa_gpio_dir(io19_gpio, MRAA_GPIO_IN);
|
||||
mraa_gpio_close(io18_gpio);
|
||||
mraa_gpio_close(io19_gpio);
|
||||
|
||||
mraa_gpio_context io18_enable = mraa_gpio_init_raw(236);
|
||||
mraa_gpio_context io19_enable = mraa_gpio_init_raw(237);
|
||||
mraa_gpio_dir(io18_enable, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io19_enable, MRAA_GPIO_OUT);
|
||||
mraa_gpio_write(io18_enable, 0);
|
||||
mraa_gpio_write(io19_enable, 0);
|
||||
mraa_gpio_close(io18_enable);
|
||||
mraa_gpio_close(io19_enable);
|
||||
|
||||
mraa_gpio_context io18_pullup = mraa_gpio_init_raw(212);
|
||||
mraa_gpio_context io19_pullup = mraa_gpio_init_raw(213);
|
||||
mraa_gpio_dir(io18_pullup, MRAA_GPIO_IN);
|
||||
mraa_gpio_dir(io19_pullup, MRAA_GPIO_IN);
|
||||
mraa_gpio_close(io18_pullup);
|
||||
mraa_gpio_close(io19_pullup);
|
||||
|
||||
mraa_intel_edison_pinmode_change(28, 1);
|
||||
mraa_intel_edison_pinmode_change(27, 1);
|
||||
|
||||
mraa_gpio_write(tristate, 1);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -249,6 +269,9 @@ mraa_intel_edison_aio_init_post(mraa_aio_context dev)
|
||||
mraa_result_t
|
||||
mraa_intel_edison_pwm_init_pre(int pin)
|
||||
{
|
||||
if (miniboard == 1) {
|
||||
return mraa_intel_edison_pinmode_change(plat->pins[pin].gpio.pinmap, 1);
|
||||
}
|
||||
if (pin < 0 || pin > 19)
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
@@ -283,6 +306,13 @@ mraa_intel_edison_pwm_init_post(mraa_pwm_context pwm)
|
||||
mraa_result_t
|
||||
mraa_intel_edison_spi_init_pre(int bus)
|
||||
{
|
||||
if (miniboard == 1) {
|
||||
mraa_intel_edison_pinmode_change(111, 1);
|
||||
mraa_intel_edison_pinmode_change(115, 1);
|
||||
mraa_intel_edison_pinmode_change(114, 1);
|
||||
mraa_intel_edison_pinmode_change(109, 1);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
mraa_gpio_write(tristate, 0);
|
||||
|
||||
mraa_gpio_context io10_out = mraa_gpio_init_raw(258);
|
||||
@@ -373,6 +403,399 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edsion_mb_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
{
|
||||
if (dev->value_fp != -1) {
|
||||
close(dev->value_fp);
|
||||
dev->value_fp = -1;
|
||||
}
|
||||
|
||||
char filepath[MAX_SIZE];
|
||||
snprintf(filepath, MAX_SIZE,
|
||||
SYSFS_PINMODE_PATH "%d/current_pullmode", dev->pin);
|
||||
|
||||
int drive = open(filepath, O_WRONLY);
|
||||
if (drive == -1) {
|
||||
syslog(LOG_ERR, "Edison: Failed to open drive for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
char bu[MAX_SIZE];
|
||||
int length;
|
||||
switch(mode) {
|
||||
case MRAA_GPIO_STRONG:
|
||||
close(drive);
|
||||
return MRAA_SUCCESS;
|
||||
case MRAA_GPIO_PULLUP:
|
||||
length = snprintf(bu, sizeof(bu), "pullup");
|
||||
break;
|
||||
case MRAA_GPIO_PULLDOWN:
|
||||
length = snprintf(bu, sizeof(bu), "pulldown");
|
||||
break;
|
||||
case MRAA_GPIO_HIZ:
|
||||
length = snprintf(bu, sizeof(bu), "nopull");
|
||||
break;
|
||||
default:
|
||||
close(drive);
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(drive, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to drive mode");
|
||||
close(drive);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
}
|
||||
|
||||
close(drive);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edsion_miniboard(mraa_board_t* b)
|
||||
{
|
||||
miniboard = 1;
|
||||
b->phy_pin_count = 56;
|
||||
b->gpio_count = 56; // A bit of a hack I suppose
|
||||
b->aio_count = 0;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*56);
|
||||
|
||||
advance_func->gpio_init_post = &mraa_intel_edison_gpio_init_post;
|
||||
advance_func->pwm_init_pre = &mraa_intel_edison_pwm_init_pre;
|
||||
advance_func->i2c_init_pre = &mraa_intel_edison_i2c_init_pre;
|
||||
advance_func->spi_init_pre = &mraa_intel_edison_spi_init_pre;
|
||||
advance_func->gpio_mode_replace = &mraa_intel_edsion_mb_gpio_mode;
|
||||
|
||||
int pos = 0;
|
||||
strncpy(b->pins[pos].name, "J17-1", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 182;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].pwm.pinmap = 2;
|
||||
b->pins[pos].pwm.parent_id = 0;
|
||||
b->pins[pos].pwm.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-2", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J17-3", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J17-4", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-5", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 135;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-6", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-7", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,0,0};
|
||||
b->pins[pos].gpio.pinmap = 27;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].i2c.pinmap = 1;
|
||||
b->pins[pos].i2c.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-8", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,0,0};
|
||||
b->pins[pos].gpio.pinmap = 20;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].i2c.pinmap = 1;
|
||||
b->pins[pos].i2c.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-9", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,0,0};
|
||||
b->pins[pos].gpio.pinmap = 28;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].i2c.pinmap = 1;
|
||||
b->pins[pos].i2c.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-10", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 111;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 5;
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-11", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 109;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 5;
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-12", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 115;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 5;
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J17-13", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J17-14", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 128;
|
||||
b->pins[pos].gpio.parent_id = 0;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-1", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 13;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].pwm.pinmap = 1;
|
||||
b->pins[pos].pwm.parent_id = 0;
|
||||
b->pins[pos].pwm.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-2", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 165;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-3", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-4", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-5", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-6", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,0,0};
|
||||
b->pins[pos].gpio.pinmap = 19;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].i2c.pinmap = 1;
|
||||
b->pins[pos].i2c.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-7", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 12;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].pwm.pinmap = 0;
|
||||
b->pins[pos].pwm.parent_id = 0;
|
||||
b->pins[pos].pwm.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-8", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 182;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].pwm.pinmap = 3;
|
||||
b->pins[pos].pwm.parent_id = 0;
|
||||
b->pins[pos].pwm.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-9", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-10", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 110;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 5;
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-11", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 114;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].spi.pinmap = 5;
|
||||
b->pins[pos].spi.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J18-12", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 129;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-13", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 130;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J18-14", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-1", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-2", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-3", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-4", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 44;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-5", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 46;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-6", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 48;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-7", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-8", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 131;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-9", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 14;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J19-10", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 40;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-11", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 43;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-12", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 77;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-13", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 82;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J19-14", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 83;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
strncpy(b->pins[pos].name, "J20-1", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-2", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-3", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-4", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 45;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-5", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 47;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-6", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 49;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-7", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 15;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-8", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 84;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-9", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 42;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-10", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 41;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-11", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 78;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-12", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 79;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-13", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 80;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
strncpy(b->pins[pos].name, "J20-14", 8);
|
||||
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0};
|
||||
b->pins[pos].gpio.pinmap = 81;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
pos++;
|
||||
|
||||
//BUS DEFINITIONS
|
||||
b->i2c_bus_count = 9;
|
||||
b->def_i2c_bus = 6;
|
||||
int ici;
|
||||
for (ici = 0; ici < 9; ici++) {
|
||||
b->i2c_bus[ici].bus_id = -1;
|
||||
}
|
||||
b->i2c_bus[1].bus_id = 1;
|
||||
b->i2c_bus[1].sda = 7;
|
||||
b->i2c_bus[1].scl = 19;
|
||||
|
||||
b->i2c_bus[6].bus_id = 6;
|
||||
b->i2c_bus[6].sda = 8;
|
||||
b->i2c_bus[6].scl = 6;
|
||||
|
||||
b->spi_bus_count = 1;
|
||||
b->def_spi_bus = 0;
|
||||
b->spi_bus[0].bus_id = 5;
|
||||
b->spi_bus[0].slave_s = 1;
|
||||
b->spi_bus[0].cs = 23;
|
||||
b->spi_bus[0].mosi = 11;
|
||||
b->spi_bus[0].miso = 24;
|
||||
b->spi_bus[0].sclk = 10;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_edison_fab_c()
|
||||
@@ -381,6 +804,18 @@ mraa_intel_edison_fab_c()
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
// This seciton will also check if the arduino board is there
|
||||
tristate = mraa_gpio_init_raw(214);
|
||||
if (tristate == NULL) {
|
||||
syslog(LOG_INFO, "Intel Edison Failed to initialise Arduino board TriState,\
|
||||
assuming Intel Edison Miniboard\n");
|
||||
if (mraa_intel_edsion_miniboard(b) != MRAA_SUCCESS) {
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
// Now Assuming the edison is attached to the Arduino board.
|
||||
b->phy_pin_count = 20;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
@@ -404,6 +839,7 @@ mraa_intel_edison_fab_c()
|
||||
if (tristate == NULL) {
|
||||
syslog(LOG_CRIT, "Intel Edison Failed to initialise Arduino board TriState,\
|
||||
check i2c devices! FATAL\n");
|
||||
free(b);
|
||||
return NULL;
|
||||
}
|
||||
mraa_gpio_dir(tristate, MRAA_GPIO_OUT);
|
||||
|
@@ -153,9 +153,10 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
||||
}
|
||||
if (value != -1) {
|
||||
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
||||
sta = mraa_gpio_write(pullup_e, value);
|
||||
sta += mraa_gpio_write(pullup_e, value);
|
||||
if (sta != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Galileo Gen 2: Error Setting pullup");
|
||||
close(drive);
|
||||
return sta;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "pwm.h"
|
||||
#include "mraa_internal.h"
|
||||
@@ -100,9 +101,18 @@ mraa_pwm_read_period(mraa_pwm_context dev)
|
||||
|
||||
read(period_f, output, size + 1);
|
||||
close(period_f);
|
||||
int ret = strtol(output, NULL, 10);
|
||||
|
||||
return ret;
|
||||
char *endptr;
|
||||
long int ret = strtol(output, &endptr, 10);
|
||||
if ('\0' != *endptr) {
|
||||
syslog(LOG_ERR, "error in string converstion");
|
||||
return -1;
|
||||
}
|
||||
else if (ret > INT_MAX || ret < INT_MIN) {
|
||||
syslog(LOG_ERR, "number is invalid");
|
||||
return -1;
|
||||
}
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -118,8 +128,17 @@ mraa_pwm_read_duty(mraa_pwm_context dev)
|
||||
char output[MAX_SIZE];
|
||||
read(dev->duty_fp, output, size+1);
|
||||
|
||||
int ret = strtol(output, NULL, 10);
|
||||
return ret;
|
||||
char *endptr;
|
||||
long int ret = strtol(output, &endptr, 10);
|
||||
if ('\0' != *endptr) {
|
||||
syslog(LOG_ERR, "error in string converstion");
|
||||
return -1;
|
||||
}
|
||||
else if (ret > INT_MAX || ret < INT_MIN) {
|
||||
syslog(LOG_ERR, "number is invalid");
|
||||
return -1;
|
||||
}
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
mraa_pwm_context
|
||||
@@ -135,7 +154,7 @@ mraa_pwm_init(int pin) {
|
||||
int pinn = pinm->pinmap;
|
||||
free(pinm);
|
||||
|
||||
if (advance_func->gpio_init_post != NULL) {
|
||||
if (advance_func->pwm_init_post != NULL) {
|
||||
mraa_pwm_context pret = mraa_pwm_init_raw(chip,pinn);
|
||||
mraa_result_t ret = advance_func->pwm_init_post(pret);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
@@ -178,6 +197,7 @@ mraa_pwm_init_raw(int chipin, int pin)
|
||||
if (write(export_f, out, size*sizeof(char)) == -1) {
|
||||
syslog(LOG_WARNING, "Failed to write to export! Potentially already enabled");
|
||||
close(export_f);
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
dev->owner = 1;
|
||||
|
@@ -20,7 +20,10 @@ GPIO Interupt (isr)
|
||||
===================
|
||||
|
||||
The GPIO module allows you to set an interupt on a GPIO. This interupt is
|
||||
controlled by the mode that the 'edge' is in.
|
||||
controlled by the mode that the 'edge' is in. Before setting another isr please
|
||||
remove the first one, multiple isrs on one pin are not supported. Some
|
||||
platforms will not support interupts on all pins so please check your return
|
||||
values.
|
||||
|
||||
**Note:** Galileo Gen1 only supports EDGE_BOTH
|
||||
|
||||
@@ -31,6 +34,9 @@ controlled by the mode that the 'edge' is in.
|
||||
**Note:** If the python script is ended the destructors will run meaning that
|
||||
the ISR will not run. The sleep call is there for that function.
|
||||
|
||||
**Note:** The python isr module treats only objects. This means that int
|
||||
counters will not work inside your isr. Please use the different edge modes.
|
||||
|
||||
I2c
|
||||
===
|
||||
|
||||
|
Reference in New Issue
Block a user