#include "types.h"
+#define MRAA_PLATFORM_NAME_MAX_SIZE 64
+
/** @file
*
* This file defines the basic shared values for libmraa
typedef unsigned int mraa_boolean_t;
/**
- * Enum representing different possible modes for a pin.
+ * Initialise MRAA
+ *
+ * Detects running platform and attempts to use included pinmap, this is run on
+ * module/library init/load but is handy to rerun to check board initialised
+ * correctly. Anything but MRAA_SUCCESS should be considered a critical failure
+ *
+ * @return Result of operation
*/
-typedef enum {
- MRAA_PIN_VALID = 0, /**< Pin Valid */
- MRAA_PIN_GPIO = 1, /**< General Purpose IO */
- MRAA_PIN_PWM = 2, /**< Pulse Width Modulation */
- MRAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
- MRAA_PIN_SPI = 4, /**< SPI */
- MRAA_PIN_I2C = 5, /**< I2C */
- MRAA_PIN_AIO = 6 /**< Analog in */
-} mraa_pinmodes_t;
+#if (defined SWIGPYTHON) || (defined SWIG)
+mraa_result_t mraa_init();
+#else
+// this sets a compiler attribute (supported by GCC & clang) to have mraa_init()
+// be called as a constructor make sure your libc supports this! uclibc needs
+// to be compiled with UCLIBC_CTOR_DTOR
+mraa_result_t mraa_init() __attribute__((constructor));
+#endif
/**
- * A bitfield representing the capabilities of a pin.
+ * De-Initilise MRAA
+ *
+ * This is not a strict requirement but useful to test memory leaks and for
+ * people who like super clean code. If dynamically loading & unloading
+ * libmraa you need to call this before unloading the library.
*/
-typedef struct {
- /*@{*/
- mraa_boolean_t valid:1; /**< Is the pin valid at all */
- mraa_boolean_t gpio:1; /**< Is the pin gpio capable */
- mraa_boolean_t pwm:1; /**< Is the pin pwm capable */
- mraa_boolean_t fast_gpio:1; /**< Is the pin fast gpio capable */
- mraa_boolean_t spi:1; /**< Is the pin spi capable */
- mraa_boolean_t i2c:1; /**< Is the pin i2c capable */
- mraa_boolean_t aio:1; /**< Is the pin analog input capable */
- /*@}*/
-} mraa_pincapabilities_t;
+void mraa_deinit();
/**
- * A Structure representing a multiplexer and the required value
+ * Checks if a pin is able to use the passed in mode.
+ *
+ * @param pin Physical Pin to be checked.
+ * @param mode the mode to be tested.
+ * @return boolean if the mode is supported, 0=false.
*/
-typedef struct {
- /*@{*/
- unsigned int pin; /**< Raw GPIO pin id */
- unsigned int value; /**< Raw GPIO value */
- /*@}*/
-} mraa_mux_t;
-
-typedef struct {
- mraa_boolean_t complex_pin:1;
- mraa_boolean_t output_en:1;
- mraa_boolean_t output_en_high:1;
- mraa_boolean_t pullup_en:1;
- mraa_boolean_t pullup_en_hiz:1;
-} mraa_pin_cap_complex_t;
-
-typedef struct {
- /*@{*/
- unsigned int pinmap; /**< sysfs pin */
- unsigned int parent_id; /** parent chip id */
- unsigned int mux_total; /** Numfer of muxes needed for operation of pin */
- mraa_mux_t mux[6]; /** Array holding information about mux */
- unsigned int output_enable; /** Output Enable GPIO, for level shifting */
- unsigned int pullup_enable; /** Pull-Up enable GPIO, inputs */
- mraa_pin_cap_complex_t complex_cap;
- /*@}*/
-} mraa_pin_t;
-
-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 */
- mraa_pin_t gpio; /** GPio context containing none mmap info */
- /*@}*/
-} mraa_mmap_pin_t;
+mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode);
/**
- * A Structure representing a physical Pin.
+ * Check the board's bit size when reading the value
+ *
+ * @return raw bits being read from kernel module. zero if no ADC
*/
-typedef struct {
- /*@{*/
- char name[8]; /**< Pin's real world name */
- mraa_pincapabilities_t capabilites; /**< Pin Capabiliites */
- mraa_pin_t gpio; /**< GPIO structure */
- mraa_pin_t pwm; /**< PWM structure */
- mraa_pin_t aio; /**< Anaglog Pin */
- mraa_mmap_pin_t mmap; /**< GPIO through memory */
- mraa_pin_t i2c; /**< i2c bus/pin */
- mraa_pin_t spi; /**< spi bus/pin */
- /*@}*/
-} mraa_pininfo_t;
+unsigned int mraa_adc_raw_bits();
/**
- * A Structure representing the physical properties of a i2c bus.
+ * Return value that the raw value should be shifted to. Zero if no ADC
+ *
+ * @return return actual bit size the adc value should be understood as.
*/
-typedef struct {
- /*@{*/
- unsigned int bus_id; /**< ID as exposed in the system */
- unsigned int scl; /**< i2c SCL */
- unsigned int sda; /**< i2c SDA */
- /*@}*/
-} mraa_i2c_bus_t;
+unsigned int mraa_adc_supported_bits();
/**
- * A Structure representing the physical properties of a spi bus.
+ * Sets the log level to use from 0-7 where 7 is very verbose. These are the
+ * syslog log levels, see syslog(3) for more information on the levels.
+ *
+ * @return Result of operation
*/
-typedef struct {
- /*@{*/
- unsigned int bus_id; /**< The Bus ID as exposed to the system. */
- unsigned int slave_s; /**< Slave select */
- mraa_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 */
- /*@}*/
-} mraa_spi_bus_t;
+mraa_result_t mraa_set_log_level(int level);
/**
- * A Structure representing a platform/board.
+ * Return the Platform's Name, If no platform detected return NULL
+ *
+ * @return platform name
*/
-typedef struct {
- /*@{*/
- unsigned int phy_pin_count; /**< The Total IO pins on board */
- unsigned int gpio_count; /**< GPIO Count */
- unsigned int aio_count; /**< Analog side Count */
- unsigned int i2c_bus_count; /**< Usable i2c Count */
- mraa_i2c_bus_t i2c_bus[6]; /**< Array of i2c */
- unsigned int def_i2c_bus; /**< Position in array of default i2c bus */
- unsigned int spi_bus_count; /**< Usable spi Count */
- mraa_spi_bus_t spi_bus[6]; /**< Array of spi */
- unsigned int def_spi_bus; /**< Position in array of defult spi bus */
- unsigned int adc_raw; /**< ADC raw bit value */
- unsigned int adc_supported; /**< ADC supported bit value */
- mraa_pininfo_t* pins; /**< Pointer to pin array */
- /*@}*/
-} mraa_board_t;
+char* mraa_get_platform_name();
/**
- * Initialise MRAA
+ * This function attempts to set the mraa 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.
*
- * Detects running platform and attempts to use included pinmap
+ * @param priority Value from typically 0 to 99
+ * @return The priority value set
+ */
+int mraa_set_priority(const unsigned int priority);
+
+/** Get the version string of mraa autogenerated from git tag
*
- * @return Result of operation
+ * 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
+ *
+ * @return version string from version.h
*/
-#ifndef SWIG
-// this sets a compiler attribute (supported by GCC & clang) to have mraa_init()
-// be called as a constructor make sure your libc supports this! uclibc needs
-// to be compiled with UCLIBC_CTOR_DTOR
-mraa_result_t mraa_init() __attribute__((constructor));
-#else
-mraa_result_t mraa_init();
-#endif
+const char* mraa_get_version();
/**
- * Checks if a pin is able to use the passed in mode.
+ * Print a textual representation of the mraa_result_t
*
- * @param pin Physical Pin to be checked.
- * @param mode the mode to be tested.
- * @return boolean if the mode is supported, 0=false.
+ * @param result the result to print
*/
-mraa_boolean_t mraa_pin_mode_test(int pin, mraa_pinmodes_t mode);
+void mraa_result_print(mraa_result_t result);
/**
- * Check the board's bit size when reading the value
+ * Get platform type, board must be initialised.
*
- * @return raw bits being read from kernel module. zero if no ADC
+ * @return mraa_platform_t Platform type enum
*/
-unsigned int mraa_adc_raw_bits();
+mraa_platform_t mraa_get_platform_type();
/**
- * Return value that the raw value should be shifted to. Zero if no ADC
+ * Get platform pincount, board must be initialised.
*
- * @return return actual bit size the adc value should be understood as.
+ * @return uint of physical pin count on the in-use platform
*/
-unsigned int mraa_adc_supported_bits();
+unsigned int mraa_get_pin_count();
+
+/**
+* Get name of pin, board must be initialised.
+*
+* @param pin number
+*
+* @return char* of pin name
+*/
+char* mraa_get_pin_name(int pin);
#ifdef __cplusplus
}