maa.i: Initial documentation of Swigified object API
[contrib/mraa.git] / src / maa.i
1 %{
2     #include "maa.h"
3     #include "gpio.h"
4     #include "pwm.h"
5     #include "i2c.h"
6     #include "spi.h"
7     #include "aio.h"
8 %}
9
10 %rename(get_version) maa_get_version();
11 const char * maa_get_version();
12
13 #### GPIO ####
14
15 typedef enum {
16     MAA_GPIO_STRONG     = 0, /**< Default. Strong high and low */
17     MAA_GPIO_PULLUP     = 1, /**< Resistive High */
18     MAA_GPIO_PULLDOWN   = 2, /**< Resistive Low */
19     MAA_GPIO_HIZ        = 3  /**< High Z State */
20 } gpio_mode_t;
21
22 typedef enum {
23     MAA_GPIO_OUT    = 0, /**< Output. A Mode can also be set */
24     MAA_GPIO_IN     = 1  /**< Input. */
25 } gpio_dir_t;
26
27 %nodefault maa_gpio_context;
28 %rename(Gpio) maa_gpio_context;
29 %ignore value_fp;
30
31 %feature("autodoc") maa_gpio_context "
32 Create a Gpio object and export it. Depending on your board the correct GPIO
33 value will be used. If raw is true then the pin that will be initialised will
34 be the hardcoded pin value in the kernel. Please see your board IO
35 documentation to understand exactly what will happen.
36
37 Parameters:
38         * pin: pin number read from the board, i.e IO3 is 3
39         * raw: set to True to use real pin value from the kernel";
40 typedef struct {
41     /*@{*/
42     int pin; /**< the pin number, as known to the os. */
43     FILE *value_fp; /**< the file pointer to the value of the gpio */
44     /*@}*/
45 } maa_gpio_context;
46
47 %extend maa_gpio_context {
48   maa_gpio_context(int pin, int raw=0)
49   {
50     if (raw)
51       return maa_gpio_init_raw(pin);
52     return maa_gpio_init(pin);
53   }
54   ~maa_gpio_context()
55   {
56     maa_gpio_close($self);
57   }
58   %feature("autodoc") write "
59   Write a value to a GPIO pin
60
61   Parameters:
62         * value: value to write to GPIO";
63   int write(int value)
64   {
65     return maa_gpio_write($self, value);
66   }
67   %feature("autodoc") dir "
68   Set the gpio direction
69
70   Parameters:
71         * dir: GPIO direction";
72   int dir(gpio_dir_t dir)
73   {
74     return maa_gpio_dir($self, dir);
75   }
76   %feature("autodoc") read "
77   Read the value of a GPIO
78
79   Returns:
80         * value: GPIO value";
81   int read()
82   {
83     return maa_gpio_read($self);
84   }
85   %feature("autodoc") mode "
86   Set the GPIO mode
87
88   Parameters:
89         * mode: GPIO mode to set";
90   int mode(gpio_mode_t mode)
91   {
92     return maa_gpio_mode($self, mode);
93   }
94 }
95
96 #### i2c ####
97
98 %nodefault maa_i2c_context;
99 %rename(I2c) maa_i2c_context;
100
101 %ignore fh;
102 typedef struct {
103     /*@{*/
104     int hz; /**< frequency of communication */
105     int fh; /**< the file handle to the /dev/i2c-* device */
106     int addr; /**< the address of the i2c slave */
107     maa_gpio_context gpio;
108     /*@}*/
109 } maa_i2c_context;
110
111 %nodefault maa_i2c_context;
112 %extend maa_i2c_context {
113   maa_i2c_context()
114   {
115     return maa_i2c_init();
116   }
117   ~maa_i2c_context()
118   {
119     maa_i2c_stop($self);
120   }
121   int frequency(int hz)
122   {
123     return maa_i2c_frequency($self, hz);
124   }
125   int read(char *data, int length)
126   {
127     return maa_i2c_read($self, data, length);
128   }
129   int read()
130   {
131     return maa_i2c_read_byte($self);
132   }
133   int write(char *data, int length)
134   {
135     return maa_i2c_write($self, data, length);
136   }
137   int write(int data)
138   {
139     return maa_i2c_write_byte($self, data);
140   }
141 }
142
143 #### PWM ####
144
145 %rename(Pwm) maa_pwm_context;
146
147 %ignore duty_fp;
148 typedef struct {
149     /*@{*/
150     int pin; /**< the pin number, as known to the os. */
151     int chipid; /**< the chip id, which the pwm resides */
152     FILE *duty_fp; /**< File pointer to duty file */
153     /*@}*/
154 } maa_pwm_context;
155
156 %nodefault maa_pwm_context;
157 %extend maa_pwm_context {
158   maa_pwm_context(int pin)
159   {
160     return maa_pwm_init(pin);
161   }
162   maa_pwm_context(int chipid, int pin)
163   {
164     return maa_pwm_init_raw(chipid, pin);
165   }
166   ~maa_pwm_context()
167   {
168     maa_pwm_close($self);
169   }
170   int write(float percentage)
171   {
172     return maa_pwm_write($self, percentage);
173   }
174   int read()
175   {
176     return maa_pwm_read($self);
177   }
178   int period(float seconds)
179   {
180     return maa_pwm_period($self, seconds);
181   }
182   int period_ms(int ms)
183   {
184     return maa_pwm_period_ms($self, ms);
185   }
186   int period_us(int us)
187   {
188     return maa_pwm_period_us($self, us);
189   }
190   int pulsewidth(float seconds)
191   {
192     return maa_pwm_pulsewidth($self, seconds);
193   }
194   int pulsewidth_ms(int ms)
195   {
196     return maa_pwm_pulsewidth($self, ms);
197   }
198   int pulsewidth_us(int us)
199   {
200     return maa_pwm_pulsewidth($self, us);
201   }
202   int enable(int enable)
203   {
204     return maa_pwm_enable($self, enable);
205   }
206 }
207
208 #### SPI ####
209
210 %rename(Spi) maa_spi_context;
211
212 %ignore spifd;
213 typedef struct {
214     /*@{*/
215     int spifd; /**< File descriptor to SPI Device */
216     /*@}*/
217 } maa_spi_context;
218
219 %nodefault maa_spi_context;
220 %extend maa_spi_context {
221   maa_spi_context()
222   {
223     return maa_spi_init();
224   }
225   ~maa_spi_context()
226   {
227     maa_spi_stop($self);
228   }
229   int mode(unsigned short mode)
230   {
231     return maa_spi_mode($self, mode);
232   }
233   int frequency(int hz)
234   {
235     return maa_spi_frequency($self, hz);
236   }
237   unsigned int write(unsigned int data)
238   {
239     return maa_spi_write($self, data);
240   }
241 }
242
243 #### AIO ####
244
245 %rename(Aio) maa_aio_context;
246
247 %ignore adc_in_fp;
248 typedef struct {
249     unsigned int channel;
250     FILE *adc_in_fp;
251 } maa_aio_context;
252
253 %nodefault maa_aio_context;
254 %extend maa_aio_context {
255   maa_aio_context(unsigned int aio_channel)
256   {
257     return maa_aio_init(aio_channel);
258   }
259   ~maa_aio_context()
260   {
261     maa_aio_close($self);
262   }
263   unsigned int read()
264   {
265     return maa_aio_read_u16($self);
266   }
267 }