maa.i: stop importing all of maa.h definitions
[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 %rename(Gpio) maa_gpio_context;
16
17 typedef struct {
18     /*@{*/
19     int pin; /**< the pin number, as known to the os. */
20     FILE *value_fp; /**< the file pointer to the value of the gpio */
21     /*@}*/
22 } maa_gpio_context;
23
24 %nodefault maa_gpio_context;
25 %extend maa_gpio_context {
26   maa_gpio_context(int pin, int raw=0)
27   {
28     if (raw)
29       return maa_gpio_init_raw(pin);
30     return maa_gpio_init(pin);
31   }
32   ~maa_gpio_context()
33   {
34     maa_gpio_close($self);
35   }
36   int write(int value)
37   {
38     return maa_gpio_write($self, value);
39   }
40   int dir(gpio_dir_t dir)
41   {
42     return maa_gpio_dir($self, dir);
43   }
44   int read()
45   {
46     return maa_gpio_read($self);
47   }
48   int mode(gpio_mode_t mode)
49   {
50     return maa_gpio_mode($self, mode);
51   }
52 }
53
54 #### i2c ####
55
56 %rename(I2c) maa_i2c_context;
57
58 typedef struct {
59     /*@{*/
60     int hz; /**< frequency of communication */
61     int fh; /**< the file handle to the /dev/i2c-* device */
62     int addr; /**< the address of the i2c slave */
63     maa_gpio_context gpio;
64     /*@}*/
65 } maa_i2c_context;
66
67 %nodefault maa_i2c_context;
68 %extend maa_i2c_context {
69   maa_i2c_context()
70   {
71     return maa_i2c_init();
72   }
73   ~maa_i2c_context()
74   {
75     maa_i2c_stop($self);
76   }
77   int frequency(int hz)
78   {
79     return maa_i2c_frequency($self, hz);
80   }
81   int read(char *data, int length)
82   {
83     return maa_i2c_read($self, data, length);
84   }
85   int read()
86   {
87     return maa_i2c_read_byte($self);
88   }
89   int write(char *data, int length)
90   {
91     return maa_i2c_write($self, data, length);
92   }
93   int write(int data)
94   {
95     return maa_i2c_write_byte($self, data);
96   }
97 }
98
99 #### PWM ####
100
101 %rename(Pwm) maa_pwm_context;
102
103 typedef struct {
104     /*@{*/
105     int pin; /**< the pin number, as known to the os. */
106     int chipid; /**< the chip id, which the pwm resides */
107     FILE *duty_fp; /**< File pointer to duty file */
108     /*@}*/
109 } maa_pwm_context;
110
111 %nodefault maa_pwm_context;
112 %extend maa_pwm_context {
113   maa_pwm_context(int pin)
114   {
115     return maa_pwm_init(pin);
116   }
117   maa_pwm_context(int chipid, int pin)
118   {
119     return maa_pwm_init_raw(chipid, pin);
120   }
121   ~maa_pwm_context()
122   {
123     maa_pwm_close($self);
124   }
125   int write(float percentage)
126   {
127     return maa_pwm_write($self, percentage);
128   }
129   int read()
130   {
131     return maa_pwm_read($self);
132   }
133   int period(float seconds)
134   {
135     return maa_pwm_period($self, seconds);
136   }
137   int period_ms(int ms)
138   {
139     return maa_pwm_period_ms($self, ms);
140   }
141   int period_us(int us)
142   {
143     return maa_pwm_period_us($self, us);
144   }
145   int pulsewidth(float seconds)
146   {
147     return maa_pwm_pulsewidth($self, seconds);
148   }
149   int pulsewidth_ms(int ms)
150   {
151     return maa_pwm_pulsewidth($self, ms);
152   }
153   int pulsewidth_us(int us)
154   {
155     return maa_pwm_pulsewidth($self, us);
156   }
157   int enable(int enable)
158   {
159     return maa_pwm_enable($self, enable);
160   }
161 }
162
163 #### SPI ####
164
165 %rename(Spi) maa_spi_context;
166
167 typedef struct {
168     /*@{*/
169     int spifd; /**< File descriptor to SPI Device */
170     /*@}*/
171 } maa_spi_context;
172
173 %nodefault maa_spi_context;
174 %extend maa_spi_context {
175   maa_spi_context()
176   {
177     return maa_spi_init();
178   }
179   ~maa_spi_context()
180   {
181     maa_spi_stop($self);
182   }
183   int mode(unsigned short mode)
184   {
185     return maa_spi_mode($self, mode);
186   }
187   int frequency(int hz)
188   {
189     return maa_spi_frequency($self, hz);
190   }
191   unsigned int write(unsigned int data)
192   {
193     return maa_spi_write($self, data);
194   }
195 }
196
197 #### AIO ####
198
199 %rename(Aio) maa_aio_context;
200
201 typedef struct {
202     unsigned int channel;
203     FILE *adc_in_fp;
204 } maa_aio_context;
205
206 %nodefault maa_aio_context;
207 %extend maa_aio_context {
208   maa_aio_context(unsigned int aio_channel)
209   {
210     return maa_aio_init(aio_channel);
211   }
212   ~maa_aio_context()
213   {
214     maa_aio_close($self);
215   }
216   unsigned int read()
217   {
218     return maa_aio_read_u16($self);
219   }
220 }