2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
4 * Copyright © 2014 Intel Corporation
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
29 * This file defines the basic shared values for libmaa
41 MAA_SUCCESS = 0, /**< Expected response */
42 MAA_ERROR_FEATURE_NOT_IMPLEMENTED = 1, /**< Feature TODO */
43 MAA_ERROR_FEATURE_NOT_SUPPORTED = 2, /**< Feature not supported by HW */
44 MAA_ERROR_INVALID_VERBOSITY_LEVEL = 3, /**< Verbosity level wrong */
45 MAA_ERROR_INVALID_PARAMETER = 4, /**< Parameter invalid */
46 MAA_ERROR_INVALID_HANDLE = 5, /**< Handle invalid */
47 MAA_ERROR_NO_RESOURCES = 6, /**< No resource of that type avail */
48 MAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
49 MAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
50 MAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
51 MAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
52 MAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
53 MAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised
55 MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
62 typedef unsigned int maa_boolean_t;
65 * A bitfield representing the capabilities of a pin.
69 maa_boolean_t valid:1; /**< Is the pin valid at all */
70 maa_boolean_t gpio:1; /**< Is the pin gpio capable */
71 maa_boolean_t pwm:1; /**< Is the pin pwm capable */
72 maa_boolean_t fast_gpio:1; /**< Is the pin fast gpio capable */
73 maa_boolean_t spi:1; /**< Is the pin spi capable */
74 maa_boolean_t i2c:1; /**< Is the pin i2c capable */
75 maa_boolean_t aio:1; /**< Is the pin analog input capable */
77 } maa_pincapabilities_t;
80 * A Structure representing a multiplexer and the required value
84 unsigned int pin; /**< Raw GPIO pin id */
85 unsigned int value; /**< Raw GPIO value */
89 * A Strucutre representing a singular I/O pin. i.e GPIO/PWM
94 unsigned int parent_id;
95 unsigned int mux_total;
101 * A Structure representing a physical Pin.
105 char name[8]; /**< Pin's real world name */
106 maa_pincapabilities_t capabilites; /**< Pin Capabiliites */
107 maa_pin_t gpio; /**< GPIO structure */
108 maa_pin_t pwm; /**< PWM structure */
109 maa_pin_t aio; /**< Anaglog Pin */
110 maa_pin_t fast_gpio; /**< Fast GPIO */
111 maa_pin_t i2c; /**< i2c bus/pin */
112 maa_pin_t spi; /**< spi bus/pin */
117 * A Structure representing the physical properties of a i2c bus.
121 unsigned int bus_id; /**< ID as exposed in the system */
122 unsigned int scl; /**< i2c SCL */
123 unsigned int sda; /**< i2c SDA */
128 * A Structure representing the physical properties of a spi bus.
132 double bus_id; /**< The Bus ID as exposed to the system. */
133 maa_boolean_t three_wire; /**< Is the bus only a three wire system */
134 unsigned int sclk; /**< Serial Clock */
135 unsigned int mosi; /**< Master Out, Slave In. */
136 unsigned int miso; /**< Master In, Slave Out. */
137 unsigned int cs; /**< Chip Select, used when the board is a spi slave */
142 * A Structure representing a platform/board.
146 unsigned int phy_pin_count; /**< The Total IO pins on board */
147 unsigned int gpio_count; /**< GPIO Count */
148 unsigned int aio_count; /**< Analog side Count */
149 unsigned int i2c_bus_count; /**< Usable i2c Count */
150 maa_i2c_bus_t i2c_bus[6]; /**< Array of i2c */
151 unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
152 unsigned int spi_bus_count; /**< Usable spi Count */
153 maa_spi_bus_t spi_bus[6]; /**< Array of spi */
154 unsigned int def_spi_bus; /**< Position in array of defult spi bus */
155 maa_pininfo_t* pins; /**< Pointer to pin array */
161 * Detects running platform and attempts to use included pinmap
162 * @return maa_result_t maa result
164 maa_result_t maa_init();
168 * Will check input is valid for gpio and will also setup required multiplexers.
169 * @param pin the pin as read from the board surface. i.e IO3 would be 3/
170 * @return the pin as found in the pinmap
172 unsigned int maa_check_gpio(int pin);
176 * Will check input is valid for aio and will also setup required multiplexers.
177 * @param pin the pin as read from the board surface. i.e A3 would be 3/
178 * @return the pin as found in the pinmap
180 unsigned int maa_check_aio(int pin);
182 /** Check i2c interface, sets up multiplexer on device.
184 * @return unsigned int if using /dev/i2c-2 returned would be 2
186 unsigned int maa_check_i2c();
188 /** Get the version string of maa autogenerated from git tag
190 * The version returned may not be what is expected however it is a reliable
191 * number associated with the git tag closest to that version at build time
192 * @return version string from version.h
194 const char* maa_get_version();