swig: add unexport() calls to be used by destructors in object api
[contrib/mraa.git] / api / pwm.h
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #pragma once
26
27 /** @file
28  *
29  * This file defines the pwm interface for libmaa
30  *
31  */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <stdio.h>
38 #include <fcntl.h>
39
40 #include "maa.h"
41
42 /**
43  * A strucutre representing a PWM pin
44  */
45 typedef struct {
46     /*@{*/
47     int pin; /**< the pin number, as known to the os. */
48     int chipid; /**< the chip id, which the pwm resides */
49     FILE *duty_fp; /**< File pointer to duty file */
50     /*@}*/
51 } maa_pwm_context;
52
53 /** Initialise pwm_context, uses board mapping.
54  *
55  * @param pin The PWM PIN.
56  *
57  * @return maa_pwm_context The returned initialised pwm context
58  */
59 maa_pwm_context* maa_pwm_init(int pin);
60
61 /** Initialise pwm_context, raw mode.
62  *
63  * @param chipid The chip inwhich the PWM is under in SYSFS
64  * @param pin The PWM PIN.
65  *
66  * @return maa_pwm_context The returned initialised pwm context
67  */
68 maa_pwm_context* maa_pwm_init_raw(int chipid, int pin);
69
70 /** Set the ouput duty-cycle percentage, as a float
71  *
72  * @param pwm The PWM context to use.
73  * @param percentage A floating-point value representing percentage of output.
74  *    The value should lie between 0.0f (representing on 0%) and 1.0f
75  *    Values above or below this range will be set at either 0.0f or 1.0f.
76  *
77  * @return maa_result_t the maa result.
78  */
79 maa_result_t maa_pwm_write(maa_pwm_context* pwm, float percentage);
80
81 /** Read the ouput duty-cycle percentage, as a float
82  *
83  * @param pwm The PWM context to use.
84  * @return percentage A floating-point value representing percentage of output.
85  *    The value should lie between 0.0f (representing on 0%) and 1.0f
86  *    Values above or below this range will be set at either 0.0f or 1.0f.
87  */
88 float maa_pwm_read(maa_pwm_context* pwm);
89
90 /** Set the PWM period as seconds represented in a float
91  *
92  * @param pwm The PWM context to use.
93  * @param seconds Peroid represented as a float in seconds.
94  *
95  * @return maa_result_t the maa result.
96  */
97 maa_result_t maa_pwm_period(maa_pwm_context* pwm, float seconds);
98
99 /** Set period, milli-oseconds.
100  *
101  * @param pwm The PWM context to use.
102  * @param ms milli-seconds for period.
103  *
104  * @return maa_result_t the maa result.
105  */
106 maa_result_t maa_pwm_period_ms(maa_pwm_context* pwm, int ms);
107
108 /** Set period, microseconds
109  *
110  * @param pwm The PWM context to use.
111  * @param ns microseconds as period.
112  *
113  * @return maa_result_t the maa result.
114  */
115 maa_result_t maa_pwm_period_us(maa_pwm_context* pwm, int us);
116
117 /** Set pulsewidth, As represnted by seconds in a (float).
118  *
119  * @param pwm The PWM context to use.
120  * @param seconds The duration of a pulse
121  *
122  * @return maa_result_t the maa result.
123  */
124 maa_result_t maa_pwm_pulsewidth(maa_pwm_context* pwm, float seconds);
125
126 /** Set pulsewidth, milliseconds
127  *
128  * @param pwm The PWM context to use.
129  * @param ms milliseconds for pulsewidth.
130  *
131  * @return maa_result_t the maa result.
132  */
133 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context* pwm, int ms);
134
135 /** Set pulsewidth, microseconds.
136  *
137  * @param pwm The PWM context to use.
138  * @param us microseconds for pulsewidth.
139  *
140  * @return maa_result_t the maa result.
141  */
142 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context* pwm, int us);
143
144 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
145  *   and 0 will disable the output.
146  *
147  * @param pwm The PWM context to use.
148  * @param enable enable status of pin
149  *
150  * @return maa_result_t the maa result.
151  */
152 maa_result_t maa_pwm_enable(maa_pwm_context* pwm, int enable);
153
154 /** Unexport the PWM context (maa_pwm_close() will call this function)
155  *
156  * @param dev The PWM context/
157  *
158  * @return maa result type.
159  */
160 maa_result_t maa_pwm_unexport(maa_pwm_context* pwm);
161
162 /** Close and unexport the PWM pin.
163  * 
164  * @param pwm The PWM context to use.
165  *
166  * @return maa_result_t the maa result.
167  */
168 maa_result_t maa_pwm_close(maa_pwm_context* pwm);
169
170 #ifdef __cplusplus
171 }
172 #endif