mraa  1.7.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Functions | Macros | Typedefs
common.h File Reference

API Description

This file defines the basic shared values for libmraa

Go to the source code of this file.

Functions

mraa_result_t mraa_init () __attribute__((constructor))
 
void mraa_deinit () __attribute__((destructor))
 
mraa_boolean_t mraa_pin_mode_test (int pin, mraa_pinmodes_t mode)
 
unsigned int mraa_adc_raw_bits ()
 
unsigned int mraa_get_platform_adc_raw_bits (uint8_t platform_offset)
 
unsigned int mraa_adc_supported_bits ()
 
unsigned int mraa_get_platform_adc_supported_bits (int platform_offset)
 
mraa_result_t mraa_set_log_level (int level)
 
const char * mraa_get_platform_name ()
 
const char * mraa_get_platform_version (int platform_offset)
 
int mraa_set_priority (const int priority)
 
const char * mraa_get_version ()
 
void mraa_result_print (mraa_result_t result)
 
mraa_platform_t mraa_get_platform_type ()
 
int mraa_get_platform_combined_type ()
 
unsigned int mraa_get_pin_count ()
 
int mraa_get_uart_count (void)
 
int mraa_get_spi_bus_count (void)
 
int mraa_get_pwm_count (void)
 
int mraa_get_gpio_count (void)
 
int mraa_get_aio_bus_count (void)
 
int mraa_get_i2c_bus_count ()
 
int mraa_get_i2c_bus_id (int i2c_bus)
 
unsigned int mraa_get_platform_pin_count (uint8_t platform_offset)
 
char * mraa_get_pin_name (int pin)
 
int mraa_gpio_lookup (const char *pin_name)
 
int mraa_i2c_lookup (const char *i2c_name)
 
int mraa_spi_lookup (const char *spi_name)
 
int mraa_pwm_lookup (const char *pwm_name)
 
int mraa_uart_lookup (const char *uart_name)
 
int mraa_get_default_i2c_bus (uint8_t platform_offset)
 
mraa_boolean_t mraa_has_sub_platform ()
 
mraa_boolean_t mraa_is_sub_platform_id (int pin_or_bus_id)
 
int mraa_get_sub_platform_id (int pin_or_bus_index)
 
int mraa_get_sub_platform_index (int pin_or_bus_id)
 
mraa_result_t mraa_add_subplatform (mraa_platform_t subplatformtype, const char *uart_dev)
 
mraa_result_t mraa_remove_subplatform (mraa_platform_t subplatformtype)
 
void * mraa_init_io (const char *desc)
 
mraa_result_t mraa_init_json_platform (const char *path)
 

Macros

#define MRAA_PLATFORM_NAME_MAX_SIZE   64
 
#define MRAA_PIN_NAME_SIZE   12
 
#define MRAA_SUB_PLATFORM_BIT_SHIFT   9
 
#define MRAA_SUB_PLATFORM_MASK   (1<<MRAA_SUB_PLATFORM_BIT_SHIFT)
 
#define MRAA_MAIN_PLATFORM_OFFSET   0
 
#define MRAA_SUB_PLATFORM_OFFSET   1
 
#define MRAA_RETURN_FOR_ERROR(func)
 

Typedefs

typedef unsigned int mraa_boolean_t
 

Function Documentation

mraa_result_t mraa_init ( ) const

Initialise MRAA

Detects running platform and attempts to use included pinmap, this is run on module/library init/load but is handy to rerun to check board initialised correctly. MRAA_SUCCESS inidicates correct initialisation.

Returns
Result of operation

Here is the caller graph for this function:

void mraa_deinit ( )

De-Initilise MRAA

This is not a strict requirement but useful to test memory leaks and for people who like super clean code. If dynamically loading & unloading libmraa you need to call this before unloading the library.

mraa_boolean_t mraa_pin_mode_test ( int  pin,
mraa_pinmodes_t  mode 
)

Checks if a pin is able to use the passed in mode.

Parameters
pinPhysical Pin to be checked.
modethe mode to be tested.
Returns
boolean if the mode is supported, 0=false.

Here is the caller graph for this function:

unsigned int mraa_adc_raw_bits ( )

Check the board's bit size when reading the value

