2014-04-10 16:53:19 +01:00
|
|
|
/*
|
2014-05-05 20:00:20 +01:00
|
|
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
|
|
|
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
2014-04-10 16:53:19 +01:00
|
|
|
* Copyright © 2014 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-04-28 18:39:07 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* This file defines the basic shared values for libmaa
|
|
|
|
|
*/
|
|
|
|
|
|
2014-04-29 18:44:09 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-01 15:26:39 +01:00
|
|
|
/**
|
|
|
|
|
* MAA return codes
|
|
|
|
|
*/
|
2014-04-27 23:11:31 +01:00
|
|
|
typedef enum {
|
2014-05-01 15:26:39 +01:00
|
|
|
MAA_SUCCESS = 0, /**< Expected response */
|
|
|
|
|
MAA_ERROR_FEATURE_NOT_IMPLEMENTED = 1, /**< Feature TODO */
|
|
|
|
|
MAA_ERROR_FEATURE_NOT_SUPPORTED = 2, /**< Feature not supported by HW */
|
|
|
|
|
MAA_ERROR_INVALID_VERBOSITY_LEVEL = 3, /**< Verbosity level wrong */
|
|
|
|
|
MAA_ERROR_INVALID_PARAMETER = 4, /**< Parameter invalid */
|
|
|
|
|
MAA_ERROR_INVALID_HANDLE = 5, /**< Handle invalid */
|
|
|
|
|
MAA_ERROR_NO_RESOURCES = 6, /**< No resource of that type avail */
|
|
|
|
|
MAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
|
|
|
|
|
MAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
|
|
|
|
|
MAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
|
2014-05-01 17:37:56 +01:00
|
|
|
MAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
|
|
|
|
|
MAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
|
2014-05-06 15:29:42 +01:00
|
|
|
MAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised */
|
2014-04-27 23:11:31 +01:00
|
|
|
|
2014-05-01 15:26:39 +01:00
|
|
|
MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
|
2014-04-27 23:11:31 +01:00
|
|
|
} maa_result_t;
|
|
|
|
|
|
2014-05-02 11:52:40 +01:00
|
|
|
/**
|
|
|
|
|
* MAA boolean type
|
|
|
|
|
* 1 For TRUE
|
|
|
|
|
*/
|
2014-04-29 15:01:24 +01:00
|
|
|
typedef unsigned int maa_boolean_t;
|
|
|
|
|
|
2014-05-07 15:12:44 +01:00
|
|
|
/**
|
|
|
|
|
* Enum representing different possible modes for a pin.
|
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
|
|
|
|
MAA_PIN_VALID = 0, /**< Pin Valid */
|
|
|
|
|
MAA_PIN_GPIO = 1, /**< General Purpose IO */
|
|
|
|
|
MAA_PIN_PWM = 2, /**< Pulse Width Modulation */
|
|
|
|
|
MAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
|
|
|
|
|
MAA_PIN_SPI = 4, /**< SPI */
|
|
|
|
|
MAA_PIN_I2C = 5, /**< I2C */
|
|
|
|
|
MAA_PIN_AIO = 6 /**< Analog in */
|
|
|
|
|
} maa_pinmodes_t;
|
|
|
|
|
|
2014-05-02 11:52:40 +01:00
|
|
|
/**
|
|
|
|
|
* A bitfield representing the capabilities of a pin.
|
|
|
|
|
*/
|
2014-05-01 16:55:23 +01:00
|
|
|
typedef struct {
|
2014-05-02 11:52:40 +01:00
|
|
|
/*@{*/
|
|
|
|
|
maa_boolean_t valid:1; /**< Is the pin valid at all */
|
|
|
|
|
maa_boolean_t gpio:1; /**< Is the pin gpio capable */
|
|
|
|
|
maa_boolean_t pwm:1; /**< Is the pin pwm capable */
|
|
|
|
|
maa_boolean_t fast_gpio:1; /**< Is the pin fast gpio capable */
|
|
|
|
|
maa_boolean_t spi:1; /**< Is the pin spi capable */
|
|
|
|
|
maa_boolean_t i2c:1; /**< Is the pin i2c capable */
|
|
|
|
|
maa_boolean_t aio:1; /**< Is the pin analog input capable */
|
|
|
|
|
/*@}*/
|
|
|
|
|
} maa_pincapabilities_t;
|
2014-04-29 15:01:24 +01:00
|
|
|
|
2014-05-02 11:52:40 +01:00
|
|
|
/**
|
|
|
|
|
* A Structure representing a multiplexer and the required value
|
|
|
|
|
*/
|
2014-04-29 15:01:24 +01:00
|
|
|
typedef struct {
|
2014-05-02 11:52:40 +01:00
|
|
|
/*@{*/
|
|
|
|
|
unsigned int pin; /**< Raw GPIO pin id */
|
|
|
|
|
unsigned int value; /**< Raw GPIO value */
|
2014-05-30 17:10:52 +01:00
|
|
|
/*@}*/
|
2014-04-29 15:01:24 +01:00
|
|
|
} maa_mux_t;
|
|
|
|
|
|
2014-05-05 20:00:20 +01:00
|
|
|
/**
|
|
|
|
|
* A Strucutre representing a singular I/O pin. i.e GPIO/PWM
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
/*@{*/
|
2014-05-29 16:30:07 +01:00
|
|
|
unsigned int pinmap; /**< sysfs pin */
|
|
|
|
|
unsigned int parent_id; /** parent chip id */
|
|
|
|
|
unsigned int mux_total; /** Numfer of muxes needed for operation of pin */
|
|
|
|
|
maa_mux_t mux[6]; /** Array holding information about mux */
|
2014-05-05 20:00:20 +01:00
|
|
|
/*@}*/
|
|
|
|
|
} maa_pin_t;
|
|
|
|
|
|
2014-05-29 16:30:07 +01:00
|
|
|
typedef struct {
|
|
|
|
|
/*@{*/
|
|
|
|
|
char mem_dev[32]; /**< Memory device to use /dev/uio0 etc */
|
|
|
|
|
unsigned int mem_sz; /** Size of memory to map */
|
|
|
|
|
unsigned int bit_pos; /** Position of value bit */
|
|
|
|
|
maa_pin_t gpio; /** GPio context containing none mmap info */
|
|
|
|
|
/*@}*/
|
|
|
|
|
} maa_mmap_pin_t;
|
|
|
|
|
|
2014-05-02 11:52:40 +01:00
|
|
|
/**
|
|
|
|
|
* A Structure representing a physical Pin.
|
|
|
|
|
*/
|
2014-04-29 15:01:24 +01:00
|
|
|
typedef struct {
|
2014-05-02 11:52:40 +01:00
|
|
|
/*@{*/
|
|
|
|
|
char name[8]; /**< Pin's real world name */
|
|
|
|
|
maa_pincapabilities_t capabilites; /**< Pin Capabiliites */
|
2014-05-05 20:00:20 +01:00
|
|
|
maa_pin_t gpio; /**< GPIO structure */
|
|
|
|
|
maa_pin_t pwm; /**< PWM structure */
|
|
|
|
|
maa_pin_t aio; /**< Anaglog Pin */
|
2014-05-29 16:30:07 +01:00
|
|
|
maa_mmap_pin_t mmap; /**< GPIO through memory */
|
2014-05-05 20:00:20 +01:00
|
|
|
maa_pin_t i2c; /**< i2c bus/pin */
|
|
|
|
|
maa_pin_t spi; /**< spi bus/pin */
|
2014-05-02 11:52:40 +01:00
|
|
|
/*@}*/
|
2014-05-01 16:55:23 +01:00
|
|
|
} maa_pininfo_t;
|
|
|
|
|
|
2014-05-05 20:00:20 +01:00
|
|
|
/**
|
|
|
|
|
* A Structure representing the physical properties of a i2c bus.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
/*@{*/
|
|
|
|
|
unsigned int bus_id; /**< ID as exposed in the system */
|
|
|
|
|
unsigned int scl; /**< i2c SCL */
|
|
|
|
|
unsigned int sda; /**< i2c SDA */
|
|
|
|
|
/*@}*/
|
|
|
|
|
} maa_i2c_bus_t;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A Structure representing the physical properties of a spi bus.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
/*@{*/
|
2014-05-20 16:50:38 +01:00
|
|
|
unsigned int bus_id; /**< The Bus ID as exposed to the system. */
|
|
|
|
|
unsigned int slave_s; /**< Slave select */
|
2014-05-05 20:00:20 +01:00
|
|
|
maa_boolean_t three_wire; /**< Is the bus only a three wire system */
|
|
|
|
|
unsigned int sclk; /**< Serial Clock */
|
|
|
|
|
unsigned int mosi; /**< Master Out, Slave In. */
|
|
|
|
|
unsigned int miso; /**< Master In, Slave Out. */
|
|
|
|
|
unsigned int cs; /**< Chip Select, used when the board is a spi slave */
|
|
|
|
|
/*@}*/
|
|
|
|
|
} maa_spi_bus_t;
|
|
|
|
|
|
2014-05-02 11:52:40 +01:00
|
|
|
/**
|
|
|
|
|
* A Structure representing a platform/board.
|
|
|
|
|
*/
|
2014-05-01 16:55:23 +01:00
|
|
|
typedef struct {
|
2014-05-02 11:52:40 +01:00
|
|
|
/*@{*/
|
2014-05-05 20:00:20 +01:00
|
|
|
unsigned int phy_pin_count; /**< The Total IO pins on board */
|
2014-05-02 11:52:40 +01:00
|
|
|
unsigned int gpio_count; /**< GPIO Count */
|
2014-05-05 20:00:20 +01:00
|
|
|
unsigned int aio_count; /**< Analog side Count */
|
2014-05-02 14:45:24 +01:00
|
|
|
unsigned int i2c_bus_count; /**< Usable i2c Count */
|
2014-05-05 20:00:20 +01:00
|
|
|
maa_i2c_bus_t i2c_bus[6]; /**< Array of i2c */
|
|
|
|
|
unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
|
2014-05-02 14:45:24 +01:00
|
|
|
unsigned int spi_bus_count; /**< Usable spi Count */
|
2014-05-05 20:00:20 +01:00
|
|
|
maa_spi_bus_t spi_bus[6]; /**< Array of spi */
|
|
|
|
|
unsigned int def_spi_bus; /**< Position in array of defult spi bus */
|
2014-05-02 11:52:40 +01:00
|
|
|
maa_pininfo_t* pins; /**< Pointer to pin array */
|
|
|
|
|
/*@}*/
|
2014-05-01 16:55:23 +01:00
|
|
|
} maa_board_t;
|
2014-04-29 15:01:24 +01:00
|
|
|
|
2014-05-30 17:10:52 +01:00
|
|
|
/**
|
|
|
|
|
* Initialise MAA
|
2014-05-02 11:52:40 +01:00
|
|
|
*
|
|
|
|
|
* Detects running platform and attempts to use included pinmap
|
2014-05-30 17:10:52 +01:00
|
|
|
*
|
|
|
|
|
* @return Result of operation
|
2014-05-02 11:52:40 +01:00
|
|
|
*/
|
2014-05-16 09:43:01 +01:00
|
|
|
#ifndef SWIG
|
|
|
|
|
// this sets a compiler attribute (supported by GCC & clang) to have maa_init()
|
|
|
|
|
// be called as a constructor make sure your libc supports this! uclibc needs
|
|
|
|
|
// to be compiled with UCLIBC_CTOR_DTOR
|
|
|
|
|
maa_result_t maa_init() __attribute__((constructor));
|
|
|
|
|
#else
|
2014-05-02 11:52:40 +01:00
|
|
|
maa_result_t maa_init();
|
2014-05-16 09:43:01 +01:00
|
|
|
#endif
|
2014-05-02 11:52:40 +01:00
|
|
|
|
2014-06-04 14:39:41 +01:00
|
|
|
/**
|
|
|
|
|
* This function attempts to set the maa process to a given priority and the
|
|
|
|
|
* scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0.
|
|
|
|
|
* This function * will set to MAX if * priority is > MAX. Function will return
|
|
|
|
|
* -1 on failure.
|
|
|
|
|
|
|
|
|
|
* @param priority Value from typically 0 to 99
|
|
|
|
|
* @return The priority value set
|
|
|
|
|
*/
|
|
|
|
|
int maa_set_priority(const unsigned int priority);
|
|
|
|
|
|
2014-04-29 16:33:15 +01:00
|
|
|
/** Get the version string of maa autogenerated from git tag
|
|
|
|
|
*
|
|
|
|
|
* The version returned may not be what is expected however it is a reliable
|
|
|
|
|
* number associated with the git tag closest to that version at build time
|
2014-05-30 17:10:52 +01:00
|
|
|
*
|
2014-04-29 16:33:15 +01:00
|
|
|
* @return version string from version.h
|
|
|
|
|
*/
|
2014-04-28 00:29:14 +01:00
|
|
|
const char* maa_get_version();
|
2014-04-29 18:44:09 +01:00
|
|
|
|
2014-05-30 17:10:52 +01:00
|
|
|
/**
|
|
|
|
|
* Print a textual representation of the maa_result_t
|
2014-05-06 15:29:42 +01:00
|
|
|
*
|
2014-05-30 17:10:52 +01:00
|
|
|
* @param result the result to print
|
2014-05-06 15:29:42 +01:00
|
|
|
*/
|
|
|
|
|
void maa_result_print(maa_result_t result);
|
|
|
|
|
|
2014-05-30 17:10:52 +01:00
|
|
|
/**
|
|
|
|
|
* Checks if a pin is able to use the passed in mode.
|
2014-05-07 15:12:44 +01:00
|
|
|
*
|
|
|
|
|
* @param pin Physical Pin to be checked.
|
|
|
|
|
* @param mode the mode to be tested.
|
|
|
|
|
* @return boolean if the mode is supported, 0=false.
|
|
|
|
|
*/
|
|
|
|
|
maa_boolean_t maa_pin_mode_test(int pin, maa_pinmodes_t mode);
|
|
|
|
|
|
2014-04-29 18:44:09 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|