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

View File

@@ -27,7 +27,8 @@
#include <stdexcept>
#include "aio.h"
namespace mraa {
namespace mraa
{
/**
* @brief API to Analog IO
@@ -36,63 +37,73 @@ namespace mraa {
*
* @snippet examples/c++/AioA0.cpp Interesting
*/
class Aio {
public:
/**
* Aio Constructor, takes a pin number which will map directly to the
* board number
*
* @param pin channel number to read ADC inputs
*/
Aio(unsigned int pin) {
m_aio = mraa_aio_init(pin);
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
}
}
/**
* Aio destructor
*/
~Aio() {
mraa_aio_close(m_aio);
}
/**
* Read a value from the AIO pin. By default mraa will shift
* the raw value up or down to a 10 bit value.
*
* @returns The current input voltage. By default, a 10bit value
*/
int read() {
return mraa_aio_read(m_aio);
}
/**
* Read a value from the AIO pin and return it as a normalized float.
*
* @returns The current input voltage as a normalized float (0.0f-1.0f)
*/
float readFloat() {
return mraa_aio_read_float(m_aio);
}
/**
* Set the bit value which mraa will shift the raw reading
* from the ADC to. I.e. 10bits
* @param bits the bits the return from read should be i.e 10
* @return mraa result type
*/
mraa_result_t setBit(int bits) {
return mraa_aio_set_bit(m_aio, bits);
}
/**
* Gets the bit value mraa is shifting the analog read to.
*
* @return bit value mraa is set return from the read function
*/
int getBit() {
return mraa_aio_get_bit(m_aio);
class Aio
{
public:
/**
* Aio Constructor, takes a pin number which will map directly to the
* board number
*
* @param pin channel number to read ADC inputs
*/
Aio(unsigned int pin)
{
m_aio = mraa_aio_init(pin);
if (m_aio == NULL) {
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
}
}
/**
* Aio destructor
*/
~Aio()
{
mraa_aio_close(m_aio);
}
/**
* Read a value from the AIO pin. By default mraa will shift
* the raw value up or down to a 10 bit value.
*
* @returns The current input voltage. By default, a 10bit value
*/
int
read()
{
return mraa_aio_read(m_aio);
}
/**
* Read a value from the AIO pin and return it as a normalized float.
*
* @returns The current input voltage as a normalized float (0.0f-1.0f)
*/
float
readFloat()
{
return mraa_aio_read_float(m_aio);
}
/**
* Set the bit value which mraa will shift the raw reading
* from the ADC to. I.e. 10bits
* @param bits the bits the return from read should be i.e 10
* @return mraa result type
*/
mraa_result_t
setBit(int bits)
{
return mraa_aio_set_bit(m_aio, bits);
}
/**
* Gets the bit value mraa is shifting the analog read to.
*
* @return bit value mraa is set return from the read function
*/
int
getBit()
{
return mraa_aio_get_bit(m_aio);
}
private:
mraa_aio_context m_aio;
private:
mraa_aio_context m_aio;
};
}

View File

@@ -30,7 +30,8 @@
/**
* @namespace mraa namespace
*/
namespace mraa {
namespace mraa
{
/**
* @file
@@ -50,7 +51,8 @@ namespace mraa {
*
* @return Result of operation
*/
inline mraa_result_t init()
inline mraa_result_t
init()
{
return mraa_init();
}
@@ -60,7 +62,8 @@ inline mraa_result_t init()
*
* @return libmraa version (e.g. v0.4.0-20-gb408207)
*/
inline std::string getVersion()
inline std::string
getVersion()
{
std::string ret = mraa_get_version();
return ret;
@@ -75,7 +78,8 @@ inline std::string getVersion()
* @param priority Value from typically 0 to 99
* @return The priority value set
*/
inline int setPriority(const unsigned int priority)
inline int
setPriority(const unsigned int priority)
{
return mraa_set_priority(priority);
}
@@ -85,7 +89,8 @@ inline int setPriority(const unsigned int priority)
*
* @return mraa_platform_t Platform type enum
*/
inline mraa_platform_t getPlatformType()
inline mraa_platform_t
getPlatformType()
{
return mraa_get_platform_type();
}
@@ -95,7 +100,8 @@ inline mraa_platform_t getPlatformType()
*
* @param result the result to print
*/
inline void printError(mraa_result_t result)
inline void
printError(mraa_result_t result)
{
mraa_result_print(result);
}
@@ -107,9 +113,10 @@ inline void printError(mraa_result_t result)
* @param mode the mode to be tested.
* @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
*/
inline unsigned int adcRawBits()
inline unsigned int
adcRawBits()
{
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.
*/
inline unsigned int adcSupportedBits()
inline unsigned int
adcSupportedBits()
{
return mraa_adc_supported_bits();
}
@@ -137,7 +146,8 @@ inline unsigned int adcSupportedBits()
*
* @return platform name
*/
inline std::string getPlatformName()
inline std::string
getPlatformName()
{
std::string ret_val(mraa_get_platform_name());
return ret_val;
@@ -148,7 +158,8 @@ inline std::string getPlatformName()
*
* @return uint of physical pins.
*/
inline unsigned int getPinCount()
inline unsigned int
getPinCount()
{
return mraa_get_pin_count();
}
@@ -160,7 +171,8 @@ inline unsigned int getPinCount()
*
* @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));
return ret_val;
@@ -173,9 +185,9 @@ inline std::string getPinName(int pin)
* @param level
* @return Result of operation
*/
inline mraa_result_t setLogLevel(int level)
inline mraa_result_t
setLogLevel(int level)
{
return mraa_set_log_level(level);
}
}

View File

@@ -59,30 +59,30 @@ typedef struct _gpio* mraa_gpio_context;
* Gpio Output modes
*/
typedef enum {
MRAA_GPIO_STRONG = 0, /**< Default. Strong high and low */
MRAA_GPIO_PULLUP = 1, /**< Resistive High */
MRAA_GPIO_PULLDOWN = 2, /**< Resistive Low */
MRAA_GPIO_HIZ = 3 /**< High Z State */
MRAA_GPIO_STRONG = 0, /**< Default. Strong high and low */
MRAA_GPIO_PULLUP = 1, /**< Resistive High */
MRAA_GPIO_PULLDOWN = 2, /**< Resistive Low */
MRAA_GPIO_HIZ = 3 /**< High Z State */
} gpio_mode_t;
/**
* Gpio Direction options
*/
typedef enum {
MRAA_GPIO_OUT = 0, /**< Output. A Mode can also be set */
MRAA_GPIO_IN = 1, /**< Input */
MRAA_GPIO_OUT = 0, /**< Output. A Mode can also be set */
MRAA_GPIO_IN = 1, /**< Input */
MRAA_GPIO_OUT_HIGH = 2, /**< Output. Init High */
MRAA_GPIO_OUT_LOW = 3 /**< Output. Init Low */
MRAA_GPIO_OUT_LOW = 3 /**< Output. Init Low */
} gpio_dir_t;
/**
* Gpio Edge types for interupts
*/
typedef enum {
MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
} gpio_edge_t;
/**
@@ -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)
* @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

View File

@@ -28,12 +28,13 @@
#include <stdexcept>
#if defined(SWIGJAVASCRIPT)
#if NODE_MODULE_VERSION >= 0x000D
#include <uv.h>
#endif
#if NODE_MODULE_VERSION >= 0x000D
#include <uv.h>
#endif
#endif
namespace mraa {
namespace mraa
{
// These enums must match the enums in gpio.h
@@ -41,30 +42,30 @@ namespace mraa {
* Gpio Output modes
*/
typedef enum {
MODE_STRONG = 0, /**< Default. Strong High and Low */
MODE_PULLUP = 1, /**< Interupt on rising & falling */
MODE_STRONG = 0, /**< Default. Strong High and Low */
MODE_PULLUP = 1, /**< Interupt on rising & falling */
MODE_PULLDOWN = 2, /**< Interupt on rising only */
MODE_HIZ = 3 /**< Interupt on falling only */
MODE_HIZ = 3 /**< Interupt on falling only */
} Mode;
/**
* Gpio Direction options
*/
typedef enum {
DIR_OUT = 0, /**< Output. A Mode can also be set */
DIR_IN = 1, /**< Input */
DIR_OUT = 0, /**< Output. A Mode can also be set */
DIR_IN = 1, /**< Input */
DIR_OUT_HIGH = 2, /**< Output. Init High */
DIR_OUT_LOW = 3 /**< Output. Init Low */
DIR_OUT_LOW = 3 /**< Output. Init Low */
} Dir;
/**
* Gpio Edge types for interupts
*/
typedef enum {
EDGE_NONE = 0, /**< No interrupt on Gpio */
EDGE_BOTH = 1, /**< Interupt on rising & falling */
EDGE_RISING = 2, /**< Interupt on rising only */
EDGE_FALLING = 3 /**< Interupt on falling only */
EDGE_NONE = 0, /**< No interrupt on Gpio */
EDGE_BOTH = 1, /**< Interupt on rising & falling */
EDGE_RISING = 2, /**< Interupt on rising only */
EDGE_FALLING = 3 /**< Interupt on falling only */
} Edge;
/**
@@ -74,182 +75,211 @@ typedef enum {
*
* @snippet Blink-IO.cpp Interesting
*/
class Gpio {
public:
/**
* Instanciates a Gpio object
*
* @param pin pin number to use
* @param owner (optional) Set pin owner, default behaviour is to 'own'
* the pin if we exported it. This means we will close it on destruct.
* Otherwise it will get left open. This is only valid in sysfs use
* cases
* @param raw (optional) Raw pins will use gpiolibs pin numbering from
* the kernel module. Note that you will not get any muxers set up for
* you so this may not always work as expected.
*/
Gpio(int pin, bool owner=true, bool raw=false) {
if (raw) {
m_gpio = mraa_gpio_init_raw(pin);
}
else {
m_gpio = mraa_gpio_init(pin);
}
class Gpio
{
public:
/**
* Instanciates a Gpio object
*
* @param pin pin number to use
* @param owner (optional) Set pin owner, default behaviour is to 'own'
* the pin if we exported it. This means we will close it on destruct.
* Otherwise it will get left open. This is only valid in sysfs use
* cases
* @param raw (optional) Raw pins will use gpiolibs pin numbering from
* the kernel module. Note that you will not get any muxers set up for
* you so this may not always work as expected.
*/
Gpio(int pin, bool owner = true, bool raw = false)
{
if (raw) {
m_gpio = mraa_gpio_init_raw(pin);
} else {
m_gpio = mraa_gpio_init(pin);
}
if (m_gpio == NULL) {
throw std::invalid_argument("Invalid GPIO pin specified");
}
if (m_gpio == NULL) {
throw std::invalid_argument("Invalid GPIO pin specified");
}
if (!owner) {
mraa_gpio_owner(m_gpio, 0);
}
}
/**
* Gpio object destructor, this will only unexport the gpio if we where
* the owner
*/
~Gpio() {
mraa_gpio_close(m_gpio);
}
/**
* Set the edge mode for ISR
*
* @param mode The edge mode to set
* @return Result of operation
*/
mraa_result_t edge(Edge mode) {
return mraa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode);
if (!owner) {
mraa_gpio_owner(m_gpio, 0);
}
}
/**
* Gpio object destructor, this will only unexport the gpio if we where
* the owner
*/
~Gpio()
{
mraa_gpio_close(m_gpio);
}
/**
* Set the edge mode for ISR
*
* @param mode The edge mode to set
* @return Result of operation
*/
mraa_result_t
edge(Edge mode)
{
return mraa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode);
}
#if defined(SWIGPYTHON)
mraa_result_t isr(Edge mode, PyObject *pyfunc, PyObject* args) {
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, (void (*) (void *)) pyfunc, (void *) args);
}
mraa_result_t
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)
static void v8isr(uv_work_t* req, int status) {
mraa::Gpio *This = (mraa::Gpio *)req->data;
int argc = 1;
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
static void
v8isr(uv_work_t* req, int status)
{
mraa::Gpio* This = (mraa::Gpio*) req->data;
int argc = 1;
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
#if NODE_MODULE_VERSION >= 0x000D
v8::Local<v8::Function> f = v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), This->m_v8isr);
f->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
v8::Local<v8::Function> f = v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), This->m_v8isr);
f->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
#else
This->m_v8isr->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
This->m_v8isr->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
#endif
delete req;
}
delete req;
}
static void nop(uv_work_t* req)
{
// Do nothing.
}
static void
nop(uv_work_t* req)
{
// Do nothing.
}
static void uvwork(void *ctx) {
uv_work_t* req = new uv_work_t;
req->data = ctx;
uv_queue_work(uv_default_loop(), req, nop, v8isr);
}
static void
uvwork(void* ctx)
{
uv_work_t* req = new uv_work_t;
req->data = ctx;
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
m_v8isr.Reset(v8::Isolate::GetCurrent(), func);
m_v8isr.Reset(v8::Isolate::GetCurrent(), func);
#else
m_v8isr = v8::Persistent<v8::Function>::New(func);
m_v8isr = v8::Persistent<v8::Function>::New(func);
#endif
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, &uvwork, this);
}
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, &uvwork, this);
}
#else
/**
* Sets a callback to be called when pin value changes
*
* @param mode The edge mode to set
* @param fptr Function pointer to function to be called when interupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
*/
mraa_result_t isr(Edge mode, void (*fptr)(void *), void * args) {
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, fptr, args);
}
/**
* Sets a callback to be called when pin value changes
*
* @param mode The edge mode to set
* @param fptr Function pointer to function to be called when interupt is
* triggered
* @param args Arguments passed to the interrupt handler (fptr)
* @return Result of operation
*/
mraa_result_t
isr(Edge mode, void (*fptr)(void*), void* args)
{
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, fptr, args);
}
#endif
/**
* Exits callback - this call will not kill the isr thread imediatlu
* but only when it is out of it's critical section
*
* @return Result of operation
*/
mraa_result_t isrExit() {
/**
* Exits callback - this call will not kill the isr thread imediatlu
* but only when it is out of it's critical section
*
* @return Result of operation
*/
mraa_result_t
isrExit()
{
#if defined(SWIGJAVASCRIPT)
#if NODE_MODULE_VERSION >= 0x000D
m_v8isr.Reset();
#else
m_v8isr.Dispose();
m_v8isr.Clear();
#endif
#if NODE_MODULE_VERSION >= 0x000D
m_v8isr.Reset();
#else
m_v8isr.Dispose();
m_v8isr.Clear();
#endif
return mraa_gpio_isr_exit(m_gpio);
#endif
return mraa_gpio_isr_exit(m_gpio);
}
/**
* Change Gpio mode
*
* @param mode The mode to change the gpio into
* @return Result of operation
*/
mraa_result_t
mode(Mode mode)
{
return mraa_gpio_mode(m_gpio, (gpio_mode_t) mode);
}
/**
* Change Gpio direction
*
* @param dir The direction to change the gpio into
* @return Result of operation
*/
mraa_result_t
dir(Dir dir)
{
return mraa_gpio_dir(m_gpio, (gpio_dir_t) dir);
}
/**
* Read value from Gpio
*
* @return Gpio value
*/
int
read()
{
return mraa_gpio_read(m_gpio);
}
/**
* Write value to Gpio
*
* @param value Value to write to Gpio
* @return Result of operation
*/
mraa_result_t
write(int value)
{
return mraa_gpio_write(m_gpio, value);
}
/**
* Enable use of mmap i/o if available.
*
* @param enable true to use mmap
* @return Result of operation
*/
mraa_result_t
useMmap(bool enable)
{
return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
}
/**
* Get pin number of Gpio. If raw param is True will return the
* number as used within sysfs
*
* @param raw (optional) get the raw gpio number.
* @return Pin number
*/
int
getPin(bool raw = false)
{
if (raw) {
return mraa_gpio_get_pin_raw(m_gpio);
}
/**
* Change Gpio mode
*
* @param mode The mode to change the gpio into
* @return Result of operation
*/
mraa_result_t mode(Mode mode) {
return mraa_gpio_mode(m_gpio, (gpio_mode_t) mode);
}
/**
* Change Gpio direction
*
* @param dir The direction to change the gpio into
* @return Result of operation
*/
mraa_result_t dir(Dir dir) {
return mraa_gpio_dir(m_gpio, (gpio_dir_t) dir);
}
/**
* Read value from Gpio
*
* @return Gpio value
*/
int read() {
return mraa_gpio_read(m_gpio);
}
/**
* Write value to Gpio
*
* @param value Value to write to Gpio
* @return Result of operation
*/
mraa_result_t write(int value) {
return mraa_gpio_write(m_gpio, value);
}
/**
* Enable use of mmap i/o if available.
*
* @param enable true to use mmap
* @return Result of operation
*/
mraa_result_t useMmap(bool enable) {
return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
}
/**
* Get pin number of Gpio. If raw param is True will return the
* number as used within sysfs
*
* @param raw (optional) get the raw gpio number.
* @return Pin number
*/
int getPin(bool raw = false) {
if (raw) {
return mraa_gpio_get_pin_raw(m_gpio);
}
return mraa_gpio_get_pin(m_gpio);
}
private:
mraa_gpio_context m_gpio;
return mraa_gpio_get_pin(m_gpio);
}
private:
mraa_gpio_context m_gpio;
#if defined(SWIGJAVASCRIPT)
v8::Persistent<v8::Function> m_v8isr;
v8::Persistent<v8::Function> m_v8isr;
#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
* @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
@@ -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
* @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

View File

@@ -27,7 +27,8 @@
#include "i2c.h"
#include <stdexcept>
namespace mraa {
namespace mraa
{
/**
* @brief API to Inter-Integrated Circuit
@@ -38,158 +39,182 @@ namespace mraa {
*
* @snippet I2c-compass.cpp Interesting
*/
class I2c {
public:
/**
* Instantiates an i2c bus. Multiple instances of the same bus can
* exist and the bus is not guarranteed to be on the correct address
* before read/write.
*
* @param bus The i2c bus to use
* @param raw Whether to disable pinmapper for your board
*/
I2c(int bus, bool raw=false) {
if (raw) {
m_i2c = mraa_i2c_init_raw(bus);
}
else {
m_i2c = mraa_i2c_init(bus);
}
if (m_i2c == NULL) {
throw std::invalid_argument("Invalid i2c bus");
}
class I2c
{
public:
/**
* Instantiates an i2c bus. Multiple instances of the same bus can
* exist and the bus is not guarranteed to be on the correct address
* before read/write.
*
* @param bus The i2c bus to use
* @param raw Whether to disable pinmapper for your board
*/
I2c(int bus, bool raw = false)
{
if (raw) {
m_i2c = mraa_i2c_init_raw(bus);
} else {
m_i2c = mraa_i2c_init(bus);
}
if (m_i2c == NULL) {
throw std::invalid_argument("Invalid i2c bus");
}
}
/**
* Closes the I2c Bus used. This does not guarrantee the bus will not
* be usable by anyone else or communicates this disconnect to any
* slaves.
*/
~I2c() {
mraa_i2c_stop(m_i2c);
}
/**
* Closes the I2c Bus used. This does not guarrantee the bus will not
* be usable by anyone else or communicates this disconnect to any
* slaves.
*/
~I2c()
{
mraa_i2c_stop(m_i2c);
}
/**
* Sets the i2c Frequency for communication. Your board may not support
* the set frequency. Anyone can change this at any time and this will
* affect every slave on the bus
*
* @param mode Frequency to set the bus to
* @return Result of operation
*/
mraa_result_t frequency(mraa_i2c_mode_t mode) {
return mraa_i2c_frequency(m_i2c, mode);
}
/**
* Sets the i2c Frequency for communication. Your board may not support
* the set frequency. Anyone can change this at any time and this will
* affect every slave on the bus
*
* @param mode Frequency to set the bus to
* @return Result of operation
*/
mraa_result_t
frequency(mraa_i2c_mode_t mode)
{
return mraa_i2c_frequency(m_i2c, mode);
}
/**
* Set the slave to talk to, typically called before every read/write
* operation
*
* @param address Communicate to the i2c slave on this address
* @return Result of operation
*/
mraa_result_t address(uint8_t address) {
return mraa_i2c_address(m_i2c, address);
}
/**
* Set the slave to talk to, typically called before every read/write
* operation
*
* @param address Communicate to the i2c slave on this address
* @return Result of operation
*/
mraa_result_t
address(uint8_t address)
{
return mraa_i2c_address(m_i2c, address);
}
/**
* Read exactly one byte from the bus
*
* @return char read from the bus
*/
uint8_t readByte() {
return (uint8_t) mraa_i2c_read_byte(m_i2c);
}
/**
* Read exactly one byte from the bus
*
* @return char read from the bus
*/
uint8_t
readByte()
{
return (uint8_t) mraa_i2c_read_byte(m_i2c);
}
/**
* Read length bytes from the bus into *data pointer
*
* @param data Data to read into
* @param length Size of read in bytes to make
* @return length of read, should match length
*/
int read(uint8_t *data, int length) {
return mraa_i2c_read(m_i2c, data, length);
}
/**
* Read length bytes from the bus into *data pointer
*
* @param data Data to read into
* @param length Size of read in bytes to make
* @return length of read, should match length
*/
int
read(uint8_t* data, int length)
{
return mraa_i2c_read(m_i2c, data, length);
}
/**
* Read byte from an i2c register
*
* @param reg Register to read from
* @return char read from register
*/
uint8_t readReg(uint8_t reg) {
return mraa_i2c_read_byte_data(m_i2c, reg);
}
/**
* Read byte from an i2c register
*
* @param reg Register to read from
* @return char read from register
*/
uint8_t
readReg(uint8_t reg)
{
return mraa_i2c_read_byte_data(m_i2c, reg);
}
/**
* Read word from an i2c register
*
* @param reg Register to read from
* @return char read from register
*/
uint16_t readWordReg(uint8_t reg) {
return mraa_i2c_read_word_data(m_i2c, reg);
}
/**
* Read word from an i2c register
*
* @param reg Register to read from
* @return char read from register
*/
uint16_t
readWordReg(uint8_t reg)
{
return mraa_i2c_read_word_data(m_i2c, reg);
}
/**
* Read length bytes from the bus into *data pointer starting from
* an i2c register
*
* @param reg Register to read from
* @param data pointer to the byte array to read data in to
* @param length max number of bytes to read
* @return length passed to the function or 0
*/
int readBytesReg(uint8_t reg, uint8_t* data, int length) {
return mraa_i2c_read_bytes_data(m_i2c, reg, data, length);
}
/**
* Read length bytes from the bus into *data pointer starting from
* an i2c register
*
* @param reg Register to read from
* @param data pointer to the byte array to read data in to
* @param length max number of bytes to read
* @return length passed to the function or 0
*/
int
readBytesReg(uint8_t reg, uint8_t* data, int length)
{
return mraa_i2c_read_bytes_data(m_i2c, reg, data, length);
}
/**
* Write a byte on the bus
*
* @param data The byte to send on the bus
* @return Result of operation
*/
mraa_result_t writeByte(uint8_t data) {
return mraa_i2c_write_byte(m_i2c, data);
}
/**
* Write a byte on the bus
*
* @param data The byte to send on the bus
* @return Result of operation
*/
mraa_result_t
writeByte(uint8_t data)
{
return mraa_i2c_write_byte(m_i2c, data);
}
/**
* Write length bytes to the bus, the first byte in the array is the
* command/register to write
*
* @param data Buffer to send on the bus, first byte is i2c command
* @param length Size of buffer to send
* @return Result of operation
*/
mraa_result_t write(const uint8_t* data, int length) {
return mraa_i2c_write(m_i2c, data, length);
}
/**
* Write length bytes to the bus, the first byte in the array is the
* command/register to write
*
* @param data Buffer to send on the bus, first byte is i2c command
* @param length Size of buffer to send
* @return Result of operation
*/
mraa_result_t
write(const uint8_t* data, int length)
{
return mraa_i2c_write(m_i2c, data, length);
}
/**
* Write a byte to an i2c register
*
* @param reg Register to write to
* @param data Value to write to register
* @return Result of operation
*/
mraa_result_t writeReg(uint8_t reg, uint8_t data) {
return mraa_i2c_write_byte_data(m_i2c, data, reg);
}
/**
* Write a byte to an i2c register
*
* @param reg Register to write to
* @param data Value to write to register
* @return Result of operation
*/
mraa_result_t
writeReg(uint8_t reg, uint8_t data)
{
return mraa_i2c_write_byte_data(m_i2c, data, reg);
}
/**
* Write a word to an i2c register
*
* @param reg Register to write to
* @param data Value to write to register
* @return Result of operation
*/
mraa_result_t writeWordReg(uint8_t reg, uint16_t data) {
return mraa_i2c_write_word_data(m_i2c, data, reg);
}
private:
mraa_i2c_context m_i2c;
/**
* Write a word to an i2c register
*
* @param reg Register to write to
* @param data Value to write to register
* @return Result of operation
*/
mraa_result_t
writeWordReg(uint8_t reg, uint16_t data)
{
return mraa_i2c_write_word_data(m_i2c, data, reg);
}
private:
mraa_i2c_context m_i2c;
};
}

View File

@@ -27,7 +27,8 @@
#include "pwm.h"
#include <stdexcept>
namespace mraa {
namespace mraa
{
/**
* @brief API to Pulse Width Modulation
@@ -36,152 +37,175 @@ namespace mraa {
*
* @snippet Pwm3-cycle.cpp Interesting
*/
class Pwm {
public:
/**
* instanciates a PWM object on a pin
*
* @param pin the pin number used on your board
* @param owner if you are the owner of the pin the destructor will
* @param chipid the pwmchip to use, use only in raw mode
* unexport the pin from sysfs, default behaviour is you are the owner
* if the pinmapper exported it
*/
Pwm(int pin, bool owner=true, int chipid=-1) {
if (chipid == -1) {
m_pwm = mraa_pwm_init(pin);
}
else {
m_pwm = mraa_pwm_init_raw(chipid, pin);
}
if (m_pwm == NULL) {
throw std::invalid_argument("Error initialising PWM on pin");
}
if (!owner) {
mraa_pwm_owner(m_pwm, 0);
}
}
/**
* Pwm destructor
*/
~Pwm() {
mraa_pwm_close(m_pwm);
}
/**
* Set the output duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
* @return Result of operation
*/
mraa_result_t write(float percentage) {
return mraa_pwm_write(m_pwm, percentage);
}
/**
* Read the ouput duty-cycle percentage, as a float
*
* @return A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
*/
float read() {
return mraa_pwm_read(m_pwm);
}
/**
* Set the PWM period as seconds represented in a float
*
* @param period Period represented as a float in seconds
* @return Result of operation
*/
mraa_result_t period(float period) {
return mraa_pwm_period(m_pwm, period);
}
/**
* Set period, milliseconds
*
* @param ms milliseconds for period
* @return Result of operation
*/
mraa_result_t period_ms(int ms) {
return mraa_pwm_period_ms(m_pwm, ms);
}
/**
* Set period, microseconds
*
* @param us microseconds as period
* @return Result of operation
*/
mraa_result_t period_us(int us) {
return mraa_pwm_period_us(m_pwm, us);
}
/**
* Set pulsewidth, As represnted by seconds in a (float)
*
* @param seconds The duration of a pulse
* @return Result of operation
*/
mraa_result_t pulsewidth(float seconds) {
return mraa_pwm_pulsewidth(m_pwm, seconds);
}
/**
* Set pulsewidth, milliseconds
*
* @param ms milliseconds for pulsewidth
* @return Result of operation
*/
mraa_result_t pulsewidth_ms(int ms) {
return mraa_pwm_pulsewidth_ms(m_pwm, ms);
}
/**
* The pulsewidth, microseconds
*
* @param us microseconds for pulsewidth
* @return Result of operation
*/
mraa_result_t pulsewidth_us(int us) {
return mraa_pwm_pulsewidth_us(m_pwm, us);
}
/**
* Set the enable status of the PWM pin. None zero will assume on with
* output being driven and 0 will disable the output
*
* @param enable enable status of pin
* @return Result of operation
*/
mraa_result_t enable(bool enable) {
if (enable)
return mraa_pwm_enable(m_pwm, 1);
else
return mraa_pwm_enable(m_pwm, 0);
}
/**
* Set the period and duty of a PWM object.
*
* @param period represented in ms.
* @param duty represnted in ms as float.
* @return Result of operation
*/
mraa_result_t config_ms(int period, float duty) {
return mraa_pwm_config_ms(m_pwm, period, duty);
}
/**
* Set the period and duty (percent) of a PWM object.
*
* @param period as represented in ms.
* @param duty percentage i.e. 50% = 0.5f
* @return Result of operation
*/
mraa_result_t config_percent(int period, float duty) {
return mraa_pwm_config_percent(m_pwm, period, duty);
class Pwm
{
public:
/**
* instanciates a PWM object on a pin
*
* @param pin the pin number used on your board
* @param owner if you are the owner of the pin the destructor will
* @param chipid the pwmchip to use, use only in raw mode
* unexport the pin from sysfs, default behaviour is you are the owner
* if the pinmapper exported it
*/
Pwm(int pin, bool owner = true, int chipid = -1)
{
if (chipid == -1) {
m_pwm = mraa_pwm_init(pin);
} else {
m_pwm = mraa_pwm_init_raw(chipid, pin);
}
private:
mraa_pwm_context m_pwm;
if (m_pwm == NULL) {
throw std::invalid_argument("Error initialising PWM on pin");
}
if (!owner) {
mraa_pwm_owner(m_pwm, 0);
}
}
/**
* Pwm destructor
*/
~Pwm()
{
mraa_pwm_close(m_pwm);
}
/**
* Set the output duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
* @return Result of operation
*/
mraa_result_t
write(float percentage)
{
return mraa_pwm_write(m_pwm, percentage);
}
/**
* Read the ouput duty-cycle percentage, as a float
*
* @return A floating-point value representing percentage of
* output. The value should lie between 0.0f (representing on 0%) and
* 1.0f Values above or below this range will be set at either 0.0f or
* 1.0f
*/
float
read()
{
return mraa_pwm_read(m_pwm);
}
/**
* Set the PWM period as seconds represented in a float
*
* @param period Period represented as a float in seconds
* @return Result of operation
*/
mraa_result_t
period(float period)
{
return mraa_pwm_period(m_pwm, period);
}
/**
* Set period, milliseconds
*
* @param ms milliseconds for period
* @return Result of operation
*/
mraa_result_t
period_ms(int ms)
{
return mraa_pwm_period_ms(m_pwm, ms);
}
/**
* Set period, microseconds
*
* @param us microseconds as period
* @return Result of operation
*/
mraa_result_t
period_us(int us)
{
return mraa_pwm_period_us(m_pwm, us);
}
/**
* Set pulsewidth, As represnted by seconds in a (float)
*
* @param seconds The duration of a pulse
* @return Result of operation
*/
mraa_result_t
pulsewidth(float seconds)
{
return mraa_pwm_pulsewidth(m_pwm, seconds);
}
/**
* Set pulsewidth, milliseconds
*
* @param ms milliseconds for pulsewidth
* @return Result of operation
*/
mraa_result_t
pulsewidth_ms(int ms)
{
return mraa_pwm_pulsewidth_ms(m_pwm, ms);
}
/**
* The pulsewidth, microseconds
*
* @param us microseconds for pulsewidth
* @return Result of operation
*/
mraa_result_t
pulsewidth_us(int us)
{
return mraa_pwm_pulsewidth_us(m_pwm, us);
}
/**
* Set the enable status of the PWM pin. None zero will assume on with
* output being driven and 0 will disable the output
*
* @param enable enable status of pin
* @return Result of operation
*/
mraa_result_t
enable(bool enable)
{
if (enable)
return mraa_pwm_enable(m_pwm, 1);
else
return mraa_pwm_enable(m_pwm, 0);
}
/**
* Set the period and duty of a PWM object.
*
* @param period represented in ms.
* @param duty represnted in ms as float.
* @return Result of operation
*/
mraa_result_t
config_ms(int period, float duty)
{
return mraa_pwm_config_ms(m_pwm, period, duty);
}
/**
* Set the period and duty (percent) of a PWM object.
*
* @param period as represented in ms.
* @param duty percentage i.e. 50% = 0.5f
* @return Result of operation
*/
mraa_result_t
config_percent(int period, float duty)
{
return mraa_pwm_config_percent(m_pwm, period, duty);
}
private:
mraa_pwm_context m_pwm;
};
}

View File

@@ -51,10 +51,14 @@ extern "C" {
* MRAA SPI Modes
*/
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_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in 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_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge,
output data (change) on falling 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 */
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;
/**

View File

@@ -27,163 +27,191 @@
#include "spi.h"
#include <stdexcept>
namespace mraa {
namespace mraa
{
/**
* MRAA SPI Modes
*/
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_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in 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_MODE0 = 0, /**< CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge,
output data (change) on falling edge */
SPI_MODE1 = 1, /**< CPOL = 0, CPHA = 1, Clock idle low, data is clocked in 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;
/**
* @brief API to Serial Peripheral Interface
*
* This file defines the SPI interface for libmraa
*
* @snippet Spi-pot.cpp Interesting
*/
class Spi {
public:
/**
* Initialise SPI object using the board mapping to set muxes
*
* @param bus to use, as listed in the platform definition, normally 0
*/
Spi(int bus) {
m_spi = mraa_spi_init(bus);
/**
* @brief API to Serial Peripheral Interface
*
* This file defines the SPI interface for libmraa
*
* @snippet Spi-pot.cpp Interesting
*/
class Spi
{
public:
/**
* Initialise SPI object using the board mapping to set muxes
*
* @param bus to use, as listed in the platform definition, normally 0
*/
Spi(int bus)
{
m_spi = mraa_spi_init(bus);
if (m_spi == NULL) {
throw std::invalid_argument("Error initialising SPI bus");
}
if (m_spi == NULL) {
throw std::invalid_argument("Error initialising SPI bus");
}
}
/**
* Closes spi bus
*/
~Spi() {
mraa_spi_stop(m_spi);
}
/**
* Closes spi bus
*/
~Spi()
{
mraa_spi_stop(m_spi);
}
/**
* Set the SPI device mode. see spidev0-3
*
* @param mode the mode. See Linux spidev doc
* @return Result of operation
*/
mraa_result_t mode(Spi_Mode mode) {
return mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode);
}
/**
* Set the SPI device mode. see spidev0-3
*
* @param mode the mode. See Linux spidev doc
* @return Result of operation
*/
mraa_result_t
mode(Spi_Mode mode)
{
return mraa_spi_mode(m_spi, (mraa_spi_mode_t) mode);
}
/**
* Set the SPI device operating clock frequency
*
* @param hz the frequency to set in hz
* @return Result of operation
*/
mraa_result_t frequency(int hz) {
return mraa_spi_frequency(m_spi, hz);
}
/**
* Set the SPI device operating clock frequency
*
* @param hz the frequency to set in hz
* @return Result of operation
*/
mraa_result_t
frequency(int hz)
{
return mraa_spi_frequency(m_spi, hz);
}
/**
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line or -1 in case of error
*/
int writeByte(uint8_t data) {
return mraa_spi_write(m_spi, (uint8_t) data);
}
/**
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line or -1 in case of error
*/
int
writeByte(uint8_t data)
{
return mraa_spi_write(m_spi, (uint8_t) data);
}
/**
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line
*/
uint16_t write_word(uint16_t data) {
return mraa_spi_write_word(m_spi, (uint16_t) data);
}
/**
* Write single byte to the SPI device
*
* @param data the byte to send
* @return data received on the miso line
*/
uint16_t
write_word(uint16_t data)
{
return mraa_spi_write_word(m_spi, (uint16_t) data);
}
/**
* Write buffer of bytes to SPI device The pointer return has to be
* free'd by the caller. It will return a NULL pointer in cases of
* error
*
* @param txBuf buffer to send
* @param length size of buffer to send
* @return uint8_t* data received on the miso line. Same length as passed in
*/
uint8_t* write(uint8_t* txBuf, int length) {
return mraa_spi_write_buf(m_spi, txBuf, length);
}
/**
* Write buffer of bytes to SPI device The pointer return has to be
* free'd by the caller. It will return a NULL pointer in cases of
* error
*
* @param txBuf buffer to send
* @param length size of buffer to send
* @return uint8_t* data received on the miso line. Same length as passed in
*/
uint8_t*
write(uint8_t* txBuf, int length)
{
return mraa_spi_write_buf(m_spi, txBuf, length);
}
/**
* Write buffer of bytes to SPI device The pointer return has to be
* free'd by the caller. It will return a NULL pointer in cases of
* error
*
* @param txBuf buffer 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
*/
uint16_t* write_word(uint16_t* txBuf, int length) {
return mraa_spi_write_buf_word(m_spi, txBuf, length);
}
/**
* Write buffer of bytes to SPI device The pointer return has to be
* free'd by the caller. It will return a NULL pointer in cases of
* error
*
* @param txBuf buffer 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
*/
uint16_t*
write_word(uint16_t* txBuf, int length)
{
return mraa_spi_write_buf_word(m_spi, txBuf, length);
}
#ifndef SWIG
/**
* Transfer data to and from SPI device Receive pointer may be null if
* return data is not needed.
*
* @param data buffer to send
* @param rxBuf buffer to optionally receive data from spi device
* @param length size of buffer to send
* @return Result of operation
*/
mraa_result_t transfer(uint8_t* txBuf, uint8_t* rxBuf, int length) {
return mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length);
}
/**
* Transfer data to and from SPI device Receive pointer may be null if
* return data is not needed.
*
* @param data buffer to send
* @param rxBuf buffer to optionally receive data from spi device
* @param length size of buffer to send
* @return Result of operation
*/
mraa_result_t
transfer(uint8_t* txBuf, uint8_t* rxBuf, int length)
{
return mraa_spi_transfer_buf(m_spi, txBuf, rxBuf, length);
}
/**
* Transfer data to and from SPI device Receive pointer may be null if
* return data is not needed.
*
* @param data buffer to send
* @param rxBuf buffer to optionally receive data from spi device
* @param length size of buffer to send
* @return Result of operation
*/
mraa_result_t transfer_word(uint16_t* txBuf, uint16_t* rxBuf, int length) {
return mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length);
}
/**
* Transfer data to and from SPI device Receive pointer may be null if
* return data is not needed.
*
* @param data buffer to send
* @param rxBuf buffer to optionally receive data from spi device
* @param length size of buffer to send
* @return Result of operation
*/
mraa_result_t
transfer_word(uint16_t* txBuf, uint16_t* rxBuf, int length)
{
return mraa_spi_transfer_buf_word(m_spi, txBuf, rxBuf, length);
}
#endif
/**
* Change the SPI lsb mode
*
* @param lsb Use least significant bit transmission - 0 for msbi
* @return Result of operation
*/
mraa_result_t lsbmode(bool lsb) {
return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
}
/**
* Change the SPI lsb mode
*
* @param lsb Use least significant bit transmission - 0 for msbi
* @return Result of operation
*/
mraa_result_t
lsbmode(bool lsb)
{
return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
}
/**
* Set bits per mode on transaction, default is 8
*
* @param bits bits per word
* @return Result of operation
*/
mraa_result_t bitPerWord(unsigned int bits) {
return mraa_spi_bit_per_word(m_spi, bits);
}
/**
* Set bits per mode on transaction, default is 8
*
* @param bits bits per word
* @return Result of operation
*/
mraa_result_t
bitPerWord(unsigned int bits)
{
return mraa_spi_bit_per_word(m_spi, bits);
}
private:
mraa_spi_context m_spi;
private:
mraa_spi_context m_spi;
};
}

View File

@@ -37,14 +37,15 @@ extern "C" {
* MRAA supported platform types
*/
typedef enum {
MRAA_INTEL_GALILEO_GEN1 = 0, /**< The Generation 1 Galileo platform (RevD) */
MRAA_INTEL_GALILEO_GEN2 = 1, /**< The Generation 2 Galileo platform (RevG/H) */
MRAA_INTEL_EDISON_FAB_C = 2, /**< The Intel Edison (FAB C) */
MRAA_INTEL_DE3815 = 3, /**< The Intel DE3815 Baytrail NUC */
MRAA_INTEL_GALILEO_GEN1 = 0, /**< The Generation 1 Galileo platform (RevD) */
MRAA_INTEL_GALILEO_GEN2 = 1, /**< The Generation 2 Galileo platform (RevG/H) */
MRAA_INTEL_EDISON_FAB_C = 2, /**< The Intel Edison (FAB C) */
MRAA_INTEL_DE3815 = 3, /**< The Intel DE3815 Baytrail NUC */
MRAA_INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */
MRAA_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;
/**
@@ -160,12 +161,12 @@ typedef enum {
MRAA_RASPBERRY_WIRING_PIN14 = 23,
MRAA_RASPBERRY_WIRING_PIN10 = 24,
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_PIN18 = 30, //RPi B V2
MRAA_RASPBERRY_WIRING_PIN19 = 31, //RPI B V2
MRAA_RASPBERRY_WIRING_PIN18 = 30, // RPi B V2
MRAA_RASPBERRY_WIRING_PIN19 = 31, // RPI B V2
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_PIN23 = 33,
MRAA_RASPBERRY_WIRING_PIN24 = 35,
@@ -179,42 +180,42 @@ typedef enum {
* MRAA return codes
*/
typedef enum {
MRAA_SUCCESS = 0, /**< Expected response */
MRAA_ERROR_FEATURE_NOT_IMPLEMENTED = 1, /**< Feature TODO */
MRAA_ERROR_FEATURE_NOT_SUPPORTED = 2, /**< Feature not supported by HW */
MRAA_ERROR_INVALID_VERBOSITY_LEVEL = 3, /**< Verbosity level wrong */
MRAA_ERROR_INVALID_PARAMETER = 4, /**< Parameter invalid */
MRAA_ERROR_INVALID_HANDLE = 5, /**< Handle invalid */
MRAA_ERROR_NO_RESOURCES = 6, /**< No resource of that type avail */
MRAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
MRAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
MRAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
MRAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
MRAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
MRAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised */
MRAA_SUCCESS = 0, /**< Expected response */
MRAA_ERROR_FEATURE_NOT_IMPLEMENTED = 1, /**< Feature TODO */
MRAA_ERROR_FEATURE_NOT_SUPPORTED = 2, /**< Feature not supported by HW */
MRAA_ERROR_INVALID_VERBOSITY_LEVEL = 3, /**< Verbosity level wrong */
MRAA_ERROR_INVALID_PARAMETER = 4, /**< Parameter invalid */
MRAA_ERROR_INVALID_HANDLE = 5, /**< Handle invalid */
MRAA_ERROR_NO_RESOURCES = 6, /**< No resource of that type avail */
MRAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
MRAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
MRAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
MRAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
MRAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
MRAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised */
MRAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
MRAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} mraa_result_t;
/**
* Enum representing different possible modes for a pin.
*/
typedef enum {
MRAA_PIN_VALID = 0, /**< Pin Valid */
MRAA_PIN_GPIO = 1, /**< General Purpose IO */
MRAA_PIN_PWM = 2, /**< Pulse Width Modulation */
MRAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
MRAA_PIN_SPI = 4, /**< SPI */
MRAA_PIN_I2C = 5, /**< I2C */
MRAA_PIN_AIO = 6, /**< Analog in */
MRAA_PIN_UART = 7 /**< UART */
MRAA_PIN_VALID = 0, /**< Pin Valid */
MRAA_PIN_GPIO = 1, /**< General Purpose IO */
MRAA_PIN_PWM = 2, /**< Pulse Width Modulation */
MRAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
MRAA_PIN_SPI = 4, /**< SPI */
MRAA_PIN_I2C = 5, /**< I2C */
MRAA_PIN_AIO = 6, /**< Analog in */
MRAA_PIN_UART = 7 /**< UART */
} mraa_pinmodes_t;
/**
* Enum reprensenting different i2c speeds/modes
*/
typedef enum {
MRAA_I2C_STD = 0, /**< up to 100Khz */
MRAA_I2C_STD = 0, /**< up to 100Khz */
MRAA_I2C_FAST = 1, /**< up to 400Khz */
MRAA_I2C_HIGH = 2 /**< up to 3.4Mhz */
} mraa_i2c_mode_t;

View File

@@ -27,47 +27,53 @@
#include "uart.h"
#include <stdexcept>
namespace mraa {
namespace mraa
{
/**
* @brief API to UART (enabling only)
*
* This file defines the UART interface for libmraa
*/
class Uart {
public:
/**
* Uart Constructor, takes a pin number which will map directly to the
* linux uart number, this 'enables' the uart, nothing more
*
* @param uart the index of the uart set to use
*/
Uart(int uart) {
m_uart = mraa_uart_init(uart);
class Uart
{
public:
/**
* Uart Constructor, takes a pin number which will map directly to the
* linux uart number, this 'enables' the uart, nothing more
*
* @param uart the index of the uart set to use
*/
Uart(int uart)
{
m_uart = mraa_uart_init(uart);
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART");
}
}
/**
* Uart destructor
*/
~Uart() {
return;
if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART");
}
}
/**
* Uart destructor
*/
~Uart()
{
return;
}
/**
* Get string with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @return char pointer of device path
*/
std::string getDevicePath() {
std::string ret_val(mraa_uart_get_dev_path(m_uart));
return ret_val;
}
private:
mraa_uart_context m_uart;
/**
* Get string with tty device path within Linux
* For example. Could point to "/dev/ttyS0"
*
* @return char pointer of device path
*/
std::string
getDevicePath()
{
std::string ret_val(mraa_uart_get_dev_path(m_uart));
return ret_val;
}
private:
mraa_uart_context m_uart;
};
}