Returns
raw bits being read from kernel module. zero if no ADC

Here is the caller graph for this function:

unsigned int mraa_get_platform_adc_raw_bits ( uint8_t  platform_offset)

Check the specified board's bit size when reading the value

Parameters
specifiedplatform offset; 0 for main platform, 1 foor sub platform
Returns
raw bits being read from kernel module. zero if no ADC
unsigned int mraa_adc_supported_bits ( )

Return value that the raw value should be shifted to. Zero if no ADC

Returns
return actual bit size the adc value should be understood as.

Here is the caller graph for this function:

unsigned int mraa_get_platform_adc_supported_bits ( int  platform_offset)

Return value that the raw value should be shifted to. Zero if no ADC

Parameters
specifiedplatform offset; 0 for main platform, 1 foor sub platform
Returns
return actual bit size the adc value should be understood as.
mraa_result_t mraa_set_log_level ( int  level)

Sets the log level to use from 0-7 where 7 is very verbose. These are the syslog log levels, see syslog(3) for more information on the levels.

Returns
Result of operation

Here is the caller graph for this function:

const char* mraa_get_platform_name ( )

Return the Platform's Name, If no platform detected return NULL

Returns
platform name

Here is the caller graph for this function:

const char* mraa_get_platform_version ( int  platform_offset)

Return the platform's versioning info, the information given depends per platform and can be NULL. platform_offset has to be given. Do not modify this pointer

Parameters
specifiedplatform offset; 0 for main platform, 1 for sub platform
Returns
platform's versioning string

Here is the caller graph for this function:

int mraa_set_priority ( const int  priority)

This function attempts to set the mraa process to a given priority and the scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0. This function * will set to MAX if * priority is > MAX. Function will return -1 on failure.

Parameters
priorityValue from typically 0 to 99
Returns
The priority value set

Here is the caller graph for this function:

const char* mraa_get_version ( )

Get the version string of mraa autogenerated from git tag

The version returned may not be what is expected however it is a reliable number associated with the git tag closest to that version at build time

Returns
version string from version.h

Here is the caller graph for this function:

void mraa_result_print ( mraa_result_t  result)

Print a textual representation of the mraa_result_t

Parameters
resultthe result to print

Here is the caller graph for this function:

mraa_platform_t mraa_get_platform_type ( )

Get platform type, board must be initialised.

Returns
mraa_platform_t Platform type enum

Here is the caller graph for this function:

int mraa_get_platform_combined_type ( )

Get combined platform type, board must be initialised. The combined type is represented as (sub_platform_type << 8) | main_platform_type

Returns
int combined platform type
unsigned int mraa_get_pin_count ( )

Get platform pincount, board must be initialised.

Returns
uint of physical pin count on the in-use platform

Here is the caller graph for this function:

int mraa_get_uart_count ( void  )

Get the number of usable UARTs, board must be initialised.

Returns
number of usable UARTs on the platform, returns -1 on failure.

Here is the caller graph for this function:

int mraa_get_spi_bus_count ( void  )

Get the number of usable SPI buses, board must be initialised.

Returns
number of usable SPI buses on the platform, returns -1 on failure.
int mraa_get_pwm_count ( void  )

Get the number of usable PWM pins, board must be initialised.

Returns
number of PWMs on the current platform, -1 on failure.
int mraa_get_gpio_count ( void  )

Get the number of usable GPIOs, board must be initialised.

Returns
number of usable external GPIO pins on the board, -1 on failure.
int mraa_get_aio_bus_count ( void  )

Get the number of usable analog pins, board must be initialised.

Returns
number of usable ADC inputs on the platform and -1 on failure.
int mraa_get_i2c_bus_count ( )

Get platform usable I2C bus count, board must be initialised.

Returns
number f usable I2C bus count on the current platform. Function will return -1 on failure

Here is the caller graph for this function:

int mraa_get_i2c_bus_id ( int  i2c_bus)

Get I2C adapter number in sysfs.

Parameters
i2c_busthe logical I2C bus number
Returns
I2C adapter number in sysfs. Function will return -1 on failure

Here is the caller graph for this function:

unsigned int mraa_get_platform_pin_count ( uint8_t  platform_offset)

Get specified platform pincount, board must be initialised.

