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 * Enum representing different possible modes for a pin.
68 MAA_PIN_VALID = 0, /**< Pin Valid */
69 MAA_PIN_GPIO = 1, /**< General Purpose IO */
70 MAA_PIN_PWM = 2, /**< Pulse Width Modulation */
71 MAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
72 MAA_PIN_SPI = 4, /**< SPI */
73 MAA_PIN_I2C = 5, /**< I2C */
74 MAA_PIN_AIO = 6 /**< Analog in */
78 * A bitfield representing the capabilities of a pin.
82 maa_boolean_t valid:1; /**< Is the pin valid at all */
83 maa_boolean_t gpio:1; /**< Is the pin gpio capable */
84 maa_boolean_t pwm:1; /**< Is the pin pwm capable */
85 maa_boolean_t fast_gpio:1; /**< Is the pin fast gpio capable */
86 maa_boolean_t spi:1; /**< Is the pin spi capable */
87 maa_boolean_t i2c:1; /**< Is the pin i2c capable */
88 maa_boolean_t aio:1; /**< Is the pin analog input capable */
90 } maa_pincapabilities_t;
93 * A Structure representing a multiplexer and the required value
97 unsigned int pin; /**< Raw GPIO pin id */
98 unsigned int value; /**< Raw GPIO value */
102 * A Strucutre representing a singular I/O pin. i.e GPIO/PWM
107 unsigned int parent_id;
108 unsigned int mux_total;
114 * A Structure representing a physical Pin.
118 char name[8]; /**< Pin's real world name */
119 maa_pincapabilities_t capabilites; /**< Pin Capabiliites */
120 maa_pin_t gpio; /**< GPIO structure */
121 maa_pin_t pwm; /**< PWM structure */
122 maa_pin_t aio; /**< Anaglog Pin */
123 maa_pin_t fast_gpio; /**< Fast GPIO */
124 maa_pin_t i2c; /**< i2c bus/pin */
125 maa_pin_t spi; /**< spi bus/pin */
130 * A Structure representing the physical properties of a i2c bus.
134 unsigned int bus_id; /**< ID as exposed in the system */
135 unsigned int scl; /**< i2c SCL */
136 unsigned int sda; /**< i2c SDA */
141 * A Structure representing the physical properties of a spi bus.
145 unsigned int bus_id; /**< The Bus ID as exposed to the system. */
146 unsigned int slave_s; /**< Slave select */
147 maa_boolean_t three_wire; /**< Is the bus only a three wire system */
148 unsigned int sclk; /**< Serial Clock */
149 unsigned int mosi; /**< Master Out, Slave In. */
150 unsigned int miso; /**< Master In, Slave Out. */
151 unsigned int cs; /**< Chip Select, used when the board is a spi slave */
156 * A Structure representing a platform/board.
160 unsigned int phy_pin_count; /**< The Total IO pins on board */
161 unsigned int gpio_count; /**< GPIO Count */
162 unsigned int aio_count; /**< Analog side Count */
163 unsigned int i2c_bus_count; /**< Usable i2c Count */
164 maa_i2c_bus_t i2c_bus[6]; /**< Array of i2c */
165 unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
166 unsigned int spi_bus_count; /**< Usable spi Count */
167 maa_spi_bus_t spi_bus[6]; /**< Array of spi */
168 unsigned int def_spi_bus; /**< Position in array of defult spi bus */
169 maa_pininfo_t* pins; /**< Pointer to pin array */
175 * Detects running platform and attempts to use included pinmap
176 * @return maa_result_t maa result
179 // this sets a compiler attribute (supported by GCC & clang) to have maa_init()
180 // be called as a constructor make sure your libc supports this! uclibc needs
181 // to be compiled with UCLIBC_CTOR_DTOR
182 maa_result_t maa_init() __attribute__((constructor));
184 maa_result_t maa_init();
187 /** Get the version string of maa autogenerated from git tag
189 * The version returned may not be what is expected however it is a reliable
190 * number associated with the git tag closest to that version at build time
191 * @return version string from version.h
193 const char* maa_get_version();
195 /** Print a textual representation of the maa_result_t
197 * @param result the result to print,
199 void maa_result_print(maa_result_t result);
201 /** Checks if a pin is able to use the passed in mode.
203 * @param pin Physical Pin to be checked.
204 * @param mode the mode to be tested.
205 * @return boolean if the mode is supported, 0=false.
207 maa_boolean_t maa_pin_mode_test(int pin, maa_pinmodes_t mode);