api: remove internal strut from public API
[contrib/mraa.git] / api / mraa / common.h
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 "types.h"
28
29 #define MRAA_PLATFORM_NAME_MAX_SIZE 64
30
31 /** @file
32  *
33  * This file defines the basic shared values for libmraa
34  */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /**
41  * MRAA boolean type
42  * 1 For TRUE
43  */
44 typedef unsigned int mraa_boolean_t;
45
46 /**
47  * Initialise MRAA
48  *
49  * Detects running platform and attempts to use included pinmap
50  *
51  * @return Result of operation
52  */
53 #if (defined SWIGPYTHON) || (defined SWIG)
54 mraa_result_t mraa_init();
55 #else
56 // this sets a compiler attribute (supported by GCC & clang) to have mraa_init()
57 // be called as a constructor make sure your libc supports this!  uclibc needs
58 // to be compiled with UCLIBC_CTOR_DTOR
59 mraa_result_t mraa_init() __attribute__((constructor));
60 #endif
61
62 /**
63  * De-Initilise MRAA
64  *
65  * This is not a strict requirement but useful to test memory leaks and for
66  * people who like super clean code. If dynamically loading & unloading
67  * libmraa you need to call this before unloading the library.
68  */
69 void mraa_deinit();
70
71 /**
72  * Checks if a pin is able to use the passed in mode.
73  *
74  * @param pin Physical Pin to be checked.
75  * @param mode the mode to be tested.
76  * @return boolean if the mode is supported, 0=false.
77  */
78 mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode);
79
80 /**
81  * Check the board's  bit size when reading the value
82  *
83  * @return raw bits being read from kernel module. zero if no ADC
84  */
85 unsigned int mraa_adc_raw_bits();
86
87 /**
88  * Return value that the raw value should be shifted to. Zero if no ADC
89  *
90  * @return return actual bit size the adc value should be understood as.
91  */
92 unsigned int mraa_adc_supported_bits();
93
94 /**
95  * Sets the log level to use from 0-7 where 7 is very verbose. These are the
96  * syslog log levels, see syslog(3) for more information on the levels.
97  *
98  * @return Result of operation
99  */
100 mraa_result_t mraa_set_log_level(int level);
101
102 /**
103  * Return the Platform's Name, If no platform detected return NULL
104  *
105  * @return platform name
106  */
107 char* mraa_get_platform_name();
108
109 /**
110  * This function attempts to set the mraa process to a given priority and the
111  * scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0.
112  * This function * will set to MAX if * priority is > MAX. Function will return
113  * -1 on failure.
114  *
115  * @param priority Value from typically 0 to 99
116  * @return The priority value set
117  */
118 int mraa_set_priority(const unsigned int priority);
119
120 /** Get the version string of mraa autogenerated from git tag
121  *
122  * The version returned may not be what is expected however it is a reliable
123  * number associated with the git tag closest to that version at build time
124  *
125  * @return version string from version.h
126  */
127 const char* mraa_get_version();
128
129 /**
130  * Print a textual representation of the mraa_result_t
131  *
132  * @param result the result to print
133  */
134 void mraa_result_print(mraa_result_t result);
135
136 /**
137  * Get platform type, board must be initialised.
138  *
139  * @return mraa_platform_t Platform type enum
140  */
141 mraa_platform_t mraa_get_platform_type();
142
143 /**
144  * Get platform pincount, board must be initialised.
145  *
146  * @return uint of physical pin count on the in-use platform
147  */
148 unsigned int mraa_get_pin_count();
149
150 #ifdef __cplusplus
151 }
152 #endif