gpio: use strtol instead of atoi
[contrib/mraa.git] / src / maa.i
index 2511888..eb2be22 100644 (file)
--- a/src/maa.i
+++ b/src/maa.i
@@ -4,15 +4,41 @@
     #include "pwm.h"
     #include "i2c.h"
     #include "spi.h"
+    #include "aio.h"
 %}
 
 %rename(get_version) maa_get_version();
-%include "maa.h"
+const char * maa_get_version();
+%rename(init) maa_init();
+int maa_init();
 
 #### GPIO ####
 
+typedef enum {
+    MAA_GPIO_STRONG     = 0, /**< Default. Strong high and low */
+    MAA_GPIO_PULLUP     = 1, /**< Resistive High */
+    MAA_GPIO_PULLDOWN   = 2, /**< Resistive Low */
+    MAA_GPIO_HIZ        = 3  /**< High Z State */
+} gpio_mode_t;
+
+typedef enum {
+    MAA_GPIO_OUT    = 0, /**< Output. A Mode can also be set */
+    MAA_GPIO_IN     = 1  /**< Input. */
+} gpio_dir_t;
+
+%nodefault maa_gpio_context;
 %rename(Gpio) maa_gpio_context;
+%ignore value_fp;
 
+%feature("autodoc") maa_gpio_context "
+Create a Gpio object and export it. Depending on your board the correct GPIO
+value will be used. If raw is true then the pin that will be initialised will
+be the hardcoded pin value in the kernel. Please see your board IO
+documentation to understand exactly what will happen.
+
+Parameters:
+        * pin: pin number read from the board, i.e IO3 is 3
+        * raw: set to True to use real pin value from the kernel";
 typedef struct {
     /*@{*/
     int pin; /**< the pin number, as known to the os. */
@@ -20,7 +46,6 @@ typedef struct {
     /*@}*/
 } maa_gpio_context;
 
-%nodefault maa_gpio_context;
 %extend maa_gpio_context {
   maa_gpio_context(int pin, int raw=0)
   {
@@ -30,20 +55,40 @@ typedef struct {
   }
   ~maa_gpio_context()
   {
-    maa_gpio_close($self);
+    maa_gpio_unexport($self);
   }
+  %feature("autodoc") write "
+  Write a value to a GPIO pin
+
+  Parameters:
+        * value: value to write to GPIO";
   int write(int value)
   {
     return maa_gpio_write($self, value);
   }
+  %feature("autodoc") dir "
+  Set the gpio direction
+
+  Parameters:
+        * dir: GPIO direction";
   int dir(gpio_dir_t dir)
   {
     return maa_gpio_dir($self, dir);
   }
+  %feature("autodoc") read "
+  Read the value of a GPIO
+
+  Returns:
+        * value: GPIO value";
   int read()
   {
     return maa_gpio_read($self);
   }
+  %feature("autodoc") mode "
+  Set the GPIO mode
+
+  Parameters:
+        * mode: GPIO mode to set";
   int mode(gpio_mode_t mode)
   {
     return maa_gpio_mode($self, mode);
@@ -52,8 +97,10 @@ typedef struct {
 
 #### i2c ####
 
+%nodefault maa_i2c_context;
 %rename(I2c) maa_i2c_context;
 
+%ignore fh;
 typedef struct {
     /*@{*/
     int hz; /**< frequency of communication */
@@ -71,7 +118,6 @@ typedef struct {
   }
   ~maa_i2c_context()
   {
-    maa_i2c_stop($self);
   }
   int frequency(int hz)
   {
@@ -99,6 +145,7 @@ typedef struct {
 
 %rename(Pwm) maa_pwm_context;
 
+%ignore duty_fp;
 typedef struct {
     /*@{*/
     int pin; /**< the pin number, as known to the os. */
@@ -119,7 +166,7 @@ typedef struct {
   }
   ~maa_pwm_context()
   {
-    maa_pwm_close($self);
+    maa_pwm_unexport($self);
   }
   int write(float percentage)
   {
@@ -163,6 +210,7 @@ typedef struct {
 
 %rename(Spi) maa_spi_context;
 
+%ignore spifd;
 typedef struct {
     /*@{*/
     int spifd; /**< File descriptor to SPI Device */
@@ -177,7 +225,6 @@ typedef struct {
   }
   ~maa_spi_context()
   {
-    maa_spi_stop($self);
   }
   int mode(unsigned short mode)
   {
@@ -192,3 +239,28 @@ typedef struct {
     return maa_spi_write($self, data);
   }
 }
+
+#### AIO ####
+
+%rename(Aio) maa_aio_context;
+
+%ignore adc_in_fp;
+typedef struct {
+    unsigned int channel;
+    FILE *adc_in_fp;
+} maa_aio_context;
+
+%nodefault maa_aio_context;
+%extend maa_aio_context {
+  maa_aio_context(unsigned int aio_channel)
+  {
+    return maa_aio_init(aio_channel);
+  }
+  ~maa_aio_context()
+  {
+  }
+  unsigned int read()
+  {
+    return maa_aio_read_u16($self);
+  }
+}