Parameters
specifiedplatform offset; 0 for main platform, 1 foor sub platform
Returns
uint of physical pin count on the in-use platform
char* mraa_get_pin_name ( int  pin)

Get name of pin, board must be initialised.

Parameters
pinnumber
Returns
char* of pin name

Here is the caller graph for this function:

int mraa_gpio_lookup ( const char *  pin_name)

Get GPIO index by pin name, board must be initialised.

Parameters
pin_nameGPIO pin name. Eg: IO0
Returns
int of MRAA index for GPIO or -1 if not found.

Here is the caller graph for this function:

int mraa_i2c_lookup ( const char *  i2c_name)

Get I2C bus index by bus name, board must be initialised.

Parameters
i2c_nameI2C bus name. Eg: I2C6
Returns
int of MRAA index for I2C bus or -1 if not found.

Here is the caller graph for this function:

int mraa_spi_lookup ( const char *  spi_name)

Get SPI bus index by bus name, board must be initialised.

Parameters
spi_nameName of SPI bus. Eg: SPI2
Returns
int of MRAA index for SPI bus or -1 if not found.

Here is the caller graph for this function:

int mraa_pwm_lookup ( const char *  pwm_name)

Get PWM index by PWM name, board must be initialised.

Parameters
pwm_nameName of PWM. Eg:PWM0
Returns
int of MRAA index for PWM or -1 if not found.

Here is the caller graph for this function:

int mraa_uart_lookup ( const char *  uart_name)

Get UART index by name, board must be initialised.

Parameters
uart_nameName of UART. Eg:UART1
Returns
int of MRAA index for UART, or -1 if not found.

Here is the caller graph for this function:

int mraa_get_default_i2c_bus ( uint8_t  platform_offset)

Get default i2c bus, board must be initialised.

Returns
int default i2c bus index

Here is the caller graph for this function:

mraa_boolean_t mraa_has_sub_platform ( )

Detect presence of sub platform.

Returns
mraa_boolean_t 1 if sub platform is present and initialized, 0 otherwise

Here is the caller graph for this function:

mraa_boolean_t mraa_is_sub_platform_id ( int  pin_or_bus_id)

Check if pin or bus id includes sub platform mask.

Parameters
intpin or bus number
Returns
mraa_boolean_t 1 if pin or bus is for sub platform, 0 otherwise

Here is the caller graph for this function:

int mraa_get_sub_platform_id ( int  pin_or_bus_index)

Convert pin or bus index to corresponding sub platform id.

Parameters
intpin or bus index
Returns
int sub platform pin or bus number

Here is the caller graph for this function:

int mraa_get_sub_platform_index ( int  pin_or_bus_id)

Convert pin or bus sub platform id to index.

Parameters
intsub platform pin or bus id
Returns
int pin or bus index

Here is the caller graph for this function:

mraa_result_t mraa_add_subplatform ( mraa_platform_t  subplatformtype,
const char *  uart_dev 
)

Add mraa subplatform

Parameters
subplatformtype
uartdevice subplatform is on
Returns
mraa_result_t indicating success

Here is the caller graph for this function:

mraa_result_t mraa_remove_subplatform ( mraa_platform_t  subplatformtype)

Remove a mraa subplatform

Parameters
subplatformtype
Returns
mraa_result indicating success
void* mraa_init_io ( const char *  desc)

Create IO using a description in the format: [io]-[pin] [io]-[raw]-[pin] [io]-[raw]-[id]-[pin] [io]-[raw]-[path]

Parameters
IOdescription
Returns
void* to IO context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_init_json_platform ( const char *  path)

Instantiate an unknown board using a json file

Parameters
Pathto the json file, relative to the folder the program was initially run in or a direct path
Returns
mraa_result indicating success

Here is the caller graph for this function:

Macro Definition Documentation

#define MRAA_RETURN_FOR_ERROR (   func)
Value:
do { \
res = func; \
if (res != MRAA_SUCCESS) \
return res;} while(0)
Definition: types.h:206
mraa_result_t
Definition: types.h:205

Executes function func and returns its result in case of error

Typedef Documentation

typedef unsigned int mraa_boolean_t

MRAA boolean type 1 For TRUE

Include dependency graph for common.h: