mraa  1.9.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
common.h
Go to the documentation of this file.
1 /*
2  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
4  * Copyright © 2014 Intel Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <stdint.h>
28 #include "types.h"
29 
31 #define MRAA_PLATFORM_NAME_MAX_SIZE 64
32 
33 #define MRAA_PIN_NAME_SIZE 12
34 
36 #define MRAA_SUB_PLATFORM_BIT_SHIFT 9
37 
38 #define MRAA_SUB_PLATFORM_MASK (1<<MRAA_SUB_PLATFORM_BIT_SHIFT)
39 
41 #define MRAA_MAIN_PLATFORM_OFFSET 0
42 
43 #define MRAA_SUB_PLATFORM_OFFSET 1
44 
47 #define MRAA_RETURN_FOR_ERROR(func) do { \
48  mraa_result_t res; \
49  res = func; \
50  if (res != MRAA_SUCCESS) \
51  return res;} while(0)
52 
56 #ifdef __GNUC__
57 #define DEPRECATED __attribute__((deprecated))
58 #elif defined(_MSC_VER)
59 #define DEPRECATED __declspec(deprecated)
60 #else
61 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
62 #define DEPRECATED
63 #endif
64 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
78 typedef unsigned int mraa_boolean_t;
79 
89 #if (defined SWIGPYTHON) || (defined SWIG)
91 #else
92 // this sets a compiler attribute (supported by GCC & clang) to have mraa_init()
93 // be called as a constructor make sure your libc supports this! uclibc needs
94 // to be compiled with UCLIBC_CTOR_DTOR
95 mraa_result_t mraa_init() __attribute__((constructor));
96 #endif
97 
105 void mraa_deinit() __attribute__((destructor));
106 
114 mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode);
115 
121 unsigned int mraa_adc_raw_bits();
122 
129 unsigned int mraa_get_platform_adc_raw_bits(uint8_t platform_offset);
130 
136 unsigned int mraa_adc_supported_bits();
137 
144 unsigned int mraa_get_platform_adc_supported_bits(int platform_offset);
145 
153 
159 const char* mraa_get_platform_name();
160 
169 const char* mraa_get_platform_version(int platform_offset);
170 
180 int mraa_set_priority(const int priority);
181 
189 const char* mraa_get_version();
190 
196 void mraa_result_print(mraa_result_t result);
197 
204 
213 
219 unsigned int mraa_get_pin_count();
220 
226 int mraa_get_uart_count();
227 
234 
240 int mraa_get_pwm_count();
241 
247 int mraa_get_gpio_count();
248 
254 int mraa_get_aio_count();
255 
263 
270 int mraa_get_i2c_bus_id(int i2c_bus);
271 
278 unsigned int mraa_get_platform_pin_count(uint8_t platform_offset);
279 
286 char* mraa_get_pin_name(int pin);
287 
294 int mraa_gpio_lookup(const char* pin_name);
295 
302 int mraa_i2c_lookup(const char* i2c_name);
303 
310 int mraa_spi_lookup(const char* spi_name);
311 
318 int mraa_pwm_lookup(const char* pwm_name);
319 
326 int mraa_uart_lookup(const char* uart_name);
327 
333 int mraa_get_default_i2c_bus(uint8_t platform_offset);
334 
340 mraa_boolean_t mraa_has_sub_platform();
341 
342 
350 mraa_boolean_t mraa_is_sub_platform_id(int pin_or_bus_id);
351 
359 int mraa_get_sub_platform_id(int pin_or_bus_index);
360 
368 int mraa_get_sub_platform_index(int pin_or_bus_id);
369 
378 mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char* dev);
379 
388 
400 void* mraa_init_io(const char* desc);
401 
410 mraa_result_t mraa_init_json_platform(const char* path);
411 
412 #ifdef __cplusplus
413 }
414 #endif
int mraa_get_platform_combined_type()
int mraa_spi_lookup(const char *spi_name)
int mraa_get_spi_bus_count()
int mraa_i2c_lookup(const char *i2c_name)
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype)
int mraa_gpio_lookup(const char *pin_name)
const char * mraa_get_version()
unsigned int mraa_get_platform_adc_raw_bits(uint8_t platform_offset)
void mraa_deinit() __attribute__((destructor))
const char * mraa_get_platform_name()
unsigned int mraa_boolean_t
Definition: common.h:78
mraa_platform_t
Definition: types.h:39
mraa_platform_t mraa_get_platform_type()
mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
unsigned int mraa_get_platform_adc_supported_bits(int platform_offset)
int mraa_get_sub_platform_index(int pin_or_bus_id)
unsigned int mraa_adc_supported_bits()
int mraa_get_i2c_bus_count()
int mraa_get_i2c_bus_id(int i2c_bus)
mraa_boolean_t mraa_is_sub_platform_id(int pin_or_bus_id)
int mraa_set_priority(const int priority)
char * mraa_get_pin_name(int pin)
int mraa_get_uart_count()
mraa_result_t mraa_init_json_platform(const char *path)
mraa_result_t mraa_init() __attribute__((constructor))
int mraa_get_pwm_count()
int mraa_uart_lookup(const char *uart_name)
mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char *dev)
int mraa_pwm_lookup(const char *pwm_name)
int mraa_get_aio_count()
int mraa_get_sub_platform_id(int pin_or_bus_index)
int mraa_get_gpio_count()
unsigned int mraa_adc_raw_bits()
mraa_result_t
Definition: types.h:209
void * mraa_init_io(const char *desc)
mraa_pinmodes_t
Definition: types.h:232
const char * mraa_get_platform_version(int platform_offset)
mraa_boolean_t mraa_has_sub_platform()
unsigned int mraa_get_platform_pin_count(uint8_t platform_offset)
void mraa_result_print(mraa_result_t result)
mraa_result_t mraa_set_log_level(int level)
int mraa_get_default_i2c_bus(uint8_t platform_offset)
unsigned int mraa_get_pin_count()