Compare commits
119 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
eb3f2b5bed | ||
|
acc3476326 | ||
|
7ad78d01e5 | ||
|
1b059c1351 | ||
|
14f4567d86 | ||
|
36e24bade8 | ||
|
96849157c8 | ||
|
ade49a82b3 | ||
|
46bb0f38c5 | ||
|
d1185efc0a | ||
|
0289c63c4c | ||
|
9f3cc6e890 | ||
|
be1a725db8 | ||
|
24e52bdbbd | ||
|
51cfc7981d | ||
|
fefe0a24cd | ||
|
a7b8d4a0ca | ||
|
bb5314efc1 | ||
|
1a1c9c2db2 | ||
|
74bcaf3984 | ||
|
d42f8f40f5 | ||
|
276b0a8920 | ||
|
8be861aa1f | ||
|
abd538dc4b | ||
|
0ca4b10687 | ||
|
a38c07f7b1 | ||
|
d4552fdc5e | ||
|
c01451989e | ||
|
7b93207fd9 | ||
|
d99bfa45a3 | ||
|
27f22d077b | ||
|
152a7b04df | ||
|
d7c92bf19e | ||
|
97e00d9298 | ||
|
8f9059767f | ||
|
148c22fb27 | ||
|
6805aebc47 | ||
|
7aea3459a9 | ||
|
41bbc0b86b | ||
|
4e0165c45a | ||
|
57540cd86c | ||
|
6bc2b0fb53 | ||
|
c123ff75f0 | ||
|
d95df3ec22 | ||
|
75be9992fd | ||
|
19d7dad364 | ||
|
e9de25d797 | ||
|
7dc29aa3b7 | ||
|
ac1c60d4fe | ||
|
1133b32b5a | ||
|
72ff035301 | ||
|
745054e7d0 | ||
|
d2ced53344 | ||
|
e84baf6636 | ||
|
9014fc61a0 | ||
|
cf43031994 | ||
|
d2457c29d3 | ||
|
3865bebe8d | ||
|
d1f9e98060 | ||
|
5d7c85c7a1 | ||
|
e39268899c | ||
|
ffd38bb68c | ||
|
66c5011cfb | ||
|
401f0cfe65 | ||
|
1cbdef1ab3 | ||
|
2be24d8887 | ||
|
a3d5af9ea1 | ||
|
ee1f7281dc | ||
|
fd920d6fd1 | ||
|
b5a273965d | ||
|
93107a388c | ||
|
fdb11d98ea | ||
|
bb3228ad58 | ||
|
cf6c3dd144 | ||
|
ac02940174 | ||
|
2896b05dcd | ||
|
d0d0d3ced7 | ||
|
274d5b2d50 | ||
|
428c99f940 | ||
|
2a851d7cc7 | ||
|
9235ed178a | ||
|
cbf4c7447f | ||
|
c852685975 | ||
|
3b01af1da1 | ||
|
29b0425c9b | ||
|
a202b3fd17 | ||
|
e5c3e491a8 | ||
|
af3aa9d8b9 | ||
|
b59aecb70d | ||
|
7c807b3acc | ||
|
418c198999 | ||
|
535d92ab79 | ||
|
a6b3d384b2 | ||
|
a67d71ed90 | ||
|
8b7c1d80cb | ||
|
232fb2cf5e | ||
|
77be6da29c | ||
|
d49f20b7ba | ||
|
c8a99ee8e4 | ||
|
071951e926 | ||
|
0f2329bd95 | ||
|
d734a661fd | ||
|
2a11e31052 | ||
|
54deb01796 | ||
|
88341c7e56 | ||
|
0a43974175 | ||
|
5e20a1cc02 | ||
|
23feec94d0 | ||
|
0cba580ca6 | ||
|
1dd5f89b37 | ||
|
03114cbadb | ||
|
c5102dffba | ||
|
d1037eda59 | ||
|
d1717fa2bb | ||
|
2b5e38b40c | ||
|
4e5ec299ed | ||
|
60f2e639b2 | ||
|
6d5a3d796c | ||
|
c5c5c9b700 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -11,3 +11,11 @@ build/
|
||||
# Temp files
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# npmpub files
|
||||
src/mraajsJAVASCRIPT_wrap.cxx
|
||||
src/version.c
|
||||
package.json
|
||||
binding.gyp
|
||||
READMEFIRST
|
||||
npm-debug.log
|
||||
|
@@ -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.4-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}")
|
||||
|
13
README.md
13
README.md
@@ -1,9 +1,12 @@
|
||||
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
|
||||
structured and sane API with port names/numbering that match boards & with
|
||||
bindings to javascript & python.
|
||||
Libmraa is a C/C++ library with bindings to javascript & python to interface
|
||||
with the IO on Galileo, Edison & other platforms, with a structured and sane
|
||||
API where port names/numbering matches the board that you are on. Use of
|
||||
libmraa does not tie you to specific hardware with board detection done at
|
||||
runtime you can create portable code that will work across the supported
|
||||
platforms.
|
||||
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
their sensors & actuators on top of supported hardware and to allow control of
|
||||
@@ -15,6 +18,8 @@ Supported Boards
|
||||
* [Galileo Gen 1 - Rev D](../master/docs/galileorevd.md)
|
||||
* [Galileo Gen 2 - Rev H](../master/docs/galileorevh.md)
|
||||
* [Edison](../master/docs/edison.md)
|
||||
* [Intel DE3815](../master/docs/intel_de3815.md)
|
||||
* [Minnowboard Max](../master/docs/minnow_max.md)
|
||||
|
||||
Installing on your board
|
||||
========
|
||||
|
@@ -24,6 +24,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include "aio.h"
|
||||
|
||||
namespace mraa {
|
||||
@@ -45,6 +46,9 @@ class Aio {
|
||||
*/
|
||||
Aio(unsigned int pin) {
|
||||
m_aio = mraa_aio_init(pin);
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio destructor
|
||||
|
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define MRAA_PLATFORM_NAME_MAX_SIZE 64
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the basic shared values for libmraa
|
||||
@@ -183,6 +185,11 @@ typedef struct {
|
||||
unsigned int def_uart_dev; /**< Position in array of defult uart */
|
||||
unsigned int uart_dev_count; /**< Usable spi Count */
|
||||
mraa_uart_dev_t uart_dev[6]; /**< Array of UARTs */
|
||||
int pwm_default_period; /**< The default PWM period is US */
|
||||
int pwm_max_period; /**< Maximum period in us */
|
||||
int pwm_min_period; /**< Minimum period in us */
|
||||
unsigned int platform_name_length; /**< Platform Name length */
|
||||
char* platform_name; /**< Platform Name pointer */
|
||||
mraa_pininfo_t* pins; /**< Pointer to pin array */
|
||||
/*@}*/
|
||||
} mraa_board_t;
|
||||
@@ -244,6 +251,13 @@ unsigned int mraa_adc_supported_bits();
|
||||
*/
|
||||
mraa_result_t mraa_set_log_level(int level);
|
||||
|
||||
/**
|
||||
* Return the Platform's Name, If no platform detected return "Unknown"
|
||||
*
|
||||
* @return platform name
|
||||
*/
|
||||
char* mraa_get_platform_name();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -44,7 +44,7 @@ namespace mraa {
|
||||
*
|
||||
* @return libmraa version (e.g. v0.4.0-20-gb408207)
|
||||
*/
|
||||
std::string getVersion()
|
||||
inline std::string getVersion()
|
||||
{
|
||||
std::string ret = mraa_get_version();
|
||||
return ret;
|
||||
@@ -59,7 +59,7 @@ std::string getVersion()
|
||||
* @param priority Value from typically 0 to 99
|
||||
* @return The priority value set
|
||||
*/
|
||||
int setPriority(const unsigned int priority)
|
||||
inline int setPriority(const unsigned int priority)
|
||||
{
|
||||
return mraa_set_priority(priority);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ int setPriority(const unsigned int priority)
|
||||
*
|
||||
* @return mraa_platform_t Platform type enum
|
||||
*/
|
||||
mraa_platform_t getPlatformType()
|
||||
inline mraa_platform_t getPlatformType()
|
||||
{
|
||||
return mraa_get_platform_type();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ mraa_platform_t getPlatformType()
|
||||
*
|
||||
* @param result the result to print
|
||||
*/
|
||||
void printError(mraa_result_t result)
|
||||
inline void printError(mraa_result_t result)
|
||||
{
|
||||
mraa_result_print(result);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ void printError(mraa_result_t result)
|
||||
* @param mode the mode to be tested.
|
||||
* @return boolean if the mode is supported, 0=false.
|
||||
*/
|
||||
bool pinModeTest(int pin, mraa_pinmodes_t mode)
|
||||
inline bool pinModeTest(int pin, mraa_pinmodes_t mode)
|
||||
{
|
||||
return (bool) mraa_pin_mode_test(pin,mode);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ bool pinModeTest(int pin, mraa_pinmodes_t mode)
|
||||
*
|
||||
* @return raw bits being read from kernel module. Zero if no ADC
|
||||
*/
|
||||
unsigned int adcRawBits()
|
||||
inline unsigned int adcRawBits()
|
||||
{
|
||||
return mraa_adc_raw_bits();
|
||||
}
|
||||
@@ -111,18 +111,30 @@ unsigned int adcRawBits()
|
||||
*
|
||||
* @return return actual bit size the adc value should be understood as.
|
||||
*/
|
||||
unsigned int adcSupportedBits()
|
||||
inline unsigned int adcSupportedBits()
|
||||
{
|
||||
return mraa_adc_supported_bits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Platform Name. "Unknown" if no platform inited.
|
||||
*
|
||||
* @return platform name
|
||||
*/
|
||||
inline std::string getPlatformName()
|
||||
{
|
||||
std::string ret_val(mraa_get_platform_name());
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the log level to use from 0-7 where 7 is very verbose. These are the
|
||||
* syslog log levels, see syslog(3) for more information on the levels.
|
||||
*
|
||||
* @param level
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setLogLevel(int level)
|
||||
inline mraa_result_t setLogLevel(int level)
|
||||
{
|
||||
return mraa_set_log_level(level);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "gpio.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -34,7 +35,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 */
|
||||
@@ -80,12 +81,20 @@ class Gpio {
|
||||
* you so this may not always work as expected.
|
||||
*/
|
||||
Gpio(int pin, bool owner=true, bool raw=false) {
|
||||
if (raw)
|
||||
if (raw) {
|
||||
m_gpio = mraa_gpio_init_raw(pin);
|
||||
else
|
||||
}
|
||||
else {
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
if (!owner)
|
||||
}
|
||||
|
||||
if (m_gpio == NULL) {
|
||||
throw std::invalid_argument("Invalid GPIO pin specified");
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
mraa_gpio_owner(m_gpio, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio object destructor, this will only unexport the gpio if we where
|
||||
|
@@ -61,7 +61,7 @@ typedef struct _i2c* mraa_i2c_context;
|
||||
mraa_i2c_context mraa_i2c_init(int bus);
|
||||
|
||||
/**
|
||||
* Initialise i2c context, passing in spi bus to use.
|
||||
* Initialise i2c context, passing in the i2c bus to use.
|
||||
*
|
||||
* @param bus The i2c bus to use i.e. /dev/i2c-2 would be "2"
|
||||
* @return i2c context or NULL
|
||||
@@ -69,7 +69,7 @@ mraa_i2c_context mraa_i2c_init(int bus);
|
||||
mraa_i2c_context mraa_i2c_init_raw(unsigned int bus);
|
||||
|
||||
/**
|
||||
* Sets the frequency of the i2c context
|
||||
* Sets the frequency of the i2c context. Most platforms do not support this.
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param hz The bus frequency in hertz
|
||||
@@ -78,7 +78,8 @@ mraa_i2c_context mraa_i2c_init_raw(unsigned int bus);
|
||||
mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, int hz);
|
||||
|
||||
/**
|
||||
* Read from an i2c context
|
||||
* Simple bulk read from an i2c context, this will always begin with the i2c
|
||||
* offset 0x0
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data pointer to the byte array to read data in to
|
||||
@@ -88,7 +89,8 @@ mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, int hz);
|
||||
int mraa_i2c_read(mraa_i2c_context dev, uint8_t *data, int length);
|
||||
|
||||
/**
|
||||
* Read a single byte from the i2c context
|
||||
* Simple read for a single byte from the i2c context, this will always begin
|
||||
* with the i2c offset 0x0
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @return The result of the read or -1 if failed
|
||||
@@ -96,7 +98,26 @@ int mraa_i2c_read(mraa_i2c_context dev, uint8_t *data, int length);
|
||||
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
|
||||
|
||||
/**
|
||||
* Write to an i2c context
|
||||
* Read a single byte from i2c context, from designated register
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param command The register
|
||||
* @return The result of the read or -1 if failed
|
||||
*/
|
||||
uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Read a single word from i2c context, from designated register
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param command The register
|
||||
* @return The result of the read or -1 if failed
|
||||
*/
|
||||
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Write length bytes to the bus, the first byte in the array is the
|
||||
* command/register to write
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data pointer to the byte array to be written
|
||||
@@ -106,7 +127,7 @@ uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
|
||||
mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t *data, int length);
|
||||
|
||||
/**
|
||||
* Write a single byte to an i2c context
|
||||
* Write a single byte to an i2c context, always at offset 0x0
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data The byte to write
|
||||
@@ -114,6 +135,26 @@ mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t *data, int leng
|
||||
*/
|
||||
mraa_result_t mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data);
|
||||
|
||||
/**
|
||||
* Write a single byte to an i2c context
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data The byte to write
|
||||
* @param command The register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Write a single word to an i2c context
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param data The word to write
|
||||
* @param command The register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Sets the i2c context address.
|
||||
*
|
||||
@@ -123,7 +164,7 @@ mraa_result_t mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data);
|
||||
* general call address.
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, int address);
|
||||
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, uint8_t address);
|
||||
|
||||
/**
|
||||
* De-inits an mraa_i2c_context device
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "i2c.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -48,11 +49,17 @@ class I2c {
|
||||
* @param raw Whether to disable pinmapper for your board
|
||||
*/
|
||||
I2c(int bus, bool raw=false) {
|
||||
if (raw)
|
||||
if (raw) {
|
||||
m_i2c = mraa_i2c_init_raw(bus);
|
||||
else
|
||||
}
|
||||
else {
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
}
|
||||
if (m_i2c == NULL) {
|
||||
throw std::invalid_argument("Invalid i2c bus");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the I2c Bus used. This does not guarrantee the bus will not
|
||||
* be usable by anyone else or communicates this disconnect to any
|
||||
@@ -61,6 +68,7 @@ class I2c {
|
||||
~I2c() {
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the i2c Frequency for communication. Your board may not support
|
||||
* the set frequency. Anyone can change this at any time and this will
|
||||
@@ -72,6 +80,7 @@ class I2c {
|
||||
mraa_result_t frequency(int hz) {
|
||||
return mraa_i2c_frequency(m_i2c, hz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the slave to talk to, typically called before every read/write
|
||||
* operation
|
||||
@@ -79,45 +88,81 @@ class I2c {
|
||||
* @param address Communicate to the i2c slave on this address
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t address(int address) {
|
||||
mraa_result_t address(uint8_t address) {
|
||||
return mraa_i2c_address(m_i2c, address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read exactly one byte from the bus
|
||||
*
|
||||
* @return char read from the bus
|
||||
*/
|
||||
unsigned char read() {
|
||||
return (unsigned char) mraa_i2c_read_byte(m_i2c);
|
||||
uint8_t read() {
|
||||
return (uint8_t) mraa_i2c_read_byte(m_i2c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mutliple bytes from the bus
|
||||
*
|
||||
* @param data Buffer to write into
|
||||
* @param length Size of read
|
||||
* @param command The i2c command
|
||||
* @return length of the read or 0 if failed
|
||||
*/
|
||||
int read(char *data, size_t length) {
|
||||
uint8_t read(char *data, size_t length) {
|
||||
return mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length);
|
||||
}
|
||||
/**
|
||||
* Read length bytes from the bus, and return as a std::string note
|
||||
* that this is not a null terminated string
|
||||
*
|
||||
* @param length Size of read to make
|
||||
* @return pointer to std::string
|
||||
*/
|
||||
std::string read(size_t length) {
|
||||
char* data = (char*) malloc(sizeof(char) * length);
|
||||
mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length);
|
||||
std::string str(data, (int) length);
|
||||
|
||||
/**
|
||||
* Read length bytes from the bus, and return as a std::string note
|
||||
* that this is not a null terminated string
|
||||
*
|
||||
* @param length Size of read in bytes to make
|
||||
* @return pointer to std::string
|
||||
*/
|
||||
std::string read(int length) {
|
||||
uint8_t* data = (uint8_t*) malloc(sizeof(uint8_t) * length);
|
||||
mraa_i2c_read(m_i2c, data, length);
|
||||
std::string str((char*)data, length);
|
||||
free(data);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write one byte to the bus
|
||||
* Read byte from an i2c register
|
||||
*
|
||||
* @param data Buffer to send on the bus
|
||||
* @param reg Register to read from
|
||||
* @return char read from register
|
||||
*/
|
||||
uint8_t readReg(uint8_t reg) {
|
||||
return mraa_i2c_read_byte_data(m_i2c, reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read word from an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
* @return char read from register
|
||||
*/
|
||||
uint16_t readWordReg(uint8_t reg) {
|
||||
return mraa_i2c_read_word_data(m_i2c, reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a byte on the bus
|
||||
*
|
||||
* @param data The byte to send on the bus
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(uint8_t data) {
|
||||
return mraa_i2c_write_byte(m_i2c, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write length bytes to the bus, the first byte in the array is the
|
||||
* command/register to write
|
||||
*
|
||||
* @param data Buffer to send on the bus, first byte is i2c command
|
||||
* @param length Size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
@@ -126,25 +171,25 @@ class I2c {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an i2c register
|
||||
* Write a byte to an i2c register
|
||||
*
|
||||
* @param reg Register to write to
|
||||
* @param data Value to write to register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t writeReg(char reg, char data) {
|
||||
const unsigned char buf[2] = {(unsigned char) reg, (unsigned char) data};
|
||||
return mraa_i2c_write(m_i2c, buf, 2);
|
||||
mraa_result_t writeReg(uint8_t reg, uint8_t data) {
|
||||
return mraa_i2c_write_byte_data(m_i2c, data, reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write multiple bytes to the bus
|
||||
* Write a word to an i2c register
|
||||
*
|
||||
* @param data The byte to send on the bus
|
||||
* @param reg Register to write to
|
||||
* @param data Value to write to register
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(char data) {
|
||||
return mraa_i2c_write_byte(m_i2c, data);
|
||||
mraa_result_t writeWordReg(uint8_t reg, uint16_t data) {
|
||||
return mraa_i2c_write_word_data(m_i2c, data, reg);
|
||||
}
|
||||
private:
|
||||
mraa_i2c_context m_i2c;
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "pwm.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -47,12 +48,20 @@ class Pwm {
|
||||
* if the pinmapper exported it
|
||||
*/
|
||||
Pwm(int pin, int chipid=-1, bool owner = true) {
|
||||
if (chipid == -1)
|
||||
if (chipid == -1) {
|
||||
m_pwm = mraa_pwm_init(pin);
|
||||
else
|
||||
}
|
||||
else {
|
||||
m_pwm = mraa_pwm_init_raw(pin, chipid);
|
||||
if (!owner)
|
||||
}
|
||||
|
||||
if (m_pwm == NULL) {
|
||||
throw std::invalid_argument("Error initialising PWM on pin");
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
mraa_pwm_owner(m_pwm, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pwm destructor
|
||||
|
@@ -96,7 +96,7 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
|
||||
uint8_t mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
|
||||
/** Write Buffer of bytes to the SPI device. The pointer return has to be
|
||||
* free'd by the caller.
|
||||
* free'd by the caller. It will return a NULL pointer in cases of error.
|
||||
*
|
||||
* @param dev The Spi context
|
||||
* @param data to send
|
||||
@@ -105,6 +105,17 @@ uint8_t mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
*/
|
||||
uint8_t* mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length);
|
||||
|
||||
/** Transfer Buffer of bytes to the SPI device. Both send and recv buffers
|
||||
* are passed in
|
||||
*
|
||||
* @param dev The Spi context
|
||||
* @param data to send
|
||||
* @param rxbuf buffer to recv data back, may be NULL
|
||||
* @param length elements within buffer, Max 4096
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
|
||||
|
||||
/**
|
||||
* Change the SPI lsb mode
|
||||
*
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spi.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -44,6 +45,10 @@ class Spi {
|
||||
*/
|
||||
Spi(int bus) {
|
||||
m_spi = mraa_spi_init(bus);
|
||||
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument("Error initialising SPI bus");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Closes spi bus
|
||||
@@ -79,7 +84,9 @@ class Spi {
|
||||
return (char) mraa_spi_write(m_spi, (uint8_t) data);
|
||||
}
|
||||
/**
|
||||
* Write buffer of bytes to SPI device
|
||||
* Write buffer of bytes to SPI device The pointer return has to be
|
||||
* free'd by the caller. It will return a NULL pointer in cases of
|
||||
* error
|
||||
*
|
||||
* @param data buffer to send
|
||||
* @param length size of buffer to send
|
||||
@@ -88,6 +95,20 @@ class Spi {
|
||||
char* write(char* data, size_t length) {
|
||||
return (char*) mraa_spi_write_buf(m_spi, (uint8_t *) data, (int) length);
|
||||
}
|
||||
#ifndef SWIG
|
||||
/**
|
||||
* Transfer data to and from SPI device Receive pointer may be null if return
|
||||
* data is not needed.
|
||||
*
|
||||
* @param data buffer to send
|
||||
* @param rxBuf buffer to optionally receive data from spi device
|
||||
* @param length size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t transfer(char* data, char* rxBuf, size_t length) {
|
||||
return mraa_spi_transfer_buf(m_spi, (uint8_t *) data, (uint8_t *)rxBuf, (int) length);
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* Change the SPI lsb mode
|
||||
*
|
||||
|
@@ -40,6 +40,8 @@ typedef enum {
|
||||
MRAA_INTEL_GALILEO_GEN1 = 0, /**< The Generation 1 Galileo platform (RevD) */
|
||||
MRAA_INTEL_GALILEO_GEN2 = 1, /**< The Generation 2 Galileo platform (RevG/H) */
|
||||
MRAA_INTEL_EDISON_FAB_C = 2, /**< The Intel Edison (FAB C) */
|
||||
MRAA_INTEL_DE3815 = 3, /**< The Intel DE3815 Baytrail NUC */
|
||||
MRAA_INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
|
||||
|
||||
MRAA_UNKNOWN_PLATFORM = 99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
|
||||
} mraa_platform_t;
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "uart.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -43,6 +44,10 @@ class Uart {
|
||||
*/
|
||||
Uart(int uart) {
|
||||
m_uart = mraa_uart_init(uart);
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Error initialising UART");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Uart destructor
|
||||
|
19
cmake/Toolchains/oe-sdk_cross.cmake
Normal file
19
cmake/Toolchains/oe-sdk_cross.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
# this toolchain file comes from gnuradio project
|
||||
|
||||
set( CMAKE_SYSTEM_NAME Linux )
|
||||
#set( CMAKE_C_COMPILER $ENV{CC} )
|
||||
#set( CMAKE_CXX_COMPILER $ENV{CXX} )
|
||||
string(REGEX MATCH "sysroots/([a-zA-Z0-9]+)" CMAKE_SYSTEM_PROCESSOR $ENV{SDKTARGETSYSROOT})
|
||||
string(REGEX REPLACE "sysroots/" "" CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
|
||||
set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS} CACHE STRING "" FORCE )
|
||||
set( CMAKE_C_FLAGS $ENV{CFLAGS} CACHE STRING "" FORCE ) #same flags for C sources
|
||||
set( CMAKE_LDFLAGS_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE ) #same flags for C sources
|
||||
set( CMAKE_LIBRARY_PATH ${OECORE_TARGET_SYSROOT}/usr/lib )
|
||||
set( CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT} $ENV{OECORE_NATIVE_SYSROOT} )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
|
||||
set( CMAKE_INSTALL_PREFIX $ENV{OECORE_TARGET_SYSROOT}/usr CACHE STRING "" FORCE)
|
||||
set( ORC_INCLUDE_DIRS $ENV{OECORE_TARGET_SYSROOT}/usr/include/orc-0.4 )
|
||||
set( ORC_LIBRARY_DIRS $ENV{OECORE_TARGET_SYSROOT}/usr/lib )
|
||||
|
@@ -16,19 +16,52 @@ cmake ..
|
||||
make
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Our cmake configure has a number of options, `cmake -i` will ask you all sorts
|
||||
of interesting questions, you can disable swig modules, build documentation
|
||||
etc...
|
||||
Our cmake configure has a number of options, cmake-gui or ccmake can show you
|
||||
all the options. The interesting ones are detailed below:
|
||||
|
||||
Few recommended options:
|
||||
Changing install path from /usr/local to /usr
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=/usr
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=/usr
|
||||
|
||||
Building debug build:
|
||||
-DCMAKE_BUILD_TYPE=DEBUG
|
||||
-DCMAKE_BUILD_TYPE=DEBUG
|
||||
|
||||
Using clang instead of gcc:
|
||||
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang
|
||||
|
||||
Building with an older version of swig (swig 2.0+) requires the disabling of javascript:
|
||||
-DBUILDSWIGNODE=OFF
|
||||
|
||||
Disabling python module building
|
||||
-DBUILDSWIGPYTHON=OFF
|
||||
|
||||
Building doc, this will require sphinx & doxygen
|
||||
-BUILDDOC=ON
|
||||
|
||||
Using a yocto/oe toolchain
|
||||
--------------------------
|
||||
|
||||
In order to compile with a yocto/oe toolchain use the following toolchain file.
|
||||
This works well on the edison 1.6 SDK. First source the environment file, then
|
||||
use our cmake toolchain file.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
source /opt/poky-edison/1.6/environment-setup-core2-32-poky-linux
|
||||
mkdir build
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/oe-sdk_cross.cmake ..
|
||||
make
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Using coverity
|
||||
--------------
|
||||
|
||||
Static analysis is routinely performed using coverity on libmraa's codebase.
|
||||
This is the procedure to submit a build to coverity. You'll need to install
|
||||
coverity-submit for your OS.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
mkdir covbuild/ && cd covbuild
|
||||
cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
|
||||
cov-build --dir cov-int make
|
||||
tar caf mraa.tar.bz2 cov-int
|
||||
~~~~~~~~~~~~~
|
||||
|
@@ -15,3 +15,11 @@ on github.
|
||||
If you'd rather not use github you are more than welcome to send git formatted
|
||||
patches to brendan.le.foll@intel.com.
|
||||
|
||||
# Basic rules
|
||||
- Your code must build
|
||||
- Commits must have a sign-off line by at least yourself
|
||||
- Commits must be named <file/module>: Some decent description
|
||||
- Try not to break master. In any commit.
|
||||
- Try to split commits up logically, you will be asked to rebase them if they
|
||||
are not.
|
||||
- Try to stick to the established coding style reguardless of your personal feeling for it!
|
||||
|
@@ -1,11 +1,19 @@
|
||||
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.
|
||||
Intel(R) Edison is a dual core Silvermont Atom(TM) 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
|
||||
|
||||
UART
|
||||
----
|
||||
On both the Arduino board and the breakout board, The avaible UART interface is on /dev/ttyMFD1
|
||||
|
||||
Intel Arduino board
|
||||
-------------------
|
||||
The Edison used with the Arduino board has the following limitations
|
||||
in libmraa:
|
||||
|
||||
@@ -14,3 +22,72 @@ 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.
|
||||
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
|
||||
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio
|
||||
|
||||
Intel(R) breakout board
|
||||
-----------------------
|
||||
|
||||
- Both I2C buses are avaible 1 & 6
|
||||
- IO on the miniboard is 1.8V
|
||||
|
||||
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,7 +1,7 @@
|
||||
Galileo Gen 1 - Rev D {#galileorevd}
|
||||
=====================
|
||||
|
||||
Galileo is a microcontroller board based on the Intel® Quark SoC X1000
|
||||
Galileo is a microcontroller board based on the Intel(R) Quark(TM) SoC X1000
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip.
|
||||
|
||||
The rev D board has the following limitations in libmraa:
|
||||
@@ -9,3 +9,5 @@ The rev D board has the following limitations in libmraa:
|
||||
- gpio register access via /dev/uio is limited to pin2 and 3
|
||||
- gpio interupts will only work on GPIO_EDGE_BOTH
|
||||
- adc kernel module will return 12bit number. MRAA defaults shift this to 10bits
|
||||
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
|
||||
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio
|
||||
|
@@ -1,14 +1,19 @@
|
||||
Galileo Gen 2 - Rev H {#galileorevh}
|
||||
=====================
|
||||
|
||||
Galileo is a microcontroller board based on the Intel® Quark SoC X1000
|
||||
Galileo is a microcontroller board based on the Intel(R) Quark(TM) SoC X1000
|
||||
Application Processor, a 32-bit Intel Pentium-class system on a chip.
|
||||
|
||||
The Gen 2 board has the following limitations in libmraa:
|
||||
|
||||
- i2c is set at 400Khz speed cannot be changed without reloading kernel module
|
||||
- i2c bus is shared with multiple devices, scanning it usually fails
|
||||
- i2c is set at 400Khz speed cannot be changed without reloading kernel module,
|
||||
the driver is intel_qrk_gip_i2c and the parameter is i2c_std_mode which must
|
||||
be set to 1 in order to set the i2c bus speed to 100Khz
|
||||
- i2c bus is shared with multiple devices in kernel space, scanning it usually
|
||||
fails
|
||||
- pwm period is set globally for all pwm channels, when changed this will halt
|
||||
all pwm channels
|
||||
- adc kernel module will return 12bit number but the ADC itself only has an
|
||||
accuracy of 10bits.
|
||||
- AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything
|
||||
else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio
|
||||
|
@@ -1,11 +1,14 @@
|
||||
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
|
||||
structured and sane API with port names/numbering that match boards & with
|
||||
bindings to javascript & python.
|
||||
Libmraa is a C/C++ library with bindings to javascript & python to interface
|
||||
with the IO on Galileo, Edison & other platforms, with a structured and sane
|
||||
API where port names/numbering matches the board that you are on. Use of
|
||||
libmraa does not tie you to specific hardware with board detection done at
|
||||
runtime you can create portable code that will work across the supported
|
||||
platforms.
|
||||
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
The intent is to make it easier for developers and sensor manufacturers to map
|
||||
their sensors & actuators on top of supported hardware and to allow control of
|
||||
low level communication protocol by high level languages & constructs.
|
||||
|
||||
@@ -36,24 +39,28 @@ Specific platform information for supported platforms is documented here:
|
||||
|
||||
- @ref galileorevd
|
||||
- @ref galileorevh
|
||||
- @ref edison
|
||||
- @ref de3815
|
||||
- @ref minnowmax
|
||||
|
||||
### ENV RECOMENDATIONS
|
||||
|
||||
All of these are 'optional', however they are recommended. Only a C compiler,
|
||||
cmake, libm and pthreads are technically required to compile.
|
||||
|
||||
- Swig 3.0.1+ built with node.js & python support (0.10.x)
|
||||
- Swig 3.0.1+ built with node.js (0.10.x) & python support
|
||||
- doxygen
|
||||
- sphinx (requires doxygen)
|
||||
- pygments
|
||||
|
||||
## 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 +68,40 @@ 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.4**
|
||||
* pwm read_* fix introduced in 0.5.3
|
||||
* improved npmpkg support
|
||||
|
||||
**0.5.3**
|
||||
* OE toolchain support added to CMake
|
||||
* Various UART fixes
|
||||
* SPI add CS exposure
|
||||
* Remove functions from mraa.c into modules
|
||||
* Rework of support for mmap
|
||||
* Intel Edison MMAP support added. Read and Write
|
||||
* I2C clean up, add cleaner functions
|
||||
* MinnowBoard Max support added
|
||||
* PWM period is written before duty
|
||||
* Node GYP build supported added
|
||||
* Add Get Platform Name function
|
||||
|
||||
**0.5.2**
|
||||
* pwm improvement & bugfix
|
||||
* spi mraa_spi_bit_per_word fix
|
||||
* new spi transfer function
|
||||
* i2c object api uses uint8_t
|
||||
* i2c readReg() calls added
|
||||
* edison i2c bus now defaults to a sensible value
|
||||
* edison uart enable support
|
||||
* edison hardware CS exposed as IO10
|
||||
* DE3815tykhe NUC support
|
||||
|
||||
**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
|
||||
|
38
docs/intel_de3815.md
Normal file
38
docs/intel_de3815.md
Normal file
@@ -0,0 +1,38 @@
|
||||
Intel(R) NUC DE3815tykhe {#de3815}
|
||||
=============
|
||||
|
||||
The DE3815 NUC Kit is a single core Atom(TM) clocked at 1.46GHz.
|
||||
http://www.intel.com/content/www/us/en/nuc/nuc-kit-de3815tykhe.html
|
||||
|
||||
Interface notes
|
||||
---------------
|
||||
**GPIO** Not yet implemented.
|
||||
|
||||
**PWM** Functionality for the PWM is provided by the `pwm_lpss` module `CONFIG_PWM_LPSS`
|
||||
|
||||
**I2C** Depending on your system you may need to load `i2c-dev`
|
||||
|
||||
Custom Solutions Header mapping
|
||||
-------------------------------
|
||||
Based on: http://downloadmirror.intel.com/23745/eng/DE3815TYBE_TechProdSpec06.pdf
|
||||
|
||||
| MRAA Number | Physical Pin | Function | Notes |
|
||||
|-------------|--------------|--------------|----------------------|
|
||||
| 0 | 1 | 1.8V sby | |
|
||||
| 1 | 2 | GND | |
|
||||
| 2 | 3 | HDMI_CEC | |
|
||||
| 3 | 4 | DMIC_CLK | |
|
||||
| 4 | 5 | 3.3V sby | |
|
||||
| 5 | 6 | DMIC_DATA | |
|
||||
| 6 | 7 | Key (no pin) | |
|
||||
| 7 | 8 | SMB_ALERT# | |
|
||||
| 8 | 9 | 5V sby (2A) | |
|
||||
| 9 | 10 | SCI_SMI_GPIO | |
|
||||
| 10 | 11 | PWM[0] | PWM Chip 0 Channel 0 |
|
||||
| 11 | 12 | PWM[1] | PWM Chip 0 Channel 1 |
|
||||
| 12 | 13 | I2C0_CLK | /dev/i2c-0 SCL |
|
||||
| 13 | 14 | I2C0_DATA | /dev/i2c-0 SDA |
|
||||
| 14 | 15 | I2C1_CLK | /dev/i2c-1 SCL |
|
||||
| 15 | 16 | I2C1_DATA | /dev/i2c-1-SDA |
|
||||
| 16 | 17 | SMB_CLK | |
|
||||
| 17 | 18 | SMB_DATA | |
|
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...)
|
||||
|
54
docs/minnow_max.md
Normal file
54
docs/minnow_max.md
Normal file
@@ -0,0 +1,54 @@
|
||||
Intel(R) Minnowboard Max {#minnowmax}
|
||||
========================
|
||||
MinnowBoard MAX is an open hardware embedded board designed with the Intel(R)
|
||||
Atom(TM) E38xx series SOC (Fromerly Bay Trail).
|
||||
|
||||
For product overview and faq see
|
||||
http://www.minnowboard.org/faq-minnowboard-max/
|
||||
|
||||
For technical details see http://www.elinux.org/Minnowboard:MinnowMax
|
||||
|
||||
Supported Firmware
|
||||
------------------
|
||||
mraa has only been tested with 64 bit firmware version 0.73 or later.
|
||||
|
||||
Interface notes
|
||||
---------------
|
||||
The low speed I/O connector supported as per table below. This assumes default
|
||||
BIOS settings, as they are not dynamcially detected If any changes are mode
|
||||
(Device Manager -> System Setup -> South Cluster -> LPSS & CSS) them mraa calls
|
||||
will not behave as expected.
|
||||
|
||||
Documentation shows i2c on bus #5, ACPI shows it on bus #6, but driver uses bus
|
||||
#7.
|
||||
|
||||
**SPI operation is not currently supported**
|
||||
|
||||
| MRAA Number | Physical Pin | Function | Sysfs GPIO | Notes |
|
||||
|-------------|---------------|------------|------------|----------------------|
|
||||
| 1 | 1 | GND | | |
|
||||
| 2 | 2 | GND | | |
|
||||
| 3 | 3 | 5v | | |
|
||||
| 4 | 4 | 3.3v | | |
|
||||
| 5 | 5 | SPI_CS | 220 | SPI (not supported) |
|
||||
| 6 | 6 | UART1_TXD | 225 | UART1 |
|
||||
| 7 | 7 | SPI_MISO | 221 | SPI (not supported) |
|
||||
| 8 | 8 | UART1_RXD | 224 | UART1 |
|
||||
| 9 | 9 | SPI_MOSI | 222 | SPI (not supported) |
|
||||
| 10 | 10 | UART1_CTS | 227 | GPIO |
|
||||
| 11 | 11 | SPI_CLK | 223 | SPI (not supported) |
|
||||
| 12 | 12 | UART1_RTS | 226 | GPIO |
|
||||
| 13 | 13 | I2C_SCL | 243 | /dev/i2c-7 |
|
||||
| 14 | 14 | I2S_CLK | 216 | GPIO |
|
||||
| 15 | 15 | I2C_SDA | 242 | /dev/i2c-7 |
|
||||
| 16 | 16 | I2S_FRM | 217 | GPIO |
|
||||
| 17 | 17 | UART2_TXD | 229 | UART2 |
|
||||
| 18 | 18 | I2S_DO | 219 | GPIO |
|
||||
| 19 | 19 | UART2_RXD | 228 | UART2 |
|
||||
| 20 | 20 | I2S_DI | 218 | GPIO |
|
||||
| 21 | 21 | GPIO_S5_0 | 82 | GPIO |
|
||||
| 22 | 22 | PWM0 | 248 | PWM Chip 0 Channel 0 |
|
||||
| 23 | 23 | GPIO_S5_1 | 83 | GPIO |
|
||||
| 24 | 24 | PWM1 | 249 | PWM Chip 1 Channel 0 |
|
||||
| 25 | 25 | S5_4 | 84 | GPIO |
|
||||
| 26 | 26 | IBL_8254 | 208 | GPIO |
|
31
docs/npm.md
Normal file
31
docs/npm.md
Normal file
@@ -0,0 +1,31 @@
|
||||
mraa NPM pkg {#npmpkg}
|
||||
============
|
||||
|
||||
What you are looking at is a tarball made after 'make npmpkg' has been run on
|
||||
our build system. It contains a few prebuilt files in order to build easily
|
||||
with node-gyp on most systems. Note that this is not the preffered way of
|
||||
building libmraa and if you'd like to contribute, please learn how the build
|
||||
system works and get your sources from git.
|
||||
|
||||
Any patches for mraajsJAVASCRIPT_wrap.cxx or version.c will be ignored as these
|
||||
are automatically generated files. When you execute a build from node-gyp/npm
|
||||
you do not generate the mraajsJAVASCRIPT_wrap.cxx file but rather use one that
|
||||
we have generated for you.
|
||||
|
||||
Recreating tarball
|
||||
------------------
|
||||
|
||||
From a checkout of mraa you can do the following to 'generate' this tarball.
|
||||
It's important to not leave a .git directory as npm will then consider the
|
||||
tarball contains a full git tree. Also you need a top level dir which matches
|
||||
the npm pkg name so we create one with a symlink and add the 'h' flag to tar to
|
||||
follow simlinks.
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DBUILDSWIGNODE=ON ..
|
||||
make npmpkg
|
||||
ln -s ../ mraa
|
||||
tar hczv --exclude='build*' --exclude='.gitignore' --exclude='.git' --exclude='build*/*' --exclude='.git/*' -f mraa.tar.gz mraa
|
||||
~~~~~~~~~~~~~
|
@@ -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
|
||||
|
@@ -9,6 +9,7 @@ add_executable (spi_mcp4261 spi_mcp4261.c)
|
||||
add_executable (mmap-io2 mmap-io2.c)
|
||||
add_executable (blink_onboard blink_onboard.c)
|
||||
add_executable (uart_setup uart_setup.c)
|
||||
add_executable (gpio gpio.c)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/api)
|
||||
|
||||
@@ -23,6 +24,7 @@ target_link_libraries (spi_mcp4261 mraa)
|
||||
target_link_libraries (mmap-io2 mraa)
|
||||
target_link_libraries (blink_onboard mraa)
|
||||
target_link_libraries (uart_setup mraa)
|
||||
target_link_libraries (gpio mraa)
|
||||
|
||||
add_subdirectory (c++)
|
||||
|
||||
|
@@ -32,17 +32,17 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
mraa_platform_t platform = mraa_get_platform_type();
|
||||
mraa_gpio_context gpio;
|
||||
char board_name[] = "Some weird devboard that isn't recognised...";
|
||||
mraa_gpio_context gpio, gpio_in = NULL;
|
||||
char* board_name = mraa_get_platform_name();
|
||||
int ledstate = 0;
|
||||
|
||||
switch (platform) {
|
||||
case MRAA_INTEL_GALILEO_GEN1:
|
||||
strcpy(board_name, "Intel Galileo Gen1");
|
||||
gpio = mraa_gpio_init_raw(3);
|
||||
break;
|
||||
case MRAA_INTEL_GALILEO_GEN2:
|
||||
strcpy(board_name, "Intel Galileo Gen2");
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
gpio = mraa_gpio_init(21);
|
||||
break;
|
||||
default:
|
||||
gpio = mraa_gpio_init(13);
|
||||
}
|
||||
@@ -50,8 +50,27 @@ main(int argc, char **argv)
|
||||
fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n",
|
||||
mraa_get_version(), board_name);
|
||||
|
||||
|
||||
if (gpio == NULL) {
|
||||
fprintf(stdout, "Could not initilaize gpio\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// on platforms with physical button use gpio_in
|
||||
if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
|
||||
gpio_in = mraa_gpio_init(14);
|
||||
if (gpio_in != NULL) {
|
||||
mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
|
||||
fprintf(stdout, "Press and hold S1 to stop\n");
|
||||
}
|
||||
}
|
||||
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
|
||||
|
||||
for (;;) {
|
||||
if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) {
|
||||
return 0;
|
||||
}
|
||||
ledstate = !ledstate;
|
||||
mraa_gpio_write(gpio, !ledstate);
|
||||
sleep(1);
|
||||
|
@@ -49,6 +49,7 @@ int main ()
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
fprintf(stdout, "Cycling PWM on IO3 (pwm3) \n");
|
||||
pwm->enable(true);
|
||||
|
||||
float value = 0.0f;
|
||||
while (running == 0) {
|
||||
|
@@ -49,6 +49,7 @@ int main ()
|
||||
spi = new mraa::Spi(0);
|
||||
|
||||
char data[] = {0x00, 100};
|
||||
char rxBuf[2];
|
||||
char *recv;
|
||||
while (running == 0) {
|
||||
int i;
|
||||
@@ -56,14 +57,18 @@ int main ()
|
||||
data[1] = i;
|
||||
recv = spi->write(data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
if (recv) {
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
free(recv);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
for (i = 130; i > 90; i--) {
|
||||
data[1] = i;
|
||||
recv = spi->write(data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",rxBuf[0],rxBuf[1]);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
|
156
examples/gpio.c
Normal file
156
examples/gpio.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mraa/gpio.h"
|
||||
|
||||
extern mraa_board_t* plat;
|
||||
|
||||
char board_name[] = "Some weird devboard that isn't recognised...";
|
||||
|
||||
void
|
||||
print_version() {
|
||||
fprintf(stdout, "Version %s on %s\n", mraa_get_version(), board_name);
|
||||
}
|
||||
|
||||
void
|
||||
print_help() {
|
||||
fprintf(stdout, "list List pins\n");
|
||||
fprintf(stdout, "set pin level Set pin to level (0/1)\n");
|
||||
fprintf(stdout, "get pin Get pin level\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_command_error() {
|
||||
fprintf(stdout, "Invalid command, options are:\n");
|
||||
fprintf(stdout, "list List pins\n");
|
||||
fprintf(stdout, "set pin level Set pin to level (0/1)\n");
|
||||
fprintf(stdout, "get pin Get pin level\n");
|
||||
}
|
||||
|
||||
void
|
||||
list_pins() {
|
||||
const mraa_board_t* platformInfo = plat;
|
||||
int i;
|
||||
for (i = 0; i < platformInfo->phy_pin_count; ++i) {
|
||||
const char *mraa_name = platformInfo->pins[i].name;
|
||||
if (strcmp(mraa_name, "INVALID") != 0) {
|
||||
mraa_pincapabilities_t caps = platformInfo->pins[i].capabilites;
|
||||
fprintf(stdout, "%02d %-8s ", i, mraa_name);
|
||||
if (caps.gpio)
|
||||
fprintf(stdout, "GPIO");
|
||||
if (caps.i2c)
|
||||
fprintf(stdout, "I2C");
|
||||
if (caps.spi)
|
||||
fprintf(stdout, "SPI");
|
||||
if (caps.pwm)
|
||||
fprintf(stdout, "PWM");
|
||||
if (caps.uart)
|
||||
fprintf(stdout, "UART");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
gpio_set(int pin, int level) {
|
||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
||||
if (gpio != NULL) {
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
|
||||
mraa_gpio_write(gpio, level);
|
||||
return MRAA_SUCCESS;
|
||||
} else
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
gpio_get(int pin, int* level) {
|
||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
||||
if (gpio != NULL) {
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_IN);
|
||||
*level = mraa_gpio_read(gpio);
|
||||
return MRAA_SUCCESS;
|
||||
} else
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
mraa_platform_t platform = mraa_get_platform_type();
|
||||
|
||||
switch (platform) {
|
||||
case MRAA_INTEL_GALILEO_GEN1:
|
||||
strcpy(board_name, "Intel Galileo Gen1");
|
||||
break;
|
||||
case MRAA_INTEL_GALILEO_GEN2:
|
||||
strcpy(board_name, "Intel Galileo Gen2");
|
||||
break;
|
||||
case MRAA_INTEL_EDISON_FAB_C:
|
||||
strcpy(board_name, "Intel Edison");
|
||||
break;
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
strcpy(board_name, "Intel Minnowboard Max");
|
||||
break;
|
||||
default:
|
||||
fprintf(stdout, "Unknown platform code %d\n", platform);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (argc == 1) {
|
||||
print_command_error();
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
if (strcmp(argv[1], "list") == 0) {
|
||||
list_pins();
|
||||
} else if (strcmp(argv[1], "help") == 0) {
|
||||
print_help();
|
||||
} else if (strcmp(argv[1], "set") == 0) {
|
||||
if (argc == 4) {
|
||||
int pin = atoi(argv[2]);
|
||||
if (gpio_set(pin, atoi(argv[3])) != MRAA_SUCCESS)
|
||||
fprintf(stdout, "Could not initialize gpio %d\n", pin);
|
||||
} else
|
||||
print_command_error();
|
||||
} else if (strcmp(argv[1], "get") == 0) {
|
||||
if (argc == 3) {
|
||||
int pin = atoi(argv[2]);
|
||||
int level;
|
||||
if (gpio_get(pin, &level) == MRAA_SUCCESS)
|
||||
fprintf(stdout, "Pin %d = %d\n", pin, level);
|
||||
else
|
||||
fprintf(stdout, "Could not initialize gpio %d\n", pin);
|
||||
} else
|
||||
print_command_error();
|
||||
} else {
|
||||
print_command_error();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@@ -24,20 +24,19 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
//! [Interesting]
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
mraa_result_t ret;
|
||||
char* board_name = mraa_get_platform_name();
|
||||
|
||||
ret = mraa_set_log_level(LOG_DEBUG);
|
||||
|
||||
fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version());
|
||||
fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);
|
||||
|
||||
mraa_deinit();
|
||||
|
||||
return ret;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@@ -81,7 +81,7 @@ main(int argc, char **argv)
|
||||
mraa_init();
|
||||
float direction = 0;
|
||||
int16_t x = 0, y = 0, z = 0;
|
||||
char rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
|
||||
//! [Interesting]
|
||||
mraa_i2c_context i2c;
|
||||
@@ -99,10 +99,23 @@ main(int argc, char **argv)
|
||||
mraa_i2c_write(i2c, rx_tx_buf, 2);
|
||||
|
||||
for(;;) {
|
||||
#if 0
|
||||
int i = 0;
|
||||
//alternative, equivalent method which helps to understand exactly what
|
||||
//the below does
|
||||
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
||||
for (i = 0; i < DATA_REG_SIZE; i++) {
|
||||
mraa_i2c_read_byte_data(i2c, HMC5883L_DATA_REG+i);
|
||||
}
|
||||
#endif
|
||||
// first 'select' the register we want to read from
|
||||
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_write_byte(i2c, HMC5883L_DATA_REG);
|
||||
|
||||
// then we read from that register incrementing with every read the
|
||||
// chosen register
|
||||
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
||||
// this call behaves very similarly to the Wire receive() call
|
||||
mraa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
|
||||
|
37
examples/javascript/rgblcd.js
Normal file
37
examples/javascript/rgblcd.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var m = require('mraa'); //require mraa
|
||||
|
||||
// helper function to go from hex val to dec
|
||||
function char(x) { return parseInt(x, 16); }
|
||||
|
||||
x = new m.I2c(0)
|
||||
x.address(0x62)
|
||||
x.writeReg(0, 0)
|
||||
x.writeReg(1, 0)
|
||||
|
||||
x.writeReg(char('0x08'), char('0xAA'))
|
||||
x.writeReg(char('0x04'), 255)
|
||||
x.writeReg(char('0x02'), 255)
|
@@ -25,5 +25,9 @@
|
||||
import mraa
|
||||
|
||||
print (mraa.getVersion())
|
||||
x = mraa.Aio(0)
|
||||
print (x.read())
|
||||
|
||||
try:
|
||||
x = mraa.Aio(0)
|
||||
print (x.read())
|
||||
except:
|
||||
print ("Are you sure you have an ADC?")
|
||||
|
@@ -25,8 +25,16 @@
|
||||
import mraa
|
||||
import time
|
||||
|
||||
class Counter:
|
||||
count = 0
|
||||
|
||||
c = Counter()
|
||||
|
||||
# inside a python interupt you cannot use 'basic' types so you'll need to use
|
||||
# objects
|
||||
def test(args):
|
||||
print("wooo")
|
||||
c.count+=1
|
||||
|
||||
x = mraa.Gpio(6)
|
||||
x.dir(mraa.DIR_IN)
|
||||
|
@@ -28,10 +28,12 @@ import mraa
|
||||
# to a nice shade of purple
|
||||
x = mraa.I2c(0)
|
||||
x.address(0x62)
|
||||
x.writeReg(0,0)
|
||||
x.writeReg(1,0)
|
||||
|
||||
# Be careful that your i2c device can actually handle a 'batch' handling of
|
||||
# such data, this is not typical in arduino type devices
|
||||
s = "\x08\xAA\x04\xFF\x02\xFF"
|
||||
x.write(s)
|
||||
# initialise device
|
||||
x.writeReg(0, 0)
|
||||
x.writeReg(1, 0)
|
||||
|
||||
# sent RGB color data
|
||||
x.writeReg(0x08, 0xAA)
|
||||
x.writeReg(0x04, 255)
|
||||
x.writeReg(0x02, 255)
|
||||
|
40
include/intel_de3815.h
Normal file
40
include/intel_de3815.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#define MRAA_INTEL_DE3815_PINCOUNT 18
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_de3815();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
41
include/intel_minnow_max.h
Normal file
41
include/intel_minnow_max.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
// +1 as pins are "1 indexed"
|
||||
#define MRAA_INTEL_MINNOW_MAX_PINCOUNT (26 + 1)
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_minnow_max();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -42,10 +42,7 @@ typedef struct {
|
||||
|
||||
mraa_result_t (*gpio_write_pre) (mraa_gpio_context dev, int value);
|
||||
mraa_result_t (*gpio_write_post) (mraa_gpio_context dev, int value);
|
||||
|
||||
mraa_result_t (*gpio_mmaped_write_replace) (mraa_gpio_context dev, int value);
|
||||
mraa_result_t (*gpio_mmaped_write_pre) (mraa_gpio_context dev, int value);
|
||||
mraa_result_t (*gpio_mmaped_write_post) (mraa_gpio_context dev, int value);
|
||||
mraa_result_t (*gpio_mmap_setup) (mraa_gpio_context dev, mraa_boolean_t en);
|
||||
|
||||
mraa_result_t (*i2c_init_pre) (unsigned int bus);
|
||||
mraa_result_t (*i2c_init_post) (mraa_i2c_context dev);
|
||||
@@ -60,4 +57,7 @@ typedef struct {
|
||||
|
||||
mraa_result_t (*spi_init_pre) (int bus);
|
||||
mraa_result_t (*spi_init_post) (mraa_spi_context spi);
|
||||
|
||||
mraa_result_t (*uart_init_pre) (int index);
|
||||
mraa_result_t (*uart_init_post) (mraa_uart_context uart);
|
||||
} mraa_adv_func_t;
|
||||
|
@@ -38,55 +38,12 @@ extern mraa_adv_func_t* advance_func;
|
||||
extern mraa_board_t* plat;
|
||||
|
||||
/**
|
||||
* Will check input is valid for gpio and will also setup required multiplexers.
|
||||
* @param pin the pin as read from the board surface. i.e IO3 would be 3/
|
||||
* @return the pin as found in the pinmap
|
||||
*/
|
||||
unsigned int mraa_setup_gpio(int pin);
|
||||
|
||||
/**
|
||||
* Will check input is valid for aio and will also setup required multiplexers.
|
||||
* @param pin the pin as read from the board surface. i.e A3 would be 3/
|
||||
* @return the pin as found in the pinmap
|
||||
*/
|
||||
unsigned int mraa_setup_aio(int pin);
|
||||
|
||||
/**
|
||||
* Setup i2c interface, sets up multiplexer on device.
|
||||
* Takes in pin information and sets up the multiplexors.
|
||||
*
|
||||
* @return unsigned int if using /dev/i2c-2 returned would be 2
|
||||
* @param meta
|
||||
* @return mraa result type indicating success of actions.
|
||||
*/
|
||||
unsigned int mraa_setup_i2c(int bus);
|
||||
|
||||
/** Setup spi interface, sets up multiplexer on device.
|
||||
*
|
||||
* @return spi bus type
|
||||
*/
|
||||
mraa_spi_bus_t* mraa_setup_spi(int bus);
|
||||
|
||||
/**
|
||||
* Will check input is valid for pwm and will also setup required multiplexers.
|
||||
* IF the pin also does gpio (strong chance), DO NOTHING, REV D quirk
|
||||
* @param pin the pin as read from the board surface.
|
||||
* @return the pwm pin_info_t of that IO pin
|
||||
*/
|
||||
mraa_pin_t* mraa_setup_pwm(int pin);
|
||||
|
||||
/**
|
||||
* Setup gpio mux to go straight to SoC, galileo.
|
||||
*
|
||||
* @param pin physical pin to use
|
||||
* @return mraa_mmap_pin_t
|
||||
*/
|
||||
mraa_mmap_pin_t* mraa_setup_mmap_gpio(int pin);
|
||||
|
||||
/**
|
||||
* Swap Directional mode.
|
||||
*
|
||||
* @param pin physical pin to operate on
|
||||
* @return out direction to setup. 1 for output 0 for input
|
||||
*/
|
||||
mraa_result_t mraa_swap_complex_gpio(int pin, int out);
|
||||
mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
|
||||
|
||||
/**
|
||||
* Setup uart muxes to exposes the pins physically.
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "mraa.h"
|
||||
|
||||
// general status failures for internal functions
|
||||
#define MRAA_PLATFORM_NO_INIT -3
|
||||
@@ -45,10 +46,8 @@ struct _gpio {
|
||||
pthread_t thread_id; /**< the isr handler thread id */
|
||||
int isr_value_fp; /**< the isr file pointer on the value */
|
||||
mraa_boolean_t owner; /**< If this context originally exported the pin */
|
||||
mraa_boolean_t mmap;
|
||||
void *reg;
|
||||
unsigned int reg_sz;
|
||||
unsigned int reg_bit_pos;
|
||||
mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
|
||||
int (*mmap_read) (mraa_gpio_context dev);
|
||||
/*@}*/
|
||||
};
|
||||
|
||||
@@ -83,3 +82,12 @@ struct _aio {
|
||||
int adc_in_fp; /**< File Pointer to raw sysfs */
|
||||
int value_bit; /**< 10 bits by default. Can be increased if board */
|
||||
};
|
||||
|
||||
/**
|
||||
* A structure representing a UART device
|
||||
*/
|
||||
struct _uart {
|
||||
/*@{*/
|
||||
int index; /**< the uart index, as known to the os. */
|
||||
/*@}*/
|
||||
};
|
||||
|
101
include/smbus.h
101
include/smbus.h
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Author: Robin Knight (robin.knight@roadnarrows.com)
|
||||
*
|
||||
* Copyright © 2009 RoadNarrows LLC.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that
|
||||
* (1) The above copyright notice and the following two paragraphs
|
||||
* appear in all copies of the source code and (2) redistributions
|
||||
* including binaries reproduces these notices in the supporting
|
||||
* documentation. Substantial modifications to this software may be
|
||||
* copyrighted by their authors and need not follow the licensing terms
|
||||
* described here, provided that the new terms are clearly indicated in
|
||||
* all files where they apply.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
|
||||
* OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
|
||||
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
|
||||
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
|
||||
* EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
|
||||
* "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "linux/i2c-dev.h"
|
||||
|
||||
typedef union i2c_smbus_data_union
|
||||
{
|
||||
uint8_t byte; ///< data byte
|
||||
unsigned short word; ///< data short word
|
||||
uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
|
||||
///< block[0] is used for length and one more for PEC
|
||||
} i2c_smbus_data_t;
|
||||
|
||||
typedef struct i2c_smbus_ioctl_data_struct
|
||||
{
|
||||
uint8_t read_write; ///< operation direction
|
||||
uint8_t command; ///< ioctl command
|
||||
int size; ///< data size
|
||||
i2c_smbus_data_t *data; ///< data
|
||||
} i2c_smbus_ioctl_data_t;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Prototypes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern int i2c_smbus_access(int fd, uint8_t read_write, uint8_t command,
|
||||
int size, i2c_smbus_data_t *data);
|
||||
|
||||
extern int i2c_smbus_write_quick(int fd, uint8_t value);
|
||||
|
||||
extern int i2c_smbus_read_byte(int fd);
|
||||
|
||||
extern int i2c_smbus_write_byte(int fd, uint8_t value);
|
||||
|
||||
extern int i2c_smbus_read_byte_data(int fd, uint8_t command);
|
||||
|
||||
extern int i2c_smbus_write_byte_data(int fd, uint8_t command, uint8_t value);
|
||||
|
||||
extern int i2c_smbus_read_word_data(int fd, uint8_t command);
|
||||
|
||||
extern int i2c_smbus_write_word_data(int fd, uint8_t command, unsigned short value);
|
||||
|
||||
extern int i2c_smbus_process_call(int fd, uint8_t command, unsigned short value);
|
||||
|
||||
extern int i2c_smbus_read_block_data(int fd, uint8_t command, uint8_t *values);
|
||||
|
||||
extern int i2c_smbus_write_block_data(int fd, uint8_t command, uint8_t length,
|
||||
const uint8_t *values);
|
||||
extern int i2c_smbus_read_i2c_block_data(int fd, uint8_t command,
|
||||
uint8_t *values);
|
||||
|
||||
extern int i2c_smbus_write_i2c_block_data(int fd, uint8_t command, uint8_t length,
|
||||
const uint8_t *values);
|
||||
|
||||
extern int i2c_smbus_block_process_call(int fd, uint8_t command, uint8_t length,
|
||||
uint8_t *values);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,14 +1,17 @@
|
||||
include_directories(
|
||||
set (mraa_LIB_INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/api
|
||||
${PROJECT_SOURCE_DIR}/api/mraa
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS
|
||||
include_directories(
|
||||
${mraa_LIB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS_NOAUTO
|
||||
${PROJECT_SOURCE_DIR}/src/mraa.c
|
||||
${PROJECT_SOURCE_DIR}/src/gpio/gpio.c
|
||||
${PROJECT_SOURCE_DIR}/src/i2c/i2c.c
|
||||
${PROJECT_SOURCE_DIR}/src/i2c/smbus.c
|
||||
${PROJECT_SOURCE_DIR}/src/pwm/pwm.c
|
||||
${PROJECT_SOURCE_DIR}/src/spi/spi.c
|
||||
${PROJECT_SOURCE_DIR}/src/aio/aio.c
|
||||
@@ -16,6 +19,12 @@ set (mraa_LIB_SRCS
|
||||
${PROJECT_SOURCE_DIR}/src/intel_galileo_rev_d.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_galileo_rev_g.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_edison_fab_c.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_de3815.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_minnow_max.c
|
||||
)
|
||||
|
||||
set (mraa_LIB_SRCS
|
||||
${mraa_LIB_SRCS_NOAUTO}
|
||||
# autogenerated version file
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.c
|
||||
)
|
||||
|
@@ -47,8 +47,8 @@ aio_get_valid_fp(mraa_aio_context dev)
|
||||
|
||||
dev->adc_in_fp = open(file_path, O_RDONLY);
|
||||
if (dev->adc_in_fp == -1) {
|
||||
syslog(LOG_ERR, "Failed to open Analog input raw file %s for "
|
||||
"reading!", file_path);
|
||||
syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!",
|
||||
file_path);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -56,41 +56,44 @@ aio_get_valid_fp(mraa_aio_context dev)
|
||||
}
|
||||
|
||||
mraa_aio_context
|
||||
mraa_aio_init(unsigned int aio_channel)
|
||||
mraa_aio_init(unsigned int aio)
|
||||
{
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "aio: Platform not initialised");
|
||||
return NULL;
|
||||
}
|
||||
if (advance_func->aio_init_pre != NULL) {
|
||||
mraa_result_t pre_ret = (advance_func->aio_init_pre(aio_channel));
|
||||
mraa_result_t pre_ret = (advance_func->aio_init_pre(aio));
|
||||
if (pre_ret != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
if (aio > plat->aio_count) {
|
||||
syslog(LOG_ERR, "aio: requested channel out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int checked_pin = mraa_setup_aio(aio_channel);
|
||||
if (checked_pin < 0) {
|
||||
switch (checked_pin) {
|
||||
case MRAA_NO_SUCH_IO:
|
||||
syslog(LOG_ERR, "Invalid analog input channel %d specified",
|
||||
aio_channel);
|
||||
return NULL;
|
||||
case MRAA_IO_SETUP_FAILURE:
|
||||
syslog(LOG_ERR, "Failed to set-up analog input channel %d "
|
||||
"multiplexer", aio_channel);
|
||||
return NULL;
|
||||
case MRAA_PLATFORM_NO_INIT:
|
||||
syslog(LOG_ERR, "Platform not initialised");
|
||||
return NULL;
|
||||
default:
|
||||
return NULL;
|
||||
int pin = aio + plat->gpio_count;
|
||||
|
||||
if (plat->pins[pin].capabilites.aio != 1) {
|
||||
syslog(LOG_ERR, "aio: pin uncapable of aio");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plat->pins[pin].aio.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//Create ADC device connected to specified channel
|
||||
mraa_aio_context dev = malloc(sizeof(struct _aio));
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "Insufficient memory for specified Analog input channel "
|
||||
"%d\n", aio_channel);
|
||||
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
|
||||
"%d\n", aio);
|
||||
return NULL;
|
||||
}
|
||||
dev->channel = checked_pin;
|
||||
dev->channel = plat->pins[pin].aio.pinmap;
|
||||
dev->value_bit = DEFAULT_BITS;
|
||||
|
||||
//Open valid analog input file and get the pointer.
|
||||
@@ -114,27 +117,32 @@ 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) {
|
||||
aio_get_valid_fp(dev);
|
||||
if (aio_get_valid_fp(dev) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "aio: Failed to get to the device");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
||||
if (read(dev->adc_in_fp, buffer, sizeof(buffer)) < 1) {
|
||||
syslog(LOG_ERR, "Failed to read a sensible value");
|
||||
syslog(LOG_ERR, "aio: 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, "aio: Value is not a decimal number");
|
||||
}
|
||||
else if (errno != 0) {
|
||||
syslog(LOG_ERR, "errno was set");
|
||||
syslog(LOG_ERR, "aio: Errno was set");
|
||||
}
|
||||
|
||||
if (dev->value_bit != raw_bits) {
|
||||
@@ -163,14 +171,10 @@ mraa_aio_close(mraa_aio_context dev)
|
||||
mraa_result_t
|
||||
mraa_aio_set_bit(mraa_aio_context dev, int bits)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "AIO Device not valid");
|
||||
if (dev == NULL || bits < 1) {
|
||||
syslog(LOG_ERR, "aio: Device not valid");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
if (bits < 1) {
|
||||
syslog(LOG_ERR, "AIO Device not valid");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
dev->value_bit = bits;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -179,7 +183,7 @@ int
|
||||
mraa_aio_get_bit(mraa_aio_context dev)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "AIO Device not valid");
|
||||
syslog(LOG_ERR, "aio: Device not valid");
|
||||
return 0;
|
||||
}
|
||||
return dev->value_bit;
|
||||
|
@@ -385,7 +385,7 @@ class Doxy2SWIG:
|
||||
def write(self, fname):
|
||||
o = my_open_write(fname)
|
||||
if self.multi:
|
||||
o.write("".join(self.pieces))
|
||||
o.write("".join(x.encode('utf-8') for x in self.pieces))
|
||||
else:
|
||||
o.write("".join(self.clean_pieces(self.pieces)))
|
||||
o.close()
|
||||
|
155
src/gpio/gpio.c
155
src/gpio/gpio.c
@@ -55,11 +55,30 @@ mraa_gpio_get_valfp(mraa_gpio_context dev)
|
||||
mraa_gpio_context
|
||||
mraa_gpio_init(int pin)
|
||||
{
|
||||
int pinm = mraa_setup_gpio(pin);
|
||||
if (pinm < 0)
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "gpio: platform not initialised");
|
||||
return NULL;
|
||||
}
|
||||
if (pin < 0 || pin > plat->phy_pin_count) {
|
||||
syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (plat->pins[pin].capabilites.gpio != 1) {
|
||||
syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin);
|
||||
return NULL;
|
||||
}
|
||||
if (plat->pins[pin].gpio.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "gpio: unable to setup muxes");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mraa_gpio_context r = mraa_gpio_init_raw(pinm);
|
||||
mraa_gpio_context r = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
||||
if (r == NULL) {
|
||||
syslog(LOG_CRIT, "gpio: mraa_gpio_init_raw(%d) returned error", pin);
|
||||
return NULL;
|
||||
}
|
||||
r->phy_pin = pin;
|
||||
|
||||
if (advance_func->gpio_init_post != NULL) {
|
||||
@@ -87,6 +106,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, "gpio: Failed to allocate memory for context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(dev, 0, sizeof(struct _gpio));
|
||||
dev->value_fp = -1;
|
||||
dev->isr_value_fp = -1;
|
||||
@@ -101,13 +125,15 @@ mraa_gpio_init_raw(int pin)
|
||||
} else {
|
||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||
if (export == -1) {
|
||||
syslog(LOG_ERR, "Failed to open export for writing");
|
||||
syslog(LOG_ERR, "gpio: Failed to open export for writing");
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
if (write(export, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to export");
|
||||
syslog(LOG_ERR, "gpio: Failed to write to export");
|
||||
close(export);
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
dev->owner = 1;
|
||||
@@ -117,26 +143,6 @@ mraa_gpio_init_raw(int pin)
|
||||
return dev;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_gpio_write_register(mraa_gpio_context dev,int value)
|
||||
{
|
||||
if (advance_func->gpio_mmaped_write_replace != NULL)
|
||||
return advance_func->gpio_mmaped_write_replace(dev,value);
|
||||
if (advance_func->gpio_mmaped_write_pre != NULL) {
|
||||
mraa_result_t pre_ret = (advance_func->gpio_mmaped_write_pre(dev,value));
|
||||
if(pre_ret != MRAA_SUCCESS)
|
||||
return pre_ret;
|
||||
}
|
||||
if (value == 1) {
|
||||
*((unsigned *)dev->reg) |= (1<<dev->reg_bit_pos);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
*((unsigned *)dev->reg) &= ~(1<<dev->reg_bit_pos);
|
||||
|
||||
if (advance_func->gpio_mmaped_write_post != NULL)
|
||||
return advance_func->gpio_mmaped_write_post(dev,value);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_gpio_wait_interrupt(int fd)
|
||||
@@ -174,7 +180,12 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
// open gpio value with open(3)
|
||||
char bu[MAX_SIZE];
|
||||
sprintf(bu, SYSFS_CLASS_GPIO "/gpio%d/value", dev->pin);
|
||||
dev->isr_value_fp = open(bu, O_RDONLY);
|
||||
int fp = open(bu, O_RDONLY);
|
||||
if (fp < 0) {
|
||||
syslog(LOG_ERR, "gpio: failed to open gpio%d/value", dev->pin);
|
||||
return NULL;
|
||||
}
|
||||
dev->isr_value_fp = fp;
|
||||
|
||||
for (;;) {
|
||||
ret = mraa_gpio_wait_interrupt(dev->isr_value_fp);
|
||||
@@ -190,11 +201,11 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
PyObject *ret;
|
||||
arglist = Py_BuildValue("(i)", dev->isr_args);
|
||||
if (arglist == NULL) {
|
||||
syslog(LOG_ERR, "Py_BuildValue NULL");
|
||||
syslog(LOG_ERR, "gpio: Py_BuildValue NULL");
|
||||
} else {
|
||||
ret = PyEval_CallObject((PyObject*)dev->isr, arglist);
|
||||
if (ret == NULL) {
|
||||
syslog(LOG_ERR, "PyEval_CallObject failed");
|
||||
syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
|
||||
} else {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
@@ -229,7 +240,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
|
||||
|
||||
int edge = open(filepath, O_RDWR);
|
||||
if (edge == -1) {
|
||||
syslog(LOG_ERR, "Failed to open edge for writing");
|
||||
syslog(LOG_ERR, "gpio: Failed to open edge for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -253,7 +264,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(edge, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to edge");
|
||||
syslog(LOG_ERR, "gpio: Failed to write to edge");
|
||||
close(edge);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -294,9 +305,10 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
// stop isr being useful
|
||||
ret = mraa_gpio_edge_mode(dev, MRAA_GPIO_EDGE_NONE);
|
||||
|
||||
if ((dev->thread_id != 0) &&
|
||||
(pthread_cancel(dev->thread_id) != 0)) {
|
||||
ret = MRAA_ERROR_INVALID_HANDLE;
|
||||
if ((dev->thread_id != 0)) {
|
||||
if ((pthread_cancel(dev->thread_id) != 0) || (pthread_join(dev->thread_id, NULL) != 0)) {
|
||||
ret = MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
// close the filehandle in case it's still open
|
||||
@@ -339,7 +351,7 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
|
||||
int drive = open(filepath, O_WRONLY);
|
||||
if (drive == -1) {
|
||||
syslog(LOG_ERR, "Failed to open drive for writing");
|
||||
syslog(LOG_ERR, "gpio: Failed to open drive for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -363,7 +375,7 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(drive, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to drive mode");
|
||||
syslog(LOG_ERR, "gpio: Failed to write to drive mode");
|
||||
close(drive);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
@@ -430,9 +442,16 @@ 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->mmap_read != NULL)
|
||||
return dev->mmap_read(dev);
|
||||
|
||||
if (dev->value_fp == -1) {
|
||||
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Failed to get value file pointer");
|
||||
syslog(LOG_ERR, "gpio: Failed to get value file pointer");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -441,20 +460,22 @@ 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");
|
||||
syslog(LOG_ERR, "gpio: 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 (int) strtol(bu, NULL, 10);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_gpio_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
if (dev->mmap == 1)
|
||||
return mraa_gpio_write_register(dev,value);
|
||||
if (dev == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
|
||||
if (dev->mmap_write != NULL)
|
||||
return dev->mmap_write(dev,value);
|
||||
|
||||
if (advance_func->gpio_write_pre != NULL) {
|
||||
mraa_result_t pre_ret = (advance_func->gpio_write_pre(dev,value));
|
||||
@@ -463,8 +484,11 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
|
||||
}
|
||||
|
||||
if (dev->value_fp == -1) {
|
||||
mraa_gpio_get_valfp(dev);
|
||||
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
if (lseek(dev->value_fp, 0, SEEK_SET) == -1) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -485,14 +509,14 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
|
||||
{
|
||||
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
|
||||
if (unexport == -1) {
|
||||
syslog(LOG_ERR, "Failed to open unexport for writing");
|
||||
syslog(LOG_ERR, "gpio: Failed to open unexport for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
char bu[MAX_SIZE];
|
||||
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
if (write(unexport, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to unexport");
|
||||
syslog(LOG_ERR, "gpio: Failed to write to unexport");
|
||||
close(unexport);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -533,43 +557,10 @@ mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t own)
|
||||
mraa_result_t
|
||||
mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
if (advance_func->gpio_mmap_setup != NULL) {
|
||||
return advance_func->gpio_mmap_setup(dev,mmap_en);
|
||||
}
|
||||
|
||||
if (mraa_pin_mode_test(dev->phy_pin, MRAA_PIN_FAST_GPIO) == 0)
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
|
||||
mraa_mmap_pin_t *mmp = mraa_setup_mmap_gpio(dev->phy_pin);
|
||||
if (mmp == NULL)
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
if (mmap_en == 1) {
|
||||
if (dev->mmap == 0) {
|
||||
close(dev->value_fp);
|
||||
int fd;
|
||||
fd = open(mmp->mem_dev, O_RDWR);
|
||||
if (fd < 1) {
|
||||
syslog(LOG_ERR, "Unable to open memory device");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->reg_sz = mmp->mem_sz;
|
||||
dev->reg = mmap(NULL, dev->reg_sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
dev->reg_bit_pos = mmp->bit_pos;
|
||||
dev->mmap = 1;
|
||||
close(fd);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (mmap_en == 0) {
|
||||
if (dev ->mmap == 1) {
|
||||
munmap(dev->reg, dev->reg_sz);
|
||||
dev->mmap = 0;
|
||||
}
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
syslog(LOG_ERR, "gpio: mmap not implemented on this platform");
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
22
src/i2c/LICENSE
Normal file
22
src/i2c/LICENSE
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2005-2014 RoadNarrows LLC.
|
||||
htpt://roadnarrows.com
|
||||
All Rights Reserved
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
200
src/i2c/i2c.c
200
src/i2c/i2c.c
@@ -2,6 +2,9 @@
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Code is modified from the RoadNarrows-robotics i2c library (distributed under
|
||||
* the MIT license, license is included verbatim under src/i2c/LICENSE)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@@ -23,28 +26,83 @@
|
||||
*/
|
||||
|
||||
#include "i2c.h"
|
||||
#include "smbus.h"
|
||||
#include "mraa_internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "linux/i2c-dev.h"
|
||||
|
||||
typedef union i2c_smbus_data_union
|
||||
{
|
||||
uint8_t byte; ///< data byte
|
||||
unsigned short word; ///< data short word
|
||||
uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
|
||||
///< block[0] is used for length and one more for PEC
|
||||
} i2c_smbus_data_t;
|
||||
|
||||
typedef struct i2c_smbus_ioctl_data_struct
|
||||
{
|
||||
uint8_t read_write; ///< operation direction
|
||||
uint8_t command; ///< ioctl command
|
||||
int size; ///< data size
|
||||
i2c_smbus_data_t *data; ///< data
|
||||
} i2c_smbus_ioctl_data_t;
|
||||
|
||||
int
|
||||
mraa_i2c_smbus_access(int fh, uint8_t read_write, uint8_t command, int size,
|
||||
i2c_smbus_data_t *data)
|
||||
{
|
||||
i2c_smbus_ioctl_data_t args;
|
||||
|
||||
args.read_write = read_write;
|
||||
args.command = command;
|
||||
args.size = size;
|
||||
args.data = data;
|
||||
|
||||
return ioctl(fh, I2C_SMBUS, &args);
|
||||
}
|
||||
|
||||
mraa_i2c_context
|
||||
mraa_i2c_init(int bus)
|
||||
{
|
||||
int checked_pin = mraa_setup_i2c(bus);
|
||||
if (checked_pin < 0) {
|
||||
switch(checked_pin) {
|
||||
case MRAA_NO_SUCH_IO:
|
||||
syslog(LOG_ERR, "No i2c on board");
|
||||
return NULL;
|
||||
case MRAA_IO_SETUP_FAILURE:
|
||||
syslog(LOG_ERR, "Failed to set-up i2c multiplexer");
|
||||
return NULL;
|
||||
case MRAA_PLATFORM_NO_INIT:
|
||||
syslog(LOG_ERR, "Platform Not Initialised");
|
||||
return NULL;
|
||||
default: return NULL;
|
||||
}
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "i2c: Platform Not Initialised");
|
||||
return NULL;
|
||||
}
|
||||
return mraa_i2c_init_raw((unsigned int) checked_pin);
|
||||
if (plat->i2c_bus_count == 0) {
|
||||
syslog(LOG_ERR, "No i2c buses defined in platform");
|
||||
return NULL;
|
||||
}
|
||||
if (bus >= plat->i2c_bus_count) {
|
||||
syslog(LOG_ERR, "Above i2c bus count");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plat->i2c_bus[bus].bus_id == -1) {
|
||||
syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
|
||||
bus = plat->def_i2c_bus;
|
||||
}
|
||||
|
||||
int pos = plat->i2c_bus[bus].sda;
|
||||
if (plat->pins[pos].i2c.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "i2c: Failed to set-up i2c sda multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pos = plat->i2c_bus[bus].scl;
|
||||
if (plat->pins[pos].i2c.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "i2c: Failed to set-up i2c scl multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mraa_i2c_init_raw((unsigned int) plat->i2c_bus[bus].bus_id);
|
||||
}
|
||||
|
||||
mraa_i2c_context
|
||||
@@ -55,13 +113,15 @@ 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, "i2c: Failed to allocate memory for context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char filepath[32];
|
||||
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
||||
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
|
||||
syslog(LOG_ERR, "Failed to open requested i2c port %s", filepath);
|
||||
syslog(LOG_ERR, "i2c: Failed to open requested i2c port %s", filepath);
|
||||
}
|
||||
|
||||
if (advance_func->i2c_init_post != NULL) {
|
||||
@@ -79,7 +139,7 @@ mraa_i2c_frequency(mraa_i2c_context dev, int hz)
|
||||
{
|
||||
dev->hz = hz;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -95,40 +155,112 @@ mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
uint8_t
|
||||
mraa_i2c_read_byte(mraa_i2c_context dev)
|
||||
{
|
||||
uint8_t byte = i2c_smbus_read_byte(dev->fh);
|
||||
if (byte < 0) {
|
||||
return -1;
|
||||
i2c_smbus_data_t d;
|
||||
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD,
|
||||
I2C_SMBUS_BYTE, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
}
|
||||
return byte;
|
||||
return 0x0FF & d.byte;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
i2c_smbus_data_t d;
|
||||
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command,
|
||||
I2C_SMBUS_BYTE_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
}
|
||||
return 0x0FF & d.byte;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
||||
{
|
||||
i2c_smbus_data_t d;
|
||||
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command,
|
||||
I2C_SMBUS_WORD_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return 0;
|
||||
}
|
||||
return 0xFFFF & d.word;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||
{
|
||||
if (i2c_smbus_write_i2c_block_data(dev->fh, data[0], length-1, (uint8_t*) data+1) < 0) {
|
||||
syslog(LOG_ERR, "Failed to write to i2c");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
i2c_smbus_data_t d;
|
||||
int i;
|
||||
uint8_t command = data[0];
|
||||
|
||||
data = &data[1];
|
||||
length = length-1;
|
||||
if (length > I2C_SMBUS_I2C_BLOCK_MAX) {
|
||||
length = I2C_SMBUS_I2C_BLOCK_MAX;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
|
||||
for (i=1; i<=length; i++) {
|
||||
d.block[i] = data[i-1];
|
||||
}
|
||||
d.block[0] = length;
|
||||
|
||||
return mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_I2C_BLOCK_DATA, &d);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
|
||||
{
|
||||
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
||||
syslog(LOG_ERR, "Failed to write to i2c");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data,
|
||||
I2C_SMBUS_BYTE, NULL) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_address(mraa_i2c_context dev, int addr)
|
||||
mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data,
|
||||
const uint8_t command)
|
||||
{
|
||||
dev->addr = addr;
|
||||
i2c_smbus_data_t d;
|
||||
|
||||
d.byte = data;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_BYTE_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data,
|
||||
const uint8_t command)
|
||||
{
|
||||
i2c_smbus_data_t d;
|
||||
|
||||
d.word = data;
|
||||
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_WORD_DATA, &d) < 0) {
|
||||
syslog(LOG_ERR, "i2c: Failed to write");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
|
||||
{
|
||||
dev->addr = (int) addr;
|
||||
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
|
||||
syslog(LOG_ERR, "Failed to set slave address %d", addr);
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr);
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
420
src/i2c/smbus.c
420
src/i2c/smbus.c
@@ -1,420 +0,0 @@
|
||||
// Library: libi2c API
|
||||
// File: smbus.c
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* $LastChangedDate: 2009-09-09 09:44:12 -0600 (Wed, 09 Sep 2009) $
|
||||
* $Rev: 130 $
|
||||
*
|
||||
* \brief System Management Bus (SMBus) over I<sup>2</sup>C communication
|
||||
* interface.
|
||||
*
|
||||
* \author Robin Knight (robin.knight@roadnarrows.com)
|
||||
*
|
||||
* \par Copyright:
|
||||
* (C) 2009. RoadNarrows LLC.
|
||||
* (http://www.roadnarrows.com) \n
|
||||
* All Rights Reserved
|
||||
*
|
||||
* <hr>
|
||||
* \par Original Source and Copyright:
|
||||
* See i2c-dev.h.
|
||||
*
|
||||
* <hr>
|
||||
*/
|
||||
// Permission is hereby granted, without written agreement and without
|
||||
// license or royalty fees, to use, copy, modify, and distribute this
|
||||
// software and its documentation for any purpose, provided that
|
||||
// (1) The above copyright notice and the following two paragraphs
|
||||
// appear in all copies of the source code and (2) redistributions
|
||||
// including binaries reproduces these notices in the supporting
|
||||
// documentation. Substantial modifications to this software may be
|
||||
// copyrighted by their authors and need not follow the licensing terms
|
||||
// described here, provided that the new terms are clearly indicated in
|
||||
// all files where they apply.
|
||||
//
|
||||
// IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
|
||||
// OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
|
||||
// PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
|
||||
// DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
|
||||
// EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
|
||||
// THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
|
||||
// "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
|
||||
// PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "smbus.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Execute an SMBus IOCTL.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param read_write Operation access type.
|
||||
* \param command Operation command or immediate data.
|
||||
* \param size Data size.
|
||||
* \param [in,out] data Read/write/control data
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_access(int fd, uint8_t read_write, uint8_t command,
|
||||
int size, i2c_smbus_data_t *data)
|
||||
{
|
||||
i2c_smbus_ioctl_data_t args;
|
||||
|
||||
args.read_write = read_write;
|
||||
args.command = command;
|
||||
args.size = size;
|
||||
args.data = data;
|
||||
|
||||
return ioctl(fd, I2C_SMBUS, &args);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write a quick value to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param value Value to write
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_quick(int fd, uint8_t value)
|
||||
{
|
||||
return i2c_smbus_access(fd, value, I2C_NOCMD, I2C_SMBUS_QUICK, NULL);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Read an immediate byte from the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
*
|
||||
* \return
|
||||
* Returns read byte on on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_read_byte(int fd)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int rc;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_READ, I2C_NOCMD, I2C_SMBUS_BYTE, &data);
|
||||
|
||||
return rc>=0? 0x0FF & data.byte: -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write an immediate byte to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param value Byte value to write.
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_byte(int fd, uint8_t value)
|
||||
{
|
||||
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Read a data byte from the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
*
|
||||
* \return
|
||||
* Returns read byte on on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_read_byte_data(int fd, uint8_t command)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int rc;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA,
|
||||
&data);
|
||||
|
||||
return rc>=0? 0x0FF & data.byte: -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write a data byte to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param value Byte value to write.
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_byte_data(int fd, uint8_t command, uint8_t value)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
|
||||
data.byte = value;
|
||||
|
||||
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_BYTE_DATA, &data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Read a data 2-byte word from the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
*
|
||||
* \return
|
||||
* Returns read 2-byte word on on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_read_word_data(int fd, uint8_t command)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int rc;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA,
|
||||
&data);
|
||||
|
||||
return rc>=0? 0x0FFFF & data.word: -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write a data 2-byte word to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param value Word value to write.
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_word_data(int fd, uint8_t command, unsigned short value)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
|
||||
data.word = value;
|
||||
|
||||
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_WORD_DATA, &data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Issue a 2-byte word process call (write/read) to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param value Word value to write.
|
||||
*
|
||||
* \return
|
||||
* Returns read 2-byte word on on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_process_call(int fd, uint8_t command, unsigned short value)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int rc;
|
||||
|
||||
data.word = value;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_WRITE, command, I2C_SMBUS_PROC_CALL,
|
||||
&data);
|
||||
|
||||
return rc>=0? 0x0FFFF & data.word: -1;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Read a block of data from the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param [out] values Buffer to hold the block of read byte values.\n
|
||||
* Must be large enough to receive the data.
|
||||
*
|
||||
* \return
|
||||
* On success, returns \h_ge 0 the number of bytes read, excluding any header
|
||||
* fields. Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_read_block_data(int fd, uint8_t command, uint8_t *values)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_READ, command, I2C_SMBUS_BLOCK_DATA,
|
||||
&data);
|
||||
|
||||
if( rc >= 0 )
|
||||
{
|
||||
for(i=1; i<=data.block[0]; ++i)
|
||||
{
|
||||
values[i-1] = data.block[i];
|
||||
}
|
||||
rc = data.block[0];
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write a data block to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param length Length of buffer (bytes) to write.
|
||||
* \param [in] values Buffer of data to write.
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_block_data(int fd, uint8_t command, uint8_t length,
|
||||
const uint8_t *values)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int i;
|
||||
|
||||
if( length > I2C_SMBUS_BLOCK_MAX )
|
||||
{
|
||||
length = I2C_SMBUS_BLOCK_MAX;
|
||||
}
|
||||
|
||||
for(i=1; i<=length; i++)
|
||||
{
|
||||
data.block[i] = values[i-1];
|
||||
}
|
||||
data.block[0] = length;
|
||||
|
||||
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_BLOCK_DATA, &data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Read a block of data from the SMBus via low-level I<sup>2</sup>C.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param [out] values Buffer to hold the block of read byte values.\n
|
||||
* Must be large enough to receive the data.
|
||||
*
|
||||
* \return
|
||||
* On success, returns \h_ge 0 the number of bytes read, excluding any header
|
||||
* fields. Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_read_i2c_block_data(int fd, uint8_t command, uint8_t *values)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA,
|
||||
&data);
|
||||
if( rc >= 0 )
|
||||
{
|
||||
for(i=1; i<=data.block[0]; i++)
|
||||
{
|
||||
values[i-1] = data.block[i];
|
||||
}
|
||||
rc = data.block[0];
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write a block of data to the SMBus via low-level I<sup>2</sup>C.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param length Length of buffer (bytes) to write.
|
||||
* \param [in] values Buffer of data to write.
|
||||
*
|
||||
* \return
|
||||
* Returns \h_ge 0 on success.
|
||||
* Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_write_i2c_block_data(int fd, uint8_t command, uint8_t length,
|
||||
const uint8_t *values)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int i;
|
||||
|
||||
if( length > I2C_SMBUS_I2C_BLOCK_MAX )
|
||||
{
|
||||
length = I2C_SMBUS_I2C_BLOCK_MAX;
|
||||
}
|
||||
|
||||
for(i=1; i<=length; i++)
|
||||
{
|
||||
data.block[i] = values[i-1];
|
||||
}
|
||||
data.block[0] = length;
|
||||
|
||||
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, command,
|
||||
I2C_SMBUS_I2C_BLOCK_DATA, &data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Issue a block process call (write/read) to the SMBus.
|
||||
*
|
||||
* \param fd File descriptor to opened SMBus device.
|
||||
* \param command Command to SMBus device.
|
||||
* \param length Length of buffer (bytes) to write.
|
||||
* \param [in,out] values Buffer of data to write and to hold the block of
|
||||
* read byte values.\n
|
||||
* Must be large enough to receive the data.
|
||||
*
|
||||
* \return
|
||||
* On success, returns \h_ge 0 the number of bytes read, excluding any header
|
||||
* fields. Else errno is set appropriately and -1 is returned.
|
||||
*/
|
||||
int i2c_smbus_block_process_call(int fd, uint8_t command, uint8_t length,
|
||||
uint8_t *values)
|
||||
{
|
||||
i2c_smbus_data_t data;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if( length > I2C_SMBUS_BLOCK_MAX )
|
||||
{
|
||||
length = I2C_SMBUS_BLOCK_MAX;
|
||||
}
|
||||
|
||||
for(i=1; i<=length; i++)
|
||||
{
|
||||
data.block[i] = values[i-1];
|
||||
}
|
||||
data.block[0] = length;
|
||||
|
||||
rc = i2c_smbus_access(fd, I2C_SMBUS_WRITE, command, I2C_SMBUS_BLOCK_PROC_CALL,
|
||||
&data);
|
||||
|
||||
if( rc >= 0 )
|
||||
{
|
||||
for(i=1; i<=data.block[0]; i++)
|
||||
{
|
||||
values[i-1] = data.block[i];
|
||||
}
|
||||
rc = data.block[0];
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
137
src/intel_de3815.c
Normal file
137
src/intel_de3815.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "intel_de3815.h"
|
||||
|
||||
#define PLATFORM_NAME "Intel DE3815"
|
||||
#define MAX_SIZE 64
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_de3815()
|
||||
{
|
||||
mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->platform_name_length = strlen(PLATFORM_NAME) + 1;
|
||||
b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
|
||||
strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
|
||||
|
||||
b->phy_pin_count = 18;
|
||||
//b->gpio_count = 14;
|
||||
b->aio_count = 0;
|
||||
b->adc_raw = 0;
|
||||
b->adc_supported = 0;
|
||||
b->pwm_default_period = 500;
|
||||
b->pwm_max_period = 2147483;
|
||||
b->pwm_min_period = 1;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_DE3815_PINCOUNT);
|
||||
|
||||
strncpy(b->pins[0].name, "1.8v", 8);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
|
||||
strncpy(b->pins[1].name, "GND", 8);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[2].name, "HDMIcec", 8);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[3].name, "DMICclk", 8);
|
||||
b->pins[3].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[4].name, "3.3v", 8);
|
||||
b->pins[4].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[5].name, "DMICda", 8);
|
||||
b->pins[5].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[6].name, "Key", 8);
|
||||
b->pins[6].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[7].name, "SMB-A", 8);
|
||||
b->pins[7].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[8].name, "5v", 8);
|
||||
b->pins[8].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[9].name, "SCI", 8);
|
||||
b->pins[9].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
|
||||
strncpy(b->pins[10].name, "PWM0", 8);
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,0,1,0,0,0,0,0};
|
||||
b->pins[10].pwm.pinmap = 0;
|
||||
b->pins[10].pwm.parent_id = 0;
|
||||
b->pins[10].pwm.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[11].name, "PWM1", 8);
|
||||
b->pins[11].capabilites = (mraa_pincapabilities_t) {1,0,1,0,0,0,0,0};
|
||||
b->pins[11].pwm.pinmap = 0;
|
||||
b->pins[11].pwm.parent_id = 1;
|
||||
b->pins[11].pwm.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[12].name, "I2C0SCL", 8);
|
||||
b->pins[12].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
|
||||
b->pins[12].i2c.pinmap = 1;
|
||||
b->pins[12].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[13].name, "I2C0SDA", 8);
|
||||
b->pins[13].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
|
||||
b->pins[13].i2c.pinmap = 1;
|
||||
b->pins[13].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[14].name, "I2C1SCL", 8);
|
||||
b->pins[14].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
|
||||
b->pins[14].i2c.pinmap = 1;
|
||||
b->pins[14].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[15].name, "I2C1SDA", 8);
|
||||
b->pins[15].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
|
||||
b->pins[15].i2c.pinmap = 1;
|
||||
b->pins[15].i2c.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[16].name, "SMB_CLK", 8);
|
||||
b->pins[16].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
strncpy(b->pins[17].name, "SMB_SDA", 8);
|
||||
b->pins[17].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
|
||||
|
||||
//BUS DEFINITIONS
|
||||
b->i2c_bus_count = 2;
|
||||
b->def_i2c_bus = 0;
|
||||
b->i2c_bus[0].bus_id = 0;
|
||||
b->i2c_bus[0].sda = 12;
|
||||
b->i2c_bus[0].scl = 13;
|
||||
|
||||
b->i2c_bus[1].bus_id = 1;
|
||||
b->i2c_bus[1].sda = 14;
|
||||
b->i2c_bus[1].scl = 15;
|
||||
|
||||
b->spi_bus_count = 1;
|
||||
b->def_spi_bus = 0;
|
||||
b->spi_bus[0].bus_id = 1;
|
||||
b->spi_bus[0].slave_s = 0;
|
||||
b->spi_bus[0].cs = 10;
|
||||
b->spi_bus[0].mosi = 11;
|
||||
b->spi_bus[0].miso = 12;
|
||||
b->spi_bus[0].sclk = 13;
|
||||
|
||||
return b;
|
||||
}
|
@@ -24,15 +24,23 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "intel_edison_fab_c.h"
|
||||
|
||||
#define PLATFORM_NAME "Intel Edison"
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
#define SYSFS_PINMODE_PATH "/sys/kernel/debug/gpio_debug/gpio"
|
||||
#define MAX_SIZE 64
|
||||
#define MAX_MODE_SIZE 8
|
||||
|
||||
// This is an absolute path to a resource file found within sysfs.
|
||||
// Might not always be correct. First thing to check if mmap stops
|
||||
// working. Check the device for 0x1199 and Intel Vendor (0x8086)
|
||||
#define MMAP_PATH "/sys/devices/pci0000:00/0000:00:0c.0/resource0"
|
||||
|
||||
typedef struct {
|
||||
int sysfs;
|
||||
int mode;
|
||||
@@ -51,6 +59,13 @@ 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;
|
||||
|
||||
//MMAP
|
||||
static uint8_t *mmap_reg = NULL;
|
||||
static int mmap_fd = 0;
|
||||
static int mmap_size;
|
||||
static unsigned int mmap_count = 0;
|
||||
|
||||
static mraa_result_t
|
||||
mraa_intel_edison_pinmode_change(int sysfs, int mode)
|
||||
@@ -62,13 +77,14 @@ mraa_intel_edison_pinmode_change(int sysfs, int mode)
|
||||
snprintf(buffer, MAX_SIZE, SYSFS_PINMODE_PATH "%i/current_pinmux",sysfs);
|
||||
int modef = open(buffer, O_WRONLY);
|
||||
if (modef == -1) {
|
||||
syslog(LOG_ERR, "Failed to open SoC pinmode for opening");
|
||||
syslog(LOG_ERR, "edison: Failed to open SoC pinmode for opening");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
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 +125,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 +141,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, switching to bus 6");
|
||||
bus = 6;
|
||||
}
|
||||
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, switching to bus 6");
|
||||
bus = 6;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -205,7 +239,7 @@ mraa_intel_edison_aio_get_fp(mraa_aio_context dev)
|
||||
|
||||
dev->adc_in_fp = open(file_path, O_RDONLY);
|
||||
if (dev->adc_in_fp == -1) {
|
||||
syslog(LOG_ERR, "Failed to open Analog input raw file %s for "
|
||||
syslog(LOG_ERR, "edison: Failed to open Analog input raw file %s for "
|
||||
"reading!", file_path);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -217,7 +251,7 @@ mraa_result_t
|
||||
mraa_intel_edison_aio_init_pre(unsigned int aio)
|
||||
{
|
||||
if (aio > plat->aio_count) {
|
||||
syslog(LOG_ERR, "Invalid analog input channel");
|
||||
syslog(LOG_ERR, "edison: Invalid analog input channel");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -249,6 +283,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 +320,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);
|
||||
@@ -341,7 +385,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
||||
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
||||
if(sta != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Edison: Failed to set gpio mode-pullup");
|
||||
syslog(LOG_ERR, "edison: Failed to set gpio mode-pullup");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -365,7 +409,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
|
||||
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
||||
sta = mraa_gpio_write(pullup_e, value);
|
||||
if (sta != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Edison: Error Setting pullup");
|
||||
syslog(LOG_ERR, "edison: Error setting pullup");
|
||||
return sta;
|
||||
}
|
||||
}
|
||||
@@ -373,6 +417,554 @@ 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, "edison: Failed to write to drive mode");
|
||||
close(drive);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
}
|
||||
|
||||
close(drive);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edison_uart_init_pre(int index)
|
||||
{
|
||||
if (miniboard == 0) {
|
||||
mraa_gpio_write(tristate, 0);
|
||||
mraa_gpio_context io0_output = mraa_gpio_init_raw(248);
|
||||
mraa_gpio_context io0_pullup = mraa_gpio_init_raw(216);
|
||||
mraa_gpio_context io1_output = mraa_gpio_init_raw(249);
|
||||
mraa_gpio_context io1_pullup = mraa_gpio_init_raw(217);
|
||||
mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io0_pullup, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io1_pullup, MRAA_GPIO_IN);
|
||||
|
||||
mraa_gpio_write(io0_output, 0);
|
||||
mraa_gpio_write(io0_pullup, 0);
|
||||
mraa_gpio_write(io1_output, 1);
|
||||
|
||||
mraa_gpio_close(io0_output);
|
||||
mraa_gpio_close(io0_pullup);
|
||||
mraa_gpio_close(io1_output);
|
||||
mraa_gpio_close(io1_pullup);
|
||||
}
|
||||
mraa_result_t ret;
|
||||
ret = mraa_intel_edison_pinmode_change(130,1); //IO0 RX
|
||||
ret = mraa_intel_edison_pinmode_change(131,1); //IO1 TX
|
||||
return ret;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edison_uart_init_post(mraa_uart_context uart)
|
||||
{
|
||||
return mraa_gpio_write(tristate, 1);
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_intel_edsion_mmap_unsetup()
|
||||
{
|
||||
if (mmap_reg == NULL) {
|
||||
syslog(LOG_ERR, "edison mmap: null register cant unsetup");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
munmap(mmap_reg, mmap_size);
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edison_mmap_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
uint8_t offset = ((dev->pin / 32) * sizeof(uint32_t));
|
||||
uint8_t valoff;
|
||||
|
||||
if (value) {
|
||||
valoff = 0x34;
|
||||
} else {
|
||||
valoff = 0x4c;
|
||||
}
|
||||
|
||||
*(volatile uint32_t*) (mmap_reg + offset + valoff) =
|
||||
(uint32_t)(1 << (dev->pin % 32));
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
mraa_intel_edison_mmap_read(mraa_gpio_context dev)
|
||||
{
|
||||
uint8_t offset = ((dev->pin / 32) * sizeof(uint32_t));
|
||||
uint32_t value;
|
||||
|
||||
value = *(volatile uint32_t*) (mmap_reg +0x04+ offset);
|
||||
if (value&(uint32_t)(1 << (dev->pin % 32)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_edison_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "edison mmap: context not valid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (en == 0) {
|
||||
if (dev->mmap_write == NULL && dev->mmap_read == NULL) {
|
||||
syslog(LOG_ERR, "edison mmap: can't disable disabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
dev->mmap_write = NULL;
|
||||
dev->mmap_read = NULL;
|
||||
mmap_count--;
|
||||
if (mmap_count == 0) {
|
||||
return mraa_intel_edsion_mmap_unsetup();
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
if (dev->mmap_write != NULL && dev->mmap_read != NULL) {
|
||||
syslog(LOG_ERR, "edison mmap: can't enable enabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//Might need to make some elements of this thread safe.
|
||||
//For example only allow one thread to enter the following block
|
||||
//to prevent mmap'ing twice.
|
||||
if (mmap_reg == NULL) {
|
||||
if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
|
||||
syslog(LOG_ERR, "edison map: unable to open resource0 file");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
struct stat fd_stat;
|
||||
fstat(mmap_fd, &fd_stat);
|
||||
mmap_size = fd_stat.st_size;
|
||||
|
||||
mmap_reg = (uint8_t*) mmap(NULL, fd_stat.st_size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_FILE | MAP_SHARED,
|
||||
mmap_fd, 0);
|
||||
if (mmap_reg == MAP_FAILED) {
|
||||
syslog(LOG_ERR, "edison mmap: failed to mmap");
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
}
|
||||
dev->mmap_write = &mraa_intel_edison_mmap_write;
|
||||
dev->mmap_read = &mraa_intel_edison_mmap_read;
|
||||
mmap_count++;
|
||||
|
||||
|
||||
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->pwm_default_period = 5000;
|
||||
b->pwm_max_period = 218453;
|
||||
b->pwm_min_period = 1;
|
||||
|
||||
|
||||
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;
|
||||
advance_func->uart_init_pre = &mraa_intel_edison_uart_init_pre;
|
||||
advance_func->gpio_mmap_setup = &mraa_intel_edison_mmap_setup;
|
||||
|
||||
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 = 183;
|
||||
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,1};
|
||||
b->pins[pos].gpio.pinmap = 130;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].uart.pinmap = 0;
|
||||
b->pins[pos].uart.parent_id = 0;
|
||||
b->pins[pos].uart.mux_total = 0;
|
||||
|
||||
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,1};
|
||||
b->pins[pos].gpio.pinmap = 131;
|
||||
b->pins[pos].gpio.mux_total = 0;
|
||||
b->pins[pos].uart.pinmap = 0;
|
||||
b->pins[pos].uart.parent_id = 0;
|
||||
b->pins[pos].uart.mux_total = 0;
|
||||
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;
|
||||
|
||||
b->uart_dev_count = 1;
|
||||
b->def_uart_dev = 0;
|
||||
b->uart_dev[0].rx = 26;
|
||||
b->uart_dev[0].tx = 35;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_edison_fab_c()
|
||||
@@ -381,6 +973,22 @@ mraa_intel_edison_fab_c()
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->platform_name_length = strlen(PLATFORM_NAME) + 1;
|
||||
b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
|
||||
strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
|
||||
|
||||
// This seciton will also check if the arduino board is there
|
||||
tristate = mraa_gpio_init_raw(214);
|
||||
if (tristate == NULL) {
|
||||
syslog(LOG_INFO, "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;
|
||||
@@ -397,32 +1005,38 @@ mraa_intel_edison_fab_c()
|
||||
advance_func->spi_init_pre = &mraa_intel_edison_spi_init_pre;
|
||||
advance_func->spi_init_post = &mraa_intel_edison_spi_init_post;
|
||||
advance_func->gpio_mode_replace = &mraa_intel_edison_gpio_mode_replace;
|
||||
advance_func->uart_init_pre = &mraa_intel_edison_uart_init_pre;
|
||||
advance_func->uart_init_post = &mraa_intel_edison_uart_init_post;
|
||||
advance_func->gpio_mmap_setup = &mraa_intel_edison_mmap_setup;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_EDISON_PINCOUNT);
|
||||
|
||||
tristate = mraa_gpio_init_raw(214);
|
||||
if (tristate == NULL) {
|
||||
syslog(LOG_CRIT, "Intel Edison Failed to initialise Arduino board TriState,\
|
||||
check i2c devices! FATAL\n");
|
||||
return NULL;
|
||||
}
|
||||
mraa_gpio_dir(tristate, MRAA_GPIO_OUT);
|
||||
mraa_intel_edison_misc_spi();
|
||||
|
||||
b->adc_raw = 12;
|
||||
b->adc_supported = 10;
|
||||
b->pwm_default_period = 5000;
|
||||
b->pwm_max_period = 218453;
|
||||
b->pwm_min_period = 1;
|
||||
|
||||
strncpy(b->pins[0].name, "IO0", 8);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1};
|
||||
b->pins[0].gpio.pinmap = 130;
|
||||
b->pins[0].gpio.parent_id = 0;
|
||||
b->pins[0].gpio.mux_total = 0;
|
||||
b->pins[0].uart.pinmap = 0;
|
||||
b->pins[0].uart.parent_id = 0;
|
||||
b->pins[0].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[1].name, "IO1", 8);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1};
|
||||
b->pins[1].gpio.pinmap = 131;
|
||||
b->pins[1].gpio.parent_id = 0;
|
||||
b->pins[1].gpio.mux_total = 0;
|
||||
b->pins[1].uart.pinmap = 0;
|
||||
b->pins[1].uart.parent_id = 0;
|
||||
b->pins[1].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[2].name, "IO2", 8);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
@@ -634,6 +1248,11 @@ mraa_intel_edison_fab_c()
|
||||
b->spi_bus[0].miso = 12;
|
||||
b->spi_bus[0].sclk = 13;
|
||||
|
||||
b->uart_dev_count = 1;
|
||||
b->def_uart_dev = 0;
|
||||
b->uart_dev[0].rx = 0;
|
||||
b->uart_dev[0].tx = 1;
|
||||
|
||||
int il;
|
||||
for (il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) {
|
||||
pinmodes[il].gpio.sysfs = -1;
|
||||
|
@@ -24,10 +24,99 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "intel_galileo_rev_d.h"
|
||||
|
||||
#define UIO_PATH "/dev/uio0"
|
||||
#define PLATFORM_NAME "Intel Galileo Gen 1"
|
||||
|
||||
static uint8_t *mmap_reg = NULL;
|
||||
static int mmap_fd = 0;
|
||||
static int mmap_size = 0x1000;
|
||||
static unsigned int mmap_count = 0;
|
||||
|
||||
static mraa_result_t
|
||||
mraa_intel_galileo_g1_mmap_unsetup()
|
||||
{
|
||||
if (mmap_reg == NULL) {
|
||||
syslog(LOG_ERR, "mmap: null register cant unsetup");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
munmap(mmap_reg, mmap_size);
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_galileo_g1_mmap_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos;
|
||||
if (value) {
|
||||
*((unsigned *)mmap_reg) |= (1<<bitpos);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
*((unsigned *)mmap_reg) &= ~(1<<bitpos);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_galileo_g1_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "Galileo mmap: context not valid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (mraa_pin_mode_test(dev->phy_pin, MRAA_PIN_FAST_GPIO) == 0) {
|
||||
syslog(LOG_ERR, "Galileo mmap: mmap not on this pin");
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
if (en == 0) {
|
||||
if (dev->mmap_write == NULL) {
|
||||
syslog(LOG_ERR, "mmap: can't disable disabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
dev->mmap_write = NULL;
|
||||
mmap_count--;
|
||||
if (mmap_count == 0) {
|
||||
return mraa_intel_galileo_g1_mmap_unsetup();
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
if (dev->mmap_write != NULL) {
|
||||
syslog(LOG_ERR, "mmap: can't enable enabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (mmap_reg == NULL) {
|
||||
if ((mmap_fd = open(UIO_PATH, O_RDWR)) < 0) {
|
||||
syslog(LOG_ERR, "mmap: Unable to open UIO device");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
mmap_reg = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED, mmap_fd, 0);
|
||||
|
||||
if (mmap_reg == MAP_FAILED) {
|
||||
syslog(LOG_ERR, "mmap: failed to mmap");
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
}
|
||||
if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio)
|
||||
!= MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mmap: unable to setup required multiplexers");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->mmap_write = &mraa_intel_galileo_g1_mmap_write;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_rev_d()
|
||||
{
|
||||
@@ -35,6 +124,10 @@ mraa_intel_galileo_rev_d()
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->platform_name_length = strlen(PLATFORM_NAME) + 1;
|
||||
b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
|
||||
strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
|
||||
|
||||
b->phy_pin_count = 20;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
@@ -42,6 +135,11 @@ mraa_intel_galileo_rev_d()
|
||||
|
||||
b->adc_raw = 12;
|
||||
b->adc_supported = 10;
|
||||
b->pwm_default_period = 500;
|
||||
b->pwm_max_period = 7968;
|
||||
b->pwm_min_period = 1;
|
||||
|
||||
advance_func->gpio_mmap_setup = &mraa_intel_galileo_g1_mmap_setup;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_GALILEO_REV_D_PINCOUNT);
|
||||
|
||||
|
@@ -25,12 +25,21 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "intel_galileo_rev_g.h"
|
||||
|
||||
#define MAX_SIZE 64
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
#define PLATFORM_NAME "Intel Galileo Gen 2"
|
||||
|
||||
#define UIO_PATH "/dev/uio0"
|
||||
|
||||
static uint8_t *mmap_reg = NULL;
|
||||
static int mmap_fd = 0;
|
||||
static int mmap_size = 0x1000;
|
||||
static unsigned int mmap_count = 0;
|
||||
|
||||
static unsigned int pullup_map[] = {33,29,35,17,37,19,21,39,41,23,27,25,43,31,49,51,53,55,57,59};
|
||||
|
||||
@@ -84,7 +93,7 @@ mraa_intel_galileo_gen2_pwm_period_replace(mraa_pwm_context dev, int period)
|
||||
|
||||
int period_f = open(bu, O_RDWR);
|
||||
if (period_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open period for writing!");
|
||||
syslog(LOG_ERR, "galileo2: Failed to open period for writing!");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
char out[MAX_SIZE];
|
||||
@@ -110,7 +119,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
||||
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
||||
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
||||
if (sta != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "Galileo Gen 2: Failed to set gpio pullup");
|
||||
syslog(LOG_ERR, "galileo2: Failed to set gpio pullup");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -119,7 +128,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
||||
|
||||
int drive = open(filepath, O_WRONLY);
|
||||
if (drive == -1) {
|
||||
syslog(LOG_ERR, "Failed to open drive for writing");
|
||||
syslog(LOG_ERR, "galileo2: Failed to open drive for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -147,15 +156,16 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (write(drive, bu, length*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to drive mode");
|
||||
syslog(LOG_ERR, "galileo2: Failed to write to drive mode");
|
||||
close(drive);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
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");
|
||||
syslog(LOG_ERR, "galileo2: Error Setting pullup");
|
||||
close(drive);
|
||||
return sta;
|
||||
}
|
||||
}
|
||||
@@ -164,6 +174,101 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_galileo_gen2_uart_init_pre(int index)
|
||||
{
|
||||
mraa_gpio_context io0_output = mraa_gpio_init_raw(32);
|
||||
mraa_gpio_context io1_output = mraa_gpio_init_raw(28);
|
||||
mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
|
||||
mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);
|
||||
|
||||
mraa_gpio_write(io0_output, 1);
|
||||
mraa_gpio_write(io1_output, 0);
|
||||
|
||||
mraa_gpio_close(io0_output);
|
||||
mraa_gpio_close(io1_output);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_intel_galileo_g2_mmap_unsetup()
|
||||
{
|
||||
if (mmap_reg == NULL) {
|
||||
syslog(LOG_ERR, "mmap: null register cant unsetup");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
munmap(mmap_reg, mmap_size);
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_galileo_g2_mmap_write(mraa_gpio_context dev, int value)
|
||||
{
|
||||
int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos;
|
||||
if (value) {
|
||||
*((unsigned *)mmap_reg) |= (1<<bitpos);
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
*((unsigned *)mmap_reg) &= ~(1<<bitpos);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_intel_galileo_g2_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_ERR, "Galileo mmap: context not valid");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (mraa_pin_mode_test(dev->phy_pin, MRAA_PIN_FAST_GPIO) == 0) {
|
||||
syslog(LOG_ERR, "Galileo mmap: mmap not on this pin");
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
if (en == 0) {
|
||||
if (dev->mmap_write == NULL) {
|
||||
syslog(LOG_ERR, "mmap: can't disable disabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
dev->mmap_write = NULL;
|
||||
mmap_count--;
|
||||
if (mmap_count == 0) {
|
||||
return mraa_intel_galileo_g2_mmap_unsetup();
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
if (dev->mmap_write != NULL) {
|
||||
syslog(LOG_ERR, "mmap: can't enable enabled mmap gpio");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (mmap_reg == NULL) {
|
||||
if ((mmap_fd = open(UIO_PATH, O_RDWR)) < 0) {
|
||||
syslog(LOG_ERR, "mmap: Unable to open UIO device");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
mmap_reg = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED, mmap_fd, 0);
|
||||
|
||||
if (mmap_reg == MAP_FAILED) {
|
||||
syslog(LOG_ERR, "mmap: failed to mmap");
|
||||
mmap_reg = NULL;
|
||||
close(mmap_fd);
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
}
|
||||
if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio)
|
||||
!= MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mmap: unable to setup required multiplexers");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->mmap_write = &mraa_intel_galileo_g2_mmap_write;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_galileo_gen2()
|
||||
{
|
||||
@@ -171,21 +276,30 @@ mraa_intel_galileo_gen2()
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->platform_name_length = strlen(PLATFORM_NAME) + 1;
|
||||
b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
|
||||
strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
|
||||
|
||||
b->phy_pin_count = 20;
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
b->adc_raw = 12;
|
||||
b->adc_supported = 10;
|
||||
b->pwm_default_period = 5000;
|
||||
b->pwm_max_period = 41666;
|
||||
b->pwm_min_period = 666;
|
||||
|
||||
advance_func->gpio_dir_pre = &mraa_intel_galileo_gen2_dir_pre;
|
||||
advance_func->i2c_init_pre = &mraa_intel_galileo_gen2_i2c_init_pre;
|
||||
advance_func->pwm_period_replace = &mraa_intel_galileo_gen2_pwm_period_replace;
|
||||
advance_func->gpio_mode_replace = &mraa_intel_galileo_gen2_gpio_mode_replace;
|
||||
advance_func->uart_init_pre = &mraa_intel_galileo_gen2_uart_init_pre;
|
||||
advance_func->gpio_mmap_setup = &mraa_intel_galileo_g2_mmap_setup;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_GALILEO_GEN_2_PINCOUNT);
|
||||
|
||||
strncpy(b->pins[0].name, "IO0", 8);
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0};
|
||||
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0,1};
|
||||
b->pins[0].gpio.pinmap = 11;
|
||||
b->pins[0].gpio.parent_id = 0;
|
||||
b->pins[0].gpio.mux_total = 0;
|
||||
@@ -201,9 +315,11 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[0].mmap.gpio.mux[1].value = 0;
|
||||
b->pins[0].mmap.mem_sz = 0x1000;
|
||||
b->pins[0].mmap.bit_pos = 3;
|
||||
b->pins[0].uart.parent_id = 0;
|
||||
b->pins[0].uart.mux_total = 0;
|
||||
|
||||
strncpy(b->pins[1].name, "IO1", 8);
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0};
|
||||
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0,1};
|
||||
b->pins[1].gpio.pinmap = 12;
|
||||
b->pins[1].gpio.parent_id = 0;
|
||||
b->pins[1].gpio.mux_total = 1;
|
||||
@@ -223,6 +339,10 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[1].mmap.gpio.mux[2].value = 0;
|
||||
b->pins[1].mmap.mem_sz = 0x1000;
|
||||
b->pins[1].mmap.bit_pos = 4;
|
||||
b->pins[1].uart.parent_id = 0;
|
||||
b->pins[1].uart.mux_total = 1;
|
||||
b->pins[1].uart.mux[0].pin = 45;
|
||||
b->pins[1].uart.mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[2].name, "IO2", 8);
|
||||
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0};
|
||||
@@ -361,7 +481,7 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[9].pwm.mux[1].value = 0;
|
||||
|
||||
strncpy(b->pins[10].name, "IO10", 8);
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,1,1,1,0,0,0};
|
||||
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,1,1,1,1,0,0};
|
||||
b->pins[10].gpio.pinmap = 10;
|
||||
b->pins[10].gpio.parent_id = 0;
|
||||
b->pins[10].gpio.mux_total = 1;
|
||||
@@ -388,6 +508,10 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[10].mmap.gpio.mux[2].value = 0;
|
||||
b->pins[10].mmap.mem_sz = 0x1000;
|
||||
b->pins[10].mmap.bit_pos = 2;
|
||||
b->pins[10].spi.parent_id = 1;
|
||||
b->pins[10].spi.mux_total = 1;
|
||||
b->pins[10].spi.mux[0].pin = 74;
|
||||
b->pins[10].spi.mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[11].name, "IO11", 8);
|
||||
b->pins[11].capabilites = (mraa_pincapabilities_t) {1,1,1,0,1,0,0};
|
||||
@@ -565,5 +689,10 @@ mraa_intel_galileo_gen2()
|
||||
b->spi_bus[0].miso = 12;
|
||||
b->spi_bus[0].sclk = 13;
|
||||
|
||||
b->uart_dev_count = 1;
|
||||
b->def_uart_dev = 0;
|
||||
b->uart_dev[0].rx = 0;
|
||||
b->uart_dev[0].tx = 1;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
154
src/intel_minnow_max.c
Normal file
154
src/intel_minnow_max.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "intel_minnow_max.h"
|
||||
|
||||
#define PLATFORM_NAME "MinnowBoard MAX"
|
||||
#define I2C_BUS_COUNT 10
|
||||
#define I2C_BUS_DEFAULT 7
|
||||
|
||||
mraa_result_t
|
||||
mraa_set_pininfo(mraa_board_t* board, int mraa_index, char *name, mraa_pincapabilities_t caps, int sysfs_pin)
|
||||
{
|
||||
if (mraa_index < board->phy_pin_count) {
|
||||
mraa_pininfo_t* pin_info = &board->pins[mraa_index];
|
||||
strncpy(pin_info->name, name, 8);
|
||||
pin_info->capabilites = caps;
|
||||
if (caps.gpio)
|
||||
pin_info->gpio.pinmap = sysfs_pin;
|
||||
if (caps.i2c) {
|
||||
pin_info->i2c.pinmap = 1;
|
||||
pin_info->i2c.mux_total = 0;
|
||||
}
|
||||
if (caps.pwm) {
|
||||
int controller = 0;
|
||||
if (strncmp(name, "PWM", 3) == 0 && strlen(name) > 3 && isdigit(name[3]))
|
||||
controller = name[3] - '0';
|
||||
pin_info->pwm.parent_id = controller;
|
||||
pin_info->pwm.pinmap = 0;
|
||||
pin_info->pwm.mux_total = 0;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_get_pin_index(mraa_board_t* board, char *name, int* pin_index) {
|
||||
int i;
|
||||
for (i = 0; i < board->phy_pin_count; ++i) {
|
||||
if (strcmp(name, board->pins[i].name) == 0) {
|
||||
*pin_index = i;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
}
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
mraa_board_t*
|
||||
mraa_intel_minnow_max()
|
||||
{
|
||||
mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->platform_name_length = strlen(PLATFORM_NAME) + 1;
|
||||
b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
|
||||
strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
|
||||
|
||||
b->phy_pin_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT;
|
||||
//b->gpio_count = 14;
|
||||
b->aio_count = 0;
|
||||
b->adc_raw = 0;
|
||||
b->adc_supported = 0;
|
||||
|
||||
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_MINNOW_MAX_PINCOUNT);
|
||||
mraa_set_pininfo(b, 0, "INVALID", (mraa_pincapabilities_t){0,0,0,0,0,0,0,0}, -1);
|
||||
mraa_set_pininfo(b, 1, "GND", (mraa_pincapabilities_t){0,0,0,0,0,0,0,0}, -1);
|
||||
mraa_set_pininfo(b, 2, "GND", (mraa_pincapabilities_t){0,0,0,0,0,0,0,0}, -1);
|
||||
mraa_set_pininfo(b, 3, "5v", (mraa_pincapabilities_t){0,0,0,0,0,0,0,0}, -1);
|
||||
mraa_set_pininfo(b, 4, "3.3v", (mraa_pincapabilities_t){1,0,0,0,0,0,0,0}, -1);
|
||||
mraa_set_pininfo(b, 5, "SPI_CS", (mraa_pincapabilities_t){1,0,0,0,1,0,0,0}, 220);
|
||||
mraa_set_pininfo(b, 6, "UART1_TX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 225);
|
||||
mraa_set_pininfo(b, 7, "SPI_MISO", (mraa_pincapabilities_t){1,0,0,0,1,0,0,0}, 221);
|
||||
mraa_set_pininfo(b, 8, "UART1_RX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 224);
|
||||
mraa_set_pininfo(b, 9, "SPI_MOSI", (mraa_pincapabilities_t){1,0,0,0,1,0,0,0}, 222);
|
||||
mraa_set_pininfo(b, 10, "UART1_CT", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 227);
|
||||
mraa_set_pininfo(b, 11, "SPI_CLK", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 223);
|
||||
mraa_set_pininfo(b, 12, "UART1_RT", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 226);
|
||||
mraa_set_pininfo(b, 13, "I2C_SCL", (mraa_pincapabilities_t){1,0,0,0,0,1,0,0}, 243);
|
||||
mraa_set_pininfo(b, 14, "I2S_CLK", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 216);
|
||||
mraa_set_pininfo(b, 15, "I2C_SDA", (mraa_pincapabilities_t){1,0,0,0,0,1,0,0}, 242);
|
||||
mraa_set_pininfo(b, 16, "I2S_FRM", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 217);
|
||||
mraa_set_pininfo(b, 17, "UART2_TX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 229);
|
||||
mraa_set_pininfo(b, 18, "I2S_DO", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 219);
|
||||
mraa_set_pininfo(b, 19, "UART2_RX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 228);
|
||||
mraa_set_pininfo(b, 20, "I2S_DI", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 218);
|
||||
mraa_set_pininfo(b, 21, "S5_0", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 82);
|
||||
mraa_set_pininfo(b, 22, "PWM0", (mraa_pincapabilities_t){1,0,1,0,0,0,0,0}, 248); // Assume BIOS configured for PWM
|
||||
mraa_set_pininfo(b, 23, "S5_1", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 83);
|
||||
mraa_set_pininfo(b, 24, "PWM1", (mraa_pincapabilities_t){1,0,1,0,0,0,0,0}, 249); // Assume BIOS configured for PWM
|
||||
mraa_set_pininfo(b, 25, "S5_4", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 84);
|
||||
mraa_set_pininfo(b, 26, "IBL_8254", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 208);
|
||||
|
||||
// Set number of i2c adaptors
|
||||
// Got this from running 'i2cdetect -l'
|
||||
b->i2c_bus_count = I2C_BUS_COUNT;
|
||||
|
||||
// Disable all i2c adaptors
|
||||
int ici;
|
||||
for (ici = 0; ici < b->i2c_bus_count; ici++) {
|
||||
b->i2c_bus[ici].bus_id = -1;
|
||||
}
|
||||
|
||||
// Configure i2c adaptor #7 and make it the default
|
||||
int pin_index_sda, pin_index_scl;
|
||||
if (mraa_get_pin_index(b, "I2C_SDA", &pin_index_sda) == MRAA_SUCCESS &&
|
||||
mraa_get_pin_index(b, "I2C_SCL", &pin_index_scl) == MRAA_SUCCESS) {
|
||||
b->def_i2c_bus = I2C_BUS_DEFAULT;
|
||||
b->i2c_bus[b->def_i2c_bus].bus_id = b->def_i2c_bus;
|
||||
b->i2c_bus[b->def_i2c_bus].sda = pin_index_sda;
|
||||
b->i2c_bus[b->def_i2c_bus].scl = pin_index_scl;
|
||||
}
|
||||
|
||||
// Configure PWM
|
||||
b->pwm_default_period = 500;
|
||||
b->pwm_max_period = 1000000000;
|
||||
b->pwm_min_period = 1;
|
||||
|
||||
b->spi_bus_count = 1;
|
||||
b->def_spi_bus = 0;
|
||||
b->spi_bus[0].bus_id = 0;
|
||||
b->spi_bus[0].slave_s = 0;
|
||||
b->spi_bus[0].cs = 5;
|
||||
b->spi_bus[0].mosi = 9;
|
||||
b->spi_bus[0].miso = 7;
|
||||
b->spi_bus[0].sclk = 11;
|
||||
|
||||
return b;
|
||||
}
|
@@ -31,7 +31,40 @@ set_target_properties (mraajs PROPERTIES
|
||||
OUTPUT_NAME mraa
|
||||
SUFFIX ".node"
|
||||
)
|
||||
macro (mraa_CREATE_INSTALL_PACKAGE_JSON generated_file install_location)
|
||||
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
|
||||
endmacro (mraa_CREATE_INSTALL_PACKAGE_JSON)
|
||||
mraa_create_install_package_json (package.json lib/node_modules/mraa)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.json
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.node
|
||||
macro (mraa_CREATE_BINDING_GYP generated_file)
|
||||
set (mraa_LIB_SRCS_GYP "")
|
||||
foreach (srcfile ${mraa_LIB_SRCS_NOAUTO})
|
||||
file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${srcfile})
|
||||
set (mraa_LIB_SRCS_GYP "'${rel}',\n${mraa_LIB_SRCS_GYP}")
|
||||
endforeach (srcfile)
|
||||
foreach (includedir ${mraa_LIB_INCLUDE_DIRS})
|
||||
file (RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${includedir})
|
||||
set (mraa_LIB_INCLUDE_DIRS_GYP "'${rel}',\n${mraa_LIB_INCLUDE_DIRS_GYP}")
|
||||
endforeach (includedir)
|
||||
configure_file (${generated_file}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
|
||||
endmacro (mraa_CREATE_BINDING_GYP)
|
||||
mraa_create_binding_gyp (binding.gyp)
|
||||
|
||||
add_custom_target (npmpkg)
|
||||
add_custom_command (TARGET npmpkg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraajsJAVASCRIPT_wrap.cxx ${CMAKE_SOURCE_DIR}/src
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_BINARY_DIR}/src/version.c ${CMAKE_SOURCE_DIR}/src
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/package.json ${CMAKE_SOURCE_DIR}
|
||||
COMMAND sed -i "'s/mraa.node/build\\/Release\\/mraa.node/'"
|
||||
${CMAKE_SOURCE_DIR}/package.json
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/binding.gyp ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_SOURCE_DIR}/docs/npm.md ${CMAKE_SOURCE_DIR}/READMEFIRST)
|
||||
add_dependencies (npmpkg mraajs)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.node
|
||||
DESTINATION lib/node_modules/mraa)
|
||||
|
19
src/javascript/binding.gyp.cmake
Normal file
19
src/javascript/binding.gyp.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'mraa',
|
||||
'sources': [
|
||||
@mraa_LIB_SRCS_GYP@
|
||||
'src/version.c',
|
||||
'src/mraajsJAVASCRIPT_wrap.cxx' ],
|
||||
'include_dirs': [
|
||||
@mraa_LIB_INCLUDE_DIRS_GYP@
|
||||
],
|
||||
'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ],
|
||||
'cflags!': [ '-fno-exceptions' ],
|
||||
'defines' : [ 'SWIG',
|
||||
'SWIGNODE',
|
||||
'BUILDING_NODE_EXTENSION=1' ],
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"name" : "mraa",
|
||||
"main" : "./mraa.node",
|
||||
"engines": {
|
||||
"node": ">= 1.0.x"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
16
src/javascript/package.json.cmake
Normal file
16
src/javascript/package.json.cmake
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name" : "mraa",
|
||||
"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",
|
||||
"keywords":["gpio", "edison","galileo","io", "mraajs", "spi", "i2c", "minnow", "intel"],
|
||||
"homepage": "http://github.com/intel-iot-devkit/mraa",
|
||||
"main" : "./mraa.node",
|
||||
"engines": {
|
||||
"node": ">= 0.10.x"
|
||||
},
|
||||
"bugs": {
|
||||
"url" : "http://github.com/intel-iot-devkit/mraa/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"version": "@VERSION@",
|
||||
"authors": "See github.com/intel-iot-devkit/mraa/graphs/contributors"
|
||||
}
|
194
src/mraa.c
194
src/mraa.c
@@ -28,10 +28,14 @@
|
||||
#include <sched.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include "mraa_internal.h"
|
||||
#include "intel_galileo_rev_d.h"
|
||||
#include "intel_galileo_rev_g.h"
|
||||
#include "intel_edison_fab_c.h"
|
||||
#include "intel_de3815.h"
|
||||
#include "intel_minnow_max.h"
|
||||
#include "gpio.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -83,12 +87,18 @@ mraa_init()
|
||||
FILE *fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
|
||||
if (fh != NULL) {
|
||||
if (getline(&line, &len, fh) != -1) {
|
||||
if (strncmp(line, "GalileoGen2", 10) == 0) {
|
||||
if (strncmp(line, "GalileoGen2", 11) == 0) {
|
||||
platform_type = MRAA_INTEL_GALILEO_GEN2;
|
||||
} else if (strncmp(line, "BODEGA BAY", 10) == 0) {
|
||||
platform_type = MRAA_INTEL_EDISON_FAB_C;
|
||||
} else if (strncmp(line, "SALT BAY", 7) == 0) {
|
||||
} else if (strncmp(line, "SALT BAY", 8) == 0) {
|
||||
platform_type = MRAA_INTEL_EDISON_FAB_C;
|
||||
} else if (strncmp(line, "DE3815", 6) == 0) {
|
||||
platform_type = MRAA_INTEL_DE3815;
|
||||
} else if (strncmp(line, "NOTEBOOK", 8) == 0) {
|
||||
platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
|
||||
} else if (strncasecmp(line, "MinnowBoard MAX", 15) == 0) {
|
||||
platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
|
||||
} else {
|
||||
platform_type = MRAA_INTEL_GALILEO_GEN1;
|
||||
}
|
||||
@@ -110,9 +120,16 @@ mraa_init()
|
||||
case MRAA_INTEL_EDISON_FAB_C:
|
||||
plat = mraa_intel_edison_fab_c();
|
||||
break;
|
||||
case MRAA_INTEL_DE3815:
|
||||
plat = mraa_intel_de3815();
|
||||
break;
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
plat = mraa_intel_minnow_max();
|
||||
break;
|
||||
|
||||
default:
|
||||
plat = mraa_intel_galileo_rev_d();
|
||||
syslog(LOG_ERR, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1");
|
||||
syslog(LOG_ERR, "Platform not supported, initialising as MRAA_INTEL_GALILEO_GEN1");
|
||||
}
|
||||
|
||||
syslog(LOG_NOTICE, "libmraa initialised for platform %d", platform_type);
|
||||
@@ -143,7 +160,7 @@ mraa_set_priority(const unsigned int priority)
|
||||
return sched_setscheduler(0, SCHED_RR, &sched_s);
|
||||
}
|
||||
|
||||
static mraa_result_t
|
||||
mraa_result_t
|
||||
mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
{
|
||||
int mi;
|
||||
@@ -159,148 +176,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mraa_setup_gpio(int pin)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return MRAA_PLATFORM_NO_INIT;
|
||||
|
||||
if (pin < 0 || pin > plat->phy_pin_count)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
|
||||
if(plat->pins[pin].capabilites.gpio != 1)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
|
||||
if (plat->pins[pin].gpio.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
return plat->pins[pin].gpio.pinmap;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mraa_setup_aio(int aio)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return MRAA_PLATFORM_NO_INIT;
|
||||
|
||||
if (aio < 0 || aio > plat->aio_count)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
|
||||
int pin = aio + plat->gpio_count;
|
||||
|
||||
if (plat->pins[pin].capabilites.aio != 1)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
|
||||
if (plat->pins[pin].aio.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS)
|
||||
return MRAA_NO_SUCH_IO;
|
||||
return plat->pins[pin].aio.pinmap;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
mraa_setup_i2c(int bus)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return MRAA_PLATFORM_NO_INIT;
|
||||
|
||||
if (plat->i2c_bus_count == 0) {
|
||||
syslog(LOG_ERR, "No i2c buses defined in platform");
|
||||
return MRAA_NO_SUCH_IO;
|
||||
}
|
||||
if (bus >= plat->i2c_bus_count) {
|
||||
syslog(LOG_ERR, "Above i2c bus count");
|
||||
return MRAA_NO_SUCH_IO;
|
||||
}
|
||||
|
||||
if (plat->i2c_bus[bus].bus_id == -1) {
|
||||
syslog(LOG_ERR, "Platform not currently allowed for mraa use");
|
||||
return MRAA_NO_SUCH_IO;
|
||||
}
|
||||
|
||||
int pos = plat->i2c_bus[bus].sda;
|
||||
if (plat->pins[pos].i2c.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
||||
return MRAA_IO_SETUP_FAILURE;
|
||||
|
||||
pos = plat->i2c_bus[bus].scl;
|
||||
if (plat->pins[pos].i2c.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
||||
return MRAA_IO_SETUP_FAILURE;
|
||||
|
||||
return plat->i2c_bus[bus].bus_id;
|
||||
}
|
||||
|
||||
mraa_spi_bus_t*
|
||||
mraa_setup_spi(int bus)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return NULL;
|
||||
|
||||
if (plat->spi_bus_count >! 0) {
|
||||
syslog(LOG_ERR, "No spi buses defined in platform");
|
||||
return NULL;
|
||||
}
|
||||
if (plat->spi_bus_count == 1) {
|
||||
bus = plat->def_spi_bus;
|
||||
}
|
||||
if (bus >= plat->spi_bus_count) {
|
||||
syslog(LOG_ERR, "Above spi bus count");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pos = plat->spi_bus[bus].sclk;
|
||||
if (plat->pins[pos].spi.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
pos = plat->spi_bus[bus].mosi;
|
||||
if (plat->pins[pos].spi.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
pos = plat->spi_bus[bus].miso;
|
||||
if (plat->pins[pos].spi.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
mraa_spi_bus_t *spi = &(plat->spi_bus[bus]);
|
||||
return spi;
|
||||
}
|
||||
|
||||
mraa_pin_t*
|
||||
mraa_setup_pwm(int pin)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return NULL;
|
||||
|
||||
if (plat->pins[pin].capabilites.pwm != 1)
|
||||
return NULL;
|
||||
|
||||
if (plat->pins[pin].capabilites.gpio == 1) {
|
||||
mraa_gpio_context mux_i;
|
||||
mux_i = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
||||
if (mux_i == NULL)
|
||||
return NULL;
|
||||
if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
// Current REV D quirk. //TODO GEN 2
|
||||
if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
if (mraa_gpio_close(mux_i) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (plat->pins[pin].pwm.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].pwm) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
mraa_pin_t *ret;
|
||||
ret = (mraa_pin_t*) malloc(sizeof(mraa_pin_t));
|
||||
ret->pinmap = plat->pins[pin].pwm.pinmap;
|
||||
ret->parent_id = plat->pins[pin].pwm.parent_id;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
mraa_result_print(mraa_result_t result)
|
||||
{
|
||||
@@ -400,25 +275,6 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
mraa_mmap_pin_t*
|
||||
mraa_setup_mmap_gpio(int pin)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return NULL;
|
||||
|
||||
if (plat->pins[pin].capabilites.fast_gpio != 1)
|
||||
return NULL;
|
||||
|
||||
if (plat->pins[pin].mmap.gpio.mux_total > 0)
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].mmap.gpio) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].mmap.gpio) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
mraa_mmap_pin_t *ret = &(plat->pins[pin].mmap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mraa_platform_t mraa_get_platform_type()
|
||||
{
|
||||
return platform_type;
|
||||
@@ -476,3 +332,11 @@ mraa_setup_uart(int index)
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
char*
|
||||
mraa_get_platform_name()
|
||||
{
|
||||
if (plat == NULL)
|
||||
return "Unknown";
|
||||
return plat->platform_name;
|
||||
}
|
||||
|
13
src/mraa.i
13
src/mraa.i
@@ -1,5 +1,6 @@
|
||||
%include stdint.i
|
||||
%include std_string.i
|
||||
%include exception.i
|
||||
|
||||
#ifdef DOXYGEN
|
||||
%include common_hpp_doc.i
|
||||
@@ -26,8 +27,16 @@
|
||||
mraa_init();
|
||||
%}
|
||||
|
||||
%typemap(in) uint8_t = char;
|
||||
%typemap(in) unsigned char* = char*;
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(const std::invalid_argument& e) {
|
||||
SWIG_exception(SWIG_ValueError, e.what());
|
||||
} catch(...) {
|
||||
SWIG_exception(SWIG_RuntimeError, "Unknown exception");
|
||||
}
|
||||
}
|
||||
|
||||
%apply (char *STRING, size_t LENGTH) { (char *data, size_t length) };
|
||||
|
||||
%include "common.hpp"
|
||||
|
148
src/pwm/pwm.c
148
src/pwm/pwm.c
@@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "pwm.h"
|
||||
#include "mraa_internal.h"
|
||||
@@ -56,7 +57,7 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
|
||||
|
||||
int period_f = open(bu, O_RDWR);
|
||||
if (period_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open period for writing");
|
||||
syslog(LOG_ERR, "pwm: Failed to open period for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
char out[MAX_SIZE];
|
||||
@@ -74,7 +75,9 @@ static mraa_result_t
|
||||
mraa_pwm_write_duty(mraa_pwm_context dev, int duty)
|
||||
{
|
||||
if (dev->duty_fp == -1) {
|
||||
mraa_pwm_setup_duty_fp(dev);
|
||||
if (mraa_pwm_setup_duty_fp(dev) == 1) {
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
char bu[64];
|
||||
int length = sprintf(bu, "%d", duty);
|
||||
@@ -92,50 +95,114 @@ mraa_pwm_read_period(mraa_pwm_context dev)
|
||||
|
||||
int period_f = open(bu, O_RDWR);
|
||||
if (period_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open period for reading");
|
||||
syslog(LOG_ERR, "pwm: Failed to open period for reading");
|
||||
return 0;
|
||||
}
|
||||
off_t size = lseek(period_f, 0, SEEK_END);
|
||||
lseek(period_f, 0, SEEK_SET);
|
||||
|
||||
read(period_f, output, size + 1);
|
||||
ssize_t rb = read(period_f, output, size + 1);
|
||||
close(period_f);
|
||||
int ret = strtol(output, NULL, 10);
|
||||
|
||||
return ret;
|
||||
if (rb < 0) {
|
||||
syslog(LOG_ERR, "pwm: Error in reading period");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *endptr;
|
||||
long int ret = strtol(output, &endptr, 10);
|
||||
if ('\0' != *endptr && '\n' != *endptr) {
|
||||
syslog(LOG_ERR, "pwm: Error in string conversion");
|
||||
return -1;
|
||||
}
|
||||
else if (ret > INT_MAX || ret < INT_MIN) {
|
||||
syslog(LOG_ERR, "pwm: Number is invalid");
|
||||
return -1;
|
||||
}
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
static int
|
||||
mraa_pwm_read_duty(mraa_pwm_context dev)
|
||||
{
|
||||
if (dev->duty_fp == -1) {
|
||||
mraa_pwm_setup_duty_fp(dev);
|
||||
if (mraa_pwm_setup_duty_fp(dev) == 1) {
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
} else {
|
||||
lseek(dev->duty_fp, 0, SEEK_SET);
|
||||
}
|
||||
off_t size = lseek(dev->duty_fp, 0, SEEK_END);
|
||||
lseek(dev->duty_fp, 0, SEEK_SET);
|
||||
char output[MAX_SIZE];
|
||||
read(dev->duty_fp, output, size+1);
|
||||
ssize_t rb = read(dev->duty_fp, output, size+1);
|
||||
if (rb < 0) {
|
||||
syslog(LOG_ERR, "pwm: Error in reading duty");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = strtol(output, NULL, 10);
|
||||
return ret;
|
||||
char *endptr;
|
||||
long int ret = strtol(output, &endptr, 10);
|
||||
if ('\0' != *endptr && '\n' != *endptr) {
|
||||
syslog(LOG_ERR, "pwm: Error in string converstion");
|
||||
return -1;
|
||||
}
|
||||
else if (ret > INT_MAX || ret < INT_MIN) {
|
||||
syslog(LOG_ERR, "pwm: Number is invalid");
|
||||
return -1;
|
||||
}
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
mraa_pwm_context
|
||||
mraa_pwm_init(int pin) {
|
||||
mraa_pwm_init(int pin)
|
||||
{
|
||||
if (advance_func->pwm_init_pre != NULL) {
|
||||
if (advance_func->pwm_init_pre(pin) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
mraa_pin_t* pinm = mraa_setup_pwm(pin);
|
||||
if (pinm == NULL)
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "pwm: Platform Not Initialised");
|
||||
return NULL;
|
||||
int chip = pinm->parent_id;
|
||||
int pinn = pinm->pinmap;
|
||||
free(pinm);
|
||||
}
|
||||
if (plat->pins[pin].capabilites.pwm != 1) {
|
||||
syslog(LOG_ERR, "pwm: pin not capable of pwm");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (advance_func->gpio_init_post != NULL) {
|
||||
if (plat->pins[pin].capabilites.gpio == 1) {
|
||||
// This deserves more investigation
|
||||
mraa_gpio_context mux_i;
|
||||
mux_i = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
||||
if (mux_i == NULL) {
|
||||
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_gpio_close(mux_i) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "pwm: error in gpio->pwm transition");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (plat->pins[pin].pwm.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pin].pwm) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "pwm: Failed to set-up multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int chip = plat->pins[pin].pwm.parent_id;
|
||||
int pinn = plat->pins[pin].pwm.pinmap;
|
||||
|
||||
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) {
|
||||
@@ -161,14 +228,14 @@ mraa_pwm_init_raw(int chipin, int pin)
|
||||
snprintf(directory, MAX_SIZE, SYSFS_PWM "/pwmchip%d/pwm%d", dev->chipid, dev->pin);
|
||||
struct stat dir;
|
||||
if (stat(directory, &dir) == 0 && S_ISDIR(dir.st_mode)) {
|
||||
syslog(LOG_NOTICE, "PWM Pin already exporting, continuing");
|
||||
syslog(LOG_NOTICE, "pwm: Pin already exported, continuing");
|
||||
dev->owner = 0; // Not Owner
|
||||
} else {
|
||||
char buffer[MAX_SIZE];
|
||||
snprintf(buffer, MAX_SIZE, "/sys/class/pwm/pwmchip%d/export", dev->chipid);
|
||||
int export_f = open(buffer, O_WRONLY);
|
||||
if (export_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open export for writing");
|
||||
syslog(LOG_ERR, "pwm: Failed to open export for writing");
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
@@ -176,11 +243,13 @@ mraa_pwm_init_raw(int chipin, int pin)
|
||||
char out[MAX_SIZE];
|
||||
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
||||
if (write(export_f, out, size*sizeof(char)) == -1) {
|
||||
syslog(LOG_WARNING, "Failed to write to export! Potentially already enabled");
|
||||
syslog(LOG_WARNING, "pwm: Failed to write to export! Potentially already enabled");
|
||||
close(export_f);
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
dev->owner = 1;
|
||||
mraa_pwm_period_us(dev, plat->pwm_default_period);
|
||||
close(export_f);
|
||||
}
|
||||
mraa_pwm_setup_duty_fp(dev);
|
||||
@@ -190,14 +259,20 @@ mraa_pwm_init_raw(int chipin, int pin)
|
||||
mraa_result_t
|
||||
mraa_pwm_write(mraa_pwm_context dev, float percentage)
|
||||
{
|
||||
if (percentage >= 1.0f) {
|
||||
return mraa_pwm_write_duty(dev, mraa_pwm_read_period(dev));
|
||||
}
|
||||
return mraa_pwm_write_duty(dev, percentage * mraa_pwm_read_period(dev));
|
||||
}
|
||||
|
||||
float
|
||||
mraa_pwm_read(mraa_pwm_context dev)
|
||||
{
|
||||
float output = mraa_pwm_read_duty(dev) / (float) mraa_pwm_read_period(dev);
|
||||
return output;
|
||||
int period = mraa_pwm_read_period(dev);
|
||||
if (period > 0) {
|
||||
return (mraa_pwm_read_duty(dev) / (float) period);
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
@@ -215,6 +290,11 @@ mraa_pwm_period_ms(mraa_pwm_context dev, int ms)
|
||||
mraa_result_t
|
||||
mraa_pwm_period_us(mraa_pwm_context dev, int us)
|
||||
{
|
||||
if (us < plat->pwm_min_period ||
|
||||
us > plat->pwm_max_period) {
|
||||
syslog(LOG_ERR, "pwm: period value outside platform range");
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
return mraa_pwm_write_period(dev, us*1000);
|
||||
}
|
||||
|
||||
@@ -251,13 +331,13 @@ mraa_pwm_enable(mraa_pwm_context dev, int enable)
|
||||
int enable_f = open(bu, O_RDWR);
|
||||
|
||||
if (enable_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open enable for writing");
|
||||
syslog(LOG_ERR, "pwm: Failed to open enable for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
char out[2];
|
||||
int size = snprintf(out, sizeof(out), "%d", enable);
|
||||
if (write(enable_f, out, size * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to enable");
|
||||
syslog(LOG_ERR, "pwm: Failed to write to enable");
|
||||
close(enable_f);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -273,14 +353,14 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
|
||||
|
||||
int unexport_f = open(filepath, O_WRONLY);
|
||||
if (unexport_f == -1) {
|
||||
syslog(LOG_ERR, "Failed to open unexport for writing");
|
||||
syslog(LOG_ERR, "pwm: Failed to open unexport for writing");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
char out[MAX_SIZE];
|
||||
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
||||
if (write(unexport_f, out, size*sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "Failed to write to unexport");
|
||||
syslog(LOG_ERR, "pwm: Failed to write to unexport");
|
||||
close(unexport_f);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -322,15 +402,15 @@ mraa_pwm_config_ms(mraa_pwm_context dev, int ms ,float ms_float)
|
||||
int old_dutycycle, old_period, status;
|
||||
old_dutycycle = mraa_pwm_read_duty(dev);
|
||||
old_period = mraa_pwm_read_period(dev);
|
||||
status = mraa_pwm_write_duty(dev, 0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_period_us(dev, ms*1000);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
mraa_pwm_write_duty(dev, old_dutycycle);
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_write_duty(dev, 0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_pulsewidth_us(dev, ms_float*1000);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
mraa_pwm_write_duty(dev, old_dutycycle);
|
||||
@@ -346,15 +426,15 @@ mraa_pwm_config_percent(mraa_pwm_context dev, int ms ,float percentage)
|
||||
int old_dutycycle, old_period, status;
|
||||
old_dutycycle = mraa_pwm_read_duty(dev);
|
||||
old_period = mraa_pwm_read_period(dev);
|
||||
status = mraa_pwm_write_duty(dev, 0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_period_us(dev, ms*1000);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
mraa_pwm_write_duty(dev, old_dutycycle);
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_write_duty(dev, 0);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
status = mraa_pwm_pulsewidth_us(dev, (ms*1000)*percentage);
|
||||
if (status != MRAA_SUCCESS) {
|
||||
mraa_pwm_write_duty(dev, old_dutycycle);
|
||||
|
@@ -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
|
||||
===
|
||||
|
||||
|
100
src/spi/spi.c
100
src/spi/spi.c
@@ -52,25 +52,72 @@ struct _spi {
|
||||
mraa_spi_context
|
||||
mraa_spi_init(int bus)
|
||||
{
|
||||
if (plat == NULL) {
|
||||
syslog(LOG_ERR, "spi: Platform Not Initialised");
|
||||
return NULL;
|
||||
}
|
||||
if (plat->spi_bus_count == 0) {
|
||||
syslog(LOG_ERR, "spi: no spi buses defined in platform");
|
||||
return NULL;
|
||||
}
|
||||
if (plat->spi_bus_count == 1) {
|
||||
bus = plat->def_spi_bus;
|
||||
}
|
||||
if (bus >= plat->spi_bus_count) {
|
||||
syslog(LOG_ERR, "spi: requested bus above spi bus count");
|
||||
return NULL;
|
||||
}
|
||||
if (advance_func->spi_init_pre != NULL) {
|
||||
if (advance_func->spi_init_pre(bus) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mraa_spi_bus_t *spi = mraa_setup_spi(bus);
|
||||
if (bus < 0) {
|
||||
syslog(LOG_ERR, "Failed. SPI platform Error");
|
||||
int pos = plat->spi_bus[bus].sclk;
|
||||
if (plat->pins[pos].spi.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "spi: failed to set-up spi sclk multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pos = plat->spi_bus[bus].mosi;
|
||||
if (plat->pins[pos].spi.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "spi: failed to set-up spi mosi multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pos = plat->spi_bus[bus].miso;
|
||||
if (plat->pins[pos].spi.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "spi: failed to set-up spi miso multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pos = plat->spi_bus[bus].cs;
|
||||
if (plat->pins[pos].spi.mux_total > 0) {
|
||||
if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "spi: failed to set-up spi cs multiplexer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
||||
if (dev == NULL) {
|
||||
syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
|
||||
return NULL;
|
||||
}
|
||||
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
||||
memset(dev, 0, sizeof(struct _spi));
|
||||
|
||||
char path[MAX_SIZE];
|
||||
sprintf(path, "/dev/spidev%u.%u", spi->bus_id, spi->slave_s);
|
||||
sprintf(path, "/dev/spidev%u.%u",
|
||||
plat->spi_bus[bus].bus_id, plat->spi_bus[bus].slave_s);
|
||||
|
||||
dev->devfd = open(path, O_RDWR);
|
||||
if (dev->devfd < 0) {
|
||||
syslog(LOG_ERR, "Failed opening SPI Device. bus:%s", path);
|
||||
syslog(LOG_ERR, "spi: Failed opening SPI Device. bus:%s", path);
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
@@ -113,7 +160,7 @@ mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
|
||||
}
|
||||
|
||||
if (ioctl (dev->devfd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
|
||||
syslog(LOG_ERR, "Failed to set spi mode");
|
||||
syslog(LOG_ERR, "spi: Failed to set spi mode");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -131,12 +178,13 @@ mraa_spi_frequency(mraa_spi_context dev, int hz)
|
||||
mraa_result_t
|
||||
mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
{
|
||||
uint8_t lsb_mode = 0;
|
||||
if (lsb == 1) {
|
||||
lsb_mode = 1;
|
||||
}
|
||||
uint8_t lsb_mode = (uint8_t) lsb;
|
||||
if (ioctl (dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) {
|
||||
syslog(LOG_ERR, "Failed to set bit order");
|
||||
syslog(LOG_ERR, "spi: Failed to set bit order");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
if (ioctl (dev->devfd, SPI_IOC_RD_LSB_FIRST, &lsb_mode) < 0) {
|
||||
syslog(LOG_ERR, "spi: Failed to set bit order");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->lsb = lsb;
|
||||
@@ -146,6 +194,10 @@ mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
mraa_result_t
|
||||
mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
|
||||
{
|
||||
if (ioctl(dev->devfd, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
|
||||
syslog(LOG_ERR, "spi: Failed to set bit per word");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
dev->bpw = bits;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@@ -166,28 +218,38 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
msg.delay_usecs = 0;
|
||||
msg.len = length;
|
||||
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
||||
syslog(LOG_ERR, "Failed to perform dev transfer");
|
||||
syslog(LOG_ERR, "spi: Failed to perform dev transfer");
|
||||
return -1;
|
||||
}
|
||||
return recv;
|
||||
}
|
||||
|
||||
uint8_t*
|
||||
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
|
||||
mraa_result_t
|
||||
mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
|
||||
{
|
||||
struct spi_ioc_transfer msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
uint8_t* recv = malloc(sizeof(uint8_t) * length);
|
||||
|
||||
msg.tx_buf = (unsigned long) data;
|
||||
msg.rx_buf = (unsigned long) recv;
|
||||
msg.rx_buf = (unsigned long) rxbuf;
|
||||
msg.speed_hz = dev->clock;
|
||||
msg.bits_per_word = dev->bpw;
|
||||
msg.delay_usecs = 0;
|
||||
msg.len = length;
|
||||
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
||||
syslog(LOG_ERR, "Failed to perform dev transfer");
|
||||
syslog(LOG_ERR, "spi: Failed to perform dev transfer");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t*
|
||||
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
|
||||
{
|
||||
uint8_t* recv = malloc(sizeof(uint8_t) * length);
|
||||
|
||||
if (mraa_spi_transfer_buf(dev, data, recv, length) != MRAA_SUCCESS) {
|
||||
free(recv);
|
||||
return NULL;
|
||||
}
|
||||
return recv;
|
||||
|
@@ -30,25 +30,28 @@
|
||||
#include "uart.h"
|
||||
#include "mraa_internal.h"
|
||||
|
||||
/**
|
||||
* A structure representing a UART device
|
||||
*/
|
||||
struct _uart {
|
||||
/*@{*/
|
||||
int index; /**< the uart index, as known to the os. */
|
||||
/*@}*/
|
||||
};
|
||||
|
||||
mraa_uart_context
|
||||
mraa_uart_init(int index)
|
||||
{
|
||||
if ( mraa_setup_uart(index) != MRAA_SUCCESS)
|
||||
if (advance_func->uart_init_pre != NULL) {
|
||||
if (advance_func->uart_init_pre(index) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_setup_uart(index) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
mraa_uart_context dev = (mraa_uart_context) malloc(sizeof(struct _uart));
|
||||
memset(dev, 0, sizeof(struct _uart));
|
||||
|
||||
dev->index = index;
|
||||
if (advance_func->uart_init_post != NULL) {
|
||||
mraa_result_t ret = advance_func->uart_init_post(dev);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
Reference in New Issue
Block a user