Private
Public Access
2
0

clang-format: run clang-format on C/C++ code

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-03-23 14:39:12 +00:00
parent 2174ee1673
commit ffcf3d7d07
46 changed files with 1630 additions and 1455 deletions

50
.clang-format Normal file
View File

@@ -0,0 +1,50 @@
AccessModifierOffset: -2
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakAfterDefinitionReturnType: true
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 0
Cpp11BracedListStyle: false
DerivePointerBinding: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 100
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 20
PointerBindsToType: true
PointerAlignment: Left
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: true
SpacesInContainerLiterals: false
SpacesInParentheses: false
Standard: Cpp11
TabWidth: 4
UseTab: Never

View File

@@ -27,7 +27,8 @@
#include <stdexcept> #include <stdexcept>
#include "aio.h" #include "aio.h"
namespace mraa { namespace mraa
{
/** /**
* @brief API to Analog IO * @brief API to Analog IO
@@ -36,7 +37,8 @@ namespace mraa {
* *
* @snippet examples/c++/AioA0.cpp Interesting * @snippet examples/c++/AioA0.cpp Interesting
*/ */
class Aio { class Aio
{
public: public:
/** /**
* Aio Constructor, takes a pin number which will map directly to the * Aio Constructor, takes a pin number which will map directly to the
@@ -44,7 +46,8 @@ class Aio {
* *
* @param pin channel number to read ADC inputs * @param pin channel number to read ADC inputs
*/ */
Aio(unsigned int pin) { Aio(unsigned int pin)
{
m_aio = mraa_aio_init(pin); m_aio = mraa_aio_init(pin);
if (m_aio == NULL) { if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?"); throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
@@ -53,7 +56,8 @@ class Aio {
/** /**
* Aio destructor * Aio destructor
*/ */
~Aio() { ~Aio()
{
mraa_aio_close(m_aio); mraa_aio_close(m_aio);
} }
/** /**
@@ -62,7 +66,9 @@ class Aio {
* *
* @returns The current input voltage. By default, a 10bit value * @returns The current input voltage. By default, a 10bit value
*/ */
int read() { int
read()
{
return mraa_aio_read(m_aio); return mraa_aio_read(m_aio);
} }
/** /**
@@ -70,7 +76,9 @@ class Aio {
* *
* @returns The current input voltage as a normalized float (0.0f-1.0f) * @returns The current input voltage as a normalized float (0.0f-1.0f)
*/ */
float readFloat() { float
readFloat()
{
return mraa_aio_read_float(m_aio); return mraa_aio_read_float(m_aio);
} }
/** /**
@@ -79,7 +87,9 @@ class Aio {
* @param bits the bits the return from read should be i.e 10 * @param bits the bits the return from read should be i.e 10
* @return mraa result type * @return mraa result type
*/ */
mraa_result_t setBit(int bits) { mraa_result_t
setBit(int bits)
{
return mraa_aio_set_bit(m_aio, bits); return mraa_aio_set_bit(m_aio, bits);
} }
/** /**
@@ -87,12 +97,13 @@ class Aio {
* *
* @return bit value mraa is set return from the read function * @return bit value mraa is set return from the read function
*/ */
int getBit() { int
getBit()
{
return mraa_aio_get_bit(m_aio); return mraa_aio_get_bit(m_aio);
} }
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
}; };
} }

View File

@@ -30,7 +30,8 @@
/** /**
* @namespace mraa namespace * @namespace mraa namespace
*/ */
namespace mraa { namespace mraa
{
/** /**
* @file * @file
@@ -50,7 +51,8 @@ namespace mraa {
* *
* @return Result of operation * @return Result of operation
*/ */
inline mraa_result_t init() inline mraa_result_t
init()
{ {
return mraa_init(); return mraa_init();
} }
@@ -60,7 +62,8 @@ inline mraa_result_t init()
* *
* @return libmraa version (e.g. v0.4.0-20-gb408207) * @return libmraa version (e.g. v0.4.0-20-gb408207)
*/ */
inline std::string getVersion() inline std::string
getVersion()
{ {
std::string ret = mraa_get_version(); std::string ret = mraa_get_version();
return ret; return ret;
@@ -75,7 +78,8 @@ inline std::string getVersion()
* @param priority Value from typically 0 to 99 * @param priority Value from typically 0 to 99
* @return The priority value set * @return The priority value set
*/ */
inline int setPriority(const unsigned int priority) inline int
setPriority(const unsigned int priority)
{ {
return mraa_set_priority(priority); return mraa_set_priority(priority);
} }
@@ -85,7 +89,8 @@ inline int setPriority(const unsigned int priority)
* *
* @return mraa_platform_t Platform type enum * @return mraa_platform_t Platform type enum
*/ */
inline mraa_platform_t getPlatformType() inline mraa_platform_t
getPlatformType()
{ {
return mraa_get_platform_type(); return mraa_get_platform_type();
} }
@@ -95,7 +100,8 @@ inline mraa_platform_t getPlatformType()
* *
* @param result the result to print * @param result the result to print
*/ */
inline void printError(mraa_result_t result) inline void
printError(mraa_result_t result)
{ {
mraa_result_print(result); mraa_result_print(result);
} }
@@ -107,9 +113,10 @@ inline void printError(mraa_result_t result)
* @param mode the mode to be tested. * @param mode the mode to be tested.
* @return boolean if the mode is supported, 0=false. * @return boolean if the mode is supported, 0=false.
*/ */
inline 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); return (bool) mraa_pin_mode_test(pin, mode);
} }
/** /**
@@ -117,7 +124,8 @@ inline bool pinModeTest(int pin, mraa_pinmodes_t mode)
* *
* @return raw bits being read from kernel module. Zero if no ADC * @return raw bits being read from kernel module. Zero if no ADC
*/ */
inline unsigned int adcRawBits() inline unsigned int
adcRawBits()
{ {
return mraa_adc_raw_bits(); return mraa_adc_raw_bits();
} }
@@ -127,7 +135,8 @@ inline unsigned int adcRawBits()
* *
* @return return actual bit size the adc value should be understood as. * @return return actual bit size the adc value should be understood as.
*/ */
inline unsigned int adcSupportedBits() inline unsigned int
adcSupportedBits()
{ {
return mraa_adc_supported_bits(); return mraa_adc_supported_bits();
} }
@@ -137,7 +146,8 @@ inline unsigned int adcSupportedBits()
* *
* @return platform name * @return platform name
*/ */
inline std::string getPlatformName() inline std::string
getPlatformName()
{ {
std::string ret_val(mraa_get_platform_name()); std::string ret_val(mraa_get_platform_name());
return ret_val; return ret_val;
@@ -148,7 +158,8 @@ inline std::string getPlatformName()
* *
* @return uint of physical pins. * @return uint of physical pins.
*/ */
inline unsigned int getPinCount() inline unsigned int
getPinCount()
{ {
return mraa_get_pin_count(); return mraa_get_pin_count();
} }
@@ -160,7 +171,8 @@ inline unsigned int getPinCount()
* *
* @return char* of pin name * @return char* of pin name
*/ */
inline std::string getPinName(int pin) inline std::string
getPinName(int pin)
{ {
std::string ret_val(mraa_get_pin_name(pin)); std::string ret_val(mraa_get_pin_name(pin));
return ret_val; return ret_val;
@@ -173,9 +185,9 @@ inline std::string getPinName(int pin)
* @param level * @param level
* @return Result of operation * @return Result of operation
*/ */
inline mraa_result_t setLogLevel(int level) inline mraa_result_t
setLogLevel(int level)
{ {
return mraa_set_log_level(level); return mraa_set_log_level(level);
} }
} }

View File

@@ -120,7 +120,7 @@ mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode);
* @param args Arguments passed to the interrupt handler (fptr) * @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, gpio_edge_t edge, void (*fptr)(void *), void * args); mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, gpio_edge_t edge, void (*fptr)(void*), void* args);
/** /**
* Stop the current interupt watcher on this Gpio, and set the Gpio edge mode * Stop the current interupt watcher on this Gpio, and set the Gpio edge mode

View File

@@ -28,12 +28,13 @@
#include <stdexcept> #include <stdexcept>
#if defined(SWIGJAVASCRIPT) #if defined(SWIGJAVASCRIPT)
#if NODE_MODULE_VERSION >= 0x000D #if NODE_MODULE_VERSION >= 0x000D
#include <uv.h> #include <uv.h>
#endif #endif
#endif #endif
namespace mraa { namespace mraa
{
// These enums must match the enums in gpio.h // These enums must match the enums in gpio.h
@@ -74,7 +75,8 @@ typedef enum {
* *
* @snippet Blink-IO.cpp Interesting * @snippet Blink-IO.cpp Interesting
*/ */
class Gpio { class Gpio
{
public: public:
/** /**
* Instanciates a Gpio object * Instanciates a Gpio object
@@ -88,11 +90,11 @@ class Gpio {
* the kernel module. Note that you will not get any muxers set up for * the kernel module. Note that you will not get any muxers set up for
* you so this may not always work as expected. * you so this may not always work as expected.
*/ */
Gpio(int pin, bool owner=true, bool raw=false) { Gpio(int pin, bool owner = true, bool raw = false)
{
if (raw) { if (raw) {
m_gpio = mraa_gpio_init_raw(pin); m_gpio = mraa_gpio_init_raw(pin);
} } else {
else {
m_gpio = mraa_gpio_init(pin); m_gpio = mraa_gpio_init(pin);
} }
@@ -108,7 +110,8 @@ class Gpio {
* Gpio object destructor, this will only unexport the gpio if we where * Gpio object destructor, this will only unexport the gpio if we where
* the owner * the owner
*/ */
~Gpio() { ~Gpio()
{
mraa_gpio_close(m_gpio); mraa_gpio_close(m_gpio);
} }
/** /**
@@ -117,16 +120,22 @@ class Gpio {
* @param mode The edge mode to set * @param mode The edge mode to set
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t edge(Edge mode) { mraa_result_t
edge(Edge mode)
{
return mraa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode); return mraa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode);
} }
#if defined(SWIGPYTHON) #if defined(SWIGPYTHON)
mraa_result_t isr(Edge mode, PyObject *pyfunc, PyObject* args) { mraa_result_t
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, (void (*) (void *)) pyfunc, (void *) args); isr(Edge mode, PyObject* pyfunc, PyObject* args)
{
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, (void (*) (void*)) pyfunc, (void*) args);
} }
#elif defined(SWIGJAVASCRIPT) #elif defined(SWIGJAVASCRIPT)
static void v8isr(uv_work_t* req, int status) { static void
mraa::Gpio *This = (mraa::Gpio *)req->data; v8isr(uv_work_t* req, int status)
{
mraa::Gpio* This = (mraa::Gpio*) req->data;
int argc = 1; int argc = 1;
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) }; v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
#if NODE_MODULE_VERSION >= 0x000D #if NODE_MODULE_VERSION >= 0x000D
@@ -138,18 +147,23 @@ class Gpio {
delete req; delete req;
} }
static void nop(uv_work_t* req) static void
nop(uv_work_t* req)
{ {
// Do nothing. // Do nothing.
} }
static void uvwork(void *ctx) { static void
uvwork(void* ctx)
{
uv_work_t* req = new uv_work_t; uv_work_t* req = new uv_work_t;
req->data = ctx; req->data = ctx;
uv_queue_work(uv_default_loop(), req, nop, v8isr); uv_queue_work(uv_default_loop(), req, nop, v8isr);
} }
mraa_result_t isr(Edge mode, v8::Handle<v8::Function> func) { mraa_result_t
isr(Edge mode, v8::Handle<v8::Function> func)
{
#if NODE_MODULE_VERSION >= 0x000D #if NODE_MODULE_VERSION >= 0x000D
m_v8isr.Reset(v8::Isolate::GetCurrent(), func); m_v8isr.Reset(v8::Isolate::GetCurrent(), func);
#else #else
@@ -167,7 +181,9 @@ class Gpio {
* @param args Arguments passed to the interrupt handler (fptr) * @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t isr(Edge mode, void (*fptr)(void *), void * args) { mraa_result_t
isr(Edge mode, void (*fptr)(void*), void* args)
{
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, fptr, args); return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, fptr, args);
} }
#endif #endif
@@ -177,14 +193,16 @@ class Gpio {
* *
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t isrExit() { mraa_result_t
isrExit()
{
#if defined(SWIGJAVASCRIPT) #if defined(SWIGJAVASCRIPT)
#if NODE_MODULE_VERSION >= 0x000D #if NODE_MODULE_VERSION >= 0x000D
m_v8isr.Reset(); m_v8isr.Reset();
#else #else
m_v8isr.Dispose(); m_v8isr.Dispose();
m_v8isr.Clear(); m_v8isr.Clear();
#endif #endif
#endif #endif
return mraa_gpio_isr_exit(m_gpio); return mraa_gpio_isr_exit(m_gpio);
} }
@@ -194,7 +212,9 @@ class Gpio {
* @param mode The mode to change the gpio into * @param mode The mode to change the gpio into
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t mode(Mode mode) { mraa_result_t
mode(Mode mode)
{
return mraa_gpio_mode(m_gpio, (gpio_mode_t) mode); return mraa_gpio_mode(m_gpio, (gpio_mode_t) mode);
} }
/** /**
@@ -203,7 +223,9 @@ class Gpio {
* @param dir The direction to change the gpio into * @param dir The direction to change the gpio into
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t dir(Dir dir) { mraa_result_t
dir(Dir dir)
{
return mraa_gpio_dir(m_gpio, (gpio_dir_t) dir); return mraa_gpio_dir(m_gpio, (gpio_dir_t) dir);
} }
/** /**
@@ -211,7 +233,9 @@ class Gpio {
* *
* @return Gpio value * @return Gpio value
*/ */
int read() { int
read()
{
return mraa_gpio_read(m_gpio); return mraa_gpio_read(m_gpio);
} }
/** /**
@@ -220,7 +244,9 @@ class Gpio {
* @param value Value to write to Gpio * @param value Value to write to Gpio
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t write(int value) { mraa_result_t
write(int value)
{
return mraa_gpio_write(m_gpio, value); return mraa_gpio_write(m_gpio, value);
} }
/** /**
@@ -229,7 +255,9 @@ class Gpio {
* @param enable true to use mmap * @param enable true to use mmap
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t useMmap(bool enable) { mraa_result_t
useMmap(bool enable)
{
return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable); return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
} }
/** /**
@@ -239,17 +267,19 @@ class Gpio {
* @param raw (optional) get the raw gpio number. * @param raw (optional) get the raw gpio number.
* @return Pin number * @return Pin number
*/ */
int getPin(bool raw = false) { int
getPin(bool raw = false)
{
if (raw) { if (raw) {
return mraa_gpio_get_pin_raw(m_gpio); return mraa_gpio_get_pin_raw(m_gpio);
} }
return mraa_gpio_get_pin(m_gpio); return mraa_gpio_get_pin(m_gpio);
} }
private: private:
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;
#if defined(SWIGJAVASCRIPT) #if defined(SWIGJAVASCRIPT)
v8::Persistent<v8::Function> m_v8isr; v8::Persistent<v8::Function> m_v8isr;
#endif #endif
}; };
} }

View File

@@ -86,7 +86,7 @@ mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode);
* @param length max number of bytes to read * @param length max number of bytes to read
* @return length of the read in bytes or 0 * @return length of the read in bytes or 0
*/ */
int mraa_i2c_read(mraa_i2c_context dev, uint8_t *data, int length); int mraa_i2c_read(mraa_i2c_context dev, uint8_t* data, int length);
/** /**
* Simple read for a single byte from the i2c context, this will always begin * Simple read for a single byte from the i2c context, this will always begin
@@ -135,7 +135,7 @@ int mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* dat
* @param length the number of bytes to transmit * @param length the number of bytes to transmit
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t *data, int length); mraa_result_t mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length);
/** /**
* Write a single byte to an i2c context, always at offset 0x0 * Write a single byte to an i2c context, always at offset 0x0

View File

@@ -27,7 +27,8 @@
#include "i2c.h" #include "i2c.h"
#include <stdexcept> #include <stdexcept>
namespace mraa { namespace mraa
{
/** /**
* @brief API to Inter-Integrated Circuit * @brief API to Inter-Integrated Circuit
@@ -38,7 +39,8 @@ namespace mraa {
* *
* @snippet I2c-compass.cpp Interesting * @snippet I2c-compass.cpp Interesting
*/ */
class I2c { class I2c
{
public: public:
/** /**
* Instantiates an i2c bus. Multiple instances of the same bus can * Instantiates an i2c bus. Multiple instances of the same bus can
@@ -48,11 +50,11 @@ class I2c {
* @param bus The i2c bus to use * @param bus The i2c bus to use
* @param raw Whether to disable pinmapper for your board * @param raw Whether to disable pinmapper for your board
*/ */
I2c(int bus, bool raw=false) { I2c(int bus, bool raw = false)
{
if (raw) { if (raw) {
m_i2c = mraa_i2c_init_raw(bus); m_i2c = mraa_i2c_init_raw(bus);
} } else {
else {
m_i2c = mraa_i2c_init(bus); m_i2c = mraa_i2c_init(bus);
} }
if (m_i2c == NULL) { if (m_i2c == NULL) {
@@ -65,7 +67,8 @@ class I2c {
* be usable by anyone else or communicates this disconnect to any * be usable by anyone else or communicates this disconnect to any
* slaves. * slaves.
*/ */
~I2c() { ~I2c()
{
mraa_i2c_stop(m_i2c); mraa_i2c_stop(m_i2c);
} }
@@ -77,7 +80,9 @@ class I2c {
* @param mode Frequency to set the bus to * @param mode Frequency to set the bus to
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t frequency(mraa_i2c_mode_t mode) { mraa_result_t
frequency(mraa_i2c_mode_t mode)
{
return mraa_i2c_frequency(m_i2c, mode); return mraa_i2c_frequency(m_i2c, mode);
} }
@@ -88,7 +93,9 @@ class I2c {
* @param address Communicate to the i2c slave on this address * @param address Communicate to the i2c slave on this address
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t address(uint8_t address) { mraa_result_t
address(uint8_t address)
{
return mraa_i2c_address(m_i2c, address); return mraa_i2c_address(m_i2c, address);
} }
@@ -97,7 +104,9 @@ class I2c {
* *
* @return char read from the bus * @return char read from the bus
*/ */
uint8_t readByte() { uint8_t
readByte()
{
return (uint8_t) mraa_i2c_read_byte(m_i2c); return (uint8_t) mraa_i2c_read_byte(m_i2c);
} }
@@ -108,7 +117,9 @@ class I2c {
* @param length Size of read in bytes to make * @param length Size of read in bytes to make
* @return length of read, should match length * @return length of read, should match length
*/ */
int read(uint8_t *data, int length) { int
read(uint8_t* data, int length)
{
return mraa_i2c_read(m_i2c, data, length); return mraa_i2c_read(m_i2c, data, length);
} }
@@ -118,7 +129,9 @@ class I2c {
* @param reg Register to read from * @param reg Register to read from
* @return char read from register * @return char read from register
*/ */
uint8_t readReg(uint8_t reg) { uint8_t
readReg(uint8_t reg)
{
return mraa_i2c_read_byte_data(m_i2c, reg); return mraa_i2c_read_byte_data(m_i2c, reg);
} }
@@ -128,7 +141,9 @@ class I2c {
* @param reg Register to read from * @param reg Register to read from
* @return char read from register * @return char read from register
*/ */
uint16_t readWordReg(uint8_t reg) { uint16_t
readWordReg(uint8_t reg)
{
return mraa_i2c_read_word_data(m_i2c, reg); return mraa_i2c_read_word_data(m_i2c, reg);
} }
@@ -141,7 +156,9 @@ class I2c {
* @param length max number of bytes to read * @param length max number of bytes to read
* @return length passed to the function or 0 * @return length passed to the function or 0
*/ */
int readBytesReg(uint8_t reg, uint8_t* data, int length) { int
readBytesReg(uint8_t reg, uint8_t* data, int length)
{
return mraa_i2c_read_bytes_data(m_i2c, reg, data, length); return mraa_i2c_read_bytes_data(m_i2c, reg, data, length);
} }
@@ -151,7 +168,9 @@ class I2c {
* @param data The byte to send on the bus * @param data The byte to send on the bus
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t writeByte(uint8_t data) { mraa_result_t
writeByte(uint8_t data)
{
return mraa_i2c_write_byte(m_i2c, data); return mraa_i2c_write_byte(m_i2c, data);
} }
@@ -163,7 +182,9 @@ class I2c {
* @param length Size of buffer to send * @param length Size of buffer to send
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t write(const uint8_t* data, int length) { mraa_result_t
write(const uint8_t* data, int length)
{
return mraa_i2c_write(m_i2c, data, length); return mraa_i2c_write(m_i2c, data, length);
} }
@@ -174,7 +195,9 @@ class I2c {
* @param data Value to write to register * @param data Value to write to register
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t writeReg(uint8_t reg, uint8_t data) { mraa_result_t
writeReg(uint8_t reg, uint8_t data)
{
return mraa_i2c_write_byte_data(m_i2c, data, reg); return mraa_i2c_write_byte_data(m_i2c, data, reg);
} }
@@ -185,11 +208,13 @@ class I2c {
* @param data Value to write to register * @param data Value to write to register
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t writeWordReg(uint8_t reg, uint16_t data) { mraa_result_t
writeWordReg(uint8_t reg, uint16_t data)
{
return mraa_i2c_write_word_data(m_i2c, data, reg); return mraa_i2c_write_word_data(m_i2c, data, reg);
} }
private: private:
mraa_i2c_context m_i2c; mraa_i2c_context m_i2c;
}; };
} }

View File

@@ -27,7 +27,8 @@
#include "pwm.h" #include "pwm.h"
#include <stdexcept> #include <stdexcept>
namespace mraa { namespace mraa
{
/** /**
* @brief API to Pulse Width Modulation * @brief API to Pulse Width Modulation
@@ -36,7 +37,8 @@ namespace mraa {
* *
* @snippet Pwm3-cycle.cpp Interesting * @snippet Pwm3-cycle.cpp Interesting
*/ */
class Pwm { class Pwm
{
public: public:
/** /**
* instanciates a PWM object on a pin * instanciates a PWM object on a pin
@@ -47,11 +49,11 @@ class Pwm {
* unexport the pin from sysfs, default behaviour is you are the owner * unexport the pin from sysfs, default behaviour is you are the owner
* if the pinmapper exported it * if the pinmapper exported it
*/ */
Pwm(int pin, bool owner=true, int chipid=-1) { Pwm(int pin, bool owner = true, int chipid = -1)
{
if (chipid == -1) { if (chipid == -1) {
m_pwm = mraa_pwm_init(pin); m_pwm = mraa_pwm_init(pin);
} } else {
else {
m_pwm = mraa_pwm_init_raw(chipid, pin); m_pwm = mraa_pwm_init_raw(chipid, pin);
} }
@@ -66,7 +68,8 @@ class Pwm {
/** /**
* Pwm destructor * Pwm destructor
*/ */
~Pwm() { ~Pwm()
{
mraa_pwm_close(m_pwm); mraa_pwm_close(m_pwm);
} }
/** /**
@@ -78,7 +81,9 @@ class Pwm {
* 1.0f * 1.0f
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t write(float percentage) { mraa_result_t
write(float percentage)
{
return mraa_pwm_write(m_pwm, percentage); return mraa_pwm_write(m_pwm, percentage);
} }
/** /**
@@ -89,7 +94,9 @@ class Pwm {
* 1.0f Values above or below this range will be set at either 0.0f or * 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f * 1.0f
*/ */
float read() { float
read()
{
return mraa_pwm_read(m_pwm); return mraa_pwm_read(m_pwm);
} }
/** /**
@@ -98,7 +105,9 @@ class Pwm {
* @param period Period represented as a float in seconds * @param period Period represented as a float in seconds
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t period(float period) { mraa_result_t
period(float period)
{
return mraa_pwm_period(m_pwm, period); return mraa_pwm_period(m_pwm, period);
} }
/** /**
@@ -107,7 +116,9 @@ class Pwm {
* @param ms milliseconds for period * @param ms milliseconds for period
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t period_ms(int ms) { mraa_result_t
period_ms(int ms)
{
return mraa_pwm_period_ms(m_pwm, ms); return mraa_pwm_period_ms(m_pwm, ms);
} }
/** /**
@@ -116,7 +127,9 @@ class Pwm {
* @param us microseconds as period * @param us microseconds as period
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t period_us(int us) { mraa_result_t
period_us(int us)
{
return mraa_pwm_period_us(m_pwm, us); return mraa_pwm_period_us(m_pwm, us);
} }
/** /**
@@ -125,7 +138,9 @@ class Pwm {
* @param seconds The duration of a pulse * @param seconds The duration of a pulse
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t pulsewidth(float seconds) { mraa_result_t
pulsewidth(float seconds)
{
return mraa_pwm_pulsewidth(m_pwm, seconds); return mraa_pwm_pulsewidth(m_pwm, seconds);
} }
/** /**
@@ -134,7 +149,9 @@ class Pwm {
* @param ms milliseconds for pulsewidth * @param ms milliseconds for pulsewidth
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t pulsewidth_ms(int ms) { mraa_result_t
pulsewidth_ms(int ms)
{
return mraa_pwm_pulsewidth_ms(m_pwm, ms); return mraa_pwm_pulsewidth_ms(m_pwm, ms);
} }
/** /**
@@ -143,7 +160,9 @@ class Pwm {
* @param us microseconds for pulsewidth * @param us microseconds for pulsewidth
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t pulsewidth_us(int us) { mraa_result_t
pulsewidth_us(int us)
{
return mraa_pwm_pulsewidth_us(m_pwm, us); return mraa_pwm_pulsewidth_us(m_pwm, us);
} }
/** /**
@@ -153,7 +172,9 @@ class Pwm {
* @param enable enable status of pin * @param enable enable status of pin
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t enable(bool enable) { mraa_result_t
enable(bool enable)
{
if (enable) if (enable)
return mraa_pwm_enable(m_pwm, 1); return mraa_pwm_enable(m_pwm, 1);
else else
@@ -166,7 +187,9 @@ class Pwm {
* @param duty represnted in ms as float. * @param duty represnted in ms as float.
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t config_ms(int period, float duty) { mraa_result_t
config_ms(int period, float duty)
{
return mraa_pwm_config_ms(m_pwm, period, duty); return mraa_pwm_config_ms(m_pwm, period, duty);
} }
/** /**
@@ -176,12 +199,13 @@ class Pwm {
* @param duty percentage i.e. 50% = 0.5f * @param duty percentage i.e. 50% = 0.5f
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t config_percent(int period, float duty) { mraa_result_t
config_percent(int period, float duty)
{
return mraa_pwm_config_percent(m_pwm, period, duty); return mraa_pwm_config_percent(m_pwm, period, duty);
} }
private: private:
mraa_pwm_context m_pwm; mraa_pwm_context m_pwm;
}; };
} }

View File

@@ -51,10 +51,14 @@ extern "C" {
* MRAA SPI Modes * MRAA SPI Modes
*/ */
typedef enum { typedef enum {
MRAA_SPI_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge */ MRAA_SPI_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge,
MRAA_SPI_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge */ output data (change) on falling edge */
MRAA_SPI_MODE2 = 2, /**< CPOL = 1, CPHA = 0, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge */ MRAA_SPI_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge,
MRAA_SPI_MODE3 = 3, /**< CPOL = 1, CPHA = 1, Clock idle low, data is clocked in on rising, edge output data (change) on falling edge */ output data (change) on rising edge */
MRAA_SPI_MODE2 = 2, /**< CPOL = 1, CPHA = 0, Clock idle low, data is clocked in on falling edge,
output data (change) on rising edge */
MRAA_SPI_MODE3 = 3, /**< CPOL = 1, CPHA = 1, Clock idle low, data is clocked in on rising, edge
output data (change) on falling edge */
} mraa_spi_mode_t; } mraa_spi_mode_t;
/** /**

View File

@@ -27,34 +27,41 @@
#include "spi.h" #include "spi.h"
#include <stdexcept> #include <stdexcept>
namespace mraa { namespace mraa
{
/** /**
* MRAA SPI Modes * MRAA SPI Modes
*/ */
typedef enum { typedef enum {
SPI_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge */ SPI_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge,
SPI_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge */ output data (change) on falling edge */
SPI_MODE2 = 2, /**< CPOL = 1, CPHA = 0, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge */ SPI_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge,
SPI_MODE3 = 3, /**< CPOL = 1, CPHA = 1, Clock idle low, data is clocked in on rising, edge output data (change) on falling edge */ output data (change) on rising edge */
SPI_MODE2 = 2, /**< CPOL = 1, CPHA = 0, Clock idle low, data is clocked in on falling edge,
output data (change) on rising edge */
SPI_MODE3 = 3, /**< CPOL = 1, CPHA = 1, Clock idle low, data is clocked in on rising, edge
output data (change) on falling edge */
} Spi_Mode; } Spi_Mode;
/** /**
* @brief API to Serial Peripheral Interface * @brief API to Serial Peripheral Interface
* *
* This file defines the SPI interface for libmraa * This file defines the SPI interface for libmraa
* *
* @snippet Spi-pot.cpp Interesting * @snippet Spi-pot.cpp Interesting
*/ */
class Spi { class Spi
{
public: public:
/** /**
* Initialise SPI object using the board mapping to set muxes * Initialise SPI object using the board mapping to set muxes
* *
* @param bus to use, as listed in the platform definition, normally 0 * @param bus to use, as listed in the platform definition, normally 0
*/ */
Spi(int bus) { Spi(int bus)
{
m_spi = mraa_spi_init(bus); m_spi = mraa_spi_init(bus);
if (m_spi == NULL) { if (m_spi == NULL) {
@@ -65,7 +72,8 @@ class Spi {
/** /**
* Closes spi bus * Closes spi bus
*/ */
~Spi() { ~Spi()
{
mraa_spi_stop(m_spi); mraa_spi_stop(m_spi);
} }
@@ -75,7 +83,9 @@ class Spi {
* @param mode the mode. See Linux spidev doc * @param mode the mode. See Linux spidev doc
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t mode(Spi_Mode mode) { mraa_result_t
mode(Spi_Mode mode)
{
return mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode); return mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode);
} }
@@ -85,7 +95,9 @@ class Spi {
* @param hz the frequency to set in hz * @param hz the frequency to set in hz
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t frequency(int hz) { mraa_result_t
frequency(int hz)
{
return mraa_spi_frequency(m_spi, hz); return mraa_spi_frequency(m_spi, hz);
} }
@@ -95,7 +107,9 @@ class Spi {
* @param data the byte to send * @param data the byte to send
* @return data received on the miso line or -1 in case of error * @return data received on the miso line or -1 in case of error
*/ */
int writeByte(uint8_t data) { int
writeByte(uint8_t data)
{
return mraa_spi_write(m_spi, (uint8_t) data); return mraa_spi_write(m_spi, (uint8_t) data);
} }
@@ -105,7 +119,9 @@ class Spi {
* @param data the byte to send * @param data the byte to send
* @return data received on the miso line * @return data received on the miso line
*/ */
uint16_t write_word(uint16_t data) { uint16_t
write_word(uint16_t data)
{
return mraa_spi_write_word(m_spi, (uint16_t) data); return mraa_spi_write_word(m_spi, (uint16_t) data);
} }
@@ -118,7 +134,9 @@ class Spi {
* @param length size of buffer to send * @param length size of buffer to send
* @return uint8_t* data received on the miso line. Same length as passed in * @return uint8_t* data received on the miso line. Same length as passed in
*/ */
uint8_t* write(uint8_t* txBuf, int length) { uint8_t*
write(uint8_t* txBuf, int length)
{
return mraa_spi_write_buf(m_spi, txBuf, length); return mraa_spi_write_buf(m_spi, txBuf, length);
} }
@@ -131,7 +149,9 @@ class Spi {
* @param length size of buffer (in bytes) to send * @param length size of buffer (in bytes) to send
* @return uint8_t* data received on the miso line. Same length as passed in * @return uint8_t* data received on the miso line. Same length as passed in
*/ */
uint16_t* write_word(uint16_t* txBuf, int length) { uint16_t*
write_word(uint16_t* txBuf, int length)
{
return mraa_spi_write_buf_word(m_spi, txBuf, length); return mraa_spi_write_buf_word(m_spi, txBuf, length);
} }
@@ -145,7 +165,9 @@ class Spi {
* @param length size of buffer to send * @param length size of buffer to send
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t transfer(uint8_t* txBuf, uint8_t* rxBuf, int length) { mraa_result_t
transfer(uint8_t* txBuf, uint8_t* rxBuf, int length)
{
return mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length); return mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length);
} }
@@ -158,7 +180,9 @@ class Spi {
* @param length size of buffer to send * @param length size of buffer to send
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t transfer_word(uint16_t* txBuf, uint16_t* rxBuf, int length) { mraa_result_t
transfer_word(uint16_t* txBuf, uint16_t* rxBuf, int length)
{
return mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length); return mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length);
} }
#endif #endif
@@ -169,7 +193,9 @@ class Spi {
* @param lsb Use least significant bit transmission - 0 for msbi * @param lsb Use least significant bit transmission - 0 for msbi
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t lsbmode(bool lsb) { mraa_result_t
lsbmode(bool lsb)
{
return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb); return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
} }
@@ -179,7 +205,9 @@ class Spi {
* @param bits bits per word * @param bits bits per word
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t bitPerWord(unsigned int bits) { mraa_result_t
bitPerWord(unsigned int bits)
{
return mraa_spi_bit_per_word(m_spi, bits); return mraa_spi_bit_per_word(m_spi, bits);
} }

View File

@@ -44,7 +44,8 @@ typedef enum {
MRAA_INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */ MRAA_INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
MRAA_RASPBERRY_PI = 5, /**< The different Raspberry PI Models -like A,B,A+,B+ */ MRAA_RASPBERRY_PI = 5, /**< The different Raspberry PI Models -like A,B,A+,B+ */
MRAA_UNKNOWN_PLATFORM = 99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */ MRAA_UNKNOWN_PLATFORM =
99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
} mraa_platform_t; } mraa_platform_t;
/** /**
@@ -160,12 +161,12 @@ typedef enum {
MRAA_RASPBERRY_WIRING_PIN14 = 23, MRAA_RASPBERRY_WIRING_PIN14 = 23,
MRAA_RASPBERRY_WIRING_PIN10 = 24, MRAA_RASPBERRY_WIRING_PIN10 = 24,
MRAA_RASPBERRY_WIRING_PIN11 = 26, MRAA_RASPBERRY_WIRING_PIN11 = 26,
MRAA_RASPBERRY_WIRING_PIN17 = 29, //RPi B V2 MRAA_RASPBERRY_WIRING_PIN17 = 29, // RPi B V2
MRAA_RASPBERRY_WIRING_PIN21 = 29, MRAA_RASPBERRY_WIRING_PIN21 = 29,
MRAA_RASPBERRY_WIRING_PIN18 = 30, //RPi B V2 MRAA_RASPBERRY_WIRING_PIN18 = 30, // RPi B V2
MRAA_RASPBERRY_WIRING_PIN19 = 31, //RPI B V2 MRAA_RASPBERRY_WIRING_PIN19 = 31, // RPI B V2
MRAA_RASPBERRY_WIRING_PIN22 = 31, MRAA_RASPBERRY_WIRING_PIN22 = 31,
MRAA_RASPBERRY_WIRING_PIN20 = 32, //RPi B V2 MRAA_RASPBERRY_WIRING_PIN20 = 32, // RPi B V2
MRAA_RASPBERRY_WIRING_PIN26 = 32, MRAA_RASPBERRY_WIRING_PIN26 = 32,
MRAA_RASPBERRY_WIRING_PIN23 = 33, MRAA_RASPBERRY_WIRING_PIN23 = 33,
MRAA_RASPBERRY_WIRING_PIN24 = 35, MRAA_RASPBERRY_WIRING_PIN24 = 35,

View File

@@ -27,14 +27,16 @@
#include "uart.h" #include "uart.h"
#include <stdexcept> #include <stdexcept>
namespace mraa { namespace mraa
{
/** /**
* @brief API to UART (enabling only) * @brief API to UART (enabling only)
* *
* This file defines the UART interface for libmraa * This file defines the UART interface for libmraa
*/ */
class Uart { class Uart
{
public: public:
/** /**
* Uart Constructor, takes a pin number which will map directly to the * Uart Constructor, takes a pin number which will map directly to the
@@ -42,7 +44,8 @@ class Uart {
* *
* @param uart the index of the uart set to use * @param uart the index of the uart set to use
*/ */
Uart(int uart) { Uart(int uart)
{
m_uart = mraa_uart_init(uart); m_uart = mraa_uart_init(uart);
if (m_uart == NULL) { if (m_uart == NULL) {
@@ -52,7 +55,8 @@ class Uart {
/** /**
* Uart destructor * Uart destructor
*/ */
~Uart() { ~Uart()
{
return; return;
} }
@@ -62,12 +66,14 @@ class Uart {
* *
* @return char pointer of device path * @return char pointer of device path
*/ */
std::string getDevicePath() { std::string
getDevicePath()
{
std::string ret_val(mraa_uart_get_dev_path(m_uart)); std::string ret_val(mraa_uart_get_dev_path(m_uart));
return ret_val; return ret_val;
} }
private: private:
mraa_uart_context m_uart; mraa_uart_context m_uart;
}; };
} }

View File

@@ -23,7 +23,8 @@ Basic rules
- Try not to break master. In any commit. - Try not to break master. In any commit.
- Try to split commits up logically, you will be asked to rebase them if they - Try to split commits up logically, you will be asked to rebase them if they
are not. are not.
- Try to stick to the established coding style regardless of your personal feeling for it! - Try to stick to the established coding style regardless of your personal
feeling for it! Use clang-format (3.6+ required)
Code signing Code signing
------------ ------------

View File

@@ -26,7 +26,8 @@
//! [Interesting] //! [Interesting]
#include "mraa/aio.h" #include "mraa/aio.h"
int main () int
main()
{ {
mraa_aio_context adc_a0; mraa_aio_context adc_a0;
uint16_t adc_value = 0; uint16_t adc_value = 0;
@@ -37,7 +38,7 @@ int main ()
return 1; return 1;
} }
for(;;) { for (;;) {
adc_value = mraa_aio_read(adc_a0); adc_value = mraa_aio_read(adc_a0);
adc_value_float = mraa_aio_read_float(adc_a0); adc_value_float = mraa_aio_read_float(adc_a0);
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value); fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);

View File

@@ -45,7 +45,7 @@ sig_handler(int signo)
} }
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_result_t r = MRAA_SUCCESS; mraa_result_t r = MRAA_SUCCESS;
iopin = DEFAULT_IOPIN; iopin = DEFAULT_IOPIN;
@@ -57,8 +57,7 @@ main(int argc, char **argv)
} }
mraa_init(); mraa_init();
fprintf(stdout, "MRAA Version: %s\nStarting Blinking on IO%d\n", fprintf(stdout, "MRAA Version: %s\nStarting Blinking on IO%d\n", mraa_get_version(), iopin);
mraa_get_version(), iopin);
mraa_gpio_context gpio; mraa_gpio_context gpio;
gpio = mraa_gpio_init(iopin); gpio = mraa_gpio_init(iopin);

View File

@@ -29,7 +29,7 @@
#include "mraa/gpio.h" #include "mraa/gpio.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_platform_t platform = mraa_get_platform_type(); mraa_platform_t platform = mraa_get_platform_type();
mraa_gpio_context gpio, gpio_in = NULL; mraa_gpio_context gpio, gpio_in = NULL;
@@ -50,8 +50,7 @@ main(int argc, char **argv)
gpio = mraa_gpio_init(13); gpio = mraa_gpio_init(13);
} }
fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);
mraa_get_version(), board_name);
if (gpio == NULL) { if (gpio == NULL) {

View File

@@ -25,7 +25,8 @@
//! [Interesting] //! [Interesting]
#include "mraa.hpp" #include "mraa.hpp"
int main () int
main()
{ {
uint16_t adc_value; uint16_t adc_value;
float adc_value_float; float adc_value_float;
@@ -36,7 +37,7 @@ int main ()
return MRAA_ERROR_UNSPECIFIED; return MRAA_ERROR_UNSPECIFIED;
} }
for(;;) { for (;;) {
adc_value = a0->read(); adc_value = a0->read();
adc_value_float = a0->readFloat(); adc_value_float = a0->readFloat();
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value); fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);

View File

@@ -43,7 +43,8 @@ sig_handler(int signo)
running = -1; running = -1;
} }
} }
int main (int argc, char **argv) int
main(int argc, char** argv)
{ {
if (argc < 2) { if (argc < 2) {
printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN); printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
@@ -54,7 +55,7 @@ int main (int argc, char **argv)
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
mraa::Gpio* gpio = new mraa::Gpio(iopin); mraa::Gpio* gpio = new mraa::Gpio(iopin);
if (gpio == NULL) { if (gpio == NULL) {
return MRAA_ERROR_UNSPECIFIED; return MRAA_ERROR_UNSPECIFIED;
@@ -73,5 +74,5 @@ int main (int argc, char **argv)
} }
delete gpio; delete gpio;
return response; return response;
//! [Interesting] //! [Interesting]
} }

View File

@@ -32,14 +32,14 @@
#define MAX_BUFFER_LENGTH 6 #define MAX_BUFFER_LENGTH 6
#define HMC5883L_I2C_ADDR 0x1E #define HMC5883L_I2C_ADDR 0x1E
//configuration registers // configuration registers
#define HMC5883L_CONF_REG_A 0x00 #define HMC5883L_CONF_REG_A 0x00
#define HMC5883L_CONF_REG_B 0x01 #define HMC5883L_CONF_REG_B 0x01
//mode register // mode register
#define HMC5883L_MODE_REG 0x02 #define HMC5883L_MODE_REG 0x02
//data register // data register
#define HMC5883L_X_MSB_REG 0 #define HMC5883L_X_MSB_REG 0
#define HMC5883L_X_LSB_REG 1 #define HMC5883L_X_LSB_REG 1
#define HMC5883L_Z_MSB_REG 2 #define HMC5883L_Z_MSB_REG 2
@@ -48,10 +48,10 @@
#define HMC5883L_Y_LSB_REG 5 #define HMC5883L_Y_LSB_REG 5
#define DATA_REG_SIZE 6 #define DATA_REG_SIZE 6
//status register // status register
#define HMC5883L_STATUS_REG 0x09 #define HMC5883L_STATUS_REG 0x09
//ID registers // ID registers
#define HMC5883L_ID_A_REG 0x0A #define HMC5883L_ID_A_REG 0x0A
#define HMC5883L_ID_B_REG 0x0B #define HMC5883L_ID_B_REG 0x0B
#define HMC5883L_ID_C_REG 0x0C #define HMC5883L_ID_C_REG 0x0C
@@ -59,7 +59,7 @@
#define HMC5883L_CONT_MODE 0x00 #define HMC5883L_CONT_MODE 0x00
#define HMC5883L_DATA_REG 0x03 #define HMC5883L_DATA_REG 0x03
//scales // scales
#define GA_0_88_REG 0x00 << 5 #define GA_0_88_REG 0x00 << 5
#define GA_1_3_REG 0x01 << 5 #define GA_1_3_REG 0x01 << 5
#define GA_1_9_REG 0x02 << 5 #define GA_1_9_REG 0x02 << 5
@@ -69,7 +69,7 @@
#define GA_5_6_REG 0x06 << 5 #define GA_5_6_REG 0x06 << 5
#define GA_8_1_REG 0x07 << 5 #define GA_8_1_REG 0x07 << 5
//digital resolutions // digital resolutions
#define SCALE_0_73_MG 0.73 #define SCALE_0_73_MG 0.73
#define SCALE_0_92_MG 0.92 #define SCALE_0_92_MG 0.92
#define SCALE_1_22_MG 1.22 #define SCALE_1_22_MG 1.22
@@ -91,13 +91,14 @@ sig_handler(int signo)
} }
} }
int main () int
main()
{ {
float direction = 0; float direction = 0;
int16_t x = 0, y = 0, z = 0; int16_t x = 0, y = 0, z = 0;
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH]; uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
//! [Interesting] //! [Interesting]
mraa::I2c* i2c; mraa::I2c* i2c;
i2c = new mraa::I2c(0); i2c = new mraa::I2c(0);
@@ -105,7 +106,7 @@ int main ()
rx_tx_buf[0] = HMC5883L_CONF_REG_B; rx_tx_buf[0] = HMC5883L_CONF_REG_B;
rx_tx_buf[1] = GA_1_3_REG; rx_tx_buf[1] = GA_1_3_REG;
i2c->write(rx_tx_buf, 2); i2c->write(rx_tx_buf, 2);
//! [Interesting] //! [Interesting]
i2c->address(HMC5883L_I2C_ADDR); i2c->address(HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_MODE_REG; rx_tx_buf[0] = HMC5883L_MODE_REG;
@@ -121,19 +122,20 @@ int main ()
i2c->address(HMC5883L_I2C_ADDR); i2c->address(HMC5883L_I2C_ADDR);
i2c->read(rx_tx_buf, DATA_REG_SIZE); i2c->read(rx_tx_buf, DATA_REG_SIZE);
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ; x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8) | rx_tx_buf[HMC5883L_X_LSB_REG];
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ; z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Z_LSB_REG];
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ; y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Y_LSB_REG];
//scale and calculate direction // scale and calculate direction
direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG); direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG);
//check if the signs are reversed // check if the signs are reversed
if (direction < 0) if (direction < 0)
direction += 2 * M_PI; direction += 2 * M_PI;
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG, z * SCALE_0_92_MG) ; printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
printf("Heading : %f\n", direction * 180/M_PI); z * SCALE_0_92_MG);
printf("Heading : %f\n", direction * 180 / M_PI);
sleep(1); sleep(1);
} }
delete i2c; delete i2c;

View File

@@ -38,10 +38,11 @@ sig_handler(int signo)
} }
} }
int main () int
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
mraa::Pwm* pwm; mraa::Pwm* pwm;
pwm = new mraa::Pwm(3); pwm = new mraa::Pwm(3);
@@ -61,7 +62,7 @@ int main ()
} }
} }
delete pwm; delete pwm;
//! [Interesting] //! [Interesting]
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }

View File

@@ -39,26 +39,27 @@ sig_handler(int signo)
} }
} }
int main () int
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
mraa::Spi* spi; mraa::Spi* spi;
spi = new mraa::Spi(0); spi = new mraa::Spi(0);
uint8_t data[] = {0x00, 100}; uint8_t data[] = { 0x00, 100 };
uint8_t rxBuf[2]; uint8_t rxBuf[2];
uint8_t *recv; uint8_t* recv;
while (running == 0) { while (running == 0) {
int i; int i;
for (i = 90; i < 130; i++) { for (i = 90; i < 130; i++) {
data[1] = i; data[1] = i;
recv = spi->write(data, 2); recv = spi->write(data, 2);
printf("Writing -%i",i); printf("Writing -%i", i);
if (recv) { if (recv) {
printf("RECIVED-%i-%i\n",recv[0],recv[1]); printf("RECIVED-%i-%i\n", recv[0], recv[1]);
free(recv); free(recv);
} }
usleep(100000); usleep(100000);
@@ -66,15 +67,14 @@ int main ()
for (i = 130; i > 90; i--) { for (i = 130; i > 90; i--) {
data[1] = i; data[1] = i;
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) { if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
printf("Writing -%i",i); printf("Writing -%i", i);
printf("RECIVED-%i-%i\n",rxBuf[0],rxBuf[1]); printf("RECIVED-%i-%i\n", rxBuf[0], rxBuf[1]);
} }
usleep(100000); usleep(100000);
} }
} }
delete spi; delete spi;
//! [Interesting] //! [Interesting]
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }

View File

@@ -27,10 +27,10 @@
#include "mraa.h" #include "mraa.h"
int int
main () main()
{ {
mraa_init(); mraa_init();
//! [Interesting] //! [Interesting]
mraa_pwm_context pwm; mraa_pwm_context pwm;
pwm = mraa_pwm_init(3); pwm = mraa_pwm_init(3);
if (pwm == NULL) { if (pwm == NULL) {
@@ -50,6 +50,6 @@ main ()
} }
float output = mraa_pwm_read(pwm); float output = mraa_pwm_read(pwm);
} }
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@@ -34,12 +34,14 @@ struct gpio_source {
}; };
void void
print_version() { print_version()
{
fprintf(stdout, "Version %s on %s\n", mraa_get_version(), mraa_get_platform_name()); fprintf(stdout, "Version %s on %s\n", mraa_get_version(), mraa_get_platform_name());
} }
void void
print_help() { print_help()
{
fprintf(stdout, "list List pins\n"); fprintf(stdout, "list List pins\n");
fprintf(stdout, "set pin level Set pin to level (0/1)\n"); fprintf(stdout, "set pin level Set pin to level (0/1)\n");
fprintf(stdout, "setraw pin level Set pin to level (0/1) via mmap (if available)\n"); fprintf(stdout, "setraw pin level Set pin to level (0/1) via mmap (if available)\n");
@@ -50,13 +52,15 @@ print_help() {
} }
void void
print_command_error() { print_command_error()
{
fprintf(stdout, "Invalid command, options are:\n"); fprintf(stdout, "Invalid command, options are:\n");
print_help(); print_help();
} }
void void
list_pins() { list_pins()
{
int pin_count = mraa_get_pin_count(); int pin_count = mraa_get_pin_count();
if (pin_count == 0) { if (pin_count == 0) {
fprintf(stdout, "No Pins\n"); fprintf(stdout, "No Pins\n");
@@ -64,7 +68,7 @@ list_pins() {
} }
int i; int i;
for (i = 0; i < pin_count; ++i) { for (i = 0; i < pin_count; ++i) {
if (strcmp(mraa_get_pin_name(i),"INVALID") != 0) { if (strcmp(mraa_get_pin_name(i), "INVALID") != 0) {
fprintf(stdout, "%02d ", i); fprintf(stdout, "%02d ", i);
fprintf(stdout, "%8s: ", mraa_get_pin_name(i)); fprintf(stdout, "%8s: ", mraa_get_pin_name(i));
if (mraa_pin_mode_test(i, MRAA_PIN_GPIO)) if (mraa_pin_mode_test(i, MRAA_PIN_GPIO))
@@ -85,13 +89,15 @@ list_pins() {
} }
mraa_result_t mraa_result_t
gpio_set(int pin, int level, mraa_boolean_t raw) { gpio_set(int pin, int level, mraa_boolean_t raw)
{
mraa_gpio_context gpio = mraa_gpio_init(pin); mraa_gpio_context gpio = mraa_gpio_init(pin);
if (gpio != NULL) { if (gpio != NULL) {
mraa_gpio_dir(gpio, MRAA_GPIO_OUT); mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
if (raw != 0) { if (raw != 0) {
if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) { if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) {
fprintf(stdout, "mmapped access to gpio not supported, falling back to normal mode\n", pin); fprintf(stdout,
"mmapped access to gpio not supported, falling back to normal mode\n", pin);
} }
} }
mraa_gpio_write(gpio, level); mraa_gpio_write(gpio, level);
@@ -101,13 +107,15 @@ gpio_set(int pin, int level, mraa_boolean_t raw) {
} }
mraa_result_t mraa_result_t
gpio_get(int pin, int *level, mraa_boolean_t raw) { gpio_get(int pin, int* level, mraa_boolean_t raw)
{
mraa_gpio_context gpio = mraa_gpio_init(pin); mraa_gpio_context gpio = mraa_gpio_init(pin);
if (gpio != NULL) { if (gpio != NULL) {
mraa_gpio_dir(gpio, MRAA_GPIO_IN); mraa_gpio_dir(gpio, MRAA_GPIO_IN);
if (raw != 0) { if (raw != 0) {
if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) { if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) {
fprintf(stdout, "mmapped access to gpio not supported, falling back to normal mode\n", pin); fprintf(stdout,
"mmapped access to gpio not supported, falling back to normal mode\n", pin);
} }
} }
*level = mraa_gpio_read(gpio); *level = mraa_gpio_read(gpio);
@@ -117,14 +125,17 @@ gpio_get(int pin, int *level, mraa_boolean_t raw) {
} }
void gpio_isr_handler(void * args) { void
struct gpio_source* gpio_info = (struct gpio_source*)args; gpio_isr_handler(void* args)
{
struct gpio_source* gpio_info = (struct gpio_source*) args;
int level = mraa_gpio_read(gpio_info->context); int level = mraa_gpio_read(gpio_info->context);
fprintf(stdout, "Pin %d = %d\n", gpio_info->pin, level); fprintf(stdout, "Pin %d = %d\n", gpio_info->pin, level);
} }
mraa_result_t mraa_result_t
gpio_isr_start(struct gpio_source* gpio_info) { gpio_isr_start(struct gpio_source* gpio_info)
{
gpio_info->context = mraa_gpio_init(gpio_info->pin); gpio_info->context = mraa_gpio_init(gpio_info->pin);
if (gpio_info->context != NULL) { if (gpio_info->context != NULL) {
mraa_result_t status = mraa_gpio_dir(gpio_info->context, MRAA_GPIO_IN); mraa_result_t status = mraa_gpio_dir(gpio_info->context, MRAA_GPIO_IN);
@@ -139,7 +150,8 @@ gpio_isr_start(struct gpio_source* gpio_info) {
mraa_result_t mraa_result_t
gpio_isr_stop(struct gpio_source* gpio_info) { gpio_isr_stop(struct gpio_source* gpio_info)
{
mraa_gpio_isr_exit(gpio_info->context); mraa_gpio_isr_exit(gpio_info->context);
mraa_gpio_close(gpio_info->context); mraa_gpio_close(gpio_info->context);
return MRAA_SUCCESS; return MRAA_SUCCESS;
@@ -147,7 +159,7 @@ gpio_isr_stop(struct gpio_source* gpio_info) {
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
if (argc == 1) { if (argc == 1) {
print_command_error(); print_command_error();
@@ -176,8 +188,7 @@ main(int argc, char **argv)
mraa_boolean_t rawmode = strcmp(argv[1], "getraw") == 0; mraa_boolean_t rawmode = strcmp(argv[1], "getraw") == 0;
if (gpio_get(pin, &level, rawmode) == MRAA_SUCCESS) { if (gpio_get(pin, &level, rawmode) == MRAA_SUCCESS) {
fprintf(stdout, "Pin %d = %d\n", pin, level); fprintf(stdout, "Pin %d = %d\n", pin, level);
} } else {
else {
fprintf(stdout, "Could not initialize gpio %d\n", pin); fprintf(stdout, "Could not initialize gpio %d\n", pin);
} }
} else { } else {
@@ -191,10 +202,10 @@ main(int argc, char **argv)
if (gpio_isr_start(&gpio_info) == MRAA_SUCCESS) { if (gpio_isr_start(&gpio_info) == MRAA_SUCCESS) {
fprintf(stdout, "Monitoring level changes to pin %d. Press RETURN to exit.\n", pin); fprintf(stdout, "Monitoring level changes to pin %d. Press RETURN to exit.\n", pin);
gpio_isr_handler(&gpio_info); gpio_isr_handler(&gpio_info);
while (getchar() != '\n'); while (getchar() != '\n')
;
gpio_isr_stop(&gpio_info); gpio_isr_stop(&gpio_info);
} } else {
else {
fprintf(stdout, "Failed to register ISR for pin %d\n", pin); fprintf(stdout, "Failed to register ISR for pin %d\n", pin);
} }
} else { } else {

View File

@@ -28,13 +28,12 @@
#include "mraa.h" #include "mraa.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_init(); mraa_init();
fprintf(stdout, "MRAA Version: %s\nStarting Read on IO6\n", fprintf(stdout, "MRAA Version: %s\nStarting Read on IO6\n", mraa_get_version());
mraa_get_version());
//! [Interesting] //! [Interesting]
mraa_gpio_context gpio; mraa_gpio_context gpio;
gpio = mraa_gpio_init(6); gpio = mraa_gpio_init(6);
@@ -47,7 +46,7 @@ main(int argc, char **argv)
} }
mraa_gpio_close(gpio); mraa_gpio_close(gpio);
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@@ -30,7 +30,7 @@
#include "mraa.h" #include "mraa.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_result_t ret = MRAA_SUCCESS; mraa_result_t ret = MRAA_SUCCESS;
mraa_platform_t platform_type = mraa_get_platform_type(); mraa_platform_t platform_type = mraa_get_platform_type();

View File

@@ -29,7 +29,7 @@
#include "mraa.h" #include "mraa.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
char* board_name = mraa_get_platform_name(); char* board_name = mraa_get_platform_name();

View File

@@ -28,14 +28,14 @@
#define MAX_BUFFER_LENGTH 6 #define MAX_BUFFER_LENGTH 6
#define HMC5883L_I2C_ADDR 0x1E #define HMC5883L_I2C_ADDR 0x1E
//configuration registers // configuration registers
#define HMC5883L_CONF_REG_A 0x00 #define HMC5883L_CONF_REG_A 0x00
#define HMC5883L_CONF_REG_B 0x01 #define HMC5883L_CONF_REG_B 0x01
//mode register // mode register
#define HMC5883L_MODE_REG 0x02 #define HMC5883L_MODE_REG 0x02
//data register // data register
#define HMC5883L_X_MSB_REG 0 #define HMC5883L_X_MSB_REG 0
#define HMC5883L_X_LSB_REG 1 #define HMC5883L_X_LSB_REG 1
#define HMC5883L_Z_MSB_REG 2 #define HMC5883L_Z_MSB_REG 2
@@ -44,10 +44,10 @@
#define HMC5883L_Y_LSB_REG 5 #define HMC5883L_Y_LSB_REG 5
#define DATA_REG_SIZE 6 #define DATA_REG_SIZE 6
//status register // status register
#define HMC5883L_STATUS_REG 0x09 #define HMC5883L_STATUS_REG 0x09
//ID registers // ID registers
#define HMC5883L_ID_A_REG 0x0A #define HMC5883L_ID_A_REG 0x0A
#define HMC5883L_ID_B_REG 0x0B #define HMC5883L_ID_B_REG 0x0B
#define HMC5883L_ID_C_REG 0x0C #define HMC5883L_ID_C_REG 0x0C
@@ -55,7 +55,7 @@
#define HMC5883L_CONT_MODE 0x00 #define HMC5883L_CONT_MODE 0x00
#define HMC5883L_DATA_REG 0x03 #define HMC5883L_DATA_REG 0x03
//scales // scales
#define GA_0_88_REG 0x00 << 5 #define GA_0_88_REG 0x00 << 5
#define GA_1_3_REG 0x01 << 5 #define GA_1_3_REG 0x01 << 5
#define GA_1_9_REG 0x02 << 5 #define GA_1_9_REG 0x02 << 5
@@ -65,7 +65,7 @@
#define GA_5_6_REG 0x06 << 5 #define GA_5_6_REG 0x06 << 5
#define GA_8_1_REG 0x07 << 5 #define GA_8_1_REG 0x07 << 5
//digital resolutions // digital resolutions
#define SCALE_0_73_MG 0.73 #define SCALE_0_73_MG 0.73
#define SCALE_0_92_MG 0.92 #define SCALE_0_92_MG 0.92
#define SCALE_1_22_MG 1.22 #define SCALE_1_22_MG 1.22
@@ -76,14 +76,14 @@
#define SCALE_4_35_MG 4.35 #define SCALE_4_35_MG 4.35
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_init(); mraa_init();
float direction = 0; float direction = 0;
int16_t x = 0, y = 0, z = 0; int16_t x = 0, y = 0, z = 0;
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH]; uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
//! [Interesting] //! [Interesting]
mraa_i2c_context i2c; mraa_i2c_context i2c;
i2c = mraa_i2c_init(0); i2c = mraa_i2c_init(0);
@@ -91,14 +91,14 @@ main(int argc, char **argv)
rx_tx_buf[0] = HMC5883L_CONF_REG_B; rx_tx_buf[0] = HMC5883L_CONF_REG_B;
rx_tx_buf[1] = GA_1_3_REG; rx_tx_buf[1] = GA_1_3_REG;
mraa_i2c_write(i2c, rx_tx_buf, 2); mraa_i2c_write(i2c, rx_tx_buf, 2);
//! [Interesting] //! [Interesting]
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR); mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_MODE_REG; rx_tx_buf[0] = HMC5883L_MODE_REG;
rx_tx_buf[1] = HMC5883L_CONT_MODE; rx_tx_buf[1] = HMC5883L_CONT_MODE;
mraa_i2c_write(i2c, rx_tx_buf, 2); mraa_i2c_write(i2c, rx_tx_buf, 2);
for(;;) { for (;;) {
#if 0 #if 0
int i = 0; int i = 0;
//alternative, equivalent method which helps to understand exactly what //alternative, equivalent method which helps to understand exactly what
@@ -118,18 +118,19 @@ main(int argc, char **argv)
// this call behaves very similarly to the Wire receive() call // this call behaves very similarly to the Wire receive() call
mraa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE); 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] ; x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8) | rx_tx_buf[HMC5883L_X_LSB_REG];
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ; z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Z_LSB_REG];
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ; y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Y_LSB_REG];
//scale and calculate direction // scale and calculate direction
direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG); direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG);
//check if the signs are reversed // check if the signs are reversed
if (direction < 0) if (direction < 0)
direction += 2 * M_PI; direction += 2 * M_PI;
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG, z * SCALE_0_92_MG) ; printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
printf("Heading : %f\n", direction * 180/M_PI) ; z * SCALE_0_92_MG);
printf("Heading : %f\n", direction * 180 / M_PI);
} }
} }

View File

@@ -29,11 +29,14 @@
static volatile int counter = 0; static volatile int counter = 0;
static volatile int oldcounter = 0; static volatile int oldcounter = 0;
void interrupt (void * args) { void
interrupt(void* args)
{
++counter; ++counter;
} }
int main () int
main()
{ {
mraa_init(); mraa_init();
mraa_gpio_context x; mraa_gpio_context x;
@@ -49,8 +52,8 @@ int main ()
mraa_gpio_isr(x, edge, &interrupt, NULL); mraa_gpio_isr(x, edge, &interrupt, NULL);
for(;;) { for (;;) {
if(counter != oldcounter) { if (counter != oldcounter) {
fprintf(stdout, "timeout counter == %d\n", counter); fprintf(stdout, "timeout counter == %d\n", counter);
oldcounter = counter; oldcounter = counter;
} }

View File

@@ -28,9 +28,9 @@
#include "mraa.h" #include "mraa.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
//! [Interesting] //! [Interesting]
fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version()); fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version());
mraa_gpio_context gpio; mraa_gpio_context gpio;
gpio = mraa_gpio_init(2); gpio = mraa_gpio_init(2);
@@ -38,10 +38,10 @@ main(int argc, char **argv)
mraa_gpio_use_mmaped(gpio, 1); mraa_gpio_use_mmaped(gpio, 1);
for (;;) { for (;;) {
mraa_gpio_write(gpio , 1); mraa_gpio_write(gpio, 1);
usleep(50000); usleep(50000);
mraa_gpio_write(gpio, 0); mraa_gpio_write(gpio, 0);
usleep(50000); usleep(50000);
} }
//! [Interesting] //! [Interesting]
} }

View File

@@ -28,8 +28,9 @@
#include <stdint.h> #include <stdint.h>
int int
main(int argc, char **argv) { main(int argc, char** argv)
//! [Interesting] {
//! [Interesting]
mraa_spi_context spi; mraa_spi_context spi;
spi = mraa_spi_init(1); spi = mraa_spi_init(1);
if (spi == NULL) { if (spi == NULL) {
@@ -55,19 +56,19 @@ main(int argc, char **argv) {
mraa_spi_write_word(spi, 0x0f00); // Testmode off mraa_spi_write_word(spi, 0x0f00); // Testmode off
// Display Pattern on the display // Display Pattern on the display
uint16_t dataAA55[] = {0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855}; uint16_t dataAA55[] = { 0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855 };
mraa_spi_write_buf_word(spi, dataAA55, 16); mraa_spi_write_buf_word(spi, dataAA55, 16);
sleep(2); sleep(2);
// Display inverted Pattern // Display inverted Pattern
uint16_t data55AA[] = {0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa}; uint16_t data55AA[] = { 0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa };
mraa_spi_write_buf_word(spi, data55AA, 16); mraa_spi_write_buf_word(spi, data55AA, 16);
sleep(2); sleep(2);
// Clear the display // Clear the display
uint16_t data[] = {0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800}; uint16_t data[] = { 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800 };
mraa_spi_write_buf_word(spi, data, 16); mraa_spi_write_buf_word(spi, data, 16);
int i; int i;
@@ -83,5 +84,5 @@ main(int argc, char **argv) {
mraa_spi_stop(spi); mraa_spi_stop(spi);
//! [Interesting] //! [Interesting]
} }

View File

@@ -27,32 +27,32 @@
#include <stdint.h> #include <stdint.h>
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_init(); mraa_init();
//! [Interesting] //! [Interesting]
mraa_spi_context spi; mraa_spi_context spi;
spi = mraa_spi_init(0); spi = mraa_spi_init(0);
unsigned int response = 0; unsigned int response = 0;
printf("Hello, SPI initialised\n"); printf("Hello, SPI initialised\n");
uint8_t data[] = {0x00, 100}; uint8_t data[] = { 0x00, 100 };
uint8_t *recv; uint8_t* recv;
while(1) { while (1) {
int i; int i;
for (i = 90; i < 130; i++) { for (i = 90; i < 130; i++) {
data[1] = i; data[1] = i;
recv = mraa_spi_write_buf(spi, data, 2); recv = mraa_spi_write_buf(spi, data, 2);
printf("Writing -%i",i); printf("Writing -%i", i);
printf("RECIVED-%i-%i\n",recv[0],recv[1]); printf("RECIVED-%i-%i\n", recv[0], recv[1]);
usleep(100000); usleep(100000);
} }
for (i = 130; i > 90; i--) { for (i = 130; i > 90; i--) {
data[1] = i; data[1] = i;
recv = mraa_spi_write_buf(spi, data, 2); recv = mraa_spi_write_buf(spi, data, 2);
printf("Writing -%i",i); printf("Writing -%i", i);
printf("RECIVED-%i-%i\n",recv[0],recv[1]); printf("RECIVED-%i-%i\n", recv[0], recv[1]);
usleep(100000); usleep(100000);
} }
} }
//! [Interesting] //! [Interesting]
} }

View File

@@ -27,7 +27,7 @@
#include "mraa.h" #include "mraa.h"
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
mraa_uart_context uart; mraa_uart_context uart;
uart = mraa_uart_init(0); uart = mraa_uart_init(0);

View File

@@ -39,16 +39,14 @@ aio_get_valid_fp(mraa_aio_context dev)
if (advance_func->aio_get_valid_fp != NULL) if (advance_func->aio_get_valid_fp != NULL)
return advance_func->aio_get_valid_fp(dev); return advance_func->aio_get_valid_fp(dev);
char file_path[64]= ""; char file_path[64] = "";
//Open file Analog device input channel raw voltage file for reading. // Open file Analog device input channel raw voltage file for reading.
snprintf(file_path, 64, "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw", snprintf(file_path, 64, "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw", dev->channel);
dev->channel );
dev->adc_in_fp = open(file_path, O_RDONLY); dev->adc_in_fp = open(file_path, O_RDONLY);
if (dev->adc_in_fp == -1) { if (dev->adc_in_fp == -1) {
syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!", syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!", file_path);
file_path);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -86,17 +84,18 @@ mraa_aio_init(unsigned int aio)
} }
} }
//Create ADC device connected to specified channel // Create ADC device connected to specified channel
mraa_aio_context dev = malloc(sizeof(struct _aio)); mraa_aio_context dev = malloc(sizeof(struct _aio));
if (dev == NULL) { if (dev == NULL) {
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel " syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
"%d\n", aio); "%d\n",
aio);
return NULL; return NULL;
} }
dev->channel = plat->pins[pin].aio.pinmap; dev->channel = plat->pins[pin].aio.pinmap;
dev->value_bit = DEFAULT_BITS; dev->value_bit = DEFAULT_BITS;
//Open valid analog input file and get the pointer. // Open valid analog input file and get the pointer.
if (MRAA_SUCCESS != aio_get_valid_fp(dev)) { if (MRAA_SUCCESS != aio_get_valid_fp(dev)) {
free(dev); free(dev);
return NULL; return NULL;
@@ -136,12 +135,11 @@ mraa_aio_read(mraa_aio_context dev)
lseek(dev->adc_in_fp, 0, SEEK_SET); lseek(dev->adc_in_fp, 0, SEEK_SET);
errno = 0; errno = 0;
char *end; char* end;
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10); unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
if (end == &buffer[0]) { if (end == &buffer[0]) {
syslog(LOG_ERR, "aio: Value is not a decimal number"); syslog(LOG_ERR, "aio: Value is not a decimal number");
} } else if (errno != 0) {
else if (errno != 0) {
syslog(LOG_ERR, "aio: Errno was set"); syslog(LOG_ERR, "aio: Errno was set");
} }
@@ -182,7 +180,7 @@ mraa_aio_close(mraa_aio_context dev)
free(dev); free(dev);
} }
return(MRAA_SUCCESS); return (MRAA_SUCCESS);
} }
mraa_result_t mraa_result_t

View File

@@ -34,8 +34,8 @@ mraa_arm_platform()
{ {
mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
size_t len = 100; size_t len = 100;
char *line = malloc(len); char* line = malloc(len);
FILE *fh = fopen("/proc/cpuinfo", "r"); FILE* fh = fopen("/proc/cpuinfo", "r");
if (fh != NULL) { if (fh != NULL) {
while (getline(&line, &len, fh) != -1) { while (getline(&line, &len, fh) != -1) {
if (strncmp(line, "Hardware", 8) == 0) { if (strncmp(line, "Hardware", 8) == 0) {
@@ -51,7 +51,7 @@ mraa_arm_platform()
} }
free(line); free(line);
switch(platform_type) { switch (platform_type) {
case MRAA_RASPBERRY_PI: case MRAA_RASPBERRY_PI:
plat = mraa_raspberry_pi(); plat = mraa_raspberry_pi();
break; break;

View File

@@ -50,27 +50,29 @@
#define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000) #define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000)
#define BCM2836_PERI_BASE 0x3f000000 #define BCM2836_PERI_BASE 0x3f000000
#define BCM2836_GPIO_BASE (BCM2836_PERI_BASE + 0x200000) #define BCM2836_GPIO_BASE (BCM2836_PERI_BASE + 0x200000)
#define BCM2835_BLOCK_SIZE (4*1024) #define BCM2835_BLOCK_SIZE (4 * 1024)
#define BCM2836_BLOCK_SIZE (4*1024) #define BCM2836_BLOCK_SIZE (4 * 1024)
#define BCM283X_GPSET0 0x001c #define BCM283X_GPSET0 0x001c
#define BCM283X_GPCLR0 0x0028 #define BCM283X_GPCLR0 0x0028
#define BCM2835_GPLEV0 0x0034 #define BCM2835_GPLEV0 0x0034
#define MAX_SIZE 64 #define MAX_SIZE 64
//MMAP // MMAP
static uint8_t *mmap_reg = NULL; static uint8_t* mmap_reg = NULL;
static int mmap_fd = 0; static int mmap_fd = 0;
static int mmap_size; static int mmap_size;
static unsigned int mmap_count = 0; static unsigned int mmap_count = 0;
static int platform_detected = 0; static int platform_detected = 0;
mraa_result_t mraa_result_t
mraa_raspberry_pi_spi_init_pre(int index) { mraa_raspberry_pi_spi_init_pre(int index)
{
char devpath[MAX_SIZE]; char devpath[MAX_SIZE];
sprintf(devpath, "/dev/spidev%u.0", plat->spi_bus[index].bus_id); sprintf(devpath, "/dev/spidev%u.0", plat->spi_bus[index].bus_id);
if (!mraa_file_exist(devpath)) { if (!mraa_file_exist(devpath)) {
syslog(LOG_ERR, "spi: Device not initialized"); syslog(LOG_ERR, "spi: Device not initialized");
syslog(LOG_ERR, "spi: If you run a kernel >=3.18 then you will have to add dtparam=spi=on to /boot/config.txt and reboot"); syslog(LOG_ERR, "spi: If you run a kernel >=3.18 then you will have to add dtparam=spi=on "
"to /boot/config.txt and reboot");
syslog(LOG_INFO, "spi: trying modprobe for spi-bcm2708"); syslog(LOG_INFO, "spi: trying modprobe for spi-bcm2708");
system("modprobe spi-bcm2708 >/dev/null 2>&1"); system("modprobe spi-bcm2708 >/dev/null 2>&1");
system("modprobe spi_bcm2708 >/dev/null 2>&1"); system("modprobe spi_bcm2708 >/dev/null 2>&1");
@@ -82,7 +84,8 @@ mraa_raspberry_pi_spi_init_pre(int index) {
} }
mraa_result_t mraa_result_t
mraa_raspberry_pi_i2c_init_pre(unsigned int bus) { mraa_raspberry_pi_i2c_init_pre(unsigned int bus)
{
char devpath[MAX_SIZE]; char devpath[MAX_SIZE];
sprintf(devpath, "/dev/i2c-%u", bus); sprintf(devpath, "/dev/i2c-%u", bus);
if (!mraa_file_exist(devpath)) { if (!mraa_file_exist(devpath)) {
@@ -95,10 +98,11 @@ mraa_raspberry_pi_i2c_init_pre(unsigned int bus) {
if (!mraa_file_exist(devpath)) { if (!mraa_file_exist(devpath)) {
syslog(LOG_ERR, "i2c: Device not initialized"); syslog(LOG_ERR, "i2c: Device not initialized");
if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1) { if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1) {
syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add dtparam=i2c0=on to /boot/config.txt and reboot"); syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add "
} "dtparam=i2c0=on to /boot/config.txt and reboot");
else { } else {
syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add dtparam=i2c1=on to /boot/config.txt and reboot"); syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add "
"dtparam=i2c1=on to /boot/config.txt and reboot");
} }
return MRAA_ERROR_NO_RESOURCES; return MRAA_ERROR_NO_RESOURCES;
} }
@@ -108,14 +112,13 @@ mraa_raspberry_pi_i2c_init_pre(unsigned int bus) {
mraa_result_t mraa_result_t
mraa_raspberry_pi_mmap_write(mraa_gpio_context dev, int value) mraa_raspberry_pi_mmap_write(mraa_gpio_context dev, int value)
{ {
volatile uint32_t *addr; volatile uint32_t* addr;
if (value) { if (value) {
*(volatile uint32_t *) (mmap_reg + BCM283X_GPSET0 + (dev->pin / 32) * 4) = *(volatile uint32_t*) (mmap_reg + BCM283X_GPSET0 + (dev->pin / 32) * 4) =
(uint32_t) (1 << (dev->pin % 32)); (uint32_t)(1 << (dev->pin % 32));
} } else {
else { *(volatile uint32_t*) (mmap_reg + BCM283X_GPCLR0 + (dev->pin / 32) * 4) =
*(volatile uint32_t *) (mmap_reg + BCM283X_GPCLR0 + (dev->pin / 32) * 4) = (uint32_t)(1 << (dev->pin % 32));
(uint32_t) (1 << (dev->pin % 32));
} }
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -139,7 +142,7 @@ int
mraa_raspberry_pi_mmap_read(mraa_gpio_context dev) mraa_raspberry_pi_mmap_read(mraa_gpio_context dev)
{ {
uint32_t value = *(volatile uint32_t*) (mmap_reg + BCM2835_GPLEV0 + (dev->pin / 32) * 4); uint32_t value = *(volatile uint32_t*) (mmap_reg + BCM2835_GPLEV0 + (dev->pin / 32) * 4);
if (value&(uint32_t)(1 << (dev->pin % 32))) { if (value & (uint32_t)(1 << (dev->pin % 32))) {
return 1; return 1;
} }
return 0; return 0;
@@ -172,26 +175,21 @@ mraa_raspberry_pi_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_ERROR_INVALID_PARAMETER; return MRAA_ERROR_INVALID_PARAMETER;
} }
//Might need to make some elements of this thread safe. // Might need to make some elements of this thread safe.
//For example only allow one thread to enter the following block // For example only allow one thread to enter the following block
//to prevent mmap'ing twice. // to prevent mmap'ing twice.
if (mmap_reg == NULL) { if (mmap_reg == NULL) {
if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) { if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
syslog(LOG_ERR, "raspberry map: unable to open resource0 file"); syslog(LOG_ERR, "raspberry map: unable to open resource0 file");
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
} }
if (platform_detected==PLATFORM_RASPBERRY_PI2_B_REV_1) { if (platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1) {
mmap_reg = (uint8_t*) mmap(NULL, BCM2836_BLOCK_SIZE, mmap_reg = (uint8_t*) mmap(NULL, BCM2836_BLOCK_SIZE, PROT_READ | PROT_WRITE,
PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, mmap_fd, BCM2836_GPIO_BASE);
MAP_FILE | MAP_SHARED, } else {
mmap_fd, BCM2836_GPIO_BASE); mmap_reg = (uint8_t*) mmap(NULL, BCM2835_BLOCK_SIZE, PROT_READ | PROT_WRITE,
} MAP_FILE | MAP_SHARED, mmap_fd, BCM2835_GPIO_BASE);
else {
mmap_reg = (uint8_t*) mmap(NULL, BCM2835_BLOCK_SIZE,
PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED,
mmap_fd, BCM2835_GPIO_BASE);
} }
if (mmap_reg == MAP_FAILED) { if (mmap_reg == MAP_FAILED) {
syslog(LOG_ERR, "raspberry mmap: failed to mmap"); syslog(LOG_ERR, "raspberry mmap: failed to mmap");
@@ -207,17 +205,18 @@ mraa_raspberry_pi_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
mraa_board_t * mraa_board_t*
mraa_raspberry_pi() { mraa_raspberry_pi()
mraa_board_t *b = (mraa_board_t *) malloc(sizeof(mraa_board_t)); {
mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
if (b == NULL) { if (b == NULL) {
return NULL; return NULL;
} }
size_t len = 100; size_t len = 100;
char *line = malloc(len); char* line = malloc(len);
FILE *fh = fopen("/proc/cpuinfo", "r"); FILE* fh = fopen("/proc/cpuinfo", "r");
if (fh != NULL) { if (fh != NULL) {
while (getline(&line, &len, fh) != -1) { while (getline(&line, &len, fh) != -1) {
if (strncmp(line, "Revision", 8) == 0) { if (strncmp(line, "Revision", 8) == 0) {
@@ -225,39 +224,32 @@ mraa_raspberry_pi() {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1; platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
} } else if (strstr(line, "0004") || strstr(line, "0005") || strstr(line, "0006") ||
else if (strstr(line, "0004") || strstr(line, "0005") || strstr(line, "0006") \ strstr(line, "000d") || strstr(line, "000e") || strstr(line, "000f")) {
|| strstr(line, "000d") || strstr(line, "000e") || strstr(line, "000f")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2;
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2; platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2;
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
} } else if (strstr(line, "0007") || strstr(line, "0008") || strstr(line, "0009")) {
else if (strstr(line, "0007") || strstr(line, "0008") || strstr(line, "0009")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2;
platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2; platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2;
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
} } else if (strstr(line, "0010")) {
else if (strstr(line, "0010")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_PLUS_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_PLUS_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI_B_PLUS_REV_1; platform_detected = PLATFORM_RASPBERRY_PI_B_PLUS_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
} } else if (strstr(line, "0011")) {
else if (strstr(line, "0011")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1; platform_detected = PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT;
} } else if (strstr(line, "0012")) {
else if (strstr(line, "0012")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI_A_PLUS_REV_1; platform_detected = PLATFORM_RASPBERRY_PI_A_PLUS_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
} } else if (strstr(line, "a01041")) {
else if (strstr(line, "a01041")) {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI2_B_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI2_B_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI2_B_REV_1; platform_detected = PLATFORM_RASPBERRY_PI2_B_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT;
} } else {
else {
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1; b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1; platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT; b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
@@ -275,70 +267,70 @@ mraa_raspberry_pi() {
b->pwm_max_period = 2147483; b->pwm_max_period = 2147483;
b->pwm_min_period = 1; b->pwm_min_period = 1;
b->pins = (mraa_pininfo_t *) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count);
advance_func->spi_init_pre = &mraa_raspberry_pi_spi_init_pre; advance_func->spi_init_pre = &mraa_raspberry_pi_spi_init_pre;
advance_func->i2c_init_pre = &mraa_raspberry_pi_i2c_init_pre; advance_func->i2c_init_pre = &mraa_raspberry_pi_i2c_init_pre;
advance_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup; advance_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup;
strncpy(b->pins[0].name, "INVALID", 8); strncpy(b->pins[0].name, "INVALID", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t) {0, 0, 0, 0, 0, 0, 0, 0}; b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[1].name, "3V3", 8); strncpy(b->pins[1].name, "3V3", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[2].name, "5V", 8); strncpy(b->pins[2].name, "5V", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[3].name, "SDA0", 8); strncpy(b->pins[3].name, "SDA0", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 1, 0, 0}; b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[3].gpio.pinmap = 2; b->pins[3].gpio.pinmap = 2;
b->pins[3].gpio.mux_total = 0; b->pins[3].gpio.mux_total = 0;
b->pins[3].i2c.pinmap = 0; b->pins[3].i2c.pinmap = 0;
b->pins[3].i2c.mux_total = 0; b->pins[3].i2c.mux_total = 0;
strncpy(b->pins[4].name, "5V", 8); strncpy(b->pins[4].name, "5V", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[5].name, "SCL0", 8); strncpy(b->pins[5].name, "SCL0", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 1, 0, 0}; b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[5].gpio.pinmap = 3; b->pins[5].gpio.pinmap = 3;
b->pins[5].gpio.mux_total = 0; b->pins[5].gpio.mux_total = 0;
b->pins[5].i2c.pinmap = 0; b->pins[5].i2c.pinmap = 0;
b->pins[5].i2c.mux_total = 0; b->pins[5].i2c.mux_total = 0;
strncpy(b->pins[6].name, "GND", 8); strncpy(b->pins[6].name, "GND", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[7].name, "GPIO4", 8); strncpy(b->pins[7].name, "GPIO4", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 4; b->pins[7].gpio.pinmap = 4;
b->pins[7].gpio.mux_total = 0; b->pins[7].gpio.mux_total = 0;
strncpy(b->pins[8].name, "UART_TX", 8); strncpy(b->pins[8].name, "UART_TX", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 1}; b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[8].gpio.pinmap = 14; b->pins[8].gpio.pinmap = 14;
b->pins[8].gpio.mux_total = 0; b->pins[8].gpio.mux_total = 0;
b->pins[8].uart.parent_id = 0; b->pins[8].uart.parent_id = 0;
b->pins[8].uart.mux_total = 0; b->pins[8].uart.mux_total = 0;
strncpy(b->pins[9].name, "GND", 8); strncpy(b->pins[9].name, "GND", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[10].name, "UART_RX", 8); strncpy(b->pins[10].name, "UART_RX", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 1}; b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[10].gpio.pinmap = 15; b->pins[10].gpio.pinmap = 15;
b->pins[10].gpio.mux_total = 0; b->pins[10].gpio.mux_total = 0;
b->pins[10].uart.parent_id = 0; b->pins[10].uart.parent_id = 0;
b->pins[10].uart.mux_total = 0; b->pins[10].uart.mux_total = 0;
strncpy(b->pins[11].name, "GPIO17", 8); strncpy(b->pins[11].name, "GPIO17", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[11].gpio.pinmap = 17; b->pins[11].gpio.pinmap = 17;
b->pins[11].gpio.mux_total = 0; b->pins[11].gpio.mux_total = 0;
strncpy(b->pins[12].name, "GPIO18", 8); strncpy(b->pins[12].name, "GPIO18", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[12].gpio.pinmap = 18; b->pins[12].gpio.pinmap = 18;
b->pins[12].gpio.mux_total = 0; b->pins[12].gpio.mux_total = 0;
@@ -349,113 +341,112 @@ mraa_raspberry_pi() {
strncpy(b->pins[13].name, "GPIO27", 8); strncpy(b->pins[13].name, "GPIO27", 8);
b->pins[13].gpio.pinmap = 27; b->pins[13].gpio.pinmap = 27;
} }
b->pins[13].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[13].gpio.mux_total = 0; b->pins[13].gpio.mux_total = 0;
strncpy(b->pins[14].name, "GND", 8); strncpy(b->pins[14].name, "GND", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[15].name, "GPIO22", 8); strncpy(b->pins[15].name, "GPIO22", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[15].gpio.pinmap = 22; b->pins[15].gpio.pinmap = 22;
b->pins[15].gpio.mux_total = 0; b->pins[15].gpio.mux_total = 0;
strncpy(b->pins[16].name, "GPIO23", 8); strncpy(b->pins[16].name, "GPIO23", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[16].gpio.pinmap = 23; b->pins[16].gpio.pinmap = 23;
b->pins[16].gpio.mux_total = 0; b->pins[16].gpio.mux_total = 0;
strncpy(b->pins[17].name, "3V3", 8); strncpy(b->pins[17].name, "3V3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[18].name, "GPIO24", 8); strncpy(b->pins[18].name, "GPIO24", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[18].gpio.pinmap = 24; b->pins[18].gpio.pinmap = 24;
b->pins[18].gpio.mux_total = 0; b->pins[18].gpio.mux_total = 0;
strncpy(b->pins[19].name, "SPI_MOSI", 8); strncpy(b->pins[19].name, "SPI_MOSI", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 1, 0, 0, 0}; b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[19].gpio.pinmap = 10; b->pins[19].gpio.pinmap = 10;
b->pins[19].gpio.mux_total = 0; b->pins[19].gpio.mux_total = 0;
b->pins[19].spi.pinmap = 0; b->pins[19].spi.pinmap = 0;
b->pins[19].spi.mux_total = 0; b->pins[19].spi.mux_total = 0;
strncpy(b->pins[20].name, "GND", 8); strncpy(b->pins[20].name, "GND", 8);
b->pins[20].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[21].name, "SPI_MISO", 8); strncpy(b->pins[21].name, "SPI_MISO", 8);
b->pins[21].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 1, 0, 0, 0}; b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[21].gpio.pinmap = 9; b->pins[21].gpio.pinmap = 9;
b->pins[21].gpio.mux_total = 0; b->pins[21].gpio.mux_total = 0;
b->pins[21].spi.pinmap = 0; b->pins[21].spi.pinmap = 0;
b->pins[21].spi.mux_total = 0; b->pins[21].spi.mux_total = 0;
strncpy(b->pins[22].name, "GPIO25", 8); strncpy(b->pins[22].name, "GPIO25", 8);
b->pins[22].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[22].gpio.pinmap = 25; b->pins[22].gpio.pinmap = 25;
b->pins[22].gpio.mux_total = 0; b->pins[22].gpio.mux_total = 0;
strncpy(b->pins[23].name, "SPI_CLK", 8); strncpy(b->pins[23].name, "SPI_CLK", 8);
b->pins[23].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 1, 0, 0, 0}; b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[23].gpio.pinmap = 11; b->pins[23].gpio.pinmap = 11;
b->pins[23].gpio.mux_total = 0; b->pins[23].gpio.mux_total = 0;
b->pins[23].spi.pinmap = 0; b->pins[23].spi.pinmap = 0;
b->pins[23].spi.mux_total = 0; b->pins[23].spi.mux_total = 0;
strncpy(b->pins[24].name, "SPI_CS0", 8); strncpy(b->pins[24].name, "SPI_CS0", 8);
b->pins[24].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 1, 0, 0, 0}; b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[24].gpio.pinmap = 8; b->pins[24].gpio.pinmap = 8;
b->pins[24].gpio.mux_total = 0; b->pins[24].gpio.mux_total = 0;
b->pins[24].spi.pinmap = 0; b->pins[24].spi.pinmap = 0;
b->pins[24].spi.mux_total = 0; b->pins[24].spi.mux_total = 0;
strncpy(b->pins[25].name, "GND", 8); strncpy(b->pins[25].name, "GND", 8);
b->pins[25].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[26].name, "SPI_CS1", 8); strncpy(b->pins[26].name, "SPI_CS1", 8);
b->pins[26].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 1, 0, 0, 0}; b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[26].gpio.pinmap = 7; b->pins[26].gpio.pinmap = 7;
b->pins[26].gpio.mux_total = 0; b->pins[26].gpio.mux_total = 0;
b->pins[26].spi.pinmap = 0; b->pins[26].spi.pinmap = 0;
b->pins[26].spi.mux_total = 0; b->pins[26].spi.mux_total = 0;
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_REV_2) || \ if ((platform_detected == PLATFORM_RASPBERRY_PI_A_REV_2) ||
(platform_detected == PLATFORM_RASPBERRY_PI_B_REV_2)) { (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_2)) {
strncpy(b->pins[27].name, "5V", 8); strncpy(b->pins[27].name, "5V", 8);
b->pins[27].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[28].name, "3V3", 8); strncpy(b->pins[28].name, "3V3", 8);
b->pins[28].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[29].name, "GPIO8", 8); strncpy(b->pins[29].name, "GPIO8", 8);
b->pins[29].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 8; b->pins[29].gpio.pinmap = 8;
b->pins[29].gpio.mux_total = 0; b->pins[29].gpio.mux_total = 0;
strncpy(b->pins[30].name, "GPIO9", 8); strncpy(b->pins[30].name, "GPIO9", 8);
b->pins[30].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[30].gpio.pinmap = 9; b->pins[30].gpio.pinmap = 9;
b->pins[30].gpio.mux_total = 0; b->pins[30].gpio.mux_total = 0;
strncpy(b->pins[31].name, "GPIO10", 8); strncpy(b->pins[31].name, "GPIO10", 8);
b->pins[31].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].gpio.pinmap = 10; b->pins[31].gpio.pinmap = 10;
b->pins[31].gpio.mux_total = 0; b->pins[31].gpio.mux_total = 0;
strncpy(b->pins[32].name, "GPIO11", 8); strncpy(b->pins[32].name, "GPIO11", 8);
b->pins[32].gpio.pinmap = 11; b->pins[32].gpio.pinmap = 11;
b->pins[32].gpio.mux_total = 0; b->pins[32].gpio.mux_total = 0;
b->pins[32].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[33].name, "GND", 8); strncpy(b->pins[33].name, "GND", 8);
b->pins[33].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[34].name, "GND", 8); strncpy(b->pins[34].name, "GND", 8);
b->pins[34].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
} }
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 1; b->i2c_bus_count = 1;
b->def_i2c_bus = 0; b->def_i2c_bus = 0;
if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1) if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1)
@@ -479,74 +470,74 @@ mraa_raspberry_pi() {
b->uart_dev[0].rx = 10; b->uart_dev[0].rx = 10;
b->uart_dev[0].tx = 8; b->uart_dev[0].tx = 8;
if ((platform_detected == PLATFORM_RASPBERRY_PI_A_PLUS_REV_1) || \ if ((platform_detected == PLATFORM_RASPBERRY_PI_A_PLUS_REV_1) ||
(platform_detected == PLATFORM_RASPBERRY_PI_B_PLUS_REV_1) || \ (platform_detected == PLATFORM_RASPBERRY_PI_B_PLUS_REV_1) ||
(platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) { (platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
strncpy(b->pins[27].name, "ID_SD", 8); strncpy(b->pins[27].name, "ID_SD", 8);
b->pins[27].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[28].name, "ID_SC", 8); strncpy(b->pins[28].name, "ID_SC", 8);
b->pins[28].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[29].name, "GPIO05", 8); strncpy(b->pins[29].name, "GPIO05", 8);
b->pins[29].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[29].gpio.pinmap = 5; b->pins[29].gpio.pinmap = 5;
b->pins[29].gpio.mux_total = 0; b->pins[29].gpio.mux_total = 0;
strncpy(b->pins[30].name, "GND", 8); strncpy(b->pins[30].name, "GND", 8);
b->pins[30].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[31].name, "GPIO06", 8); strncpy(b->pins[31].name, "GPIO06", 8);
b->pins[31].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[31].gpio.pinmap = 6; b->pins[31].gpio.pinmap = 6;
b->pins[31].gpio.mux_total = 0; b->pins[31].gpio.mux_total = 0;
strncpy(b->pins[32].name, "GPIO12", 8); strncpy(b->pins[32].name, "GPIO12", 8);
b->pins[32].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[32].gpio.pinmap = 12; b->pins[32].gpio.pinmap = 12;
b->pins[32].gpio.mux_total = 0; b->pins[32].gpio.mux_total = 0;
strncpy(b->pins[33].name, "GPIO13", 8); strncpy(b->pins[33].name, "GPIO13", 8);
b->pins[33].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[33].gpio.pinmap = 13; b->pins[33].gpio.pinmap = 13;
b->pins[33].gpio.mux_total = 0; b->pins[33].gpio.mux_total = 0;
strncpy(b->pins[34].name, "GND", 8); strncpy(b->pins[34].name, "GND", 8);
b->pins[34].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[35].name, "GPIO19", 8); strncpy(b->pins[35].name, "GPIO19", 8);
b->pins[35].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[35].gpio.pinmap = 19; b->pins[35].gpio.pinmap = 19;
b->pins[35].gpio.mux_total = 0; b->pins[35].gpio.mux_total = 0;
strncpy(b->pins[36].name, "GPIO16", 8); strncpy(b->pins[36].name, "GPIO16", 8);
b->pins[36].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[36].gpio.pinmap = 16; b->pins[36].gpio.pinmap = 16;
b->pins[36].gpio.mux_total = 0; b->pins[36].gpio.mux_total = 0;
strncpy(b->pins[37].name, "GPIO26", 8); strncpy(b->pins[37].name, "GPIO26", 8);
b->pins[37].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[37].gpio.pinmap = 26; b->pins[37].gpio.pinmap = 26;
b->pins[37].gpio.mux_total = 0; b->pins[37].gpio.mux_total = 0;
strncpy(b->pins[38].name, "GPIO20", 8); strncpy(b->pins[38].name, "GPIO20", 8);
b->pins[38].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[38].gpio.pinmap = 20; b->pins[38].gpio.pinmap = 20;
b->pins[38].gpio.mux_total = 0; b->pins[38].gpio.mux_total = 0;
strncpy(b->pins[39].name, "GND", 8); strncpy(b->pins[39].name, "GND", 8);
b->pins[39].capabilites = (mraa_pincapabilities_t) {1, 0, 0, 0, 0, 0, 0, 0}; b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[40].name, "GPIO21", 8); strncpy(b->pins[40].name, "GPIO21", 8);
b->pins[40].capabilites = (mraa_pincapabilities_t) {1, 1, 0, 0, 0, 0, 0, 0}; b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[40].gpio.pinmap = 21; b->pins[40].gpio.pinmap = 21;
b->pins[40].gpio.mux_total = 0; b->pins[40].gpio.mux_total = 0;
} }
b->gpio_count=0; b->gpio_count = 0;
int i; int i;
for (i=0; i < b->phy_pin_count; i++) { for (i = 0; i < b->phy_pin_count; i++) {
if (b->pins[i].capabilites.gpio) { if (b->pins[i].capabilites.gpio) {
b->gpio_count++; b->gpio_count++;
} }

View File

@@ -131,7 +131,7 @@ mraa_gpio_init_raw(int pin)
return NULL; return NULL;
} }
length = snprintf(bu, sizeof(bu), "%d", dev->pin); length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(export, bu, length*sizeof(char)) == -1) { if (write(export, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write %d to export", dev->pin); syslog(LOG_ERR, "gpio: Failed to write %d to export", dev->pin);
close(export); close(export);
free(dev); free(dev);
@@ -160,15 +160,15 @@ mraa_gpio_wait_interrupt(int fd)
pfd.events = POLLPRI; pfd.events = POLLPRI;
// do an initial read to clear interrupt // do an initial read to clear interrupt
lseek (fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
read (fd, &c, 1); read(fd, &c, 1);
// Wait for it forever or until pthread_cancel // Wait for it forever or until pthread_cancel
// poll is a cancelable point like sleep() // poll is a cancelable point like sleep()
int x = poll (&pfd, 1, -1); int x = poll(&pfd, 1, -1);
// do a final read to clear interrupt // do a final read to clear interrupt
read (fd, &c, 1); read(fd, &c, 1);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -199,13 +199,13 @@ mraa_gpio_interrupt_handler(void* arg)
// nessecary but especially if doing IO (like print()) python will segfault // nessecary but especially if doing IO (like print()) python will segfault
// if we do not hold a lock on the GIL // if we do not hold a lock on the GIL
PyGILState_STATE gilstate = PyGILState_Ensure(); PyGILState_STATE gilstate = PyGILState_Ensure();
PyObject *arglist; PyObject* arglist;
PyObject *ret; PyObject* ret;
arglist = Py_BuildValue("(i)", dev->isr_args); arglist = Py_BuildValue("(i)", dev->isr_args);
if (arglist == NULL) { if (arglist == NULL) {
syslog(LOG_ERR, "gpio: Py_BuildValue NULL"); syslog(LOG_ERR, "gpio: Py_BuildValue NULL");
} else { } else {
ret = PyEval_CallObject((PyObject*)dev->isr, arglist); ret = PyEval_CallObject((PyObject*) dev->isr, arglist);
if (ret == NULL) { if (ret == NULL) {
syslog(LOG_ERR, "gpio: PyEval_CallObject failed"); syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
} else { } else {
@@ -214,7 +214,7 @@ mraa_gpio_interrupt_handler(void* arg)
Py_DECREF(arglist); Py_DECREF(arglist);
} }
PyGILState_Release (gilstate); PyGILState_Release(gilstate);
#else #else
dev->isr(dev->isr_args); dev->isr(dev->isr_args);
#endif #endif
@@ -248,7 +248,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length; int length;
switch(mode) { switch (mode) {
case MRAA_GPIO_EDGE_NONE: case MRAA_GPIO_EDGE_NONE:
length = snprintf(bu, sizeof(bu), "none"); length = snprintf(bu, sizeof(bu), "none");
break; break;
@@ -265,7 +265,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
close(edge); close(edge);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
} }
if (write(edge, bu, length*sizeof(char)) == -1) { if (write(edge, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to edge"); syslog(LOG_ERR, "gpio: Failed to write to edge");
close(edge); close(edge);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -276,7 +276,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
} }
mraa_result_t mraa_result_t
mraa_gpio_isr(mraa_gpio_context dev, gpio_edge_t mode, void (*fptr)(void *), void * args) mraa_gpio_isr(mraa_gpio_context dev, gpio_edge_t mode, void (*fptr)(void*), void* args)
{ {
// we only allow one isr per mraa_gpio_context // we only allow one isr per mraa_gpio_context
if (dev->thread_id != 0) { if (dev->thread_id != 0) {
@@ -289,7 +289,7 @@ mraa_gpio_isr(mraa_gpio_context dev, gpio_edge_t mode, void (*fptr)(void *), voi
dev->isr = fptr; dev->isr = fptr;
dev->isr_args = args; dev->isr_args = args;
pthread_create (&dev->thread_id, NULL, mraa_gpio_interrupt_handler, (void *) dev); pthread_create(&dev->thread_id, NULL, mraa_gpio_interrupt_handler, (void*) dev);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -335,11 +335,11 @@ mraa_result_t
mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode) mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
{ {
if (advance_func->gpio_mode_replace != NULL) if (advance_func->gpio_mode_replace != NULL)
return advance_func->gpio_mode_replace(dev,mode); return advance_func->gpio_mode_replace(dev, mode);
if (advance_func->gpio_mode_pre != NULL) { if (advance_func->gpio_mode_pre != NULL) {
mraa_result_t pre_ret = (advance_func->gpio_mode_pre(dev,mode)); mraa_result_t pre_ret = (advance_func->gpio_mode_pre(dev, mode));
if(pre_ret != MRAA_SUCCESS) if (pre_ret != MRAA_SUCCESS)
return pre_ret; return pre_ret;
} }
@@ -359,7 +359,7 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length; int length;
switch(mode) { switch (mode) {
case MRAA_GPIO_STRONG: case MRAA_GPIO_STRONG:
length = snprintf(bu, sizeof(bu), "strong"); length = snprintf(bu, sizeof(bu), "strong");
break; break;
@@ -376,16 +376,15 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
close(drive); close(drive);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
} }
if (write(drive, bu, length*sizeof(char)) == -1) { if (write(drive, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to drive mode"); syslog(LOG_ERR, "gpio: Failed to write to drive mode");
close(drive); close(drive);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
close(drive); close(drive);
if (advance_func->gpio_mode_post != NULL) if (advance_func->gpio_mode_post != NULL)
return advance_func->gpio_mode_post(dev,mode); return advance_func->gpio_mode_post(dev, mode);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -393,10 +392,10 @@ mraa_result_t
mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir) mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir)
{ {
if (advance_func->gpio_dir_replace != NULL) { if (advance_func->gpio_dir_replace != NULL) {
return advance_func->gpio_dir_replace(dev,dir); return advance_func->gpio_dir_replace(dev, dir);
} }
if (advance_func->gpio_dir_pre != NULL) { if (advance_func->gpio_dir_pre != NULL) {
mraa_result_t pre_ret = (advance_func->gpio_dir_pre(dev,dir)); mraa_result_t pre_ret = (advance_func->gpio_dir_pre(dev, dir));
if (pre_ret != MRAA_SUCCESS) { if (pre_ret != MRAA_SUCCESS) {
return pre_ret; return pre_ret;
} }
@@ -429,7 +428,7 @@ mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length; int length;
switch(dir) { switch (dir) {
case MRAA_GPIO_OUT: case MRAA_GPIO_OUT:
length = snprintf(bu, sizeof(bu), "out"); length = snprintf(bu, sizeof(bu), "out");
break; break;
@@ -447,14 +446,14 @@ mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
} }
if (write(direction, bu, length*sizeof(char)) == -1) { if (write(direction, bu, length * sizeof(char)) == -1) {
close(direction); close(direction);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
close(direction); close(direction);
if (advance_func->gpio_dir_post != NULL) if (advance_func->gpio_dir_post != NULL)
return advance_func->gpio_dir_post(dev,dir); return advance_func->gpio_dir_post(dev, dir);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -472,13 +471,12 @@ mraa_gpio_read(mraa_gpio_context dev)
syslog(LOG_ERR, "gpio: Failed to get value file pointer"); syslog(LOG_ERR, "gpio: Failed to get value file pointer");
return -1; return -1;
} }
} } else {
else {
// if value_fp is new this is pointless // if value_fp is new this is pointless
lseek(dev->value_fp, 0, SEEK_SET); lseek(dev->value_fp, 0, SEEK_SET);
} }
char bu[2]; char bu[2];
if (read(dev->value_fp, bu, 2*sizeof(char)) != 2) { if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) {
syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs"); syslog(LOG_ERR, "gpio: Failed to read a sensible value from sysfs");
return -1; return -1;
} }
@@ -494,11 +492,11 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
if (dev->mmap_write != NULL) if (dev->mmap_write != NULL)
return dev->mmap_write(dev,value); return dev->mmap_write(dev, value);
if (advance_func->gpio_write_pre != NULL) { if (advance_func->gpio_write_pre != NULL) {
mraa_result_t pre_ret = (advance_func->gpio_write_pre(dev,value)); mraa_result_t pre_ret = (advance_func->gpio_write_pre(dev, value));
if(pre_ret != MRAA_SUCCESS) if (pre_ret != MRAA_SUCCESS)
return pre_ret; return pre_ret;
} }
@@ -514,12 +512,12 @@ mraa_gpio_write(mraa_gpio_context dev, int value)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", value); int length = snprintf(bu, sizeof(bu), "%d", value);
if (write(dev->value_fp, bu, length*sizeof(char)) == -1) { if (write(dev->value_fp, bu, length * sizeof(char)) == -1) {
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
} }
if (advance_func->gpio_write_post != NULL) if (advance_func->gpio_write_post != NULL)
return advance_func->gpio_write_post(dev,value); return advance_func->gpio_write_post(dev, value);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -534,7 +532,7 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length = snprintf(bu, sizeof(bu), "%d", dev->pin); int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
if (write(unexport, bu, length*sizeof(char)) == -1) { if (write(unexport, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "gpio: Failed to write to unexport"); syslog(LOG_ERR, "gpio: Failed to write to unexport");
close(unexport); close(unexport);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -547,7 +545,7 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
static mraa_result_t static mraa_result_t
mraa_gpio_unexport(mraa_gpio_context dev) mraa_gpio_unexport(mraa_gpio_context dev)
{ {
if(dev->owner) { if (dev->owner) {
return mraa_gpio_unexport_force(dev); return mraa_gpio_unexport_force(dev);
} }
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -585,7 +583,7 @@ mraa_result_t
mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en) mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
{ {
if (advance_func->gpio_mmap_setup != NULL) { if (advance_func->gpio_mmap_setup != NULL) {
return advance_func->gpio_mmap_setup(dev,mmap_en); return advance_func->gpio_mmap_setup(dev, mmap_en);
} }
syslog(LOG_ERR, "gpio: mmap not implemented on this platform"); syslog(LOG_ERR, "gpio: mmap not implemented on this platform");

View File

@@ -37,25 +37,22 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "linux/i2c-dev.h" #include "linux/i2c-dev.h"
typedef union i2c_smbus_data_union typedef union i2c_smbus_data_union {
{
uint8_t byte; ///< data byte uint8_t byte; ///< data byte
unsigned short word; ///< data short word unsigned short word; ///< data short word
uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
///< block[0] is used for length and one more for PEC ///< block[0] is used for length and one more for PEC
} i2c_smbus_data_t; } i2c_smbus_data_t;
typedef struct i2c_smbus_ioctl_data_struct typedef struct i2c_smbus_ioctl_data_struct {
{
uint8_t read_write; ///< operation direction uint8_t read_write; ///< operation direction
uint8_t command; ///< ioctl command uint8_t command; ///< ioctl command
int size; ///< data size int size; ///< data size
i2c_smbus_data_t *data; ///< data i2c_smbus_data_t* data; ///< data
} i2c_smbus_ioctl_data_t; } i2c_smbus_ioctl_data_t;
int int
mraa_i2c_smbus_access(int fh, uint8_t read_write, uint8_t command, int size, mraa_i2c_smbus_access(int fh, uint8_t read_write, uint8_t command, int size, i2c_smbus_data_t* data)
i2c_smbus_data_t *data)
{ {
i2c_smbus_ioctl_data_t args; i2c_smbus_ioctl_data_t args;
@@ -166,8 +163,7 @@ mraa_i2c_read_byte(mraa_i2c_context dev)
{ {
i2c_smbus_data_t d; i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, I2C_NOCMD, I2C_SMBUS_BYTE, &d) < 0) {
I2C_SMBUS_BYTE, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return 0; return 0;
} }
@@ -179,8 +175,7 @@ mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{ {
i2c_smbus_data_t d; i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return 0; return 0;
} }
@@ -192,8 +187,7 @@ mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{ {
i2c_smbus_data_t d; i2c_smbus_data_t d;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return 0; return 0;
} }
@@ -229,25 +223,23 @@ mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
uint8_t command = data[0]; uint8_t command = data[0];
data = &data[1]; data = &data[1];
length = length-1; length = length - 1;
if (length > I2C_SMBUS_I2C_BLOCK_MAX) { if (length > I2C_SMBUS_I2C_BLOCK_MAX) {
length = I2C_SMBUS_I2C_BLOCK_MAX; length = I2C_SMBUS_I2C_BLOCK_MAX;
} }
for (i=1; i<=length; i++) { for (i = 1; i <= length; i++) {
d.block[i] = data[i-1]; d.block[i] = data[i - 1];
} }
d.block[0] = length; d.block[0] = length;
return mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, return mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &d);
I2C_SMBUS_I2C_BLOCK_DATA, &d);
} }
mraa_result_t mraa_result_t
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data) mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
{ {
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) < 0) {
I2C_SMBUS_BYTE, NULL) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
} }
@@ -255,14 +247,12 @@ mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
} }
mraa_result_t mraa_result_t
mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
const uint8_t command)
{ {
i2c_smbus_data_t d; i2c_smbus_data_t d;
d.byte = data; d.byte = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &d) < 0) {
I2C_SMBUS_BYTE_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
} }
@@ -270,14 +260,12 @@ mraa_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data,
} }
mraa_result_t mraa_result_t
mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, mraa_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
const uint8_t command)
{ {
i2c_smbus_data_t d; i2c_smbus_data_t d;
d.word = data; d.word = data;
if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, if (mraa_i2c_smbus_access(dev->fh, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &d) < 0) {
I2C_SMBUS_WORD_DATA, &d) < 0) {
syslog(LOG_ERR, "i2c: Failed to write"); syslog(LOG_ERR, "i2c: Failed to write");
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;
} }

View File

@@ -39,7 +39,7 @@ mraa_board_t* plat = NULL;
static mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; static mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
mraa_adv_func_t* advance_func; mraa_adv_func_t* advance_func;
const char * const char*
mraa_get_version() mraa_get_version()
{ {
return gVERSION; return gVERSION;
@@ -67,7 +67,7 @@ mraa_init()
} }
uid_t proc_euid = geteuid(); uid_t proc_euid = geteuid();
struct passwd *proc_user = getpwuid(proc_euid); struct passwd* proc_user = getpwuid(proc_euid);
#ifdef DEBUG #ifdef DEBUG
setlogmask(LOG_UPTO(LOG_DEBUG)); setlogmask(LOG_UPTO(LOG_DEBUG));
@@ -76,11 +76,8 @@ mraa_init()
#endif #endif
openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog(LOG_NOTICE, syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
"libmraa version %s initialised by user '%s' with EUID %d", mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);
mraa_get_version(),
(proc_user != NULL) ? proc_user->pw_name : "<unknown>",
proc_euid);
#ifdef SWIGPYTHON #ifdef SWIGPYTHON
// Initialise python threads, this allows use to grab the GIL when we are // Initialise python threads, this allows use to grab the GIL when we are
@@ -98,7 +95,7 @@ mraa_init()
// Use runtime ARM platform detection // Use runtime ARM platform detection
platform_type = mraa_arm_platform(); platform_type = mraa_arm_platform();
#else #else
#error mraa_ARCH NOTHING #error mraa_ARCH NOTHING
#endif #endif
if (plat == NULL) { if (plat == NULL) {
@@ -106,10 +103,7 @@ mraa_init()
return MRAA_ERROR_PLATFORM_NOT_INITIALISED; return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
} }
syslog(LOG_INFO, syslog(LOG_INFO, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), platform_type);
"libmraa initialised for platform '%s' of type %d",
mraa_get_platform_name(),
platform_type);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -133,8 +127,7 @@ mraa_set_priority(const unsigned int priority)
memset(&sched_s, 0, sizeof(struct sched_param)); memset(&sched_s, 0, sizeof(struct sched_param));
if (priority > sched_get_priority_max(SCHED_RR)) { if (priority > sched_get_priority_max(SCHED_RR)) {
sched_s.sched_priority = sched_get_priority_max(SCHED_RR); sched_s.sched_priority = sched_get_priority_max(SCHED_RR);
} } else {
else {
sched_s.sched_priority = priority; sched_s.sched_priority = priority;
} }
@@ -227,36 +220,36 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
if (plat == NULL) if (plat == NULL)
return 0; return 0;
} }
if (pin > (plat->phy_pin_count -1) || pin < 0) if (pin > (plat->phy_pin_count - 1) || pin < 0)
return 0; return 0;
switch(mode) { switch (mode) {
case MRAA_PIN_VALID: case MRAA_PIN_VALID:
if (plat->pins[pin].capabilites.valid == 1) if (plat->pins[pin].capabilites.valid == 1)
return 1; return 1;
break; break;
case MRAA_PIN_GPIO: case MRAA_PIN_GPIO:
if (plat->pins[pin].capabilites.gpio ==1) if (plat->pins[pin].capabilites.gpio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_PWM: case MRAA_PIN_PWM:
if (plat->pins[pin].capabilites.pwm ==1) if (plat->pins[pin].capabilites.pwm == 1)
return 1; return 1;
break; break;
case MRAA_PIN_FAST_GPIO: case MRAA_PIN_FAST_GPIO:
if (plat->pins[pin].capabilites.fast_gpio ==1) if (plat->pins[pin].capabilites.fast_gpio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_SPI: case MRAA_PIN_SPI:
if (plat->pins[pin].capabilites.spi ==1) if (plat->pins[pin].capabilites.spi == 1)
return 1; return 1;
break; break;
case MRAA_PIN_I2C: case MRAA_PIN_I2C:
if (plat->pins[pin].capabilites.i2c ==1) if (plat->pins[pin].capabilites.i2c == 1)
return 1; return 1;
break; break;
case MRAA_PIN_AIO: case MRAA_PIN_AIO:
if (plat->pins[pin].capabilites.aio ==1) if (plat->pins[pin].capabilites.aio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_UART: case MRAA_PIN_UART:
@@ -270,7 +263,8 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
return 0; return 0;
} }
mraa_platform_t mraa_get_platform_type() mraa_platform_t
mraa_get_platform_type()
{ {
return platform_type; return platform_type;
} }
@@ -318,7 +312,8 @@ mraa_get_pin_count()
} }
mraa_boolean_t mraa_boolean_t
mraa_file_exist(char *filename) { mraa_file_exist(char* filename)
{
glob_t results; glob_t results;
results.gl_pathc = 0; results.gl_pathc = 0;
glob(filename, 0, NULL, &results); glob(filename, 0, NULL, &results);
@@ -333,15 +328,16 @@ mraa_get_pin_name(int pin)
if (plat == NULL) { if (plat == NULL) {
return NULL; return NULL;
} }
if (pin > (plat->phy_pin_count -1) || pin < 0) if (pin > (plat->phy_pin_count - 1) || pin < 0)
return NULL; return NULL;
return (char*) plat->pins[pin].name; return (char*) plat->pins[pin].name;
} }
char* char*
mraa_file_unglob(char *filename) { mraa_file_unglob(char* filename)
{
glob_t results; glob_t results;
char *res = NULL; char* res = NULL;
results.gl_pathc = 0; results.gl_pathc = 0;
glob(filename, 0, NULL, &results); glob(filename, 0, NULL, &results);
if (results.gl_pathc == 1) if (results.gl_pathc == 1)
@@ -351,30 +347,29 @@ mraa_file_unglob(char *filename) {
} }
mraa_boolean_t mraa_boolean_t
mraa_link_targets(char *filename,char *targetname) { mraa_link_targets(char* filename, char* targetname)
{
int size = 100; int size = 100;
int nchars = 0; int nchars = 0;
char *buffer = NULL; char* buffer = NULL;
while (nchars == 0) while (nchars == 0) {
{ buffer = (char*) realloc(buffer, size);
buffer = (char *) realloc(buffer,size);
if (buffer == NULL) if (buffer == NULL)
return 0; return 0;
nchars = readlink(filename,buffer,size); nchars = readlink(filename, buffer, size);
if (nchars < 0 ) { if (nchars < 0) {
free(buffer); free(buffer);
return 0; return 0;
} }
if (nchars >= size) { if (nchars >= size) {
size *=2; size *= 2;
nchars=0; nchars = 0;
} }
} }
if (strstr(buffer,targetname)) { if (strstr(buffer, targetname)) {
free(buffer); free(buffer);
return 1; return 1;
} } else {
else {
free(buffer); free(buffer);
return 0; return 0;
} }

View File

@@ -37,7 +37,7 @@ static int
mraa_pwm_setup_duty_fp(mraa_pwm_context dev) mraa_pwm_setup_duty_fp(mraa_pwm_context dev)
{ {
char bu[MAX_SIZE]; char bu[MAX_SIZE];
snprintf(bu,MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/duty_cycle", dev->chipid, dev->pin); snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/duty_cycle", dev->chipid, dev->pin);
dev->duty_fp = open(bu, O_RDWR); dev->duty_fp = open(bu, O_RDWR);
if (dev->duty_fp == -1) { if (dev->duty_fp == -1) {
@@ -50,14 +50,14 @@ static mraa_result_t
mraa_pwm_write_period(mraa_pwm_context dev, int period) mraa_pwm_write_period(mraa_pwm_context dev, int period)
{ {
if (advance_func->pwm_period_replace != NULL) { if (advance_func->pwm_period_replace != NULL) {
mraa_result_t result = advance_func->pwm_period_replace(dev,period); mraa_result_t result = advance_func->pwm_period_replace(dev, period);
if (result == MRAA_SUCCESS) { if (result == MRAA_SUCCESS) {
dev->period = period; dev->period = period;
} }
return result; return result;
} }
char bu[MAX_SIZE]; char bu[MAX_SIZE];
snprintf(bu,MAX_SIZE ,"/sys/class/pwm/pwmchip%d/pwm%d/period", dev->chipid, dev->pin); snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/period", dev->chipid, dev->pin);
int period_f = open(bu, O_RDWR); int period_f = open(bu, O_RDWR);
if (period_f == -1) { if (period_f == -1) {
@@ -66,7 +66,7 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
} }
char out[MAX_SIZE]; char out[MAX_SIZE];
int length = snprintf(out, MAX_SIZE, "%d", period); int length = snprintf(out, MAX_SIZE, "%d", period);
if (write(period_f, out, length*sizeof(char)) == -1) { if (write(period_f, out, length * sizeof(char)) == -1) {
close(period_f); close(period_f);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -96,7 +96,7 @@ mraa_pwm_read_period(mraa_pwm_context dev)
{ {
char bu[MAX_SIZE]; char bu[MAX_SIZE];
char output[MAX_SIZE]; char output[MAX_SIZE];
snprintf(bu,MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/period", dev->chipid, dev->pin); snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/period", dev->chipid, dev->pin);
int period_f = open(bu, O_RDWR); int period_f = open(bu, O_RDWR);
if (period_f == -1) { if (period_f == -1) {
@@ -114,17 +114,16 @@ mraa_pwm_read_period(mraa_pwm_context dev)
return -1; return -1;
} }
char *endptr; char* endptr;
long int ret = strtol(output, &endptr, 10); long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) { if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string conversion"); syslog(LOG_ERR, "pwm: Error in string conversion");
return -1; return -1;
} } else if (ret > INT_MAX || ret < INT_MIN) {
else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid"); syslog(LOG_ERR, "pwm: Number is invalid");
return -1; return -1;
} }
dev->period = (int)ret; dev->period = (int) ret;
return (int) ret; return (int) ret;
} }
@@ -141,19 +140,18 @@ mraa_pwm_read_duty(mraa_pwm_context dev)
off_t size = lseek(dev->duty_fp, 0, SEEK_END); off_t size = lseek(dev->duty_fp, 0, SEEK_END);
lseek(dev->duty_fp, 0, SEEK_SET); lseek(dev->duty_fp, 0, SEEK_SET);
char output[MAX_SIZE]; char output[MAX_SIZE];
ssize_t rb = read(dev->duty_fp, output, size+1); ssize_t rb = read(dev->duty_fp, output, size + 1);
if (rb < 0) { if (rb < 0) {
syslog(LOG_ERR, "pwm: Error in reading duty"); syslog(LOG_ERR, "pwm: Error in reading duty");
return -1; return -1;
} }
char *endptr; char* endptr;
long int ret = strtol(output, &endptr, 10); long int ret = strtol(output, &endptr, 10);
if ('\0' != *endptr && '\n' != *endptr) { if ('\0' != *endptr && '\n' != *endptr) {
syslog(LOG_ERR, "pwm: Error in string converstion"); syslog(LOG_ERR, "pwm: Error in string converstion");
return -1; return -1;
} } else if (ret > INT_MAX || ret < INT_MIN) {
else if (ret > INT_MAX || ret < INT_MIN) {
syslog(LOG_ERR, "pwm: Number is invalid"); syslog(LOG_ERR, "pwm: Number is invalid");
return -1; return -1;
} }
@@ -209,7 +207,7 @@ mraa_pwm_init(int pin)
int pinn = plat->pins[pin].pwm.pinmap; int pinn = plat->pins[pin].pwm.pinmap;
if (advance_func->pwm_init_post != NULL) { if (advance_func->pwm_init_post != NULL) {
mraa_pwm_context pret = mraa_pwm_init_raw(chip,pinn); mraa_pwm_context pret = mraa_pwm_init_raw(chip, pinn);
mraa_result_t ret = advance_func->pwm_init_post(pret); mraa_result_t ret = advance_func->pwm_init_post(pret);
if (ret != MRAA_SUCCESS) { if (ret != MRAA_SUCCESS) {
free(pret); free(pret);
@@ -217,7 +215,7 @@ mraa_pwm_init(int pin)
} }
return pret; return pret;
} }
return mraa_pwm_init_raw(chip,pinn); return mraa_pwm_init_raw(chip, pinn);
} }
mraa_pwm_context mraa_pwm_context
@@ -249,7 +247,7 @@ mraa_pwm_init_raw(int chipin, int pin)
char out[MAX_SIZE]; char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin); int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(export_f, out, size*sizeof(char)) == -1) { if (write(export_f, out, size * sizeof(char)) == -1) {
syslog(LOG_WARNING, "pwm: Failed to write to export! Potentially already enabled"); syslog(LOG_WARNING, "pwm: Failed to write to export! Potentially already enabled");
close(export_f); close(export_f);
free(dev); free(dev);
@@ -290,42 +288,41 @@ mraa_pwm_read(mraa_pwm_context dev)
mraa_result_t mraa_result_t
mraa_pwm_period(mraa_pwm_context dev, float seconds) mraa_pwm_period(mraa_pwm_context dev, float seconds)
{ {
return mraa_pwm_period_ms(dev, seconds*1000); return mraa_pwm_period_ms(dev, seconds * 1000);
} }
mraa_result_t mraa_result_t
mraa_pwm_period_ms(mraa_pwm_context dev, int ms) mraa_pwm_period_ms(mraa_pwm_context dev, int ms)
{ {
return mraa_pwm_period_us(dev, ms*1000); return mraa_pwm_period_us(dev, ms * 1000);
} }
mraa_result_t mraa_result_t
mraa_pwm_period_us(mraa_pwm_context dev, int us) mraa_pwm_period_us(mraa_pwm_context dev, int us)
{ {
if (us < plat->pwm_min_period || if (us < plat->pwm_min_period || us > plat->pwm_max_period) {
us > plat->pwm_max_period) {
syslog(LOG_ERR, "pwm: period value outside platform range"); syslog(LOG_ERR, "pwm: period value outside platform range");
return MRAA_ERROR_INVALID_PARAMETER; return MRAA_ERROR_INVALID_PARAMETER;
} }
return mraa_pwm_write_period(dev, us*1000); return mraa_pwm_write_period(dev, us * 1000);
} }
mraa_result_t mraa_result_t
mraa_pwm_pulsewidth(mraa_pwm_context dev, float seconds) mraa_pwm_pulsewidth(mraa_pwm_context dev, float seconds)
{ {
return mraa_pwm_pulsewidth_ms(dev, seconds*1000); return mraa_pwm_pulsewidth_ms(dev, seconds * 1000);
} }
mraa_result_t mraa_result_t
mraa_pwm_pulsewidth_ms(mraa_pwm_context dev, int ms) mraa_pwm_pulsewidth_ms(mraa_pwm_context dev, int ms)
{ {
return mraa_pwm_pulsewidth_us(dev, ms*1000); return mraa_pwm_pulsewidth_us(dev, ms * 1000);
} }
mraa_result_t mraa_result_t
mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us) mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us)
{ {
return mraa_pwm_write_duty(dev, us*1000); return mraa_pwm_write_duty(dev, us * 1000);
} }
mraa_result_t mraa_result_t
@@ -338,7 +335,7 @@ mraa_pwm_enable(mraa_pwm_context dev, int enable)
status = enable; status = enable;
} }
char bu[MAX_SIZE]; char bu[MAX_SIZE];
snprintf(bu,MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/enable", dev->chipid, dev->pin); snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/enable", dev->chipid, dev->pin);
int enable_f = open(bu, O_RDWR); int enable_f = open(bu, O_RDWR);
@@ -371,7 +368,7 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
char out[MAX_SIZE]; char out[MAX_SIZE];
int size = snprintf(out, MAX_SIZE, "%d", dev->pin); int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
if (write(unexport_f, out, size*sizeof(char)) == -1) { if (write(unexport_f, out, size * sizeof(char)) == -1) {
syslog(LOG_ERR, "pwm: Failed to write to unexport"); syslog(LOG_ERR, "pwm: Failed to write to unexport");
close(unexport_f); close(unexport_f);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -409,12 +406,12 @@ mraa_pwm_owner(mraa_pwm_context dev, mraa_boolean_t owner_new)
} }
mraa_result_t mraa_result_t
mraa_pwm_config_ms(mraa_pwm_context dev, int ms ,float ms_float) mraa_pwm_config_ms(mraa_pwm_context dev, int ms, float ms_float)
{ {
int old_dutycycle, old_period, status; int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev); old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev); old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms*1000); status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle); mraa_pwm_write_duty(dev, old_dutycycle);
return status; return status;
@@ -423,7 +420,7 @@ mraa_pwm_config_ms(mraa_pwm_context dev, int ms ,float ms_float)
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
return status; return status;
} }
status = mraa_pwm_pulsewidth_us(dev, ms_float*1000); status = mraa_pwm_pulsewidth_us(dev, ms_float * 1000);
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle); mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period); mraa_pwm_write_period(dev, old_period);
@@ -433,12 +430,12 @@ mraa_pwm_config_ms(mraa_pwm_context dev, int ms ,float ms_float)
} }
mraa_result_t mraa_result_t
mraa_pwm_config_percent(mraa_pwm_context dev, int ms ,float percentage) mraa_pwm_config_percent(mraa_pwm_context dev, int ms, float percentage)
{ {
int old_dutycycle, old_period, status; int old_dutycycle, old_period, status;
old_dutycycle = mraa_pwm_read_duty(dev); old_dutycycle = mraa_pwm_read_duty(dev);
old_period = mraa_pwm_read_period(dev); old_period = mraa_pwm_read_period(dev);
status = mraa_pwm_period_us(dev, ms*1000); status = mraa_pwm_period_us(dev, ms * 1000);
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle); mraa_pwm_write_duty(dev, old_dutycycle);
return status; return status;
@@ -447,7 +444,7 @@ mraa_pwm_config_percent(mraa_pwm_context dev, int ms ,float percentage)
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
return status; return status;
} }
status = mraa_pwm_pulsewidth_us(dev, (ms*1000)*percentage); status = mraa_pwm_pulsewidth_us(dev, (ms * 1000) * percentage);
if (status != MRAA_SUCCESS) { if (status != MRAA_SUCCESS) {
mraa_pwm_write_duty(dev, old_dutycycle); mraa_pwm_write_duty(dev, old_dutycycle);
mraa_pwm_write_period(dev, old_period); mraa_pwm_write_period(dev, old_period);

View File

@@ -139,8 +139,7 @@ mraa_spi_init_raw(unsigned int bus, unsigned int cs)
int speed = 0; int speed = 0;
if ((ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) && (speed < 4000000)) { if ((ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) && (speed < 4000000)) {
dev->clock = speed; dev->clock = speed;
} } else {
else {
dev->clock = 4000000; dev->clock = 4000000;
} }
@@ -184,7 +183,7 @@ mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
break; break;
} }
if (ioctl (dev->devfd, SPI_IOC_WR_MODE, &spi_mode) < 0) { if (ioctl(dev->devfd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
syslog(LOG_ERR, "spi: Failed to set spi mode"); syslog(LOG_ERR, "spi: Failed to set spi mode");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -211,11 +210,11 @@ mraa_result_t
mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb) mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
{ {
uint8_t lsb_mode = (uint8_t) lsb; uint8_t lsb_mode = (uint8_t) lsb;
if (ioctl (dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) { if (ioctl(dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) {
syslog(LOG_ERR, "spi: Failed to set bit order"); syslog(LOG_ERR, "spi: Failed to set bit order");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
if (ioctl (dev->devfd, SPI_IOC_RD_LSB_FIRST, &lsb_mode) < 0) { if (ioctl(dev->devfd, SPI_IOC_RD_LSB_FIRST, &lsb_mode) < 0) {
syslog(LOG_ERR, "spi: Failed to set bit order"); syslog(LOG_ERR, "spi: Failed to set bit order");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -329,7 +328,7 @@ mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
} }
uint16_t* uint16_t*
mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t *data, int length) mraa_spi_write_buf_word(mraa_spi_context dev, uint16_t* data, int length)
{ {
uint16_t* recv = malloc(sizeof(uint16_t) * length); uint16_t* recv = malloc(sizeof(uint16_t) * length);

View File

@@ -42,7 +42,7 @@ mraa_intel_de3815()
b->platform_name = PLATFORM_NAME; b->platform_name = PLATFORM_NAME;
b->phy_pin_count = 18; b->phy_pin_count = 18;
//b->gpio_count = 14; // b->gpio_count = 14;
b->aio_count = 0; b->aio_count = 0;
b->adc_raw = 0; b->adc_raw = 0;
b->adc_supported = 0; b->adc_supported = 0;
@@ -50,71 +50,71 @@ mraa_intel_de3815()
b->pwm_max_period = 2147483; b->pwm_max_period = 2147483;
b->pwm_min_period = 1; b->pwm_min_period = 1;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_DE3815_PINCOUNT); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_DE3815_PINCOUNT);
if (b->pins == NULL) { if (b->pins == NULL) {
goto error; goto error;
} }
strncpy(b->pins[0].name, "1.8v", 8); strncpy(b->pins[0].name, "1.8v", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[1].name, "GND", 8); strncpy(b->pins[1].name, "GND", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[2].name, "HDMIcec", 8); strncpy(b->pins[2].name, "HDMIcec", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[3].name, "DMICclk", 8); strncpy(b->pins[3].name, "DMICclk", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[4].name, "3.3v", 8); strncpy(b->pins[4].name, "3.3v", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[5].name, "DMICda", 8); strncpy(b->pins[5].name, "DMICda", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[6].name, "Key", 8); strncpy(b->pins[6].name, "Key", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[7].name, "SMB-A", 8); strncpy(b->pins[7].name, "SMB-A", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[8].name, "5v", 8); strncpy(b->pins[8].name, "5v", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[9].name, "SCI", 8); strncpy(b->pins[9].name, "SCI", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[10].name, "PWM0", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[10].pwm.pinmap = 0; b->pins[10].pwm.pinmap = 0;
b->pins[10].pwm.parent_id = 0; b->pins[10].pwm.parent_id = 0;
b->pins[10].pwm.mux_total = 0; b->pins[10].pwm.mux_total = 0;
strncpy(b->pins[11].name, "PWM1", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
b->pins[11].pwm.pinmap = 0; b->pins[11].pwm.pinmap = 0;
b->pins[11].pwm.parent_id = 1; b->pins[11].pwm.parent_id = 1;
b->pins[11].pwm.mux_total = 0; b->pins[11].pwm.mux_total = 0;
strncpy(b->pins[12].name, "I2C0SCL", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[12].i2c.pinmap = 1; b->pins[12].i2c.pinmap = 1;
b->pins[12].i2c.mux_total = 0; b->pins[12].i2c.mux_total = 0;
strncpy(b->pins[13].name, "I2C0SDA", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[13].i2c.pinmap = 1; b->pins[13].i2c.pinmap = 1;
b->pins[13].i2c.mux_total = 0; b->pins[13].i2c.mux_total = 0;
strncpy(b->pins[14].name, "I2C1SCL", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[14].i2c.pinmap = 1; b->pins[14].i2c.pinmap = 1;
b->pins[14].i2c.mux_total = 0; b->pins[14].i2c.mux_total = 0;
strncpy(b->pins[15].name, "I2C1SDA", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
b->pins[15].i2c.pinmap = 1; b->pins[15].i2c.pinmap = 1;
b->pins[15].i2c.mux_total = 0; b->pins[15].i2c.mux_total = 0;
strncpy(b->pins[16].name, "SMB_CLK", 8); strncpy(b->pins[16].name, "SMB_CLK", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
strncpy(b->pins[17].name, "SMB_SDA", 8); strncpy(b->pins[17].name, "SMB_SDA", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 2; b->i2c_bus_count = 2;
b->def_i2c_bus = 0; b->def_i2c_bus = 0;
b->i2c_bus[0].bus_id = 0; b->i2c_bus[0].bus_id = 0;

View File

@@ -58,14 +58,16 @@ typedef struct {
static mraa_gpio_context tristate; static mraa_gpio_context tristate;
static mraa_intel_edison_pinmodes_t pinmodes[MRAA_INTEL_EDISON_PINCOUNT]; 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 outputen[] = { 248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
static mraa_gpio_context agpioOutputen[sizeof(outputen)/sizeof(outputen[0])]; 258, 259, 260, 261, 232, 233, 234, 235, 236, 237 };
static mraa_gpio_context agpioOutputen[sizeof(outputen) / sizeof(outputen[0])];
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 unsigned int pullup_map[] = { 216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 208, 209, 210, 211, 212, 213 };
static int miniboard = 0; static int miniboard = 0;
//MMAP // MMAP
static uint8_t *mmap_reg = NULL; static uint8_t* mmap_reg = NULL;
static int mmap_fd = 0; static int mmap_fd = 0;
static int mmap_size; static int mmap_size;
static unsigned int mmap_count = 0; static unsigned int mmap_count = 0;
@@ -73,12 +75,12 @@ static unsigned int mmap_count = 0;
static mraa_result_t static mraa_result_t
mraa_intel_edison_pinmode_change(int sysfs, int mode) mraa_intel_edison_pinmode_change(int sysfs, int mode)
{ {
if (mode < 0 ) { if (mode < 0) {
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
char buffer[MAX_SIZE]; char buffer[MAX_SIZE];
snprintf(buffer, MAX_SIZE, SYSFS_PINMODE_PATH "%i/current_pinmux",sysfs); snprintf(buffer, MAX_SIZE, SYSFS_PINMODE_PATH "%i/current_pinmux", sysfs);
int modef = open(buffer, O_WRONLY); int modef = open(buffer, O_WRONLY);
if (modef == -1) { if (modef == -1) {
syslog(LOG_ERR, "edison: Failed to open SoC pinmode for opening"); syslog(LOG_ERR, "edison: Failed to open SoC pinmode for opening");
@@ -87,8 +89,8 @@ mraa_intel_edison_pinmode_change(int sysfs, int mode)
mraa_result_t ret = MRAA_SUCCESS; mraa_result_t ret = MRAA_SUCCESS;
char mode_buf[MAX_MODE_SIZE]; char mode_buf[MAX_MODE_SIZE];
int length = sprintf(mode_buf, "mode%u",mode); int length = sprintf(mode_buf, "mode%u", mode);
if (write(modef, mode_buf, length*sizeof(char)) == -1) { if (write(modef, mode_buf, length * sizeof(char)) == -1) {
ret = MRAA_ERROR_INVALID_RESOURCE; ret = MRAA_ERROR_INVALID_RESOURCE;
} }
close(modef); close(modef);
@@ -207,7 +209,7 @@ mraa_intel_edison_i2c_init_pre(unsigned int bus)
mraa_gpio_write(tristate, 1); mraa_gpio_write(tristate, 1);
} else { } else {
if(bus != 6 && bus != 1) { if (bus != 6 && bus != 1) {
syslog(LOG_ERR, "edison: You can't use that bus, switching to bus 6"); syslog(LOG_ERR, "edison: You can't use that bus, switching to bus 6");
bus = 6; bus = 6;
} }
@@ -263,15 +265,15 @@ mraa_intel_edison_misc_spi()
mraa_result_t mraa_result_t
mraa_intel_edison_aio_get_fp(mraa_aio_context dev) mraa_intel_edison_aio_get_fp(mraa_aio_context dev)
{ {
char file_path[64]= ""; char file_path[64] = "";
snprintf(file_path, 64, "/sys/bus/iio/devices/iio:device1/in_voltage%d_raw", snprintf(file_path, 64, "/sys/bus/iio/devices/iio:device1/in_voltage%d_raw", dev->channel);
dev->channel );
dev->adc_in_fp = open(file_path, O_RDONLY); dev->adc_in_fp = open(file_path, O_RDONLY);
if (dev->adc_in_fp == -1) { if (dev->adc_in_fp == -1) {
syslog(LOG_ERR, "edison: 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); "reading!",
file_path);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -448,7 +450,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
} }
int value = -1; int value = -1;
switch(mode) { switch (mode) {
case MRAA_GPIO_STRONG: case MRAA_GPIO_STRONG:
break; break;
case MRAA_GPIO_PULLUP: case MRAA_GPIO_PULLUP:
@@ -469,7 +471,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
mraa_gpio_close(pullup_e); mraa_gpio_close(pullup_e);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
if (mraa_gpio_write(pullup_e, value)!= MRAA_SUCCESS) { if (mraa_gpio_write(pullup_e, value) != MRAA_SUCCESS) {
syslog(LOG_ERR, "edison: Error setting pullup"); syslog(LOG_ERR, "edison: Error setting pullup");
mraa_gpio_close(pullup_e); mraa_gpio_close(pullup_e);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -490,8 +492,7 @@ mraa_intel_edsion_mb_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
} }
char filepath[MAX_SIZE]; char filepath[MAX_SIZE];
snprintf(filepath, MAX_SIZE, snprintf(filepath, MAX_SIZE, SYSFS_PINMODE_PATH "%d/current_pullmode", dev->pin);
SYSFS_PINMODE_PATH "%d/current_pullmode", dev->pin);
int drive = open(filepath, O_WRONLY); int drive = open(filepath, O_WRONLY);
if (drive == -1) { if (drive == -1) {
@@ -501,7 +502,7 @@ mraa_intel_edsion_mb_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length; int length;
switch(mode) { switch (mode) {
case MRAA_GPIO_STRONG: case MRAA_GPIO_STRONG:
close(drive); close(drive);
return MRAA_SUCCESS; return MRAA_SUCCESS;
@@ -518,7 +519,7 @@ mraa_intel_edsion_mb_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
close(drive); close(drive);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
} }
if (write(drive, bu, length*sizeof(char)) == -1) { if (write(drive, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "edison: Failed to write to drive mode"); syslog(LOG_ERR, "edison: Failed to write to drive mode");
close(drive); close(drive);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
@@ -554,8 +555,8 @@ mraa_intel_edison_uart_init_pre(int index)
mraa_gpio_close(io1_pullup); mraa_gpio_close(io1_pullup);
} }
mraa_result_t ret; mraa_result_t ret;
ret = mraa_intel_edison_pinmode_change(130,1); //IO0 RX ret = mraa_intel_edison_pinmode_change(130, 1); // IO0 RX
ret = mraa_intel_edison_pinmode_change(131,1); //IO1 TX ret = mraa_intel_edison_pinmode_change(131, 1); // IO1 TX
return ret; return ret;
} }
@@ -592,8 +593,7 @@ mraa_intel_edison_mmap_write(mraa_gpio_context dev, int value)
valoff = 0x4c; valoff = 0x4c;
} }
*(volatile uint32_t*) (mmap_reg + offset + valoff) = *(volatile uint32_t*) (mmap_reg + offset + valoff) = (uint32_t)(1 << (dev->pin % 32));
(uint32_t)(1 << (dev->pin % 32));
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -604,8 +604,8 @@ mraa_intel_edison_mmap_read(mraa_gpio_context dev)
uint8_t offset = ((dev->pin / 32) * sizeof(uint32_t)); uint8_t offset = ((dev->pin / 32) * sizeof(uint32_t));
uint32_t value; uint32_t value;
value = *(volatile uint32_t*) (mmap_reg +0x04+ offset); value = *(volatile uint32_t*) (mmap_reg + 0x04 + offset);
if (value&(uint32_t)(1 << (dev->pin % 32))) { if (value & (uint32_t)(1 << (dev->pin % 32))) {
return 1; return 1;
} }
return 0; return 0;
@@ -638,9 +638,9 @@ mraa_intel_edison_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_ERROR_INVALID_PARAMETER; return MRAA_ERROR_INVALID_PARAMETER;
} }
//Might need to make some elements of this thread safe. // Might need to make some elements of this thread safe.
//For example only allow one thread to enter the following block // For example only allow one thread to enter the following block
//to prevent mmap'ing twice. // to prevent mmap'ing twice.
if (mmap_reg == NULL) { if (mmap_reg == NULL) {
if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) { if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
syslog(LOG_ERR, "edison map: unable to open resource0 file"); syslog(LOG_ERR, "edison map: unable to open resource0 file");
@@ -651,10 +651,8 @@ mraa_intel_edison_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
fstat(mmap_fd, &fd_stat); fstat(mmap_fd, &fd_stat);
mmap_size = fd_stat.st_size; mmap_size = fd_stat.st_size;
mmap_reg = (uint8_t*) mmap(NULL, fd_stat.st_size, mmap_reg =
PROT_READ | PROT_WRITE, (uint8_t*) mmap(NULL, fd_stat.st_size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, mmap_fd, 0);
MAP_FILE | MAP_SHARED,
mmap_fd, 0);
if (mmap_reg == MAP_FAILED) { if (mmap_reg == MAP_FAILED) {
syslog(LOG_ERR, "edison mmap: failed to mmap"); syslog(LOG_ERR, "edison mmap: failed to mmap");
mmap_reg = NULL; mmap_reg = NULL;
@@ -706,7 +704,7 @@ mraa_intel_edison_i2c_freq(mraa_i2c_context dev, mraa_i2c_mode_t mode)
close(sysnode); close(sysnode);
return MRAA_ERROR_INVALID_PARAMETER; return MRAA_ERROR_INVALID_PARAMETER;
} }
if (write(sysnode, bu, length*sizeof(char)) == -1) { if (write(sysnode, bu, length * sizeof(char)) == -1) {
close(sysnode); close(sysnode);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -725,7 +723,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
b->pwm_max_period = 218453; b->pwm_max_period = 218453;
b->pwm_min_period = 1; b->pwm_min_period = 1;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*56); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * 56);
if (b->pins == NULL) { if (b->pins == NULL) {
return MRAA_ERROR_UNSPECIFIED; return MRAA_ERROR_UNSPECIFIED;
} }
@@ -742,7 +740,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
int pos = 0; int pos = 0;
strncpy(b->pins[pos].name, "J17-1", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 182; b->pins[pos].gpio.pinmap = 182;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 2; b->pins[pos].pwm.pinmap = 2;
@@ -751,27 +749,27 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-2", 8); strncpy(b->pins[pos].name, "J17-2", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J17-3", 8); strncpy(b->pins[pos].name, "J17-3", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J17-4", 8); strncpy(b->pins[pos].name, "J17-4", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J17-5", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 135; b->pins[pos].gpio.pinmap = 135;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J17-6", 8); strncpy(b->pins[pos].name, "J17-6", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J17-7", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[pos].gpio.pinmap = 27; b->pins[pos].gpio.pinmap = 27;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].i2c.pinmap = 1; b->pins[pos].i2c.pinmap = 1;
@@ -779,7 +777,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-8", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[pos].gpio.pinmap = 20; b->pins[pos].gpio.pinmap = 20;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].i2c.pinmap = 1; b->pins[pos].i2c.pinmap = 1;
@@ -787,7 +785,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-9", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[pos].gpio.pinmap = 28; b->pins[pos].gpio.pinmap = 28;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].i2c.pinmap = 1; b->pins[pos].i2c.pinmap = 1;
@@ -795,7 +793,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-10", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 111; b->pins[pos].gpio.pinmap = 111;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].spi.pinmap = 5; b->pins[pos].spi.pinmap = 5;
@@ -803,7 +801,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-11", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 109; b->pins[pos].gpio.pinmap = 109;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].spi.pinmap = 5; b->pins[pos].spi.pinmap = 5;
@@ -811,25 +809,25 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J17-12", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 115; b->pins[pos].gpio.pinmap = 115;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].spi.pinmap = 5; b->pins[pos].spi.pinmap = 5;
b->pins[pos].spi.mux_total = 0; b->pins[pos].spi.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J17-13", 8); strncpy(b->pins[pos].name, "J17-13", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J17-14", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 128; b->pins[pos].gpio.pinmap = 128;
b->pins[pos].gpio.parent_id = 0; b->pins[pos].gpio.parent_id = 0;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J18-1", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 13; b->pins[pos].gpio.pinmap = 13;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 1; b->pins[pos].pwm.pinmap = 1;
@@ -838,22 +836,22 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J18-2", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 165; b->pins[pos].gpio.pinmap = 165;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J18-3", 8); strncpy(b->pins[pos].name, "J18-3", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J18-4", 8); strncpy(b->pins[pos].name, "J18-4", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J18-5", 8); strncpy(b->pins[pos].name, "J18-5", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J18-6", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
b->pins[pos].gpio.pinmap = 19; b->pins[pos].gpio.pinmap = 19;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].i2c.pinmap = 1; b->pins[pos].i2c.pinmap = 1;
@@ -861,7 +859,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J18-7", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 12; b->pins[pos].gpio.pinmap = 12;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 0; b->pins[pos].pwm.pinmap = 0;
@@ -870,7 +868,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J18-8", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 183; b->pins[pos].gpio.pinmap = 183;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].pwm.pinmap = 3; b->pins[pos].pwm.pinmap = 3;
@@ -878,18 +876,18 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
b->pins[pos].pwm.mux_total = 0; b->pins[pos].pwm.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J18-9", 8); strncpy(b->pins[pos].name, "J18-9", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J18-10", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 110; b->pins[pos].gpio.pinmap = 110;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].spi.pinmap = 5; b->pins[pos].spi.pinmap = 5;
b->pins[pos].spi.mux_total = 0; b->pins[pos].spi.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J18-11", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 114; b->pins[pos].gpio.pinmap = 114;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].spi.pinmap = 5; b->pins[pos].spi.pinmap = 5;
@@ -897,12 +895,12 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J18-12", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 129; b->pins[pos].gpio.pinmap = 129;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J18-13", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[pos].gpio.pinmap = 130; b->pins[pos].gpio.pinmap = 130;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].uart.pinmap = 0; b->pins[pos].uart.pinmap = 0;
@@ -911,41 +909,41 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J18-14", 8); strncpy(b->pins[pos].name, "J18-14", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J19-1", 8); strncpy(b->pins[pos].name, "J19-1", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J19-2", 8); strncpy(b->pins[pos].name, "J19-2", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J19-3", 8); strncpy(b->pins[pos].name, "J19-3", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J19-4", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 44; b->pins[pos].gpio.pinmap = 44;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-5", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 46; b->pins[pos].gpio.pinmap = 46;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-6", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 48; b->pins[pos].gpio.pinmap = 48;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-7", 8); strncpy(b->pins[pos].name, "J19-7", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J19-8", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[pos].gpio.pinmap = 131; b->pins[pos].gpio.pinmap = 131;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
b->pins[pos].uart.pinmap = 0; b->pins[pos].uart.pinmap = 0;
@@ -954,103 +952,103 @@ mraa_intel_edison_miniboard(mraa_board_t* b)
pos++; pos++;
strncpy(b->pins[pos].name, "J19-9", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 14; b->pins[pos].gpio.pinmap = 14;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-10", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 40; b->pins[pos].gpio.pinmap = 40;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-11", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 43; b->pins[pos].gpio.pinmap = 43;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-12", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 77; b->pins[pos].gpio.pinmap = 77;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-13", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 82; b->pins[pos].gpio.pinmap = 82;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J19-14", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 83; b->pins[pos].gpio.pinmap = 83;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-1", 8); strncpy(b->pins[pos].name, "J20-1", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J20-2", 8); strncpy(b->pins[pos].name, "J20-2", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J20-3", 8); strncpy(b->pins[pos].name, "J20-3", 8);
b->pins[pos].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; b->pins[pos].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
pos++; pos++;
strncpy(b->pins[pos].name, "J20-4", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 45; b->pins[pos].gpio.pinmap = 45;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-5", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 47; b->pins[pos].gpio.pinmap = 47;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-6", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 49; b->pins[pos].gpio.pinmap = 49;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-7", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 15; b->pins[pos].gpio.pinmap = 15;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-8", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 84; b->pins[pos].gpio.pinmap = 84;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-9", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 42; b->pins[pos].gpio.pinmap = 42;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-10", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 41; b->pins[pos].gpio.pinmap = 41;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-11", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 78; b->pins[pos].gpio.pinmap = 78;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-12", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 79; b->pins[pos].gpio.pinmap = 79;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-13", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 80; b->pins[pos].gpio.pinmap = 80;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
strncpy(b->pins[pos].name, "J20-14", 8); 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].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[pos].gpio.pinmap = 81; b->pins[pos].gpio.pinmap = 81;
b->pins[pos].gpio.mux_total = 0; b->pins[pos].gpio.mux_total = 0;
pos++; pos++;
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 9; b->i2c_bus_count = 9;
b->def_i2c_bus = 6; b->def_i2c_bus = 6;
int ici; int ici;
@@ -1125,7 +1123,7 @@ mraa_intel_edison_fab_c()
advance_func->uart_init_post = &mraa_intel_edison_uart_init_post; advance_func->uart_init_post = &mraa_intel_edison_uart_init_post;
advance_func->gpio_mmap_setup = &mraa_intel_edison_mmap_setup; advance_func->gpio_mmap_setup = &mraa_intel_edison_mmap_setup;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_EDISON_PINCOUNT); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_EDISON_PINCOUNT);
if (b->pins == NULL) { if (b->pins == NULL) {
goto error; goto error;
} }
@@ -1140,7 +1138,7 @@ mraa_intel_edison_fab_c()
b->pwm_min_period = 1; b->pwm_min_period = 1;
strncpy(b->pins[0].name, "IO0", 8); strncpy(b->pins[0].name, "IO0", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1}; 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.pinmap = 130;
b->pins[0].gpio.parent_id = 0; b->pins[0].gpio.parent_id = 0;
b->pins[0].gpio.mux_total = 0; b->pins[0].gpio.mux_total = 0;
@@ -1149,7 +1147,7 @@ mraa_intel_edison_fab_c()
b->pins[0].uart.mux_total = 0; b->pins[0].uart.mux_total = 0;
strncpy(b->pins[1].name, "IO1", 8); strncpy(b->pins[1].name, "IO1", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1}; 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.pinmap = 131;
b->pins[1].gpio.parent_id = 0; b->pins[1].gpio.parent_id = 0;
b->pins[1].gpio.mux_total = 0; b->pins[1].gpio.mux_total = 0;
@@ -1158,13 +1156,13 @@ mraa_intel_edison_fab_c()
b->pins[1].uart.mux_total = 0; b->pins[1].uart.mux_total = 0;
strncpy(b->pins[2].name, "IO2", 8); strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[2].gpio.pinmap = 128; b->pins[2].gpio.pinmap = 128;
b->pins[2].gpio.parent_id = 0; b->pins[2].gpio.parent_id = 0;
b->pins[2].gpio.mux_total = 0; b->pins[2].gpio.mux_total = 0;
strncpy(b->pins[3].name, "IO3", 8); strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0}; b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[3].gpio.pinmap = 12; b->pins[3].gpio.pinmap = 12;
b->pins[3].gpio.parent_id = 0; b->pins[3].gpio.parent_id = 0;
b->pins[3].gpio.mux_total = 0; b->pins[3].gpio.mux_total = 0;
@@ -1173,13 +1171,13 @@ mraa_intel_edison_fab_c()
b->pins[3].pwm.mux_total = 0; b->pins[3].pwm.mux_total = 0;
strncpy(b->pins[4].name, "IO4", 8); strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 129; b->pins[4].gpio.pinmap = 129;
b->pins[4].gpio.parent_id = 0; b->pins[4].gpio.parent_id = 0;
b->pins[4].gpio.mux_total = 0; b->pins[4].gpio.mux_total = 0;
strncpy(b->pins[5].name, "IO5", 8); strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[5].gpio.pinmap = 13; b->pins[5].gpio.pinmap = 13;
b->pins[5].gpio.parent_id = 0; b->pins[5].gpio.parent_id = 0;
b->pins[5].gpio.mux_total = 0; b->pins[5].gpio.mux_total = 0;
@@ -1188,7 +1186,7 @@ mraa_intel_edison_fab_c()
b->pins[5].pwm.mux_total = 0; b->pins[5].pwm.mux_total = 0;
strncpy(b->pins[6].name, "IO6", 8); strncpy(b->pins[6].name, "IO6", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].gpio.pinmap = 182; b->pins[6].gpio.pinmap = 182;
b->pins[6].gpio.parent_id = 0; b->pins[6].gpio.parent_id = 0;
b->pins[6].gpio.mux_total = 0; b->pins[6].gpio.mux_total = 0;
@@ -1197,19 +1195,19 @@ mraa_intel_edison_fab_c()
b->pins[6].pwm.mux_total = 0; b->pins[6].pwm.mux_total = 0;
strncpy(b->pins[7].name, "IO7", 8); strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 48; b->pins[7].gpio.pinmap = 48;
b->pins[7].gpio.parent_id = 0; b->pins[7].gpio.parent_id = 0;
b->pins[7].gpio.mux_total = 0; b->pins[7].gpio.mux_total = 0;
strncpy(b->pins[8].name, "IO8", 8); strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 49; b->pins[8].gpio.pinmap = 49;
b->pins[8].gpio.parent_id = 0; b->pins[8].gpio.parent_id = 0;
b->pins[8].gpio.mux_total = 0; b->pins[8].gpio.mux_total = 0;
strncpy(b->pins[9].name, "IO9", 8); strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 183; b->pins[9].gpio.pinmap = 183;
b->pins[9].gpio.parent_id = 0; b->pins[9].gpio.parent_id = 0;
b->pins[9].gpio.mux_total = 0; b->pins[9].gpio.mux_total = 0;
@@ -1218,7 +1216,7 @@ mraa_intel_edison_fab_c()
b->pins[9].pwm.mux_total = 0; b->pins[9].pwm.mux_total = 0;
strncpy(b->pins[10].name, "IO10", 8); strncpy(b->pins[10].name, "IO10", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[10].gpio.pinmap = 41; b->pins[10].gpio.pinmap = 41;
b->pins[10].gpio.parent_id = 0; b->pins[10].gpio.parent_id = 0;
b->pins[10].gpio.mux_total = 2; b->pins[10].gpio.mux_total = 2;
@@ -1234,7 +1232,7 @@ mraa_intel_edison_fab_c()
b->pins[10].spi.mux[1].value = 1; b->pins[10].spi.mux[1].value = 1;
strncpy(b->pins[11].name, "IO11", 8); strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[11].gpio.pinmap = 43; b->pins[11].gpio.pinmap = 43;
b->pins[11].gpio.parent_id = 0; b->pins[11].gpio.parent_id = 0;
b->pins[11].gpio.mux_total = 2; b->pins[11].gpio.mux_total = 2;
@@ -1250,7 +1248,7 @@ mraa_intel_edison_fab_c()
b->pins[11].spi.mux[1].value = 1; b->pins[11].spi.mux[1].value = 1;
strncpy(b->pins[12].name, "IO12", 8); strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[12].gpio.pinmap = 42; b->pins[12].gpio.pinmap = 42;
b->pins[12].gpio.parent_id = 0; b->pins[12].gpio.parent_id = 0;
b->pins[12].gpio.mux_total = 1; b->pins[12].gpio.mux_total = 1;
@@ -1262,7 +1260,7 @@ mraa_intel_edison_fab_c()
b->pins[12].spi.mux[0].value = 1; b->pins[12].spi.mux[0].value = 1;
strncpy(b->pins[13].name, "IO13", 8); strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[13].gpio.pinmap = 40; b->pins[13].gpio.pinmap = 40;
b->pins[13].gpio.parent_id = 0; b->pins[13].gpio.parent_id = 0;
b->pins[13].gpio.mux_total = 1; b->pins[13].gpio.mux_total = 1;
@@ -1274,7 +1272,7 @@ mraa_intel_edison_fab_c()
b->pins[13].spi.mux[0].value = 1; b->pins[13].spi.mux[0].value = 1;
strncpy(b->pins[14].name, "A0", 8); strncpy(b->pins[14].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].aio.pinmap = 0; b->pins[14].aio.pinmap = 0;
b->pins[14].aio.mux_total = 1; b->pins[14].aio.mux_total = 1;
b->pins[14].aio.mux[0].pin = 200; b->pins[14].aio.mux[0].pin = 200;
@@ -1285,7 +1283,7 @@ mraa_intel_edison_fab_c()
b->pins[14].gpio.mux[0].value = 0; b->pins[14].gpio.mux[0].value = 0;
strncpy(b->pins[15].name, "A1", 8); strncpy(b->pins[15].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].aio.pinmap = 1; b->pins[15].aio.pinmap = 1;
b->pins[15].aio.mux_total = 1; b->pins[15].aio.mux_total = 1;
b->pins[15].aio.mux[0].pin = 201; b->pins[15].aio.mux[0].pin = 201;
@@ -1296,7 +1294,7 @@ mraa_intel_edison_fab_c()
b->pins[15].gpio.mux[0].value = 0; b->pins[15].gpio.mux[0].value = 0;
strncpy(b->pins[16].name, "A2", 8); strncpy(b->pins[16].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].aio.pinmap = 2; b->pins[16].aio.pinmap = 2;
b->pins[16].aio.mux_total = 1; b->pins[16].aio.mux_total = 1;
b->pins[16].aio.mux[0].pin = 202; b->pins[16].aio.mux[0].pin = 202;
@@ -1307,7 +1305,7 @@ mraa_intel_edison_fab_c()
b->pins[16].gpio.mux[0].value = 0; b->pins[16].gpio.mux[0].value = 0;
strncpy(b->pins[17].name, "A3", 8); strncpy(b->pins[17].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].aio.pinmap = 3; b->pins[17].aio.pinmap = 3;
b->pins[17].aio.mux_total = 1; b->pins[17].aio.mux_total = 1;
b->pins[17].aio.mux[0].pin = 203; b->pins[17].aio.mux[0].pin = 203;
@@ -1318,7 +1316,7 @@ mraa_intel_edison_fab_c()
b->pins[17].gpio.mux[0].value = 0; b->pins[17].gpio.mux[0].value = 0;
strncpy(b->pins[18].name, "A4", 8); strncpy(b->pins[18].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1,0}; b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[18].i2c.pinmap = 1; b->pins[18].i2c.pinmap = 1;
b->pins[18].i2c.mux_total = 1; b->pins[18].i2c.mux_total = 1;
b->pins[18].i2c.mux[0].pin = 204; b->pins[18].i2c.mux[0].pin = 204;
@@ -1333,7 +1331,7 @@ mraa_intel_edison_fab_c()
b->pins[18].gpio.mux[0].value = 0; b->pins[18].gpio.mux[0].value = 0;
strncpy(b->pins[19].name, "A5", 8); strncpy(b->pins[19].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1,0}; b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[19].i2c.pinmap = 1; b->pins[19].i2c.pinmap = 1;
b->pins[19].i2c.mux_total = 1; b->pins[19].i2c.mux_total = 1;
b->pins[19].i2c.mux[0].pin = 205; b->pins[19].i2c.mux[0].pin = 205;
@@ -1347,7 +1345,7 @@ mraa_intel_edison_fab_c()
b->pins[19].gpio.mux[0].pin = 205; b->pins[19].gpio.mux[0].pin = 205;
b->pins[19].gpio.mux[0].value = 0; b->pins[19].gpio.mux[0].value = 0;
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 9; b->i2c_bus_count = 9;
b->def_i2c_bus = 6; b->def_i2c_bus = 6;
int ici; int ici;
@@ -1374,7 +1372,7 @@ mraa_intel_edison_fab_c()
b->uart_dev[0].device_path = UART_DEV_PATH; b->uart_dev[0].device_path = UART_DEV_PATH;
int il; int il;
for (il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) { for (il = 0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) {
pinmodes[il].gpio.sysfs = -1; pinmodes[il].gpio.sysfs = -1;
pinmodes[il].gpio.mode = -1; pinmodes[il].gpio.mode = -1;
pinmodes[il].pwm.sysfs = -1; pinmodes[il].pwm.sysfs = -1;
@@ -1416,7 +1414,7 @@ mraa_intel_edison_fab_c()
pinmodes[6].pwm.sysfs = 182; pinmodes[6].pwm.sysfs = 182;
pinmodes[6].pwm.mode = 1; pinmodes[6].pwm.mode = 1;
//7 and 8 are provided by something on i2c, very simplepinmodes[3].gpio.sysfs = 12; // 7 and 8 are provided by something on i2c, very simplepinmodes[3].gpio.sysfs = 12;
pinmodes[9].gpio.sysfs = 183; pinmodes[9].gpio.sysfs = 183;
pinmodes[9].gpio.mode = 0; pinmodes[9].gpio.mode = 0;
pinmodes[9].pwm.sysfs = 183; pinmodes[9].pwm.sysfs = 183;
@@ -1441,7 +1439,7 @@ mraa_intel_edison_fab_c()
pinmodes[13].gpio.mode = 0; pinmodes[13].gpio.mode = 0;
pinmodes[13].spi.sysfs = 109; // Different pin provides, switched at mux level. pinmodes[13].spi.sysfs = 109; // Different pin provides, switched at mux level.
pinmodes[13].spi.mode = 1; pinmodes[13].spi.mode = 1;
//Everything else but A4 A5 LEAVE // Everything else but A4 A5 LEAVE
pinmodes[18].gpio.sysfs = 14; pinmodes[18].gpio.sysfs = 14;
pinmodes[18].gpio.mode = 0; pinmodes[18].gpio.mode = 0;
pinmodes[18].i2c.sysfs = 28; pinmodes[18].i2c.sysfs = 28;

View File

@@ -32,7 +32,7 @@
#define UIO_PATH "/dev/uio0" #define UIO_PATH "/dev/uio0"
#define PLATFORM_NAME "Intel Galileo Gen 1" #define PLATFORM_NAME "Intel Galileo Gen 1"
static uint8_t *mmap_reg = NULL; static uint8_t* mmap_reg = NULL;
static int mmap_fd = 0; static int mmap_fd = 0;
static int mmap_size = 0x1000; static int mmap_size = 0x1000;
static unsigned int mmap_count = 0; static unsigned int mmap_count = 0;
@@ -55,10 +55,10 @@ mraa_intel_galileo_g1_mmap_write(mraa_gpio_context dev, int value)
{ {
int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos; int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos;
if (value) { if (value) {
*((unsigned *)mmap_reg) |= (1<<bitpos); *((unsigned*) mmap_reg) |= (1 << bitpos);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
*((unsigned *)mmap_reg) &= ~(1<<bitpos); *((unsigned*) mmap_reg) &= ~(1 << bitpos);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -97,8 +97,7 @@ mraa_intel_galileo_g1_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
syslog(LOG_ERR, "galileo1: Unable to open UIO device"); syslog(LOG_ERR, "galileo1: Unable to open UIO device");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
mmap_reg = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, mmap_reg = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, mmap_fd, 0);
MAP_SHARED, mmap_fd, 0);
if (mmap_reg == MAP_FAILED) { if (mmap_reg == MAP_FAILED) {
syslog(LOG_ERR, "galileo1: Mmap failed to mmap"); syslog(LOG_ERR, "galileo1: Mmap failed to mmap");
@@ -107,8 +106,7 @@ mraa_intel_galileo_g1_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_ERROR_NO_RESOURCES; return MRAA_ERROR_NO_RESOURCES;
} }
} }
if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio) if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio) != MRAA_SUCCESS) {
!= MRAA_SUCCESS) {
syslog(LOG_ERR, "galileo1: Unable to setup required multiplexers for mmap"); syslog(LOG_ERR, "galileo1: Unable to setup required multiplexers for mmap");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -139,14 +137,14 @@ mraa_intel_galileo_rev_d()
advance_func->gpio_mmap_setup = &mraa_intel_galileo_g1_mmap_setup; 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); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_GALILEO_REV_D_PINCOUNT);
if (b->pins == NULL) { if (b->pins == NULL) {
goto error; goto error;
} }
//GPIO IO0 - IO10 // GPIO IO0 - IO10
strncpy(b->pins[0].name, "IO0", 8); strncpy(b->pins[0].name, "IO0", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1}; b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[0].gpio.pinmap = 50; b->pins[0].gpio.pinmap = 50;
b->pins[0].gpio.parent_id = 0; b->pins[0].gpio.parent_id = 0;
b->pins[0].gpio.mux_total = 1; b->pins[0].gpio.mux_total = 1;
@@ -159,7 +157,7 @@ mraa_intel_galileo_rev_d()
b->pins[0].uart.mux[0].value = 0; b->pins[0].uart.mux[0].value = 0;
strncpy(b->pins[1].name, "IO1", 8); strncpy(b->pins[1].name, "IO1", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,1}; b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
b->pins[1].gpio.pinmap = 51; b->pins[1].gpio.pinmap = 51;
b->pins[1].gpio.mux_total = 1; b->pins[1].gpio.mux_total = 1;
b->pins[1].gpio.mux[0].pin = 41; b->pins[1].gpio.mux[0].pin = 41;
@@ -171,7 +169,7 @@ mraa_intel_galileo_rev_d()
b->pins[1].uart.mux[0].value = 0; b->pins[1].uart.mux[0].value = 0;
strncpy(b->pins[2].name, "IO2", 8); strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0,0}; b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 0, 0, 0, 0 };
b->pins[2].gpio.pinmap = 32; b->pins[2].gpio.pinmap = 32;
b->pins[2].gpio.mux_total = 1; b->pins[2].gpio.mux_total = 1;
b->pins[2].gpio.mux[0].pin = 31; b->pins[2].gpio.mux[0].pin = 31;
@@ -187,7 +185,7 @@ mraa_intel_galileo_rev_d()
b->pins[2].mmap.bit_pos = 6; b->pins[2].mmap.bit_pos = 6;
strncpy(b->pins[3].name, "IO3", 8); strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t) {1,1,1,1,0,0,0,0}; b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 0, 0, 0, 0 };
b->pins[3].gpio.pinmap = 18; b->pins[3].gpio.pinmap = 18;
b->pins[3].gpio.mux_total = 1; b->pins[3].gpio.mux_total = 1;
b->pins[3].gpio.mux[0].pin = 30; b->pins[3].gpio.mux[0].pin = 30;
@@ -209,12 +207,12 @@ mraa_intel_galileo_rev_d()
strncpy(b->pins[4].name, "IO4", 8); strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 28; b->pins[4].gpio.pinmap = 28;
b->pins[4].gpio.mux_total = 0; b->pins[4].gpio.mux_total = 0;
strncpy(b->pins[5].name, "IO5", 8); strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[5].gpio.pinmap = 17; b->pins[5].gpio.pinmap = 17;
b->pins[5].gpio.mux_total = 0; b->pins[5].gpio.mux_total = 0;
b->pins[5].pwm.pinmap = 5; b->pins[5].pwm.pinmap = 5;
@@ -223,24 +221,24 @@ mraa_intel_galileo_rev_d()
strncpy(b->pins[6].name, "IO6", 8); strncpy(b->pins[6].name, "IO6", 8);
b->pins[6].gpio.pinmap = 24; b->pins[6].gpio.pinmap = 24;
b->pins[6].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[6].gpio.mux_total = 0; b->pins[6].gpio.mux_total = 0;
b->pins[6].pwm.pinmap = 6; b->pins[6].pwm.pinmap = 6;
b->pins[6].pwm.parent_id = 0; b->pins[6].pwm.parent_id = 0;
b->pins[6].pwm.mux_total = 0; b->pins[6].pwm.mux_total = 0;
strncpy(b->pins[7].name, "IO7", 8); strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 27; b->pins[7].gpio.pinmap = 27;
b->pins[7].gpio.mux_total = 0; b->pins[7].gpio.mux_total = 0;
strncpy(b->pins[8].name, "IO8", 8); strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 26; b->pins[8].gpio.pinmap = 26;
b->pins[8].gpio.mux_total = 0; b->pins[8].gpio.mux_total = 0;
strncpy(b->pins[9].name, "IO9", 8); strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0,0}; b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 19; b->pins[9].gpio.pinmap = 19;
b->pins[9].gpio.mux_total = 0; b->pins[9].gpio.mux_total = 0;
b->pins[9].pwm.pinmap = 1; b->pins[9].pwm.pinmap = 1;
@@ -248,7 +246,7 @@ mraa_intel_galileo_rev_d()
b->pins[9].pwm.mux_total = 0; b->pins[9].pwm.mux_total = 0;
strncpy(b->pins[10].name, "IO10", 8); strncpy(b->pins[10].name, "IO10", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,1,1,0,1,0,0,0}; b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 0 };
b->pins[10].gpio.pinmap = 16; b->pins[10].gpio.pinmap = 16;
b->pins[10].gpio.mux_total = 1; b->pins[10].gpio.mux_total = 1;
b->pins[10].gpio.mux[0].pin = 42; b->pins[10].gpio.mux[0].pin = 42;
@@ -264,7 +262,7 @@ mraa_intel_galileo_rev_d()
b->pins[10].spi.mux[0].value = 0; b->pins[10].spi.mux[0].value = 0;
strncpy(b->pins[11].name, "IO11", 8); strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t) {1,1,1,0,1,0,0,0}; b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0, 0 };
b->pins[11].gpio.pinmap = 25; b->pins[11].gpio.pinmap = 25;
b->pins[11].gpio.mux_total = 1; b->pins[11].gpio.mux_total = 1;
b->pins[11].gpio.mux[0].pin = 43; b->pins[11].gpio.mux[0].pin = 43;
@@ -280,7 +278,7 @@ mraa_intel_galileo_rev_d()
b->pins[11].spi.mux[0].value = 0; b->pins[11].spi.mux[0].value = 0;
strncpy(b->pins[12].name, "IO12", 8); strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[12].gpio.pinmap = 38; b->pins[12].gpio.pinmap = 38;
b->pins[12].gpio.mux_total = 1; b->pins[12].gpio.mux_total = 1;
b->pins[12].gpio.mux[0].pin = 54; b->pins[12].gpio.mux[0].pin = 54;
@@ -291,7 +289,7 @@ mraa_intel_galileo_rev_d()
b->pins[12].spi.mux[0].value = 0; b->pins[12].spi.mux[0].value = 0;
strncpy(b->pins[13].name, "IO13", 8); strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0,0}; b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
b->pins[13].gpio.pinmap = 39; b->pins[13].gpio.pinmap = 39;
b->pins[13].gpio.mux_total = 1; b->pins[13].gpio.mux_total = 1;
b->pins[13].gpio.mux[0].pin = 55; b->pins[13].gpio.mux[0].pin = 55;
@@ -302,7 +300,7 @@ mraa_intel_galileo_rev_d()
b->pins[13].spi.mux[0].value = 0; b->pins[13].spi.mux[0].value = 0;
strncpy(b->pins[14].name, "A0", 8); strncpy(b->pins[14].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[14].gpio.pinmap = 44; b->pins[14].gpio.pinmap = 44;
b->pins[14].gpio.mux_total = 1; b->pins[14].gpio.mux_total = 1;
b->pins[14].gpio.mux[0].pin = 37; b->pins[14].gpio.mux[0].pin = 37;
@@ -313,7 +311,7 @@ mraa_intel_galileo_rev_d()
b->pins[14].aio.mux[0].value = 0; b->pins[14].aio.mux[0].value = 0;
strncpy(b->pins[15].name, "A1", 8); strncpy(b->pins[15].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[15].gpio.pinmap = 45; b->pins[15].gpio.pinmap = 45;
b->pins[15].gpio.mux_total = 1; b->pins[15].gpio.mux_total = 1;
b->pins[15].gpio.mux[0].pin = 36; b->pins[15].gpio.mux[0].pin = 36;
@@ -324,7 +322,7 @@ mraa_intel_galileo_rev_d()
b->pins[15].aio.mux[0].value = 0; b->pins[15].aio.mux[0].value = 0;
strncpy(b->pins[16].name, "A2", 8); strncpy(b->pins[16].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[16].gpio.pinmap = 46; b->pins[16].gpio.pinmap = 46;
b->pins[16].gpio.mux_total = 1; b->pins[16].gpio.mux_total = 1;
b->pins[16].gpio.mux[0].pin = 23; b->pins[16].gpio.mux[0].pin = 23;
@@ -335,7 +333,7 @@ mraa_intel_galileo_rev_d()
b->pins[16].aio.mux[0].value = 0; b->pins[16].aio.mux[0].value = 0;
strncpy(b->pins[17].name, "A3", 8); strncpy(b->pins[17].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1,0}; b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1, 0 };
b->pins[17].gpio.pinmap = 47; b->pins[17].gpio.pinmap = 47;
b->pins[17].gpio.mux_total = 1; b->pins[17].gpio.mux_total = 1;
b->pins[17].gpio.mux[0].pin = 22; b->pins[17].gpio.mux[0].pin = 22;
@@ -346,7 +344,7 @@ mraa_intel_galileo_rev_d()
b->pins[17].aio.mux[0].value = 0; b->pins[17].aio.mux[0].value = 0;
strncpy(b->pins[18].name, "A4", 8); strncpy(b->pins[18].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1,0}; b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[18].gpio.pinmap = 48; b->pins[18].gpio.pinmap = 48;
b->pins[18].gpio.mux_total = 2; b->pins[18].gpio.mux_total = 2;
b->pins[18].gpio.mux[0].pin = 29; b->pins[18].gpio.mux[0].pin = 29;
@@ -365,7 +363,7 @@ mraa_intel_galileo_rev_d()
b->pins[18].aio.mux[1].value = 0; b->pins[18].aio.mux[1].value = 0;
strncpy(b->pins[19].name, "A5", 8); strncpy(b->pins[19].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1,0}; b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1, 0 };
b->pins[19].gpio.pinmap = 49; b->pins[19].gpio.pinmap = 49;
b->pins[19].gpio.mux_total = 2; b->pins[19].gpio.mux_total = 2;
b->pins[19].gpio.mux[0].pin = 29; b->pins[19].gpio.mux[0].pin = 29;
@@ -383,7 +381,7 @@ mraa_intel_galileo_rev_d()
b->pins[19].aio.mux[1].pin = 20; b->pins[19].aio.mux[1].pin = 20;
b->pins[19].aio.mux[1].value = 0; b->pins[19].aio.mux[1].value = 0;
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 1; b->i2c_bus_count = 1;
b->def_i2c_bus = 0; b->def_i2c_bus = 0;
b->i2c_bus[0].bus_id = 0; b->i2c_bus[0].bus_id = 0;

View File

@@ -36,12 +36,13 @@
#define UIO_PATH "/dev/uio0" #define UIO_PATH "/dev/uio0"
static uint8_t *mmap_reg = NULL; static uint8_t* mmap_reg = NULL;
static int mmap_fd = 0; static int mmap_fd = 0;
static int mmap_size = 0x1000; static int mmap_size = 0x1000;
static unsigned int mmap_count = 0; 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}; 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 };
static mraa_gpio_context agpioOutputen[MRAA_INTEL_GALILEO_GEN_2_PINCOUNT]; static mraa_gpio_context agpioOutputen[MRAA_INTEL_GALILEO_GEN_2_PINCOUNT];
@@ -120,7 +121,7 @@ mraa_result_t
mraa_intel_galileo_gen2_pwm_period_replace(mraa_pwm_context dev, int period) mraa_intel_galileo_gen2_pwm_period_replace(mraa_pwm_context dev, int period)
{ {
char bu[MAX_SIZE]; char bu[MAX_SIZE];
snprintf(bu,MAX_SIZE ,"/sys/class/pwm/pwmchip%d/device/pwm_period", dev->chipid); snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/device/pwm_period", dev->chipid);
int period_f = open(bu, O_RDWR); int period_f = open(bu, O_RDWR);
if (period_f == -1) { if (period_f == -1) {
@@ -129,7 +130,7 @@ mraa_intel_galileo_gen2_pwm_period_replace(mraa_pwm_context dev, int period)
} }
char out[MAX_SIZE]; char out[MAX_SIZE];
int length = snprintf(out, MAX_SIZE, "%d", period); int length = snprintf(out, MAX_SIZE, "%d", period);
if (write(period_f, out, length*sizeof(char)) == -1) { if (write(period_f, out, length * sizeof(char)) == -1) {
close(period_f); close(period_f);
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -169,7 +170,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
char bu[MAX_SIZE]; char bu[MAX_SIZE];
int length; int length;
int value = -1; int value = -1;
switch(mode) { switch (mode) {
case MRAA_GPIO_STRONG: case MRAA_GPIO_STRONG:
length = snprintf(bu, sizeof(bu), "hiz"); length = snprintf(bu, sizeof(bu), "hiz");
break; break;
@@ -189,7 +190,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
close(drive); close(drive);
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
} }
if (write(drive, bu, length*sizeof(char)) == -1) { if (write(drive, bu, length * sizeof(char)) == -1) {
syslog(LOG_ERR, "galileo2: Failed to write to drive mode"); syslog(LOG_ERR, "galileo2: Failed to write to drive mode");
close(drive); close(drive);
mraa_gpio_close(pullup_e); mraa_gpio_close(pullup_e);
@@ -257,10 +258,10 @@ mraa_intel_galileo_g2_mmap_write(mraa_gpio_context dev, int value)
{ {
int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos; int bitpos = plat->pins[dev->phy_pin].mmap.bit_pos;
if (value) { if (value) {
*((unsigned *)mmap_reg) |= (1<<bitpos); *((unsigned*) mmap_reg) |= (1 << bitpos);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
*((unsigned *)mmap_reg) &= ~(1<<bitpos); *((unsigned*) mmap_reg) &= ~(1 << bitpos);
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -299,8 +300,7 @@ mraa_intel_galileo_g2_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
syslog(LOG_ERR, "mmap: Unable to open UIO device"); syslog(LOG_ERR, "mmap: Unable to open UIO device");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
mmap_reg = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, mmap_reg = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, mmap_fd, 0);
MAP_SHARED, mmap_fd, 0);
if (mmap_reg == MAP_FAILED) { if (mmap_reg == MAP_FAILED) {
syslog(LOG_ERR, "mmap: failed to mmap"); syslog(LOG_ERR, "mmap: failed to mmap");
@@ -309,8 +309,7 @@ mraa_intel_galileo_g2_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
return MRAA_ERROR_NO_RESOURCES; return MRAA_ERROR_NO_RESOURCES;
} }
} }
if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio) if (mraa_setup_mux_mapped(plat->pins[dev->phy_pin].mmap.gpio) != MRAA_SUCCESS) {
!= MRAA_SUCCESS) {
syslog(LOG_ERR, "mmap: unable to setup required multiplexers"); syslog(LOG_ERR, "mmap: unable to setup required multiplexers");
return MRAA_ERROR_INVALID_RESOURCE; return MRAA_ERROR_INVALID_RESOURCE;
} }
@@ -344,17 +343,17 @@ mraa_intel_galileo_gen2()
advance_func->uart_init_pre = &mraa_intel_galileo_gen2_uart_init_pre; advance_func->uart_init_pre = &mraa_intel_galileo_gen2_uart_init_pre;
advance_func->gpio_mmap_setup = &mraa_intel_galileo_g2_mmap_setup; 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); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_GALILEO_GEN_2_PINCOUNT);
if (b->pins == NULL) { if (b->pins == NULL) {
goto error; goto error;
} }
strncpy(b->pins[0].name, "IO0", 8); strncpy(b->pins[0].name, "IO0", 8);
b->pins[0].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0,1}; 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.pinmap = 11;
b->pins[0].gpio.parent_id = 0; b->pins[0].gpio.parent_id = 0;
b->pins[0].gpio.mux_total = 0; b->pins[0].gpio.mux_total = 0;
b->pins[0].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[0].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[0].gpio.output_enable = 32; b->pins[0].gpio.output_enable = 32;
b->pins[0].gpio.pullup_enable = 33; b->pins[0].gpio.pullup_enable = 33;
b->pins[0].mmap.gpio.pinmap = 11; b->pins[0].mmap.gpio.pinmap = 11;
@@ -370,13 +369,13 @@ mraa_intel_galileo_gen2()
b->pins[0].uart.mux_total = 0; b->pins[0].uart.mux_total = 0;
strncpy(b->pins[1].name, "IO1", 8); strncpy(b->pins[1].name, "IO1", 8);
b->pins[1].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0,1}; 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.pinmap = 12;
b->pins[1].gpio.parent_id = 0; b->pins[1].gpio.parent_id = 0;
b->pins[1].gpio.mux_total = 1; b->pins[1].gpio.mux_total = 1;
b->pins[1].gpio.mux[0].pin = 45; b->pins[1].gpio.mux[0].pin = 45;
b->pins[1].gpio.mux[0].value = 0; b->pins[1].gpio.mux[0].value = 0;
b->pins[1].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[1].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[1].gpio.output_enable = 28; b->pins[1].gpio.output_enable = 28;
b->pins[1].gpio.pullup_enable = 29; b->pins[1].gpio.pullup_enable = 29;
b->pins[1].mmap.gpio.pinmap = 12; b->pins[1].mmap.gpio.pinmap = 12;
@@ -396,13 +395,13 @@ mraa_intel_galileo_gen2()
b->pins[1].uart.mux[0].value = 1; b->pins[1].uart.mux[0].value = 1;
strncpy(b->pins[2].name, "IO2", 8); strncpy(b->pins[2].name, "IO2", 8);
b->pins[2].capabilites = (mraa_pincapabilities_t) {1,1,0,1,0,0,0}; b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 0, 0, 0 };
b->pins[2].gpio.pinmap = 13; b->pins[2].gpio.pinmap = 13;
b->pins[2].gpio.parent_id = 0; b->pins[2].gpio.parent_id = 0;
b->pins[2].gpio.mux_total = 1; b->pins[2].gpio.mux_total = 1;
b->pins[2].gpio.mux[0].pin = 77; b->pins[2].gpio.mux[0].pin = 77;
b->pins[2].gpio.mux[0].value = 0; b->pins[2].gpio.mux[0].value = 0;
b->pins[2].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[2].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[2].gpio.output_enable = 34; b->pins[2].gpio.output_enable = 34;
b->pins[2].gpio.pullup_enable = 35; b->pins[2].gpio.pullup_enable = 35;
b->pins[2].mmap.gpio.pinmap = 13; b->pins[2].mmap.gpio.pinmap = 13;
@@ -418,7 +417,7 @@ mraa_intel_galileo_gen2()
b->pins[2].mmap.bit_pos = 5; b->pins[2].mmap.bit_pos = 5;
strncpy(b->pins[3].name, "IO3", 8); strncpy(b->pins[3].name, "IO3", 8);
b->pins[3].capabilites = (mraa_pincapabilities_t) {1,1,1,1,0,0,0}; b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 1, 0, 0, 0 };
b->pins[3].gpio.pinmap = 14; b->pins[3].gpio.pinmap = 14;
b->pins[3].gpio.parent_id = 0; b->pins[3].gpio.parent_id = 0;
b->pins[3].gpio.mux_total = 2; b->pins[3].gpio.mux_total = 2;
@@ -426,7 +425,7 @@ mraa_intel_galileo_gen2()
b->pins[3].gpio.mux[0].value = 0; b->pins[3].gpio.mux[0].value = 0;
b->pins[3].gpio.mux[1].pin = 64; b->pins[3].gpio.mux[1].pin = 64;
b->pins[3].gpio.mux[1].value = 0; b->pins[3].gpio.mux[1].value = 0;
b->pins[3].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[3].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[3].gpio.output_enable = 16; b->pins[3].gpio.output_enable = 16;
b->pins[3].gpio.pullup_enable = 17; b->pins[3].gpio.pullup_enable = 17;
b->pins[3].pwm.pinmap = 1; b->pins[3].pwm.pinmap = 1;
@@ -453,22 +452,22 @@ mraa_intel_galileo_gen2()
b->pins[3].mmap.bit_pos = 6; b->pins[3].mmap.bit_pos = 6;
strncpy(b->pins[4].name, "IO4", 8); strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[4].gpio.pinmap = 6; b->pins[4].gpio.pinmap = 6;
b->pins[4].gpio.parent_id = 0; b->pins[4].gpio.parent_id = 0;
b->pins[4].gpio.mux_total = 0; b->pins[4].gpio.mux_total = 0;
b->pins[4].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[4].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[4].gpio.output_enable = 36; b->pins[4].gpio.output_enable = 36;
b->pins[4].gpio.pullup_enable = 37; b->pins[4].gpio.pullup_enable = 37;
strncpy(b->pins[5].name, "IO5", 8); strncpy(b->pins[5].name, "IO5", 8);
b->pins[5].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0}; b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[5].gpio.pinmap = 0; b->pins[5].gpio.pinmap = 0;
b->pins[5].gpio.parent_id = 0; b->pins[5].gpio.parent_id = 0;
b->pins[5].gpio.mux_total = 1; b->pins[5].gpio.mux_total = 1;
b->pins[5].gpio.mux[0].pin = 66; b->pins[5].gpio.mux[0].pin = 66;
b->pins[5].gpio.mux[0].value = 0; b->pins[5].gpio.mux[0].value = 0;
b->pins[5].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[5].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[5].gpio.output_enable = 18; b->pins[5].gpio.output_enable = 18;
b->pins[5].gpio.pullup_enable = 19; b->pins[5].gpio.pullup_enable = 19;
b->pins[5].pwm.pinmap = 3; b->pins[5].pwm.pinmap = 3;
@@ -480,13 +479,13 @@ mraa_intel_galileo_gen2()
b->pins[5].pwm.mux[1].value = 0; b->pins[5].pwm.mux[1].value = 0;
strncpy(b->pins[6].name, "IO6", 8); strncpy(b->pins[6].name, "IO6", 8);
b->pins[6].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0}; b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[6].gpio.pinmap = 1; b->pins[6].gpio.pinmap = 1;
b->pins[6].gpio.parent_id = 0; b->pins[6].gpio.parent_id = 0;
b->pins[6].gpio.mux_total = 1; b->pins[6].gpio.mux_total = 1;
b->pins[6].gpio.mux[0].pin = 68; b->pins[6].gpio.mux[0].pin = 68;
b->pins[6].gpio.mux[0].value = 0; b->pins[6].gpio.mux[0].value = 0;
b->pins[6].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[6].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[6].gpio.output_enable = 20; b->pins[6].gpio.output_enable = 20;
b->pins[6].gpio.pullup_enable = 21; b->pins[6].gpio.pullup_enable = 21;
b->pins[6].pwm.pinmap = 5; b->pins[6].pwm.pinmap = 5;
@@ -498,29 +497,29 @@ mraa_intel_galileo_gen2()
b->pins[6].pwm.mux[1].value = 0; b->pins[6].pwm.mux[1].value = 0;
strncpy(b->pins[7].name, "IO7", 8); strncpy(b->pins[7].name, "IO7", 8);
b->pins[7].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[7].gpio.pinmap = 38; b->pins[7].gpio.pinmap = 38;
b->pins[7].gpio.parent_id = 0; b->pins[7].gpio.parent_id = 0;
b->pins[7].gpio.mux_total = 0; b->pins[7].gpio.mux_total = 0;
b->pins[7].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[7].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[7].gpio.pullup_enable = 39; b->pins[7].gpio.pullup_enable = 39;
strncpy(b->pins[8].name, "IO8", 8); strncpy(b->pins[8].name, "IO8", 8);
b->pins[8].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0}; b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0 };
b->pins[8].gpio.pinmap = 40; b->pins[8].gpio.pinmap = 40;
b->pins[8].gpio.parent_id = 0; b->pins[8].gpio.parent_id = 0;
b->pins[8].gpio.mux_total = 0; b->pins[8].gpio.mux_total = 0;
b->pins[8].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[8].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[8].gpio.pullup_enable = 41; b->pins[8].gpio.pullup_enable = 41;
strncpy(b->pins[9].name, "IO9", 8); strncpy(b->pins[9].name, "IO9", 8);
b->pins[9].capabilites = (mraa_pincapabilities_t) {1,1,1,0,0,0,0}; b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0 };
b->pins[9].gpio.pinmap = 4; b->pins[9].gpio.pinmap = 4;
b->pins[9].gpio.parent_id = 0; b->pins[9].gpio.parent_id = 0;
b->pins[9].gpio.mux_total = 1; b->pins[9].gpio.mux_total = 1;
b->pins[9].gpio.mux[0].pin = 70; b->pins[9].gpio.mux[0].pin = 70;
b->pins[9].gpio.mux[0].value = 0; b->pins[9].gpio.mux[0].value = 0;
b->pins[9].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[9].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[9].gpio.output_enable = 22; b->pins[9].gpio.output_enable = 22;
b->pins[9].gpio.pullup_enable = 23; b->pins[9].gpio.pullup_enable = 23;
b->pins[9].pwm.pinmap = 7; b->pins[9].pwm.pinmap = 7;
@@ -532,13 +531,13 @@ mraa_intel_galileo_gen2()
b->pins[9].pwm.mux[1].value = 0; b->pins[9].pwm.mux[1].value = 0;
strncpy(b->pins[10].name, "IO10", 8); strncpy(b->pins[10].name, "IO10", 8);
b->pins[10].capabilites = (mraa_pincapabilities_t) {1,1,1,1,1,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.pinmap = 10;
b->pins[10].gpio.parent_id = 0; b->pins[10].gpio.parent_id = 0;
b->pins[10].gpio.mux_total = 1; b->pins[10].gpio.mux_total = 1;
b->pins[10].gpio.mux[0].pin = 74; b->pins[10].gpio.mux[0].pin = 74;
b->pins[10].gpio.mux[0].value = 0; b->pins[10].gpio.mux[0].value = 0;
b->pins[10].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[10].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[10].gpio.output_enable = 26; b->pins[10].gpio.output_enable = 26;
b->pins[10].gpio.pullup_enable = 27; b->pins[10].gpio.pullup_enable = 27;
b->pins[10].pwm.pinmap = 11; b->pins[10].pwm.pinmap = 11;
@@ -565,7 +564,7 @@ mraa_intel_galileo_gen2()
b->pins[10].spi.mux[0].value = 0; b->pins[10].spi.mux[0].value = 0;
strncpy(b->pins[11].name, "IO11", 8); strncpy(b->pins[11].name, "IO11", 8);
b->pins[11].capabilites = (mraa_pincapabilities_t) {1,1,1,0,1,0,0}; b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 1, 0, 0 };
b->pins[11].gpio.pinmap = 5; b->pins[11].gpio.pinmap = 5;
b->pins[11].gpio.parent_id = 0; b->pins[11].gpio.parent_id = 0;
b->pins[11].gpio.mux_total = 2; b->pins[11].gpio.mux_total = 2;
@@ -573,7 +572,7 @@ mraa_intel_galileo_gen2()
b->pins[11].gpio.mux[0].value = 0; b->pins[11].gpio.mux[0].value = 0;
b->pins[11].gpio.mux[1].pin = 44; b->pins[11].gpio.mux[1].pin = 44;
b->pins[11].gpio.mux[1].value = 0; b->pins[11].gpio.mux[1].value = 0;
b->pins[11].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[11].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[11].gpio.output_enable = 24; b->pins[11].gpio.output_enable = 24;
b->pins[11].gpio.pullup_enable = 25; b->pins[11].gpio.pullup_enable = 25;
b->pins[11].pwm.pinmap = 9; b->pins[11].pwm.pinmap = 9;
@@ -595,11 +594,11 @@ mraa_intel_galileo_gen2()
b->pins[11].spi.mux[2].value = 0; b->pins[11].spi.mux[2].value = 0;
strncpy(b->pins[12].name, "IO12", 8); strncpy(b->pins[12].name, "IO12", 8);
b->pins[12].capabilites = (mraa_pincapabilities_t) {1,1,0,1,1,0,0}; b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 1, 1, 0, 0 };
b->pins[12].gpio.pinmap = 15; b->pins[12].gpio.pinmap = 15;
b->pins[12].gpio.parent_id = 0; b->pins[12].gpio.parent_id = 0;
b->pins[12].gpio.mux_total = 0; b->pins[12].gpio.mux_total = 0;
b->pins[12].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[12].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[12].gpio.output_enable = 42; b->pins[12].gpio.output_enable = 42;
b->pins[12].gpio.pullup_enable = 43; b->pins[12].gpio.pullup_enable = 43;
b->pins[12].spi.pinmap = 1; b->pins[12].spi.pinmap = 1;
@@ -617,13 +616,13 @@ mraa_intel_galileo_gen2()
b->pins[12].mmap.bit_pos = 7; b->pins[12].mmap.bit_pos = 7;
strncpy(b->pins[13].name, "IO13", 8); strncpy(b->pins[13].name, "IO13", 8);
b->pins[13].capabilites = (mraa_pincapabilities_t) {1,1,0,0,1,0,0}; b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0 };
b->pins[13].gpio.pinmap = 7; b->pins[13].gpio.pinmap = 7;
b->pins[13].gpio.parent_id = 0; b->pins[13].gpio.parent_id = 0;
b->pins[13].gpio.mux_total = 1; b->pins[13].gpio.mux_total = 1;
b->pins[13].gpio.mux[0].pin = 46; b->pins[13].gpio.mux[0].pin = 46;
b->pins[13].gpio.mux[0].value = 0; b->pins[13].gpio.mux[0].value = 0;
b->pins[13].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,1,0,1,1}; b->pins[13].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
b->pins[13].gpio.output_enable = 30; b->pins[13].gpio.output_enable = 30;
b->pins[13].gpio.pullup_enable = 31; b->pins[13].gpio.pullup_enable = 31;
b->pins[13].spi.pinmap = 1; b->pins[13].spi.pinmap = 1;
@@ -633,10 +632,10 @@ mraa_intel_galileo_gen2()
b->pins[13].spi.mux[1].pin = 30; b->pins[13].spi.mux[1].pin = 30;
b->pins[13].spi.mux[1].value = 0; b->pins[13].spi.mux[1].value = 0;
//ANALOG // ANALOG
strncpy(b->pins[14].name, "A0", 8); strncpy(b->pins[14].name, "A0", 8);
b->pins[14].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1}; b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[14].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[14].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[14].gpio.pullup_enable = 49; b->pins[14].gpio.pullup_enable = 49;
b->pins[14].aio.pinmap = 0; b->pins[14].aio.pinmap = 0;
b->pins[14].aio.mux_total = 1; b->pins[14].aio.mux_total = 1;
@@ -646,8 +645,8 @@ mraa_intel_galileo_gen2()
b->pins[14].gpio.mux_total = 0; b->pins[14].gpio.mux_total = 0;
strncpy(b->pins[15].name, "A1", 8); strncpy(b->pins[15].name, "A1", 8);
b->pins[15].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1}; b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[15].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[15].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[15].gpio.pullup_enable = 51; b->pins[15].gpio.pullup_enable = 51;
b->pins[15].aio.pinmap = 1; b->pins[15].aio.pinmap = 1;
b->pins[15].aio.mux[0].pin = 51; b->pins[15].aio.mux[0].pin = 51;
@@ -657,8 +656,8 @@ mraa_intel_galileo_gen2()
b->pins[15].gpio.mux_total = 0; b->pins[15].gpio.mux_total = 0;
strncpy(b->pins[16].name, "A2", 8); strncpy(b->pins[16].name, "A2", 8);
b->pins[16].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1}; b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[16].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[16].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[16].gpio.pullup_enable = 53; b->pins[16].gpio.pullup_enable = 53;
b->pins[16].aio.pinmap = 2; b->pins[16].aio.pinmap = 2;
b->pins[16].aio.mux_total = 1; b->pins[16].aio.mux_total = 1;
@@ -668,8 +667,8 @@ mraa_intel_galileo_gen2()
b->pins[16].gpio.mux_total = 0; b->pins[16].gpio.mux_total = 0;
strncpy(b->pins[17].name, "A3", 8); strncpy(b->pins[17].name, "A3", 8);
b->pins[17].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,1}; b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 1 };
b->pins[17].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[17].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[17].gpio.pullup_enable = 55; b->pins[17].gpio.pullup_enable = 55;
b->pins[17].aio.pinmap = 3; b->pins[17].aio.pinmap = 3;
b->pins[17].aio.mux_total = 1; b->pins[17].aio.mux_total = 1;
@@ -679,8 +678,8 @@ mraa_intel_galileo_gen2()
b->pins[17].gpio.mux_total = 0; b->pins[17].gpio.mux_total = 0;
strncpy(b->pins[18].name, "A4", 8); strncpy(b->pins[18].name, "A4", 8);
b->pins[18].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1}; b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1 };
b->pins[18].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[18].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[18].gpio.pullup_enable = 57; b->pins[18].gpio.pullup_enable = 57;
b->pins[18].i2c.pinmap = 1; b->pins[18].i2c.pinmap = 1;
b->pins[18].i2c.mux_total = 1; b->pins[18].i2c.mux_total = 1;
@@ -702,8 +701,8 @@ mraa_intel_galileo_gen2()
b->pins[18].gpio.mux[1].value = 1; b->pins[18].gpio.mux[1].value = 1;
strncpy(b->pins[19].name, "A5", 8); strncpy(b->pins[19].name, "A5", 8);
b->pins[19].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,1,1}; b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 1 };
b->pins[19].gpio.complex_cap = (mraa_pin_cap_complex_t) {1,0,0,1,1}; b->pins[19].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 0, 0, 1, 1 };
b->pins[19].gpio.pullup_enable = 59; b->pins[19].gpio.pullup_enable = 59;
b->pins[19].i2c.pinmap = 1; b->pins[19].i2c.pinmap = 1;
b->pins[19].i2c.mux_total = 1; b->pins[19].i2c.mux_total = 1;
@@ -724,7 +723,7 @@ mraa_intel_galileo_gen2()
b->pins[19].gpio.mux[1].pin = 79; b->pins[19].gpio.mux[1].pin = 79;
b->pins[19].gpio.mux[1].value = 1; b->pins[19].gpio.mux[1].value = 1;
//BUS DEFINITIONS // BUS DEFINITIONS
b->i2c_bus_count = 1; b->i2c_bus_count = 1;
b->def_i2c_bus = 0; b->def_i2c_bus = 0;
b->i2c_bus[0].bus_id = 0; b->i2c_bus[0].bus_id = 0;

