Compile libmraa for Android and Brillo
[contrib/mraa.git] / include / mraa_internal_types.h
index 07d7b2a..8350831 100644 (file)
 
 #include "common.h"
 #include "mraa.h"
+#include "mraa_func.h"
+#include "mraa_adv_func.h"
+
+// Bionic does not implement pthread cancellation API
+#ifndef __BIONIC__
+#define HAVE_PTHREAD_CANCEL
+#endif
 
 // general status failures for internal functions
 #define MRAA_PLATFORM_NO_INIT -3
@@ -45,9 +52,14 @@ struct _gpio {
     void *isr_args; /**< args return when interupt service request triggered */
     pthread_t thread_id; /**< the isr handler thread id */
     int isr_value_fp; /**< the isr file pointer on the value */
+#ifndef HAVE_PTHREAD_CANCEL
+    int isr_control_pipe[2]; /**< a pipe used to interrupt the isr from polling the value fd*/
+#endif
+    mraa_boolean_t isr_thread_terminating; /**< is the isr thread being terminated? */
     mraa_boolean_t owner; /**< If this context originally exported the pin */
     mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
     int (*mmap_read) (mraa_gpio_context dev);
+    mraa_adv_func_t* advance_func; /**< override function table */
     /*@}*/
 };
 
@@ -59,7 +71,23 @@ struct _i2c {
     int busnum; /**< the bus number of the /dev/i2c-* device */
     int fh; /**< the file handle to the /dev/i2c-* device */
     int addr; /**< the address of the i2c slave */
-    unsigned long funcs;
+    unsigned long funcs; /**< /dev/i2c-* device capabilities as per https://www.kernel.org/doc/Documentation/i2c/functionality */
+    void *handle; /**< generic handle for non-standard drivers that don't use file descriptors  */
+    mraa_adv_func_t* advance_func; /**< override function table */
+    /*@}*/
+};
+
+/**
+ * A structure representing the SPI device
+ */
+struct _spi {
+    /*@{*/
+    int devfd;          /**< File descriptor to SPI Device */
+    uint32_t mode;      /**< Spi mode see spidev.h */
+    int clock;          /**< clock to run transactions at */
+    mraa_boolean_t lsb; /**< least significant bit mode */
+    unsigned int bpw;   /**< Bits per word */
+    mraa_adv_func_t* advance_func; /**< override function table */
     /*@}*/
 };
 
@@ -73,6 +101,7 @@ struct _pwm {
     int duty_fp; /**< File pointer to duty file */
     int period;  /**< Cache the period to speed up setting duty */
     mraa_boolean_t owner; /**< Owner of pwm context*/
+    mraa_adv_func_t* advance_func; /**< override function table */
     /*@}*/
 };
 
@@ -80,9 +109,12 @@ struct _pwm {
  * A structure representing a Analog Input Channel
  */
 struct _aio {
+    /*@{*/
     unsigned int channel; /**< the channel as on board and ADC module */
     int adc_in_fp; /**< File Pointer to raw sysfs */
     int value_bit; /**< 10 bits by default. Can be increased if board */
+    mraa_adv_func_t* advance_func; /**< override function table */
+    /*@}*/
 };
 
 /**
@@ -91,8 +123,9 @@ struct _aio {
 struct _uart {
     /*@{*/
     int index; /**< the uart index, as known to the os. */
-    char* path; /**< the uart device path. */
+    const char* path; /**< the uart device path. */
     int fd; /**< file descriptor for device. */
+    mraa_adv_func_t* advance_func; /**< override function table */
     /*@}*/
 };
 
@@ -176,6 +209,7 @@ typedef struct {
     unsigned int bus_id; /**< ID as exposed in the system */
     unsigned int scl; /**< i2c SCL */
     unsigned int sda; /**< i2c SDA */
+    // mraa_drv_api_t drv_type; /**< Driver type */
     /*@}*/
 } mraa_i2c_bus_t;
 
@@ -209,7 +243,8 @@ typedef struct {
 /**
  * A Structure representing a platform/board.
  */
-typedef struct {
+
+typedef struct _board_t {
     /*@{*/
     unsigned int phy_pin_count; /**< The Total IO pins on board */
     unsigned int gpio_count; /**< GPIO Count */
@@ -228,7 +263,12 @@ typedef struct {
     int pwm_default_period; /**< The default PWM period is US */
     int pwm_max_period; /**< Maximum period in us */
     int pwm_min_period; /**< Minimum period in us */
+    mraa_platform_t platform_type; /**< Platform type */
     const char* platform_name; /**< Platform Name pointer */
     mraa_pininfo_t* pins;     /**< Pointer to pin array */
+    mraa_adv_func_t* adv_func;    /**< Pointer to advanced function disptach table */
+    struct _board_t* sub_platform;     /**< Pointer to sub platform */
     /*@}*/
 } mraa_board_t;
+
+