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