View File

@@ -37,7 +37,7 @@
int arch_nr_gpios_adjust = 0x100; int arch_nr_gpios_adjust = 0x100;
mraa_result_t mraa_result_t
mraa_set_pininfo(mraa_board_t* board, int mraa_index, char *name, mraa_pincapabilities_t caps, int sysfs_pin) 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) { if (mraa_index < board->phy_pin_count) {
// adjust mraa_index for ARCH_NR_GPIOS value // adjust mraa_index for ARCH_NR_GPIOS value
@@ -69,7 +69,8 @@ mraa_set_pininfo(mraa_board_t* board, int mraa_index, char *name, mraa_pincapabi
} }
mraa_result_t mraa_result_t
mraa_get_pin_index(mraa_board_t* board, char *name, int* pin_index) { mraa_get_pin_index(mraa_board_t* board, char* name, int* pin_index)
{
int i; int i;
for (i = 0; i < board->phy_pin_count; ++i) { for (i = 0; i < board->phy_pin_count; ++i) {
if (strcmp(name, board->pins[i].name) == 0) { if (strcmp(name, board->pins[i].name) == 0) {
@@ -99,7 +100,7 @@ mraa_intel_minnow_max()
b->adc_raw = 0; b->adc_raw = 0;
b->adc_supported = 0; b->adc_supported = 0;
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_MINNOW_MAX_PINCOUNT); b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_MINNOW_MAX_PINCOUNT);
if (b->pins == NULL) { if (b->pins == NULL) {
goto error; goto error;
} }
@@ -115,37 +116,39 @@ mraa_intel_minnow_max()
* they start at 512 and number down, at some point this is going to change again when * they start at 512 and number down, at some point this is going to change again when
* GPIO moves to a radix. * GPIO moves to a radix.
*/ */
if (uname_major <= 3 && uname_minor <= 17 ) { if (uname_major <= 3 && uname_minor <= 17) {
arch_nr_gpios_adjust = 0; arch_nr_gpios_adjust = 0;
} }
mraa_set_pininfo(b, 0, "INVALID", (mraa_pincapabilities_t){0,0,0,0,0,0,0,0}, -1 ); 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, 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, 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, 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, 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, 5, "SPI_CS", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 220);
mraa_set_pininfo(b, 6, "UART1TX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 225); mraa_set_pininfo(b, 6, "UART1TX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 225);
mraa_set_pininfo(b, 7, "SPIMISO", (mraa_pincapabilities_t){1,0,0,0,1,0,0,0}, 221); mraa_set_pininfo(b, 7, "SPIMISO", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 221);
mraa_set_pininfo(b, 8, "UART1RX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 224); mraa_set_pininfo(b, 8, "UART1RX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 224);
mraa_set_pininfo(b, 9, "SPIMOSI", (mraa_pincapabilities_t){1,0,0,0,1,0,0,0}, 222); mraa_set_pininfo(b, 9, "SPIMOSI", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 222);
mraa_set_pininfo(b, 10, "UART1CT", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 227); mraa_set_pininfo(b, 10, "UART1CT", (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, 11, "SPI_CLK", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 223);
mraa_set_pininfo(b, 12, "UART1RT", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 226); mraa_set_pininfo(b, 12, "UART1RT", (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, 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, 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, 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, 16, "I2S_FRM", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 217);
mraa_set_pininfo(b, 17, "UART2TX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 229); mraa_set_pininfo(b, 17, "UART2TX", (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, 18, "I2S_DO", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 219);
mraa_set_pininfo(b, 19, "UART2RX", (mraa_pincapabilities_t){1,0,0,0,0,0,0,1}, 228); mraa_set_pininfo(b, 19, "UART2RX", (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, 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, 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, 22, "PWM0", (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 },
mraa_set_pininfo(b, 23, "S5_1", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 83 ); 248); // Assume BIOS configured for PWM
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, 23, "S5_1", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 83);
mraa_set_pininfo(b, 25, "S5_4", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 84 ); mraa_set_pininfo(b, 24, "PWM1", (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 },
mraa_set_pininfo(b, 26, "IBL8254", (mraa_pincapabilities_t){1,1,0,0,0,0,0,0}, 208); 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, "IBL8254", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 208);
// Set number of i2c adaptors // Set number of i2c adaptors
// Got this from running 'i2cdetect -l' // Got this from running 'i2cdetect -l'

View File

@@ -36,10 +36,10 @@ mraa_platform_t
mraa_x86_platform() mraa_x86_platform()
{ {
mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
char *line = NULL; char* line = NULL;
// let getline allocate memory for *line // let getline allocate memory for *line
size_t len = 0; size_t len = 0;
FILE *fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
if (fh != NULL) { if (fh != NULL) {
if (getline(&line, &len, fh) != -1) { if (getline(&line, &len, fh) != -1) {
if (strncmp(line, "GalileoGen2", 11) == 0) { if (strncmp(line, "GalileoGen2", 11) == 0) {